@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
@@ -8,7 +8,10 @@ import { RequestError } from '@agentclientprotocol/sdk';
8
8
  import { connect, object } from './transport.js';
9
9
  import { State, hasActiveWriter } from './state.js';
10
10
  import { mergeTool } from './tool-events.js';
11
+ import { currentA2AExecution } from '@1agents/acp-service/a2a';
11
12
  import { toSafeError } from '@1agents/acp-service/runtime';
13
+ import { capacityPendingOf, noteProcessCapacity, noteProcessReady, noteSessionRestore, requestWhenAdmitted } from './process-admission.js';
14
+ import { AgentSessionSettings, pinnedModeError, pinnedOptionError, replayPinnedOptions } from './session-settings.js';
12
15
  export function validateSessionPolicies(policies = []) {
13
16
  const seen = new Set();
14
17
  if (!Array.isArray(policies))
@@ -16,7 +19,7 @@ export function validateSessionPolicies(policies = []) {
16
19
  return policies.map(policy => {
17
20
  if (!policy || typeof policy.cwd !== 'string' || !isAbsolute(policy.cwd)
18
21
  || typeof policy.agent !== 'string' || !/^[a-z0-9_-]+$/i.test(policy.agent)
19
- || !['approve-reads', 'approve-all', 'deny-all'].includes(policy.permissionMode)
22
+ || (policy.permissionMode !== undefined && !['approve-reads', 'approve-all', 'deny-all'].includes(policy.permissionMode))
20
23
  || (policy.initialModeId !== undefined && (typeof policy.initialModeId !== 'string' || !policy.initialModeId))) {
21
24
  throw new Error('Invalid workspace-scoped ACP session policy');
22
25
  }
@@ -44,6 +47,12 @@ function serviceProjection(error) {
44
47
  return data;
45
48
  }
46
49
  /** Only actual cancellation rejections may replace a racing provider failure. */
50
+ function isDeletedAcpSession(error) {
51
+ if (!error || typeof error !== 'object')
52
+ return false;
53
+ const value = error;
54
+ return value.code === -32003 || value.message === 'Session was deleted';
55
+ }
47
56
  function isCancellationRejection(error, signal) {
48
57
  if (!signal.aborted)
49
58
  return false;
@@ -85,10 +94,22 @@ class Queue {
85
94
  }
86
95
  }
87
96
  }
97
+ function acpFromProcessView(kind, view) {
98
+ const outcome = view.answer?.outcome;
99
+ const closed = view.status === 'expired' || view.status === 'cancelled' || outcome === 'cancelled' || outcome === 'abandoned';
100
+ if (kind === 'permission')
101
+ return { outcome: !closed && (outcome === 'approved' || outcome === 'rejected') ? outcome : 'cancelled' };
102
+ if (kind === 'plan')
103
+ return { outcome: !closed && (outcome === 'approved' || outcome === 'rejected') ? outcome : 'abandoned' };
104
+ if (!closed && outcome === 'accepted' && view.answer?.answers)
105
+ return { outcome: 'accepted', answers: view.answer.answers };
106
+ return { outcome: 'cancelled' };
107
+ }
88
108
  export class AcpAdapter {
89
109
  ctx;
90
110
  config;
91
111
  diagnostics;
112
+ processRequests;
92
113
  state;
93
114
  initializationFailures = new Map();
94
115
  controllers = new Map();
@@ -101,15 +122,24 @@ export class AcpAdapter {
101
122
  commandDisposers = new Map();
102
123
  output = new Map();
103
124
  lifetime = new AbortController();
104
- constructor(ctx, config, diagnostics) {
125
+ sessionSettings;
126
+ /** MCP servers offered when a session is created or restored, such as the A2A hand-back tool. */
127
+ mcpServersFor;
128
+ constructor(ctx, config, diagnostics, processRequests) {
105
129
  this.ctx = ctx;
106
130
  this.config = config;
107
131
  this.diagnostics = diagnostics;
132
+ this.processRequests = processRequests;
108
133
  this.state = new State(config.stateDirectory);
134
+ this.sessionSettings = new AgentSessionSettings(config.stateDirectory);
109
135
  }
110
136
  providerInfo(provider) { return { id: provider, name: 'ACP Agents' }; }
111
137
  providerRetryPolicy() { return { mode: 'normal', maxRetries: 0, retryableCodes: [], initialDelayMs: 1000, maxDelayMs: 1000, jitterRatio: 0 }; }
112
138
  imageRequestPricing() { return undefined; }
139
+ /** DSH 0.2.1 requires this. ACP Agents take text only, so keep the base class's untouched image target. */
140
+ imageRequestTarget(_provider, _model, image) {
141
+ return { width: image.width, height: image.height, maxBytes: image.bytes };
142
+ }
113
143
  async listModels(provider) {
114
144
  return [];
115
145
  }
@@ -162,11 +192,15 @@ export class AcpAdapter {
162
192
  const link = await this.connection(agent);
163
193
  const sessionId = this.state.get(agent.id).sessionId;
164
194
  const capabilities = this.capabilities.get(agent.id);
195
+ const name = this.agentName(agent);
196
+ const cwd = agent.session.header.cwd;
165
197
  if (configId === '$mode') {
166
198
  if (!capabilities.modes?.availableModes.some(m => m.id === value))
167
199
  throw new Error('Unknown ACP mode');
168
200
  await link.rpc.request('session/set_mode', { sessionId, modeId: value });
169
201
  capabilities.modes.currentModeId = value;
202
+ if (name && cwd)
203
+ this.sessionSettings.remember(cwd, name, { modeId: value });
170
204
  }
171
205
  else {
172
206
  const option = capabilities.configOptions.find(o => o.id === configId);
@@ -174,6 +208,8 @@ export class AcpAdapter {
174
208
  throw new Error('Unknown ACP configuration');
175
209
  const result = await link.rpc.request('session/set_config_option', { sessionId, configId, value });
176
210
  capabilities.configOptions = result.configOptions;
211
+ if (name && cwd)
212
+ this.sessionSettings.remember(cwd, name, { option: { id: configId, value, ...(option.category === 'model' || option.id === 'model' ? { model: true } : {}) } });
177
213
  }
178
214
  return capabilities;
179
215
  }
@@ -196,10 +232,18 @@ export class AcpAdapter {
196
232
  plan: async () => ({ outcome: 'abandoned' }),
197
233
  }, this.lifetime.signal);
198
234
  try {
199
- const result = object(await link.rpc.request('_1agents/session/import', {
200
- sessionId: nativeSessionId, cwd, mcpServers: [],
201
- _meta: { '1agents': { permissionMode: 'approve-reads' } },
202
- }, { cancellationSignal: AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]) }));
235
+ const capacityId = `import:${nativeSessionId}`;
236
+ const result = object(await requestWhenAdmitted({
237
+ signal: this.lifetime.signal,
238
+ isPending: capacityPendingOf,
239
+ cancel: async () => { await link.rpc.request('_1agents/capacity/cancel', { capacityId }).catch(() => undefined); },
240
+ request: () => link.rpc.request('_1agents/session/import', {
241
+ sessionId: nativeSessionId, cwd, mcpServers: [],
242
+ // Bridge permissionMode is not sent. The imported session keeps the
243
+ // Agent's own mode and config options (ACP 设置).
244
+ _meta: { '1agents': { capacityId } },
245
+ }, { cancellationSignal: AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]) }),
246
+ }));
203
247
  if (typeof result.sessionId !== 'string' || !result.sessionId)
204
248
  throw new Error('ACP import returned no service session ID');
205
249
  return { agent: name, cwd, endpoint: endpoint.href, sessionId: result.sessionId, restoreMethod: 'session/resume' };
@@ -240,9 +284,33 @@ export class AcpAdapter {
240
284
  }));
241
285
  }
