@1agents/acp-service 0.9.0 → 0.10.0
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 +19 -13
- package/dist/bin/a2a.js +6 -2
- package/dist/bin/acp-service.js +25 -1
- package/dist/bin/process.d.ts +4 -0
- package/dist/bin/process.js +57 -0
- package/dist/bin/roles.js +21 -18
- 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 +7 -2
- package/dist/src/a2a/executor.js +127 -60
- package/dist/src/a2a/gateway.d.ts +581 -10
- package/dist/src/a2a/gateway.js +1018 -95
- package/dist/src/a2a/index.d.ts +8 -1
- package/dist/src/a2a/index.js +4 -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 +3 -0
- package/dist/src/a2a/result-metadata.js +27 -5
- package/dist/src/a2a/server.d.ts +10 -0
- package/dist/src/a2a/server.js +125 -1
- 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 +70 -1
- package/dist/src/a2a/types.d.ts +46 -6
- package/dist/src/a2a/types.js +4 -6
- 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 +27 -3
- package/dist/src/bridge.d.ts +1 -0
- package/dist/src/bridge.js +191 -39
- package/dist/src/capacity-queue.d.ts +35 -0
- package/dist/src/capacity-queue.js +139 -2
- package/dist/src/capacity.d.ts +25 -0
- package/dist/src/capacity.js +48 -9
- 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 +2 -0
- package/dist/src/execution/human-review.js +3 -1
- package/dist/src/execution/ledger.d.ts +52 -0
- package/dist/src/execution/ledger.js +83 -5
- package/dist/src/execution/ppt-delivery.d.ts +0 -5
- package/dist/src/execution/ppt-delivery.js +0 -26
- package/dist/src/execution/process-request.d.ts +151 -0
- package/dist/src/execution/process-request.js +177 -0
- package/dist/src/execution/targets.d.ts +64 -5
- package/dist/src/execution/targets.js +58 -7
- 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 +32 -1
- package/dist/src/execution/workbench.js +113 -22
- package/dist/src/roles/index.d.ts +1 -1
- package/dist/src/roles/index.js +1 -1
- package/dist/src/roles/skills.d.ts +27 -58
- package/dist/src/roles/skills.js +89 -404
- 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 +19 -8
- package/skills/acp-service/SKILL.md +4 -2
- package/skills/acp-service/references/a2a.md +18 -6
- package/skills/acp-service/references/dsh.md +2 -0
- package/skills/acp-service/references/roles-and-tasks.md +10 -10
- package/skills/rsi-coach/SKILL.md +134 -0
- package/vendor/dsh/README.md +10 -6
- package/vendor/dsh/a2a-executor.d.ts +56 -2
- package/vendor/dsh/a2a-executor.js +163 -17
- package/vendor/dsh/a2a.d.ts +12 -2
- package/vendor/dsh/a2a.js +9 -2
- package/vendor/dsh/adapter.d.ts +52 -3
- package/vendor/dsh/adapter.js +297 -30
- package/vendor/dsh/client.js +67 -11
- package/vendor/dsh/index.js +55 -3
- 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/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 +2 -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/package.json +6 -4
- package/vendor/runtime/skills/acpx/SKILL.md +2 -0
package/dist/src/a2a/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/** Shared A2A 1.0 server, persistent state and host-independent executor interfaces. */
|
|
2
2
|
export { createA2AServer } from './server.js';
|
|
3
3
|
export type { A2AServerOptions } from './server.js';
|
|
4
|
+
export { A2AResubmitError } from './resubmit.js';
|
|
5
|
+
export { WORKBENCH_UI_PATH, isAgentRequest, sameOriginBrowser, serveWorkbenchPage } from './workbench-ui.js';
|
|
6
|
+
export type { A2AResubmission, A2AResubmitCode, A2ASessionTask } from './resubmit.js';
|
|
4
7
|
export { FileA2AStore } from './store.js';
|
|
5
|
-
export type { A2ABackend, A2APrepareInput, A2ARunResult, A2ATarget, A2APreflightInput, A2APreflightRequirements, A2APreflightReport, A2ARoleSkills } from './types.js';
|
|
8
|
+
export type { A2ABackend, A2ACloseResult, A2APrepareInput, A2ARunResult, A2ASessionStatus, A2ATarget, A2APreflightInput, A2APreflightRequirements, A2APreflightReport, A2ARoleSkills } from './types.js';
|
|
9
|
+
export { bindA2AExecution, currentA2AExecution, unbindA2AExecution } from './execution-binding.js';
|
|
10
|
+
export type { A2AExecutionRef } from './execution-binding.js';
|
|
6
11
|
export { a2aRoleSkillsSchema } from './types.js';
|
|
7
12
|
export type { A2AExecutionOptions } from './executor.js';
|
|
8
13
|
export { a2aPreflightInputSchema, a2aPreflightRequirementsSchema, a2aPreflightReportSchema, A2APreflightError, runA2APreflight } from './preflight.js';
|
|
@@ -10,6 +15,8 @@ export { a2aResultContractSchema, A2AResultValidationError, createA2AResultMetad
|
|
|
10
15
|
export type { A2AResultContract, A2AVerifiedArtifact, A2AResultMetadata } from './result-metadata.js';
|
|
11
16
|
export { RemoteAgentGateway, serveA2AGateway, REMOTE_AGENT_METHODS } from './gateway.js';
|
|
12
17
|
export type { A2AGatewayConfig, RemoteAgentNotice } from './gateway.js';
|
|
18
|
+
export { runExecutorTicket } from '../execution/ticket-executor.js';
|
|
19
|
+
export type { ExecutorTicketArgs, ExecutorTicketChannel, ExecutorTicketScope, ExecutorTicketTool } from '../execution/ticket-executor.js';
|
|
13
20
|
export { ProjectRoleDiscovery, DISCOVERY_METHODS, projectDiscoveryConfigSchema } from '../execution/project-discovery.js';
|
|
14
21
|
export { A2AAutomation } from './automation.js';
|
|
15
22
|
export type { A2AAutomationConfig, AutomationRun, AutomationRunStatus } from './automation.js';
|
package/dist/src/a2a/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/** Shared A2A 1.0 server, persistent state and host-independent executor interfaces. */
|
|
2
2
|
export { createA2AServer } from './server.js';
|
|
3
|
+
export { A2AResubmitError } from './resubmit.js';
|
|
4
|
+
export { WORKBENCH_UI_PATH, isAgentRequest, sameOriginBrowser, serveWorkbenchPage } from './workbench-ui.js';
|
|
3
5
|
export { FileA2AStore } from './store.js';
|
|
6
|
+
export { bindA2AExecution, currentA2AExecution, unbindA2AExecution } from './execution-binding.js';
|
|
4
7
|
export { a2aRoleSkillsSchema } from './types.js';
|
|
5
8
|
export { a2aPreflightInputSchema, a2aPreflightRequirementsSchema, a2aPreflightReportSchema, A2APreflightError, runA2APreflight } from './preflight.js';
|
|
6
9
|
export { a2aResultContractSchema, A2AResultValidationError, createA2AResultMetadata, saveA2AResultMetadata } from './result-metadata.js';
|
|
7
10
|
export { RemoteAgentGateway, serveA2AGateway, REMOTE_AGENT_METHODS } from './gateway.js';
|
|
11
|
+
export { runExecutorTicket } from '../execution/ticket-executor.js';
|
|
8
12
|
export { ProjectRoleDiscovery, DISCOVERY_METHODS, projectDiscoveryConfigSchema } from '../execution/project-discovery.js';
|
|
9
13
|
export { A2AAutomation } from './automation.js';
|
|
10
14
|
export { DirectoryLease } from './lease.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const defaultJobDirectory: (cwd: string, jobId: string) => string;
|
|
2
|
+
export declare const defaultManifestPath: (cwd: string, jobId: string, attemptId: string) => string;
|
|
3
|
+
/** True for a directory strictly below `<cwd>/.1agents/jobs`. */
|
|
4
|
+
export declare function isDefaultJobDirectory(cwd: string, directory: string): boolean;
|
|
5
|
+
/** The agent-facing contract, appended to the task prompt. */
|
|
6
|
+
export declare function artifactInstructions(directory: string, manifest: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default per-task artifact location, relative to the task's cwd on the execution host:
|
|
3
|
+
* `<cwd>/.1agents/jobs/<jobId>/`, with one manifest per attempt. Pure POSIX path arithmetic, because the
|
|
4
|
+
* path is interpreted by the host, not by the gateway's operating system.
|
|
5
|
+
*/
|
|
6
|
+
import { posix } from 'node:path';
|
|
7
|
+
export const defaultJobDirectory = (cwd, jobId) => posix.join(cwd, '.1agents', 'jobs', jobId);
|
|
8
|
+
export const defaultManifestPath = (cwd, jobId, attemptId) => posix.join(defaultJobDirectory(cwd, jobId), `manifest-${attemptId}.json`);
|
|
9
|
+
/** True for a directory strictly below `<cwd>/.1agents/jobs`. */
|
|
10
|
+
export function isDefaultJobDirectory(cwd, directory) {
|
|
11
|
+
const tail = posix.relative(posix.join(cwd, '.1agents', 'jobs'), directory);
|
|
12
|
+
return tail !== '' && tail !== '..' && !tail.startsWith('../') && !posix.isAbsolute(tail);
|
|
13
|
+
}
|
|
14
|
+
/** The agent-facing contract, appended to the task prompt. */
|
|
15
|
+
export function artifactInstructions(directory, manifest) {
|
|
16
|
+
return `\n\n---\n[产物约定] 如果本任务产生了需要交付或审核的文件,请把它们写到目录 ${directory}/ 下(目录已创建),\n`
|
|
17
|
+
+ `并在结束前写入清单 ${manifest},格式:{"artifacts":[{"path":"<文件绝对路径>","mediaType":"<可选>"}]}。\n`
|
|
18
|
+
+ '清单里的文件必须在该目录内;只有登记在清单里、并通过校验的文件才会作为产物展示。没有交付文件时不要创建清单。';
|
|
19
|
+
}
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { constants } from 'node:fs';
|
|
5
|
-
import { access, open, realpath, stat, unlink } from 'node:fs/promises';
|
|
5
|
+
import { access, lstat, mkdir, open, realpath, stat, unlink } from 'node:fs/promises';
|
|
6
6
|
import { tmpdir } from 'node:os';
|
|
7
7
|
import { isAbsolute, join, relative, sep } from 'node:path';
|
|
8
8
|
import { promisify } from 'node:util';
|
|
9
9
|
import { z } from 'zod';
|
|
10
|
+
import { isDefaultJobDirectory } from './job-directory.js';
|
|
10
11
|
const absolutePath = z.string().min(1).max(4096).refine(value => isAbsolute(value) && !value.includes('\0'), 'Expected an absolute host path');
|
|
11
12
|
const pythonModule = z.string().regex(/^[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*$/).max(200);
|
|
12
13
|
const nodeModule = z.string().regex(/^(?:@[A-Za-z0-9_.-]+\/)?[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*$/).max(200);
|
|
@@ -35,6 +36,18 @@ const within = (root, path) => {
|
|
|
35
36
|
const tail = relative(root, path);
|
|
36
37
|
return tail === '' || (!tail.startsWith(`..${sep}`) && tail !== '..' && !isAbsolute(tail));
|
|
37
38
|
};
|
|
39
|
+
/** Creates `<cwd>/.1agents/jobs/<id>` segment by segment, refusing symbolic links so nothing is created outside cwd. */
|
|
40
|
+
async function ensureDefaultJobDirectory(cwd, directory) {
|
|
41
|
+
let current = cwd;
|
|
42
|
+
for (const segment of relative(cwd, directory).split(sep)) {
|
|
43
|
+
current = join(current, segment);
|
|
44
|
+
const info = await lstat(current).catch(() => undefined);
|
|
45
|
+
if (info?.isSymbolicLink())
|
|
46
|
+
throw new Error('the default job directory path must not contain symbolic links');
|
|
47
|
+
if (!info)
|
|
48
|
+
await mkdir(current, { mode: 0o700 });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
38
51
|
const failure = (error) => error instanceof Error ? error.message.slice(0, 400) : 'Host check failed';
|
|
39
52
|
/** Enforce an explicitly supplied cwd allowlist against host realpaths and access permissions.
|
|
40
53
|
* This is an admission check, not an OS sandbox or a restriction on every file the agent can read.
|
|
@@ -95,6 +108,8 @@ export async function runA2APreflight(raw) {
|
|
|
95
108
|
await check('jobDirectory', async () => {
|
|
96
109
|
if (!cwdOk)
|
|
97
110
|
throw new Error('Cannot validate writable scope without a valid cwd');
|
|
111
|
+
if (isDefaultJobDirectory(input.cwd, input.jobDirectory))
|
|
112
|
+
await ensureDefaultJobDirectory(input.cwd, input.jobDirectory);
|
|
98
113
|
const directory = await realpath(input.jobDirectory);
|
|
99
114
|
if (!(await stat(directory)).isDirectory())
|
|
100
115
|
throw new Error('jobDirectory must already exist and be a directory');
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Task, type StreamResponse } from '@a2a-js/sdk';
|
|
2
|
+
import { ServerCallContext } from '@a2a-js/sdk/server';
|
|
3
|
+
import { type A2AResultMetadata } from './result-metadata.js';
|
|
4
|
+
import type { FileA2AStore } from './store.js';
|
|
5
|
+
export type A2AResubmitCode = 'NOT_A2A_SESSION' | 'TASK_RUNNING' | 'TASK_NOT_RESUBMITTABLE' | 'ARTIFACTS_INVALID' | 'INVALID_SUMMARY';
|
|
6
|
+
export declare class A2AResubmitError extends Error {
|
|
7
|
+
readonly code: A2AResubmitCode;
|
|
8
|
+
constructor(code: A2AResubmitCode, message: string);
|
|
9
|
+
}
|
|
10
|
+
export interface A2ASessionTask {
|
|
11
|
+
taskId: string;
|
|
12
|
+
contextId: string;
|
|
13
|
+
jobId?: string;
|
|
14
|
+
state: string;
|
|
15
|
+
running: boolean;
|
|
16
|
+
/** Completed or awaiting input, and not running: the session may be handed back. */
|
|
17
|
+
resubmittable: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface A2AResubmission {
|
|
20
|
+
taskId: string;
|
|
21
|
+
contextId: string;
|
|
22
|
+
jobId?: string;
|
|
23
|
+
artifacts: {
|
|
24
|
+
path: string;
|
|
25
|
+
size: number;
|
|
26
|
+
sha256: string;
|
|
27
|
+
}[];
|
|
28
|
+
validation: A2AResultMetadata['validation']['status'];
|
|
29
|
+
submittedAt: string;
|
|
30
|
+
}
|
|
31
|
+
interface Deps {
|
|
32
|
+
store: FileA2AStore;
|
|
33
|
+
executor: {
|
|
34
|
+
isRunning(taskId: string): boolean;
|
|
35
|
+
releaseInput(taskId: string): void;
|
|
36
|
+
};
|
|
37
|
+
push(event: StreamResponse, context: ServerCallContext, task: Task): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
export declare function a2aSessionTask(deps: Pick<Deps, 'store' | 'executor'>, sessionId: string): A2ASessionTask | undefined;
|
|
40
|
+
/** The DSH session that ran an A2A task; the gateway ledger records only the task ID. */
|
|
41
|
+
export declare function a2aTaskSession(deps: Pick<Deps, 'store'>, taskId: string): string | undefined;
|
|
42
|
+
export declare function resubmitA2ASession(deps: Deps, input: {
|
|
43
|
+
sessionId: string;
|
|
44
|
+
summary: string;
|
|
45
|
+
}): Promise<A2AResubmission>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manual takeover: a person finished a task in its DSH session and the agent hands the result back.
|
|
3
|
+
* The host re-verifies the job directory's manifest exactly as at completion; the gateway sees a newer
|
|
4
|
+
* completed snapshot and records it as a new result revision awaiting business acceptance.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { Message, Task, TaskState } from '@a2a-js/sdk';
|
|
8
|
+
import { ServerCallContext } from '@a2a-js/sdk/server';
|
|
9
|
+
import { a2aResultContractSchema, A2AResultValidationError, createA2AResultMetadata, saveA2AResultMetadata } from './result-metadata.js';
|
|
10
|
+
export class A2AResubmitError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
constructor(code, message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const SUMMARY_LIMIT = 64 * 1024;
|
|
18
|
+
const resubmittable = new Set([TaskState.TASK_STATE_COMPLETED, TaskState.TASK_STATE_INPUT_REQUIRED]);
|
|
19
|
+
const hostContext = () => new ServerCallContext({ requestedVersion: '1.0', user: { isAuthenticated: true, userName: 'dsh-a2a' } });
|
|
20
|
+
const meta = (task) => (task.metadata?.['1agents'] ?? {});
|
|
21
|
+
export function a2aSessionTask(deps, sessionId) {
|
|
22
|
+
const task = deps.store.latestTaskForSession(sessionId, hostContext());
|
|
23
|
+
if (!task)
|
|
24
|
+
return undefined;
|
|
25
|
+
const running = deps.executor.isRunning(task.id), state = task.status?.state ?? TaskState.TASK_STATE_UNSPECIFIED;
|
|
26
|
+
const jobId = meta(task).result?.lineage?.jobId;
|
|
27
|
+
return { taskId: task.id, contextId: task.contextId, ...(jobId ? { jobId } : {}), state: TaskState[state] ?? String(state),
|
|
28
|
+
running, resubmittable: !running && resubmittable.has(state) };
|
|
29
|
+
}
|
|
30
|
+
/** The DSH session that ran an A2A task; the gateway ledger records only the task ID. */
|
|
31
|
+
export function a2aTaskSession(deps, taskId) {
|
|
32
|
+
return deps.store.sessionOfTask(taskId, hostContext());
|
|
33
|
+
}
|
|
34
|
+
export async function resubmitA2ASession(deps, input) {
|
|
35
|
+
const summary = input.summary.trim();
|
|
36
|
+
if (!summary || Buffer.byteLength(summary) > SUMMARY_LIMIT)
|
|
37
|
+
throw new A2AResubmitError('INVALID_SUMMARY', 'summary must be non-empty text of at most 64 KiB');
|
|
38
|
+
const context = hostContext();
|
|
39
|
+
const task = deps.store.latestTaskForSession(input.sessionId, context);
|
|
40
|
+
if (!task)
|
|
41
|
+
throw new A2AResubmitError('NOT_A2A_SESSION', 'This session did not run an A2A workbench task');
|
|
42
|
+
if (deps.executor.isRunning(task.id))
|
|
43
|
+
throw new A2AResubmitError('TASK_RUNNING', 'The A2A turn is still running; submit after it ends');
|
|
44
|
+
if (!resubmittable.has(task.status?.state ?? TaskState.TASK_STATE_UNSPECIFIED)) {
|
|
45
|
+
throw new A2AResubmitError('TASK_NOT_RESUBMITTABLE', 'Only a completed task or one awaiting input can be handed back; dispatch a failed or canceled task again from the workbench');
|
|
46
|
+
}
|
|
47
|
+
const previous = meta(task), target = deps.store.loadTarget(task.contextId, context);
|
|
48
|
+
const { source: _source, ...declared } = previous.result?.lineage ?? {};
|
|
49
|
+
const contract = previous.result?.lineage ? a2aResultContractSchema.parse(declared) : undefined;
|
|
50
|
+
// Same verification as a completed turn: only the job directory's manifest names artifacts.
|
|
51
|
+
const result = await createA2AResultMetadata({ taskId: task.id, contextId: task.contextId, requestId: `manual-${randomUUID()}`,
|
|
52
|
+
startedAt: previous.result?.startedAt ?? new Date().toISOString(), outcome: 'completed', ...(target ? { target } : {}), ...(contract ? { contract } : {}) })
|
|
53
|
+
.catch(error => {
|
|
54
|
+
if (error instanceof A2AResultValidationError)
|
|
55
|
+
throw new A2AResubmitError('ARTIFACTS_INVALID', `Artifact manifest check failed: ${error.code}`);
|
|
56
|
+
throw error;
|
|
57
|
+
});
|
|
58
|
+
if (result.validation.status === 'failed')
|
|
59
|
+
throw new A2AResubmitError('ARTIFACTS_INVALID', `Artifact manifest check failed: ${result.validation.code}`);
|
|
60
|
+
await saveA2AResultMetadata(result, target);
|
|
61
|
+
deps.executor.releaseInput(task.id);
|
|
62
|
+
const submittedAt = result.finishedAt;
|
|
63
|
+
const verified = result.artifacts.filter(artifact => artifact.url);
|
|
64
|
+
const next = Task.fromJSON(Task.toJSON(task));
|
|
65
|
+
next.status = { state: TaskState.TASK_STATE_COMPLETED, timestamp: submittedAt, message: Message.fromJSON({
|
|
66
|
+
messageId: randomUUID(), role: 'ROLE_AGENT', contextId: task.contextId, taskId: task.id, parts: [{ text: summary }]
|
|
67
|
+
}) };
|
|
68
|
+
// The gateway reads the result text from text artifacts; the earlier answer stays in its result history.
|
|
69
|
+
next.artifacts = [
|
|
70
|
+
{ artifactId: `${task.id}-manual-${randomUUID()}`, name: 'Manual submission', description: '',
|
|
71
|
+
parts: [{ content: { $case: 'text', value: summary }, mediaType: 'text/plain', filename: '', metadata: undefined }], metadata: undefined, extensions: [] },
|
|
72
|
+
...(verified.length ? [{ artifactId: `${task.id}-verified-artifacts`, name: 'Verified artifacts', description: '',
|
|
73
|
+
parts: verified.map(artifact => ({ content: { $case: 'url', value: artifact.url }, mediaType: artifact.mediaType ?? 'application/octet-stream',
|
|
74
|
+
filename: '', metadata: { sha256: artifact.sha256, size: artifact.size } })), metadata: { verifiedBy: '1agents/a2a-host' }, extensions: [] }] : []),
|
|
75
|
+
];
|
|
76
|
+
next.metadata = { ...task.metadata, '1agents': { ...previous, result, manualSubmissions: (previous.manualSubmissions ?? 0) + 1 } };
|
|
77
|
+
await deps.store.taskStore.save(next, context);
|
|
78
|
+
// A webhook failure leaves the stored snapshot authoritative; the gateway also reads it on refresh.
|
|
79
|
+
void deps.push({ payload: { $case: 'task', value: next } }, context, next).catch(() => { });
|
|
80
|
+
return { taskId: task.id, contextId: task.contextId, ...(result.lineage?.jobId ? { jobId: result.lineage.jobId } : {}),
|
|
81
|
+
artifacts: result.artifacts.map(({ path, size, sha256 }) => ({ path, size, sha256 })), validation: result.validation.status, submittedAt };
|
|
82
|
+
}
|
|
@@ -24,6 +24,9 @@ export interface A2AResultMetadata {
|
|
|
24
24
|
sessionId?: string;
|
|
25
25
|
cwd?: string;
|
|
26
26
|
agentPreset?: string;
|
|
27
|
+
/** Model actually selected for a standard preset; absent means the host default. */
|
|
28
|
+
provider?: string;
|
|
29
|
+
model?: string;
|
|
27
30
|
roleId?: string;
|
|
28
31
|
/** Resolved by the execution host, independently from caller-declared lineage. */
|
|
29
32
|
roleSkills?: A2ATarget['roleSkills'];
|
|
@@ -4,6 +4,7 @@ import { constants } from 'node:fs';
|
|
|
4
4
|
import { lstat, open, realpath, rename, unlink } from 'node:fs/promises';
|
|
5
5
|
import { basename, dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { isDefaultJobDirectory } from './job-directory.js';
|
|
7
8
|
const identifier = z.string().trim().min(1).max(512);
|
|
8
9
|
const absolutePath = z.string().min(1).max(8192).refine(value => isAbsolute(value) && !value.includes('\0'), 'Expected an absolute path');
|
|
9
10
|
export const a2aResultContractSchema = z.object({
|
|
@@ -103,6 +104,7 @@ export async function createA2AResultMetadata(input) {
|
|
|
103
104
|
version: 1, producer: '1agents/a2a-host', taskId: input.taskId, contextId: input.contextId,
|
|
104
105
|
requestId: input.requestId, ...(target ? { sessionId: target.sessionId, cwd: target.cwd,
|
|
105
106
|
...(target.agentPreset ? { agentPreset: target.agentPreset } : {}),
|
|
107
|
+
...(target.provider ? { provider: target.provider, model: target.model } : {}),
|
|
106
108
|
...(target.roleSkills ? { roleId: target.roleId, roleSkills: structuredClone(target.roleSkills) } : {}) } : {}),
|
|
107
109
|
startedAt: input.startedAt, finishedAt: new Date().toISOString(), outcome: input.outcome,
|
|
108
110
|
...(contract ? { lineage: { ...contract, source: 'caller-declared' } } : {}),
|
|
@@ -111,17 +113,37 @@ export async function createA2AResultMetadata(input) {
|
|
|
111
113
|
};
|
|
112
114
|
if (contract?.artifactManifestPath && input.outcome === 'completed' && !input.validationCode) {
|
|
113
115
|
const root = target?.preflight?.ok && target.preflight.jobDirectory;
|
|
114
|
-
|
|
116
|
+
// A manifest the gateway announced by default is optional: no admitted directory or manifest means no artifacts,
|
|
117
|
+
// and a bad one is reported in `validation` without failing a task that otherwise completed.
|
|
118
|
+
// The gateway may name cwd through a symlink while the host stores the resolved path, so compare both spellings.
|
|
119
|
+
const real = async (path) => realpath(path).catch(() => path);
|
|
120
|
+
const manifestDirectory = dirname(contract.artifactManifestPath);
|
|
121
|
+
const implicit = Boolean(target?.cwd) && (isDefaultJobDirectory(target.cwd, manifestDirectory)
|
|
122
|
+
|| isDefaultJobDirectory(await real(target.cwd), await real(manifestDirectory)));
|
|
123
|
+
if (!root) {
|
|
124
|
+
if (implicit)
|
|
125
|
+
return metadata;
|
|
115
126
|
throw new A2AResultValidationError('artifact-job-directory-not-admitted');
|
|
116
|
-
|
|
127
|
+
}
|
|
128
|
+
if (await realpath(root) !== root) {
|
|
129
|
+
if (implicit) {
|
|
130
|
+
metadata.validation = { status: 'failed', code: 'job-directory-changed' };
|
|
131
|
+
return metadata;
|
|
132
|
+
}
|
|
117
133
|
throw new A2AResultValidationError('job-directory-changed');
|
|
134
|
+
}
|
|
135
|
+
if (implicit && !(await lstat(contract.artifactManifestPath).catch(() => undefined)))
|
|
136
|
+
return metadata;
|
|
118
137
|
try {
|
|
119
138
|
metadata.artifacts = await verifiedArtifacts(root, contract.artifactManifestPath);
|
|
120
139
|
}
|
|
121
140
|
catch (error) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
141
|
+
const code = error instanceof A2AResultValidationError ? error.code : 'artifact-manifest-or-file-unavailable';
|
|
142
|
+
if (implicit) {
|
|
143
|
+
metadata.validation = { status: 'failed', code };
|
|
144
|
+
return metadata;
|
|
145
|
+
}
|
|
146
|
+
throw error instanceof A2AResultValidationError ? error : new A2AResultValidationError(code);
|
|
125
147
|
}
|
|
126
148
|
metadata.validation = { status: 'passed' };
|
|
127
149
|
}
|
package/dist/src/a2a/server.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
2
2
|
import { AgentCard } from '@a2a-js/sdk';
|
|
3
3
|
import { type A2AExecutionOptions } from './executor.js';
|
|
4
4
|
import type { A2ABackend } from './types.js';
|
|
5
|
+
import { type A2AResubmission, type A2ASessionTask } from './resubmit.js';
|
|
5
6
|
/** Remote execution is explicitly enabled with a host-owned bearer credential. */
|
|
6
7
|
export interface A2AServerOptions extends A2AExecutionOptions {
|
|
7
8
|
backend: A2ABackend;
|
|
@@ -18,5 +19,14 @@ export declare function createA2AServer(options: A2AServerOptions): Promise<{
|
|
|
18
19
|
card: AgentCard;
|
|
19
20
|
handler: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
|
|
20
21
|
cardHandler: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
|
|
22
|
+
/** The A2A task a DSH session last ran, for in-process takeover controls. */
|
|
23
|
+
sessionTask: (sessionId: string) => A2ASessionTask | undefined;
|
|
24
|
+
/** The DSH session an A2A task ran in. */
|
|
25
|
+
taskSession: (taskId: string) => string | undefined;
|
|
26
|
+
/** Hand a taken-over session's result back to the workflow as a new completed snapshot. */
|
|
27
|
+
resubmit: (input: {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
summary: string;
|
|
30
|
+
}) => Promise<A2AResubmission>;
|
|
21
31
|
close: () => Promise<void>;
|
|
22
32
|
}>;
|
package/dist/src/a2a/server.js
CHANGED
|
@@ -9,6 +9,34 @@ import { toSafeError } from '@1agents/acp-service/runtime';
|
|
|
9
9
|
import { a2aRequestId } from './request-id.js';
|
|
10
10
|
import { FileA2AStore } from './store.js';
|
|
11
11
|
import { a2aPreflightInputSchema } from './preflight.js';
|
|
12
|
+
import { ArtifactContentError, readVerifiedArtifact } from './artifact-content.js';
|
|
13
|
+
import { a2aSessionTask, a2aTaskSession, resubmitA2ASession } from './resubmit.js';
|
|
14
|
+
async function readBoundedJson(req, limit) {
|
|
15
|
+
const chunks = [];
|
|
16
|
+
let size = 0;
|
|
17
|
+
for await (const chunk of req) {
|
|
18
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
19
|
+
size += buffer.length;
|
|
20
|
+
if (size > limit)
|
|
21
|
+
throw new Error('body too large');
|
|
22
|
+
chunks.push(buffer);
|
|
23
|
+
}
|
|
24
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
25
|
+
}
|
|
26
|
+
function sessionRouteError(error) {
|
|
27
|
+
const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : '';
|
|
28
|
+
switch (code) {
|
|
29
|
+
case 'SESSION_NOT_FOUND': return { status: 404, code };
|
|
30
|
+
case 'SESSION_DELETED': return { status: 404, code };
|
|
31
|
+
case 'SESSION_CLOSED': return { status: 409, code };
|
|
32
|
+
case 'SESSION_BUSY': return { status: 409, code };
|
|
33
|
+
case 'SESSION_CONFLICT': return { status: 400, code };
|
|
34
|
+
case 'SESSION_ATTACH_IN_PROGRESS': return { status: 409, code };
|
|
35
|
+
case 'UNSUPPORTED': return { status: 501, code };
|
|
36
|
+
case 'REMOTE_UNAVAILABLE': return { status: 503, code };
|
|
37
|
+
default: return { status: 503, code: 'REMOTE_UNAVAILABLE' };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
12
40
|
function allowedCallback(config, origins) {
|
|
13
41
|
if (!origins.size)
|
|
14
42
|
throw new PushNotificationNotSupportedError('Configure pushNotificationOrigins to enable webhooks');
|
|
@@ -274,6 +302,94 @@ export async function createA2AServer(options) {
|
|
|
274
302
|
}
|
|
275
303
|
return;
|
|
276
304
|
}
|
|
305
|
+
if (req.url === `${path}/sessions/close` || req.url === `${path}/sessions/status` || req.url === `${path}/sessions/delete`) {
|
|
306
|
+
const action = req.url.endsWith('/status') ? 'status' : req.url.endsWith('/delete') ? 'delete' : 'close';
|
|
307
|
+
if (!options.backend[action]) {
|
|
308
|
+
res.writeHead(501, { 'Content-Type': 'application/json' });
|
|
309
|
+
res.end(JSON.stringify({ error: 'UNSUPPORTED' }));
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const body = await readBoundedJson(req, 65536);
|
|
314
|
+
if (!body || typeof body !== 'object' || typeof body.sessionId !== 'string' || !body.sessionId.trim()
|
|
315
|
+
|| typeof body.contextId !== 'string' || !body.contextId.trim()) {
|
|
316
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
317
|
+
res.end(JSON.stringify({ error: 'SESSION_CONFLICT' }));
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const context = new ServerCallContext({ requestedVersion: '1.0', user: { isAuthenticated: true, userName: 'dsh-a2a' } });
|
|
321
|
+
const target = store.loadTarget(body.contextId, context);
|
|
322
|
+
if (!target || target.sessionId !== body.sessionId) {
|
|
323
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
324
|
+
res.end(JSON.stringify({ error: 'SESSION_NOT_FOUND' }));
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (action === 'status') {
|
|
328
|
+
const report = await options.backend.status(target);
|
|
329
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
330
|
+
res.end(JSON.stringify(report));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (action === 'delete') {
|
|
334
|
+
if (target.state === 'deleted') {
|
|
335
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
336
|
+
res.end(JSON.stringify({ processReleased: true, alreadyClosed: true, state: 'deleted', acp: target.agentPreset?.startsWith('oneagents-acp-') === true, sessionId: target.sessionId, contextId: body.contextId }));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const result = await options.backend.delete(target);
|
|
340
|
+
store.saveTarget(body.contextId, { ...target, state: 'deleted', lastUsedAt: new Date().toISOString() }, context);
|
|
341
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
342
|
+
res.end(JSON.stringify({ ...result, alreadyClosed: false, state: 'deleted', sessionId: target.sessionId, contextId: body.contextId }));
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (target.state === 'closed' || target.state === 'closing' || target.state === 'deleted') {
|
|
346
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
347
|
+
res.end(JSON.stringify({ processReleased: target.state === 'closed' ? true : 'pending', alreadyClosed: true,
|
|
348
|
+
acp: target.agentPreset?.startsWith('oneagents-acp-') === true, sessionId: target.sessionId, contextId: body.contextId }));
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const result = await options.backend.close(target);
|
|
352
|
+
store.saveTarget(body.contextId, { ...target, state: result.processReleased === true ? 'closed' : 'closing', lastUsedAt: new Date().toISOString() }, context);
|
|
353
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
|
354
|
+
res.end(JSON.stringify({ ...result, alreadyClosed: false, sessionId: target.sessionId, contextId: body.contextId }));
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
if (error instanceof SyntaxError || (error instanceof Error && error.message === 'body too large')) {
|
|
358
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
359
|
+
res.end(JSON.stringify({ error: 'SESSION_CONFLICT' }));
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const mapped = sessionRouteError(error);
|
|
363
|
+
res.writeHead(mapped.status, { 'Content-Type': 'application/json' });
|
|
364
|
+
res.end(JSON.stringify({ error: mapped.code }));
|
|
365
|
+
}
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
// Same credential boundary as execution: the caller names a task and a receipt entry, never an arbitrary path.
|
|
369
|
+
if (req.url === `${path}/artifacts/content`) {
|
|
370
|
+
try {
|
|
371
|
+
const body = await readBoundedJson(req, 65536);
|
|
372
|
+
if (!body || typeof body !== 'object' || typeof body.taskId !== 'string' || typeof body.path !== 'string'
|
|
373
|
+
|| typeof body.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(body.sha256)) {
|
|
374
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
375
|
+
res.end(JSON.stringify({ error: 'invalid-artifact-request' }));
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const context = new ServerCallContext({ requestedVersion: '1.0', user: { isAuthenticated: true, userName: 'dsh-a2a' } });
|
|
379
|
+
const task = await store.taskStore.load(body.taskId, context);
|
|
380
|
+
const result = task?.metadata?.['1agents']?.result;
|
|
381
|
+
const content = await readVerifiedArtifact(result?.artifacts ?? [], body.path, body.sha256);
|
|
382
|
+
res.writeHead(200, { 'Content-Type': 'application/octet-stream', 'Content-Length': content.length, 'Cache-Control': 'no-store' });
|
|
383
|
+
res.end(content);
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
const status = error instanceof ArtifactContentError ? error.status : 400;
|
|
387
|
+
const code = error instanceof ArtifactContentError ? error.code : 'invalid-artifact-request';
|
|
388
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
389
|
+
res.end(JSON.stringify({ error: code }));
|
|
390
|
+
}
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
277
393
|
res.setHeader('A2A-Version', '1.0');
|
|
278
394
|
let id = null;
|
|
279
395
|
try {
|
|
@@ -365,7 +481,15 @@ export async function createA2AServer(options) {
|
|
|
365
481
|
void pending.then(clean, clean);
|
|
366
482
|
return pending;
|
|
367
483
|
};
|
|
368
|
-
return { path, card, handler, cardHandler,
|
|
484
|
+
return { path, card, handler, cardHandler,
|
|
485
|
+
sessionTask: sessionId => a2aSessionTask({ store, executor }, sessionId),
|
|
486
|
+
taskSession: taskId => a2aTaskSession({ store }, taskId),
|
|
487
|
+
resubmit: input => {
|
|
488
|
+
if (stopped)
|
|
489
|
+
return Promise.reject(new Error('A2A host is stopping'));
|
|
490
|
+
return resubmitA2ASession({ store, executor, push: (event, context, task) => sender.send(event, context, task) }, input);
|
|
491
|
+
},
|
|
492
|
+
close: async () => {
|
|
369
493
|
if (stopped)
|
|
370
494
|
return;
|
|
371
495
|
stopped = true;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Gateway session policy. This is not runtime ensureSession's mode. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const sessionLifecycleSchema: z.ZodObject<{
|
|
4
|
+
mode: z.ZodDefault<z.ZodEnum<{
|
|
5
|
+
persistent: "persistent";
|
|
6
|
+
"one-shot": "one-shot";
|
|
7
|
+
}>>;
|
|
8
|
+
idleTtlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
closeAfter: z.ZodOptional<z.ZodEnum<{
|
|
10
|
+
terminal: "terminal";
|
|
11
|
+
ack: "ack";
|
|
12
|
+
}>>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
export interface SessionLifecycle {
|
|
15
|
+
mode: 'persistent' | 'one-shot';
|
|
16
|
+
idleTtlSeconds: number;
|
|
17
|
+
closeAfter: 'terminal' | 'ack';
|
|
18
|
+
}
|
|
19
|
+
export type CloseReason = 'explicit' | 'one-shot' | 'idle-ttl';
|
|
20
|
+
export type SessionRecordState = 'attached' | 'busy' | 'idle' | 'closing' | 'closed' | 'stale';
|
|
21
|
+
/** One-shot closes only these task states. REJECTED stays open. INPUT_REQUIRED stays open. */
|
|
22
|
+
export declare const ONE_SHOT_TERMINAL_STATES: Set<string>;
|
|
23
|
+
export declare function normalizeLifecycle(value: unknown, defaultIdleTtlSeconds?: number): SessionLifecycle;
|
|
24
|
+
/** Jobs saved before one-shot became the default carry no lifecycle. They keep the persistent policy they ran under. */
|
|
25
|
+
export declare function legacyLifecycle(defaultIdleTtlSeconds?: number): SessionLifecycle;
|
|
26
|
+
export declare function isAcpAgentPreset(preset: string | undefined): boolean;
|
|
27
|
+
/** One-shot only. Persistent idle close is the gateway's P3 scan, which also confirms remote status. */
|
|
28
|
+
export declare function oneShotShouldClose(lifecycle: SessionLifecycle | undefined, state: string, acknowledged: boolean): boolean;
|
|
29
|
+
export declare class A2ASessionError extends Error {
|
|
30
|
+
readonly code: 'SESSION_NOT_FOUND' | 'SESSION_DELETED' | 'SESSION_CLOSED' | 'SESSION_BUSY' | 'SESSION_CONFLICT' | 'SESSION_ATTACH_IN_PROGRESS' | 'UNSUPPORTED' | 'REMOTE_UNAVAILABLE';
|
|
31
|
+
constructor(code: 'SESSION_NOT_FOUND' | 'SESSION_DELETED' | 'SESSION_CLOSED' | 'SESSION_BUSY' | 'SESSION_CONFLICT' | 'SESSION_ATTACH_IN_PROGRESS' | 'UNSUPPORTED' | 'REMOTE_UNAVAILABLE', message: string);
|
|
32
|
+
}
|
|
33
|
+
export type ColdAttachStep = 'enqueued' | 'attach-failed' | 'attach-hung' | 'attach-done-no-turn' | 'activeTurn';
|
|
34
|
+
/** Record where a later message stopped. This does not invent an error code. */
|
|
35
|
+
export declare function classifyColdAttach(trace: {
|
|
36
|
+
enqueued: boolean;
|
|
37
|
+
attach: 'none' | 'pending' | 'failed' | 'done';
|
|
38
|
+
turnStarted: boolean;
|
|
39
|
+
activeTurn: boolean;
|
|
40
|
+
}): ColdAttachStep;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Gateway session policy. This is not runtime ensureSession's mode. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export const sessionLifecycleSchema = z.object({
|
|
4
|
+
mode: z.enum(['persistent', 'one-shot']).default('one-shot'),
|
|
5
|
+
/** Omitted means 600 seconds. Zero disables idle close. Positive values override 600. */
|
|
6
|
+
idleTtlSeconds: z.number().int().min(0).max(30 * 24 * 60 * 60).optional(),
|
|
7
|
+
closeAfter: z.enum(['terminal', 'ack']).optional(),
|
|
8
|
+
}).strict();
|
|
9
|
+
/** One-shot closes only these task states. REJECTED stays open. INPUT_REQUIRED stays open. */
|
|
10
|
+
export const ONE_SHOT_TERMINAL_STATES = new Set([
|
|
11
|
+
'TASK_STATE_COMPLETED', 'TASK_STATE_FAILED', 'TASK_STATE_CANCELED',
|
|
12
|
+
]);
|
|
13
|
+
export function normalizeLifecycle(value, defaultIdleTtlSeconds = 600) {
|
|
14
|
+
const parsed = sessionLifecycleSchema.parse(value ?? {});
|
|
15
|
+
return {
|
|
16
|
+
mode: parsed.mode,
|
|
17
|
+
idleTtlSeconds: parsed.idleTtlSeconds ?? defaultIdleTtlSeconds,
|
|
18
|
+
closeAfter: parsed.closeAfter ?? 'terminal',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Jobs saved before one-shot became the default carry no lifecycle. They keep the persistent policy they ran under. */
|
|
22
|
+
export function legacyLifecycle(defaultIdleTtlSeconds = 600) {
|
|
23
|
+
return { mode: 'persistent', idleTtlSeconds: defaultIdleTtlSeconds, closeAfter: 'terminal' };
|
|
24
|
+
}
|
|
25
|
+
export function isAcpAgentPreset(preset) {
|
|
26
|
+
return typeof preset === 'string' && preset.startsWith('oneagents-acp-');
|
|
27
|
+
}
|
|
28
|
+
/** One-shot only. Persistent idle close is the gateway's P3 scan, which also confirms remote status. */
|
|
29
|
+
export function oneShotShouldClose(lifecycle, state, acknowledged) {
|
|
30
|
+
const policy = lifecycle ?? legacyLifecycle();
|
|
31
|
+
if (policy.mode !== 'one-shot' || !ONE_SHOT_TERMINAL_STATES.has(state))
|
|
32
|
+
return false;
|
|
33
|
+
return policy.closeAfter === 'ack' ? acknowledged : true;
|
|
34
|
+
}
|
|
35
|
+
export class A2ASessionError extends Error {
|
|
36
|
+
code;
|
|
37
|
+
constructor(code, message) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.code = code;
|
|
40
|
+
this.name = 'A2ASessionError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Record where a later message stopped. This does not invent an error code. */
|
|
44
|
+
export function classifyColdAttach(trace) {
|
|
45
|
+
if (trace.activeTurn || trace.turnStarted)
|
|
46
|
+
return 'activeTurn';
|
|
47
|
+
if (trace.attach === 'done')
|
|
48
|
+
return 'attach-done-no-turn';
|
|
49
|
+
if (trace.attach === 'failed')
|
|
50
|
+
return 'attach-failed';
|
|
51
|
+
if (trace.attach === 'pending')
|
|
52
|
+
return 'attach-hung';
|
|
53
|
+
return 'enqueued';
|
|
54
|
+
}
|
package/dist/src/a2a/store.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ export declare class FileA2AStore {
|
|
|
20
20
|
private closed;
|
|
21
21
|
constructor(directory: string);
|
|
22
22
|
loadTarget(contextId: string, context: ServerCallContext): A2ATarget | undefined;
|
|
23
|
+
/** The most recently updated task this host ran in one DSH session, within the caller's scope. */
|
|
24
|
+
latestTaskForSession(sessionId: string, context: ServerCallContext): Task | undefined;
|
|
25
|
+
/** The DSH session a task ran in, within the caller's scope. */
|
|
26
|
+
sessionOfTask(taskId: string, context: ServerCallContext): string | undefined;
|
|
23
27
|
saveTarget(contextId: string, target: A2ATarget, context: ServerCallContext): void;
|
|
24
28
|
/** Persist failure for interrupted executions. A restart never reruns work. */
|
|
25
29
|
recoverInterrupted(recover?: (task: Task, context: ServerCallContext) => Promise<SafeError | undefined>): Promise<void>;
|