agents 0.30.0 → 0.31.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 (130) hide show
  1. package/README.md +4 -2
  2. package/dist/{agent-routing-CDbpVjYq.d.ts → agent-routing-wS1TimZ_.d.ts} +64 -603
  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-Bamxxb6Y.d.ts} +2 -2
  6. package/dist/agent-tools.d.ts +1 -1
  7. package/dist/{ai-iXw0uOGj.d.ts → ai-CDn3Abax.d.ts} +30 -4
  8. package/dist/{ai-sdk-DRPh2rRa.js → ai-sdk-Kon40i0q.js} +2 -36
  9. package/dist/ai-sdk-Kon40i0q.js.map +1 -0
  10. package/dist/ai-sdk-hW3vntnk.d.ts +72 -0
  11. package/dist/browser/ai.d.ts +1 -1
  12. package/dist/browser/ai.js +16 -3
  13. package/dist/browser/ai.js.map +1 -1
  14. package/dist/browser/index.d.ts +64 -16
  15. package/dist/browser/index.js +4 -4
  16. package/dist/browser/tools/ai-sdk.d.ts +7 -70
  17. package/dist/browser/tools/ai-sdk.js +4 -4
  18. package/dist/browser/tools/ai-sdk.js.map +1 -1
  19. package/dist/browser/tools/pi.d.ts +9 -15
  20. package/dist/browser/tools/pi.js +6 -14
  21. package/dist/browser/tools/pi.js.map +1 -1
  22. package/dist/browser/tools/tanstack-ai.d.ts +46 -23
  23. package/dist/browser/tools/tanstack-ai.js +8 -4
  24. package/dist/browser/tools/tanstack-ai.js.map +1 -1
  25. package/dist/{browser-DccPw_wW.js → browser-1eUbPvC2.js} +413 -14
  26. package/dist/browser-1eUbPvC2.js.map +1 -0
  27. package/dist/{browser-DlXhSAdf.d.ts → browser-D9RNpJuT.d.ts} +254 -20
  28. package/dist/browser-tool-BhjCcNVE.d.ts +71 -0
  29. package/dist/browser-tool-lGnvEBLJ.js +497 -0
  30. package/dist/browser-tool-lGnvEBLJ.js.map +1 -0
  31. package/dist/capability-id-B3J8Nok_.js +13 -0
  32. package/dist/capability-id-B3J8Nok_.js.map +1 -0
  33. package/dist/chat/index.d.ts +2 -2
  34. package/dist/chat-sdk/index.d.ts +3 -3
  35. package/dist/chat-sdk/index.js +1 -1
  36. package/dist/client-4OlMIJx-.js.map +1 -1
  37. package/dist/{client-BnYbNT3z.js → client-DMWujQJ1.js} +68 -244
  38. package/dist/client-DMWujQJ1.js.map +1 -0
  39. package/dist/{client-C27CtRZr.d.ts → client-wn4-yqGz.d.ts} +9 -7
  40. package/dist/client.d.ts +1 -1
  41. package/dist/{connector-DAXBOIIi.js → connector-CM-uuxKM.js} +96 -8
  42. package/dist/connector-CM-uuxKM.js.map +1 -0
  43. package/dist/{connector-20DJ6p4k.d.ts → connector-DZ71EjE-.d.ts} +109 -9
  44. package/dist/experimental/webmcp.js +1 -1
  45. package/dist/{handler-stateless-Bly_nSH3.js → handler-stateless-B5hU3dxK.js} +35 -2
  46. package/dist/handler-stateless-B5hU3dxK.js.map +1 -0
  47. package/dist/{handler-stateless-DxYpJ_XF.d.ts → handler-stateless-C90kD5_R.d.ts} +3 -47
  48. package/dist/harness/container/index.d.ts +15 -15
  49. package/dist/harness/opencode/index.js.map +1 -1
  50. package/dist/harness/pi/index.d.ts +7 -3
  51. package/dist/harness/pi/index.js +46 -15
  52. package/dist/harness/pi/index.js.map +1 -1
  53. package/dist/harness/think/index.d.ts +2 -1
  54. package/dist/{images-xaDv2Fqe.js → images-CfuRCjwq.js} +1 -5
  55. package/dist/images-CfuRCjwq.js.map +1 -0
  56. package/dist/{index-DCxk3OSJ.d.ts → index-8k4qsX1T.d.ts} +2 -28
  57. package/dist/index.d.ts +14 -14
  58. package/dist/index.js +2 -2
  59. package/dist/internal-hosts-Kfp5A392.d.ts +230 -0
  60. package/dist/internal-kmw70xwR.js.map +1 -1
  61. package/dist/invoker-BC1SZ3q1.js +26 -0
  62. package/dist/invoker-BC1SZ3q1.js.map +1 -0
  63. package/dist/invoker-DoLFPJZV.d.ts +21 -0
  64. package/dist/mcp/client/index.d.ts +15 -1
  65. package/dist/mcp/client/index.js +2 -2
  66. package/dist/mcp/client/x402.d.ts +7 -5
  67. package/dist/mcp/client/x402.js +34 -1
  68. package/dist/mcp/client/x402.js.map +1 -1
  69. package/dist/mcp/index.d.ts +561 -27
  70. package/dist/mcp/index.js +180 -3
  71. package/dist/mcp/index.js.map +1 -1
  72. package/dist/mcp/server/index.d.ts +1 -1
  73. package/dist/mcp/server/index.js +1 -1
  74. package/dist/models/ai-sdk/index.d.ts +2 -2
  75. package/dist/models/ai-sdk/index.js +1 -1
  76. package/dist/models/opencode/index.d.ts +2 -2
  77. package/dist/models/opencode/index.js +1 -1
  78. package/dist/models/pi-ai/index.d.ts +3 -28
  79. package/dist/models/pi-ai/index.js +31 -16
  80. package/dist/models/pi-ai/index.js.map +1 -1
  81. package/dist/protocol-BEgrJYC5.d.ts +29 -29
  82. package/dist/react.d.ts +2 -2
  83. package/dist/routing/index.d.ts +1 -1
  84. package/dist/serializable.d.ts +1 -1
  85. package/dist/{session-store-yvwq1f9x.js → session-7CDgVE0z.js} +455 -33
  86. package/dist/session-7CDgVE0z.js.map +1 -0
  87. package/dist/{session-store-_IK6dV-w.d.ts → session-store-B7Ca-u1t.d.ts} +8 -1
  88. package/dist/settings-Dk2il2Hf.js.map +1 -1
  89. package/dist/{src-DfLzdwlK.js → src-BGolXG_H.js} +18 -2
  90. package/dist/src-BGolXG_H.js.map +1 -0
  91. package/dist/sub-routing.d.ts +12 -12
  92. package/dist/tool-CTp72Jb_.d.ts +10 -10
  93. package/dist/tool-DoVberpN.d.ts +22 -22
  94. package/dist/tool-helpers-BodWi4gd.js +256 -0
  95. package/dist/tool-helpers-BodWi4gd.js.map +1 -0
  96. package/dist/{transport-CPh7YGiw.d.ts → transport-5moD2pW5.d.ts} +1 -43
  97. package/dist/types-D2naO3rA.d.ts +49 -0
  98. package/dist/voice/index.d.ts +1 -1
  99. package/dist/workflow-types.d.ts +1 -1
  100. package/dist/workflows.d.ts +1 -1
  101. package/dist/workflows.js +1 -1
  102. package/docs/browse-the-web.md +247 -413
  103. package/docs/get-current-agent.md +4 -7
  104. package/docs/harnesses/pi.md +28 -28
  105. package/docs/human-in-the-loop.md +3 -7
  106. package/docs/index.md +6 -6
  107. package/docs/mcp-client.md +4 -28
  108. package/docs/mcp-servers.md +137 -411
  109. package/docs/mcp-transports.md +30 -289
  110. package/docs/models-pi-ai.md +9 -11
  111. package/docs/models.md +1 -8
  112. package/docs/routing.md +0 -2
  113. package/docs/securing-mcp-servers.md +120 -304
  114. package/package.json +8 -3
  115. package/dist/ai-sdk-DRPh2rRa.js.map +0 -1
  116. package/dist/browser-DccPw_wW.js.map +0 -1
  117. package/dist/browser-tool-B1mhifin.js +0 -616
  118. package/dist/browser-tool-B1mhifin.js.map +0 -1
  119. package/dist/browser-tool-Cxjk5sgG.d.ts +0 -92
  120. package/dist/client-BnYbNT3z.js.map +0 -1
  121. package/dist/connector-DAXBOIIi.js.map +0 -1
  122. package/dist/handler-stateless-Bly_nSH3.js.map +0 -1
  123. package/dist/images-xaDv2Fqe.js.map +0 -1
  124. package/dist/invoker-CG0_p_Wq.d.ts +0 -20
  125. package/dist/invoker-CHMnoxIA.js +0 -57
  126. package/dist/invoker-CHMnoxIA.js.map +0 -1
  127. package/dist/session-store-yvwq1f9x.js.map +0 -1
  128. package/dist/src-DfLzdwlK.js.map +0 -1
  129. package/dist/tool-helpers-O5BDVEAY.js +0 -58
  130. package/dist/tool-helpers-O5BDVEAY.js.map +0 -1