242
286
  }
243
- async connection(agent) {
287
+ /** Replay this Agent's own accepted values. Another Agent's catalog is never consulted. */
288
+ async applyPinnedSettings(name, cwd, link, sessionId, capabilities, policy, cancellationSignal) {
289
+ const pinned = this.sessionSettings.get(cwd, name);
290
+ let advertised = capabilities.configOptions;
291
+ for (const option of replayPinnedOptions(pinned?.options ?? [])) {
292
+ const mismatch = pinnedOptionError(name, option, advertised);
293
+ if (mismatch)
294
+ throw new Error(mismatch);
295
+ const next = await link.rpc.request('session/set_config_option', { sessionId, configId: option.id, value: option.value }, { cancellationSignal });
296
+ advertised = next.configOptions ?? [];
297
+ capabilities.configOptions = advertised;
298
+ }
299
+ const modeId = pinned?.modeId ?? policy?.initialModeId;
300
+ if (!modeId)
301
+ return;
302
+ const mismatch = pinned?.modeId
303
+ ? pinnedModeError(name, modeId, capabilities.modes?.availableModes)
304
+ : capabilities.modes?.availableModes.some(mode => mode.id === modeId) ? undefined : 'Configured initial ACP mode is not advertised by the Agent';
305
+ if (mismatch)
306
+ throw new Error(mismatch);
307
+ await link.rpc.request('session/set_mode', { sessionId, modeId }, { cancellationSignal });
308
+ if (capabilities.modes)
309
+ capabilities.modes.currentModeId = modeId;
310
+ }
311
+ async connection(agent, capacityId, callerSignal) {
244
312
  const operation = (this.connections.get(agent.id) ?? Promise.resolve())
245
- .catch(() => undefined).then(() => this.openConnection(agent));
313
+ .catch(() => undefined).then(() => this.openConnection(agent, capacityId, callerSignal));
246
314
  this.connections.set(agent.id, operation);
247
315
  try {
248
316
  return await operation;
@@ -252,7 +320,7 @@ export class AcpAdapter {
252
320
  this.connections.delete(agent.id);
253
321
  }
254
322
  }
255
- async openConnection(agent) {
323
+ async openConnection(agent, capacityId, callerSignal) {
256
324
  const name = this.agentName(agent);
257
325
  if (!name)
258
326
  throw new Error('ACP is available only in an ACP Agent preset; start a new ACP session');
@@ -347,23 +415,36 @@ export class AcpAdapter {
347
415
  let createdBinding;
348
416
  try {
349
417
  const policy = this.config.sessionPolicies?.find(p => p.cwd === resolve(cwd) && p.agent === name);
350
- const params = { cwd, mcpServers: [], _meta: { '1agents': { permissionMode: policy?.permissionMode ?? 'approve-reads' } } };
351
- const cancellationSignal = AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]);
418
+ // Bridge permissionMode (approve-reads / approve-all / deny-all) is not
419
+ // sent. Mode and reasoning effort come from ACP 设置: session/set_mode,
420
+ // session/set_config_option, or the settings kept by a native import.
421
+ // initialModeId below still selects an advertised native mode.
422
+ const params = { cwd, mcpServers: this.mcpServersFor?.(agent.id) ?? [], ...(capacityId ? { _meta: { '1agents': { capacityId } } } : {}) };
423
+ const admit = (request) => capacityId
424
+ ? requestWhenAdmitted({
425
+ request,
426
+ signal: callerSignal ? AbortSignal.any([this.lifetime.signal, callerSignal]) : this.lifetime.signal,
427
+ isPending: capacityPendingOf,
428
+ onPending: pending => noteProcessCapacity(agent.id, pending),
429
+ cancel: async () => { await link.rpc.request('_1agents/capacity/cancel', { capacityId }).catch(() => undefined); },
430
+ })
431
+ : request();
432
+ // Queue waits return immediately. This 60s bound covers only the attempt that holds the slot.
433
+ const handshake = () => AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000), ...(callerSignal ? [callerSignal] : [])]);
434
+ const restoreMethod = binding ? binding.restoreMethod ?? 'session/load' : undefined;
352
435
  const result = binding
353
- ? await link.rpc.request(binding.restoreMethod ?? 'session/load', { ...params, sessionId: binding.sessionId }, { cancellationSignal })
354
- : await link.rpc.request('session/new', params, { cancellationSignal });
436
+ ? await admit(() => link.rpc.request(restoreMethod, { ...params, sessionId: binding.sessionId }, { cancellationSignal: handshake() }))
437
+ : await admit(() => link.rpc.request('session/new', params, { cancellationSignal: handshake() }));
438
+ if (binding && restoreMethod)
439
+ noteSessionRestore(agent.id, restoreMethod);
355
440
  if (!binding)
356
441
  createdBinding = { agent: name, endpoint: endpoint.href, cwd, sessionId: result.sessionId };
357
442
  capabilities.configOptions = result.configOptions ?? capabilities.configOptions;
358
443
  capabilities.modes = result.modes ?? undefined;
359
- // Select an advertised native mode before the first prompt. Loading an
360
- // existing session must retain its native mode and user selections.
361
- if (!binding && policy?.initialModeId) {
362
- if (!capabilities.modes?.availableModes.some(m => m.id === policy.initialModeId))
363
- throw new Error('Configured initial ACP mode is not advertised by the Agent');
364
- await link.rpc.request('session/set_mode', { sessionId: result.sessionId, modeId: policy.initialModeId }, { cancellationSignal });
365
- capabilities.modes.currentModeId = policy.initialModeId;
366
- }
444
+ // A new session replays only this Agent's accepted settings. Loading an
445
+ // existing session keeps the mode and options already on that session.
446
+ if (!binding)
447
+ await this.applyPinnedSettings(name, resolve(cwd), link, result.sessionId, capabilities, policy, handshake());
367
448
  if (createdBinding)
368
449
  this.state.save(agent.id, createdBinding);
369
450
  void link.closed.then(() => { if (this.links.get(agent.id) === operation)
@@ -371,6 +452,13 @@ export class AcpAdapter {
371
452
  return link;
372
453
  }
373
454
  catch (error) {
455
+ if (binding && isDeletedAcpSession(error)) {
456
+ link.close();
457
+ const deleted = new LlmError('Session was deleted', 'SESSION_DELETED');
458
+ // The stream catch replaces unowned errors with ACP_TURN_FAILED. Keep this code.
459
+ ownedFailures.set(deleted, toSafeError(deleted, { origin: 'acp', outcomeUnknown: false }));
460
+ throw deleted;
461
+ }
374
462
  let failure = error;
375
463
  if (createdBinding) {
376
464
  const cleanup = new AbortController();
@@ -410,6 +498,93 @@ export class AcpAdapter {
410
498
  throw error;
411
499
  }
412
500
  }
501
+ /** Ordinary ACP release. The binding, session id, and restore method stay. No session/delete. */
502
+ async releaseSession(sessionId) {
503
+ const agent = this.ctx.agents.get(sessionId);
504
+ if (!agent) {
505
+ const error = new Error('Session not found');
506
+ error.code = 'SESSION_NOT_FOUND';
507
+ throw error;
508
+ }
509
+ if (!this.agentName(agent))
510
+ return { processReleased: true, acp: false };
511
+ const binding = this.state.get(agent.id);
512
+ const pending = this.links.get(agent.id);
513
+ const link = pending ? await pending.catch(() => undefined) : undefined;
514
+ let processReleased = 'pending';
515
+ if (link && binding?.sessionId) {
516
+ try {
517
+ const result = await link.rpc.request('session/close', { sessionId: binding.sessionId }, {
518
+ cancellationSignal: AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]),
519
+ });
520
+ // The service confirms only after it saw the agent exit and its process lease disappear.
521
+ if (result?._meta?.['1agents']?.processReleased === true)
522
+ processReleased = true;
523
+ }
524
+ catch (error) {
525
+ const message = error instanceof Error ? error.message : '';
526
+ if (!/not found|Session not found|-32001/i.test(message)) {
527
+ const wrapped = new Error('Remote session close failed');
528
+ wrapped.code = 'REMOTE_UNAVAILABLE';
529
+ throw wrapped;
530
+ }
531
+ }
532
+ link.close();
533
+ if (this.links.get(agent.id) === pending)
534
+ this.links.delete(agent.id);
535
+ }
536
+ return { processReleased, acp: true };
537
+ }
538
+ /**
539
+ * Controlled delete. ACP session/delete closes the process and marks the record deleted.
540
+ * The DSH session and its history stay. A detached session gets a bare link, so no agent process starts.
541
+ */
542
+ async deleteSession(sessionId) {
543
+ const agent = this.ctx.agents.get(sessionId);
544
+ if (!agent) {
545
+ const error = new Error('Session not found');
546
+ error.code = 'SESSION_NOT_FOUND';
547
+ throw error;
548
+ }
549
+ if (!this.agentName(agent))
550
+ return { processReleased: true, acp: false };
551
+ const binding = this.state.get(agent.id);
552
+ if (!binding?.sessionId || 'initializationCleanupPending' in binding)
553
+ return { processReleased: true, acp: true };
554
+ const pending = this.links.get(agent.id);
555
+ const attached = pending ? await pending.catch(() => undefined) : undefined;
556
+ const link = attached ?? await connect(binding.endpoint, {
557
+ update: () => { },
558
+ permission: async () => ({ outcome: { outcome: 'cancelled' } }),
559
+ question: async () => ({ outcome: 'cancelled' }),
560
+ plan: async () => ({ outcome: 'abandoned' }),
561
+ }, this.lifetime.signal);
562
+ try {
563
+ await link.rpc.request('session/delete', { sessionId: binding.sessionId }, {
564
+ cancellationSignal: AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]),
565
+ });
566
+ }
567
+ catch (error) {
568
+ const message = error instanceof Error ? error.message : '';
569
+ if (!/not found|Session not found|-32001/i.test(message)) {
570
+ const wrapped = new Error('Remote session delete failed');
571
+ wrapped.code = 'REMOTE_UNAVAILABLE';
572
+ throw wrapped;
573
+ }
574
+ }
575
+ finally {
576
+ link.close();
577
+ if (attached && this.links.get(agent.id) === pending)
578
+ this.links.delete(agent.id);
579
+ }
580
+ return { processReleased: attached ? 'pending' : true, acp: true };
581
+ }
582
+ async sessionStatus(sessionId) {
583
+ const agent = this.ctx.agents.get(sessionId);
584
+ if (!agent)
585
+ return { attached: false, activeTurn: false };
586
+ return { attached: this.links.has(agent.id), activeTurn: this.controllers.has(agent.id) };
587
+ }
413
588
  async *stream(options) {
414
589
  const agent = options.sessionId ? this.ctx.agents.get(options.sessionId) : undefined;
415
590
  if (!agent || options.purpose)
@@ -438,18 +613,33 @@ export class AcpAdapter {
438
613
  const deny = params.options.find(o => o.kind === 'reject_once');
439
614
  if (!allow)
440
615
  return { outcome: { outcome: 'cancelled' } };
441
- const decision = await this.ctx.approval.request({ agent, toolName: params.toolCall.title || 'ACP tool',
442
- reason: JSON.stringify(params.toolCall.rawInput ?? params.toolCall.content ?? {}, null, 2), signal });
443
- const selected = decision === 'allowed-once' ? allow : decision === 'rejected' ? deny : undefined;
616
+ // DSH full access never asks, so its approval service would reject every ACP request. The user's switch to
617
+ // full access is the grant: allow without asking. The fold reads only an explicit sandbox/mode switch.
618
+ if (this.ctx.sessionProjections.stateOf(agent.session, 'sandboxMode') === 'danger-full-access') {
619
+ return { outcome: { outcome: 'selected', optionId: allow.optionId } };
620
+ }
621
+ const toolName = params.toolCall.title || 'ACP tool';
622
+ const reason = JSON.stringify(params.toolCall.rawInput ?? params.toolCall.content ?? {}, null, 2);
623
+ // An A2A turn also offers the approval to the workbench; the first answer wins. The tool call id keeps
624
+ // each call its own request, so an earlier approval never covers a later identical command.
625
+ const result = await this.withProcessRequest(agent, signal, { kind: 'permission', body: [params.toolCall.toolCallId, toolName, reason],
626
+ toolTitle: toolName.slice(0, 500), toolDetail: reason.slice(0, 16 * 1024),
627
+ local: async (localSignal) => {
628
+ const decision = await this.ctx.approval.request({ agent, toolName, reason, signal: localSignal });
629
+ return { outcome: decision === 'allowed-once' ? 'approved' : decision === 'rejected' ? 'rejected' : 'cancelled' };
630
+ } });
631
+ const selected = result.outcome === 'approved' ? allow : result.outcome === 'rejected' ? deny : undefined;
444
632
  return { outcome: selected ? { outcome: 'selected', optionId: selected.optionId } : { outcome: 'cancelled' } };
445
633
  }
446
- async question(agent, p, signal) {
447
- const questions = (Array.isArray(p.questions) ? p.questions : []).map((value, i) => {
634
+ questionsOf(p) {
635
+ return (Array.isArray(p.questions) ? p.questions : []).map((value, i) => {
448
636
  const q = object(value);
449
637
  return { id: String(i), question: String(q.question ?? ''), header: typeof q.header === 'string' ? q.header : undefined,
450
- options: Array.isArray(q.options) ? q.options.map(value => { const o = object(value); return { label: String(o.label), description: typeof o.description === 'string' ? o.description : undefined }; }) : undefined,
638
+ options: Array.isArray(q.options) ? q.options.map(item => { const o = object(item); return { label: String(o.label), description: typeof o.description === 'string' ? o.description : undefined }; }) : undefined,
451
639
  multiSelect: q.multiSelect === true };
452
640
  });
641
+ }
642
+ async askQuestions(agent, questions, signal) {
453
643
  try {
454
644
  const result = await this.ctx.userQuestions.ask({ agent, questions, signal });
455
645
  return { outcome: 'accepted', answers: Object.fromEntries(result.answers.map(a => [questions[Number(a.id)].question, a.custom || (a.selected.length === 1 ? a.selected[0] : a.selected)])) };
@@ -460,9 +650,9 @@ export class AcpAdapter {
460
650
  throw error;
461
651
  }
462
652
  }
463
- async plan(agent, p, signal) {
653
+ async askPlan(agent, content, signal) {
464
654
  try {
465
- const result = await this.ctx.userQuestions.ask({ agent, signal, questions: [{ id: 'plan', question: 'ACP Agent 请求执行计划', detail: String(p.planContent ?? ''), options: [{ label: '批准' }, { label: '拒绝' }], intent: { kind: 'plan-review', approve: '批准' } }] });
655
+ const result = await this.ctx.userQuestions.ask({ agent, signal, questions: [{ id: 'plan', question: 'ACP Agent 请求执行计划', detail: content, options: [{ label: '批准' }, { label: '拒绝' }], intent: { kind: 'plan-review', approve: '批准' } }] });
466
656
  return { outcome: result.answers[0]?.selected.includes('批准') ? 'approved' : 'rejected' };
467
657
  }
468
658
  catch (error) {
@@ -471,6 +661,74 @@ export class AcpAdapter {
471
661
  throw error;
472
662
  }
473
663
  }
664
+ async question(agent, p, signal) {
665
+ const questions = this.questionsOf(p);
666
+ return this.withProcessRequest(agent, signal, { kind: 'question', body: questions, questions, local: askSignal => this.askQuestions(agent, questions, askSignal) });
667
+ }
668
+ async plan(agent, p, signal) {
669
+ const planContent = String(p.planContent ?? '');
670
+ return this.withProcessRequest(agent, signal, { kind: 'plan', body: planContent, planContent, local: askSignal => this.askPlan(agent, planContent, askSignal) });
671
+ }
672
+ /** The workbench answer completes this wait. A later A2A user message does not. */
673
+ async withProcessRequest(agent, signal, spec) {
674
+ const fallback = spec.kind === 'plan' ? 'abandoned' : 'cancelled';
675
+ if (!this.processRequests)
676
+ return spec.local(signal);
677
+ const binding = currentA2AExecution(agent.id);
678
+ if (!binding)
679
+ return spec.local(signal);
680
+ const requestId = `prc-${createHash('sha256').update(JSON.stringify([binding.jobId, binding.attemptId, spec.kind, spec.body])).digest('hex').slice(0, 32)}`;
681
+ let opened;
682
+ try {
683
+ opened = await this.processRequests.open({ requestId, jobId: binding.jobId, attemptId: binding.attemptId, sessionId: agent.id, kind: spec.kind, questions: spec.questions, planContent: spec.planContent,
684
+ ...(spec.toolTitle ? { toolTitle: spec.toolTitle, toolDetail: spec.toolDetail } : {}) });
685
+ }
686
+ catch {
687
+ return spec.local(signal);
688
+ }
689
+ if (signal.aborted) {
690
+ void this.reportProcess(binding.jobId, opened.requestId, fallback, undefined, `dsh-cancel:${opened.requestId}`);
691
+ return { outcome: fallback };
692
+ }
693
+ const child = new AbortController(), waitAbort = new AbortController();
694
+ const stop = () => { child.abort(signal.reason); waitAbort.abort(signal.reason); };
695
+ signal.addEventListener('abort', stop, { once: true });
696
+ const localTask = spec.local(child.signal);
697
+ const remoteTask = this.processRequests.wait({ jobId: binding.jobId, requestId: opened.requestId, signal: AbortSignal.any([signal, waitAbort.signal]) });
698
+ void localTask.catch(() => { });
699
+ void remoteTask.catch(() => { });
700
+ try {
701
+ const winner = await Promise.race([
702
+ localTask.then(value => ({ source: 'local', value })),
703
+ remoteTask.then(value => ({ source: 'workbench', value })),
704
+ ]);
705
+ if (winner.source === 'local') {
706
+ waitAbort.abort();
707
+ const outcome = typeof winner.value.outcome === 'string' ? winner.value.outcome : fallback;
708
+ const answers = winner.value.answers;
709
+ void this.reportProcess(binding.jobId, opened.requestId, outcome, answers, outcome === 'cancelled' || outcome === 'abandoned' ? `dsh-cancel:${opened.requestId}` : `dsh-ui:${opened.requestId}`);
710
+ return winner.value;
711
+ }
712
+ child.abort();
713
+ return acpFromProcessView(spec.kind, winner.value);
714
+ }
715
+ catch (error) {
716
+ child.abort();
717
+ waitAbort.abort();
718
+ if (signal.aborted) {
719
+ void this.reportProcess(binding.jobId, opened.requestId, fallback, undefined, `dsh-cancel:${opened.requestId}`);
720
+ return { outcome: fallback };
721
+ }
722
+ void this.reportProcess(binding.jobId, opened.requestId, fallback, undefined, `dsh-cancel:${opened.requestId}`);
723
+ throw error;
724
+ }
725
+ finally {
726
+ signal.removeEventListener('abort', stop);
727
+ }
728
+ }
729
+ reportProcess(jobId, requestId, outcome, answers, clientRequestId) {
730
+ return this.processRequests.report({ jobId, requestId, clientRequestId: clientRequestId ?? `dsh-ui:${requestId}`, outcome, ...(answers ? { answers } : {}) }).catch(() => { });
731
+ }
474
732
  async run(agent, options, signal, queue) {
475
733
  const cwd = agent.session.header.cwd;
476
734
  if (!cwd)
@@ -596,7 +854,16 @@ export class AcpAdapter {
596
854
  signal.throwIfAborted();
597
855
  try {
598
856
  this.output.set(agent.id, update);
599
- active = await this.connection(agent);
857
+ const capacityId = input.flatMap(message => message.role === 'user' && message.source?.kind === 'user' && 'rpcId' in message.source
858
+ && typeof message.source.rpcId === 'string' && message.source.rpcId.startsWith('a2a-') ? [message.source.rpcId] : [])[0];
859
+ try {
860
+ active = await this.connection(agent, capacityId, signal);
861
+ noteProcessReady(agent.id);
862
+ }
863
+ catch (error) {
864
+ noteProcessCapacity(agent.id, undefined);
865
+ throw error;
866
+ }
600
867
  binding = this.state.get(agent.id);
601
868
  signal.throwIfAborted();
602
869
  if (diagnosticId)
@@ -53,14 +53,14 @@ ${item.newText}` }];
53
53
  if (content.length || tool.rawOutput == null) return content;
54
54
  return [{ type: "text", text: typeof tool.rawOutput === "string" ? tool.rawOutput : JSON.stringify(tool.rawOutput, null, 2) }];
55
55
  }
56
- function rootOf(state, location) {
56
+ function rootOf(state, location2) {
57
57
  const { tool, requestId, turn, step } = state.data;
58
58
  const name = tool.name && tool.name !== "Tool" ? tool.name : names[tool.kind] ?? tool.title ?? tool.name ?? "Tool";
59
59
  const input = tool.rawInput ?? (tool.locations?.[0]?.path ? { path: tool.locations[0].path } : tool.title ? { description: tool.title } : {});
60
60
  const argsRaw = JSON.stringify(input);
61
61
  const head = { callId: `${requestId}:${tool.toolCallId}`, name, argsRaw, turn, step, time: state.time, subCalls: [] };
62
62
  const settled = tool.status === "completed" || tool.status === "failed";
63
- const closed = location?.kind === "step" && location.step.status === "closed" ? location.step.end : (location?.kind === "step" || location?.kind === "turn") && location.turn.status === "closed" ? location.turn.end : void 0;
63
+ const closed = location2?.kind === "step" && location2.step.status === "closed" ? location2.step.end : (location2?.kind === "step" || location2?.kind === "turn") && location2.turn.status === "closed" ? location2.turn.end : void 0;
64
64
  if (!settled && !closed) return { ...head, phase: "start" };
65
65
  return {
66
66
  kind: "tool-result",
@@ -137,10 +137,10 @@ var toolConversationDefinition = {
137
137
  buildViewNode: (context) => {
138
138
  const state = context.state;
139
139
  if (!state?.acp) return null;
140
- const location = context.start?.location ?? context.matches[0]?.location ?? { kind: "unresolved" };
140
+ const location2 = context.start?.location ?? context.matches[0]?.location ?? { kind: "unresolved" };
141
141
  const parts = [];
142
142
  for (const [index, block] of [...state.blocks].sort(([a], [b]) => a - b)) {
143
- if (block.kind === "tool") parts.push({ kind: "tool", root: rootOf(state.tools.get(block.id), location) });
143
+ if (block.kind === "tool") parts.push({ kind: "tool", root: rootOf(state.tools.get(block.id), location2) });
144
144
  else if (block.text.trim()) {
145
145
  const last = parts.at(-1);
146
146
  if (last?.kind === block.kind) last.text += block.text;
@@ -148,7 +148,7 @@ var toolConversationDefinition = {
148
148
  }
149
149
  }
150
150
  if (!parts.length) return null;
151
- const status = state.final ? "settled" : location.kind === "step" && location.step.status === "closed" ? "interrupted" : "running";
151
+ const status = state.final ? "settled" : location2.kind === "step" && location2.step.status === "closed" ? "interrupted" : "running";
152
152
  const turn = context.matches[0].event.data.turn, step = context.matches[0].event.data.step;
153
153
  const text = parts.filter((part) => part.kind === "text").map((part) => part.text).join("\n");
154
154
  const blocks = [{ kind: "text", text: text || parts.filter((part) => part.kind === "tool").map((part) => part.root.name ?? part.root.call.name).join(", ") || "ACP" }];
@@ -158,7 +158,7 @@ var toolConversationDefinition = {
158
158
  kind: "assistant-step",
159
159
  target: "chat",
160
160
  anchorSeq: state.seq,
161
- location,
161
+ location: location2,
162
162
  visibility: "visible",
163
163
  data: {
164
164
  status,
@@ -264,10 +264,11 @@ function installTranscriptView(ctx) {
264
264
  }
265
265
 
266
266
  // src/client.js
267
- var inject = ["slots", "sessions", "commandUi", "remote", "remote.session", "locale", "uiConversation", "conversation"];
267
+ var inject = ["slots", "sessions", "commandUi", "remote", "remote.session", "locale", "uiConversation", "conversation", "uiWorkspace"];
268
+ var WORKBENCH_PANEL = "oneagents-a2a-workbench";
268
269
  var dictionaries = {
269
- zh: { toolGroup: "\u5DF2\u8C03\u7528 {count} \u4E2A\u5DE5\u5177", model: "\u6A21\u578B", choose: "\u9009\u62E9\u6A21\u578B", loading: "\u6B63\u5728\u8FDE\u63A5 Agent\u2026", loadingModels: "\u6B63\u5728\u52A0\u8F7D\u6A21\u578B\u2026", retry: "\u91CD\u8BD5", mode: "\u6A21\u5F0F", command: "Agent \u6307\u4EE4", effort: "\u601D\u8003\u5F3A\u5EA6", unsupported: "Agent \u672A\u63D0\u4F9B\u53EF\u5207\u6362\u7684\u6A21\u578B", description: "\u9009\u62E9\u5F53\u524D Agent \u7684\u6A21\u578B", error: "\u8FDE\u63A5\u5931\u8D25", noCommands: "Agent \u5C1A\u672A\u63D0\u4F9B\u6307\u4EE4", native: "ACP \u8BBE\u7F6E", activeWriter: "\u539F\u4F1A\u8BDD\u6B63\u5728\u5176\u4ED6\u5BA2\u6237\u7AEF\u8FD0\u884C\uFF0C\u53EF\u67E5\u770B\u5386\u53F2\uFF1B\u5360\u7528\u89E3\u9664\u540E\u81EA\u52A8\u6062\u590D\u8F93\u5165\u3002" },
270
- en: { toolGroup: "{count} tool calls", model: "Model", choose: "Select model", loading: "Connecting to Agent\u2026", loadingModels: "Loading models\u2026", retry: "Retry", mode: "Mode", command: "Agent commands", effort: "Reasoning effort", unsupported: "This Agent does not advertise model selection", description: "Select this Agent\u2019s model", error: "Connection failed", noCommands: "No commands advertised", native: "ACP settings", activeWriter: "The original session is running in another client. History is available; input resumes when it is released." }
270
+ zh: { toolGroup: "\u5DF2\u8C03\u7528 {count} \u4E2A\u5DE5\u5177", model: "\u6A21\u578B", choose: "\u9009\u62E9\u6A21\u578B", loading: "\u6B63\u5728\u8FDE\u63A5 Agent\u2026", loadingModels: "\u6B63\u5728\u52A0\u8F7D\u6A21\u578B\u2026", retry: "\u91CD\u8BD5", mode: "\u6A21\u5F0F", command: "Agent \u6307\u4EE4", effort: "\u601D\u8003\u5F3A\u5EA6", unsupported: "Agent \u672A\u63D0\u4F9B\u53EF\u5207\u6362\u7684\u6A21\u578B", description: "\u9009\u62E9\u5F53\u524D Agent \u7684\u6A21\u578B", error: "\u8FDE\u63A5\u5931\u8D25", noCommands: "Agent \u5C1A\u672A\u63D0\u4F9B\u6307\u4EE4", native: "ACP \u8BBE\u7F6E", activeWriter: "\u539F\u4F1A\u8BDD\u6B63\u5728\u5176\u4ED6\u5BA2\u6237\u7AEF\u8FD0\u884C\uFF0C\u53EF\u67E5\u770B\u5386\u53F2\uFF1B\u5360\u7528\u89E3\u9664\u540E\u81EA\u52A8\u6062\u590D\u8F93\u5165\u3002", workbench: "A2A \u5DE5\u4F5C\u53F0", a2aRunning: "A2A \u4EFB\u52A1\u6B63\u5728\u6B64\u4F1A\u8BDD\u6267\u884C\uFF0C\u7ED3\u675F\u540E\u53EF\u4EBA\u5DE5\u63A5\u7BA1\u3002" },
271
+ en: { toolGroup: "{count} tool calls", model: "Model", choose: "Select model", loading: "Connecting to Agent\u2026", loadingModels: "Loading models\u2026", retry: "Retry", mode: "Mode", command: "Agent commands", effort: "Reasoning effort", unsupported: "This Agent does not advertise model selection", description: "Select this Agent\u2019s model", error: "Connection failed", noCommands: "No commands advertised", native: "ACP settings", activeWriter: "The original session is running in another client. History is available; input resumes when it is released.", workbench: "A2A Workbench", a2aRunning: "An A2A task is running in this session; you can take over once it ends." }
271
272
  };
272
273
  function choices(option) {
273
274
  return (option.options ?? []).flatMap((item) => "group" in item ? item.options.map((value) => ({ ...value, group: item.name ?? item.group })) : [item]);
@@ -317,12 +318,26 @@ function apply(ctx) {
317
318
  return selected;
318
319
  };
319
320
  const isAcp = (id) => String(presetOf(id) ?? "").startsWith("oneagents-acp-");
320
- const block = (id, reason) => {
321
- if (disposed || !reason && !blockedSessions.has(id)) return;
321
+ const acpBlocks = /* @__PURE__ */ new Map();
322
+ const a2aBlocks = /* @__PURE__ */ new Map();
323
+ const applyBlock = (id) => {
324
+ const reason = acpBlocks.get(id) ?? a2aBlocks.get(id);
322
325
  if (reason) blockedSessions.add(id);
323
326
  else blockedSessions.delete(id);
324
327
  ctx.conversation.blocks.set(id, reason ? { reason } : void 0);
325
328
  };
329
+ const block = (id, reason) => {
330
+ if (disposed || !reason && !blockedSessions.has(id)) return;
331
+ if (reason) acpBlocks.set(id, reason);
332
+ else acpBlocks.delete(id);
333
+ applyBlock(id);
334
+ };
335
+ const blockA2A = (id, reason) => {
336
+ if (disposed || reason === a2aBlocks.get(id)) return;
337
+ if (reason) a2aBlocks.set(id, reason);
338
+ else a2aBlocks.delete(id);
339
+ applyBlock(id);
340
+ };
326
341
  const notify = (id) => {
327
342
  for (const fn of listeners.get(id) ?? []) fn();
328
343
  };
@@ -446,6 +461,24 @@ function apply(ctx) {
446
461
  }, 5e3);
447
462
  return () => clearInterval(timer);
448
463
  }, [external, sessionId, presetId]);
464
+ (0, import_react2.useEffect)(() => {
465
+ let live = true, timer;
466
+ const check = () => fetch(`/workbench/ui/api/dsh/sessions/${encodeURIComponent(sessionId)}`, { credentials: "same-origin" }).then((response) => response.ok ? response.json() : void 0).then((value) => {
467
+ if (!live) return;
468
+ const task = value?.task;
469
+ blockA2A(sessionId, task?.running ? t("a2aRunning") : void 0);
470
+ if (task && timer === void 0) timer = setInterval(() => {
471
+ if (document.visibilityState === "visible") void check();
472
+ }, 5e3);
473
+ }, () => {
474
+ });
475
+ void check();
476
+ return () => {
477
+ live = false;
478
+ if (timer !== void 0) clearInterval(timer);
479
+ blockA2A(sessionId, void 0);
480
+ };
481
+ }, [sessionId]);
449
482
  const change = async (action) => {
450
483
  const operation = ++changeSequence.current;
451
484
  const revision = revisionOf(sessionId);
@@ -491,6 +524,29 @@ function apply(ctx) {
491
524
  return (0, import_react2.createElement)("div", { "data-oneagents-acp-controls": external ? "acp" : "dsh", style: { display: "flex", alignItems: "center", flexWrap: "wrap", gap: 8 } }, controls);
492
525
  }
493
526
  ctx.slots.inject("conversation.input.model", () => ctx.slots.register({ name: "conversation.input.model", inject: (sessionId) => ({ sessionId }) }, ModelControls));
527
+ function WorkbenchPanel() {
528
+ const frame = (0, import_react2.useRef)(null);
529
+ (0, import_react2.useEffect)(() => {
530
+ const onMessage = (event) => {
531
+ if (event.origin !== location.origin || event.source !== frame.current?.contentWindow) return;
532
+ const { type, sessionId } = event.data ?? {};
533
+ if (type === "1agents:open-session" && typeof sessionId === "string" && sessionId) ctx.uiWorkspace.openSession(sessionId);
534
+ };
535
+ window.addEventListener("message", onMessage);
536
+ return () => window.removeEventListener("message", onMessage);
537
+ }, []);
538
+ return (0, import_react2.createElement)("iframe", { ref: frame, src: "/workbench/ui/", title: t("workbench"), style: { display: "block", width: "100%", height: "100%", border: 0 } });
539
+ }
540
+ function WorkbenchIcon({ size }) {
541
+ return (0, import_react2.createElement)(
542
+ "svg",
543
+ { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.75, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true },
544
+ (0, import_react2.createElement)("rect", { x: 3, y: 4, width: 18, height: 16, rx: 2 }),
545
+ (0, import_react2.createElement)("path", { d: "M9 4v16M13 9h5M13 13h5" })
546
+ );
547
+ }
548
+ ctx.slots.inject("main", () => ctx.slots.register({ name: "main", key: WORKBENCH_PANEL }, WorkbenchPanel));
549
+ ctx.slots.inject("sidebar.panellist", () => ctx.slots.register({ name: "sidebar.panellist", id: WORKBENCH_PANEL, order: 20, label: () => t("workbench") }, WorkbenchIcon));
494
550
  ctx.effect(() => ctx.commandUi.register({
495
551
  name: "model",
496
552
  description: () => t("description"),