@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.
Files changed (274) hide show
  1. package/README.md +19 -13
  2. package/dist/bin/a2a.js +6 -2
  3. package/dist/bin/acp-service.js +25 -1
  4. package/dist/bin/process.d.ts +4 -0
  5. package/dist/bin/process.js +57 -0
  6. package/dist/bin/roles.js +21 -18
  7. package/dist/bin/rsi.d.ts +3 -0
  8. package/dist/bin/rsi.js +114 -0
  9. package/dist/bin/ticket.d.ts +13 -0
  10. package/dist/bin/ticket.js +97 -0
  11. package/dist/bin/trail.d.ts +4 -0
  12. package/dist/bin/trail.js +62 -0
  13. package/dist/src/a2a/artifact-content.d.ts +9 -0
  14. package/dist/src/a2a/artifact-content.js +45 -0
  15. package/dist/src/a2a/desktop-notify.d.ts +1 -0
  16. package/dist/src/a2a/desktop-notify.js +12 -0
  17. package/dist/src/a2a/execution-binding.d.ts +9 -0
  18. package/dist/src/a2a/execution-binding.js +19 -0
  19. package/dist/src/a2a/executor.d.ts +7 -2
  20. package/dist/src/a2a/executor.js +127 -60
  21. package/dist/src/a2a/gateway.d.ts +581 -10
  22. package/dist/src/a2a/gateway.js +1018 -95
  23. package/dist/src/a2a/index.d.ts +8 -1
  24. package/dist/src/a2a/index.js +4 -0
  25. package/dist/src/a2a/job-directory.d.ts +6 -0
  26. package/dist/src/a2a/job-directory.js +19 -0
  27. package/dist/src/a2a/preflight.js +16 -1
  28. package/dist/src/a2a/resubmit.d.ts +46 -0
  29. package/dist/src/a2a/resubmit.js +82 -0
  30. package/dist/src/a2a/result-metadata.d.ts +3 -0
  31. package/dist/src/a2a/result-metadata.js +27 -5
  32. package/dist/src/a2a/server.d.ts +10 -0
  33. package/dist/src/a2a/server.js +125 -1
  34. package/dist/src/a2a/session-lifecycle.d.ts +40 -0
  35. package/dist/src/a2a/session-lifecycle.js +54 -0
  36. package/dist/src/a2a/store.d.ts +4 -0
  37. package/dist/src/a2a/store.js +70 -1
  38. package/dist/src/a2a/types.d.ts +46 -6
  39. package/dist/src/a2a/types.js +4 -6
  40. package/dist/src/a2a/workbench-ui.d.ts +28 -0
  41. package/dist/src/a2a/workbench-ui.js +182 -0
  42. package/dist/src/acp-connection.js +27 -3
  43. package/dist/src/bridge.d.ts +1 -0
  44. package/dist/src/bridge.js +191 -39
  45. package/dist/src/capacity-queue.d.ts +35 -0
  46. package/dist/src/capacity-queue.js +139 -2
  47. package/dist/src/capacity.d.ts +25 -0
  48. package/dist/src/capacity.js +48 -9
  49. package/dist/src/dsh.js +1 -1
  50. package/dist/src/execution/agent-files.d.ts +25 -0
  51. package/dist/src/execution/agent-files.js +90 -0
  52. package/dist/src/execution/agent-registry.d.ts +164 -0
  53. package/dist/src/execution/agent-registry.js +275 -0
  54. package/dist/src/execution/human-review.d.ts +2 -0
  55. package/dist/src/execution/human-review.js +3 -1
  56. package/dist/src/execution/ledger.d.ts +52 -0
  57. package/dist/src/execution/ledger.js +83 -5
  58. package/dist/src/execution/ppt-delivery.d.ts +0 -5
  59. package/dist/src/execution/ppt-delivery.js +0 -26
  60. package/dist/src/execution/process-request.d.ts +151 -0
  61. package/dist/src/execution/process-request.js +177 -0
  62. package/dist/src/execution/targets.d.ts +64 -5
  63. package/dist/src/execution/targets.js +58 -7
  64. package/dist/src/execution/ticket-executor.d.ts +25 -0
  65. package/dist/src/execution/ticket-executor.js +27 -0
  66. package/dist/src/execution/ticket.d.ts +326 -0
  67. package/dist/src/execution/ticket.js +301 -0
  68. package/dist/src/execution/workbench-chat.d.ts +25 -0
  69. package/dist/src/execution/workbench-chat.js +54 -0
  70. package/dist/src/execution/workbench.d.ts +32 -1
  71. package/dist/src/execution/workbench.js +113 -22
  72. package/dist/src/roles/index.d.ts +1 -1
  73. package/dist/src/roles/index.js +1 -1
  74. package/dist/src/roles/skills.d.ts +27 -58
  75. package/dist/src/roles/skills.js +89 -404
  76. package/dist/src/rsi/gate.d.ts +25 -0
  77. package/dist/src/rsi/gate.js +59 -0
  78. package/dist/src/rsi/outline-run.d.ts +107 -0
  79. package/dist/src/rsi/outline-run.js +443 -0
  80. package/dist/workbench-ui/app.css +453 -0
  81. package/dist/workbench-ui/app.js +13 -0
  82. package/dist/workbench-ui/chunk-23JHGYT3.js +1 -0
  83. package/dist/workbench-ui/chunk-3H6STGPV.js +1 -0
  84. package/dist/workbench-ui/chunk-3SNBBMGH.js +1 -0
  85. package/dist/workbench-ui/chunk-3XJZ6DIE.js +1 -0
  86. package/dist/workbench-ui/chunk-44KDLLKJ.js +1 -0
  87. package/dist/workbench-ui/chunk-46H7FU5Y.js +7 -0
  88. package/dist/workbench-ui/chunk-4N44QPL7.js +1 -0
  89. package/dist/workbench-ui/chunk-4YN4BS7I.js +1 -0
  90. package/dist/workbench-ui/chunk-53EG4IVQ.js +96 -0
  91. package/dist/workbench-ui/chunk-5FIPUNR4.js +1 -0
  92. package/dist/workbench-ui/chunk-6DWWYA6G.js +2 -0
  93. package/dist/workbench-ui/chunk-6FU3T633.js +99 -0
  94. package/dist/workbench-ui/chunk-6XKIHRA4.js +1 -0
  95. package/dist/workbench-ui/chunk-7GIX43Y5.js +1 -0
  96. package/dist/workbench-ui/chunk-7Q4WBGX6.js +4 -0
  97. package/dist/workbench-ui/chunk-A3BQM7HR.js +1 -0
  98. package/dist/workbench-ui/chunk-AFCFDDOP.js +24 -0
  99. package/dist/workbench-ui/chunk-AG67EUYD.js +89 -0
  100. package/dist/workbench-ui/chunk-AGJHMMTN.js +1 -0
  101. package/dist/workbench-ui/chunk-AO6JUBV6.js +41 -0
  102. package/dist/workbench-ui/chunk-AUSLTP43.js +72 -0
  103. package/dist/workbench-ui/chunk-AVZL46TT.js +1 -0
  104. package/dist/workbench-ui/chunk-AZRIGIV2.js +168 -0
  105. package/dist/workbench-ui/chunk-B2LIVH37.js +1 -0
  106. package/dist/workbench-ui/chunk-B7YX5TR5.js +1 -0
  107. package/dist/workbench-ui/chunk-BCB4X4XX.js +1 -0
  108. package/dist/workbench-ui/chunk-BCRQUL2A.js +88 -0
  109. package/dist/workbench-ui/chunk-BI6UHHQP.js +1 -0
  110. package/dist/workbench-ui/chunk-BLSLQ4AQ.js +120 -0
  111. package/dist/workbench-ui/chunk-C3QSRS6E.js +1 -0
  112. package/dist/workbench-ui/chunk-CK7M2PJ3.js +62 -0
  113. package/dist/workbench-ui/chunk-CM6LZ7TU.js +1 -0
  114. package/dist/workbench-ui/chunk-CP63H27F.js +36 -0
  115. package/dist/workbench-ui/chunk-CPUMMIS2.js +70 -0
  116. package/dist/workbench-ui/chunk-CSEIBI5U.js +2 -0
  117. package/dist/workbench-ui/chunk-CUS65DKZ.js +161 -0
  118. package/dist/workbench-ui/chunk-CVQY7TNC.js +1 -0
  119. package/dist/workbench-ui/chunk-D6S3XBIX.js +106 -0
  120. package/dist/workbench-ui/chunk-E253Y562.js +1 -0
  121. package/dist/workbench-ui/chunk-EADDJUDC.js +1 -0
  122. package/dist/workbench-ui/chunk-EBGJ3YXG.js +206 -0
  123. package/dist/workbench-ui/chunk-EKPVZ3WY.js +8 -0
  124. package/dist/workbench-ui/chunk-EQDCEAFY.js +1 -0
  125. package/dist/workbench-ui/chunk-ES3SSDJY.js +40 -0
  126. package/dist/workbench-ui/chunk-ESFD2H7N.js +231 -0
  127. package/dist/workbench-ui/chunk-FVOHPMS6.js +1 -0
  128. package/dist/workbench-ui/chunk-FXMQAGVT.js +1 -0
  129. package/dist/workbench-ui/chunk-GGTADRXD.js +24 -0
  130. package/dist/workbench-ui/chunk-GHIVPGNQ.js +1 -0
  131. package/dist/workbench-ui/chunk-GLU2YQV2.js +1 -0
  132. package/dist/workbench-ui/chunk-GOCKBYSM.js +1 -0
  133. package/dist/workbench-ui/chunk-H2KMMTJB.js +1 -0
  134. package/dist/workbench-ui/chunk-HGVLDNPP.js +39 -0
  135. package/dist/workbench-ui/chunk-HSAVC5GY.js +1 -0
  136. package/dist/workbench-ui/chunk-HSEAD2JH.js +1 -0
  137. package/dist/workbench-ui/chunk-HSIHOBTY.js +1 -0
  138. package/dist/workbench-ui/chunk-IZXOKUGG.js +67 -0
  139. package/dist/workbench-ui/chunk-JFT2LC2T.js +1 -0
  140. package/dist/workbench-ui/chunk-JHL3ZDYK.js +3 -0
  141. package/dist/workbench-ui/chunk-JMORLCZG.js +257 -0
  142. package/dist/workbench-ui/chunk-JR4SIX7A.js +1 -0
  143. package/dist/workbench-ui/chunk-K23HAGEH.js +30 -0
  144. package/dist/workbench-ui/chunk-K43JDCBH.js +1 -0
  145. package/dist/workbench-ui/chunk-KINKFJY7.js +1 -0
  146. package/dist/workbench-ui/chunk-KKQSA4LI.js +2 -0
  147. package/dist/workbench-ui/chunk-KOUZX3UX.js +1 -0
  148. package/dist/workbench-ui/chunk-KR4DRHW2.js +78 -0
  149. package/dist/workbench-ui/chunk-KT4DJNOR.js +1 -0
  150. package/dist/workbench-ui/chunk-KTPNKRRZ.js +292 -0
  151. package/dist/workbench-ui/chunk-LFHIPGSU.js +7 -0
  152. package/dist/workbench-ui/chunk-LWDL4HZB.js +125 -0
  153. package/dist/workbench-ui/chunk-MVYC3CY4.js +1 -0
  154. package/dist/workbench-ui/chunk-NWUPALCY.js +129 -0
  155. package/dist/workbench-ui/chunk-NY7C662Z.js +1 -0
  156. package/dist/workbench-ui/chunk-O76WTHWP.js +1 -0
  157. package/dist/workbench-ui/chunk-OTF7YHRE.js +162 -0
  158. package/dist/workbench-ui/chunk-P6TKKRKP.js +1 -0
  159. package/dist/workbench-ui/chunk-PFHOOWV3.js +1 -0
  160. package/dist/workbench-ui/chunk-PUQLANIM.js +1 -0
  161. package/dist/workbench-ui/chunk-PZCGBYVO.js +1 -0
  162. package/dist/workbench-ui/chunk-QOHUZGP4.js +1 -0
  163. package/dist/workbench-ui/chunk-QSEG3OFF.js +1 -0
  164. package/dist/workbench-ui/chunk-QYPOXZIA.js +84 -0
  165. package/dist/workbench-ui/chunk-R6SOF3JC.js +1 -0
  166. package/dist/workbench-ui/chunk-RCLOYU5F.js +1 -0
  167. package/dist/workbench-ui/chunk-RSRUP64S.js +1 -0
  168. package/dist/workbench-ui/chunk-RVAIT6JW.js +1 -0
  169. package/dist/workbench-ui/chunk-S2CCN3II.js +1 -0
  170. package/dist/workbench-ui/chunk-S2Q52W46.js +1 -0
  171. package/dist/workbench-ui/chunk-S2W5THJ5.js +1 -0
  172. package/dist/workbench-ui/chunk-S6ZQZNOX.js +1 -0
  173. package/dist/workbench-ui/chunk-S74PLMMS.js +1 -0
  174. package/dist/workbench-ui/chunk-S7C4HKEY.js +1 -0
  175. package/dist/workbench-ui/chunk-SDTB3Q65.js +1 -0
  176. package/dist/workbench-ui/chunk-SLPRGYUV.js +32 -0
  177. package/dist/workbench-ui/chunk-SQE76S5B.js +1 -0
  178. package/dist/workbench-ui/chunk-SSDZPVPW.js +1 -0
  179. package/dist/workbench-ui/chunk-SVI7DGIE.js +1 -0
  180. package/dist/workbench-ui/chunk-T6QKLZ4H.js +62 -0
  181. package/dist/workbench-ui/chunk-TJNRPTFL.js +1 -0
  182. package/dist/workbench-ui/chunk-TP6U4EDH.js +2 -0
  183. package/dist/workbench-ui/chunk-TYAAT3GQ.js +1 -0
  184. package/dist/workbench-ui/chunk-U6OCY4ZH.js +1 -0
  185. package/dist/workbench-ui/chunk-UAN3NLRF.js +1 -0
  186. package/dist/workbench-ui/chunk-UMLU3FIX.js +1 -0
  187. package/dist/workbench-ui/chunk-URIY2OTM.js +1 -0
  188. package/dist/workbench-ui/chunk-V2NUKAA7.js +38 -0
  189. package/dist/workbench-ui/chunk-V4QLL4TE.js +139 -0
  190. package/dist/workbench-ui/chunk-VASHXUK4.js +2 -0
  191. package/dist/workbench-ui/chunk-VJLIWNIU.js +1 -0
  192. package/dist/workbench-ui/chunk-VQNQFBID.js +1 -0
  193. package/dist/workbench-ui/chunk-VSIWU7XA.js +3 -0
  194. package/dist/workbench-ui/chunk-VSJASPUZ.js +321 -0
  195. package/dist/workbench-ui/chunk-VXPNUNUX.js +3 -0
  196. package/dist/workbench-ui/chunk-WBKLDCV6.js +1 -0
  197. package/dist/workbench-ui/chunk-WOKJM3FY.js +1 -0
  198. package/dist/workbench-ui/chunk-X3U3NA3X.js +34 -0
  199. package/dist/workbench-ui/chunk-XBYU7M4J.js +1 -0
  200. package/dist/workbench-ui/chunk-XBZAO4ID.js +10 -0
  201. package/dist/workbench-ui/chunk-XLLPZ2WO.js +1 -0
  202. package/dist/workbench-ui/chunk-YFVL4NJL.js +1 -0
  203. package/dist/workbench-ui/chunk-YRFQENM4.js +1 -0
  204. package/dist/workbench-ui/chunk-YUADQVB2.js +1 -0
  205. package/dist/workbench-ui/chunk-Z3TCAKM5.js +1 -0
  206. package/dist/workbench-ui/chunk-Z6QR6FRE.js +10 -0
  207. package/dist/workbench-ui/chunk-ZJPSORPP.js +3 -0
  208. package/dist/workbench-ui/chunk-ZLGCSTR2.js +15 -0
  209. package/dist/workbench-ui/chunk-ZLR4SG5X.js +1 -0
  210. package/dist/workbench-ui/chunk-ZND3TTGF.js +1 -0
  211. package/dist/workbench-ui/chunk-ZOP3ZYH7.js +2 -0
  212. package/dist/workbench-ui/index.html +14 -0
  213. package/package.json +19 -8
  214. package/skills/acp-service/SKILL.md +4 -2
  215. package/skills/acp-service/references/a2a.md +18 -6
  216. package/skills/acp-service/references/dsh.md +2 -0
  217. package/skills/acp-service/references/roles-and-tasks.md +10 -10
  218. package/skills/rsi-coach/SKILL.md +134 -0
  219. package/vendor/dsh/README.md +10 -6
  220. package/vendor/dsh/a2a-executor.d.ts +56 -2
  221. package/vendor/dsh/a2a-executor.js +163 -17
  222. package/vendor/dsh/a2a.d.ts +12 -2
  223. package/vendor/dsh/a2a.js +9 -2
  224. package/vendor/dsh/adapter.d.ts +52 -3
  225. package/vendor/dsh/adapter.js +297 -30
  226. package/vendor/dsh/client.js +67 -11
  227. package/vendor/dsh/index.js +55 -3
  228. package/vendor/dsh/native-approvals.d.ts +4 -0
  229. package/vendor/dsh/native-approvals.js +44 -0
  230. package/vendor/dsh/preset-route.d.ts +49 -0
  231. package/vendor/dsh/preset-route.js +51 -0
  232. package/vendor/dsh/preset.js +10 -3
  233. package/vendor/dsh/process-admission.d.ts +25 -0
  234. package/vendor/dsh/process-admission.js +87 -0
  235. package/vendor/dsh/process-requests.d.ts +57 -0
  236. package/vendor/dsh/process-requests.js +49 -0
  237. package/vendor/dsh/review-mcp.d.ts +1 -0
  238. package/vendor/dsh/review-mcp.js +56 -0
  239. package/vendor/dsh/review.d.ts +30 -0
  240. package/vendor/dsh/review.js +149 -0
  241. package/vendor/dsh/session-settings.d.ts +34 -0
  242. package/vendor/dsh/session-settings.js +114 -0
  243. package/vendor/dsh/ticket-spec.d.ts +30 -0
  244. package/vendor/dsh/ticket-spec.js +10 -0
  245. package/vendor/dsh/ticket-tools.d.ts +21 -0
  246. package/vendor/dsh/ticket-tools.js +43 -0
  247. package/vendor/dsh/workbench.d.ts +18 -0
  248. package/vendor/dsh/workbench.js +91 -0
  249. package/vendor/runtime/README.md +6 -4
  250. package/vendor/runtime/dist/docs-site/CLI.html +2 -2
  251. package/vendor/runtime/dist/docs-site/VISION.html +2 -2
  252. package/vendor/runtime/dist/docs-site/agents.html +2 -2
  253. package/vendor/runtime/dist/docs-site/compare.html +2 -2
  254. package/vendor/runtime/dist/docs-site/config.html +2 -2
  255. package/vendor/runtime/dist/docs-site/custom-agents.html +2 -2
  256. package/vendor/runtime/dist/docs-site/exit-codes.html +2 -2
  257. package/vendor/runtime/dist/docs-site/flows.html +2 -2
  258. package/vendor/runtime/dist/docs-site/index.html +1 -1
  259. package/vendor/runtime/dist/docs-site/install.html +2 -2
  260. package/vendor/runtime/dist/docs-site/llms.txt +1 -1
  261. package/vendor/runtime/dist/docs-site/output-formats.html +2 -2
  262. package/vendor/runtime/dist/docs-site/permissions.html +2 -2
  263. package/vendor/runtime/dist/docs-site/prompting.html +2 -2
  264. package/vendor/runtime/dist/docs-site/quickstart.html +2 -2
  265. package/vendor/runtime/dist/docs-site/releasing.html +2 -2
  266. package/vendor/runtime/dist/docs-site/runtime-environment.html +2 -2
  267. package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +2 -2
  268. package/vendor/runtime/dist/docs-site/safe-errors.html +2 -2
  269. package/vendor/runtime/dist/docs-site/session-control.html +2 -2
  270. package/vendor/runtime/dist/docs-site/session-watch.html +2 -2
  271. package/vendor/runtime/dist/docs-site/sessions.html +2 -2
  272. package/vendor/runtime/dist/docs-site/shared-sessions.html +2 -2
  273. package/vendor/runtime/package.json +6 -4
  274. package/vendor/runtime/skills/acpx/SKILL.md +2 -0
