agents 0.26.0 → 0.27.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 (233) hide show
  1. package/README.md +8 -9
  2. package/dist/{agent-routing-0DR0Tk2v.d.ts → agent-routing-Bhdbvf7s.d.ts} +13 -8
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +1 -1
  5. package/dist/{agent-tools-YrATZJu2.d.ts → agent-tools-bJZwBMfq.d.ts} +2 -2
  6. package/dist/agent-tools.d.ts +1 -1
  7. package/dist/ai-sdk-OoGkFy3s.js +2444 -0
  8. package/dist/ai-sdk-OoGkFy3s.js.map +1 -0
  9. package/dist/apply-chunks-1FheRb9W.js +99 -0
  10. package/dist/apply-chunks-1FheRb9W.js.map +1 -0
  11. package/dist/broadcast-state-CEyI4uAK.js +69 -0
  12. package/dist/broadcast-state-CEyI4uAK.js.map +1 -0
  13. package/dist/browser/ai-sdk.d.ts +1 -1
  14. package/dist/browser/ai-sdk.js +2 -2
  15. package/dist/browser/ai-sdk.js.map +1 -1
  16. package/dist/browser/index.d.ts +1 -1
  17. package/dist/browser/tanstack-ai.d.ts +1 -1
  18. package/dist/browser/tanstack-ai.js +1 -1
  19. package/dist/{browser-DE3d-RLk.d.ts → browser-tmkcAAI3.d.ts} +2 -2
  20. package/dist/{browser-tool-DuNdlwZ9.d.ts → browser-tool-Bn-nzJQI.d.ts} +3 -3
  21. package/dist/{browser-tool-CQ10e6Kj.js → browser-tool-CBqs6hqa.js} +58 -18
  22. package/dist/browser-tool-CBqs6hqa.js.map +1 -0
  23. package/dist/capability-B4WbF81e.js.map +1 -1
  24. package/dist/{capability-runner-DBAnGr6L.d.ts → capability-runner-O5VbQzqg.d.ts} +9 -1
  25. package/dist/channel-Bak_6zDP.d.ts +333 -0
  26. package/dist/chat/index.d.ts +11 -9
  27. package/dist/chat/index.js +5 -194
  28. package/dist/chat/index.js.map +1 -1
  29. package/dist/chat/react.d.ts +2 -4
  30. package/dist/chat/react.js +3 -1
  31. package/dist/chat/react.js.map +1 -1
  32. package/dist/chat-sdk/index.d.ts +1 -1
  33. package/dist/chat-sdk/index.js +1 -1
  34. package/dist/cli.js +144 -0
  35. package/dist/{client-fyQrLGkD.js → client-1tEQ1Oqz.js} +27 -2
  36. package/dist/{client-fyQrLGkD.js.map → client-1tEQ1Oqz.js.map} +1 -1
  37. package/dist/{client-je3koD9Z.d.ts → client-DS3Dz9l0.d.ts} +2 -2
  38. package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
  39. package/dist/client.d.ts +1 -1
  40. package/dist/conversations-DH0ut_8n.d.ts +192 -0
  41. package/dist/{current-agent-vAk_5JMt.d.ts → current-agent-C07C5o5Y.d.ts} +3 -3
  42. package/dist/daemon-core-Buubj-y1.js +481 -0
  43. package/dist/daemon-core-Buubj-y1.js.map +1 -0
  44. package/dist/daemon-core-CbohVPAu.d.ts +132 -0
  45. package/dist/{do-oauth-client-provider-Tmf1vgKz.d.ts → do-oauth-client-provider-DfsUcpc3.d.ts} +7 -1
  46. package/dist/{durable-object-lifecycle-HhgOMWq9.d.ts → durable-object-lifecycle-DRqp475_.d.ts} +2 -2
  47. package/dist/{channels/email.d.ts → experimental/channels/email/index.d.ts} +25 -12
  48. package/dist/{channels/email.js → experimental/channels/email/index.js} +13 -35
  49. package/dist/experimental/channels/email/index.js.map +1 -0
  50. package/dist/experimental/channels/index.d.ts +270 -0
  51. package/dist/experimental/channels/index.js +1186 -0
  52. package/dist/experimental/channels/index.js.map +1 -0
  53. package/dist/{channels/slack.d.ts → experimental/channels/slack/index.d.ts} +19 -9
  54. package/dist/experimental/channels/slack/index.js +267 -0
  55. package/dist/experimental/channels/slack/index.js.map +1 -0
  56. package/dist/{channels/telegram.d.ts → experimental/channels/telegram/index.d.ts} +19 -9
  57. package/dist/experimental/channels/telegram/index.js +198 -0
  58. package/dist/experimental/channels/telegram/index.js.map +1 -0
  59. package/dist/experimental/channels/web/ai-sdk.d.ts +55 -0
  60. package/dist/experimental/channels/web/ai-sdk.js +266 -0
  61. package/dist/experimental/channels/web/ai-sdk.js.map +1 -0
  62. package/dist/experimental/channels/web/client.d.ts +97 -0
  63. package/dist/experimental/channels/web/client.js +349 -0
  64. package/dist/experimental/channels/web/client.js.map +1 -0
  65. package/dist/experimental/channels/web/index.d.ts +189 -0
  66. package/dist/experimental/channels/web/index.js +332 -0
  67. package/dist/experimental/channels/web/index.js.map +1 -0
  68. package/dist/gateway-BDC07gYO.d.ts +100 -0
  69. package/dist/handle-zAzh0UW2.d.ts +460 -0
  70. package/dist/harness/ai-sdk/index.d.ts +175 -0
  71. package/dist/harness/ai-sdk/index.js +605 -0
  72. package/dist/harness/ai-sdk/index.js.map +1 -0
  73. package/dist/harness/container/daemon/index.d.ts +76 -0
  74. package/dist/harness/container/daemon/index.js +3 -0
  75. package/dist/harness/container/index.d.ts +740 -0
  76. package/dist/harness/container/index.js +2152 -0
  77. package/dist/harness/container/index.js.map +1 -0
  78. package/dist/harness/container/runtime/index.d.ts +144 -0
  79. package/dist/harness/container/runtime/index.js +1082 -0
  80. package/dist/harness/container/runtime/index.js.map +1 -0
  81. package/dist/harness/opencode/index.d.ts +369 -0
  82. package/dist/harness/opencode/index.js +1072 -0
  83. package/dist/harness/opencode/index.js.map +1 -0
  84. package/dist/harness/pi/index.d.ts +2 -1
  85. package/dist/harness/store/index.d.ts +24 -0
  86. package/dist/harness/store/index.js +2 -0
  87. package/dist/harness/think/index.d.ts +821 -0
  88. package/dist/harness/think/index.js +2529 -0
  89. package/dist/harness/think/index.js.map +1 -0
  90. package/dist/harness-B6B9S3rb.d.ts +203 -0
  91. package/dist/{images-iiTDSyRu.js → images-Ce9SCu3X.js} +2 -248
  92. package/dist/images-Ce9SCu3X.js.map +1 -0
  93. package/dist/{index-BreL0YrQ.d.ts → index-D0A5tbWu.d.ts} +2 -2
  94. package/dist/index-Ib_4dwOo.d.ts +200 -0
  95. package/dist/index.d.ts +5 -5
  96. package/dist/index.js +2 -2
  97. package/dist/ingress-EFbrS547.js +9 -0
  98. package/dist/ingress-EFbrS547.js.map +1 -0
  99. package/dist/input-schema-DNrpTu49.js +23 -0
  100. package/dist/input-schema-DNrpTu49.js.map +1 -0
  101. package/dist/internal-kmw70xwR.js +46 -0
  102. package/dist/internal-kmw70xwR.js.map +1 -0
  103. package/dist/internal_context.d.ts +1 -1
  104. package/dist/lifecycle/index.d.ts +3 -3
  105. package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
  106. package/dist/mcp/client/do-oauth-client-provider.js +9 -0
  107. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
  108. package/dist/mcp/client/index.d.ts +1 -1
  109. package/dist/mcp/client/index.js +1 -1
  110. package/dist/mcp/client/x402.d.ts +35 -4
  111. package/dist/mcp/client/x402.js +24 -3
  112. package/dist/mcp/client/x402.js.map +1 -1
  113. package/dist/mcp/index.d.ts +1 -1
  114. package/dist/mcp/index.js +2 -2
  115. package/dist/models/ai-sdk/index.d.ts +16 -14
  116. package/dist/models/ai-sdk/index.js +1 -2442
  117. package/dist/models/opencode/index.d.ts +65 -0
  118. package/dist/models/opencode/index.js +285 -0
  119. package/dist/models/opencode/index.js.map +1 -0
  120. package/dist/models/pi-ai/index.d.ts +9 -7
  121. package/dist/models/pi-ai/index.js +2 -1
  122. package/dist/models/pi-ai/index.js.map +1 -1
  123. package/dist/options-pwTNq9z6.d.ts +134 -0
  124. package/dist/protocol-BEgrJYC5.d.ts +331 -0
  125. package/dist/protocol-CukuI73M.d.ts +386 -0
  126. package/dist/protocol-cOklVBBD.js +227 -0
  127. package/dist/protocol-cOklVBBD.js.map +1 -0
  128. package/dist/{protocol-kHsr-f0X.js → protocol-eXeJxhgu.js} +2 -67
  129. package/dist/protocol-eXeJxhgu.js.map +1 -0
  130. package/dist/protocol-y2sSY584.js +148 -0
  131. package/dist/protocol-y2sSY584.js.map +1 -0
  132. package/dist/queue/index.d.ts +1 -1
  133. package/dist/react.d.ts +2 -2
  134. package/dist/routing/index.d.ts +2 -2
  135. package/dist/{scheduler-RdACNXDP.d.ts → scheduler-CrFCnv_J.d.ts} +2 -2
  136. package/dist/schedules/index.d.ts +1 -1
  137. package/dist/serializable.d.ts +1 -1
  138. package/dist/sessions/index.d.ts +11 -434
  139. package/dist/sessions/index.js +1 -2271
  140. package/dist/sessions-B9pNuxdT.js +2272 -0
  141. package/dist/sessions-B9pNuxdT.js.map +1 -0
  142. package/dist/settings-C45hDliX.js +253 -0
  143. package/dist/settings-C45hDliX.js.map +1 -0
  144. package/dist/{transport-PfFnt-Ld.d.ts → settings-NgGwF7Qt.d.ts} +14 -208
  145. package/dist/{src-BZeu-SCD.js → src-DgCbZtIR.js} +4 -4
  146. package/dist/{src-BZeu-SCD.js.map → src-DgCbZtIR.js.map} +1 -1
  147. package/dist/stall-watchdog-BpRF2uwG.js +195 -0
  148. package/dist/stall-watchdog-BpRF2uwG.js.map +1 -0
  149. package/dist/state/index.d.ts +1 -1
  150. package/dist/store-DLeqKuj3.d.ts +310 -0
  151. package/dist/store-vgcPYo8K.js +432 -0
  152. package/dist/store-vgcPYo8K.js.map +1 -0
  153. package/dist/streams/index.d.ts +1 -1
  154. package/dist/streams/index.js +1 -1
  155. package/dist/{streams-DW-UCOUc.js → streams-CITClVer.js} +16 -3
  156. package/dist/streams-CITClVer.js.map +1 -0
  157. package/dist/{streams-Cmkj9QfW.d.ts → streams-fbG61qM8.d.ts} +2 -2
  158. package/dist/sub-routing.d.ts +1 -1
  159. package/dist/tasks/index.d.ts +1 -1
  160. package/dist/tasks/index.js +1 -1
  161. package/dist/{tasks-68DESxf0.js → tasks-CkTZNaV1.js} +2 -1
  162. package/dist/tasks-CkTZNaV1.js.map +1 -0
  163. package/dist/{tasks-9YxYtByh.d.ts → tasks-PtlB4Uyn.d.ts} +2 -2
  164. package/dist/tool-3PA8xjB_.js +421 -0
  165. package/dist/tool-3PA8xjB_.js.map +1 -0
  166. package/dist/tool-BPJEbwaX.d.ts +278 -0
  167. package/dist/transport-k2mFrtL8.d.ts +200 -0
  168. package/dist/turns-DCV3ycDl.js +317 -0
  169. package/dist/turns-DCV3ycDl.js.map +1 -0
  170. package/dist/voice/client.js +1 -1
  171. package/dist/voice/index.d.ts +2 -2
  172. package/dist/voice/index.js +1 -1
  173. package/dist/websearch/index.d.ts +58 -0
  174. package/dist/websearch/index.js +2 -0
  175. package/dist/websearch/tools/ai-sdk.d.ts +77 -0
  176. package/dist/websearch/tools/ai-sdk.js +46 -0
  177. package/dist/websearch/tools/ai-sdk.js.map +1 -0
  178. package/dist/websearch/tools/pi.d.ts +82 -0
  179. package/dist/websearch/tools/pi.js +89 -0
  180. package/dist/websearch/tools/pi.js.map +1 -0
  181. package/dist/websearch/tools/tanstack-ai.d.ts +71 -0
  182. package/dist/websearch/tools/tanstack-ai.js +46 -0
  183. package/dist/websearch/tools/tanstack-ai.js.map +1 -0
  184. package/dist/websockets/index.d.ts +12 -296
  185. package/dist/websockets/index.js +1 -1
  186. package/dist/{websockets-Ci-LZFHH.js → websockets-CmENGb-Z.js} +18 -4
  187. package/dist/websockets-CmENGb-Z.js.map +1 -0
  188. package/dist/{wire-types-CrjKvDyi.d.ts → wire-types-Cv0iwjk5.d.ts} +3 -51
  189. package/dist/workflow-types.d.ts +1 -1
  190. package/dist/workflows.d.ts +1 -1
  191. package/dist/workflows.js +1 -1
  192. package/docs/browse-the-web.md +3 -0
  193. package/docs/harnesses/think.md +215 -0
  194. package/docs/index.md +2 -1
  195. package/docs/lifecycle.md +40 -0
  196. package/docs/search-the-web.md +133 -0
  197. package/package.json +117 -38
  198. package/dist/browser-tool-CQ10e6Kj.js.map +0 -1
  199. package/dist/channel-Bnm4S7T2.d.ts +0 -491
  200. package/dist/channels/ai-sdk.d.ts +0 -46
  201. package/dist/channels/ai-sdk.js +0 -120
  202. package/dist/channels/ai-sdk.js.map +0 -1
  203. package/dist/channels/email.js.map +0 -1
  204. package/dist/channels/index.d.ts +0 -233
  205. package/dist/channels/index.js +0 -608
  206. package/dist/channels/index.js.map +0 -1
  207. package/dist/channels/slack.js +0 -614
  208. package/dist/channels/slack.js.map +0 -1
  209. package/dist/channels/tanstack-ai.d.ts +0 -39
  210. package/dist/channels/tanstack-ai.js +0 -17
  211. package/dist/channels/tanstack-ai.js.map +0 -1
  212. package/dist/channels/telegram.js +0 -427
  213. package/dist/channels/telegram.js.map +0 -1
  214. package/dist/channels/voice.d.ts +0 -45
  215. package/dist/channels/voice.js +0 -122
  216. package/dist/channels/voice.js.map +0 -1
  217. package/dist/images-iiTDSyRu.js.map +0 -1
  218. package/dist/index-BB0kqhIz.d.ts +0 -101
  219. package/dist/ingress-BfetZbMO.js +0 -83
  220. package/dist/ingress-BfetZbMO.js.map +0 -1
  221. package/dist/internal-CYlgHl1l.js +0 -59
  222. package/dist/internal-CYlgHl1l.js.map +0 -1
  223. package/dist/models/ai-sdk/index.js.map +0 -1
  224. package/dist/protocol-kHsr-f0X.js.map +0 -1
  225. package/dist/sessions/index.js.map +0 -1
  226. package/dist/streams-DW-UCOUc.js.map +0 -1
  227. package/dist/surface-bZZJqBka.js +0 -17
  228. package/dist/surface-bZZJqBka.js.map +0 -1
  229. package/dist/tasks-68DESxf0.js.map +0 -1
  230. package/dist/tool-schema-CBjGPrsQ.js +0 -31
  231. package/dist/tool-schema-CBjGPrsQ.js.map +0 -1
  232. package/dist/websockets-Ci-LZFHH.js.map +0 -1
  233. package/docs/channels.md +0 -323
