返回 DeepSeek-Reasonix
remoteComposerOwner.ts
根目录 / desktop / frontend / src / app-runtime / remoteComposerOwner.ts
1 import type { SessionOperationAuthority } from "./useResourceOperations";
2 import type { RemoteSessionApi } from "../lib/useRemoteSession";
3 import type { RemoteTabRefView } from "../lib/types";
4 import type { RemoteNavigationCommand } from "../lib/remoteNavigationCommands";
5 import { CommandCancelled } from "../lib/commandOutcome";
6
7 type RemoteSendPorts = Pick<RemoteSessionApi, "compact" | "runManagementCommand" | "setModel" | "setEffort"> & {
8 send: (display: string, submit: string, choice?: import("../lib/modelApplication").ModelApplicationChoice) => Promise<void>;
9 applyGoal: (tab: string, goal: string) => Promise<unknown>;
10 requestClear: () => void;
11 newSession: RemoteNavigationCommand;
12 };
13 export type RemoteSendInput = {
14 tabId: string;
15 remote?: RemoteTabRefView;
16 activateGoal: boolean;
17 display: string;
18 submit: string;
19 choice?: import("../lib/modelApplication").ModelApplicationChoice;
20 commandText: string;
21 command: ReturnType<typeof import("../lib/useRemoteComposerIntegration").remoteRuntimeCommand>;
22 ports: RemoteSendPorts;
23 };
24
25 export async function executeRemoteSend(input: RemoteSendInput, authority: SessionOperationAuthority): Promise<void> {
26 const { command, ports } = input;
27 authority.checkpoint();
28 if (command?.method === "clearSession") { if (authority.ownsUI()) ports.requestClear(); return; }
29 if (command?.method === "newSession") {
30 if (input.remote && authority.ownsUI()) {
31 const outcome = await ports.newSession(input.remote, { newSession: true });
32 if (outcome.status === "failed") throw outcome.error;
33 if (outcome.status === "cancelled") throw new CommandCancelled(outcome.reason);
34 }
35 return;
36 }
37 if (command?.method === "compact") return ports.compact(command.value);
38 if (command?.method === "runManagementCommand") return ports.runManagementCommand(input.commandText, command.rehydrate);
39 if (command?.method === "setModel" || command?.method === "setEffort") return ports[command.method](command.value);
40 if (input.activateGoal) {
41 await ports.applyGoal(input.tabId, input.commandText);
42 authority.checkpoint();
43 }
44 await ports.send(input.display, input.submit, input.choice);
45 }
46
47 export type ComposerRuntimeInput = {
48 tabId: string;
49 remote: boolean;
50 action: "pause" | "resume" | "effort";
51 level?: string;
52 ports: Pick<RemoteSessionApi, "pauseGoal" | "resumeGoal" | "setEffort"> & {
53 pauseLocal: (tab: string) => Promise<unknown>;
54 resumeLocal: (tab: string) => Promise<unknown>;
55 effortLocal: (tab: string, level: string) => Promise<void>;
56 };
57 };
58 export async function executeComposerRuntime(input: ComposerRuntimeInput, authority: SessionOperationAuthority) {
59 authority.checkpoint();
60 const { ports, tabId, remote } = input;
61 if (input.action === "pause") await (remote ? ports.pauseGoal() : ports.pauseLocal(tabId));
62 else if (input.action === "resume") await (remote ? ports.resumeGoal() : ports.resumeLocal(tabId));
63 else await (remote ? ports.setEffort(input.level ?? "") : ports.effortLocal(tabId, input.level ?? ""));
64 }
65
65 lines TYPESCRIPT