返回 DeepSeek-Reasonix
deliveryContinue.ts
根目录 / desktop / frontend / src / lib / deliveryContinue.ts
1 // Delivery recovery ("continue checks") flow for final_readiness notices.
2 //
3 // Ordinary Delivery turns carry no Goal, so the recovery prompt is submitted
4 // directly. A tab with a Goal must resume it first so its delivery scope and
5 // persisted checkpoint survive the continuation; a Goal that refuses to resume
6 // (completed, or the tab vanished) is not poked further. The active tab is
7 // re-checked after the async resume so a mid-flight tab switch cannot deliver
8 // the continuation into the wrong session.
9 export interface DeliveryContinueOptions {
10 tabId: string | null | undefined;
11 ready: boolean;
12 goal: string | undefined;
13 /** Full committed UI ownership; unlike activeTabId this cannot revive on A → B → A. */
14 uiOwnership?: unknown;
15 ownsUI?: (ownership: unknown) => boolean;
16 /** One-release compatibility adapter for callers without a surface fence. */
17 activeTabId?: () => string | null | undefined;
18 resumeGoal: (tabId: string) => Promise<boolean>;
19 send: (tabId: string) => Promise<void>;
20 }
21
22 export async function continueDelivery(opts: DeliveryContinueOptions): Promise<void> {
23 const { tabId, ready, goal } = opts;
24 if (!tabId || !ready) return;
25 if ((goal ?? "").trim()) {
26 const resumed = await opts.resumeGoal(tabId);
27 if (!resumed) return;
28 if (opts.ownsUI ? !opts.ownsUI(opts.uiOwnership) : opts.activeTabId?.() !== tabId) return;
29 }
30 await opts.send(tabId);
31 }
32
32 lines TYPESCRIPT