agents 0.30.1 → 0.32.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 (182) hide show
  1. package/README.md +2 -1
  2. package/dist/{agent-routing-CDbpVjYq.d.ts → agent-routing-vVMA7m8Y.d.ts} +69 -608
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +1 -1
  5. package/dist/{agent-tools-C8DH8Yii.d.ts → agent-tools-gGXXkf1z.d.ts} +2 -2
  6. package/dist/agent-tools.d.ts +1 -1
  7. package/dist/agent-tools.js +0 -1
  8. package/dist/agent-tools.js.map +1 -1
  9. package/dist/{ai-iXw0uOGj.d.ts → ai-CDn3Abax.d.ts} +30 -4
  10. package/dist/{ai-sdk-DRPh2rRa.js → ai-sdk-Kon40i0q.js} +2 -36
  11. package/dist/ai-sdk-Kon40i0q.js.map +1 -0
  12. package/dist/browser/ai.d.ts +1 -1
  13. package/dist/browser/ai.js +16 -3
  14. package/dist/browser/ai.js.map +1 -1
  15. package/dist/browser/index.d.ts +64 -16
  16. package/dist/browser/index.js +4 -4
  17. package/dist/browser/tools/ai-sdk.d.ts +7 -5
  18. package/dist/browser/tools/ai-sdk.js +4 -4
  19. package/dist/browser/tools/ai-sdk.js.map +1 -1
  20. package/dist/browser/tools/pi.d.ts +9 -15
  21. package/dist/browser/tools/pi.js +6 -14
  22. package/dist/browser/tools/pi.js.map +1 -1
  23. package/dist/browser/tools/tanstack-ai.d.ts +48 -25
  24. package/dist/browser/tools/tanstack-ai.js +8 -4
  25. package/dist/browser/tools/tanstack-ai.js.map +1 -1
  26. package/dist/{browser-DccPw_wW.js → browser-1eUbPvC2.js} +413 -14
  27. package/dist/browser-1eUbPvC2.js.map +1 -0
  28. package/dist/{browser-DlXhSAdf.d.ts → browser-D9RNpJuT.d.ts} +254 -20
  29. package/dist/browser-tool-BhjCcNVE.d.ts +71 -0
  30. package/dist/browser-tool-DRan7Lk6.js +497 -0
  31. package/dist/browser-tool-DRan7Lk6.js.map +1 -0
  32. package/dist/capability-id-B3J8Nok_.js +13 -0
  33. package/dist/capability-id-B3J8Nok_.js.map +1 -0
  34. package/dist/catalog-BpOejOsE.js +239 -0
  35. package/dist/catalog-BpOejOsE.js.map +1 -0
  36. package/dist/catalog-BpiVV1OF.d.ts +173 -0
  37. package/dist/chat/index.d.ts +2 -2
  38. package/dist/chat-sdk/index.d.ts +3 -3
  39. package/dist/chat-sdk/index.js +1 -1
  40. package/dist/client-4OlMIJx-.js.map +1 -1
  41. package/dist/{client-BnYbNT3z.js → client-DMWujQJ1.js} +68 -244
  42. package/dist/client-DMWujQJ1.js.map +1 -0
  43. package/dist/{client-C27CtRZr.d.ts → client-eSfgYvd3.d.ts} +9 -7
  44. package/dist/client.d.ts +1 -1
  45. package/dist/{cloudflare-Dzvc7V2N.js → cloudflare-CUUm_9q9.js} +26 -4
  46. package/dist/cloudflare-CUUm_9q9.js.map +1 -0
  47. package/dist/{connector-DAXBOIIi.js → connector-CM-uuxKM.js} +96 -8
  48. package/dist/connector-CM-uuxKM.js.map +1 -0
  49. package/dist/{connector-20DJ6p4k.d.ts → connector-DZ71EjE-.d.ts} +109 -9
  50. package/dist/{do-oauth-client-provider-DfsUcpc3.d.ts → do-oauth-client-provider-DtNqv7oj.d.ts} +26 -2
  51. package/dist/{index-YSKgfgg9.d.ts → emitter-BJZtCVjQ.d.ts} +6 -140
  52. package/dist/emitter-DPOVcCln.js +15 -0
  53. package/dist/emitter-DPOVcCln.js.map +1 -0
  54. package/dist/experimental/channels/web/index.js +1 -1
  55. package/dist/experimental/webmcp.js +1 -1
  56. package/dist/{handler-stateless-Bly_nSH3.js → handler-stateless-B5hU3dxK.js} +35 -2
  57. package/dist/handler-stateless-B5hU3dxK.js.map +1 -0
  58. package/dist/{handler-stateless-DxYpJ_XF.d.ts → handler-stateless-C90kD5_R.d.ts} +3 -47
  59. package/dist/harness/container/index.d.ts +15 -15
  60. package/dist/harness/container/index.js +0 -1
  61. package/dist/harness/container/index.js.map +1 -1
  62. package/dist/harness/container/runtime/index.js +2 -2
  63. package/dist/harness/opencode/index.js +0 -1
  64. package/dist/harness/opencode/index.js.map +1 -1
  65. package/dist/harness/pi/index.d.ts +15 -7
  66. package/dist/harness/pi/index.js +74 -151
  67. package/dist/harness/pi/index.js.map +1 -1
  68. package/dist/harness/think/index.d.ts +2 -1
  69. package/dist/{images-xaDv2Fqe.js → images-CfuRCjwq.js} +1 -5
  70. package/dist/images-CfuRCjwq.js.map +1 -0
  71. package/dist/{index-DCxk3OSJ.d.ts → index-8k4qsX1T.d.ts} +2 -28
  72. package/dist/index.d.ts +15 -16
  73. package/dist/index.js +3 -3
  74. package/dist/internal-hosts-Kfp5A392.d.ts +230 -0
  75. package/dist/internal-kmw70xwR.js.map +1 -1
  76. package/dist/invoker-BC1SZ3q1.js +26 -0
  77. package/dist/invoker-BC1SZ3q1.js.map +1 -0
  78. package/dist/invoker-DoLFPJZV.d.ts +21 -0
  79. package/dist/markdown-BZ-VLtA1.js +86 -0
  80. package/dist/markdown-BZ-VLtA1.js.map +1 -0
  81. package/dist/mcp/client/do-oauth-client-provider.d.ts +4 -2
  82. package/dist/mcp/client/do-oauth-client-provider.js +15 -1
  83. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
  84. package/dist/mcp/client/index.d.ts +15 -1
  85. package/dist/mcp/client/index.js +2 -2
  86. package/dist/mcp/client/x402.d.ts +7 -5
  87. package/dist/mcp/client/x402.js +34 -1
  88. package/dist/mcp/client/x402.js.map +1 -1
  89. package/dist/mcp/index.d.ts +561 -27
  90. package/dist/mcp/index.js +180 -3
  91. package/dist/mcp/index.js.map +1 -1
  92. package/dist/mcp/server/index.d.ts +1 -1
  93. package/dist/mcp/server/index.js +1 -1
  94. package/dist/models/ai-sdk/index.d.ts +2 -2
  95. package/dist/models/ai-sdk/index.js +1 -1
  96. package/dist/models/opencode/index.d.ts +2 -2
  97. package/dist/models/opencode/index.js +1 -1
  98. package/dist/models/pi-ai/index.d.ts +3 -28
  99. package/dist/models/pi-ai/index.js +160 -18
  100. package/dist/models/pi-ai/index.js.map +1 -1
  101. package/dist/observability/ai/index.js +1 -2
  102. package/dist/observability/ai/index.js.map +1 -1
  103. package/dist/observability/index.d.ts +170 -9
  104. package/dist/observability/index.js +386 -11
  105. package/dist/observability/index.js.map +1 -1
  106. package/dist/protocol-BEgrJYC5.d.ts +29 -29
  107. package/dist/react.d.ts +2 -2
  108. package/dist/resource-B59OV2a2.js +325 -0
  109. package/dist/resource-B59OV2a2.js.map +1 -0
  110. package/dist/routing/index.d.ts +1 -1
  111. package/dist/script-CFDLTk5b.d.ts +91 -0
  112. package/dist/script-workspace-BpdAYq1R.d.ts +41 -0
  113. package/dist/serializable.d.ts +1 -1
  114. package/dist/{session-store-yvwq1f9x.js → session-7CDgVE0z.js} +455 -33
  115. package/dist/session-7CDgVE0z.js.map +1 -0
  116. package/dist/{session-store-_IK6dV-w.d.ts → session-store-B7Ca-u1t.d.ts} +8 -1
  117. package/dist/settings-Dk2il2Hf.js.map +1 -1
  118. package/dist/skill-DRBcIBjC.d.ts +221 -0
  119. package/dist/skills/index.d.ts +275 -36
  120. package/dist/skills/index.js +265 -1534
  121. package/dist/skills/index.js.map +1 -1
  122. package/dist/skills/runner.d.ts +37 -0
  123. package/dist/skills/runner.js +912 -0
  124. package/dist/skills/runner.js.map +1 -0
  125. package/dist/skills/tools/ai-sdk.d.ts +36 -0
  126. package/dist/skills/tools/ai-sdk.js +94 -0
  127. package/dist/skills/tools/ai-sdk.js.map +1 -0
  128. package/dist/source-9RQzlEhM.d.ts +112 -0
  129. package/dist/{src-DfLzdwlK.js → src-DoGNJ4Ud.js} +21 -6
  130. package/dist/src-DoGNJ4Ud.js.map +1 -0
  131. package/dist/sub-routing.d.ts +12 -12
  132. package/dist/tool-CTp72Jb_.d.ts +10 -10
  133. package/dist/tool-CxKsvxjm.js.map +1 -1
  134. package/dist/tool-DkT_DJBm.js.map +1 -1
  135. package/dist/tool-DoVberpN.d.ts +22 -22
  136. package/dist/tool-helpers-BI7ifO2S.js +255 -0
  137. package/dist/tool-helpers-BI7ifO2S.js.map +1 -0
  138. package/dist/{transport-CPh7YGiw.d.ts → transport-5moD2pW5.d.ts} +1 -43
  139. package/dist/types-D2naO3rA.d.ts +49 -0
  140. package/dist/vite.d.ts +2 -2
  141. package/dist/vite.js +10 -258
  142. package/dist/vite.js.map +1 -1
  143. package/dist/voice/index.d.ts +1 -1
  144. package/dist/websockets/index.js +1 -1
  145. package/dist/{websockets-CyoeosdO.js → websockets-C6SJtWCJ.js} +1 -2
  146. package/dist/{websockets-CyoeosdO.js.map → websockets-C6SJtWCJ.js.map} +1 -1
  147. package/dist/workflow-types.d.ts +1 -1
  148. package/dist/workflows.d.ts +1 -1
  149. package/dist/workflows.js +0 -1
  150. package/dist/workflows.js.map +1 -1
  151. package/docs/browse-the-web.md +247 -413
  152. package/docs/harnesses/pi.md +36 -30
  153. package/docs/index.md +4 -4
  154. package/docs/mcp-client.md +25 -1
  155. package/docs/mcp-servers.md +26 -7
  156. package/docs/models-pi-ai.md +9 -11
  157. package/docs/models.md +1 -8
  158. package/docs/observability.md +5 -3
  159. package/docs/securing-mcp-servers.md +113 -302
  160. package/package.json +31 -17
  161. package/dist/ai-sdk-DRPh2rRa.js.map +0 -1
  162. package/dist/browser-DccPw_wW.js.map +0 -1
  163. package/dist/browser-tool-B1mhifin.js +0 -616
  164. package/dist/browser-tool-B1mhifin.js.map +0 -1
  165. package/dist/browser-tool-Cxjk5sgG.d.ts +0 -92
  166. package/dist/client-BnYbNT3z.js.map +0 -1
  167. package/dist/cloudflare-Dzvc7V2N.js.map +0 -1
  168. package/dist/connector-DAXBOIIi.js.map +0 -1
  169. package/dist/handler-stateless-Bly_nSH3.js.map +0 -1
  170. package/dist/images-xaDv2Fqe.js.map +0 -1
  171. package/dist/index-iv9FTXX9.d.ts +0 -311
  172. package/dist/invoker-CG0_p_Wq.d.ts +0 -20
  173. package/dist/invoker-CHMnoxIA.js +0 -57
  174. package/dist/invoker-CHMnoxIA.js.map +0 -1
  175. package/dist/session-store-yvwq1f9x.js.map +0 -1
  176. package/dist/skills/compile.d.ts +0 -40
  177. package/dist/skills/compile.js +0 -65
  178. package/dist/skills/compile.js.map +0 -1
  179. package/dist/src-DfLzdwlK.js.map +0 -1
  180. package/dist/tool-helpers-O5BDVEAY.js +0 -58
  181. package/dist/tool-helpers-O5BDVEAY.js.map +0 -1
  182. package/skills-module.d.ts +0 -22
