@zvada/agent-server 0.3.17 → 0.3.19

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 (578) hide show
  1. package/AGENTS.md +11 -26
  2. package/CHANGELOG.md +1060 -0
  3. package/README.md +50 -26
  4. package/dist/types/accounts/chatgpt.d.ts +34 -0
  5. package/dist/types/accounts/chatgpt.d.ts.map +1 -0
  6. package/dist/types/accounts/check.d.ts +24 -0
  7. package/dist/types/accounts/check.d.ts.map +1 -0
  8. package/dist/types/accounts/claude.d.ts +21 -0
  9. package/dist/types/accounts/claude.d.ts.map +1 -0
  10. package/dist/types/accounts/endpoint.d.ts +50 -0
  11. package/dist/types/accounts/endpoint.d.ts.map +1 -0
  12. package/dist/types/accounts/http.d.ts +38 -0
  13. package/dist/types/accounts/http.d.ts.map +1 -0
  14. package/dist/types/accounts/index.d.ts +6 -0
  15. package/dist/types/accounts/index.d.ts.map +1 -0
  16. package/dist/types/client/client.d.ts +272 -0
  17. package/dist/types/client/client.d.ts.map +1 -0
  18. package/dist/types/client/connection.d.ts +160 -0
  19. package/dist/types/client/connection.d.ts.map +1 -0
  20. package/dist/types/client/history.d.ts +8 -0
  21. package/dist/types/client/history.d.ts.map +1 -0
  22. package/dist/types/client/index.d.ts +5 -0
  23. package/dist/types/client/index.d.ts.map +1 -0
  24. package/dist/types/client/listeners.d.ts +8 -0
  25. package/dist/types/client/listeners.d.ts.map +1 -0
  26. package/dist/types/client/logins.d.ts +35 -0
  27. package/dist/types/client/logins.d.ts.map +1 -0
  28. package/dist/types/client/rpc.d.ts +46 -0
  29. package/dist/types/client/rpc.d.ts.map +1 -0
  30. package/dist/types/client/streams.d.ts +150 -0
  31. package/dist/types/client/streams.d.ts.map +1 -0
  32. package/dist/types/client/transports.d.ts +35 -0
  33. package/dist/types/client/transports.d.ts.map +1 -0
  34. package/dist/types/client/turns.d.ts +81 -0
  35. package/dist/types/client/turns.d.ts.map +1 -0
  36. package/dist/types/core/agents/acp/acp-agent.d.ts +68 -0
  37. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -0
  38. package/dist/types/core/agents/acp/adapter.d.ts +39 -0
  39. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -0
  40. package/dist/types/core/agents/acp/client.d.ts +90 -0
  41. package/dist/types/core/agents/acp/client.d.ts.map +1 -0
  42. package/dist/types/core/agents/acp/known-agents.d.ts +35 -0
  43. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -0
  44. package/dist/types/core/agents/acp/mappings.d.ts +46 -0
  45. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -0
  46. package/dist/types/core/agents/acp/requests.d.ts +26 -0
  47. package/dist/types/core/agents/acp/requests.d.ts.map +1 -0
  48. package/dist/types/core/agents/attachments.d.ts +11 -0
  49. package/dist/types/core/agents/attachments.d.ts.map +1 -0
  50. package/dist/types/core/agents/base.d.ts +227 -0
  51. package/dist/types/core/agents/base.d.ts.map +1 -0
  52. package/dist/types/core/agents/claude-code/adapter.d.ts +58 -0
  53. package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -0
  54. package/dist/types/core/agents/claude-code/approvals.d.ts +26 -0
  55. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -0
  56. package/dist/types/core/agents/claude-code/claude-agent.d.ts +70 -0
  57. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -0
  58. package/dist/types/core/agents/claude-code/credentials.d.ts +54 -0
  59. package/dist/types/core/agents/claude-code/credentials.d.ts.map +1 -0
  60. package/dist/types/core/agents/claude-code/events.d.ts +42 -0
  61. package/dist/types/core/agents/claude-code/events.d.ts.map +1 -0
  62. package/dist/types/core/agents/claude-code/login.d.ts +61 -0
  63. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -0
  64. package/dist/types/core/agents/claude-code/mcp.d.ts +52 -0
  65. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -0
  66. package/dist/types/core/agents/claude-code/models.d.ts +30 -0
  67. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -0
  68. package/dist/types/core/agents/claude-code/options.d.ts +183 -0
  69. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -0
  70. package/dist/types/core/agents/claude-code/outcome.d.ts +50 -0
  71. package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -0
  72. package/dist/types/core/agents/claude-code/session-pool.d.ts +36 -0
  73. package/dist/types/core/agents/claude-code/session-pool.d.ts.map +1 -0
  74. package/dist/types/core/agents/claude-code/session.d.ts +148 -0
  75. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -0
  76. package/dist/types/core/agents/claude-code/spawn.d.ts +29 -0
  77. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -0
  78. package/dist/types/core/agents/claude-code/spend.d.ts +58 -0
  79. package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -0
  80. package/dist/types/core/agents/claude-code/tools.d.ts +4 -0
  81. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -0
  82. package/dist/types/core/agents/claude-code/turn-usage.d.ts +52 -0
  83. package/dist/types/core/agents/claude-code/turn-usage.d.ts.map +1 -0
  84. package/dist/types/core/agents/claude-code/turn.d.ts +121 -0
  85. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -0
  86. package/dist/types/core/agents/codex-app-server/adapter.d.ts +59 -0
  87. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -0
  88. package/dist/types/core/agents/codex-app-server/client.d.ts +116 -0
  89. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -0
  90. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +113 -0
  91. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -0
  92. package/dist/types/core/agents/codex-app-server/commands.d.ts +66 -0
  93. package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -0
  94. package/dist/types/core/agents/codex-app-server/credentials.d.ts +49 -0
  95. package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -0
  96. package/dist/types/core/agents/codex-app-server/effort.d.ts +12 -0
  97. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -0
  98. package/dist/types/core/agents/codex-app-server/events.d.ts +45 -0
  99. package/dist/types/core/agents/codex-app-server/events.d.ts.map +1 -0
  100. package/dist/types/core/agents/codex-app-server/homes.d.ts +20 -0
  101. package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -0
  102. package/dist/types/core/agents/codex-app-server/input.d.ts +26 -0
  103. package/dist/types/core/agents/codex-app-server/input.d.ts.map +1 -0
  104. package/dist/types/core/agents/codex-app-server/items.d.ts +31 -0
  105. package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -0
  106. package/dist/types/core/agents/codex-app-server/login.d.ts +38 -0
  107. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -0
  108. package/dist/types/core/agents/codex-app-server/mcp.d.ts +62 -0
  109. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -0
  110. package/dist/types/core/agents/codex-app-server/models.d.ts +67 -0
  111. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -0
  112. package/dist/types/core/agents/codex-app-server/options.d.ts +40 -0
  113. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -0
  114. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +19 -0
  115. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -0
  116. package/dist/types/core/agents/codex-app-server/protocol.d.ts +99 -0
  117. package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -0
  118. package/dist/types/core/agents/codex-app-server/requests.d.ts +42 -0
  119. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -0
  120. package/dist/types/core/agents/codex-app-server/session.d.ts +96 -0
  121. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -0
  122. package/dist/types/core/agents/codex-app-server/subagents.d.ts +53 -0
  123. package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -0
  124. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +87 -0
  125. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -0
  126. package/dist/types/core/agents/codex-app-server/turn-items.d.ts +33 -0
  127. package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -0
  128. package/dist/types/core/agents/codex-app-server/turn.d.ts +163 -0
  129. package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -0
  130. package/dist/types/core/agents/config-fingerprint.d.ts +5 -0
  131. package/dist/types/core/agents/config-fingerprint.d.ts.map +1 -0
  132. package/dist/types/core/agents/credentials.d.ts +28 -0
  133. package/dist/types/core/agents/credentials.d.ts.map +1 -0
  134. package/dist/types/core/agents/elicitation.d.ts +37 -0
  135. package/dist/types/core/agents/elicitation.d.ts.map +1 -0
  136. package/dist/types/core/agents/inherit-config.d.ts +18 -0
  137. package/dist/types/core/agents/inherit-config.d.ts.map +1 -0
  138. package/dist/types/core/agents/login.d.ts +67 -0
  139. package/dist/types/core/agents/login.d.ts.map +1 -0
  140. package/dist/types/core/agents/mcp-config.d.ts +57 -0
  141. package/dist/types/core/agents/mcp-config.d.ts.map +1 -0
  142. package/dist/types/core/agents/plan.d.ts +16 -0
  143. package/dist/types/core/agents/plan.d.ts.map +1 -0
  144. package/dist/types/core/agents/registry.d.ts +30 -0
  145. package/dist/types/core/agents/registry.d.ts.map +1 -0
  146. package/dist/types/core/agents/session-agent.d.ts +48 -0
  147. package/dist/types/core/agents/session-agent.d.ts.map +1 -0
  148. package/dist/types/core/agents/session-pool.d.ts +41 -0
  149. package/dist/types/core/agents/session-pool.d.ts.map +1 -0
  150. package/dist/types/core/agents/stderr-tail.d.ts +28 -0
  151. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -0
  152. package/dist/types/core/agents/thinking-levels.d.ts +4 -0
  153. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -0
  154. package/dist/types/core/agents/types.d.ts +124 -0
  155. package/dist/types/core/agents/types.d.ts.map +1 -0
  156. package/dist/types/core/diagnostics.d.ts +36 -0
  157. package/dist/types/core/diagnostics.d.ts.map +1 -0
  158. package/dist/types/core/index.d.ts +29 -0
  159. package/dist/types/core/index.d.ts.map +1 -0
  160. package/dist/types/core/presets.d.ts +80 -0
  161. package/dist/types/core/presets.d.ts.map +1 -0
  162. package/dist/types/core/processes/identity.d.ts +31 -0
  163. package/dist/types/core/processes/identity.d.ts.map +1 -0
  164. package/dist/types/core/processes/lifeline.d.ts +47 -0
  165. package/dist/types/core/processes/lifeline.d.ts.map +1 -0
  166. package/dist/types/core/processes/native-processes.d.ts +130 -0
  167. package/dist/types/core/processes/native-processes.d.ts.map +1 -0
  168. package/dist/types/core/processes/process-table.d.ts +43 -0
  169. package/dist/types/core/processes/process-table.d.ts.map +1 -0
  170. package/dist/types/core/provision/cache-trust.d.ts +13 -0
  171. package/dist/types/core/provision/cache-trust.d.ts.map +1 -0
  172. package/dist/types/core/provision/cache-usage.d.ts +14 -0
  173. package/dist/types/core/provision/cache-usage.d.ts.map +1 -0
  174. package/dist/types/core/provision/checksums.d.ts +46 -0
  175. package/dist/types/core/provision/checksums.d.ts.map +1 -0
  176. package/dist/types/core/provision/extract.d.ts +7 -0
  177. package/dist/types/core/provision/extract.d.ts.map +1 -0
  178. package/dist/types/core/provision/index.d.ts +5 -0
  179. package/dist/types/core/provision/index.d.ts.map +1 -0
  180. package/dist/types/core/provision/install-build.d.ts +36 -0
  181. package/dist/types/core/provision/install-build.d.ts.map +1 -0
  182. package/dist/types/core/provision/npm.d.ts +40 -0
  183. package/dist/types/core/provision/npm.d.ts.map +1 -0
  184. package/dist/types/core/provision/pins.d.ts +24 -0
  185. package/dist/types/core/provision/pins.d.ts.map +1 -0
  186. package/dist/types/core/provision/platform.d.ts +28 -0
  187. package/dist/types/core/provision/platform.d.ts.map +1 -0
  188. package/dist/types/core/provision/provisioner.d.ts +189 -0
  189. package/dist/types/core/provision/provisioner.d.ts.map +1 -0
  190. package/dist/types/core/provision/releases.d.ts +8 -0
  191. package/dist/types/core/provision/releases.d.ts.map +1 -0
  192. package/dist/types/core/provision/tools.d.ts +81 -0
  193. package/dist/types/core/provision/tools.d.ts.map +1 -0
  194. package/dist/types/core/proxy/anthropic-proxy.d.ts +52 -0
  195. package/dist/types/core/proxy/anthropic-proxy.d.ts.map +1 -0
  196. package/dist/types/core/proxy/api-key-store.d.ts +37 -0
  197. package/dist/types/core/proxy/api-key-store.d.ts.map +1 -0
  198. package/dist/types/core/proxy/index.d.ts +3 -0
  199. package/dist/types/core/proxy/index.d.ts.map +1 -0
  200. package/dist/types/core/proxy/loopback.d.ts +14 -0
  201. package/dist/types/core/proxy/loopback.d.ts.map +1 -0
  202. package/dist/types/core/runtime/agent-runtime.d.ts +181 -0
  203. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -0
  204. package/dist/types/core/runtime/event-processor.d.ts +87 -0
  205. package/dist/types/core/runtime/event-processor.d.ts.map +1 -0
  206. package/dist/types/core/runtime/event-sink.d.ts +44 -0
  207. package/dist/types/core/runtime/event-sink.d.ts.map +1 -0
  208. package/dist/types/core/runtime/harness-clis.d.ts +10 -0
  209. package/dist/types/core/runtime/harness-clis.d.ts.map +1 -0
  210. package/dist/types/core/runtime/harness-logins.d.ts +68 -0
  211. package/dist/types/core/runtime/harness-logins.d.ts.map +1 -0
  212. package/dist/types/core/runtime/login-reads.d.ts +28 -0
  213. package/dist/types/core/runtime/login-reads.d.ts.map +1 -0
  214. package/dist/types/core/runtime/model-lists.d.ts +37 -0
  215. package/dist/types/core/runtime/model-lists.d.ts.map +1 -0
  216. package/dist/types/core/runtime/permission-policy.d.ts +61 -0
  217. package/dist/types/core/runtime/permission-policy.d.ts.map +1 -0
  218. package/dist/types/core/runtime/request-broker.d.ts +49 -0
  219. package/dist/types/core/runtime/request-broker.d.ts.map +1 -0
  220. package/dist/types/core/runtime/steering.d.ts +38 -0
  221. package/dist/types/core/runtime/steering.d.ts.map +1 -0
  222. package/dist/types/core/runtime/turn-outcome.d.ts +21 -0
  223. package/dist/types/core/runtime/turn-outcome.d.ts.map +1 -0
  224. package/dist/types/core/runtime/turn.d.ts +121 -0
  225. package/dist/types/core/runtime/turn.d.ts.map +1 -0
  226. package/dist/types/core/utils/bounded.d.ts +6 -0
  227. package/dist/types/core/utils/bounded.d.ts.map +1 -0
  228. package/dist/types/core/utils/deadline.d.ts +14 -0
  229. package/dist/types/core/utils/deadline.d.ts.map +1 -0
  230. package/dist/types/core/utils/errors.d.ts +104 -0
  231. package/dist/types/core/utils/errors.d.ts.map +1 -0
  232. package/dist/types/core/utils/is-record.d.ts +3 -0
  233. package/dist/types/core/utils/is-record.d.ts.map +1 -0
  234. package/dist/types/core/utils/loopback.d.ts +6 -0
  235. package/dist/types/core/utils/loopback.d.ts.map +1 -0
  236. package/dist/types/index.d.ts +2 -0
  237. package/dist/types/index.d.ts.map +1 -0
  238. package/dist/types/protocol/account.d.ts +26 -0
  239. package/dist/types/protocol/account.d.ts.map +1 -0
  240. package/dist/types/protocol/async-queue.d.ts +21 -0
  241. package/dist/types/protocol/async-queue.d.ts.map +1 -0
  242. package/dist/types/protocol/auth.d.ts +228 -0
  243. package/dist/types/protocol/auth.d.ts.map +1 -0
  244. package/dist/types/protocol/canonical.d.ts +9 -0
  245. package/dist/types/protocol/canonical.d.ts.map +1 -0
  246. package/dist/types/protocol/clis.d.ts +74 -0
  247. package/dist/types/protocol/clis.d.ts.map +1 -0
  248. package/dist/types/protocol/config.d.ts +200 -0
  249. package/dist/types/protocol/config.d.ts.map +1 -0
  250. package/dist/types/protocol/conversation.d.ts +942 -0
  251. package/dist/types/protocol/conversation.d.ts.map +1 -0
  252. package/dist/types/protocol/credentials.d.ts +145 -0
  253. package/dist/types/protocol/credentials.d.ts.map +1 -0
  254. package/dist/types/protocol/errors.d.ts +36 -0
  255. package/dist/types/protocol/errors.d.ts.map +1 -0
  256. package/dist/types/protocol/execution.d.ts +28 -0
  257. package/dist/types/protocol/execution.d.ts.map +1 -0
  258. package/dist/types/protocol/factories.d.ts +94 -0
  259. package/dist/types/protocol/factories.d.ts.map +1 -0
  260. package/dist/types/protocol/guards.d.ts +55 -0
  261. package/dist/types/protocol/guards.d.ts.map +1 -0
  262. package/dist/types/protocol/harness.d.ts +70 -0
  263. package/dist/types/protocol/harness.d.ts.map +1 -0
  264. package/dist/types/protocol/history.d.ts +318 -0
  265. package/dist/types/protocol/history.d.ts.map +1 -0
  266. package/dist/types/protocol/ids.d.ts +9 -0
  267. package/dist/types/protocol/ids.d.ts.map +1 -0
  268. package/dist/types/protocol/index.d.ts +35 -0
  269. package/dist/types/protocol/index.d.ts.map +1 -0
  270. package/dist/types/protocol/lifecycle.d.ts +1190 -0
  271. package/dist/types/protocol/lifecycle.d.ts.map +1 -0
  272. package/dist/types/protocol/meta-keys.d.ts +17 -0
  273. package/dist/types/protocol/meta-keys.d.ts.map +1 -0
  274. package/dist/types/protocol/meta.d.ts +13 -0
  275. package/dist/types/protocol/meta.d.ts.map +1 -0
  276. package/dist/types/protocol/model-catalog.d.ts +11 -0
  277. package/dist/types/protocol/model-catalog.d.ts.map +1 -0
  278. package/dist/types/protocol/models.d.ts +107 -0
  279. package/dist/types/protocol/models.d.ts.map +1 -0
  280. package/dist/types/protocol/part-input.d.ts +101 -0
  281. package/dist/types/protocol/part-input.d.ts.map +1 -0
  282. package/dist/types/protocol/parts.d.ts +357 -0
  283. package/dist/types/protocol/parts.d.ts.map +1 -0
  284. package/dist/types/protocol/reduce.d.ts +26 -0
  285. package/dist/types/protocol/reduce.d.ts.map +1 -0
  286. package/dist/types/protocol/selectors.d.ts +64 -0
  287. package/dist/types/protocol/selectors.d.ts.map +1 -0
  288. package/dist/types/protocol/seq-cursor.d.ts +66 -0
  289. package/dist/types/protocol/seq-cursor.d.ts.map +1 -0
  290. package/dist/types/protocol/stop-reasons.d.ts +33 -0
  291. package/dist/types/protocol/stop-reasons.d.ts.map +1 -0
  292. package/dist/types/protocol/thinking.d.ts +28 -0
  293. package/dist/types/protocol/thinking.d.ts.map +1 -0
  294. package/dist/types/protocol/time.d.ts +21 -0
  295. package/dist/types/protocol/time.d.ts.map +1 -0
  296. package/dist/types/protocol/tokens.d.ts +29 -0
  297. package/dist/types/protocol/tokens.d.ts.map +1 -0
  298. package/dist/types/protocol/tool-closure.d.ts +25 -0
  299. package/dist/types/protocol/tool-closure.d.ts.map +1 -0
  300. package/dist/types/protocol/tool-state.d.ts +209 -0
  301. package/dist/types/protocol/tool-state.d.ts.map +1 -0
  302. package/dist/types/protocol/verify.d.ts +52 -0
  303. package/dist/types/protocol/verify.d.ts.map +1 -0
  304. package/dist/types/protocol/vocabulary.d.ts +19 -0
  305. package/dist/types/protocol/vocabulary.d.ts.map +1 -0
  306. package/dist/types/protocol/wire-api.d.ts +1983 -0
  307. package/dist/types/protocol/wire-api.d.ts.map +1 -0
  308. package/dist/types/protocol/wire.d.ts +1758 -0
  309. package/dist/types/protocol/wire.d.ts.map +1 -0
  310. package/dist/types/server/acp/binding.d.ts +33 -0
  311. package/dist/types/server/acp/binding.d.ts.map +1 -0
  312. package/dist/types/server/acp/session-records.d.ts +17 -0
  313. package/dist/types/server/acp/session-records.d.ts.map +1 -0
  314. package/dist/types/server/acp/translate.d.ts +48 -0
  315. package/dist/types/server/acp/translate.d.ts.map +1 -0
  316. package/dist/types/server/agent-server.d.ts +121 -0
  317. package/dist/types/server/agent-server.d.ts.map +1 -0
  318. package/dist/types/server/feedback.d.ts +37 -0
  319. package/dist/types/server/feedback.d.ts.map +1 -0
  320. package/dist/types/server/history.d.ts +15 -0
  321. package/dist/types/server/history.d.ts.map +1 -0
  322. package/dist/types/server/index.d.ts +7 -0
  323. package/dist/types/server/index.d.ts.map +1 -0
  324. package/dist/types/server/install.d.ts +42 -0
  325. package/dist/types/server/install.d.ts.map +1 -0
  326. package/dist/types/server/open-parts.d.ts +27 -0
  327. package/dist/types/server/open-parts.d.ts.map +1 -0
  328. package/dist/types/server/routes.d.ts +61 -0
  329. package/dist/types/server/routes.d.ts.map +1 -0
  330. package/dist/types/server/secrets.d.ts +11 -0
  331. package/dist/types/server/secrets.d.ts.map +1 -0
  332. package/dist/types/server/session-gate.d.ts +32 -0
  333. package/dist/types/server/session-gate.d.ts.map +1 -0
  334. package/dist/types/server/session-log.d.ts +39 -0
  335. package/dist/types/server/session-log.d.ts.map +1 -0
  336. package/dist/types/server/session-store.d.ts +119 -0
  337. package/dist/types/server/session-store.d.ts.map +1 -0
  338. package/dist/types/server/subscriptions.d.ts +74 -0
  339. package/dist/types/server/subscriptions.d.ts.map +1 -0
  340. package/dist/types/server/transports.d.ts +74 -0
  341. package/dist/types/server/transports.d.ts.map +1 -0
  342. package/dist/types/server/wire-error.d.ts +9 -0
  343. package/dist/types/server/wire-error.d.ts.map +1 -0
  344. package/dist/types/sync/event-log.d.ts +45 -0
  345. package/dist/types/sync/event-log.d.ts.map +1 -0
  346. package/dist/types/sync/fit.d.ts +40 -0
  347. package/dist/types/sync/fit.d.ts.map +1 -0
  348. package/dist/types/sync/history-reader.d.ts +8 -0
  349. package/dist/types/sync/history-reader.d.ts.map +1 -0
  350. package/dist/types/sync/history-sqlite.d.ts +37 -0
  351. package/dist/types/sync/history-sqlite.d.ts.map +1 -0
  352. package/dist/types/sync/history.d.ts +70 -0
  353. package/dist/types/sync/history.d.ts.map +1 -0
  354. package/dist/types/sync/index.d.ts +4 -0
  355. package/dist/types/sync/index.d.ts.map +1 -0
  356. package/dist/types/sync/journal-sqlite.d.ts +51 -0
  357. package/dist/types/sync/journal-sqlite.d.ts.map +1 -0
  358. package/dist/types/sync/journal.d.ts +107 -0
  359. package/dist/types/sync/journal.d.ts.map +1 -0
  360. package/dist/types/sync/live-tails.d.ts +30 -0
  361. package/dist/types/sync/live-tails.d.ts.map +1 -0
  362. package/dist/types/sync/node-sqlite.d.ts +7 -0
  363. package/dist/types/sync/node-sqlite.d.ts.map +1 -0
  364. package/dist/types/sync/projection.d.ts +10 -0
  365. package/dist/types/sync/projection.d.ts.map +1 -0
  366. package/dist/types/sync/recovery.d.ts +25 -0
  367. package/dist/types/sync/recovery.d.ts.map +1 -0
  368. package/dist/types/sync/retry.d.ts +25 -0
  369. package/dist/types/sync/retry.d.ts.map +1 -0
  370. package/dist/types/sync/schema.d.ts +4 -0
  371. package/dist/types/sync/schema.d.ts.map +1 -0
  372. package/dist/types/sync/sql.d.ts +38 -0
  373. package/dist/types/sync/sql.d.ts.map +1 -0
  374. package/dist/types/sync/sqlite-file.d.ts +9 -0
  375. package/dist/types/sync/sqlite-file.d.ts.map +1 -0
  376. package/dist/types/sync/sqlite.d.ts +6 -0
  377. package/dist/types/sync/sqlite.d.ts.map +1 -0
  378. package/dist/types/sync/worker.d.ts +63 -0
  379. package/dist/types/sync/worker.d.ts.map +1 -0
  380. package/docs/consuming.md +460 -54
  381. package/docs/deploy.md +218 -47
  382. package/docs/durable-sessions.md +195 -0
  383. package/docs/feedback.md +116 -0
  384. package/docs/harnesses.md +219 -87
  385. package/docs/sync-history.md +197 -0
  386. package/docs/sync-integration.md +119 -0
  387. package/package.json +53 -23
  388. package/src/accounts/chatgpt.ts +194 -0
  389. package/src/accounts/check.ts +112 -0
  390. package/src/accounts/claude.ts +111 -0
  391. package/src/accounts/endpoint.ts +151 -0
  392. package/src/accounts/http.ts +97 -0
  393. package/src/accounts/index.ts +19 -0
  394. package/src/client/client.ts +641 -602
  395. package/src/client/connection.ts +371 -0
  396. package/src/client/history.ts +65 -0
  397. package/src/client/index.ts +11 -2
  398. package/src/client/listeners.ts +20 -0
  399. package/src/client/logins.ts +105 -0
  400. package/src/client/rpc.ts +144 -0
  401. package/src/client/streams.ts +488 -0
  402. package/src/client/transports.ts +62 -8
  403. package/src/client/turns.ts +171 -0
  404. package/src/core/agents/acp/acp-agent.ts +94 -118
  405. package/src/core/agents/acp/adapter.ts +20 -9
  406. package/src/core/agents/acp/client.ts +125 -47
  407. package/src/core/agents/acp/known-agents.ts +36 -4
  408. package/src/core/agents/acp/mappings.ts +64 -18
  409. package/src/core/agents/acp/requests.ts +125 -0
  410. package/src/core/agents/attachments.ts +18 -0
  411. package/src/core/agents/base.ts +120 -42
  412. package/src/core/agents/claude-code/adapter.ts +177 -238
  413. package/src/core/agents/claude-code/approvals.ts +270 -0
  414. package/src/core/agents/claude-code/claude-agent.ts +175 -158
  415. package/src/core/agents/claude-code/credentials.ts +171 -0
  416. package/src/core/agents/claude-code/events.ts +55 -0
  417. package/src/core/agents/claude-code/login.ts +269 -0
  418. package/src/core/agents/claude-code/mcp.ts +206 -0
  419. package/src/core/agents/claude-code/models.ts +15 -9
  420. package/src/core/agents/claude-code/options.ts +326 -39
  421. package/src/core/agents/claude-code/outcome.ts +209 -0
  422. package/src/core/agents/claude-code/session-pool.ts +136 -0
  423. package/src/core/agents/claude-code/session.ts +513 -0
  424. package/src/core/agents/claude-code/spawn.ts +144 -0
  425. package/src/core/agents/claude-code/spend.ts +160 -0
  426. package/src/core/agents/claude-code/tools.ts +47 -0
  427. package/src/core/agents/claude-code/turn-usage.ts +135 -0
  428. package/src/core/agents/claude-code/turn.ts +232 -0
  429. package/src/core/agents/codex-app-server/adapter.ts +314 -117
  430. package/src/core/agents/codex-app-server/client.ts +186 -84
  431. package/src/core/agents/codex-app-server/codex-agent.ts +343 -0
  432. package/src/core/agents/codex-app-server/commands.ts +228 -0
  433. package/src/core/agents/codex-app-server/credentials.ts +126 -0
  434. package/src/core/agents/codex-app-server/effort.ts +29 -0
  435. package/src/core/agents/codex-app-server/events.ts +47 -0
  436. package/src/core/agents/codex-app-server/homes.ts +64 -0
  437. package/src/core/agents/codex-app-server/input.ts +60 -0
  438. package/src/core/agents/codex-app-server/items.ts +149 -0
  439. package/src/core/agents/codex-app-server/login.ts +180 -0
  440. package/src/core/agents/codex-app-server/mcp.ts +182 -37
  441. package/src/core/agents/codex-app-server/models.ts +99 -46
  442. package/src/core/agents/codex-app-server/options.ts +146 -0
  443. package/src/core/agents/codex-app-server/plan-approval.ts +135 -0
  444. package/src/core/agents/codex-app-server/protocol.ts +117 -0
  445. package/src/core/agents/codex-app-server/requests.ts +332 -0
  446. package/src/core/agents/codex-app-server/session.ts +285 -0
  447. package/src/core/agents/codex-app-server/subagents.ts +108 -42
  448. package/src/core/agents/codex-app-server/thread-settings.ts +279 -0
  449. package/src/core/agents/codex-app-server/turn-items.ts +88 -0
  450. package/src/core/agents/codex-app-server/turn.ts +463 -0
  451. package/src/core/agents/config-fingerprint.ts +7 -14
  452. package/src/core/agents/credentials.ts +98 -0
  453. package/src/core/agents/elicitation.ts +75 -0
  454. package/src/core/agents/inherit-config.ts +21 -0
  455. package/src/core/agents/login.ts +116 -0
  456. package/src/core/agents/mcp-config.ts +112 -8
  457. package/src/core/agents/plan.ts +25 -0
  458. package/src/core/agents/registry.ts +21 -4
  459. package/src/core/agents/session-agent.ts +96 -4
  460. package/src/core/agents/{session-store.ts → session-pool.ts} +11 -5
  461. package/src/core/agents/stderr-tail.ts +75 -0
  462. package/src/core/agents/types.ts +40 -5
  463. package/src/core/index.ts +60 -48
  464. package/src/core/presets.ts +100 -39
  465. package/src/core/processes/identity.ts +113 -0
  466. package/src/core/processes/lifeline.ts +170 -0
  467. package/src/core/processes/native-processes.ts +379 -0
  468. package/src/core/processes/process-table.ts +174 -0
  469. package/src/core/provision/cache-trust.ts +121 -0
  470. package/src/core/provision/cache-usage.ts +69 -0
  471. package/src/core/provision/checksums.ts +64 -0
  472. package/src/core/provision/extract.ts +11 -2
  473. package/src/core/provision/index.ts +4 -1
  474. package/src/core/provision/install-build.ts +136 -0
  475. package/src/core/provision/npm.ts +112 -17
  476. package/src/core/provision/pins.ts +11 -34
  477. package/src/core/provision/platform.ts +12 -1
  478. package/src/core/provision/provisioner.ts +329 -397
  479. package/src/core/provision/releases.ts +86 -0
  480. package/src/core/provision/tools.ts +329 -0
  481. package/src/core/proxy/anthropic-proxy.ts +55 -25
  482. package/src/core/proxy/api-key-store.ts +2 -12
  483. package/src/core/proxy/loopback.ts +106 -0
  484. package/src/core/runtime/agent-runtime.ts +340 -481
  485. package/src/core/runtime/event-processor.ts +207 -75
  486. package/src/core/runtime/event-sink.ts +45 -2
  487. package/src/core/runtime/harness-clis.ts +61 -0
  488. package/src/core/runtime/harness-logins.ts +328 -0
  489. package/src/core/runtime/login-reads.ts +78 -0
  490. package/src/core/runtime/model-lists.ts +57 -57
  491. package/src/core/runtime/permission-policy.ts +113 -0
  492. package/src/core/runtime/request-broker.ts +204 -0
  493. package/src/core/runtime/steering.ts +112 -0
  494. package/src/core/runtime/turn-outcome.ts +30 -0
  495. package/src/core/runtime/turn.ts +360 -0
  496. package/src/core/utils/bounded.ts +12 -0
  497. package/src/core/utils/deadline.ts +38 -0
  498. package/src/core/utils/errors.ts +113 -21
  499. package/src/core/utils/is-record.ts +4 -0
  500. package/src/core/utils/loopback.ts +10 -0
  501. package/src/protocol/account.ts +104 -0
  502. package/src/protocol/auth.ts +199 -0
  503. package/src/protocol/canonical.ts +16 -0
  504. package/src/protocol/clis.ts +69 -0
  505. package/src/protocol/config.ts +60 -6
  506. package/src/protocol/conversation.ts +272 -0
  507. package/src/protocol/credentials.ts +145 -0
  508. package/src/protocol/errors.ts +78 -20
  509. package/src/protocol/execution.ts +5 -2
  510. package/src/protocol/factories.ts +55 -7
  511. package/src/protocol/guards.ts +55 -2
  512. package/src/protocol/harness.ts +56 -6
  513. package/src/protocol/history.ts +275 -0
  514. package/src/protocol/ids.ts +4 -17
  515. package/src/protocol/index.ts +10 -0
  516. package/src/protocol/lifecycle.ts +250 -79
  517. package/src/protocol/meta-keys.ts +17 -0
  518. package/src/protocol/meta.ts +3 -3
  519. package/src/protocol/models.ts +2 -43
  520. package/src/protocol/part-input.ts +2 -1
  521. package/src/protocol/parts.ts +12 -3
  522. package/src/protocol/reduce.ts +302 -413
  523. package/src/protocol/selectors.ts +1 -20
  524. package/src/protocol/seq-cursor.ts +14 -0
  525. package/src/protocol/stop-reasons.ts +1 -1
  526. package/src/protocol/thinking.ts +1 -30
  527. package/src/protocol/time.ts +2 -2
  528. package/src/protocol/tool-closure.ts +93 -0
  529. package/src/protocol/tool-state.ts +19 -4
  530. package/src/protocol/verify.ts +222 -92
  531. package/src/protocol/vocabulary.ts +21 -5
  532. package/src/protocol/wire-api.ts +232 -0
  533. package/src/protocol/wire.ts +425 -57
  534. package/src/server/acp/binding.ts +63 -103
  535. package/src/server/acp/session-records.ts +53 -0
  536. package/src/server/acp/translate.ts +129 -20
  537. package/src/server/agent-server.ts +275 -366
  538. package/src/server/bin.ts +295 -72
  539. package/src/server/feedback.ts +204 -14
  540. package/src/server/history.ts +160 -0
  541. package/src/server/index.ts +4 -8
  542. package/src/server/install.ts +107 -8
  543. package/src/server/open-parts.ts +95 -0
  544. package/src/server/routes.ts +391 -0
  545. package/src/server/secrets.ts +24 -0
  546. package/src/server/session-gate.ts +69 -0
  547. package/src/server/session-log.ts +14 -2
  548. package/src/server/session-store.ts +289 -0
  549. package/src/server/subscriptions.ts +232 -0
  550. package/src/server/transports.ts +125 -25
  551. package/src/server/wire-error.ts +38 -0
  552. package/src/sync/event-log.ts +160 -0
  553. package/src/sync/fit.ts +140 -0
  554. package/src/sync/history-reader.ts +57 -0
  555. package/src/sync/history-sqlite.ts +339 -0
  556. package/src/sync/history.ts +220 -0
  557. package/src/sync/index.ts +18 -0
  558. package/src/sync/journal-sqlite.ts +439 -0
  559. package/src/sync/journal.ts +132 -0
  560. package/src/sync/live-tails.ts +107 -0
  561. package/src/sync/node-sqlite.ts +20 -0
  562. package/src/sync/projection.ts +35 -0
  563. package/src/sync/recovery.ts +141 -0
  564. package/src/sync/retry.ts +49 -0
  565. package/src/sync/schema.ts +77 -0
  566. package/src/sync/sql.ts +106 -0
  567. package/src/sync/sqlite-file.ts +38 -0
  568. package/src/sync/sqlite.ts +21 -0
  569. package/src/sync/worker.ts +259 -0
  570. package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
  571. package/docs/rfds/0002-native-subagents.md +0 -197
  572. package/src/core/agents/claude-code/generator-session.ts +0 -572
  573. package/src/core/agents/claude-code/session-manager.ts +0 -166
  574. package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
  575. package/src/core/agents/codex-items.ts +0 -149
  576. package/src/core/agents/codex-sdk/adapter.ts +0 -237
  577. package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
  578. package/src/core/agents/tool-meta.ts +0 -68
