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
2 changes: 2 additions & 0 deletions main/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { registerSubagentHandlers } from "./subagents.js";
import { registerAssistantLiveHandlers } from "./assistant-live.js";
import { registerAidenRemoteHandlers } from "./aiden-remote.js";
import { registerPeerHostHandlers } from "./peer-hosts.js";
import { registerLocalRunIpc } from "./local-runs-main.js";
import { registerBotHandlers } from "./bots.js";
import { registerBotRoutineHandlers } from "./bot-routines.js";
import { registerDiagnosticHandlers } from "./diagnostics.js";
Expand Down Expand Up @@ -84,6 +85,7 @@ export function registerHandlers(): void {
registerAssistantLiveHandlers();
registerAidenRemoteHandlers();
registerPeerHostHandlers();
registerLocalRunIpc();
if (hostPlatformCapabilities().bots) registerBotHandlers();
registerBtwHandlers();
registerTtsHandlers();
Expand Down
51 changes: 51 additions & 0 deletions main/handlers/local-runs-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ipcMain, logger } from "../platform.js";
import { hostRunRegistry } from "../services/host-runs-main.js";
import { llmClient } from "../services/llm-client.js";
import { LocalRunObservers } from "../services/local-run-observers.js";
import { rendererDocumentOwner } from "../services/renderer-document-owner.js";
import { registerLocalRunHandlers } from "./local-runs.js";

let observers: LocalRunObservers | null = null;

function localRunObservers(): LocalRunObservers {
observers ??= new LocalRunObservers({
registry: hostRunRegistry,
setTimer: (callback, ms) => setTimeout(callback, ms),
clearTimer: (handle) => clearTimeout(handle as ReturnType<typeof setTimeout>),
});
return observers;
}

export function registerLocalRunIpc(): void {
registerLocalRunHandlers<Electron.IpcMainInvokeEvent>({
handle: (channel, handler) => ipcMain.handle(channel, handler),
owner: (event) => {
const owner = rendererDocumentOwner(
event,
() => new Error("Watching a run requires an active application document."),
);
return {
key: `${owner.id}:${owner.documentId}`,
isDestroyed: owner.isDestroyed,
send: owner.send,
onInvalidated: owner.onInvalidated,
};
},
observers: localRunObservers,
stopRun: (runId) => {
const summary = hostRunRegistry.summary(runId);
if (!summary || summary.state === "done" || summary.state === "failed" || summary.state === "cancelled") {
return false;
}
// The same host-authority stop Aiden Remote's run controls use.
const cancelled = llmClient.cancel(runId, "user_stop");
if (cancelled) logger.info("chat", JSON.stringify({ event: "renderer_host_run_stop", runId }));
return cancelled;
},
isRunSettled: (runId) => {
const state = hostRunRegistry.summary(runId)?.state;
const terminal = state === "done" || state === "failed" || state === "cancelled";
return terminal && !llmClient.isGenerationLive(runId);
},
});
}
Loading
Loading