@1agents/acp-service 0.9.0 → 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.
Files changed (266) hide show
  1. package/README.md +19 -13
  2. package/dist/bin/a2a.js +6 -2
  3. package/dist/bin/acp-service.js +24 -0
  4. package/dist/bin/process.d.ts +4 -0
  5. package/dist/bin/process.js +57 -0
  6. package/dist/bin/rsi.d.ts +3 -0
  7. package/dist/bin/rsi.js +114 -0
  8. package/dist/bin/ticket.d.ts +13 -0
  9. package/dist/bin/ticket.js +97 -0
  10. package/dist/bin/trail.d.ts +4 -0
  11. package/dist/bin/trail.js +62 -0
  12. package/dist/src/a2a/artifact-content.d.ts +9 -0
  13. package/dist/src/a2a/artifact-content.js +45 -0
  14. package/dist/src/a2a/desktop-notify.d.ts +1 -0
  15. package/dist/src/a2a/desktop-notify.js +12 -0
  16. package/dist/src/a2a/execution-binding.d.ts +9 -0
  17. package/dist/src/a2a/execution-binding.js +19 -0
  18. package/dist/src/a2a/executor.d.ts +6 -0
  19. package/dist/src/a2a/executor.js +112 -12
  20. package/dist/src/a2a/gateway.d.ts +537 -2
  21. package/dist/src/a2a/gateway.js +1014 -87
  22. package/dist/src/a2a/index.d.ts +8 -1
  23. package/dist/src/a2a/index.js +4 -0
  24. package/dist/src/a2a/job-directory.d.ts +6 -0
  25. package/dist/src/a2a/job-directory.js +19 -0
  26. package/dist/src/a2a/preflight.js +16 -1
  27. package/dist/src/a2a/resubmit.d.ts +46 -0
  28. package/dist/src/a2a/resubmit.js +82 -0
  29. package/dist/src/a2a/result-metadata.d.ts +3 -0
  30. package/dist/src/a2a/result-metadata.js +23 -5
  31. package/dist/src/a2a/server.d.ts +10 -0
  32. package/dist/src/a2a/server.js +125 -1
  33. package/dist/src/a2a/session-lifecycle.d.ts +40 -0
  34. package/dist/src/a2a/session-lifecycle.js +54 -0
  35. package/dist/src/a2a/store.d.ts +4 -0
  36. package/dist/src/a2a/store.js +70 -1
  37. package/dist/src/a2a/types.d.ts +45 -0
  38. package/dist/src/a2a/workbench-ui.d.ts +28 -0
  39. package/dist/src/a2a/workbench-ui.js +182 -0
  40. package/dist/src/acp-connection.js +27 -3
  41. package/dist/src/bridge.d.ts +1 -0
  42. package/dist/src/bridge.js +191 -39
  43. package/dist/src/capacity-queue.d.ts +35 -0
  44. package/dist/src/capacity-queue.js +139 -2
  45. package/dist/src/capacity.d.ts +25 -0
  46. package/dist/src/capacity.js +48 -9
  47. package/dist/src/dsh.js +1 -1
  48. package/dist/src/execution/agent-files.d.ts +25 -0
  49. package/dist/src/execution/agent-files.js +90 -0
  50. package/dist/src/execution/agent-registry.d.ts +164 -0
  51. package/dist/src/execution/agent-registry.js +275 -0
  52. package/dist/src/execution/human-review.d.ts +2 -0
  53. package/dist/src/execution/human-review.js +3 -1
  54. package/dist/src/execution/ledger.d.ts +52 -0
  55. package/dist/src/execution/ledger.js +83 -5
  56. package/dist/src/execution/process-request.d.ts +151 -0
  57. package/dist/src/execution/process-request.js +177 -0
  58. package/dist/src/execution/targets.d.ts +15 -0
  59. package/dist/src/execution/targets.js +22 -3
  60. package/dist/src/execution/ticket-executor.d.ts +25 -0
  61. package/dist/src/execution/ticket-executor.js +27 -0
  62. package/dist/src/execution/ticket.d.ts +326 -0
  63. package/dist/src/execution/ticket.js +301 -0
  64. package/dist/src/execution/workbench-chat.d.ts +25 -0
  65. package/dist/src/execution/workbench-chat.js +54 -0
  66. package/dist/src/execution/workbench.d.ts +32 -1
  67. package/dist/src/execution/workbench.js +113 -22
  68. package/dist/src/rsi/gate.d.ts +25 -0
  69. package/dist/src/rsi/gate.js +59 -0
  70. package/dist/src/rsi/outline-run.d.ts +107 -0
  71. package/dist/src/rsi/outline-run.js +443 -0
  72. package/dist/workbench-ui/app.css +453 -0
  73. package/dist/workbench-ui/app.js +13 -0
  74. package/dist/workbench-ui/chunk-23JHGYT3.js +1 -0
  75. package/dist/workbench-ui/chunk-3H6STGPV.js +1 -0
  76. package/dist/workbench-ui/chunk-3SNBBMGH.js +1 -0
  77. package/dist/workbench-ui/chunk-3XJZ6DIE.js +1 -0
  78. package/dist/workbench-ui/chunk-44KDLLKJ.js +1 -0
  79. package/dist/workbench-ui/chunk-46H7FU5Y.js +7 -0
  80. package/dist/workbench-ui/chunk-4N44QPL7.js +1 -0
  81. package/dist/workbench-ui/chunk-4YN4BS7I.js +1 -0
  82. package/dist/workbench-ui/chunk-53EG4IVQ.js +96 -0
  83. package/dist/workbench-ui/chunk-5FIPUNR4.js +1 -0
  84. package/dist/workbench-ui/chunk-6DWWYA6G.js +2 -0
  85. package/dist/workbench-ui/chunk-6FU3T633.js +99 -0
  86. package/dist/workbench-ui/chunk-6XKIHRA4.js +1 -0
  87. package/dist/workbench-ui/chunk-7GIX43Y5.js +1 -0
  88. package/dist/workbench-ui/chunk-7Q4WBGX6.js +4 -0
  89. package/dist/workbench-ui/chunk-A3BQM7HR.js +1 -0
  90. package/dist/workbench-ui/chunk-AFCFDDOP.js +24 -0
  91. package/dist/workbench-ui/chunk-AG67EUYD.js +89 -0
  92. package/dist/workbench-ui/chunk-AGJHMMTN.js +1 -0
  93. package/dist/workbench-ui/chunk-AO6JUBV6.js +41 -0
  94. package/dist/workbench-ui/chunk-AUSLTP43.js +72 -0
  95. package/dist/workbench-ui/chunk-AVZL46TT.js +1 -0
  96. package/dist/workbench-ui/chunk-AZRIGIV2.js +168 -0
  97. package/dist/workbench-ui/chunk-B2LIVH37.js +1 -0
  98. package/dist/workbench-ui/chunk-B7YX5TR5.js +1 -0
  99. package/dist/workbench-ui/chunk-BCB4X4XX.js +1 -0
  100. package/dist/workbench-ui/chunk-BCRQUL2A.js +88 -0
  101. package/dist/workbench-ui/chunk-BI6UHHQP.js +1 -0
  102. package/dist/workbench-ui/chunk-BLSLQ4AQ.js +120 -0
  103. package/dist/workbench-ui/chunk-C3QSRS6E.js +1 -0
  104. package/dist/workbench-ui/chunk-CK7M2PJ3.js +62 -0
  105. package/dist/workbench-ui/chunk-CM6LZ7TU.js +1 -0
  106. package/dist/workbench-ui/chunk-CP63H27F.js +36 -0
  107. package/dist/workbench-ui/chunk-CPUMMIS2.js +70 -0
  108. package/dist/workbench-ui/chunk-CSEIBI5U.js +2 -0
  109. package/dist/workbench-ui/chunk-CUS65DKZ.js +161 -0
  110. package/dist/workbench-ui/chunk-CVQY7TNC.js +1 -0
  111. package/dist/workbench-ui/chunk-D6S3XBIX.js +106 -0
  112. package/dist/workbench-ui/chunk-E253Y562.js +1 -0
  113. package/dist/workbench-ui/chunk-EADDJUDC.js +1 -0
  114. package/dist/workbench-ui/chunk-EBGJ3YXG.js +206 -0
  115. package/dist/workbench-ui/chunk-EKPVZ3WY.js +8 -0
  116. package/dist/workbench-ui/chunk-EQDCEAFY.js +1 -0
  117. package/dist/workbench-ui/chunk-ES3SSDJY.js +40 -0
  118. package/dist/workbench-ui/chunk-ESFD2H7N.js +231 -0
  119. package/dist/workbench-ui/chunk-FVOHPMS6.js +1 -0
  120. package/dist/workbench-ui/chunk-FXMQAGVT.js +1 -0
  121. package/dist/workbench-ui/chunk-GGTADRXD.js +24 -0
  122. package/dist/workbench-ui/chunk-GHIVPGNQ.js +1 -0
  123. package/dist/workbench-ui/chunk-GLU2YQV2.js +1 -0
  124. package/dist/workbench-ui/chunk-GOCKBYSM.js +1 -0
  125. package/dist/workbench-ui/chunk-H2KMMTJB.js +1 -0
  126. package/dist/workbench-ui/chunk-HGVLDNPP.js +39 -0
  127. package/dist/workbench-ui/chunk-HSAVC5GY.js +1 -0
  128. package/dist/workbench-ui/chunk-HSEAD2JH.js +1 -0
  129. package/dist/workbench-ui/chunk-HSIHOBTY.js +1 -0
  130. package/dist/workbench-ui/chunk-IZXOKUGG.js +67 -0
  131. package/dist/workbench-ui/chunk-JFT2LC2T.js +1 -0
  132. package/dist/workbench-ui/chunk-JHL3ZDYK.js +3 -0
  133. package/dist/workbench-ui/chunk-JMORLCZG.js +257 -0
  134. package/dist/workbench-ui/chunk-JR4SIX7A.js +1 -0
  135. package/dist/workbench-ui/chunk-K23HAGEH.js +30 -0
  136. package/dist/workbench-ui/chunk-K43JDCBH.js +1 -0
  137. package/dist/workbench-ui/chunk-KINKFJY7.js +1 -0
  138. package/dist/workbench-ui/chunk-KKQSA4LI.js +2 -0
  139. package/dist/workbench-ui/chunk-KOUZX3UX.js +1 -0
  140. package/dist/workbench-ui/chunk-KR4DRHW2.js +78 -0
  141. package/dist/workbench-ui/chunk-KT4DJNOR.js +1 -0
  142. package/dist/workbench-ui/chunk-KTPNKRRZ.js +292 -0
  143. package/dist/workbench-ui/chunk-LFHIPGSU.js +7 -0
  144. package/dist/workbench-ui/chunk-LWDL4HZB.js +125 -0
  145. package/dist/workbench-ui/chunk-MVYC3CY4.js +1 -0
  146. package/dist/workbench-ui/chunk-NWUPALCY.js +129 -0
  147. package/dist/workbench-ui/chunk-NY7C662Z.js +1 -0
  148. package/dist/workbench-ui/chunk-O76WTHWP.js +1 -0
  149. package/dist/workbench-ui/chunk-OTF7YHRE.js +162 -0
  150. package/dist/workbench-ui/chunk-P6TKKRKP.js +1 -0
  151. package/dist/workbench-ui/chunk-PFHOOWV3.js +1 -0
  152. package/dist/workbench-ui/chunk-PUQLANIM.js +1 -0
  153. package/dist/workbench-ui/chunk-PZCGBYVO.js +1 -0
  154. package/dist/workbench-ui/chunk-QOHUZGP4.js +1 -0
  155. package/dist/workbench-ui/chunk-QSEG3OFF.js +1 -0
  156. package/dist/workbench-ui/chunk-QYPOXZIA.js +84 -0
  157. package/dist/workbench-ui/chunk-R6SOF3JC.js +1 -0
  158. package/dist/workbench-ui/chunk-RCLOYU5F.js +1 -0
  159. package/dist/workbench-ui/chunk-RSRUP64S.js +1 -0
  160. package/dist/workbench-ui/chunk-RVAIT6JW.js +1 -0
  161. package/dist/workbench-ui/chunk-S2CCN3II.js +1 -0
  162. package/dist/workbench-ui/chunk-S2Q52W46.js +1 -0
  163. package/dist/workbench-ui/chunk-S2W5THJ5.js +1 -0
  164. package/dist/workbench-ui/chunk-S6ZQZNOX.js +1 -0
  165. package/dist/workbench-ui/chunk-S74PLMMS.js +1 -0
  166. package/dist/workbench-ui/chunk-S7C4HKEY.js +1 -0
  167. package/dist/workbench-ui/chunk-SDTB3Q65.js +1 -0
  168. package/dist/workbench-ui/chunk-SLPRGYUV.js +32 -0
  169. package/dist/workbench-ui/chunk-SQE76S5B.js +1 -0
  170. package/dist/workbench-ui/chunk-SSDZPVPW.js +1 -0
  171. package/dist/workbench-ui/chunk-SVI7DGIE.js +1 -0
  172. package/dist/workbench-ui/chunk-T6QKLZ4H.js +62 -0
  173. package/dist/workbench-ui/chunk-TJNRPTFL.js +1 -0
  174. package/dist/workbench-ui/chunk-TP6U4EDH.js +2 -0
  175. package/dist/workbench-ui/chunk-TYAAT3GQ.js +1 -0
  176. package/dist/workbench-ui/chunk-U6OCY4ZH.js +1 -0
  177. package/dist/workbench-ui/chunk-UAN3NLRF.js +1 -0
  178. package/dist/workbench-ui/chunk-UMLU3FIX.js +1 -0
  179. package/dist/workbench-ui/chunk-URIY2OTM.js +1 -0
  180. package/dist/workbench-ui/chunk-V2NUKAA7.js +38 -0
  181. package/dist/workbench-ui/chunk-V4QLL4TE.js +139 -0
  182. package/dist/workbench-ui/chunk-VASHXUK4.js +2 -0
  183. package/dist/workbench-ui/chunk-VJLIWNIU.js +1 -0
  184. package/dist/workbench-ui/chunk-VQNQFBID.js +1 -0
  185. package/dist/workbench-ui/chunk-VSIWU7XA.js +3 -0
  186. package/dist/workbench-ui/chunk-VSJASPUZ.js +321 -0
  187. package/dist/workbench-ui/chunk-VXPNUNUX.js +3 -0
  188. package/dist/workbench-ui/chunk-WBKLDCV6.js +1 -0
  189. package/dist/workbench-ui/chunk-WOKJM3FY.js +1 -0
  190. package/dist/workbench-ui/chunk-X3U3NA3X.js +34 -0
  191. package/dist/workbench-ui/chunk-XBYU7M4J.js +1 -0
  192. package/dist/workbench-ui/chunk-XBZAO4ID.js +10 -0
  193. package/dist/workbench-ui/chunk-XLLPZ2WO.js +1 -0
  194. package/dist/workbench-ui/chunk-YFVL4NJL.js +1 -0
  195. package/dist/workbench-ui/chunk-YRFQENM4.js +1 -0
  196. package/dist/workbench-ui/chunk-YUADQVB2.js +1 -0
  197. package/dist/workbench-ui/chunk-Z3TCAKM5.js +1 -0
  198. package/dist/workbench-ui/chunk-Z6QR6FRE.js +10 -0
  199. package/dist/workbench-ui/chunk-ZJPSORPP.js +3 -0
  200. package/dist/workbench-ui/chunk-ZLGCSTR2.js +15 -0
  201. package/dist/workbench-ui/chunk-ZLR4SG5X.js +1 -0
  202. package/dist/workbench-ui/chunk-ZND3TTGF.js +1 -0
  203. package/dist/workbench-ui/chunk-ZOP3ZYH7.js +2 -0
  204. package/dist/workbench-ui/index.html +14 -0
  205. package/package.json +19 -8
  206. package/skills/acp-service/SKILL.md +3 -1
  207. package/skills/acp-service/references/a2a.md +17 -5
  208. package/skills/acp-service/references/dsh.md +2 -0
  209. package/skills/acp-service/references/roles-and-tasks.md +1 -1
  210. package/skills/rsi-coach/SKILL.md +134 -0
  211. package/vendor/dsh/README.md +10 -6
  212. package/vendor/dsh/a2a-executor.d.ts +56 -2
  213. package/vendor/dsh/a2a-executor.js +163 -17
  214. package/vendor/dsh/a2a.d.ts +12 -2
  215. package/vendor/dsh/a2a.js +9 -2
  216. package/vendor/dsh/adapter.d.ts +52 -3
  217. package/vendor/dsh/adapter.js +297 -30
  218. package/vendor/dsh/client.js +67 -11
  219. package/vendor/dsh/index.js +55 -3
  220. package/vendor/dsh/native-approvals.d.ts +4 -0
  221. package/vendor/dsh/native-approvals.js +44 -0
  222. package/vendor/dsh/preset-route.d.ts +49 -0
  223. package/vendor/dsh/preset-route.js +51 -0
  224. package/vendor/dsh/preset.js +10 -3
  225. package/vendor/dsh/process-admission.d.ts +25 -0
  226. package/vendor/dsh/process-admission.js +87 -0
  227. package/vendor/dsh/process-requests.d.ts +57 -0
  228. package/vendor/dsh/process-requests.js +49 -0
  229. package/vendor/dsh/review-mcp.d.ts +1 -0
  230. package/vendor/dsh/review-mcp.js +56 -0
  231. package/vendor/dsh/review.d.ts +30 -0
  232. package/vendor/dsh/review.js +149 -0
  233. package/vendor/dsh/session-settings.d.ts +34 -0
  234. package/vendor/dsh/session-settings.js +114 -0
  235. package/vendor/dsh/ticket-spec.d.ts +30 -0
  236. package/vendor/dsh/ticket-spec.js +10 -0
  237. package/vendor/dsh/ticket-tools.d.ts +21 -0
  238. package/vendor/dsh/ticket-tools.js +43 -0
  239. package/vendor/dsh/workbench.d.ts +18 -0
  240. package/vendor/dsh/workbench.js +91 -0
  241. package/vendor/runtime/README.md +6 -4
  242. package/vendor/runtime/dist/docs-site/CLI.html +2 -2
  243. package/vendor/runtime/dist/docs-site/VISION.html +2 -2
  244. package/vendor/runtime/dist/docs-site/agents.html +2 -2
  245. package/vendor/runtime/dist/docs-site/compare.html +2 -2
  246. package/vendor/runtime/dist/docs-site/config.html +2 -2
  247. package/vendor/runtime/dist/docs-site/custom-agents.html +2 -2
  248. package/vendor/runtime/dist/docs-site/exit-codes.html +2 -2
  249. package/vendor/runtime/dist/docs-site/flows.html +2 -2
  250. package/vendor/runtime/dist/docs-site/index.html +1 -1
  251. package/vendor/runtime/dist/docs-site/install.html +2 -2
  252. package/vendor/runtime/dist/docs-site/llms.txt +1 -1
  253. package/vendor/runtime/dist/docs-site/output-formats.html +2 -2
  254. package/vendor/runtime/dist/docs-site/permissions.html +2 -2
  255. package/vendor/runtime/dist/docs-site/prompting.html +2 -2
  256. package/vendor/runtime/dist/docs-site/quickstart.html +2 -2
  257. package/vendor/runtime/dist/docs-site/releasing.html +2 -2
  258. package/vendor/runtime/dist/docs-site/runtime-environment.html +2 -2
  259. package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +2 -2
  260. package/vendor/runtime/dist/docs-site/safe-errors.html +2 -2
  261. package/vendor/runtime/dist/docs-site/session-control.html +2 -2
  262. package/vendor/runtime/dist/docs-site/session-watch.html +2 -2
  263. package/vendor/runtime/dist/docs-site/sessions.html +2 -2
  264. package/vendor/runtime/dist/docs-site/shared-sessions.html +2 -2
  265. package/vendor/runtime/package.json +6 -4
  266. package/vendor/runtime/skills/acpx/SKILL.md +2 -0