@@ -3,8 +3,10 @@ import { RunConfigSchema } from "./config.ts";
3
3
  import { AgentCapabilitiesSchema, AgentHarnessSchema } from "./harness.ts";
4
4
  import {
5
5
  type DecodedLifecycleEvent,
6
+ ElicitationOutcomeSchema,
6
7
  LifecycleEventSchema,
7
8
  PermissionOutcomeSchema,
9
+ TurnEndedEventSchema,
8
10
  type UnknownEvent,
9
11
  decodeLifecycleEvent,
10
12
  } from "./lifecycle.ts";
@@ -12,14 +14,35 @@ import { ModelListSchema } from "./models.ts";
12
14
  import { AgentInputSchema } from "./part-input.ts";
13
15
 
14
16
  /**
15
- * The standard wire (phase 2): JSON-RPC 2.0 over a newline-delimited JSON
17
+ * The standard wire: JSON-RPC 2.0 over a newline-delimited JSON
16
18
  * stream (stdio, WebSocket, or any duplex byte channel). Requests flow
17
19
  * client -> server only; the server pushes `event` notifications. Turns are
18
20
  * quick-ack: `turn/start` acknowledges immediately and completion is observed
19
21
  * via the `turn.ended` lifecycle event, mirroring the engine's event-driven
20
22
  * model (and ACP v2's prompt lifecycle).
23
+ *
24
+ * Version 3: a `message.part.delta` is no longer sequenced. It carries the
25
+ * `seq` of the session's last kept event, and replay and history never return
26
+ * it (see `MessagePartDeltaEventSchema`).
27
+ *
28
+ * Version 4: one vocabulary — snake_case values (`in_session`), `history/read`,
29
+ * `unknownTurn`.
30
+ *
31
+ * Version 5: a connection receives the sessions it subscribes to
32
+ * (`session/subscribe`; `turn/start` subscribes its caller), and a frame the
33
+ * server does not keep says so (`live: true`): token deltas, and the open
34
+ * parts that follow a subscription. The engine no longer checkpoints a
35
+ * streaming part. A peer of another version is refused at `initialize`, never
36
+ * half served by values it cannot read.
37
+ *
38
+ * Version 6: a connection watches a session (`session/subscribe {sessionId}`)
39
+ * or follows one of its running turns (`turn/start`, `session/subscribe
40
+ * {sessionId, turnId}`), and a turn's subscription ends with the turn.
41
+ * `session/subscribe` takes no `afterSeq`: a client catches up with
42
+ * `events/replay`. Every session is `session/subscribeAll` and
43
+ * `session/unsubscribeAll`, each with its own answer, not `{all: true}`.
21
44
  */
