agents 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -9
- package/dist/{agent-routing-0DR0Tk2v.d.ts → agent-routing-Bhdbvf7s.d.ts} +13 -8
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-YrATZJu2.d.ts → agent-tools-bJZwBMfq.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/ai-sdk-OoGkFy3s.js +2444 -0
- package/dist/ai-sdk-OoGkFy3s.js.map +1 -0
- package/dist/apply-chunks-1FheRb9W.js +99 -0
- package/dist/apply-chunks-1FheRb9W.js.map +1 -0
- package/dist/broadcast-state-CEyI4uAK.js +69 -0
- package/dist/broadcast-state-CEyI4uAK.js.map +1 -0
- package/dist/browser/ai-sdk.d.ts +1 -1
- package/dist/browser/ai-sdk.js +2 -2
- package/dist/browser/ai-sdk.js.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/tanstack-ai.d.ts +1 -1
- package/dist/browser/tanstack-ai.js +1 -1
- package/dist/{browser-DE3d-RLk.d.ts → browser-tmkcAAI3.d.ts} +2 -2
- package/dist/{browser-tool-DuNdlwZ9.d.ts → browser-tool-Bn-nzJQI.d.ts} +3 -3
- package/dist/{browser-tool-CQ10e6Kj.js → browser-tool-CBqs6hqa.js} +58 -18
- package/dist/browser-tool-CBqs6hqa.js.map +1 -0
- package/dist/capability-B4WbF81e.js.map +1 -1
- package/dist/{capability-runner-DBAnGr6L.d.ts → capability-runner-O5VbQzqg.d.ts} +9 -1
- package/dist/channel-Bak_6zDP.d.ts +333 -0
- package/dist/chat/index.d.ts +11 -9
- package/dist/chat/index.js +5 -194
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +2 -4
- package/dist/chat/react.js +3 -1
- package/dist/chat/react.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 +144 -0
- package/dist/{client-fyQrLGkD.js → client-1tEQ1Oqz.js} +27 -2
- package/dist/{client-fyQrLGkD.js.map → client-1tEQ1Oqz.js.map} +1 -1
- package/dist/{client-je3koD9Z.d.ts → client-DS3Dz9l0.d.ts} +2 -2
- package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
- package/dist/client.d.ts +1 -1
- package/dist/conversations-DH0ut_8n.d.ts +192 -0
- package/dist/{current-agent-vAk_5JMt.d.ts → current-agent-C07C5o5Y.d.ts} +3 -3
- package/dist/daemon-core-Buubj-y1.js +481 -0
- package/dist/daemon-core-Buubj-y1.js.map +1 -0
- package/dist/daemon-core-CbohVPAu.d.ts +132 -0
- package/dist/{do-oauth-client-provider-Tmf1vgKz.d.ts → do-oauth-client-provider-DfsUcpc3.d.ts} +7 -1
- package/dist/{durable-object-lifecycle-HhgOMWq9.d.ts → durable-object-lifecycle-DRqp475_.d.ts} +2 -2
- package/dist/{channels/email.d.ts → experimental/channels/email/index.d.ts} +25 -12
- package/dist/{channels/email.js → experimental/channels/email/index.js} +13 -35
- package/dist/experimental/channels/email/index.js.map +1 -0
- package/dist/experimental/channels/index.d.ts +270 -0
- package/dist/experimental/channels/index.js +1186 -0
- package/dist/experimental/channels/index.js.map +1 -0
- package/dist/{channels/slack.d.ts → experimental/channels/slack/index.d.ts} +19 -9
- package/dist/experimental/channels/slack/index.js +267 -0
- package/dist/experimental/channels/slack/index.js.map +1 -0
- package/dist/{channels/telegram.d.ts → experimental/channels/telegram/index.d.ts} +19 -9
- package/dist/experimental/channels/telegram/index.js +198 -0
- package/dist/experimental/channels/telegram/index.js.map +1 -0
- package/dist/experimental/channels/web/ai-sdk.d.ts +55 -0
- package/dist/experimental/channels/web/ai-sdk.js +266 -0
- package/dist/experimental/channels/web/ai-sdk.js.map +1 -0
- package/dist/experimental/channels/web/client.d.ts +97 -0
- package/dist/experimental/channels/web/client.js +349 -0
- package/dist/experimental/channels/web/client.js.map +1 -0
- package/dist/experimental/channels/web/index.d.ts +189 -0
- package/dist/experimental/channels/web/index.js +332 -0
- package/dist/experimental/channels/web/index.js.map +1 -0
- package/dist/gateway-BDC07gYO.d.ts +100 -0
- package/dist/handle-zAzh0UW2.d.ts +460 -0
- package/dist/harness/ai-sdk/index.d.ts +175 -0
- package/dist/harness/ai-sdk/index.js +605 -0
- package/dist/harness/ai-sdk/index.js.map +1 -0
- package/dist/harness/container/daemon/index.d.ts +76 -0
- package/dist/harness/container/daemon/index.js +3 -0
- package/dist/harness/container/index.d.ts +740 -0
- package/dist/harness/container/index.js +2152 -0
- package/dist/harness/container/index.js.map +1 -0
- package/dist/harness/container/runtime/index.d.ts +144 -0
- package/dist/harness/container/runtime/index.js +1082 -0
- package/dist/harness/container/runtime/index.js.map +1 -0
- package/dist/harness/opencode/index.d.ts +369 -0
- package/dist/harness/opencode/index.js +1072 -0
- package/dist/harness/opencode/index.js.map +1 -0
- package/dist/harness/pi/index.d.ts +2 -1
- package/dist/harness/store/index.d.ts +24 -0
- package/dist/harness/store/index.js +2 -0
- package/dist/harness/think/index.d.ts +821 -0
- package/dist/harness/think/index.js +2529 -0
- package/dist/harness/think/index.js.map +1 -0
- package/dist/harness-B6B9S3rb.d.ts +203 -0
- package/dist/{images-iiTDSyRu.js → images-Ce9SCu3X.js} +2 -248
- package/dist/images-Ce9SCu3X.js.map +1 -0
- package/dist/{index-BreL0YrQ.d.ts → index-D0A5tbWu.d.ts} +2 -2
- package/dist/index-Ib_4dwOo.d.ts +200 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/ingress-EFbrS547.js +9 -0
- package/dist/ingress-EFbrS547.js.map +1 -0
- package/dist/input-schema-DNrpTu49.js +23 -0
- package/dist/input-schema-DNrpTu49.js.map +1 -0
- package/dist/internal-kmw70xwR.js +46 -0
- package/dist/internal-kmw70xwR.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js +9 -0
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/client/index.d.ts +1 -1
- package/dist/mcp/client/index.js +1 -1
- package/dist/mcp/client/x402.d.ts +35 -4
- package/dist/mcp/client/x402.js +24 -3
- package/dist/mcp/client/x402.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +2 -2
- package/dist/models/ai-sdk/index.d.ts +16 -14
- package/dist/models/ai-sdk/index.js +1 -2442
- package/dist/models/opencode/index.d.ts +65 -0
- package/dist/models/opencode/index.js +285 -0
- package/dist/models/opencode/index.js.map +1 -0
- package/dist/models/pi-ai/index.d.ts +9 -7
- package/dist/models/pi-ai/index.js +2 -1
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/options-pwTNq9z6.d.ts +134 -0
- package/dist/protocol-BEgrJYC5.d.ts +331 -0
- package/dist/protocol-CukuI73M.d.ts +386 -0
- package/dist/protocol-cOklVBBD.js +227 -0
- package/dist/protocol-cOklVBBD.js.map +1 -0
- package/dist/{protocol-kHsr-f0X.js → protocol-eXeJxhgu.js} +2 -67
- package/dist/protocol-eXeJxhgu.js.map +1 -0
- package/dist/protocol-y2sSY584.js +148 -0
- package/dist/protocol-y2sSY584.js.map +1 -0
- package/dist/queue/index.d.ts +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/{scheduler-RdACNXDP.d.ts → scheduler-CrFCnv_J.d.ts} +2 -2
- package/dist/schedules/index.d.ts +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/sessions/index.d.ts +11 -434
- package/dist/sessions/index.js +1 -2271
- package/dist/sessions-B9pNuxdT.js +2272 -0
- package/dist/sessions-B9pNuxdT.js.map +1 -0
- package/dist/settings-C45hDliX.js +253 -0
- package/dist/settings-C45hDliX.js.map +1 -0
- package/dist/{transport-PfFnt-Ld.d.ts → settings-NgGwF7Qt.d.ts} +14 -208
- package/dist/{src-BZeu-SCD.js → src-DgCbZtIR.js} +4 -4
- package/dist/{src-BZeu-SCD.js.map → src-DgCbZtIR.js.map} +1 -1
- package/dist/stall-watchdog-BpRF2uwG.js +195 -0
- package/dist/stall-watchdog-BpRF2uwG.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/store-DLeqKuj3.d.ts +310 -0
- package/dist/store-vgcPYo8K.js +432 -0
- package/dist/store-vgcPYo8K.js.map +1 -0
- package/dist/streams/index.d.ts +1 -1
- package/dist/streams/index.js +1 -1
- package/dist/{streams-DW-UCOUc.js → streams-CITClVer.js} +16 -3
- package/dist/streams-CITClVer.js.map +1 -0
- package/dist/{streams-Cmkj9QfW.d.ts → streams-fbG61qM8.d.ts} +2 -2
- package/dist/sub-routing.d.ts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-68DESxf0.js → tasks-CkTZNaV1.js} +2 -1
- package/dist/tasks-CkTZNaV1.js.map +1 -0
- package/dist/{tasks-9YxYtByh.d.ts → tasks-PtlB4Uyn.d.ts} +2 -2
- package/dist/tool-3PA8xjB_.js +421 -0
- package/dist/tool-3PA8xjB_.js.map +1 -0
- package/dist/tool-BPJEbwaX.d.ts +278 -0
- package/dist/transport-k2mFrtL8.d.ts +200 -0
- package/dist/turns-DCV3ycDl.js +317 -0
- package/dist/turns-DCV3ycDl.js.map +1 -0
- package/dist/voice/client.js +1 -1
- package/dist/voice/index.d.ts +2 -2
- package/dist/voice/index.js +1 -1
- package/dist/websearch/index.d.ts +58 -0
- package/dist/websearch/index.js +2 -0
- package/dist/websearch/tools/ai-sdk.d.ts +77 -0
- package/dist/websearch/tools/ai-sdk.js +46 -0
- package/dist/websearch/tools/ai-sdk.js.map +1 -0
- package/dist/websearch/tools/pi.d.ts +82 -0
- package/dist/websearch/tools/pi.js +89 -0
- package/dist/websearch/tools/pi.js.map +1 -0
- package/dist/websearch/tools/tanstack-ai.d.ts +71 -0
- package/dist/websearch/tools/tanstack-ai.js +46 -0
- package/dist/websearch/tools/tanstack-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +12 -296
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-Ci-LZFHH.js → websockets-CmENGb-Z.js} +18 -4
- package/dist/websockets-CmENGb-Z.js.map +1 -0
- package/dist/{wire-types-CrjKvDyi.d.ts → wire-types-Cv0iwjk5.d.ts} +3 -51
- 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 +3 -0
- package/docs/harnesses/think.md +215 -0
- package/docs/index.md +2 -1
- package/docs/lifecycle.md +40 -0
- package/docs/search-the-web.md +133 -0
- package/package.json +117 -38
- package/dist/browser-tool-CQ10e6Kj.js.map +0 -1
- package/dist/channel-Bnm4S7T2.d.ts +0 -491
- package/dist/channels/ai-sdk.d.ts +0 -46
- package/dist/channels/ai-sdk.js +0 -120
- package/dist/channels/ai-sdk.js.map +0 -1
- package/dist/channels/email.js.map +0 -1
- package/dist/channels/index.d.ts +0 -233
- package/dist/channels/index.js +0 -608
- package/dist/channels/index.js.map +0 -1
- package/dist/channels/slack.js +0 -614
- package/dist/channels/slack.js.map +0 -1
- package/dist/channels/tanstack-ai.d.ts +0 -39
- package/dist/channels/tanstack-ai.js +0 -17
- package/dist/channels/tanstack-ai.js.map +0 -1
- package/dist/channels/telegram.js +0 -427
- package/dist/channels/telegram.js.map +0 -1
- package/dist/channels/voice.d.ts +0 -45
- package/dist/channels/voice.js +0 -122
- package/dist/channels/voice.js.map +0 -1
- package/dist/images-iiTDSyRu.js.map +0 -1
- package/dist/index-BB0kqhIz.d.ts +0 -101
- package/dist/ingress-BfetZbMO.js +0 -83
- package/dist/ingress-BfetZbMO.js.map +0 -1
- package/dist/internal-CYlgHl1l.js +0 -59
- package/dist/internal-CYlgHl1l.js.map +0 -1
- package/dist/models/ai-sdk/index.js.map +0 -1
- package/dist/protocol-kHsr-f0X.js.map +0 -1
- package/dist/sessions/index.js.map +0 -1
- package/dist/streams-DW-UCOUc.js.map +0 -1
- package/dist/surface-bZZJqBka.js +0 -17
- package/dist/surface-bZZJqBka.js.map +0 -1
- package/dist/tasks-68DESxf0.js.map +0 -1
- package/dist/tool-schema-CBjGPrsQ.js +0 -31
- package/dist/tool-schema-CBjGPrsQ.js.map +0 -1
- package/dist/websockets-Ci-LZFHH.js.map +0 -1
- package/docs/channels.md +0 -323
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
//#region src/websearch/contract.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The `web_search` tool contract: its name, what it tells the model, what the
|
|
4
|
+
* model passes in, what comes back, and how results are rendered for the
|
|
5
|
+
* model. Shared by every executor of the tool — the harness-executed
|
|
6
|
+
* adapters in `agents/websearch/*` today, and a gateway-executed variant in
|
|
7
|
+
* `agents/models/*` once AI Gateway server tools ship — so a `web_search` call
|
|
8
|
+
* looks the same in a transcript whoever ran it.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The tool's name, as the model calls it and as it appears in transcripts.
|
|
12
|
+
* `web_search` is the name models know from Anthropic's and OpenAI's built-in
|
|
13
|
+
* search tools.
|
|
14
|
+
*/
|
|
15
|
+
declare const WEB_SEARCH_TOOL_NAME = "web_search";
|
|
16
|
+
/** The default number of results when the model doesn't ask for a count. */
|
|
17
|
+
declare const DEFAULT_WEB_SEARCH_LIMIT = 5;
|
|
18
|
+
/** The most results one search can return; the API rejects more. */
|
|
19
|
+
declare const MAX_WEB_SEARCH_LIMIT = 10;
|
|
20
|
+
/** The longest query the API accepts, in characters. */
|
|
21
|
+
declare const MAX_WEB_SEARCH_QUERY_LENGTH = 1024;
|
|
22
|
+
/**
|
|
23
|
+
* Per-result description length in the model's view, in characters. Provider
|
|
24
|
+
* descriptions run to ~8,000 characters (Ceramic returns page text), which at
|
|
25
|
+
* ten results is 80 KB of context per search. The full text stays in the
|
|
26
|
+
* host-side output.
|
|
27
|
+
*/
|
|
28
|
+
declare const DEFAULT_WEB_SEARCH_DESCRIPTION_CHARS = 600;
|
|
29
|
+
/** What the model says when it wants a search. */
|
|
30
|
+
type WebSearchToolInput = {
|
|
31
|
+
/** The search query. */ query: string /** How many results to return, 1–10. Defaults to the host's `limit`. */;
|
|
32
|
+
limit?: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* One search result. `url` and `title` are always present; the rest only
|
|
36
|
+
* when the provider returns them (Exa adds `imageUrl` and
|
|
37
|
+
* `lastModifiedDate`, Linkup adds `faviconUrl`, Ceramic adds neither).
|
|
38
|
+
*/
|
|
39
|
+
type WebSearchResult = {
|
|
40
|
+
url: string;
|
|
41
|
+
title: string /** A snippet or extract of the page. Length and style vary by provider. */;
|
|
42
|
+
description?: string /** ISO 8601 timestamp of the page's last modification. */;
|
|
43
|
+
lastModifiedDate?: string;
|
|
44
|
+
imageUrl?: string;
|
|
45
|
+
faviconUrl?: string;
|
|
46
|
+
};
|
|
47
|
+
/** The Web Search API's response: results plus request metadata. */
|
|
48
|
+
type WebSearchResponse = {
|
|
49
|
+
items: WebSearchResult[];
|
|
50
|
+
metadata: {
|
|
51
|
+
/** The query as the provider saw it. */ query: string /** AI Gateway request id, for the gateway log. */;
|
|
52
|
+
requestId: string /** Provider latency in milliseconds. */;
|
|
53
|
+
latencyMs: number;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* What one `web_search` run produces for the host: the full API response and
|
|
58
|
+
* which provider served it. The model sees {@link renderWebSearchResults}
|
|
59
|
+
* of this.
|
|
60
|
+
*/
|
|
61
|
+
type WebSearchToolOutput = WebSearchResponse & {
|
|
62
|
+
/** The provider that ran the search, when the source knows. */ provider?: string;
|
|
63
|
+
};
|
|
64
|
+
declare const WEB_SEARCH_TOOL_DESCRIPTION: string;
|
|
65
|
+
interface RenderWebSearchResultsOptions {
|
|
66
|
+
/**
|
|
67
|
+
* Trim each description to this many characters in the model's view.
|
|
68
|
+
* Defaults to {@link DEFAULT_WEB_SEARCH_DESCRIPTION_CHARS}; `Infinity`
|
|
69
|
+
* disables trimming.
|
|
70
|
+
*/
|
|
71
|
+
maxDescriptionChars?: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Render search results as the text the model reads: one numbered block per
|
|
75
|
+
* result, descriptions trimmed and whitespace collapsed.
|
|
76
|
+
*/
|
|
77
|
+
declare function renderWebSearchResults(
|
|
78
|
+
response: WebSearchResponse,
|
|
79
|
+
options?: RenderWebSearchResultsOptions
|
|
80
|
+
): string;
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/websearch/source.d.ts
|
|
83
|
+
/**
|
|
84
|
+
* Search providers behind the Cloudflare Web Search API. `ceramic` is the
|
|
85
|
+
* platform default and the cheapest; `exa` and `linkup` cost more and, in our
|
|
86
|
+
* testing, ranked announcement-style queries noticeably better. Pricing and
|
|
87
|
+
* data-retention terms are in the Web Search docs.
|
|
88
|
+
*/
|
|
89
|
+
type WebSearchProvider = "ceramic" | "exa" | "linkup";
|
|
90
|
+
/** One search request as a source receives it. */
|
|
91
|
+
interface WebSearchRequest {
|
|
92
|
+
/** 1–1024 characters. */
|
|
93
|
+
query: string;
|
|
94
|
+
/** 1–10. Defaults to 5. */
|
|
95
|
+
limit?: number;
|
|
96
|
+
}
|
|
97
|
+
/** Per-call options a source receives alongside the request. */
|
|
98
|
+
interface WebSearchCallOptions {
|
|
99
|
+
/** Abort the search. A source should reject with the signal's reason. */
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Runs searches. The tool core calls `search` and renders what comes back.
|
|
104
|
+
* An object rather than a bare function so a wrapper (caching, logging)
|
|
105
|
+
* keeps `provider` by spreading the source it wraps.
|
|
106
|
+
*/
|
|
107
|
+
interface WebSearchSource {
|
|
108
|
+
search(
|
|
109
|
+
request: WebSearchRequest,
|
|
110
|
+
options?: WebSearchCallOptions
|
|
111
|
+
): Promise<WebSearchResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* The provider this source searches with, when known. Informational:
|
|
114
|
+
* recorded on the tool's host output.
|
|
115
|
+
*/
|
|
116
|
+
readonly provider?: WebSearchProvider;
|
|
117
|
+
}
|
|
118
|
+
/** Options shared by the AI-binding and HTTP sources. */
|
|
119
|
+
interface WebSearchGatewayOptions {
|
|
120
|
+
/** AI Gateway id. Defaults to `"default"`, which Cloudflare creates on first use. */
|
|
121
|
+
gateway?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Which provider runs the search. Host-chosen; the model never picks.
|
|
124
|
+
* Defaults to the platform default (`ceramic`).
|
|
125
|
+
*/
|
|
126
|
+
provider?: WebSearchProvider;
|
|
127
|
+
/**
|
|
128
|
+
* The BYOK key alias on the gateway to bill the provider with. When set
|
|
129
|
+
* and no such key exists the request fails rather than falling back to
|
|
130
|
+
* AI Gateway credits. When omitted, a key under the `default` alias is
|
|
131
|
+
* used if one exists, otherwise credits.
|
|
132
|
+
*/
|
|
133
|
+
byokAlias?: string;
|
|
134
|
+
}
|
|
135
|
+
/** A search over the Workers AI binding (`env.AI.websearch`). */
|
|
136
|
+
interface AIWebSearchOptions extends WebSearchGatewayOptions {
|
|
137
|
+
/** The Workers AI binding. Requires `"ai": { "binding": "AI" }` in wrangler.jsonc. */
|
|
138
|
+
binding: Ai;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Search through the Workers AI binding. The Worker's own account and the
|
|
142
|
+
* named gateway are billed.
|
|
143
|
+
*/
|
|
144
|
+
declare function createAIWebSearch(
|
|
145
|
+
options: AIWebSearchOptions
|
|
146
|
+
): WebSearchSource;
|
|
147
|
+
/** A search over the HTTP API, from any runtime with `fetch`. */
|
|
148
|
+
interface HTTPWebSearchOptions extends WebSearchGatewayOptions {
|
|
149
|
+
/** The Cloudflare account the gateway belongs to. */
|
|
150
|
+
accountId: string;
|
|
151
|
+
/** An API token with `Workers AI: Read` and `AI Gateway: Read` on that account. */
|
|
152
|
+
apiToken: string;
|
|
153
|
+
/** Override for tests. Defaults to the global `fetch`. */
|
|
154
|
+
fetch?: typeof fetch;
|
|
155
|
+
/** API origin. Defaults to `https://api.cloudflare.com`. */
|
|
156
|
+
baseUrl?: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Search through `POST /accounts/{account_id}/ai/websearch`. Use this
|
|
160
|
+
* outside Workers, or to search through a gateway in another account.
|
|
161
|
+
*/
|
|
162
|
+
declare function createHTTPWebSearch(
|
|
163
|
+
options: HTTPWebSearchOptions
|
|
164
|
+
): WebSearchSource;
|
|
165
|
+
/**
|
|
166
|
+
* Error codes a {@link WebSearchError} carries. The `web_search_*` codes the
|
|
167
|
+
* API returns pass through as-is; failures without one get a code from the
|
|
168
|
+
* HTTP status, so every error has a code to branch on.
|
|
169
|
+
*/
|
|
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 & {});
|
|
181
|
+
/** Why a search failed, with what the API said. */
|
|
182
|
+
declare class WebSearchError extends Error {
|
|
183
|
+
readonly name = "WebSearchError";
|
|
184
|
+
readonly status: number;
|
|
185
|
+
readonly code: WebSearchErrorCode;
|
|
186
|
+
/** Whether retrying the same search might succeed. */
|
|
187
|
+
readonly retryable: boolean;
|
|
188
|
+
/** AI Gateway's id for the failed request, for the gateway log. */
|
|
189
|
+
readonly requestId?: string;
|
|
190
|
+
/** The Cloudflare API's numeric error code, when it gave one. */
|
|
191
|
+
readonly apiCode?: number;
|
|
192
|
+
constructor(
|
|
193
|
+
message: string,
|
|
194
|
+
details: {
|
|
195
|
+
status: number;
|
|
196
|
+
code: WebSearchErrorCode;
|
|
197
|
+
retryable?: boolean;
|
|
198
|
+
requestId?: string;
|
|
199
|
+
apiCode?: number;
|
|
200
|
+
cause?: unknown;
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/websearch/tool.d.ts
|
|
206
|
+
/** Search through the Workers AI binding; the tool builds the source. */
|
|
207
|
+
type WebSearchToolBindingOptions = AIWebSearchOptions & {
|
|
208
|
+
source?: never;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Search through a source you built. Gateway, provider, and billing belong
|
|
212
|
+
* to the source, so the binding options are not accepted here.
|
|
213
|
+
*/
|
|
214
|
+
type WebSearchToolSourceOptions = {
|
|
215
|
+
/** Where searches run, instead of the Workers AI binding. */ source: WebSearchSource;
|
|
216
|
+
binding?: never;
|
|
217
|
+
gateway?: never;
|
|
218
|
+
provider?: never;
|
|
219
|
+
byokAlias?: never;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Options every `web_search` tool adapter accepts. Invalid values throw a
|
|
223
|
+
* `RangeError` when the tool is created.
|
|
224
|
+
*/
|
|
225
|
+
type WebSearchToolOptions = (
|
|
226
|
+
| WebSearchToolBindingOptions
|
|
227
|
+
| WebSearchToolSourceOptions
|
|
228
|
+
) & {
|
|
229
|
+
/**
|
|
230
|
+
* Results per search when the model doesn't ask for a count, and the most
|
|
231
|
+
* it gets when it asks for more. An integer from 1 to 10; defaults to 5.
|
|
232
|
+
*/
|
|
233
|
+
limit?: number /** Replaces the default tool description. */;
|
|
234
|
+
description?: string;
|
|
235
|
+
/**
|
|
236
|
+
* Per-result description length in the model's view. A positive integer;
|
|
237
|
+
* defaults to 600 characters. `Infinity` passes descriptions through whole.
|
|
238
|
+
*/
|
|
239
|
+
maxDescriptionChars?: number;
|
|
240
|
+
/**
|
|
241
|
+
* Give up on a search after this many milliseconds, as a retryable
|
|
242
|
+
* `web_search_timeout` failure. A positive integer; defaults to 30 seconds.
|
|
243
|
+
*/
|
|
244
|
+
timeoutMs?: number;
|
|
245
|
+
};
|
|
246
|
+
/** The default for {@link WebSearchToolOptions.timeoutMs}. */
|
|
247
|
+
declare const DEFAULT_WEB_SEARCH_TIMEOUT_MS = 30000;
|
|
248
|
+
//#endregion
|
|
249
|
+
export {
|
|
250
|
+
WebSearchResponse as C,
|
|
251
|
+
renderWebSearchResults as D,
|
|
252
|
+
WebSearchToolOutput as E,
|
|
253
|
+
WEB_SEARCH_TOOL_NAME as S,
|
|
254
|
+
WebSearchToolInput as T,
|
|
255
|
+
DEFAULT_WEB_SEARCH_LIMIT as _,
|
|
256
|
+
AIWebSearchOptions as a,
|
|
257
|
+
RenderWebSearchResultsOptions as b,
|
|
258
|
+
WebSearchError as c,
|
|
259
|
+
WebSearchProvider as d,
|
|
260
|
+
WebSearchRequest as f,
|
|
261
|
+
DEFAULT_WEB_SEARCH_DESCRIPTION_CHARS as g,
|
|
262
|
+
createHTTPWebSearch as h,
|
|
263
|
+
WebSearchToolSourceOptions as i,
|
|
264
|
+
WebSearchErrorCode as l,
|
|
265
|
+
createAIWebSearch as m,
|
|
266
|
+
WebSearchToolBindingOptions as n,
|
|
267
|
+
HTTPWebSearchOptions as o,
|
|
268
|
+
WebSearchSource as p,
|
|
269
|
+
WebSearchToolOptions as r,
|
|
270
|
+
WebSearchCallOptions as s,
|
|
271
|
+
DEFAULT_WEB_SEARCH_TIMEOUT_MS as t,
|
|
272
|
+
WebSearchGatewayOptions as u,
|
|
273
|
+
MAX_WEB_SEARCH_LIMIT as v,
|
|
274
|
+
WebSearchResult as w,
|
|
275
|
+
WEB_SEARCH_TOOL_DESCRIPTION as x,
|
|
276
|
+
MAX_WEB_SEARCH_QUERY_LENGTH as y
|
|
277
|
+
};
|
|
278
|
+
//# sourceMappingURL=tool-BPJEbwaX.d.ts.map
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { a as ResolvedGateway } from "./settings-NgGwF7Qt.js";
|
|
2
|
+
|
|
3
|
+
//#region src/models/core/errors.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Coarse classification of a failed Cloudflare AI call.
|
|
6
|
+
*
|
|
7
|
+
* @experimental This surface is experimental and may change.
|
|
8
|
+
*/
|
|
9
|
+
type CloudflareAIErrorCode =
|
|
10
|
+
| "auth"
|
|
11
|
+
| "rate-limit"
|
|
12
|
+
| "not-found"
|
|
13
|
+
| "bad-request"
|
|
14
|
+
| "provider-error"
|
|
15
|
+
| "gateway-error"
|
|
16
|
+
| "unknown";
|
|
17
|
+
/**
|
|
18
|
+
* One leg of a {@link CloudflareAIError} fallback chain.
|
|
19
|
+
*
|
|
20
|
+
* @experimental This surface is experimental and may change.
|
|
21
|
+
*/
|
|
22
|
+
interface CloudflareAIAttempt {
|
|
23
|
+
/** The model id that was tried. */
|
|
24
|
+
model: string;
|
|
25
|
+
/** The error that leg failed with. */
|
|
26
|
+
error: unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Error thrown for every failed Cloudflare AI call, whether it came back as a
|
|
30
|
+
* non-2xx `Response` or as a thrown Workers AI binding error. Framework
|
|
31
|
+
* modules wrap it into their own error type at their boundary (the AI SDK
|
|
32
|
+
* module into an `APICallError`, so `ai`'s retry loop honours
|
|
33
|
+
* {@link CloudflareAIError.isRetryable}).
|
|
34
|
+
*
|
|
35
|
+
* @experimental This surface is experimental and may change.
|
|
36
|
+
*/
|
|
37
|
+
declare class CloudflareAIError extends Error {
|
|
38
|
+
/** HTTP status, when the failure carried one. */
|
|
39
|
+
readonly status: number | undefined;
|
|
40
|
+
/** Coarse classification used for routing and fallback decisions. */
|
|
41
|
+
readonly code: CloudflareAIErrorCode;
|
|
42
|
+
/** `cf-aig-log-id` of the failed request, when the response carried one. */
|
|
43
|
+
readonly logId: string | undefined;
|
|
44
|
+
/** The model id that produced this error. */
|
|
45
|
+
readonly model: string;
|
|
46
|
+
/** Which binding path the request went down, for error reporting. */
|
|
47
|
+
readonly url: string;
|
|
48
|
+
/** The request body that failed. */
|
|
49
|
+
readonly requestBodyValues: unknown;
|
|
50
|
+
/** Response headers, when there was a response. */
|
|
51
|
+
readonly responseHeaders: Record<string, string> | undefined;
|
|
52
|
+
/** Raw response body text, when there was a response. */
|
|
53
|
+
readonly responseBody: string | undefined;
|
|
54
|
+
/** Whether a retry is worth attempting. */
|
|
55
|
+
readonly isRetryable: boolean;
|
|
56
|
+
/** Parsed error envelope, or other structured detail. */
|
|
57
|
+
readonly data: unknown;
|
|
58
|
+
/** Every leg tried, when this error ends a fallback chain. */
|
|
59
|
+
readonly attempts: CloudflareAIAttempt[] | undefined;
|
|
60
|
+
readonly cause: unknown;
|
|
61
|
+
constructor(options: {
|
|
62
|
+
message: string;
|
|
63
|
+
model: string;
|
|
64
|
+
url: string;
|
|
65
|
+
requestBodyValues: unknown;
|
|
66
|
+
status?: number;
|
|
67
|
+
code: CloudflareAIErrorCode;
|
|
68
|
+
logId?: string;
|
|
69
|
+
responseHeaders?: Record<string, string>;
|
|
70
|
+
responseBody?: string;
|
|
71
|
+
isRetryable?: boolean;
|
|
72
|
+
data?: unknown;
|
|
73
|
+
cause?: unknown;
|
|
74
|
+
attempts?: CloudflareAIAttempt[];
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/models/core/gateway-providers.d.ts
|
|
79
|
+
/**
|
|
80
|
+
* The AI Gateway provider table: which gateway provider slug a vendor's own
|
|
81
|
+
* base URL belongs to, and what the universal request's `endpoint` is for a
|
|
82
|
+
* given upstream URL.
|
|
83
|
+
*
|
|
84
|
+
* This is platform knowledge, not vendor knowledge — the gateway publishes the
|
|
85
|
+
* list, and every entry here appears in `AIGatewayProviders` from
|
|
86
|
+
* `@cloudflare/workers-types`. Nothing about a vendor's wire format, model ids
|
|
87
|
+
* or capabilities lives here: the vendor's own provider package builds the
|
|
88
|
+
* request, and this table only says where it goes.
|
|
89
|
+
*
|
|
90
|
+
* Adapted from `@cloudflare/ai-gateway-provider`'s `providers.ts`.
|
|
91
|
+
*
|
|
92
|
+
* @experimental This surface is experimental and may change.
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* The gateway provider slugs this table maps onto. A subset of the ambient
|
|
96
|
+
* `AIGatewayProviders` union; {@link GatewayProviderNameCheck} keeps it one.
|
|
97
|
+
*
|
|
98
|
+
* @experimental This surface is experimental and may change.
|
|
99
|
+
*/
|
|
100
|
+
declare const GATEWAY_PROVIDER_NAMES: readonly [
|
|
101
|
+
"workers-ai",
|
|
102
|
+
"anthropic",
|
|
103
|
+
"openai",
|
|
104
|
+
"azure-openai",
|
|
105
|
+
"google-ai-studio",
|
|
106
|
+
"google-vertex-ai",
|
|
107
|
+
"grok",
|
|
108
|
+
"mistral",
|
|
109
|
+
"perplexity-ai",
|
|
110
|
+
"replicate",
|
|
111
|
+
"groq",
|
|
112
|
+
"deepseek",
|
|
113
|
+
"openrouter",
|
|
114
|
+
"cerebras",
|
|
115
|
+
"cohere",
|
|
116
|
+
"huggingface",
|
|
117
|
+
"aws-bedrock",
|
|
118
|
+
"elevenlabs",
|
|
119
|
+
"cartesia"
|
|
120
|
+
];
|
|
121
|
+
/**
|
|
122
|
+
* A gateway provider slug.
|
|
123
|
+
*
|
|
124
|
+
* @experimental This surface is experimental and may change.
|
|
125
|
+
*/
|
|
126
|
+
type GatewayProviderName = (typeof GATEWAY_PROVIDER_NAMES)[number];
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/models/core/transport.d.ts
|
|
129
|
+
/** One request on the Cloudflare run path. */
|
|
130
|
+
interface TransportRequest {
|
|
131
|
+
/** Model id — Workers AI slug or catalog `<author>/<model>`. */
|
|
132
|
+
model: string;
|
|
133
|
+
/** The provider-shaped request body (`input` on the run path). */
|
|
134
|
+
input: Record<string, unknown>;
|
|
135
|
+
/** Gateway options for this request. */
|
|
136
|
+
gateway: ResolvedGateway;
|
|
137
|
+
/** Extra request headers, merged last. */
|
|
138
|
+
headers: Record<string, string>;
|
|
139
|
+
/** Abort signal, forwarded to the binding or to `fetch`. */
|
|
140
|
+
signal?: AbortSignal;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* One request on the universal AI Gateway path: a vendor's own request, routed
|
|
144
|
+
* by the gateway to that vendor. The body is the vendor's, untouched — nothing
|
|
145
|
+
* here knows the vendor's wire format.
|
|
146
|
+
*
|
|
147
|
+
* @experimental This surface is experimental and may change.
|
|
148
|
+
*/
|
|
149
|
+
interface UniversalRequest {
|
|
150
|
+
/** The gateway provider slug the request is routed to. */
|
|
151
|
+
provider: GatewayProviderName | string;
|
|
152
|
+
/** The vendor path the gateway appends to that provider's base URL. */
|
|
153
|
+
endpoint: string;
|
|
154
|
+
/** The vendor's own request headers, minus its credential header. */
|
|
155
|
+
headers: Record<string, string>;
|
|
156
|
+
/** The vendor's request body, verbatim. */
|
|
157
|
+
query: unknown;
|
|
158
|
+
/** Gateway options for this request. */
|
|
159
|
+
gateway: ResolvedGateway;
|
|
160
|
+
/** Extra headers merged last, outside the vendor's own set. */
|
|
161
|
+
extraHeaders?: Record<string, string>;
|
|
162
|
+
/** Abort signal, forwarded to the binding or to `fetch`. */
|
|
163
|
+
signal?: AbortSignal;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The single code path both backends implement. Always resolves to a raw
|
|
167
|
+
* `Response`, so streaming and non-streaming calls share one path and nothing
|
|
168
|
+
* is buffered on the caller's behalf.
|
|
169
|
+
*
|
|
170
|
+
* @experimental This surface is experimental and may change.
|
|
171
|
+
*/
|
|
172
|
+
interface Transport {
|
|
173
|
+
/** A stable identifier for the endpoint, used in error reporting. */
|
|
174
|
+
readonly url: string;
|
|
175
|
+
run(request: TransportRequest): Promise<Response>;
|
|
176
|
+
/**
|
|
177
|
+
* Sends a vendor's own request through the gateway's universal endpoint.
|
|
178
|
+
* Always resolves to the vendor's raw `Response`, error responses included:
|
|
179
|
+
* only the gateway's own failures (a missing gateway, an unpaid account) are
|
|
180
|
+
* lifted into a {@link CloudflareAIError}, because the vendor's provider
|
|
181
|
+
* knows how to read its own errors and we do not.
|
|
182
|
+
*/
|
|
183
|
+
universal(request: UniversalRequest): Promise<Response>;
|
|
184
|
+
/**
|
|
185
|
+
* A log id read off the backend itself when the response carried none. The
|
|
186
|
+
* Workers AI binding exposes the last gateway log id as a mutable property,
|
|
187
|
+
* so it is captured per response rather than read late.
|
|
188
|
+
*/
|
|
189
|
+
logIdFallback(response: Response): string | undefined;
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
export {
|
|
193
|
+
CloudflareAIError as a,
|
|
194
|
+
CloudflareAIAttempt as i,
|
|
195
|
+
GATEWAY_PROVIDER_NAMES as n,
|
|
196
|
+
CloudflareAIErrorCode as o,
|
|
197
|
+
GatewayProviderName as r,
|
|
198
|
+
Transport as t
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=transport-k2mFrtL8.d.ts.map
|