agents 0.28.1 → 0.29.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.
- package/dist/{agent-routing-BMvWTFEp.d.ts → agent-routing-CDbpVjYq.d.ts} +7 -8
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-ohoewW-B.d.ts → agent-tools-C8DH8Yii.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/{ai-ahruGw7e.d.ts → ai-iXw0uOGj.d.ts} +3 -3
- package/dist/{ai-sdk-C2iTAwUd.js → ai-sdk-DRPh2rRa.js} +185 -125
- package/dist/ai-sdk-DRPh2rRa.js.map +1 -0
- package/dist/browser/ai.d.ts +1 -1
- package/dist/browser/ai.js +2 -2
- package/dist/browser/index.d.ts +8 -8
- package/dist/browser/index.js +3 -3
- package/dist/browser/tools/ai-sdk.d.ts +2 -2
- package/dist/browser/tools/ai-sdk.js +1 -1
- package/dist/browser/tools/pi.d.ts +1 -1
- package/dist/browser/tools/pi.js +3 -3
- package/dist/browser/tools/pi.js.map +1 -1
- package/dist/browser/tools/tanstack-ai.d.ts +2 -2
- package/dist/browser/tools/tanstack-ai.js +1 -1
- package/dist/{browser-CEdNlsaD.js → browser-DccPw_wW.js} +130 -79
- package/dist/browser-DccPw_wW.js.map +1 -0
- package/dist/{browser-D30VlpcA.d.ts → browser-DlXhSAdf.d.ts} +41 -37
- package/dist/{browser-tool-4iomavs_.js → browser-tool-B1mhifin.js} +3 -3
- package/dist/{browser-tool-4iomavs_.js.map → browser-tool-B1mhifin.js.map} +1 -1
- package/dist/{browser-tool-vtrPOV8e.d.ts → browser-tool-Cxjk5sgG.d.ts} +2 -2
- package/dist/chat/index.d.ts +143 -71
- package/dist/chat/index.js +269 -110
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/chat-sdk/index.js +1 -1
- package/dist/cli.js +33 -33
- package/dist/{client-Bp-JwL3p.d.ts → client-C27CtRZr.d.ts} +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/{connector-DEXzVoaY.d.ts → connector-20DJ6p4k.d.ts} +2 -2
- package/dist/{connector-CtZylXdk.js → connector-DAXBOIIi.js} +2 -2
- package/dist/{connector-CtZylXdk.js.map → connector-DAXBOIIi.js.map} +1 -1
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/harness/container/index.js +1 -1
- package/dist/harness/container/index.js.map +1 -1
- package/dist/harness/opencode/index.js +1 -1
- package/dist/harness/pi/index.d.ts +13 -5
- package/dist/harness/pi/index.js +8 -214
- package/dist/harness/pi/index.js.map +1 -1
- package/dist/{images-C4hiIexM.js → images-xaDv2Fqe.js} +636 -168
- package/dist/images-xaDv2Fqe.js.map +1 -0
- package/dist/index-DCxk3OSJ.d.ts +378 -0
- package/dist/{index-kbSUIer3.d.ts → index-iv9FTXX9.d.ts} +80 -112
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{input-schema-xBofjBKC.js → input-schema-B0Etuo-o.js} +2 -2
- package/dist/{input-schema-xBofjBKC.js.map → input-schema-B0Etuo-o.js.map} +1 -1
- package/dist/lifecycle/index.js +1 -1
- package/dist/{lifecycle-DGorpAmA.js → lifecycle-ClT4DmF2.js} +11 -3
- package/dist/lifecycle-ClT4DmF2.js.map +1 -0
- package/dist/mcp/client/index.d.ts +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/models/ai-sdk/index.d.ts +29 -352
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.d.ts +25 -13
- package/dist/models/opencode/index.js +16 -11
- package/dist/models/opencode/index.js.map +1 -1
- package/dist/models/pi-ai/index.d.ts +13 -14
- package/dist/models/pi-ai/index.js +85 -32
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/{session-store-DoPY12xM.d.ts → session-store-_IK6dV-w.d.ts} +14 -2
- package/dist/{session-store-Do4xkDcf.js → session-store-yvwq1f9x.js} +55 -2
- package/dist/session-store-yvwq1f9x.js.map +1 -0
- package/dist/{settings-BjAiPd6Z.js → settings-Dk2il2Hf.js} +4 -1
- package/dist/settings-Dk2il2Hf.js.map +1 -0
- package/dist/skills/index.d.ts +22 -28
- package/dist/skills/index.js +183 -143
- package/dist/skills/index.js.map +1 -1
- package/dist/{src-CQxJFv4l.js → src-6lr7MtM_.js} +3 -3
- package/dist/src-6lr7MtM_.js.map +1 -0
- package/dist/sub-routing.d.ts +1 -1
- package/dist/{tool-VF0qiO7q.js → tool-DkT_DJBm.js} +2 -2
- package/dist/tool-DkT_DJBm.js.map +1 -0
- package/dist/transport-CPh7YGiw.d.ts +623 -0
- package/dist/voice/index.d.ts +1 -1
- package/dist/web/fetch/tools/pi.js +2 -2
- package/dist/web/fetch/tools/pi.js.map +1 -1
- package/dist/web/search/index.js +1 -1
- package/dist/web/search/tools/ai-sdk.js +2 -2
- package/dist/web/search/tools/pi.js +3 -3
- package/dist/web/search/tools/pi.js.map +1 -1
- package/dist/web/search/tools/tanstack-ai.js +2 -2
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-C3zy8YR0.js → websockets-CqxnntmE.js} +2 -2
- package/dist/{websockets-C3zy8YR0.js.map → websockets-CqxnntmE.js.map} +1 -1
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/dist/workflows.js +1 -1
- package/docs/browse-the-web.md +1 -1
- package/docs/chat-agents.md +19 -18
- package/docs/harnesses/pi.md +47 -18
- package/docs/models-pi-ai.md +62 -20
- package/docs/models.md +197 -172
- package/package.json +7 -7
- package/dist/ai-sdk-C2iTAwUd.js.map +0 -1
- package/dist/browser-CEdNlsaD.js.map +0 -1
- package/dist/images-C4hiIexM.js.map +0 -1
- package/dist/lifecycle-DGorpAmA.js.map +0 -1
- package/dist/session-store-Do4xkDcf.js.map +0 -1
- package/dist/settings-BjAiPd6Z.js.map +0 -1
- package/dist/settings-DnD__xuE.d.ts +0 -349
- package/dist/src-CQxJFv4l.js.map +0 -1
- package/dist/tool-VF0qiO7q.js.map +0 -1
- package/dist/transport-DCyarnwm.d.ts +0 -200
|
@@ -0,0 +1,623 @@
|
|
|
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
|
+
* An AI Gateway dynamic route, by name: `dynamic/<route>`.
|
|
114
|
+
*
|
|
115
|
+
* A dynamic route is configured on the gateway — which models it tries, in
|
|
116
|
+
* which order, with what rate limits or budgets — and called through the
|
|
117
|
+
* Workers AI run path like a model. It answers in the OpenAI chat-completions
|
|
118
|
+
* shape whatever model served it, so it is a language model only.
|
|
119
|
+
*
|
|
120
|
+
* @experimental This surface is experimental and may change.
|
|
121
|
+
*/
|
|
122
|
+
type DynamicRouteId = `dynamic/${string}`;
|
|
123
|
+
/**
|
|
124
|
+
* A model from the AI Gateway catalog, by its catalog id:
|
|
125
|
+
* `<author>/<model>`, such as `openai/gpt-5.5`,
|
|
126
|
+
* `anthropic/claude-opus-4.8` or `cloudflare/auto`.
|
|
127
|
+
*
|
|
128
|
+
* The catalog id is the gateway's own spelling, which can differ from the
|
|
129
|
+
* vendor's (`claude-opus-4.8`, not `claude-opus-4-8`). It runs on
|
|
130
|
+
* `env.AI.run`, where AI Gateway's `/run` engine picks the provider, converts
|
|
131
|
+
* the request, and bills through Unified Billing or a key stored on the
|
|
132
|
+
* gateway.
|
|
133
|
+
*
|
|
134
|
+
* @experimental This surface is experimental and may change.
|
|
135
|
+
*/
|
|
136
|
+
type CatalogModelId = `${string}/${string}`;
|
|
137
|
+
/**
|
|
138
|
+
* A text-embedding model id accepted by `ai.embedding()`.
|
|
139
|
+
*
|
|
140
|
+
* The modality methods are Workers AI only — there is no vendor route for them
|
|
141
|
+
* — so, like {@link WorkersAIModelId}, they take `@cf/` ids and nothing else.
|
|
142
|
+
*
|
|
143
|
+
* @experimental This surface is experimental and may change.
|
|
144
|
+
*/
|
|
145
|
+
type CloudflareEmbeddingModelId =
|
|
146
|
+
| Extract<
|
|
147
|
+
EmbeddingCatalogId | WorkersAIModelIdsExtending<BaseAiTextEmbeddings>,
|
|
148
|
+
`@cf/${string}`
|
|
149
|
+
>
|
|
150
|
+
| (`@cf/${string}` & {});
|
|
151
|
+
/**
|
|
152
|
+
* Workers AI text-to-image ids that the generated `AiModels` entries do not
|
|
153
|
+
* classify as {@link BaseAiTextToImage} — the newer partner models get their
|
|
154
|
+
* own generated class instead. Curated for autocomplete only; the catalog
|
|
155
|
+
* lives server-side and any slug is accepted.
|
|
156
|
+
*
|
|
157
|
+
* The FLUX.2 family (`flux-2-dev`, `flux-2-klein-4b`, `flux-2-klein-9b`) is
|
|
158
|
+
* deliberately absent, for the reason {@link UnsupportedTranscriptionId}
|
|
159
|
+
* records for the Deepgram recognisers: its generated input takes a required
|
|
160
|
+
* `multipart` object body (`{ multipart: { body, contentType } }`) and no
|
|
161
|
+
* `prompt`, which the JSON run path cannot carry — live, the run path answers
|
|
162
|
+
* `400 Bad input: required properties at "/" are 'multipart'`. Suggesting an
|
|
163
|
+
* id that always 400s is worse than not suggesting it.
|
|
164
|
+
*
|
|
165
|
+
* @experimental This surface is experimental and may change.
|
|
166
|
+
*/
|
|
167
|
+
type KnownImageModelId =
|
|
168
|
+
| "@cf/black-forest-labs/flux-1-schnell"
|
|
169
|
+
| "@cf/leonardo/lucid-origin"
|
|
170
|
+
| "@cf/leonardo/phoenix-1.0";
|
|
171
|
+
/**
|
|
172
|
+
* An image model id accepted by `ai.image()`.
|
|
173
|
+
*
|
|
174
|
+
* @experimental This surface is experimental and may change.
|
|
175
|
+
*/
|
|
176
|
+
type CloudflareImageModelId =
|
|
177
|
+
| Extract<
|
|
178
|
+
WorkersAIModelIdsExtending<BaseAiTextToImage> | KnownImageModelId,
|
|
179
|
+
`@cf/${string}`
|
|
180
|
+
>
|
|
181
|
+
| (`@cf/${string}` & {});
|
|
182
|
+
/**
|
|
183
|
+
* Workers AI text-to-speech ids without a {@link BaseAiTextToSpeech} entry.
|
|
184
|
+
* Curated for autocomplete only.
|
|
185
|
+
*
|
|
186
|
+
* @experimental This surface is experimental and may change.
|
|
187
|
+
*/
|
|
188
|
+
type KnownSpeechModelId =
|
|
189
|
+
| "@cf/deepgram/aura-1"
|
|
190
|
+
| "@cf/deepgram/aura-2-en"
|
|
191
|
+
| "@cf/deepgram/aura-2-es";
|
|
192
|
+
/**
|
|
193
|
+
* A text-to-speech model id accepted by `ai.speech()`.
|
|
194
|
+
*
|
|
195
|
+
* @experimental This surface is experimental and may change.
|
|
196
|
+
*/
|
|
197
|
+
type CloudflareSpeechModelId =
|
|
198
|
+
| Extract<
|
|
199
|
+
WorkersAIModelIdsExtending<BaseAiTextToSpeech> | KnownSpeechModelId,
|
|
200
|
+
`@cf/${string}`
|
|
201
|
+
>
|
|
202
|
+
| (`@cf/${string}` & {});
|
|
203
|
+
/**
|
|
204
|
+
* Deepgram's Flux takes websocket connections only. It stays out of the
|
|
205
|
+
* suggested arm, and the transcription model answers a clear error for it.
|
|
206
|
+
*/
|
|
207
|
+
type UnsupportedTranscriptionId = "@cf/deepgram/flux";
|
|
208
|
+
/**
|
|
209
|
+
* A speech-recognition model id accepted by `ai.transcription()`.
|
|
210
|
+
*
|
|
211
|
+
* Deepgram's Flux (`@cf/deepgram/flux`) is deliberately not suggested: it
|
|
212
|
+
* takes websocket connections only, so this provider answers a clear error
|
|
213
|
+
* for it rather than a 400.
|
|
214
|
+
*
|
|
215
|
+
* @experimental This surface is experimental and may change.
|
|
216
|
+
*/
|
|
217
|
+
type CloudflareTranscriptionModelId =
|
|
218
|
+
| Extract<
|
|
219
|
+
| Exclude<TranscriptionCatalogId, UnsupportedTranscriptionId>
|
|
220
|
+
| Exclude<
|
|
221
|
+
WorkersAIModelIdsExtending<BaseAiAutomaticSpeechRecognition>,
|
|
222
|
+
UnsupportedTranscriptionId
|
|
223
|
+
>,
|
|
224
|
+
`@cf/${string}`
|
|
225
|
+
>
|
|
226
|
+
| (`@cf/${string}` & {});
|
|
227
|
+
/**
|
|
228
|
+
* A reranking model id accepted by `ai.reranking()`.
|
|
229
|
+
*
|
|
230
|
+
* @experimental This surface is experimental and may change.
|
|
231
|
+
*/
|
|
232
|
+
type CloudflareRerankingModelId =
|
|
233
|
+
| Extract<RerankingCatalogId, `@cf/${string}`>
|
|
234
|
+
| (`@cf/${string}` & {});
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/models/core/settings.d.ts
|
|
237
|
+
/**
|
|
238
|
+
* AI Gateway settings for a request. The gateway is an option, not a separate
|
|
239
|
+
* product: every call goes through one, and `id` defaults to `"default"`,
|
|
240
|
+
* which Cloudflare creates on first use.
|
|
241
|
+
*
|
|
242
|
+
* @experimental This surface is experimental and may change.
|
|
243
|
+
*/
|
|
244
|
+
interface GatewayOptions {
|
|
245
|
+
/** Gateway id. Defaults to `"default"` (auto-created on first use). */
|
|
246
|
+
id?: string;
|
|
247
|
+
/** Bypass the cache for this request. */
|
|
248
|
+
skipCache?: boolean;
|
|
249
|
+
/** Cache lifetime in seconds. */
|
|
250
|
+
cacheTtl?: number;
|
|
251
|
+
/** Explicit cache key, instead of the request-derived one. */
|
|
252
|
+
cacheKey?: string;
|
|
253
|
+
/** Whether the gateway stores the request/response in its log. */
|
|
254
|
+
collectLog?: boolean;
|
|
255
|
+
/** Arbitrary key/values attached to the gateway log entry. */
|
|
256
|
+
metadata?: Record<string, string | number | boolean | null>;
|
|
257
|
+
/** Correlates several requests into one gateway event. */
|
|
258
|
+
eventId?: string;
|
|
259
|
+
/** Upstream request timeout in milliseconds. */
|
|
260
|
+
requestTimeoutMs?: number;
|
|
261
|
+
/** Server-side retry policy for the upstream provider call. */
|
|
262
|
+
retries?: {
|
|
263
|
+
maxAttempts?: 1 | 2 | 3 | 4 | 5;
|
|
264
|
+
retryDelayMs?: number;
|
|
265
|
+
backoff?: "constant" | "linear" | "exponential";
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* The stored BYOK key to use when the gateway holds more than one for a
|
|
269
|
+
* provider, by alias. Sent as `cf-aig-byok-alias`, for catalog models and
|
|
270
|
+
* for model objects reached through the provider-native path.
|
|
271
|
+
*/
|
|
272
|
+
byokAlias?: string;
|
|
273
|
+
/**
|
|
274
|
+
* Zero Data Retention for this request, sent as `cf-aig-zdr`: `true` turns
|
|
275
|
+
* it on and `false` off, whatever the gateway's own setting. Unified
|
|
276
|
+
* billing only, and only for model objects reached through the
|
|
277
|
+
* provider-native path — `/run` does not read it.
|
|
278
|
+
*/
|
|
279
|
+
zdr?: boolean;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* How `createAI` reaches Cloudflare: the `AI` binding, or an account id and
|
|
283
|
+
* API token. Both take the same routes — a model id to the run path, a
|
|
284
|
+
* vendor's model object to the provider-native path — and the same gateway
|
|
285
|
+
* options.
|
|
286
|
+
*
|
|
287
|
+
* @experimental This surface is experimental and may change.
|
|
288
|
+
*/
|
|
289
|
+
type AISettings = (BindingAccess | AccountAccess) & ProviderGatewaySettings;
|
|
290
|
+
/**
|
|
291
|
+
* Reach Cloudflare through the `AI` binding: no account id or token to hold,
|
|
292
|
+
* and the gateway is the Worker's own account's.
|
|
293
|
+
*
|
|
294
|
+
* @experimental This surface is experimental and may change.
|
|
295
|
+
*/
|
|
296
|
+
interface BindingAccess {
|
|
297
|
+
/** The `AI` binding from a Worker's env. */
|
|
298
|
+
binding: Ai;
|
|
299
|
+
accountId?: never;
|
|
300
|
+
apiToken?: never;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Reach Cloudflare over HTTP with an account id and API token, for a gateway
|
|
304
|
+
* in another account or code that runs outside a Worker. A model id goes to
|
|
305
|
+
* the REST API (`api.cloudflare.com/client/v4/accounts/{accountId}/ai/...`),
|
|
306
|
+
* a model object to the provider-native path
|
|
307
|
+
* (`gateway.ai.cloudflare.com/v1/{accountId}/{gateway}/...`). The token is
|
|
308
|
+
* only ever sent to those two hosts.
|
|
309
|
+
*
|
|
310
|
+
* @experimental This surface is experimental and may change.
|
|
311
|
+
*/
|
|
312
|
+
interface AccountAccess {
|
|
313
|
+
/** The account the gateway belongs to. */
|
|
314
|
+
accountId: string;
|
|
315
|
+
/**
|
|
316
|
+
* A Cloudflare API token for that account, with Workers AI Read (model ids,
|
|
317
|
+
* on the REST API) and AI Gateway Run (model objects, on the
|
|
318
|
+
* provider-native path).
|
|
319
|
+
*/
|
|
320
|
+
apiToken: string;
|
|
321
|
+
binding?: never;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Provider-wide gateway defaults, in either spelling: nested under `gateway`,
|
|
325
|
+
* or flat (`{ id: "prod", cacheTtl: 60 }`). Both merge, the flat key winning.
|
|
326
|
+
*
|
|
327
|
+
* @experimental This surface is experimental and may change.
|
|
328
|
+
*/
|
|
329
|
+
interface ProviderGatewaySettings extends GatewayOptions {
|
|
330
|
+
/** Gateway id or full gateway options. */
|
|
331
|
+
gateway?: string | GatewayOptions;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Per-model and per-call options. The flat gateway keys are sugar for
|
|
335
|
+
* `gateway: { ... }`; both forms merge, with the flat key winning.
|
|
336
|
+
*
|
|
337
|
+
* The same shape is accepted per call under
|
|
338
|
+
* `providerOptions.cloudflare`, where it takes precedence over the per-model
|
|
339
|
+
* options, which in turn take precedence over the `createAI` settings.
|
|
340
|
+
*
|
|
341
|
+
* `Leg` is what a framework module accepts as a fallback leg. Workers AI ids
|
|
342
|
+
* are the only kind this module can resolve on its own, so they are the
|
|
343
|
+
* default; a module whose legs may also be model objects says so
|
|
344
|
+
* (`ModelOptions<WorkersAIModelId | LanguageModelV4>`) rather than rebuilding
|
|
345
|
+
* the type.
|
|
346
|
+
*
|
|
347
|
+
* @experimental This surface is experimental and may change.
|
|
348
|
+
*/
|
|
349
|
+
interface ModelOptions<Leg = WorkersAIModelId> extends ProviderGatewaySettings {
|
|
350
|
+
/**
|
|
351
|
+
* Models to try, in order, if the primary fails before any output is
|
|
352
|
+
* produced. A leg travels with the chain's gateway options — those win over
|
|
353
|
+
* a leg's own, and `metadata` merges — while everything a leg was built with
|
|
354
|
+
* itself stays its own. Client-side today; becomes server-side when the
|
|
355
|
+
* platform ships model-first routing.
|
|
356
|
+
*/
|
|
357
|
+
fallback?: Leg[];
|
|
358
|
+
/** Extra request headers, merged last. */
|
|
359
|
+
headers?: Record<string, string>;
|
|
360
|
+
/**
|
|
361
|
+
* Workers AI only: route same-key requests to the same replica for
|
|
362
|
+
* prefix-cache hits. Sent as the `x-session-affinity` header.
|
|
363
|
+
*/
|
|
364
|
+
sessionAffinity?: string;
|
|
365
|
+
/**
|
|
366
|
+
* Explicit reasoning effort. `null` disables reasoning on models that
|
|
367
|
+
* support toggling it. The unified AI SDK `reasoning` call option maps onto
|
|
368
|
+
* this when this is not set.
|
|
369
|
+
*/
|
|
370
|
+
reasoningEffort?: "low" | "medium" | "high" | null;
|
|
371
|
+
/**
|
|
372
|
+
* Workers AI only: forwarded verbatim as `chat_template_kwargs`, e.g.
|
|
373
|
+
* `{ enable_thinking: false }`.
|
|
374
|
+
*/
|
|
375
|
+
chatTemplateKwargs?: Record<string, unknown>;
|
|
376
|
+
}
|
|
377
|
+
/** A gateway config with the id filled in. */
|
|
378
|
+
interface ResolvedGateway extends GatewayOptions {
|
|
379
|
+
id: string;
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/models/core/errors.d.ts
|
|
383
|
+
/**
|
|
384
|
+
* Coarse classification of a failed Cloudflare AI call.
|
|
385
|
+
*
|
|
386
|
+
* @experimental This surface is experimental and may change.
|
|
387
|
+
*/
|
|
388
|
+
type CloudflareAIErrorCode =
|
|
389
|
+
| "auth"
|
|
390
|
+
| "rate-limit"
|
|
391
|
+
| "not-found"
|
|
392
|
+
| "bad-request"
|
|
393
|
+
| "provider-error"
|
|
394
|
+
| "gateway-error"
|
|
395
|
+
| "unknown";
|
|
396
|
+
/**
|
|
397
|
+
* One leg of a {@link CloudflareAIError} fallback chain.
|
|
398
|
+
*
|
|
399
|
+
* @experimental This surface is experimental and may change.
|
|
400
|
+
*/
|
|
401
|
+
interface CloudflareAIAttempt {
|
|
402
|
+
/** The model id that was tried. */
|
|
403
|
+
model: string;
|
|
404
|
+
/** The error that leg failed with. */
|
|
405
|
+
error: unknown;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Error thrown for every failed Cloudflare AI call, whether it came back as a
|
|
409
|
+
* non-2xx `Response` or as a thrown Workers AI binding error. Framework
|
|
410
|
+
* modules wrap it into their own error type at their boundary (the AI SDK
|
|
411
|
+
* module into an `APICallError`, so `ai`'s retry loop honours
|
|
412
|
+
* {@link CloudflareAIError.isRetryable}).
|
|
413
|
+
*
|
|
414
|
+
* @experimental This surface is experimental and may change.
|
|
415
|
+
*/
|
|
416
|
+
declare class CloudflareAIError extends Error {
|
|
417
|
+
/** HTTP status, when the failure carried one. */
|
|
418
|
+
readonly status: number | undefined;
|
|
419
|
+
/** Coarse classification used for routing and fallback decisions. */
|
|
420
|
+
readonly code: CloudflareAIErrorCode;
|
|
421
|
+
/** `cf-aig-log-id` of the failed request, when the response carried one. */
|
|
422
|
+
readonly logId: string | undefined;
|
|
423
|
+
/** The model id that produced this error. */
|
|
424
|
+
readonly model: string;
|
|
425
|
+
/** Which binding path the request went down, for error reporting. */
|
|
426
|
+
readonly url: string;
|
|
427
|
+
/** The request body that failed. */
|
|
428
|
+
readonly requestBodyValues: unknown;
|
|
429
|
+
/** Response headers, when there was a response. */
|
|
430
|
+
readonly responseHeaders: Record<string, string> | undefined;
|
|
431
|
+
/** Raw response body text, when there was a response. */
|
|
432
|
+
readonly responseBody: string | undefined;
|
|
433
|
+
/** Whether a retry is worth attempting. */
|
|
434
|
+
readonly isRetryable: boolean;
|
|
435
|
+
/** Parsed error envelope, or other structured detail. */
|
|
436
|
+
readonly data: unknown;
|
|
437
|
+
/** Every leg tried, when this error ends a fallback chain. */
|
|
438
|
+
readonly attempts: CloudflareAIAttempt[] | undefined;
|
|
439
|
+
readonly cause: unknown;
|
|
440
|
+
constructor(options: {
|
|
441
|
+
message: string;
|
|
442
|
+
model: string;
|
|
443
|
+
url: string;
|
|
444
|
+
requestBodyValues: unknown;
|
|
445
|
+
status?: number;
|
|
446
|
+
code: CloudflareAIErrorCode;
|
|
447
|
+
logId?: string;
|
|
448
|
+
responseHeaders?: Record<string, string>;
|
|
449
|
+
responseBody?: string;
|
|
450
|
+
isRetryable?: boolean;
|
|
451
|
+
data?: unknown;
|
|
452
|
+
cause?: unknown;
|
|
453
|
+
attempts?: CloudflareAIAttempt[];
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/models/core/gateway-providers.d.ts
|
|
458
|
+
/**
|
|
459
|
+
* The AI Gateway provider table: which gateway provider slug a vendor's own
|
|
460
|
+
* base URL belongs to, and what the provider-native `endpoint` is for a
|
|
461
|
+
* given upstream URL.
|
|
462
|
+
*
|
|
463
|
+
* This is platform knowledge, not vendor knowledge — the gateway publishes the
|
|
464
|
+
* list, and every entry here appears in `AIGatewayProviders` from
|
|
465
|
+
* `@cloudflare/workers-types`. Nothing about a vendor's wire format, model ids
|
|
466
|
+
* or capabilities lives here: the vendor's own provider package builds the
|
|
467
|
+
* request, and this table only says where it goes.
|
|
468
|
+
*
|
|
469
|
+
* Adapted from `@cloudflare/ai-gateway-provider`'s `providers.ts`.
|
|
470
|
+
*
|
|
471
|
+
* @experimental This surface is experimental and may change.
|
|
472
|
+
*/
|
|
473
|
+
/**
|
|
474
|
+
* The gateway provider slugs this table maps onto. A subset of the ambient
|
|
475
|
+
* `AIGatewayProviders` union; {@link GatewayProviderNameCheck} keeps it one.
|
|
476
|
+
*
|
|
477
|
+
* @experimental This surface is experimental and may change.
|
|
478
|
+
*/
|
|
479
|
+
declare const GATEWAY_PROVIDER_NAMES: readonly [
|
|
480
|
+
"workers-ai",
|
|
481
|
+
"anthropic",
|
|
482
|
+
"openai",
|
|
483
|
+
"azure-openai",
|
|
484
|
+
"google-ai-studio",
|
|
485
|
+
"google-vertex-ai",
|
|
486
|
+
"grok",
|
|
487
|
+
"mistral",
|
|
488
|
+
"perplexity-ai",
|
|
489
|
+
"replicate",
|
|
490
|
+
"groq",
|
|
491
|
+
"deepseek",
|
|
492
|
+
"openrouter",
|
|
493
|
+
"cerebras",
|
|
494
|
+
"cohere",
|
|
495
|
+
"huggingface",
|
|
496
|
+
"aws-bedrock",
|
|
497
|
+
"elevenlabs",
|
|
498
|
+
"cartesia"
|
|
499
|
+
];
|
|
500
|
+
/**
|
|
501
|
+
* A gateway provider slug.
|
|
502
|
+
*
|
|
503
|
+
* @experimental This surface is experimental and may change.
|
|
504
|
+
*/
|
|
505
|
+
type GatewayProviderName = (typeof GATEWAY_PROVIDER_NAMES)[number];
|
|
506
|
+
//#endregion
|
|
507
|
+
//#region src/models/core/transport.d.ts
|
|
508
|
+
/**
|
|
509
|
+
* The shape of a run-path request body, and of its answer, for a model AI
|
|
510
|
+
* Gateway's `/run` serves. A request in a model's native format is not
|
|
511
|
+
* converted, streams included.
|
|
512
|
+
*
|
|
513
|
+
* @experimental This surface is experimental and may change.
|
|
514
|
+
*/
|
|
515
|
+
type RunRequestFormat = "chat-completions" | "messages" | "responses";
|
|
516
|
+
/** One request on the Cloudflare run path. */
|
|
517
|
+
interface TransportRequest {
|
|
518
|
+
/**
|
|
519
|
+
* Model id — a Workers AI id, an AI Gateway catalog id
|
|
520
|
+
* (`<author>/<model>`), or a dynamic route (`dynamic/<route>`).
|
|
521
|
+
*/
|
|
522
|
+
model: string;
|
|
523
|
+
/** The provider-shaped request body (`input` on the run path). */
|
|
524
|
+
input: Record<string, unknown>;
|
|
525
|
+
/**
|
|
526
|
+
* The format `input` is in, and that the answer comes back in, for a model
|
|
527
|
+
* AI Gateway's `/run` serves. Defaults to chat completions. A Workers AI
|
|
528
|
+
* model's input is its own, so this is ignored for one.
|
|
529
|
+
*/
|
|
530
|
+
format?: RunRequestFormat;
|
|
531
|
+
/** Gateway options for this request. */
|
|
532
|
+
gateway: ResolvedGateway;
|
|
533
|
+
/** Extra request headers, merged last. */
|
|
534
|
+
headers: Record<string, string>;
|
|
535
|
+
/** Abort signal, forwarded to the binding or to `fetch`. */
|
|
536
|
+
signal?: AbortSignal;
|
|
537
|
+
/**
|
|
538
|
+
* Audio for a Workers AI model that takes it as a raw body
|
|
539
|
+
* (`audio: { body, contentType }`, as Deepgram's Nova-3 does). `input`
|
|
540
|
+
* carries the model's other fields. The request goes to Workers AI
|
|
541
|
+
* directly: AI Gateway does not accept the body.
|
|
542
|
+
*/
|
|
543
|
+
audio?: RawAudio;
|
|
544
|
+
}
|
|
545
|
+
/** Audio bytes and their media type, sent as a request body of their own. */
|
|
546
|
+
interface RawAudio {
|
|
547
|
+
bytes: Uint8Array;
|
|
548
|
+
contentType: string;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* A vendor's own request, sent to AI Gateway's provider-native path:
|
|
552
|
+
* `{gateway}/{provider}/{endpoint}`. Nothing is converted on the way — the
|
|
553
|
+
* method, headers and body are the vendor's — so the answer is the vendor's
|
|
554
|
+
* own response, streams included.
|
|
555
|
+
*
|
|
556
|
+
* @experimental This surface is experimental and may change.
|
|
557
|
+
*/
|
|
558
|
+
interface NativeRequest {
|
|
559
|
+
/** The gateway provider slug, e.g. `anthropic`. */
|
|
560
|
+
provider: GatewayProviderName | string;
|
|
561
|
+
/** The vendor path after the provider slug, query string included. */
|
|
562
|
+
endpoint: string;
|
|
563
|
+
/** The HTTP method the vendor used. */
|
|
564
|
+
method: string;
|
|
565
|
+
/** The vendor's own request headers. */
|
|
566
|
+
headers: Record<string, string>;
|
|
567
|
+
/** The vendor's request body, untouched: JSON, multipart, or none. */
|
|
568
|
+
body: BodyInit | null | undefined;
|
|
569
|
+
/** Gateway options, sent as `cf-aig-*` headers. */
|
|
570
|
+
gateway: ResolvedGateway;
|
|
571
|
+
/** Abort signal, forwarded to the binding. */
|
|
572
|
+
signal?: AbortSignal;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* The single code path both backends, the binding and HTTP, implement. Always
|
|
576
|
+
* resolves to a raw `Response`, so streaming and non-streaming calls share one
|
|
577
|
+
* path and nothing is buffered on the caller's behalf.
|
|
578
|
+
*
|
|
579
|
+
* @experimental This surface is experimental and may change.
|
|
580
|
+
*/
|
|
581
|
+
interface Transport {
|
|
582
|
+
/** A stable identifier for the endpoint, used in error reporting. */
|
|
583
|
+
readonly url: string;
|
|
584
|
+
run(request: TransportRequest): Promise<Response>;
|
|
585
|
+
/**
|
|
586
|
+
* Sends a vendor's own request to AI Gateway's provider-native path. It
|
|
587
|
+
* resolves to the vendor's raw `Response`, error responses included: only
|
|
588
|
+
* the gateway's own failures (a missing gateway, an unpaid account) are
|
|
589
|
+
* lifted, by the caller, because the vendor's own code knows how to read
|
|
590
|
+
* its errors and we do not.
|
|
591
|
+
*/
|
|
592
|
+
native(request: NativeRequest): Promise<Response>;
|
|
593
|
+
/**
|
|
594
|
+
* A log id read off the backend itself when the response carried none. The
|
|
595
|
+
* Workers AI binding exposes the last gateway log id as a mutable property,
|
|
596
|
+
* so it is captured per response rather than read late.
|
|
597
|
+
*/
|
|
598
|
+
logIdFallback(response: Response): string | undefined;
|
|
599
|
+
}
|
|
600
|
+
//#endregion
|
|
601
|
+
export {
|
|
602
|
+
DynamicRouteId as _,
|
|
603
|
+
CloudflareAIError as a,
|
|
604
|
+
WorkersAIModelId as b,
|
|
605
|
+
GatewayOptions as c,
|
|
606
|
+
CatalogModelId as d,
|
|
607
|
+
CloudflareEmbeddingModelId as f,
|
|
608
|
+
CloudflareTranscriptionModelId as g,
|
|
609
|
+
CloudflareSpeechModelId as h,
|
|
610
|
+
CloudflareAIAttempt as i,
|
|
611
|
+
ModelOptions as l,
|
|
612
|
+
CloudflareRerankingModelId as m,
|
|
613
|
+
GATEWAY_PROVIDER_NAMES as n,
|
|
614
|
+
CloudflareAIErrorCode as o,
|
|
615
|
+
CloudflareImageModelId as p,
|
|
616
|
+
GatewayProviderName as r,
|
|
617
|
+
AISettings as s,
|
|
618
|
+
Transport as t,
|
|
619
|
+
ProviderGatewaySettings as u,
|
|
620
|
+
KnownImageModelId as v,
|
|
621
|
+
KnownSpeechModelId as y
|
|
622
|
+
};
|
|
623
|
+
//# sourceMappingURL=transport-CPh7YGiw.d.ts.map
|
package/dist/voice/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ function webFetchTool(options) {
|
|
|
53
53
|
async execute(input, _api, context) {
|
|
54
54
|
const run = await core.run(input, { signal: context.abortSignal });
|
|
55
55
|
if (run.ok) return {
|
|
56
|
-
|
|
56
|
+
output: [{
|
|
57
57
|
type: "text",
|
|
58
58
|
text: run.text
|
|
59
59
|
}],
|
|
@@ -72,7 +72,7 @@ function webFetchTool(options) {
|
|
|
72
72
|
if (run.error.url !== void 0) details.url = run.error.url;
|
|
73
73
|
if (run.error.contentType !== void 0) details.contentType = run.error.contentType;
|
|
74
74
|
return {
|
|
75
|
-
|
|
75
|
+
output: [{
|
|
76
76
|
type: "text",
|
|
77
77
|
text: run.text
|
|
78
78
|
}],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi.js","names":[],"sources":["../../../../src/web/fetch/tools/pi.ts"],"sourcesContent":["/**\n * `agents/webfetch/pi` — the `web_fetch` tool for the pi harness.\n *\n * @beta\n */\nimport { Type } from \"@earendil-works/pi-ai\";\nimport type { ToolRegistration } from \"@earendil-works/pi-durable\";\nimport { MAX_WEB_FETCH_URL_LENGTH, type WebFetchToolOutput } from \"../contract\";\nimport type { WebFetchErrorCode } from \"../source\";\nimport { createWebFetchToolCore, type WebFetchToolOptions } from \"../tool\";\n\nexport type {\n WebFetchFormat,\n WebFetchPage,\n WebFetchToolInput,\n WebFetchToolOutput,\n WebFetchVia\n} from \"../contract\";\nexport {\n WebFetchError,\n type WebFetchErrorCode,\n type WebFetchRequest,\n type WebFetchSource\n} from \"../source\";\nexport type { WebFetchToolOptions } from \"../tool\";\n\n/** The model's input schema. pi already coerces `\"20000\"` to `20000`. */\nfunction webFetchParameters() {\n return Type.Object({\n url: Type.String({\n minLength: 1,\n maxLength: MAX_WEB_FETCH_URL_LENGTH,\n description: \"The http(s) URL to read.\"\n }),\n offset: Type.Optional(\n Type.Integer({\n minimum: 0,\n description:\n \"Character offset into the content, to continue a long page from the previous result's offset. Default 0.\"\n })\n ),\n format: Type.Optional(\n Type.Union([Type.Literal(\"auto\"), Type.Literal(\"raw\")], {\n description:\n '\"auto\" (default) converts to the most readable form; \"raw\" returns the body as served.'\n })\n )\n });\n}\n\ntype WebFetchParameters = ReturnType<typeof webFetchParameters>;\n\n/**\n * Host-side details pi stores with each `web_fetch` result: the output (the\n * window the model read, with the page's metadata) or the failure.\n */\nexport type WebFetchToolDetails =\n | { ok: true; output: WebFetchToolOutput }\n | {\n ok: false;\n /** The source's error message, with the detail for the host. */\n message: string;\n status: number;\n code: WebFetchErrorCode;\n retryable: boolean;\n url?: string;\n /** The response's media type, when a response was read. */\n contentType?: string;\n };\n\n/**\n * Create a pi tool that reads a URL as Markdown, JSON, or text. Install it\n * on a registry like any other pi tool.\n *\n * The model chooses the URL, the window (`offset`), and the format; the\n * host chooses the URL policy, size limits, and window size. The tool is\n * `replay: \"safe\"`: a fetch interrupted mid-call (say, by an eviction) runs\n * again when the session recovers. Completed results are stored and not\n * fetched again.\n *\n * @example\n * ```ts\n * import { createRegistry } from \"@earendil-works/pi-durable\";\n * import { webFetchTool } from \"agents/webfetch/pi\";\n *\n * const registry = createRegistry();\n * registry.install({\n * name: \"tools\",\n * tools: [webFetchTool({ binding: env.AI })]\n * });\n * ```\n */\nexport function webFetchTool(\n options: WebFetchToolOptions\n): ToolRegistration<WebFetchParameters, WebFetchToolDetails> {\n const core = createWebFetchToolCore(options);\n return {\n name: core.name,\n description: core.description,\n parameters: webFetchParameters(),\n replay: \"safe\",\n async execute(input, _api, context) {\n const run = await core.run(input, { signal: context.abortSignal });\n if (run.ok) {\n return {\n
|
|
1
|
+
{"version":3,"file":"pi.js","names":[],"sources":["../../../../src/web/fetch/tools/pi.ts"],"sourcesContent":["/**\n * `agents/webfetch/pi` — the `web_fetch` tool for the pi harness.\n *\n * @beta\n */\nimport { Type } from \"@earendil-works/pi-ai\";\nimport type { ToolRegistration } from \"@earendil-works/pi-durable\";\nimport { MAX_WEB_FETCH_URL_LENGTH, type WebFetchToolOutput } from \"../contract\";\nimport type { WebFetchErrorCode } from \"../source\";\nimport { createWebFetchToolCore, type WebFetchToolOptions } from \"../tool\";\n\nexport type {\n WebFetchFormat,\n WebFetchPage,\n WebFetchToolInput,\n WebFetchToolOutput,\n WebFetchVia\n} from \"../contract\";\nexport {\n WebFetchError,\n type WebFetchErrorCode,\n type WebFetchRequest,\n type WebFetchSource\n} from \"../source\";\nexport type { WebFetchToolOptions } from \"../tool\";\n\n/** The model's input schema. pi already coerces `\"20000\"` to `20000`. */\nfunction webFetchParameters() {\n return Type.Object({\n url: Type.String({\n minLength: 1,\n maxLength: MAX_WEB_FETCH_URL_LENGTH,\n description: \"The http(s) URL to read.\"\n }),\n offset: Type.Optional(\n Type.Integer({\n minimum: 0,\n description:\n \"Character offset into the content, to continue a long page from the previous result's offset. Default 0.\"\n })\n ),\n format: Type.Optional(\n Type.Union([Type.Literal(\"auto\"), Type.Literal(\"raw\")], {\n description:\n '\"auto\" (default) converts to the most readable form; \"raw\" returns the body as served.'\n })\n )\n });\n}\n\ntype WebFetchParameters = ReturnType<typeof webFetchParameters>;\n\n/**\n * Host-side details pi stores with each `web_fetch` result: the output (the\n * window the model read, with the page's metadata) or the failure.\n */\nexport type WebFetchToolDetails =\n | { ok: true; output: WebFetchToolOutput }\n | {\n ok: false;\n /** The source's error message, with the detail for the host. */\n message: string;\n status: number;\n code: WebFetchErrorCode;\n retryable: boolean;\n url?: string;\n /** The response's media type, when a response was read. */\n contentType?: string;\n };\n\n/**\n * Create a pi tool that reads a URL as Markdown, JSON, or text. Install it\n * on a registry like any other pi tool.\n *\n * The model chooses the URL, the window (`offset`), and the format; the\n * host chooses the URL policy, size limits, and window size. The tool is\n * `replay: \"safe\"`: a fetch interrupted mid-call (say, by an eviction) runs\n * again when the session recovers. Completed results are stored and not\n * fetched again.\n *\n * @example\n * ```ts\n * import { createRegistry } from \"@earendil-works/pi-durable\";\n * import { webFetchTool } from \"agents/webfetch/pi\";\n *\n * const registry = createRegistry();\n * registry.install({\n * name: \"tools\",\n * tools: [webFetchTool({ binding: env.AI })]\n * });\n * ```\n */\nexport function webFetchTool(\n options: WebFetchToolOptions\n): ToolRegistration<WebFetchParameters, WebFetchToolDetails> {\n const core = createWebFetchToolCore(options);\n return {\n name: core.name,\n description: core.description,\n parameters: webFetchParameters(),\n replay: \"safe\",\n async execute(input, _api, context) {\n const run = await core.run(input, { signal: context.abortSignal });\n if (run.ok) {\n return {\n output: [{ type: \"text\", text: run.text }],\n details: { ok: true, output: run.output }\n };\n }\n const details: WebFetchToolDetails = {\n ok: false,\n message: run.error.message,\n status: run.error.status,\n code: run.error.code,\n retryable: run.error.retryable\n };\n if (run.error.url !== undefined) details.url = run.error.url;\n if (run.error.contentType !== undefined) {\n details.contentType = run.error.contentType;\n }\n return {\n output: [{ type: \"text\", text: run.text }],\n isError: true,\n details\n };\n }\n };\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAS,qBAAqB;CAC5B,OAAO,KAAK,OAAO;EACjB,KAAK,KAAK,OAAO;GACf,WAAW;GACX,WAAW;GACX,aAAa;EACf,CAAC;EACD,QAAQ,KAAK,SACX,KAAK,QAAQ;GACX,SAAS;GACT,aACE;EACJ,CAAC,CACH;EACA,QAAQ,KAAK,SACX,KAAK,MAAM,CAAC,KAAK,QAAQ,MAAM,GAAG,KAAK,QAAQ,KAAK,CAAC,GAAG,EACtD,aACE,6FACJ,CAAC,CACH;CACF,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,aACd,SAC2D;CAC3D,MAAM,OAAO,uBAAuB,OAAO;CAC3C,OAAO;EACL,MAAM,KAAK;EACX,aAAa,KAAK;EAClB,YAAY,mBAAmB;EAC/B,QAAQ;EACR,MAAM,QAAQ,OAAO,MAAM,SAAS;GAClC,MAAM,MAAM,MAAM,KAAK,IAAI,OAAO,EAAE,QAAQ,QAAQ,YAAY,CAAC;GACjE,IAAI,IAAI,IACN,OAAO;IACL,QAAQ,CAAC;KAAE,MAAM;KAAQ,MAAM,IAAI;IAAK,CAAC;IACzC,SAAS;KAAE,IAAI;KAAM,QAAQ,IAAI;IAAO;GAC1C;GAEF,MAAM,UAA+B;IACnC,IAAI;IACJ,SAAS,IAAI,MAAM;IACnB,QAAQ,IAAI,MAAM;IAClB,MAAM,IAAI,MAAM;IAChB,WAAW,IAAI,MAAM;GACvB;GACA,IAAI,IAAI,MAAM,QAAQ,KAAA,GAAW,QAAQ,MAAM,IAAI,MAAM;GACzD,IAAI,IAAI,MAAM,gBAAgB,KAAA,GAC5B,QAAQ,cAAc,IAAI,MAAM;GAElC,OAAO;IACL,QAAQ,CAAC;KAAE,MAAM;KAAQ,MAAM,IAAI;IAAK,CAAC;IACzC,SAAS;IACT;GACF;EACF;CACF;AACF"}
|
package/dist/web/search/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as createAIWebSearch, c as DEFAULT_WEB_SEARCH_LIMIT, d as WEB_SEARCH_TOOL_DESCRIPTION, f as WEB_SEARCH_TOOL_NAME, i as WebSearchError, l as MAX_WEB_SEARCH_LIMIT, o as createHTTPWebSearch, p as renderWebSearchResults, s as DEFAULT_WEB_SEARCH_DESCRIPTION_CHARS, t as DEFAULT_WEB_SEARCH_TIMEOUT_MS, u as MAX_WEB_SEARCH_QUERY_LENGTH } from "../../tool-
|
|
1
|
+
import { a as createAIWebSearch, c as DEFAULT_WEB_SEARCH_LIMIT, d as WEB_SEARCH_TOOL_DESCRIPTION, f as WEB_SEARCH_TOOL_NAME, i as WebSearchError, l as MAX_WEB_SEARCH_LIMIT, o as createHTTPWebSearch, p as renderWebSearchResults, s as DEFAULT_WEB_SEARCH_DESCRIPTION_CHARS, t as DEFAULT_WEB_SEARCH_TIMEOUT_MS, u as MAX_WEB_SEARCH_QUERY_LENGTH } from "../../tool-DkT_DJBm.js";
|
|
2
2
|
export { DEFAULT_WEB_SEARCH_DESCRIPTION_CHARS, DEFAULT_WEB_SEARCH_LIMIT, DEFAULT_WEB_SEARCH_TIMEOUT_MS, MAX_WEB_SEARCH_LIMIT, MAX_WEB_SEARCH_QUERY_LENGTH, WEB_SEARCH_TOOL_DESCRIPTION, WEB_SEARCH_TOOL_NAME, WebSearchError, createAIWebSearch, createHTTPWebSearch, renderWebSearchResults };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as WebSearchError, n as createWebSearchToolCore, r as toolFailure } from "../../../tool-
|
|
2
|
-
import { t as webSearchInputSchema } from "../../../input-schema-
|
|
1
|
+
import { i as WebSearchError, n as createWebSearchToolCore, r as toolFailure } from "../../../tool-DkT_DJBm.js";
|
|
2
|
+
import { t as webSearchInputSchema } from "../../../input-schema-B0Etuo-o.js";
|
|
3
3
|
//#region src/web/search/tools/ai-sdk.ts
|
|
4
4
|
/**
|
|
5
5
|
* Create an AI SDK tool that searches the web through Cloudflare's Web
|