22
- export const WIRE_PROTOCOL_VERSION = 2;
45
+ export const WIRE_PROTOCOL_VERSION = 6;
23
46
 
24
47
  // ---- JSON-RPC 2.0 envelopes --------------------------------------------------
25
48
 
@@ -52,9 +75,68 @@ export const WIRE_ERROR_CODES = {
52
75
  protocolVersionMismatch: -32004,
53
76
  /** A session/close for this session is still in flight; retry after it settles. */
54
77
  sessionClosing: -32005,
55
- /** A turn with this turnId already ran (or is running) with DIFFERENT input. */
78
+ /**
79
+ * A turn with this turnId already ran (or is running) with DIFFERENT input,
80
+ * or a steerId was reused with different input or in another turn.
81
+ */
56
82
  turnConflict: -32006,
83
+ /** A durable session was closed; its id is not reused. */
84
+ sessionClosed: -32007,
85
+ /**
86
+ * A server restart cut off the session's last turn and could not confirm
87
+ * its native process stopped (`data.reason`, a `RecoveryReason`). Check it
88
+ * stopped, then confirm (`session/confirmStopped` with `data.headSeq`)
89
+ * before starting another turn.
90
+ */
91
+ recoveryRequired: -32008,
92
+ /**
93
+ * This server process has not run the durable session yet: pass its
94
+ * `data.nativeSessionId` as `config.resumeSessionId`, or use a new session.
95
+ */
96
+ resumeRequired: -32009,
97
+ /** The host refused this caller the history operation. */
98
+ notAuthorized: -32010,
99
+ /** No such history, or it does not hold the requested version. */
100
+ unknownHistory: -32011,
101
+ /** The request contradicts committed history (payload, hash, expected head or commit id). */
102
+ historyConflict: -32012,
103
+ /** The session is known, but no turn with this turnId was admitted to it. */
104
+ unknownTurn: -32013,
105
+ /** The connection watches `maxSubscriptions` sessions already (`data.limit`): unsubscribe one first. */
106
+ subscriptionLimit: -32014,
107
+ /** No login under way has this loginId: it ended, expired, was cancelled or never started. */
108
+ unknownLogin: -32015,
57
109
  } as const;