@@ -1,16 +1,16 @@
1
1
  import {
2
- An as getSubAgentByName,
3
- Cn as BuildAgentPathOptions,
4
- Dn as buildAgentUrl,
5
- En as buildAgentPath,
6
- Mn as routeSubAgentRequest,
7
- On as buildSubAgentPath,
8
- Sn as AgentPathStep,
9
- Tn as SubAgentPathMatch,
10
- jn as parseSubAgentPath,
11
- kn as buildSubAgentPathUnchecked,
12
- wn as SUB_PREFIX
13
- } from "./agent-routing-CDbpVjYq.js";
2
+ an as SUB_PREFIX,
3
+ cn as buildAgentUrl,
4
+ dn as getSubAgentByName,
5
+ fn as parseSubAgentPath,
6
+ in as BuildAgentPathOptions,
7
+ ln as buildSubAgentPath,
8
+ on as SubAgentPathMatch,
9
+ pn as routeSubAgentRequest,
10
+ rn as AgentPathStep,
11
+ sn as buildAgentPath,
12
+ un as buildSubAgentPathUnchecked
13
+ } from "./agent-routing-wS1TimZ_.js";
14
14
  export {
15
15
  AgentPathStep,
16
16
  BuildAgentPathOptions,
@@ -168,16 +168,16 @@ declare function createHTTPWebSearch(
168
168
  * HTTP status, so every error has a code to branch on.
169
169
  */
170
170
  type WebSearchErrorCode =
171
- /** No AI Gateway credits and no provider key for the search. */ | "web_search_payment_required" /** `byokAlias` names a key the gateway does not have. */
172
- | "web_search_byok_not_configured" /** The query, limit, or provider was rejected. */
173
- | "invalid_web_search_input" /** The gateway does not exist or is not set up. */
174
- | "web_search_gateway_not_configured" /** The API token or binding is not allowed to search. */
175
- | "web_search_unauthorized" /** Too many searches; retry later. */
176
- | "web_search_rate_limited" /** The search took longer than the tool's `timeoutMs`. */
177
- | "web_search_timeout" /** The API or the provider failed. */
178
- | "web_search_unavailable" /** The Workers runtime has no `env.AI.websearch()`. */
179
- | "web_search_unsupported_runtime" /** A code the API added after this release. */
180
- | (string & {});
171
+ | /** No AI Gateway credits and no provider key for the search. */ "web_search_payment_required" /** `byokAlias` names a key the gateway does not have. */
172
+ | "web_search_byok_not_configured" /** The query, limit, or provider was rejected. */
173
+ | "invalid_web_search_input" /** The gateway does not exist or is not set up. */
174
+ | "web_search_gateway_not_configured" /** The API token or binding is not allowed to search. */
175
+ | "web_search_unauthorized" /** Too many searches; retry later. */
176
+ | "web_search_rate_limited" /** The search took longer than the tool's `timeoutMs`. */
177
+ | "web_search_timeout" /** The API or the provider failed. */
178
+ | "web_search_unavailable" /** The Workers runtime has no `env.AI.websearch()`. */
179
+ | "web_search_unsupported_runtime" /** A code the API added after this release. */
180
+ | (string & {});
181
181
  /** Why a search failed, with what the API said. */
182
182
  declare class WebSearchError extends Error {
183
183
  readonly name = "WebSearchError";
@@ -36,17 +36,17 @@ type WebFetchToolInput = {
36
36
  };
37
37
  /** How the content of a {@link WebFetchPage} was produced. */
38
38
  type WebFetchVia =
39
- /** The server answered `text/markdown` (Markdown for Agents). */ | "markdown-negotiated" /** Converted to Markdown by Workers AI (`env.AI.toMarkdown`). */
40
- | "converted" /** JSON, pretty-printed. */
41
- | "json" /** Text passed through as served. */
42
- | "text" /** `format: "raw"`: the body as served. */
43
- | "raw"
44
- /**
45
- * Rendered in a browser first (Browser Run). Reserved: nothing produces
46
- * it yet. It is in the union now so adding a browser source later doesn't
47
- * break hosts' exhaustive switches.
48
- */
49
- | "rendered";
39
+ | /** The server answered `text/markdown` (Markdown for Agents). */ "markdown-negotiated" /** Converted to Markdown by Workers AI (`env.AI.toMarkdown`). */
40
+ | "converted" /** JSON, pretty-printed. */
41
+ | "json" /** Text passed through as served. */
42
+ | "text" /** `format: "raw"`: the body as served. */
43
+ | "raw"
44
+ /**
45
+ * Rendered in a browser first (Browser Run). Reserved: nothing produces
46
+ * it yet. It is in the union now so adding a browser source later doesn't
47
+ * break hosts' exhaustive switches.
48
+ */
49
+ | "rendered";
50
50
  /**
51
51
  * One fetched page, whole: what a `WebFetchSource` and `fetchWeb()`
52
52
  * return. The model never sees this directly; the tool stores one window of
@@ -184,17 +184,17 @@ declare function createDirectWebFetch(
184
184
  * to branch on.
185
185
  */
186
186
  type WebFetchErrorCode =
187
- /** The URL or format was malformed or too long. */ | "invalid_web_fetch_input" /** The URL's scheme, credentials, or host isn't allowed here. */
188
- | "web_fetch_disallowed_url" /** A redirect pointed at a URL that isn't allowed here, or from https to http. */
189
- | "web_fetch_disallowed_redirect" /** More redirects than allowed, or a redirect loop. */
190
- | "web_fetch_too_many_redirects" /** The fetch took longer than the tool's `timeoutMs` (on the error as `timeoutMs`). */
191
- | "web_fetch_timeout" /** The body is larger than `maxBytes`. */
192
- | "web_fetch_too_large" /** The body is binary, or a document requested with `format: "raw"`. */
193
- | "web_fetch_unsupported_content_type" /** A 4xx/5xx response with an empty or non-textual body. */
194
- | "web_fetch_http_error" /** The site answered with a bot challenge instead of the page. */
195
- | "web_fetch_blocked" /** Workers AI could not convert the body to Markdown. */
196
- | "web_fetch_conversion_failed" /** The network failed: before a response (DNS, TLS, connection) or while reading the body. */
197
- | "web_fetch_unavailable";
187
+ | /** The URL or format was malformed or too long. */ "invalid_web_fetch_input" /** The URL's scheme, credentials, or host isn't allowed here. */
188
+ | "web_fetch_disallowed_url" /** A redirect pointed at a URL that isn't allowed here, or from https to http. */
189
+ | "web_fetch_disallowed_redirect" /** More redirects than allowed, or a redirect loop. */
190
+ | "web_fetch_too_many_redirects" /** The fetch took longer than the tool's `timeoutMs` (on the error as `timeoutMs`). */
191
+ | "web_fetch_timeout" /** The body is larger than `maxBytes`. */
192
+ | "web_fetch_too_large" /** The body is binary, or a document requested with `format: "raw"`. */
193
+ | "web_fetch_unsupported_content_type" /** A 4xx/5xx response with an empty or non-textual body. */
194
+ | "web_fetch_http_error" /** The site answered with a bot challenge instead of the page. */
195
+ | "web_fetch_blocked" /** Workers AI could not convert the body to Markdown. */
196
+ | "web_fetch_conversion_failed" /** The network failed: before a response (DNS, TLS, connection) or while reading the body. */
197
+ | "web_fetch_unavailable";
198
198
  /** Why a fetch failed. */
199
199
  declare class WebFetchError extends Error {
200
200
  readonly name = "WebFetchError";
@@ -0,0 +1,256 @@
1
+ import { t as __DO_NOT_USE_WILL_BREAK__agentContext } from "./current-agent-DhoDkSnH.js";
2
+ import "./internal_context.js";
3
+ import "./session-7CDgVE0z.js";
4
+ import { t as redactBase64Payloads } from "./base64-redaction-C1Uu29t5.js";
5
+ //#region src/browser/truncate.ts
6
+ /**
7
+ * Result truncation for the browser tools, copied from
8
+ * `@cloudflare/codemode`'s `truncateResult` so `agents/browser` doesn't need
9
+ * codemode. Internal — not an entry point.
10
+ *
11
+ * Structured values are truncated structurally: the output is always valid
12
+ * JSON of the same shape, with the largest values cut first. A truncated
13
+ * string ends with a marker, a truncated array ends with a marker element
14
+ * counting the dropped items, and an object that had to lose entries carries a
15
+ * marker entry naming the omitted keys. Every marker contains
16
+ * `--- TRUNCATED ---` so callers and models can find them.
17
+ */
18
+ /** ~4 characters per token is a reasonable cross-model estimate. */
19
+ const CHARS_PER_TOKEN = 4;
20
+ const DEFAULT_MAX_TOKENS = 6e3;
21
+ const TRUNCATION_MARKER = "--- TRUNCATED ---";
22
+ /**
23
+ * The least a string or container is worth keeping at (see `floorSize`). A
24
+ * value that would get fewer serialized characters than this is dropped in
25
+ * favour of its siblings rather than reduced to a bare marker.
26
+ */
27
+ const MIN_SLOT = 128;
28
+ function budget(options) {
29
+ const maxTokens = options?.maxTokens ?? DEFAULT_MAX_TOKENS;
30
+ return {
31
+ maxChars: options?.maxChars ?? maxTokens * CHARS_PER_TOKEN,
32
+ maxTokens
33
+ };
34
+ }
35
+ /**
36
+ * Truncate a text response to a character budget, appending a marker that notes
37
+ * the original size so the model knows the output was clipped. Returns the
38
+ * input unchanged when it is within budget.
39
+ */
40
+ function truncateResponse(text, options) {
41
+ const { maxChars, maxTokens } = budget(options);
42
+ if (text.length <= maxChars) return text;
43
+ const estimatedTokens = Math.ceil(text.length / CHARS_PER_TOKEN);
44
+ return text.slice(0, maxChars) + `\n\n${TRUNCATION_MARKER}\nResponse was ~${estimatedTokens.toLocaleString()} tokens (limit: ${maxTokens.toLocaleString()}). Narrow the request to reduce response size.`;
45
+ }
46
+ /**
47
+ * Truncate a structured result. Strings are truncated directly. Other values
48
+ * pass through unchanged (same reference) when their JSON serialization is
49
+ * within budget. When oversized, the value is shrunk structurally — largest
50
+ * values first, deepest last — so the model gets a bounded value that is still
51
+ * valid JSON of the original shape, with markers where content was cut.
52
+ *
53
+ * Values that can't be serialized (cycles, bigint, `undefined`) are returned
54
+ * unchanged.
55
+ */
56
+ function truncateResult(value, options) {
57
+ if (typeof value === "string") return truncateResponse(value, options);
58
+ let serialized;
59
+ try {
60
+ serialized = JSON.stringify(value);
61
+ } catch {
62
+ return value;
63
+ }
64
+ if (serialized === void 0) return value;
65
+ const { maxChars } = budget(options);
66
+ if (serialized.length <= maxChars) return value;
67
+ const shrunk = shrink(JSON.parse(serialized), maxChars);
68
+ return size(shrunk) <= maxChars ? shrunk : truncateResponse(serialized, options);
69
+ }
70
+ /** Serialized size in characters (compact JSON). */
71
+ function size(value) {
72
+ return JSON.stringify(value).length;
73
+ }
74
+ /** Only strings and containers can give up characters; scalars are atomic. */
75
+ function shrinkable(value) {
76
+ return typeof value === "string" || typeof value === "object" && !!value;
77
+ }
78
+ /**
79
+ * The least budget a value is kept at; a scalar must fit whole. The floor
80
+ * never exceeds half the container's own budget, so tiny budgets still keep
81
+ * something rather than nothing.
82
+ */
83
+ function floorSize(value, maxChars) {
84
+ const full = size(value);
85
+ return shrinkable(value) ? Math.min(full, MIN_SLOT, Math.max(2, Math.floor(maxChars / 2))) : full;
86
+ }
87
+ function shrink(value, maxChars) {
88
+ if (size(value) <= maxChars) return value;
89
+ if (typeof value === "string") return shrinkString(value, maxChars);
90
+ if (Array.isArray(value)) return shrinkArray(value, maxChars);
91
+ if (typeof value === "object" && value !== null) return shrinkObject(value, maxChars);
92
+ return value;
93
+ }
94
+ function shrinkString(value, maxChars) {
95
+ const suffix = ` ${TRUNCATION_MARKER} ${value.length.toLocaleString()} chars`;
96
+ let keep = Math.max(0, maxChars - suffix.length - 2);
97
+ let out = value.slice(0, keep) + suffix;
98
+ while (keep > 0 && size(out) > maxChars) {
99
+ keep = Math.max(0, keep - (size(out) - maxChars));
100
+ out = value.slice(0, keep) + suffix;
101
+ }
102
+ return size(out) <= maxChars ? out : TRUNCATION_MARKER.slice(0, Math.max(0, maxChars - 2));
103
+ }
104
+ /**
105
+ * Share `available` characters across values by water-filling: values are
106
+ * admitted smallest first, each taking the lesser of its full size and an
107
+ * equal share of what is left. Requires `available >= Σ floorSize(values)`;
108
+ * then every value receives at least its floor.
109
+ */
110
+ function allocate(values, available) {
111
+ const sizes = values.map(size);
112
+ const order = sizes.map((_, i) => i).sort((a, b) => sizes[a] - sizes[b]);
113
+ const allocation = new Array(values.length);
114
+ let remaining = available;
115
+ let count = values.length;
116
+ for (const i of order) {
117
+ const alloc = Math.min(sizes[i], Math.floor(remaining / count));
118
+ allocation[i] = alloc;
119
+ remaining -= alloc;
120
+ count--;
121
+ }
122
+ return allocation;
123
+ }
124
+ function shrinkArray(items, maxChars) {
125
+ const marker = (dropped) => `${TRUNCATION_MARKER} ${dropped.toLocaleString()} more items`;
126
+ const floors = items.map((item) => floorSize(item, maxChars));
127
+ const skeleton = (count) => 2 + Math.max(0, count - 1);
128
+ let keep = items.length;
129
+ if (floors.reduce((n, f) => n + f, 0) + skeleton(keep) > maxChars) {
130
+ const tail = size(marker(items.length)) + 1;
131
+ let used = skeleton(0) + tail;
132
+ keep = 0;
133
+ while (keep < items.length && used + floors[keep] + 1 <= maxChars) {
134
+ used += floors[keep] + 1;
135
+ keep++;
136
+ }
137
+ }
138
+ const kept = items.slice(0, keep);
139
+ const dropped = items.length - keep;
140
+ const tail = dropped > 0 ? size(marker(dropped)) + (keep > 0 ? 1 : 0) : 0;
141
+ const allocation = allocate(kept, maxChars - skeleton(keep) - tail);
142
+ const out = kept.map((item, i) => shrink(item, allocation[i]));
143
+ if (dropped > 0 && size([...out, marker(dropped)]) <= maxChars) out.push(marker(dropped));
144
+ return out;
145
+ }
146
+ function shrinkObject(value, maxChars) {
147
+ const entries = Object.entries(value);
148
+ let markerKey = TRUNCATION_MARKER;
149
+ while (markerKey in value) markerKey += " ";
150
+ const keyCost = (key) => size(key) + 1;
151
+ const floors = entries.map(([k, v]) => keyCost(k) + floorSize(v, maxChars));
152
+ const floorOf = (chars) => Math.min(chars, MIN_SLOT, Math.max(2, Math.floor(maxChars / 2)));
153
+ const byValueSize = entries.map((_, i) => i).sort((a, b) => size(entries[b][1]) - size(entries[a][1]));
154
+ const dropped = /* @__PURE__ */ new Set();
155
+ let present = entries.length;
156
+ let floorsSum = floors.reduce((n, f) => n + f, 0);
157
+ let namesLength = 0;
158
+ const noteLength = () => `${dropped.size.toLocaleString()} keys omitted: `.length + namesLength + 2 * (dropped.size - 1);
159
+ const cost = () => {
160
+ const marker = dropped.size > 0 ? keyCost(markerKey) + floorOf(noteLength() + 2) : 0;
161
+ const count = present + (dropped.size > 0 ? 1 : 0);
162
+ return 2 + Math.max(0, count - 1) + floorsSum + marker;
163
+ };
164
+ for (const i of byValueSize) {
165
+ if (cost() <= maxChars) break;
166
+ dropped.add(i);
167
+ present--;
168
+ floorsSum -= floors[i];
169
+ namesLength += size(entries[i][0]) - 2;
170
+ }
171
+ const kept = entries.filter((_, i) => !dropped.has(i));
172
+ const omitted = [...dropped].sort((a, b) => a - b).map((i) => entries[i][0]);
173
+ const note = `${omitted.length.toLocaleString()} keys omitted: ${omitted.join(", ")}`;
174
+ if (cost() > maxChars) {
175
+ const room = maxChars - 2 - keyCost(markerKey);
176
+ return room >= 2 ? { [markerKey]: shrink(note, room) } : {};
177
+ }
178
+ const all = [...kept];
179
+ if (omitted.length > 0) all.push([markerKey, note]);
180
+ const fixed = 2 + Math.max(0, all.length - 1) + all.reduce((n, [k]) => n + keyCost(k), 0);
181
+ const allocation = allocate(all.map(([, v]) => v), maxChars - fixed);
182
+ const out = {};
183
+ all.forEach(([k, v], i) => {
184
+ out[k] = shrink(v, allocation[i]);
185
+ });
186
+ return out;
187
+ }
188
+ //#endregion
189
+ //#region src/browser/tool-helpers.ts
190
+ /** What `Page.captureScreenshot` can produce. */
191
+ const SCREENSHOT_MEDIA_TYPES = /* @__PURE__ */ new Set([
192
+ "image/png",
193
+ "image/jpeg",
194
+ "image/webp"
195
+ ]);
196
+ const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
197
+ /**
198
+ * The screenshot the model's code returned, or `null` if it didn't return
199
+ * one. The model writes this shape itself, so only an image type, base64
200
+ * data, and the session's size limit count: anything else is treated as a
201
+ * plain result and cut down like one, rather than kept whole or sent to the
202
+ * model as an image.
203
+ */
204
+ function browserScreenshotOutput(value) {
205
+ const outer = typeof value === "object" && value !== null ? value : null;
206
+ const result = outer && typeof outer.result === "object" && outer.result !== null ? outer.result : outer;
207
+ if (result?.type !== "browser_screenshot" || typeof result.mediaType !== "string" || typeof result.data !== "string" || !SCREENSHOT_MEDIA_TYPES.has(result.mediaType) || result.data.length > 1e6 || !BASE64.test(result.data)) return null;
208
+ return result;
209
+ }
210
+ function transformBrowserResult(value) {
211
+ return browserScreenshotOutput(value) ? value : truncateResult(redactBase64Payloads(value));
212
+ }
213
+ /**
214
+ * @param notes Sentences appended when a screenshot collapses the output to
215
+ * text, so notices on the output aren't lost with it.
216
+ */
217
+ function browserExecuteModelOutput(output, notes = []) {
218
+ const screenshot = browserScreenshotOutput(output);
219
+ if (screenshot) {
220
+ const approximateBytes = Math.floor(screenshot.data.length * 3 / 4);
221
+ return {
222
+ type: "text",
223
+ value: [`Screenshot captured successfully (${screenshot.mediaType}, approximately ${approximateBytes.toLocaleString()} bytes); the image is kept for the UI and omitted here.`, ...notes].join(" ")
224
+ };
225
+ }
226
+ const redacted = redactBase64Payloads(typeof output === "object" && output !== null && !Array.isArray(output) ? (({ calls: _calls, ...rest }) => ({
227
+ ...rest,
228
+ ...Array.isArray(rest.logs) ? { logs: truncateResult(rest.logs) } : {}
229
+ }))(output) : output);
230
+ try {
231
+ const serialized = JSON.stringify(redacted);
232
+ return {
233
+ type: "json",
234
+ value: serialized === void 0 ? null : JSON.parse(serialized)
235
+ };
236
+ } catch {
237
+ return {
238
+ type: "text",
239
+ value: "Browser execution completed, but its result could not be serialized for model context."
240
+ };
241
+ }
242
+ }
243
+ /**
244
+ * The Durable Object state to build the runtime in: the explicit `ctx` if
245
+ * given, otherwise the current Agent's `ctx` (via `getCurrentAgent()`), so
246
+ * `createBrowserRuntime` can be called from an Agent method without threading
247
+ * `this.ctx` through.
248
+ */
249
+ function resolveCtx(options) {
250
+ if (options.ctx) return options.ctx;
251
+ return (__DO_NOT_USE_WILL_BREAK__agentContext.getStore()?.agent)?.ctx;
252
+ }
253
+ //#endregion
254
+ export { truncateResult as a, transformBrowserResult as i, browserScreenshotOutput as n, resolveCtx as r, browserExecuteModelOutput as t };
255
+
256
+ //# sourceMappingURL=tool-helpers-BodWi4gd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-helpers-BodWi4gd.js","names":["agentContext"],"sources":["../src/browser/truncate.ts","../src/browser/tool-helpers.ts"],"sourcesContent":["/**\n * Result truncation for the browser tools, copied from\n * `@cloudflare/codemode`'s `truncateResult` so `agents/browser` doesn't need\n * codemode. Internal — not an entry point.\n *\n * Structured values are truncated structurally: the output is always valid\n * JSON of the same shape, with the largest values cut first. A truncated\n * string ends with a marker, a truncated array ends with a marker element\n * counting the dropped items, and an object that had to lose entries carries a\n * marker entry naming the omitted keys. Every marker contains\n * `--- TRUNCATED ---` so callers and models can find them.\n */\n\n/** ~4 characters per token is a reasonable cross-model estimate. */\nconst CHARS_PER_TOKEN = 4;\nconst DEFAULT_MAX_TOKENS = 6000;\nconst TRUNCATION_MARKER = \"--- TRUNCATED ---\";\n/**\n * The least a string or container is worth keeping at (see `floorSize`). A\n * value that would get fewer serialized characters than this is dropped in\n * favour of its siblings rather than reduced to a bare marker.\n */\nconst MIN_SLOT = 128;\n\ntype TruncateOptions = {\n /**\n * Maximum characters in the (serialized) output before truncation kicks in.\n * Defaults to `maxTokens * 4`.\n */\n maxChars?: number;\n /** Token budget used to derive the default `maxChars`. Defaults to 6000. */\n maxTokens?: number;\n};\n\nfunction budget(options?: TruncateOptions): {\n maxChars: number;\n maxTokens: number;\n} {\n const maxTokens = options?.maxTokens ?? DEFAULT_MAX_TOKENS;\n const maxChars = options?.maxChars ?? maxTokens * CHARS_PER_TOKEN;\n return { maxChars, maxTokens };\n}\n\n/**\n * Truncate a text response to a character budget, appending a marker that notes\n * the original size so the model knows the output was clipped. Returns the\n * input unchanged when it is within budget.\n */\nfunction truncateResponse(text: string, options?: TruncateOptions): string {\n const { maxChars, maxTokens } = budget(options);\n if (text.length <= maxChars) return text;\n\n const estimatedTokens = Math.ceil(text.length / CHARS_PER_TOKEN);\n return (\n text.slice(0, maxChars) +\n `\\n\\n${TRUNCATION_MARKER}\\nResponse was ~${estimatedTokens.toLocaleString()} tokens ` +\n `(limit: ${maxTokens.toLocaleString()}). Narrow the request to reduce response size.`\n );\n}\n\n/**\n * Truncate a structured result. Strings are truncated directly. Other values\n * pass through unchanged (same reference) when their JSON serialization is\n * within budget. When oversized, the value is shrunk structurally — largest\n * values first, deepest last — so the model gets a bounded value that is still\n * valid JSON of the original shape, with markers where content was cut.\n *\n * Values that can't be serialized (cycles, bigint, `undefined`) are returned\n * unchanged.\n */\nexport function truncateResult(\n value: unknown,\n options?: TruncateOptions\n): unknown {\n if (typeof value === \"string\") return truncateResponse(value, options);\n\n let serialized: string | undefined;\n try {\n serialized = JSON.stringify(value);\n } catch {\n return value;\n }\n if (serialized === undefined) return value;\n\n const { maxChars } = budget(options);\n if (serialized.length <= maxChars) return value;\n\n // Re-parse so `toJSON`, class instances and `undefined` members are seen in\n // their serialized form — the shape the model would receive anyway.\n const shrunk = shrink(JSON.parse(serialized) as Json, maxChars);\n // `shrink` honours its budget for anything a container can hold; only a\n // scalar (a number too long for the budget) can still miss it.\n return size(shrunk) <= maxChars\n ? shrunk\n : truncateResponse(serialized, options);\n}\n\n// ---------------------------------------------------------------------------\n// Structural shrinking\n// ---------------------------------------------------------------------------\n//\n// Every `shrink*` below returns a value whose compact serialization fits the\n// budget it was given, provided the budget can hold an empty container (2\n// chars). Containers share their budget by water-filling: each child is owed\n// at least its floor (`floorSize`), small children keep their full size, and\n// the largest children absorb the cut. A container only drops children when\n// even their floors cannot fit — arrays drop from the tail (order carries\n// meaning), objects drop their largest values first (keys are all meaningful).\n\ntype Json = string | number | boolean | null | Json[] | { [key: string]: Json };\n\n/** Serialized size in characters (compact JSON). */\nfunction size(value: Json): number {\n return JSON.stringify(value).length;\n}\n\n/** Only strings and containers can give up characters; scalars are atomic. */\nfunction shrinkable(value: Json): boolean {\n return typeof value === \"string\" || (typeof value === \"object\" && !!value);\n}\n\n/**\n * The least budget a value is kept at; a scalar must fit whole. The floor\n * never exceeds half the container's own budget, so tiny budgets still keep\n * something rather than nothing.\n */\nfunction floorSize(value: Json, maxChars: number): number {\n const full = size(value);\n return shrinkable(value)\n ? Math.min(full, MIN_SLOT, Math.max(2, Math.floor(maxChars / 2)))\n : full;\n}\n\nfunction shrink(value: Json, maxChars: number): Json {\n if (size(value) <= maxChars) return value;\n if (typeof value === \"string\") return shrinkString(value, maxChars);\n if (Array.isArray(value)) return shrinkArray(value, maxChars);\n if (typeof value === \"object\" && value !== null) {\n return shrinkObject(value, maxChars);\n }\n return value;\n}\n\nfunction shrinkString(value: string, maxChars: number): string {\n const suffix = ` ${TRUNCATION_MARKER} ${value.length.toLocaleString()} chars`;\n let keep = Math.max(0, maxChars - suffix.length - 2);\n let out = value.slice(0, keep) + suffix;\n // Escapes inflate the serialized form; back off until it fits.\n while (keep > 0 && size(out) > maxChars) {\n keep = Math.max(0, keep - (size(out) - maxChars));\n out = value.slice(0, keep) + suffix;\n }\n // No room for a prefix and the size note: keep as much of the marker as fits.\n return size(out) <= maxChars\n ? out\n : TRUNCATION_MARKER.slice(0, Math.max(0, maxChars - 2));\n}\n\n/**\n * Share `available` characters across values by water-filling: values are\n * admitted smallest first, each taking the lesser of its full size and an\n * equal share of what is left. Requires `available >= Σ floorSize(values)`;\n * then every value receives at least its floor.\n */\nfunction allocate(values: Json[], available: number): number[] {\n const sizes = values.map(size);\n const order = sizes.map((_, i) => i).sort((a, b) => sizes[a] - sizes[b]);\n const allocation = new Array<number>(values.length);\n let remaining = available;\n let count = values.length;\n for (const i of order) {\n const alloc = Math.min(sizes[i], Math.floor(remaining / count));\n allocation[i] = alloc;\n remaining -= alloc;\n count--;\n }\n return allocation;\n}\n\nfunction shrinkArray(items: Json[], maxChars: number): Json[] {\n const marker = (dropped: number) =>\n `${TRUNCATION_MARKER} ${dropped.toLocaleString()} more items`;\n const floors = items.map((item) => floorSize(item, maxChars));\n const skeleton = (count: number) => 2 + Math.max(0, count - 1);\n\n // Keep everything when every floor fits.\n let keep = items.length;\n if (floors.reduce((n, f) => n + f, 0) + skeleton(keep) > maxChars) {\n // Otherwise keep the longest prefix whose floors fit beside a tail marker\n // (sized for the largest possible count, so the real one always fits).\n const tail = size(marker(items.length)) + 1;\n let used = skeleton(0) + tail;\n keep = 0;\n while (keep < items.length && used + floors[keep] + 1 <= maxChars) {\n used += floors[keep] + 1;\n keep++;\n }\n }\n\n const kept = items.slice(0, keep);\n const dropped = items.length - keep;\n const tail = dropped > 0 ? size(marker(dropped)) + (keep > 0 ? 1 : 0) : 0;\n const allocation = allocate(kept, maxChars - skeleton(keep) - tail);\n const out = kept.map((item, i) => shrink(item, allocation[i]));\n if (dropped > 0 && size([...out, marker(dropped)]) <= maxChars) {\n out.push(marker(dropped));\n }\n return out;\n}\n\nfunction shrinkObject(\n value: { [key: string]: Json },\n maxChars: number\n): { [key: string]: Json } {\n const entries = Object.entries(value);\n // The marker entry must not shadow a real key.\n let markerKey = TRUNCATION_MARKER;\n while (markerKey in value) markerKey += \" \";\n const keyCost = (key: string) => size(key) + 1;\n const floors = entries.map(([k, v]) => keyCost(k) + floorSize(v, maxChars));\n const floorOf = (chars: number) =>\n Math.min(chars, MIN_SLOT, Math.max(2, Math.floor(maxChars / 2)));\n\n // Drop the largest values first, only until the remaining floors fit. Costs\n // are tracked incrementally so a wide object stays linear in its key count;\n // the marker note's cost is derived arithmetically from the omitted names.\n const byValueSize = entries\n .map((_, i) => i)\n .sort((a, b) => size(entries[b][1]) - size(entries[a][1]));\n const dropped = new Set<number>();\n let present = entries.length;\n let floorsSum = floors.reduce((n, f) => n + f, 0);\n let namesLength = 0;\n const noteLength = () =>\n `${dropped.size.toLocaleString()} keys omitted: `.length +\n namesLength +\n 2 * (dropped.size - 1);\n const cost = () => {\n const marker =\n dropped.size > 0 ? keyCost(markerKey) + floorOf(noteLength() + 2) : 0;\n const count = present + (dropped.size > 0 ? 1 : 0);\n return 2 + Math.max(0, count - 1) + floorsSum + marker;\n };\n for (const i of byValueSize) {\n if (cost() <= maxChars) break;\n dropped.add(i);\n present--;\n floorsSum -= floors[i];\n namesLength += size(entries[i][0]) - 2;\n }\n\n const kept = entries.filter((_, i) => !dropped.has(i));\n const omitted = [...dropped].sort((a, b) => a - b).map((i) => entries[i][0]);\n const note = `${omitted.length.toLocaleString()} keys omitted: ${omitted.join(\", \")}`;\n if (cost() > maxChars) {\n // Not even the marker fits at its floor: keep as much of it as there is\n // room for, or nothing.\n const room = maxChars - 2 - keyCost(markerKey);\n return room >= 2 ? { [markerKey]: shrink(note, room) } : {};\n }\n const all: [string, Json][] = [...kept];\n if (omitted.length > 0) all.push([markerKey, note]);\n const fixed =\n 2 + Math.max(0, all.length - 1) + all.reduce((n, [k]) => n + keyCost(k), 0);\n // The note is shrunk like any other value, so it can never overshoot.\n const allocation = allocate(\n all.map(([, v]) => v),\n maxChars - fixed\n );\n const out: { [key: string]: Json } = {};\n all.forEach(([k, v], i) => {\n out[k] = shrink(v, allocation[i]);\n });\n return out;\n}\n","/**\n * Helpers shared by the browser tools: `createBrowserTools` in `ai.ts`, and\n * the `browserTool` adapters in `tools/`. Internal — not an entry point.\n */\nimport type { JSONValue } from \"ai\";\nimport { DEFAULT_MAX_RESULT_BYTES } from \"./session\";\nimport { truncateResult } from \"./truncate\";\nimport { redactBase64Payloads } from \"../core/base64-redaction\";\nimport { __DO_NOT_USE_WILL_BREAK__agentContext as agentContext } from \"../internal_context\";\n\ninterface BrowserScreenshotOutput {\n type: \"browser_screenshot\";\n mediaType: string;\n data: string;\n}\n\n/** What `Page.captureScreenshot` can produce. */\nconst SCREENSHOT_MEDIA_TYPES = new Set([\n \"image/png\",\n \"image/jpeg\",\n \"image/webp\"\n]);\nconst BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;\n\n/**\n * The screenshot the model's code returned, or `null` if it didn't return\n * one. The model writes this shape itself, so only an image type, base64\n * data, and the session's size limit count: anything else is treated as a\n * plain result and cut down like one, rather than kept whole or sent to the\n * model as an image.\n */\nexport function browserScreenshotOutput(\n value: unknown\n): BrowserScreenshotOutput | null {\n const outer =\n typeof value === \"object\" && value !== null\n ? (value as Record<string, unknown>)\n : null;\n const result =\n outer && typeof outer.result === \"object\" && outer.result !== null\n ? (outer.result as Record<string, unknown>)\n : outer;\n if (\n result?.type !== \"browser_screenshot\" ||\n typeof result.mediaType !== \"string\" ||\n typeof result.data !== \"string\" ||\n !SCREENSHOT_MEDIA_TYPES.has(result.mediaType) ||\n result.data.length > DEFAULT_MAX_RESULT_BYTES ||\n !BASE64.test(result.data)\n ) {\n return null;\n }\n return result as unknown as BrowserScreenshotOutput;\n}\n\nexport function transformBrowserResult(value: unknown): unknown {\n // Keep canonical screenshot output intact for UIMessage persistence and the\n // chat renderer. Other results are redacted before truncation so a nested\n // binary payload cannot become a large serialized preview.\n return browserScreenshotOutput(value)\n ? value\n : truncateResult(redactBase64Payloads(value));\n}\n\n/** What the model sees in place of a browser tool's output. */\nexport type BrowserModelOutput =\n | { type: \"text\"; value: string }\n | { type: \"json\"; value: JSONValue };\n\n/**\n * @param notes Sentences appended when a screenshot collapses the output to\n * text, so notices on the output aren't lost with it.\n */\nexport function browserExecuteModelOutput(\n output: unknown,\n notes: string[] = []\n): BrowserModelOutput {\n const screenshot = browserScreenshotOutput(output);\n if (screenshot) {\n const approximateBytes = Math.floor((screenshot.data.length * 3) / 4);\n return {\n type: \"text\",\n value: [\n `Screenshot captured successfully (${screenshot.mediaType}, approximately ${approximateBytes.toLocaleString()} bytes); the image is kept for the UI and omitted here.`,\n ...notes\n ].join(\" \")\n };\n }\n\n // `calls`, the durable audit log `createBrowserTools` adds, stays on the\n // persisted part and never enters the model's context, and the sandbox\n // `logs` are bounded like a result.\n const modelFacing =\n typeof output === \"object\" && output !== null && !Array.isArray(output)\n ? (({ calls: _calls, ...rest }: { calls?: unknown; logs?: unknown }) => ({\n ...rest,\n ...(Array.isArray(rest.logs)\n ? { logs: truncateResult(rest.logs) }\n : {})\n }))(output)\n : output;\n const redacted = redactBase64Payloads(modelFacing);\n try {\n const serialized = JSON.stringify(redacted);\n return {\n type: \"json\",\n value:\n serialized === undefined ? null : (JSON.parse(serialized) as JSONValue)\n };\n } catch {\n return {\n type: \"text\",\n value:\n \"Browser execution completed, but its result could not be serialized for model context.\"\n };\n }\n}\n\n/**\n * The Durable Object state to build the runtime in: the explicit `ctx` if\n * given, otherwise the current Agent's `ctx` (via `getCurrentAgent()`), so\n * `createBrowserRuntime` can be called from an Agent method without threading\n * `this.ctx` through.\n */\nexport function resolveCtx(options: {\n ctx?: DurableObjectState;\n}): DurableObjectState | undefined {\n if (options.ctx) return options.ctx;\n const agent = agentContext.getStore()?.agent as\n | { ctx?: DurableObjectState }\n | undefined;\n return agent?.ctx;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;;;;;;AAM1B,MAAM,WAAW;AAYjB,SAAS,OAAO,SAGd;CACA,MAAM,YAAY,SAAS,aAAa;CAExC,OAAO;EAAE,UADQ,SAAS,YAAY,YAAY;EAC/B;CAAU;AAC/B;;;;;;AAOA,SAAS,iBAAiB,MAAc,SAAmC;CACzE,MAAM,EAAE,UAAU,cAAc,OAAO,OAAO;CAC9C,IAAI,KAAK,UAAU,UAAU,OAAO;CAEpC,MAAM,kBAAkB,KAAK,KAAK,KAAK,SAAS,eAAe;CAC/D,OACE,KAAK,MAAM,GAAG,QAAQ,IACtB,OAAO,kBAAkB,kBAAkB,gBAAgB,eAAe,EAAE,kBACjE,UAAU,eAAe,EAAE;AAE1C;;;;;;;;;;;AAYA,SAAgB,eACd,OACA,SACS;CACT,IAAI,OAAO,UAAU,UAAU,OA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,IAAI,QAAQ,KAAK,OAAO,QAAQ;CAIhC,QAHcA,sCAAa,SAAS,CAAC,EAAE,MAAA,EAGzB;AAChB"}
@@ -96,8 +96,6 @@ type RerankingCatalogId = {
96
96
  *
97
97
  * Third-party models are not ids here — they are model objects built by their
98
98
  * own provider package and routed through AI Gateway.
99
- *
100
- * @experimental This surface is experimental and may change.
101
99
  */
102
100
  type WorkersAIModelId =
103
101
  | Extract<
@@ -116,8 +114,6 @@ type WorkersAIModelId =
116
114
  * which order, with what rate limits or budgets — and called through the
117
115
  * Workers AI run path like a model. It answers in the OpenAI chat-completions
118
116
  * shape whatever model served it, so it is a language model only.
119
- *
120
- * @experimental This surface is experimental and may change.
121
117
  */
122
118
  type DynamicRouteId = `dynamic/${string}`;
123
119
  /**
@@ -130,8 +126,6 @@ type DynamicRouteId = `dynamic/${string}`;
130
126
  * `env.AI.run`, where AI Gateway's `/run` engine picks the provider, converts
131
127
  * the request, and bills through Unified Billing or a key stored on the
132
128
  * gateway.
133
- *
134
- * @experimental This surface is experimental and may change.
135
129
  */
136
130
  type CatalogModelId = `${string}/${string}`;
137
131
  /**
@@ -139,8 +133,6 @@ type CatalogModelId = `${string}/${string}`;
139
133
  *
140
134
  * The modality methods are Workers AI only — there is no vendor route for them
141
135
  * — so, like {@link WorkersAIModelId}, they take `@cf/` ids and nothing else.
142
- *
143
- * @experimental This surface is experimental and may change.
144
136
  */
145
137
  type CloudflareEmbeddingModelId =
146
138
  | Extract<
@@ -161,8 +153,6 @@ type CloudflareEmbeddingModelId =
161
153
  * `prompt`, which the JSON run path cannot carry — live, the run path answers
162
154
  * `400 Bad input: required properties at "/" are 'multipart'`. Suggesting an
163
155
  * id that always 400s is worse than not suggesting it.
164
- *
165
- * @experimental This surface is experimental and may change.
166
156
  */
167
157
  type KnownImageModelId =
168
158
  | "@cf/black-forest-labs/flux-1-schnell"
@@ -170,8 +160,6 @@ type KnownImageModelId =
170
160
  | "@cf/leonardo/phoenix-1.0";
171
161
  /**
172
162
  * An image model id accepted by `ai.image()`.
173
- *
174
- * @experimental This surface is experimental and may change.
175
163
  */
176
164
  type CloudflareImageModelId =
177
165
  | Extract<
@@ -182,8 +170,6 @@ type CloudflareImageModelId =
182
170
  /**
183
171
  * Workers AI text-to-speech ids without a {@link BaseAiTextToSpeech} entry.
184
172
  * Curated for autocomplete only.
185
- *
186
- * @experimental This surface is experimental and may change.
187
173
  */
188
174
  type KnownSpeechModelId =
189
175
  | "@cf/deepgram/aura-1"
@@ -191,8 +177,6 @@ type KnownSpeechModelId =
191
177
  | "@cf/deepgram/aura-2-es";
192
178
  /**
193
179
  * A text-to-speech model id accepted by `ai.speech()`.
194
- *
195
- * @experimental This surface is experimental and may change.
196
180
  */
197
181
  type CloudflareSpeechModelId =
198
182
  | Extract<
@@ -211,8 +195,6 @@ type UnsupportedTranscriptionId = "@cf/deepgram/flux";
211
195
  * Deepgram's Flux (`@cf/deepgram/flux`) is deliberately not suggested: it
212
196
  * takes websocket connections only, so this provider answers a clear error
213
197
  * for it rather than a 400.
214
- *
215
- * @experimental This surface is experimental and may change.
216
198
  */
217
199
  type CloudflareTranscriptionModelId =
218
200
  | Extract<
@@ -226,8 +208,6 @@ type CloudflareTranscriptionModelId =
226
208
  | (`@cf/${string}` & {});
227
209
  /**
228
210
  * A reranking model id accepted by `ai.reranking()`.
229
- *
230
- * @experimental This surface is experimental and may change.
231
211
  */
232
212
  type CloudflareRerankingModelId =
233
213
  | Extract<RerankingCatalogId, `@cf/${string}`>
@@ -238,8 +218,6 @@ type CloudflareRerankingModelId =
238
218
  * AI Gateway settings for a request. The gateway is an option, not a separate
239
219
  * product: every call goes through one, and `id` defaults to `"default"`,
240
220
  * which Cloudflare creates on first use.
241
- *
242
- * @experimental This surface is experimental and may change.
243
221
  */
244
222
  interface GatewayOptions {
245
223
  /** Gateway id. Defaults to `"default"` (auto-created on first use). */
@@ -283,15 +261,11 @@ interface GatewayOptions {
283
261
  * API token. Both take the same routes — a model id to the run path, a
284
262
  * vendor's model object to the provider-native path — and the same gateway
285
263
  * options.
286
- *
287
- * @experimental This surface is experimental and may change.
288
264
  */
289
265
  type AISettings = (BindingAccess | AccountAccess) & ProviderGatewaySettings;
290
266
  /**
291
267
  * Reach Cloudflare through the `AI` binding: no account id or token to hold,
292
268
  * and the gateway is the Worker's own account's.
293
- *
294
- * @experimental This surface is experimental and may change.
295
269
  */
296
270
  interface BindingAccess {
297
271
  /** The `AI` binding from a Worker's env. */
@@ -306,8 +280,6 @@ interface BindingAccess {
306
280
  * a model object to the provider-native path
307
281
  * (`gateway.ai.cloudflare.com/v1/{accountId}/{gateway}/...`). The token is
308
282
  * only ever sent to those two hosts.
309
- *
310
- * @experimental This surface is experimental and may change.
311
283
  */
312
284
  interface AccountAccess {
313
285
  /** The account the gateway belongs to. */
@@ -323,8 +295,6 @@ interface AccountAccess {
323
295
  /**
324
296
  * Provider-wide gateway defaults, in either spelling: nested under `gateway`,
325
297
  * or flat (`{ id: "prod", cacheTtl: 60 }`). Both merge, the flat key winning.
326
- *
327
- * @experimental This surface is experimental and may change.
328
298
  */
329
299
  interface ProviderGatewaySettings extends GatewayOptions {
330
300
  /** Gateway id or full gateway options. */
@@ -343,8 +313,6 @@ interface ProviderGatewaySettings extends GatewayOptions {
343
313
  * default; a module whose legs may also be model objects says so
344
314
  * (`ModelOptions<WorkersAIModelId | LanguageModelV4>`) rather than rebuilding
345
315
  * the type.
346
- *
347
- * @experimental This surface is experimental and may change.
348
316
  */
349
317
  interface ModelOptions<Leg = WorkersAIModelId> extends ProviderGatewaySettings {
350
318
  /**
@@ -382,8 +350,6 @@ interface ResolvedGateway extends GatewayOptions {
382
350
  //#region src/models/core/errors.d.ts
383
351
  /**
384
352
  * Coarse classification of a failed Cloudflare AI call.
385
- *
386
- * @experimental This surface is experimental and may change.
387
353
  */
388
354
  type CloudflareAIErrorCode =
389
355
  | "auth"
@@ -395,8 +361,6 @@ type CloudflareAIErrorCode =
395
361
  | "unknown";
396
362
  /**
397
363
  * One leg of a {@link CloudflareAIError} fallback chain.
398
- *
399
- * @experimental This surface is experimental and may change.
400
364
  */
401
365
  interface CloudflareAIAttempt {
402
366
  /** The model id that was tried. */
@@ -410,8 +374,6 @@ interface CloudflareAIAttempt {
410
374
  * modules wrap it into their own error type at their boundary (the AI SDK
411
375
  * module into an `APICallError`, so `ai`'s retry loop honours
412
376
  * {@link CloudflareAIError.isRetryable}).
413
- *
414
- * @experimental This surface is experimental and may change.
415
377
  */
416
378
  declare class CloudflareAIError extends Error {
417
379
  /** HTTP status, when the failure carried one. */
@@ -473,8 +435,6 @@ declare class CloudflareAIError extends Error {
473
435
  /**
474
436
  * The gateway provider slugs this table maps onto. A subset of the ambient
475
437
  * `AIGatewayProviders` union; {@link GatewayProviderNameCheck} keeps it one.
476
- *
477
- * @experimental This surface is experimental and may change.
478
438
  */
479
439
  declare const GATEWAY_PROVIDER_NAMES: readonly [
480
440
  "workers-ai",
@@ -499,8 +459,6 @@ declare const GATEWAY_PROVIDER_NAMES: readonly [
499
459
  ];
500
460
  /**
501
461
  * A gateway provider slug.
502
- *
503
- * @experimental This surface is experimental and may change.
504
462
  */
505
463
  type GatewayProviderName = (typeof GATEWAY_PROVIDER_NAMES)[number];
506
464
  //#endregion
@@ -620,4 +578,4 @@ export {
620
578
  KnownImageModelId as v,
621
579
  KnownSpeechModelId as y
622
580
  };
623
- //# sourceMappingURL=transport-CPh7YGiw.d.ts.map
581
+ //# sourceMappingURL=transport-5moD2pW5.d.ts.map
@@ -0,0 +1,49 @@
1
+ import { ClientOptions } from "@modelcontextprotocol/client";
2
+
3
+ //#region src/mcp/types.d.ts
4
+ type MaybePromise<T> = T | Promise<T>;
5
+ type HttpTransportType = "sse" | "streamable-http";
6
+ type BaseTransportType = HttpTransportType | "rpc";
7
+ type TransportType = BaseTransportType | "auto";
8
+ /**
9
+ * Agents-owned MCP client configuration. Only these SDK behaviours are part of
10
+ * the supported interface; new beta SDK fields are not persisted or exposed
11
+ * accidentally.
12
+ */
13
+ interface McpClientOptions {
14
+ capabilities?: ClientOptions["capabilities"];
15
+ jsonSchemaValidator?: ClientOptions["jsonSchemaValidator"];
16
+ versionNegotiation?: ClientOptions["versionNegotiation"];
17
+ inputRequired?: ClientOptions["inputRequired"];
18
+ listChanged?: ClientOptions["listChanged"];
19
+ supportedProtocolVersions?: ClientOptions["supportedProtocolVersions"];
20
+ enforceStrictCapabilities?: ClientOptions["enforceStrictCapabilities"];
21
+ debouncedNotificationMethods?: ClientOptions["debouncedNotificationMethods"];
22
+ listMaxPages?: ClientOptions["listMaxPages"];
23
+ responseCacheStore?: ClientOptions["responseCacheStore"];
24
+ cachePartition?: ClientOptions["cachePartition"];
25
+ defaultCacheTtlMs?: ClientOptions["defaultCacheTtlMs"];
26
+ }
27
+ interface CORSOptions {
28
+ origin?: string;
29
+ methods?: string;
30
+ headers?: string;
31
+ maxAge?: number;
32
+ exposeHeaders?: string;
33
+ }
34
+ interface ServeOptions {
35
+ binding?: string;
36
+ corsOptions?: CORSOptions;
37
+ transport?: TransportType;
38
+ jurisdiction?: DurableObjectJurisdiction;
39
+ }
40
+ //#endregion
41
+ export {
42
+ ServeOptions as a,
43
+ McpClientOptions as i,
44
+ CORSOptions as n,
45
+ TransportType as o,
46
+ MaybePromise as r,
47
+ BaseTransportType as t
48
+ };
49
+ //# sourceMappingURL=types-D2naO3rA.d.ts.map