@@ -5,7 +5,7 @@ import {
5
5
  o as getMcpAuthContext,
6
6
  r as StatelessMcpServerInput,
7
7
  t as CreateStatelessMcpHandlerOptions
8
- } from "../../handler-stateless-DxYpJ_XF.js";
8
+ } from "../../handler-stateless-C90kD5_R.js";
9
9
  export {
10
10
  type CreateStatelessMcpHandlerOptions as CreateMcpHandlerOptions,
11
11
  type CreateStatelessMcpHandlerOptions,
@@ -1,2 +1,2 @@
1
- import { n as getMcpAuthContext, t as createStatelessMcpHandler } from "../../handler-stateless-Bly_nSH3.js";
1
+ import { n as getMcpAuthContext, t as createStatelessMcpHandler } from "../../handler-stateless-B5hU3dxK.js";
2
2
  export { createStatelessMcpHandler as createMcpHandler, getMcpAuthContext };
@@ -14,7 +14,7 @@ import {
14
14
  u as ProviderGatewaySettings,
15
15
  v as KnownImageModelId,
16
16
  y as KnownSpeechModelId
17
- } from "../../transport-CPh7YGiw.js";
17
+ } from "../../transport-5moD2pW5.js";
18
18
  import {
19
19
  a as CloudflareAIError,
20
20
  c as GatewayModelOptions,
@@ -28,7 +28,7 @@ import {
28
28
  s as FallbackLeg,
29
29
  t as AI,
30
30
  u as ModelOptions
31
- } from "../../index-DCxk3OSJ.js";
31
+ } from "../../index-8k4qsX1T.js";
32
32
  export {
33
33
  AI,
34
34
  type AISettings,
@@ -1,2 +1,2 @@
1
- import { n as GatewayLanguageModel, r as CloudflareAIError, t as createAI } from "../../ai-sdk-DRPh2rRa.js";
1
+ import { n as GatewayLanguageModel, r as CloudflareAIError, t as createAI } from "../../ai-sdk-Kon40i0q.js";
2
2
  export { CloudflareAIError, GatewayLanguageModel, createAI };
@@ -4,11 +4,11 @@ import {
4
4
  c as GatewayOptions,
5
5
  d as CatalogModelId,
6
6
  s as AISettings
7
- } from "../../transport-CPh7YGiw.js";
7
+ } from "../../transport-5moD2pW5.js";
8
8
  import {
9
9
  o as CloudflareLanguageModelId,
10
10
  u as ModelOptions
11
- } from "../../index-DCxk3OSJ.js";
11
+ } from "../../index-8k4qsX1T.js";
12
12
  import { Plugin } from "@opencode/plugin";