110
+ export type WireErrorName = keyof typeof WIRE_ERROR_CODES;
111
+ const WIRE_ERROR_NAMES = new Map(
112
+ Object.entries(WIRE_ERROR_CODES).map(([name, code]) => [code as number, name as WireErrorName]),
113
+ );
114
+ /** Whether a name is one of `WIRE_ERROR_CODES`'. */
115
+ export function isWireErrorName(name: string): name is WireErrorName {
116
+ return Object.hasOwn(WIRE_ERROR_CODES, name);
117
+ }
118
+ /** The name `WIRE_ERROR_CODES` gives an error response's code, if it is one of them. */
119
+ export function wireErrorName(code: number): WireErrorName | undefined {
120
+ return WIRE_ERROR_NAMES.get(code);
121
+ }
122
+
123
+ /**
124
+ * A refusal: a request this side will not carry out, answered with the wire
125
+ * error it names — as opposed to a fault, which answers `internalError`. The
126
+ * history port's and the journal's refusals are refusals of this kind, so a
127
+ * caller in-process and one over the wire see the same code.
128
+ */
129
+ export class WireRefusal<Code extends WireErrorName = WireErrorName, Data = unknown> extends Error {
130
+ override readonly name: string = "WireRefusal";
131
+ constructor(
132
+ readonly code: Code,
133
+ message: string,
134
+ /** What the caller needs to act on the refusal, e.g. the `headSeq` to confirm. */
135
+ readonly data?: Data,
136
+ ) {
137
+ super(message);
138
+ }
139
+ }
58
140
 
