@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
package/dist/src/a2a/store.js
CHANGED
|
@@ -6,6 +6,7 @@ import { InMemoryTaskStore, resolveUserScope, ServerCallContext, } from '@a2a-js
|
|
|
6
6
|
import { RequestMalformedError } from '@a2a-js/sdk/errors';
|
|
7
7
|
import { toSafeError } from '@1agents/acp-service/runtime';
|
|
8
8
|
import { DirectoryLease } from './lease.js';
|
|
9
|
+
import { a2aRoleSkillsSchema } from './types.js';
|
|
9
10
|
import { a2aPreflightReportSchema } from './preflight.js';
|
|
10
11
|
const terminalStates = new Set([
|
|
11
12
|
TaskState.TASK_STATE_COMPLETED, TaskState.TASK_STATE_FAILED,
|
|
@@ -66,6 +67,7 @@ function parseTask(value) {
|
|
|
66
67
|
text(artifact.artifactId, 'artifact ID');
|
|
67
68
|
return task;
|
|
68
69
|
}
|
|
70
|
+
const targetStates = new Set(['attached', 'busy', 'idle', 'closing', 'closed', 'stale', 'deleted']);
|
|
69
71
|
function parseTarget(value) {
|
|
70
72
|
const source = record(value, 'target');
|
|
71
73
|
const sessionId = text(source.sessionId, 'session ID');
|
|
@@ -74,7 +76,57 @@ function parseTarget(value) {
|
|
|
74
76
|
throw new Error('Invalid A2A working directory: expected an absolute path');
|
|
75
77
|
const agentPreset = source.agentPreset === undefined ? undefined : text(source.agentPreset, 'agent preset');
|
|
76
78
|
const preflight = source.preflight === undefined ? undefined : a2aPreflightReportSchema.parse(source.preflight);
|
|
77
|
-
|
|
79
|
+
const roleSkills = source.roleSkills === undefined ? undefined : a2aRoleSkillsSchema.parse(source.roleSkills);
|
|
80
|
+
const roleId = source.roleId === undefined ? undefined : text(source.roleId, 'role identity');
|
|
81
|
+
const provider = source.provider === undefined ? undefined : text(source.provider, 'model provider');
|
|
82
|
+
const model = source.model === undefined ? undefined : text(source.model, 'model');
|
|
83
|
+
if ((provider !== undefined) !== (model !== undefined))
|
|
84
|
+
throw new Error('A2A model provider and model must be stored together');
|
|
85
|
+
if ((roleId !== undefined) !== (roleSkills !== undefined))
|
|
86
|
+
throw new Error('A2A role identity and skill lock must be stored together');
|
|
87
|
+
let state;
|
|
88
|
+
if (source.state !== undefined) {
|
|
89
|
+
if (typeof source.state !== 'string' || !targetStates.has(source.state))
|
|
90
|
+
throw new Error('Invalid A2A target state');
|
|
91
|
+
state = source.state;
|
|
92
|
+
}
|
|
93
|
+
let lastUsedAt;
|
|
94
|
+
if (source.lastUsedAt !== undefined) {
|
|
95
|
+
lastUsedAt = text(source.lastUsedAt, 'last used time');
|
|
96
|
+
if (!Number.isFinite(Date.parse(lastUsedAt)))
|
|
97
|
+
throw new Error('Invalid A2A target last used time');
|
|
98
|
+
}
|
|
99
|
+
let resumed;
|
|
100
|
+
if (source.resumed !== undefined) {
|
|
101
|
+
if (typeof source.resumed !== 'boolean')
|
|
102
|
+
throw new Error('Invalid A2A resume marker');
|
|
103
|
+
resumed = source.resumed;
|
|
104
|
+
}
|
|
105
|
+
let restoreMethod;
|
|
106
|
+
if (source.restoreMethod !== undefined) {
|
|
107
|
+
if (source.restoreMethod !== 'session/load' && source.restoreMethod !== 'session/resume')
|
|
108
|
+
throw new Error('Invalid A2A restore method');
|
|
109
|
+
restoreMethod = source.restoreMethod;
|
|
110
|
+
}
|
|
111
|
+
let lifecycle;
|
|
112
|
+
if (source.lifecycle !== undefined) {
|
|
113
|
+
const policy = record(source.lifecycle, 'target lifecycle');
|
|
114
|
+
if (policy.mode !== 'persistent' && policy.mode !== 'one-shot')
|
|
115
|
+
throw new Error('Invalid A2A target lifecycle');
|
|
116
|
+
if (policy.idleTtlSeconds !== undefined && (!Number.isSafeInteger(policy.idleTtlSeconds) || policy.idleTtlSeconds < 0)) {
|
|
117
|
+
throw new Error('Invalid A2A target idle TTL');
|
|
118
|
+
}
|
|
119
|
+
if (policy.closeAfter !== undefined && policy.closeAfter !== 'terminal' && policy.closeAfter !== 'ack') {
|
|
120
|
+
throw new Error('Invalid A2A target close timing');
|
|
121
|
+
}
|
|
122
|
+
lifecycle = { mode: policy.mode, ...(policy.idleTtlSeconds === undefined ? {} : { idleTtlSeconds: policy.idleTtlSeconds }),
|
|
123
|
+
...(policy.closeAfter === undefined ? {} : { closeAfter: policy.closeAfter }) };
|
|
124
|
+
}
|
|
125
|
+
return { sessionId, cwd, ...(agentPreset === undefined ? {} : { agentPreset }), ...(preflight === undefined ? {} : { preflight }),
|
|
126
|
+
...(roleSkills === undefined ? {} : { roleId, roleSkills }), ...(state === undefined ? {} : { state }),
|
|
127
|
+
...(resumed === undefined ? {} : { resumed }), ...(restoreMethod === undefined ? {} : { restoreMethod }),
|
|
128
|
+
...(lastUsedAt === undefined ? {} : { lastUsedAt }), ...(lifecycle === undefined ? {} : { lifecycle }),
|
|
129
|
+
...(provider === undefined ? {} : { provider, model }) };
|
|
78
130
|
}
|
|
79
131
|
function validatePushUrl(value) {
|
|
80
132
|
const url = text(value, 'push URL');
|
|
@@ -266,6 +318,29 @@ export class FileA2AStore {
|
|
|
266
318
|
const target = this.targets.get(key(scopeOf(context), contextId));
|
|
267
319
|
return target && structuredClone(target);
|
|
268
320
|
}
|
|
321
|
+
/** The most recently updated task this host ran in one DSH session, within the caller's scope. */
|
|
322
|
+
latestTaskForSession(sessionId, context) {
|
|
323
|
+
this.assertOpen();
|
|
324
|
+
text(sessionId, 'session ID');
|
|
325
|
+
const scope = scopeOf(context);
|
|
326
|
+
let latest;
|
|
327
|
+
for (const cached of this.tasks.values()) {
|
|
328
|
+
if (cached.scope.tenant !== scope.tenant || cached.scope.owner !== scope.owner)
|
|
329
|
+
continue;
|
|
330
|
+
if (cached.task.metadata?.['1agents']?.sessionId !== sessionId)
|
|
331
|
+
continue;
|
|
332
|
+
if (!latest || Date.parse(cached.task.status?.timestamp ?? '') > Date.parse(latest.status?.timestamp ?? ''))
|
|
333
|
+
latest = cached.task;
|
|
334
|
+
}
|
|
335
|
+
return latest && parseTask(Task.toJSON(latest));
|
|
336
|
+
}
|
|
337
|
+
/** The DSH session a task ran in, within the caller's scope. */
|
|
338
|
+
sessionOfTask(taskId, context) {
|
|
339
|
+
this.assertOpen();
|
|
340
|
+
text(taskId, 'task ID');
|
|
341
|
+
const sessionId = this.tasks.get(key(scopeOf(context), taskId))?.task.metadata?.['1agents']?.sessionId;
|
|
342
|
+
return typeof sessionId === 'string' ? sessionId : undefined;
|
|
343
|
+
}
|
|
269
344
|
saveTarget(contextId, target, context) {
|
|
270
345
|
this.assertOpen();
|
|
271
346
|
text(contextId, 'context ID');
|
package/dist/src/a2a/types.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
/** Execution interfaces shared by DSH and future standalone A2A hosts. */
|
|
2
2
|
import type { SafeError } from '@1agents/acp-service/runtime';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import type { A2AExecutionRef } from './execution-binding.js';
|
|
5
|
+
/** Host-authored summary of a verified, immutable role/skill lock. */
|
|
6
|
+
export declare const a2aRoleSkillsSchema: z.ZodObject<{
|
|
7
|
+
roleId: z.ZodString;
|
|
8
|
+
roleVersion: z.ZodString;
|
|
9
|
+
lockPath: z.ZodString;
|
|
10
|
+
roleDirectory: z.ZodString;
|
|
11
|
+
entryGuidePath: z.ZodOptional<z.ZodString>;
|
|
12
|
+
skills: z.ZodArray<z.ZodObject<{
|
|
13
|
+
key: z.ZodString;
|
|
14
|
+
skillId: z.ZodString;
|
|
15
|
+
sourceId: z.ZodString;
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
revision: z.ZodString;
|
|
18
|
+
directory: z.ZodString;
|
|
19
|
+
guidePath: z.ZodString;
|
|
20
|
+
}, z.core.$strict>>;
|
|
21
|
+
}, z.core.$strict>;
|
|
22
|
+
export type A2ARoleSkills = z.infer<typeof a2aRoleSkillsSchema>;
|
|
3
23
|
/** Explicit host-side requirements checked without creating an agent session. */
|
|
4
24
|
export interface A2APreflightRequirements {
|
|
5
25
|
allowedDirectories?: string[];
|
|
@@ -34,6 +54,33 @@ export interface A2ATarget {
|
|
|
34
54
|
cwd: string;
|
|
35
55
|
agentPreset?: string;
|
|
36
56
|
preflight?: A2APreflightReport;
|
|
57
|
+
/** Logical host binding; several bindings may use one canonical skill profile. */
|
|
58
|
+
roleId?: string;
|
|
59
|
+
roleSkills?: A2ARoleSkills;
|
|
60
|
+
/** Set when this target was attached again through session/load or session/resume. */
|
|
61
|
+
resumed?: boolean;
|
|
62
|
+
restoreMethod?: 'session/load' | 'session/resume';
|
|
63
|
+
/** Absent on records written before session close. Callers treat that as attached. */
|
|
64
|
+
state?: 'attached' | 'busy' | 'idle' | 'closing' | 'closed' | 'stale' | 'deleted';
|
|
65
|
+
lastUsedAt?: string;
|
|
66
|
+
lifecycle?: {
|
|
67
|
+
mode: 'persistent' | 'one-shot';
|
|
68
|
+
idleTtlSeconds?: number;
|
|
69
|
+
closeAfter?: 'terminal' | 'ack';
|
|
70
|
+
};
|
|
71
|
+
/** Model the host selected for a standard preset. Absent when the session uses the host default. */
|
|
72
|
+
provider?: string;
|
|
73
|
+
model?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface A2ACloseResult {
|
|
76
|
+
processReleased: true | 'pending';
|
|
77
|
+
/** False when the preset has no ACP child process. */
|
|
78
|
+
acp?: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface A2ASessionStatus {
|
|
81
|
+
attached: boolean;
|
|
82
|
+
activeTurn: boolean;
|
|
83
|
+
lastUsedAt?: string;
|
|
37
84
|
}
|
|
38
85
|
/** Omitted location and preset reuse a saved context or the host defaults. */
|
|
39
86
|
export interface A2APrepareInput {
|
|
@@ -41,6 +88,15 @@ export interface A2APrepareInput {
|
|
|
41
88
|
cwd?: string;
|
|
42
89
|
agentPreset?: string;
|
|
43
90
|
preflight?: A2APreflightRequirements;
|
|
91
|
+
/** Only selects a host-configured profile; clients cannot supply profile or cache configuration. */
|
|
92
|
+
roleId?: string;
|
|
93
|
+
/** Optional existing parent lock under the host cache's locks directory. */
|
|
94
|
+
roleLockPath?: string;
|
|
95
|
+
/** A path agent's agents/*.md inside cwd; its body prefixes the first message of a new session. Not combined with roleId. */
|
|
96
|
+
agentFile?: string;
|
|
97
|
+
/** Standard presets only, passed together. Omitted keeps the session's current or host-default model. */
|
|
98
|
+
provider?: string;
|
|
99
|
+
model?: string;
|
|
44
100
|
}
|
|
45
101
|
/** A single DSH turn's output, without transport or host dependencies. */
|
|
46
102
|
export interface A2ARunResult {
|
|
@@ -60,9 +116,29 @@ export interface A2ABackend {
|
|
|
60
116
|
recover?(target: A2ATarget, options: {
|
|
61
117
|
requestId: string;
|
|
62
118
|
}): Promise<SafeError | undefined>;
|
|
63
|
-
|
|
119
|
+
/** Cancel pending admission and drain owned initialization before rejecting an aborted preparation. */
|
|
120
|
+
prepare(input: A2APrepareInput, options?: {
|
|
121
|
+
signal: AbortSignal;
|
|
122
|
+
}): Promise<A2ATarget>;
|
|
64
123
|
run(target: A2ATarget, prompt: string, options: {
|
|
65
124
|
requestId: string;
|
|
66
125
|
signal: AbortSignal;
|
|
126
|
+
/** Hosts with a session queue call this again immediately before submitting the prompt. */
|
|
127
|
+
beforeStart?: (signal?: AbortSignal) => Promise<void>;
|
|
128
|
+
/** Process-slot wait stays submitted. Undefined means the handshake has started. */
|
|
129
|
+
onCapacity?: (pending: {
|
|
130
|
+
code: 'CAPACITY_PENDING';
|
|
131
|
+
position: number;
|
|
132
|
+
waitedMs: number;
|
|
133
|
+
} | undefined) => void;
|
|
134
|
+
/** Set by the gateway. The DSH host binds it for the prompt and never puts the workbench credential here. */
|
|
135
|
+
execution?: A2AExecutionRef;
|
|
67
136
|
}): Promise<A2ARunResult>;
|
|
137
|
+
/** Ordinary session release. Hosts that cannot close omit this and the gateway reports UNSUPPORTED. */
|
|
138
|
+
close?(target: A2ATarget, options?: {
|
|
139
|
+
signal?: AbortSignal;
|
|
140
|
+
}): Promise<A2ACloseResult>;
|
|
141
|
+
status?(target: A2ATarget): Promise<A2ASessionStatus>;
|
|
142
|
+
/** Controlled delete: ACP session/delete, never DSH history. The gateway sends it only when allowDelete is set. */
|
|
143
|
+
delete?(target: A2ATarget): Promise<A2ACloseResult>;
|
|
68
144
|
}
|
package/dist/src/a2a/types.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { isAbsolute } from 'node:path';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const roleText = z.string().min(1).max(4096).refine(value => !value.includes('\0'));
|
|
4
|
+
const rolePath = roleText.refine(isAbsolute, 'Expected an absolute role cache path');
|
|
5
|
+
/** Host-authored summary of a verified, immutable role/skill lock. */
|
|
6
|
+
export const a2aRoleSkillsSchema = z.object({
|
|
7
|
+
roleId: roleText, roleVersion: roleText, lockPath: rolePath, roleDirectory: rolePath,
|
|
8
|
+
entryGuidePath: rolePath.optional(),
|
|
9
|
+
skills: z.array(z.object({ key: roleText, skillId: roleText, sourceId: roleText, name: roleText,
|
|
10
|
+
revision: z.string().regex(/^[a-f0-9]{64}$/), directory: rolePath, guidePath: rolePath }).strict()).min(1).max(100),
|
|
11
|
+
}).strict();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
export declare const WORKBENCH_UI_PATH = "/workbench/ui";
|
|
3
|
+
/**
|
|
4
|
+
* The page and its static assets under WORKBENCH_UI_PATH. `frameAncestors` lets a host that embeds the
|
|
5
|
+
* page in its own frame (DSH) allow exactly that; the gateway's own page is never framed.
|
|
6
|
+
*/
|
|
7
|
+
export declare function serveWorkbenchPage(req: IncomingMessage, res: ServerResponse, pathname: string, options?: {
|
|
8
|
+
frameAncestors?: "'none'" | "'self'";
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
/** Agent sessions and CLI tools never act as the human reviewer. */
|
|
11
|
+
export declare function isAgentRequest(req: IncomingMessage): boolean;
|
|
12
|
+
/** Same rule as the former 1agents proxy: a direct browser request whose Origin authority is this Host. */
|
|
13
|
+
export declare function sameOriginBrowser(req: IncomingMessage): boolean;
|
|
14
|
+
export declare class WorkbenchUi {
|
|
15
|
+
private readonly token;
|
|
16
|
+
private readonly now;
|
|
17
|
+
private readonly sessions;
|
|
18
|
+
constructor(token: string | undefined, now?: () => number);
|
|
19
|
+
/**
|
|
20
|
+
* Serves the page, the login session and static assets. For an authorized page API call it returns
|
|
21
|
+
* the matching /workbench route, which the caller dispatches exactly like the bearer API.
|
|
22
|
+
*/
|
|
23
|
+
handle(req: IncomingMessage, res: ServerResponse, url: URL): Promise<{
|
|
24
|
+
route: string;
|
|
25
|
+
} | undefined>;
|
|
26
|
+
private authorized;
|
|
27
|
+
private session;
|
|
28
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gateway's own workbench page. A logged-in same-origin browser reaches the same routes as the bearer API.
|
|
3
|
+
* Without a configured token the page needs no login; writes still need a same-origin browser.
|
|
4
|
+
*/
|
|
5
|
+
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { readFile } from 'node:fs/promises';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
export const WORKBENCH_UI_PATH = '/workbench/ui';
|
|
11
|
+
const API_PATH = `${WORKBENCH_UI_PATH}/api`;
|
|
12
|
+
const COOKIE = 'acp_workbench';
|
|
13
|
+
const SESSION_MS = 12 * 60 * 60 * 1000;
|
|
14
|
+
const MAX_SESSIONS = 64;
|
|
15
|
+
const ASSETS = { 'app.js': 'text/javascript; charset=utf-8', 'app.css': 'text/css; charset=utf-8' };
|
|
16
|
+
/** Lazy-loaded renderer chunks (markdown, highlighting) emitted by the page build. */
|
|
17
|
+
const CHUNK = /^chunk-[A-Za-z0-9_-]+\.js$/;
|
|
18
|
+
const SECURITY_HEADERS = {
|
|
19
|
+
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'",
|
|
20
|
+
'X-Content-Type-Options': 'nosniff',
|
|
21
|
+
'Referrer-Policy': 'no-referrer',
|
|
22
|
+
'Cache-Control': 'no-store',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Built output sits in dist/workbench-ui; the source tree runs from src/a2a under tsx. Only the build
|
|
26
|
+
* has app.js, so the page source directory beside src is never served.
|
|
27
|
+
*/
|
|
28
|
+
function assetDirectory() {
|
|
29
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
return [path.resolve(here, '../../workbench-ui'), path.resolve(here, '../../dist/workbench-ui')]
|
|
31
|
+
.find(directory => existsSync(path.join(directory, 'app.js')));
|
|
32
|
+
}
|
|
33
|
+
function send(res, status, type, payload, headers = {}) {
|
|
34
|
+
res.writeHead(status, { ...SECURITY_HEADERS, 'Content-Type': type, ...headers });
|
|
35
|
+
res.end(payload);
|
|
36
|
+
}
|
|
37
|
+
function sendJson(res, status, data, headers = {}) {
|
|
38
|
+
send(res, status, 'application/json', JSON.stringify(data), headers);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The page and its static assets under WORKBENCH_UI_PATH. `frameAncestors` lets a host that embeds the
|
|
42
|
+
* page in its own frame (DSH) allow exactly that; the gateway's own page is never framed.
|
|
43
|
+
*/
|
|
44
|
+
export async function serveWorkbenchPage(req, res, pathname, options = {}) {
|
|
45
|
+
const headers = options.frameAncestors === "'self'"
|
|
46
|
+
? { 'Content-Security-Policy': SECURITY_HEADERS['Content-Security-Policy'].replace("frame-ancestors 'none'", "frame-ancestors 'self'") } : {};
|
|
47
|
+
if (req.method !== 'GET')
|
|
48
|
+
return sendJson(res, 405, { error: 'Method not allowed' }, headers);
|
|
49
|
+
const directory = assetDirectory();
|
|
50
|
+
if (!directory)
|
|
51
|
+
return sendJson(res, 503, { error: 'Workbench page is not built' }, headers);
|
|
52
|
+
if (pathname === WORKBENCH_UI_PATH || pathname === `${WORKBENCH_UI_PATH}/`) {
|
|
53
|
+
return send(res, 200, 'text/html; charset=utf-8', await readFile(path.join(directory, 'index.html')), headers);
|
|
54
|
+
}
|
|
55
|
+
const asset = pathname.slice(`${WORKBENCH_UI_PATH}/`.length);
|
|
56
|
+
const type = Object.hasOwn(ASSETS, asset) ? ASSETS[asset] : CHUNK.test(asset) ? ASSETS['app.js'] : undefined;
|
|
57
|
+
if (!type)
|
|
58
|
+
return sendJson(res, 404, { error: 'No workbench page asset' }, headers);
|
|
59
|
+
try {
|
|
60
|
+
return send(res, 200, type, await readFile(path.join(directory, asset)), headers);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return sendJson(res, 404, { error: 'No workbench page asset' }, headers);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Agent sessions and CLI tools never act as the human reviewer. */
|
|
67
|
+
export function isAgentRequest(req) {
|
|
68
|
+
if (['x-oneagents-session-id', 'x-oneagents-session-token', 'x-oneagents-turn-id'].some(name => req.headers[name]))
|
|
69
|
+
return true;
|
|
70
|
+
const origin = String(req.headers['x-oneagents-origin'] ?? '').toLowerCase();
|
|
71
|
+
return origin === 'mcp' || origin === 'cli' || Boolean(req.headers.authorization);
|
|
72
|
+
}
|
|
73
|
+
/** Same rule as the former 1agents proxy: a direct browser request whose Origin authority is this Host. */
|
|
74
|
+
export function sameOriginBrowser(req) {
|
|
75
|
+
if (req.headers['sec-fetch-site'] !== 'same-origin')
|
|
76
|
+
return false;
|
|
77
|
+
try {
|
|
78
|
+
const origin = new URL(String(req.headers.origin ?? ''));
|
|
79
|
+
if (!['http:', 'https:'].includes(origin.protocol) || origin.username || origin.password)
|
|
80
|
+
return false;
|
|
81
|
+
if ((origin.pathname !== '' && origin.pathname !== '/') || origin.search || origin.hash)
|
|
82
|
+
return false;
|
|
83
|
+
return origin.host.toLowerCase() === String(req.headers.host ?? '').toLowerCase();
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function cookieValue(req) {
|
|
90
|
+
for (const part of String(req.headers.cookie ?? '').split(';')) {
|
|
91
|
+
const [name, ...value] = part.trim().split('=');
|
|
92
|
+
if (name === COOKIE)
|
|
93
|
+
return value.join('=');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function readToken(req) {
|
|
97
|
+
let length = 0;
|
|
98
|
+
const chunks = [];
|
|
99
|
+
for await (const data of req) {
|
|
100
|
+
length += data.length;
|
|
101
|
+
if (length > 4096)
|
|
102
|
+
throw new Error('Request body too large');
|
|
103
|
+
chunks.push(Buffer.from(data));
|
|
104
|
+
}
|
|
105
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8')).token;
|
|
106
|
+
}
|
|
107
|
+
export class WorkbenchUi {
|
|
108
|
+
token;
|
|
109
|
+
now;
|
|
110
|
+
sessions = new Map();
|
|
111
|
+
constructor(token, now = Date.now) {
|
|
112
|
+
this.token = token;
|
|
113
|
+
this.now = now;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Serves the page, the login session and static assets. For an authorized page API call it returns
|
|
117
|
+
* the matching /workbench route, which the caller dispatches exactly like the bearer API.
|
|
118
|
+
*/
|
|
119
|
+
async handle(req, res, url) {
|
|
120
|
+
const pathname = url.pathname;
|
|
121
|
+
if (!pathname.startsWith(`${API_PATH}/`))
|
|
122
|
+
return void await serveWorkbenchPage(req, res, pathname);
|
|
123
|
+
if (isAgentRequest(req))
|
|
124
|
+
return void sendJson(res, 403, { error: 'browser_action_required', message: 'Agents and tools use the bearer workbench API, not the page.' });
|
|
125
|
+
const write = req.method !== 'GET';
|
|
126
|
+
if (write && !sameOriginBrowser(req)) {
|
|
127
|
+
return void sendJson(res, 403, { error: 'browser_action_required', message: '请在本工作台页面提交。' });
|
|
128
|
+
}
|
|
129
|
+
if (pathname === `${API_PATH}/session`)
|
|
130
|
+
return this.session(req, res);
|
|
131
|
+
if (!this.authorized(req))
|
|
132
|
+
return void sendJson(res, 401, { error: 'login_required', message: '请先登录工作台。' });
|
|
133
|
+
return { route: `/workbench${pathname.slice(API_PATH.length)}` };
|
|
134
|
+
}
|
|
135
|
+
authorized(req) {
|
|
136
|
+
if (!this.token)
|
|
137
|
+
return true;
|
|
138
|
+
const id = cookieValue(req);
|
|
139
|
+
const expires = id ? this.sessions.get(id) : undefined;
|
|
140
|
+
if (!id || expires === undefined)
|
|
141
|
+
return false;
|
|
142
|
+
if (expires <= this.now()) {
|
|
143
|
+
this.sessions.delete(id);
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
async session(req, res) {
|
|
149
|
+
if (req.method === 'GET')
|
|
150
|
+
return void sendJson(res, 200, { authenticated: this.authorized(req), loginRequired: Boolean(this.token) });
|
|
151
|
+
if (req.method === 'DELETE') {
|
|
152
|
+
const id = cookieValue(req);
|
|
153
|
+
if (id)
|
|
154
|
+
this.sessions.delete(id);
|
|
155
|
+
return void sendJson(res, 200, { authenticated: false }, { 'Set-Cookie': `${COOKIE}=; HttpOnly; SameSite=Strict; Path=${WORKBENCH_UI_PATH}; Max-Age=0` });
|
|
156
|
+
}
|
|
157
|
+
if (req.method !== 'POST')
|
|
158
|
+
return void sendJson(res, 405, { error: 'Method not allowed' });
|
|
159
|
+
if (!this.token)
|
|
160
|
+
return void sendJson(res, 200, { authenticated: true });
|
|
161
|
+
let supplied;
|
|
162
|
+
try {
|
|
163
|
+
supplied = await readToken(req);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return void sendJson(res, 400, { error: 'invalid', message: '请求格式不正确。' });
|
|
167
|
+
}
|
|
168
|
+
const expected = Buffer.from(this.token), given = Buffer.from(typeof supplied === 'string' ? supplied : '');
|
|
169
|
+
if (given.length !== expected.length || !timingSafeEqual(given, expected)) {
|
|
170
|
+
return void sendJson(res, 401, { error: 'login_failed', message: '工作台令牌不正确。' });
|
|
171
|
+
}
|
|
172
|
+
const now = this.now();
|
|
173
|
+
for (const [id, expires] of this.sessions)
|
|
174
|
+
if (expires <= now)
|
|
175
|
+
this.sessions.delete(id);
|
|
176
|
+
while (this.sessions.size >= MAX_SESSIONS)
|
|
177
|
+
this.sessions.delete(this.sessions.keys().next().value);
|
|
178
|
+
const id = randomBytes(32).toString('base64url');
|
|
179
|
+
this.sessions.set(id, now + SESSION_MS);
|
|
180
|
+
return void sendJson(res, 200, { authenticated: true }, { 'Set-Cookie': `${COOKIE}=${id}; HttpOnly; SameSite=Strict; Path=${WORKBENCH_UI_PATH}; Max-Age=${SESSION_MS / 1000}` });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -12,6 +12,12 @@ const NS = '1agents';
|
|
|
12
12
|
const EXT = '_1agents/';
|
|
13
13
|
/** Error envelopes have a closed projection; provider data never becomes metadata. */
|
|
14
14
|
function safeFailureEvent(event, trustedRuntimeErrors) {
|
|
15
|
+
// Process-slot admission is not a turn failure. Keep the queue position for the caller.
|
|
16
|
+
if (event.code === 'CAPACITY_PENDING' || event.message === 'CAPACITY_PENDING') {
|
|
17
|
+
const data = event.data && typeof event.data === 'object' ? event.data : {};
|
|
18
|
+
return { event: event.event ?? 'error', sessionId: event.sessionId, code: 'CAPACITY_PENDING',
|
|
19
|
+
message: 'CAPACITY_PENDING', scope: 'control', terminal: false, data: { position: data.position, waitedMs: data.waitedMs } };
|
|
20
|
+
}
|
|
15
21
|
if (['tool_call', 'tool_call_update', 'tool_result'].includes(event.event)) {
|
|
16
22
|
if (event.error === undefined && event.errorCode === undefined && event.errorText === undefined)
|
|
17
23
|
return event;
|
|
@@ -134,6 +140,9 @@ export class RuntimePeer {
|
|
|
134
140
|
}
|
|
135
141
|
const failureEvent = events.find(e => (e.event === 'error' || e.type === 'error' || e.event === 'protocol_error') && e.scope !== 'turn');
|
|
136
142
|
if (failureEvent) {
|
|
143
|
+
if (failureEvent.code === 'CAPACITY_PENDING' || failureEvent.message === 'CAPACITY_PENDING') {
|
|
144
|
+
throw new RequestError(-32010, 'CAPACITY_PENDING', failureEvent.data);
|
|
145
|
+
}
|
|
137
146
|
const safe = toSafeError(failureEvent.error ?? failureEvent, { origin: 'service', operationId: payload.requestId });
|
|
138
147
|
throw new RequestError(-32000, safe.message, safe);
|
|
139
148
|
}
|
|
@@ -333,8 +342,27 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
|
|
|
333
342
|
});
|
|
334
343
|
}
|
|
335
344
|
}
|
|
336
|
-
async function ensure(params, fresh, replay) {
|
|
345
|
+
async function ensure(params, fresh, replay, signal) {
|
|
337
346
|
requireInitialized();
|
|
347
|
+
signal?.throwIfAborted();
|
|
348
|
+
// Read-only status/replay work may be abandoned after cancellation; the
|
|
349
|
+
// dispatch that owns process creation is always awaited and explicitly closed.
|
|
350
|
+
async function readWhileActive(operation) {
|
|
351
|
+
if (!signal)
|
|
352
|
+
return operation;
|
|
353
|
+
signal.throwIfAborted();
|
|
354
|
+
let abort;
|
|
355
|
+
const canceled = new Promise((_, reject) => {
|
|
356
|
+
abort = () => reject(signal.reason);
|
|
357
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
358
|
+
});
|
|
359
|
+
try {
|
|
360
|
+
return await Promise.race([operation, canceled]);
|
|
361
|
+
}
|
|
362
|
+
finally {
|
|
363
|
+
signal.removeEventListener('abort', abort);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
338
366
|
if (typeof params.cwd !== 'string' || !isAbsolute(params.cwd))
|
|
339
367
|
throw RequestError.invalidParams('cwd must be absolute');
|
|
340
368
|
try {
|
|
@@ -346,7 +374,8 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
|
|
|
346
374
|
const id = fresh ? randomUUID() : params.sessionId;
|
|
347
375
|
const custom = extensions ? metadata(params) : {};
|
|
348
376
|
const stored = state.get(id);
|
|
349
|
-
const record = fresh ? undefined : await backend.record(stored?.runtimeRecordId || id);
|
|
377
|
+
const record = fresh ? undefined : await readWhileActive(backend.record(stored?.runtimeRecordId || id));
|
|
378
|
+
signal?.throwIfAborted();
|
|
350
379
|
if (!fresh) {
|
|
351
380
|
const live = backend.sessions.get(id);
|
|
352
381
|
const binding = state.get(id);
|
|
@@ -367,9 +396,44 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
|
|
|
367
396
|
}
|
|
368
397
|
if (held.has(id))
|
|
369
398
|
throw new RequestError(-32000, 'Session attachment is already in progress');
|
|
399
|
+
const previousSession = backend.sessions.get(id);
|
|
400
|
+
const previousPeer = previousSession?.ws;
|
|
401
|
+
const previousResponsePolicy = previousSession?.acpResponsePolicy;
|
|
402
|
+
const previouslyAttached = attached.has(id);
|
|
370
403
|
held.set(id, []);
|
|
404
|
+
let dispatchStarted = false;
|
|
405
|
+
let abortCleanup;
|
|
406
|
+
let restoredExisting = false;
|
|
407
|
+
const closeOwnedStartup = async () => {
|
|
408
|
+
const current = backend.sessions.get(id);
|
|
409
|
+
if (previousSession && current === previousSession) {
|
|
410
|
+
// A canceled reattachment must preserve the user's original live turn.
|
|
411
|
+
if (current.ws === peer) {
|
|
412
|
+
current.ws = previousPeer;
|
|
413
|
+
current.acpResponsePolicy = previousResponsePolicy;
|
|
414
|
+
restoredExisting = true;
|
|
415
|
+
}
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
// Ownership may have passed to another successful attachment while a
|
|
419
|
+
// canceled request was awaiting status. Never close that connection.
|
|
420
|
+
if (current && current.ws !== peer)
|
|
421
|
+
return;
|
|
422
|
+
await peer.command(backend, { action: 'close_session', sessionId: id, initializationSignal: signal });
|
|
423
|
+
};
|
|
424
|
+
const abort = () => {
|
|
425
|
+
if (!dispatchStarted)
|
|
426
|
+
return;
|
|
427
|
+
// The client does not know a fresh session's ID yet. Cancel its private
|
|
428
|
+
// initialization immediately, including while dispatch is awaiting capacity.
|
|
429
|
+
abortCleanup ??= closeOwnedStartup().catch(() => undefined);
|
|
430
|
+
};
|
|
431
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
371
432
|
try {
|
|
372
|
-
|
|
433
|
+
signal?.throwIfAborted();
|
|
434
|
+
dispatchStarted = true;
|
|
435
|
+
const events = await peer.command(backend, { ...custom, action: 'ensure_session', sessionId: id, workspacePath: params.cwd, agentType: agentName, mcpServers: params.mcpServers, runtimeSessionKey: stored?.runtimeRecordId, resumeSessionId: fresh ? custom.resumeSessionId : record?.acpSessionId, responsePolicy: 'stream', initializationSignal: signal });
|
|
436
|
+
signal?.throwIfAborted();
|
|
373
437
|
state.create({ sessionId: id, agentType: agentName, cwd: params.cwd, completeHistory: fresh ? !custom.resumeSessionId : stored?.completeHistory === true, runtimeRecordId: backend.sessions.get(id)?.handle?.acpxRecordId });
|
|
374
438
|
attached.add(id);
|
|
375
439
|
const session = backend.sessions.get(id);
|
|
@@ -382,9 +446,11 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
|
|
|
382
446
|
for (const update of state.history(id)) {
|
|
383
447
|
notify('session/update', { sessionId: id, update });
|
|
384
448
|
}
|
|
385
|
-
await output;
|
|
449
|
+
await readWhileActive(output);
|
|
450
|
+
signal?.throwIfAborted();
|
|
386
451
|
}
|
|
387
|
-
const status = await backend.status(id);
|
|
452
|
+
const status = await readWhileActive(backend.status(id));
|
|
453
|
+
signal?.throwIfAborted();
|
|
388
454
|
if (backend.sessions.get(id)?.ws !== peer)
|
|
389
455
|
throw new RequestError(-32000, 'Session taken over during attachment');
|
|
390
456
|
if (status.availableCommands) {
|
|
@@ -392,15 +458,39 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
|
|
|
392
458
|
sessionUpdate: 'available_commands_update',
|
|
393
459
|
availableCommands: status.availableCommands.map((c) => ({ name: c.name, description: c.description || '', ...(c.hasInput ? { input: { hint: c.inputHint || 'Arguments' } } : {}) })),
|
|
394
460
|
} });
|
|
395
|
-
await output;
|
|
461
|
+
await readWhileActive(output);
|
|
462
|
+
signal?.throwIfAborted();
|
|
396
463
|
}
|
|
397
464
|
const ready = events.find(e => e.event === 'session_ready') || {};
|
|
465
|
+
signal?.throwIfAborted();
|
|
466
|
+
if (previousSession && backend.sessions.get(id) === previousSession && previousSession.ws === peer &&
|
|
467
|
+
previousPeer && previousPeer !== peer && previousPeer.readyState === 1) {
|
|
468
|
+
previousPeer.send(JSON.stringify({ event: 'session_taken_over', sessionId: id }));
|
|
469
|
+
}
|
|
398
470
|
return { ...(fresh ? { sessionId: id } : {}), ...(status.modes ? { modes: status.modes } : {}), configOptions: configOptions(status), _meta: { [NS]: { agentSessionId: ready.agentSessionId, turnProtocolVersion: 3, agentType: agentName } } };
|
|
399
471
|
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
if (signal?.aborted && dispatchStarted) {
|
|
474
|
+
if (!previouslyAttached)
|
|
475
|
+
attached.delete(id);
|
|
476
|
+
abort();
|
|
477
|
+
await abortCleanup;
|
|
478
|
+
// A backend may finish attachment after the first close was sent.
|
|
479
|
+
// Awaiting dispatch and then closing again retires that late handle too.
|
|
480
|
+
await closeOwnedStartup();
|
|
481
|
+
signal.throwIfAborted();
|
|
482
|
+
}
|
|
483
|
+
throw error;
|
|
484
|
+
}
|
|
400
485
|
finally {
|
|
486
|
+
signal?.removeEventListener('abort', abort);
|
|
401
487
|
const buffered = held.get(id) || [];
|
|
402
488
|
held.delete(id);
|
|
403
|
-
|
|
489
|
+
if (signal?.aborted && restoredExisting && previousPeer && previousPeer !== peer && backend.sessions.get(id)?.ws === previousPeer) {
|
|
490
|
+
for (const event of buffered)
|
|
491
|
+
previousPeer.send(JSON.stringify(event));
|
|
492
|
+
}
|
|
493
|
+
for (const event of signal?.aborted && !previouslyAttached ? [] : buffered) {
|
|
404
494
|
// The explicit load replay is the standard transcript; runtime history
|
|
405
495
|
// snapshots are emitted only as negotiated application extensions.
|
|
406
496
|
receive(event);
|
|
@@ -416,9 +506,9 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
|
|
|
416
506
|
return { protocolVersion: PROTOCOL_VERSION, agentInfo: { name: '1agents-acp-service', version: '0.2.0' }, authMethods: [], agentCapabilities: { promptCapabilities: { image: true, audio: true }, loadSession: true, sessionCapabilities: { resume: {}, close: {}, list: {}, delete: {} }, _meta: { [NS]: { version: 1, agentType: agentName, interactions: true, turnSync: true } } } };
|
|
417
507
|
})
|
|
418
508
|
.onRequest('authenticate', () => { requireInitialized(); throw RequestError.invalidParams('No connection authentication methods are configured'); })
|
|
419
|
-
.onRequest('session/new', async ({ params }) => await ensure(params, true, false))
|
|
420
|
-
.onRequest('session/load', ({ params }) => ensure(params, false, true))
|
|
421
|
-
.onRequest('session/resume', ({ params }) => ensure(params, false, false))
|
|
509
|
+
.onRequest('session/new', async ({ params, signal }) => await ensure(params, true, false, signal))
|
|
510
|
+
.onRequest('session/load', ({ params, signal }) => ensure(params, false, true, signal))
|
|
511
|
+
.onRequest('session/resume', ({ params, signal }) => ensure(params, false, false, signal))
|
|
422
512
|
.onRequest('session/prompt', async ({ params, signal }) => {
|
|
423
513
|
requireSession(params.sessionId);
|
|
424
514
|
const custom = extensions ? metadata(params) : {};
|
|
@@ -462,14 +552,16 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
|
|
|
462
552
|
.onNotification('session/cancel', async ({ params }) => { requireSession(params.sessionId); await peer.command(backend, { action: 'cancel_turn', sessionId: params.sessionId }); })
|
|
463
553
|
.onRequest('session/close', async ({ params }) => {
|
|
464
554
|
requireSession(params.sessionId);
|
|
465
|
-
await peer.command(backend, { action: 'close_session', sessionId: params.sessionId });
|
|
555
|
+
const events = await peer.command(backend, { action: 'close_session', sessionId: params.sessionId });
|
|
466
556
|
attached.delete(params.sessionId);
|
|
467
557
|
for (const [key, pending] of prompts)
|
|
468
558
|
if (pending.sessionId === params.sessionId) {
|
|
469
559
|
prompts.delete(key);
|
|
470
560
|
pending.resolve({ stopReason: 'cancelled' });
|
|
471
561
|
}
|
|
472
|
-
|
|
562
|
+
// Only an observed exit with its lease gone is a release; everything else stays pending upstream.
|
|
563
|
+
const released = events.some(e => e.event === 'session_released' && e.sessionId === params.sessionId && e.processReleased === true);
|
|
564
|
+
return released ? { _meta: { [NS]: { processReleased: true } } } : {};
|
|
473
565
|
})
|
|
474
566
|
.onRequest('session/set_mode', async ({ params }) => { requireSession(params.sessionId); await peer.command(backend, { action: 'set_session_mode', sessionId: params.sessionId, payload: { modeId: params.modeId } }); return {}; })
|
|
475
567
|
.onRequest('session/set_config_option', async ({ params }) => { requireSession(params.sessionId); await peer.command(backend, { action: 'set_config_option', sessionId: params.sessionId, payload: { key: params.configId, value: params.value } }); return { configOptions: configOptions(await backend.status(params.sessionId)) }; })
|
|
@@ -516,11 +608,24 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
|
|
|
516
608
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
517
609
|
throw RequestError.invalidParams('Expected object');
|
|
518
610
|
return value;
|
|
519
|
-
}, async ({ params }) => {
|
|
611
|
+
}, async ({ params, signal }) => {
|
|
520
612
|
requireInitialized();
|
|
521
613
|
if (!extensions || typeof params.sessionId !== 'string' || !params.sessionId)
|
|
522
614
|
throw RequestError.invalidParams('Native session ID required');
|
|
523
|
-
return ensure({ ...params, _meta: { [NS]: { ...metadata(params), resumeSessionId: params.sessionId } } }, true, false);
|
|
615
|
+
return ensure({ ...params, _meta: { [NS]: { ...metadata(params), resumeSessionId: params.sessionId, capacityId: `import:${params.sessionId}` } } }, true, false, signal);
|
|
616
|
+
});
|
|
617
|
+
app.onRequest(`${EXT}capacity/cancel`, (value) => {
|
|
618
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
619
|
+
throw RequestError.invalidParams('Expected object');
|
|
620
|
+
return value;
|
|
621
|
+
}, async ({ params }) => {
|
|
622
|
+
requireInitialized();
|
|
623
|
+
if (!extensions)
|
|
624
|
+
throw RequestError.methodNotFound(`${EXT}capacity/cancel`);
|
|
625
|
+
if (typeof params.capacityId !== 'string' || !params.capacityId.trim() || params.capacityId.length > 4096)
|
|
626
|
+
throw RequestError.invalidParams('capacityId is required');
|
|
627
|
+
await peer.command(backend, { action: 'capacity_cancel', capacityId: params.capacityId });
|
|
628
|
+
return {};
|
|
524
629
|
});
|
|
525
630
|
const controls = { 'session/history': 'get_history', 'session/permission_mode': 'set_permission_mode', 'session/cancel_queued': 'cancel_queued', 'session/fork': 'fork_session', 'session/authenticate': 'authenticate', 'session/logout': 'logout' };
|
|
526
631
|
for (const [method, action] of Object.entries(controls)) {
|