@@ -0,0 +1,333 @@
1
+ import {
2
+ b as ChannelMessageSurface,
3
+ m as ResponseChunk,
4
+ p as Participant,
5
+ x as ChannelMessageSurfaceInput
6
+ } from "./protocol-CukuI73M.js";
7
+
8
+ //#region src/experimental/channels/identity.d.ts
9
+ type ChannelIdentity = Readonly<{
10
+ /** Configured Channel that observed this identity. */ channelKey: string /** Stable Channel namespace in which `subject` is unique. @default "default" */;
11
+ scope?: string /** Stable Channel subject within `scope`. */;
12
+ subject: string;
13
+ }>;
14
+ /** A Channel-produced identity before its Host stamps the configured key. */
15
+ type ChannelIdentityInput = Readonly<{
16
+ scope?: string;
17
+ subject: string;
18
+ }>;
19
+ /** Build a stable key for comparing or indexing a Channel identity. */
20
+ declare function identityKey(identity: ChannelIdentity): string;
21
+ //#endregion
22
+ //#region src/experimental/channels/ingress.d.ts
23
+ /** Serializable provider attachment facts available after ingress returns. */
24
+ type ChannelAttachment = {
25
+ id?: string;
26
+ mediaType?: string;
27
+ name?: string;
28
+ size?: number;
29
+ text?: string;
30
+ url?: string;
31
+ };
32
+ type ChannelActor = {
33
+ readonly id: string /** Stable Channel identity suitable for explicit application linking. */;
34
+ readonly identity?: ChannelIdentity;
35
+ readonly username?: string;
36
+ readonly fullName?: string;
37
+ readonly isBot?: boolean | "unknown";
38
+ readonly isSelf?: boolean;
39
+ };
40
+ /** An actor before the Host stamps its configured Channel key. */
41
+ type ChannelActorInput = Omit<ChannelActor, "identity"> & {
42
+ readonly identity?: ChannelIdentityInput;
43
+ };
44
+ type ChannelEventContext = {
45
+ /** Immutable Channel-scoped identity, independent of application routing. */ readonly eventId: string;
46
+ readonly thread: {
47
+ readonly id: string;
48
+ readonly isDirectMessage: boolean | "unknown";
49
+ } /** Exact provider destination for responding to this inbound event. */;
50
+ readonly replySurface?: ChannelMessageSurface;
51
+ readonly actor?: ChannelActor;
52
+ };
53
+ /** A normalized inbound message from a Channel. */
54
+ type ChannelInboundMessage = ChannelEventContext & {
55
+ readonly type: "message";
56
+ readonly message: {
57
+ readonly id: string;
58
+ readonly text: string;
59
+ readonly title?: string;
60
+ readonly markdown?: string;
61
+ readonly attachments?: readonly ChannelAttachment[];
62
+ readonly isMention?: boolean;
63
+ readonly reply?: {
64
+ readonly id: string;
65
+ readonly text?: string;
66
+ };
67
+ readonly metadata?: {
68
+ /** ISO 8601 timestamp supplied by the provider. */ readonly sentAt?: string;
69
+ readonly edited?: boolean /** ISO 8601 timestamp supplied by the provider. */;
70
+ readonly editedAt?: string;
71
+ readonly autoReply?: boolean;
72
+ };
73
+ };
74
+ };
75
+ /** A provider-normalized response to an external approval request. */
76
+ type ChannelApprovalResponse = ChannelEventContext & {
77
+ readonly type: "approval-response";
78
+ readonly approvalId: string;
79
+ readonly decision:
80
+ | "approve"
81
+ | "reject" /** Provider reference for this inbound response. */;
82
+ readonly reference: string;
83
+ };
84
+ type ChannelIngressEvent = ChannelInboundMessage | ChannelApprovalResponse;
85
+ /** A normalized message before the Host stamps its configured Channel key. */
86
+ type ChannelEventContextInput = Omit<
87
+ ChannelEventContext,
88
+ "replySurface" | "actor"
89
+ > & {
90
+ readonly replySurface?: ChannelMessageSurfaceInput;
91
+ readonly actor?: ChannelActorInput;
92
+ };
93
+ type ChannelInboundMessageInput = Omit<
94
+ ChannelInboundMessage,
95
+ "replySurface" | "actor"
96
+ > & {
97
+ readonly replySurface?: ChannelMessageSurfaceInput;
98
+ readonly actor?: ChannelActorInput;
99
+ };
100
+ /** A normalized approval before the Host stamps its configured Channel key. */
101
+ type ChannelApprovalResponseInput = Omit<
102
+ ChannelApprovalResponse,
103
+ "replySurface" | "actor"
104
+ > & {
105
+ readonly replySurface?: ChannelMessageSurfaceInput;
106
+ readonly actor?: ChannelActorInput;
107
+ };
108
+ /** Authenticated event produced by a Channel before Host dispatch. */
109
+ type ChannelIngressEventInput =
110
+ | ChannelInboundMessageInput
111
+ | ChannelApprovalResponseInput;
112
+ /** Authenticated Channel output retained only until Host routing completes. */
113
+ type ChannelIngressEnvelope<TRaw = unknown> = {
114
+ event: ChannelIngressEventInput;
115
+ raw: TRaw;
116
+ };
117
+ /** The normalized envelopes and provider acknowledgement produced by ingress. */
118
+ type ChannelIngressResult<TRaw = unknown> = {
119
+ events: readonly ChannelIngressEnvelope<TRaw>[];
120
+ response: Response;
121
+ };
122
+ /** Match an HTTP request to one exact URL pathname. */
123
+ declare function matchesPath(request: Request, path: string): boolean;
124
+ /** Webhook-shaped inbound support owned by a Channel. */
125
+ interface ChannelIngress<TRaw = unknown> {
126
+ /** Return null when this Channel does not own the request. */
127
+ receive(request: Request): Promise<ChannelIngressResult<TRaw> | null>;
128
+ }
129
+ /** Structural input supported by Workers Email and Agent email handlers. */
130
+ type ChannelEmailInput = {
131
+ from: string;
132
+ to: string;
133
+ headers: Headers;
134
+ raw?: ReadableStream<Uint8Array>;
135
+ getRaw?: () => Promise<Uint8Array>;
136
+ };
137
+ type ChannelEmailIngressResult<TRaw = unknown> = {
138
+ events: readonly ChannelIngressEnvelope<TRaw>[];
139
+ };
140
+ /** Non-HTTP ingress for a Workers Email event. */
141
+ interface ChannelEmailIngress<TRaw = unknown> {
142
+ /** Return null when this Channel does not own the email. */
143
+ receive(
144
+ email: ChannelEmailInput
145
+ ): Promise<ChannelEmailIngressResult<TRaw> | null>;
146
+ }
147
+ //#endregion
148
+ //#region src/experimental/channels/channel.d.ts
149
+ type Awaitable<T> = T | Promise<T>;
150
+ /** A transport-neutral outbound message whose canonical content is Markdown. */
151
+ type ChannelMessage = {
152
+ /** Optional topic. Each transport decides how to represent it. */ title?: string /** Canonical Markdown content. */;
153
+ markdown: string;
154
+ };
155
+ /** A transport failure safe to expose to an AI model. */
156
+ type DeliveryFailure = {
157
+ code: string;
158
+ message: string;
159
+ };
160
+ /**
161
+ * The result of a direct delivery attempt, defined by what reached the reader.
162
+ *
163
+ * `delivered` means the whole message reached the reader, not that a person
164
+ * read it. `failed` means none of it did; its `retryable` field says whether
165
+ * the same route can be attempted again. `uncertain` means an unknown amount
166
+ * of the message reached the reader, so another attempt or route could
167
+ * duplicate content. A stream that ends before its answer is complete is
168
+ * `uncertain`, and carries a `reference` when the Channel created something
169
+ * the caller can point at.
170
+ */
171
+ type DeliveryResult =
172
+ | {
173
+ status: "delivered";
174
+ reference?: string;
175
+ }
176
+ | {
177
+ status: "failed";
178
+ retryable: boolean;
179
+ error: DeliveryFailure;
180
+ }
181
+ | {
182
+ status: "uncertain";
183
+ reference?: string;
184
+ error: DeliveryFailure;
185
+ };
186
+ /** A response's chunks, as `ChannelGateway.stream` takes them. */
187
+ type ChannelChunkSource = ReadableStream<ResponseChunk>;
188
+ /** Caller options for one finished delivery. */
189
+ type ChannelDeliveryOptions = {
190
+ /** Caller-owned correlation an Adapter may use where the provider supports it. */ delivery?: ChannelDeliveryContext;
191
+ };
192
+ /** Caller options for one streamed answer. */
193
+ type ChannelStreamOptions = {
194
+ /**
195
+ * Optional topic. It is an option rather than a chunk because it is known
196
+ * before the first token, and a Channel usually needs it in its opening
197
+ * provider call.
198
+ */
199
+ title?: string /** Caller-owned correlation an Adapter may use where the provider supports it. */;
200
+ delivery?: ChannelDeliveryContext;
201
+ };
202
+ /**
203
+ * Caller-owned correlation supplied to one provider delivery attempt.
204
+ *
205
+ * This is not an idempotency guarantee. An Adapter may map it to a provider
206
+ * idempotency primitive when one exists, or otherwise use it for observability.
207
+ */
208
+ type ChannelDeliveryContext = {
209
+ deliveryId: string;
210
+ };
211
+ /**
212
+ * Who a sender is, as the application decides it. A string is shorthand
213
+ * for `{ id }`; `null` refuses the sender. Participants that share an id
214
+ * are the same participant.
215
+ */
216
+ type ParticipantResult = Participant | string | null;
217
+ /**
218
+ * Resolve who sent an authenticated event. Channels has no opinion on
219
+ * identity: this is the only place a webhook sender becomes a participant.
220
+ */
221
+ type ChannelParticipant<TRaw = unknown> = (
222
+ event: ChannelIngressEvent,
223
+ raw: TRaw
224
+ ) => Awaitable<ParticipantResult>;
225
+ /**
226
+ * Pick the agent object an event reaches, or return null to ignore it.
227
+ *
228
+ * The agent object is the authorization boundary: anyone who reaches one
229
+ * may use every conversation in it. Default: an agent object of the
230
+ * participant's own (`routes.perParticipant`).
231
+ */
232
+ type ChannelRoute<TRaw = unknown> = (
233
+ event: ChannelIngressEvent,
234
+ raw: TRaw,
235
+ participant: Participant
236
+ ) => Awaitable<string | null>;
237
+ /** A WebSocket upgrade's conversation, once it is known to be for Channels. */
238
+ type ChannelUpgradeMatch = {
239
+ /** The conversation to follow. Default: the agent's default conversation. */ conversationId?: string;
240
+ };
241
+ /** How a Channel takes WebSocket upgrades in the gateway. */
242
+ interface ChannelUpgrade {
243
+ /** Return undefined for an upgrade that is not for this Channel. */
244
+ match(request: Request): ChannelUpgradeMatch | undefined;
245
+ /** Who is connecting. Return null to refuse the upgrade. */
246
+ participant(request: Request): Awaitable<ParticipantResult>;
247
+ /** The agent object the upgrade reaches, or null to refuse it. */
248
+ route(request: Request, participant: Participant): Awaitable<string | null>;
249
+ }
250
+ /** A configured delivery route with optional ingress support. */
251
+ interface Channel<TRaw = unknown> {
252
+ /**
253
+ * Who sent an ingress event. Required when the Channel has `ingress` or
254
+ * `emailIngress`; the gateway refuses to start without it.
255
+ */
256
+ participant?(
257
+ event: ChannelIngressEvent,
258
+ raw: TRaw
259
+ ): Awaitable<ParticipantResult>;
260
+ /** Pick the agent object an event reaches. See `ChannelRoute`. */
261
+ route?(
262
+ event: ChannelIngressEvent,
263
+ raw: TRaw,
264
+ participant: Participant
265
+ ): Awaitable<string | null>;
266
+ /** Derive a direct destination from this configured Channel's identity. */
267
+ contactSurface?(identity: ChannelIdentity): ChannelMessageSurfaceInput | null;
268
+ /**
269
+ * Deliver one finished message. Only for Channels that cannot stream:
270
+ * the gateway delivers to a Channel that can by streaming the message.
271
+ */
272
+ deliver?(
273
+ surface: ChannelMessageSurface,
274
+ message: ChannelMessage,
275
+ options?: ChannelDeliveryOptions
276
+ ): Promise<DeliveryResult>;
277
+ /**
278
+ * Deliver one progressively generated answer. Absent for Channels that
279
+ * cannot stream, which the Host serves by collecting and calling `deliver`.
280
+ *
281
+ * The Channel owns the consumption loop. It must finalize whether the
282
+ * stream closed or errored, because a model can fail mid-generation, and it
283
+ * must not abandon a terminal provider call on error.
284
+ */
285
+ stream?(
286
+ surface: ChannelMessageSurface,
287
+ chunks: ChannelChunkSource,
288
+ options: ChannelStreamOptions
289
+ ): Promise<DeliveryResult>;
290
+ readonly ingress?: ChannelIngress<TRaw>;
291
+ readonly emailIngress?: ChannelEmailIngress<TRaw>;
292
+ /** WebSocket upgrades this Channel takes, such as the Web Channel's. */
293
+ readonly upgrade?: ChannelUpgrade;
294
+ }
295
+ //#endregion
296
+ export {
297
+ ChannelIngressEventInput as A,
298
+ ChannelEventContext as C,
299
+ ChannelIngress as D,
300
+ ChannelInboundMessageInput as E,
301
+ identityKey as F,
302
+ matchesPath as M,
303
+ ChannelIdentity as N,
304
+ ChannelIngressEnvelope as O,
305
+ ChannelIdentityInput as P,
306
+ ChannelEmailInput as S,
307
+ ChannelInboundMessage as T,
308
+ ChannelApprovalResponse as _,
309
+ ChannelDeliveryOptions as a,
310
+ ChannelEmailIngress as b,
311
+ ChannelRoute as c,
312
+ ChannelUpgradeMatch as d,
313
+ DeliveryFailure as f,
314
+ ChannelActorInput as g,
315
+ ChannelActor as h,
316
+ ChannelDeliveryContext as i,
317
+ ChannelIngressResult as j,
318
+ ChannelIngressEvent as k,
319
+ ChannelStreamOptions as l,
320
+ ParticipantResult as m,
321
+ Channel as n,
322
+ ChannelMessage as o,
323
+ DeliveryResult as p,
324
+ ChannelChunkSource as r,
325
+ ChannelParticipant as s,
326
+ Awaitable as t,
327
+ ChannelUpgrade as u,
328
+ ChannelApprovalResponseInput as v,
329
+ ChannelEventContextInput as w,
330
+ ChannelEmailIngressResult as x,
331
+ ChannelAttachment as y
332
+ };
333
+ //# sourceMappingURL=channel-Bak_6zDP.d.ts.map
@@ -9,21 +9,23 @@ import {
9
9
  _ as FiberRecoveryContext$1,
10
10
  at as isPositionlessAgentToolChunk,
11
11
  z as AgentToolEventState
12
- } from "../agent-routing-0DR0Tk2v.js";
13
- import { _ as TaskStep, m as TaskRunOptions } from "../tasks-9YxYtByh.js";
12
+ } from "../agent-routing-Bhdbvf7s.js";
13
+ import { _ as TaskStep, m as TaskRunOptions } from "../tasks-PtlB4Uyn.js";
14
+ import {
15
+ n as ClientToolSchema,
16
+ r as createToolsFromClientSchemas,
17
+ t as ClientToolExecutor
18
+ } from "../client-tools-aIBO0Fk7.js";
19
+ import { n as Streams } from "../streams-fbG61qM8.js";
14
20
  import {
15
21
  a as CHAT_MESSAGE_TYPES,
16
- c as ClientToolExecutor,
17
22
  i as OutgoingMessage,
18
- l as ClientToolSchema,
19
23
  n as IncomingMessage,
20
24
  o as STREAM_RESUME_NONE_REASONS,
21
25
  r as MessageType,
22
26
  s as StreamResumeNoneReason,
23
- t as ChatTurnOutcome,
24
- u as createToolsFromClientSchemas
25
- } from "../wire-types-CrjKvDyi.js";
26
- import { n as Streams } from "../streams-Cmkj9QfW.js";
27
+ t as ChatTurnOutcome
28
+ } from "../wire-types-Cv0iwjk5.js";
27
29
  import {
28
30
  a as applyAgentToolEvent,
29
31
  i as AgentToolProgressEmitter,
@@ -32,7 +34,7 @@ import {
32
34
  r as AgentToolProgressEmitResult,
33
35
  s as interceptAgentToolBroadcast,
34
36
  t as AgentToolBroadcastHooks
35
- } from "../agent-tools-YrATZJu2.js";
37
+ } from "../agent-tools-bJZwBMfq.js";
36
38
  import { l as SessionMessage } from "../types-B7LojTe4.js";
