@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,356 @@
|
|
|
1
|
+
import { deliveryProgress } from './delivery-progress.js';
|
|
2
|
+
import { projectProcessRequest } from './process-request.js';
|
|
3
|
+
import { describeTaskDevelopment, projectWorkbenchAgents } from './agent-registry.js';
|
|
4
|
+
const stageNames = { summary: '文稿生成', human_review: '人工审核', make: '设计制作', validate: '机器校验', review: '独立验收', finished: '交付完成' };
|
|
5
|
+
const purposeNames = { project_script: '文稿生成', ppt_production: '设计制作', independent_review: '独立验收' };
|
|
6
|
+
const terminal = new Set(['completed', 'failed', 'canceled', 'rejected']);
|
|
7
|
+
const stateDescriptions = { not_started: '等待开始执行。', submitted: '任务已提交,等待执行角色开始。', working: '执行角色正在处理任务。',
|
|
8
|
+
input_required: '任务等待补充输入。', auth_required: '任务等待完成认证。', completed: '执行已完成,可查看产物和执行记录。',
|
|
9
|
+
failed: '执行失败,请查看异常原因。', canceled: '任务已取消,已有产物与历史保留。', rejected: '执行请求未被接受。', unknown: '执行状态尚未确认,请核实执行宿主。' };
|
|
10
|
+
function runDescription(run) {
|
|
11
|
+
if (terminal.has(run.executionStatus))
|
|
12
|
+
return stateDescriptions[run.executionStatus];
|
|
13
|
+
if (run.stage === 'make' && !run.currentChild && !run.pending)
|
|
14
|
+
return '文字稿已确认,等待启动设计制作。';
|
|
15
|
+
return ({ summary: '文稿作者正在生成或修订文字稿。', make: '制作角色正在根据确认的文字稿设计 PPT。', validate: '正在检查制作产物的文件与结构。',
|
|
16
|
+
review: '独立验收角色正在核对事实和页面效果。', finished: '交付已完成,可查看最终产物。' })[run.stage];
|
|
17
|
+
}
|
|
18
|
+
function byNewest(items) { return items.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)); }
|
|
19
|
+
function latestReview(reviews, job) {
|
|
20
|
+
return byNewest(reviews.filter(r => r.jobId === job.jobId && r.attemptId === job.currentAttemptId).map(r => structuredClone(r)).reverse())[0];
|
|
21
|
+
}
|
|
22
|
+
function metadataText(value) {
|
|
23
|
+
if (typeof value !== 'string')
|
|
24
|
+
return undefined;
|
|
25
|
+
const text = value.trim();
|
|
26
|
+
return text && text.length <= 512 && !/[\u0000-\u001f\u007f]/.test(text) ? text : undefined;
|
|
27
|
+
}
|
|
28
|
+
function metadataObject(value) {
|
|
29
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
30
|
+
}
|
|
31
|
+
function serviceEndpoint(value) {
|
|
32
|
+
if (typeof value !== 'string' || value.length > 8192 || /[\u0000-\u001f\u007f]/.test(value))
|
|
33
|
+
return undefined;
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(value);
|
|
36
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
|
|
37
|
+
return undefined;
|
|
38
|
+
const host = metadataText(url.hostname.replace(/^\[|\]$/g, ''));
|
|
39
|
+
if (!host)
|
|
40
|
+
return undefined;
|
|
41
|
+
const locality = host === 'localhost' || host === '::1' || /^127\.(?:\d{1,3}\.){2}\d{1,3}$/.test(host) ? 'loopback' : 'network';
|
|
42
|
+
return { host, port: url.port ? Number(url.port) : url.protocol === 'https:' ? 443 : 80, locality };
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Separate a connection alias from the service this attempt was recorded against. */
|
|
49
|
+
function serviceView(attempt, snapshot, binding, workflow) {
|
|
50
|
+
const backend = attempt?.backendRunRef;
|
|
51
|
+
const connectionAlias = metadataText(backend?.remote) ?? metadataText(snapshot.remote);
|
|
52
|
+
const alias = connectionAlias ? { connectionAlias } : {};
|
|
53
|
+
const recordedWorkflow = workflow || backend?.provider === 'report_review' || backend?.provider === 'resident_role' && Boolean(metadataText(backend.runId));
|
|
54
|
+
if (recordedWorkflow || binding.driver === 'ppt_delivery')
|
|
55
|
+
return { kind: 'gateway_workflow', source: recordedWorkflow ? 'workflow_run' : 'target_snapshot', ...alias };
|
|
56
|
+
const provider = metadataText(backend?.provider) ?? metadataText(snapshot.provider) ?? metadataText(attempt?.provider);
|
|
57
|
+
const kind = provider === 'a2a' ? 'a2a' : provider === 'activepieces' ? 'activepieces' : 'unknown';
|
|
58
|
+
const actual = serviceEndpoint(backend?.endpoint), configured = serviceEndpoint(snapshot.endpoint);
|
|
59
|
+
return { kind, source: actual ? 'backend_run' : configured ? 'target_snapshot' : 'unrecorded', ...(actual ?? configured), ...alias };
|
|
60
|
+
}
|
|
61
|
+
/** Historical identities come only from this execution's frozen facts, never today's target directory. */
|
|
62
|
+
function executionView(attempt, targetId, workflow = false) {
|
|
63
|
+
const snapshot = attempt?.targetSnapshot ?? {}, binding = metadataObject(snapshot.binding);
|
|
64
|
+
const serviceInfo = serviceView(attempt, snapshot, binding, workflow);
|
|
65
|
+
const snapshotRole = metadataText(snapshot.roleId), bindingRole = metadataText(binding.roleId);
|
|
66
|
+
const roleConflict = Boolean(snapshotRole && bindingRole && snapshotRole !== bindingRole);
|
|
67
|
+
const roleId = roleConflict ? undefined : snapshotRole ?? bindingRole;
|
|
68
|
+
const hasRole = Boolean(snapshotRole || bindingRole);
|
|
69
|
+
const targetKind = metadataText(snapshot.targetKind);
|
|
70
|
+
let kind = 'unknown';
|
|
71
|
+
if (serviceInfo.kind === 'gateway_workflow' || targetKind === 'workflow')
|
|
72
|
+
kind = 'workflow';
|
|
73
|
+
else if (roleConflict || targetKind === 'agent_host' && hasRole)
|
|
74
|
+
kind = 'unknown';
|
|
75
|
+
else if (targetKind === 'resident_agent' || hasRole)
|
|
76
|
+
kind = 'resident';
|
|
77
|
+
else if (targetKind === 'agent_host' || targetId.startsWith('legacy:'))
|
|
78
|
+
kind = 'temporary';
|
|
79
|
+
const snapshotPreset = metadataText(snapshot.agentPreset), bindingPreset = metadataText(binding.agentPreset);
|
|
80
|
+
const presetConflict = Boolean(snapshotPreset && bindingPreset && snapshotPreset !== bindingPreset);
|
|
81
|
+
const presetUnusable = snapshot.agentPreset !== undefined && !snapshotPreset || binding.agentPreset !== undefined && !bindingPreset;
|
|
82
|
+
const hasFrozenTarget = Boolean(attempt && metadataText(snapshot.targetId) === targetId);
|
|
83
|
+
const agentPreset = kind === 'workflow' || presetConflict ? undefined : snapshotPreset ?? bindingPreset;
|
|
84
|
+
const presetStatus = kind === 'workflow' ? 'not_applicable'
|
|
85
|
+
: agentPreset ? 'recorded' : kind === 'temporary' && hasFrozenTarget && !presetConflict && !presetUnusable && snapshot.historicalConfigUnknown !== true ? 'host_default' : 'unknown';
|
|
86
|
+
const targetName = metadataText(snapshot.targetName), service = metadataText(snapshot.remote) ?? metadataText(attempt?.backendRunRef?.remote);
|
|
87
|
+
const provider = metadataText(snapshot.provider) ?? metadataText(attempt?.provider) ?? metadataText(attempt?.backendRunRef?.provider);
|
|
88
|
+
const connectionId = metadataText(snapshot.connectionId) ?? metadataText(attempt?.connectionId);
|
|
89
|
+
return { kind, targetId: metadataText(targetId) ?? '', presetStatus, serviceInfo,
|
|
90
|
+
...(targetName ? { targetName } : {}), ...(roleId ? { roleId } : {}), ...(agentPreset ? { agentPreset } : {}),
|
|
91
|
+
...(service ? { service } : {}), ...(provider ? { provider } : {}), ...(connectionId ? { connectionId } : {}) };
|
|
92
|
+
}
|
|
93
|
+
function safeArtifact(input) {
|
|
94
|
+
if (typeof input === 'string') {
|
|
95
|
+
try {
|
|
96
|
+
const url = new URL(input);
|
|
97
|
+
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password ? input : undefined;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!input || typeof input !== 'object')
|
|
104
|
+
return undefined;
|
|
105
|
+
const value = input;
|
|
106
|
+
// Path-only artifacts (no url) are listed by name/path without a link; a present but unsafe url is still dropped.
|
|
107
|
+
if (value.url !== undefined ? typeof value.url !== 'string' || !safeArtifact(value.url) : typeof value.path !== 'string')
|
|
108
|
+
return undefined;
|
|
109
|
+
const result = value.url !== undefined ? { url: value.url } : {};
|
|
110
|
+
for (const key of ['name', 'path', 'mediaType', 'size', 'sha256'])
|
|
111
|
+
if (['string', 'number'].includes(typeof value[key]))
|
|
112
|
+
result[key] = value[key];
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
function attemptView(attempt, workflow = false) {
|
|
116
|
+
const { input: _input, targetSnapshot: _snapshot, backendRunRef, ...view } = structuredClone(attempt);
|
|
117
|
+
const refs = {};
|
|
118
|
+
for (const key of ['provider', 'remote', 'taskId', 'contextId', 'sessionId', 'flowRunId', 'runId'])
|
|
119
|
+
if (typeof backendRunRef?.[key] === 'string')
|
|
120
|
+
refs[key] = backendRunRef[key];
|
|
121
|
+
for (const result of [view.result, ...view.resultHistory ?? []])
|
|
122
|
+
if (result) {
|
|
123
|
+
result.artifactLinks = result.artifactLinks.map(safeArtifact).filter(item => item !== undefined);
|
|
124
|
+
if (result.resultArtifacts)
|
|
125
|
+
result.resultArtifacts = result.resultArtifacts.map(safeArtifact).filter(item => item !== undefined);
|
|
126
|
+
delete result.structuredResultRef;
|
|
127
|
+
}
|
|
128
|
+
return { ...view, ...(Object.keys(refs).length ? { backendRunRef: refs } : {}), execution: executionView(attempt, attempt.targetId, workflow) };
|
|
129
|
+
}
|
|
130
|
+
function eventView(event) {
|
|
131
|
+
const clean = (value) => {
|
|
132
|
+
if (Array.isArray(value))
|
|
133
|
+
return value.map(clean);
|
|
134
|
+
if (value && typeof value === 'object')
|
|
135
|
+
return Object.fromEntries(Object.entries(value).filter(([key]) => !/token|password|secret|authorization|apiKey|input|prompt|endpoint/i.test(key)).map(([key, item]) => [key, clean(item)]));
|
|
136
|
+
return value;
|
|
137
|
+
};
|
|
138
|
+
return { ...structuredClone(event), ...(event.data === undefined ? {} : { data: clean(event.data) }) };
|
|
139
|
+
}
|
|
140
|
+
function progress(job, run, reviews, attempt, now) {
|
|
141
|
+
if (!run) {
|
|
142
|
+
const name = purposeNames[job.purpose ?? ''] ?? '任务执行', status = attempt?.executionStatus ?? job.executionStatus;
|
|
143
|
+
return { stage: job.purpose ?? 'execution', phase: attempt?.phase ?? '', stages: [{ stage: job.purpose ?? 'execution', name, status, planned: false, jobId: job.jobId, attemptId: job.currentAttemptId }],
|
|
144
|
+
completedStages: status === 'completed' ? [name] : [], remainingStages: status === 'completed' ? [] : [name], updatedAt: job.updatedAt };
|
|
145
|
+
}
|
|
146
|
+
const review = latestReview(reviews, job), latest = (purpose) => [...run.children].reverse().find(child => child.purpose === purpose);
|
|
147
|
+
const script = latest('project_script'), maker = latest('ppt_production'), reviewer = latest('independent_review');
|
|
148
|
+
const stage = (key, child, status) => ({ stage: key, name: stageNames[key], status: status ?? child?.child.executionStatus ?? 'not_started',
|
|
149
|
+
planned: !child, ...(child ? { jobId: child.child.jobId, attemptId: child.child.attemptId } : {}) });
|
|
150
|
+
const stages = [stage('summary', script)];
|
|
151
|
+
const human = run;
|
|
152
|
+
const requireReview = run.policy.requireHumanReview;
|
|
153
|
+
if (review || requireReview)
|
|
154
|
+
stages.push({ stage: 'human_review', name: stageNames.human_review, status: review?.status ?? 'not_started', planned: !review, jobId: job.jobId, attemptId: job.currentAttemptId });
|
|
155
|
+
stages.push(stage('make', maker), { stage: 'validate', name: stageNames.validate, status: run.validation ? 'completed' : run.stage === 'validate' ? run.executionStatus : 'not_started', planned: !run.validation && run.stage !== 'validate' }, stage('review', reviewer, run.review?.verdict === 'passed' ? 'completed' : run.review?.verdict === 'changes_requested' ? 'changes_requested' : reviewer?.child.executionStatus));
|
|
156
|
+
const complete = (s) => ['completed', 'approved'].includes(s.status);
|
|
157
|
+
return { stage: review?.status === 'pending' && !terminal.has(job.executionStatus) && !terminal.has(run.executionStatus) ? 'human_review' : run.stage, phase: run.phase, stages,
|
|
158
|
+
completedStages: stages.filter(complete).map(s => s.name), remainingStages: stages.filter(s => !complete(s)).map(s => s.name),
|
|
159
|
+
executionElapsedMs: run.metrics.elapsedMs, humanWaitingMs: (human.humanWaitingMs ?? 0) + (human.humanWaitStartedAt && Number.isFinite(Date.parse(human.humanWaitStartedAt)) ? Math.max(0, now - Date.parse(human.humanWaitStartedAt)) : 0),
|
|
160
|
+
availableResults: deliveryProgress(run).availableResults, updatedAt: run.updatedAt };
|
|
161
|
+
}
|
|
162
|
+
function pendingProcessRequest(requests, job, now) {
|
|
163
|
+
return requests.filter(request => request.jobId === job.jobId && request.attemptId === job.currentAttemptId)
|
|
164
|
+
.map(request => projectProcessRequest(request, now)).filter(request => request.status === 'pending')
|
|
165
|
+
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))[0];
|
|
166
|
+
}
|
|
167
|
+
/** Same rule as the ledger view: acceptance counts only for the current completed result revision and digest. */
|
|
168
|
+
function currentAcceptance(job, ledger) {
|
|
169
|
+
const attempt = ledger.attempts[job.currentAttemptId], result = attempt?.result;
|
|
170
|
+
if (attempt?.executionStatus !== 'completed' || !result?.resultAvailable)
|
|
171
|
+
return undefined;
|
|
172
|
+
return (ledger.acceptances[job.jobId] ?? []).findLast(item => item.attemptId === attempt.attemptId
|
|
173
|
+
&& item.resultRevision === result.resultRevision && item.resultDigest === result.resultDigest);
|
|
174
|
+
}
|
|
175
|
+
/** A tool is blocked when its latest request was not approved; an agent's retry that a person allowed clears it. */
|
|
176
|
+
function blockedTools(requests, job, now) {
|
|
177
|
+
if (job.executionStatus !== 'completed')
|
|
178
|
+
return [];
|
|
179
|
+
const latest = new Map();
|
|
180
|
+
for (const request of requests.filter(request => request.kind === 'permission' && request.jobId === job.jobId && request.attemptId === job.currentAttemptId)
|
|
181
|
+
.map(request => projectProcessRequest(request, now)).sort((a, b) => a.createdAt.localeCompare(b.createdAt))) {
|
|
182
|
+
latest.set(JSON.stringify([request.toolTitle ?? '', request.toolDetail ?? '']), request);
|
|
183
|
+
}
|
|
184
|
+
return [...latest.values()].filter(request => request.answer?.outcome !== 'approved')
|
|
185
|
+
.map(request => request.toolTitle ?? '').filter((name, index, all) => name && all.indexOf(name) === index);
|
|
186
|
+
}
|
|
187
|
+
function summary(job, run, reviews, ledger, actorId, requests, now) {
|
|
188
|
+
const attempt = ledger.attempts[job.currentAttemptId], review = latestReview(reviews, job), pending = review?.status === 'pending' && !terminal.has(job.executionStatus) && (!run || !terminal.has(run.executionStatus));
|
|
189
|
+
const pendingRequest = terminal.has(job.executionStatus) ? undefined : pendingProcessRequest(requests, job, now);
|
|
190
|
+
const awaitingResume = review?.resume?.status === 'pending' && !terminal.has(job.executionStatus);
|
|
191
|
+
const resumeError = awaitingResume ? run?.diagnostics?.findLast(item => item.startsWith('Human continuation deferred:')) : undefined;
|
|
192
|
+
const acceptance = currentAcceptance(job, ledger), blocked = blockedTools(requests, job, now);
|
|
193
|
+
const toolBlocked = blocked.length > 0 && acceptance?.reviewStatus !== 'accepted';
|
|
194
|
+
const unwatched = attempt?.unwatched && !terminal.has(job.executionStatus) ? attempt.unwatched : undefined;
|
|
195
|
+
const displayStatus = toolBlocked ? 'tool_blocked' : pending || pendingRequest ? 'awaiting_human' : unwatched ? 'unwatched' : awaitingResume && !resumeError ? 'resuming' : review?.status === 'changes_requested' && !terminal.has(job.executionStatus) ? 'changes_requested' : job.executionStatus;
|
|
196
|
+
const phase = pending ? 'human_review' : pendingRequest ? 'process_request' : awaitingResume ? 'human_resume' : run?.phase ?? attempt?.phase ?? job.purpose ?? '';
|
|
197
|
+
const progressSummary = pending ? `${review.title}已形成,等待确认 ${review.revision};通过后开始设计制作。`
|
|
198
|
+
: pendingRequest ? (pendingRequest.kind === 'plan' ? '计划待批准,请在过程请求里提交。' : pendingRequest.kind === 'permission' ? `工具「${pendingRequest.toolTitle}」待批准,请在过程请求里提交。` : '有待回答的问题,请在过程请求里提交。')
|
|
199
|
+
: awaitingResume ? resumeError ? `决定已保存,继续执行受阻:${resumeError.slice('Human continuation deferred:'.length).trim()}` : '本版决定已保存,等待系统继续处理。'
|
|
200
|
+
: review?.status === 'changes_requested' && !terminal.has(job.executionStatus) ? run?.summaryRevisionPending ? '修改意见已保存,正在提交原作者。' : '修改意见已提交原作者,等待新版本。'
|
|
201
|
+
: toolBlocked ? `执行已结束,但有 ${blocked.length} 个工具调用未获批准,结果可能不完整,请核对后再验收。`
|
|
202
|
+
: unwatched ? `发起方在 ${unwatched.at} 停止等待(${unwatched.reason})。任务可能仍在执行或已经结束,请重新查询执行宿主。`
|
|
203
|
+
: attempt?.diagnostic || (run ? runDescription(run) : attempt?.result?.resultSummary || stateDescriptions[job.executionStatus] || '等待同步执行进展。');
|
|
204
|
+
const execution = executionView(attempt, job.targetId, Boolean(run));
|
|
205
|
+
const development = describeTaskDevelopment(attempt?.targetSnapshot?.development, { targetId: job.targetId, resident: execution.kind === 'resident', residentName: execution.targetName });
|
|
206
|
+
return { sourceId: job.sourceId, jobId: job.jobId, title: job.title ?? `${purposeNames[job.purpose ?? ''] ?? '执行任务'} ${job.jobId.slice(0, 8)}`,
|
|
207
|
+
channel: development.channel, ...(development.agentId ? { agentId: development.agentId, agentName: development.name, agentPhase: development.phase } : {}),
|
|
208
|
+
originSessionId: job.originSessionId, ...(job.parentJobRef ? { parentJobRef: job.parentJobRef } : {}), ...(job.parentAttemptId ? { parentAttemptId: job.parentAttemptId } : {}),
|
|
209
|
+
...(job.purpose ? { purpose: job.purpose } : {}), targetId: job.targetId, currentAttemptId: job.currentAttemptId, executionStatus: job.executionStatus, displayStatus, phase,
|
|
210
|
+
createdAt: job.createdAt, updatedAt: [job.updatedAt, review?.updatedAt, pendingRequest?.updatedAt].filter((value) => Boolean(value)).sort().at(-1), stale: attempt?.stale ?? true,
|
|
211
|
+
inFlightAttemptIds: [...job.inFlightAttemptIds], unresolvedAttemptIds: [...job.unresolvedAttemptIds], execution,
|
|
212
|
+
...(review ? { reviewStatus: review.status } : {}), ...(pending && review.reviewerId === actorId ? { pendingReviewId: review.reviewId } : {}),
|
|
213
|
+
...(pendingRequest ? { pendingProcessRequestId: pendingRequest.requestId } : {}), progressSummary,
|
|
214
|
+
...(acceptance ? { businessAcceptance: structuredClone(acceptance) } : {}), ...(blocked.length ? { blockedTools: blocked } : {}),
|
|
215
|
+
...(job.executionStatus === 'failed' && !run && !job.parentJobRef && !job.unresolvedAttemptIds.length ? { canContinue: true } : {}),
|
|
216
|
+
...(job.executionStatus === 'completed' && !run && !job.parentJobRef && !acceptance && attempt?.result?.resultAvailable && attempt.result.resultRevision && attempt.result.resultDigest ? { canAccept: true } : {}),
|
|
217
|
+
...(job.initiatedBy ? { initiatedBy: job.initiatedBy } : {}) };
|
|
218
|
+
}
|
|
219
|
+
function bubbleProcessWait(summaries) {
|
|
220
|
+
const tasks = [...summaries.values()];
|
|
221
|
+
for (let depth = 0; depth < 5; depth++) {
|
|
222
|
+
let changed = false;
|
|
223
|
+
for (const task of tasks) {
|
|
224
|
+
if (task.pendingReviewId || task.pendingProcessRequestId || terminal.has(task.executionStatus))
|
|
225
|
+
continue;
|
|
226
|
+
const child = tasks.filter(item => item.parentJobRef?.jobId === task.jobId && item.pendingProcessRequestId).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))[0];
|
|
227
|
+
if (!child?.pendingProcessRequestId)
|
|
228
|
+
continue;
|
|
229
|
+
task.pendingProcessRequestId = child.pendingProcessRequestId;
|
|
230
|
+
if (!['awaiting_human', 'resuming', 'changes_requested'].includes(task.displayStatus)) {
|
|
231
|
+
task.displayStatus = 'awaiting_human';
|
|
232
|
+
task.phase = 'process_request';
|
|
233
|
+
task.progressSummary = child.progressSummary;
|
|
234
|
+
if (child.updatedAt > task.updatedAt)
|
|
235
|
+
task.updatedAt = child.updatedAt;
|
|
236
|
+
}
|
|
237
|
+
changed = true;
|
|
238
|
+
}
|
|
239
|
+
if (!changed)
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
export function workbenchSnapshot(source) {
|
|
244
|
+
const { ledger, actorId } = source, allowed = source.allowedOrigins ? new Set(source.allowedOrigins) : undefined;
|
|
245
|
+
const jobs = Object.values(ledger.jobs).filter(job => !allowed || allowed.has(job.originSessionId));
|
|
246
|
+
const visible = new Set(jobs.map(job => job.jobId)), runFor = (job) => source.runs.find(run => run.jobId === job.jobId && run.attemptId === job.currentAttemptId);
|
|
247
|
+
const now = source.now ?? Date.now();
|
|
248
|
+
const summaries = new Map(jobs.map(job => [job.jobId, summary(job, runFor(job), source.reviews, ledger, actorId, source.processRequests ?? [], now)]));
|
|
249
|
+
bubbleProcessWait(summaries);
|
|
250
|
+
const details = {};
|
|
251
|
+
for (const job of jobs) {
|
|
252
|
+
const run = runFor(job), ownReviews = source.reviews.filter(r => r.jobId === job.jobId || r.authorJobId === job.jobId && visible.has(r.jobId));
|
|
253
|
+
const ancestors = [], visited = new Set([job.jobId]);
|
|
254
|
+
let parent = job.parentJobRef;
|
|
255
|
+
while (parent?.sourceId === ledger.sourceId && visible.has(parent.jobId) && !visited.has(parent.jobId)) {
|
|
256
|
+
visited.add(parent.jobId);
|
|
257
|
+
ancestors.unshift(summaries.get(parent.jobId));
|
|
258
|
+
parent = ledger.jobs[parent.jobId]?.parentJobRef;
|
|
259
|
+
}
|
|
260
|
+
const children = jobs.filter(child => child.parentJobRef?.sourceId === ledger.sourceId && child.parentJobRef.jobId === job.jobId).map(child => summaries.get(child.jobId));
|
|
261
|
+
const dependencies = children.map(child => ({ from: job.jobId, to: child.jobId, kind: 'parent', label: '子任务', parentAttemptId: child.parentAttemptId }));
|
|
262
|
+
if (job.parentJobRef?.sourceId === ledger.sourceId && visible.has(job.parentJobRef.jobId))
|
|
263
|
+
dependencies.unshift({ from: job.parentJobRef.jobId, to: job.jobId, kind: 'parent', label: '子任务', parentAttemptId: job.parentAttemptId });
|
|
264
|
+
for (const related of jobs.filter(item => item.jobId === job.jobId || item.parentJobRef?.jobId === job.jobId)) {
|
|
265
|
+
if (related.replacesJobRef?.sourceId === ledger.sourceId && visible.has(related.replacesJobRef.jobId))
|
|
266
|
+
dependencies.push({ from: related.replacesJobRef.jobId, to: related.jobId, kind: 'replaces', label: '接替执行' });
|
|
267
|
+
}
|
|
268
|
+
// Only this explicit domain workflow supplies ordering. Parent refs alone never imply dependencies.
|
|
269
|
+
if (run) {
|
|
270
|
+
const last = (purpose) => [...run.children].reverse().find(item => item.purpose === purpose)?.child.jobId;
|
|
271
|
+
const chain = [last('project_script'), last('ppt_production'), last('independent_review')].filter((id) => Boolean(id && visible.has(id)));
|
|
272
|
+
for (let index = 1; index < chain.length; index++)
|
|
273
|
+
dependencies.push({ from: chain[index - 1], to: chain[index], kind: 'depends_on', label: '阶段依赖' });
|
|
274
|
+
}
|
|
275
|
+
const artifacts = [];
|
|
276
|
+
for (const item of [...(run?.artifactHistory ?? []), ...(run?.validation ? [{ revision: run.revision, validation: run.validation }] : [])]) {
|
|
277
|
+
if (!artifacts.some(a => a.revision === `revision-${item.revision}` && a.digest === item.validation.artifactDigest))
|
|
278
|
+
artifacts.push({ revision: `revision-${item.revision}`, digest: item.validation.artifactDigest, artifacts: item.validation.artifacts.map(safeArtifact).filter(a => a !== undefined) });
|
|
279
|
+
}
|
|
280
|
+
const attempts = Object.values(ledger.attempts).filter(attempt => attempt.jobId === job.jobId)
|
|
281
|
+
.map(attempt => attemptView(attempt, source.runs.some(item => item.jobId === job.jobId && item.attemptId === attempt.attemptId)));
|
|
282
|
+
if (!run)
|
|
283
|
+
for (const attempt of attempts) {
|
|
284
|
+
const pathOnly = (attempt.result?.resultArtifacts ?? []).filter(item => !item.url);
|
|
285
|
+
const links = [...(attempt.result?.artifactLinks ?? []), ...pathOnly];
|
|
286
|
+
if (links.length)
|
|
287
|
+
artifacts.push({ revision: attempt.result.resultRevision ?? attempt.attemptId, digest: attempt.result.resultDigest, artifacts: links });
|
|
288
|
+
}
|
|
289
|
+
const humanEvents = ownReviews.flatMap(review => review.history.map((decision, index) => ({ eventId: decision.decisionId, sourceId: ledger.sourceId, sequence: -(index + 1), jobId: review.jobId,
|
|
290
|
+
attemptId: review.attemptId, jobVersion: 0, type: `human_review.${decision.action}`, observedAt: decision.at,
|
|
291
|
+
data: { reviewId: review.reviewId, revision: review.revision, actor: decision.actor, ...(decision.note ? { note: decision.note } : {}) } })));
|
|
292
|
+
const asked = Object.values(ledger.attempts).filter(attempt => attempt.jobId === job.jobId)
|
|
293
|
+
.sort((a, b) => (a.createdAt ?? '').localeCompare(b.createdAt ?? ''))[0]?.input;
|
|
294
|
+
const description = typeof asked?.prompt === 'string' && asked.prompt.trim() ? asked.prompt.slice(0, 20_000) : undefined;
|
|
295
|
+
details[job.jobId] = { ...summaries.get(job.jobId), ...(description ? { description } : {}), attempts, children, ancestors, progress: progress(job, run, source.reviews, ledger.attempts[job.currentAttemptId], source.now ?? Date.now()),
|
|
296
|
+
processRequests: (source.processRequests ?? []).filter(request => request.jobId === job.jobId || children.some(child => child.jobId === request.jobId)).map(request => {
|
|
297
|
+
const projected = projectProcessRequest(request, now);
|
|
298
|
+
const owner = ledger.jobs[request.jobId];
|
|
299
|
+
return { ...projected, canAnswer: projected.status === 'pending' && owner?.currentAttemptId === request.attemptId && !terminal.has(owner.executionStatus) };
|
|
300
|
+
}),
|
|
301
|
+
reviews: ownReviews.map(review => {
|
|
302
|
+
const ownerRun = source.runs.find(item => item.jobId === review.jobId && item.attemptId === review.attemptId);
|
|
303
|
+
const resumeError = review.resume?.status === 'pending' ? ownerRun?.diagnostics?.findLast(item => item.startsWith('Human continuation deferred:')) : undefined;
|
|
304
|
+
return { ...structuredClone(review), canReview: review.status === 'pending' && review.reviewerId === actorId && ledger.jobs[review.jobId]?.currentAttemptId === review.attemptId && !terminal.has(ledger.jobs[review.jobId].executionStatus)
|
|
305
|
+
&& !ownerRun?.cancellationRequestedAt && (!ownerRun || !terminal.has(ownerRun.executionStatus))
|
|
306
|
+
&& latestReview(source.reviews, ledger.jobs[review.jobId])?.reviewId === review.reviewId,
|
|
307
|
+
...(review.resume ? { resumeStatus: review.resume.status } : {}), ...(resumeError ? { resumeError: resumeError.slice('Human continuation deferred:'.length).trim() } : {}) };
|
|
308
|
+
}),
|
|
309
|
+
events: [...ledger.events.filter(event => event.jobId === job.jobId).map(eventView), ...humanEvents].sort((a, b) => a.observedAt.localeCompare(b.observedAt)), dependencies, artifacts };
|
|
310
|
+
}
|
|
311
|
+
for (const report of source.reportRuns ?? []) {
|
|
312
|
+
const detail = details[report.jobId], task = summaries.get(report.jobId);
|
|
313
|
+
if (!detail || !task || detail.currentAttemptId !== report.attemptId)
|
|
314
|
+
continue;
|
|
315
|
+
delete task.canContinue;
|
|
316
|
+
delete detail.canContinue;
|
|
317
|
+
delete task.canAccept;
|
|
318
|
+
delete detail.canAccept;
|
|
319
|
+
const pending = report.humanReviews.at(-1), author = report.child;
|
|
320
|
+
const stages = [
|
|
321
|
+
{ stage: 'research', name: '临时智能体分析', status: author ? ledger.attempts[author.attemptId]?.executionStatus ?? 'unknown' : 'not_started', planned: !author,
|
|
322
|
+
...(author ? { jobId: author.jobId, attemptId: author.attemptId } : {}) },
|
|
323
|
+
{ stage: 'file_check', name: '报告文件检查', status: report.fileCheck ? report.fileCheck.passed ? 'completed' : 'failed' : 'not_started', planned: !report.fileCheck },
|
|
324
|
+
{ stage: 'human_review', name: '人工最终确认', status: pending?.status ?? 'not_started', planned: !pending, jobId: report.jobId, attemptId: report.attemptId },
|
|
325
|
+
];
|
|
326
|
+
if (!detail.pendingProcessRequestId) {
|
|
327
|
+
task.progressSummary = report.resultSummary ?? '临时智能体正在分析项目,输出报告后进行文件检查与人工最终确认。';
|
|
328
|
+
detail.progressSummary = task.progressSummary;
|
|
329
|
+
}
|
|
330
|
+
detail.progress = { stage: report.stage, phase: report.phase, stages,
|
|
331
|
+
completedStages: stages.filter(stage => ['completed', 'approved'].includes(stage.status)).map(stage => stage.name),
|
|
332
|
+
remainingStages: stages.filter(stage => !['completed', 'approved'].includes(stage.status)).map(stage => stage.name), updatedAt: report.updatedAt };
|
|
333
|
+
}
|
|
334
|
+
return structuredClone({ sourceId: ledger.sourceId, tasks: byNewest([...summaries.values()]), details });
|
|
335
|
+
}
|
|
336
|
+
export function listWorkbenchTasks(snapshot, query = {}) {
|
|
337
|
+
const filter = query.filter ?? 'all', offset = Math.max(0, Math.trunc(query.offset ?? 0)), limit = Math.min(200, Math.max(1, Math.trunc(query.limit ?? 50)));
|
|
338
|
+
const rootIds = new Set(snapshot.tasks.filter(task => !task.parentJobRef || !Object.hasOwn(snapshot.details, task.parentJobRef.jobId)).map(task => task.jobId));
|
|
339
|
+
const needsPerson = (task) => Boolean(task.pendingReviewId || task.pendingProcessRequestId);
|
|
340
|
+
const isWorking = (task) => task.displayStatus === 'resuming' || !needsPerson(task) && task.displayStatus !== 'unwatched' && ['working', 'submitted', 'not_started'].includes(task.executionStatus);
|
|
341
|
+
const isFailed = (task) => task.unresolvedAttemptIds.length > 0 || task.displayStatus === 'tool_blocked' || task.displayStatus === 'unwatched' || ['failed', 'rejected', 'unknown', 'auth_required', 'input_required'].includes(task.executionStatus) && !['awaiting_human', 'resuming'].includes(task.displayStatus);
|
|
342
|
+
const roots = snapshot.tasks.filter(task => rootIds.has(task.jobId));
|
|
343
|
+
const counts = { all: roots.length, pending: roots.filter(needsPerson).length, working: roots.filter(isWorking).length, failed: roots.filter(isFailed).length };
|
|
344
|
+
const matches = snapshot.tasks.filter(task => filter === 'all' ? true : filter === 'pending' ? needsPerson(task) : filter === 'working' ? isWorking(task) : isFailed(task));
|
|
345
|
+
return { items: structuredClone(matches.slice(offset, offset + limit)), total: matches.length, counts, offset, limit };
|
|
346
|
+
}
|
|
347
|
+
export function listWorkbenchAgents(snapshot, catalog, residents = []) {
|
|
348
|
+
const tasks = snapshot.tasks.map(task => ({ ...(task.agentId ? { agentId: task.agentId } : {}), ...(task.pendingReviewId ? { pendingReviewId: task.pendingReviewId } : {}), ...(task.pendingProcessRequestId ? { pendingProcessRequestId: task.pendingProcessRequestId } : {}) }));
|
|
349
|
+
return projectWorkbenchAgents({ ...catalog, residents }, tasks);
|
|
350
|
+
}
|
|
351
|
+
export function getWorkbenchTask(snapshot, jobId) {
|
|
352
|
+
const detail = Object.hasOwn(snapshot.details, jobId) ? snapshot.details[jobId] : undefined;
|
|
353
|
+
if (!detail)
|
|
354
|
+
throw new Error('Task not found in authorized scope');
|
|
355
|
+
return structuredClone(detail);
|
|
356
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -10,3 +10,7 @@ export type { ServerOptions } from './server.js';
|
|
|
10
10
|
export { attachBridgeServer, activeSessions, sessionBackgroundTasks, killAllManagedAgents } from './bridge.js';
|
|
11
11
|
export { discoverAgents } from './catalog.js';
|
|
12
12
|
export type { AgentStatus, DiscoveryOptions } from './catalog.js';
|
|
13
|
+
export { CapacityGovernor, CapacityError } from './capacity.js';
|
|
14
|
+
export type { CapacityOptions, CapacityLease, CapacitySnapshot } from './capacity.js';
|
|
15
|
+
export { createCapacityLifecycle } from './capacity-lifecycle.js';
|
|
16
|
+
export { CapacityQueue } from './capacity-queue.js';
|
package/dist/src/index.js
CHANGED
|
@@ -7,3 +7,6 @@ export { buildManifest, ACP_CAPABILITIES, DEFAULT_ACP_PORT } from './manifest.js
|
|
|
7
7
|
export { createAcpServer, serveAcpService } from './server.js';
|
|
8
8
|
export { attachBridgeServer, activeSessions, sessionBackgroundTasks, killAllManagedAgents } from './bridge.js';
|
|
9
9
|
export { discoverAgents } from './catalog.js';
|
|
10
|
+
export { CapacityGovernor, CapacityError } from './capacity.js';
|
|
11
|
+
export { createCapacityLifecycle } from './capacity-lifecycle.js';
|
|
12
|
+
export { CapacityQueue } from './capacity-queue.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveRoleSkills, roleSkillProfileSchema, roleSkillLockSchema, skillContentRevision, type RoleSkillProfile, type RoleSkillLock } from './skills.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveRoleSkills, roleSkillProfileSchema, roleSkillLockSchema, skillContentRevision } from './skills.js';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const roleSkillProfileSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
version: z.ZodString;
|
|
5
|
+
instructionsPath: z.ZodOptional<z.ZodString>;
|
|
6
|
+
network: z.ZodObject<{
|
|
7
|
+
agentUrl: z.ZodString;
|
|
8
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
skills: z.ZodArray<z.ZodObject<{
|
|
11
|
+
key: z.ZodString;
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
nodeUrl: z.ZodOptional<z.ZodString>;
|
|
14
|
+
skillId: z.ZodOptional<z.ZodString>;
|
|
15
|
+
sourceId: z.ZodOptional<z.ZodString>;
|
|
16
|
+
assetsManifest: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strict>>;
|
|
18
|
+
entrySkill: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
export type RoleSkillProfile = z.infer<typeof roleSkillProfileSchema>;
|
|
21
|
+
export declare const roleSkillLockSchema: z.ZodObject<{
|
|
22
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
23
|
+
roleId: z.ZodString;
|
|
24
|
+
roleVersion: z.ZodString;
|
|
25
|
+
profilePath: z.ZodString;
|
|
26
|
+
profileSha256: z.ZodString;
|
|
27
|
+
cacheRoot: z.ZodString;
|
|
28
|
+
roleDirectory: z.ZodString;
|
|
29
|
+
createdAt: z.ZodString;
|
|
30
|
+
instructionsPath: z.ZodOptional<z.ZodString>;
|
|
31
|
+
instructionsSha256: z.ZodOptional<z.ZodString>;
|
|
32
|
+
instructionsBytes: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
entrySkill: z.ZodOptional<z.ZodString>;
|
|
34
|
+
entryGuidePath: z.ZodOptional<z.ZodString>;
|
|
35
|
+
skills: z.ZodArray<z.ZodObject<{
|
|
36
|
+
key: z.ZodString;
|
|
37
|
+
nodeUrl: z.ZodString;
|
|
38
|
+
skillId: z.ZodString;
|
|
39
|
+
sourceId: z.ZodString;
|
|
40
|
+
name: z.ZodString;
|
|
41
|
+
revision: z.ZodString;
|
|
42
|
+
cacheDirectory: z.ZodString;
|
|
43
|
+
directory: z.ZodString;
|
|
44
|
+
guidePath: z.ZodString;
|
|
45
|
+
guideResource: z.ZodString;
|
|
46
|
+
files: z.ZodArray<z.ZodObject<{
|
|
47
|
+
path: z.ZodString;
|
|
48
|
+
bytes: z.ZodNumber;
|
|
49
|
+
sha256: z.ZodString;
|
|
50
|
+
}, z.core.$strict>>;
|
|
51
|
+
assets: z.ZodArray<z.ZodObject<{
|
|
52
|
+
path: z.ZodString;
|
|
53
|
+
bytes: z.ZodNumber;
|
|
54
|
+
sha256: z.ZodString;
|
|
55
|
+
url: z.ZodString;
|
|
56
|
+
}, z.core.$strict>>;
|
|
57
|
+
}, z.core.$strict>>;
|
|
58
|
+
}, z.core.$strict>;
|
|
59
|
+
export type RoleSkillLock = z.infer<typeof roleSkillLockSchema>;
|
|
60
|
+
/** Same content revision as Skill Manager: paths sorted by UTF-8 bytes, then path\0length\0 + file bytes. */
|
|
61
|
+
export declare function skillContentRevision(files: {
|
|
62
|
+
path: string;
|
|
63
|
+
bytes: Uint8Array;
|
|
64
|
+
}[]): string;
|
|
65
|
+
/** New lock => latest catalogue revisions; existing lock => checked, fully offline reuse even if the source/profile changed. */
|
|
66
|
+
export declare function resolveRoleSkills(options: {
|
|
67
|
+
profilePath: string;
|
|
68
|
+
cacheRoot: string;
|
|
69
|
+
lockPath: string;
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
}): Promise<RoleSkillLock>;
|