agents 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/README.md +8 -9
  2. package/dist/abortable-C1SpfVoi.js +21 -0
  3. package/dist/abortable-C1SpfVoi.js.map +1 -0
  4. package/dist/{agent-routing-0DR0Tk2v.d.ts → agent-routing-QDcchcQP.d.ts} +16 -16
  5. package/dist/agent-routing.d.ts +1 -1
  6. package/dist/agent-tool-types.d.ts +1 -1
  7. package/dist/{agent-tools-YrATZJu2.d.ts → agent-tools-DHL2XI7u.d.ts} +2 -2
  8. package/dist/agent-tools.d.ts +1 -1
  9. package/dist/ai-ahruGw7e.d.ts +239 -0
  10. package/dist/ai-sdk-Bdsf6mSA.js +2444 -0
  11. package/dist/ai-sdk-Bdsf6mSA.js.map +1 -0
  12. package/dist/apply-chunks-1FheRb9W.js +99 -0
  13. package/dist/apply-chunks-1FheRb9W.js.map +1 -0
  14. package/dist/broadcast-state-CEyI4uAK.js +69 -0
  15. package/dist/broadcast-state-CEyI4uAK.js.map +1 -0
  16. package/dist/browser/ai.d.ts +8 -227
  17. package/dist/browser/ai.js +259 -1
  18. package/dist/browser/ai.js.map +1 -0
  19. package/dist/browser/index.d.ts +56 -46
  20. package/dist/browser/index.js +4 -361
  21. package/dist/browser/{ai-sdk.d.ts → tools/ai-sdk.d.ts} +7 -7
  22. package/dist/browser/{ai-sdk.js → tools/ai-sdk.js} +6 -5
  23. package/dist/browser/tools/ai-sdk.js.map +1 -0
  24. package/dist/browser/tools/pi.d.ts +111 -0
  25. package/dist/browser/tools/pi.js +119 -0
  26. package/dist/browser/tools/pi.js.map +1 -0
  27. package/dist/browser/{tanstack-ai.d.ts → tools/tanstack-ai.d.ts} +39 -37
  28. package/dist/browser/{tanstack-ai.js → tools/tanstack-ai.js} +73 -59
  29. package/dist/browser/tools/tanstack-ai.js.map +1 -0
  30. package/dist/browser-CEdNlsaD.js +481 -0
  31. package/dist/browser-CEdNlsaD.js.map +1 -0
  32. package/dist/{browser-DE3d-RLk.d.ts → browser-D30VlpcA.d.ts} +63 -37
  33. package/dist/{browser-tool-CQ10e6Kj.js → browser-tool-4iomavs_.js} +198 -62
  34. package/dist/browser-tool-4iomavs_.js.map +1 -0
  35. package/dist/{browser-tool-DuNdlwZ9.d.ts → browser-tool-vtrPOV8e.d.ts} +25 -6
  36. package/dist/{capability-B4WbF81e.js → capability-DBAKc6UZ.js} +1 -3
  37. package/dist/capability-DBAKc6UZ.js.map +1 -0
  38. package/dist/{capability-runner-DBAnGr6L.d.ts → capability-runner-BiVUtjqC.d.ts} +9 -7
  39. package/dist/channel-Bak_6zDP.d.ts +333 -0
  40. package/dist/chat/index.d.ts +11 -9
  41. package/dist/chat/index.js +5 -194
  42. package/dist/chat/index.js.map +1 -1
  43. package/dist/chat/react.d.ts +2 -4
  44. package/dist/chat/react.js +3 -1
  45. package/dist/chat/react.js.map +1 -1
  46. package/dist/chat-sdk/index.d.ts +1 -1
  47. package/dist/chat-sdk/index.js +1 -1
  48. package/dist/cli.js +144 -0
  49. package/dist/{client-je3koD9Z.d.ts → client-BGIQKJhX.d.ts} +2 -2
  50. package/dist/{client-fyQrLGkD.js → client-BnYbNT3z.js} +29 -5
  51. package/dist/client-BnYbNT3z.js.map +1 -0
  52. package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
  53. package/dist/client.d.ts +1 -1
  54. package/dist/{connector-58XDGvc3.js → connector-CtZylXdk.js} +3 -603
  55. package/dist/connector-CtZylXdk.js.map +1 -0
  56. package/dist/{connector-Cl-VqPmA.d.ts → connector-DEXzVoaY.d.ts} +9 -374
  57. package/dist/conversations-FjHDRZyD.d.ts +192 -0
  58. package/dist/{current-agent-vAk_5JMt.d.ts → current-agent-CKgT5d1O.d.ts} +3 -5
  59. package/dist/current-agent-DhoDkSnH.js.map +1 -1
  60. package/dist/daemon-core-Buubj-y1.js +481 -0
  61. package/dist/daemon-core-Buubj-y1.js.map +1 -0
  62. package/dist/daemon-core-CbohVPAu.d.ts +132 -0
  63. package/dist/{do-oauth-client-provider-Tmf1vgKz.d.ts → do-oauth-client-provider-DfsUcpc3.d.ts} +7 -1
  64. package/dist/{durable-object-lifecycle-HhgOMWq9.d.ts → durable-object-lifecycle-DOI_bzCH.d.ts} +2 -2
  65. package/dist/{channels/email.d.ts → experimental/channels/email/index.d.ts} +25 -12
  66. package/dist/{channels/email.js → experimental/channels/email/index.js} +13 -35
  67. package/dist/experimental/channels/email/index.js.map +1 -0
  68. package/dist/experimental/channels/index.d.ts +270 -0
  69. package/dist/experimental/channels/index.js +1186 -0
  70. package/dist/experimental/channels/index.js.map +1 -0
  71. package/dist/{channels/slack.d.ts → experimental/channels/slack/index.d.ts} +19 -9
  72. package/dist/experimental/channels/slack/index.js +267 -0
  73. package/dist/experimental/channels/slack/index.js.map +1 -0
  74. package/dist/{channels/telegram.d.ts → experimental/channels/telegram/index.d.ts} +19 -9
  75. package/dist/experimental/channels/telegram/index.js +198 -0
  76. package/dist/experimental/channels/telegram/index.js.map +1 -0
  77. package/dist/experimental/channels/web/ai-sdk.d.ts +55 -0
  78. package/dist/experimental/channels/web/ai-sdk.js +266 -0
  79. package/dist/experimental/channels/web/ai-sdk.js.map +1 -0
  80. package/dist/experimental/channels/web/client.d.ts +97 -0
  81. package/dist/experimental/channels/web/client.js +349 -0
  82. package/dist/experimental/channels/web/client.js.map +1 -0
  83. package/dist/experimental/channels/web/index.d.ts +189 -0
  84. package/dist/experimental/channels/web/index.js +332 -0
  85. package/dist/experimental/channels/web/index.js.map +1 -0
  86. package/dist/gateway-BFO6vRDn.d.ts +100 -0
  87. package/dist/handle-zAzh0UW2.d.ts +460 -0
  88. package/dist/harness/ai-sdk/index.d.ts +175 -0
  89. package/dist/harness/ai-sdk/index.js +605 -0
  90. package/dist/harness/ai-sdk/index.js.map +1 -0
  91. package/dist/harness/container/daemon/index.d.ts +76 -0
  92. package/dist/harness/container/daemon/index.js +3 -0
  93. package/dist/harness/container/index.d.ts +740 -0
  94. package/dist/harness/container/index.js +2152 -0
  95. package/dist/harness/container/index.js.map +1 -0
  96. package/dist/harness/container/runtime/index.d.ts +144 -0
  97. package/dist/harness/container/runtime/index.js +1082 -0
  98. package/dist/harness/container/runtime/index.js.map +1 -0
  99. package/dist/harness/opencode/index.d.ts +369 -0
  100. package/dist/harness/opencode/index.js +1072 -0
  101. package/dist/harness/opencode/index.js.map +1 -0
  102. package/dist/harness/pi/index.d.ts +3 -2
  103. package/dist/harness/pi/index.js +3 -3
  104. package/dist/harness/store/index.d.ts +24 -0
  105. package/dist/harness/store/index.js +2 -0
  106. package/dist/harness/think/index.d.ts +821 -0
  107. package/dist/harness/think/index.js +2721 -0
  108. package/dist/harness/think/index.js.map +1 -0
  109. package/dist/harness-B6B9S3rb.d.ts +203 -0
  110. package/dist/{images-iiTDSyRu.js → images-Ce9SCu3X.js} +2 -248
  111. package/dist/images-Ce9SCu3X.js.map +1 -0
  112. package/dist/{index-BreL0YrQ.d.ts → index-BEL3ZV-s.d.ts} +2 -6
  113. package/dist/index-CBt8oRJt.d.ts +198 -0
  114. package/dist/index.d.ts +5 -5
  115. package/dist/index.js +2 -2
  116. package/dist/ingress-EFbrS547.js +9 -0
  117. package/dist/ingress-EFbrS547.js.map +1 -0
  118. package/dist/input-schema-BQykTEp_.js +20 -0
  119. package/dist/input-schema-BQykTEp_.js.map +1 -0
  120. package/dist/input-schema-D2QAtHZH.js +23 -0
  121. package/dist/input-schema-D2QAtHZH.js.map +1 -0
  122. package/dist/internal-kmw70xwR.js +46 -0
  123. package/dist/internal-kmw70xwR.js.map +1 -0
  124. package/dist/internal_context.d.ts +1 -1
  125. package/dist/lifecycle/index.d.ts +3 -3
  126. package/dist/lifecycle/index.js +2 -2
  127. package/dist/{lifecycle-CFu6OV03.js → lifecycle-DGorpAmA.js} +2 -4
  128. package/dist/lifecycle-DGorpAmA.js.map +1 -0
  129. package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
  130. package/dist/mcp/client/do-oauth-client-provider.js +9 -0
  131. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
  132. package/dist/mcp/client/index.d.ts +1 -1
  133. package/dist/mcp/client/index.js +1 -1
  134. package/dist/mcp/client/x402.d.ts +35 -4
  135. package/dist/mcp/client/x402.js +24 -3
  136. package/dist/mcp/client/x402.js.map +1 -1
  137. package/dist/mcp/index.d.ts +1 -1
  138. package/dist/mcp/index.js +2 -2
  139. package/dist/models/ai-sdk/index.d.ts +16 -14
  140. package/dist/models/ai-sdk/index.js +1 -2442
  141. package/dist/models/opencode/index.d.ts +65 -0
  142. package/dist/models/opencode/index.js +285 -0
  143. package/dist/models/opencode/index.js.map +1 -0
  144. package/dist/models/pi-ai/index.d.ts +9 -7
  145. package/dist/models/pi-ai/index.js +2 -1
  146. package/dist/models/pi-ai/index.js.map +1 -1
  147. package/dist/options-CiIsJHXR.d.ts +130 -0
  148. package/dist/protocol-BEgrJYC5.d.ts +331 -0
  149. package/dist/protocol-CukuI73M.d.ts +386 -0
  150. package/dist/protocol-cOklVBBD.js +227 -0
  151. package/dist/protocol-cOklVBBD.js.map +1 -0
  152. package/dist/{protocol-kHsr-f0X.js → protocol-eXeJxhgu.js} +2 -67
  153. package/dist/protocol-eXeJxhgu.js.map +1 -0
  154. package/dist/protocol-y2sSY584.js +148 -0
  155. package/dist/protocol-y2sSY584.js.map +1 -0
  156. package/dist/queue/index.d.ts +1 -1
  157. package/dist/queue/index.js +1 -1
  158. package/dist/{queue-BB-zfIYF.js → queue-CcIjVYTE.js} +2 -2
  159. package/dist/{queue-BB-zfIYF.js.map → queue-CcIjVYTE.js.map} +1 -1
  160. package/dist/react.d.ts +2 -2
  161. package/dist/routing/index.d.ts +2 -2
  162. package/dist/routing/index.js +1 -1
  163. package/dist/{scheduler-RdACNXDP.d.ts → scheduler-BCLESHSC.d.ts} +2 -12
  164. package/dist/{scheduler-DZ3xQfeK.js → scheduler-FIHv2-kJ.js} +2 -4
  165. package/dist/scheduler-FIHv2-kJ.js.map +1 -0
  166. package/dist/schedules/index.d.ts +1 -1
  167. package/dist/schedules/index.js +1 -1
  168. package/dist/serializable.d.ts +1 -1
  169. package/dist/session-store-Do4xkDcf.js +606 -0
  170. package/dist/session-store-Do4xkDcf.js.map +1 -0
  171. package/dist/session-store-DoPY12xM.d.ts +383 -0
  172. package/dist/sessions/index.d.ts +11 -434
  173. package/dist/sessions/index.js +1 -2271
  174. package/dist/sessions-_vN5BEZX.js +2272 -0
  175. package/dist/sessions-_vN5BEZX.js.map +1 -0
  176. package/dist/settings-C45hDliX.js +253 -0
  177. package/dist/settings-C45hDliX.js.map +1 -0
  178. package/dist/{transport-PfFnt-Ld.d.ts → settings-NgGwF7Qt.d.ts} +14 -208
  179. package/dist/{src-BZeu-SCD.js → src-CQxJFv4l.js} +8 -8
  180. package/dist/src-CQxJFv4l.js.map +1 -0
  181. package/dist/stall-watchdog-BpRF2uwG.js +195 -0
  182. package/dist/stall-watchdog-BpRF2uwG.js.map +1 -0
  183. package/dist/state/index.d.ts +1 -1
  184. package/dist/state/index.js +1 -3
  185. package/dist/state/index.js.map +1 -1
  186. package/dist/store-BKM4Xm9M.d.ts +332 -0
  187. package/dist/store-CslVzfN7.js +458 -0
  188. package/dist/store-CslVzfN7.js.map +1 -0
  189. package/dist/streams/index.d.ts +1 -1
  190. package/dist/streams/index.js +1 -1
  191. package/dist/{streams-DW-UCOUc.js → streams-lsHMJhRW.js} +17 -4
  192. package/dist/streams-lsHMJhRW.js.map +1 -0
  193. package/dist/{streams-Cmkj9QfW.d.ts → streams-vrCtbUIn.d.ts} +2 -2
  194. package/dist/sub-routing.d.ts +1 -1
  195. package/dist/tasks/index.d.ts +1 -1
  196. package/dist/tasks/index.js +1 -1
  197. package/dist/{tasks-68DESxf0.js → tasks-BN_5AWqI.js} +3 -2
  198. package/dist/tasks-BN_5AWqI.js.map +1 -0
  199. package/dist/{tasks-9YxYtByh.d.ts → tasks-E89KdwkS.d.ts} +2 -2
  200. package/dist/tool-CTp72Jb_.d.ts +278 -0
  201. package/dist/tool-CxKsvxjm.js +1126 -0
  202. package/dist/tool-CxKsvxjm.js.map +1 -0
  203. package/dist/tool-DoVberpN.d.ts +301 -0
  204. package/dist/tool-cQRkwSZZ.js +410 -0
  205. package/dist/tool-cQRkwSZZ.js.map +1 -0
  206. package/dist/tool-helpers-O5BDVEAY.js +58 -0
  207. package/dist/tool-helpers-O5BDVEAY.js.map +1 -0
  208. package/dist/transport-k2mFrtL8.d.ts +200 -0
  209. package/dist/turns-DCV3ycDl.js +317 -0
  210. package/dist/turns-DCV3ycDl.js.map +1 -0
  211. package/dist/voice/client.js +1 -1
  212. package/dist/voice/index.d.ts +2 -2
  213. package/dist/voice/index.js +1 -1
  214. package/dist/web/fetch/index.d.ts +89 -0
  215. package/dist/web/fetch/index.js +20 -0
  216. package/dist/web/fetch/index.js.map +1 -0
  217. package/dist/web/fetch/tools/ai-sdk.d.ts +80 -0
  218. package/dist/web/fetch/tools/ai-sdk.js +47 -0
  219. package/dist/web/fetch/tools/ai-sdk.js.map +1 -0
  220. package/dist/web/fetch/tools/pi.d.ts +84 -0
  221. package/dist/web/fetch/tools/pi.js +88 -0
  222. package/dist/web/fetch/tools/pi.js.map +1 -0
  223. package/dist/web/fetch/tools/tanstack-ai.d.ts +78 -0
  224. package/dist/web/fetch/tools/tanstack-ai.js +45 -0
  225. package/dist/web/fetch/tools/tanstack-ai.js.map +1 -0
  226. package/dist/web/search/index.d.ts +58 -0
  227. package/dist/web/search/index.js +2 -0
  228. package/dist/web/search/tools/ai-sdk.d.ts +77 -0
  229. package/dist/web/search/tools/ai-sdk.js +46 -0
  230. package/dist/web/search/tools/ai-sdk.js.map +1 -0
  231. package/dist/web/search/tools/pi.d.ts +82 -0
  232. package/dist/web/search/tools/pi.js +89 -0
  233. package/dist/web/search/tools/pi.js.map +1 -0
  234. package/dist/web/search/tools/tanstack-ai.d.ts +71 -0
  235. package/dist/web/search/tools/tanstack-ai.js +46 -0
  236. package/dist/web/search/tools/tanstack-ai.js.map +1 -0
  237. package/dist/websockets/index.d.ts +12 -296
  238. package/dist/websockets/index.js +1 -1
  239. package/dist/{websockets-Ci-LZFHH.js → websockets-C3zy8YR0.js} +20 -8
  240. package/dist/websockets-C3zy8YR0.js.map +1 -0
  241. package/dist/{wire-types-CrjKvDyi.d.ts → wire-types-Cv0iwjk5.d.ts} +3 -51
  242. package/dist/workflow-types.d.ts +1 -1
  243. package/dist/workflows.d.ts +1 -1
  244. package/dist/workflows.js +1 -1
  245. package/docs/browse-the-web.md +29 -1
  246. package/docs/fetch-the-web.md +276 -0
  247. package/docs/harnesses/pi.md +25 -0
  248. package/docs/harnesses/think.md +215 -0
  249. package/docs/index.md +99 -75
  250. package/docs/lifecycle.md +42 -3
  251. package/docs/queue.md +2 -3
  252. package/docs/scheduling.md +2 -6
  253. package/docs/search-the-web.md +135 -0
  254. package/package.json +148 -44
  255. package/dist/ai-fm7xx1BK.js +0 -312
  256. package/dist/ai-fm7xx1BK.js.map +0 -1
  257. package/dist/browser/ai-sdk.js.map +0 -1
  258. package/dist/browser/index.js.map +0 -1
  259. package/dist/browser/tanstack-ai.js.map +0 -1
  260. package/dist/browser-tool-CQ10e6Kj.js.map +0 -1
  261. package/dist/capability-B4WbF81e.js.map +0 -1
  262. package/dist/channel-Bnm4S7T2.d.ts +0 -491
  263. package/dist/channels/ai-sdk.d.ts +0 -46
  264. package/dist/channels/ai-sdk.js +0 -120
  265. package/dist/channels/ai-sdk.js.map +0 -1
  266. package/dist/channels/email.js.map +0 -1
  267. package/dist/channels/index.d.ts +0 -233
  268. package/dist/channels/index.js +0 -608
  269. package/dist/channels/index.js.map +0 -1
  270. package/dist/channels/slack.js +0 -614
  271. package/dist/channels/slack.js.map +0 -1
  272. package/dist/channels/tanstack-ai.d.ts +0 -39
  273. package/dist/channels/tanstack-ai.js +0 -17
  274. package/dist/channels/tanstack-ai.js.map +0 -1
  275. package/dist/channels/telegram.js +0 -427
  276. package/dist/channels/telegram.js.map +0 -1
  277. package/dist/channels/voice.d.ts +0 -45
  278. package/dist/channels/voice.js +0 -122
  279. package/dist/channels/voice.js.map +0 -1
  280. package/dist/client-fyQrLGkD.js.map +0 -1
  281. package/dist/connector-58XDGvc3.js.map +0 -1
  282. package/dist/images-iiTDSyRu.js.map +0 -1
  283. package/dist/index-BB0kqhIz.d.ts +0 -101
  284. package/dist/ingress-BfetZbMO.js +0 -83
  285. package/dist/ingress-BfetZbMO.js.map +0 -1
  286. package/dist/internal-CYlgHl1l.js +0 -59
  287. package/dist/internal-CYlgHl1l.js.map +0 -1
  288. package/dist/lifecycle-CFu6OV03.js.map +0 -1
  289. package/dist/models/ai-sdk/index.js.map +0 -1
  290. package/dist/protocol-kHsr-f0X.js.map +0 -1
  291. package/dist/scheduler-DZ3xQfeK.js.map +0 -1
  292. package/dist/sessions/index.js.map +0 -1
  293. package/dist/src-BZeu-SCD.js.map +0 -1
  294. package/dist/streams-DW-UCOUc.js.map +0 -1
  295. package/dist/surface-bZZJqBka.js +0 -17
  296. package/dist/surface-bZZJqBka.js.map +0 -1
  297. package/dist/tasks-68DESxf0.js.map +0 -1
  298. package/dist/tool-schema-CBjGPrsQ.js +0 -31
  299. package/dist/tool-schema-CBjGPrsQ.js.map +0 -1
  300. package/dist/websockets-Ci-LZFHH.js.map +0 -1
  301. package/docs/channels.md +0 -323