37
39
  import { ModelMessage, UIMessage } from "ai";
38
40
  import { Connection, FiberRecoveryContext } from "agents";
@@ -2,12 +2,13 @@ import { isPositionlessAgentToolChunk } from "../agent-tool-types.js";
2
2
  import { isDurableObjectResetError, isPlatformFailure, tryN } from "../retries.js";
3
3
  import { a as isReplayChunk, i as isLateToolInputChunk, n as applyLateToolInput, o as lateToolInputForwardChunks, r as getPartialStreamText, s as normalizeToolInput, t as applyChunkToParts } from "../message-builder-DAl9AhHH.js";
4
4
  import { a as interceptAgentToolBroadcast, i as createAgentToolEventState, r as applyAgentToolEvent, s as storedChunkBytes, t as AgentToolProgressEmitter } from "../agent-tools-CdJC-8Dc.js";
5
- import { t as TextSegmentJoiner } from "../text-segment-joiner-BtAFQSA_.js";
6
5
  import { n as sanitizeMessage, t as byteLength } from "../sanitize-D9TujEK8.js";
7
- import { a as StreamAccumulator, i as transition, n as STREAM_RESUME_NONE_REASONS, t as CHAT_MESSAGE_TYPES } from "../protocol-kHsr-f0X.js";
8
- import { n as Streams } from "../streams-DW-UCOUc.js";
6
+ import { n as STREAM_RESUME_NONE_REASONS, r as StreamAccumulator, t as CHAT_MESSAGE_TYPES } from "../protocol-eXeJxhgu.js";
7
+ import { t as TextSegmentJoiner } from "../text-segment-joiner-BtAFQSA_.js";
8
+ import { n as transition } from "../broadcast-state-CEyI4uAK.js";
9
+ import { n as Streams } from "../streams-CITClVer.js";
10
+ import { i as createToolsFromClientSchemas, n as iterateWithStallWatchdog, r as parseProtocolMessage, t as ChatStreamStalledError } from "../stall-watchdog-BpRF2uwG.js";
9
11
  import { t as MessageType } from "../wire-types-CnMt6_HR.js";
