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
|
@@ -1,8 +1,63 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { isTerminal, taskPending } from "./store.js";
|
|
2
|
+
import { isTerminal, taskPending, taskHasImmutableEvidence, } from "./store.js";
|
|
3
|
+
/** Closed conversations kept per room for reading history; open ones are capacity, closed ones are archive. */
|
|
4
|
+
export const CLOSED_CONVERSATION_RETENTION = 200;
|
|
5
|
+
/** Idempotency receipts outlive message retention; replay must never re-dispatch evicted messages. */
|
|
6
|
+
export const ROOM_RECEIPT_RETENTION = 2000;
|
|
7
|
+
export const RECEIPT_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
8
|
+
/** A conversation whose Bot registration no longer matches cannot continue; report it instead of a late 409. */
|
|
9
|
+
export function conversationStale(state, conversation) {
|
|
10
|
+
const bot = state.bots.find((b) => b.id === conversation.botId && b.accountId === conversation.accountId);
|
|
11
|
+
if (!bot || !bot.enabled || bot.revision !== conversation.botRevision || bot.deviceId !== conversation.deviceId)
|
|
12
|
+
return true;
|
|
13
|
+
const room = state.rooms.find((r) => r.id === conversation.roomId && r.accountId === conversation.accountId);
|
|
14
|
+
return !room || !room.botIds.includes(bot.id);
|
|
15
|
+
}
|
|
16
|
+
/** Delivery/review records are the audit trail; a conversation carrying them is never silently dropped. */
|
|
17
|
+
export function conversationHasAuditRecords(state, conversationId) {
|
|
18
|
+
return (state.deliveries.some((delivery) => delivery.conversationId === conversationId) ||
|
|
19
|
+
state.reviews.some((review) => review.conversationId === conversationId) ||
|
|
20
|
+
state.integrations.some((integration) => integration.conversationId === conversationId) ||
|
|
21
|
+
state.tasks.some((task) => task.conversationId === conversationId && taskHasImmutableEvidence(task)));
|
|
22
|
+
}
|
|
23
|
+
/** Delete every record scoped to one conversation. Never called for conversations with audit records. */
|
|
24
|
+
export function dropConversationRecords(state, conversationId) {
|
|
25
|
+
const taskIds = new Set(state.tasks.filter((task) => task.conversationId === conversationId).map((task) => task.id));
|
|
26
|
+
state.conversations = state.conversations.filter((conversation) => conversation.id !== conversationId);
|
|
27
|
+
state.tasks = state.tasks.filter((task) => !taskIds.has(task.id));
|
|
28
|
+
state.conversationMessages = state.conversationMessages.filter((message) => message.conversationId !== conversationId);
|
|
29
|
+
state.deliveryReceipts = state.deliveryReceipts.filter((receipt) => receipt.conversationId !== conversationId);
|
|
30
|
+
state.integrations = state.integrations.filter((integration) => integration.conversationId !== conversationId);
|
|
31
|
+
}
|
|
32
|
+
/** Bound the closed-conversation archive per room without touching auditable or still-running work. */
|
|
33
|
+
export function trimClosedConversations(state, roomId, limit = CLOSED_CONVERSATION_RETENTION) {
|
|
34
|
+
const closed = state.conversations
|
|
35
|
+
.filter((conversation) => conversation.roomId === roomId && conversation.closed)
|
|
36
|
+
.sort((a, b) => a.updatedAt - b.updatedAt);
|
|
37
|
+
if (closed.length <= limit)
|
|
38
|
+
return;
|
|
39
|
+
for (const conversation of closed.slice(0, closed.length - limit))
|
|
40
|
+
if (!conversationHasAuditRecords(state, conversation.id) &&
|
|
41
|
+
!state.tasks.some((task) => task.conversationId === conversation.id && taskPending(task)))
|
|
42
|
+
dropConversationRecords(state, conversation.id);
|
|
43
|
+
}
|
|
44
|
+
/** Receipts are the replay guard, so they must not be evicted by message retention. */
|
|
45
|
+
export function trimRoomReceipts(state, roomId, limit = ROOM_RECEIPT_RETENTION) {
|
|
46
|
+
const cutoff = Date.now() - RECEIPT_TTL_MS;
|
|
47
|
+
const stale = new Set(state.receipts
|
|
48
|
+
.filter((receipt) => receipt.roomId === roomId && receipt.createdAt !== undefined && receipt.createdAt < cutoff)
|
|
49
|
+
.map((receipt) => receipt.key));
|
|
50
|
+
if (stale.size)
|
|
51
|
+
state.receipts = state.receipts.filter((receipt) => !(receipt.roomId === roomId && stale.has(receipt.key)));
|
|
52
|
+
const room = state.receipts.filter((receipt) => receipt.roomId === roomId);
|
|
53
|
+
if (room.length <= limit)
|
|
54
|
+
return;
|
|
55
|
+
const drop = new Set(room.slice(0, room.length - limit));
|
|
56
|
+
state.receipts = state.receipts.filter((receipt) => !drop.has(receipt));
|
|
57
|
+
}
|
|
3
58
|
export function trimConversationHistory(state, roomId, limit = 500) {
|
|
4
59
|
const protectedIds = new Set();
|
|
5
|
-
for (const task of state.tasks.filter((t) => t.roomId === roomId && taskPending(t))) {
|
|
60
|
+
for (const task of state.tasks.filter((t) => t.roomId === roomId && (taskPending(t) || taskHasImmutableEvidence(t)))) {
|
|
6
61
|
protectedIds.add(task.id);
|
|
7
62
|
if (task.rootTaskId)
|
|
8
63
|
protectedIds.add(task.rootTaskId);
|
|
@@ -35,7 +90,16 @@ export function conversationPage(state, conversationId, before) {
|
|
|
35
90
|
if (!messages.length && size > 60 * 1024) {
|
|
36
91
|
message = { ...message, text: message.text.slice(0, 1024) };
|
|
37
92
|
if (task)
|
|
38
|
-
task = {
|
|
93
|
+
task = {
|
|
94
|
+
...task,
|
|
95
|
+
text: task.text.slice(0, 1024),
|
|
96
|
+
report: task.report?.slice(0, 1024),
|
|
97
|
+
handoff: undefined,
|
|
98
|
+
// Full immutable payloads remain on the task; history pages are bounded projections.
|
|
99
|
+
contract: undefined,
|
|
100
|
+
contextManifest: undefined,
|
|
101
|
+
artifact: undefined,
|
|
102
|
+
};
|
|
39
103
|
truncated = true;
|
|
40
104
|
size = Buffer.byteLength(JSON.stringify({ message, task: includeTask ? task : undefined }));
|
|
41
105
|
}
|
|
@@ -117,7 +181,7 @@ export function recordConversationTurn(state, task, key, fingerprint) {
|
|
|
117
181
|
});
|
|
118
182
|
}
|
|
119
183
|
/** A terminal child result creates one durable continuation. Its task is the delivery receipt. */
|
|
120
|
-
export function queueParentResult(state, child) {
|
|
184
|
+
export function queueParentResult(state, child, limits) {
|
|
121
185
|
if (child.cancelRequested ||
|
|
122
186
|
!isTerminal(child.status) ||
|
|
123
187
|
child.kind === "result" ||
|
|
@@ -143,8 +207,8 @@ export function queueParentResult(state, child) {
|
|
|
143
207
|
bot.deviceId !== conversation.deviceId ||
|
|
144
208
|
bot.revision !== conversation.botRevision ||
|
|
145
209
|
!state.rooms.some((room) => room.id === child.roomId && room.botIds.includes(bot.id)) ||
|
|
146
|
-
(root.dispatchCount ?? 0) >= 16 ||
|
|
147
|
-
(child.dispatchDepth ?? 0) >= 8)
|
|
210
|
+
(root.dispatchCount ?? 0) >= (limits?.maxDispatchBudget ?? 16) ||
|
|
211
|
+
(child.dispatchDepth ?? 0) >= (limits?.maxDispatchDepth ?? 8))
|
|
148
212
|
return;
|
|
149
213
|
root.dispatchCount = (root.dispatchCount ?? 0) + 1;
|
|
150
214
|
const now = Date.now();
|
|
@@ -169,6 +233,7 @@ export function queueParentResult(state, child) {
|
|
|
169
233
|
status: "queued",
|
|
170
234
|
createdAt: now,
|
|
171
235
|
updatedAt: now,
|
|
236
|
+
...(parent.attenuatedTools ? { attenuatedTools: [...parent.attenuatedTools] } : {}),
|
|
172
237
|
};
|
|
173
238
|
state.tasks.push(task);
|
|
174
239
|
advanceConversationTask(state, conversation, task);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { hashSecret } from "./store.js";
|
|
3
|
+
import { assertDeliveryAuthority, assertNoApplyingIntegration, deriveArtifactSubject } from "./delivery-authority.js";
|
|
4
|
+
import { artifactRefsMatch, deliveryReviewMatches } from "./delivery-subject.js";
|
|
5
|
+
import { hasVerifiedIntegration } from "./integration-verification.js";
|
|
3
6
|
function fail(status, message) {
|
|
4
7
|
throw Object.assign(new Error(message), { status });
|
|
5
8
|
}
|
|
@@ -102,6 +105,7 @@ function append(state, kind, conversationId, key, actor, payload, create) {
|
|
|
102
105
|
t.status === "running" &&
|
|
103
106
|
!t.cancelRequested))
|
|
104
107
|
fail(409, "New records require a running Bot task");
|
|
108
|
+
assertNoApplyingIntegration(state, actor.accountId, state.conversations.find((c) => c.id === conversationId).roomId, conversationId);
|
|
105
109
|
const record = create();
|
|
106
110
|
const history = [...state.deliveries, ...state.reviews].filter((r) => r.conversationId === conversationId);
|
|
107
111
|
if (history.length >= 200 ||
|
|
@@ -117,6 +121,7 @@ export function addDelivery(state, roomId, conversationId, actor, input) {
|
|
|
117
121
|
"sourceBotId",
|
|
118
122
|
"parentTaskId",
|
|
119
123
|
"idempotencyKey",
|
|
124
|
+
"artifactTaskId",
|
|
120
125
|
"repository",
|
|
121
126
|
"baseCommit",
|
|
122
127
|
"commit",
|
|
@@ -156,17 +161,41 @@ export function addDelivery(state, roomId, conversationId, actor, input) {
|
|
|
156
161
|
const limits = body.limitations ?? [];
|
|
157
162
|
if (!Array.isArray(limits) || limits.length > 32)
|
|
158
163
|
fail(400, "Invalid limitations");
|
|
164
|
+
let subject;
|
|
165
|
+
if (body.artifactTaskId !== undefined) {
|
|
166
|
+
if (body.repository !== undefined || body.baseCommit !== undefined || body.commit !== undefined)
|
|
167
|
+
fail(400, "Artifact delivery derives repository and baseline; commit is not an artifact tree");
|
|
168
|
+
const artifactTaskId = text(body.artifactTaskId, 128, "artifactTaskId");
|
|
169
|
+
const task = state.tasks.find((t) => t.id === artifactTaskId &&
|
|
170
|
+
t.accountId === actor.accountId &&
|
|
171
|
+
t.roomId === roomId &&
|
|
172
|
+
t.conversationId === conversationId &&
|
|
173
|
+
t.botId === actor.bot.id &&
|
|
174
|
+
t.deviceId === actor.bot.deviceId &&
|
|
175
|
+
t.botRevision === actor.bot.revision);
|
|
176
|
+
if (!task)
|
|
177
|
+
fail(409, "Artifact task must belong to the same author, device, revision and conversation");
|
|
178
|
+
const artifactRef = deriveArtifactSubject(state, task);
|
|
179
|
+
subject = {
|
|
180
|
+
artifactRef,
|
|
181
|
+
repository: artifactRef.repositoryId,
|
|
182
|
+
baseCommit: artifactRef.baselineCommit,
|
|
183
|
+
acceptanceCriteria: [...(task.contract.acceptanceCriteria ?? [])],
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
else
|
|
187
|
+
subject = { repository: repository(body.repository), baseCommit: sha(body.baseCommit), commit: sha(body.commit) };
|
|
159
188
|
const payload = {
|
|
160
189
|
taskId: text(body.parentTaskId, 128, "parentTaskId"),
|
|
161
|
-
|
|
162
|
-
baseCommit: sha(body.baseCommit),
|
|
163
|
-
commit: sha(body.commit),
|
|
190
|
+
...subject,
|
|
164
191
|
...(body.branch === undefined ? {} : { branch: text(body.branch, 256, "branch") }),
|
|
165
192
|
summary: text(body.summary, 8192, "summary"),
|
|
166
193
|
checks,
|
|
167
194
|
limitations: limits.map((s) => text(s, 2048, "limitation")),
|
|
168
195
|
};
|
|
169
|
-
|
|
196
|
+
// The request budget covers author input; sealed Hub-derived criteria use the existing history budget.
|
|
197
|
+
const { acceptanceCriteria: _criteria, artifactRef: _artifactRef, ...requestPayload } = payload;
|
|
198
|
+
if (Buffer.byteLength(JSON.stringify(requestPayload)) > 24 * 1024)
|
|
170
199
|
fail(413, "Delivery budget exceeded");
|
|
171
200
|
return append(state, "delivery", conversationId, key, actor, payload, () => ({
|
|
172
201
|
...payload,
|
|
@@ -185,6 +214,10 @@ export function addReview(state, roomId, conversationId, actor, input) {
|
|
|
185
214
|
"idempotencyKey",
|
|
186
215
|
"deliveryId",
|
|
187
216
|
"commit",
|
|
217
|
+
"artifactDigest",
|
|
218
|
+
"integrationId",
|
|
219
|
+
"verificationDigest",
|
|
220
|
+
"criteriaResults",
|
|
188
221
|
"verdict",
|
|
189
222
|
"summary",
|
|
190
223
|
]);
|
|
@@ -193,22 +226,93 @@ export function addReview(state, roomId, conversationId, actor, input) {
|
|
|
193
226
|
fail(400, "Human review cannot claim Bot identity");
|
|
194
227
|
const key = text(body.idempotencyKey, 128, "idempotencyKey");
|
|
195
228
|
const deliveryId = text(body.deliveryId, 128, "deliveryId");
|
|
196
|
-
const commit = sha(body.commit);
|
|
197
229
|
if (!["accepted", "changes_requested"].includes(body.verdict))
|
|
198
230
|
fail(400, "Invalid verdict");
|
|
231
|
+
const delivery = state.deliveries.find((d) => d.id === deliveryId &&
|
|
232
|
+
d.conversationId === conversationId &&
|
|
233
|
+
d.roomId === roomId &&
|
|
234
|
+
d.accountId === actor.accountId);
|
|
235
|
+
if (!delivery)
|
|
236
|
+
fail(400, "Delivery missing");
|
|
237
|
+
const task = assertDeliveryAuthority(state, delivery);
|
|
238
|
+
let subject;
|
|
239
|
+
if (delivery.artifactRef) {
|
|
240
|
+
if (body.commit !== undefined || body.artifactDigest !== delivery.artifactRef.artifactDigest)
|
|
241
|
+
fail(400, "Review artifact digest must match delivery");
|
|
242
|
+
let criteriaResults;
|
|
243
|
+
if (body.criteriaResults !== undefined) {
|
|
244
|
+
if (!Array.isArray(body.criteriaResults) || body.criteriaResults.length > 64)
|
|
245
|
+
fail(400, "Invalid criteria results");
|
|
246
|
+
criteriaResults = body.criteriaResults.map((value) => {
|
|
247
|
+
const item = object(value, ["criterionIndex", "verdict", "evidence"]);
|
|
248
|
+
if (!Number.isSafeInteger(item.criterionIndex) ||
|
|
249
|
+
item.criterionIndex < 0 ||
|
|
250
|
+
item.criterionIndex >= (task.contract.acceptanceCriteria ?? []).length ||
|
|
251
|
+
!["met", "not_met"].includes(item.verdict))
|
|
252
|
+
fail(400, "Invalid criterion result");
|
|
253
|
+
return {
|
|
254
|
+
criterionIndex: item.criterionIndex,
|
|
255
|
+
verdict: item.verdict,
|
|
256
|
+
evidence: text(item.evidence, 2000, "criterion evidence"),
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
if (new Set(criteriaResults.map((c) => c.criterionIndex)).size !== criteriaResults.length)
|
|
260
|
+
fail(400, "Duplicate criterion result");
|
|
261
|
+
}
|
|
262
|
+
const integrationId = body.integrationId === undefined ? undefined : text(body.integrationId, 128, "integrationId");
|
|
263
|
+
const verificationDigest = body.verificationDigest === undefined ? undefined : text(body.verificationDigest, 64, "verificationDigest");
|
|
264
|
+
if (body.verdict === "accepted") {
|
|
265
|
+
const integration = state.integrations.find((i) => i.id === integrationId &&
|
|
266
|
+
i.accountId === actor.accountId &&
|
|
267
|
+
i.roomId === roomId &&
|
|
268
|
+
i.conversationId === conversationId &&
|
|
269
|
+
i.deliveryId === deliveryId);
|
|
270
|
+
const target = integration &&
|
|
271
|
+
state.bots.find((b) => b.id === integration.targetBotId &&
|
|
272
|
+
b.accountId === actor.accountId &&
|
|
273
|
+
b.deviceId === integration.targetDeviceId &&
|
|
274
|
+
b.revision === integration.targetBotRevision &&
|
|
275
|
+
b.enabled);
|
|
276
|
+
if (!integration ||
|
|
277
|
+
!target ||
|
|
278
|
+
!state.rooms.some((r) => r.id === roomId && r.accountId === actor.accountId && r.botIds.includes(target.id)) ||
|
|
279
|
+
!state.devices.some((d) => d.id === target.deviceId && d.accountId === actor.accountId) ||
|
|
280
|
+
!["verified", "applying", "applied"].includes(integration.status) ||
|
|
281
|
+
!hasVerifiedIntegration(integration) ||
|
|
282
|
+
!artifactRefsMatch(delivery.artifactRef, integration.artifactRef) ||
|
|
283
|
+
integration.verification.digest !== verificationDigest)
|
|
284
|
+
fail(409, "Accepted artifact review requires matching successful verification");
|
|
285
|
+
if (!criteriaResults ||
|
|
286
|
+
criteriaResults.length !== (task.contract.acceptanceCriteria ?? []).length ||
|
|
287
|
+
criteriaResults.some((c) => c.verdict !== "met"))
|
|
288
|
+
fail(400, "Accepted review must cover every sealed criterion");
|
|
289
|
+
}
|
|
290
|
+
subject = {
|
|
291
|
+
artifactRef: delivery.artifactRef,
|
|
292
|
+
artifactDigest: delivery.artifactRef.artifactDigest,
|
|
293
|
+
integrationId,
|
|
294
|
+
verificationDigest,
|
|
295
|
+
criteriaResults,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
if (body.artifactDigest !== undefined ||
|
|
300
|
+
body.integrationId !== undefined ||
|
|
301
|
+
body.verificationDigest !== undefined ||
|
|
302
|
+
body.criteriaResults !== undefined)
|
|
303
|
+
fail(400, "Legacy review requires commit only");
|
|
304
|
+
const commit = sha(body.commit);
|
|
305
|
+
if (delivery.commit !== commit)
|
|
306
|
+
fail(400, "Delivery and commit must match");
|
|
307
|
+
subject = { commit };
|
|
308
|
+
}
|
|
199
309
|
const payload = {
|
|
200
310
|
deliveryId,
|
|
201
|
-
|
|
311
|
+
...subject,
|
|
202
312
|
verdict: body.verdict,
|
|
203
313
|
summary: text(body.summary, 8192, "summary"),
|
|
204
314
|
...(actor.bot ? { taskId: text(body.parentTaskId, 128, "parentTaskId") } : {}),
|
|
205
315
|
};
|
|
206
|
-
const delivery = state.deliveries.find((d) => d.id === deliveryId &&
|
|
207
|
-
d.conversationId === conversationId &&
|
|
208
|
-
d.roomId === roomId &&
|
|
209
|
-
d.accountId === actor.accountId);
|
|
210
|
-
if (!delivery || delivery.commit !== commit)
|
|
211
|
-
fail(400, "Delivery and commit must match");
|
|
212
316
|
if (actor.bot?.id === delivery.botId)
|
|
213
317
|
fail(403, "Self review is forbidden");
|
|
214
318
|
return append(state, "review", conversationId, key, actor, payload, () => {
|
|
@@ -220,7 +324,7 @@ export function addReview(state, roomId, conversationId, actor, input) {
|
|
|
220
324
|
roomId,
|
|
221
325
|
conversationId,
|
|
222
326
|
deliveryId,
|
|
223
|
-
|
|
327
|
+
...subject,
|
|
224
328
|
verdict: payload.verdict,
|
|
225
329
|
summary: payload.summary,
|
|
226
330
|
reviewer: actor.bot ? { type: "bot", id: actor.bot.id } : { type: "human", id: actor.accountId },
|
|
@@ -270,8 +374,9 @@ export function getAcceptedDeliveryForIntegration(state, conversationId, deliver
|
|
|
270
374
|
}
|
|
271
375
|
const reviews = state.reviews.filter((r) => r.deliveryId === deliveryId);
|
|
272
376
|
const latestReview = reviews.at(-1);
|
|
273
|
-
|
|
274
|
-
|
|
377
|
+
assertDeliveryAuthority(state, latest);
|
|
378
|
+
if (!latestReview || latestReview.verdict !== "accepted" || !deliveryReviewMatches(latest, latestReview)) {
|
|
379
|
+
fail(400, "Delivery has no accepted review for its subject");
|
|
275
380
|
}
|
|
276
381
|
return { delivery: latest, review: latestReview };
|
|
277
382
|
}
|