@zvada/agent-server 0.3.22 → 0.3.23

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 (348) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/dist/types/accounts/chatgpt.d.ts +1 -1
  3. package/dist/types/accounts/chatgpt.d.ts.map +1 -1
  4. package/dist/types/accounts/http.d.ts +2 -4
  5. package/dist/types/accounts/http.d.ts.map +1 -1
  6. package/dist/types/client/client.d.ts +37 -11
  7. package/dist/types/client/client.d.ts.map +1 -1
  8. package/dist/types/client/connection.d.ts +64 -13
  9. package/dist/types/client/connection.d.ts.map +1 -1
  10. package/dist/types/client/index.d.ts +1 -1
  11. package/dist/types/client/index.d.ts.map +1 -1
  12. package/dist/types/client/logins.d.ts +2 -1
  13. package/dist/types/client/logins.d.ts.map +1 -1
  14. package/dist/types/client/streams.d.ts +9 -3
  15. package/dist/types/client/streams.d.ts.map +1 -1
  16. package/dist/types/client/turns.d.ts +1 -1
  17. package/dist/types/client/turns.d.ts.map +1 -1
  18. package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
  19. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  20. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  21. package/dist/types/core/agents/acp/client.d.ts +12 -3
  22. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  23. package/dist/types/core/agents/acp/mappings.d.ts +8 -2
  24. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  25. package/dist/types/core/agents/base.d.ts +22 -8
  26. package/dist/types/core/agents/base.d.ts.map +1 -1
  27. package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
  28. package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
  29. package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
  30. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  31. package/dist/types/core/agents/claude-code/claude-agent.d.ts +16 -5
  32. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  33. package/dist/types/core/agents/claude-code/events.d.ts +9 -1
  34. package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
  35. package/dist/types/core/agents/claude-code/login.d.ts +4 -1
  36. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  37. package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
  38. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  39. package/dist/types/core/agents/claude-code/models.d.ts +5 -1
  40. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  41. package/dist/types/core/agents/claude-code/options.d.ts +10 -4
  42. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  43. package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
  44. package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
  45. package/dist/types/core/agents/claude-code/results.d.ts +16 -0
  46. package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
  47. package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
  48. package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
  49. package/dist/types/core/agents/claude-code/session.d.ts +50 -12
  50. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  51. package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
  52. package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
  53. package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
  54. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  55. package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
  56. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  57. package/dist/types/core/agents/codex-app-server/client.d.ts +12 -2
  58. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  59. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +58 -13
  60. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  61. package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
  62. package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
  63. package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
  64. package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
  65. package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
  66. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  67. package/dist/types/core/agents/codex-app-server/homes.d.ts +19 -0
  68. package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
  69. package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
  70. package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
  71. package/dist/types/core/agents/codex-app-server/login.d.ts +4 -1
  72. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  73. package/dist/types/core/agents/codex-app-server/mcp.d.ts +15 -30
  74. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  75. package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
  76. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  77. package/dist/types/core/agents/codex-app-server/options.d.ts +27 -4
  78. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  79. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
  80. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
  81. package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
  82. package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
  83. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  84. package/dist/types/core/agents/codex-app-server/session.d.ts +68 -40
  85. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  86. package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
  87. package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
  88. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
  89. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  90. package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
  91. package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
  92. package/dist/types/core/agents/codex-app-server/turn.d.ts +31 -8
  93. package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
  94. package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
  95. package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
  96. package/dist/types/core/agents/credentials.d.ts +3 -1
  97. package/dist/types/core/agents/credentials.d.ts.map +1 -1
  98. package/dist/types/core/agents/diffs.d.ts +9 -0
  99. package/dist/types/core/agents/diffs.d.ts.map +1 -0
  100. package/dist/types/core/agents/elicitation.d.ts +3 -2
  101. package/dist/types/core/agents/elicitation.d.ts.map +1 -1
  102. package/dist/types/core/agents/login.d.ts +6 -0
  103. package/dist/types/core/agents/login.d.ts.map +1 -1
  104. package/dist/types/core/agents/mcp-config.d.ts +0 -4
  105. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  106. package/dist/types/core/agents/process-pool.d.ts +193 -0
  107. package/dist/types/core/agents/process-pool.d.ts.map +1 -0
  108. package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
  109. package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
  110. package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
  111. package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
  112. package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
  113. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
  114. package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
  115. package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
  116. package/dist/types/core/agents/scripted/steps.d.ts +132 -0
  117. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
  118. package/dist/types/core/agents/session-agent.d.ts +49 -6
  119. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  120. package/dist/types/core/diagnostics.d.ts +4 -1
  121. package/dist/types/core/diagnostics.d.ts.map +1 -1
  122. package/dist/types/core/index.d.ts +5 -0
  123. package/dist/types/core/index.d.ts.map +1 -1
  124. package/dist/types/core/presets.d.ts +32 -6
  125. package/dist/types/core/presets.d.ts.map +1 -1
  126. package/dist/types/core/processes/lifeline.d.ts +0 -20
  127. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  128. package/dist/types/core/provision/index.d.ts +2 -2
  129. package/dist/types/core/provision/index.d.ts.map +1 -1
  130. package/dist/types/core/provision/install-build.d.ts +2 -1
  131. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  132. package/dist/types/core/provision/npm.d.ts +20 -8
  133. package/dist/types/core/provision/npm.d.ts.map +1 -1
  134. package/dist/types/core/provision/provisioner.d.ts +4 -1
  135. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  136. package/dist/types/core/provision/tools.d.ts +2 -1
  137. package/dist/types/core/provision/tools.d.ts.map +1 -1
  138. package/dist/types/core/runtime/agent-runtime.d.ts +16 -8
  139. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  140. package/dist/types/core/runtime/event-processor.d.ts +5 -1
  141. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  142. package/dist/types/core/runtime/harness-clis.d.ts +9 -0
  143. package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
  144. package/dist/types/core/runtime/harness-logins.d.ts +33 -5
  145. package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
  146. package/dist/types/core/runtime/model-lists.d.ts +2 -0
  147. package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
  148. package/dist/types/core/runtime/permission-policy.d.ts +5 -3
  149. package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
  150. package/dist/types/core/runtime/request-broker.d.ts +2 -1
  151. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  152. package/dist/types/core/runtime/turn.d.ts +12 -1
  153. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  154. package/dist/types/core/utils/deadline.d.ts +6 -0
  155. package/dist/types/core/utils/deadline.d.ts.map +1 -1
  156. package/dist/types/core/utils/errors.d.ts +7 -1
  157. package/dist/types/core/utils/errors.d.ts.map +1 -1
  158. package/dist/types/operator/operator.d.ts.map +1 -1
  159. package/dist/types/operator/render.d.ts +6 -4
  160. package/dist/types/operator/render.d.ts.map +1 -1
  161. package/dist/types/protocol/auth.d.ts +54 -24
  162. package/dist/types/protocol/auth.d.ts.map +1 -1
  163. package/dist/types/protocol/clis.d.ts +14 -7
  164. package/dist/types/protocol/clis.d.ts.map +1 -1
  165. package/dist/types/protocol/config.d.ts +2 -0
  166. package/dist/types/protocol/config.d.ts.map +1 -1
  167. package/dist/types/protocol/conversation.d.ts +40 -3
  168. package/dist/types/protocol/conversation.d.ts.map +1 -1
  169. package/dist/types/protocol/credentials.d.ts +7 -0
  170. package/dist/types/protocol/credentials.d.ts.map +1 -1
  171. package/dist/types/protocol/execution.d.ts +2 -1
  172. package/dist/types/protocol/execution.d.ts.map +1 -1
  173. package/dist/types/protocol/factories.d.ts +12 -2
  174. package/dist/types/protocol/factories.d.ts.map +1 -1
  175. package/dist/types/protocol/harness.d.ts +6 -2
  176. package/dist/types/protocol/harness.d.ts.map +1 -1
  177. package/dist/types/protocol/history.d.ts +19 -0
  178. package/dist/types/protocol/history.d.ts.map +1 -1
  179. package/dist/types/protocol/lifecycle.d.ts +47 -8
  180. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  181. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  182. package/dist/types/protocol/models.d.ts +3 -0
  183. package/dist/types/protocol/models.d.ts.map +1 -1
  184. package/dist/types/protocol/parts.d.ts +14 -0
  185. package/dist/types/protocol/parts.d.ts.map +1 -1
  186. package/dist/types/protocol/tool-state.d.ts +12 -0
  187. package/dist/types/protocol/tool-state.d.ts.map +1 -1
  188. package/dist/types/protocol/wire-api.d.ts +129 -23
  189. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  190. package/dist/types/protocol/wire.d.ts +70 -10
  191. package/dist/types/protocol/wire.d.ts.map +1 -1
  192. package/dist/types/server/acp/binding.d.ts +6 -1
  193. package/dist/types/server/acp/binding.d.ts.map +1 -1
  194. package/dist/types/server/acp/translate.d.ts +33 -7
  195. package/dist/types/server/acp/translate.d.ts.map +1 -1
  196. package/dist/types/server/agent-server.d.ts +6 -0
  197. package/dist/types/server/agent-server.d.ts.map +1 -1
  198. package/dist/types/server/feedback.d.ts +2 -1
  199. package/dist/types/server/feedback.d.ts.map +1 -1
  200. package/dist/types/server/install.d.ts +11 -0
  201. package/dist/types/server/install.d.ts.map +1 -1
  202. package/dist/types/server/session-gate.d.ts +2 -1
  203. package/dist/types/server/session-gate.d.ts.map +1 -1
  204. package/dist/types/server/session-store.d.ts +1 -0
  205. package/dist/types/server/session-store.d.ts.map +1 -1
  206. package/dist/types/server/subscriptions.d.ts +2 -1
  207. package/dist/types/server/subscriptions.d.ts.map +1 -1
  208. package/dist/types/server/transports.d.ts.map +1 -1
  209. package/dist/types/sync/fit.d.ts +8 -7
  210. package/dist/types/sync/fit.d.ts.map +1 -1
  211. package/dist/types/sync/history-sqlite.d.ts.map +1 -1
  212. package/dist/types/sync/index.d.ts +1 -0
  213. package/dist/types/sync/index.d.ts.map +1 -1
  214. package/dist/types/sync/journal-sqlite.d.ts +2 -1
  215. package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
  216. package/dist/types/sync/journal.d.ts +11 -3
  217. package/dist/types/sync/journal.d.ts.map +1 -1
  218. package/dist/types/sync/projection.d.ts +6 -0
  219. package/dist/types/sync/projection.d.ts.map +1 -1
  220. package/dist/types/sync/recovery.d.ts +2 -1
  221. package/dist/types/sync/recovery.d.ts.map +1 -1
  222. package/dist/types/sync/schema.d.ts +10 -0
  223. package/dist/types/sync/schema.d.ts.map +1 -1
  224. package/dist/types/sync/sql.d.ts +2 -1
  225. package/dist/types/sync/sql.d.ts.map +1 -1
  226. package/docs/consuming.md +278 -28
  227. package/docs/deploy.md +36 -8
  228. package/docs/durable-sessions.md +35 -5
  229. package/docs/harnesses.md +385 -24
  230. package/package.json +6 -1
  231. package/src/accounts/chatgpt.ts +2 -2
  232. package/src/accounts/http.ts +2 -16
  233. package/src/client/client.ts +92 -31
  234. package/src/client/connection.ts +103 -22
  235. package/src/client/index.ts +1 -0
  236. package/src/client/logins.ts +1 -1
  237. package/src/client/streams.ts +12 -4
  238. package/src/client/turns.ts +1 -1
  239. package/src/core/agents/acp/acp-agent.ts +181 -52
  240. package/src/core/agents/acp/adapter.ts +9 -1
  241. package/src/core/agents/acp/client.ts +16 -4
  242. package/src/core/agents/acp/mappings.ts +27 -0
  243. package/src/core/agents/base.ts +25 -10
  244. package/src/core/agents/claude-code/adapter.ts +47 -17
  245. package/src/core/agents/claude-code/approvals.ts +6 -5
  246. package/src/core/agents/claude-code/claude-agent.ts +60 -30
  247. package/src/core/agents/claude-code/events.ts +11 -1
  248. package/src/core/agents/claude-code/login.ts +14 -2
  249. package/src/core/agents/claude-code/mcp.ts +31 -15
  250. package/src/core/agents/claude-code/models.ts +7 -2
  251. package/src/core/agents/claude-code/options.ts +11 -3
  252. package/src/core/agents/claude-code/outcome.ts +10 -2
  253. package/src/core/agents/claude-code/results.ts +73 -0
  254. package/src/core/agents/claude-code/sdk-pair.ts +66 -0
  255. package/src/core/agents/claude-code/session.ts +166 -37
  256. package/src/core/agents/claude-code/spend.ts +1 -1
  257. package/src/core/agents/claude-code/tools.ts +108 -12
  258. package/src/core/agents/codex-app-server/adapter.ts +37 -12
  259. package/src/core/agents/codex-app-server/client.ts +37 -8
  260. package/src/core/agents/codex-app-server/codex-agent.ts +115 -50
  261. package/src/core/agents/codex-app-server/commands.ts +2 -2
  262. package/src/core/agents/codex-app-server/credentials.ts +10 -5
  263. package/src/core/agents/codex-app-server/effort.ts +1 -1
  264. package/src/core/agents/codex-app-server/homes.ts +43 -1
  265. package/src/core/agents/codex-app-server/items.ts +219 -31
  266. package/src/core/agents/codex-app-server/login.ts +14 -2
  267. package/src/core/agents/codex-app-server/mcp.ts +47 -32
  268. package/src/core/agents/codex-app-server/models.ts +9 -8
  269. package/src/core/agents/codex-app-server/options.ts +69 -10
  270. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  271. package/src/core/agents/codex-app-server/protocol.ts +14 -4
  272. package/src/core/agents/codex-app-server/requests.ts +14 -6
  273. package/src/core/agents/codex-app-server/session.ts +151 -113
  274. package/src/core/agents/codex-app-server/subagents.ts +21 -14
  275. package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
  276. package/src/core/agents/codex-app-server/turn-items.ts +1 -1
  277. package/src/core/agents/codex-app-server/turn.ts +79 -32
  278. package/src/core/agents/codex-app-server/user-login.ts +107 -0
  279. package/src/core/agents/credentials.ts +5 -2
  280. package/src/core/agents/diffs.ts +25 -0
  281. package/src/core/agents/elicitation.ts +2 -2
  282. package/src/core/agents/login.ts +6 -0
  283. package/src/core/agents/mcp-config.ts +2 -2
  284. package/src/core/agents/process-pool.ts +432 -0
  285. package/src/core/agents/scripted/adapter.ts +142 -0
  286. package/src/core/agents/scripted/mcp-call.ts +134 -0
  287. package/src/core/agents/scripted/scripted-agent.ts +418 -0
  288. package/src/core/agents/scripted/scripts.ts +171 -0
  289. package/src/core/agents/scripted/steps.ts +127 -0
  290. package/src/core/agents/session-agent.ts +105 -8
  291. package/src/core/diagnostics.ts +9 -1
  292. package/src/core/index.ts +11 -0
  293. package/src/core/presets.ts +99 -14
  294. package/src/core/processes/lifeline.ts +99 -25
  295. package/src/core/provision/index.ts +1 -2
  296. package/src/core/provision/install-build.ts +4 -1
  297. package/src/core/provision/npm.ts +309 -97
  298. package/src/core/provision/provisioner.ts +22 -8
  299. package/src/core/provision/tools.ts +44 -19
  300. package/src/core/runtime/agent-runtime.ts +48 -18
  301. package/src/core/runtime/event-processor.ts +18 -2
  302. package/src/core/runtime/harness-clis.ts +36 -1
  303. package/src/core/runtime/harness-logins.ts +82 -31
  304. package/src/core/runtime/model-lists.ts +1 -1
  305. package/src/core/runtime/permission-policy.ts +4 -3
  306. package/src/core/runtime/request-broker.ts +1 -1
  307. package/src/core/runtime/turn.ts +51 -3
  308. package/src/core/utils/deadline.ts +23 -0
  309. package/src/core/utils/errors.ts +11 -4
  310. package/src/operator/operator.ts +8 -4
  311. package/src/operator/render.ts +46 -8
  312. package/src/protocol/auth.ts +30 -23
  313. package/src/protocol/clis.ts +12 -4
  314. package/src/protocol/credentials.ts +19 -0
  315. package/src/protocol/execution.ts +5 -0
  316. package/src/protocol/factories.ts +25 -3
  317. package/src/protocol/harness.ts +11 -1
  318. package/src/protocol/history.ts +20 -0
  319. package/src/protocol/lifecycle.ts +10 -1
  320. package/src/protocol/model-catalog.ts +19 -8
  321. package/src/protocol/parts.ts +12 -1
  322. package/src/protocol/tool-state.ts +14 -1
  323. package/src/protocol/wire.ts +14 -0
  324. package/src/server/acp/binding.ts +113 -23
  325. package/src/server/acp/translate.ts +161 -8
  326. package/src/server/agent-server.ts +10 -1
  327. package/src/server/bin.ts +83 -9
  328. package/src/server/feedback.ts +1 -1
  329. package/src/server/install.ts +82 -4
  330. package/src/server/session-gate.ts +1 -1
  331. package/src/server/session-store.ts +5 -1
  332. package/src/server/subscriptions.ts +1 -1
  333. package/src/server/transports.ts +14 -0
  334. package/src/sync/fit.ts +115 -28
  335. package/src/sync/history-sqlite.ts +6 -2
  336. package/src/sync/index.ts +1 -0
  337. package/src/sync/journal-sqlite.ts +20 -2
  338. package/src/sync/journal.ts +10 -2
  339. package/src/sync/projection.ts +10 -0
  340. package/src/sync/recovery.ts +11 -4
  341. package/src/sync/schema.ts +7 -5
  342. package/src/sync/sql.ts +1 -1
  343. package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
  344. package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
  345. package/dist/types/core/agents/session-pool.d.ts +0 -41
  346. package/dist/types/core/agents/session-pool.d.ts.map +0 -1
  347. package/src/core/agents/claude-code/session-pool.ts +0 -136
  348. package/src/core/agents/session-pool.ts +0 -111