10
- import { jsonSchema, tool } from "ai";
11
12
  import { nanoid } from "nanoid";
12
13
  //#region src/chat/tool-output-truncation.ts
13
14
  const DEFAULT_MAX_DEPTH = 8;
@@ -1495,42 +1496,6 @@ function buildInClauseStrings(prefix, count) {
1495
1496
  return asTemplateStringsArray(parts);
1496
1497
  }
1497
1498
  //#endregion
1498
- //#region src/chat/client-tools.ts
1499
- /**
1500
- * Converts client tool schemas to AI SDK tool format.
1501
- *
1502
- * By default these tools have no `execute` function — when the AI model calls
1503
- * them, the tool call is sent back to the client for execution.
1504
- *
1505
- * When `options.execute` is provided, each tool is built WITH an `execute` that
1506
- * delegates to it. This is used by the RPC path (e.g. a parent agent driving a
1507
- * Think sub-agent) so the model's client-tool call is resolved inline within
1508
- * the same turn.
1509
- *
1510
- * @param clientTools - Array of tool schemas from the client
1511
- * @param options - Optional `execute` delegate to run the tools inline
1512
- * @returns Record of AI SDK tools that can be spread into your tools object
1513
- */
1514
- function createToolsFromClientSchemas(clientTools, options) {
1515
- if (!clientTools || clientTools.length === 0) return {};
1516
- const seenNames = /* @__PURE__ */ new Set();
1517
- for (const t of clientTools) {
1518
- if (seenNames.has(t.name)) console.warn(`[createToolsFromClientSchemas] Duplicate tool name "${t.name}" found. Later definitions will override earlier ones.`);
1519
- seenNames.add(t.name);
1520
- }
1521
- const execute = options?.execute;
1522
- const createTool = tool;
1523
- return Object.fromEntries(clientTools.map((t) => [t.name, createTool({
1524
- description: typeof t.description === "function" ? "" : t.description ?? "",
1525
- inputSchema: jsonSchema(t.parameters ?? { type: "object" }),
1526
- ...execute ? { execute: (input, executeOptions) => execute({
1527
- toolName: t.name,
1528
- input,
1529
- toolCallId: executeOptions?.toolCallId ?? ""
1530
- }) } : {}
1531
- })]));
1532
- }
1533
- //#endregion
1534
1499
  //#region src/chat/continuation-state.ts
