@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
@@ -40,6 +40,7 @@ import {
40
40
  type ConnectionEvent,
41
41
  type ConnectionRefusal,
42
42
  ConnectionRefusedError,
43
+ ProtocolVersionMismatchError,
43
44
  type TransportFactory,
44
45
  } from "./connection.ts";
45
46
  import { createHistoryClient } from "./history.ts";
@@ -63,6 +64,7 @@ export {
63
64
  type ConnectionRefusal,
64
65
  ConnectionRefusedError,
65
66
  EventGapError,
67
+ ProtocolVersionMismatchError,
66
68
  type SessionEventGap,
67
69
  type TurnHandle,
68
70
  };
@@ -137,6 +139,8 @@ export class AgentServerClient {
137
139
  private readonly progress = new Listeners<HarnessCliProgress>();
138
140
  private readonly authUpdates = new Listeners<AuthUpdated>();
139
141
  private readonly streams: Streams;
142
+ /** `subscribeAll` calls whose ask no server has answered yet: across redials, the next answer settles them. */
143
+ private readonly allAsked: Array<{ resolve(): void; reject(error: unknown): void }> = [];
140
144
  /** Portable history operations (`history/*`), independent of execution subscriptions. */
141
145
  readonly history: AsyncHistoryApi;
142
146
 
@@ -144,24 +148,34 @@ export class AgentServerClient {
144
148
  factory: TransportFactory,
145
149
  private readonly options: AgentServerClientOptions,
146
150
  redials: boolean,
151
+ url?: string,
147
152
  ) {
148
- this.connection = new Connection(factory, options, redials, {
149
- line: (line, transport) => this.handleLine(line, transport),
150
- opened: (redialed) => this.streams.reconnected(redialed),
151
- serverChanged: () => this.streams.adoptFreshLogs(),
152
- reconnected: () => {
153
- this.streams.resume();
154
- this.subscribeAgain();
153
+ this.connection = new Connection(
154
+ factory,
155
+ options,
156
+ redials,
157
+ {
158
+ line: (line, transport) => this.handleLine(line, transport),
159
+ opened: (redialed) => this.streams.reconnected(redialed),
160
+ serverChanged: () => this.streams.adoptFreshLogs(),
161
+ reconnected: () => {
162
+ this.streams.resume();
163
+ this.subscribeAgain();
164
+ },
165
+ closed: (error) => {
166
+ this.turns.failAll(error);
167
+ this.answeredAll(error);
168
+ },
155
169
  },
156
- closed: (error) => this.turns.failAll(error),
157
- });
170
+ url,
171
+ );
158
172
  this.streams = new Streams(
159
173
  {
160
174
  transport: () => this.connection.transport,
161
175
  open: () => !this.connection.closed,
162
176
  replay: (sessionId, fromSeq) => this.replay(sessionId, fromSeq),
163
177
  resubscribe: (sessionId, turnId) => void this.resubscribe(sessionId, turnId),
164
- resubscribeAll: () => void this.resubscribeAll(),
178
+ resubscribeAll: () => void this.requestAll(),
165
179
  maxReplayAttempts: options.maxReplayAttempts ?? 3,
166
180
  replayRetryDelayMs: options.replayRetryDelayMs ?? options.reconnectDelayMs ?? 250,
167
181
  },
@@ -213,6 +227,7 @@ export class AgentServerClient {
213
227
  () => connectTransport(url, headers),
214
228
  options,
215
229
  options.reconnect ?? true,
230
+ url,
216
231
  );
217
232
  await client.connection.open();
218
233
  return client;
@@ -449,16 +464,32 @@ export class AgentServerClient {
449
464
  /**
450
465
  * Every session's frames, live from now, to `onEvent` (observers): no
451
466
  * history, the open parts of running turns, and after a redial, the gaps a
452
- * dropped connection left healed.
467
+ * dropped connection left healed. The client follows every session from
468
+ * the ask until `unsubscribeAll`: a connection that drops before the
469
+ * answer asks the server it redials, whose answer this waits for; it fails
470
+ * when the server refuses it or the client closes.
453
471
  */
454
472
  async subscribeAll(): Promise<void> {
455
- await this.initialize();
456
- await this.requestAll();
473
+ // @ref LLP 0008#what-requests-do-to-subscriptions — the intent is recorded at the ask, so every later server is asked
474
+ this.streams.followAll();
475
+ const answered = new Promise<void>((resolve, reject) =>
476
+ this.allAsked.push({ resolve, reject }),
477
+ );
478
+ try {
479
+ await this.initialize();
480
+ } catch (error) {
481
+ // A dropped connection: its redial asks every session (`subscribeAgain`).
482
+ if (!this.redialing(error)) this.answeredAll(error);
483
+ return answered;
484
+ }
485
+ void this.requestAll();
486
+ return answered;
457
487
  }
458
488
 
459
489
  /** Stop following every session (`subscribeAll`); those subscribed by name stay. */
460
490
  async unsubscribeAll(): Promise<boolean> {
461
491
  this.streams.unfollowAll();
492
+ this.answeredAll();
462
493
  const { unsubscribed } = await this.connection.request(WIRE_METHODS.sessionUnsubscribeAll, {});
463
494
  return unsubscribed;
464
495
  }
@@ -491,7 +522,9 @@ export class AgentServerClient {
491
522
  /**
492
523
  * The models a harness offers for the login and folder a turn with the same
493
524
  * `cwd`, `env` and `apiKey` would use. `source: "catalog"` (with `error`)
494
- * means the CLI did not answer and the list is agent-server's built-in one.
525
+ * means the CLI did not answer and the list is agent-server's built-in one,
526
+ * as it is while the harness's CLI is not installed yet: a read installs
527
+ * nothing (`prepareClis` does), and the first list after the install is live.
495
528
  */
496
529
  listModels(params: ModelsListParams): Promise<ModelList> {
497
530
  return this.connection.request(WIRE_METHODS.modelsList, params);
@@ -627,8 +660,12 @@ export class AgentServerClient {
627
660
  /**
628
661
  * Each harness's login on the server (every harness when `harnesses` is
629
662
  * absent), for the store and environment a turn with `env` would use:
630
- * signed in, with what and as whom, signed out, or unknown and why; and
631
- * the logins it offers.
663
+ * signed in, with what and as whom, signed out, or unknown and why; the
664
+ * logins it offers; and the login under way to that store
665
+ * (`loginUnderWay`), whoever started it, so a second window or a handle
666
+ * whose connection dropped finds it. A read installs nothing: a harness
667
+ * whose CLI is not installed yet is `unknown` with no methods
668
+ * (`prepareClis` installs it, as `login` does).
632
669
  */
633
670
  async authStatus(
634
671
  options: { harnesses?: AgentHarness[]; env?: Record<string, string> } = {},
@@ -642,7 +679,11 @@ export class AgentServerClient {
642
679
  * Start one of a harness's logins through its CLI's own flow: answered
643
680
  * once the CLI says where the user signs in (`url`, `userCode`, or from
644
681
  * another device `codeUrl`, then `complete` with the code it shows).
645
- * `done` resolves with the harness's login once it succeeded.
682
+ * `done` resolves with the harness's login once it succeeded. Every
683
+ * connection hears it start (`onAuthUpdated`, `auth.loginUnderWay`), and
684
+ * a newer login to the same store cancels it. It installs the harness's
685
+ * CLI first when it is not there yet, inside the 20 s the CLI has to
686
+ * start the login: on a slow network, `prepareClis` first.
646
687
  */
647
688
  async login(
648
689
  harness: AgentHarness,
@@ -683,7 +724,12 @@ export class AgentServerClient {
683
724
  return this.progress.add(handler);
684
725
  }
685
726
 
686
- /** A harness's login changed on the server, or a login ended, whoever caused it (`auth/updated`). */
727
+ /**
728
+ * A harness's login changed on the server, a login started (no `login`;
729
+ * `auth.loginUnderWay` is it), or a login ended (`login`), whoever caused
730
+ * it (`auth/updated`). Every update's `auth` carries the login then under
731
+ * way to that harness, if any.
732
+ */
687
733
  onAuthUpdated(handler: (update: AuthUpdated) => void): () => void {
688
734
  return this.authUpdates.add(handler);
689
735
  }
@@ -808,13 +854,18 @@ export class AgentServerClient {
808
854
  }
809
855
  }
810
856
 
811
- /** Every session again; refused, the client follows every session no more. */
812
- private async resubscribeAll(): Promise<void> {
813
- try {
814
- await this.requestAll();
815
- } catch (error) {
816
- if (error instanceof WireRequestError) this.streams.refusedAll(error.message);
817
- }
857
+ /** A failure a redial heals: the connection dropped and will be redialed, which subscribes again. */
858
+ private redialing(error: unknown): boolean {
859
+ return (
860
+ error instanceof ConnectionClosedError && this.connection.redials && !this.connection.closed
861
+ );
862
+ }
863
+
864
+ /** Settle the `subscribeAll` calls waiting for an answer: answered, or failed with `error`. */
865
+ private answeredAll(error?: unknown): void {
866
+ for (const waiter of this.allAsked.splice(0))
867
+ if (error === undefined) waiter.resolve();
868
+ else waiter.reject(error);
818
869
  }
819
870
 
820
871
  // @ref LLP 0008#what-requests-do-to-subscriptions — a redial subscribes the running turns first
@@ -822,14 +873,24 @@ export class AgentServerClient {
822
873
  private subscribeAgain(): void {
823
874
  for (const { sessionId, turnId } of this.streams.resubscriptions())
824
875
  void this.resubscribe(sessionId, turnId);
825
- if (this.streams.followsAll) void this.resubscribeAll();
876
+ if (this.streams.followsAll) void this.requestAll();
826
877
  }
827
878
 
828
- /** `session/subscribeAll`, sent now. */
829
- private requestAll(): Promise<unknown> {
830
- return this.connection.request(WIRE_METHODS.sessionSubscribeAll, {}, ({ sessions }) =>
831
- this.streams.joinedAll(sessions),
832
- );
879
+ /**
880
+ * `session/subscribeAll`, sent now; its answer settles the `subscribeAll`
881
+ * calls waiting. Refused, the client follows every session no more; dropped,
882
+ * the redial asks again.
883
+ */
884
+ private async requestAll(): Promise<void> {
885
+ try {
886
+ await this.connection.request(WIRE_METHODS.sessionSubscribeAll, {}, ({ sessions }) =>
887
+ this.streams.joinedAll(sessions),
888
+ );
889
+ this.answeredAll();
890
+ } catch (error) {
891
+ if (error instanceof WireRequestError) this.streams.refusedAll(error.message);
892
+ if (!this.redialing(error)) this.answeredAll(error);
893
+ }
833
894
  }
834
895
 
835
896
  /** `session/subscribe` for one session, `onAnswer` given its point the moment it arrives. */
@@ -9,6 +9,7 @@ import {
9
9
  type WireParams,
10
10
  type WireRequestMethod,
11
11
  type WireTransport,
12
+ readRefusalData,
12
13
  } from "../protocol/index.ts";
13
14
  import { Listeners } from "./listeners.ts";
14
15
  import { type OnAnswer, Rpc, WireRequestError } from "./rpc.ts";
@@ -19,10 +20,12 @@ export class ConnectionClosedError extends Error {
19
20
  }
20
21
 
21
22
  /**
22
- * Why a server refused this client, which it answers 401: the token it sent
23
- * (`token_refused`), or that it sent none (`token_required`).
23
+ * Why a server refused this client: answered 401, the token it sent
24
+ * (`token_refused`) or that it sent none (`token_required`); or, answering
25
+ * `initialize`, that it speaks another wire protocol version
26
+ * (`protocol_mismatch`, a `ProtocolVersionMismatchError`).
24
27
  */
25
- export type ConnectionRefusal = "token_refused" | "token_required";
28
+ export type ConnectionRefusal = "token_refused" | "token_required" | "protocol_mismatch";
26
29
 
27
30
  /**
28
31
  * The server answered, and refused this client (`reason`). Asked again it
@@ -33,13 +36,44 @@ export class ConnectionRefusedError extends ConnectionClosedError {
33
36
  override readonly name: string = "ConnectionRefusedError";
34
37
  constructor(
35
38
  readonly reason: ConnectionRefusal,
36
- /** The server that refused it. */
39
+ /** The server that refused it; empty for a client that dialed no URL (`spawn`, `attach`, a factory). */
37
40
  readonly url: string,
41
+ message = `agent-server at ${url} ${reason === "token_refused" ? "refused the token" : "needs a token"} (401)`,
42
+ ) {
43
+ super(message);
44
+ }
45
+ }
46
+
47
+ /**
48
+ * The server speaks another wire protocol version than this client: it
49
+ * answered `initialize` with `protocolVersionMismatch`, or selected a version
50
+ * this build does not speak. No redial can change that (only another build of
51
+ * the client or of the server), so it is a refusal: the client stops and what
52
+ * waits on it fails with this. `code` and `data` are the wire error's, as a
53
+ * `WireRequestError` would carry them.
54
+ */
55
+ export class ProtocolVersionMismatchError extends ConnectionRefusedError {
56
+ override readonly name: string = "ProtocolVersionMismatchError";
57
+ override readonly reason = "protocol_mismatch" as const;
58
+ readonly code = WIRE_ERROR_CODES.protocolVersionMismatch;
59
+ constructor(
60
+ /** The version this client speaks (`WIRE_PROTOCOL_VERSION`). */
61
+ readonly protocolVersion: number,
62
+ /** The versions the server speaks, as it said; empty when it did not say. */
63
+ readonly supported: number[],
64
+ url: string,
65
+ /** What the server said, when it refused the version itself. */
66
+ detail?: string,
38
67
  ) {
39
68
  super(
40
- `agent-server at ${url} ${reason === "token_refused" ? "refused the token" : "needs a token"} (401)`,
69
+ "protocol_mismatch",
70
+ url,
71
+ `agent-server${url ? ` at ${url}` : ""} speaks wire protocol ${supported.length ? supported.join(", ") : "another version"}, this client ${protocolVersion}${detail ? ` (${detail})` : ""}: upgrade the one that is older`,
41
72
  );
42
73
  }
74
+ get data(): { supported: number[] } {
75
+ return { supported: this.supported };
76
+ }
43
77
  }
44
78
 
45
79
  /**
@@ -67,10 +101,19 @@ export type ConnectionEvent =
67
101
  initialize: InitializeResult;
68
102
  }
69
103
  /**
70
- * A redial the server refused (`ConnectionRefusedError`): no outage, its
71
- * answer, which every redial would get. The client stops; `closed` follows.
104
+ * A server that refused the client (`ConnectionRefusedError`): no outage,
105
+ * its answer, which every redial would get. The client stops; `closed`
106
+ * follows. A refused token is told of a redial (`connect` itself rejects
107
+ * with it); another protocol version (`ProtocolVersionMismatchError`) of
108
+ * any handshake: `protocolVersion` this client's, `supported` the server's.
72
109
  */
73
- | { state: "refused"; reason: ConnectionRefusal }
110
+ | { state: "refused"; reason: "token_refused" | "token_required" }
111
+ | {
112
+ state: "refused";
113
+ reason: "protocol_mismatch";
114
+ protocolVersion: number;
115
+ supported: number[];
116
+ }
74
117
  /**
75
118
  * For good: `close()`, a dropped connection that does not redial,
76
119
  * redialing gave up, or the server refused it.
@@ -106,7 +149,7 @@ export type TransportFactory = () => Promise<WireTransport> | WireTransport;
106
149
  const MAX_RESENDS = 3;
107
150
 
108
151
  /** What the connection tells the client around it. */
109
- export interface ConnectionHost {
152
+ interface ConnectionHost {
110
153
  /** A line from the current transport. */
111
154
  line(line: string, transport: WireTransport): void;
112
155
  /** A new transport opened; `redialed`: its handshake comes next, before anything else may run. */
@@ -148,6 +191,8 @@ export class Connection {
148
191
  private readonly options: AgentServerClientOptions,
149
192
  readonly redials: boolean,
150
193
  private readonly host: ConnectionHost,
194
+ /** The URL it dials, for what a refusal says; empty when it dials none. */
195
+ private readonly url = "",
151
196
  ) {
152
197
  this.rpc = new Rpc({
153
198
  requestTimeoutMs: options.requestTimeoutMs,
@@ -180,20 +225,18 @@ export class Connection {
180
225
  transport.onClose((reason) => this.dropped(transport, reason));
181
226
  }
182
227
 
183
- /** Handshake (memoized). */
228
+ /**
229
+ * Handshake (memoized). A server of another protocol version closes the
230
+ * client for good: it rejects with `ProtocolVersionMismatchError`.
231
+ */
184
232
  initialize(): Promise<InitializeResult> {
185
233
  this.initializing ??= this.request(WIRE_METHODS.initialize, {
186
234
  protocolVersion: WIRE_PROTOCOL_VERSION,
187
235
  client: this.options.clientInfo,
188
236
  })
189
237
  .then((result) => {
190
- if (result.protocolVersion !== WIRE_PROTOCOL_VERSION) {
191
- throw new WireRequestError(
192
- WIRE_ERROR_CODES.protocolVersionMismatch,
193
- `server selected unsupported protocol version: ${result.protocolVersion}`,
194
- { supported: [WIRE_PROTOCOL_VERSION] },
195
- );
196
- }
238
+ if (result.protocolVersion !== WIRE_PROTOCOL_VERSION)
239
+ throw this.mismatched([result.protocolVersion], "it selected another");
197
240
  // The restart question, answered by the handshake instead of
198
241
  // inferred from seq patterns: a changed identity means every session
199
242
  // log the client followed died with the old process. Durable logs
@@ -204,13 +247,34 @@ export class Connection {
204
247
  this.serverIdentity = identity;
205
248
  return result;
206
249
  })
207
- .catch((error) => {
250
+ .catch((error: unknown) => {
208
251
  this.initializing = null;
252
+ if (
253
+ error instanceof WireRequestError &&
254
+ error.code === WIRE_ERROR_CODES.protocolVersionMismatch
255
+ )
256
+ throw this.mismatched(
257
+ readRefusalData(error, "protocolVersionMismatch")?.supported ?? [],
258
+ error.message,
259
+ );
209
260
  throw error;
210
261
  });
211
262
  return this.initializing;
212
263
  }
213
264
 
265
+ // @ref LLP 0001#d16--a-listener-answers-native-clients-only-and-needs-a-token-beyond-loopback — refused like a token: no redial changes it
266
+ /** The server speaks another protocol version: the client is closed by its refusal, which this returns. */
267
+ private mismatched(supported: number[], detail: string): ConnectionRefusedError {
268
+ const refusal = new ProtocolVersionMismatchError(
269
+ WIRE_PROTOCOL_VERSION,
270
+ supported,
271
+ this.url,
272
+ detail,
273
+ );
274
+ this.refused(refusal);
275
+ return this.refusal ?? refusal;
276
+ }
277
+
214
278
  /** A request, its answer read as `WIRE_API` reads the method's. */
215
279
  request<M extends WireRequestMethod>(
216
280
  method: M,
@@ -318,8 +382,8 @@ export class Connection {
318
382
  continue;
319
383
  }
320
384
  // Re-handshake: the transport may have reconnected to a DIFFERENT
321
- // process (or a different build). A version mismatch fails loudly
322
- // here instead of silently mixing dialects, and a changed identity
385
+ // process (or a different build). A version mismatch is a refusal
386
+ // (it closes the client) instead of silently mixing dialects, and a changed identity
323
387
  // adopts the fresh logs before anything is subscribed again.
324
388
  this.initializing = null;
325
389
  const initialize = await this.initialize();
@@ -369,13 +433,30 @@ export class Connection {
369
433
  transport?.close();
370
434
  }
371
435
 
372
- /** Closed for good by the server's refusal, which what waits on the connection fails with. */
436
+ /**
437
+ * Closed for good by the server's refusal, which what waits on the
438
+ * connection fails with: the requests in flight, and the transport it came
439
+ * on (a handshake's) let go.
440
+ */
373
441
  private refused(refusal: ConnectionRefusedError): void {
374
442
  if (this.closed) return;
375
443
  this.closed = true;
376
444
  this.refusal = refusal;
445
+ this.rpc.failAll(refusal);
446
+ this.discard();
447
+ this.stopBackoff?.();
377
448
  this.host.closed(refusal);
378
- this.events.emit({ state: "refused", reason: refusal.reason });
449
+ const { reason } = refusal;
450
+ this.events.emit(
451
+ reason === "protocol_mismatch"
452
+ ? {
453
+ state: "refused",
454
+ reason,
455
+ protocolVersion: WIRE_PROTOCOL_VERSION,
456
+ supported: refusal instanceof ProtocolVersionMismatchError ? refusal.supported : [],
457
+ }
458
+ : { state: "refused", reason },
459
+ );
379
460
  this.events.emit({ state: "closed", reason: refusal.message });
380
461
  }
381
462
  }
@@ -12,6 +12,7 @@ export {
12
12
  EventGapError,
13
13
  type FollowOptions,
14
14
  type JoinTurnOptions,
15
+ ProtocolVersionMismatchError,
15
16
  type SessionEventGap,
16
17
  type SessionSubscription,
17
18
  type SubscribeOptions,
@@ -30,7 +30,7 @@ export interface LoginHandle extends AuthLogin {
30
30
  }
31
31
 
32
32
  /** What a login handle asks of the client. */
33
- export interface LoginsPort {
33
+ interface LoginsPort {
34
34
  readonly updates: Listeners<AuthUpdated>;
35
35
  readonly connection: Listeners<ConnectionEvent>;
36
36
  complete(loginId: string, code: string): Promise<AuthUpdated>;
@@ -73,7 +73,7 @@ class SessionStream {
73
73
  }
74
74
 
75
75
  /** What the streams ask of the client around them. */
76
- export interface StreamsHost {
76
+ interface StreamsHost {
77
77
  /** The transport frames come on now; null between connections. */
78
78
  transport(): WireTransport | null;
79
79
  /** False once the client closed. */
@@ -101,7 +101,7 @@ export class Streams {
101
101
  /** Per-session seq discipline — the shared `/protocol` implementation. */
102
102
  private readonly cursor = createSeqCursor();
103
103
  private readonly streams = new Map<string, SessionStream>();
104
- /** Subscribed to every session (`subscribeAll`). */
104
+ /** Follows every session (`subscribeAll`): from the ask, not its answer, until `unsubscribeAll` or a refusal. */
105
105
  private all = false;
106
106
  /** A redialed transport's handshake is pending: frames wait for it to say which server this is. */
107
107
  private paused = false;
@@ -189,9 +189,17 @@ export class Streams {
189
189
  if (!this.pastTurn(sessionId)) void this.heal(sessionId);
190
190
  }
191
191
 
192
- /** Every session's frames, from now: those with a running turn start at their head. */
193
- joinedAll(sessions: Array<{ sessionId: string; headSeq: number }>): void {
192
+ /** `subscribeAll` asked: every server from now on is asked for every session, until `unfollowAll`. */
193
+ followAll(): void {
194
194
  this.all = true;
195
+ }
196
+
197
+ /**
198
+ * Every session's frames, from now: those with a running turn start at
199
+ * their head. An answer to an ask `unfollowAll` withdrew follows nothing.
200
+ */
201
+ joinedAll(sessions: Array<{ sessionId: string; headSeq: number }>): void {
202
+ if (!this.all) return;
195
203
  for (const { sessionId, headSeq } of sessions) this.joined(sessionId, headSeq, "all");
196
204
  }
197
205
 
@@ -43,7 +43,7 @@ export interface TurnHandle {
43
43
  * kept events after `headSeq` and the live frames that arrived after the
44
44
  * `position`-th frame the client received.
45
45
  */
46
- export interface JoinPoint {
46
+ interface JoinPoint {
47
47
  headSeq: number;
48
48
  position: number;
49
49
  }