@@ -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
+ }
@@ -25,6 +25,10 @@ export declare function parseA2AInput(request: SendMessageRequest, options: A2AE
25
25
  prompt: string;
26
26
  input: A2APrepareInput;
27
27
  resultContract?: A2AResultContract;
28
+ execution?: {
29
+ jobId: string;
30
+ attemptId: string;
31
+ };
28
32
  };
29
33
  /** SDK owns the execution lifetime; an HTTP disconnect never aborts this signal. */
30
34
  export declare class A2ASessionExecutor implements AgentExecutor {
@@ -40,6 +44,8 @@ export declare class A2ASessionExecutor implements AgentExecutor {
40
44
  private roleIdFor;
41
45
  private roleFor;
42
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;
43
49
  execute(context: RequestContext, bus: ExecutionEventBus): Promise<void>;
44
50
  cancelTask(taskId: string, bus: ExecutionEventBus): Promise<void>;
45
51
  close(): Promise<void>;
@@ -9,6 +9,7 @@ import { a2aRequestId } from './request-id.js';
9
9
  import { toSafeError } from '@1agents/acp-service/runtime';
10
10
  import { a2aRoleSkillsSchema } from './types.js';
11
11
  import { resolveRoleSkills } from '../roles/index.js';
12
+ import { agentPromptPrefix, readAgentFile } from '../execution/agent-files.js';
12
13
  import { A2APreflightError, a2aPreflightRequirementsSchema } from './preflight.js';
13
14
  import { a2aResultContractSchema, A2AResultValidationError, createA2AResultMetadata, saveA2AResultMetadata } from './result-metadata.js';
14
15
  import { CapacityGovernor, CapacityError } from '../capacity.js';
@@ -42,6 +43,27 @@ export function validateA2AExecutionOptions(options) {
42
43
  class RoleSkillLoadingError extends Error {
43
44
  constructor(cause) { super('Role skills could not be loaded or verified; the model was not started', { cause }); }
44
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
+ }
45
67
  async function waitForPreparation(previous, signal) {
46
68
  signal.throwIfAborted();
47
69
  let abort;
@@ -72,18 +94,23 @@ export function parseA2AInput(request, options) {
72
94
  throw new RequestMalformedError('metadata.1agents must be an object');
73
95
  const value = (metadata ?? {});
74
96
  for (const key of Object.keys(value))
75
- if (!['cwd', 'agentPreset', 'workspace', 'preflight', 'resultContract', 'roleId', 'roleLockPath'].includes(key))
97
+ if (!['cwd', 'agentPreset', 'workspace', 'preflight', 'resultContract', 'roleId', 'roleLockPath', 'agentFile', 'provider', 'model', 'execution'].includes(key))
76
98
  throw new RequestMalformedError(`Unknown metadata.1agents field: ${key}`);
77
- for (const key of ['cwd', 'agentPreset', 'workspace', 'roleId', 'roleLockPath']) {
99
+ for (const key of ['cwd', 'agentPreset', 'workspace', 'roleId', 'roleLockPath', 'agentFile', 'provider', 'model']) {
78
100
  if (value[key] !== undefined && (typeof value[key] !== 'string' || !value[key].trim()))
79
101
  throw new RequestMalformedError(`${key} must be a nonempty string`);
80
102
  }
103
+ if ((value.provider === undefined) !== (value.model === undefined))
104
+ throw new RequestMalformedError('provider and model must be passed together');
81
105
  if (value.roleId !== undefined && (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/.test(value.roleId)
82
106
  || !options.roleSkills || !Object.hasOwn(options.roleSkills.profiles, value.roleId)))
83
107
  throw new RequestMalformedError('Unknown host role');
84
108
  if (value.roleLockPath !== undefined && (!options.roleSkills || !isAbsolute(value.roleLockPath)
85
109
  || value.roleLockPath.includes('\0')))
86
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');
87
114
  if (value.cwd && value.workspace)
88
115
  throw new RequestMalformedError('Use cwd or workspace, not both');
89
116
  let cwd = value.cwd;
@@ -98,11 +125,31 @@ export function parseA2AInput(request, options) {
98
125
  const resultContract = value.resultContract === undefined ? undefined : a2aResultContractSchema.safeParse(value.resultContract);
99
126
  if (resultContract && !resultContract.success)
100
127
  throw new RequestMalformedError('Invalid result contract');
128
+ const execution = executionOf(value.execution);
101
129
  return { prompt, input: { cwd, agentPreset: value.agentPreset,
102
130
  ...(preflight?.success ? { preflight: preflight.data } : {}),
103
131
  ...(value.roleId ? { roleId: value.roleId } : {}),
104
- ...(value.roleLockPath ? { roleLockPath: value.roleLockPath } : {}) },
105
- ...(resultContract?.success ? { resultContract: resultContract.data } : {}) };
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() };
106
153
  }
107
154
  /** SDK owns the execution lifetime; an HTTP disconnect never aborts this signal. */
108
155
  export class A2ASessionExecutor {
@@ -177,6 +224,8 @@ export class A2ASessionExecutor {
177
224
  return { roleId, summary, promptPrefix: `宿主已加载角色 ${roleId},本任务技能锁:${lockPath}。仅使用此锁及下列缓存技能,不重新检索或切换版本;续派和恢复沿用同一锁。先读取适用指南及其配套资源。\n${guides}\n${instructions}\n\n上游任务:\n` };
178
225
  }
179
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); }
180
229
  async execute(context, bus) {
181
230
  if (this.stopped)
182
231
  throw new UnsupportedOperationError('A2A host is stopping');
@@ -199,12 +248,14 @@ export class A2ASessionExecutor {
199
248
  // DSH deduplicates prompts by rpcId across the whole session. A Task can
200
249
  // have several input-required turns, each with its own message identity.
201
250
  const requestId = a2aRequestId(context.taskId, context.userMessage.messageId);
202
- const status = (state, text, error) => {
251
+ const status = (state, text, error, capacity, slots) => {
203
252
  bus.publish(AgentEvent.statusUpdate({ taskId: context.taskId, contextId: context.contextId,
204
253
  status: { state, timestamp: new Date().toISOString(), message: text ? Message.fromJSON({
205
254
  messageId: randomUUID(), role: 'ROLE_AGENT', contextId: context.contextId, taskId: context.taskId, parts: [{ text }],
206
- }) : undefined }, metadata: target || error || resultMetadata ? { '1agents': {
255
+ }) : undefined }, metadata: target || error || resultMetadata || capacity || slots ? { '1agents': {
207
256
  ...target, ...(resultMetadata ? { result: resultMetadata } : {}), ...(error ? { error } : {}),
257
+ ...(capacity ? { capacity } : {}),
258
+ ...(slots ? { taskSlot: slots.taskSlot, processSlot: slots.processSlot } : {}),
208
259
  } } : undefined }));
209
260
  };
210
261
  const submitted = (text) => {
@@ -244,7 +295,9 @@ export class A2ASessionExecutor {
244
295
  }
245
296
  }
246
297
  signal.throwIfAborted();
247
- status(TaskState.TASK_STATE_WORKING);
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);
248
301
  };
249
302
  try {
250
303
  const parsed = parseA2AInput(context.request, this.options);
@@ -273,6 +326,8 @@ export class A2ASessionExecutor {
273
326
  await waitForPreparation(previous, controller.signal);
274
327
  controller.signal.throwIfAborted();
275
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' });
276
331
  if (saved?.roleSkills)
277
332
  submitted();
278
333
  let role;
@@ -283,21 +338,46 @@ export class A2ASessionExecutor {
283
338
  throw new RoleSkillLoadingError(error);
284
339
  }
285
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' });
286
345
  // ACP session preparation can itself wait in the process FIFO.
287
- if ((input.agentPreset ?? saved?.agentPreset ?? this.options.defaultAgentPreset)?.startsWith('oneagents-acp-'))
346
+ if (agentPreset?.startsWith('oneagents-acp-'))
288
347
  pendingCapacity();
289
348
  // Acquire only after context/role waits, immediately before session creation.
290
349
  capacityLease = await acquireCapacity();
291
350
  controller.signal.throwIfAborted();
292
351
  target = await this.backend.prepare({ sessionId: saved?.sessionId,
293
352
  cwd: input.cwd ?? saved?.cwd ?? this.options.defaultCwd,
294
- agentPreset: input.agentPreset ?? saved?.agentPreset ?? this.options.defaultAgentPreset,
295
- ...(input.preflight ? { preflight: input.preflight } : {}) }, { signal: controller.signal });
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
+ }
296
363
  if (role) {
297
364
  target.roleId = role.roleId;
298
365
  target.roleSkills = role.summary;
299
366
  promptPrefix = role.promptPrefix;
300
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
+ }
301
381
  this.store.saveTarget(context.contextId, target, context.context);
302
382
  }
303
383
  finally {
@@ -308,7 +388,27 @@ export class A2ASessionExecutor {
308
388
  // Preparation can include I/O or a cold ACP handshake. Never start the
309
389
  // model using a memory observation taken before that work.
310
390
  await beforeStart();
311
- const result = await this.backend.run(target, promptPrefix + prompt, { requestId, signal: controller.signal, 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 } : {}) });
312
412
  returnedError = result.outcome === 'failed' && result.error !== undefined
313
413
  ? toSafeError(result.error, { origin: 'a2a', operationId: requestId }) : undefined;
314
414
  returnedFailureMessage = result.outcome === 'failed' && typeof result.failureReason === 'string' && Object.hasOwn(FAILURE_MESSAGES, result.failureReason)
@@ -353,7 +453,7 @@ export class A2ASessionExecutor {
353
453
  });
354
454
  resultMetadata = await createA2AResultMetadata({ taskId: context.taskId, contextId: context.contextId,
355
455
  requestId, startedAt, outcome: controller.signal.aborted ? 'canceled' : 'failed', target, contract: resultContract,
356
- validationCode: capacityFailure?.code ?? (error instanceof A2AResultValidationError ? error.code : error instanceof RoleSkillLoadingError ? 'role-skills-unavailable' : undefined),
456
+ validationCode: capacityFailure?.code ?? sessionFailureCode(error) ?? (error instanceof A2AResultValidationError ? error.code : error instanceof RoleSkillLoadingError ? 'role-skills-unavailable' : undefined),
357
457
  ...(error instanceof A2APreflightError ? { preflight: error.report } : {}) });
358
458
  try {
359
459
  await saveA2AResultMetadata(resultMetadata, target);