13
13
 
14
14
  //#region src/models/opencode/index.d.ts
@@ -1,4 +1,4 @@
1
- import { t as createAI$1 } from "../../ai-sdk-DRPh2rRa.js";
1
+ import { t as createAI$1 } from "../../ai-sdk-Kon40i0q.js";
2
2
  import { Model, Provider } from "@opencode/plugin";
3
3
  //#region src/models/opencode/language-v3.ts
4
4
  /**
@@ -10,7 +10,7 @@ import {
10
10
  o as CloudflareAIErrorCode,
11
11
  r as GatewayProviderName,
12
12
  s as AISettings
13
- } from "../../transport-CPh7YGiw.js";
13
+ } from "../../transport-5moD2pW5.js";
14
14
  import {
15
15
  Api,
16
16
  AssistantImages,
@@ -43,18 +43,13 @@ interface CompatWarning {
43
43
  //#region src/models/pi-ai/models/image.d.ts
44
44
  /**
45
45
  * The `api` marker on image models from this provider.
46
- *
47
- * @beta This surface is in beta and may change.
48
46
  */
49
47
  declare const CLOUDFLARE_AI_IMAGES_API = "cloudflare-ai-images";
50
- /** @beta This surface is in beta and may change. */
51
48
  type CloudflareImagesModel = ImageModel<typeof CLOUDFLARE_AI_IMAGES_API>;