59
141
  // ---- methods -----------------------------------------------------------------
60
142
 
@@ -62,15 +144,38 @@ export const WIRE_METHODS = {
62
144
  initialize: "initialize",
63
145
  turnStart: "turn/start",
64
146
  turnCancel: "turn/cancel",
147
+ turnSteer: "turn/steer",
65
148
  sessionClose: "session/close",
66
149
  permissionRespond: "permission/respond",
150
+ elicitationRespond: "elicitation/respond",
67
151
  eventsReplay: "events/replay",
68
152
  modelsList: "models/list",
153
+ clisList: "clis/list",
154
+ clisPrepare: "clis/prepare",
155
+ authStatus: "auth/status",
156
+ authLogin: "auth/login",
157
+ authComplete: "auth/complete",
158
+ authCancel: "auth/cancel",
159
+ authLogout: "auth/logout",
160
+ /** Durable servers only (`historyId` in `initialize`); others answer methodNotFound. */
161
+ turnGet: "turn/get",
162
+ sessionGet: "session/get",
163
+ sessionConfirmStopped: "session/confirmStopped",
164
+ sessionRelease: "session/release",
165
+ sessionSubscribe: "session/subscribe",
166
+ sessionUnsubscribe: "session/unsubscribe",
167
+ sessionSubscribeAll: "session/subscribeAll",
168
+ sessionUnsubscribeAll: "session/unsubscribeAll",
69
169
  shutdown: "shutdown",
70
170
  /** Server -> client notification carrying one sequenced lifecycle event. */
71
171
  event: "event",
172
+ /** Server -> client notification: a subscription the server dropped because the connection fell behind. */
173
+ sessionOverflow: "session/overflow",
174
+ /** Server -> client notification: a harness's CLI being installed. */
175
+ clisProgress: "clis/progress",
176
+ /** Server -> client notification: a harness's login changed, or a login ended. */
177
+ authUpdated: "auth/updated",
72
178
  } as const;
73
- export type WireMethod = (typeof WIRE_METHODS)[keyof typeof WIRE_METHODS];
74
179
 
