Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .ade/db.sqlite
Empty file.
77 changes: 76 additions & 1 deletion apps/desktop/src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app, BrowserWindow, nativeImage, shell } from "electron";
import { app, BrowserWindow, nativeImage, protocol, shell } from "electron";
import path from "node:path";
type NodePtyType = typeof import("node-pty");

Check warning on line 3 in apps/desktop/src/main/main.ts

View workflow job for this annotation

GitHub Actions / lint-desktop

`import()` type annotations are forbidden
import { registerIpc } from "./services/ipc/registerIpc";
import { createFileLogger } from "./services/logging/logger";
import { openKvDb } from "./services/state/kvDb";
Expand Down Expand Up @@ -394,7 +394,82 @@
return win;
}

// Register custom protocol for serving local artifact files (images, videos) to the renderer.
// Must be called before app.whenReady().
protocol.registerSchemesAsPrivileged([
{ scheme: "ade-artifact", privileges: { standard: false, supportFetchAPI: true, stream: true, bypassCSP: true } },
]);

app.whenReady().then(async () => {
// Handle ade-artifact:// requests — serves local files for proof drawer previews.
// Path is encoded in the URL: ade-artifact:///absolute/path/to/file.png
protocol.handle("ade-artifact", (request) => {
const url = new URL(request.url);
let filePath = decodeURIComponent(url.pathname);
// On Windows, pathname starts with /C:/... — strip leading slash
if (process.platform === "win32" && /^\/[a-zA-Z]:/.test(filePath)) {
filePath = filePath.slice(1);
}
try {
const stat = fs.statSync(filePath);
if (!stat.isFile()) return new Response("Not found", { status: 404 });
const fileSize = stat.size;
const ext = path.extname(filePath).replace(/^\./, "").toLowerCase();
const mimeMap: Record<string, string> = {
png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp",
gif: "image/gif", bmp: "image/bmp", svg: "image/svg+xml",
mp4: "video/mp4", webm: "video/webm", mov: "video/quicktime", avi: "video/x-msvideo", mkv: "video/x-matroska",
};
const mime = mimeMap[ext] ?? "application/octet-stream";

// Support Range requests — required for <video> playback and seeking
const rangeHeader = request.headers.get("Range");
if (rangeHeader) {
const match = /bytes=(\d+)-(\d*)/.exec(rangeHeader);
const start = match ? parseInt(match[1], 10) : 0;
const end = match && match[2] ? parseInt(match[2], 10) : fileSize - 1;
const chunkSize = end - start + 1;
const fileStream = fs.createReadStream(filePath, { start, end });
const webStream = new ReadableStream({
start(controller) {
fileStream.on("data", (chunk) => controller.enqueue(typeof chunk === "string" ? Buffer.from(chunk) : chunk));
fileStream.on("end", () => controller.close());
fileStream.on("error", () => controller.close());
},
cancel() { fileStream.destroy(); },
});
return new Response(webStream, {
status: 206,
headers: {
"Content-Type": mime,
"Content-Range": `bytes ${start}-${end}/${fileSize}`,
"Content-Length": String(chunkSize),
"Accept-Ranges": "bytes",
},
});
}

// Full file response (images, small files)
const fileStream = fs.createReadStream(filePath);
const webStream = new ReadableStream({
start(controller) {
fileStream.on("data", (chunk) => controller.enqueue(typeof chunk === "string" ? Buffer.from(chunk) : chunk));
fileStream.on("end", () => controller.close());
fileStream.on("error", () => controller.close());
},
cancel() { fileStream.destroy(); },
});
return new Response(webStream, {
headers: {
"Content-Type": mime,
"Content-Length": String(fileSize),
"Accept-Ranges": "bytes",
},
});
} catch {
return new Response("Not found", { status: 404 });
}
});
console.log("[info] app.hardware_acceleration", {
enabled: !disableHardwareAcceleration,
reason: disableHardwareAcceleration
Expand Down
13 changes: 13 additions & 0 deletions apps/desktop/src/main/services/chat/agentChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import type { LinearCredentialService } from "../cto/linearCredentialService";
import type { createPrService } from "../prs/prService";
import type { ComputerUseArtifactBrokerService } from "../computerUse/computerUseArtifactBrokerService";
import { createProofObserver } from "../computerUse/proofObserver";
import { maybeSyntheticToolResult } from "../computerUse/syntheticToolResult";
import { resolveAdeMcpServerLaunch, resolveUnifiedRuntimeRoot } from "../orchestrator/unifiedOrchestratorAdapter";
import type { createMissionService } from "../missions/missionService";
import type { createAiOrchestratorService } from "../orchestrator/aiOrchestratorService";
Expand Down Expand Up @@ -4795,6 +4796,12 @@ export function createAgentChatService(args: {
itemId,
turnId,
});
// Synthesize a tool_result for the proof observer since the
// Claude V2 SDK never surfaces tool results in the stream.
const syntheticResult = maybeSyntheticToolResult(toolName, block.input ?? {}, itemId, turnId);
if (syntheticResult) {
emitChatEvent(managed, syntheticResult);
}
}
}
}
Expand Down Expand Up @@ -4893,6 +4900,12 @@ export function createAgentChatService(args: {
itemId,
turnId,
});
// Synthesize a tool_result for the proof observer since the
// Claude V2 SDK never surfaces tool results in the stream.
const syntheticResult = maybeSyntheticToolResult(toolName, block.input ?? {}, itemId, turnId);
if (syntheticResult) {
emitChatEvent(managed, syntheticResult);
}
}
}
} else if (event.type === "message_start") {
Expand Down
Loading
Loading