@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,45 @@
|
|
|
1
|
+
/** Serve back only files the host already verified for a task; the receipt, not the caller, names what may be read. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { open, realpath } from 'node:fs/promises';
|
|
5
|
+
export const ARTIFACT_CONTENT_LIMIT = 32 * 1024 * 1024;
|
|
6
|
+
export class ArtifactContentError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
code;
|
|
9
|
+
constructor(status, code) {
|
|
10
|
+
super(code);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** The bytes must still match the receipt: a file edited or swapped after verification is refused, not served. */
|
|
16
|
+
export async function readVerifiedArtifact(artifacts, path, sha256) {
|
|
17
|
+
const artifact = artifacts.find(item => item.path === path && item.sha256 === sha256);
|
|
18
|
+
if (!artifact)
|
|
19
|
+
throw new ArtifactContentError(404, 'artifact-not-registered');
|
|
20
|
+
if (artifact.size > ARTIFACT_CONTENT_LIMIT)
|
|
21
|
+
throw new ArtifactContentError(413, 'artifact-too-large');
|
|
22
|
+
let file;
|
|
23
|
+
try {
|
|
24
|
+
if (await realpath(path) !== path)
|
|
25
|
+
throw new ArtifactContentError(409, 'artifact-changed');
|
|
26
|
+
file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error instanceof ArtifactContentError)
|
|
30
|
+
throw error;
|
|
31
|
+
throw new ArtifactContentError(409, 'artifact-unavailable');
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const info = await file.stat();
|
|
35
|
+
if (!info.isFile() || info.size !== artifact.size)
|
|
36
|
+
throw new ArtifactContentError(409, 'artifact-changed');
|
|
37
|
+
const content = await file.readFile();
|
|
38
|
+
if (createHash('sha256').update(content).digest('hex') !== sha256)
|
|
39
|
+
throw new ArtifactContentError(409, 'artifact-changed');
|
|
40
|
+
return content;
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
await file.close();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function notifyDesktop(title: string, message: string, url?: string): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** macOS banner for a new workbench request. terminal-notifier opens the page on click; osascript only shows the banner. Failures are ignored. */
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
export function notifyDesktop(title, message, url) {
|
|
4
|
+
if (process.platform !== 'darwin')
|
|
5
|
+
return;
|
|
6
|
+
execFile('terminal-notifier', ['-title', title, '-message', message, ...(url ? ['-open', url] : [])], error => {
|
|
7
|
+
if (!error)
|
|
8
|
+
return;
|
|
9
|
+
// argv keeps the text out of the AppleScript source.
|
|
10
|
+
execFile('osascript', ['-e', 'on run argv', '-e', 'display notification (item 2 of argv) with title (item 1 of argv)', '-e', 'end run', title, message], () => { });
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Session-scoped link from the DSH prompt to the gateway job that is waiting on it. */
|
|
2
|
+
export interface A2AExecutionRef {
|
|
3
|
+
jobId: string;
|
|
4
|
+
attemptId: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function bindA2AExecution(sessionId: string, execution: A2AExecutionRef): void;
|
|
7
|
+
export declare function currentA2AExecution(sessionId: string): A2AExecutionRef | undefined;
|
|
8
|
+
/** Clears the binding only when it still belongs to this attempt. */
|
|
9
|
+
export declare function unbindA2AExecution(sessionId: string, execution?: A2AExecutionRef): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const bindings = new Map();
|
|
2
|
+
export function bindA2AExecution(sessionId, execution) {
|
|
3
|
+
if (!sessionId.trim() || !execution.jobId.trim() || !execution.attemptId.trim())
|
|
4
|
+
throw new Error('A2A execution binding requires a session, job, and attempt');
|
|
5
|
+
bindings.set(sessionId, { jobId: execution.jobId, attemptId: execution.attemptId });
|
|
6
|
+
}
|
|
7
|
+
export function currentA2AExecution(sessionId) {
|
|
8
|
+
const value = bindings.get(sessionId);
|
|
9
|
+
return value ? { ...value } : undefined;
|
|
10
|
+
}
|
|
11
|
+
/** Clears the binding only when it still belongs to this attempt. */
|
|
12
|
+
export function unbindA2AExecution(sessionId, execution) {
|
|
13
|
+
const current = bindings.get(sessionId);
|
|
14
|
+
if (!current)
|
|
15
|
+
return;
|
|
16
|
+
if (execution && (current.jobId !== execution.jobId || current.attemptId !== execution.attemptId))
|
|
17
|
+
return;
|
|
18
|
+
bindings.delete(sessionId);
|
|
19
|
+
}
|
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
import { type SendMessageRequest } from '@a2a-js/sdk';
|
|
2
2
|
import { type AgentExecutor, type ExecutionEventBus, type RequestContext } from '@a2a-js/sdk/server';
|
|
3
3
|
import type { FileA2AStore } from './store.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type A2ABackend, type A2APrepareInput } from './types.js';
|
|
5
5
|
import { type A2AResultContract } from './result-metadata.js';
|
|
6
|
+
import { type CapacityOptions } from '../capacity.js';
|
|
6
7
|
export interface A2AExecutionOptions {
|
|
8
|
+
/** Trusted host policy. All A2A executions are automatic; request metadata cannot override it. */
|
|
9
|
+
capacity?: CapacityOptions;
|
|
7
10
|
defaultCwd?: string;
|
|
8
11
|
defaultAgentPreset?: string;
|
|
9
12
|
workspaces?: Record<string, string>;
|
|
13
|
+
/** Profiles and the writable cache root are controlled by the execution host. */
|
|
14
|
+
roleSkills?: {
|
|
15
|
+
cacheRoot: string;
|
|
16
|
+
profiles: Record<string, string>;
|
|
17
|
+
/** Optional compatibility binding for fresh fixed-preset contexts only. */
|
|
18
|
+
presetRoles?: Record<string, string>;
|
|
19
|
+
};
|
|
10
20
|
}
|
|
21
|
+
/** Validate trusted host configuration before acquiring a state-directory lease. */
|
|
22
|
+
export declare function validateA2AExecutionOptions(options: A2AExecutionOptions): void;
|
|
11
23
|
/** Validate application metadata before the SDK starts an execution. */
|
|
12
24
|
export declare function parseA2AInput(request: SendMessageRequest, options: A2AExecutionOptions): {
|
|
13
25
|
prompt: string;
|
|
14
26
|
input: A2APrepareInput;
|
|
15
27
|
resultContract?: A2AResultContract;
|
|
28
|
+
execution?: {
|
|
29
|
+
jobId: string;
|
|
30
|
+
attemptId: string;
|
|
31
|
+
};
|
|
16
32
|
};
|
|
17
33
|
/** SDK owns the execution lifetime; an HTTP disconnect never aborts this signal. */
|
|
18
34
|
export declare class A2ASessionExecutor implements AgentExecutor {
|
|
19
35
|
private readonly backend;
|
|
20
36
|
private readonly store;
|
|
21
37
|
private readonly options;
|
|
38
|
+
private readonly capacity;
|
|
22
39
|
private readonly active;
|
|
23
40
|
private readonly awaitingInput;
|
|
24
41
|
private readonly preparing;
|
|
25
42
|
private stopped;
|
|
26
43
|
constructor(backend: A2ABackend, store: FileA2AStore, options: A2AExecutionOptions);
|
|
44
|
+
private roleIdFor;
|
|
45
|
+
private roleFor;
|
|
27
46
|
isRunning(taskId: string): boolean;
|
|
47
|
+
/** A person took the session over: the pending question is no longer answered through A2A. */
|
|
48
|
+
releaseInput(taskId: string): void;
|
|
28
49
|
execute(context: RequestContext, bus: ExecutionEventBus): Promise<void>;
|
|
29
50
|
cancelTask(taskId: string, bus: ExecutionEventBus): Promise<void>;
|
|
30
51
|
close(): Promise<void>;
|
package/dist/src/a2a/executor.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
/** Official A2A executor with durable DSH context bindings and independent turns. */
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { lstat, mkdir, readFile, realpath } from 'node:fs/promises';
|
|
4
|
+
import { isAbsolute, join, relative, sep } from 'node:path';
|
|
3
5
|
import { Role, Task, TaskState, Message } from '@a2a-js/sdk';
|
|
4
6
|
import { ContentTypeNotSupportedError, RequestMalformedError, UnsupportedOperationError } from '@a2a-js/sdk/errors';
|
|
5
7
|
import { AgentEvent, resolveUserScope } from '@a2a-js/sdk/server';
|
|
6
8
|
import { a2aRequestId } from './request-id.js';
|
|
7
9
|
import { toSafeError } from '@1agents/acp-service/runtime';
|
|
10
|
+
import { a2aRoleSkillsSchema } from './types.js';
|
|
11
|
+
import { resolveRoleSkills } from '../roles/index.js';
|
|
12
|
+
import { agentPromptPrefix, readAgentFile } from '../execution/agent-files.js';
|
|
8
13
|
import { A2APreflightError, a2aPreflightRequirementsSchema } from './preflight.js';
|
|
9
14
|
import { a2aResultContractSchema, A2AResultValidationError, createA2AResultMetadata, saveA2AResultMetadata } from './result-metadata.js';
|
|
15
|
+
import { CapacityGovernor, CapacityError } from '../capacity.js';
|
|
16
|
+
import { CapacityQueue } from '../capacity-queue.js';
|
|
10
17
|
const FAILURE_MESSAGES = {
|
|
11
18
|
'missing-final-answer': 'DSH completed the task without a final answer; ACP final-answer metadata contained no final output',
|
|
12
19
|
'max-tokens': 'DSH reached the model output token limit',
|
|
@@ -17,6 +24,60 @@ const FAILURE_MESSAGES = {
|
|
|
17
24
|
aborted: 'DSH task execution was canceled',
|
|
18
25
|
interrupted: 'DSH task execution was interrupted',
|
|
19
26
|
};
|
|
27
|
+
/** Validate trusted host configuration before acquiring a state-directory lease. */
|
|
28
|
+
export function validateA2AExecutionOptions(options) {
|
|
29
|
+
new CapacityGovernor(options.capacity);
|
|
30
|
+
const roles = options.roleSkills;
|
|
31
|
+
if (roles === undefined)
|
|
32
|
+
return;
|
|
33
|
+
if (!roles || typeof roles !== 'object' || typeof roles.cacheRoot !== 'string' || !isAbsolute(roles.cacheRoot) || roles.cacheRoot.includes('\0')
|
|
34
|
+
|| !roles.profiles || typeof roles.profiles !== 'object' || Array.isArray(roles.profiles)
|
|
35
|
+
|| Object.entries(roles.profiles).some(([id, path]) => !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/.test(id)
|
|
36
|
+
|| typeof path !== 'string' || !isAbsolute(path) || path.includes('\0')))
|
|
37
|
+
throw new Error('Role skills require host-owned absolute cache and profile paths');
|
|
38
|
+
if (roles.presetRoles !== undefined && (!roles.presetRoles || typeof roles.presetRoles !== 'object' || Array.isArray(roles.presetRoles)
|
|
39
|
+
|| Object.entries(roles.presetRoles).some(([preset, roleId]) => !preset.trim() || preset.length > 256 || preset.includes('\0')
|
|
40
|
+
|| typeof roleId !== 'string' || !Object.hasOwn(roles.profiles, roleId))))
|
|
41
|
+
throw new Error('Role preset bindings must reference registered host profiles');
|
|
42
|
+
}
|
|
43
|
+
class RoleSkillLoadingError extends Error {
|
|
44
|
+
constructor(cause) { super('Role skills could not be loaded or verified; the model was not started', { cause }); }
|
|
45
|
+
}
|
|
46
|
+
const sessionFailureCodes = new Set(['SESSION_NOT_FOUND', 'SESSION_DELETED', 'SESSION_CLOSED', 'SESSION_CONFLICT', 'SESSION_ATTACH_IN_PROGRESS', 'MODEL_UNAVAILABLE', 'MODEL_SELECTION_UNSUPPORTED']);
|
|
47
|
+
function sessionFailureCode(error) {
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
const queue = [error];
|
|
50
|
+
while (queue.length) {
|
|
51
|
+
const current = queue.shift();
|
|
52
|
+
if (!current || typeof current !== 'object' || seen.has(current))
|
|
53
|
+
continue;
|
|
54
|
+
seen.add(current);
|
|
55
|
+
const record = current;
|
|
56
|
+
if (typeof record.code === 'string' && sessionFailureCodes.has(record.code))
|
|
57
|
+
return record.code;
|
|
58
|
+
if (record.code === -32003 || record.message === 'Session was deleted')
|
|
59
|
+
return 'SESSION_DELETED';
|
|
60
|
+
if (typeof record.message === 'string' && /cwd conflicts|preset conflicts|identity conflicts/.test(record.message))
|
|
61
|
+
return 'SESSION_CONFLICT';
|
|
62
|
+
if (record.cause !== undefined)
|
|
63
|
+
queue.push(record.cause);
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
async function waitForPreparation(previous, signal) {
|
|
68
|
+
signal.throwIfAborted();
|
|
69
|
+
let abort;
|
|
70
|
+
const canceled = new Promise((_, reject) => {
|
|
71
|
+
abort = () => reject(signal.reason);
|
|
72
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
await Promise.race([previous, canceled]);
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
signal.removeEventListener('abort', abort);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
20
81
|
/** Validate application metadata before the SDK starts an execution. */
|
|
21
82
|
export function parseA2AInput(request, options) {
|
|
22
83
|
const message = request.message;
|
|
@@ -33,12 +94,23 @@ export function parseA2AInput(request, options) {
|
|
|
33
94
|
throw new RequestMalformedError('metadata.1agents must be an object');
|
|
34
95
|
const value = (metadata ?? {});
|
|
35
96
|
for (const key of Object.keys(value))
|
|
36
|
-
if (!['cwd', 'agentPreset', 'workspace', 'preflight', 'resultContract'].includes(key))
|
|
97
|
+
if (!['cwd', 'agentPreset', 'workspace', 'preflight', 'resultContract', 'roleId', 'roleLockPath', 'agentFile', 'provider', 'model', 'execution'].includes(key))
|
|
37
98
|
throw new RequestMalformedError(`Unknown metadata.1agents field: ${key}`);
|
|
38
|
-
for (const key of ['cwd', 'agentPreset', 'workspace']) {
|
|
99
|
+
for (const key of ['cwd', 'agentPreset', 'workspace', 'roleId', 'roleLockPath', 'agentFile', 'provider', 'model']) {
|
|
39
100
|
if (value[key] !== undefined && (typeof value[key] !== 'string' || !value[key].trim()))
|
|
40
101
|
throw new RequestMalformedError(`${key} must be a nonempty string`);
|
|
41
102
|
}
|
|
103
|
+
if ((value.provider === undefined) !== (value.model === undefined))
|
|
104
|
+
throw new RequestMalformedError('provider and model must be passed together');
|
|
105
|
+
if (value.roleId !== undefined && (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/.test(value.roleId)
|
|
106
|
+
|| !options.roleSkills || !Object.hasOwn(options.roleSkills.profiles, value.roleId)))
|
|
107
|
+
throw new RequestMalformedError('Unknown host role');
|
|
108
|
+
if (value.roleLockPath !== undefined && (!options.roleSkills || !isAbsolute(value.roleLockPath)
|
|
109
|
+
|| value.roleLockPath.includes('\0')))
|
|
110
|
+
throw new RequestMalformedError('Invalid role lock path');
|
|
111
|
+
if (value.agentFile !== undefined && (!isAbsolute(value.agentFile) || value.agentFile.includes('\0')
|
|
112
|
+
|| value.roleId !== undefined || value.roleLockPath !== undefined))
|
|
113
|
+
throw new RequestMalformedError('agentFile must be an absolute path and cannot be combined with a host role');
|
|
42
114
|
if (value.cwd && value.workspace)
|
|
43
115
|
throw new RequestMalformedError('Use cwd or workspace, not both');
|
|
44
116
|
let cwd = value.cwd;
|
|
@@ -53,15 +125,38 @@ export function parseA2AInput(request, options) {
|
|
|
53
125
|
const resultContract = value.resultContract === undefined ? undefined : a2aResultContractSchema.safeParse(value.resultContract);
|
|
54
126
|
if (resultContract && !resultContract.success)
|
|
55
127
|
throw new RequestMalformedError('Invalid result contract');
|
|
128
|
+
const execution = executionOf(value.execution);
|
|
56
129
|
return { prompt, input: { cwd, agentPreset: value.agentPreset,
|
|
57
|
-
...(preflight?.success ? { preflight: preflight.data } : {})
|
|
58
|
-
|
|
130
|
+
...(preflight?.success ? { preflight: preflight.data } : {}),
|
|
131
|
+
...(value.roleId ? { roleId: value.roleId } : {}),
|
|
132
|
+
...(value.roleLockPath ? { roleLockPath: value.roleLockPath } : {}),
|
|
133
|
+
...(value.agentFile ? { agentFile: value.agentFile } : {}),
|
|
134
|
+
...(value.provider ? { provider: value.provider, model: value.model } : {}) },
|
|
135
|
+
...(resultContract?.success ? { resultContract: resultContract.data } : {}),
|
|
136
|
+
...(execution ? { execution } : {}) };
|
|
137
|
+
}
|
|
138
|
+
function executionOf(value) {
|
|
139
|
+
if (value === undefined)
|
|
140
|
+
return undefined;
|
|
141
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
142
|
+
throw new RequestMalformedError('execution must be an object');
|
|
143
|
+
const record = value;
|
|
144
|
+
for (const key of Object.keys(record))
|
|
145
|
+
if (key !== 'jobId' && key !== 'attemptId')
|
|
146
|
+
throw new RequestMalformedError(`Unknown metadata.1agents.execution field: ${key}`);
|
|
147
|
+
for (const key of ['jobId', 'attemptId']) {
|
|
148
|
+
const item = record[key];
|
|
149
|
+
if (typeof item !== 'string' || !item.trim() || item.length > 512 || item.includes('\0'))
|
|
150
|
+
throw new RequestMalformedError(`execution.${key} must be a nonempty string`);
|
|
151
|
+
}
|
|
152
|
+
return { jobId: record.jobId.trim(), attemptId: record.attemptId.trim() };
|
|
59
153
|
}
|
|
60
154
|
/** SDK owns the execution lifetime; an HTTP disconnect never aborts this signal. */
|
|
61
155
|
export class A2ASessionExecutor {
|
|
62
156
|
backend;
|
|
63
157
|
store;
|
|
64
158
|
options;
|
|
159
|
+
capacity;
|
|
65
160
|
active = new Map();
|
|
66
161
|
awaitingInput = new Map();
|
|
67
162
|
preparing = new Map();
|
|
@@ -70,8 +165,67 @@ export class A2ASessionExecutor {
|
|
|
70
165
|
this.backend = backend;
|
|
71
166
|
this.store = store;
|
|
72
167
|
this.options = options;
|
|
168
|
+
validateA2AExecutionOptions(options);
|
|
169
|
+
this.capacity = new CapacityQueue(options.capacity);
|
|
170
|
+
}
|
|
171
|
+
roleIdFor(input, saved) {
|
|
172
|
+
if (input.roleId)
|
|
173
|
+
return input.roleId;
|
|
174
|
+
// Existing contexts keep their original typed or untyped identity even if
|
|
175
|
+
// the host later adds or changes preset-to-role compatibility bindings.
|
|
176
|
+
if (saved)
|
|
177
|
+
return saved.roleId;
|
|
178
|
+
const preset = input.agentPreset ?? this.options.defaultAgentPreset, bindings = this.options.roleSkills?.presetRoles;
|
|
179
|
+
return preset && bindings && Object.hasOwn(bindings, preset) ? bindings[preset] : undefined;
|
|
180
|
+
}
|
|
181
|
+
async roleFor(input, saved, contextKey, signal) {
|
|
182
|
+
const roleId = this.roleIdFor(input, saved);
|
|
183
|
+
if (!roleId) {
|
|
184
|
+
if (input.roleLockPath)
|
|
185
|
+
throw new Error('A role lock requires a role identity');
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
if (saved && (!saved.roleSkills || saved.roleId !== roleId))
|
|
189
|
+
throw new Error('An existing context cannot change its role');
|
|
190
|
+
const configuration = this.options.roleSkills;
|
|
191
|
+
if (!configuration || !Object.hasOwn(configuration.profiles, roleId))
|
|
192
|
+
throw new Error('The saved role is no longer configured on this host');
|
|
193
|
+
await mkdir(join(configuration.cacheRoot, 'locks'), { recursive: true, mode: 0o700 });
|
|
194
|
+
const lockRootInfo = await lstat(join(configuration.cacheRoot, 'locks'));
|
|
195
|
+
if (!lockRootInfo.isDirectory() || lockRootInfo.isSymbolicLink())
|
|
196
|
+
throw new Error('The host role locks directory must be a real directory');
|
|
197
|
+
const lockRoot = await realpath(join(configuration.cacheRoot, 'locks'));
|
|
198
|
+
const existingPath = saved?.roleSkills?.lockPath ?? input.roleLockPath;
|
|
199
|
+
let lockPath;
|
|
200
|
+
if (existingPath) {
|
|
201
|
+
const info = await lstat(existingPath);
|
|
202
|
+
const actual = await realpath(existingPath), tail = relative(lockRoot, actual);
|
|
203
|
+
if (!info.isFile() || info.isSymbolicLink() || tail === '' || tail === '..' || tail.startsWith(`..${sep}`) || isAbsolute(tail))
|
|
204
|
+
throw new Error('Role lock must be an existing regular file inside the host locks directory');
|
|
205
|
+
// Preserve a saved summary byte-for-byte when a migrated cache retains
|
|
206
|
+
// the old root as a compatible alias. Fresh contexts use canonical paths.
|
|
207
|
+
lockPath = saved?.roleSkills?.lockPath ?? actual;
|
|
208
|
+
if (saved?.roleSkills && input.roleLockPath && await realpath(input.roleLockPath) !== actual)
|
|
209
|
+
throw new Error('An existing context cannot change its role lock');
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
lockPath = join(lockRoot, `a2a-${createHash('sha256').update(contextKey).digest('hex')}.json`);
|
|
213
|
+
}
|
|
214
|
+
const lock = await resolveRoleSkills({ profilePath: configuration.profiles[roleId], cacheRoot: configuration.cacheRoot, lockPath, signal });
|
|
215
|
+
const summary = a2aRoleSkillsSchema.parse({ roleId: lock.roleId, roleVersion: lock.roleVersion, lockPath,
|
|
216
|
+
roleDirectory: lock.roleDirectory, ...(lock.entryGuidePath ? { entryGuidePath: lock.entryGuidePath } : {}),
|
|
217
|
+
skills: lock.skills.map(({ key, skillId, sourceId, name, revision, directory, guidePath }) => ({ key, skillId, sourceId, name, revision, directory, guidePath })) });
|
|
218
|
+
if (saved?.roleSkills && JSON.stringify(saved.roleSkills) !== JSON.stringify(summary))
|
|
219
|
+
throw new Error('Saved role skill identity differs from its verified lock');
|
|
220
|
+
const instructions = lock.instructionsPath ? await readFile(lock.instructionsPath, 'utf8') : '';
|
|
221
|
+
if (Buffer.byteLength(instructions) > 65536)
|
|
222
|
+
throw new Error('Role instructions exceed the host prompt budget');
|
|
223
|
+
const guides = summary.skills.map(skill => `- ${skill.key}: ${skill.guidePath} (revision=${skill.revision})`).join('\n');
|
|
224
|
+
return { roleId, summary, promptPrefix: `宿主已加载角色 ${roleId},本任务技能锁:${lockPath}。仅使用此锁及下列缓存技能,不重新检索或切换版本;续派和恢复沿用同一锁。先读取适用指南及其配套资源。\n${guides}\n${instructions}\n\n上游任务:\n` };
|
|
73
225
|
}
|
|
74
226
|
isRunning(taskId) { return this.active.has(taskId); }
|
|
227
|
+
/** A person took the session over: the pending question is no longer answered through A2A. */
|
|
228
|
+
releaseInput(taskId) { this.awaitingInput.delete(taskId); }
|
|
75
229
|
async execute(context, bus) {
|
|
76
230
|
if (this.stopped)
|
|
77
231
|
throw new UnsupportedOperationError('A2A host is stopping');
|
|
@@ -89,49 +243,172 @@ export class A2ASessionExecutor {
|
|
|
89
243
|
const startedAt = new Date().toISOString();
|
|
90
244
|
let resultContract;
|
|
91
245
|
let resultMetadata;
|
|
246
|
+
let capacityLease;
|
|
247
|
+
let capacityFailure;
|
|
92
248
|
// DSH deduplicates prompts by rpcId across the whole session. A Task can
|
|
93
249
|
// have several input-required turns, each with its own message identity.
|
|
94
250
|
const requestId = a2aRequestId(context.taskId, context.userMessage.messageId);
|
|
95
|
-
const status = (state, text, error) => {
|
|
251
|
+
const status = (state, text, error, capacity, slots) => {
|
|
96
252
|
bus.publish(AgentEvent.statusUpdate({ taskId: context.taskId, contextId: context.contextId,
|
|
97
253
|
status: { state, timestamp: new Date().toISOString(), message: text ? Message.fromJSON({
|
|
98
254
|
messageId: randomUUID(), role: 'ROLE_AGENT', contextId: context.contextId, taskId: context.taskId, parts: [{ text }],
|
|
99
|
-
}) : undefined }, metadata: error || resultMetadata ? { '1agents': {
|
|
255
|
+
}) : undefined }, metadata: target || error || resultMetadata || capacity || slots ? { '1agents': {
|
|
100
256
|
...target, ...(resultMetadata ? { result: resultMetadata } : {}), ...(error ? { error } : {}),
|
|
257
|
+
...(capacity ? { capacity } : {}),
|
|
258
|
+
...(slots ? { taskSlot: slots.taskSlot, processSlot: slots.processSlot } : {}),
|
|
101
259
|
} } : undefined }));
|
|
102
260
|
};
|
|
261
|
+
const submitted = (text) => {
|
|
262
|
+
if (published)
|
|
263
|
+
return;
|
|
264
|
+
const task = Task.fromJSON({ ...Task.toJSON(context.task ?? Task.fromJSON({ id: context.taskId, contextId: context.contextId })),
|
|
265
|
+
status: { state: 'TASK_STATE_SUBMITTED', timestamp: new Date().toISOString(),
|
|
266
|
+
...(text ? { message: { messageId: randomUUID(), role: 'ROLE_AGENT', contextId: context.contextId,
|
|
267
|
+
taskId: context.taskId, parts: [{ text }] } } : {}) },
|
|
268
|
+
metadata: { ...context.task?.metadata, '1agents': target ?? {} } });
|
|
269
|
+
bus.publish(AgentEvent.task(task));
|
|
270
|
+
published = true;
|
|
271
|
+
};
|
|
272
|
+
const pendingCapacity = () => {
|
|
273
|
+
const message = 'Pending: waiting in FIFO order for device memory and ACP capacity.';
|
|
274
|
+
submitted(message);
|
|
275
|
+
status(TaskState.TASK_STATE_SUBMITTED, message);
|
|
276
|
+
};
|
|
277
|
+
const acquireCapacity = (signal = controller.signal) => this.capacity.acquire({ kind: 'task', source: 'automatic', id: requestId }, {
|
|
278
|
+
signal, onPending: pendingCapacity,
|
|
279
|
+
});
|
|
280
|
+
const beforeStart = async (hostSignal) => {
|
|
281
|
+
const signal = hostSignal ? AbortSignal.any([controller.signal, hostSignal]) : controller.signal;
|
|
282
|
+
for (;;) {
|
|
283
|
+
signal.throwIfAborted();
|
|
284
|
+
try {
|
|
285
|
+
await capacityLease.recheck();
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
if (!(error instanceof CapacityError))
|
|
290
|
+
throw error;
|
|
291
|
+
await capacityLease.release();
|
|
292
|
+
capacityLease = undefined;
|
|
293
|
+
pendingCapacity();
|
|
294
|
+
capacityLease = await acquireCapacity(signal);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
signal.throwIfAborted();
|
|
298
|
+
// ACP process admission is still ahead of this call. Stay submitted until the slot is held.
|
|
299
|
+
if (!target?.agentPreset?.startsWith('oneagents-acp-'))
|
|
300
|
+
status(TaskState.TASK_STATE_WORKING);
|
|
301
|
+
};
|
|
103
302
|
try {
|
|
104
303
|
const parsed = parseA2AInput(context.request, this.options);
|
|
105
304
|
const { prompt, input } = parsed;
|
|
106
305
|
resultContract = parsed.resultContract;
|
|
306
|
+
// Only role loading needs early admission for potentially cold packages.
|
|
307
|
+
// Ordinary clients retain the first Task's prepared session metadata.
|
|
308
|
+
if (this.roleIdFor(input, this.store.loadTarget(context.contextId, context.context)))
|
|
309
|
+
submitted();
|
|
107
310
|
const key = JSON.stringify([context.context.tenant ?? '', resolveUserScope(context.context), context.contextId]);
|
|
311
|
+
if (this.preparing.has(key)) {
|
|
312
|
+
const message = 'Pending: waiting for an earlier task to prepare this session.';
|
|
313
|
+
submitted(message);
|
|
314
|
+
status(TaskState.TASK_STATE_SUBMITTED, message);
|
|
315
|
+
}
|
|
108
316
|
const previous = this.preparing.get(key) ?? Promise.resolve();
|
|
317
|
+
let promptPrefix = '';
|
|
109
318
|
let unlock;
|
|
110
319
|
const lock = new Promise(resolve => { unlock = resolve; });
|
|
111
|
-
|
|
320
|
+
// A canceled waiter must not let later requests bypass its still-pending predecessor.
|
|
321
|
+
const tail = previous.then(() => lock);
|
|
322
|
+
this.preparing.set(key, tail);
|
|
323
|
+
void tail.then(() => { if (this.preparing.get(key) === tail)
|
|
324
|
+
this.preparing.delete(key); });
|
|
112
325
|
try {
|
|
113
|
-
await previous;
|
|
326
|
+
await waitForPreparation(previous, controller.signal);
|
|
114
327
|
controller.signal.throwIfAborted();
|
|
115
328
|
const saved = this.store.loadTarget(context.contextId, context.context);
|
|
329
|
+
if (saved?.state === 'deleted')
|
|
330
|
+
throw Object.assign(new Error('Session was deleted'), { code: 'SESSION_DELETED' });
|
|
331
|
+
if (saved?.roleSkills)
|
|
332
|
+
submitted();
|
|
333
|
+
let role;
|
|
334
|
+
try {
|
|
335
|
+
role = await this.roleFor(input, saved, key, controller.signal);
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
throw new RoleSkillLoadingError(error);
|
|
339
|
+
}
|
|
340
|
+
controller.signal.throwIfAborted();
|
|
341
|
+
const agentPreset = input.agentPreset ?? saved?.agentPreset ?? this.options.defaultAgentPreset;
|
|
342
|
+
// ACP Agents publish their own model options through session/set_config_option.
|
|
343
|
+
if (input.provider && agentPreset?.startsWith('oneagents-acp-'))
|
|
344
|
+
throw Object.assign(new Error('provider and model apply only to standard presets'), { code: 'MODEL_SELECTION_UNSUPPORTED' });
|
|
345
|
+
// ACP session preparation can itself wait in the process FIFO.
|
|
346
|
+
if (agentPreset?.startsWith('oneagents-acp-'))
|
|
347
|
+
pendingCapacity();
|
|
348
|
+
// Acquire only after context/role waits, immediately before session creation.
|
|
349
|
+
capacityLease = await acquireCapacity();
|
|
350
|
+
controller.signal.throwIfAborted();
|
|
116
351
|
target = await this.backend.prepare({ sessionId: saved?.sessionId,
|
|
117
352
|
cwd: input.cwd ?? saved?.cwd ?? this.options.defaultCwd,
|
|
118
|
-
agentPreset
|
|
119
|
-
...(input.preflight ? { preflight: input.preflight } : {})
|
|
353
|
+
agentPreset,
|
|
354
|
+
...(input.preflight ? { preflight: input.preflight } : {}),
|
|
355
|
+
...(input.provider ? { provider: input.provider, model: input.model } : {}) }, { signal: controller.signal });
|
|
356
|
+
if (input.provider && !target.provider)
|
|
357
|
+
throw Object.assign(new Error('The host did not apply the requested model'), { code: 'MODEL_UNAVAILABLE' });
|
|
358
|
+
// The DSH session keeps its earlier selection; report it until a new value is passed.
|
|
359
|
+
if (!target.provider && saved?.provider) {
|
|
360
|
+
target.provider = saved.provider;
|
|
361
|
+
target.model = saved.model;
|
|
362
|
+
}
|
|
363
|
+
if (role) {
|
|
364
|
+
target.roleId = role.roleId;
|
|
365
|
+
target.roleSkills = role.summary;
|
|
366
|
+
promptPrefix = role.promptPrefix;
|
|
367
|
+
}
|
|
368
|
+
// A path agent's role is read on this host, inside the session's real cwd. A continuation already carries it in its history.
|
|
369
|
+
if (input.agentFile && !saved?.sessionId) {
|
|
370
|
+
if (role)
|
|
371
|
+
throw Object.assign(new Error('A path agent cannot also take a host role bound to its preset'), { code: 'AGENT_FILE_INVALID' });
|
|
372
|
+
let agent;
|
|
373
|
+
try {
|
|
374
|
+
agent = await readAgentFile(input.agentFile, target.cwd ?? '');
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
throw Object.assign(new Error(`Cannot load path agent: ${error instanceof Error ? error.message : String(error)}`), { code: 'AGENT_FILE_INVALID' });
|
|
378
|
+
}
|
|
379
|
+
promptPrefix = agentPromptPrefix(agent);
|
|
380
|
+
}
|
|
120
381
|
this.store.saveTarget(context.contextId, target, context.context);
|
|
121
382
|
}
|
|
122
383
|
finally {
|
|
123
384
|
unlock();
|
|
124
|
-
if (this.preparing.get(key) === lock)
|
|
125
|
-
this.preparing.delete(key);
|
|
126
385
|
}
|
|
127
|
-
|
|
128
|
-
status: { state: 'TASK_STATE_SUBMITTED', timestamp: new Date().toISOString() },
|
|
129
|
-
metadata: { ...context.task?.metadata, '1agents': target } });
|
|
130
|
-
bus.publish(AgentEvent.task(task));
|
|
131
|
-
published = true;
|
|
386
|
+
submitted();
|
|
132
387
|
controller.signal.throwIfAborted();
|
|
133
|
-
|
|
134
|
-
|
|
388
|
+
// Preparation can include I/O or a cold ACP handshake. Never start the
|
|
389
|
+
// model using a memory observation taken before that work.
|
|
390
|
+
await beforeStart();
|
|
391
|
+
const onCapacity = (pending) => {
|
|
392
|
+
if (!target?.agentPreset?.startsWith('oneagents-acp-'))
|
|
393
|
+
return;
|
|
394
|
+
void this.capacity.slotView().then(slots => {
|
|
395
|
+
if (pending) {
|
|
396
|
+
submitted();
|
|
397
|
+
status(TaskState.TASK_STATE_SUBMITTED, 'CAPACITY_PENDING', undefined, pending, slots);
|
|
398
|
+
}
|
|
399
|
+
else
|
|
400
|
+
status(TaskState.TASK_STATE_WORKING, undefined, undefined, undefined, slots);
|
|
401
|
+
}).catch(() => {
|
|
402
|
+
if (pending) {
|
|
403
|
+
submitted();
|
|
404
|
+
status(TaskState.TASK_STATE_SUBMITTED, 'CAPACITY_PENDING', undefined, pending);
|
|
405
|
+
}
|
|
406
|
+
else
|
|
407
|
+
status(TaskState.TASK_STATE_WORKING);
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
const result = await this.backend.run(target, promptPrefix + prompt, { requestId, signal: controller.signal, beforeStart, onCapacity,
|
|
411
|
+
...(parsed.execution ? { execution: parsed.execution } : {}) });
|
|
135
412
|
returnedError = result.outcome === 'failed' && result.error !== undefined
|
|
136
413
|
? toSafeError(result.error, { origin: 'a2a', operationId: requestId }) : undefined;
|
|
137
414
|
returnedFailureMessage = result.outcome === 'failed' && typeof result.failureReason === 'string' && Object.hasOwn(FAILURE_MESSAGES, result.failureReason)
|
|
@@ -164,6 +441,8 @@ export class A2ASessionExecutor {
|
|
|
164
441
|
status(result.outcome === 'completed' ? TaskState.TASK_STATE_COMPLETED : result.outcome === 'input-required' ? TaskState.TASK_STATE_INPUT_REQUIRED : TaskState.TASK_STATE_FAILED, returnedFailureMessage ?? error?.message ?? result.detail, error);
|
|
165
442
|
}
|
|
166
443
|
catch (error) {
|
|
444
|
+
if (error instanceof CapacityError)
|
|
445
|
+
capacityFailure = error;
|
|
167
446
|
if (!published)
|
|
168
447
|
bus.publish(AgentEvent.task(Task.fromJSON({ id: context.taskId, contextId: context.contextId,
|
|
169
448
|
status: { state: 'TASK_STATE_SUBMITTED', timestamp: new Date().toISOString() } })));
|
|
@@ -174,7 +453,7 @@ export class A2ASessionExecutor {
|
|
|
174
453
|
});
|
|
175
454
|
resultMetadata = await createA2AResultMetadata({ taskId: context.taskId, contextId: context.contextId,
|
|
176
455
|
requestId, startedAt, outcome: controller.signal.aborted ? 'canceled' : 'failed', target, contract: resultContract,
|
|
177
|
-
validationCode: error instanceof A2AResultValidationError ? error.code : undefined,
|
|
456
|
+
validationCode: capacityFailure?.code ?? sessionFailureCode(error) ?? (error instanceof A2AResultValidationError ? error.code : error instanceof RoleSkillLoadingError ? 'role-skills-unavailable' : undefined),
|
|
178
457
|
...(error instanceof A2APreflightError ? { preflight: error.report } : {}) });
|
|
179
458
|
try {
|
|
180
459
|
await saveA2AResultMetadata(resultMetadata, target);
|
|
@@ -183,9 +462,16 @@ export class A2ASessionExecutor {
|
|
|
183
462
|
resultMetadata.validation = { status: 'failed', code: 'result-record-write-failed' };
|
|
184
463
|
delete resultMetadata.recordPath;
|
|
185
464
|
}
|
|
186
|
-
status(controller.signal.aborted ? TaskState.TASK_STATE_CANCELED : TaskState.TASK_STATE_FAILED, returnedFailureMessage ?? safe.message, safe);
|
|
465
|
+
status(controller.signal.aborted ? TaskState.TASK_STATE_CANCELED : TaskState.TASK_STATE_FAILED, capacityFailure?.message ?? returnedFailureMessage ?? safe.message, safe);
|
|
187
466
|
}
|
|
188
467
|
finally {
|
|
468
|
+
// Release failures retain the durable reservation and cannot strand close().
|
|
469
|
+
try {
|
|
470
|
+
await capacityLease?.release();
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
console.warn('ACP task capacity reservation could not be released');
|
|
474
|
+
}
|
|
189
475
|
this.active.delete(context.taskId);
|
|
190
476
|
finish();
|
|
191
477
|
}
|