返回 DeepSeek-Reasonix
goalSubmit.ts
根目录 / desktop / frontend / src / lib / goalSubmit.ts
1 import type { StructuredInvocationSubmit } from "./invocationDisplay";
2
3 /**
4 * Activate a Goal, then submit the first turn.
5 *
6 * For structured Skill/Subagent submissions there is no `/goal` prose fallback:
7 * if Goal activation fails, this must not call `send` (the Skill would otherwise
8 * run without an active Goal). Callers should let activation errors propagate.
9 */
10 export async function activateGoalAndSubmit({
11 displayText,
12 submitText,
13 structured,
14 applyGoal,
15 send,
16 }: {
17 displayText: string;
18 submitText: string;
19 structured?: StructuredInvocationSubmit;
20 applyGoal: (goal: string) => void | Promise<void>;
21 send: (displayText: string, submitText: string, structured?: StructuredInvocationSubmit) => void | Promise<void>;
22 }): Promise<void> {
23 const goal = displayText.trim();
24 // Fail closed: structured paths have no `/goal` wrap, so a no-op or rejected
25 // activation must abort before SubmitInvocationsToTab.
26 await applyGoal(goal);
27 await send(
28 goal,
29 structured ? submitText.trim() : `/goal ${submitText.trim()}`,
30 structured,
31 );
32 }
33
34 /**
35 * Tab-scoped first Goal turn. The backend receives the source tab in one call,
36 * so Goal activation and the structured Skill submit cannot be split by a tab
37 * switch.
38 */
39 export async function activateGoalAndSubmitOnTab({
40 tabId,
41 displayText,
42 submitText,
43 structured,
44 sendToTab,
45 }: {
46 tabId: string;
47 displayText: string;
48 submitText: string;
49 structured?: StructuredInvocationSubmit;
50 sendToTab: (
51 tabId: string,
52 goal: string,
53 displayText: string,
54 submitText: string,
55 structured?: StructuredInvocationSubmit,
56 ) => void | Promise<void>;
57 }): Promise<void> {
58 const sourceTabId = tabId;
59 const goal = displayText.trim();
60 await sendToTab(
61 sourceTabId,
62 goal,
63 goal,
64 structured ? submitText.trim() : `/goal ${submitText.trim()}`,
65 structured,
66 );
67 }
68
68 lines TYPESCRIPT