@@ -35,21 +35,21 @@ export const GENERATED_MODEL_CATALOG: {
35
35
  },
36
36
  },
37
37
  {
38
- id: "fable",
38
+ id: "sonnet",
39
39
  harness: "claude-code",
40
- label: "Fable 5.1",
41
- description: "For your toughest challenges",
42
- resolvedId: "claude-fable-5-1",
40
+ label: "Sonnet 5.5",
41
+ description: "Most efficient for simpler tasks",
42
+ resolvedId: "claude-sonnet-5-5",
43
43
  thinking: {
44
44
  levels: ["low", "medium", "high", "xhigh", "max"],
45
45
  },
46
46
  },
47
47
  {
48
- id: "sonnet",
48
+ id: "fable",
49
49
  harness: "claude-code",
50
- label: "Sonnet 5.5",
51
- description: "Most efficient for simpler tasks",
52
- resolvedId: "claude-sonnet-5-5",
50
+ label: "Fable 5.1",
51
+ description: "Most capable for your hardest and longest-running tasks",
52
+ resolvedId: "claude-fable-5-1",
53
53
  thinking: {
54
54
  levels: ["low", "medium", "high", "xhigh", "max"],
55
55
  },
@@ -150,6 +150,17 @@ export const GENERATED_MODEL_CATALOG: {
150
150
  },
151
151
  images: true,
152
152
  },