@@ -67,6 +67,7 @@ function parseTask(value) {
67
67
  text(artifact.artifactId, 'artifact ID');
68
68
  return task;
69
69
  }
70
+ const targetStates = new Set(['attached', 'busy', 'idle', 'closing', 'closed', 'stale', 'deleted']);
70
71
  function parseTarget(value) {
71
72
  const source = record(value, 'target');
72
73
  const sessionId = text(source.sessionId, 'session ID');
@@ -77,10 +78,55 @@ function parseTarget(value) {
77
78
  const preflight = source.preflight === undefined ? undefined : a2aPreflightReportSchema.parse(source.preflight);
78
79
  const roleSkills = source.roleSkills === undefined ? undefined : a2aRoleSkillsSchema.parse(source.roleSkills);
79
80
  const roleId = source.roleId === undefined ? undefined : text(source.roleId, 'role identity');
81
+ const provider = source.provider === undefined ? undefined : text(source.provider, 'model provider');
82
+ const model = source.model === undefined ? undefined : text(source.model, 'model');
83
+ if ((provider !== undefined) !== (model !== undefined))
84
+ throw new Error('A2A model provider and model must be stored together');
80
85
  if ((roleId !== undefined) !== (roleSkills !== undefined))
81
86
  throw new Error('A2A role identity and skill lock must be stored together');
87
+ let state;
88
+ if (source.state !== undefined) {
89
+ if (typeof source.state !== 'string' || !targetStates.has(source.state))
90
+ throw new Error('Invalid A2A target state');
91
+ state = source.state;
92
+ }
93
+ let lastUsedAt;
94
+ if (source.lastUsedAt !== undefined) {
95
+ lastUsedAt = text(source.lastUsedAt, 'last used time');
96
+ if (!Number.isFinite(Date.parse(lastUsedAt)))
97
+ throw new Error('Invalid A2A target last used time');
98
+ }
99
+ let resumed;
100
+ if (source.resumed !== undefined) {
101
+ if (typeof source.resumed !== 'boolean')
102
+ throw new Error('Invalid A2A resume marker');
103
+ resumed = source.resumed;
104
+ }
105
+ let restoreMethod;
106
+ if (source.restoreMethod !== undefined) {
107
+ if (source.restoreMethod !== 'session/load' && source.restoreMethod !== 'session/resume')
108
+ throw new Error('Invalid A2A restore method');
109
+ restoreMethod = source.restoreMethod;
110
+ }
111
+ let lifecycle;
112
+ if (source.lifecycle !== undefined) {
113
+ const policy = record(source.lifecycle, 'target lifecycle');
114
+ if (policy.mode !== 'persistent' && policy.mode !== 'one-shot')
115
+ throw new Error('Invalid A2A target lifecycle');
116
+ if (policy.idleTtlSeconds !== undefined && (!Number.isSafeInteger(policy.idleTtlSeconds) || policy.idleTtlSeconds < 0)) {
117
+ throw new Error('Invalid A2A target idle TTL');
118
+ }
119
+ if (policy.closeAfter !== undefined && policy.closeAfter !== 'terminal' && policy.closeAfter !== 'ack') {
120
+ throw new Error('Invalid A2A target close timing');
121
+ }
122
+ lifecycle = { mode: policy.mode, ...(policy.idleTtlSeconds === undefined ? {} : { idleTtlSeconds: policy.idleTtlSeconds }),
123
+ ...(policy.closeAfter === undefined ? {} : { closeAfter: policy.closeAfter }) };
124
+ }
82
125
  return { sessionId, cwd, ...(agentPreset === undefined ? {} : { agentPreset }), ...(preflight === undefined ? {} : { preflight }),
83
- ...(roleSkills === undefined ? {} : { roleId, roleSkills }) };
126
+ ...(roleSkills === undefined ? {} : { roleId, roleSkills }), ...(state === undefined ? {} : { state }),
127
+ ...(resumed === undefined ? {} : { resumed }), ...(restoreMethod === undefined ? {} : { restoreMethod }),
128
+ ...(lastUsedAt === undefined ? {} : { lastUsedAt }), ...(lifecycle === undefined ? {} : { lifecycle }),
129
+ ...(provider === undefined ? {} : { provider, model }) };
84
130
  }