1535
1500
  /**
1536
1501
  * ContinuationState — shared state container for auto-continuation lifecycle.
@@ -2274,84 +2239,6 @@ function hasIncompleteToolBatch(messages) {
2274
2239
  return false;
2275
2240
  }
2276
2241
  //#endregion
2277
- //#region src/chat/parse-protocol.ts
2278
- /**
2279
- * Protocol Message Parser — typed parsing of cf_agent_chat_* WebSocket messages.
2280
- *
2281
- * Parses raw WebSocket messages into a discriminated union of protocol events.
2282
- * Both AIChatAgent and Think can use this instead of manual JSON.parse + type checking.
2283
- */
2284
- /**
2285
- * Parse a raw WebSocket message string into a typed protocol event.
2286
- *
2287
- * Returns `null` if the message is not valid JSON or not a recognized
2288
- * protocol message type. Callers should fall through to the user's
2289
- * `onMessage` handler when `null` is returned.
2290
- *
2291
- * @example
2292
- * ```typescript
2293
- * const event = parseProtocolMessage(rawMessage);
2294
- * if (!event) return userOnMessage(connection, rawMessage);
2295
- *
2296
- * switch (event.type) {
2297
- * case "chat-request": { ... }
2298
- * case "clear": { ... }
2299
- * case "tool-result": { ... }
2300
- * }
2301
- * ```
2302
- */
2303
- function parseProtocolMessage(raw) {
2304
- let data;
2305
- try {
2306
- data = JSON.parse(raw);
2307
- } catch {
2308
- return null;
2309
- }
2310
- const wireType = data.type;
2311
- if (!wireType) return null;
2312
- switch (wireType) {
2313
- case CHAT_MESSAGE_TYPES.USE_CHAT_REQUEST: return {
2314
- type: "chat-request",
2315
- id: data.id,
2316
- init: data.init ?? {}
2317
- };
2318
- case CHAT_MESSAGE_TYPES.CHAT_CLEAR: return { type: "clear" };
2319
- case CHAT_MESSAGE_TYPES.CHAT_REQUEST_CANCEL: return {
2320
- type: "cancel",
2321
- id: data.id
2322
- };
2323
- case CHAT_MESSAGE_TYPES.TOOL_RESULT: return {
2324
- type: "tool-result",
2325
- toolCallId: data.toolCallId,
2326
- toolName: data.toolName ?? "",
2327
- output: data.output,
2328
- state: data.state,
2329
- errorText: data.errorText,
2330
- autoContinue: data.autoContinue,
2331
- clientTools: data.clientTools
2332
- };
2333
- case CHAT_MESSAGE_TYPES.TOOL_APPROVAL: return {
2334
- type: "tool-approval",
2335
- toolCallId: data.toolCallId,
2336
- approved: data.approved,
2337
- autoContinue: data.autoContinue
2338
- };
2339
- case CHAT_MESSAGE_TYPES.STREAM_RESUME_REQUEST: return {
2340
- type: "stream-resume-request",
2341
- ...typeof data.probeId === "string" ? { probeId: data.probeId } : {}
2342
- };
2343
- case CHAT_MESSAGE_TYPES.STREAM_RESUME_ACK: return {
2344
- type: "stream-resume-ack",
2345
- id: data.id
2346
- };
2347
- case CHAT_MESSAGE_TYPES.CHAT_MESSAGES: return {
2348
- type: "messages",
2349
- messages: data.messages ?? []
2350
- };
2351
- default: return null;
2352
- }
2353
- }
2354
- //#endregion
2355
2242
  //#region src/chat/message-reconciler.ts
