agents 0.23.0 → 0.25.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 (187) hide show
  1. package/dist/{agent-routing-DE5zmCQ8.d.ts → agent-routing-0DR0Tk2v.d.ts} +270 -190
  2. package/dist/agent-routing.d.ts +1 -1
  3. package/dist/agent-routing.js.map +1 -1
  4. package/dist/agent-tool-types.d.ts +13 -7
  5. package/dist/agent-tool-types.js +23 -1
  6. package/dist/agent-tool-types.js.map +1 -1
  7. package/dist/{agent-tools-y7zLfw4Q.js → agent-tools-CdJC-8Dc.js} +72 -9
  8. package/dist/agent-tools-CdJC-8Dc.js.map +1 -0
  9. package/dist/{agent-tools-DtXMTDGM.d.ts → agent-tools-YrATZJu2.d.ts} +29 -15
  10. package/dist/agent-tools.d.ts +6 -4
  11. package/dist/agent-tools.js.map +1 -1
  12. package/dist/ai-fm7xx1BK.js +312 -0
  13. package/dist/ai-fm7xx1BK.js.map +1 -0
  14. package/dist/base64-redaction-C1Uu29t5.js +59 -0
  15. package/dist/base64-redaction-C1Uu29t5.js.map +1 -0
  16. package/dist/browser/ai-sdk.d.ts +90 -0
  17. package/dist/browser/ai-sdk.js +51 -0
  18. package/dist/browser/ai-sdk.js.map +1 -0
  19. package/dist/browser/ai.d.ts +4 -4
  20. package/dist/browser/ai.js +1 -347
  21. package/dist/browser/index.d.ts +81 -79
  22. package/dist/browser/index.js +361 -2
  23. package/dist/browser/index.js.map +1 -0
  24. package/dist/browser/tanstack-ai.d.ts +96 -1
  25. package/dist/browser/tanstack-ai.js +62 -2
  26. package/dist/browser/tanstack-ai.js.map +1 -1
  27. package/dist/browser-DE3d-RLk.d.ts +275 -0
  28. package/dist/browser-tool-CQ10e6Kj.js +480 -0
  29. package/dist/browser-tool-CQ10e6Kj.js.map +1 -0
  30. package/dist/browser-tool-DuNdlwZ9.d.ts +73 -0
  31. package/dist/{capability-BjSKYpzg.js → capability-B4WbF81e.js} +2 -1
  32. package/dist/capability-B4WbF81e.js.map +1 -0
  33. package/dist/{capability-runner-Be_-PLR1.d.ts → capability-runner-DBAnGr6L.d.ts} +45 -15
  34. package/dist/chat/index.d.ts +341 -232
  35. package/dist/chat/index.js +602 -72
  36. package/dist/chat/index.js.map +1 -1
  37. package/dist/chat/react.d.ts +42 -2
  38. package/dist/chat/react.js +191 -35
  39. package/dist/chat/react.js.map +1 -1
  40. package/dist/chat/transport.d.ts +1 -1
  41. package/dist/chat/transport.js +1 -1
  42. package/dist/chat-sdk/index.d.ts +17 -3
  43. package/dist/chat-sdk/index.js +28 -2
  44. package/dist/chat-sdk/index.js.map +1 -1
  45. package/dist/client-4OlMIJx-.js +591 -0
  46. package/dist/client-4OlMIJx-.js.map +1 -0
  47. package/dist/{client-jagG8a9_.js → client-fyQrLGkD.js} +2 -2
  48. package/dist/{client-jagG8a9_.js.map → client-fyQrLGkD.js.map} +1 -1
  49. package/dist/client-je3koD9Z.d.ts +446 -0
  50. package/dist/client.d.ts +29 -283
  51. package/dist/client.js +2 -274
  52. package/dist/{connector-CptFKzRh.js → connector-58XDGvc3.js} +251 -120
  53. package/dist/connector-58XDGvc3.js.map +1 -0
  54. package/dist/{connector-CkQD4MK3.d.ts → connector-Cl-VqPmA.d.ts} +244 -146
  55. package/dist/context/index.d.ts +29 -0
  56. package/dist/context/index.js +64 -17
  57. package/dist/context/index.js.map +1 -1
  58. package/dist/current-agent-DhoDkSnH.js.map +1 -1
  59. package/dist/current-agent-vAk_5JMt.d.ts +93 -0
  60. package/dist/{current-agent-Da_C9a3b.d.ts → durable-object-lifecycle-HhgOMWq9.d.ts} +26 -127
  61. package/dist/harnesses/pi/index.d.ts +348 -0
  62. package/dist/harnesses/pi/index.js +754 -0
  63. package/dist/harnesses/pi/index.js.map +1 -0
  64. package/dist/images-iiTDSyRu.js +1631 -0
  65. package/dist/images-iiTDSyRu.js.map +1 -0
  66. package/dist/index-BreL0YrQ.d.ts +78 -0
  67. package/dist/index-kbSUIer3.d.ts +343 -0
  68. package/dist/index.d.ts +43 -41
  69. package/dist/index.js +2 -2
  70. package/dist/internal_context.d.ts +1 -1
  71. package/dist/lifecycle/index.d.ts +19 -17
  72. package/dist/lifecycle/index.js +2 -2
  73. package/dist/{lifecycle-CMRGjZdw.js → lifecycle-CFu6OV03.js} +73 -29
  74. package/dist/lifecycle-CFu6OV03.js.map +1 -0
  75. package/dist/mcp/client/index.d.ts +20 -20
  76. package/dist/mcp/client/index.js +1 -1
  77. package/dist/mcp/client/x402.js +21 -19
  78. package/dist/mcp/client/x402.js.map +1 -1
  79. package/dist/mcp/index.d.ts +35 -35
  80. package/dist/mcp/index.js +2 -2
  81. package/dist/{message-builder-BymO4N_D.js → message-builder-DAl9AhHH.js} +89 -4
  82. package/dist/message-builder-DAl9AhHH.js.map +1 -0
  83. package/dist/models/ai-sdk/index.d.ts +353 -0
  84. package/dist/models/ai-sdk/index.js +2443 -0
  85. package/dist/models/ai-sdk/index.js.map +1 -0
  86. package/dist/models/pi-ai/index.d.ts +313 -0
  87. package/dist/models/pi-ai/index.js +1795 -0
  88. package/dist/models/pi-ai/index.js.map +1 -0
  89. package/dist/observability/ai/index.js +20 -4
  90. package/dist/observability/ai/index.js.map +1 -1
  91. package/dist/{protocol-B0nh6KNf.js → protocol-kHsr-f0X.js} +26 -12
  92. package/dist/{protocol-B0nh6KNf.js.map → protocol-kHsr-f0X.js.map} +1 -1
  93. package/dist/queue/index.d.ts +123 -0
  94. package/dist/queue/index.js +2 -0
  95. package/dist/queue-BB-zfIYF.js +406 -0
  96. package/dist/queue-BB-zfIYF.js.map +1 -0
  97. package/dist/react.d.ts +31 -13
  98. package/dist/react.js +190 -71
  99. package/dist/react.js.map +1 -1
  100. package/dist/{retries-D9Ds-1lz.d.ts → retries-CV6AkXmQ.d.ts} +23 -8
  101. package/dist/retries.d.ts +12 -8
  102. package/dist/retries.js +19 -1
  103. package/dist/retries.js.map +1 -1
  104. package/dist/routing/index.d.ts +2 -2
  105. package/dist/routing/index.js +1 -1
  106. package/dist/{scheduler-DD9NdYbF.js → scheduler-DZ3xQfeK.js} +4 -11
  107. package/dist/scheduler-DZ3xQfeK.js.map +1 -0
  108. package/dist/{scheduler-Dwh85ZGl.d.ts → scheduler-RdACNXDP.d.ts} +6 -6
  109. package/dist/schedules/index.d.ts +1 -1
  110. package/dist/schedules/index.js +1 -1
  111. package/dist/serializable.d.ts +1 -1
  112. package/dist/sessions/index.d.ts +70 -3
  113. package/dist/sessions/index.js +276 -67
  114. package/dist/sessions/index.js.map +1 -1
  115. package/dist/skills/index.d.ts +29 -314
  116. package/dist/socket-address.d.ts +16 -0
  117. package/dist/socket-address.js +19 -0
  118. package/dist/socket-address.js.map +1 -0
  119. package/dist/{src-DlSHshb2.js → src-BZeu-SCD.js} +541 -500
  120. package/dist/src-BZeu-SCD.js.map +1 -0
  121. package/dist/state/index.d.ts +6 -0
  122. package/dist/state/index.js +137 -0
  123. package/dist/state/index.js.map +1 -0
  124. package/dist/streams/index.d.ts +1 -1
  125. package/dist/streams/index.js +1 -1
  126. package/dist/{streams-D6tJ0NN9.d.ts → streams-Cmkj9QfW.d.ts} +4 -2
  127. package/dist/{streams-DZKgAj9b.js → streams-DW-UCOUc.js} +9 -2
  128. package/dist/streams-DW-UCOUc.js.map +1 -0
  129. package/dist/sub-routing.d.ts +12 -12
  130. package/dist/tasks/index.d.ts +1 -1
  131. package/dist/tasks/index.js +1 -1
  132. package/dist/{tasks-ylZgBjhj.js → tasks-68DESxf0.js} +3 -3
  133. package/dist/{tasks-ylZgBjhj.js.map → tasks-68DESxf0.js.map} +1 -1
  134. package/dist/{tasks-BRJ5zgya.d.ts → tasks-9YxYtByh.d.ts} +5 -5
  135. package/dist/transport-PfFnt-Ld.d.ts +525 -0
  136. package/dist/transport-protocol-BxyngQ_R.js +25 -0
  137. package/dist/transport-protocol-BxyngQ_R.js.map +1 -0
  138. package/dist/transport-protocol-ZTew5Wso.d.ts +27 -0
  139. package/dist/types-BA4anrjI.d.ts +70 -0
  140. package/dist/voice/index.d.ts +2 -2
  141. package/dist/websockets/index.d.ts +195 -69
  142. package/dist/websockets/index.js +3 -2
  143. package/dist/websockets-Ci-LZFHH.js +1030 -0
  144. package/dist/websockets-Ci-LZFHH.js.map +1 -0
  145. package/dist/wire-types-CnMt6_HR.js.map +1 -1
  146. package/dist/wire-types-CrjKvDyi.d.ts +300 -0
  147. package/dist/workflow-types.d.ts +25 -25
  148. package/dist/workflows.d.ts +21 -21
  149. package/dist/workflows.js +1 -1
  150. package/dist/{ws-chat-transport-UNRIS2xl.d.ts → ws-chat-transport-BbT1A5Lc.d.ts} +51 -2
  151. package/dist/{ws-chat-transport-rWwta645.js → ws-chat-transport-cqMKq3IY.js} +143 -16
  152. package/dist/ws-chat-transport-cqMKq3IY.js.map +1 -0
  153. package/docs/agent-class.md +2 -2
  154. package/docs/agent-tools.md +29 -4
  155. package/docs/browse-the-web.md +87 -5
  156. package/docs/chat-agents.md +124 -16
  157. package/docs/client-sdk.md +30 -0
  158. package/docs/context.md +27 -0
  159. package/docs/durable-execution.md +2 -0
  160. package/docs/harnesses/pi.md +91 -0
  161. package/docs/human-in-the-loop.md +4 -0
  162. package/docs/index.md +4 -1
  163. package/docs/lifecycle.md +114 -23
  164. package/docs/models-pi-ai.md +325 -0
  165. package/docs/models.md +504 -0
  166. package/docs/queue.md +135 -241
  167. package/docs/resumable-streaming.md +2 -0
  168. package/docs/retries.md +1 -1
  169. package/docs/routing.md +13 -13
  170. package/docs/sessions.md +36 -1
  171. package/docs/state.md +1 -0
  172. package/docs/sub-agents.md +12 -3
  173. package/package.json +51 -3
  174. package/dist/agent-tools-y7zLfw4Q.js.map +0 -1
  175. package/dist/browser/ai.js.map +0 -1
  176. package/dist/capability-BjSKYpzg.js.map +0 -1
  177. package/dist/client-tools-aIBO0Fk7.d.ts +0 -53
  178. package/dist/client.js.map +0 -1
  179. package/dist/connector-CptFKzRh.js.map +0 -1
  180. package/dist/lifecycle-CMRGjZdw.js.map +0 -1
  181. package/dist/message-builder-BymO4N_D.js.map +0 -1
  182. package/dist/scheduler-DD9NdYbF.js.map +0 -1
  183. package/dist/src-DlSHshb2.js.map +0 -1
  184. package/dist/streams-DZKgAj9b.js.map +0 -1
  185. package/dist/websockets-DUfRHPRq.js +0 -502
  186. package/dist/websockets-DUfRHPRq.js.map +0 -1
  187. package/dist/ws-chat-transport-rWwta645.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  import {
2
- _ as LifecycleJobOutcome,
2
+ _ as LifecycleJobContext,
3
3
  d as LifecycleRouteContext,
4
- g as LifecycleJobContext,
5
4
  o as MemoryLimitContext,
6
- s as LifecycleCapability
7
- } from "./capability-runner-Be_-PLR1.js";
5
+ s as LifecycleCapability,
6
+ v as LifecycleJobOutcome
7
+ } from "./capability-runner-DBAnGr6L.js";
8
8
 
