@tangle-network/agent-app 0.50.27 → 0.50.29
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/dist/hosted-agent/react/index.js +36 -15
- package/dist/hosted-agent/react/index.js.map +1 -1
- package/dist/hosted-agent/react/lines.css +10 -5
- package/dist/work-product/index.js +28 -16
- package/dist/work-product/index.js.map +1 -1
- package/dist/work-product/route.d.ts +4 -2
- package/dist/work-product/service.d.ts +2 -0
- package/package.json +1 -1
|
@@ -210,10 +210,8 @@ function createWorkProductService(options) {
|
|
|
210
210
|
at: now()
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
async function transition(
|
|
214
|
-
const
|
|
215
|
-
if (!record) return rejected(`Work product ${id} not found`);
|
|
216
|
-
const from = record.status;
|
|
213
|
+
async function transition(record, to, patch = {}, eventMeta = {}) {
|
|
214
|
+
const { id, status: from } = record;
|
|
217
215
|
if (isWorkProductTerminal(from)) {
|
|
218
216
|
return rejected(`Work product ${id} is terminal (${from}); cannot transition to ${to}`);
|
|
219
217
|
}
|
|
@@ -324,10 +322,10 @@ function createWorkProductService(options) {
|
|
|
324
322
|
const record = merged.value;
|
|
325
323
|
const blocking = unresolvedBlockingExceptions(record.exceptions).length;
|
|
326
324
|
if (record.status === "draft" && blocking > 0) {
|
|
327
|
-
return transition(
|
|
325
|
+
return transition(record, "blocked", {}, { blocking });
|
|
328
326
|
}
|
|
329
327
|
if (record.status === "blocked" && blocking === 0) {
|
|
330
|
-
return transition(
|
|
328
|
+
return transition(record, "draft", {}, { blocking });
|
|
331
329
|
}
|
|
332
330
|
return merged;
|
|
333
331
|
};
|
|
@@ -362,7 +360,7 @@ function createWorkProductService(options) {
|
|
|
362
360
|
at: now()
|
|
363
361
|
};
|
|
364
362
|
return transition(
|
|
365
|
-
|
|
363
|
+
record,
|
|
366
364
|
"ready",
|
|
367
365
|
{
|
|
368
366
|
artifact: input.artifact,
|
|
@@ -374,32 +372,37 @@ function createWorkProductService(options) {
|
|
|
374
372
|
);
|
|
375
373
|
};
|
|
376
374
|
const applyVerdict = async (id, input) => {
|
|
375
|
+
const { verdict, reviewedBy, note, expectedVersion } = input;
|
|
376
|
+
if (expectedVersion !== void 0 && (!Number.isSafeInteger(expectedVersion) || expectedVersion < 1)) {
|
|
377
|
+
return rejected("Expected review version must be a positive safe integer");
|
|
378
|
+
}
|
|
377
379
|
const record = await store.load(id);
|
|
378
380
|
if (!record) return rejected(`Work product ${id} not found`);
|
|
381
|
+
if (expectedVersion !== void 0 && expectedVersion !== record.version) return lostRace(id);
|
|
379
382
|
if (record.status !== "ready") {
|
|
380
383
|
return rejected(`Work product ${id} is ${record.status}; a verdict applies only to ready`);
|
|
381
384
|
}
|
|
382
|
-
const to =
|
|
385
|
+
const to = verdict === "approve" ? "approved" : "changes_requested";
|
|
383
386
|
const entry = {
|
|
384
387
|
version: record.version,
|
|
385
388
|
status: to,
|
|
386
389
|
provenance: record.provenance,
|
|
387
390
|
...record.artifact?.path === void 0 ? {} : { artifactPath: record.artifact.path },
|
|
388
|
-
reviewedBy
|
|
389
|
-
...
|
|
391
|
+
reviewedBy,
|
|
392
|
+
...note === void 0 ? {} : { reviewNote: note },
|
|
390
393
|
at: now()
|
|
391
394
|
};
|
|
392
395
|
const outcome = await transition(
|
|
393
|
-
|
|
396
|
+
record,
|
|
394
397
|
to,
|
|
395
398
|
{ history: [...record.history, entry] },
|
|
396
|
-
{ verdict
|
|
399
|
+
{ verdict, reviewedBy }
|
|
397
400
|
);
|
|
398
401
|
if (!outcome.succeeded || to !== "approved") return outcome;
|
|
399
402
|
const priorApproved = await store.listByWorkspace(record.workspaceId, { status: ["approved"] });
|
|
400
403
|
for (const prior of priorApproved) {
|
|
401
404
|
if (prior.id === id || prior.scopeKey !== record.scopeKey) continue;
|
|
402
|
-
await transition(prior
|
|
405
|
+
await transition(prior, "superseded", {}, { supersededBy: id });
|
|
403
406
|
}
|
|
404
407
|
return outcome;
|
|
405
408
|
};
|
|
@@ -416,7 +419,10 @@ function createWorkProductService(options) {
|
|
|
416
419
|
recordChecks,
|
|
417
420
|
submit,
|
|
418
421
|
applyVerdict,
|
|
419
|
-
supersede: (id) =>
|
|
422
|
+
supersede: async (id) => {
|
|
423
|
+
const record = await store.load(id);
|
|
424
|
+
return record ? transition(record, "superseded") : rejected(`Work product ${id} not found`);
|
|
425
|
+
}
|
|
420
426
|
};
|
|
421
427
|
}
|
|
422
428
|
function createInMemoryWorkProductStore() {
|
|
@@ -1251,6 +1257,11 @@ function buildWorkProductTools(config) {
|
|
|
1251
1257
|
function validateWorkProductVerdictBody(body) {
|
|
1252
1258
|
const id = typeof body.id === "string" && body.id.trim() ? body.id.trim() : null;
|
|
1253
1259
|
if (!id) return { ok: false, error: "Missing work product id" };
|
|
1260
|
+
const version = body.version;
|
|
1261
|
+
if (version !== void 0 && (typeof version !== "number" || !Number.isSafeInteger(version) || version < 1)) {
|
|
1262
|
+
return { ok: false, error: "Invalid work product version: expected a positive safe integer" };
|
|
1263
|
+
}
|
|
1264
|
+
const ref = { id, ...version === void 0 ? {} : { version } };
|
|
1254
1265
|
const verdict = body.verdict;
|
|
1255
1266
|
if (verdict !== "approve" && verdict !== "request_changes") {
|
|
1256
1267
|
return { ok: false, error: "Invalid verdict: expected approve or request_changes" };
|
|
@@ -1259,9 +1270,9 @@ function validateWorkProductVerdictBody(body) {
|
|
|
1259
1270
|
if (note === null) return { ok: false, error: "Invalid note: expected a string" };
|
|
1260
1271
|
if (verdict === "request_changes") {
|
|
1261
1272
|
if (!note) return { ok: false, error: "request_changes requires a note \u2014 it becomes the correction instruction in chat" };
|
|
1262
|
-
return { ok: true,
|
|
1273
|
+
return { ok: true, ...ref, verdict, note };
|
|
1263
1274
|
}
|
|
1264
|
-
return note ? { ok: true,
|
|
1275
|
+
return note ? { ok: true, ...ref, verdict, note } : { ok: true, ...ref, verdict };
|
|
1265
1276
|
}
|
|
1266
1277
|
function createWorkProductRoutes(options) {
|
|
1267
1278
|
const logger = options.logger ?? console;
|
|
@@ -1306,6 +1317,7 @@ function createWorkProductRoutes(options) {
|
|
|
1306
1317
|
const outcome = await service.applyVerdict(validation.id, {
|
|
1307
1318
|
verdict: validation.verdict,
|
|
1308
1319
|
reviewedBy: auth.reviewedBy,
|
|
1320
|
+
expectedVersion: validation.version ?? existing.version,
|
|
1309
1321
|
...validation.note === void 0 ? {} : { note: validation.note }
|
|
1310
1322
|
});
|
|
1311
1323
|
if (!outcome.succeeded) {
|