agents 0.26.0 → 0.28.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/abortable-C1SpfVoi.js +21 -0
- package/dist/abortable-C1SpfVoi.js.map +1 -0
- package/dist/{agent-routing-0DR0Tk2v.d.ts → agent-routing-QDcchcQP.d.ts} +16 -16
- 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-DHL2XI7u.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/ai-ahruGw7e.d.ts +239 -0
- package/dist/ai-sdk-Bdsf6mSA.js +2444 -0
- package/dist/ai-sdk-Bdsf6mSA.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.d.ts +8 -227
- package/dist/browser/ai.js +259 -1
- package/dist/browser/ai.js.map +1 -0
- package/dist/browser/index.d.ts +56 -46
- package/dist/browser/index.js +4 -361
- package/dist/browser/{ai-sdk.d.ts → tools/ai-sdk.d.ts} +7 -7
- package/dist/browser/{ai-sdk.js → tools/ai-sdk.js} +6 -5
- package/dist/browser/tools/ai-sdk.js.map +1 -0
- package/dist/browser/tools/pi.d.ts +111 -0
- package/dist/browser/tools/pi.js +119 -0
- package/dist/browser/tools/pi.js.map +1 -0
- package/dist/browser/{tanstack-ai.d.ts → tools/tanstack-ai.d.ts} +39 -37
- package/dist/browser/{tanstack-ai.js → tools/tanstack-ai.js} +73 -59
- package/dist/browser/tools/tanstack-ai.js.map +1 -0
- package/dist/browser-CEdNlsaD.js +481 -0
- package/dist/browser-CEdNlsaD.js.map +1 -0
- package/dist/{browser-DE3d-RLk.d.ts → browser-D30VlpcA.d.ts} +63 -37
- package/dist/{browser-tool-CQ10e6Kj.js → browser-tool-4iomavs_.js} +198 -62
- package/dist/browser-tool-4iomavs_.js.map +1 -0
- package/dist/{browser-tool-DuNdlwZ9.d.ts → browser-tool-vtrPOV8e.d.ts} +25 -6
- package/dist/{capability-B4WbF81e.js → capability-DBAKc6UZ.js} +1 -3
- package/dist/capability-DBAKc6UZ.js.map +1 -0
- package/dist/{capability-runner-DBAnGr6L.d.ts → capability-runner-BiVUtjqC.d.ts} +9 -7
- 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-je3koD9Z.d.ts → client-BGIQKJhX.d.ts} +2 -2
- package/dist/{client-fyQrLGkD.js → client-BnYbNT3z.js} +29 -5
- package/dist/client-BnYbNT3z.js.map +1 -0
- package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
- package/dist/client.d.ts +1 -1
- package/dist/{connector-58XDGvc3.js → connector-CtZylXdk.js} +3 -603
- package/dist/connector-CtZylXdk.js.map +1 -0
- package/dist/{connector-Cl-VqPmA.d.ts → connector-DEXzVoaY.d.ts} +9 -374
- package/dist/conversations-FjHDRZyD.d.ts +192 -0
- package/dist/{current-agent-vAk_5JMt.d.ts → current-agent-CKgT5d1O.d.ts} +3 -5
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- 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-DOI_bzCH.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-BFO6vRDn.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 +3 -2
- package/dist/harness/pi/index.js +3 -3
- 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 +2721 -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-BEL3ZV-s.d.ts} +2 -6
- package/dist/index-CBt8oRJt.d.ts +198 -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-BQykTEp_.js +20 -0
- package/dist/input-schema-BQykTEp_.js.map +1 -0
- package/dist/input-schema-D2QAtHZH.js +23 -0
- package/dist/input-schema-D2QAtHZH.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/lifecycle/index.js +2 -2
- package/dist/{lifecycle-CFu6OV03.js → lifecycle-DGorpAmA.js} +2 -4
- package/dist/lifecycle-DGorpAmA.js.map +1 -0
- 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-CiIsJHXR.d.ts +130 -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/queue/index.js +1 -1
- package/dist/{queue-BB-zfIYF.js → queue-CcIjVYTE.js} +2 -2
- package/dist/{queue-BB-zfIYF.js.map → queue-CcIjVYTE.js.map} +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/routing/index.js +1 -1
- package/dist/{scheduler-RdACNXDP.d.ts → scheduler-BCLESHSC.d.ts} +2 -12
- package/dist/{scheduler-DZ3xQfeK.js → scheduler-FIHv2-kJ.js} +2 -4
- package/dist/scheduler-FIHv2-kJ.js.map +1 -0
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/session-store-Do4xkDcf.js +606 -0
- package/dist/session-store-Do4xkDcf.js.map +1 -0
- package/dist/session-store-DoPY12xM.d.ts +383 -0
- package/dist/sessions/index.d.ts +11 -434
- package/dist/sessions/index.js +1 -2271
- package/dist/sessions-_vN5BEZX.js +2272 -0
- package/dist/sessions-_vN5BEZX.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-CQxJFv4l.js} +8 -8
- package/dist/src-CQxJFv4l.js.map +1 -0
- 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/state/index.js +1 -3
- package/dist/state/index.js.map +1 -1
- package/dist/store-BKM4Xm9M.d.ts +332 -0
- package/dist/store-CslVzfN7.js +458 -0
- package/dist/store-CslVzfN7.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-lsHMJhRW.js} +17 -4
- package/dist/streams-lsHMJhRW.js.map +1 -0
- package/dist/{streams-Cmkj9QfW.d.ts → streams-vrCtbUIn.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-BN_5AWqI.js} +3 -2
- package/dist/tasks-BN_5AWqI.js.map +1 -0
- package/dist/{tasks-9YxYtByh.d.ts → tasks-E89KdwkS.d.ts} +2 -2
- package/dist/tool-CTp72Jb_.d.ts +278 -0
- package/dist/tool-CxKsvxjm.js +1126 -0
- package/dist/tool-CxKsvxjm.js.map +1 -0
- package/dist/tool-DoVberpN.d.ts +301 -0
- package/dist/tool-cQRkwSZZ.js +410 -0
- package/dist/tool-cQRkwSZZ.js.map +1 -0
- package/dist/tool-helpers-O5BDVEAY.js +58 -0
- package/dist/tool-helpers-O5BDVEAY.js.map +1 -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/web/fetch/index.d.ts +89 -0
- package/dist/web/fetch/index.js +20 -0
- package/dist/web/fetch/index.js.map +1 -0
- package/dist/web/fetch/tools/ai-sdk.d.ts +80 -0
- package/dist/web/fetch/tools/ai-sdk.js +47 -0
- package/dist/web/fetch/tools/ai-sdk.js.map +1 -0
- package/dist/web/fetch/tools/pi.d.ts +84 -0
- package/dist/web/fetch/tools/pi.js +88 -0
- package/dist/web/fetch/tools/pi.js.map +1 -0
- package/dist/web/fetch/tools/tanstack-ai.d.ts +78 -0
- package/dist/web/fetch/tools/tanstack-ai.js +45 -0
- package/dist/web/fetch/tools/tanstack-ai.js.map +1 -0
- package/dist/web/search/index.d.ts +58 -0
- package/dist/web/search/index.js +2 -0
- package/dist/web/search/tools/ai-sdk.d.ts +77 -0
- package/dist/web/search/tools/ai-sdk.js +46 -0
- package/dist/web/search/tools/ai-sdk.js.map +1 -0
- package/dist/web/search/tools/pi.d.ts +82 -0
- package/dist/web/search/tools/pi.js +89 -0
- package/dist/web/search/tools/pi.js.map +1 -0
- package/dist/web/search/tools/tanstack-ai.d.ts +71 -0
- package/dist/web/search/tools/tanstack-ai.js +46 -0
- package/dist/web/search/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-C3zy8YR0.js} +20 -8
- package/dist/websockets-C3zy8YR0.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 +29 -1
- package/docs/fetch-the-web.md +276 -0
- package/docs/harnesses/pi.md +25 -0
- package/docs/harnesses/think.md +215 -0
- package/docs/index.md +99 -75
- package/docs/lifecycle.md +42 -3
- package/docs/queue.md +2 -3
- package/docs/scheduling.md +2 -6
- package/docs/search-the-web.md +135 -0
- package/package.json +148 -44
- package/dist/ai-fm7xx1BK.js +0 -312
- package/dist/ai-fm7xx1BK.js.map +0 -1
- package/dist/browser/ai-sdk.js.map +0 -1
- package/dist/browser/index.js.map +0 -1
- package/dist/browser/tanstack-ai.js.map +0 -1
- package/dist/browser-tool-CQ10e6Kj.js.map +0 -1
- package/dist/capability-B4WbF81e.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/client-fyQrLGkD.js.map +0 -1
- package/dist/connector-58XDGvc3.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/lifecycle-CFu6OV03.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/scheduler-DZ3xQfeK.js.map +0 -1
- package/dist/sessions/index.js.map +0 -1
- package/dist/src-BZeu-SCD.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,20 @@
|
|
|
1
|
+
import { a as WebFetchError, c as DEFAULT_WEB_FETCH_MAX_REDIRECTS, d as MAX_WEB_FETCH_URL_LENGTH, f as WEB_FETCH_TOOL_DESCRIPTION, g as isPrivateOrLocalHost, h as windowWebFetchPage, i as validateTimeout, l as DEFAULT_WEB_FETCH_PAGE_CHARS, m as renderWebFetchPage, n as fetchWithDeadline, o as createDirectWebFetch, p as WEB_FETCH_TOOL_NAME, s as DEFAULT_WEB_FETCH_MAX_BYTES, u as DEFAULT_WEB_FETCH_TIMEOUT_MS } from "../../tool-CxKsvxjm.js";
|
|
2
|
+
//#region src/web/fetch/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Fetch one URL directly, without a tool: {@link createDirectWebFetch} plus
|
|
5
|
+
* a deadline. Returns the whole page; to show it to a model a window at a
|
|
6
|
+
* time, as the tool does, pass it to {@link windowWebFetchPage} and
|
|
7
|
+
* {@link renderWebFetchPage}.
|
|
8
|
+
*/
|
|
9
|
+
async function fetchWeb(request, options) {
|
|
10
|
+
const { timeoutMs, signal, ...sourceOptions } = options;
|
|
11
|
+
const deadline = validateTimeout(timeoutMs);
|
|
12
|
+
return fetchWithDeadline(createDirectWebFetch(sourceOptions), request, {
|
|
13
|
+
timeoutMs: deadline,
|
|
14
|
+
signal
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { DEFAULT_WEB_FETCH_MAX_BYTES, DEFAULT_WEB_FETCH_MAX_REDIRECTS, DEFAULT_WEB_FETCH_PAGE_CHARS, DEFAULT_WEB_FETCH_TIMEOUT_MS, MAX_WEB_FETCH_URL_LENGTH, WEB_FETCH_TOOL_DESCRIPTION, WEB_FETCH_TOOL_NAME, WebFetchError, createDirectWebFetch, fetchWeb, isPrivateOrLocalHost, renderWebFetchPage, windowWebFetchPage };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/web/fetch/index.ts"],"sourcesContent":["/**\n * `agents/webfetch` — read a URL as Markdown, JSON, or text, with\n * host-controlled URL policy and size limits, from a Worker.\n *\n * The tool adapters live beside this entry: `agents/webfetch/pi`,\n * `agents/webfetch/ai-sdk`, and `agents/webfetch/tanstack-ai`. Import from\n * here to fetch without a model in the loop, or to build a source for the\n * tools.\n *\n * @beta\n */\nimport type { WebFetchPage } from \"./contract\";\nimport {\n createDirectWebFetch,\n type DirectWebFetchOptions,\n type WebFetchRequest\n} from \"./source\";\nimport { fetchWithDeadline, validateTimeout } from \"./tool\";\n\nexport {\n DEFAULT_WEB_FETCH_MAX_BYTES,\n DEFAULT_WEB_FETCH_MAX_REDIRECTS,\n DEFAULT_WEB_FETCH_PAGE_CHARS,\n DEFAULT_WEB_FETCH_TIMEOUT_MS,\n MAX_WEB_FETCH_URL_LENGTH,\n WEB_FETCH_TOOL_DESCRIPTION,\n WEB_FETCH_TOOL_NAME,\n renderWebFetchPage,\n windowWebFetchPage,\n type WebFetchFormat,\n type WebFetchPage,\n type WebFetchToolInput,\n type WebFetchToolOutput,\n type WebFetchVia,\n type WindowWebFetchPageOptions\n} from \"./contract\";\nexport {\n WebFetchError,\n createDirectWebFetch,\n type DirectWebFetchOptions,\n type WebFetchCallOptions,\n type WebFetchErrorCode,\n type WebFetchRequest,\n type WebFetchSource\n} from \"./source\";\nexport { isPrivateOrLocalHost } from \"../url-policy\";\nexport {\n type WebFetchToolDirectOptions,\n type WebFetchToolOptions,\n type WebFetchToolSourceOptions\n} from \"./tool\";\n\n/** Options for {@link fetchWeb}: the direct source's, plus a deadline. */\nexport interface FetchWebOptions extends DirectWebFetchOptions {\n /**\n * Give up after this many milliseconds with a `web_fetch_timeout` error.\n * A positive integer; defaults to 30 seconds.\n */\n timeoutMs?: number;\n /** Abort the fetch; rejects with the signal's reason. */\n signal?: AbortSignal;\n}\n\n/**\n * Fetch one URL directly, without a tool: {@link createDirectWebFetch} plus\n * a deadline. Returns the whole page; to show it to a model a window at a\n * time, as the tool does, pass it to {@link windowWebFetchPage} and\n * {@link renderWebFetchPage}.\n */\nexport async function fetchWeb(\n request: WebFetchRequest,\n options: FetchWebOptions\n): Promise<WebFetchPage> {\n const { timeoutMs, signal, ...sourceOptions } = options;\n const deadline = validateTimeout(timeoutMs);\n const source = createDirectWebFetch(sourceOptions);\n return fetchWithDeadline(source, request, { timeoutMs: deadline, signal });\n}\n"],"mappings":";;;;;;;;AAqEA,eAAsB,SACpB,SACA,SACuB;CACvB,MAAM,EAAE,WAAW,QAAQ,GAAG,kBAAkB;CAChD,MAAM,WAAW,gBAAgB,SAAS;CAE1C,OAAO,kBADQ,qBAAqB,aACN,GAAG,SAAS;EAAE,WAAW;EAAU;CAAO,CAAC;AAC3E"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
S as WebFetchVia,
|
|
3
|
+
b as WebFetchToolInput,
|
|
4
|
+
c as WebFetchRequest,
|
|
5
|
+
l as WebFetchSource,
|
|
6
|
+
n as WebFetchToolOptions,
|
|
7
|
+
o as WebFetchError,
|
|
8
|
+
s as WebFetchErrorCode,
|
|
9
|
+
v as WebFetchFormat,
|
|
10
|
+
x as WebFetchToolOutput,
|
|
11
|
+
y as WebFetchPage
|
|
12
|
+
} from "../../../tool-DoVberpN.js";
|
|
13
|
+
import { FlexibleSchema } from "ai";
|
|
14
|
+
|
|
15
|
+
//#region src/web/fetch/tools/ai-sdk.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* The part of the AI SDK's tool execution options the tool reads. Spelled
|
|
18
|
+
* out rather than imported so it fits every supported `ai` major.
|
|
19
|
+
*/
|
|
20
|
+
interface WebFetchToolExecuteOptions {
|
|
21
|
+
abortSignal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The AI SDK tool {@link webFetchTool} returns. Assignable to the AI SDK's
|
|
25
|
+
* `Tool`; `execute` and `toModelOutput` are always present.
|
|
26
|
+
*/
|
|
27
|
+
interface WebFetchTool {
|
|
28
|
+
description: string;
|
|
29
|
+
inputSchema: FlexibleSchema<WebFetchToolInput>;
|
|
30
|
+
execute(
|
|
31
|
+
input: WebFetchToolInput,
|
|
32
|
+
options: WebFetchToolExecuteOptions
|
|
33
|
+
): Promise<WebFetchToolOutput>;
|
|
34
|
+
toModelOutput(options: { output: WebFetchToolOutput }): {
|
|
35
|
+
type: "text";
|
|
36
|
+
value: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create an AI SDK tool that reads a URL as Markdown, JSON, or text. The
|
|
41
|
+
* tool's output is the window the model read plus the page's metadata
|
|
42
|
+
* (status, headers, redirects, total length), so it stays small in stored
|
|
43
|
+
* messages; `toModelOutput` renders it for the model. A failed fetch throws a `WebFetchError`, which
|
|
44
|
+
* the AI SDK reports to the model as a tool error: its `message` is written
|
|
45
|
+
* for the model, and its `cause` is the source's error with the detail.
|
|
46
|
+
*
|
|
47
|
+
* `toModelOutput` only applies to earlier turns when the tools are passed to
|
|
48
|
+
* `convertToModelMessages(messages, { tools })`; otherwise the AI SDK sends
|
|
49
|
+
* the output back to the model as JSON, without the header or the
|
|
50
|
+
* untrusted-content wrapper. `AiSdkHarness` passes them.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { webFetchTool } from "agents/webfetch/ai-sdk";
|
|
55
|
+
*
|
|
56
|
+
* const result = streamText({
|
|
57
|
+
* model,
|
|
58
|
+
* tools: { web_fetch: webFetchTool({ binding: env.AI }) },
|
|
59
|
+
* messages
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function webFetchTool(options: WebFetchToolOptions): WebFetchTool;
|
|
64
|
+
//#endregion
|
|
65
|
+
export {
|
|
66
|
+
WebFetchError,
|
|
67
|
+
type WebFetchErrorCode,
|
|
68
|
+
type WebFetchFormat,
|
|
69
|
+
type WebFetchPage,
|
|
70
|
+
type WebFetchRequest,
|
|
71
|
+
type WebFetchSource,
|
|
72
|
+
WebFetchTool,
|
|
73
|
+
WebFetchToolExecuteOptions,
|
|
74
|
+
type WebFetchToolInput,
|
|
75
|
+
type WebFetchToolOptions,
|
|
76
|
+
type WebFetchToolOutput,
|
|
77
|
+
type WebFetchVia,
|
|
78
|
+
webFetchTool
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=ai-sdk.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { a as WebFetchError, r as toolFailure, t as createWebFetchToolCore } from "../../../tool-CxKsvxjm.js";
|
|
2
|
+
import { t as webFetchInputSchema } from "../../../input-schema-BQykTEp_.js";
|
|
3
|
+
//#region src/web/fetch/tools/ai-sdk.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create an AI SDK tool that reads a URL as Markdown, JSON, or text. The
|
|
6
|
+
* tool's output is the window the model read plus the page's metadata
|
|
7
|
+
* (status, headers, redirects, total length), so it stays small in stored
|
|
8
|
+
* messages; `toModelOutput` renders it for the model. A failed fetch throws a `WebFetchError`, which
|
|
9
|
+
* the AI SDK reports to the model as a tool error: its `message` is written
|
|
10
|
+
* for the model, and its `cause` is the source's error with the detail.
|
|
11
|
+
*
|
|
12
|
+
* `toModelOutput` only applies to earlier turns when the tools are passed to
|
|
13
|
+
* `convertToModelMessages(messages, { tools })`; otherwise the AI SDK sends
|
|
14
|
+
* the output back to the model as JSON, without the header or the
|
|
15
|
+
* untrusted-content wrapper. `AiSdkHarness` passes them.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { webFetchTool } from "agents/webfetch/ai-sdk";
|
|
20
|
+
*
|
|
21
|
+
* const result = streamText({
|
|
22
|
+
* model,
|
|
23
|
+
* tools: { web_fetch: webFetchTool({ binding: env.AI }) },
|
|
24
|
+
* messages
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function webFetchTool(options) {
|
|
29
|
+
const core = createWebFetchToolCore(options);
|
|
30
|
+
return {
|
|
31
|
+
description: core.description,
|
|
32
|
+
inputSchema: webFetchInputSchema(),
|
|
33
|
+
async execute(input, { abortSignal }) {
|
|
34
|
+
const run = await core.run(input, { signal: abortSignal });
|
|
35
|
+
if (!run.ok) throw toolFailure(run);
|
|
36
|
+
return run.output;
|
|
37
|
+
},
|
|
38
|
+
toModelOutput: ({ output }) => ({
|
|
39
|
+
type: "text",
|
|
40
|
+
value: core.render(output)
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { WebFetchError, webFetchTool };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=ai-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk.js","names":[],"sources":["../../../../src/web/fetch/tools/ai-sdk.ts"],"sourcesContent":["/**\n * `agents/webfetch/ai-sdk` — the `web_fetch` tool for the AI SDK.\n *\n * @beta\n */\nimport type { FlexibleSchema } from \"ai\";\nimport type { WebFetchToolInput, WebFetchToolOutput } from \"../contract\";\nimport {\n createWebFetchToolCore,\n toolFailure,\n type WebFetchToolOptions\n} from \"../tool\";\nimport { webFetchInputSchema } from \"./input-schema\";\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/**\n * The part of the AI SDK's tool execution options the tool reads. Spelled\n * out rather than imported so it fits every supported `ai` major.\n */\nexport interface WebFetchToolExecuteOptions {\n abortSignal?: AbortSignal;\n}\n\n/**\n * The AI SDK tool {@link webFetchTool} returns. Assignable to the AI SDK's\n * `Tool`; `execute` and `toModelOutput` are always present.\n */\nexport interface WebFetchTool {\n description: string;\n inputSchema: FlexibleSchema<WebFetchToolInput>;\n execute(\n input: WebFetchToolInput,\n options: WebFetchToolExecuteOptions\n ): Promise<WebFetchToolOutput>;\n toModelOutput(options: { output: WebFetchToolOutput }): {\n type: \"text\";\n value: string;\n };\n}\n\n/**\n * Create an AI SDK tool that reads a URL as Markdown, JSON, or text. The\n * tool's output is the window the model read plus the page's metadata\n * (status, headers, redirects, total length), so it stays small in stored\n * messages; `toModelOutput` renders it for the model. A failed fetch throws a `WebFetchError`, which\n * the AI SDK reports to the model as a tool error: its `message` is written\n * for the model, and its `cause` is the source's error with the detail.\n *\n * `toModelOutput` only applies to earlier turns when the tools are passed to\n * `convertToModelMessages(messages, { tools })`; otherwise the AI SDK sends\n * the output back to the model as JSON, without the header or the\n * untrusted-content wrapper. `AiSdkHarness` passes them.\n *\n * @example\n * ```ts\n * import { webFetchTool } from \"agents/webfetch/ai-sdk\";\n *\n * const result = streamText({\n * model,\n * tools: { web_fetch: webFetchTool({ binding: env.AI }) },\n * messages\n * });\n * ```\n */\nexport function webFetchTool(options: WebFetchToolOptions): WebFetchTool {\n const core = createWebFetchToolCore(options);\n return {\n description: core.description,\n inputSchema: webFetchInputSchema(),\n async execute(input, { abortSignal }) {\n const run = await core.run(input, { signal: abortSignal });\n if (!run.ok) throw toolFailure(run);\n return run.output;\n },\n toModelOutput: ({ output }) => ({\n type: \"text\",\n value: core.render(output)\n })\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,SAAgB,aAAa,SAA4C;CACvE,MAAM,OAAO,uBAAuB,OAAO;CAC3C,OAAO;EACL,aAAa,KAAK;EAClB,aAAa,oBAAoB;EACjC,MAAM,QAAQ,OAAO,EAAE,eAAe;GACpC,MAAM,MAAM,MAAM,KAAK,IAAI,OAAO,EAAE,QAAQ,YAAY,CAAC;GACzD,IAAI,CAAC,IAAI,IAAI,MAAM,YAAY,GAAG;GAClC,OAAO,IAAI;EACb;EACA,gBAAgB,EAAE,cAAc;GAC9B,MAAM;GACN,OAAO,KAAK,OAAO,MAAM;EAC3B;CACF;AACF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
S as WebFetchVia,
|
|
3
|
+
b as WebFetchToolInput,
|
|
4
|
+
c as WebFetchRequest,
|
|
5
|
+
l as WebFetchSource,
|
|
6
|
+
n as WebFetchToolOptions,
|
|
7
|
+
o as WebFetchError,
|
|
8
|
+
s as WebFetchErrorCode,
|
|
9
|
+
v as WebFetchFormat,
|
|
10
|
+
x as WebFetchToolOutput,
|
|
11
|
+
y as WebFetchPage
|
|
12
|
+
} from "../../../tool-DoVberpN.js";
|
|
13
|
+
import { Type } from "@earendil-works/pi-ai";
|
|
14
|
+
import { ToolRegistration } from "@earendil-works/pi-durable";
|
|
15
|
+
|
|
16
|
+
//#region src/web/fetch/tools/pi.d.ts
|
|
17
|
+
/** The model's input schema. pi already coerces `"20000"` to `20000`. */
|
|
18
|
+
declare function webFetchParameters(): Type.TObject<{
|
|
19
|
+
url: Type.TString;
|
|
20
|
+
offset: Type.TOptional<Type.TInteger>;
|
|
21
|
+
format: Type.TOptional<
|
|
22
|
+
Type.TUnion<[Type.TLiteral<"auto">, Type.TLiteral<"raw">]>
|
|
23
|
+
>;
|
|
24
|
+
}>;
|
|
25
|
+
type WebFetchParameters = ReturnType<typeof webFetchParameters>;
|
|
26
|
+
/**
|
|
27
|
+
* Host-side details pi stores with each `web_fetch` result: the output (the
|
|
28
|
+
* window the model read, with the page's metadata) or the failure.
|
|
29
|
+
*/
|
|
30
|
+
type WebFetchToolDetails =
|
|
31
|
+
| {
|
|
32
|
+
ok: true;
|
|
33
|
+
output: WebFetchToolOutput;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
ok: false /** The source's error message, with the detail for the host. */;
|
|
37
|
+
message: string;
|
|
38
|
+
status: number;
|
|
39
|
+
code: WebFetchErrorCode;
|
|
40
|
+
retryable: boolean;
|
|
41
|
+
url?: string /** The response's media type, when a response was read. */;
|
|
42
|
+
contentType?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Create a pi tool that reads a URL as Markdown, JSON, or text. Install it
|
|
46
|
+
* on a registry like any other pi tool.
|
|
47
|
+
*
|
|
48
|
+
* The model chooses the URL, the window (`offset`), and the format; the
|
|
49
|
+
* host chooses the URL policy, size limits, and window size. The tool is
|
|
50
|
+
* `replay: "safe"`: a fetch interrupted mid-call (say, by an eviction) runs
|
|
51
|
+
* again when the session recovers. Completed results are stored and not
|
|
52
|
+
* fetched again.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { createRegistry } from "@earendil-works/pi-durable";
|
|
57
|
+
* import { webFetchTool } from "agents/webfetch/pi";
|
|
58
|
+
*
|
|
59
|
+
* const registry = createRegistry();
|
|
60
|
+
* registry.install({
|
|
61
|
+
* name: "tools",
|
|
62
|
+
* tools: [webFetchTool({ binding: env.AI })]
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function webFetchTool(
|
|
67
|
+
options: WebFetchToolOptions
|
|
68
|
+
): ToolRegistration<WebFetchParameters, WebFetchToolDetails>;
|
|
69
|
+
//#endregion
|
|
70
|
+
export {
|
|
71
|
+
WebFetchError,
|
|
72
|
+
type WebFetchErrorCode,
|
|
73
|
+
type WebFetchFormat,
|
|
74
|
+
type WebFetchPage,
|
|
75
|
+
type WebFetchRequest,
|
|
76
|
+
type WebFetchSource,
|
|
77
|
+
WebFetchToolDetails,
|
|
78
|
+
type WebFetchToolInput,
|
|
79
|
+
type WebFetchToolOptions,
|
|
80
|
+
type WebFetchToolOutput,
|
|
81
|
+
type WebFetchVia,
|
|
82
|
+
webFetchTool
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=pi.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { a as WebFetchError, d as MAX_WEB_FETCH_URL_LENGTH, t as createWebFetchToolCore } from "../../../tool-CxKsvxjm.js";
|
|
2
|
+
import { Type } from "@earendil-works/pi-ai";
|
|
3
|
+
//#region src/web/fetch/tools/pi.ts
|
|
4
|
+
/**
|
|
5
|
+
* `agents/webfetch/pi` — the `web_fetch` tool for the pi harness.
|
|
6
|
+
*
|
|
7
|
+
* @beta
|
|
8
|
+
*/
|
|
9
|
+
/** The model's input schema. pi already coerces `"20000"` to `20000`. */
|
|
10
|
+
function webFetchParameters() {
|
|
11
|
+
return Type.Object({
|
|
12
|
+
url: Type.String({
|
|
13
|
+
minLength: 1,
|
|
14
|
+
maxLength: MAX_WEB_FETCH_URL_LENGTH,
|
|
15
|
+
description: "The http(s) URL to read."
|
|
16
|
+
}),
|
|
17
|
+
offset: Type.Optional(Type.Integer({
|
|
18
|
+
minimum: 0,
|
|
19
|
+
description: "Character offset into the content, to continue a long page from the previous result's offset. Default 0."
|
|
20
|
+
})),
|
|
21
|
+
format: Type.Optional(Type.Union([Type.Literal("auto"), Type.Literal("raw")], { description: "\"auto\" (default) converts to the most readable form; \"raw\" returns the body as served." }))
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a pi tool that reads a URL as Markdown, JSON, or text. Install it
|
|
26
|
+
* on a registry like any other pi tool.
|
|
27
|
+
*
|
|
28
|
+
* The model chooses the URL, the window (`offset`), and the format; the
|
|
29
|
+
* host chooses the URL policy, size limits, and window size. The tool is
|
|
30
|
+
* `replay: "safe"`: a fetch interrupted mid-call (say, by an eviction) runs
|
|
31
|
+
* again when the session recovers. Completed results are stored and not
|
|
32
|
+
* fetched again.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { createRegistry } from "@earendil-works/pi-durable";
|
|
37
|
+
* import { webFetchTool } from "agents/webfetch/pi";
|
|
38
|
+
*
|
|
39
|
+
* const registry = createRegistry();
|
|
40
|
+
* registry.install({
|
|
41
|
+
* name: "tools",
|
|
42
|
+
* tools: [webFetchTool({ binding: env.AI })]
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function webFetchTool(options) {
|
|
47
|
+
const core = createWebFetchToolCore(options);
|
|
48
|
+
return {
|
|
49
|
+
name: core.name,
|
|
50
|
+
description: core.description,
|
|
51
|
+
parameters: webFetchParameters(),
|
|
52
|
+
replay: "safe",
|
|
53
|
+
async execute(input, _api, context) {
|
|
54
|
+
const run = await core.run(input, { signal: context.abortSignal });
|
|
55
|
+
if (run.ok) return {
|
|
56
|
+
content: [{
|
|
57
|
+
type: "text",
|
|
58
|
+
text: run.text
|
|
59
|
+
}],
|
|
60
|
+
details: {
|
|
61
|
+
ok: true,
|
|
62
|
+
output: run.output
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const details = {
|
|
66
|
+
ok: false,
|
|
67
|
+
message: run.error.message,
|
|
68
|
+
status: run.error.status,
|
|
69
|
+
code: run.error.code,
|
|
70
|
+
retryable: run.error.retryable
|
|
71
|
+
};
|
|
72
|
+
if (run.error.url !== void 0) details.url = run.error.url;
|
|
73
|
+
if (run.error.contentType !== void 0) details.contentType = run.error.contentType;
|
|
74
|
+
return {
|
|
75
|
+
content: [{
|
|
76
|
+
type: "text",
|
|
77
|
+
text: run.text
|
|
78
|
+
}],
|
|
79
|
+
isError: true,
|
|
80
|
+
details
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
export { WebFetchError, webFetchTool };
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=pi.js.map
|
|
@@ -0,0 +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 content: [{ 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 content: [{ 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,SAAS,CAAC;KAAE,MAAM;KAAQ,MAAM,IAAI;IAAK,CAAC;IAC1C,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,SAAS,CAAC;KAAE,MAAM;KAAQ,MAAM,IAAI;IAAK,CAAC;IAC1C,SAAS;IACT;GACF;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
S as WebFetchVia,
|
|
3
|
+
_ as WEB_FETCH_TOOL_NAME,
|
|
4
|
+
b as WebFetchToolInput,
|
|
5
|
+
c as WebFetchRequest,
|
|
6
|
+
l as WebFetchSource,
|
|
7
|
+
n as WebFetchToolOptions,
|
|
8
|
+
o as WebFetchError,
|
|
9
|
+
s as WebFetchErrorCode,
|
|
10
|
+
v as WebFetchFormat,
|
|
11
|
+
x as WebFetchToolOutput,
|
|
12
|
+
y as WebFetchPage
|
|
13
|
+
} from "../../../tool-DoVberpN.js";
|
|
14
|
+
|
|
15
|
+
//#region src/web/fetch/tools/tanstack-ai.d.ts
|
|
16
|
+
type TanStackWebFetchToolOptions<
|
|
17
|
+
TName extends string = typeof WEB_FETCH_TOOL_NAME
|
|
18
|
+
> = WebFetchToolOptions & {
|
|
19
|
+
/** The tool's name. TanStack AI tools carry it in the definition. */ name?: TName;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Create a TanStack AI tool that reads a URL as Markdown, JSON, or text.
|
|
23
|
+
* TanStack AI has one return channel, so the model and the host both get
|
|
24
|
+
* the rendered window. A failed fetch throws a `WebFetchError`, which
|
|
25
|
+
* TanStack AI reports as an error result: its `message` is written for the
|
|
26
|
+
* model, and its `cause` is the source's error with the detail. The tool is
|
|
27
|
+
* named `web_fetch` unless you pass `name`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { webFetchTool } from "agents/webfetch/tanstack-ai";
|
|
32
|
+
* import { chat } from "@tanstack/ai";
|
|
33
|
+
*
|
|
34
|
+
* const stream = chat({
|
|
35
|
+
* adapter,
|
|
36
|
+
* tools: [webFetchTool({ binding: env.AI })],
|
|
37
|
+
* messages
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function webFetchTool<
|
|
42
|
+
TName extends string = typeof WEB_FETCH_TOOL_NAME
|
|
43
|
+
>(
|
|
44
|
+
options: TanStackWebFetchToolOptions<TName>
|
|
45
|
+
): import("@tanstack/ai").ServerTool<
|
|
46
|
+
import("zod").ZodObject<
|
|
47
|
+
{
|
|
48
|
+
url: import("zod").ZodString;
|
|
49
|
+
offset: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
50
|
+
format: import("zod").ZodOptional<
|
|
51
|
+
import("zod").ZodEnum<{
|
|
52
|
+
auto: "auto";
|
|
53
|
+
raw: "raw";
|
|
54
|
+
}>
|
|
55
|
+
>;
|
|
56
|
+
},
|
|
57
|
+
import("zod/v4/core").$strip
|
|
58
|
+
>,
|
|
59
|
+
import("@tanstack/ai").SchemaInput,
|
|
60
|
+
TName,
|
|
61
|
+
unknown
|
|
62
|
+
>;
|
|
63
|
+
//#endregion
|
|
64
|
+
export {
|
|
65
|
+
TanStackWebFetchToolOptions,
|
|
66
|
+
WebFetchError,
|
|
67
|
+
type WebFetchErrorCode,
|
|
68
|
+
type WebFetchFormat,
|
|
69
|
+
type WebFetchPage,
|
|
70
|
+
type WebFetchRequest,
|
|
71
|
+
type WebFetchSource,
|
|
72
|
+
type WebFetchToolInput,
|
|
73
|
+
type WebFetchToolOptions,
|
|
74
|
+
type WebFetchToolOutput,
|
|
75
|
+
type WebFetchVia,
|
|
76
|
+
webFetchTool
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=tanstack-ai.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { a as WebFetchError, r as toolFailure, t as createWebFetchToolCore } from "../../../tool-CxKsvxjm.js";
|
|
2
|
+
import { t as webFetchInputSchema } from "../../../input-schema-BQykTEp_.js";
|
|
3
|
+
import { toolDefinition } from "@tanstack/ai";
|
|
4
|
+
//#region src/web/fetch/tools/tanstack-ai.ts
|
|
5
|
+
/**
|
|
6
|
+
* `agents/webfetch/tanstack-ai` — the `web_fetch` tool for TanStack AI.
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Create a TanStack AI tool that reads a URL as Markdown, JSON, or text.
|
|
12
|
+
* TanStack AI has one return channel, so the model and the host both get
|
|
13
|
+
* the rendered window. A failed fetch throws a `WebFetchError`, which
|
|
14
|
+
* TanStack AI reports as an error result: its `message` is written for the
|
|
15
|
+
* model, and its `cause` is the source's error with the detail. The tool is
|
|
16
|
+
* named `web_fetch` unless you pass `name`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { webFetchTool } from "agents/webfetch/tanstack-ai";
|
|
21
|
+
* import { chat } from "@tanstack/ai";
|
|
22
|
+
*
|
|
23
|
+
* const stream = chat({
|
|
24
|
+
* adapter,
|
|
25
|
+
* tools: [webFetchTool({ binding: env.AI })],
|
|
26
|
+
* messages
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function webFetchTool(options) {
|
|
31
|
+
const core = createWebFetchToolCore(options);
|
|
32
|
+
return toolDefinition({
|
|
33
|
+
name: options.name ?? core.name,
|
|
34
|
+
description: core.description,
|
|
35
|
+
inputSchema: webFetchInputSchema()
|
|
36
|
+
}).server(async (input, context) => {
|
|
37
|
+
const run = await core.run(input, { signal: context?.abortSignal });
|
|
38
|
+
if (!run.ok) throw toolFailure(run);
|
|
39
|
+
return run.text;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { WebFetchError, webFetchTool };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=tanstack-ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tanstack-ai.js","names":[],"sources":["../../../../src/web/fetch/tools/tanstack-ai.ts"],"sourcesContent":["/**\n * `agents/webfetch/tanstack-ai` — the `web_fetch` tool for TanStack AI.\n *\n * @beta\n */\nimport { toolDefinition } from \"@tanstack/ai\";\nimport type { WEB_FETCH_TOOL_NAME } from \"../contract\";\nimport {\n createWebFetchToolCore,\n toolFailure,\n type WebFetchToolOptions\n} from \"../tool\";\nimport { webFetchInputSchema } from \"./input-schema\";\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\nexport type TanStackWebFetchToolOptions<\n TName extends string = typeof WEB_FETCH_TOOL_NAME\n> = WebFetchToolOptions & {\n /** The tool's name. TanStack AI tools carry it in the definition. */\n name?: TName;\n};\n\n/**\n * Create a TanStack AI tool that reads a URL as Markdown, JSON, or text.\n * TanStack AI has one return channel, so the model and the host both get\n * the rendered window. A failed fetch throws a `WebFetchError`, which\n * TanStack AI reports as an error result: its `message` is written for the\n * model, and its `cause` is the source's error with the detail. The tool is\n * named `web_fetch` unless you pass `name`.\n *\n * @example\n * ```ts\n * import { webFetchTool } from \"agents/webfetch/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * const stream = chat({\n * adapter,\n * tools: [webFetchTool({ binding: env.AI })],\n * messages\n * });\n * ```\n */\nexport function webFetchTool<TName extends string = typeof WEB_FETCH_TOOL_NAME>(\n options: TanStackWebFetchToolOptions<TName>\n) {\n const core = createWebFetchToolCore(options);\n return toolDefinition({\n name: options.name ?? (core.name as TName),\n description: core.description,\n inputSchema: webFetchInputSchema()\n }).server(async (input, context) => {\n const run = await core.run(input, { signal: context?.abortSignal });\n if (!run.ok) throw toolFailure(run);\n return run.text;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,aACd,SACA;CACA,MAAM,OAAO,uBAAuB,OAAO;CAC3C,OAAO,eAAe;EACpB,MAAM,QAAQ,QAAS,KAAK;EAC5B,aAAa,KAAK;EAClB,aAAa,oBAAoB;CACnC,CAAC,CAAC,CAAC,OAAO,OAAO,OAAO,YAAY;EAClC,MAAM,MAAM,MAAM,KAAK,IAAI,OAAO,EAAE,QAAQ,SAAS,YAAY,CAAC;EAClE,IAAI,CAAC,IAAI,IAAI,MAAM,YAAY,GAAG;EAClC,OAAO,IAAI;CACb,CAAC;AACH"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
C as WebSearchResponse,
|
|
3
|
+
D as renderWebSearchResults,
|
|
4
|
+
E as WebSearchToolOutput,
|
|
5
|
+
S as WEB_SEARCH_TOOL_NAME,
|
|
6
|
+
T as WebSearchToolInput,
|
|
7
|
+
_ as DEFAULT_WEB_SEARCH_LIMIT,
|
|
8
|
+
a as AIWebSearchOptions,
|
|
9
|
+
b as RenderWebSearchResultsOptions,
|
|
10
|
+
c as WebSearchError,
|
|
11
|
+
d as WebSearchProvider,
|
|
12
|
+
f as WebSearchRequest,
|
|
13
|
+
g as DEFAULT_WEB_SEARCH_DESCRIPTION_CHARS,
|
|
14
|
+
h as createHTTPWebSearch,
|
|
15
|
+
i as WebSearchToolSourceOptions,
|
|
16
|
+
l as WebSearchErrorCode,
|
|
17
|
+
m as createAIWebSearch,
|
|
18
|
+
n as WebSearchToolBindingOptions,
|
|
19
|
+
o as HTTPWebSearchOptions,
|
|
20
|
+
p as WebSearchSource,
|
|
21
|
+
r as WebSearchToolOptions,
|
|
22
|
+
s as WebSearchCallOptions,
|
|
23
|
+
t as DEFAULT_WEB_SEARCH_TIMEOUT_MS,
|
|
24
|
+
u as WebSearchGatewayOptions,
|
|
25
|
+
v as MAX_WEB_SEARCH_LIMIT,
|
|
26
|
+
w as WebSearchResult,
|
|
27
|
+
x as WEB_SEARCH_TOOL_DESCRIPTION,
|
|
28
|
+
y as MAX_WEB_SEARCH_QUERY_LENGTH
|
|
29
|
+
} from "../../tool-CTp72Jb_.js";
|
|
30
|
+
export {
|
|
31
|
+
type AIWebSearchOptions,
|
|
32
|
+
DEFAULT_WEB_SEARCH_DESCRIPTION_CHARS,
|
|
33
|
+
DEFAULT_WEB_SEARCH_LIMIT,
|
|
34
|
+
DEFAULT_WEB_SEARCH_TIMEOUT_MS,
|
|
35
|
+
type HTTPWebSearchOptions,
|
|
36
|
+
MAX_WEB_SEARCH_LIMIT,
|
|
37
|
+
MAX_WEB_SEARCH_QUERY_LENGTH,
|
|
38
|
+
type RenderWebSearchResultsOptions,
|
|
39
|
+
WEB_SEARCH_TOOL_DESCRIPTION,
|
|
40
|
+
WEB_SEARCH_TOOL_NAME,
|
|
41
|
+
type WebSearchCallOptions,
|
|
42
|
+
WebSearchError,
|
|
43
|
+
type WebSearchErrorCode,
|
|
44
|
+
type WebSearchGatewayOptions,
|
|
45
|
+
type WebSearchProvider,
|
|
46
|
+
type WebSearchRequest,
|
|
47
|
+
type WebSearchResponse,
|
|
48
|
+
type WebSearchResult,
|
|
49
|
+
type WebSearchSource,
|
|
50
|
+
type WebSearchToolBindingOptions,
|
|
51
|
+
type WebSearchToolInput,
|
|
52
|
+
type WebSearchToolOptions,
|
|
53
|
+
type WebSearchToolOutput,
|
|
54
|
+
type WebSearchToolSourceOptions,
|
|
55
|
+
createAIWebSearch,
|
|
56
|
+
createHTTPWebSearch,
|
|
57
|
+
renderWebSearchResults
|
|
58
|
+
};
|
|
@@ -0,0 +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-cQRkwSZZ.js";
|
|
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 };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
C as WebSearchResponse,
|
|
3
|
+
E as WebSearchToolOutput,
|
|
4
|
+
T as WebSearchToolInput,
|
|
5
|
+
c as WebSearchError,
|
|
6
|
+
d as WebSearchProvider,
|
|
7
|
+
l as WebSearchErrorCode,
|
|
8
|
+
p as WebSearchSource,
|
|
9
|
+
r as WebSearchToolOptions,
|
|
10
|
+
w as WebSearchResult
|
|
11
|
+
} from "../../../tool-CTp72Jb_.js";
|
|
12
|
+
import { FlexibleSchema } from "ai";
|
|
13
|
+
|
|
14
|
+
//#region src/web/search/tools/ai-sdk.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* The part of the AI SDK's tool execution options the tool reads. Spelled
|
|
17
|
+
* out rather than imported so it fits every supported `ai` major.
|
|
18
|
+
*/
|
|
19
|
+
interface WebSearchToolExecuteOptions {
|
|
20
|
+
abortSignal?: AbortSignal;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The AI SDK tool {@link webSearchTool} returns. Assignable to the AI SDK's
|
|
24
|
+
* `Tool`; `execute` and `toModelOutput` are always present.
|
|
25
|
+
*/
|
|
26
|
+
interface WebSearchTool {
|
|
27
|
+
description: string;
|
|
28
|
+
inputSchema: FlexibleSchema<WebSearchToolInput>;
|
|
29
|
+
execute(
|
|
30
|
+
input: WebSearchToolInput,
|
|
31
|
+
options: WebSearchToolExecuteOptions
|
|
32
|
+
): Promise<WebSearchToolOutput>;
|
|
33
|
+
toModelOutput(options: { output: WebSearchToolOutput }): {
|
|
34
|
+
type: "text";
|
|
35
|
+
value: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create an AI SDK tool that searches the web through Cloudflare's Web
|
|
40
|
+
* Search API. The host gets the full response as the tool's output (whole
|
|
41
|
+
* descriptions, provider metadata); the model gets a trimmed text rendering
|
|
42
|
+
* via `toModelOutput`. A failed search throws a `WebSearchError`, which the
|
|
43
|
+
* AI SDK reports to the model as a tool error: its `message` is written for
|
|
44
|
+
* the model, and its `cause` is the source's error with the API's detail.
|
|
45
|
+
*
|
|
46
|
+
* `toModelOutput` only applies to earlier turns when the tools are passed to
|
|
47
|
+
* `convertToModelMessages(messages, { tools })`; otherwise the AI SDK sends
|
|
48
|
+
* the full response back to the model as JSON. `AiSdkHarness` passes them.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { webSearchTool } from "agents/websearch/ai-sdk";
|
|
53
|
+
*
|
|
54
|
+
* const result = streamText({
|
|
55
|
+
* model,
|
|
56
|
+
* tools: { web_search: webSearchTool({ binding: env.AI }) },
|
|
57
|
+
* messages
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare function webSearchTool(options: WebSearchToolOptions): WebSearchTool;
|
|
62
|
+
//#endregion
|
|
63
|
+
export {
|
|
64
|
+
WebSearchError,
|
|
65
|
+
type WebSearchErrorCode,
|
|
66
|
+
type WebSearchProvider,
|
|
67
|
+
type WebSearchResponse,
|
|
68
|
+
type WebSearchResult,
|
|
69
|
+
type WebSearchSource,
|
|
70
|
+
WebSearchTool,
|
|
71
|
+
WebSearchToolExecuteOptions,
|
|
72
|
+
type WebSearchToolInput,
|
|
73
|
+
type WebSearchToolOptions,
|
|
74
|
+
type WebSearchToolOutput,
|
|
75
|
+
webSearchTool
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=ai-sdk.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { i as WebSearchError, n as createWebSearchToolCore, r as toolFailure } from "../../../tool-cQRkwSZZ.js";
|
|
2
|
+
import { t as webSearchInputSchema } from "../../../input-schema-D2QAtHZH.js";
|
|
3
|
+
//#region src/web/search/tools/ai-sdk.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create an AI SDK tool that searches the web through Cloudflare's Web
|
|
6
|
+
* Search API. The host gets the full response as the tool's output (whole
|
|
7
|
+
* descriptions, provider metadata); the model gets a trimmed text rendering
|
|
8
|
+
* via `toModelOutput`. A failed search throws a `WebSearchError`, which the
|
|
9
|
+
* AI SDK reports to the model as a tool error: its `message` is written for
|
|
10
|
+
* the model, and its `cause` is the source's error with the API's detail.
|
|
11
|
+
*
|
|
12
|
+
* `toModelOutput` only applies to earlier turns when the tools are passed to
|
|
13
|
+
* `convertToModelMessages(messages, { tools })`; otherwise the AI SDK sends
|
|
14
|
+
* the full response back to the model as JSON. `AiSdkHarness` passes them.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { webSearchTool } from "agents/websearch/ai-sdk";
|
|
19
|
+
*
|
|
20
|
+
* const result = streamText({
|
|
21
|
+
* model,
|
|
22
|
+
* tools: { web_search: webSearchTool({ binding: env.AI }) },
|
|
23
|
+
* messages
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function webSearchTool(options) {
|
|
28
|
+
const core = createWebSearchToolCore(options);
|
|
29
|
+
return {
|
|
30
|
+
description: core.description,
|
|
31
|
+
inputSchema: webSearchInputSchema(core.limit),
|
|
32
|
+
async execute(input, { abortSignal }) {
|
|
33
|
+
const run = await core.run(input, { signal: abortSignal });
|
|
34
|
+
if (!run.ok) throw toolFailure(run);
|
|
35
|
+
return run.output;
|
|
36
|
+
},
|
|
37
|
+
toModelOutput: ({ output }) => ({
|
|
38
|
+
type: "text",
|
|
39
|
+
value: core.render(output)
|
|
40
|
+
})
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { WebSearchError, webSearchTool };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=ai-sdk.js.map
|