pi-web-ui 0.115.0 → 0.117.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 +65 -2
- package/bin/device-hub-cli.mjs +26 -3
- package/bin/pi-web-ui.mjs +159 -71
- package/dist/server/agent-service-daemon.js +136 -8
- package/dist/server/agent-service.js +594 -159
- package/dist/server/canvas/canvas-workspace.js +18 -86
- package/dist/server/client-state.js +52 -8
- package/dist/server/compaction-markers.js +43 -24
- package/dist/server/dangling-tools.js +172 -16
- package/dist/server/device-center/bot-execution.js +77 -2
- package/dist/server/device-center/collab-service.js +61 -12
- package/dist/server/device-center/collab-tool.js +482 -21
- package/dist/server/device-center/connector.js +107 -37
- package/dist/server/device-center/delivery-authority.js +98 -0
- package/dist/server/device-center/delivery-subject.js +30 -0
- package/dist/server/device-center/device-integration.js +453 -183
- package/dist/server/device-center/execution-guides.js +17 -7
- package/dist/server/device-center/execution-instructions.js +2 -1
- package/dist/server/device-center/execution-settings.js +138 -25
- package/dist/server/device-center/executor.js +51 -6
- package/dist/server/device-center/file-sync.js +14 -13
- package/dist/server/device-center/group-context-message.js +3 -1
- package/dist/server/device-center/group-context.js +73 -3
- package/dist/server/device-center/hub-conversations.js +71 -6
- package/dist/server/device-center/hub-deliveries.js +120 -15
- package/dist/server/device-center/hub-integration.js +655 -334
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +16 -35
- package/dist/server/device-center/hub-setup.js +23 -1
- package/dist/server/device-center/hub-transaction-log.js +197 -0
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +1531 -305
- package/dist/server/device-center/integration-verification.js +113 -0
- package/dist/server/device-center/local-hub.js +8 -3
- package/dist/server/device-center/local-publication.js +423 -0
- package/dist/server/device-center/local-verification-job.js +97 -0
- package/dist/server/device-center/local-verification.js +274 -0
- package/dist/server/device-center/local.js +181 -13
- package/dist/server/device-center/main.js +4 -1
- package/dist/server/device-center/partition-log.js +330 -0
- package/dist/server/device-center/publication-journal.js +312 -0
- package/dist/server/device-center/publish-intent.js +379 -0
- package/dist/server/device-center/relay.js +134 -24
- package/dist/server/device-center/runtime.js +475 -42
- package/dist/server/device-center/store.js +366 -89
- package/dist/server/device-center/task-outcome.js +81 -0
- package/dist/server/device-center/task-recovery.js +603 -178
- package/dist/server/device-center/task-scheduler.js +48 -3
- package/dist/server/device-center/task-settlement.js +353 -0
- package/dist/server/device-center/task-workspace.js +443 -0
- package/dist/server/device-center/transfers.js +41 -15
- package/dist/server/device-center/verification-limits.js +10 -0
- package/dist/server/device-center/work-contract.js +995 -0
- package/dist/server/dispatch-domain-handlers.js +29 -3
- package/dist/server/dsh/dsh-agent-service.js +9 -2
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/index.js +159 -17
- package/dist/server/managed.js +2 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/patch-node-pty.js +3 -2
- package/dist/server/patch-remote-catalog.js +3 -2
- package/dist/server/plugins.js +64 -7
- package/dist/server/preset-fields.js +17 -1
- package/dist/server/preset-share.js +1 -0
- package/dist/server/prompt-composer.js +39 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/quick-ask-settings.js +28 -0
- package/dist/server/quick-ask.js +164 -0
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/resolve-global-sdk.js +61 -11
- package/dist/server/scheduler-tasks.js +35 -8
- package/dist/server/session-list-scan.js +223 -0
- package/dist/server/session-open.js +93 -0
- package/dist/server/session-parser.js +4 -0
- package/dist/server/session-scan.js +90 -38
- package/dist/server/settings-service.js +9 -1
- package/dist/server/soft-cap.js +5 -0
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagents.js +2 -1
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/transcript-prepare.js +73 -0
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/universal/drivers/claude-code.js +98 -34
- package/dist/server/universal/universal-session.js +4 -0
- package/dist/server/workspace-handle.js +428 -0
- package/docs/architecture-plugins.md +959 -0
- package/docs/device-center.md +34 -20
- package/package.json +4 -4
- package/plugin-sdk/README.md +16 -8
- package/plugin-sdk/client.d.ts +27 -0
- package/plugin-sdk/client.mjs +82 -0
- package/plugin-sdk/index.d.ts +10 -0
- package/plugin-sdk/index.mjs +4 -683
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/testing.d.ts +10 -0
- package/plugin-sdk/testing.mjs +566 -0
- package/themes/flow-cristallo.css +168 -0
- package/themes/flow-ink.css +169 -0
- package/themes/flow-obsidian.css +169 -0
- package/themes/flow-zurich.css +169 -0
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BYzPgmoq.js → BgTasksModal-BjNRIUIc.js} +1 -1
- package/web/dist/assets/{BgTasksModal-ni0VTmAQ.js → BgTasksModal-C0zuU8FE.js} +1 -1
- package/web/dist/assets/{CanvasStudio-DNmDNBod.js → CanvasStudio-BWvdmJ0M.js} +3 -3
- package/web/dist/assets/{CanvasStudio-BCUeEf25.js → CanvasStudio-VQFjmTGq.js} +3 -3
- package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
- package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +1 -0
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
- package/web/dist/assets/{Dropdown-CGXD0DfT.js → Dropdown-CQtstPGv.js} +1 -1
- package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
- package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
- package/web/dist/assets/{GlobalSearchModal-mevF-ySi.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-qL99FN_F.js → GlobalSearchModal-DGv_WINq.js} +1 -1
- package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
- package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
- package/web/dist/assets/{HintTip-LHwkS2jV.js → HintTip-ChTW8o1m.js} +1 -1
- package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
- package/web/dist/assets/{PiSetupModal-DE5-gEtI.js → PiSetupModal-BX5rUuoI.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-6UMARucA.js → ProviderOAuthControls-DY4SCfXg.js} +1 -1
- package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
- package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
- package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
- package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
- package/web/dist/assets/{TerminalPanel-CTp_BZ4S.js → TerminalPanel-D4By_RVc.js} +2 -2
- package/web/dist/assets/{TerminalPanel-CkYxC-Gh.js → TerminalPanel-lZw8-i3j.js} +2 -2
- package/web/dist/assets/{TuiOverlayModal-1cRLP8IF.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-2xlptqWX.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
- package/web/dist/assets/{canvas-client-Bye9nSFO.js → canvas-client-BY6ojmle.js} +1 -1
- package/web/dist/assets/{desktop-kjBoE3Nu.js → desktop-CV6KKp9R.js} +1 -1
- package/web/dist/assets/index-BawF7ZP5.js +397 -0
- package/web/dist/assets/index-BoGCoq5X.js +397 -0
- package/web/dist/assets/index-CVW9FoY2.css +1 -0
- package/web/dist/assets/{plugin-host-C8mNgghx.js → plugin-host-Dn8Dd6SC.js} +1 -1
- package/web/dist/assets/{remote-ssh-client-CeP3CLUW.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
- package/web/dist/assets/{theme-BXGpyTMh.js → theme-D_bihpdN.js} +1 -1
- package/web/dist/index.html +11 -11
- package/web/dist/sw.js +1 -1
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +0 -3
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +0 -3
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +0 -1
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +0 -1
- package/web/dist/assets/FilePreview-B8iqnBjy.js +0 -2
- package/web/dist/assets/FilePreview-BqviZKCN.js +0 -2
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +0 -3
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +0 -3
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +0 -2
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +0 -2
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +0 -2
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +0 -20
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +0 -20
- package/web/dist/assets/app-globals-DZNa9v8u.js +0 -325
- package/web/dist/assets/index-CsFs_HMb.css +0 -1
- package/web/dist/assets/index-DHeeHS_l.js +0 -85
- package/web/dist/assets/index-DTZch8uz.js +0 -85
|
@@ -31,6 +31,25 @@ export function createDeviceConnector(options) {
|
|
|
31
31
|
const waitingForHumanTaskIds = new Set();
|
|
32
32
|
const planAcks = new Map();
|
|
33
33
|
const runningTasks = new Map();
|
|
34
|
+
function sendOutboxEntry(ws, item) {
|
|
35
|
+
options.recovery?.markOutboxAttempt(item.id);
|
|
36
|
+
sendFrame(ws, {
|
|
37
|
+
type: "task_event",
|
|
38
|
+
taskId: item.taskId,
|
|
39
|
+
botId: item.botId,
|
|
40
|
+
attemptId: item.attemptId,
|
|
41
|
+
status: item.status,
|
|
42
|
+
report: item.report,
|
|
43
|
+
error: item.error,
|
|
44
|
+
reportMetadata: item.reportMetadata,
|
|
45
|
+
leaseToken: item.leaseToken,
|
|
46
|
+
leaseGeneration: item.leaseGeneration,
|
|
47
|
+
fingerprint: item.fingerprint,
|
|
48
|
+
artifact: item.artifact,
|
|
49
|
+
executionCompleted: item.executionCompleted,
|
|
50
|
+
artifactProduced: item.artifactProduced,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
34
53
|
function stopTasks(forceAll = false) {
|
|
35
54
|
for (const pending of planAcks.values())
|
|
36
55
|
pending.settle(false);
|
|
@@ -143,6 +162,7 @@ export function createDeviceConnector(options) {
|
|
|
143
162
|
const rpc = createCommandChannel(ws, options.onCommand);
|
|
144
163
|
const messages = createWsMessageChannel(ws);
|
|
145
164
|
const cancellations = new Set();
|
|
165
|
+
const steerings = new Set();
|
|
146
166
|
ws.on("open", () => {
|
|
147
167
|
if (socket !== ws || closed) {
|
|
148
168
|
ws.terminate();
|
|
@@ -181,20 +201,8 @@ export function createDeviceConnector(options) {
|
|
|
181
201
|
});
|
|
182
202
|
}
|
|
183
203
|
if (options.recovery) {
|
|
184
|
-
for (const item of options.recovery.getPendingOutbox())
|
|
185
|
-
|
|
186
|
-
sendFrame(ws, {
|
|
187
|
-
type: "task_event",
|
|
188
|
-
taskId: item.taskId,
|
|
189
|
-
botId: item.botId,
|
|
190
|
-
attemptId: item.attemptId,
|
|
191
|
-
status: item.status,
|
|
192
|
-
...(item.report ? { report: item.report } : {}),
|
|
193
|
-
...(item.error ? { error: item.error } : {}),
|
|
194
|
-
...(item.reportMetadata ? { reportMetadata: item.reportMetadata } : {}),
|
|
195
|
-
...(item.fingerprint ? { fingerprint: item.fingerprint } : {}),
|
|
196
|
-
});
|
|
197
|
-
}
|
|
204
|
+
for (const item of options.recovery.getPendingOutbox())
|
|
205
|
+
sendOutboxEntry(ws, item);
|
|
198
206
|
}
|
|
199
207
|
// =======================================================
|
|
200
208
|
void Promise.resolve()
|
|
@@ -242,9 +250,31 @@ export function createDeviceConnector(options) {
|
|
|
242
250
|
return;
|
|
243
251
|
}
|
|
244
252
|
if (frame.type === "task_result_ack") {
|
|
245
|
-
if (
|
|
253
|
+
if ([frame.fingerprint, frame.artifactDigest, frame.contractDigest, frame.manifestDigest].some((value) => value !== undefined && typeof value !== "string"))
|
|
254
|
+
return;
|
|
255
|
+
const pending = typeof frame.taskId === "string" && typeof frame.attemptId === "string"
|
|
256
|
+
? options.recovery?.getPendingOutboxEntry(frame.taskId, frame.attemptId)
|
|
257
|
+
: undefined;
|
|
258
|
+
if ((frame.contractDigest !== undefined && frame.contractDigest !== pending?.contractDigest) ||
|
|
259
|
+
(frame.manifestDigest !== undefined && frame.manifestDigest !== pending?.manifestDigest))
|
|
260
|
+
return;
|
|
261
|
+
if (frame.accepted === false &&
|
|
262
|
+
frame.permanent === true &&
|
|
263
|
+
typeof frame.taskId === "string" &&
|
|
264
|
+
typeof frame.attemptId === "string") {
|
|
265
|
+
options.recovery?.quarantineOutbox(frame.taskId, frame.attemptId, frame.fingerprint, frame.reasonCode, frame.status, frame.artifactDigest);
|
|
266
|
+
}
|
|
267
|
+
if (frame.accepted === true &&
|
|
268
|
+
typeof frame.taskId === "string" &&
|
|
269
|
+
typeof frame.attemptId === "string" &&
|
|
270
|
+
typeof frame.status === "string") {
|
|
246
271
|
const fp = typeof frame.fingerprint === "string" ? frame.fingerprint : undefined;
|
|
247
|
-
options.recovery?.ackOutbox(frame.taskId, frame.attemptId, fp
|
|
272
|
+
options.recovery?.ackOutbox(frame.taskId, frame.attemptId, fp, {
|
|
273
|
+
status: frame.status,
|
|
274
|
+
artifactDigest: typeof frame.artifactDigest === "string" ? frame.artifactDigest : undefined,
|
|
275
|
+
contractDigest: typeof frame.contractDigest === "string" ? frame.contractDigest : undefined,
|
|
276
|
+
manifestDigest: typeof frame.manifestDigest === "string" ? frame.manifestDigest : undefined,
|
|
277
|
+
});
|
|
248
278
|
}
|
|
249
279
|
return;
|
|
250
280
|
}
|
|
@@ -277,6 +307,38 @@ export function createDeviceConnector(options) {
|
|
|
277
307
|
});
|
|
278
308
|
return;
|
|
279
309
|
}
|
|
310
|
+
if (frame.type === "task_steer") {
|
|
311
|
+
if (typeof frame.id !== "string" ||
|
|
312
|
+
!frame.id ||
|
|
313
|
+
frame.id.length > 128 ||
|
|
314
|
+
typeof frame.taskId !== "string" ||
|
|
315
|
+
typeof frame.attemptId !== "string" ||
|
|
316
|
+
typeof frame.text !== "string" ||
|
|
317
|
+
steerings.size >= RELAY_LIMITS.steerings ||
|
|
318
|
+
steerings.has(frame.id))
|
|
319
|
+
throw new Error("Invalid task steer");
|
|
320
|
+
const id = frame.id;
|
|
321
|
+
const taskId = frame.taskId;
|
|
322
|
+
const text = frame.text;
|
|
323
|
+
const task = runningTasks.get(taskId);
|
|
324
|
+
const matched = task?.ws === ws && task.attemptId === frame.attemptId;
|
|
325
|
+
steerings.add(id);
|
|
326
|
+
void Promise.resolve()
|
|
327
|
+
.then(() => (matched && options.onSteer ? options.onSteer(taskId, text) : false))
|
|
328
|
+
.catch(() => false)
|
|
329
|
+
.then((steered) => {
|
|
330
|
+
steerings.delete(id);
|
|
331
|
+
if (socket === ws && !closed)
|
|
332
|
+
sendFrame(ws, {
|
|
333
|
+
type: "task_steered",
|
|
334
|
+
id,
|
|
335
|
+
taskId,
|
|
336
|
+
attemptId: frame.attemptId,
|
|
337
|
+
steered: Boolean(steered),
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
280
342
|
if (frame.type === "task_interaction_answer") {
|
|
281
343
|
if (!validInteractionAnswer(frame.answer))
|
|
282
344
|
return;
|
|
@@ -354,27 +416,32 @@ export function createDeviceConnector(options) {
|
|
|
354
416
|
};
|
|
355
417
|
const emit = (status, report) => {
|
|
356
418
|
const activeWs = execution.ws;
|
|
357
|
-
if (activeWs
|
|
358
|
-
activeWs.readyState
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
taskId: task.id,
|
|
368
|
-
botId: task.botId,
|
|
369
|
-
attemptId: task.attemptId,
|
|
370
|
-
status,
|
|
371
|
-
...(report ? { report } : {}),
|
|
372
|
-
...(status !== "running"
|
|
373
|
-
? { reportMetadata: reportUploadMetadata(options.reportOutbox?.get(task)) }
|
|
374
|
-
: {}),
|
|
375
|
-
...(outboxItem?.fingerprint ? { fingerprint: outboxItem.fingerprint } : {}),
|
|
376
|
-
});
|
|
419
|
+
if (!activeWs ||
|
|
420
|
+
activeWs.readyState !== WebSocket.OPEN ||
|
|
421
|
+
closed ||
|
|
422
|
+
runningTasks.get(task.id) !== execution)
|
|
423
|
+
return;
|
|
424
|
+
if (status !== "running" && options.recovery) {
|
|
425
|
+
const item = options.recovery.getPendingOutboxEntry(task.id, task.attemptId);
|
|
426
|
+
if (item)
|
|
427
|
+
sendOutboxEntry(activeWs, item);
|
|
428
|
+
return;
|
|
377
429
|
}
|
|
430
|
+
if (controller.signal.aborted)
|
|
431
|
+
return;
|
|
432
|
+
sendFrame(activeWs, {
|
|
433
|
+
type: "task_event",
|
|
434
|
+
taskId: task.id,
|
|
435
|
+
botId: task.botId,
|
|
436
|
+
attemptId: task.attemptId,
|
|
437
|
+
leaseToken: task.leaseToken,
|
|
438
|
+
leaseGeneration: task.leaseGeneration,
|
|
439
|
+
status,
|
|
440
|
+
...(report ? { report } : {}),
|
|
441
|
+
...(status !== "running"
|
|
442
|
+
? { reportMetadata: reportUploadMetadata(options.reportOutbox?.get(task)) }
|
|
443
|
+
: {}),
|
|
444
|
+
});
|
|
378
445
|
};
|
|
379
446
|
emit("running");
|
|
380
447
|
execution.settled = Promise.resolve()
|
|
@@ -467,8 +534,11 @@ export function createDeviceConnector(options) {
|
|
|
467
534
|
});
|
|
468
535
|
})
|
|
469
536
|
.then(async (result) => {
|
|
470
|
-
if (
|
|
537
|
+
if (options.recovery) {
|
|
538
|
+
emit("completed");
|
|
539
|
+
retryReports();
|
|
471
540
|
return;
|
|
541
|
+
}
|
|
472
542
|
const safeReport = typeof result === "string" ? result : undefined;
|
|
473
543
|
const reportEntry = options.reportOutbox?.get(task) ?? options.reportOutbox?.markMissing(task);
|
|
474
544
|
if (reportEntry)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { artifactRefsMatch } from "./delivery-subject.js";
|
|
2
|
+
import { validateCodeArtifactOutcome, validateContextManifest, validateWorkContract } from "./work-contract.js";
|
|
3
|
+
function conflict(message) {
|
|
4
|
+
throw Object.assign(new Error(message), { status: 409 });
|
|
5
|
+
}
|
|
6
|
+
/** Contract authority spans conversations within its owning account and room. */
|
|
7
|
+
export function assertLatestContract(state, task) {
|
|
8
|
+
const contract = task.contract;
|
|
9
|
+
if (!contract)
|
|
10
|
+
conflict("Artifact contract missing");
|
|
11
|
+
for (const other of state.tasks) {
|
|
12
|
+
if (other.accountId !== task.accountId || other.roomId !== task.roomId || other.contract?.id !== contract.id)
|
|
13
|
+
continue;
|
|
14
|
+
if (other.contract.revision > contract.revision ||
|
|
15
|
+
(other.contract.revision === contract.revision && other.contract.digest !== contract.digest))
|
|
16
|
+
conflict("Artifact contract version is no longer authoritative");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function deriveArtifactSubject(state, task, options) {
|
|
20
|
+
if (task.status !== "completed" ||
|
|
21
|
+
task.cancelRequested ||
|
|
22
|
+
task.executionCompleted !== true ||
|
|
23
|
+
task.artifactProduced !== true ||
|
|
24
|
+
!task.contract ||
|
|
25
|
+
!task.contextManifest ||
|
|
26
|
+
!task.artifact ||
|
|
27
|
+
task.contract.executionMode !== "code")
|
|
28
|
+
conflict("Completed code artifact required");
|
|
29
|
+
const contract = validateWorkContract(task.contract);
|
|
30
|
+
const manifest = validateContextManifest(task.contextManifest, task.contract);
|
|
31
|
+
const artifact = validateCodeArtifactOutcome({
|
|
32
|
+
task,
|
|
33
|
+
artifact: task.artifact,
|
|
34
|
+
executionCompleted: task.executionCompleted,
|
|
35
|
+
artifactProduced: task.artifactProduced,
|
|
36
|
+
});
|
|
37
|
+
if (!contract.valid ||
|
|
38
|
+
!manifest.valid ||
|
|
39
|
+
!artifact.valid ||
|
|
40
|
+
!artifact.artifact ||
|
|
41
|
+
!task.artifact.baseline ||
|
|
42
|
+
!task.artifact.inputTree ||
|
|
43
|
+
!task.artifact.outputTree ||
|
|
44
|
+
task.artifact.producer.contractDigest !== task.contract.digest ||
|
|
45
|
+
task.artifact.producer.manifestDigest !== task.contextManifest.digest ||
|
|
46
|
+
task.contextManifest.executionPolicy?.botRevision !== task.botRevision ||
|
|
47
|
+
task.contextManifest.executionPolicy?.botId !== task.botId ||
|
|
48
|
+
task.contextManifest.executionPolicy?.deviceId !== task.deviceId)
|
|
49
|
+
conflict("Invalid sealed artifact evidence");
|
|
50
|
+
if (!options?.allowSuperseded)
|
|
51
|
+
assertLatestContract(state, task);
|
|
52
|
+
return {
|
|
53
|
+
artifactTaskId: task.id,
|
|
54
|
+
attemptId: task.attemptId,
|
|
55
|
+
artifactId: task.artifact.id,
|
|
56
|
+
artifactDigest: task.artifact.digest,
|
|
57
|
+
contractId: task.contract.id,
|
|
58
|
+
contractRevision: task.contract.revision,
|
|
59
|
+
contractDigest: task.contract.digest,
|
|
60
|
+
manifestDigest: task.contextManifest.digest,
|
|
61
|
+
baselineCommit: task.artifact.baseline.commit,
|
|
62
|
+
repositoryId: task.artifact.baseline.repositoryId,
|
|
63
|
+
inputTree: task.artifact.inputTree,
|
|
64
|
+
outputTree: task.artifact.outputTree,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function assertDeliveryAuthority(state, delivery) {
|
|
68
|
+
if (!delivery.artifactRef)
|
|
69
|
+
return undefined;
|
|
70
|
+
const task = state.tasks.find((t) => t.id === delivery.artifactRef.artifactTaskId &&
|
|
71
|
+
t.accountId === delivery.accountId &&
|
|
72
|
+
t.roomId === delivery.roomId &&
|
|
73
|
+
t.conversationId === delivery.conversationId &&
|
|
74
|
+
t.botId === delivery.botId);
|
|
75
|
+
if (!task || !artifactRefsMatch(delivery.artifactRef, deriveArtifactSubject(state, task)))
|
|
76
|
+
conflict("Delivery artifact subject changed");
|
|
77
|
+
return task;
|
|
78
|
+
}
|
|
79
|
+
/** Legacy records have no durable CAS identity: preserve their uncertainty for manual recovery. */
|
|
80
|
+
export function isLegacyPublicationUnknown(integration) {
|
|
81
|
+
return (!integration.publishIntent &&
|
|
82
|
+
(integration.status === "applying" || !!integration.error?.startsWith("Apply failed; check target outcome:")));
|
|
83
|
+
}
|
|
84
|
+
/** Effect receipts do not prove a previously started Git child has stopped. */
|
|
85
|
+
export function hasOpenPublication(integration) {
|
|
86
|
+
return (!!integration.publishIntent &&
|
|
87
|
+
((!!integration.publishStop && !integration.publishStop.stopConfirmed) ||
|
|
88
|
+
(!integration.publishReceipt && !(integration.publishStop?.closed && integration.publishStop.stopConfirmed))));
|
|
89
|
+
}
|
|
90
|
+
export function assertNoApplyingIntegration(state, accountId, roomId, conversationId, contractId) {
|
|
91
|
+
if (state.integrations.some((i) => i.accountId === accountId &&
|
|
92
|
+
i.roomId === roomId &&
|
|
93
|
+
(hasOpenPublication(i) || isLegacyPublicationUnknown(i)) &&
|
|
94
|
+
((!conversationId && !contractId) ||
|
|
95
|
+
(conversationId && i.conversationId === conversationId) ||
|
|
96
|
+
(contractId && i.artifactRef?.contractId === contractId))))
|
|
97
|
+
conflict("Integration apply freezes delivery, review and contract evidence");
|
|
98
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Artifact identity is the complete immutable subject, never an absent commit. */
|
|
2
|
+
export function artifactRefsMatch(a, b) {
|
|
3
|
+
return (!!a &&
|
|
4
|
+
!!b &&
|
|
5
|
+
a.artifactTaskId === b.artifactTaskId &&
|
|
6
|
+
a.attemptId === b.attemptId &&
|
|
7
|
+
a.artifactId === b.artifactId &&
|
|
8
|
+
a.artifactDigest === b.artifactDigest &&
|
|
9
|
+
a.contractId === b.contractId &&
|
|
10
|
+
a.contractRevision === b.contractRevision &&
|
|
11
|
+
a.contractDigest === b.contractDigest &&
|
|
12
|
+
a.manifestDigest === b.manifestDigest &&
|
|
13
|
+
a.baselineCommit === b.baselineCommit &&
|
|
14
|
+
a.repositoryId === b.repositoryId &&
|
|
15
|
+
a.inputTree === b.inputTree &&
|
|
16
|
+
a.outputTree === b.outputTree);
|
|
17
|
+
}
|
|
18
|
+
export function deliveryReviewMatches(delivery, review) {
|
|
19
|
+
if (!delivery ||
|
|
20
|
+
!review ||
|
|
21
|
+
delivery.id !== review.deliveryId ||
|
|
22
|
+
delivery.accountId !== review.accountId ||
|
|
23
|
+
delivery.roomId !== review.roomId ||
|
|
24
|
+
delivery.conversationId !== review.conversationId)
|
|
25
|
+
return false;
|
|
26
|
+
if (delivery.artifactRef)
|
|
27
|
+
return (review.artifactDigest === delivery.artifactRef.artifactDigest &&
|
|
28
|
+
artifactRefsMatch(delivery.artifactRef, review.artifactRef));
|
|
29
|
+
return !review.artifactRef && !review.artifactDigest && !!delivery.commit && delivery.commit === review.commit;
|
|
30
|
+
}
|