52
49
  /**
53
50
  * Per-model options for image models: gateway options plus the generation
54
51
  * knobs Workers AI understands. Anything given here is the default for every
55
52
  * call; `generateImages` options override it.
56
- *
57
- * @beta This surface is in beta and may change.
58
53
  */
59
54
  interface PiImagesModelOptions extends ModelOptions {
60
55
  name?: string;
@@ -80,8 +75,6 @@ interface PiImagesCallOptions extends ImagesOptions {
80
75
  * pi-ai's `AssistantImages` has no warnings channel, so a knob this catalog
81
76
  * drops is reported the way the language wires report theirs: as a diagnostic
82
77
  * of type {@link COMPAT_DIAGNOSTIC}.
83
- *
84
- * @beta This surface is in beta and may change.
85
78
  */
86
79
  interface CloudflareAssistantImages extends AssistantImages {
87
80
  diagnostics?: {
@@ -98,33 +91,23 @@ interface CloudflareAssistantImages extends AssistantImages {
98
91
  * The `api` marker Workers AI models from this provider carry. It is not a
99
92
  * wire format: Workers AI runs on `env.AI.run`, and the compat layer maps that
100
93
  * onto strict OpenAI chat completions.
101
- *
102
- * @beta This surface is in beta and may change.
103
94
  */
104
95
  declare const CLOUDFLARE_AI_API = "cloudflare-ai";
105
- /** @beta This surface is in beta and may change. */
106
96
  type CloudflareAIApi = typeof CLOUDFLARE_AI_API;
107
97
  /**
108
98
  * The pi-ai provider id. A `Models` registry resolves specifiers as
109
99
  * `cloudflare/<id>`, e.g. `cloudflare/anthropic/claude-opus-4.8`.
110
- *
111
- * @beta This surface is in beta and may change.
112
100
  */
113
101
  declare const CLOUDFLARE_PROVIDER_ID = "cloudflare";
114
102
  /**
115
103
  * A Workers AI model produced by this provider. `id` is the `@cf/` id exactly
116
104
  * as given; `api` is {@link CLOUDFLARE_AI_API}.
117
- *
118
- * @beta This surface is in beta and may change.
119
105
  */
120
106
  type CloudflareModel = Model<CloudflareAIApi>;
121
- /** @beta This surface is in beta and may change. */
122
107
  type ModelCost = Model<Api>["cost"];
123
108
  /**
124
109
  * A model this provider routes: a Workers AI model or any pi-ai model the
125
110
  * caller handed to `ai(model)`.
126
- *
127
- * @beta This surface is in beta and may change.
128
111
  */
129
112
  type RoutedModel = Model<Api>;
130
113
  /**
@@ -132,8 +115,6 @@ type RoutedModel = Model<Api>;
132
115
  * session affinity, plus pi-ai model metadata overrides and the stream idle
133
116
  * deadline. Metadata overrides only apply to the `@cf/` form — a model object
134
117
  * brings its own metadata, and this module never second-guesses it.
135
- *
136
- * @beta This surface is in beta and may change.
137
118
  */
138
119
  /**
139
120
  * A fallback leg: a Workers AI id, a `<slug>/<id>` pi-ai's gateway registry
@@ -181,8 +162,6 @@ declare const CLOUDFLARE_DIAGNOSTIC = "cloudflare";
181
162
  //#region src/models/pi-ai/index.d.ts
182
163
  /**
183
164
  * pi-agent-core's `streamFn` shape: what `Agent` calls to run a turn.
184
- *
185
- * @beta This surface is in beta and may change.
186
165
  */
187
166
  type StreamFn = (
188
167
  model: Model<string>,
@@ -194,8 +173,6 @@ type StreamFn = (
194
173
  * pi-ai model to get a model this instance routes; use `stream`/`complete` to
195
174
  * run it, `streamFn` with pi-agent-core's `Agent`, and `provider` with a pi-ai
196
175
  * `Models` registry.
197
- *
198
- * @beta This surface is in beta and may change.
199
176
  */
200
177
  interface AI {
201
178
  /** A Workers AI model: Cloudflare's own catalog, on the run path. */
@@ -275,12 +252,10 @@ interface AI {
275
252
  *
276
253
  * ```ts
277
254
  * const ai = createAI({ binding: env.AI, id: "prod" });
278
- * ai("@cf/zai-org/glm-4.7-flash");
279
- * ai(anthropicModel, { fallback: ["@cf/zai-org/glm-4.7-flash"] });
255
+ * ai("@cf/zai-org/glm-5.3-flash");
256
+ * ai(anthropicModel, { fallback: ["@cf/zai-org/glm-5.3-flash"] });
280
257
  * new Agent({ streamFn: ai.streamFn, initialState: { model: ai(openaiModel) } });
281
258
  * ```
282
- *
283
- * @beta This surface is in beta and may change.
284
259
  */
285
260
  declare function createAI(settings: AISettings): AI;
286
261
  //#endregion
@@ -1,4 +1,6 @@
1
- import { C as isCatalogModelId, T as isRunPathLanguageModelId, _ as isGatewayErrorEnvelope, a as normalizeChatCompletion, c as gatewaySlugForBaseUrl, d as resolveGatewayProvider, f as createTransport, g as headersToObject, h as errorFromResponse, i as normalizeChatCompletionsStream, l as isGatewayShapedUrl, m as errorFromGatewayEnvelope, n as imageMediaTypeOf, o as prepareChatCompletionsRequest, r as sseDataStream, s as GATEWAY_PROVIDER_NAMES, t as buildImageInput, v as unwrapEnvelope, x as isAbortError, y as CloudflareAIError } from "../../images-xaDv2Fqe.js";
1
+ import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../../classPrivateFieldGet2-DZBYAB34.js";
2
+ import { t as _classPrivateMethodInitSpec } from "../../classPrivateMethodInitSpec-qMjJ6sHQ.js";
3
+ import { C as isCatalogModelId, T as isRunPathLanguageModelId, _ as isGatewayErrorEnvelope, a as normalizeChatCompletion, c as gatewaySlugForBaseUrl, d as resolveGatewayProvider, f as createTransport, g as headersToObject, h as errorFromResponse, i as normalizeChatCompletionsStream, l as isGatewayShapedUrl, m as errorFromGatewayEnvelope, n as imageMediaTypeOf, o as prepareChatCompletionsRequest, r as sseDataStream, s as GATEWAY_PROVIDER_NAMES, t as buildImageInput, v as unwrapEnvelope, x as isAbortError, y as CloudflareAIError } from "../../images-CfuRCjwq.js";
2
4
  import { i as mergeModelOptions, o as resolveOptions, r as gatewayLayerOf } from "../../settings-Dk2il2Hf.js";
3
5
  import { calculateCost, clampThinkingLevel, createAssistantMessageEventStream, createProvider, getCurrentTools, normalizeContext, parseStreamingJson } from "@earendil-works/pi-ai";
4
6
  import { CLOUDFLARE_AI_GATEWAY_MODELS } from "@earendil-works/pi-ai/providers/cloudflare-ai-gateway.models";
@@ -13,15 +15,11 @@ import { clampOpenAIPromptCacheKey } from "@earendil-works/pi-ai/api/openai-prom
13
15
  * The `api` marker Workers AI models from this provider carry. It is not a
14
16
  * wire format: Workers AI runs on `env.AI.run`, and the compat layer maps that
15
17
  * onto strict OpenAI chat completions.
16
- *
17
- * @beta This surface is in beta and may change.
18
18
  */
19
19
  const CLOUDFLARE_AI_API = "cloudflare-ai";
20
20
  /**
21
21
  * The pi-ai provider id. A `Models` registry resolves specifiers as
22
22
  * `cloudflare/<id>`, e.g. `cloudflare/anthropic/claude-opus-4.8`.
23
- *
24
- * @beta This surface is in beta and may change.
25
23
  */
26
24
  const CLOUDFLARE_PROVIDER_ID = "cloudflare";
27
25
  const MODEL_OPTIONS = Symbol.for("agents.models.pi-ai.options");
@@ -487,6 +485,32 @@ function anthropicVendorHeaders(betas) {
487
485
  "content-type": "application/json"
488
486
  };
489
487
  }
488
+ /**
489
+ * The vendor headers `/run` also carries. The rest (`anthropic-version`,
490
+ * `accept`, `content-type`) belong to the gateway there, but `anthropic-beta`
491
+ * holds the beta features the body was built for: without it Anthropic refuses
492
+ * a body that uses one, or quietly drops the feature. The binding sends
493
+ * `extraHeaders` as request headers, and AI Gateway passes this one on.
494
+ */
495
+ const RUN_VENDOR_HEADERS = ["anthropic-beta"];
496
+ /**
497
+ * The headers a `/run` request sends: the vendor headers in
498
+ * {@link RUN_VENDOR_HEADERS}, then the caller's own, which win. Names compare
499
+ * case-insensitively, so a caller's `Anthropic-Beta` replaces the wire's
500
+ * rather than being sent alongside it.
501
+ */
502
+ function runHeaders(vendorHeaders, callerHeaders) {
503
+ const callerNames = new Set(Object.keys(callerHeaders).map((name) => name.toLowerCase()));
504
+ const headers = {};
505
+ for (const name of RUN_VENDOR_HEADERS) {
506
+ const value = vendorHeaders[name];
507
+ if (value !== void 0 && !callerNames.has(name)) headers[name] = value;
508
+ }
509
+ return {
510
+ ...headers,
511
+ ...callerHeaders
512
+ };
513
+ }
490
514
  /** The vendor headers an OpenAI-shaped request needs. */
491
515
  function openAIVendorHeaders() {
492
516
  return {
@@ -526,7 +550,7 @@ async function sendGateway(request, transport, body, vendorHeaders, format, onRe
526
550
  const response = await transport.run({
527
551
  format,
528
552
  gateway: resolved.gateway,
529
- headers: request.headers,
553
+ headers: runHeaders(vendorHeaders, request.headers),
530
554
  input,
531
555
  model: catalogId,
532
556
  signal: options.signal
@@ -644,6 +668,124 @@ async function assertOk(response, context) {
644
668
  throw await errorFromResponse(response, context);
645
669
  }
646
670
  //#endregion
671
+ //#region src/models/pi-ai/wires/partial-arguments.ts
672
+ const VALID_ESCAPES = /* @__PURE__ */ new Set([
673
+ "\"",
674
+ "\\",
675
+ "/",
676
+ "b",
677
+ "f",
678
+ "n",
679
+ "r",
680
+ "t",
681
+ "u"
682
+ ]);
683
+ const HEX = /^[0-9a-fA-F]$/;
684
+ var _text = /* @__PURE__ */ new WeakMap();
685
+ var _snapshot = /* @__PURE__ */ new WeakMap();
686
+ var _needsRepair = /* @__PURE__ */ new WeakMap();
687
+ var _containers = /* @__PURE__ */ new WeakMap();
688
+ var _inString = /* @__PURE__ */ new WeakMap();
689
+ var _escape = /* @__PURE__ */ new WeakMap();
690
+ var _PartialArguments_brand = /* @__PURE__ */ new WeakSet();
691
+ /**
692
+ * A streamed tool call's arguments, parsed as their text arrives.
693
+ *
694
+ * pi-ai's `parseStreamingJson` re-parses the whole text on every delta: a
695
+ * `JSON.parse` that throws, a character-by-character repair, a second throwing
696
+ * `JSON.parse`, then a partial parse. Over a long argument, such as a file
697
+ * passed to a write tool, that is quadratic in time and garbage.
698
+ *
699
+ * This keeps the lexer state (open containers, whether the text ends inside a
700
+ * string or an escape) across deltas, so each delta scans only its own
701
+ * characters. A snapshot closes the open string and containers and hands the
702
+ * result to the native `JSON.parse`, which still reads the whole text but
703
+ * throws nothing and builds no intermediate strings in JavaScript. When the text ends mid-token (a key, a
704
+ * number, `tru`) the closed text does not parse, and the previous snapshot
705
+ * stands until the next delta. Unlike `parseStreamingJson`, a partial string
706
+ * keeps its trailing whitespace. Text that needs pi-ai's repairs (raw control
707
+ * characters or invalid escapes inside a string) goes back to
708
+ * `parseStreamingJson` for the rest of the call.
709
+ */
710
+ var PartialArguments = class {
711
+ constructor() {
712
+ _classPrivateMethodInitSpec(this, _PartialArguments_brand);
713
+ _classPrivateFieldInitSpec(this, _text, "");
714
+ _classPrivateFieldInitSpec(this, _snapshot, {});
715
+ _classPrivateFieldInitSpec(this, _needsRepair, false);
716
+ _classPrivateFieldInitSpec(this, _containers, []);
717
+ _classPrivateFieldInitSpec(this, _inString, false);
718
+ _classPrivateFieldInitSpec(this, _escape, void 0);
719
+ }
720
+ get text() {
721
+ return _classPrivateFieldGet2(_text, this);
722
+ }
723
+ /** Append `delta` and return the arguments parsed so far. */
724
+ push(delta) {
725
+ _classPrivateFieldSet2(_text, this, _classPrivateFieldGet2(_text, this) + delta);
726
+ if (!_classPrivateFieldGet2(_needsRepair, this)) _assertClassBrand(_PartialArguments_brand, this, _scan).call(this, delta);
727
+ if (_classPrivateFieldGet2(_needsRepair, this)) {
728
+ _classPrivateFieldSet2(_snapshot, this, parseStreamingJson(_classPrivateFieldGet2(_text, this)));
729
+ return _classPrivateFieldGet2(_snapshot, this);
730
+ }
731
+ const parsed = _assertClassBrand(_PartialArguments_brand, this, _parseClosed).call(this);
732
+ if (parsed !== void 0) _classPrivateFieldSet2(_snapshot, this, parsed);
733
+ return _classPrivateFieldGet2(_snapshot, this);
734
+ }
735
+ };
736
+ function _scan(delta) {
737
+ for (const char of delta) {
738
+ if (_classPrivateFieldGet2(_escape, this) !== void 0) {
739
+ _classPrivateFieldSet2(_escape, this, _classPrivateFieldGet2(_escape, this) + char);
740
+ if (_classPrivateFieldGet2(_escape, this).length === 1) {
741
+ if (!VALID_ESCAPES.has(char)) {
742
+ _classPrivateFieldSet2(_needsRepair, this, true);
743
+ return;
744
+ }
745
+ if (char !== "u") _classPrivateFieldSet2(_escape, this, void 0);
746
+ } else {
747
+ if (!HEX.test(char)) {
748
+ _classPrivateFieldSet2(_needsRepair, this, true);
749
+ return;
750
+ }
751
+ if (_classPrivateFieldGet2(_escape, this).length === 5) _classPrivateFieldSet2(_escape, this, void 0);
752
+ }
753
+ continue;
754
+ }
755
+ if (_classPrivateFieldGet2(_inString, this)) {
756
+ if (char === "\"") _classPrivateFieldSet2(_inString, this, false);
757
+ else if (char === "\\") _classPrivateFieldSet2(_escape, this, "");
758
+ else if (char < " ") {
759
+ _classPrivateFieldSet2(_needsRepair, this, true);
760
+ return;
761
+ }
762
+ continue;
763
+ }
764
+ if (char === "\"") _classPrivateFieldSet2(_inString, this, true);
765
+ else if (char === "{") _classPrivateFieldGet2(_containers, this).push("}");
766
+ else if (char === "[") _classPrivateFieldGet2(_containers, this).push("]");
767
+ else if (char === "}" || char === "]") _classPrivateFieldGet2(_containers, this).pop();
768
+ }
769
+ }
770
+ function _parseClosed() {
771
+ let text = _classPrivateFieldGet2(_text, this);
772
+ if (_classPrivateFieldGet2(_inString, this)) {
773
+ if (_classPrivateFieldGet2(_escape, this) !== void 0) text = text.slice(0, text.length - _classPrivateFieldGet2(_escape, this).length - 1);
774
+ text += "\"";
775
+ } else {
776
+ text = text.trimEnd();
777
+ if (text.endsWith(",")) text = text.slice(0, -1);
778
+ }
779
+ for (let i = _classPrivateFieldGet2(_containers, this).length - 1; i >= 0; i--) text += _classPrivateFieldGet2(_containers, this)[i];
780
+ if (text.trim() === "") return {};
781
+ try {
782
+ const value = JSON.parse(text);
783
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
784
+ } catch {
785
+ return;
786
+ }
787
+ }
788
+ //#endregion
647
789
  //#region src/models/pi-ai/wires/chat-completions.ts
648
790
  /**
649
791
  * Chat-completions wire: Workers AI on the run path, and any pi-ai model whose
@@ -734,6 +876,7 @@ var CompletionAssembler = class {
734
876
  this.stream = stream;
735
877
  this.openToolCalls = /* @__PURE__ */ new Map();
736
878
  this.closedToolCalls = /* @__PURE__ */ new Set();
879
+ this.toolArguments = /* @__PURE__ */ new Map();
737
880
  this.blocks = output.content;
738
881
  }
739
882
  indexOf(block) {
@@ -815,6 +958,7 @@ var CompletionAssembler = class {
815
958
  this.closedToolCalls.add(index);
816
959
  block.arguments = parseStreamingJson(block.partialArguments ?? "");
817
960
  delete block.partialArguments;
961
+ this.toolArguments.delete(index);
818
962
  this.stream.push({
819
963
  contentIndex: this.indexOf(block),
820
964
  partial: this.output,
@@ -857,8 +1001,13 @@ var CompletionAssembler = class {
857
1001
  }
858
1002
  this.lastToolIndex = index;
859
1003
  if (args.length > 0) {
860
- block.partialArguments = (block.partialArguments ?? "") + args;
861
- block.arguments = parseStreamingJson(block.partialArguments);
1004
+ let parser = this.toolArguments.get(index);
1005
+ if (parser === void 0) {
1006
+ parser = new PartialArguments();
1007
+ this.toolArguments.set(index, parser);
1008
+ }
1009
+ block.arguments = parser.push(args);
1010
+ block.partialArguments = parser.text;
862
1011
  this.stream.push({
863
1012
  contentIndex: this.indexOf(block),
864
1013
  delta: args,
@@ -1078,8 +1227,6 @@ function streamCompletions(request, transport) {
1078
1227
  //#region src/models/pi-ai/models/image.ts
1079
1228
  /**
1080
1229
  * The `api` marker on image models from this provider.
1081
- *
1082
- * @beta This surface is in beta and may change.
1083
1230
  */
1084
1231
  const CLOUDFLARE_AI_IMAGES_API = "cloudflare-ai-images";
1085
1232
  const IMAGE_OPTIONS = Symbol.for("agents.models.pi-ai.image-options");
@@ -1745,7 +1892,7 @@ function createStreams(config) {
1745
1892
  *
1746
1893
  * const ai = createAI({ binding: env.AI, id: "prod" });
1747
1894
  *
1748
- * ai("@cf/zai-org/glm-4.7-flash"); // Workers AI: ours
1895
+ * ai("@cf/zai-org/glm-5.3-flash"); // Workers AI: ours
1749
1896
  * ai(getBuiltinModel("anthropic", "claude-opus-4-8")); // theirs, our transport
1750
1897
  * ai("anthropic/claude-opus-4-8"); // same, via pi's catalog
1751
1898
  * ```
@@ -1758,9 +1905,6 @@ function createStreams(config) {
1758
1905
  * metadata (`api`, `compat`, `thinkingLevelMap`, cost, limits) is whatever its
1759
1906
  * own registry says, and pi-ai's converters and stream processors do the rest.
1760
1907
  *
1761
- * @beta Everything exported here is in beta: the surface may
1762
- * change in a minor release while the design settles.
1763
- *
1764
1908
  * @module
1765
1909
  */
1766
1910
  /** The prefixes a bare vendor id is most often written with, for the error. */
@@ -1802,12 +1946,10 @@ function buildModel(target, options) {
1802
1946
  *
1803
1947
  * ```ts
1804
1948
  * const ai = createAI({ binding: env.AI, id: "prod" });
1805
- * ai("@cf/zai-org/glm-4.7-flash");
1806
- * ai(anthropicModel, { fallback: ["@cf/zai-org/glm-4.7-flash"] });
1949
+ * ai("@cf/zai-org/glm-5.3-flash");
1950
+ * ai(anthropicModel, { fallback: ["@cf/zai-org/glm-5.3-flash"] });
1807
1951
  * new Agent({ streamFn: ai.streamFn, initialState: { model: ai(openaiModel) } });
1808
1952
  * ```
1809
- *
1810
- * @beta This surface is in beta and may change.
1811
1953
  */
1812
1954
  function createAI(settings) {
1813
1955
  const transport = createTransport(settings);