9
9
  //#region src/tasks/duration.d.ts
10
10
  /**
@@ -514,4 +514,4 @@ export {
514
514
  TaskWaitReason as x,
515
515
  TaskStepConfig as y
516
516
  };
517
- //# sourceMappingURL=tasks-BRJ5zgya.d.ts.map
517
+ //# sourceMappingURL=tasks-9YxYtByh.d.ts.map
@@ -0,0 +1,525 @@
1
+ //#region src/models/core/catalog.d.ts
2
+ /**
3
+ * Keys of the ambient `AiModels` interface (from `@cloudflare/workers-types`)
4
+ * whose model type extends `T`. Kept in step with the installed workers-types
5
+ * version rather than hand-maintained here.
6
+ */
7
+ type WorkersAIModelIdsExtending<T> = {
8
+ [K in keyof AiModels]: AiModels[K] extends T ? K : never;
9
+ }[keyof AiModels];
10
+ /** The `inputs` shape a catalog entry declares. */
11
+ type InputsOf<K extends keyof AiModels> = AiModels[K] extends {
12
+ inputs: infer I;
13
+ }
14
+ ? I
15
+ : never;
16
+ /** The `postProcessedOutputs` shape a catalog entry declares. */
17
+ type OutputsOf<K extends keyof AiModels> = AiModels[K] extends {
18
+ postProcessedOutputs: infer O;
19
+ }
20
+ ? O
21
+ : never;
22
+ /**
23
+ * Catalog keys whose input takes a required `messages` array — every current
24
+ * chat model. Newer entries get their own generated class rather than
25
+ * extending `BaseAiTextGeneration`, so the base-class arm alone misses them.
26
+ */
27
+ type ChatCatalogId = {
28
+ [K in keyof AiModels]: Extract<
29
+ InputsOf<K>,
30
+ {
31
+ messages: unknown;
32
+ }
33
+ > extends never
34
+ ? never
35
+ : K;
36
+ }[keyof AiModels];
37
+ /**
38
+ * Catalog keys that take text and answer with embedding vectors. Both halves
39
+ * matter: the input test alone also matches translation, classification and
40
+ * speech models, which take `text` but return something else entirely.
41
+ */
42
+ type EmbeddingCatalogId = {
43
+ [K in keyof AiModels]: Extract<
44
+ InputsOf<K>,
45
+ {
46
+ text: unknown;
47
+ }
48
+ > extends never
49
+ ? never
50
+ : Extract<
51
+ OutputsOf<K>,
52
+ {
53
+ data?: number[][];
54
+ }
55
+ > extends never
56
+ ? never
57
+ : K;
58
+ }[keyof AiModels];
59
+ /**
60
+ * Catalog keys that take audio to transcribe. The `audio` key is required on
61
+ * every speech-recognition input and on no other input shape, so the test is
62
+ * exact rather than heuristic.
63
+ */
64
+ type TranscriptionCatalogId = {
65
+ [K in keyof AiModels]: Extract<
66
+ InputsOf<K>,
67
+ {
68
+ audio: unknown;
69
+ }
70
+ > extends never
71
+ ? never
72
+ : K;
73
+ }[keyof AiModels];
74
+ /**
75
+ * Catalog keys that score a list of contexts against a query — rerankers.
76
+ * `contexts` is required on exactly those inputs.
77
+ */
78
+ type RerankingCatalogId = {
79
+ [K in keyof AiModels]: Extract<
80
+ InputsOf<K>,
81
+ {
82
+ contexts: unknown;
83
+ }
84
+ > extends never
85
+ ? never
86
+ : K;
87
+ }[keyof AiModels];
88
+ /**
89
+ * A Workers AI model id.
90
+ *
91
+ * Workers AI is the one catalog this package keeps up with, so this is the
92
+ * only id shape it accepts: `@cf/<author>/<model>`. Autocomplete covers the
93
+ * text-generation catalog from the installed `@cloudflare/workers-types`; the
94
+ * template arm keeps every other `@cf/` slug assignable, because the catalog
95
+ * lives server-side and moves independently of these types.
96
+ *
97
+ * Third-party models are not ids here — they are model objects built by their
98
+ * own provider package and routed through AI Gateway.
99
+ *
100
+ * @experimental This surface is experimental and may change.
101
+ */
102
+ type WorkersAIModelId =
103
+ | Extract<
104
+ | ChatCatalogId
105
+ | Exclude<
106
+ WorkersAIModelIdsExtending<BaseAiTextGeneration>,
107
+ WorkersAIModelIdsExtending<BaseAiTextToImage>
108
+ >,
109
+ `@cf/${string}`
110
+ >
111
+ | (`@cf/${string}` & {});
112
+ /**
113
+ * A text-embedding model id accepted by `ai.embedding()`.
114
+ *
115
+ * The modality methods are Workers AI only — there is no vendor route for them
116
+ * — so, like {@link WorkersAIModelId}, they take `@cf/` ids and nothing else.
117
+ *
118
+ * @experimental This surface is experimental and may change.
119
+ */
120
+ type CloudflareEmbeddingModelId =
121
+ | Extract<
122
+ EmbeddingCatalogId | WorkersAIModelIdsExtending<BaseAiTextEmbeddings>,
123
+ `@cf/${string}`
124
+ >
125
+ | (`@cf/${string}` & {});
126
+ /**
127
+ * Workers AI text-to-image ids that the generated `AiModels` entries do not
128
+ * classify as {@link BaseAiTextToImage} — the newer partner models get their
129
+ * own generated class instead. Curated for autocomplete only; the catalog
130
+ * lives server-side and any slug is accepted.
131
+ *
132
+ * The FLUX.2 family (`flux-2-dev`, `flux-2-klein-4b`, `flux-2-klein-9b`) is
133
+ * deliberately absent, for the reason {@link UnsupportedTranscriptionId}
134
+ * records for the Deepgram recognisers: its generated input takes a required
135
+ * `multipart` object body (`{ multipart: { body, contentType } }`) and no
136
+ * `prompt`, which the JSON run path cannot carry — live, the run path answers
137
+ * `400 Bad input: required properties at "/" are 'multipart'`. Suggesting an
138
+ * id that always 400s is worse than not suggesting it.
139
+ *
140
+ * @experimental This surface is experimental and may change.
141
+ */
142
+ type KnownImageModelId =
143
+ | "@cf/black-forest-labs/flux-1-schnell"
144
+ | "@cf/leonardo/lucid-origin"
145
+ | "@cf/leonardo/phoenix-1.0";
146
+ /**
147
+ * An image model id accepted by `ai.image()`.
148
+ *
149
+ * @experimental This surface is experimental and may change.
150
+ */
151
+ type CloudflareImageModelId =
152
+ | Extract<
153
+ WorkersAIModelIdsExtending<BaseAiTextToImage> | KnownImageModelId,
154
+ `@cf/${string}`
155
+ >
156
+ | (`@cf/${string}` & {});
157
+ /**
158
+ * Workers AI text-to-speech ids without a {@link BaseAiTextToSpeech} entry.
159
+ * Curated for autocomplete only.
160
+ *
161
+ * @experimental This surface is experimental and may change.
162
+ */
163
+ type KnownSpeechModelId =
164
+ | "@cf/deepgram/aura-1"
165
+ | "@cf/deepgram/aura-2-en"
166
+ | "@cf/deepgram/aura-2-es";
167
+ /**
168
+ * A text-to-speech model id accepted by `ai.speech()`.
169
+ *
170
+ * @experimental This surface is experimental and may change.
171
+ */
172
+ type CloudflareSpeechModelId =
173
+ | Extract<
174
+ WorkersAIModelIdsExtending<BaseAiTextToSpeech> | KnownSpeechModelId,
175
+ `@cf/${string}`
176
+ >
177
+ | (`@cf/${string}` & {});
178
+ /**
179
+ * Deepgram's recognition models want the audio as an object body
180
+ * (`audio: { body, contentType }`) rather than as base64, which the JSON run
181
+ * path cannot carry — every documented variant answered `400` live. They stay
182
+ * out of the suggested arm, and the transcription model answers a clear error
183
+ * for them.
184
+ */
185
+ type UnsupportedTranscriptionId = "@cf/deepgram/nova-3" | "@cf/deepgram/flux";
186
+ /**
187
+ * A speech-recognition model id accepted by `ai.transcription()`.
188
+ *
189
+ * Deepgram's recognition models (`@cf/deepgram/nova-3`, `@cf/deepgram/flux`)
190
+ * are deliberately not suggested: the run path rejects their documented input
191
+ * shape, so this provider answers a clear error for them rather than a 400.
192
+ *
193
+ * @experimental This surface is experimental and may change.
194
+ */
195
+ type CloudflareTranscriptionModelId =
196
+ | Extract<
197
+ | Exclude<TranscriptionCatalogId, UnsupportedTranscriptionId>
198
+ | Exclude<
199
+ WorkersAIModelIdsExtending<BaseAiAutomaticSpeechRecognition>,
200
+ UnsupportedTranscriptionId
201
+ >,
202
+ `@cf/${string}`
203
+ >
204
+ | (`@cf/${string}` & {});
205
+ /**
206
+ * A reranking model id accepted by `ai.reranking()`.
207
+ *
208
+ * @experimental This surface is experimental and may change.
209
+ */
210
+ type CloudflareRerankingModelId =
211
+ | Extract<RerankingCatalogId, `@cf/${string}`>
212
+ | (`@cf/${string}` & {});
213
+ //#endregion
214
+ //#region src/models/core/settings.d.ts
215
+ /**
216
+ * AI Gateway settings for a request. The gateway is an option, not a separate
217
+ * product: every call goes through one, and `id` defaults to `"default"`,
218
+ * which Cloudflare creates on first use.
219
+ *
220
+ * @experimental This surface is experimental and may change.
221
+ */
222
+ interface GatewayOptions {
223
+ /** Gateway id. Defaults to `"default"` (auto-created on first use). */
224
+ id?: string;
225
+ /** Bypass the cache for this request. */
226
+ skipCache?: boolean;
227
+ /** Cache lifetime in seconds. */
228
+ cacheTtl?: number;
229
+ /** Explicit cache key, instead of the request-derived one. */
230
+ cacheKey?: string;
231
+ /** Whether the gateway stores the request/response in its log. */
232
+ collectLog?: boolean;
233
+ /** Arbitrary key/values attached to the gateway log entry. */
234
+ metadata?: Record<string, string | number | boolean | null>;
235
+ /** Correlates several requests into one gateway event. */
236
+ eventId?: string;
237
+ /** Upstream request timeout in milliseconds. */
238
+ requestTimeoutMs?: number;
239
+ /** Server-side retry policy for the upstream provider call. */
240
+ retries?: {
241
+ maxAttempts?: 1 | 2 | 3 | 4 | 5;
242
+ retryDelayMs?: number;
243
+ backoff?: "constant" | "linear" | "exponential";
244
+ };
245
+ }
246
+ /**
247
+ * How `createAI` reaches Cloudflare: the Workers AI binding, and nothing else.
248
+ * Workers AI models go through `env.AI.run`, vendor models through
249
+ * `env.AI.gateway(id).run` — both are the binding, so there is no HTTP
250
+ * transport, no account id and no API token to hold.
251
+ *
252
+ * @experimental This surface is experimental and may change.
253
+ */
254
+ type AISettings = {
255
+ /** The `AI` binding from a Worker's env. */ binding: Ai;
256
+ } & ProviderGatewaySettings;
257
+ /**
258
+ * Provider-wide gateway defaults, in either spelling: nested under `gateway`,
259
+ * or flat (`{ id: "prod", cacheTtl: 60 }`). Both merge, the flat key winning.
260
+ *
261
+ * @experimental This surface is experimental and may change.
262
+ */
263
+ interface ProviderGatewaySettings extends GatewayOptions {
264
+ /** Gateway id or full gateway options. */
265
+ gateway?: string | GatewayOptions;
266
+ }
267
+ /**
268
+ * Per-model and per-call options. The flat gateway keys are sugar for
269
+ * `gateway: { ... }`; both forms merge, with the flat key winning.
270
+ *
271
+ * The same shape is accepted per call under
272
+ * `providerOptions.cloudflare`, where it takes precedence over the per-model
273
+ * options, which in turn take precedence over the `createAI` settings.
274
+ *
275
+ * `Leg` is what a framework module accepts as a fallback leg. Workers AI ids
276
+ * are the only kind this module can resolve on its own, so they are the
277
+ * default; a module whose legs may also be model objects says so
278
+ * (`ModelOptions<WorkersAIModelId | LanguageModelV4>`) rather than rebuilding
279
+ * the type.
280
+ *
281
+ * @experimental This surface is experimental and may change.
282
+ */
283
+ interface ModelOptions<Leg = WorkersAIModelId> extends ProviderGatewaySettings {
284
+ /**
285
+ * Models to try, in order, if the primary fails before any output is
286
+ * produced. A leg travels with the chain's gateway options — those win over
287
+ * a leg's own, and `metadata` merges — while everything a leg was built with
288
+ * itself stays its own. Client-side today; becomes server-side when the
289
+ * platform ships model-first routing.
290
+ */
291
+ fallback?: Leg[];
292
+ /** Extra request headers, merged last. */
293
+ headers?: Record<string, string>;
294
+ /**
295
+ * Workers AI only: route same-key requests to the same replica for
296
+ * prefix-cache hits. Sent as the `x-session-affinity` header.
297
+ */
298
+ sessionAffinity?: string;
299
+ /**
300
+ * Explicit reasoning effort. `null` disables reasoning on models that
301
+ * support toggling it. The unified AI SDK `reasoning` call option maps onto
302
+ * this when this is not set.
303
+ */
304
+ reasoningEffort?: "low" | "medium" | "high" | null;
305
+ /**
306
+ * Workers AI only: forwarded verbatim as `chat_template_kwargs`, e.g.
307
+ * `{ enable_thinking: false }`.
308
+ */
309
+ chatTemplateKwargs?: Record<string, unknown>;
310
+ }
311
+ /** A gateway config with the id filled in. */
312
+ interface ResolvedGateway extends GatewayOptions {
313
+ id: string;
314
+ }
315
+ //#endregion
316
+ //#region src/models/core/errors.d.ts
317
+ /**
318
+ * Coarse classification of a failed Cloudflare AI call.
319
+ *
320
+ * @experimental This surface is experimental and may change.
321
+ */
322
+ type CloudflareAIErrorCode =
323
+ | "auth"
324
+ | "rate-limit"
325
+ | "not-found"
326
+ | "bad-request"
327
+ | "provider-error"
328
+ | "gateway-error"
329
+ | "unknown";
330
+ /**
331
+ * One leg of a {@link CloudflareAIError} fallback chain.
332
+ *
333
+ * @experimental This surface is experimental and may change.
334
+ */
335
+ interface CloudflareAIAttempt {
336
+ /** The model id that was tried. */
337
+ model: string;
338
+ /** The error that leg failed with. */
339
+ error: unknown;
340
+ }
341
+ /**
342
+ * Error thrown for every failed Cloudflare AI call, whether it came back as a
343
+ * non-2xx `Response` or as a thrown Workers AI binding error. Framework
344
+ * modules wrap it into their own error type at their boundary (the AI SDK
345
+ * module into an `APICallError`, so `ai`'s retry loop honours
346
+ * {@link CloudflareAIError.isRetryable}).
347
+ *
348
+ * @experimental This surface is experimental and may change.
349
+ */
350
+ declare class CloudflareAIError extends Error {
351
+ /** HTTP status, when the failure carried one. */
352
+ readonly status: number | undefined;
353
+ /** Coarse classification used for routing and fallback decisions. */
354
+ readonly code: CloudflareAIErrorCode;
355
+ /** `cf-aig-log-id` of the failed request, when the response carried one. */
356
+ readonly logId: string | undefined;
357
+ /** The model id that produced this error. */
358
+ readonly model: string;
359
+ /** Which binding path the request went down, for error reporting. */
360
+ readonly url: string;
361
+ /** The request body that failed. */
362
+ readonly requestBodyValues: unknown;
363
+ /** Response headers, when there was a response. */
364
+ readonly responseHeaders: Record<string, string> | undefined;
365
+ /** Raw response body text, when there was a response. */
366
+ readonly responseBody: string | undefined;
367
+ /** Whether a retry is worth attempting. */
368
+ readonly isRetryable: boolean;
369
+ /** Parsed error envelope, or other structured detail. */
370
+ readonly data: unknown;
371
+ /** Every leg tried, when this error ends a fallback chain. */
372
+ readonly attempts: CloudflareAIAttempt[] | undefined;
373
+ readonly cause: unknown;
374
+ constructor(options: {
375
+ message: string;
376
+ model: string;
377
+ url: string;
378
+ requestBodyValues: unknown;
379
+ status?: number;
380
+ code: CloudflareAIErrorCode;
381
+ logId?: string;
382
+ responseHeaders?: Record<string, string>;
383
+ responseBody?: string;
384
+ isRetryable?: boolean;
385
+ data?: unknown;
386
+ cause?: unknown;
387
+ attempts?: CloudflareAIAttempt[];
388
+ });
389
+ }
390
+ //#endregion
391
+ //#region src/models/core/gateway-providers.d.ts
392
+ /**
393
+ * The AI Gateway provider table: which gateway provider slug a vendor's own
394
+ * base URL belongs to, and what the universal request's `endpoint` is for a
395
+ * given upstream URL.
396
+ *
397
+ * This is platform knowledge, not vendor knowledge — the gateway publishes the
398
+ * list, and every entry here appears in `AIGatewayProviders` from
399
+ * `@cloudflare/workers-types`. Nothing about a vendor's wire format, model ids
400
+ * or capabilities lives here: the vendor's own provider package builds the
401
+ * request, and this table only says where it goes.
402
+ *
403
+ * Adapted from `@cloudflare/ai-gateway-provider`'s `providers.ts`.
404
+ *
405
+ * @experimental This surface is experimental and may change.
406
+ */
407
+ /**
408
+ * The gateway provider slugs this table maps onto. A subset of the ambient
409
+ * `AIGatewayProviders` union; {@link GatewayProviderNameCheck} keeps it one.
410
+ *
411
+ * @experimental This surface is experimental and may change.
412
+ */
413
+ declare const GATEWAY_PROVIDER_NAMES: readonly [
414
+ "workers-ai",
415
+ "anthropic",
416
+ "openai",
417
+ "azure-openai",
418
+ "google-ai-studio",
419
+ "google-vertex-ai",
420
+ "grok",
421
+ "mistral",
422
+ "perplexity-ai",
423
+ "replicate",
424
+ "groq",
425
+ "deepseek",
426
+ "openrouter",
427
+ "cerebras",
428
+ "cohere",
429
+ "huggingface",
430
+ "aws-bedrock",
431
+ "elevenlabs",
432
+ "cartesia"
433
+ ];
434
+ /**
435
+ * A gateway provider slug.
436
+ *
437
+ * @experimental This surface is experimental and may change.
438
+ */
439
+ type GatewayProviderName = (typeof GATEWAY_PROVIDER_NAMES)[number];
440
+ //#endregion
441
+ //#region src/models/core/transport.d.ts
442
+ /** One request on the Cloudflare run path. */
443
+ interface TransportRequest {
444
+ /** Model id — Workers AI slug or catalog `<author>/<model>`. */
445
+ model: string;
446
+ /** The provider-shaped request body (`input` on the run path). */
447
+ input: Record<string, unknown>;
448
+ /** Gateway options for this request. */
449
+ gateway: ResolvedGateway;
450
+ /** Extra request headers, merged last. */
451
+ headers: Record<string, string>;
452
+ /** Abort signal, forwarded to the binding or to `fetch`. */
453
+ signal?: AbortSignal;
454
+ }
455
+ /**
456
+ * One request on the universal AI Gateway path: a vendor's own request, routed
457
+ * by the gateway to that vendor. The body is the vendor's, untouched — nothing
458
+ * here knows the vendor's wire format.
459
+ *
460
+ * @experimental This surface is experimental and may change.
461
+ */
462
+ interface UniversalRequest {
463
+ /** The gateway provider slug the request is routed to. */
464
+ provider: GatewayProviderName | string;
465
+ /** The vendor path the gateway appends to that provider's base URL. */
466
+ endpoint: string;
467
+ /** The vendor's own request headers, minus its credential header. */
468
+ headers: Record<string, string>;
469
+ /** The vendor's request body, verbatim. */
470
+ query: unknown;
471
+ /** Gateway options for this request. */
472
+ gateway: ResolvedGateway;
473
+ /** Extra headers merged last, outside the vendor's own set. */
474
+ extraHeaders?: Record<string, string>;
475
+ /** Abort signal, forwarded to the binding or to `fetch`. */
476
+ signal?: AbortSignal;
477
+ }
478
+ /**
479
+ * The single code path both backends implement. Always resolves to a raw
480
+ * `Response`, so streaming and non-streaming calls share one path and nothing
481
+ * is buffered on the caller's behalf.
482
+ *
483
+ * @experimental This surface is experimental and may change.
484
+ */
485
+ interface Transport {
486
+ /** A stable identifier for the endpoint, used in error reporting. */
487
+ readonly url: string;
488
+ run(request: TransportRequest): Promise<Response>;
489
+ /**
490
+ * Sends a vendor's own request through the gateway's universal endpoint.
491
+ * Always resolves to the vendor's raw `Response`, error responses included:
492
+ * only the gateway's own failures (a missing gateway, an unpaid account) are
493
+ * lifted into a {@link CloudflareAIError}, because the vendor's provider
494
+ * knows how to read its own errors and we do not.
495
+ */
496
+ universal(request: UniversalRequest): Promise<Response>;
497
+ /**
498
+ * A log id read off the backend itself when the response carried none. The
499
+ * Workers AI binding exposes the last gateway log id as a mutable property,
500
+ * so it is captured per response rather than read late.
501
+ */
502
+ logIdFallback(response: Response): string | undefined;
503
+ }
504
+ //#endregion
505
+ export {
506
+ KnownSpeechModelId as _,
507
+ CloudflareAIError as a,
508
+ GatewayOptions as c,
509
+ CloudflareEmbeddingModelId as d,
510
+ CloudflareImageModelId as f,
511
+ KnownImageModelId as g,
512
+ CloudflareTranscriptionModelId as h,
513
+ CloudflareAIAttempt as i,
514
+ ModelOptions as l,
515
+ CloudflareSpeechModelId as m,
516
+ GATEWAY_PROVIDER_NAMES as n,
517
+ CloudflareAIErrorCode as o,
518
+ CloudflareRerankingModelId as p,
519
+ GatewayProviderName as r,
520
+ AISettings as s,
521
+ Transport as t,
522
+ ProviderGatewaySettings as u,
523
+ WorkersAIModelId as v
524
+ };
525
+ //# sourceMappingURL=transport-PfFnt-Ld.d.ts.map
@@ -0,0 +1,25 @@
1
+ //#region src/websockets/transport-protocol.ts
2
+ /** Query parameter selecting the Cap'n Web connection transport. */
3
+ const CAPNWEB_TRANSPORT_QUERY = "__agents_transport";
4
+ const CAPNWEB_TRANSPORT_VALUE = "capnweb";
5
+ /**
6
+ * The single method on the host's session root: the frame pipe from the
7
+ * client to the host. Every Agent protocol frame travels through it.
8
+ */
9
+ const CAPNWEB_TRANSPORT_SEND = "__cf_agent_send";
10
+ /** Rewrite a host URL to select the Cap'n Web transport over `ws(s)`. */
11
+ function capnWebTransportUrl(url) {
12
+ const resolved = new URL(url);
13
+ if (resolved.protocol === "http:") resolved.protocol = "ws:";
14
+ if (resolved.protocol === "https:") resolved.protocol = "wss:";
15
+ resolved.searchParams.set(CAPNWEB_TRANSPORT_QUERY, CAPNWEB_TRANSPORT_VALUE);
16
+ return resolved.toString();
17
+ }
18
+ /** Whether a request is a WebSocket upgrade selecting the transport. */
19
+ function isCapnWebTransportUpgrade(request) {
20
+ return request.headers.get("Upgrade")?.toLowerCase() === "websocket" && new URL(request.url).searchParams.get("__agents_transport") === "capnweb";
21
+ }
22
+ //#endregion
23
+ export { isCapnWebTransportUpgrade as a, capnWebTransportUrl as i, CAPNWEB_TRANSPORT_SEND as n, CAPNWEB_TRANSPORT_VALUE as r, CAPNWEB_TRANSPORT_QUERY as t };
24
+
25
+ //# sourceMappingURL=transport-protocol-BxyngQ_R.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport-protocol-BxyngQ_R.js","names":[],"sources":["../src/websockets/transport-protocol.ts"],"sourcesContent":["/**\n * Isomorphic wire contract for the Cap'n Web connection transport.\n *\n * Imported by browser bundles and by the Worker runtime, so it must not\n * import `cloudflare:workers`.\n */\n\n/** Wire a `useAgent` / `AgentClient` connection travels on. */\nexport type AgentTransport = \"cf-websocket\" | \"capnweb\";\n\n/** Query parameter selecting the Cap'n Web connection transport. */\nexport const CAPNWEB_TRANSPORT_QUERY = \"__agents_transport\";\nexport const CAPNWEB_TRANSPORT_VALUE = \"capnweb\";\n\n/**\n * The single method on the host's session root: the frame pipe from the\n * client to the host. Every Agent protocol frame travels through it.\n */\nexport const CAPNWEB_TRANSPORT_SEND = \"__cf_agent_send\";\n\nexport type TransportMessage = string | ArrayBuffer | ArrayBufferView;\n\n/** Root the client exposes; the host delivers frames through it. */\nexport type TransportClientEvents = {\n message(value: TransportMessage): void | Promise<void>;\n};\n\n/** Root the host exposes; the client sends frames through it. */\nexport type TransportHostPipe = {\n [CAPNWEB_TRANSPORT_SEND](message: TransportMessage): Promise<void>;\n};\n\n/** Rewrite a host URL to select the Cap'n Web transport over `ws(s)`. */\nexport function capnWebTransportUrl(url: string | URL): string {\n const resolved = new URL(url);\n if (resolved.protocol === \"http:\") resolved.protocol = \"ws:\";\n if (resolved.protocol === \"https:\") resolved.protocol = \"wss:\";\n resolved.searchParams.set(CAPNWEB_TRANSPORT_QUERY, CAPNWEB_TRANSPORT_VALUE);\n return resolved.toString();\n}\n\n/** Whether a request is a WebSocket upgrade selecting the transport. */\nexport function isCapnWebTransportUpgrade(request: Request): boolean {\n return (\n request.headers.get(\"Upgrade\")?.toLowerCase() === \"websocket\" &&\n new URL(request.url).searchParams.get(CAPNWEB_TRANSPORT_QUERY) ===\n CAPNWEB_TRANSPORT_VALUE\n );\n}\n"],"mappings":";;AAWA,MAAa,0BAA0B;AACvC,MAAa,0BAA0B;;;;;AAMvC,MAAa,yBAAyB;;AAetC,SAAgB,oBAAoB,KAA2B;CAC7D,MAAM,WAAW,IAAI,IAAI,GAAG;CAC5B,IAAI,SAAS,aAAa,SAAS,SAAS,WAAW;CACvD,IAAI,SAAS,aAAa,UAAU,SAAS,WAAW;CACxD,SAAS,aAAa,IAAI,yBAAyB,uBAAuB;CAC1E,OAAO,SAAS,SAAS;AAC3B;;AAGA,SAAgB,0BAA0B,SAA2B;CACnE,OACE,QAAQ,QAAQ,IAAI,SAAS,CAAC,EAAE,YAAY,MAAM,eAClD,IAAI,IAAI,QAAQ,GAAG,CAAC,CAAC,aAAa,IAAA,oBAA2B,MAAA;AAGjE"}
@@ -0,0 +1,27 @@
1
+ //#region src/websockets/transport-protocol.d.ts
2
+ /**
3
+ * Isomorphic wire contract for the Cap'n Web connection transport.
4
+ *
5
+ * Imported by browser bundles and by the Worker runtime, so it must not
6
+ * import `cloudflare:workers`.
7
+ */
8
+ /** Wire a `useAgent` / `AgentClient` connection travels on. */
9
+ type AgentTransport = "cf-websocket" | "capnweb";
10
+ /** Query parameter selecting the Cap'n Web connection transport. */
11
+ declare const CAPNWEB_TRANSPORT_QUERY = "__agents_transport";
12
+ declare const CAPNWEB_TRANSPORT_VALUE = "capnweb";
13
+ type TransportMessage = string | ArrayBuffer | ArrayBufferView;
14
+ /** Rewrite a host URL to select the Cap'n Web transport over `ws(s)`. */
15
+ declare function capnWebTransportUrl(url: string | URL): string;
16
+ /** Whether a request is a WebSocket upgrade selecting the transport. */
17
+ declare function isCapnWebTransportUpgrade(request: Request): boolean;
18
+ //#endregion
19
+ export {
20
+ capnWebTransportUrl as a,
21
+ TransportMessage as i,
22
+ CAPNWEB_TRANSPORT_QUERY as n,
23
+ isCapnWebTransportUpgrade as o,
24
+ CAPNWEB_TRANSPORT_VALUE as r,
25
+ AgentTransport as t
26
+ };
27
+ //# sourceMappingURL=transport-protocol-ZTew5Wso.d.ts.map
@@ -0,0 +1,70 @@
1
+ import { t as RetryOptions } from "./retries-CV6AkXmQ.js";
2
+
3
+ //#region src/queue/types.d.ts
4
+ /**
5
+ * One durable background task waiting in a Queue.
6
+ *
7
+ * @template T Type of the callback payload.
8
+ */
9
+ type QueueItem<T = unknown> = {
10
+ /** Unique item identifier. */ id: string /** Name of the callback invoked with the payload. */;
11
+ callback: string /** Data passed to the callback. */;
12
+ payload: T /** Creation time as a Unix timestamp in seconds. */;
13
+ createdAt: number /** Retry policy applied when the callback throws. */;
14
+ retry?: RetryOptions;
15
+ };
16
+ /**
17
+ * Constraint for a Queue's registered callback map: named handlers receiving
18
+ * the parsed payload and the item being processed.
19
+ *
20
+ * @experimental The API surface may change before stabilizing.
21
+ */
22
+ type QueueHandlers = Record<string, (payload: never, item: never) => unknown>;
23
+ /**
24
+ * Default callback surface for a Queue constructed without registered
25
+ * callbacks: any name compiles with an untyped payload. At runtime a name
26
+ * must be registered or supplied by a composition-root resolver (the
27
+ * aperture behind Agent's name-based queue API); a bare Queue rejects it
28
+ * otherwise.
29
+ *
30
+ * @experimental The API surface may change before stabilizing.
31
+ */
32
+ type QueueCallbacks = Record<
33
+ string,
34
+ (payload: unknown, item: QueueItem<unknown>) => unknown
35
+ >;
36
+ /**
37
+ * The payload type a registered queue callback accepts.
38
+ *
39
+ * @experimental The API surface may change before stabilizing.
40
+ */
41
+ type QueuePayload<Handler> = Handler extends (
42
+ payload: infer Payload,
43
+ ...rest: never[]
44
+ ) => unknown
45
+ ? Payload
46
+ : never;
47
+ /** Options accepted when pushing one item. */
48
+ type QueuePushOptions = {
49
+ /**
50
+ * Stable item id. A push with an existing id replaces that item in place
51
+ * (and supersedes a dispatch of it that is still in flight). Omitted ids
52
+ * are generated.
53
+ */
54
+ id?: string /** Retry policy for callback execution, overriding the Queue default. */;
55
+ retry?: RetryOptions;
56
+ };
57
+ /** Filters accepted by `list()`. */
58
+ type QueueCriteria = {
59
+ /** Only items addressed to this callback. */ callback?: string;
60
+ };
61
+ //#endregion
62
+ export {
63
+ QueuePayload as a,
64
+ QueueItem as i,
65
+ QueueCriteria as n,
66
+ QueuePushOptions as o,
67
+ QueueHandlers as r,
68
+ QueueCallbacks as t
69
+ };
70
+ //# sourceMappingURL=types-BA4anrjI.d.ts.map
@@ -1,5 +1,5 @@
1
- import { b as Connection } from "../capability-runner-Be_-PLR1.js";
2
- import { c as Agent } from "../agent-routing-DE5zmCQ8.js";
1
+ import { x as Connection } from "../capability-runner-DBAnGr6L.js";
2
+ import { c as Agent } from "../agent-routing-0DR0Tk2v.js";
3
3
  import {
4
4
  C as VoiceTransport,
5
5
  D as VoiceTurnSource,