75
180
  export const WireImplementationInfoSchema = z.object({
76
181
  name: z.string(),
@@ -95,6 +200,12 @@ export const InitializeResultSchema = z.object({
95
200
  * fact four downstream heuristics used to guess.
96
201
  */
97
202
  instanceId: z.string(),
203
+ /**
204
+ * Durable servers only: the journal's identity, the `sourceId` of every
205
+ * session history it serves. It outlives the process, and so do the session
206
+ * logs: a client keeps its seq cursors while this is unchanged.
207
+ */
208
+ historyId: z.string().optional(),
98
209
  /** Capabilities per registered harness — only available harnesses appear. */
99
210
  harnesses: z.record(z.string(), AgentCapabilitiesSchema),
100
211
  });
@@ -111,6 +222,13 @@ export const TurnStartParamsSchema = z.object({
111
222
  turnId: z.string().min(1).optional(),
112
223
  input: AgentInputSchema,
113
224
  config: RunConfigSchema,
225
+ /**
226
+ * Stream the session to the caller from the head at admission until the
227
+ * turn ends, as `session/subscribe {sessionId, turnId}` does. Default true;
228
+ * a deduplicated start of a running turn subscribes too, a refused one
229
+ * changes nothing.
230
+ */
231
+ subscribe: z.boolean().optional(),
114
232
  });
115
233
  export type TurnStartParams = z.infer<typeof TurnStartParamsSchema>;
116
234
 
@@ -124,6 +242,16 @@ export const TurnStartResultSchema = z.object({
124
242
  * execution happened; catch up on its events via `events/replay`.
125
243
  */
126
244
  deduplicated: z.boolean().optional(),
245
+ /** A deduplicated turn that already ended: its `turn.ended`. */
246
+ terminal: TurnEndedEventSchema.optional(),
247
+ /**
248
+ * The session's last kept seq at admission, the subscription point: a new
249
+ * turn's first event follows it. A client with no cursor for the session
250
+ * starts one here, so it downloads none of the session's history.
251
+ */
252
+ headSeq: z.number().int().nonnegative(),
253
+ /** A deduplicated turn whose `turn.started` is kept: its seq, to catch up from. */
254
+ startedSeq: z.number().int().positive().optional(),
127
255
  });
128
256
  export type TurnStartResult = z.infer<typeof TurnStartResultSchema>;
129
257
 
@@ -131,17 +259,16 @@ export const TurnCancelParamsSchema = z.object({
131
259
  sessionId: z.string().min(1),
132
260
  /**
133
261
  * Cancel only if THIS turn is the active one — a late cancel meant for a
134
- * finished turn must not kill its successor. Omitted = session-scoped
135
- * cancel of whatever is active (legacy behavior). Empty ids are rejected
136
- * rather than silently treated as unstamped.
262
+ * finished turn must not kill its successor. Omitted: cancel whatever turn
263
+ * the session is running. Empty ids are rejected rather than silently
264
+ * treated as unstamped.
137
265
  */
138
266
  turnId: z.string().min(1).optional(),
139
267
  });
140
268
  export type TurnCancelParams = z.infer<typeof TurnCancelParamsSchema>;
141
269
 
142
270
  /**
143
- * Single-outcome cancel result (replaces the 0.2 two-boolean shape whose
144
- * combinations included illegal states):
271
+ * What a cancel did, as one outcome:
145
272
  * - `cancelled` — the harness confirmed the interrupt.
146
273
  * - `unconfirmed` — best-effort dispatched but unacknowledged; the agent
147
274
  * process may still be running and the turn's `turn.ended` remains the
@@ -156,6 +283,47 @@ export const TurnCancelResultSchema = z.discriminatedUnion("outcome", [
156
283
  ]);
157
284
  export type TurnCancelResult = z.infer<typeof TurnCancelResultSchema>;
158
285
 
286
+ /**
287
+ * More input for a running turn. `turnId` is required: a steer meant for one
288
+ * turn must never land in the next. `steerId` names the user message the steer
289
+ * becomes (`steerMessageId`), so it is unique in the session, as a turn id is;
290
+ * the server mints one when it is omitted. A retry with the same `steerId` and
291
+ * input converges instead of steering twice; reusing it otherwise is
292
+ * `turnConflict`.
293
+ */
294
+ export const TurnSteerParamsSchema = z.object({
295
+ sessionId: z.string().min(1),
296
+ turnId: z.string().min(1),
297
+ steerId: z.string().min(1).optional(),
298
+ input: AgentInputSchema.refine(
299
+ (input) => (typeof input === "string" ? input.trim() !== "" : input.length > 0),
300
+ "a steer carries input",
301
+ ),
302
+ });
303
+ export type TurnSteerParams = z.infer<typeof TurnSteerParamsSchema>;
304
+
305
+ /**
306
+ * What a steer did, as one outcome:
307
+ * - `steered` — accepted. It reaches the agent at its next step and
308
+ * appears as a user message in the turn, or, if the turn ends first, in
309
+ * the turn's `turn.ended.undeliveredSteers`.
310
+ * - `no_active_turn` — the turn is not taking input: it ended or is ending,
311
+ * or another turn is active (`activeTurnId`). Send it as a new turn.
312
+ * - `unsupported` — this harness cannot take input mid-turn
313
+ * (`AgentCapabilities.steering`).
314
+ */
315
+ export const TurnSteerResultSchema = z.discriminatedUnion("outcome", [
316
+ z.object({
317
+ outcome: z.literal("steered"),
318
+ steerId: z.string(),
319
+ /** A retry of a steer already accepted: nothing was sent twice. */
320
+ deduplicated: z.boolean().optional(),
321
+ }),
322
+ z.object({ outcome: z.literal("no_active_turn"), activeTurnId: z.string().optional() }),
323
+ z.object({ outcome: z.literal("unsupported") }),
324
+ ]);
325
+ export type TurnSteerResult = z.infer<typeof TurnSteerResultSchema>;
326
+
159
327
  export const SessionCloseParamsSchema = z.object({ sessionId: z.string() });
160
328
  export type SessionCloseParams = z.infer<typeof SessionCloseParamsSchema>;
161
329
 
@@ -174,29 +342,41 @@ export type PermissionRespondParams = z.infer<typeof PermissionRespondParamsSche
174
342
  export const PermissionRespondResultSchema = z.object({ accepted: z.boolean() });
175
343
  export type PermissionRespondResult = z.infer<typeof PermissionRespondResultSchema>;
176
344
 
177
- /**
178
- * One sequenced event as broadcast on the wire. `seq` is per-session,
179
- * monotonic, and starts at 1 — a client that has seen nothing replays from 1.
180
- * The envelope duplicates `sessionId` so consumers can route without parsing
181
- * the event body.
182
- */
183
- export const WireEventEnvelopeSchema = z.object({
345
+ export const ElicitationRespondParamsSchema = z.object({
184
346
  sessionId: z.string(),
185
- seq: z.number().int().positive(),
186
- event: LifecycleEventSchema,
347
+ requestId: z.string(),
348
+ outcome: ElicitationOutcomeSchema,
187
349
  });
188
- export type WireEventEnvelope = z.infer<typeof WireEventEnvelopeSchema>;
350
+ export type ElicitationRespondParams = z.infer<typeof ElicitationRespondParamsSchema>;
351
+
352
+ /** `accepted: false` means the request was unknown or already resolved. */
353
+ export const ElicitationRespondResultSchema = z.object({ accepted: z.boolean() });
354
+ export type ElicitationRespondResult = z.infer<typeof ElicitationRespondResultSchema>;
189
355
 
190
356
  /** The routing fields of an envelope — strict, because the wire owns them. */
191
357
  const WireEventEnvelopeHeaderSchema = z.object({
192
358
  sessionId: z.string(),
193
359
  seq: z.number().int().positive(),
360
+ live: z.literal(true).optional(),
194
361
  });
362
+ // @ref LLP 0002#snapshots-win-over-deltas — a frame no one keeps says so
363
+ /**
364
+ * One frame of a session as sent on the wire. `seq` is per-session,
365
+ * monotonic, and starts at 1. A frame the server does not keep says
366
+ * `live: true`: a token delta, or an open part sent after a subscription (a
367
+ * `message.part` carrying the part's content so far). It takes no seq of its
368
+ * own, carries that of the last kept event before it (fold it with
369
+ * `SeqCursor.advanceLive`; `isLiveEnvelope` tells), and replay and history
370
+ * never return it. The envelope duplicates `sessionId` so consumers can route
371
+ * without parsing the event body.
372
+ */
373
+ export const WireEventEnvelopeSchema = WireEventEnvelopeHeaderSchema.extend({
374
+ event: LifecycleEventSchema,
375
+ });
376
+ export type WireEventEnvelope = z.infer<typeof WireEventEnvelopeSchema>;
195
377
 
196
- /** An envelope whose event was decoded the Law-6 way (unknowns preserved). */
197
- export interface DecodedWireEventEnvelope {
198
- sessionId: string;
199
- seq: number;
378
+ /** An envelope whose event was decoded tolerantly (unknowns preserved). */
379
+ export interface DecodedWireEventEnvelope extends Omit<WireEventEnvelope, "event"> {
200
380
  event: DecodedLifecycleEvent | UnknownEvent;
201
381
  }
202
382
 
@@ -211,34 +391,11 @@ export function decodeWireEventEnvelope(value: unknown): DecodedWireEventEnvelop
211
391
  return {
212
392
  sessionId: header.sessionId,
213
393
  seq: header.seq,
394
+ ...(header.live && { live: true }),
214
395
  event: decodeLifecycleEvent((value as { event?: unknown }).event),
215
396
  };
216
397
  }
217
398
 
218
- /** `events/replay` with its envelopes decoded leniently. */
219
- export interface DecodedEventsReplayResult {
220
- events: DecodedWireEventEnvelope[];
221
- firstAvailableSeq: number | null;
222
- latestSeq: number | null;
223
- }
224
-
225
- /**
226
- * The replay result, decoded envelope-by-envelope. `EventsReplayResultSchema`
227
- * embeds the CLOSED event union, so parsing a buffer with it makes one unknown
228
- * event type poison the whole replay — the healing path for a gap must not be
229
- * the thing that cannot survive an unknown.
230
- */
231
- export function decodeEventsReplayResult(value: unknown): DecodedEventsReplayResult {
232
- const parsed = z
233
- .object({
234
- events: z.array(z.unknown()),
235
- firstAvailableSeq: z.number().int().positive().nullable(),
236
- latestSeq: z.number().int().positive().nullable(),
237
- })
238
- .parse(value);
239
- return { ...parsed, events: parsed.events.map((event) => decodeWireEventEnvelope(event)) };
240
- }
241
-
242
399
  export const EventsReplayParamsSchema = z.object({
243
400
  sessionId: z.string(),
244
401
  /** Replay buffered events with `seq >= fromSeq`. */
@@ -249,15 +406,35 @@ export type EventsReplayParams = z.infer<typeof EventsReplayParamsSchema>;
249
406
  /**
250
407
  * Replay is served from a bounded per-session ring buffer. When
251
408
  * `firstAvailableSeq > fromSeq`, the requested prefix was evicted and the gap
252
- * is unfillable — the consumer must treat its local view as stale.
409
+ * is unfillable — the consumer must treat its local view as stale. A durable
410
+ * server keeps every event and answers in pages: `hasMore` asks for the next.
253
411
  */
254
412
  export const EventsReplayResultSchema = z.object({
255
413
  events: z.array(WireEventEnvelopeSchema),
256
414
  firstAvailableSeq: z.number().int().positive().nullable(),
257
415
  latestSeq: z.number().int().positive().nullable(),
416
+ hasMore: z.boolean().optional(),
258
417
  });
259
418
  export type EventsReplayResult = z.infer<typeof EventsReplayResultSchema>;
260
419
 
420
+ /** `events/replay` with its envelopes decoded leniently. */
421
+ export interface DecodedEventsReplayResult extends Omit<EventsReplayResult, "events"> {
422
+ events: DecodedWireEventEnvelope[];
423
+ }
424
+ /** A replay result with its events left to decode one by one. */
425
+ const ReplayResultFrameSchema = EventsReplayResultSchema.extend({ events: z.array(z.unknown()) });
426
+
427
+ /**
428
+ * The replay result, decoded envelope-by-envelope. `EventsReplayResultSchema`
429
+ * embeds the CLOSED event union, so parsing a buffer with it makes one unknown
430
+ * event type poison the whole replay — the healing path for a gap must not be
431
+ * the thing that cannot survive an unknown.
432
+ */
433
+ export function decodeEventsReplayResult(value: unknown): DecodedEventsReplayResult {
434
+ const parsed = ReplayResultFrameSchema.parse(value);
435
+ return { ...parsed, events: parsed.events.map((event) => decodeWireEventEnvelope(event)) };
436
+ }
437
+
261
438
  /**
262
439
  * `models/list`: the models a harness offers, read from its CLI for the login
263
440
  * and folder a turn with the same `cwd`, `env` and `apiKey` would use (Claude
@@ -276,10 +453,158 @@ export const ModelsListParamsSchema = z.object({
276
453
  });
277
454
  export type ModelsListParams = z.infer<typeof ModelsListParamsSchema>;
278
455
 
279
- /** Never an error for an available harness: without a live list it is the catalog, with `error`. */
280
- export const ModelsListResultSchema = ModelListSchema;
456
+ /**
457
+ * `turn/get`: a durable turn's receipt. Admission records it, with the input,
458
+ * before the `turn/start` ack, so a turn whose process died before its first
459
+ * event is still known; `interrupted` means a restart cut it off.
460
+ */
461
+ export const TurnGetParamsSchema = z.object({ sessionId: z.string(), turnId: z.string() });
462
+ export type TurnGetParams = z.infer<typeof TurnGetParamsSchema>;
463
+ export const TurnReceiptSchema = TurnGetParamsSchema.extend({
464
+ state: z.enum(["admitted", "completed", "interrupted"]),
465
+ input: AgentInputSchema.optional(),
466
+ terminal: TurnEndedEventSchema.optional(),
467
+ });
468
+ export type TurnReceipt = z.infer<typeof TurnReceiptSchema>;
469
+
470
+ /** `session/get`: what a durable server knows about a session. */
471
+ export const SessionGetParamsSchema = z.object({ sessionId: z.string() });
472
+ export type SessionGetParams = z.infer<typeof SessionGetParamsSchema>;
473
+ /**
474
+ * Why a restart could not lift a session's fence: `not_owned`, a host's own
475
+ * spawner started its agent; `not_verified`, nothing could tell whether its
476
+ * process still runs (no sweep, no process table, a pid it may not signal);
477
+ * `not_stopped`, it was still there after SIGKILL.
478
+ */
479
+ export const RECOVERY_REASONS = ["not_owned", "not_verified", "not_stopped"] as const;
480
+ export const RecoveryReasonSchema = z.enum(RECOVERY_REASONS);
481
+ export type RecoveryReason = z.infer<typeof RecoveryReasonSchema>;
482
+
483
+ export const DurableSessionSchema = z.object({
484
+ sessionId: z.string(),
485
+ harness: AgentHarnessSchema,
486
+ /** The seq of its latest event; 0 before the first. */
487
+ headSeq: z.number().int().nonnegative(),
488
+ nativeSessionId: z.string().nullable(),
489
+ closed: z.boolean(),
490
+ /**
491
+ * A restart cut off a turn and could not confirm its agent stopped: see
492
+ * `recoveryRequired` and `session/confirmStopped`.
493
+ */
494
+ recoveryRequired: z.boolean(),
495
+ /** Why, while `recoveryRequired` is set. */
496
+ recoveryReason: RecoveryReasonSchema.optional(),
497
+ });
498
+ export type DurableSession = z.infer<typeof DurableSessionSchema>;
499
+
500
+ /**
501
+ * `session/confirmStopped`: the caller checked that the native execution a
502
+ * restart cut off is no longer running (history alone cannot prove that a
503
+ * detached agent or tool process died). `expectedHeadSeq` fences a stale
504
+ * confirmation against a newer interruption.
505
+ */
506
+ export const SessionConfirmStoppedParamsSchema = z.object({
507
+ sessionId: z.string(),
508
+ expectedHeadSeq: z.number().int().nonnegative(),
509
+ confirmedStopped: z.literal(true),
510
+ });
511
+ export type SessionConfirmStoppedParams = z.infer<typeof SessionConfirmStoppedParamsSchema>;
512
+ /** `recovered: false` when nothing awaited confirmation. */
513
+ export const SessionConfirmStoppedResultSchema = z.object({ recovered: z.boolean() });
514
+ export type SessionConfirmStoppedResult = z.infer<typeof SessionConfirmStoppedResultSchema>;
515
+
516
+ /**
517
+ * `session/release`: let an idle session's agent go (its process and what it
518
+ * holds, a Codex home included) while the session stays open. Its next turn
519
+ * names its native conversation (`config.resumeSessionId`; until then
520
+ * `resumeRequired`), as after a restart. `session/close` ends a session;
521
+ * this only frees what it runs on. Nothing is broadcast: another client of
522
+ * the session learns of it when its next turn is refused `resumeRequired`,
523
+ * whose data names the conversation, the answer a client that survives a
524
+ * restart already handles.
525
+ */
526
+ export const SessionReleaseParamsSchema = z.object({ sessionId: z.string() });
527
+ export type SessionReleaseParams = z.infer<typeof SessionReleaseParamsSchema>;
528
+ /** `released: false` when the server holds no open session by that id. */
529
+ export const SessionReleaseResultSchema = z.object({ released: z.boolean() });
530
+ export type SessionReleaseResult = z.infer<typeof SessionReleaseResultSchema>;
531
+
532
+ // @ref LLP 0008#ordering-joining-without-a-gap-or-a-duplicate — the answer marks the point
533
+ /**
534
+ * `session/subscribe`: stream a session to this connection. The answer marks
535
+ * the subscription point in the connection's frames. After it come, first,
536
+ * the session's open parts (`live` `message.part` frames at `headSeq`), then
537
+ * every kept event after `headSeq` and every delta after the point, each
538
+ * once. Kept events up to `headSeq` the caller does not hold it reads with
539
+ * `events/replay`: the server pushes no catch-up. Subscribing again answers
540
+ * a new point and sends the open parts again; no other frame is sent twice.
541
+ *
542
+ * Without `turnId` the connection watches the session until it unsubscribes
543
+ * or the session ends; with one it follows that turn, while it runs, until
544
+ * its `turn.ended` (a turn that is not running subscribes nothing, and the
545
+ * answer's `activeTurn` says so). Refused `unknownSession` when the server has
546
+ * no log for the session (it never ran, or it was closed), and
547
+ * `subscriptionLimit` past the connection's cap, which counts the sessions it
548
+ * watches (`session/subscribeAll` once), never the turns it follows.
549
+ */
550
+ export const SessionSubscribeParamsSchema = z.object({
551
+ sessionId: z.string().min(1),
552
+ /** Follow this running turn of the session, until it ends, instead of watching the session. */
553
+ turnId: z.string().min(1).optional(),
554
+ });
555
+ export type SessionSubscribeParams = z.infer<typeof SessionSubscribeParamsSchema>;
556
+ /** The turn a session runs at a subscription point. */
557
+ export const RunningTurnSchema = z.object({
558
+ turnId: z.string(),
559
+ /** Once its `turn.started` is kept: where to catch up on the turn from. */
560
+ startedSeq: z.number().int().positive().optional(),
561
+ });
562
+ export type RunningTurn = z.infer<typeof RunningTurnSchema>;
563
+ export const SessionSubscribeResultSchema = z.object({
564
+ /** The session's last kept seq at the subscription point (0: none yet). */
565
+ headSeq: z.number().int().nonnegative(),
566
+ /** The oldest kept seq replay still holds (null: none): a ring may have evicted what a catch-up needs. */
567
+ firstAvailableSeq: z.number().int().positive().nullable(),
568
+ /** The turn running at the point. */
569
+ activeTurn: RunningTurnSchema.optional(),
570
+ });
571
+ export type SessionSubscribeResult = z.infer<typeof SessionSubscribeResultSchema>;
572
+ /**
573
+ * `session/subscribeAll`: stream every session to this connection, live from
574
+ * now, with no catch-up: for observers. It counts once against the cap.
575
+ */
576
+ export const SessionSubscribeAllParamsSchema = z.object({});
577
+ /** Each session with a running turn, at its point; their open parts follow. */
578
+ export const SessionSubscribeAllResultSchema = z.object({
579
+ sessions: z.array(SessionSubscribeResultSchema.extend({ sessionId: z.string() })),
580
+ });
581
+ export type SessionSubscribeAllResult = z.infer<typeof SessionSubscribeAllResultSchema>;
582
+
583
+ /**
584
+ * `session/unsubscribe`: stop watching a session. A turn the connection
585
+ * follows streams on until it ends.
586
+ */
587
+ export const SessionUnsubscribeParamsSchema = z.object({ sessionId: z.string().min(1) });
588
+ export type SessionUnsubscribeParams = z.infer<typeof SessionUnsubscribeParamsSchema>;
589
+ /** `session/unsubscribeAll`: stop streaming every session; those watched by name stream on. */
590
+ export const SessionUnsubscribeAllParamsSchema = z.object({});
591
+ /** `unsubscribed: false` when this connection did not watch it (or every session). */
592
+ export const SessionUnsubscribeResultSchema = z.object({ unsubscribed: z.boolean() });
593
+ export type SessionUnsubscribeResult = z.infer<typeof SessionUnsubscribeResultSchema>;
594
+
595
+ /**
596
+ * `session/overflow` (server -> client): this connection fell
597
+ * `maxBacklogBytes` behind, so the server stopped sending the session after
598
+ * `lastSeq`, the last kept seq it sent, and dropped the subscription.
599
+ * Subscribe again after the last seq you hold; its open parts come with it.
600
+ * `{all: true}`: the subscription to every session was dropped.
601
+ */
602
+ export const SessionOverflowParamsSchema = z.union([
603
+ z.object({ sessionId: z.string(), lastSeq: z.number().int().nonnegative() }),
604
+ z.object({ all: z.literal(true) }),
605
+ ]);
606
+ export type SessionOverflowParams = z.infer<typeof SessionOverflowParamsSchema>;
281
607
 
282
- export const ShutdownParamsSchema = z.object({}).optional();
283
608
  export const ShutdownResultSchema = z.object({});
284
609
 
285
610
  // ---- codec -------------------------------------------------------------------
@@ -290,8 +615,8 @@ export type WireMessage =
290
615
  | { kind: "notification"; method: string; params?: unknown }
291
616
  /** `id` is null on protocol-level errors answering unparseable requests. */
292
617
  | { kind: "response"; id: JsonRpcId | null; result?: unknown; error?: JsonRpcError }
293
- /** The decoder sets parseError; optional for existing callers constructing invalid messages. */
294
- | { kind: "invalid"; error: string; parseError?: boolean };
618
+ /** `parseError`: the line was not JSON at all (JSON-RPC's -32700), not just a bad envelope. */
619
+ | { kind: "invalid"; error: string; parseError: boolean };
295
620
 
296
621
  /** Decode one NDJSON line into a JSON-RPC message (never throws). */
297
622
  export function decodeWireMessage(line: string): WireMessage {
@@ -354,11 +679,17 @@ export function encodeErrorResponse(
354
679
 
355
680
  /**
356
681
  * A duplex line channel the wire runs over. Implementations exist for stdio,
357
- * WebSocket, and in-memory pairs (tests). Handlers registered after close are
358
- * never called; `send` after close is a silent no-op.
682
+ * WebSocket, and in-process pairs (`channelPair`). Handlers registered after
683
+ * close are never called; `send` after close is a silent no-op.
359
684
  */
360
685
  export interface WireTransport {
361
686
  send(line: string): void;
687
+ /**
688
+ * Bytes sent but not yet written out (a socket's buffered amount, a pipe's
689
+ * writable length), where the channel can tell: the server stops streaming
690
+ * a session to a connection this far behind (`session/overflow`).
691
+ */
692
+ bufferedAmount?(): number;
362
693
  /** Register a line handler; returns an unsubscribe function. */
363
694
  onLine(handler: (line: string) => void): () => void;
364
695
  /** Register a close handler; returns an unsubscribe function. */
@@ -385,10 +716,14 @@ export function pushNdjsonLines(push: (line: string) => void, data: unknown): vo
385
716
  /**
386
717
  * Build a WireTransport from a raw byte-channel binding: the caller supplies
387
718
  * the outbound `send`/`close`, and pushes inbound lines / close through the
388
- * returned handles. Every concrete transport (stdio, WebSocket, memory pair)
719
+ * returned handles. Every concrete transport (stdio, WebSocket, `channelPair`)
389
720
  * is this bridge plus platform wiring.
390
721
  */
391
- export function channelTransport(io: { send(line: string): void; close?(): void }): {
722
+ export function channelTransport(io: {
723
+ send(line: string): void;
724
+ close?(): void;
725
+ bufferedAmount?(): number;
726
+ }): {
392
727
  transport: WireTransport;
393
728
  push(line: string): void;
394
729
  end(reason?: string): void;
@@ -405,10 +740,12 @@ export function channelTransport(io: { send(line: string): void; close?(): void
405
740
  closeHandlers.clear();
406
741
  };
407
742
 
743
+ const { bufferedAmount } = io;
408
744
  const transport: WireTransport = {
409
745
  send(line) {
410
746
  if (!closed) io.send(line);
411
747
  },
748
+ ...(bufferedAmount && { bufferedAmount: () => bufferedAmount.call(io) }),
412
749
  onLine(handler) {
413
750
  lineHandlers.add(handler);
414
751
  return () => lineHandlers.delete(handler);
@@ -436,3 +773,34 @@ export function channelTransport(io: { send(line: string): void; close?(): void
436
773
  end,
437
774
  };
438
775
  }
776
+
777
+ /**
778
+ * Two transports wired to each other in one process: the in-process wire
779
+ * between an `AgentServer` and its client (`server.attach(pair.server)`,
780
+ * `AgentServerClient.attach(pair.client)`). `deliver` schedules each line's
781
+ * arrival, a microtask later by default, as a socket's arrives on a later
782
+ * tick; `kill` drops the connection at both ends.
783
+ */
784
+ export function channelPair(deliver: (arrive: () => void) => void = queueMicrotask): {
785
+ client: WireTransport;
786
+ server: WireTransport;
787
+ kill(reason?: string): void;
788
+ } {
789
+ type Channel = ReturnType<typeof channelTransport>;
790
+ const ends: Channel[] = [];
791
+ const end = (peer: number) =>
792
+ channelTransport({
793
+ send: (line) => deliver(() => ends[peer]?.push(line)),
794
+ close: () => deliver(() => ends[peer]?.end("peer closed")),
795
+ });
796
+ ends.push(end(1), end(0));
797
+ const [client, server] = ends as [Channel, Channel];
798
+ return {
799
+ client: client.transport,
800
+ server: server.transport,
801
+ kill(reason = "connection dropped") {
802
+ client.end(reason);
803
+ server.end(reason);
804
+ },
805
+ };
806
+ }