@1agents/acp-service 0.8.3 → 0.9.1
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/README.md +25 -13
- package/dist/bin/a2a.js +16 -4
- package/dist/bin/acp-service.js +30 -0
- package/dist/bin/process.d.ts +4 -0
- package/dist/bin/process.js +57 -0
- package/dist/bin/roles.d.ts +1 -0
- package/dist/bin/roles.js +24 -0
- package/dist/bin/rsi.d.ts +3 -0
- package/dist/bin/rsi.js +114 -0
- package/dist/bin/ticket.d.ts +13 -0
- package/dist/bin/ticket.js +97 -0
- package/dist/bin/trail.d.ts +4 -0
- package/dist/bin/trail.js +62 -0
- package/dist/src/a2a/artifact-content.d.ts +9 -0
- package/dist/src/a2a/artifact-content.js +45 -0
- package/dist/src/a2a/desktop-notify.d.ts +1 -0
- package/dist/src/a2a/desktop-notify.js +12 -0
- package/dist/src/a2a/execution-binding.d.ts +9 -0
- package/dist/src/a2a/execution-binding.js +19 -0
- package/dist/src/a2a/executor.d.ts +22 -1
- package/dist/src/a2a/executor.js +308 -22
- package/dist/src/a2a/gateway.d.ts +613 -1
- package/dist/src/a2a/gateway.js +1337 -88
- package/dist/src/a2a/index.d.ts +14 -1
- package/dist/src/a2a/index.js +8 -0
- package/dist/src/a2a/job-directory.d.ts +6 -0
- package/dist/src/a2a/job-directory.js +19 -0
- package/dist/src/a2a/preflight.js +16 -1
- package/dist/src/a2a/resubmit.d.ts +46 -0
- package/dist/src/a2a/resubmit.js +82 -0
- package/dist/src/a2a/result-metadata.d.ts +6 -0
- package/dist/src/a2a/result-metadata.js +25 -6
- package/dist/src/a2a/server.d.ts +10 -0
- package/dist/src/a2a/server.js +127 -2
- package/dist/src/a2a/session-lifecycle.d.ts +40 -0
- package/dist/src/a2a/session-lifecycle.js +54 -0
- package/dist/src/a2a/store.d.ts +4 -0
- package/dist/src/a2a/store.js +76 -1
- package/dist/src/a2a/types.d.ts +77 -1
- package/dist/src/a2a/types.js +11 -1
- package/dist/src/a2a/workbench-ui.d.ts +28 -0
- package/dist/src/a2a/workbench-ui.js +182 -0
- package/dist/src/acp-connection.js +119 -14
- package/dist/src/bridge.d.ts +1 -0
- package/dist/src/bridge.js +312 -37
- package/dist/src/capacity-lifecycle.d.ts +5 -0
- package/dist/src/capacity-lifecycle.js +57 -0
- package/dist/src/capacity-queue.d.ts +58 -0
- package/dist/src/capacity-queue.js +388 -0
- package/dist/src/capacity.d.ts +101 -0
- package/dist/src/capacity.js +416 -0
- package/dist/src/dsh.js +1 -1
- package/dist/src/execution/agent-files.d.ts +25 -0
- package/dist/src/execution/agent-files.js +90 -0
- package/dist/src/execution/agent-registry.d.ts +164 -0
- package/dist/src/execution/agent-registry.js +275 -0
- package/dist/src/execution/human-review.d.ts +105 -0
- package/dist/src/execution/human-review.js +89 -0
- package/dist/src/execution/ledger.d.ts +57 -0
- package/dist/src/execution/ledger.js +122 -13
- package/dist/src/execution/ppt-delivery.d.ts +36 -3
- package/dist/src/execution/ppt-delivery.js +243 -53
- package/dist/src/execution/process-request.d.ts +151 -0
- package/dist/src/execution/process-request.js +177 -0
- package/dist/src/execution/project-discovery.d.ts +56 -0
- package/dist/src/execution/project-discovery.js +429 -0
- package/dist/src/execution/report-review.d.ts +60 -0
- package/dist/src/execution/report-review.js +173 -0
- package/dist/src/execution/targets.d.ts +20 -0
- package/dist/src/execution/targets.js +23 -3
- package/dist/src/execution/ticket-executor.d.ts +25 -0
- package/dist/src/execution/ticket-executor.js +27 -0
- package/dist/src/execution/ticket.d.ts +326 -0
- package/dist/src/execution/ticket.js +301 -0
- package/dist/src/execution/workbench-chat.d.ts +25 -0
- package/dist/src/execution/workbench-chat.js +54 -0
- package/dist/src/execution/workbench.d.ts +162 -0
- package/dist/src/execution/workbench.js +356 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +3 -0
- package/dist/src/roles/index.d.ts +1 -0
- package/dist/src/roles/index.js +1 -0
- package/dist/src/roles/skills.d.ts +71 -0
- package/dist/src/roles/skills.js +427 -0
- package/dist/src/rsi/gate.d.ts +25 -0
- package/dist/src/rsi/gate.js +59 -0
- package/dist/src/rsi/outline-run.d.ts +107 -0
- package/dist/src/rsi/outline-run.js +443 -0
- package/dist/workbench-ui/app.css +453 -0
- package/dist/workbench-ui/app.js +13 -0
- package/dist/workbench-ui/chunk-23JHGYT3.js +1 -0
- package/dist/workbench-ui/chunk-3H6STGPV.js +1 -0
- package/dist/workbench-ui/chunk-3SNBBMGH.js +1 -0
- package/dist/workbench-ui/chunk-3XJZ6DIE.js +1 -0
- package/dist/workbench-ui/chunk-44KDLLKJ.js +1 -0
- package/dist/workbench-ui/chunk-46H7FU5Y.js +7 -0
- package/dist/workbench-ui/chunk-4N44QPL7.js +1 -0
- package/dist/workbench-ui/chunk-4YN4BS7I.js +1 -0
- package/dist/workbench-ui/chunk-53EG4IVQ.js +96 -0
- package/dist/workbench-ui/chunk-5FIPUNR4.js +1 -0
- package/dist/workbench-ui/chunk-6DWWYA6G.js +2 -0
- package/dist/workbench-ui/chunk-6FU3T633.js +99 -0
- package/dist/workbench-ui/chunk-6XKIHRA4.js +1 -0
- package/dist/workbench-ui/chunk-7GIX43Y5.js +1 -0
- package/dist/workbench-ui/chunk-7Q4WBGX6.js +4 -0
- package/dist/workbench-ui/chunk-A3BQM7HR.js +1 -0
- package/dist/workbench-ui/chunk-AFCFDDOP.js +24 -0
- package/dist/workbench-ui/chunk-AG67EUYD.js +89 -0
- package/dist/workbench-ui/chunk-AGJHMMTN.js +1 -0
- package/dist/workbench-ui/chunk-AO6JUBV6.js +41 -0
- package/dist/workbench-ui/chunk-AUSLTP43.js +72 -0
- package/dist/workbench-ui/chunk-AVZL46TT.js +1 -0
- package/dist/workbench-ui/chunk-AZRIGIV2.js +168 -0
- package/dist/workbench-ui/chunk-B2LIVH37.js +1 -0
- package/dist/workbench-ui/chunk-B7YX5TR5.js +1 -0
- package/dist/workbench-ui/chunk-BCB4X4XX.js +1 -0
- package/dist/workbench-ui/chunk-BCRQUL2A.js +88 -0
- package/dist/workbench-ui/chunk-BI6UHHQP.js +1 -0
- package/dist/workbench-ui/chunk-BLSLQ4AQ.js +120 -0
- package/dist/workbench-ui/chunk-C3QSRS6E.js +1 -0
- package/dist/workbench-ui/chunk-CK7M2PJ3.js +62 -0
- package/dist/workbench-ui/chunk-CM6LZ7TU.js +1 -0
- package/dist/workbench-ui/chunk-CP63H27F.js +36 -0
- package/dist/workbench-ui/chunk-CPUMMIS2.js +70 -0
- package/dist/workbench-ui/chunk-CSEIBI5U.js +2 -0
- package/dist/workbench-ui/chunk-CUS65DKZ.js +161 -0
- package/dist/workbench-ui/chunk-CVQY7TNC.js +1 -0
- package/dist/workbench-ui/chunk-D6S3XBIX.js +106 -0
- package/dist/workbench-ui/chunk-E253Y562.js +1 -0
- package/dist/workbench-ui/chunk-EADDJUDC.js +1 -0
- package/dist/workbench-ui/chunk-EBGJ3YXG.js +206 -0
- package/dist/workbench-ui/chunk-EKPVZ3WY.js +8 -0
- package/dist/workbench-ui/chunk-EQDCEAFY.js +1 -0
- package/dist/workbench-ui/chunk-ES3SSDJY.js +40 -0
- package/dist/workbench-ui/chunk-ESFD2H7N.js +231 -0
- package/dist/workbench-ui/chunk-FVOHPMS6.js +1 -0
- package/dist/workbench-ui/chunk-FXMQAGVT.js +1 -0
- package/dist/workbench-ui/chunk-GGTADRXD.js +24 -0
- package/dist/workbench-ui/chunk-GHIVPGNQ.js +1 -0
- package/dist/workbench-ui/chunk-GLU2YQV2.js +1 -0
- package/dist/workbench-ui/chunk-GOCKBYSM.js +1 -0
- package/dist/workbench-ui/chunk-H2KMMTJB.js +1 -0
- package/dist/workbench-ui/chunk-HGVLDNPP.js +39 -0
- package/dist/workbench-ui/chunk-HSAVC5GY.js +1 -0
- package/dist/workbench-ui/chunk-HSEAD2JH.js +1 -0
- package/dist/workbench-ui/chunk-HSIHOBTY.js +1 -0
- package/dist/workbench-ui/chunk-IZXOKUGG.js +67 -0
- package/dist/workbench-ui/chunk-JFT2LC2T.js +1 -0
- package/dist/workbench-ui/chunk-JHL3ZDYK.js +3 -0
- package/dist/workbench-ui/chunk-JMORLCZG.js +257 -0
- package/dist/workbench-ui/chunk-JR4SIX7A.js +1 -0
- package/dist/workbench-ui/chunk-K23HAGEH.js +30 -0
- package/dist/workbench-ui/chunk-K43JDCBH.js +1 -0
- package/dist/workbench-ui/chunk-KINKFJY7.js +1 -0
- package/dist/workbench-ui/chunk-KKQSA4LI.js +2 -0
- package/dist/workbench-ui/chunk-KOUZX3UX.js +1 -0
- package/dist/workbench-ui/chunk-KR4DRHW2.js +78 -0
- package/dist/workbench-ui/chunk-KT4DJNOR.js +1 -0
- package/dist/workbench-ui/chunk-KTPNKRRZ.js +292 -0
- package/dist/workbench-ui/chunk-LFHIPGSU.js +7 -0
- package/dist/workbench-ui/chunk-LWDL4HZB.js +125 -0
- package/dist/workbench-ui/chunk-MVYC3CY4.js +1 -0
- package/dist/workbench-ui/chunk-NWUPALCY.js +129 -0
- package/dist/workbench-ui/chunk-NY7C662Z.js +1 -0
- package/dist/workbench-ui/chunk-O76WTHWP.js +1 -0
- package/dist/workbench-ui/chunk-OTF7YHRE.js +162 -0
- package/dist/workbench-ui/chunk-P6TKKRKP.js +1 -0
- package/dist/workbench-ui/chunk-PFHOOWV3.js +1 -0
- package/dist/workbench-ui/chunk-PUQLANIM.js +1 -0
- package/dist/workbench-ui/chunk-PZCGBYVO.js +1 -0
- package/dist/workbench-ui/chunk-QOHUZGP4.js +1 -0
- package/dist/workbench-ui/chunk-QSEG3OFF.js +1 -0
- package/dist/workbench-ui/chunk-QYPOXZIA.js +84 -0
- package/dist/workbench-ui/chunk-R6SOF3JC.js +1 -0
- package/dist/workbench-ui/chunk-RCLOYU5F.js +1 -0
- package/dist/workbench-ui/chunk-RSRUP64S.js +1 -0
- package/dist/workbench-ui/chunk-RVAIT6JW.js +1 -0
- package/dist/workbench-ui/chunk-S2CCN3II.js +1 -0
- package/dist/workbench-ui/chunk-S2Q52W46.js +1 -0
- package/dist/workbench-ui/chunk-S2W5THJ5.js +1 -0
- package/dist/workbench-ui/chunk-S6ZQZNOX.js +1 -0
- package/dist/workbench-ui/chunk-S74PLMMS.js +1 -0
- package/dist/workbench-ui/chunk-S7C4HKEY.js +1 -0
- package/dist/workbench-ui/chunk-SDTB3Q65.js +1 -0
- package/dist/workbench-ui/chunk-SLPRGYUV.js +32 -0
- package/dist/workbench-ui/chunk-SQE76S5B.js +1 -0
- package/dist/workbench-ui/chunk-SSDZPVPW.js +1 -0
- package/dist/workbench-ui/chunk-SVI7DGIE.js +1 -0
- package/dist/workbench-ui/chunk-T6QKLZ4H.js +62 -0
- package/dist/workbench-ui/chunk-TJNRPTFL.js +1 -0
- package/dist/workbench-ui/chunk-TP6U4EDH.js +2 -0
- package/dist/workbench-ui/chunk-TYAAT3GQ.js +1 -0
- package/dist/workbench-ui/chunk-U6OCY4ZH.js +1 -0
- package/dist/workbench-ui/chunk-UAN3NLRF.js +1 -0
- package/dist/workbench-ui/chunk-UMLU3FIX.js +1 -0
- package/dist/workbench-ui/chunk-URIY2OTM.js +1 -0
- package/dist/workbench-ui/chunk-V2NUKAA7.js +38 -0
- package/dist/workbench-ui/chunk-V4QLL4TE.js +139 -0
- package/dist/workbench-ui/chunk-VASHXUK4.js +2 -0
- package/dist/workbench-ui/chunk-VJLIWNIU.js +1 -0
- package/dist/workbench-ui/chunk-VQNQFBID.js +1 -0
- package/dist/workbench-ui/chunk-VSIWU7XA.js +3 -0
- package/dist/workbench-ui/chunk-VSJASPUZ.js +321 -0
- package/dist/workbench-ui/chunk-VXPNUNUX.js +3 -0
- package/dist/workbench-ui/chunk-WBKLDCV6.js +1 -0
- package/dist/workbench-ui/chunk-WOKJM3FY.js +1 -0
- package/dist/workbench-ui/chunk-X3U3NA3X.js +34 -0
- package/dist/workbench-ui/chunk-XBYU7M4J.js +1 -0
- package/dist/workbench-ui/chunk-XBZAO4ID.js +10 -0
- package/dist/workbench-ui/chunk-XLLPZ2WO.js +1 -0
- package/dist/workbench-ui/chunk-YFVL4NJL.js +1 -0
- package/dist/workbench-ui/chunk-YRFQENM4.js +1 -0
- package/dist/workbench-ui/chunk-YUADQVB2.js +1 -0
- package/dist/workbench-ui/chunk-Z3TCAKM5.js +1 -0
- package/dist/workbench-ui/chunk-Z6QR6FRE.js +10 -0
- package/dist/workbench-ui/chunk-ZJPSORPP.js +3 -0
- package/dist/workbench-ui/chunk-ZLGCSTR2.js +15 -0
- package/dist/workbench-ui/chunk-ZLR4SG5X.js +1 -0
- package/dist/workbench-ui/chunk-ZND3TTGF.js +1 -0
- package/dist/workbench-ui/chunk-ZOP3ZYH7.js +2 -0
- package/dist/workbench-ui/index.html +14 -0
- package/package.json +23 -8
- package/skills/acp-service/SKILL.md +24 -8
- package/skills/acp-service/references/a2a.md +24 -8
- package/skills/acp-service/references/async-caller.md +48 -0
- package/skills/acp-service/references/dsh.md +2 -0
- package/skills/acp-service/references/roles-and-tasks.md +120 -0
- package/skills/acp-service/scripts/a2a-caller.py +242 -0
- package/skills/rsi-coach/SKILL.md +134 -0
- package/vendor/dsh/README.md +11 -5
- package/vendor/dsh/a2a-executor.d.ts +60 -3
- package/vendor/dsh/a2a-executor.js +208 -18
- package/vendor/dsh/a2a.d.ts +12 -2
- package/vendor/dsh/a2a.js +9 -2
- package/vendor/dsh/adapter.d.ts +61 -2
- package/vendor/dsh/adapter.js +354 -23
- package/vendor/dsh/client.js +67 -11
- package/vendor/dsh/index.js +57 -4
- package/vendor/dsh/native-approvals.d.ts +4 -0
- package/vendor/dsh/native-approvals.js +44 -0
- package/vendor/dsh/preset-route.d.ts +49 -0
- package/vendor/dsh/preset-route.js +51 -0
- package/vendor/dsh/preset.js +10 -3
- package/vendor/dsh/process-admission.d.ts +25 -0
- package/vendor/dsh/process-admission.js +87 -0
- package/vendor/dsh/process-requests.d.ts +57 -0
- package/vendor/dsh/process-requests.js +49 -0
- package/vendor/dsh/review-mcp.d.ts +1 -0
- package/vendor/dsh/review-mcp.js +56 -0
- package/vendor/dsh/review.d.ts +30 -0
- package/vendor/dsh/review.js +149 -0
- package/vendor/dsh/session-settings.d.ts +34 -0
- package/vendor/dsh/session-settings.js +114 -0
- package/vendor/dsh/ticket-spec.d.ts +30 -0
- package/vendor/dsh/ticket-spec.js +10 -0
- package/vendor/dsh/ticket-tools.d.ts +21 -0
- package/vendor/dsh/ticket-tools.js +43 -0
- package/vendor/dsh/workbench.d.ts +18 -0
- package/vendor/dsh/workbench.js +91 -0
- package/vendor/runtime/README.md +6 -4
- package/vendor/runtime/dist/{cli-DeOpE2Xz.js → cli-DXmYwv3U.js} +4 -4
- package/vendor/runtime/dist/{cli-DeOpE2Xz.js.map → cli-DXmYwv3U.js.map} +1 -1
- package/vendor/runtime/dist/cli.js +7 -7
- package/vendor/runtime/dist/client-VQsqcIOJ.d.ts.map +1 -1
- package/vendor/runtime/dist/docs-site/CLI.html +2 -2
- package/vendor/runtime/dist/docs-site/VISION.html +2 -2
- package/vendor/runtime/dist/docs-site/agents.html +2 -2
- package/vendor/runtime/dist/docs-site/compare.html +2 -2
- package/vendor/runtime/dist/docs-site/config.html +2 -2
- package/vendor/runtime/dist/docs-site/custom-agents.html +2 -2
- package/vendor/runtime/dist/docs-site/exit-codes.html +2 -2
- package/vendor/runtime/dist/docs-site/flows.html +2 -2
- package/vendor/runtime/dist/docs-site/index.html +1 -1
- package/vendor/runtime/dist/docs-site/install.html +2 -2
- package/vendor/runtime/dist/docs-site/llms.txt +1 -1
- package/vendor/runtime/dist/docs-site/output-formats.html +2 -2
- package/vendor/runtime/dist/docs-site/permissions.html +2 -2
- package/vendor/runtime/dist/docs-site/prompting.html +2 -2
- package/vendor/runtime/dist/docs-site/quickstart.html +2 -2
- package/vendor/runtime/dist/docs-site/releasing.html +2 -2
- package/vendor/runtime/dist/docs-site/runtime-environment.html +2 -2
- package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +3 -2
- package/vendor/runtime/dist/docs-site/safe-errors.html +2 -2
- package/vendor/runtime/dist/docs-site/session-control.html +2 -2
- package/vendor/runtime/dist/docs-site/session-watch.html +2 -2
- package/vendor/runtime/dist/docs-site/sessions.html +2 -2
- package/vendor/runtime/dist/docs-site/shared-sessions.html +2 -2
- package/vendor/runtime/dist/{flows-oaBGn31w.js → flows-DJ17ajbw.js} +3 -3
- package/vendor/runtime/dist/{flows-oaBGn31w.js.map → flows-DJ17ajbw.js.map} +1 -1
- package/vendor/runtime/dist/flows.js +1 -1
- package/vendor/runtime/dist/{invocation-options-CUDEE8vW.js → invocation-options-PBfCgrdi.js} +3 -3
- package/vendor/runtime/dist/{invocation-options-CUDEE8vW.js.map → invocation-options-PBfCgrdi.js.map} +1 -1
- package/vendor/runtime/dist/{output-CFv3jcOQ.js → output-B3MDn7kv.js} +2 -2
- package/vendor/runtime/dist/{output-CFv3jcOQ.js.map → output-B3MDn7kv.js.map} +1 -1
- package/vendor/runtime/dist/{queue-owner-runtime-DvMJiGbP.js → queue-owner-runtime-DXCVngwU.js} +15 -8
- package/vendor/runtime/dist/queue-owner-runtime-DXCVngwU.js.map +1 -0
- package/vendor/runtime/dist/runtime.js +1 -1
- package/vendor/runtime/dist/{session-watch-Di-wIdCH.js → session-watch-DURyCw31.js} +2 -2
- package/vendor/runtime/dist/{session-watch-Di-wIdCH.js.map → session-watch-DURyCw31.js.map} +1 -1
- package/vendor/runtime/package.json +6 -4
- package/vendor/runtime/skills/acpx/SKILL.md +2 -0
- package/vendor/runtime/dist/queue-owner-runtime-DvMJiGbP.js.map +0 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The task ticket on an executor's job: every issue sent back, how the executor handled it and who confirmed it.
|
|
3
|
+
* The ledger keeps it with the job; each operation here belongs to one actor and returns the changes it made,
|
|
4
|
+
* which the ledger appends as `ticket.*` events, so who did what is recorded by the system rather than declared.
|
|
5
|
+
* Failed program checks become items the host verifies by re-running them; the host merges QA's review.
|
|
6
|
+
* When the ticket names an export path, every change also rewrites that read-only copy for people to read.
|
|
7
|
+
*/
|
|
8
|
+
import { rmSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
export const checkResultSchema = z.object({ itemId: z.string(), pass: z.boolean(), evidence: z.array(z.unknown()) }).strict();
|
|
12
|
+
export const qualityReviewSchema = z.object({
|
|
13
|
+
verdict: z.enum(['pass', 'revise']),
|
|
14
|
+
summary: z.string().trim().min(1).max(4000),
|
|
15
|
+
scores: z.record(z.string(), z.number().int().min(1).max(5)),
|
|
16
|
+
issues: z.array(z.object({ where: z.string().trim().min(1).max(300), problem: z.string().trim().min(1).max(2000),
|
|
17
|
+
suggestion: z.string().trim().min(1).max(2000), severity: z.enum(['must', 'should']) }).strict()).max(30),
|
|
18
|
+
/** On a re-review: QA's verdict on each ticket item the executor handled, by item id. */
|
|
19
|
+
previous: z.array(z.object({ id: z.string().trim().min(1).max(40), status: z.enum(['fixed', 'partly', 'not_fixed', 'withdrawn']),
|
|
20
|
+
note: z.string().trim().max(2000).optional() }).strict()).max(30).optional(),
|
|
21
|
+
/** Changes to the role itself: a program check, the executor's or QA's instructions, or a locked item only a person can change. */
|
|
22
|
+
proposals: z.array(z.object({ kind: z.enum(['check', 'role', 'qa', 'locked']), text: z.string().trim().min(1).max(2000) }).strict()).max(10).optional(),
|
|
23
|
+
}).passthrough().refine(review => review.verdict === 'pass' || review.issues.length > 0, { message: 'A revise verdict needs at least one issue' });
|
|
24
|
+
/** An operation the ticket's rules do not allow; the message is for the agent or person who asked. */
|
|
25
|
+
export class TicketError extends Error {
|
|
26
|
+
}
|
|
27
|
+
const fail = (message) => { throw new TicketError(message); };
|
|
28
|
+
const PENDING = ['open', 'reopened'];
|
|
29
|
+
export const pendingItems = (ticket) => ticket.items.filter(item => PENDING.includes(item.state));
|
|
30
|
+
/** Must-fix items nobody has confirmed as settled. */
|
|
31
|
+
export const unsettledMust = (ticket) => ticket.items.filter(item => item.severity === 'must' && item.state !== 'verified' && item.state !== 'withdrawn');
|
|
32
|
+
const isFinal = (ticket) => ticket.status === 'closed' || ticket.status === 'stopped';
|
|
33
|
+
const expect = (ticket, allowed, what) => {
|
|
34
|
+
if (!allowed.includes(ticket.status))
|
|
35
|
+
fail(`任务单状态是 ${ticket.status},${what}`);
|
|
36
|
+
};
|
|
37
|
+
export function openTicket(roleId, caseId, exportPath) {
|
|
38
|
+
return { ticket: { schemaVersion: 1, roleId, caseId, outline: 'outline.json', status: 'drafting', round: 1, ...(exportPath ? { exportPath } : {}),
|
|
39
|
+
items: [], proposals: [], history: [] },
|
|
40
|
+
changes: [{ type: 'ticket.opened', data: { actor: 'host', round: 1, roleId, caseId } }] };
|
|
41
|
+
}
|
|
42
|
+
/** Host: failed checks become or reopen program items, items whose check now passes are verified; all passing moves the ticket to review. */
|
|
43
|
+
export function applyChecks(ticket, results) {
|
|
44
|
+
expect(ticket, ['drafting', 'ready_for_review'], '只有执行者交稿后才能合并程序检查');
|
|
45
|
+
const round = ticket.round, changes = [];
|
|
46
|
+
const settle = (item, state, note) => {
|
|
47
|
+
item.state = state;
|
|
48
|
+
item.log.push({ round, by: 'host', action: state, note });
|
|
49
|
+
changes.push({ type: 'ticket.item_settled', data: { actor: 'host', round, itemId: item.id, state, note } });
|
|
50
|
+
};
|
|
51
|
+
for (const result of results) {
|
|
52
|
+
const item = ticket.items.find(entry => entry.source === 'program' && entry.checkId === result.itemId && entry.state !== 'verified');
|
|
53
|
+
if (result.pass) {
|
|
54
|
+
if (item)
|
|
55
|
+
settle(item, 'verified', `${result.itemId} 通过`);
|
|
56
|
+
}
|
|
57
|
+
else if (item) {
|
|
58
|
+
item.evidence = result.evidence;
|
|
59
|
+
if (item.state !== 'open')
|
|
60
|
+
settle(item, 'reopened', `${result.itemId} 仍未通过`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const where = result.evidence[0]?.path;
|
|
64
|
+
const raised = { id: `P${round}-${result.itemId}`, source: 'program', raisedInRound: round, severity: 'must',
|
|
65
|
+
where: typeof where === 'string' ? where : result.itemId, problem: `程序检查 ${result.itemId} 未通过`, checkId: result.itemId,
|
|
66
|
+
evidence: result.evidence, state: 'open', log: [{ round, by: 'host', action: 'raised' }] };
|
|
67
|
+
ticket.items.push(raised);
|
|
68
|
+
changes.push({ type: 'ticket.item_raised', data: { actor: 'host', round, itemId: raised.id, source: 'program', severity: 'must', where: raised.where, problem: raised.problem } });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const failed = results.filter(result => !result.pass).map(result => result.itemId);
|
|
72
|
+
if (!failed.length)
|
|
73
|
+
ticket.status = 'in_review';
|
|
74
|
+
changes.push({ type: 'ticket.checked', data: { actor: 'host', round, passed: !failed.length, failed, status: ticket.status } });
|
|
75
|
+
return changes;
|
|
76
|
+
}
|
|
77
|
+
const verdicts = { fixed: 'verified', partly: 'reopened', not_fixed: 'reopened', withdrawn: 'withdrawn' };
|
|
78
|
+
/** Host, on QA's behalf: QA's verdicts on handled items, its new issues and its proposals, merged into the ticket. */
|
|
79
|
+
export function applyReview(ticket, review, qaJobId) {
|
|
80
|
+
expect(ticket, ['in_review'], '只有程序检查通过后才能合并质检意见');
|
|
81
|
+
const round = ticket.round, changes = [], qa = qaJobId ? { qaJobId } : {};
|
|
82
|
+
for (const entry of review.previous ?? []) {
|
|
83
|
+
const item = ticket.items.find(candidate => candidate.id === entry.id && candidate.source === 'qa');
|
|
84
|
+
if (!item || item.state === 'verified' || item.state === 'withdrawn')
|
|
85
|
+
continue;
|
|
86
|
+
item.state = verdicts[entry.status];
|
|
87
|
+
item.log.push({ round, by: 'qa', action: entry.status, ...(entry.note ? { note: entry.note } : {}) });
|
|
88
|
+
changes.push({ type: 'ticket.item_settled', data: { actor: 'qa', round, itemId: item.id, state: item.state, verdict: entry.status, ...(entry.note ? { note: entry.note } : {}), ...qa } });
|
|
89
|
+
}
|
|
90
|
+
review.issues.forEach((issue, index) => {
|
|
91
|
+
const id = `Q${round}-${index + 1}`;
|
|
92
|
+
ticket.items.push({ id, source: 'qa', raisedInRound: round, severity: issue.severity, where: issue.where, problem: issue.problem,
|
|
93
|
+
suggestion: issue.suggestion, state: 'open', log: [{ round, by: 'qa', action: 'raised' }] });
|
|
94
|
+
changes.push({ type: 'ticket.item_raised', data: { actor: 'qa', round, itemId: id, source: 'qa', severity: issue.severity, where: issue.where, problem: issue.problem, ...qa } });
|
|
95
|
+
});
|
|
96
|
+
// A proposal QA repeats word for word is already on the ticket.
|
|
97
|
+
(review.proposals ?? []).forEach((proposal, index) => {
|
|
98
|
+
if (ticket.proposals.some(known => known.kind === proposal.kind && known.text === proposal.text))
|
|
99
|
+
return;
|
|
100
|
+
const id = `R${round}-${index + 1}`;
|
|
101
|
+
ticket.proposals.push({ id, kind: proposal.kind, text: proposal.text, raisedInRound: round, state: 'open' });
|
|
102
|
+
changes.push({ type: 'ticket.proposal_raised', data: { actor: 'qa', round, proposalId: id, kind: proposal.kind, text: proposal.text, ...qa } });
|
|
103
|
+
});
|
|
104
|
+
ticket.history.push({ round, by: 'qa', action: 'reviewed', verdict: review.verdict, scores: review.scores, summary: review.summary });
|
|
105
|
+
changes.push({ type: 'ticket.reviewed', data: { actor: 'qa', round, verdict: review.verdict, scores: review.scores, summary: review.summary, ...qa } });
|
|
106
|
+
return changes;
|
|
107
|
+
}
|
|
108
|
+
/** Host: the ticket goes back to the executor for the next round. */
|
|
109
|
+
export function startRevision(ticket, note) {
|
|
110
|
+
if (isFinal(ticket))
|
|
111
|
+
fail(`任务单已经 ${ticket.status}`);
|
|
112
|
+
ticket.round++;
|
|
113
|
+
ticket.status = 'in_revision';
|
|
114
|
+
return [{ type: 'ticket.revision_started', data: { actor: 'host', round: ticket.round, ...(note ? { note } : {}) } }];
|
|
115
|
+
}
|
|
116
|
+
/** Executor: a pending item is done or disputed, with a note, in the current round. */
|
|
117
|
+
export function markItem(ticket, itemId, state, note) {
|
|
118
|
+
expect(ticket, ['in_revision'], '现在不能修改');
|
|
119
|
+
const item = ticket.items.find(entry => entry.id === itemId) ?? fail(`任务单上没有 ${itemId}`);
|
|
120
|
+
if (!PENDING.includes(item.state))
|
|
121
|
+
fail(`${itemId} 已经是 ${item.state},只能处理 open 或 reopened 的意见`);
|
|
122
|
+
if (state !== 'done' && state !== 'disputed')
|
|
123
|
+
fail('只能标为 done(已改)或 disputed(不同意)');
|
|
124
|
+
const text = note.trim();
|
|
125
|
+
if (!text)
|
|
126
|
+
fail('说明不能为空:写清怎么改的,或者不同意的理由');
|
|
127
|
+
item.state = state;
|
|
128
|
+
item.log.push({ round: ticket.round, by: 'executor', action: state, note: text });
|
|
129
|
+
return [{ type: 'ticket.item_marked', data: { actor: 'executor', round: ticket.round, itemId, state, note: text } }];
|
|
130
|
+
}
|
|
131
|
+
/** Executor: everything is handled; the ticket is ready for the host's checks. */
|
|
132
|
+
export function submitTicket(ticket) {
|
|
133
|
+
expect(ticket, ['in_revision'], '现在不能提交');
|
|
134
|
+
const left = pendingItems(ticket);
|
|
135
|
+
if (left.length)
|
|
136
|
+
fail(`还有 ${left.length} 条没处理:${left.map(item => item.id).join('、')}`);
|
|
137
|
+
ticket.status = 'ready_for_review';
|
|
138
|
+
ticket.history.push({ round: ticket.round, by: 'executor', action: 'submitted' });
|
|
139
|
+
return [{ type: 'ticket.submitted', data: { actor: 'executor', round: ticket.round } }];
|
|
140
|
+
}
|
|
141
|
+
/** Person or coach: what became of a proposal. Allowed after the run ends, which is when the coach reads them. */
|
|
142
|
+
export function setProposal(ticket, proposalId, state, note, by = { kind: 'person' }) {
|
|
143
|
+
const proposal = ticket.proposals.find(entry => entry.id === proposalId) ?? fail(`任务单上没有提议 ${proposalId}`);
|
|
144
|
+
proposal.state = state;
|
|
145
|
+
proposal.by = by;
|
|
146
|
+
if (note)
|
|
147
|
+
proposal.note = note;
|
|
148
|
+
const { kind, ...who } = by;
|
|
149
|
+
return [{ type: 'ticket.proposal_marked', data: { actor: kind, round: ticket.round, proposalId, state, ...(note ? { note } : {}), ...who } }];
|
|
150
|
+
}
|
|
151
|
+
/** The read-only copy; the ledger stays the record, so a copy that cannot be written does not undo the change. */
|
|
152
|
+
function writeExport(ticket) {
|
|
153
|
+
if (!ticket.exportPath)
|
|
154
|
+
return;
|
|
155
|
+
try {
|
|
156
|
+
rmSync(ticket.exportPath, { force: true });
|
|
157
|
+
writeFileSync(ticket.exportPath, JSON.stringify(ticket, null, 2) + '\n', { mode: 0o444 });
|
|
158
|
+
}
|
|
159
|
+
catch { /* The next change, or ticket_get, has the current ticket. */ }
|
|
160
|
+
}
|
|
161
|
+
/** Host: the run is over, passed (closed) or not (stopped). */
|
|
162
|
+
export function closeTicket(ticket, status, stopReason) {
|
|
163
|
+
if (isFinal(ticket))
|
|
164
|
+
fail(`任务单已经 ${ticket.status}`);
|
|
165
|
+
if (status === 'stopped')
|
|
166
|
+
ticket.stoppedFrom = ticket.status;
|
|
167
|
+
ticket.status = status;
|
|
168
|
+
if (status === 'stopped' && stopReason)
|
|
169
|
+
ticket.stopReason = stopReason;
|
|
170
|
+
ticket.history.push({ round: ticket.round, by: 'host', action: status, ...(stopReason ? { note: stopReason } : {}) });
|
|
171
|
+
return [{ type: `ticket.${status}`, data: { actor: 'host', round: ticket.round, ...(stopReason ? { note: stopReason } : {}) } }];
|
|
172
|
+
}
|
|
173
|
+
/** Host: a stopped run goes on, so the ticket returns to where it stood; work going back to the executor enters a revision if it had left the executor's hands. */
|
|
174
|
+
export function reopenTicket(ticket, note, forExecutor = false) {
|
|
175
|
+
expect(ticket, ['stopped'], '只有 stopped 的任务单能重新打开');
|
|
176
|
+
const from = ticket.stoppedFrom ?? (ticket.round === 1 ? 'drafting' : 'in_revision');
|
|
177
|
+
ticket.status = from;
|
|
178
|
+
delete ticket.stoppedFrom;
|
|
179
|
+
delete ticket.stopReason;
|
|
180
|
+
ticket.history.push({ round: ticket.round, by: 'host', action: 'reopened', ...(note ? { note } : {}) });
|
|
181
|
+
const changes = [{ type: 'ticket.reopened', data: { actor: 'host', round: ticket.round, status: from, ...(note ? { note } : {}) } }];
|
|
182
|
+
return forExecutor && from !== 'drafting' && from !== 'in_revision' ? [...changes, ...startRevision(ticket, note)] : changes;
|
|
183
|
+
}
|
|
184
|
+
const id = z.string().trim().min(1).max(512);
|
|
185
|
+
const jobSchema = z.object({ originSessionId: id, jobId: id }).strict();
|
|
186
|
+
const openSchema = jobSchema.extend({ roleId: id, caseId: id,
|
|
187
|
+
exportPath: z.string().min(1).max(4096).refine(value => path.isAbsolute(value) && value.endsWith('.json'), 'exportPath must be an absolute .json path').optional() }).strict();
|
|
188
|
+
const settlerSchema = z.object({ kind: z.enum(['person', 'coach']), agent: id.optional(), sessionId: id.optional() }).strict()
|
|
189
|
+
.refine(by => by.kind === 'coach' || (!by.agent && !by.sessionId), 'Only a coach names an agent session');
|
|
190
|
+
const checksSchema = jobSchema.extend({ results: z.array(checkResultSchema).max(200) }).strict();
|
|
191
|
+
const reviewSchema = jobSchema.extend({ review: qualityReviewSchema, qaJobId: id.optional() }).strict();
|
|
192
|
+
const reviseSchema = jobSchema.extend({ note: z.string().trim().max(2000).optional() }).strict();
|
|
193
|
+
const reopenSchema = reviseSchema;
|
|
194
|
+
const proposalSchema = jobSchema.extend({ proposalId: id, state: z.enum(['accepted', 'rejected', 'done']), note: z.string().trim().max(2000).optional(),
|
|
195
|
+
by: settlerSchema.optional() }).strict();
|
|
196
|
+
const closeSchema = jobSchema.extend({ status: z.enum(['closed', 'stopped']), stopReason: id.optional() }).strict();
|
|
197
|
+
/**
|
|
198
|
+
* The executor names the attempt it is running and its session, never an origin or a role. The DSH tools and the ACP
|
|
199
|
+
* agents' MCP server resolve both from the calling session; the CLI runs in the executor's shell, knows only the job,
|
|
200
|
+
* and acts for the job's current attempt. `via` records which of the three the call came through. Nothing attests who
|
|
201
|
+
* ran the CLI, so its events carry no session and say the caller is unverified rather than borrowing the executor's.
|
|
202
|
+
*/
|
|
203
|
+
const executorBase = z.object({ jobId: id, attemptId: id.optional(), sessionId: id.optional(), via: z.enum(['dsh', 'mcp', 'cli']).optional() }).strict();
|
|
204
|
+
const attested = (input) => input.via === 'cli' ? !input.attemptId && !input.sessionId : Boolean(input.attemptId && input.sessionId);
|
|
205
|
+
const attestation = 'attemptId and sessionId are required, except from the CLI, which names only the job';
|
|
206
|
+
const executorSchema = executorBase.refine(attested, attestation);
|
|
207
|
+
const markSchema = executorBase.extend({ itemId: id, state: z.enum(['done', 'disputed']), note: z.string().max(4000) }).strict().refine(attested, attestation);
|
|
208
|
+
export const TICKET_METHODS = {
|
|
209
|
+
ticket_get: { description: '读取执行者任务上的任务单(意见、状态、轮次、提议、历史)。每次改动都在 execution_events 里留有 ticket.* 事件。', parameters: z.toJSONSchema(jobSchema) },
|
|
210
|
+
ticket_open: { description: '宿主:在执行者任务上开任务单,一个任务一张。exportPath 为只读导出的绝对路径,之后每次改动都会重写。', parameters: z.toJSONSchema(openSchema) },
|
|
211
|
+
ticket_checks: { description: '宿主:执行者交稿后合并本轮程序检查结果。未通过的项成为或重开意见,通过的核实;全部通过则进入审阅。', parameters: z.toJSONSchema(checksSchema) },
|
|
212
|
+
ticket_review: { description: '宿主:审阅中合并质检结果(previous 按意见编号 fixed/partly/not_fixed/withdrawn、新意见、去重后的提议),记录质检任务 qaJobId。质检自己不能改任务单。', parameters: z.toJSONSchema(reviewSchema) },
|
|
213
|
+
ticket_revise: { description: '宿主:把任务单打回执行者,进入下一轮修改。', parameters: z.toJSONSchema(reviseSchema) },
|
|
214
|
+
ticket_show: { description: '执行者:用正在执行的 jobId、attemptId 和 sessionId 读取自己的任务单;命令行只给 jobId,via 为 cli,按该任务当前这一轮执行。', parameters: z.toJSONSchema(executorSchema) },
|
|
215
|
+
ticket_mark: { description: '执行者:修改中把本轮 open 或 reopened 的意见标为 done 或 disputed,必须写说明;只能由正在执行当前轮次的会话调用。', parameters: z.toJSONSchema(markSchema) },
|
|
216
|
+
ticket_submit: { description: '执行者:没有待处理意见时提交任务单,等待宿主检查。', parameters: z.toJSONSchema(executorSchema) },
|
|
217
|
+
ticket_proposal: { description: '人或教练:把一条提议标为 accepted、rejected 或 done,可写说明;运行结束后也可以。by 说明是人还是教练(教练写明所在的智能体会话),缺省为人。', parameters: z.toJSONSchema(proposalSchema) },
|
|
218
|
+
ticket_close: { description: '宿主:运行结束时关单,通过为 closed,否则为 stopped 并写停止原因。', parameters: z.toJSONSchema(closeSchema) },
|
|
219
|
+
ticket_reopen: { description: '宿主:停下的运行接着跑时,把 stopped 的任务单放回停止前的状态。', parameters: z.toJSONSchema(reopenSchema) },
|
|
220
|
+
};
|
|
221
|
+
/** An explicit continue gives the executor another go, so a stopped ticket opens with it; a job without a ticket has nothing to do. */
|
|
222
|
+
export function reopenForContinue(ledger, originSessionId, jobId) {
|
|
223
|
+
let status;
|
|
224
|
+
try {
|
|
225
|
+
status = ledger.ticket(originSessionId, jobId).status;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
if (error instanceof TicketError)
|
|
229
|
+
return;
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
if (status !== 'stopped')
|
|
233
|
+
return;
|
|
234
|
+
writeExport(ledger.changeTicket(originSessionId, jobId, current => ({ ticket: current, changes: reopenTicket(current, '任务被继续', true) })));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* The gateway's ticket methods. The method decides the actor: the host opens, merges checks and reviews, sends back
|
|
238
|
+
* and closes; a person settles proposals; the executor shows, marks and submits. The executor's call names its
|
|
239
|
+
* running attempt and session, and the ledger checks that the attempt is the job's current, unfinished one and,
|
|
240
|
+
* once the host has reported which session runs it, that the session matches; a CLI call names only the job and acts
|
|
241
|
+
* for its current attempt. Nothing here proves the call came from that session's agent: the DSH tools and the MCP
|
|
242
|
+
* server resolve the session themselves, the CLI is trusted to run in the executor's shell, and this MVP does not
|
|
243
|
+
* defend against a local caller that bypasses them with the right IDs.
|
|
244
|
+
*/
|
|
245
|
+
export function invokeTicket(ledger, method, params) {
|
|
246
|
+
const change = (origin, jobId, operation, caller = {}) => {
|
|
247
|
+
const ticket = ledger.changeTicket(origin, jobId, current => ({ ticket: current ?? fail('这个任务还没有任务单'), changes: operation(current) }), caller);
|
|
248
|
+
writeExport(ticket);
|
|
249
|
+
return ticket;
|
|
250
|
+
};
|
|
251
|
+
switch (method) {
|
|
252
|
+
case 'ticket_get': {
|
|
253
|
+
const input = jobSchema.parse(params);
|
|
254
|
+
return ledger.ticket(input.originSessionId, input.jobId);
|
|
255
|
+
}
|
|
256
|
+
case 'ticket_open': {
|
|
257
|
+
const input = openSchema.parse(params);
|
|
258
|
+
const ticket = ledger.changeTicket(input.originSessionId, input.jobId, current => current ? fail('这个任务已经有任务单') : openTicket(input.roleId, input.caseId, input.exportPath));
|
|
259
|
+
writeExport(ticket);
|
|
260
|
+
return ticket;
|
|
261
|
+
}
|
|
262
|
+
case 'ticket_checks': {
|
|
263
|
+
const input = checksSchema.parse(params);
|
|
264
|
+
return change(input.originSessionId, input.jobId, ticket => applyChecks(ticket, input.results));
|
|
265
|
+
}
|
|
266
|
+
case 'ticket_review': {
|
|
267
|
+
const input = reviewSchema.parse(params);
|
|
268
|
+
return change(input.originSessionId, input.jobId, ticket => applyReview(ticket, input.review, input.qaJobId));
|
|
269
|
+
}
|
|
270
|
+
case 'ticket_revise': {
|
|
271
|
+
const input = reviseSchema.parse(params);
|
|
272
|
+
return change(input.originSessionId, input.jobId, ticket => startRevision(ticket, input.note));
|
|
273
|
+
}
|
|
274
|
+
case 'ticket_proposal': {
|
|
275
|
+
const input = proposalSchema.parse(params);
|
|
276
|
+
return change(input.originSessionId, input.jobId, ticket => setProposal(ticket, input.proposalId, input.state, input.note, input.by));
|
|
277
|
+
}
|
|
278
|
+
case 'ticket_close': {
|
|
279
|
+
const input = closeSchema.parse(params);
|
|
280
|
+
return change(input.originSessionId, input.jobId, ticket => closeTicket(ticket, input.status, input.stopReason));
|
|
281
|
+
}
|
|
282
|
+
case 'ticket_reopen': {
|
|
283
|
+
const input = reopenSchema.parse(params);
|
|
284
|
+
return change(input.originSessionId, input.jobId, ticket => reopenTicket(ticket, input.note));
|
|
285
|
+
}
|
|
286
|
+
case 'ticket_show':
|
|
287
|
+
case 'ticket_mark':
|
|
288
|
+
case 'ticket_submit': {
|
|
289
|
+
const mark = method === 'ticket_mark' ? markSchema.parse(params) : undefined, input = mark ?? executorSchema.parse(params);
|
|
290
|
+
const current = input.via === 'cli' ? ledger.currentAttempt(input.jobId) : undefined;
|
|
291
|
+
const attemptId = current?.attemptId ?? input.attemptId, sessionId = current ? current.sessionId : input.sessionId;
|
|
292
|
+
const origin = ledger.executorOrigin(input.jobId, attemptId, sessionId ?? '');
|
|
293
|
+
if (method === 'ticket_show')
|
|
294
|
+
return ledger.ticket(origin, input.jobId);
|
|
295
|
+
const caller = current ? { attemptId, via: 'cli', callerUnverified: true }
|
|
296
|
+
: { attemptId, ...(sessionId !== undefined ? { sessionId } : {}), ...(input.via ? { via: input.via } : {}) };
|
|
297
|
+
return change(origin, input.jobId, ticket => mark ? markItem(ticket, mark.itemId, mark.state, mark.note) : submitTicket(ticket), caller);
|
|
298
|
+
}
|
|
299
|
+
default: throw new Error(`Unknown ticket method: ${method}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface WorkbenchChatItem {
|
|
2
|
+
id: string;
|
|
3
|
+
createdAt: number;
|
|
4
|
+
kind: 'user' | 'assistant_text';
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WorkbenchChatPage {
|
|
8
|
+
items: WorkbenchChatItem[];
|
|
9
|
+
hasMore: boolean;
|
|
10
|
+
nextCursor?: string;
|
|
11
|
+
total: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One item per message: text parts joined, structured data fenced, file parts as links. Status notices are
|
|
15
|
+
* dropped and repeats collapse; the agent's final answer lives in the task's text artifacts, not its history.
|
|
16
|
+
*/
|
|
17
|
+
export declare function chatItems(tasks: {
|
|
18
|
+
attemptId?: string;
|
|
19
|
+
task: unknown;
|
|
20
|
+
}[]): WorkbenchChatItem[];
|
|
21
|
+
/** `before` is the index the previous page started at; pages walk from the newest toward the oldest. */
|
|
22
|
+
export declare function pageChat(items: WorkbenchChatItem[], query?: {
|
|
23
|
+
limit?: number;
|
|
24
|
+
before?: number;
|
|
25
|
+
}): WorkbenchChatPage;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Turns the A2A tasks behind one workbench job into the chat view's transcript items, newest page first. */
|
|
2
|
+
import { Role, Task } from '@a2a-js/sdk';
|
|
3
|
+
/** Queue and progress notices the executor writes into A2A history on every poll; they are status, not conversation. */
|
|
4
|
+
const STATUS_NOTICE = /^(CAPACITY_PENDING|Pending: waiting\b)/;
|
|
5
|
+
const fence = (value) => '```json\n' + JSON.stringify(value, null, 2) + '\n```';
|
|
6
|
+
/**
|
|
7
|
+
* One item per message: text parts joined, structured data fenced, file parts as links. Status notices are
|
|
8
|
+
* dropped and repeats collapse; the agent's final answer lives in the task's text artifacts, not its history.
|
|
9
|
+
*/
|
|
10
|
+
export function chatItems(tasks) {
|
|
11
|
+
const items = [], seen = new Set();
|
|
12
|
+
for (const { attemptId, task: raw } of tasks) {
|
|
13
|
+
const task = Task.fromJSON(raw);
|
|
14
|
+
const messages = [...task.history, ...(task.status?.message ? [task.status.message] : [])];
|
|
15
|
+
for (const message of messages) {
|
|
16
|
+
const key = `${task.id}:${message.messageId}`;
|
|
17
|
+
if (seen.has(key))
|
|
18
|
+
continue;
|
|
19
|
+
seen.add(key);
|
|
20
|
+
const blocks = message.parts.flatMap(part => {
|
|
21
|
+
const content = part.content;
|
|
22
|
+
if (!content)
|
|
23
|
+
return [];
|
|
24
|
+
if (content.$case === 'text')
|
|
25
|
+
return content.value.trim() ? [content.value] : [];
|
|
26
|
+
if (content.$case === 'data')
|
|
27
|
+
return [fence(content.value)];
|
|
28
|
+
if (content.$case === 'url')
|
|
29
|
+
return [`[${part.filename || content.value}](${content.value})`];
|
|
30
|
+
return [];
|
|
31
|
+
});
|
|
32
|
+
const content = blocks.join('\n\n');
|
|
33
|
+
const role = message.role === Role.ROLE_USER ? 'user' : 'assistant_text';
|
|
34
|
+
if (!content || role === 'assistant_text' && STATUS_NOTICE.test(content.trim()))
|
|
35
|
+
continue;
|
|
36
|
+
if (items.at(-1)?.kind === role && items.at(-1).content === content)
|
|
37
|
+
continue;
|
|
38
|
+
// Ordinals, not clocks: A2A history carries no timestamps, and ids must stay stable as history grows.
|
|
39
|
+
items.push({ id: `${attemptId ?? task.id}:${message.messageId}`, createdAt: items.length, kind: role, content });
|
|
40
|
+
}
|
|
41
|
+
for (const artifact of task.artifacts) {
|
|
42
|
+
const answer = artifact.parts.flatMap(part => part.content?.$case === 'text' && part.content.value.trim() ? [part.content.value] : []).join('\n\n');
|
|
43
|
+
if (!answer || items.some(item => item.kind === 'assistant_text' && item.content === answer))
|
|
44
|
+
continue;
|
|
45
|
+
items.push({ id: `${attemptId ?? task.id}:artifact:${artifact.artifactId}`, createdAt: items.length, kind: 'assistant_text', content: answer });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return items;
|
|
49
|
+
}
|
|
50
|
+
/** `before` is the index the previous page started at; pages walk from the newest toward the oldest. */
|
|
51
|
+
export function pageChat(items, query = {}) {
|
|
52
|
+
const end = Math.min(query.before ?? items.length, items.length), start = Math.max(0, end - (query.limit ?? 40));
|
|
53
|
+
return { items: items.slice(start, end), hasMore: start > 0, ...(start > 0 ? { nextCursor: String(start) } : {}), total: items.length };
|
|
54
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/** Human-readable projections of the execution ledger. Reading never dispatches or acknowledges work. */
|
|
2
|
+
import type { BusinessAcceptance, JobRef, LedgerActor, LedgerAttempt, LedgerEvent, LedgerState } from './ledger.js';
|
|
3
|
+
import type { ReportReviewRun } from './report-review.js';
|
|
4
|
+
import type { PptDeliveryRun } from './ppt-delivery.js';
|
|
5
|
+
import { deliveryProgress } from './delivery-progress.js';
|
|
6
|
+
import type { HumanReviewRequest, HumanReviewStatus } from './human-review.js';
|
|
7
|
+
import { type ProcessRequest } from './process-request.js';
|
|
8
|
+
import { type AgentDraft, type AgentRelease, type ResidentAgentRef, type WorkbenchAgentRow } from './agent-registry.js';
|
|
9
|
+
export interface WorkbenchServiceInfo {
|
|
10
|
+
kind: 'a2a' | 'gateway_workflow' | 'activepieces' | 'unknown';
|
|
11
|
+
source: 'backend_run' | 'target_snapshot' | 'workflow_run' | 'unrecorded';
|
|
12
|
+
host?: string;
|
|
13
|
+
port?: number;
|
|
14
|
+
locality?: 'loopback' | 'network';
|
|
15
|
+
connectionAlias?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface WorkbenchExecution {
|
|
18
|
+
kind: 'temporary' | 'resident' | 'workflow' | 'unknown';
|
|
19
|
+
targetId: string;
|
|
20
|
+
targetName?: string;
|
|
21
|
+
roleId?: string;
|
|
22
|
+
agentPreset?: string;
|
|
23
|
+
presetStatus: 'recorded' | 'host_default' | 'unknown' | 'not_applicable';
|
|
24
|
+
service?: string;
|
|
25
|
+
serviceInfo?: WorkbenchServiceInfo;
|
|
26
|
+
provider?: string;
|
|
27
|
+
connectionId?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface AcpTaskSummary {
|
|
30
|
+
sourceId: string;
|
|
31
|
+
jobId: string;
|
|
32
|
+
title: string;
|
|
33
|
+
originSessionId: string;
|
|
34
|
+
parentJobRef?: JobRef;
|
|
35
|
+
parentAttemptId?: string;
|
|
36
|
+
purpose?: string;
|
|
37
|
+
targetId: string;
|
|
38
|
+
currentAttemptId: string;
|
|
39
|
+
executionStatus: string;
|
|
40
|
+
displayStatus: string;
|
|
41
|
+
phase: string;
|
|
42
|
+
createdAt: string | null;
|
|
43
|
+
updatedAt: string;
|
|
44
|
+
stale: boolean;
|
|
45
|
+
reviewStatus?: HumanReviewStatus;
|
|
46
|
+
pendingReviewId?: string;
|
|
47
|
+
pendingProcessRequestId?: string;
|
|
48
|
+
progressSummary: string;
|
|
49
|
+
channel: 'trial' | 'formal' | 'standalone';
|
|
50
|
+
agentId?: string;
|
|
51
|
+
agentName?: string;
|
|
52
|
+
agentPhase?: 'developing' | 'published';
|
|
53
|
+
inFlightAttemptIds: string[];
|
|
54
|
+
unresolvedAttemptIds: string[];
|
|
55
|
+
execution: WorkbenchExecution;
|
|
56
|
+
/** The origin session's execution_review for the current result, if one was recorded. */
|
|
57
|
+
businessAcceptance?: BusinessAcceptance;
|
|
58
|
+
/** Tools the finished attempt asked for that nobody approved; its result may be incomplete. */
|
|
59
|
+
blockedTools?: string[];
|
|
60
|
+
/** The round failed and nothing else drives this task, so a person can send it another round from the workbench. */
|
|
61
|
+
canContinue?: boolean;
|
|
62
|
+
/** A finished top-level result with no conclusion yet and no review flow of its own, so a person can mark it read. */
|
|
63
|
+
canAccept?: boolean;
|
|
64
|
+
initiatedBy?: LedgerActor;
|
|
65
|
+
}
|
|
66
|
+
export interface WorkbenchStage {
|
|
67
|
+
stage: string;
|
|
68
|
+
name: string;
|
|
69
|
+
status: string;
|
|
70
|
+
planned: boolean;
|
|
71
|
+
jobId?: string;
|
|
72
|
+
attemptId?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface WorkbenchProgress {
|
|
75
|
+
stage: string;
|
|
76
|
+
phase: string;
|
|
77
|
+
stages: WorkbenchStage[];
|
|
78
|
+
completedStages: string[];
|
|
79
|
+
remainingStages: string[];
|
|
80
|
+
executionElapsedMs?: number;
|
|
81
|
+
humanWaitingMs?: number;
|
|
82
|
+
updatedAt: string;
|
|
83
|
+
availableResults?: ReturnType<typeof deliveryProgress>['availableResults'];
|
|
84
|
+
}
|
|
85
|
+
export interface WorkbenchDependency {
|
|
86
|
+
from: string;
|
|
87
|
+
to: string;
|
|
88
|
+
kind: 'parent' | 'depends_on' | 'replaces';
|
|
89
|
+
label: string;
|
|
90
|
+
parentAttemptId?: string;
|
|
91
|
+
}
|
|
92
|
+
export type WorkbenchReview = HumanReviewRequest & {
|
|
93
|
+
canReview: boolean;
|
|
94
|
+
resumeStatus?: 'pending' | 'applied';
|
|
95
|
+
resumeError?: string;
|
|
96
|
+
};
|
|
97
|
+
export type WorkbenchProcessRequest = ProcessRequest & {
|
|
98
|
+
canAnswer: boolean;
|
|
99
|
+
};
|
|
100
|
+
export type WorkbenchAttempt = Omit<LedgerAttempt, 'input' | 'targetSnapshot' | 'backendRunRef'> & {
|
|
101
|
+
backendRunRef?: Record<string, string>;
|
|
102
|
+
execution: WorkbenchExecution;
|
|
103
|
+
};
|
|
104
|
+
export interface AcpTaskDetail extends AcpTaskSummary {
|
|
105
|
+
/** The first attempt's prompt: what the task was asked to do. Other input fields stay private. */
|
|
106
|
+
description?: string;
|
|
107
|
+
attempts: WorkbenchAttempt[];
|
|
108
|
+
children: AcpTaskSummary[];
|
|
109
|
+
ancestors: AcpTaskSummary[];
|
|
110
|
+
progress: WorkbenchProgress;
|
|
111
|
+
reviews: WorkbenchReview[];
|
|
112
|
+
processRequests: WorkbenchProcessRequest[];
|
|
113
|
+
events: LedgerEvent[];
|
|
114
|
+
dependencies: WorkbenchDependency[];
|
|
115
|
+
artifacts: {
|
|
116
|
+
revision: string;
|
|
117
|
+
digest?: string;
|
|
118
|
+
artifacts: unknown[];
|
|
119
|
+
}[];
|
|
120
|
+
}
|
|
121
|
+
export interface WorkbenchSource {
|
|
122
|
+
ledger: LedgerState;
|
|
123
|
+
runs: readonly PptDeliveryRun[];
|
|
124
|
+
reviews: readonly HumanReviewRequest[];
|
|
125
|
+
reportRuns?: readonly ReportReviewRun[];
|
|
126
|
+
processRequests?: readonly ProcessRequest[];
|
|
127
|
+
actorId: string;
|
|
128
|
+
allowedOrigins?: readonly string[];
|
|
129
|
+
now?: number;
|
|
130
|
+
}
|
|
131
|
+
export type { AgentDraft, AgentRelease, WorkbenchAgentRow };
|
|
132
|
+
export interface WorkbenchSnapshot {
|
|
133
|
+
sourceId: string;
|
|
134
|
+
tasks: AcpTaskSummary[];
|
|
135
|
+
details: Record<string, AcpTaskDetail>;
|
|
136
|
+
}
|
|
137
|
+
export interface WorkbenchListQuery {
|
|
138
|
+
filter?: 'all' | 'pending' | 'working' | 'failed';
|
|
139
|
+
limit?: number;
|
|
140
|
+
offset?: number;
|
|
141
|
+
}
|
|
142
|
+
export declare function workbenchSnapshot(source: WorkbenchSource): WorkbenchSnapshot;
|
|
143
|
+
export declare function listWorkbenchTasks(snapshot: WorkbenchSnapshot, query?: WorkbenchListQuery): {
|
|
144
|
+
items: AcpTaskSummary[];
|
|
145
|
+
total: number;
|
|
146
|
+
counts: {
|
|
147
|
+
all: number;
|
|
148
|
+
pending: number;
|
|
149
|
+
working: number;
|
|
150
|
+
failed: number;
|
|
151
|
+
};
|
|
152
|
+
offset: number;
|
|
153
|
+
limit: number;
|
|
154
|
+
};
|
|
155
|
+
export declare function listWorkbenchAgents(snapshot: WorkbenchSnapshot, catalog: {
|
|
156
|
+
drafts: readonly AgentDraft[];
|
|
157
|
+
releases: readonly AgentRelease[];
|
|
158
|
+
}, residents?: readonly ResidentAgentRef[]): {
|
|
159
|
+
developing: WorkbenchAgentRow[];
|
|
160
|
+
published: WorkbenchAgentRow[];
|
|
161
|
+
};
|
|
162
|
+
export declare function getWorkbenchTask(snapshot: WorkbenchSnapshot, jobId: string): AcpTaskDetail;
|