@@ -0,0 +1,130 @@
1
+ import {
2
+ S as ConnectionContext,
3
+ T as WSMessage,
4
+ x as Connection
5
+ } from "./capability-runner-BiVUtjqC.js";
6
+ import { RpcTarget } from "cloudflare:workers";
7
+
8
+ //#region src/websockets/options.d.ts
9
+ /**
10
+ * The part of a `State` capability the WebSockets capability uses. A
11
+ * structural port, so any `State<T>` fits without a cast and the
12
+ * capability never depends on the class itself.
13
+ */
14
+ type SyncedState = {
15
+ /** Current state, or `undefined` when nothing is stored. */ get(): unknown /** Validate and persist a change; throws when the host rejects it. */;
16
+ set(nextState: never, source: Connection): void;
17
+ };
18
+ /** A frame delivered on a capability-owned WebSocket connection. */
19
+ type WebSocketMessage = WSMessage;
20
+ /**
21
+ * Connection handlers for the WebSockets capability. Handlers run inside
22
+ * the host invocation boundary with the live connection in ambient
23
+ * context (`getCurrentAgent().connection`).
24
+ */
25
+ type WebSocketHandlers = {
26
+ /** Handle a newly accepted hibernating WebSocket connection. */ onConnect?(
27
+ connection: Connection,
28
+ ctx: ConnectionContext
29
+ ): void | Promise<void>;
30
+ /**
31
+ * Handle a message from a hibernating WebSocket connection. For handlers
32
+ * added with `WebSockets.use`, returning true claims the message, so
33
+ * later handlers do not see it.
34
+ */
35
+ onMessage?(
36
+ connection: Connection,
37
+ message: WebSocketMessage
38
+ ):
39
+ | void
40
+ | boolean
41
+ | Promise<
42
+ void | boolean
43
+ > /** Handle a closing hibernating WebSocket connection. */;
44
+ onClose?(
45
+ connection: Connection,
46
+ code: number,
47
+ reason: string,
48
+ wasClean: boolean
49
+ ): void | Promise<void> /** Handle a mid-connection WebSocket error. */;
50
+ onError?(connection: Connection, error: unknown): void | Promise<void>;
51
+ };
52
+ /**
53
+ * Configuration for the WebSockets capability.
54
+ */
55
+ interface WebSocketsOptions {
56
+ /**
57
+ * Connection handlers for WebSocket clients. The capability accepts and
58
+ * tracks every WebSocket upgrade either way; handlers add behavior on
59
+ * connect, message, close and error.
60
+ */
61
+ readonly handlers?: WebSocketHandlers;
62
+ /**
63
+ * An `RpcTarget` whose prototype methods are the host's complete remote
64
+ * interface, reached through `useAgent().call` and `.stub`. On the
65
+ * `cf-websocket` wire they are answered as JSON `rpc` frames. On the
66
+ * `capnweb` wire they are native Cap'n Web methods on the session root:
67
+ * an `RpcTarget` result becomes a live stub, a `ReadableStream` streams,
68
+ * and calls pipeline. Methods run through the host invocation boundary
69
+ * with the calling connection in scope. `Agent` answers its own
70
+ * decorated methods on the JSON wire and does not set this.
71
+ */
72
+ readonly callables?: RpcTarget;
73
+ /**
74
+ * Whether a new connection gets the connect-time protocol frames —
75
+ * identity (`cf_agent_identity`), then the current state when `state`
76
+ * is set — and whether protocol frames reach it at all.
77
+ *
78
+ * - `true` (default): every connection.
79
+ * - a function: decided per connection at accept time. `false` marks
80
+ * the connection no-protocol: it gets no protocol text frames, on
81
+ * connect or via `broadcastState()`, but can still send and receive
82
+ * ordinary messages and use callables. For binary-only clients.
83
+ * - `false`: the host drives the connect sequence itself with
84
+ * `sendConnectFrames()` (or `sendIdentity()` and `sendState()`
85
+ * separately), and applies client state frames
86
+ * with `applyStateFrame()` — `Agent` does this, since it must decide
87
+ * whether a connection belongs to a facet before any frame is sent.
88
+ */
89
+ readonly protocol?:
90
+ | boolean
91
+ | ((connection: Connection, ctx: ConnectionContext) => boolean);
92
+ /**
93
+ * Decide at accept time whether a connection is readonly. A readonly
94
+ * connection's `cf_agent_state` frames are refused with
95
+ * `cf_agent_state_error`; everything else works. Also settable later
96
+ * with `setReadonly()`.
97
+ */
98
+ readonly readonly?: (
99
+ connection: Connection,
100
+ ctx: ConnectionContext
101
+ ) => boolean;
102
+ /**
103
+ * A {@link SyncedState} — normally a `State` capability — to sync over
104
+ * connections. The capability pushes the current value to each new
105
+ * connection after identity and applies `cf_agent_state` frames a
106
+ * client sends: a readonly connection is refused, and a change the
107
+ * host's validator rejects is answered with `cf_agent_state_error`.
108
+ * Broadcasting a change is the state owner's call — wire the `State`'s
109
+ * `onChanged` to `broadcastState(source)`. Install the same instance on
110
+ * the lifecycle so it owns storage and validation; without this option
111
+ * state is never sent or accepted over connections.
112
+ */
113
+ readonly state?: SyncedState;
114
+ /**
115
+ * Tags attached to each accepted connection, queryable through
116
+ * `getConnections(tag)`. The connection id is always the first tag.
117
+ */
118
+ readonly getConnectionTags?: (
119
+ connection: Connection,
120
+ ctx: ConnectionContext
121
+ ) => string[] | Promise<string[]>;
122
+ }
123
+ //#endregion
124
+ export {
125
+ WebSocketsOptions as i,
126
+ WebSocketHandlers as n,
127
+ WebSocketMessage as r,
128
+ SyncedState as t
129
+ };
130
+ //# sourceMappingURL=options-CiIsJHXR.d.ts.map
@@ -0,0 +1,331 @@
1
+ //#region src/harness/container/protocol.d.ts
2
+ /**
3
+ * The wire between `ContainerHarness` (in a Durable Object) and the harness
4
+ * daemon (in the container). Isomorphic and dependency-free: the daemon
5
+ * imports it in Node, the harness in Workers.
6
+ *
7
+ * One WebSocket per session, dialled by the object through
8
+ * `ctx.container.getTcpPort(port)` at `/sessions/<id>`. The daemon speaks
9
+ * first with `hello`; the object answers with `open` (when the daemon does
10
+ * not hold the session yet) and `replay`, then delivers `prompt`s.
11
+ *
12
+ * Everything the daemon produces for a session is a numbered `frame`. The
13
+ * numbers start at 1 for each session in each container, so a frame is
14
+ * addressed by `(runtimeId, seq)`. The daemon keeps frames until they are
15
+ * acknowledged, so an object that lost its socket (evicted, redeployed)
16
+ * replays what it missed from its cursor. A different `runtimeId` in
17
+ * `hello` means a different container: its numbering starts again, and
18
+ * whatever the old container was doing is gone.
19
+ *
20
+ * @experimental The wire may change before it stabilizes. The object and the image are
21
+ * a matched pair; a version mismatch is reported in `hello`.
22
+ */
23
+ /** Bumped on any incompatible change. */
24
+ declare const CONTAINER_PROTOCOL_VERSION = 1;
25
+ /** The daemon answers `200` here once it accepts connections. */
26
+ declare const CONTAINER_HEALTH_PATH = "/healthz";
27
+ /** The session socket: `/sessions/<encoded session id>`. */
28
+ declare const CONTAINER_SESSION_PATH = "/sessions/";
29
+ /** The shared secret the object passes on every request. */
30
+ declare const CONTAINER_TOKEN_HEADER = "x-cf-harness-token";
31
+ /** The environment variables the object starts the container with. */
32
+ declare const CONTAINER_ENV: {
33
+ /** Shared secret for `CONTAINER_TOKEN_HEADER`. */ readonly token: "CF_HARNESS_TOKEN" /** This container's id. Echoed in `hello`. */;
34
+ readonly runtimeId: "CF_HARNESS_RUNTIME_ID" /** The port the daemon listens on. */;
35
+ readonly port: "CF_HARNESS_PORT";
36
+ };
37
+ /** WebSocket close code: a newer connection for the session replaced this one. */
38
+ declare const CLOSE_REPLACED = 4001;
39
+ /** WebSocket close code: the request was not authorized. */
40
+ declare const CLOSE_UNAUTHORIZED = 4003;
41
+ /** A JSON value on the wire. */
42
+ type JsonValue =
43
+ | string
44
+ | number
45
+ | boolean
46
+ | null
47
+ | readonly JsonValue[]
48
+ | {
49
+ readonly [key: string]: JsonValue;
50
+ };
51
+ /** One part of a prompt. */
52
+ type ContainerInputPart =
53
+ | {
54
+ readonly type: "text";
55
+ readonly text: string;
56
+ }
57
+ | {
58
+ readonly type: "image" /** IANA media type, such as `image/png`. */;
59
+ readonly mediaType: string /** Base64 bytes. */;
60
+ readonly data: string;
61
+ };
62
+ /** What a prompt carries: plain text, or parts. */
63
+ type ContainerInput = string | readonly ContainerInputPart[];
64
+ /** What a submission does when the session is already running. */
65
+ type ContainerWhenBusy = "followUp" | "steer";
66
+ /**
67
+ * Per-session settings the object sends the adapter. `model` is the
68
+ * adapter's own model name; `options` is opaque to everything but the
69
+ * adapter.
70
+ */
71
+ type ContainerSettings = {
72
+ readonly model?: string;
73
+ readonly options?: JsonValue;
74
+ };
75
+ /** One part of a transcript message. */
76
+ type ContainerPart =
77
+ | {
78
+ readonly type: "text";
79
+ readonly text: string;
80
+ }
81
+ | {
82
+ readonly type: "reasoning";
83
+ readonly text: string;
84
+ }
85
+ | {
86
+ readonly type: "image";
87
+ readonly mediaType: string;
88
+ readonly data: string;
89
+ }
90
+ | {
91
+ readonly type: "tool";
92
+ readonly toolCallId: string;
93
+ readonly toolName: string;
94
+ readonly input: JsonValue;
95
+ readonly state: "running" | "done" | "error";
96
+ readonly output?: JsonValue;
97
+ };
98
+ /**
99
+ * A transcript message, in the one format every container adapter
100
+ * produces. An adapter emits a message again, under the same id, to update
101
+ * it (a tool result arriving, for example).
102
+ */
103
+ type ContainerMessage = {
104
+ readonly id: string;
105
+ readonly role: "user" | "assistant";
106
+ readonly parts: readonly ContainerPart[] /** The operation the message belongs to. */;
107
+ readonly operationId?: string;
108
+ readonly createdAt: number;
109
+ };
110
+ /** What an adapter reports while it runs. */
111
+ type ContainerEvent =
112
+ /** Live text for an assistant message that is still being written. */ | {
113
+ readonly type: "text-delta";
114
+ readonly messageId: string;
115
+ readonly delta: string;
116
+ } /** Live reasoning for an assistant message that is still being written. */
117
+ | {
118
+ readonly type: "reasoning-delta";
119
+ readonly messageId: string;
120
+ readonly delta: string;
121
+ } /** A finished or updated transcript message. Stored. */
122
+ | {
123
+ readonly type: "message";
124
+ readonly message: ContainerMessage;
125
+ } /** Token and cost figures the adapter reports, as the adapter counts them. */
126
+ | {
127
+ readonly type: "usage";
128
+ readonly inputTokens?: number;
129
+ readonly outputTokens?: number;
130
+ readonly costUsd?: number;
131
+ } /** A diagnostic line. */
132
+ | {
133
+ readonly type: "log";
134
+ readonly level: "info" | "warn" | "error";
135
+ readonly message: string;
136
+ } /** Anything adapter-specific, passed through untouched. */
137
+ | {
138
+ readonly type: "raw";
139
+ readonly value: JsonValue;
140
+ };
141
+ /** How an operation ended, as the daemon reports it. */
142
+ type ContainerOutcome =
143
+ | {
144
+ readonly status: "done";
145
+ readonly text: string;
146
+ }
147
+ | {
148
+ readonly status: "unanswered";
149
+ readonly reason: string;
150
+ };
151
+ /** What the daemon knows about one operation it was given. */
152
+ type DaemonOperation =
153
+ | {
154
+ readonly operationId: string;
155
+ readonly status: "queued" | "running";
156
+ }
157
+ | {
158
+ readonly operationId: string;
159
+ readonly status: "settled";
160
+ readonly outcome: ContainerOutcome;
161
+ };
162
+ /** One numbered thing the daemon produced for a session. */
163
+ type DaemonFrame =
164
+ | {
165
+ readonly kind: "start";
166
+ readonly operationId: string;
167
+ }
168
+ | {
169
+ readonly kind: "event";
170
+ readonly operationId: string | null;
171
+ readonly event: ContainerEvent;
172
+ }
173
+ /**
174
+ * Adapter resume state to keep. The object stores these entries in order
175
+ * and hands all of them back in `open` on a new container.
176
+ */
177
+ | {
178
+ readonly kind: "persist";
179
+ readonly entries: readonly JsonValue[];
180
+ }
181
+ | {
182
+ readonly kind: "settle";
183
+ readonly operationId: string;
184
+ readonly outcome: ContainerOutcome;
185
+ };
186
+ /** The adapter running in the container. */
187
+ type AdapterInfo = {
188
+ readonly id: string;
189
+ readonly version: string;
190
+ readonly capabilities: readonly string[];
191
+ };
192
+ /** Daemon → object. */
193
+ type DaemonMessage =
194
+ | {
195
+ readonly type: "hello";
196
+ readonly protocol: number;
197
+ readonly runtimeId: string;
198
+ readonly session: string;
199
+ readonly adapter: AdapterInfo /** The generation of the open adapter session, or null if none is open. */;
200
+ readonly open:
201
+ | number
202
+ | null /** The newest frame number for this session in this container. */;
203
+ readonly lastSeq: number /** Every operation this container was given for the session. */;
204
+ readonly operations: readonly DaemonOperation[];
205
+ }
206
+ | {
207
+ readonly type: "frame";
208
+ readonly seq: number;
209
+ readonly frame: DaemonFrame;
210
+ } /** Every kept frame after the `replay` cursor has been sent. */
211
+ | {
212
+ readonly type: "caught-up";
213
+ readonly lastSeq: number;
214
+ }
215
+ | {
216
+ readonly type: "error";
217
+ readonly message: string;
218
+ };
219
+ /**
220
+ * Most JSON characters the object puts in one `restore` message, and the
221
+ * daemon in one `persist` frame (a single larger entry travels alone).
222
+ * Keeps every message well inside WebSocket message limits.
223
+ */
224
+ declare const MAX_CHUNK_CHARS: number;
225
+ /** Object → daemon. */
226
+ type HostMessage =
227
+ /**
228
+ * Part of the resume state for the next `open` of `generation`. Sent
229
+ * before that `open`, in order, so no single message grows with the
230
+ * session's history.
231
+ */
232
+ | {
233
+ readonly type: "restore";
234
+ readonly generation: number;
235
+ readonly entries: readonly JsonValue[];
236
+ }
237
+ /**
238
+ * Open the adapter session. Ignored when the same generation is already
239
+ * open; a different generation closes the open one first.
240
+ */
241
+ | {
242
+ readonly type: "open";
243
+ readonly generation: number;
244
+ readonly settings: ContainerSettings;
245
+ /**
246
+ * The last of the entries the adapter persisted for this session,
247
+ * after any sent in `restore` messages for this generation.
248
+ */
249
+ readonly restore: readonly JsonValue[];
250
+ } /** Send every kept frame after `after`, then live frames. */
251
+ | {
252
+ readonly type: "replay";
253
+ readonly after: number;
254
+ } /** Queue an operation. Idempotent on `operationId`. */
255
+ | {
256
+ readonly type: "prompt";
257
+ readonly operationId: string;
258
+ readonly input: ContainerInput;
259
+ readonly whenBusy: ContainerWhenBusy;
260
+ } /** Stop one operation, or every operation of the session. */
261
+ | {
262
+ readonly type: "abort";
263
+ readonly operationId?: string;
264
+ }
265
+ | {
266
+ readonly type: "configure";
267
+ readonly settings: ContainerSettings;
268
+ } /** Frames up to `seq` are stored; the daemon may forget them. */
269
+ | {
270
+ readonly type: "ack";
271
+ readonly seq: number;
272
+ };
273
+ /**
274
+ * Parse one message from the daemon.
275
+ *
276
+ * @param text - The raw WebSocket message.
277
+ * @returns The message, or `undefined` when it is not one.
278
+ */
279
+ declare function parseDaemonMessage(text: string): DaemonMessage | undefined;
280
+ /**
281
+ * Parse one message from the object.
282
+ *
283
+ * @param text - The raw WebSocket message.
284
+ * @returns The message, or `undefined` when it is not one.
285
+ */
286
+ declare function parseHostMessage(text: string): HostMessage | undefined;
287
+ /**
288
+ * The text of an input, with image parts left out.
289
+ *
290
+ * @param input - A prompt's input.
291
+ * @returns Its text.
292
+ */
293
+ declare function inputText(input: ContainerInput): string;
294
+ /**
295
+ * Split entries into groups whose JSON stays under `MAX_CHUNK_CHARS`. An
296
+ * entry larger than that is a group of its own.
297
+ *
298
+ * @param entries - The entries, in order.
299
+ * @returns The groups, in order. Empty for no entries.
300
+ */
301
+ declare function chunkEntries(entries: readonly JsonValue[]): JsonValue[][];
302
+ //#endregion
303
+ export {
304
+ chunkEntries as C,
305
+ parseHostMessage as E,
306
+ MAX_CHUNK_CHARS as S,
307
+ parseDaemonMessage as T,
308
+ DaemonFrame as _,
309
+ CONTAINER_HEALTH_PATH as a,
310
+ HostMessage as b,
311
+ CONTAINER_TOKEN_HEADER as c,
312
+ ContainerInputPart as d,
313
+ ContainerMessage as f,
314
+ ContainerWhenBusy as g,
315
+ ContainerSettings as h,
316
+ CONTAINER_ENV as i,
317
+ ContainerEvent as l,
318
+ ContainerPart as m,
319
+ CLOSE_REPLACED as n,
320
+ CONTAINER_PROTOCOL_VERSION as o,
321
+ ContainerOutcome as p,
322
+ CLOSE_UNAUTHORIZED as r,
323
+ CONTAINER_SESSION_PATH as s,
324
+ AdapterInfo as t,
325
+ ContainerInput as u,
326
+ DaemonMessage as v,
327
+ inputText as w,
328
+ JsonValue as x,
329
+ DaemonOperation as y
330
+ };
331
+ //# sourceMappingURL=protocol-BEgrJYC5.d.ts.map