153
+ {
154
+ id: "gpt-6.1-terra",
155
+ harness: "codex-app-server",
156
+ label: "GPT-6.1 Terra",
157
+ description: "GPT-6.1 Terra Codex model.",
158
+ thinking: {
159
+ levels: ["low", "medium", "high", "xhigh", "max", "ultra"],
160
+ default: "low",
161
+ },
162
+ images: true,
163
+ },
153
164
  {
154
165
  id: "gpt-6-sol",
155
166
  harness: "codex-app-server",
@@ -2,7 +2,12 @@ import { z } from "zod";
2
2
  import { isKnownPartType } from "./guards.ts";
3
3
  import { MetaSchema } from "./meta.ts";
4
4
  import { OpenTimeSpanSchema } from "./time.ts";
5
- import { ToolKindSchema, ToolLocationSchema, ToolStateSchema } from "./tool-state.ts";
5
+ import {
6
+ McpToolSchema,
7
+ ToolKindSchema,
8
+ ToolLocationSchema,
9
+ ToolStateSchema,
10
+ } from "./tool-state.ts";
6
11
 
7
12
  /**
8
13
  * A Part is the atomic unit of message content, normalized across harnesses.
@@ -71,8 +76,14 @@ export const ToolPartSchema = PartBase.extend({
71
76
  toolName: z.string(),
72
77
  /** Normalized classification of what the call does (ACP ToolKind + `task`). */
73
78
  kind: ToolKindSchema.optional(),
79
+ /** A call to an MCP tool: its server and tool, when the harness knows both. `toolName` stays the harness's own. */
80
+ mcp: McpToolSchema.optional(),
74
81
  /** Human-readable label when the harness provides one. */
75
82
  title: z.string().optional(),
83
+ /** A command's line as the agent wrote it, apart from any wrapper the harness adds. `state.input` stays the harness's own. */
84
+ command: z.string().optional(),
85
+ /** A fetch's address. */
86
+ url: z.string().optional(),
76
87
  /** Files this call touches, for follow-along UIs. */
77
88
  locations: z.array(ToolLocationSchema).optional(),
78
89
  /** Present when this tool spawned a subagent (implies kind "task"). */
@@ -60,6 +60,17 @@ export const ToolLocationSchema = z.object({
60
60
  });
61
61
  export type ToolLocation = z.infer<typeof ToolLocationSchema>;
62
62
 
63
+ /**
64
+ * The MCP server and tool a call is to, as names, on every harness that
65
+ * knows both: what a product reads instead of each harness's spelling of
66
+ * `toolName` (`mcp__docs__search` on Claude, `docs.search` on Codex).
67
+ */
68
+ export const McpToolSchema = z.object({
69
+ server: z.string(),
70
+ tool: z.string(),
71
+ });
72
+ export type McpTool = z.infer<typeof McpToolSchema>;
73
+
63
74
  /**
64
75
  * Structured, display-grade tool output. Three-audience doctrine:
65
76
  * `ToolStateCompleted.output` (string) is the MODEL-facing factual record and
@@ -116,7 +127,7 @@ export const ToolStateCompletedSchema = z.object({
116
127
  output: z.string(),
117
128
  /** Display-grade structured output, when expressible (diffs, images, terminals). */
118
129
  content: z.array(ToolResultContentSchema).optional(),
119
- /** Machine channel: harness-native extras (e.g. `exitCode`). */
130
+ /** Machine channel: harness-native extras (a command's `exitCode`, …). */
120
131
  metadata: z.record(z.string(), z.unknown()).optional(),
121
132
  title: z.string().optional(),
122
133
  time: TimeSpanSchema,
@@ -141,6 +152,8 @@ export const ToolStateFailedSchema = z.object({
141
152
  error: z.string(),
142
153
  /** Set when the engine closed the tool, absent when the harness reported the failure. */
143
154
  closure: ToolClosureSchema.optional(),
155
+ /** Machine channel, as on a completed tool: a failed command's `exitCode`. */
156
+ metadata: z.record(z.string(), z.unknown()).optional(),
144
157
  time: TimeSpanSchema,
145
158
  _meta: MetaSchema,
146
159
  });
@@ -480,6 +480,18 @@ export const RECOVERY_REASONS = ["not_owned", "not_verified", "not_stopped"] as
480
480
  export const RecoveryReasonSchema = z.enum(RECOVERY_REASONS);
481
481
  export type RecoveryReason = z.infer<typeof RecoveryReasonSchema>;
482
482
 
483
+ /**
484
+ * A session's latest turn: `stopReason` and `error` as its `turn.ended` said,
485
+ * both absent while it runs. One a restart cut off ended `error`, category
486
+ * `server_restart`.
487
+ */
488
+ export const LastTurnSchema = TurnEndedEventSchema.pick({
489
+ turnId: true,
490
+ stopReason: true,
491
+ error: true,
492
+ }).partial({ stopReason: true });
493
+ export type LastTurn = z.infer<typeof LastTurnSchema>;
494
+
483
495
  export const DurableSessionSchema = z.object({
484
496
  sessionId: z.string(),
485
497
  harness: AgentHarnessSchema,
@@ -494,6 +506,8 @@ export const DurableSessionSchema = z.object({
494
506
  recoveryRequired: z.boolean(),
495
507
  /** Why, while `recoveryRequired` is set. */
496
508
  recoveryReason: RecoveryReasonSchema.optional(),
509
+ /** Its latest turn, once it has admitted one (`session/get` only). */
510
+ lastTurn: LastTurnSchema.optional(),
497
511
  });
498
512
  export type DurableSession = z.infer<typeof DurableSessionSchema>;
499
513
 
@@ -1,18 +1,28 @@
1
1
  import { Readable, Writable } from "node:stream";
2
- import type { AgentApp, AgentConnection } from "@agentclientprotocol/sdk";
2
+ import type {
3
+ AgentApp,
4
+ AgentConnection,
5
+ ElicitationCapabilities,
6
+ McpCapabilities,
7
+ McpServer,
8
+ } from "@agentclientprotocol/sdk";
3
9
  import type { AgentRuntime, EventSink } from "../../core/index.ts";
4
10
  import { generateUUIDv7 } from "../../core/index.ts";
5
11
  import type {
6
12
  AgentHarness,
13
+ ElicitationOutcome,
7
14
  LifecycleEvent,
8
15
  PermissionMode,
9
16
  PermissionOutcome,
17
+ ThinkingLevel,
10
18
  } from "../../protocol/index.ts";
11
19
  import { SessionRecords } from "./session-records.ts";
12
20
  import {
13
21
  AcpUpdateTranslator,
22
+ fromAcpElicitation,
14
23
  fromAcpMcpServers,
15
24
  fromPromptBlocks,
25
+ toAcpElicitation,
16
26
  toAcpPermissionRequest,
17
27
  toAcpPromptResponse,
18
28
  } from "./translate.ts";
@@ -24,7 +34,12 @@ export interface AcpBindingOptions {
24
34
  runtime: AgentRuntime;
25
35
  /** The harness this ACP agent fronts (operator-chosen at launch). */
26
36
  harness: AgentHarness;
37
+ /**
38
+ * The model and thinking level every turn runs at: the operator's, never an
39
+ * ACP client's. Absent: the harness's own default.
40
+ */
27
41
  model?: string;
42
+ thinkingLevel?: ThinkingLevel;
28
43
  /** Defaults to `default` so tool approvals flow to the ACP client. */
29
44
  permissionMode?: PermissionMode;
30
45
  name?: string;
@@ -45,6 +60,19 @@ interface BoundSession {
45
60
  permissionMode: PermissionMode;
46
61
  }
47
62
 
63
+ /**
64
+ * The MCP transports beside stdio the fronted harness attaches, as the
65
+ * binding advertises them. The `acp` harness has none: the agent behind it
66
+ * decides what it takes, and this binding cannot ask.
67
+ */
68
+ const MCP_TRANSPORTS: Partial<Record<AgentHarness, McpCapabilities>> = {
69
+ "claude-code": { http: true, sse: true },
70
+ // Codex takes Streamable HTTP, never legacy SSE.
71
+ "codex-app-server": { http: true },
72
+ // Its `call` step speaks HTTP alone.
73
+ scripted: { http: true },
74
+ };
75
+
48
76
  /** What each permission mode is called in an ACP client's mode picker. */
49
77
  const MODE_NAMES: Record<PermissionMode, string> = {
50
78
  default: "Default",
@@ -69,19 +97,34 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
69
97
  const acp = await import("@agentclientprotocol/sdk");
70
98
  const { runtime, harness } = options;
71
99
  const sessions = new Map<string, BoundSession>();
72
- const checkMcpSupport = (servers: readonly unknown[] | undefined): void => {
73
- if (harness === "codex-app-server" && servers?.length) {
74
- // ACP supplies MCP entries, and this binding does not pass them on to
75
- // Codex: it names no CODEX_HOME for the session, and whether a session
76
- // may run in the operator's own home is not ACP's to say (LLP 0001, D21).
100
+ /** A session's MCP servers as the engine takes them, or the request refused. */
101
+ const mcpServersOf = (servers: McpServer[] | undefined) => {
102
+ try {
103
+ const taken = fromAcpMcpServers(servers);
104
+ // @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — what Codex cannot attach is refused at admission
105
+ // A Codex turn that names no home carries its servers in its thread,
106
+ // so they pass on; what Codex would fail the turn over is refused here.
107
+ if (harness === "codex-app-server")
108
+ for (const [name, server] of Object.entries(taken ?? {})) {
109
+ if (server.type === "sse")
110
+ throw new Error(
111
+ `MCP server "${name}" uses the sse transport, which Codex does not attach (it takes stdio and http)`,
112
+ );
113
+ if (name === "codex_apps")
114
+ throw new Error("MCP server name codex_apps is reserved by Codex");
115
+ }
116
+ return taken;
117
+ } catch (error) {
77
118
  throw acp.RequestError.invalidParams(
78
119
  undefined,
79
- "Codex MCP is not supported by this ACP binding; use the engine or JSON-RPC API with a session-specific env.CODEX_HOME",
120
+ error instanceof Error ? error.message : String(error),
80
121
  );
81
122
  }
82
123
  };
83
124
 
84
125
  const records = new SessionRecords(options.sessionDir, harness);
126
+ /** What the client said at `initialize` it can ask the person: none until it says. */
127
+ let elicitation: ElicitationCapabilities | null | undefined;
85
128
 
86
129
  const requireSession = (sessionId: string): BoundSession => {
87
130
  const session = sessions.get(sessionId);
@@ -101,30 +144,33 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
101
144
 
102
145
  return acp
103
146
  .agent({ name: options.name ?? "agent-server" })
104
- .onRequest("initialize", (ctx) => ({
105
- protocolVersion: Math.min(ctx.params.protocolVersion, PROTOCOL_VERSION),
106
- agentInfo: { name: options.name ?? "agent-server", version: options.version ?? "0.0.0" },
107
- agentCapabilities: {
108
- promptCapabilities: { image: true },
109
- // Clients send HTTP/SSE servers only to agents that advertise them.
110
- ...(harness === "claude-code" && { mcpCapabilities: { http: true, sse: true } }),
111
- sessionCapabilities: { resume: {}, close: {} },
112
- },
113
- authMethods: [],
114
- }))
147
+ .onRequest("initialize", (ctx) => {
148
+ elicitation = ctx.params.clientCapabilities?.elicitation;
149
+ return {
150
+ protocolVersion: Math.min(ctx.params.protocolVersion, PROTOCOL_VERSION),
151
+ agentInfo: { name: options.name ?? "agent-server", version: options.version ?? "0.0.0" },
152
+ agentCapabilities: {
153
+ promptCapabilities: { image: true },
154
+ // Clients send HTTP/SSE servers only to agents that advertise them.
155
+ ...(MCP_TRANSPORTS[harness] && { mcpCapabilities: MCP_TRANSPORTS[harness] }),
156
+ sessionCapabilities: { resume: {}, close: {} },
157
+ },
158
+ authMethods: [],
159
+ };
160
+ })
115
161
  .onRequest("session/new", (ctx) => {
116
- checkMcpSupport(ctx.params.mcpServers);
162
+ const mcpServers = mcpServersOf(ctx.params.mcpServers);
117
163
  const sessionId = generateUUIDv7();
118
164
  const session: BoundSession = {
119
165
  cwd: ctx.params.cwd,
120
- mcpServers: fromAcpMcpServers(ctx.params.mcpServers),
166
+ mcpServers,
121
167
  permissionMode: startMode,
122
168
  };
123
169
  sessions.set(sessionId, session);
124
170
  return { sessionId, modes: modes(session) };
125
171
  })
126
172
  .onRequest("session/resume", async (ctx) => {
127
- checkMcpSupport(ctx.params.mcpServers);
173
+ const mcpServers = mcpServersOf(ctx.params.mcpServers);
128
174
  let session = sessions.get(ctx.params.sessionId);
129
175
  if (!session) {
130
176
  const resumeSessionId = await records.recall(ctx.params.sessionId);
@@ -133,7 +179,7 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
133
179
  sessions.set(ctx.params.sessionId, session);
134
180
  }
135
181
  session.cwd = ctx.params.cwd;
136
- if (ctx.params.mcpServers) session.mcpServers = fromAcpMcpServers(ctx.params.mcpServers);
182
+ if (ctx.params.mcpServers) session.mcpServers = mcpServers;
137
183
  return { modes: modes(session) };
138
184
  })
139
185
  .onRequest("session/set_mode", (ctx) => {
@@ -158,6 +204,8 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
158
204
  .onRequest("session/prompt", async (ctx) => {
159
205
  const session = requireSession(ctx.params.sessionId);
160
206
  const translator = new AcpUpdateTranslator();
207
+ /** The questions asked of the client and not yet answered, by request id. */
208
+ const asked = new Map<string, AbortController>();
161
209
  const sink: EventSink = {
162
210
  emit: async (event: LifecycleEvent) => {
163
211
  if (event.type === "permission.requested") {
@@ -175,6 +223,39 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
175
223
  runtime.respondPermission(ctx.params.sessionId, event.requestId, outcome);
176
224
  return;
177
225
  }
226
+ if (event.type === "elicitation.requested") {
227
+ // Asked of the client in a mode it said it takes; any other is declined.
228
+ const request = toAcpElicitation(ctx.params.sessionId, event, elicitation);
229
+ if (!request) {
230
+ runtime.respondElicitation(ctx.params.sessionId, event.requestId, {
231
+ action: "decline",
232
+ });
233
+ return;
234
+ }
235
+ // Sent in order, its answer not awaited here: the person may take
236
+ // as long as they like, and the turn's cancel and end must not
237
+ // wait behind them.
238
+ const abort = new AbortController();
239
+ asked.set(event.requestId, abort);
240
+ // Answered by other means first (a cancel, the turn's end): a reply is too late.
241
+ const open = () => asked.get(event.requestId) === abort;
242
+ void ctx.client
243
+ .request("elicitation/create", request, { cancellationSignal: abort.signal })
244
+ .then((response) => (open() ? fromAcpElicitation(event, response) : undefined))
245
+ // A failed request, or a reply that does not read, is a cancel.
246
+ .catch((): ElicitationOutcome => ({ action: "cancel" }))
247
+ .then((outcome) => {
248
+ if (!outcome || !open()) return;
249
+ asked.delete(event.requestId);
250
+ runtime.respondElicitation(ctx.params.sessionId, event.requestId, outcome);
251
+ });
252
+ return;
253
+ }
254
+ if (event.type === "elicitation.resolved") {
255
+ // The broker answered it without the client: the question is withdrawn.
256
+ asked.get(event.requestId)?.abort();
257
+ asked.delete(event.requestId);
258
+ }
178
259
  if (event.type === "session.mode") {
179
260
  // The agent switched modes (an approved plan, or Claude planning by
180
261
  // itself): the session goes on in it, and the client hears so.
@@ -195,7 +276,7 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
195
276
  }
196
277
  },
197
278
  };
198
- const summary = await runtime.run(
279
+ const run = runtime.run(
199
280
  {
200
281
  sessionId: ctx.params.sessionId,
201
282
  turnId: generateUUIDv7(),
@@ -204,13 +285,22 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
204
285
  harness,
205
286
  cwd: session.cwd,
206
287
  model: options.model,
288
+ thinkingLevel: options.thinkingLevel,
207
289
  permissionMode: session.permissionMode,
290
+ // A client that takes a form or a URL is asked what it takes; any
291
+ // other request is declined (`toAcpElicitation`).
292
+ elicitation: Boolean(elicitation?.form || elicitation?.url),
208
293
  mcpServers: session.mcpServers,
209
294
  resumeSessionId: session.resumeSessionId,
210
295
  },
211
296
  },
212
297
  sink,
213
298
  );
299
+ // The turn's end answers every question still open; none outlives it.
300
+ const summary = await run.finally(() => {
301
+ for (const abort of asked.values()) abort.abort();
302
+ asked.clear();
303
+ });
214
304
  if (summary.nativeSessionId) {
215
305
  session.resumeSessionId = undefined;
216
306
  await records.remember(ctx.params.sessionId, summary.nativeSessionId);
@@ -1,6 +1,12 @@
1
1
  import type {
2
2
  ToolKind as AcpToolKind,
3
3
  ContentBlock,
4
+ CreateElicitationRequest,
5
+ CreateElicitationResponse,
6
+ ElicitationCapabilities,
7
+ ElicitationPropertySchema,
8
+ ElicitationSchema,
9
+ EnumOption,
4
10
  McpServer,
5
11
  PermissionOption,
6
12
  PermissionOptionKind,
@@ -8,9 +14,13 @@ import type {
8
14
  RequestPermissionRequest,
9
15
  SessionUpdate,
10
16
  StopReason,
17
+ ToolCallContent,
11
18
  } from "@agentclientprotocol/sdk";
12
19
  import type { RunSummary } from "../../core/index.ts";
13
20
  import {
21
+ type ElicitationOutcome,
22
+ type ElicitationQuestion,
23
+ type ElicitationRequestedEvent,
14
24
  type LifecycleEvent,
15
25
  META_KEYS,
16
26
  type McpServerConfig,
@@ -19,6 +29,7 @@ import {
19
29
  type TokenUsage,
20
30
  type ToolKind,
21
31
  type ToolPart,
32
+ type ToolResultContent,
22
33
  } from "../../protocol/index.ts";
23
34
 
24
35
  /** ACP v1's ToolKind set: ours without `task` and the extensions. */
@@ -64,7 +75,7 @@ function isAcpOption(option: { kind: string }): option is PermissionOption {
64
75
  }
65
76
 
66
77
  /** The engine's disjoint token buckets as ACP's (still unstable) turn usage. */
67
- export function toAcpUsage(usage: TokenUsage): NonNullable<PromptResponse["usage"]> {
78
+ function toAcpUsage(usage: TokenUsage): NonNullable<PromptResponse["usage"]> {
68
79
  const read = usage.cache?.read ?? 0;
69
80
  const write = usage.cache?.write ?? 0;
70
81
  return {
@@ -104,7 +115,9 @@ export function toAcpPromptResponse(
104
115
  /**
105
116
  * A brokered permission request as ACP's `session/request_permission`: the
106
117
  * option vocabulary is ACP's, so the options pass through (one of a kind ACP
107
- * cannot carry is not offered, never read as an approval).
118
+ * cannot carry is not offered, never read as an approval). The call's name
119
+ * and locations ride ACP's own fields; its command, address, reason and MCP
120
+ * identity have none.
108
121
  */
109
122
  export function toAcpPermissionRequest(
110
123
  sessionId: string,
@@ -116,14 +129,108 @@ export function toAcpPermissionRequest(
116
129
  toolCall: {
117
130
  toolCallId: call?.toolCallId ?? event.requestId,
118
131
  title: event.title,
132
+ ...(call && { name: call.toolName }),
119
133
  status: "pending",
120
134
  ...(call?.kind && { kind: toAcpToolKind(call.kind) }),
135
+ ...(call?.locations?.length && { locations: call.locations }),
121
136
  ...(call?.rawInput && { rawInput: call.rawInput }),
122
137
  },
123
138
  options: event.options.filter(isAcpOption),
124
139
  };
125
140
  }
126
141
 
142
+ // @ref LLP 0001#d12--what-the-agent-asks-the-user-is-first-class-protocol-opted-into-per-turn — a question reaches an ACP client as a form
143
+ /**
144
+ * A request for the person's input as ACP's `elicitation/create`, or
145
+ * `undefined` when the client cannot take it. ACP v1 has a form and a URL
146
+ * mode and no question mode, so the agent's own questions are a form, one
147
+ * required field per question: its choices a single or multiple select, a
148
+ * free answer (or one beside the choices) a string. ACP has no masked
149
+ * field, so a `secret` question is an ordinary one.
150
+ */
151
+ export function toAcpElicitation(
152
+ sessionId: string,
153
+ event: ElicitationRequestedEvent,
154
+ client: ElicitationCapabilities | null | undefined,
155
+ ): CreateElicitationRequest | undefined {
156
+ const scope = {
157
+ sessionId,
158
+ ...(event.toolCallId && { toolCallId: event.toolCallId }),
159
+ message: event.message,
160
+ };
161
+ if (event.mode === "question" && client?.form && event.questions?.length)
162
+ return {
163
+ ...scope,
164
+ mode: "form",
165
+ requestedSchema: {
166
+ type: "object",
167
+ properties: Object.fromEntries(event.questions.map((q) => [q.id, questionField(q)])),
168
+ required: event.questions.map((q) => q.id),
169
+ },
170
+ };
171
+ if (event.mode === "form" && client?.form && event.requestedSchema)
172
+ return {
173
+ ...scope,
174
+ mode: "form",
175
+ // An MCP server's schema, which ACP's form mode takes as MCP defines it.
176
+ requestedSchema: event.requestedSchema as ElicitationSchema,
177
+ };
178
+ if (event.mode === "url" && client?.url && event.url && event.elicitationId)
179
+ return { ...scope, mode: "url", url: event.url, elicitationId: event.elicitationId };
180
+ return undefined;
181
+ }
182
+
183
+ /** One question as a form field. */
184
+ function questionField(question: ElicitationQuestion): ElicitationPropertySchema {
185
+ const label = {
186
+ title: question.header ?? question.question,
187
+ ...(question.header && { description: question.question }),
188
+ };
189
+ const choices = question.options?.map(
190
+ (option): EnumOption => ({
191
+ const: option.label,
192
+ title: option.label,
193
+ ...(option.description && { description: option.description }),
194
+ }),
195
+ );
196
+ // Words of the person's own beside the choices: a string, the choices named.
197
+ if (!choices?.length || question.allowOther)
198
+ return {
199
+ type: "string",
200
+ ...label,
201
+ ...(choices?.length && {
202
+ description: `${question.question} (${choices.map((c) => c.const).join(", ")}, or your own words)`,
203
+ }),
204
+ };
205
+ if (question.multiSelect) return { type: "array", ...label, items: { anyOf: choices } };
206
+ return { type: "string", ...label, oneOf: choices };
207
+ }
208
+
209
+ /**
210
+ * The client's answer as the engine's outcome: a question's answers are each
211
+ * an array (a form's single value becomes one), a form's content passes as
212
+ * it is, and an action ACP may add later is a cancel.
213
+ */
214
+ export function fromAcpElicitation(
215
+ event: ElicitationRequestedEvent,
216
+ response: CreateElicitationResponse,
217
+ ): ElicitationOutcome {
218
+ if (response.action === "decline") return { action: "decline" };
219
+ if (response.action !== "accept") return { action: "cancel" };
220
+ const content = (response as { content?: Record<string, unknown> | null }).content;
221
+ if (!content) return { action: "accept" };
222
+ if (event.mode !== "question") return { action: "accept", content };
223
+ return {
224
+ action: "accept",
225
+ content: Object.fromEntries(
226
+ Object.entries(content).map(([id, value]) => [
227
+ id,
228
+ Array.isArray(value) ? value.map(String) : [String(value)],
229
+ ]),
230
+ ),
231
+ };
232
+ }
233
+
127
234
  /**
128
235
  * Per-prompt translator from the engine's LifecycleEvents to ACP v1
129
236
  * `session/update` payloads — the exact inverse of the acp harness adapter
@@ -256,18 +363,43 @@ export class AcpUpdateTranslator {
256
363
  : part.state.status === "completed"
257
364
  ? part.state.output
258
365
  : undefined;
366
+ const content: ToolCallContent[] = [
367
+ ...(output
368
+ ? [{ type: "content" as const, content: { type: "text" as const, text: output } }]
369
+ : []),
370
+ ...toAcpDiffs(part.state.status === "completed" ? part.state.content : undefined),
371
+ ];
259
372
  updates.push({
260
373
  sessionUpdate: "tool_call_update",
261
374
  toolCallId: part.toolCallId,
262
375
  status,
263
- ...(output && {
264
- content: [{ type: "content", content: { type: "text", text: output } }],
265
- }),
376
+ ...(content.length && { content }),
266
377
  });
267
378
  return updates;
268
379
  }
269
380
  }
270
381
 
382
+ // @ref LLP 0002#tool-output-has-three-audiences — a part's diffs reach an ACP client as ACP diffs
383
+ /**
384
+ * A part's `diff` entries as ACP's, which a client draws. A `terminal`
385
+ * names a terminal of the agent's, which no client of ours can show, so it
386
+ * is not sent; text is the part's output.
387
+ */
388
+ function toAcpDiffs(content: ToolResultContent[] | undefined): ToolCallContent[] {
389
+ return (content ?? []).flatMap((item): ToolCallContent[] =>
390
+ item.type === "diff"
391
+ ? [
392
+ {
393
+ type: "diff",
394
+ path: item.path,
395
+ ...(item.oldText !== undefined && { oldText: item.oldText }),
396
+ newText: item.newText,
397
+ },
398
+ ]
399
+ : [],
400
+ );
401
+ }
402
+
271
403
  function chunk(
272
404
  kind: "agent_message_chunk" | "agent_thought_chunk",
273
405
  text: string,
@@ -276,11 +408,21 @@ function chunk(
276
408
  return { sessionUpdate: kind, content: { type: "text", text }, messageId };
277
409
  }
278
410
 
279
- /** ACP prompt content → engine input (text + base64 images; the rest is dropped). */
411
+ /**
412
+ * ACP prompt content → engine input: text, base64 images, and a resource
413
+ * link as a Markdown link in the text, which ACP v1 has every agent take (a
414
+ * client's @-mention of a file) and any harness's agent can follow. Audio
415
+ * and embedded resources, which the binding does not advertise, are dropped.
416
+ */
280
417
  export function fromPromptBlocks(prompt: ContentBlock[]): string | PartInput[] {
281
418
  const parts: PartInput[] = [];
282
419
  for (const block of prompt) {
283
420
  if (block.type === "text" && block.text) parts.push({ type: "text", text: block.text });
421
+ else if (block.type === "resource_link")
422
+ parts.push({
423
+ type: "text",
424
+ text: block.name && block.name !== block.uri ? `[${block.name}](${block.uri})` : block.uri,
425
+ });
284
426
  else if (block.type === "image" && block.data) {
285
427
  parts.push({ type: "image", data: block.data, mimeType: block.mimeType });
286
428
  }
@@ -289,13 +431,18 @@ export function fromPromptBlocks(prompt: ContentBlock[]): string | PartInput[] {
289
431
  return parts.length ? parts : "";
290
432
  }
291
433
 
292
- /** ACP `McpServer[]` → engine MCP config map (inverse of the harness-side mapping). */
434
+ /**
435
+ * ACP `McpServer[]` → engine MCP config map (inverse of the harness-side
436
+ * mapping). A server of another transport throws, naming it: ACP v1 lets a
437
+ * client send one only to an agent that advertised it, says nothing of what
438
+ * an agent does with one it did not, and a session without a server it
439
+ * asked for must not run as if it had it.
440
+ */
293
441
  export function fromAcpMcpServers(
294
442
  servers: McpServer[] | undefined,
295
443
  ): Record<string, McpServerConfig> | undefined {
296
444
  if (!servers?.length) return undefined;
297
445
  const out: Record<string, McpServerConfig> = {};
298
- // Note: the SDK's `type: "acp"` nested-agent variant is silently dropped.
299
446
  for (const server of servers) {
300
447
  if ("command" in server) {
301
448
  out[server.name] = {
@@ -310,6 +457,12 @@ export function fromAcpMcpServers(
310
457
  url: server.url,
311
458
  headers: Object.fromEntries((server.headers ?? []).map((h) => [h.name, h.value])),
312
459
  };
460
+ } else {
461
+ // The SDK's `acp` transport (MCP over the ACP channel, unstable) or one newer still.
462
+ const transport = (server as { type?: unknown }).type;
463
+ throw new Error(
464
+ `MCP server "${server.name}" uses the ${String(transport)} transport, which agent-server cannot attach (it takes stdio, http and sse)`,
465
+ );
313
466
  }
314
467
  }
315
468
  return Object.keys(out).length ? out : undefined;
@@ -134,7 +134,7 @@ export class AgentServer {
134
134
  this.store = journal ?? new MemorySessionStore(options.bufferSize);
135
135
  this.subscriptions = new Subscriptions({
136
136
  maxSubscriptions: options.maxSubscriptions ?? DEFAULT_MAX_SUBSCRIPTIONS,
137
- maxBacklogBytes: options.maxBacklogBytes ?? DEFAULT_MAX_BACKLOG_BYTES,
137
+ maxBacklogBytes: this.maxBacklogBytes,
138
138
  });
139
139
  // Each native process a session's turn starts is in the journal before it gets work.
140
140
  this.unrecord = journal
@@ -179,6 +179,15 @@ export class AgentServer {
179
179
  };
180
180
  }
181
181
 
182
+ /**
183
+ * How far behind a connection may fall before it is sent `session/overflow`
184
+ * (`AgentServerOptions.maxBacklogBytes`): `listen` keeps its socket's own
185
+ * limit above it, so the notice is never the frame the socket drops.
186
+ */
187
+ get maxBacklogBytes(): number {
188
+ return this.options.maxBacklogBytes ?? DEFAULT_MAX_BACKLOG_BYTES;
189
+ }
190
+
182
191
  /** Serve the wire on a transport; returns a detach function, which drops its subscriptions. */
183
192
  attach(transport: WireTransport): () => void {
184
193
  this.subscriptions.attach(transport);