85
131
  function validatePushUrl(value) {
86
132
  const url = text(value, 'push URL');
@@ -272,6 +318,29 @@ export class FileA2AStore {
272
318
  const target = this.targets.get(key(scopeOf(context), contextId));
273
319
  return target && structuredClone(target);
274
320
  }
321
+ /** The most recently updated task this host ran in one DSH session, within the caller's scope. */
322
+ latestTaskForSession(sessionId, context) {
323
+ this.assertOpen();
324
+ text(sessionId, 'session ID');
325
+ const scope = scopeOf(context);
326
+ let latest;
327
+ for (const cached of this.tasks.values()) {
328
+ if (cached.scope.tenant !== scope.tenant || cached.scope.owner !== scope.owner)
329
+ continue;
330
+ if (cached.task.metadata?.['1agents']?.sessionId !== sessionId)
331
+ continue;
332
+ if (!latest || Date.parse(cached.task.status?.timestamp ?? '') > Date.parse(latest.status?.timestamp ?? ''))
333
+ latest = cached.task;
334
+ }
335
+ return latest && parseTask(Task.toJSON(latest));
336
+ }
337
+ /** The DSH session a task ran in, within the caller's scope. */
338
+ sessionOfTask(taskId, context) {
339
+ this.assertOpen();
340
+ text(taskId, 'task ID');
341
+ const sessionId = this.tasks.get(key(scopeOf(context), taskId))?.task.metadata?.['1agents']?.sessionId;
342
+ return typeof sessionId === 'string' ? sessionId : undefined;
343
+ }
275
344
  saveTarget(contextId, target, context) {
276
345
  this.assertOpen();
277
346
  text(contextId, 'context ID');
@@ -1,19 +1,16 @@
1
1
  /** Execution interfaces shared by DSH and future standalone A2A hosts. */
2
2
  import type { SafeError } from '@1agents/acp-service/runtime';
3
3
  import { z } from 'zod';
4
- /** Host-authored summary of a verified, immutable role/skill lock. */
4
+ import type { A2AExecutionRef } from './execution-binding.js';
5
+ /** Host-authored summary of the role skills a session was given: each one sits in the session's `.agents/skills`. */
5
6
  export declare const a2aRoleSkillsSchema: z.ZodObject<{
6
7
  roleId: z.ZodString;
7
8
  roleVersion: z.ZodString;
8
- lockPath: z.ZodString;
9
9
  roleDirectory: z.ZodString;
10
10
  entryGuidePath: z.ZodOptional<z.ZodString>;
11
11
  skills: z.ZodArray<z.ZodObject<{
12
12
  key: z.ZodString;
13
- skillId: z.ZodString;
14
- sourceId: z.ZodString;
15
13
  name: z.ZodString;
16
- revision: z.ZodString;
17
14
  directory: z.ZodString;
18
15
  guidePath: z.ZodString;
19
16
  }, z.core.$strict>>;
@@ -56,6 +53,30 @@ export interface A2ATarget {
56
53
  /** Logical host binding; several bindings may use one canonical skill profile. */
57
54
  roleId?: string;
58
55
  roleSkills?: A2ARoleSkills;
56
+ /** Set when this target was attached again through session/load or session/resume. */
57
+ resumed?: boolean;
58
+ restoreMethod?: 'session/load' | 'session/resume';
59
+ /** Absent on records written before session close. Callers treat that as attached. */
60
+ state?: 'attached' | 'busy' | 'idle' | 'closing' | 'closed' | 'stale' | 'deleted';
61
+ lastUsedAt?: string;
62
+ lifecycle?: {
63
+ mode: 'persistent' | 'one-shot';
64
+ idleTtlSeconds?: number;
65
+ closeAfter?: 'terminal' | 'ack';
66
+ };
67
+ /** Model the host selected for a standard preset. Absent when the session uses the host default. */
68
+ provider?: string;
69
+ model?: string;
70
+ }
71
+ export interface A2ACloseResult {
72
+ processReleased: true | 'pending';
73
+ /** False when the preset has no ACP child process. */
74
+ acp?: boolean;
75
+ }
76
+ export interface A2ASessionStatus {
77
+ attached: boolean;
78
+ activeTurn: boolean;
79
+ lastUsedAt?: string;
59
80
  }
60
81
  /** Omitted location and preset reuse a saved context or the host defaults. */
61
82
  export interface A2APrepareInput {
@@ -66,7 +87,11 @@ export interface A2APrepareInput {
66
87
  /** Only selects a host-configured profile; clients cannot supply profile or cache configuration. */
67
88
  roleId?: string;
68
89
  /** Optional existing parent lock under the host cache's locks directory. */
69
- roleLockPath?: string;
90
+ /** A path agent's agents/*.md inside cwd; its body prefixes the first message of a new session. Not combined with roleId. */
91
+ agentFile?: string;
92
+ /** Standard presets only, passed together. Omitted keeps the session's current or host-default model. */
93
+ provider?: string;
94
+ model?: string;
70
95
  }
71
96
  /** A single DSH turn's output, without transport or host dependencies. */
72
97
  export interface A2ARunResult {
@@ -95,5 +120,20 @@ export interface A2ABackend {
95
120
  signal: AbortSignal;
96
121
  /** Hosts with a session queue call this again immediately before submitting the prompt. */
97
122
  beforeStart?: (signal?: AbortSignal) => Promise<void>;
123
+ /** Process-slot wait stays submitted. Undefined means the handshake has started. */
124
+ onCapacity?: (pending: {
125
+ code: 'CAPACITY_PENDING';
126
+ position: number;
127
+ waitedMs: number;
128
+ } | undefined) => void;
129
+ /** Set by the gateway. The DSH host binds it for the prompt and never puts the workbench credential here. */
130
+ execution?: A2AExecutionRef;
98
131
  }): Promise<A2ARunResult>;
132
+ /** Ordinary session release. Hosts that cannot close omit this and the gateway reports UNSUPPORTED. */
133
+ close?(target: A2ATarget, options?: {
134
+ signal?: AbortSignal;
135
+ }): Promise<A2ACloseResult>;
136
+ status?(target: A2ATarget): Promise<A2ASessionStatus>;
137
+ /** Controlled delete: ACP session/delete, never DSH history. The gateway sends it only when allowDelete is set. */
138
+ delete?(target: A2ATarget): Promise<A2ACloseResult>;
99
139
  }
@@ -1,11 +1,9 @@
1
1
  import { isAbsolute } from 'node:path';
2
2
  import { z } from 'zod';
3
3
  const roleText = z.string().min(1).max(4096).refine(value => !value.includes('\0'));
4
- const rolePath = roleText.refine(isAbsolute, 'Expected an absolute role cache path');
5
- /** Host-authored summary of a verified, immutable role/skill lock. */
4
+ const rolePath = roleText.refine(isAbsolute, 'Expected an absolute role path');
5
+ /** Host-authored summary of the role skills a session was given: each one sits in the session's `.agents/skills`. */
6
6
  export const a2aRoleSkillsSchema = z.object({
7
- roleId: roleText, roleVersion: roleText, lockPath: rolePath, roleDirectory: rolePath,
8
- entryGuidePath: rolePath.optional(),
9
- skills: z.array(z.object({ key: roleText, skillId: roleText, sourceId: roleText, name: roleText,
10
- revision: z.string().regex(/^[a-f0-9]{64}$/), directory: rolePath, guidePath: rolePath }).strict()).min(1).max(100),
7
+ roleId: roleText, roleVersion: roleText, roleDirectory: rolePath, entryGuidePath: rolePath.optional(),
8
+ skills: z.array(z.object({ key: roleText, name: roleText, directory: rolePath, guidePath: rolePath }).strict()).min(1).max(100),
11
9
  }).strict();
@@ -0,0 +1,28 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ export declare const WORKBENCH_UI_PATH = "/workbench/ui";
3
+ /**
4
+ * The page and its static assets under WORKBENCH_UI_PATH. `frameAncestors` lets a host that embeds the
5
+ * page in its own frame (DSH) allow exactly that; the gateway's own page is never framed.
6
+ */
7
+ export declare function serveWorkbenchPage(req: IncomingMessage, res: ServerResponse, pathname: string, options?: {
8
+ frameAncestors?: "'none'" | "'self'";
9
+ }): Promise<void>;
10
+ /** Agent sessions and CLI tools never act as the human reviewer. */
11
+ export declare function isAgentRequest(req: IncomingMessage): boolean;
12
+ /** Same rule as the former 1agents proxy: a direct browser request whose Origin authority is this Host. */
13
+ export declare function sameOriginBrowser(req: IncomingMessage): boolean;
14
+ export declare class WorkbenchUi {
15
+ private readonly token;
16
+ private readonly now;
17
+ private readonly sessions;
18
+ constructor(token: string | undefined, now?: () => number);
19
+ /**
20
+ * Serves the page, the login session and static assets. For an authorized page API call it returns
21
+ * the matching /workbench route, which the caller dispatches exactly like the bearer API.
22
+ */
23
+ handle(req: IncomingMessage, res: ServerResponse, url: URL): Promise<{
24
+ route: string;
25
+ } | undefined>;
26
+ private authorized;
27
+ private session;
28
+ }
@@ -0,0 +1,182 @@
1
+ /**
2
+ * The gateway's own workbench page. A logged-in same-origin browser reaches the same routes as the bearer API.
3
+ * Without a configured token the page needs no login; writes still need a same-origin browser.
4
+ */
5
+ import { randomBytes, timingSafeEqual } from 'node:crypto';
6
+ import { existsSync } from 'node:fs';
7
+ import { readFile } from 'node:fs/promises';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ export const WORKBENCH_UI_PATH = '/workbench/ui';
11
+ const API_PATH = `${WORKBENCH_UI_PATH}/api`;
12
+ const COOKIE = 'acp_workbench';
13
+ const SESSION_MS = 12 * 60 * 60 * 1000;
14
+ const MAX_SESSIONS = 64;
15
+ const ASSETS = { 'app.js': 'text/javascript; charset=utf-8', 'app.css': 'text/css; charset=utf-8' };
16
+ /** Lazy-loaded renderer chunks (markdown, highlighting) emitted by the page build. */
17
+ const CHUNK = /^chunk-[A-Za-z0-9_-]+\.js$/;
18
+ const SECURITY_HEADERS = {
19
+ 'Content-Security-Policy': "default-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'",
20
+ 'X-Content-Type-Options': 'nosniff',
21
+ 'Referrer-Policy': 'no-referrer',
22
+ 'Cache-Control': 'no-store',
23
+ };
24
+ /**
25
+ * Built output sits in dist/workbench-ui; the source tree runs from src/a2a under tsx. Only the build
26
+ * has app.js, so the page source directory beside src is never served.
27
+ */
28
+ function assetDirectory() {
29
+ const here = path.dirname(fileURLToPath(import.meta.url));
30
+ return [path.resolve(here, '../../workbench-ui'), path.resolve(here, '../../dist/workbench-ui')]
31
+ .find(directory => existsSync(path.join(directory, 'app.js')));
32
+ }
33
+ function send(res, status, type, payload, headers = {}) {
34
+ res.writeHead(status, { ...SECURITY_HEADERS, 'Content-Type': type, ...headers });
35
+ res.end(payload);
36
+ }
37
+ function sendJson(res, status, data, headers = {}) {
38
+ send(res, status, 'application/json', JSON.stringify(data), headers);
39
+ }
40
+ /**
41
+ * The page and its static assets under WORKBENCH_UI_PATH. `frameAncestors` lets a host that embeds the
42
+ * page in its own frame (DSH) allow exactly that; the gateway's own page is never framed.
43
+ */
44
+ export async function serveWorkbenchPage(req, res, pathname, options = {}) {
45
+ const headers = options.frameAncestors === "'self'"
46
+ ? { 'Content-Security-Policy': SECURITY_HEADERS['Content-Security-Policy'].replace("frame-ancestors 'none'", "frame-ancestors 'self'") } : {};
47
+ if (req.method !== 'GET')
48
+ return sendJson(res, 405, { error: 'Method not allowed' }, headers);
49
+ const directory = assetDirectory();
50
+ if (!directory)
51
+ return sendJson(res, 503, { error: 'Workbench page is not built' }, headers);
52
+ if (pathname === WORKBENCH_UI_PATH || pathname === `${WORKBENCH_UI_PATH}/`) {
53
+ return send(res, 200, 'text/html; charset=utf-8', await readFile(path.join(directory, 'index.html')), headers);
54
+ }
55
+ const asset = pathname.slice(`${WORKBENCH_UI_PATH}/`.length);
56
+ const type = Object.hasOwn(ASSETS, asset) ? ASSETS[asset] : CHUNK.test(asset) ? ASSETS['app.js'] : undefined;
57
+ if (!type)
58
+ return sendJson(res, 404, { error: 'No workbench page asset' }, headers);
59
+ try {
60
+ return send(res, 200, type, await readFile(path.join(directory, asset)), headers);
61
+ }
62
+ catch {
63
+ return sendJson(res, 404, { error: 'No workbench page asset' }, headers);
64
+ }
65
+ }
66
+ /** Agent sessions and CLI tools never act as the human reviewer. */
67
+ export function isAgentRequest(req) {
68
+ if (['x-oneagents-session-id', 'x-oneagents-session-token', 'x-oneagents-turn-id'].some(name => req.headers[name]))
69
+ return true;
70
+ const origin = String(req.headers['x-oneagents-origin'] ?? '').toLowerCase();
71
+ return origin === 'mcp' || origin === 'cli' || Boolean(req.headers.authorization);
72
+ }
73
+ /** Same rule as the former 1agents proxy: a direct browser request whose Origin authority is this Host. */
74
+ export function sameOriginBrowser(req) {
75
+ if (req.headers['sec-fetch-site'] !== 'same-origin')
76
+ return false;
77
+ try {
78
+ const origin = new URL(String(req.headers.origin ?? ''));
79
+ if (!['http:', 'https:'].includes(origin.protocol) || origin.username || origin.password)
80
+ return false;
81
+ if ((origin.pathname !== '' && origin.pathname !== '/') || origin.search || origin.hash)
82
+ return false;
83
+ return origin.host.toLowerCase() === String(req.headers.host ?? '').toLowerCase();
84
+ }
85
+ catch {
86
+ return false;
87
+ }
88
+ }
89
+ function cookieValue(req) {
90
+ for (const part of String(req.headers.cookie ?? '').split(';')) {
91
+ const [name, ...value] = part.trim().split('=');
92
+ if (name === COOKIE)
93
+ return value.join('=');
94
+ }
95
+ }
96
+ async function readToken(req) {
97
+ let length = 0;
98
+ const chunks = [];
99
+ for await (const data of req) {
100
+ length += data.length;
101
+ if (length > 4096)
102
+ throw new Error('Request body too large');
103
+ chunks.push(Buffer.from(data));
104
+ }
105
+ return JSON.parse(Buffer.concat(chunks).toString('utf8')).token;
106
+ }
107
+ export class WorkbenchUi {
108
+ token;
109
+ now;
110
+ sessions = new Map();
111
+ constructor(token, now = Date.now) {
112
+ this.token = token;
113
+ this.now = now;
114
+ }
115
+ /**
116
+ * Serves the page, the login session and static assets. For an authorized page API call it returns
117
+ * the matching /workbench route, which the caller dispatches exactly like the bearer API.
118
+ */
119
+ async handle(req, res, url) {
120
+ const pathname = url.pathname;
121
+ if (!pathname.startsWith(`${API_PATH}/`))
122
+ return void await serveWorkbenchPage(req, res, pathname);
123
+ if (isAgentRequest(req))
124
+ return void sendJson(res, 403, { error: 'browser_action_required', message: 'Agents and tools use the bearer workbench API, not the page.' });
125
+ const write = req.method !== 'GET';
126
+ if (write && !sameOriginBrowser(req)) {
127
+ return void sendJson(res, 403, { error: 'browser_action_required', message: '请在本工作台页面提交。' });
128
+ }
129
+ if (pathname === `${API_PATH}/session`)
130
+ return this.session(req, res);
131
+ if (!this.authorized(req))
132
+ return void sendJson(res, 401, { error: 'login_required', message: '请先登录工作台。' });
133
+ return { route: `/workbench${pathname.slice(API_PATH.length)}` };
134
+ }
135
+ authorized(req) {
136
+ if (!this.token)
137
+ return true;
138
+ const id = cookieValue(req);
139
+ const expires = id ? this.sessions.get(id) : undefined;
140
+ if (!id || expires === undefined)
141
+ return false;
142
+ if (expires <= this.now()) {
143
+ this.sessions.delete(id);
144
+ return false;
145
+ }
146
+ return true;
147
+ }
148
+ async session(req, res) {
149
+ if (req.method === 'GET')
150
+ return void sendJson(res, 200, { authenticated: this.authorized(req), loginRequired: Boolean(this.token) });
151
+ if (req.method === 'DELETE') {
152
+ const id = cookieValue(req);
153
+ if (id)
154
+ this.sessions.delete(id);
155
+ return void sendJson(res, 200, { authenticated: false }, { 'Set-Cookie': `${COOKIE}=; HttpOnly; SameSite=Strict; Path=${WORKBENCH_UI_PATH}; Max-Age=0` });
156
+ }
157
+ if (req.method !== 'POST')
158
+ return void sendJson(res, 405, { error: 'Method not allowed' });
159
+ if (!this.token)
160
+ return void sendJson(res, 200, { authenticated: true });
161
+ let supplied;
162
+ try {
163
+ supplied = await readToken(req);
164
+ }
165
+ catch {
166
+ return void sendJson(res, 400, { error: 'invalid', message: '请求格式不正确。' });
167
+ }
168
+ const expected = Buffer.from(this.token), given = Buffer.from(typeof supplied === 'string' ? supplied : '');
169
+ if (given.length !== expected.length || !timingSafeEqual(given, expected)) {
170
+ return void sendJson(res, 401, { error: 'login_failed', message: '工作台令牌不正确。' });
171
+ }
172
+ const now = this.now();
173
+ for (const [id, expires] of this.sessions)
174
+ if (expires <= now)
175
+ this.sessions.delete(id);
176
+ while (this.sessions.size >= MAX_SESSIONS)
177
+ this.sessions.delete(this.sessions.keys().next().value);
178
+ const id = randomBytes(32).toString('base64url');
179
+ this.sessions.set(id, now + SESSION_MS);
180
+ return void sendJson(res, 200, { authenticated: true }, { 'Set-Cookie': `${COOKIE}=${id}; HttpOnly; SameSite=Strict; Path=${WORKBENCH_UI_PATH}; Max-Age=${SESSION_MS / 1000}` });
181
+ }
182
+ }
@@ -12,6 +12,12 @@ const NS = '1agents';
12
12
  const EXT = '_1agents/';
13
13
  /** Error envelopes have a closed projection; provider data never becomes metadata. */
14
14
  function safeFailureEvent(event, trustedRuntimeErrors) {
15
+ // Process-slot admission is not a turn failure. Keep the queue position for the caller.
16
+ if (event.code === 'CAPACITY_PENDING' || event.message === 'CAPACITY_PENDING') {
17
+ const data = event.data && typeof event.data === 'object' ? event.data : {};
18
+ return { event: event.event ?? 'error', sessionId: event.sessionId, code: 'CAPACITY_PENDING',
19
+ message: 'CAPACITY_PENDING', scope: 'control', terminal: false, data: { position: data.position, waitedMs: data.waitedMs } };
20
+ }
15
21
  if (['tool_call', 'tool_call_update', 'tool_result'].includes(event.event)) {
16
22
  if (event.error === undefined && event.errorCode === undefined && event.errorText === undefined)
17
23
  return event;
@@ -134,6 +140,9 @@ export class RuntimePeer {
134
140
  }
135
141
  const failureEvent = events.find(e => (e.event === 'error' || e.type === 'error' || e.event === 'protocol_error') && e.scope !== 'turn');
136
142
  if (failureEvent) {
143
+ if (failureEvent.code === 'CAPACITY_PENDING' || failureEvent.message === 'CAPACITY_PENDING') {
144
+ throw new RequestError(-32010, 'CAPACITY_PENDING', failureEvent.data);
145
+ }
137
146
  const safe = toSafeError(failureEvent.error ?? failureEvent, { origin: 'service', operationId: payload.requestId });
138
147
  throw new RequestError(-32000, safe.message, safe);
139
148
  }
@@ -543,14 +552,16 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
543
552
  .onNotification('session/cancel', async ({ params }) => { requireSession(params.sessionId); await peer.command(backend, { action: 'cancel_turn', sessionId: params.sessionId }); })
544
553
  .onRequest('session/close', async ({ params }) => {
545
554
  requireSession(params.sessionId);
546
- await peer.command(backend, { action: 'close_session', sessionId: params.sessionId });
555
+ const events = await peer.command(backend, { action: 'close_session', sessionId: params.sessionId });
547
556
  attached.delete(params.sessionId);
548
557
  for (const [key, pending] of prompts)
549
558
  if (pending.sessionId === params.sessionId) {
550
559
  prompts.delete(key);
551
560
  pending.resolve({ stopReason: 'cancelled' });
552
561
  }
553
- return {};
562
+ // Only an observed exit with its lease gone is a release; everything else stays pending upstream.
563
+ const released = events.some(e => e.event === 'session_released' && e.sessionId === params.sessionId && e.processReleased === true);
564
+ return released ? { _meta: { [NS]: { processReleased: true } } } : {};
554
565
  })
555
566
  .onRequest('session/set_mode', async ({ params }) => { requireSession(params.sessionId); await peer.command(backend, { action: 'set_session_mode', sessionId: params.sessionId, payload: { modeId: params.modeId } }); return {}; })
556
567
  .onRequest('session/set_config_option', async ({ params }) => { requireSession(params.sessionId); await peer.command(backend, { action: 'set_config_option', sessionId: params.sessionId, payload: { key: params.configId, value: params.value } }); return { configOptions: configOptions(await backend.status(params.sessionId)) }; })
@@ -601,7 +612,20 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
601
612
  requireInitialized();
602
613
  if (!extensions || typeof params.sessionId !== 'string' || !params.sessionId)
603
614
  throw RequestError.invalidParams('Native session ID required');
604
- return ensure({ ...params, _meta: { [NS]: { ...metadata(params), resumeSessionId: params.sessionId } } }, true, false, signal);
615
+ return ensure({ ...params, _meta: { [NS]: { ...metadata(params), resumeSessionId: params.sessionId, capacityId: `import:${params.sessionId}` } } }, true, false, signal);
616
+ });
617
+ app.onRequest(`${EXT}capacity/cancel`, (value) => {
618
+ if (!value || typeof value !== 'object' || Array.isArray(value))
619
+ throw RequestError.invalidParams('Expected object');
620
+ return value;
621
+ }, async ({ params }) => {
622
+ requireInitialized();
623
+ if (!extensions)
624
+ throw RequestError.methodNotFound(`${EXT}capacity/cancel`);
625
+ if (typeof params.capacityId !== 'string' || !params.capacityId.trim() || params.capacityId.length > 4096)
626
+ throw RequestError.invalidParams('capacityId is required');
627
+ await peer.command(backend, { action: 'capacity_cancel', capacityId: params.capacityId });
628
+ return {};
605
629
  });
606
630
  const controls = { 'session/history': 'get_history', 'session/permission_mode': 'set_permission_mode', 'session/cancel_queued': 'cancel_queued', 'session/fork': 'fork_session', 'session/authenticate': 'authenticate', 'session/logout': 'logout' };
607
631
  for (const [method, action] of Object.entries(controls)) {
@@ -18,6 +18,7 @@ export const runtime: import("@1agents/acp-service/runtime").AcpxRuntime;
18
18
  export const activeSessions: Map<any, any>;
19
19
  export const sessionBackgroundTasks: Map<any, any>;
20
20
  export function gracefulExit(source: any): Promise<void>;
21
+ export function prewarmGrokSession(targetCwd: any): Promise<void>;
21
22
  export const pendingPermissions: Map<any, any>;
22
23
  export const pendingAskUserQuestions: Map<any, any>;
23
24
  export const pendingExitPlanModes: Map<any, any>;