pi-web-ui 0.114.2 → 0.115.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -1
- package/bin/pi-web-ui.mjs +69 -7
- package/dist/server/agent-service-daemon.js +440 -32
- package/dist/server/agent-service.js +878 -383
- package/dist/server/canvas/canvas-dispatch.js +13 -1
- package/dist/server/client-state.js +25 -0
- package/dist/server/communicate-tool.js +2 -0
- package/dist/server/context-usage.js +105 -0
- package/dist/server/conversation-communication.js +14 -0
- package/dist/server/conversation-identity.js +27 -0
- package/dist/server/device-center/approval-summary.js +31 -0
- package/dist/server/device-center/bot-catalog.js +21 -7
- package/dist/server/device-center/bot-execution.js +72 -9
- package/dist/server/device-center/bot-presets.js +46 -0
- package/dist/server/device-center/collab-service.js +328 -10
- package/dist/server/device-center/collab-tool.js +738 -12
- package/dist/server/device-center/connector.js +359 -23
- package/dist/server/device-center/desktop-page.js +22 -16
- package/dist/server/device-center/device-integration.js +595 -0
- package/dist/server/device-center/execution-guides.js +32 -0
- package/dist/server/device-center/execution-instructions.js +19 -0
- package/dist/server/device-center/execution-settings.js +100 -0
- package/dist/server/device-center/execution-system-prompt.js +38 -0
- package/dist/server/device-center/execution-workspace.js +20 -0
- package/dist/server/device-center/executor.js +389 -40
- package/dist/server/device-center/file-sync-paths.js +171 -0
- package/dist/server/device-center/file-sync.js +180 -91
- package/dist/server/device-center/group-context-delta.js +37 -0
- package/dist/server/device-center/group-context-message.js +208 -0
- package/dist/server/device-center/group-context.js +109 -0
- package/dist/server/device-center/group-events.js +136 -0
- package/dist/server/device-center/group-plan-guard.js +138 -0
- package/dist/server/device-center/hub-conversations.js +178 -0
- package/dist/server/device-center/hub-deliveries.js +277 -0
- package/dist/server/device-center/hub-integration.js +451 -0
- package/dist/server/device-center/hub.js +1544 -80
- package/dist/server/device-center/human-interaction.js +232 -0
- package/dist/server/device-center/integration-errors.js +25 -0
- package/dist/server/device-center/local-hub.js +18 -0
- package/dist/server/device-center/local.js +356 -40
- package/dist/server/device-center/main.js +11 -1
- package/dist/server/device-center/path-portal.js +11 -3
- package/dist/server/device-center/relay.js +364 -35
- package/dist/server/device-center/report-metadata.js +66 -0
- package/dist/server/device-center/report-upload.js +63 -0
- package/dist/server/device-center/runtime.js +549 -41
- package/dist/server/device-center/store.js +66 -3
- package/dist/server/device-center/task-context-budget.js +161 -0
- package/dist/server/device-center/task-journal.js +385 -0
- package/dist/server/device-center/task-plan.js +33 -0
- package/dist/server/device-center/task-progress.js +141 -0
- package/dist/server/device-center/task-recovery.js +452 -0
- package/dist/server/device-center/task-report-outbox.js +216 -0
- package/dist/server/device-center/task-report.js +384 -0
- package/dist/server/device-center/task-scheduler.js +400 -0
- package/dist/server/device-center/task-state.js +333 -0
- package/dist/server/device-center/transfer-stream.js +1006 -0
- package/dist/server/device-center/transfers.js +815 -8
- package/dist/server/dispatch-domain-handlers.js +21 -3
- package/dist/server/dsh/dsh-agent-service.js +6 -0
- package/dist/server/goal-service.js +10 -5
- package/dist/server/index.js +89 -13
- package/dist/server/message-deletion.js +40 -0
- package/dist/server/message-window.js +9 -0
- package/dist/server/patch-executable-lookup.js +396 -0
- package/dist/server/payload-limits.js +2 -0
- package/dist/server/plugin-llm.js +100 -9
- package/dist/server/plugins.js +1 -0
- package/dist/server/preset-fields.js +24 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/prompt-base-store.js +85 -0
- package/dist/server/prompt-composer.js +5 -2
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/protocol.js +2 -2
- package/dist/server/remote-ssh-service.js +22 -9
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/session-search.js +1 -1
- package/dist/server/settings-service.js +90 -39
- package/dist/server/skill-content-filler.js +29 -8
- package/dist/server/skill-tool.js +12 -3
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagents.js +50 -36
- package/dist/server/tool-host-factories.js +1 -0
- package/dist/server/universal/universal-session.js +5 -0
- package/dist/server/webui-context.js +25 -5
- package/docs/README.md +94 -0
- package/docs/device-center.md +100 -12
- package/docs/dsh-engine.md +10 -10
- package/extensions/webui.ts +43 -1
- package/package.json +1 -1
- package/themes/aetheris.css +5 -0
- package/themes/ayu-light.css +6 -0
- package/themes/bases/flow-base.css +68 -68
- package/themes/catppuccin-latte.css +6 -0
- package/themes/catppuccin.css +6 -0
- package/themes/claude-code-dark.css +5 -0
- package/themes/codex.css +6 -0
- package/themes/cyberpunk.css +6 -0
- package/themes/dark-teal.css +6 -1
- package/themes/dazzle.css +6 -0
- package/themes/everforest-light.css +6 -0
- package/themes/flow-light.css +8 -1
- package/themes/flow.css +6 -1
- package/themes/geist.css +6 -0
- package/themes/gruvbox-light.css +6 -0
- package/themes/kanagawa-lotus.css +6 -0
- package/themes/md-preview.css +6 -0
- package/themes/mist.css +6 -0
- package/themes/nord.css +6 -0
- package/themes/one-dark.css +6 -0
- package/themes/paper.css +6 -0
- package/themes/rose-pine-dawn.css +6 -0
- package/themes/sakura.css +6 -0
- package/themes/solarized-light.css +6 -0
- package/themes/tokyo-night.css +6 -0
- package/themes/translucent.css +6 -0
- package/themes/transparent.css +6 -0
- package/themes/vs-code-dark.css +5 -0
- package/themes/wallpaper-flow.css +5 -1
- package/themes/wallpaper-obsidian.css +6 -0
- package/themes/white.css +6 -0
- package/themes/zhujian-dark.css +6 -1
- package/themes/zhujian.css +6 -1
- package/themes/zhupi-dark.css +6 -1
- package/themes/zhupi.css +6 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BYzPgmoq.js +1 -0
- package/web/dist/assets/BgTasksModal-ni0VTmAQ.js +1 -0
- package/web/dist/assets/{CanvasStudio-B3W6b_rA.js → CanvasStudio-BCUeEf25.js} +3 -3
- package/web/dist/assets/{CanvasStudio-Csv1Sj1-.js → CanvasStudio-DNmDNBod.js} +3 -3
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +3 -0
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +3 -0
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +1 -0
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +1 -0
- package/web/dist/assets/Dropdown-CGXD0DfT.js +1 -0
- package/web/dist/assets/FilePreview-B8iqnBjy.js +2 -0
- package/web/dist/assets/FilePreview-BqviZKCN.js +2 -0
- package/web/dist/assets/GlobalSearchModal-mevF-ySi.js +1 -0
- package/web/dist/assets/GlobalSearchModal-qL99FN_F.js +1 -0
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +3 -0
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +3 -0
- package/web/dist/assets/HintTip-LHwkS2jV.js +1 -0
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +2 -0
- package/web/dist/assets/PiSetupModal-DE5-gEtI.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-6UMARucA.js +1 -0
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +2 -0
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +2 -0
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +20 -0
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +20 -0
- package/web/dist/assets/TerminalPanel-CTp_BZ4S.js +3 -0
- package/web/dist/assets/TerminalPanel-CkYxC-Gh.js +3 -0
- package/web/dist/assets/TuiOverlayModal-1cRLP8IF.js +1 -0
- package/web/dist/assets/TuiOverlayModal-2xlptqWX.js +1 -0
- package/web/dist/assets/app-globals-DZNa9v8u.js +325 -0
- package/web/dist/assets/canvas-client-Bye9nSFO.js +1 -0
- package/web/dist/assets/{desktop-YguLbrX1.js → desktop-kjBoE3Nu.js} +1 -1
- package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
- package/web/dist/assets/index-CsFs_HMb.css +1 -0
- package/web/dist/assets/index-DHeeHS_l.js +85 -0
- package/web/dist/assets/index-DTZch8uz.js +85 -0
- package/web/dist/assets/plugin-host-C8mNgghx.js +1 -0
- package/web/dist/assets/remote-ssh-client-CeP3CLUW.js +1 -0
- package/web/dist/assets/theme-BXGpyTMh.js +1 -0
- package/web/dist/index.html +10 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/BgTasksModal-BIlQ89vr.js +0 -1
- package/web/dist/assets/BgTasksModal-Ck2sjlPM.js +0 -1
- package/web/dist/assets/DeviceCenter-BQdDcO8A.js +0 -3
- package/web/dist/assets/DeviceCenter-CHRKL0Vy.js +0 -3
- package/web/dist/assets/DeviceGroups-D2rogxEN.js +0 -1
- package/web/dist/assets/Dropdown-ZLS04O8p.js +0 -1
- package/web/dist/assets/FilePreview-B9xoU6ON.js +0 -2
- package/web/dist/assets/FilePreview-DUQpVZkH.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BXEGvUZq.js +0 -1
- package/web/dist/assets/GlobalSearchModal-CnVPmfOI.js +0 -1
- package/web/dist/assets/GroupConversation-CyIpQzDd.js +0 -1
- package/web/dist/assets/GroupConversation-DgYV3uYS.js +0 -1
- package/web/dist/assets/ModelConfigModal-DDZccDYt.js +0 -2
- package/web/dist/assets/PiSetupModal-DHbqfx8T.js +0 -1
- package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +0 -1
- package/web/dist/assets/SCMPanel-imYI2Ecw.js +0 -2
- package/web/dist/assets/SCMPanel-sVZcV7dR.js +0 -2
- package/web/dist/assets/SettingsModal-Xw1Yoi3_.js +0 -20
- package/web/dist/assets/SettingsModal-mb4e34-0.js +0 -20
- package/web/dist/assets/TerminalPanel-CLkJJvxg.js +0 -3
- package/web/dist/assets/TerminalPanel-DpcIellm.js +0 -3
- package/web/dist/assets/TuiOverlayModal-4-fFAZe7.js +0 -1
- package/web/dist/assets/TuiOverlayModal-DCu01lks.js +0 -1
- package/web/dist/assets/app-globals-DcyO0UPi.js +0 -1
- package/web/dist/assets/fi-DaSO0Q-m.js +0 -325
- package/web/dist/assets/index-Cdh3sibd.js +0 -85
- package/web/dist/assets/index-DDZMv6LO.css +0 -1
- package/web/dist/assets/index-DWw_SxRq.js +0 -85
- package/web/dist/assets/plugin-host-BRBg6zmQ.js +0 -1
- package/web/dist/assets/theme-DDl-Oy1b.js +0 -1
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { approvalOperationSummary } from "./approval-summary.js";
|
|
3
|
+
export const INTERACTION_LIMITS = { count: 8, bytes: 24576, answerBytes: 16384 };
|
|
4
|
+
const size = (value) => {
|
|
5
|
+
try {
|
|
6
|
+
return Buffer.byteLength(JSON.stringify(value));
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return Infinity;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function validQuestions(value) {
|
|
13
|
+
if (!Array.isArray(value) || value.length < 1 || value.length > 3)
|
|
14
|
+
return false;
|
|
15
|
+
const ids = new Set();
|
|
16
|
+
const validOptions = (v) => Array.isArray(v) &&
|
|
17
|
+
v.length <= 32 &&
|
|
18
|
+
v.every((o) => record(o) &&
|
|
19
|
+
typeof o.label === "string" &&
|
|
20
|
+
o.label.length <= 1000 &&
|
|
21
|
+
[o.description, o.preview].every((s) => s === undefined || typeof s === "string") &&
|
|
22
|
+
(o.recommended === undefined || typeof o.recommended === "boolean"));
|
|
23
|
+
return value.every((q) => {
|
|
24
|
+
if (!record(q) ||
|
|
25
|
+
typeof q.id !== "string" ||
|
|
26
|
+
!q.id ||
|
|
27
|
+
ids.has(q.id) ||
|
|
28
|
+
typeof q.question !== "string" ||
|
|
29
|
+
[q.detail, q.header].some((s) => s !== undefined && typeof s !== "string") ||
|
|
30
|
+
(q.multiSelect !== undefined && typeof q.multiSelect !== "boolean") ||
|
|
31
|
+
(q.options !== undefined && !validOptions(q.options)))
|
|
32
|
+
return false;
|
|
33
|
+
if (q.dependsOn &&
|
|
34
|
+
(!record(q.dependsOn) ||
|
|
35
|
+
!ids.has(q.dependsOn.questionId) ||
|
|
36
|
+
(q.dependsOn.value !== undefined &&
|
|
37
|
+
typeof q.dependsOn.value !== "string" &&
|
|
38
|
+
!(Array.isArray(q.dependsOn.value) && q.dependsOn.value.every((s) => typeof s === "string")))))
|
|
39
|
+
return false;
|
|
40
|
+
if (q.optionsMap &&
|
|
41
|
+
(!record(q.optionsMap) ||
|
|
42
|
+
Object.keys(q.optionsMap).length > 32 ||
|
|
43
|
+
!Object.values(q.optionsMap).every(validOptions)))
|
|
44
|
+
return false;
|
|
45
|
+
ids.add(q.id);
|
|
46
|
+
return true;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const record = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
50
|
+
export function validInteractionAnswer(value) {
|
|
51
|
+
if (!record(value) ||
|
|
52
|
+
size(value) > INTERACTION_LIMITS.answerBytes ||
|
|
53
|
+
Object.keys(value).some((k) => !["taskId", "attemptId", "interactionId", "answers", "cancelled", "decision"].includes(k)))
|
|
54
|
+
return false;
|
|
55
|
+
if ([value.taskId, value.attemptId, value.interactionId].some((v) => typeof v !== "string" || !v || v.length > 128))
|
|
56
|
+
return false;
|
|
57
|
+
if (value.decision !== undefined)
|
|
58
|
+
return ["approve", "deny"].includes(value.decision) && value.answers === undefined && value.cancelled === undefined;
|
|
59
|
+
return ((value.cancelled === undefined || typeof value.cancelled === "boolean") &&
|
|
60
|
+
Array.isArray(value.answers) &&
|
|
61
|
+
value.answers.length <= 3 &&
|
|
62
|
+
value.answers.every((a) => record(a) &&
|
|
63
|
+
Object.keys(a).every((k) => ["id", "selected", "custom"].includes(k)) &&
|
|
64
|
+
typeof a.id === "string" &&
|
|
65
|
+
Array.isArray(a.selected) &&
|
|
66
|
+
a.selected.length <= 32 &&
|
|
67
|
+
a.selected.every((s) => typeof s === "string") &&
|
|
68
|
+
(a.custom === undefined || typeof a.custom === "string")));
|
|
69
|
+
}
|
|
70
|
+
export function validInteractionProjection(value, binding) {
|
|
71
|
+
return (Array.isArray(value) &&
|
|
72
|
+
value.length <= INTERACTION_LIMITS.count &&
|
|
73
|
+
size(value) <= INTERACTION_LIMITS.bytes &&
|
|
74
|
+
new Set(value.map((v) => (record(v) ? v.id : undefined))).size === value.length &&
|
|
75
|
+
value.every((v) => record(v) &&
|
|
76
|
+
Object.entries(binding).every(([k, x]) => v[k] === x) &&
|
|
77
|
+
typeof v.id === "string" &&
|
|
78
|
+
v.id.length <= 128 &&
|
|
79
|
+
Number.isFinite(v.createdAt) &&
|
|
80
|
+
(v.deadline === undefined || Number.isFinite(v.deadline)) &&
|
|
81
|
+
Object.keys(v).every((k) => [
|
|
82
|
+
"taskId",
|
|
83
|
+
"attemptId",
|
|
84
|
+
"roomId",
|
|
85
|
+
"botId",
|
|
86
|
+
"deviceId",
|
|
87
|
+
"id",
|
|
88
|
+
"kind",
|
|
89
|
+
"createdAt",
|
|
90
|
+
"deadline",
|
|
91
|
+
"questions",
|
|
92
|
+
"toolName",
|
|
93
|
+
"paramsPreview",
|
|
94
|
+
"reason",
|
|
95
|
+
].includes(k)) &&
|
|
96
|
+
(v.kind === "question"
|
|
97
|
+
? validQuestions(v.questions)
|
|
98
|
+
: v.kind === "approval" && typeof v.toolName === "string" && typeof v.paramsPreview === "string")));
|
|
99
|
+
}
|
|
100
|
+
/** Holds native IDs locally. Neither Hub nor browser can supply a native WS frame. */
|
|
101
|
+
export function createHumanInteractionBridge(binding, options) {
|
|
102
|
+
const pending = new Map();
|
|
103
|
+
const consumed = new Set();
|
|
104
|
+
let closed = false;
|
|
105
|
+
const publish = () => options.publish(structuredClone([...pending.values()].map((v) => v.item)));
|
|
106
|
+
const remove = (nativeId) => {
|
|
107
|
+
for (const [id, v] of pending)
|
|
108
|
+
if (v.nativeId === nativeId)
|
|
109
|
+
pending.delete(id);
|
|
110
|
+
};
|
|
111
|
+
function observe(message) {
|
|
112
|
+
if (closed || !options.isCurrent())
|
|
113
|
+
return;
|
|
114
|
+
if (message.type === "question_retracted" || message.type === "tool_approval_resolved") {
|
|
115
|
+
if (message.owner || message.global)
|
|
116
|
+
return;
|
|
117
|
+
remove(message.id);
|
|
118
|
+
publish();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (message.type !== "question_pending" && message.type !== "tool_approval_pending")
|
|
122
|
+
return;
|
|
123
|
+
// Missing conversation/foreign owner/global asks must stay local.
|
|
124
|
+
if (message.conversationId !== options.conversationId || message.global || message.owner)
|
|
125
|
+
return;
|
|
126
|
+
const kind = message.type === "question_pending" ? "question" : "approval";
|
|
127
|
+
if (consumed.has(`${kind}:${message.id}`))
|
|
128
|
+
return;
|
|
129
|
+
// Stop projection after the per-execution consumption budget instead of forgetting tombstones.
|
|
130
|
+
if (consumed.size >= 256)
|
|
131
|
+
return;
|
|
132
|
+
if ([...pending.values()].some((v) => v.nativeId === message.id && v.item.kind === kind))
|
|
133
|
+
return;
|
|
134
|
+
const item = {
|
|
135
|
+
...binding,
|
|
136
|
+
id: randomUUID(),
|
|
137
|
+
kind,
|
|
138
|
+
createdAt: Date.now(),
|
|
139
|
+
...(message.type === "question_pending"
|
|
140
|
+
? { questions: structuredClone(message.questions), ...(message.deadline ? { deadline: message.deadline } : {}) }
|
|
141
|
+
: {
|
|
142
|
+
toolName: message.toolName,
|
|
143
|
+
paramsPreview: approvalOperationSummary(message.toolName, message.params),
|
|
144
|
+
reason: "",
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
const next = [...pending.values()].map((v) => v.item).concat(item);
|
|
148
|
+
if (!validInteractionProjection(next, binding))
|
|
149
|
+
return;
|
|
150
|
+
pending.set(item.id, { nativeId: message.id, item });
|
|
151
|
+
publish();
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
observe,
|
|
155
|
+
snapshot(state) {
|
|
156
|
+
if (closed || state.conversationId !== options.conversationId || !options.isCurrent())
|
|
157
|
+
return;
|
|
158
|
+
const entries = [state.pendingQuestion, ...(state.pendingApprovals ?? []), state.pendingApproval].filter(Boolean);
|
|
159
|
+
const ids = new Set(entries.map((v) => v.id));
|
|
160
|
+
for (const [id, v] of pending)
|
|
161
|
+
if (!ids.has(v.nativeId))
|
|
162
|
+
pending.delete(id);
|
|
163
|
+
if (state.pendingQuestion)
|
|
164
|
+
observe({ type: "question_pending", ...state.pendingQuestion });
|
|
165
|
+
for (const v of [...(state.pendingApprovals ?? []), state.pendingApproval])
|
|
166
|
+
if (v)
|
|
167
|
+
observe({ type: "tool_approval_pending", ...v });
|
|
168
|
+
publish();
|
|
169
|
+
},
|
|
170
|
+
answer(value) {
|
|
171
|
+
if (closed ||
|
|
172
|
+
!options.isCurrent() ||
|
|
173
|
+
!validInteractionAnswer(value) ||
|
|
174
|
+
value.taskId !== binding.taskId ||
|
|
175
|
+
value.attemptId !== binding.attemptId)
|
|
176
|
+
return false;
|
|
177
|
+
const v = pending.get(value.interactionId);
|
|
178
|
+
if (!v || (v.item.deadline !== undefined && v.item.deadline <= Date.now()))
|
|
179
|
+
return false;
|
|
180
|
+
if (v.item.kind === "question" && !value.cancelled) {
|
|
181
|
+
const answers = value.answers ?? [];
|
|
182
|
+
const visible = v.item.questions.filter((q) => !q.dependsOn ||
|
|
183
|
+
answers.some((a) => a.id === q.dependsOn.questionId &&
|
|
184
|
+
(a.selected.length || a.custom?.trim()) &&
|
|
185
|
+
(q.dependsOn.value === undefined ||
|
|
186
|
+
[q.dependsOn.value].flat().some((label) => a.selected.includes(label)))));
|
|
187
|
+
if (answers.length !== visible.length ||
|
|
188
|
+
visible.some((q) => {
|
|
189
|
+
const a = answers.find((a) => a.id === q.id);
|
|
190
|
+
if (!a || (!a.selected.length && !a.custom?.trim()) || (!q.multiSelect && a.selected.length > 1))
|
|
191
|
+
return true;
|
|
192
|
+
const source = q.dependsOn && q.optionsMap
|
|
193
|
+
? (q.optionsMap[answers.find((a) => a.id === q.dependsOn.questionId)?.selected[0] ?? ""] ?? q.options)
|
|
194
|
+
: q.options;
|
|
195
|
+
return a.selected.some((label) => !source?.some((o) => o.label === label));
|
|
196
|
+
}))
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
let frame;
|
|
200
|
+
if (v.item.kind === "approval") {
|
|
201
|
+
if (!value.decision)
|
|
202
|
+
return false;
|
|
203
|
+
frame = { type: "tool_approval_response", id: v.nativeId, decision: value.decision, scope: "once" };
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
if (value.decision ||
|
|
207
|
+
!value.answers ||
|
|
208
|
+
new Set(value.answers.map((a) => a.id)).size !== value.answers.length ||
|
|
209
|
+
value.answers.some((a) => !v.item.questions?.some((q) => q.id === a.id)))
|
|
210
|
+
return false;
|
|
211
|
+
frame = {
|
|
212
|
+
type: "question_answer",
|
|
213
|
+
id: v.nativeId,
|
|
214
|
+
answers: structuredClone(value.answers),
|
|
215
|
+
...(value.cancelled ? { cancelled: true } : {}),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
consumed.add(`${v.item.kind}:${v.nativeId}`);
|
|
219
|
+
pending.delete(value.interactionId); // Consume before calling send: duplicate/reentrant answers fail closed.
|
|
220
|
+
options.send(frame);
|
|
221
|
+
publish();
|
|
222
|
+
return true;
|
|
223
|
+
},
|
|
224
|
+
close() {
|
|
225
|
+
if (closed)
|
|
226
|
+
return;
|
|
227
|
+
closed = true;
|
|
228
|
+
pending.clear();
|
|
229
|
+
publish();
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Only these fixed integration failures may cross the device RPC boundary.
|
|
2
|
+
// Raw Git stderr, paths, command lines and arbitrary error messages stay local.
|
|
3
|
+
const integrationErrors = {
|
|
4
|
+
INTEGRATION_TARGET_CHECKED_OUT: {
|
|
5
|
+
status: 409,
|
|
6
|
+
message: "Target branch is currently checked out in a worktree; please switch away from target branch before applying integration",
|
|
7
|
+
},
|
|
8
|
+
INTEGRATION_TARGET_MOVED: {
|
|
9
|
+
status: 409,
|
|
10
|
+
message: "Target branch moved from the prepared SHA; prepare a new integration against its current SHA",
|
|
11
|
+
},
|
|
12
|
+
INTEGRATION_CUSTOM_DRIVER: {
|
|
13
|
+
status: 422,
|
|
14
|
+
message: "Custom filter/merge driver is forbidden for isolated integration; remove external driver configuration before preparing again",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export function integrationError(code) {
|
|
18
|
+
const { status, message } = integrationErrors[code];
|
|
19
|
+
return Object.assign(new Error(message), { code, status });
|
|
20
|
+
}
|
|
21
|
+
export function integrationErrorFromCode(code) {
|
|
22
|
+
if (typeof code !== "string" || !Object.hasOwn(integrationErrors, code))
|
|
23
|
+
return undefined;
|
|
24
|
+
return integrationError(code);
|
|
25
|
+
}
|
|
@@ -4,6 +4,7 @@ import { hostname } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { createDeviceHub } from "./hub.js";
|
|
6
6
|
import { createDeviceRelay } from "./relay.js";
|
|
7
|
+
import { installDeviceTransfers } from "./transfers.js";
|
|
7
8
|
import { hashSecret } from "./store.js";
|
|
8
9
|
/** Private loopback Hub: uses the same authenticated Bot, room and task paths as a remote Hub. */
|
|
9
10
|
export async function createLocalDeviceHub(dataDir) {
|
|
@@ -56,14 +57,30 @@ export async function createLocalDeviceHub(dataDir) {
|
|
|
56
57
|
getAccount: hub.getRelayAccount,
|
|
57
58
|
authenticateDevice: (id, token) => hub.store.authenticateDevice(id, token),
|
|
58
59
|
ownsDevice: (owner, id) => hub.store.getDeviceOwner(id) === owner,
|
|
60
|
+
getDeviceName: (id) => hub.store.getDevice(id)?.name,
|
|
61
|
+
onTaskProgress: (id, event) => hub.acceptTaskProgress(id, event),
|
|
62
|
+
onTaskToolLifecycle: (id, frame) => hub.acceptTaskToolLifecycle(id, frame),
|
|
63
|
+
onTaskPlanReady: (id, frame) => hub.acceptTaskPlanReady(id, frame),
|
|
64
|
+
onTaskInteractions: (id, event) => hub.acceptInteractions(id, event),
|
|
59
65
|
onTaskEvent: async (id, event) => {
|
|
60
66
|
await hub.acceptTaskEvent(id, event);
|
|
61
67
|
},
|
|
68
|
+
onTaskClaim: (id, claim) => hub.claimTask(id, claim),
|
|
69
|
+
onTaskLeaseRenew: (id, renew) => hub.renewTaskLease(id, renew),
|
|
70
|
+
onTaskDisconnect: (id, taskId, attemptId) => hub.onTaskDisconnect(id, taskId, attemptId),
|
|
62
71
|
});
|
|
63
72
|
hub.setRelay({
|
|
64
73
|
onTask: relay.sendTask,
|
|
74
|
+
answerInteraction: relay.answerInteraction,
|
|
65
75
|
onRevoke: relay.revoke,
|
|
66
76
|
handleRequest: relay.handleRequest,
|
|
77
|
+
callDevice: relay.callDevice,
|
|
78
|
+
});
|
|
79
|
+
const transfers = await installDeviceTransfers({
|
|
80
|
+
app: hub.app,
|
|
81
|
+
hub,
|
|
82
|
+
dataDir: join(dataDir, "local-device-hub"),
|
|
83
|
+
relay,
|
|
67
84
|
});
|
|
68
85
|
const config = {
|
|
69
86
|
hubUrl,
|
|
@@ -76,6 +93,7 @@ export async function createLocalDeviceHub(dataDir) {
|
|
|
76
93
|
return {
|
|
77
94
|
config,
|
|
78
95
|
async close() {
|
|
96
|
+
await transfers.close();
|
|
79
97
|
relay?.close();
|
|
80
98
|
await hub?.close();
|
|
81
99
|
},
|