2356
2243
  /**
2357
2244
  * Reconcile incoming client messages against server state.
@@ -4057,82 +3944,6 @@ async function runChatRecoveryExhaustion(input, hooks) {
4057
3944
  await hooks.terminalize(ctx);
4058
3945
  }
4059
3946
  //#endregion
4060
- //#region src/chat/stall-watchdog.ts
4061
- /**
4062
- * Shared inactivity watchdog for UI-message streams.
4063
- *
4064
- * A model/transport stream can park indefinitely without ever throwing (a hung
4065
- * provider, a wedged transport). Left unguarded, the consumer read-loop waits
4066
- * forever. {@link iterateWithStallWatchdog} wraps such a stream so that a gap of
4067
- * `timeoutMs` between chunks aborts the upstream and throws
4068
- * {@link ChatStreamStalledError}, letting the consumer route the stall into
4069
- * bounded recovery (#1626) — a transient hang is retried within the existing
4070
- * recovery budget — while genuine in-band errors stay terminal.
4071
- *
4072
- * @internal Sibling-package support for `@cloudflare/ai-chat` and
4073
- * `@cloudflare/think`, not a public API. See
4074
- * `design/rfc-chat-recovery-foundation.md`.
4075
- */
4076
- /**
4077
- * Thrown by {@link iterateWithStallWatchdog} when the inactivity watchdog fires
4078
- * (a model/transport stream that parks without ever throwing). Distinct from
4079
- * in-band model/stream errors so the read-loop catch can route a stall into
4080
- * bounded recovery (#1626) — a transient hang is retried within the existing
4081
- * recovery budget — while genuine errors stay terminal.
4082
- */
4083
- var ChatStreamStalledError = class extends Error {
4084
- constructor(message) {
4085
- super(message);
4086
- this.isChatStreamStall = true;
4087
- this.name = "ChatStreamStalledError";
4088
- }
4089
- };
4090
- /**
4091
- * Wrap a UI-message stream with an inactivity watchdog. If no chunk arrives
4092
- * within `timeoutMs`, `onStall` runs (aborting the upstream model stream) and
4093
- * the iterator throws, so the consumer loop exits with a terminal error
4094
- * instead of parking forever on a hung provider/transport. `timeoutMs <= 0`
4095
- * passes the source through untouched.
4096
- */
4097
- async function* iterateWithStallWatchdog(source, timeoutMs, onStall) {
4098
- if (!(timeoutMs > 0)) {
4099
- yield* source;
4100
- return;
4101
- }
4102
- const iterator = source[Symbol.asyncIterator]();
4103
- let selfAborted = false;
4104
- try {
4105
- while (true) {
4106
- let timer;
4107
- let stalled = false;
4108
- const stall = new Promise((_, reject) => {
4109
- timer = setTimeout(() => {
4110
- stalled = true;
4111
- reject(new ChatStreamStalledError(`Chat stream stalled: no activity for ${timeoutMs}ms; the turn was aborted by the stall watchdog.`));
4112
- }, timeoutMs);
4113
- });
4114
- const nextPromise = iterator.next();
4115
- nextPromise.catch(() => {});
4116
- let next;
4117
- try {
4118
- next = await Promise.race([nextPromise, stall]);
4119
- } catch (err) {
4120
- if (stalled) {
4121
- selfAborted = true;
4122
- onStall();
4123
- }
4124
- throw err;
4125
- } finally {
4126
- if (timer !== void 0) clearTimeout(timer);
4127
- }
4128
- if (next.done) return;
4129
- yield next.value;
4130
- }
4131
- } finally {
4132
- if (!selfAborted) await iterator.return?.(void 0).catch(() => {});
4133
- }
4134
- }
4135
- //#endregion
4136
3947
  //#region src/chat/truncate-older-messages.ts
4137
3948
  /**
4138
3949
  * Truncate tool outputs and long text in older messages.