eve 0.13.7 → 0.14.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/CHANGELOG.md +22 -0
- package/dist/src/channel/routes.d.ts +5 -0
- package/dist/src/channel/send.js +1 -1
- package/dist/src/channel/types.d.ts +5 -0
- package/dist/src/compiled/.vendor-stamp.json +12 -8
- package/dist/src/compiled/@ai-sdk/anthropic/index.d.ts +2 -2
- package/dist/src/compiled/@ai-sdk/anthropic/index.js +2 -2
- package/dist/src/compiled/@ai-sdk/google/index.d.ts +25 -3
- package/dist/src/compiled/@ai-sdk/google/index.js +6 -6
- package/dist/src/compiled/@ai-sdk/mcp/index.d.ts +647 -30
- package/dist/src/compiled/@ai-sdk/mcp/index.js +1 -1
- package/dist/src/compiled/@ai-sdk/openai/index.d.ts +8 -2
- package/dist/src/compiled/@ai-sdk/openai/index.js +2 -2
- package/dist/src/compiled/@ai-sdk/otel/index.d.ts +165 -28
- package/dist/src/compiled/@ai-sdk/otel/index.js +3 -3
- package/dist/src/compiled/@ai-sdk/provider/index.d.ts +10 -2
- package/dist/src/compiled/@ai-sdk/provider-utils/index.d.ts +2362 -0
- package/dist/src/compiled/@ai-sdk/provider-utils/index.js +1 -0
- package/dist/src/compiled/@workflow/serde/LICENSE.md +3 -0
- package/dist/src/compiled/@workflow/serde/index.d.ts +30 -0
- package/dist/src/compiled/@workflow/serde/index.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{dist-C9PV_vnE.js → dist-D7CzPkf8.js} +1 -1
- package/dist/src/compiled/eventsource-parser/stream/LICENSE +21 -0
- package/dist/src/compiled/eventsource-parser/stream/index.d.ts +121 -0
- package/dist/src/compiled/eventsource-parser/stream/index.js +1 -0
- package/dist/src/compiled/experimental-ai-sdk-code-mode/approval-continuation.d.ts +7 -7
- package/dist/src/compiled/experimental-ai-sdk-code-mode/continuation-capability.d.ts +15 -4
- package/dist/src/compiled/experimental-ai-sdk-code-mode/index.d.ts +1 -1
- package/dist/src/compiled/experimental-ai-sdk-code-mode/index.js +15 -15
- package/dist/src/compiled/experimental-ai-sdk-code-mode/interrupt-continuation.d.ts +5 -5
- package/dist/src/compiled/experimental-ai-sdk-code-mode/runtime/protocol.d.ts +13 -2
- package/dist/src/compiled/experimental-ai-sdk-code-mode/types.d.ts +26 -0
- package/dist/src/compiled/json-schema/LICENSE +21 -0
- package/dist/src/compiled/json-schema/index.d.ts +749 -0
- package/dist/src/compiled/json-schema/index.js +1 -0
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/compiler/normalize-agent-config.js +1 -1
- package/dist/src/context/build-dynamic-tools.js +1 -1
- package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
- package/dist/src/context/keys.d.ts +1 -1
- package/dist/src/execution/create-session-step.d.ts +0 -17
- package/dist/src/execution/create-session-step.js +1 -1
- package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
- package/dist/src/execution/dispatch-workflow-runtime-actions-step.d.ts +12 -0
- package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +1 -0
- package/dist/src/execution/eve-workflow-attributes.d.ts +1 -1
- package/dist/src/execution/next-driver-action.d.ts +1 -1
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/sandbox/prewarm.js +1 -1
- package/dist/src/execution/session.js +3 -3
- package/dist/src/execution/turn-workflow.js +1 -1
- package/dist/src/execution/workflow-entry.js +1 -1
- package/dist/src/execution/workflow-runtime.d.ts +2 -3
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/execution/workflow-steps.d.ts +1 -1
- package/dist/src/execution/workflow-steps.js +1 -1
- package/dist/src/harness/action-result-helpers.d.ts +2 -2
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/execute-tool.d.ts +2 -2
- package/dist/src/harness/input-extraction.js +1 -1
- package/dist/src/harness/tool-loop.js +1 -1
- package/dist/src/harness/tools.d.ts +4 -6
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/harness/types.d.ts +4 -10
- package/dist/src/harness/workflow-continuation-security.d.ts +4 -0
- package/dist/src/harness/workflow-continuation-security.js +1 -0
- package/dist/src/harness/workflow-interrupt-state.d.ts +14 -0
- package/dist/src/harness/workflow-interrupt-state.js +1 -0
- package/dist/src/harness/workflow-lifecycle.d.ts +13 -0
- package/dist/src/harness/workflow-lifecycle.js +1 -0
- package/dist/src/harness/workflow-runtime-action-state.d.ts +9 -0
- package/dist/src/harness/workflow-runtime-action-state.js +1 -0
- package/dist/src/harness/workflow-sandbox.d.ts +22 -0
- package/dist/src/harness/workflow-sandbox.js +2 -0
- package/dist/src/harness/workflow-tool-description.d.ts +2 -2
- package/dist/src/harness/workflow-tool-description.js +16 -4
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-definition/connection.js +1 -1
- package/dist/src/internal/authored-definition/core.js +1 -1
- package/dist/src/internal/authored-definition/schema-backed.js +1 -1
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/nitro/host/workflow-sandbox-runtime-plugin.d.ts +1 -0
- package/dist/src/internal/nitro/host/workflow-sandbox-runtime-plugin.js +1 -0
- package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response-from-manifest.js +1 -1
- package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
- package/dist/src/internal/workflow/runtime.d.ts +1 -0
- package/dist/src/public/channels/slack/attachments.js +1 -1
- package/dist/src/public/channels/slack/auth.d.ts +2 -0
- package/dist/src/public/channels/slack/auth.js +1 -1
- package/dist/src/public/channels/slack/defaults.js +2 -2
- package/dist/src/public/channels/slack/inbound.d.ts +4 -11
- package/dist/src/public/channels/slack/inbound.js +1 -2
- package/dist/src/public/channels/slack/model-context.d.ts +28 -0
- package/dist/src/public/channels/slack/model-context.js +3 -0
- package/dist/src/public/channels/slack/slackChannel.d.ts +8 -0
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/connections/index.d.ts +1 -1
- package/dist/src/public/definitions/agent.d.ts +1 -1
- package/dist/src/public/definitions/approval.d.ts +40 -0
- package/dist/src/public/definitions/approval.js +1 -0
- package/dist/src/public/definitions/connections/mcp.d.ts +11 -9
- package/dist/src/public/definitions/connections/mcp.js +1 -1
- package/dist/src/public/definitions/connections/openapi.d.ts +9 -7
- package/dist/src/public/definitions/connections/openapi.js +1 -1
- package/dist/src/public/definitions/tool.d.ts +7 -20
- package/dist/src/public/index.d.ts +1 -1
- package/dist/src/public/tools/approval/approval-helpers.d.ts +7 -7
- package/dist/src/public/tools/approval/approval-helpers.js +1 -1
- package/dist/src/public/tools/approval/index.d.ts +1 -1
- package/dist/src/public/tools/index.d.ts +2 -1
- package/dist/src/public/tools/internal.js +1 -1
- package/dist/src/runtime/agent/bootstrap.d.ts +1 -0
- package/dist/src/runtime/agent/bootstrap.js +1 -1
- package/dist/src/runtime/agent/mock-model-adapter.js +2 -3
- package/dist/src/runtime/attributes/emit.d.ts +2 -43
- package/dist/src/runtime/attributes/emit.js +1 -1
- package/dist/src/runtime/attributes/normalize.d.ts +17 -0
- package/dist/src/runtime/attributes/normalize.js +1 -0
- package/dist/src/runtime/connections/mcp-client.d.ts +3 -3
- package/dist/src/runtime/connections/mcp-client.js +1 -1
- package/dist/src/runtime/connections/registry.d.ts +2 -2
- package/dist/src/runtime/connections/resolve-authorization.d.ts +11 -0
- package/dist/src/runtime/connections/resolve-authorization.js +1 -0
- package/dist/src/runtime/connections/types.d.ts +27 -11
- package/dist/src/runtime/framework-tools/connection-search-dynamic.js +1 -1
- package/dist/src/runtime/resolve-agent-graph.js +1 -1
- package/dist/src/runtime/resolve-agent.js +1 -1
- package/dist/src/runtime/resolve-connection.js +1 -1
- package/dist/src/runtime/resolve-tool.d.ts +1 -1
- package/dist/src/runtime/resolve-tool.js +1 -1
- package/dist/src/runtime/sessions/compiled-agent-cache.js +1 -1
- package/dist/src/runtime/types.d.ts +8 -7
- package/dist/src/setup/primitives/pm/pnpm.js +6 -5
- package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +2 -2
- package/dist/src/setup/scaffold/update/channels.js +1 -1
- package/dist/src/shared/agent-definition.d.ts +11 -13
- package/dist/src/shared/dynamic-tool-definition.d.ts +3 -3
- package/dist/src/shared/tool-definition.d.ts +1 -2
- package/dist/src/shared/workflow-sandbox.d.ts +37 -0
- package/dist/src/shared/workflow-sandbox.js +1 -0
- package/docs/agent-config.md +30 -10
- package/docs/channels/custom.mdx +2 -2
- package/docs/channels/slack.mdx +7 -13
- package/docs/connections/mcp.mdx +2 -2
- package/docs/connections/openapi.mdx +37 -2
- package/docs/connections/overview.mdx +32 -0
- package/docs/guides/deployment.md +2 -2
- package/docs/guides/dynamic-workflows.md +1 -7
- package/docs/guides/frontend/overview.mdx +1 -1
- package/docs/guides/frontend/use-eve-agent-svelte.mdx +1 -1
- package/docs/guides/frontend/use-eve-agent-vue.mdx +1 -1
- package/docs/guides/session-context.md +2 -1
- package/docs/reference/typescript-api.md +2 -2
- package/docs/subagents.mdx +2 -2
- package/docs/tools/human-in-the-loop.md +43 -6
- package/docs/tools/overview.mdx +3 -3
- package/docs/tutorial/first-agent.mdx +1 -1
- package/docs/tutorial/guard-the-spend.mdx +4 -3
- package/docs/tutorial/ship-it.mdx +1 -1
- package/package.json +14 -11
- package/dist/src/compiled/@ai-sdk/anthropic/_provider-utils.d.ts +0 -15
- package/dist/src/compiled/@ai-sdk/google/_provider-utils.d.ts +0 -11
- package/dist/src/compiled/@ai-sdk/openai/_provider-utils.d.ts +0 -15
- package/dist/src/compiled/@ai-sdk/provider/_json-schema.d.ts +0 -5
- package/dist/src/execution/dispatch-code-mode-runtime-actions-step.d.ts +0 -21
- package/dist/src/execution/dispatch-code-mode-runtime-actions-step.js +0 -1
- package/dist/src/harness/code-mode-interrupt-state.d.ts +0 -26
- package/dist/src/harness/code-mode-interrupt-state.js +0 -1
- package/dist/src/harness/code-mode-lifecycle.d.ts +0 -16
- package/dist/src/harness/code-mode-lifecycle.js +0 -1
- package/dist/src/harness/code-mode-runtime-action-state.d.ts +0 -6
- package/dist/src/harness/code-mode-runtime-action-state.js +0 -1
- package/dist/src/harness/code-mode.d.ts +0 -26
- package/dist/src/harness/code-mode.js +0 -1
- package/dist/src/harness/sandbox-surface.d.ts +0 -68
- package/dist/src/harness/sandbox-surface.js +0 -1
- package/dist/src/internal/nitro/host/code-mode-runtime-dependency-plugin.d.ts +0 -1
- package/dist/src/internal/nitro/host/code-mode-runtime-dependency-plugin.js +0 -1
- package/dist/src/runtime/framework-tools/code-mode-connection-auth.d.ts +0 -29
- package/dist/src/runtime/framework-tools/code-mode-connection-auth.js +0 -1
- package/dist/src/shared/code-mode.d.ts +0 -29
- package/dist/src/shared/code-mode.js +0 -1
|
@@ -0,0 +1,2362 @@
|
|
|
1
|
+
import { SharedV4FileDataUrl, SharedV4FileDataReference, SharedV4FileDataText, SharedV4ProviderOptions, SharedV4ProviderReference, JSONValue, ImageModelV4File, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, APICallError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, JSONObject, LanguageModelV4FilePart, LanguageModelV4StreamPart, SharedV4ProviderMetadata, TypeValidationContext } from '#compiled/@ai-sdk/provider/index.js';
|
|
2
|
+
export { getErrorMessage } from '#compiled/@ai-sdk/provider/index.js';
|
|
3
|
+
import { StandardSchemaV1, StandardJSONSchemaV1 } from '#compiled/@standard-schema/spec/index.js';
|
|
4
|
+
export * from '#compiled/@standard-schema/spec/index.js';
|
|
5
|
+
import * as z3 from '#compiled/zod/index.js';
|
|
6
|
+
import * as z4 from '#compiled/zod/index.js';
|
|
7
|
+
export { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from '#compiled/@workflow/serde/index.js';
|
|
8
|
+
export { EventSourceMessage, EventSourceParserStream } from '#compiled/eventsource-parser/stream/index.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A value that can be provided either as a single item, an array of items,
|
|
12
|
+
* or be left undefined.
|
|
13
|
+
*/
|
|
14
|
+
type Arrayable<T> = T | T[] | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Normalizes a possibly undefined or non-array value into an array.
|
|
17
|
+
*/
|
|
18
|
+
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
19
|
+
|
|
20
|
+
declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Converts an AsyncIterator to a ReadableStream.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of elements produced by the AsyncIterator.
|
|
26
|
+
* @param { <T>} iterator - The AsyncIterator to convert.
|
|
27
|
+
* @returns {ReadableStream<T>} - A ReadableStream that provides the same data as the AsyncIterator.
|
|
28
|
+
*/
|
|
29
|
+
declare function convertAsyncIteratorToReadableStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
|
33
|
+
*/
|
|
34
|
+
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* File data variant containing raw bytes (`Uint8Array`, `ArrayBuffer`, or
|
|
38
|
+
* `Buffer`) or a base64-encoded string.
|
|
39
|
+
*
|
|
40
|
+
* This is slightly more permissive than `SharedV4FileDataData`.
|
|
41
|
+
*/
|
|
42
|
+
interface FileDataData {
|
|
43
|
+
type: 'data';
|
|
44
|
+
data: DataContent;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* File data variant containing a URL that points to the file.
|
|
48
|
+
*/
|
|
49
|
+
type FileDataUrl = SharedV4FileDataUrl;
|
|
50
|
+
/**
|
|
51
|
+
* File data variant containing a provider reference (`{ [provider]: id }`).
|
|
52
|
+
*/
|
|
53
|
+
type FileDataReference = SharedV4FileDataReference;
|
|
54
|
+
/**
|
|
55
|
+
* File data variant containing inline text content (e.g. an inline text
|
|
56
|
+
* document).
|
|
57
|
+
*/
|
|
58
|
+
type FileDataText = SharedV4FileDataText;
|
|
59
|
+
/**
|
|
60
|
+
* File data as a tagged discriminated union:
|
|
61
|
+
*
|
|
62
|
+
* - `{ type: 'data', data }`: raw bytes (`Uint8Array`, `ArrayBuffer`, or
|
|
63
|
+
* `Buffer`) or a base64-encoded string.
|
|
64
|
+
* - `{ type: 'url', url }`: a URL that points to the file.
|
|
65
|
+
* - `{ type: 'reference', reference }`: a provider reference (`{ [provider]: id }`).
|
|
66
|
+
* - `{ type: 'text', text }`: inline text content (e.g. an inline text document).
|
|
67
|
+
*/
|
|
68
|
+
type FileData = FileDataData | FileDataUrl | FileDataReference | FileDataText;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Additional provider-specific options.
|
|
72
|
+
*
|
|
73
|
+
* They are passed through to the provider from the AI SDK and enable
|
|
74
|
+
* provider-specific functionality that can be fully encapsulated in the provider.
|
|
75
|
+
*/
|
|
76
|
+
type ProviderOptions = SharedV4ProviderOptions;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A mapping of provider names to provider-specific file identifiers.
|
|
80
|
+
*
|
|
81
|
+
* Provider references allow files to be identified across different
|
|
82
|
+
* providers without re-uploading, by storing each provider's own
|
|
83
|
+
* identifier for the same logical file.
|
|
84
|
+
*/
|
|
85
|
+
type ProviderReference = SharedV4ProviderReference;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Text content part of a prompt. It contains a string of text.
|
|
89
|
+
*/
|
|
90
|
+
interface TextPart {
|
|
91
|
+
type: 'text';
|
|
92
|
+
/**
|
|
93
|
+
* The text content.
|
|
94
|
+
*/
|
|
95
|
+
text: string;
|
|
96
|
+
/**
|
|
97
|
+
* Additional provider-specific metadata. They are passed through
|
|
98
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
99
|
+
* functionality that can be fully encapsulated in the provider.
|
|
100
|
+
*/
|
|
101
|
+
providerOptions?: ProviderOptions;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Image content part of a prompt. It contains an image.
|
|
105
|
+
*
|
|
106
|
+
* @deprecated Use `FilePart` with `mediaType: 'image'` instead:
|
|
107
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
|
|
108
|
+
*/
|
|
109
|
+
interface ImagePart {
|
|
110
|
+
type: 'image';
|
|
111
|
+
/**
|
|
112
|
+
* Image data. Can either be:
|
|
113
|
+
*
|
|
114
|
+
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
115
|
+
* - URL: a URL that points to the image
|
|
116
|
+
* - ProviderReference: a provider reference from `uploadFile`
|
|
117
|
+
*/
|
|
118
|
+
image: DataContent | URL | ProviderReference;
|
|
119
|
+
/**
|
|
120
|
+
* Optional IANA media type of the image.
|
|
121
|
+
*
|
|
122
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
123
|
+
*/
|
|
124
|
+
mediaType?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Additional provider-specific metadata. They are passed through
|
|
127
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
128
|
+
* functionality that can be fully encapsulated in the provider.
|
|
129
|
+
*/
|
|
130
|
+
providerOptions?: ProviderOptions;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* File content part of a prompt. It contains a file.
|
|
134
|
+
*/
|
|
135
|
+
interface FilePart {
|
|
136
|
+
type: 'file';
|
|
137
|
+
/**
|
|
138
|
+
* File data. Either a tagged shape or a bare shorthand:
|
|
139
|
+
*
|
|
140
|
+
* - `{ type: 'data', data }` or bare `DataContent`: raw bytes
|
|
141
|
+
* (base64 string, Uint8Array, ArrayBuffer, Buffer)
|
|
142
|
+
* - `{ type: 'url', url }` or bare `URL`: a URL that points to the file
|
|
143
|
+
* - `{ type: 'reference', reference }` or bare `ProviderReference`:
|
|
144
|
+
* a provider reference from `uploadFile`
|
|
145
|
+
* - `{ type: 'text', text }`: inline text content (tagged only)
|
|
146
|
+
*/
|
|
147
|
+
data: FileData | DataContent | URL | ProviderReference;
|
|
148
|
+
/**
|
|
149
|
+
* Optional filename of the file.
|
|
150
|
+
*/
|
|
151
|
+
filename?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
|
|
154
|
+
* the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
|
|
155
|
+
*
|
|
156
|
+
* `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
|
|
157
|
+
* top-level segment alone (e.g. `image`). Providers can use the helpers in
|
|
158
|
+
* `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
|
|
159
|
+
* `detectMediaType`) to resolve the field according to their API
|
|
160
|
+
* requirements.
|
|
161
|
+
*
|
|
162
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
163
|
+
*/
|
|
164
|
+
mediaType: string;
|
|
165
|
+
/**
|
|
166
|
+
* Additional provider-specific metadata. They are passed through
|
|
167
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
168
|
+
* functionality that can be fully encapsulated in the provider.
|
|
169
|
+
*/
|
|
170
|
+
providerOptions?: ProviderOptions;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Reasoning content part of a prompt. It contains a reasoning.
|
|
174
|
+
*/
|
|
175
|
+
interface ReasoningPart {
|
|
176
|
+
type: 'reasoning';
|
|
177
|
+
/**
|
|
178
|
+
* The reasoning text.
|
|
179
|
+
*/
|
|
180
|
+
text: string;
|
|
181
|
+
/**
|
|
182
|
+
* Additional provider-specific metadata. They are passed through
|
|
183
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
184
|
+
* functionality that can be fully encapsulated in the provider.
|
|
185
|
+
*/
|
|
186
|
+
providerOptions?: ProviderOptions;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Custom content part of a prompt. It contains no standardized payload beyond
|
|
190
|
+
* provider-specific options.
|
|
191
|
+
*/
|
|
192
|
+
interface CustomPart {
|
|
193
|
+
type: 'custom';
|
|
194
|
+
/**
|
|
195
|
+
* The kind of custom content, in the format `{provider}.{provider-type}`.
|
|
196
|
+
*/
|
|
197
|
+
kind: `${string}.${string}`;
|
|
198
|
+
/**
|
|
199
|
+
* Additional provider-specific metadata. They are passed through
|
|
200
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
201
|
+
* functionality that can be fully encapsulated in the provider.
|
|
202
|
+
*/
|
|
203
|
+
providerOptions?: ProviderOptions;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
|
|
207
|
+
*/
|
|
208
|
+
interface ReasoningFilePart {
|
|
209
|
+
type: 'reasoning-file';
|
|
210
|
+
/**
|
|
211
|
+
* Reasoning file data.
|
|
212
|
+
*
|
|
213
|
+
* Reasoning files originate from a model's reasoning output and are always
|
|
214
|
+
* raw bytes or a fetchable URL. Unlike `FilePart.data`, the `reference` and
|
|
215
|
+
* `text` shapes are not supported here: provider references describe files
|
|
216
|
+
* uploaded by the user (not produced as model output), and reasoning text is
|
|
217
|
+
* carried by `ReasoningPart` rather than as a file.
|
|
218
|
+
*
|
|
219
|
+
* Either a tagged shape or a bare shorthand:
|
|
220
|
+
*
|
|
221
|
+
* - `{ type: 'data', data }` or bare `DataContent`: raw bytes
|
|
222
|
+
* (base64 string, Uint8Array, ArrayBuffer, Buffer)
|
|
223
|
+
* - `{ type: 'url', url }` or bare `URL`: a URL that points to the file
|
|
224
|
+
*/
|
|
225
|
+
data: FileDataData | FileDataUrl | DataContent | URL;
|
|
226
|
+
/**
|
|
227
|
+
* IANA media type of the file.
|
|
228
|
+
*
|
|
229
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
230
|
+
*/
|
|
231
|
+
mediaType: string;
|
|
232
|
+
/**
|
|
233
|
+
* Additional provider-specific metadata. They are passed through
|
|
234
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
235
|
+
* functionality that can be fully encapsulated in the provider.
|
|
236
|
+
*/
|
|
237
|
+
providerOptions?: ProviderOptions;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
241
|
+
*/
|
|
242
|
+
interface ToolCallPart {
|
|
243
|
+
type: 'tool-call';
|
|
244
|
+
/**
|
|
245
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
246
|
+
*/
|
|
247
|
+
toolCallId: string;
|
|
248
|
+
/**
|
|
249
|
+
* Name of the tool that is being called.
|
|
250
|
+
*/
|
|
251
|
+
toolName: string;
|
|
252
|
+
/**
|
|
253
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
254
|
+
*/
|
|
255
|
+
input: unknown;
|
|
256
|
+
/**
|
|
257
|
+
* Additional provider-specific metadata. They are passed through
|
|
258
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
259
|
+
* functionality that can be fully encapsulated in the provider.
|
|
260
|
+
*/
|
|
261
|
+
providerOptions?: ProviderOptions;
|
|
262
|
+
/**
|
|
263
|
+
* Whether the tool call was executed by the provider.
|
|
264
|
+
*/
|
|
265
|
+
providerExecuted?: boolean;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
|
269
|
+
*/
|
|
270
|
+
interface ToolResultPart {
|
|
271
|
+
type: 'tool-result';
|
|
272
|
+
/**
|
|
273
|
+
* ID of the tool call that this result is associated with.
|
|
274
|
+
*/
|
|
275
|
+
toolCallId: string;
|
|
276
|
+
/**
|
|
277
|
+
* Name of the tool that generated this result.
|
|
278
|
+
*/
|
|
279
|
+
toolName: string;
|
|
280
|
+
/**
|
|
281
|
+
* Result of the tool call. This is a JSON-serializable object.
|
|
282
|
+
*/
|
|
283
|
+
output: ToolResultOutput;
|
|
284
|
+
/**
|
|
285
|
+
* Additional provider-specific metadata. They are passed through
|
|
286
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
287
|
+
* functionality that can be fully encapsulated in the provider.
|
|
288
|
+
*/
|
|
289
|
+
providerOptions?: ProviderOptions;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Output of a tool result.
|
|
293
|
+
*/
|
|
294
|
+
type ToolResultOutput = {
|
|
295
|
+
/**
|
|
296
|
+
* Text tool output that should be directly sent to the API.
|
|
297
|
+
*/
|
|
298
|
+
type: 'text';
|
|
299
|
+
value: string;
|
|
300
|
+
/**
|
|
301
|
+
* Provider-specific options.
|
|
302
|
+
*/
|
|
303
|
+
providerOptions?: ProviderOptions;
|
|
304
|
+
} | {
|
|
305
|
+
type: 'json';
|
|
306
|
+
value: JSONValue;
|
|
307
|
+
/**
|
|
308
|
+
* Provider-specific options.
|
|
309
|
+
*/
|
|
310
|
+
providerOptions?: ProviderOptions;
|
|
311
|
+
} | {
|
|
312
|
+
/**
|
|
313
|
+
* Type when the user has denied the execution of the tool call.
|
|
314
|
+
*/
|
|
315
|
+
type: 'execution-denied';
|
|
316
|
+
/**
|
|
317
|
+
* Optional reason for the execution denial.
|
|
318
|
+
*/
|
|
319
|
+
reason?: string;
|
|
320
|
+
/**
|
|
321
|
+
* Provider-specific options.
|
|
322
|
+
*/
|
|
323
|
+
providerOptions?: ProviderOptions;
|
|
324
|
+
} | {
|
|
325
|
+
type: 'error-text';
|
|
326
|
+
value: string;
|
|
327
|
+
/**
|
|
328
|
+
* Provider-specific options.
|
|
329
|
+
*/
|
|
330
|
+
providerOptions?: ProviderOptions;
|
|
331
|
+
} | {
|
|
332
|
+
type: 'error-json';
|
|
333
|
+
value: JSONValue;
|
|
334
|
+
/**
|
|
335
|
+
* Provider-specific options.
|
|
336
|
+
*/
|
|
337
|
+
providerOptions?: ProviderOptions;
|
|
338
|
+
} | {
|
|
339
|
+
type: 'content';
|
|
340
|
+
value: Array<{
|
|
341
|
+
type: 'text';
|
|
342
|
+
/**
|
|
343
|
+
* Text content.
|
|
344
|
+
*/
|
|
345
|
+
text: string;
|
|
346
|
+
/**
|
|
347
|
+
* Provider-specific options.
|
|
348
|
+
*/
|
|
349
|
+
providerOptions?: ProviderOptions;
|
|
350
|
+
} | {
|
|
351
|
+
type: 'file';
|
|
352
|
+
/**
|
|
353
|
+
* File data as a tagged discriminated union:
|
|
354
|
+
*
|
|
355
|
+
* - `{ type: 'data', data }`: raw bytes
|
|
356
|
+
* (base64 string, Uint8Array, ArrayBuffer, Buffer)
|
|
357
|
+
* - `{ type: 'url', url }`: a URL that points to the file
|
|
358
|
+
* - `{ type: 'reference', reference }`: a provider reference
|
|
359
|
+
* from `uploadFile`
|
|
360
|
+
* - `{ type: 'text', text }`: inline text content (e.g. an inline
|
|
361
|
+
* text document)
|
|
362
|
+
*/
|
|
363
|
+
data: FileData;
|
|
364
|
+
/**
|
|
365
|
+
* Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
|
|
366
|
+
* the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
|
|
367
|
+
*
|
|
368
|
+
* `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
|
|
369
|
+
* top-level segment alone (e.g. `image`). Providers can use the helpers in
|
|
370
|
+
* `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
|
|
371
|
+
* `detectMediaType`) to resolve the field according to their API
|
|
372
|
+
* requirements.
|
|
373
|
+
*
|
|
374
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
375
|
+
*/
|
|
376
|
+
mediaType: string;
|
|
377
|
+
/**
|
|
378
|
+
* Optional filename of the file.
|
|
379
|
+
*/
|
|
380
|
+
filename?: string;
|
|
381
|
+
/**
|
|
382
|
+
* Provider-specific options.
|
|
383
|
+
*/
|
|
384
|
+
providerOptions?: ProviderOptions;
|
|
385
|
+
} | {
|
|
386
|
+
/**
|
|
387
|
+
* @deprecated Use 'file' with mediaType + tagged data instead:
|
|
388
|
+
* `{ type: 'file', mediaType, data: { type: 'data', data } }`.
|
|
389
|
+
*/
|
|
390
|
+
type: 'file-data';
|
|
391
|
+
/**
|
|
392
|
+
* Base-64 encoded media data.
|
|
393
|
+
*/
|
|
394
|
+
data: string;
|
|
395
|
+
/**
|
|
396
|
+
* IANA media type.
|
|
397
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
398
|
+
*/
|
|
399
|
+
mediaType: string;
|
|
400
|
+
/**
|
|
401
|
+
* Optional filename of the file.
|
|
402
|
+
*/
|
|
403
|
+
filename?: string;
|
|
404
|
+
/**
|
|
405
|
+
* Provider-specific options.
|
|
406
|
+
*/
|
|
407
|
+
providerOptions?: ProviderOptions;
|
|
408
|
+
} | {
|
|
409
|
+
/**
|
|
410
|
+
* @deprecated Use 'file' with mediaType and tagged data instead:
|
|
411
|
+
* `{ type: 'file', mediaType, data: { type: 'url', url: new URL(url) } }`.
|
|
412
|
+
*/
|
|
413
|
+
type: 'file-url';
|
|
414
|
+
/**
|
|
415
|
+
* URL of the file.
|
|
416
|
+
*/
|
|
417
|
+
url: string;
|
|
418
|
+
/**
|
|
419
|
+
* IANA media type.
|
|
420
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
421
|
+
*/
|
|
422
|
+
mediaType?: string;
|
|
423
|
+
/**
|
|
424
|
+
* Provider-specific options.
|
|
425
|
+
*/
|
|
426
|
+
providerOptions?: ProviderOptions;
|
|
427
|
+
} | {
|
|
428
|
+
/**
|
|
429
|
+
* @deprecated Use 'file' with tagged data instead:
|
|
430
|
+
* `{ type: 'file', mediaType, data: { type: 'reference', reference } }`.
|
|
431
|
+
*/
|
|
432
|
+
type: 'file-id';
|
|
433
|
+
/**
|
|
434
|
+
* ID of the file.
|
|
435
|
+
*
|
|
436
|
+
* If you use multiple providers, you need to
|
|
437
|
+
* specify the provider specific ids using
|
|
438
|
+
* the Record option. The key is the provider
|
|
439
|
+
* name, e.g. 'openai' or 'anthropic'.
|
|
440
|
+
*/
|
|
441
|
+
fileId: string | Record<string, string>;
|
|
442
|
+
/**
|
|
443
|
+
* Provider-specific options.
|
|
444
|
+
*/
|
|
445
|
+
providerOptions?: ProviderOptions;
|
|
446
|
+
} | {
|
|
447
|
+
/**
|
|
448
|
+
* @deprecated Use 'file' with tagged data instead:
|
|
449
|
+
* `{ type: 'file', mediaType, data: { type: 'reference', reference } }`.
|
|
450
|
+
*/
|
|
451
|
+
type: 'file-reference';
|
|
452
|
+
/**
|
|
453
|
+
* Provider-specific references for the file.
|
|
454
|
+
* The key is the provider name, e.g. 'openai' or 'anthropic'.
|
|
455
|
+
*/
|
|
456
|
+
providerReference: ProviderReference;
|
|
457
|
+
/**
|
|
458
|
+
* Provider-specific options.
|
|
459
|
+
*/
|
|
460
|
+
providerOptions?: ProviderOptions;
|
|
461
|
+
} | {
|
|
462
|
+
/**
|
|
463
|
+
* @deprecated Use 'file' with mediaType (e.g. 'image' or a specific
|
|
464
|
+
* `image/*` subtype) and tagged data instead:
|
|
465
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'data', data } }`.
|
|
466
|
+
*/
|
|
467
|
+
type: 'image-data';
|
|
468
|
+
/**
|
|
469
|
+
* Base-64 encoded image data.
|
|
470
|
+
*/
|
|
471
|
+
data: string;
|
|
472
|
+
/**
|
|
473
|
+
* IANA media type.
|
|
474
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
475
|
+
*/
|
|
476
|
+
mediaType: string;
|
|
477
|
+
/**
|
|
478
|
+
* Provider-specific options.
|
|
479
|
+
*/
|
|
480
|
+
providerOptions?: ProviderOptions;
|
|
481
|
+
} | {
|
|
482
|
+
/**
|
|
483
|
+
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
484
|
+
* `image/*` subtype) and tagged data instead:
|
|
485
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'url', url: new URL(url) } }`.
|
|
486
|
+
*/
|
|
487
|
+
type: 'image-url';
|
|
488
|
+
/**
|
|
489
|
+
* URL of the image.
|
|
490
|
+
*/
|
|
491
|
+
url: string;
|
|
492
|
+
/**
|
|
493
|
+
* Provider-specific options.
|
|
494
|
+
*/
|
|
495
|
+
providerOptions?: ProviderOptions;
|
|
496
|
+
} | {
|
|
497
|
+
/**
|
|
498
|
+
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
499
|
+
* `image/*` subtype) and tagged data instead:
|
|
500
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'reference', reference } }`.
|
|
501
|
+
*/
|
|
502
|
+
type: 'image-file-id';
|
|
503
|
+
/**
|
|
504
|
+
* Image that is referenced using a provider file id.
|
|
505
|
+
*
|
|
506
|
+
* If you use multiple providers, you need to
|
|
507
|
+
* specify the provider specific ids using
|
|
508
|
+
* the Record option. The key is the provider
|
|
509
|
+
* name, e.g. 'openai' or 'anthropic'.
|
|
510
|
+
*/
|
|
511
|
+
fileId: string | Record<string, string>;
|
|
512
|
+
/**
|
|
513
|
+
* Provider-specific options.
|
|
514
|
+
*/
|
|
515
|
+
providerOptions?: ProviderOptions;
|
|
516
|
+
} | {
|
|
517
|
+
/**
|
|
518
|
+
* @deprecated Use 'file' with `mediaType: 'image'` (or a specific
|
|
519
|
+
* `image/*` subtype) and tagged data instead:
|
|
520
|
+
* `{ type: 'file', mediaType: 'image', data: { type: 'reference', reference } }`.
|
|
521
|
+
*/
|
|
522
|
+
type: 'image-file-reference';
|
|
523
|
+
/**
|
|
524
|
+
* Provider-specific references for the image file.
|
|
525
|
+
* The key is the provider name, e.g. 'openai' or 'anthropic'.
|
|
526
|
+
*/
|
|
527
|
+
providerReference: ProviderReference;
|
|
528
|
+
/**
|
|
529
|
+
* Provider-specific options.
|
|
530
|
+
*/
|
|
531
|
+
providerOptions?: ProviderOptions;
|
|
532
|
+
} | {
|
|
533
|
+
/**
|
|
534
|
+
* Custom content part. This can be used to implement
|
|
535
|
+
* provider-specific content parts.
|
|
536
|
+
*/
|
|
537
|
+
type: 'custom';
|
|
538
|
+
/**
|
|
539
|
+
* Provider-specific options.
|
|
540
|
+
*/
|
|
541
|
+
providerOptions?: ProviderOptions;
|
|
542
|
+
}>;
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
type InlineFileData = Extract<FilePart['data'], {
|
|
546
|
+
type: 'data';
|
|
547
|
+
} | {
|
|
548
|
+
type: 'text';
|
|
549
|
+
}>;
|
|
550
|
+
/**
|
|
551
|
+
* Converts inline file data (a tagged `data` or `text` shape) into raw bytes.
|
|
552
|
+
*
|
|
553
|
+
* - `{ type: 'text', text }` → UTF-8 encoded bytes
|
|
554
|
+
* - `{ type: 'data', data: Uint8Array | Buffer }` → returned as-is
|
|
555
|
+
* - `{ type: 'data', data: ArrayBuffer }` → wrapped in a `Uint8Array`
|
|
556
|
+
* - `{ type: 'data', data: string }` → decoded as base64
|
|
557
|
+
*/
|
|
558
|
+
declare function convertInlineFileDataToUint8Array(data: InlineFileData): Uint8Array;
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Convert an ImageModelV4File to a URL or data URI string.
|
|
562
|
+
*
|
|
563
|
+
* If the file is a URL, it returns the URL as-is.
|
|
564
|
+
* If the file is base64 data, it returns a data URI with the base64 data.
|
|
565
|
+
* If the file is a Uint8Array, it converts it to base64 and returns a data URI.
|
|
566
|
+
*/
|
|
567
|
+
declare function convertImageModelFileToDataUri(file: ImageModelV4File): string;
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Converts an input object to FormData for multipart/form-data requests.
|
|
571
|
+
*
|
|
572
|
+
* Handles the following cases:
|
|
573
|
+
* - `null` or `undefined` values are skipped
|
|
574
|
+
* - Arrays with a single element are appended as a single value
|
|
575
|
+
* - Arrays with multiple elements are appended with `[]` suffix (e.g., `image[]`)
|
|
576
|
+
* unless `useArrayBrackets` is set to `false`
|
|
577
|
+
* - All other values are appended directly
|
|
578
|
+
*
|
|
579
|
+
* @param input - The input object to convert. Use a generic type for type validation.
|
|
580
|
+
* @param options - Optional configuration object.
|
|
581
|
+
* @param options.useArrayBrackets - Whether to add `[]` suffix for multi-element arrays.
|
|
582
|
+
* Defaults to `true`. Set to `false` for APIs that expect repeated keys without brackets.
|
|
583
|
+
* @returns A FormData object containing the input values.
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
* ```ts
|
|
587
|
+
* type MyInput = {
|
|
588
|
+
* model: string;
|
|
589
|
+
* prompt: string;
|
|
590
|
+
* images: Blob[];
|
|
591
|
+
* };
|
|
592
|
+
*
|
|
593
|
+
* const formData = convertToFormData<MyInput>({
|
|
594
|
+
* model: 'gpt-image-1',
|
|
595
|
+
* prompt: 'A cat',
|
|
596
|
+
* images: [blob1, blob2],
|
|
597
|
+
* });
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
|
|
601
|
+
useArrayBrackets?: boolean;
|
|
602
|
+
}): FormData;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Interface for mapping between custom tool names and provider tool names.
|
|
606
|
+
*/
|
|
607
|
+
interface ToolNameMapping {
|
|
608
|
+
/**
|
|
609
|
+
* Maps a custom tool name (used by the client) to the provider's tool name.
|
|
610
|
+
* If the custom tool name does not have a mapping, returns the input name.
|
|
611
|
+
*
|
|
612
|
+
* @param customToolName - The custom name of the tool defined by the client.
|
|
613
|
+
* @returns The corresponding provider tool name, or the input name if not mapped.
|
|
614
|
+
*/
|
|
615
|
+
toProviderToolName: (customToolName: string) => string;
|
|
616
|
+
/**
|
|
617
|
+
* Maps a provider tool name to the custom tool name used by the client.
|
|
618
|
+
* If the provider tool name does not have a mapping, returns the input name.
|
|
619
|
+
*
|
|
620
|
+
* @param providerToolName - The name of the tool as understood by the provider.
|
|
621
|
+
* @returns The corresponding custom tool name, or the input name if not mapped.
|
|
622
|
+
*/
|
|
623
|
+
toCustomToolName: (providerToolName: string) => string;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* @param tools - Tools that were passed to the language model.
|
|
627
|
+
* @param providerToolNames - Maps the provider tool ids to the provider tool names.
|
|
628
|
+
*/
|
|
629
|
+
declare function createToolNameMapping({ tools, providerToolNames, }: {
|
|
630
|
+
/**
|
|
631
|
+
* Tools that were passed to the language model.
|
|
632
|
+
*/
|
|
633
|
+
tools: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool> | undefined;
|
|
634
|
+
/**
|
|
635
|
+
* Maps the provider tool ids to the provider tool names.
|
|
636
|
+
*/
|
|
637
|
+
providerToolNames: Record<`${string}.${string}`, string>;
|
|
638
|
+
}): ToolNameMapping;
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Creates a Promise that resolves after a specified delay
|
|
642
|
+
* @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
|
|
643
|
+
* @param signal - Optional AbortSignal to cancel the delay
|
|
644
|
+
* @returns A Promise that resolves after the specified delay
|
|
645
|
+
* @throws {DOMException} When the signal is aborted
|
|
646
|
+
*/
|
|
647
|
+
declare function delay(delayInMs?: number | null, options?: {
|
|
648
|
+
abortSignal?: AbortSignal;
|
|
649
|
+
}): Promise<void>;
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Delayed promise. It is only constructed once the value is accessed.
|
|
653
|
+
* This is useful to avoid unhandled promise rejections when the promise is created
|
|
654
|
+
* but not accessed.
|
|
655
|
+
*/
|
|
656
|
+
declare class DelayedPromise<T> {
|
|
657
|
+
private status;
|
|
658
|
+
private _promise;
|
|
659
|
+
private _resolve;
|
|
660
|
+
private _reject;
|
|
661
|
+
get promise(): Promise<T>;
|
|
662
|
+
resolve(value: T): void;
|
|
663
|
+
reject(error: unknown): void;
|
|
664
|
+
isResolved(): boolean;
|
|
665
|
+
isRejected(): boolean;
|
|
666
|
+
isPending(): boolean;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Detect the IANA media type of a file from its raw bytes or base64 string.
|
|
671
|
+
*
|
|
672
|
+
* - When `topLevelType` is omitted, every known signature is considered
|
|
673
|
+
* (image, audio, video, and application). Returns `undefined` when the
|
|
674
|
+
* bytes do not match any known signature.
|
|
675
|
+
* - When `topLevelType` is provided, only signatures for that top-level
|
|
676
|
+
* segment are considered. Returns `undefined` for unsupported segments
|
|
677
|
+
* (e.g. `"text"`) or when no signature matches.
|
|
678
|
+
*/
|
|
679
|
+
declare function detectMediaType({ data, topLevelType, }: {
|
|
680
|
+
data: Uint8Array | string;
|
|
681
|
+
topLevelType?: string;
|
|
682
|
+
}): string | undefined;
|
|
683
|
+
/**
|
|
684
|
+
* Returns the top-level segment of a media type (the portion before `/`).
|
|
685
|
+
*
|
|
686
|
+
* Examples:
|
|
687
|
+
* - `"image/png"` -> `"image"`
|
|
688
|
+
* - `"image/*"` -> `"image"`
|
|
689
|
+
* - `"image"` -> `"image"`
|
|
690
|
+
* - `"image/"` -> `"image"`
|
|
691
|
+
* - `""` -> `""`
|
|
692
|
+
* - `"/"` -> `""`
|
|
693
|
+
*/
|
|
694
|
+
declare function getTopLevelMediaType(mediaType: string): string;
|
|
695
|
+
/**
|
|
696
|
+
* Returns `true` only when the given media type has a non-empty, non-wildcard
|
|
697
|
+
* subtype (i.e. matches the form `type/subtype`, and `subtype` is not `*`).
|
|
698
|
+
*
|
|
699
|
+
* Examples:
|
|
700
|
+
* - `"image/png"` -> `true`
|
|
701
|
+
* - `"image/*"` -> `false`
|
|
702
|
+
* - `"image"` -> `false`
|
|
703
|
+
* - `"image/"` -> `false`
|
|
704
|
+
* - `""` -> `false`
|
|
705
|
+
* - `"/"` -> `false`
|
|
706
|
+
*/
|
|
707
|
+
declare function isFullMediaType(mediaType: string): boolean;
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Download a file from a URL and return it as a Blob.
|
|
711
|
+
*
|
|
712
|
+
* @param url - The URL to download from.
|
|
713
|
+
* @param options - Optional settings for the download.
|
|
714
|
+
* @param options.maxBytes - Maximum allowed download size in bytes. Defaults to 100 MiB.
|
|
715
|
+
* @param options.abortSignal - An optional abort signal to cancel the download.
|
|
716
|
+
* @returns A Promise that resolves to the downloaded Blob.
|
|
717
|
+
*
|
|
718
|
+
* @throws DownloadError if the download fails or exceeds maxBytes.
|
|
719
|
+
*/
|
|
720
|
+
declare function downloadBlob(url: string, options?: {
|
|
721
|
+
maxBytes?: number;
|
|
722
|
+
abortSignal?: AbortSignal;
|
|
723
|
+
}): Promise<Blob>;
|
|
724
|
+
|
|
725
|
+
declare const symbol: unique symbol;
|
|
726
|
+
declare class DownloadError extends AISDKError {
|
|
727
|
+
private readonly [symbol];
|
|
728
|
+
readonly url: string;
|
|
729
|
+
readonly statusCode?: number;
|
|
730
|
+
readonly statusText?: string;
|
|
731
|
+
constructor({ url, statusCode, statusText, cause, message, }: {
|
|
732
|
+
url: string;
|
|
733
|
+
statusCode?: number;
|
|
734
|
+
statusText?: string;
|
|
735
|
+
message?: string;
|
|
736
|
+
cause?: unknown;
|
|
737
|
+
});
|
|
738
|
+
static isInstance(error: unknown): error is DownloadError;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Fetches a URL while enforcing the SSRF download guard on every hop.
|
|
743
|
+
*
|
|
744
|
+
* Redirects are followed manually (`redirect: 'manual'`) so each hop is
|
|
745
|
+
* validated with {@link validateDownloadUrl} *before* it is requested. Relying
|
|
746
|
+
* on the default `redirect: 'follow'` would issue the request to a redirect
|
|
747
|
+
* target (e.g. an internal address) before we ever see its URL, defeating the
|
|
748
|
+
* SSRF guard.
|
|
749
|
+
*
|
|
750
|
+
* A `redirect: 'manual'` request yields an unreadable opaque response in the
|
|
751
|
+
* browser (and in other spec-compliant fetch implementations), so the redirect
|
|
752
|
+
* target cannot be validated here. In a real browser this is safe to follow
|
|
753
|
+
* natively because SSRF is not reachable (fetch is constrained by CORS and
|
|
754
|
+
* cannot reach a server's internal network or cloud-metadata). On any other
|
|
755
|
+
* runtime we cannot validate the hop, so we fail closed rather than follow it
|
|
756
|
+
* blindly and bypass the SSRF guard.
|
|
757
|
+
*
|
|
758
|
+
* The returned response is the final (non-redirect) response. The caller is
|
|
759
|
+
* responsible for checking `response.ok` and reading the body.
|
|
760
|
+
*
|
|
761
|
+
* @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
|
|
762
|
+
* a redirect cannot be validated on a non-browser runtime.
|
|
763
|
+
*/
|
|
764
|
+
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, }: {
|
|
765
|
+
url: string;
|
|
766
|
+
headers?: HeadersInit;
|
|
767
|
+
abortSignal?: AbortSignal;
|
|
768
|
+
maxRedirects?: number;
|
|
769
|
+
}): Promise<Response>;
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Extracts a 1-based inclusive line range from `text`, auto-detecting the
|
|
773
|
+
* file's line ending (`\r\n`, `\n`, or `\r`, in that priority).
|
|
774
|
+
*
|
|
775
|
+
* Mixed line endings are not supported: detection picks one and uses it for
|
|
776
|
+
* both the split and the rejoin, so files that mix conventions will not slice
|
|
777
|
+
* cleanly. When neither `startLine` nor `endLine` is provided, the input is
|
|
778
|
+
* returned unchanged. `endLine` past EOF clamps to the last line.
|
|
779
|
+
*/
|
|
780
|
+
declare function extractLines({ text, startLine, endLine, }: {
|
|
781
|
+
text: string;
|
|
782
|
+
startLine?: number;
|
|
783
|
+
endLine?: number;
|
|
784
|
+
}): string;
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Extracts the headers from a response object and returns them as a key-value object.
|
|
788
|
+
*
|
|
789
|
+
* @param response - The response object to extract headers from.
|
|
790
|
+
* @returns The headers as a key-value object.
|
|
791
|
+
*/
|
|
792
|
+
declare function extractResponseHeaders(response: Response): {
|
|
793
|
+
[k: string]: string;
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Fetch function type (standardizes the version of fetch used).
|
|
798
|
+
*/
|
|
799
|
+
type FetchFunction = typeof globalThis.fetch;
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Filters `null` and `undefined` values out of a list of values.
|
|
803
|
+
*
|
|
804
|
+
* @param values - The values to filter.
|
|
805
|
+
* @returns A new array containing only non-nullish values.
|
|
806
|
+
*/
|
|
807
|
+
declare function filterNullable<T>(...values: Array<T | undefined | null>): Array<T>;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Creates an ID generator.
|
|
811
|
+
* The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
812
|
+
* Not cryptographically secure.
|
|
813
|
+
*
|
|
814
|
+
* @param alphabet - The alphabet to use for the ID. Default: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
|
|
815
|
+
* @param prefix - The prefix of the ID to generate. Optional.
|
|
816
|
+
* @param separator - The separator between the prefix and the random part of the ID. Default: '-'.
|
|
817
|
+
* @param size - The size of the random part of the ID to generate. Default: 16.
|
|
818
|
+
*/
|
|
819
|
+
declare const createIdGenerator: ({ prefix, size, alphabet, separator, }?: {
|
|
820
|
+
prefix?: string;
|
|
821
|
+
separator?: string;
|
|
822
|
+
size?: number;
|
|
823
|
+
alphabet?: string;
|
|
824
|
+
}) => IdGenerator;
|
|
825
|
+
/**
|
|
826
|
+
* A function that generates an ID.
|
|
827
|
+
*/
|
|
828
|
+
type IdGenerator = () => string;
|
|
829
|
+
/**
|
|
830
|
+
* Generates a 16-character random string to use for IDs.
|
|
831
|
+
* Not cryptographically secure.
|
|
832
|
+
*/
|
|
833
|
+
declare const generateId: IdGenerator;
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
837
|
+
*/
|
|
838
|
+
declare const schemaSymbol: unique symbol;
|
|
839
|
+
type ValidationResult<OBJECT> = {
|
|
840
|
+
success: true;
|
|
841
|
+
value: OBJECT;
|
|
842
|
+
} | {
|
|
843
|
+
success: false;
|
|
844
|
+
error: Error;
|
|
845
|
+
};
|
|
846
|
+
type Schema<OBJECT = unknown> = {
|
|
847
|
+
/**
|
|
848
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
849
|
+
*/
|
|
850
|
+
[schemaSymbol]: true;
|
|
851
|
+
/**
|
|
852
|
+
* Schema type for inference.
|
|
853
|
+
*/
|
|
854
|
+
_type: OBJECT;
|
|
855
|
+
/**
|
|
856
|
+
* Optional. Validates that the structure of a value matches this schema,
|
|
857
|
+
* and returns a typed version of the value if it does.
|
|
858
|
+
*/
|
|
859
|
+
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
860
|
+
/**
|
|
861
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
|
862
|
+
*/
|
|
863
|
+
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
|
864
|
+
};
|
|
865
|
+
/**
|
|
866
|
+
* Creates a schema with deferred creation.
|
|
867
|
+
* This is important to reduce the startup time of the library
|
|
868
|
+
* and to avoid initializing unused validators.
|
|
869
|
+
*
|
|
870
|
+
* @param createValidator A function that creates a schema.
|
|
871
|
+
* @returns A function that returns a schema.
|
|
872
|
+
*/
|
|
873
|
+
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
|
874
|
+
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
|
875
|
+
type ZodSchema<SCHEMA = any> = z3.Schema<SCHEMA, z3.ZodTypeDef, any> | z4.core.$ZodType<SCHEMA, any>;
|
|
876
|
+
type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & StandardJSONSchemaV1<unknown, SCHEMA>;
|
|
877
|
+
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
|
|
878
|
+
type InferSchema<SCHEMA> = SCHEMA extends ZodSchema<infer T> ? T : SCHEMA extends StandardSchema<infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
|
|
879
|
+
/**
|
|
880
|
+
* Create a schema using a JSON Schema.
|
|
881
|
+
*
|
|
882
|
+
* @param jsonSchema The JSON Schema for the schema.
|
|
883
|
+
* @param options.validate Optional. A validation function for the schema.
|
|
884
|
+
*/
|
|
885
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
|
886
|
+
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
887
|
+
}): Schema<OBJECT>;
|
|
888
|
+
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
|
889
|
+
declare function zodSchema<OBJECT>(zodSchema: z4.core.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
|
890
|
+
/**
|
|
891
|
+
* Enables support for references in the schema.
|
|
892
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
|
893
|
+
* However, not all language models and providers support such references.
|
|
894
|
+
* Defaults to `false`.
|
|
895
|
+
*/
|
|
896
|
+
useReferences?: boolean;
|
|
897
|
+
}): Schema<OBJECT>;
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Parses a JSON string into an unknown object.
|
|
901
|
+
*
|
|
902
|
+
* @param text - The JSON string to parse.
|
|
903
|
+
* @returns {JSONValue} - The parsed JSON object.
|
|
904
|
+
*/
|
|
905
|
+
declare function parseJSON(options: {
|
|
906
|
+
text: string;
|
|
907
|
+
schema?: undefined;
|
|
908
|
+
}): Promise<JSONValue>;
|
|
909
|
+
/**
|
|
910
|
+
* Parses a JSON string into a strongly-typed object using the provided schema.
|
|
911
|
+
*
|
|
912
|
+
* @template T - The type of the object to parse the JSON into.
|
|
913
|
+
* @param {string} text - The JSON string to parse.
|
|
914
|
+
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
915
|
+
* @returns {Promise<T>} - The parsed object.
|
|
916
|
+
*/
|
|
917
|
+
declare function parseJSON<T>(options: {
|
|
918
|
+
text: string;
|
|
919
|
+
schema: FlexibleSchema<T>;
|
|
920
|
+
}): Promise<T>;
|
|
921
|
+
type ParseResult<T> = {
|
|
922
|
+
success: true;
|
|
923
|
+
value: T;
|
|
924
|
+
rawValue: unknown;
|
|
925
|
+
} | {
|
|
926
|
+
success: false;
|
|
927
|
+
error: JSONParseError | TypeValidationError;
|
|
928
|
+
rawValue: unknown;
|
|
929
|
+
};
|
|
930
|
+
/**
|
|
931
|
+
* Safely parses a JSON string and returns the result as an object of type `unknown`.
|
|
932
|
+
*
|
|
933
|
+
* @param text - The JSON string to parse.
|
|
934
|
+
* @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
|
|
935
|
+
*/
|
|
936
|
+
declare function safeParseJSON(options: {
|
|
937
|
+
text: string;
|
|
938
|
+
schema?: undefined;
|
|
939
|
+
}): Promise<ParseResult<JSONValue>>;
|
|
940
|
+
/**
|
|
941
|
+
* Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
|
|
942
|
+
*
|
|
943
|
+
* @template T - The type of the object to parse the JSON into.
|
|
944
|
+
* @param {string} text - The JSON string to parse.
|
|
945
|
+
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
946
|
+
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
|
947
|
+
*/
|
|
948
|
+
declare function safeParseJSON<T>(options: {
|
|
949
|
+
text: string;
|
|
950
|
+
schema: FlexibleSchema<T>;
|
|
951
|
+
}): Promise<ParseResult<T>>;
|
|
952
|
+
declare function isParsableJson(input: string): boolean;
|
|
953
|
+
|
|
954
|
+
type ResponseHandler<RETURN_TYPE> = (options: {
|
|
955
|
+
url: string;
|
|
956
|
+
requestBodyValues: unknown;
|
|
957
|
+
response: Response;
|
|
958
|
+
}) => PromiseLike<{
|
|
959
|
+
value: RETURN_TYPE;
|
|
960
|
+
rawValue?: unknown;
|
|
961
|
+
responseHeaders?: Record<string, string>;
|
|
962
|
+
}>;
|
|
963
|
+
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
|
964
|
+
errorSchema: FlexibleSchema<T>;
|
|
965
|
+
errorToMessage: (error: T) => string;
|
|
966
|
+
isRetryable?: (response: Response, error?: T) => boolean;
|
|
967
|
+
}) => ResponseHandler<APICallError>;
|
|
968
|
+
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
969
|
+
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
970
|
+
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
971
|
+
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
972
|
+
|
|
973
|
+
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
|
974
|
+
url: string;
|
|
975
|
+
headers?: Record<string, string | undefined>;
|
|
976
|
+
failedResponseHandler: ResponseHandler<Error>;
|
|
977
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
978
|
+
abortSignal?: AbortSignal;
|
|
979
|
+
fetch?: FetchFunction;
|
|
980
|
+
}) => Promise<{
|
|
981
|
+
value: T;
|
|
982
|
+
rawValue?: unknown;
|
|
983
|
+
responseHeaders?: Record<string, string>;
|
|
984
|
+
}>;
|
|
985
|
+
|
|
986
|
+
declare function getRuntimeEnvironmentUserAgent(globalThisAny?: any): string;
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* Checks if an object has required keys.
|
|
990
|
+
* @param OBJECT - The object to check.
|
|
991
|
+
* @returns True if the object has required keys, false otherwise.
|
|
992
|
+
*/
|
|
993
|
+
type HasRequiredKey<OBJECT> = {} extends OBJECT ? false : true;
|
|
994
|
+
|
|
995
|
+
declare function injectJsonInstructionIntoMessages({ messages, schema, schemaPrefix, schemaSuffix, }: {
|
|
996
|
+
messages: LanguageModelV4Prompt;
|
|
997
|
+
schema?: JSONSchema7;
|
|
998
|
+
schemaPrefix?: string;
|
|
999
|
+
schemaSuffix?: string;
|
|
1000
|
+
}): LanguageModelV4Prompt;
|
|
1001
|
+
|
|
1002
|
+
declare function isAbortError(error: unknown): error is Error;
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Returns `true` when running in a browser.
|
|
1006
|
+
*
|
|
1007
|
+
* Detection keys on the presence of a global `window`, matching the browser
|
|
1008
|
+
* check used elsewhere in this package (see `getRuntimeEnvironmentUserAgent`)
|
|
1009
|
+
* so the SDK has a single, consistent definition of "browser". Server runtimes
|
|
1010
|
+
* (Node.js, Deno, Bun, edge/workers) do not define `window`.
|
|
1011
|
+
*/
|
|
1012
|
+
declare function isBrowserRuntime(globalThisAny?: any): boolean;
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Type-guard for Node.js `Buffer` instances.
|
|
1016
|
+
*
|
|
1017
|
+
* Uses optional chaining on `globalThis.Buffer` so it returns `false` in
|
|
1018
|
+
* runtimes where `Buffer` is not available (e.g. CloudFlare Workers).
|
|
1019
|
+
*/
|
|
1020
|
+
declare function isBuffer(value: unknown): value is Buffer;
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* Returns true when `url` has the same origin (scheme + host + port) as
|
|
1024
|
+
* `baseUrl`.
|
|
1025
|
+
*
|
|
1026
|
+
* Used to decide whether provider credentials may be attached to a request to a
|
|
1027
|
+
* URL taken from a provider response (e.g. a polling or media-download URL).
|
|
1028
|
+
* Credentials must only be sent to the provider's own origin; a response that
|
|
1029
|
+
* names a foreign host (a CDN, or an attacker-controlled host if the response
|
|
1030
|
+
* is tampered with) must not receive the API key.
|
|
1031
|
+
*
|
|
1032
|
+
* Returns false if either value is not a valid absolute URL (fail-closed).
|
|
1033
|
+
*/
|
|
1034
|
+
declare function isSameOrigin(url: string, baseUrl: string): boolean;
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Type guard that checks whether a value is not `null` or `undefined`.
|
|
1038
|
+
*
|
|
1039
|
+
* @template T - The type of the value to check.
|
|
1040
|
+
* @param value - The value to check.
|
|
1041
|
+
* @returns `true` if the value is neither `null` nor `undefined`, otherwise `false`.
|
|
1042
|
+
*/
|
|
1043
|
+
declare function isNonNullable<T>(value: T | undefined | null): value is NonNullable<T>;
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* Checks whether a value is a provider reference (a mapping of provider names
|
|
1047
|
+
* to provider-specific identifiers) as opposed to raw bytes, a URL, or a
|
|
1048
|
+
* tagged `{ type: ... }` object.
|
|
1049
|
+
*/
|
|
1050
|
+
declare function isProviderReference(data: unknown): data is SharedV4ProviderReference;
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Checks if the given URL is supported natively by the model.
|
|
1054
|
+
*
|
|
1055
|
+
* @param mediaType - The media type of the URL. Case-sensitive. May be a full
|
|
1056
|
+
* `type/subtype`, a wildcard `type/*`, or just the
|
|
1057
|
+
* top-level segment (e.g. `image`).
|
|
1058
|
+
* @param url - The URL to check.
|
|
1059
|
+
* @param supportedUrls - A record where keys are case-sensitive media types (or '*')
|
|
1060
|
+
* and values are arrays of RegExp patterns for URLs.
|
|
1061
|
+
*
|
|
1062
|
+
* @returns `true` if the URL matches a pattern under the specific media type
|
|
1063
|
+
* or the wildcard '*', `false` otherwise.
|
|
1064
|
+
*/
|
|
1065
|
+
declare function isUrlSupported({ mediaType, url, supportedUrls, }: {
|
|
1066
|
+
mediaType: string;
|
|
1067
|
+
url: string;
|
|
1068
|
+
supportedUrls: Record<string, RegExp[]>;
|
|
1069
|
+
}): boolean;
|
|
1070
|
+
|
|
1071
|
+
declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
|
|
1072
|
+
apiKey: string | undefined;
|
|
1073
|
+
environmentVariableName: string;
|
|
1074
|
+
apiKeyParameterName?: string;
|
|
1075
|
+
description: string;
|
|
1076
|
+
}): string;
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Loads an optional `string` setting from the environment or a parameter.
|
|
1080
|
+
*
|
|
1081
|
+
* @param settingValue - The setting value.
|
|
1082
|
+
* @param environmentVariableName - The environment variable name.
|
|
1083
|
+
* @returns The setting value.
|
|
1084
|
+
*/
|
|
1085
|
+
declare function loadOptionalSetting({ settingValue, environmentVariableName, }: {
|
|
1086
|
+
settingValue: string | undefined;
|
|
1087
|
+
environmentVariableName: string;
|
|
1088
|
+
}): string | undefined;
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Loads a `string` setting from the environment or a parameter.
|
|
1092
|
+
*
|
|
1093
|
+
* @param settingValue - The setting value.
|
|
1094
|
+
* @param environmentVariableName - The environment variable name.
|
|
1095
|
+
* @param settingName - The setting name.
|
|
1096
|
+
* @param description - The description of the setting.
|
|
1097
|
+
* @returns The setting value.
|
|
1098
|
+
*/
|
|
1099
|
+
declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
|
|
1100
|
+
settingValue: string | undefined;
|
|
1101
|
+
environmentVariableName: string;
|
|
1102
|
+
settingName: string;
|
|
1103
|
+
description: string;
|
|
1104
|
+
}): string;
|
|
1105
|
+
|
|
1106
|
+
type ReasoningLevel = Exclude<LanguageModelV4CallOptions['reasoning'], 'none' | 'provider-default' | undefined>;
|
|
1107
|
+
declare function isCustomReasoning(reasoning: LanguageModelV4CallOptions['reasoning']): reasoning is Exclude<LanguageModelV4CallOptions['reasoning'], 'provider-default' | undefined>;
|
|
1108
|
+
/**
|
|
1109
|
+
* Maps a top-level reasoning level to a provider-specific effort string using
|
|
1110
|
+
* the given effort map. Pushes a compatibility warning if the reasoning level
|
|
1111
|
+
* maps to a different string, or an unsupported warning if the level is not
|
|
1112
|
+
* present in the map.
|
|
1113
|
+
*
|
|
1114
|
+
* @returns The mapped effort string, or `undefined` if the level is not
|
|
1115
|
+
* supported.
|
|
1116
|
+
*/
|
|
1117
|
+
declare function mapReasoningToProviderEffort<T extends string>({ reasoning, effortMap, warnings, }: {
|
|
1118
|
+
reasoning: ReasoningLevel;
|
|
1119
|
+
effortMap: Partial<Record<ReasoningLevel, T>>;
|
|
1120
|
+
warnings: SharedV4Warning[];
|
|
1121
|
+
}): T | undefined;
|
|
1122
|
+
/**
|
|
1123
|
+
* Maps a top-level reasoning level to an absolute token budget by multiplying
|
|
1124
|
+
* the model's max output tokens by a percentage from the budget percentages
|
|
1125
|
+
* map. The result is clamped between `minReasoningBudget` (default 1024) and
|
|
1126
|
+
* `maxReasoningBudget`. Pushes an unsupported warning if the level is not
|
|
1127
|
+
* present in the budget percentages map.
|
|
1128
|
+
*
|
|
1129
|
+
* @returns The computed token budget, or `undefined` if the level is not
|
|
1130
|
+
* supported.
|
|
1131
|
+
*/
|
|
1132
|
+
declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxReasoningBudget, minReasoningBudget, budgetPercentages, warnings, }: {
|
|
1133
|
+
reasoning: ReasoningLevel;
|
|
1134
|
+
maxOutputTokens: number;
|
|
1135
|
+
maxReasoningBudget: number;
|
|
1136
|
+
minReasoningBudget?: number;
|
|
1137
|
+
budgetPercentages?: Partial<Record<ReasoningLevel, number>>;
|
|
1138
|
+
warnings: SharedV4Warning[];
|
|
1139
|
+
}): number | undefined;
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* A value that can be provided either synchronously or as a promise-like.
|
|
1143
|
+
*/
|
|
1144
|
+
type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* Maps a media type to its corresponding file extension.
|
|
1148
|
+
* It was originally introduced to set a filename for audio file uploads
|
|
1149
|
+
* in https://github.com/vercel/ai/pull/8159.
|
|
1150
|
+
*
|
|
1151
|
+
* @param mediaType The media type to map.
|
|
1152
|
+
* @returns The corresponding file extension
|
|
1153
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
|
|
1154
|
+
*/
|
|
1155
|
+
declare function mediaTypeToExtension(mediaType: string): string;
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Normalizes different header inputs into a plain record with lower-case keys.
|
|
1159
|
+
* Entries with `undefined` or `null` values are removed.
|
|
1160
|
+
*
|
|
1161
|
+
* @param headers - Input headers (`Headers`, tuples array, plain record) to normalize.
|
|
1162
|
+
* @returns A record containing the normalized header entries.
|
|
1163
|
+
*/
|
|
1164
|
+
declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
1168
|
+
*/
|
|
1169
|
+
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
|
1170
|
+
stream: ReadableStream<Uint8Array>;
|
|
1171
|
+
schema: FlexibleSchema<T>;
|
|
1172
|
+
}): ReadableStream<ParseResult<T>>;
|
|
1173
|
+
|
|
1174
|
+
declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
|
|
1175
|
+
provider: string;
|
|
1176
|
+
providerOptions: Record<string, unknown> | undefined;
|
|
1177
|
+
schema: FlexibleSchema<OPTIONS>;
|
|
1178
|
+
}): Promise<OPTIONS | undefined>;
|
|
1179
|
+
|
|
1180
|
+
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
|
1181
|
+
url: string;
|
|
1182
|
+
headers?: Record<string, string | undefined>;
|
|
1183
|
+
body: unknown;
|
|
1184
|
+
failedResponseHandler: ResponseHandler<APICallError>;
|
|
1185
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1186
|
+
abortSignal?: AbortSignal;
|
|
1187
|
+
fetch?: FetchFunction;
|
|
1188
|
+
}) => Promise<{
|
|
1189
|
+
value: T;
|
|
1190
|
+
rawValue?: unknown;
|
|
1191
|
+
responseHeaders?: Record<string, string>;
|
|
1192
|
+
}>;
|
|
1193
|
+
declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
|
1194
|
+
url: string;
|
|
1195
|
+
headers?: Record<string, string | undefined>;
|
|
1196
|
+
formData: FormData;
|
|
1197
|
+
failedResponseHandler: ResponseHandler<APICallError>;
|
|
1198
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1199
|
+
abortSignal?: AbortSignal;
|
|
1200
|
+
fetch?: FetchFunction;
|
|
1201
|
+
}) => Promise<{
|
|
1202
|
+
value: T;
|
|
1203
|
+
rawValue?: unknown;
|
|
1204
|
+
responseHeaders?: Record<string, string>;
|
|
1205
|
+
}>;
|
|
1206
|
+
declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
|
1207
|
+
url: string;
|
|
1208
|
+
headers?: Record<string, string | undefined>;
|
|
1209
|
+
body: {
|
|
1210
|
+
content: string | FormData | Uint8Array;
|
|
1211
|
+
values: unknown;
|
|
1212
|
+
};
|
|
1213
|
+
failedResponseHandler: ResponseHandler<Error>;
|
|
1214
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1215
|
+
abortSignal?: AbortSignal;
|
|
1216
|
+
fetch?: FetchFunction;
|
|
1217
|
+
}) => Promise<{
|
|
1218
|
+
value: T;
|
|
1219
|
+
rawValue?: unknown;
|
|
1220
|
+
responseHeaders?: Record<string, string>;
|
|
1221
|
+
}>;
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* A context object that is passed into tool execution.
|
|
1225
|
+
*/
|
|
1226
|
+
type Context = Record<string, unknown>;
|
|
1227
|
+
|
|
1228
|
+
/**
|
|
1229
|
+
* A tool that is guaranteed to expose an execute function.
|
|
1230
|
+
*/
|
|
1231
|
+
type ExecutableTool<TOOL extends Tool = Tool> = TOOL & {
|
|
1232
|
+
execute: NonNullable<TOOL['execute']>;
|
|
1233
|
+
};
|
|
1234
|
+
/**
|
|
1235
|
+
* Checks whether a tool exposes an execute function.
|
|
1236
|
+
*/
|
|
1237
|
+
declare function isExecutableTool<TOOL extends Tool>(tool: TOOL | undefined): tool is ExecutableTool<TOOL>;
|
|
1238
|
+
|
|
1239
|
+
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Tool approval request prompt part.
|
|
1243
|
+
*/
|
|
1244
|
+
type ToolApprovalRequest = {
|
|
1245
|
+
type: 'tool-approval-request';
|
|
1246
|
+
/**
|
|
1247
|
+
* ID of the tool approval.
|
|
1248
|
+
*/
|
|
1249
|
+
approvalId: string;
|
|
1250
|
+
/**
|
|
1251
|
+
* ID of the tool call that the approval request is for.
|
|
1252
|
+
*/
|
|
1253
|
+
toolCallId: string;
|
|
1254
|
+
/**
|
|
1255
|
+
* Flag indicating whether the tool was automatically approved or denied.
|
|
1256
|
+
*
|
|
1257
|
+
* @default false
|
|
1258
|
+
*/
|
|
1259
|
+
isAutomatic?: boolean;
|
|
1260
|
+
/**
|
|
1261
|
+
* HMAC-SHA256 signature binding this approval to its tool call.
|
|
1262
|
+
* Present only when `experimental_toolApprovalSecret` is configured.
|
|
1263
|
+
*/
|
|
1264
|
+
signature?: string;
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
|
1269
|
+
*/
|
|
1270
|
+
type AssistantModelMessage = {
|
|
1271
|
+
role: 'assistant';
|
|
1272
|
+
content: AssistantContent;
|
|
1273
|
+
/**
|
|
1274
|
+
* Additional provider-specific metadata. They are passed through
|
|
1275
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1276
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1277
|
+
*/
|
|
1278
|
+
providerOptions?: ProviderOptions;
|
|
1279
|
+
};
|
|
1280
|
+
/**
|
|
1281
|
+
* Content of an assistant message.
|
|
1282
|
+
* It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
|
1283
|
+
*/
|
|
1284
|
+
type AssistantContent = string | Array<TextPart | CustomPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* A system message. It can contain system information.
|
|
1288
|
+
*
|
|
1289
|
+
* Note: using the "system" part of the prompt is strongly preferred
|
|
1290
|
+
* to increase the resilience against prompt injection attacks,
|
|
1291
|
+
* and because not all providers support several system messages.
|
|
1292
|
+
*/
|
|
1293
|
+
type SystemModelMessage = {
|
|
1294
|
+
role: 'system';
|
|
1295
|
+
content: string;
|
|
1296
|
+
/**
|
|
1297
|
+
* Additional provider-specific metadata. They are passed through
|
|
1298
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1299
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1300
|
+
*/
|
|
1301
|
+
providerOptions?: ProviderOptions;
|
|
1302
|
+
};
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* Tool approval response prompt part.
|
|
1306
|
+
*/
|
|
1307
|
+
type ToolApprovalResponse = {
|
|
1308
|
+
type: 'tool-approval-response';
|
|
1309
|
+
/**
|
|
1310
|
+
* ID of the tool approval.
|
|
1311
|
+
*/
|
|
1312
|
+
approvalId: string;
|
|
1313
|
+
/**
|
|
1314
|
+
* Flag indicating whether the approval was granted or denied.
|
|
1315
|
+
*/
|
|
1316
|
+
approved: boolean;
|
|
1317
|
+
/**
|
|
1318
|
+
* Optional reason for the approval or denial.
|
|
1319
|
+
*/
|
|
1320
|
+
reason?: string;
|
|
1321
|
+
/**
|
|
1322
|
+
* Flag indicating whether the tool call is provider-executed.
|
|
1323
|
+
* Only provider-executed tool approval responses should be sent to the model.
|
|
1324
|
+
*/
|
|
1325
|
+
providerExecuted?: boolean;
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* A tool message. It contains the result of one or more tool calls.
|
|
1330
|
+
*/
|
|
1331
|
+
type ToolModelMessage = {
|
|
1332
|
+
role: 'tool';
|
|
1333
|
+
content: ToolContent;
|
|
1334
|
+
/**
|
|
1335
|
+
* Additional provider-specific metadata. They are passed through
|
|
1336
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1337
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1338
|
+
*/
|
|
1339
|
+
providerOptions?: ProviderOptions;
|
|
1340
|
+
};
|
|
1341
|
+
/**
|
|
1342
|
+
* Content of a tool message. It is an array of tool result parts.
|
|
1343
|
+
*/
|
|
1344
|
+
type ToolContent = Array<ToolResultPart | ToolApprovalResponse>;
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* A user message. It can contain text or a combination of text and images.
|
|
1348
|
+
*/
|
|
1349
|
+
type UserModelMessage = {
|
|
1350
|
+
role: 'user';
|
|
1351
|
+
content: UserContent;
|
|
1352
|
+
/**
|
|
1353
|
+
* Additional provider-specific metadata. They are passed through
|
|
1354
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1355
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1356
|
+
*/
|
|
1357
|
+
providerOptions?: ProviderOptions;
|
|
1358
|
+
};
|
|
1359
|
+
/**
|
|
1360
|
+
* Content of a user message. It can be a string or an array of text and image parts.
|
|
1361
|
+
*/
|
|
1362
|
+
type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
|
1363
|
+
|
|
1364
|
+
/**
|
|
1365
|
+
* A message that can be used in the `messages` field of a prompt.
|
|
1366
|
+
* It can be a user message, an assistant message, or a tool message.
|
|
1367
|
+
*/
|
|
1368
|
+
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* Options for executing a command in the sandbox via `run` or `spawn`.
|
|
1372
|
+
*/
|
|
1373
|
+
type SandboxProcessOptions = {
|
|
1374
|
+
/**
|
|
1375
|
+
* Command to execute in the sandbox.
|
|
1376
|
+
*/
|
|
1377
|
+
command: string;
|
|
1378
|
+
/**
|
|
1379
|
+
* Working directory to execute the command in.
|
|
1380
|
+
*/
|
|
1381
|
+
workingDirectory?: string;
|
|
1382
|
+
/**
|
|
1383
|
+
* Environment variables to set for this command. Merged with the
|
|
1384
|
+
* sandbox's default environment; values here take precedence.
|
|
1385
|
+
* Supporting environment variables as an option is preferable from a
|
|
1386
|
+
* security perspective, e.g. to avoid them leaking in logs.
|
|
1387
|
+
*/
|
|
1388
|
+
env?: Record<string, string>;
|
|
1389
|
+
/**
|
|
1390
|
+
* Signal that can be used to abort the command. When aborted, the running
|
|
1391
|
+
* process is killed; for `spawn`, `wait()` rejects with the abort reason.
|
|
1392
|
+
*/
|
|
1393
|
+
abortSignal?: AbortSignal;
|
|
1394
|
+
};
|
|
1395
|
+
/**
|
|
1396
|
+
* Options for reading a file from the sandbox.
|
|
1397
|
+
*/
|
|
1398
|
+
type ReadFileOptions = {
|
|
1399
|
+
/**
|
|
1400
|
+
* Path of the file to read.
|
|
1401
|
+
*/
|
|
1402
|
+
path: string;
|
|
1403
|
+
/**
|
|
1404
|
+
* Signal that can be used to abort the read.
|
|
1405
|
+
*/
|
|
1406
|
+
abortSignal?: AbortSignal;
|
|
1407
|
+
};
|
|
1408
|
+
/**
|
|
1409
|
+
* Options for writing a file to the sandbox. `CONTENT` is the payload written
|
|
1410
|
+
* to the file: a byte stream, raw bytes, or a string.
|
|
1411
|
+
*/
|
|
1412
|
+
type WriteFileOptions<CONTENT> = {
|
|
1413
|
+
/**
|
|
1414
|
+
* Path of the file to write.
|
|
1415
|
+
*/
|
|
1416
|
+
path: string;
|
|
1417
|
+
/**
|
|
1418
|
+
* Content to write to the file.
|
|
1419
|
+
*/
|
|
1420
|
+
content: CONTENT;
|
|
1421
|
+
/**
|
|
1422
|
+
* Signal that can be used to abort the write.
|
|
1423
|
+
*/
|
|
1424
|
+
abortSignal?: AbortSignal;
|
|
1425
|
+
};
|
|
1426
|
+
/**
|
|
1427
|
+
* Sandbox session that can execute commands and read/write files.
|
|
1428
|
+
*/
|
|
1429
|
+
type SandboxSession = {
|
|
1430
|
+
/**
|
|
1431
|
+
* Description of the sandbox environment that can be added to the agent's instructions
|
|
1432
|
+
* so that the agent knows about relevant details such as the root directory, exposed
|
|
1433
|
+
* ports, the public hostname, etc.
|
|
1434
|
+
*/
|
|
1435
|
+
readonly description: string;
|
|
1436
|
+
/**
|
|
1437
|
+
* Read one file from the sandbox as a stream of bytes. Resolves to `null`
|
|
1438
|
+
* when the file does not exist.
|
|
1439
|
+
*
|
|
1440
|
+
* Relative path handling is implementation-defined. This is the lowest-level
|
|
1441
|
+
* read primitive; prefer `readBinaryFile` or `readTextFile` unless you need
|
|
1442
|
+
* to stream bytes.
|
|
1443
|
+
*/
|
|
1444
|
+
readonly readFile: (options: ReadFileOptions) => PromiseLike<ReadableStream<Uint8Array> | null>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Read one file from the sandbox as raw bytes. Resolves to `null` when the
|
|
1447
|
+
* file does not exist.
|
|
1448
|
+
*/
|
|
1449
|
+
readonly readBinaryFile: (options: ReadFileOptions) => PromiseLike<Uint8Array | null>;
|
|
1450
|
+
/**
|
|
1451
|
+
* Read one text file from the sandbox, decoded using the requested encoding.
|
|
1452
|
+
* Resolves to `null` when the file does not exist.
|
|
1453
|
+
*
|
|
1454
|
+
* Line ranges are 1-based and inclusive. When `endLine` is past EOF the read
|
|
1455
|
+
* returns through EOF without error.
|
|
1456
|
+
*/
|
|
1457
|
+
readonly readTextFile: (options: ReadFileOptions & {
|
|
1458
|
+
/**
|
|
1459
|
+
* Text encoding used to decode the file bytes. Defaults to `"utf-8"`.
|
|
1460
|
+
*/
|
|
1461
|
+
encoding?: string;
|
|
1462
|
+
/**
|
|
1463
|
+
* 1-based inclusive start line. Defaults to 1.
|
|
1464
|
+
*/
|
|
1465
|
+
startLine?: number;
|
|
1466
|
+
/**
|
|
1467
|
+
* 1-based inclusive end line. When past the file's line count, the read
|
|
1468
|
+
* returns through EOF without error.
|
|
1469
|
+
*/
|
|
1470
|
+
endLine?: number;
|
|
1471
|
+
}) => PromiseLike<string | null>;
|
|
1472
|
+
/**
|
|
1473
|
+
* Write one file to the sandbox from a stream of bytes. Creates parent
|
|
1474
|
+
* directories recursively and overwrites any existing file.
|
|
1475
|
+
*
|
|
1476
|
+
* This is the lowest-level write primitive; prefer `writeBinaryFile` or
|
|
1477
|
+
* `writeTextFile` when the full content is already materialized in memory.
|
|
1478
|
+
*/
|
|
1479
|
+
readonly writeFile: (options: WriteFileOptions<ReadableStream<Uint8Array>>) => PromiseLike<void>;
|
|
1480
|
+
/**
|
|
1481
|
+
* Write one file to the sandbox from raw bytes. Creates parent directories
|
|
1482
|
+
* recursively and overwrites any existing file.
|
|
1483
|
+
*/
|
|
1484
|
+
readonly writeBinaryFile: (options: WriteFileOptions<Uint8Array>) => PromiseLike<void>;
|
|
1485
|
+
/**
|
|
1486
|
+
* Write one file to the sandbox from a string, encoded using the requested
|
|
1487
|
+
* encoding. Creates parent directories recursively and overwrites any
|
|
1488
|
+
* existing file.
|
|
1489
|
+
*/
|
|
1490
|
+
readonly writeTextFile: (options: WriteFileOptions<string> & {
|
|
1491
|
+
/**
|
|
1492
|
+
* Text encoding used to encode the string to bytes. Defaults to `"utf-8"`.
|
|
1493
|
+
*/
|
|
1494
|
+
encoding?: string;
|
|
1495
|
+
}) => PromiseLike<void>;
|
|
1496
|
+
/**
|
|
1497
|
+
* Spawn a long-running process in the sandbox. Returns immediately with a
|
|
1498
|
+
* handle that streams stdout/stderr, can be waited on, and can be killed.
|
|
1499
|
+
*
|
|
1500
|
+
* `run` is conceptually a thin wrapper over this primitive: spawn,
|
|
1501
|
+
* collect both streams to strings, await `wait()`, return the result.
|
|
1502
|
+
*/
|
|
1503
|
+
readonly spawn: (options: SandboxProcessOptions) => PromiseLike<SandboxProcess>;
|
|
1504
|
+
/**
|
|
1505
|
+
* Run a command in the sandbox.
|
|
1506
|
+
*/
|
|
1507
|
+
readonly run: (options: SandboxProcessOptions) => PromiseLike<{
|
|
1508
|
+
/**
|
|
1509
|
+
* Exit code returned by the command.
|
|
1510
|
+
*/
|
|
1511
|
+
exitCode: number;
|
|
1512
|
+
/**
|
|
1513
|
+
* Standard output produced by the command.
|
|
1514
|
+
*/
|
|
1515
|
+
stdout: string;
|
|
1516
|
+
/**
|
|
1517
|
+
* Standard error produced by the command.
|
|
1518
|
+
*/
|
|
1519
|
+
stderr: string;
|
|
1520
|
+
}>;
|
|
1521
|
+
};
|
|
1522
|
+
/**
|
|
1523
|
+
* Handle to a long-running process started via `SandboxSession.spawn`.
|
|
1524
|
+
*/
|
|
1525
|
+
type SandboxProcess = {
|
|
1526
|
+
/**
|
|
1527
|
+
* Process identifier, if the sandbox implementation exposes one.
|
|
1528
|
+
*/
|
|
1529
|
+
readonly pid?: number;
|
|
1530
|
+
/**
|
|
1531
|
+
* Stream of bytes written by the process to standard output.
|
|
1532
|
+
*/
|
|
1533
|
+
readonly stdout: ReadableStream<Uint8Array>;
|
|
1534
|
+
/**
|
|
1535
|
+
* Stream of bytes written by the process to standard error.
|
|
1536
|
+
*/
|
|
1537
|
+
readonly stderr: ReadableStream<Uint8Array>;
|
|
1538
|
+
/**
|
|
1539
|
+
* Resolve when the process exits, yielding its exit code.
|
|
1540
|
+
*/
|
|
1541
|
+
wait(): PromiseLike<{
|
|
1542
|
+
exitCode: number;
|
|
1543
|
+
}>;
|
|
1544
|
+
/**
|
|
1545
|
+
* Terminate the process. Idempotent.
|
|
1546
|
+
*/
|
|
1547
|
+
kill(): PromiseLike<void>;
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1550
|
+
/**
|
|
1551
|
+
* Additional options that are sent into each tool execution.
|
|
1552
|
+
*/
|
|
1553
|
+
interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
|
|
1554
|
+
/**
|
|
1555
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1556
|
+
*/
|
|
1557
|
+
toolCallId: string;
|
|
1558
|
+
/**
|
|
1559
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
|
1560
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
|
1561
|
+
*/
|
|
1562
|
+
messages: ModelMessage[];
|
|
1563
|
+
/**
|
|
1564
|
+
* An optional abort signal that indicates that the overall operation should be aborted.
|
|
1565
|
+
*/
|
|
1566
|
+
abortSignal?: AbortSignal;
|
|
1567
|
+
/**
|
|
1568
|
+
* Tool context as defined by the tool's context schema.
|
|
1569
|
+
* The tool context is specific to the tool and is passed to the tool execution.
|
|
1570
|
+
*
|
|
1571
|
+
* Treat the context object as immutable inside tools.
|
|
1572
|
+
* Mutating the context object can lead to race conditions and unexpected results
|
|
1573
|
+
* when tools are called in parallel.
|
|
1574
|
+
*
|
|
1575
|
+
* If you need to mutate the context, analyze the tool calls and results
|
|
1576
|
+
* in `prepareStep` and update it there.
|
|
1577
|
+
*/
|
|
1578
|
+
context: CONTEXT;
|
|
1579
|
+
/**
|
|
1580
|
+
* The sandbox environment that the tool is operating in.
|
|
1581
|
+
*/
|
|
1582
|
+
experimental_sandbox?: SandboxSession;
|
|
1583
|
+
}
|
|
1584
|
+
/**
|
|
1585
|
+
* Function that executes the tool and returns either a single result or a stream of results.
|
|
1586
|
+
*/
|
|
1587
|
+
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1588
|
+
|
|
1589
|
+
/**
|
|
1590
|
+
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
1591
|
+
*
|
|
1592
|
+
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
1593
|
+
*/
|
|
1594
|
+
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: {
|
|
1595
|
+
/**
|
|
1596
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1597
|
+
*/
|
|
1598
|
+
toolCallId: string;
|
|
1599
|
+
/**
|
|
1600
|
+
* Messages that were sent to the language model to initiate the response that contained the tool call.
|
|
1601
|
+
* The messages **do not** include the system prompt nor the assistant response that contained the tool call.
|
|
1602
|
+
*/
|
|
1603
|
+
messages: ModelMessage[];
|
|
1604
|
+
/**
|
|
1605
|
+
* Tool context as defined by the tool's context schema.
|
|
1606
|
+
* The tool context is specific to the tool and is passed to the tool execution.
|
|
1607
|
+
*
|
|
1608
|
+
* Treat the context object as immutable inside tools.
|
|
1609
|
+
* Mutating the context object can lead to race conditions and unexpected results
|
|
1610
|
+
* when tools are called in parallel.
|
|
1611
|
+
*
|
|
1612
|
+
* If you need to mutate the context, analyze the tool calls and results
|
|
1613
|
+
* in `prepareStep` and update it there.
|
|
1614
|
+
*/
|
|
1615
|
+
context: CONTEXT;
|
|
1616
|
+
}) => boolean | PromiseLike<boolean>;
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Helper type to determine the outputSchema and execute function properties of a tool.
|
|
1620
|
+
*/
|
|
1621
|
+
type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context | unknown | never> = NeverOptional<OUTPUT, {
|
|
1622
|
+
/**
|
|
1623
|
+
* The optional schema of the output that the tool produces.
|
|
1624
|
+
*
|
|
1625
|
+
* If not provided, the output shape will be inferred from the execute function.
|
|
1626
|
+
*/
|
|
1627
|
+
outputSchema?: FlexibleSchema<OUTPUT>;
|
|
1628
|
+
/**
|
|
1629
|
+
* An async function that is called with the arguments from the tool call and produces a result.
|
|
1630
|
+
* If not provided, the tool will not be executed automatically.
|
|
1631
|
+
*
|
|
1632
|
+
* @args is the input of the tool call.
|
|
1633
|
+
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
1634
|
+
*/
|
|
1635
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1636
|
+
} | {
|
|
1637
|
+
/**
|
|
1638
|
+
* The schema of the output that the tool produces.
|
|
1639
|
+
*
|
|
1640
|
+
* Required when no execute function is provided.
|
|
1641
|
+
*/
|
|
1642
|
+
outputSchema: FlexibleSchema<OUTPUT>;
|
|
1643
|
+
execute?: never;
|
|
1644
|
+
}>;
|
|
1645
|
+
/**
|
|
1646
|
+
* Common properties shared by all tool kinds.
|
|
1647
|
+
*/
|
|
1648
|
+
type BaseTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = {
|
|
1649
|
+
/**
|
|
1650
|
+
* An optional title of the tool.
|
|
1651
|
+
*
|
|
1652
|
+
* @deprecated Use `providerMetadata` for source-specific tool display metadata.
|
|
1653
|
+
*/
|
|
1654
|
+
title?: string;
|
|
1655
|
+
/**
|
|
1656
|
+
* Additional provider-specific metadata. They are passed through
|
|
1657
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1658
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1659
|
+
*/
|
|
1660
|
+
providerOptions?: ProviderOptions;
|
|
1661
|
+
/**
|
|
1662
|
+
* Optional metadata about the tool itself (e.g. its source).
|
|
1663
|
+
*
|
|
1664
|
+
* Unlike `providerOptions`, this metadata is not sent to the language
|
|
1665
|
+
* model. Instead, it is propagated onto the resulting tool call's
|
|
1666
|
+
* `toolMetadata` so consumers can read it from tool call / result parts
|
|
1667
|
+
* and UI message parts. This is useful for sources of dynamic tools (e.g.
|
|
1668
|
+
* an MCP server) to identify themselves.
|
|
1669
|
+
*/
|
|
1670
|
+
metadata?: JSONObject;
|
|
1671
|
+
/**
|
|
1672
|
+
* The schema of the input that the tool expects.
|
|
1673
|
+
* The language model will use this to generate the input.
|
|
1674
|
+
* It is also used to validate the output of the language model.
|
|
1675
|
+
*
|
|
1676
|
+
* You can use descriptions on the schema properties to make the input understandable for the language model.
|
|
1677
|
+
*/
|
|
1678
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
1679
|
+
/**
|
|
1680
|
+
* An optional schema describing the context that the tool expects.
|
|
1681
|
+
*
|
|
1682
|
+
* The context is passed to execute function as part of the execution options.
|
|
1683
|
+
*/
|
|
1684
|
+
contextSchema?: FlexibleSchema<CONTEXT>;
|
|
1685
|
+
/**
|
|
1686
|
+
* Whether the tool needs approval before it can be executed.
|
|
1687
|
+
*
|
|
1688
|
+
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
1689
|
+
*/
|
|
1690
|
+
needsApproval?: boolean | ToolNeedsApprovalFunction<[
|
|
1691
|
+
INPUT
|
|
1692
|
+
] extends [never] ? unknown : INPUT, NoInfer<CONTEXT>>;
|
|
1693
|
+
/**
|
|
1694
|
+
* Optional function that is called when the argument streaming starts.
|
|
1695
|
+
* Only called when the tool is used in a streaming context.
|
|
1696
|
+
*/
|
|
1697
|
+
onInputStart?: (options: ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1698
|
+
/**
|
|
1699
|
+
* Optional function that is called when an argument streaming delta is available.
|
|
1700
|
+
* Only called when the tool is used in a streaming context.
|
|
1701
|
+
*/
|
|
1702
|
+
onInputDelta?: (options: {
|
|
1703
|
+
inputTextDelta: string;
|
|
1704
|
+
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1705
|
+
/**
|
|
1706
|
+
* Optional function that is called when a tool call can be started,
|
|
1707
|
+
* even if the execute function is not provided.
|
|
1708
|
+
*/
|
|
1709
|
+
onInputAvailable?: (options: {
|
|
1710
|
+
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
1711
|
+
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1712
|
+
/**
|
|
1713
|
+
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1714
|
+
*
|
|
1715
|
+
* If not provided, the tool result will be sent as a JSON object.
|
|
1716
|
+
*
|
|
1717
|
+
* This function is invoked on the server by `convertToModelMessages`, so ensure that you pass the same "tools" (ToolSet) to both "convertToModelMessages" and "streamText" (or other generation APIs).
|
|
1718
|
+
*/
|
|
1719
|
+
toModelOutput?: (options: {
|
|
1720
|
+
/**
|
|
1721
|
+
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1722
|
+
*/
|
|
1723
|
+
toolCallId: string;
|
|
1724
|
+
/**
|
|
1725
|
+
* The input of the tool call.
|
|
1726
|
+
*/
|
|
1727
|
+
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
1728
|
+
/**
|
|
1729
|
+
* The output of the tool call.
|
|
1730
|
+
*/
|
|
1731
|
+
output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>;
|
|
1732
|
+
}) => ToolResultOutput | PromiseLike<ToolResultOutput>;
|
|
1733
|
+
} & ToolOutputProperties<INPUT, OUTPUT, NoInfer<CONTEXT>>;
|
|
1734
|
+
/**
|
|
1735
|
+
* Common properties shared by function-style tools.
|
|
1736
|
+
*/
|
|
1737
|
+
type BaseFunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1738
|
+
/**
|
|
1739
|
+
* Optional description of what the tool does.
|
|
1740
|
+
*
|
|
1741
|
+
* Included in the tool definition sent to the language model so it can
|
|
1742
|
+
* decide when and how to call the tool.
|
|
1743
|
+
*
|
|
1744
|
+
* Provide a string for a fixed description, or a function that returns a
|
|
1745
|
+
* string from the current `context` (and optional `experimental_sandbox`) when the
|
|
1746
|
+
* description should vary per call.
|
|
1747
|
+
*/
|
|
1748
|
+
description?: string | ((options: {
|
|
1749
|
+
context: NoInfer<CONTEXT>;
|
|
1750
|
+
experimental_sandbox?: SandboxSession;
|
|
1751
|
+
}) => string);
|
|
1752
|
+
/**
|
|
1753
|
+
* Strict mode setting for the tool.
|
|
1754
|
+
*
|
|
1755
|
+
* Providers that support strict mode will use this setting to determine
|
|
1756
|
+
* how the input should be generated. Strict mode will always produce
|
|
1757
|
+
* valid inputs, but it might limit what input schemas are supported.
|
|
1758
|
+
*/
|
|
1759
|
+
strict?: boolean;
|
|
1760
|
+
/**
|
|
1761
|
+
* An optional list of input examples that show the language
|
|
1762
|
+
* model what the input should look like.
|
|
1763
|
+
*/
|
|
1764
|
+
inputExamples?: Array<{
|
|
1765
|
+
input: NoInfer<INPUT>;
|
|
1766
|
+
}>;
|
|
1767
|
+
id?: never;
|
|
1768
|
+
isProviderExecuted?: never;
|
|
1769
|
+
args?: never;
|
|
1770
|
+
supportsDeferredResults?: never;
|
|
1771
|
+
};
|
|
1772
|
+
/**
|
|
1773
|
+
* Tool with user-defined input and output schemas that is executed by the AI SDK.
|
|
1774
|
+
*/
|
|
1775
|
+
type FunctionTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseFunctionTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1776
|
+
type?: undefined | 'function';
|
|
1777
|
+
};
|
|
1778
|
+
/**
|
|
1779
|
+
* Tool that is defined at runtime.
|
|
1780
|
+
* The types of input and output are not known at development time.
|
|
1781
|
+
*
|
|
1782
|
+
* For example, MCP tools that are not known at development time.
|
|
1783
|
+
*/
|
|
1784
|
+
type DynamicTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseFunctionTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1785
|
+
type: 'dynamic';
|
|
1786
|
+
};
|
|
1787
|
+
/**
|
|
1788
|
+
* Common properties shared by provider tools.
|
|
1789
|
+
*/
|
|
1790
|
+
type BaseProviderTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1791
|
+
type: 'provider';
|
|
1792
|
+
/**
|
|
1793
|
+
* The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
|
|
1794
|
+
*/
|
|
1795
|
+
id: `${string}.${string}`;
|
|
1796
|
+
/**
|
|
1797
|
+
* The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
|
1798
|
+
*/
|
|
1799
|
+
args: Record<string, unknown>;
|
|
1800
|
+
description?: never;
|
|
1801
|
+
strict?: never;
|
|
1802
|
+
inputExamples?: never;
|
|
1803
|
+
};
|
|
1804
|
+
/**
|
|
1805
|
+
* Tool with provider-defined input and output schemas that is executed by the
|
|
1806
|
+
* user.
|
|
1807
|
+
*
|
|
1808
|
+
* For example, shell tools that are executed in a local shell, but have provider-defined input and output schemas.
|
|
1809
|
+
*/
|
|
1810
|
+
type ProviderDefinedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseProviderTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1811
|
+
/**
|
|
1812
|
+
* Flag that indicates whether the tool is executed by the provider.
|
|
1813
|
+
*/
|
|
1814
|
+
isProviderExecuted: false;
|
|
1815
|
+
supportsDeferredResults?: never;
|
|
1816
|
+
};
|
|
1817
|
+
/**
|
|
1818
|
+
* Tool with provider-defined input and output schemas that is executed by the
|
|
1819
|
+
* provider.
|
|
1820
|
+
*
|
|
1821
|
+
* For example, web search tools and code execution tools that are executed by the provider itself.
|
|
1822
|
+
*/
|
|
1823
|
+
type ProviderExecutedTool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = BaseProviderTool<INPUT, OUTPUT, CONTEXT> & {
|
|
1824
|
+
/**
|
|
1825
|
+
* Flag that indicates whether the tool is executed by the provider.
|
|
1826
|
+
*/
|
|
1827
|
+
isProviderExecuted: true;
|
|
1828
|
+
/**
|
|
1829
|
+
* Whether this provider-executed tool supports deferred results.
|
|
1830
|
+
*
|
|
1831
|
+
* When true, the tool result may not be returned in the same turn as the
|
|
1832
|
+
* tool call (e.g., when using programmatic tool calling where a server tool
|
|
1833
|
+
* triggers a client-executed tool, and the server tool's result is deferred
|
|
1834
|
+
* until the client tool is resolved).
|
|
1835
|
+
*
|
|
1836
|
+
* This flag allows the AI SDK to handle tool results that arrive without
|
|
1837
|
+
* a matching tool call in the current response.
|
|
1838
|
+
*
|
|
1839
|
+
* @default false
|
|
1840
|
+
*/
|
|
1841
|
+
supportsDeferredResults?: boolean;
|
|
1842
|
+
};
|
|
1843
|
+
/**
|
|
1844
|
+
* A tool can either be user-defined or provider-defined.
|
|
1845
|
+
*
|
|
1846
|
+
* It contains the schemas and metadata needed for the language model to call
|
|
1847
|
+
* the tool and can include an execute function for tools that are executed by
|
|
1848
|
+
* the AI SDK.
|
|
1849
|
+
*/
|
|
1850
|
+
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context | unknown | never = any> = FunctionTool<INPUT, OUTPUT, CONTEXT> | DynamicTool<INPUT, OUTPUT, CONTEXT> | ProviderDefinedTool<INPUT, OUTPUT, CONTEXT> | ProviderExecutedTool<INPUT, OUTPUT, CONTEXT>;
|
|
1851
|
+
/**
|
|
1852
|
+
* Infer the tool type from a tool object.
|
|
1853
|
+
*
|
|
1854
|
+
* This is useful for type inference when working with tool objects.
|
|
1855
|
+
*
|
|
1856
|
+
* When the input has an `execute` function, the return type narrows to
|
|
1857
|
+
* `ExecutableTool<Tool<...>>` so that `.execute` is non-nullable without
|
|
1858
|
+
* needing `isExecutableTool` or a `!` assertion at the call site.
|
|
1859
|
+
*/
|
|
1860
|
+
declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT> & {
|
|
1861
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1862
|
+
}): ExecutableTool<Tool<INPUT, OUTPUT, CONTEXT>>;
|
|
1863
|
+
declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT>): Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1864
|
+
declare function tool<INPUT, CONTEXT extends Context>(tool: Tool<INPUT, never, CONTEXT>): Tool<INPUT, never, CONTEXT>;
|
|
1865
|
+
declare function tool<OUTPUT, CONTEXT extends Context>(tool: Tool<never, OUTPUT, CONTEXT>): Tool<never, OUTPUT, CONTEXT>;
|
|
1866
|
+
declare function tool<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>): Tool<never, never, CONTEXT>;
|
|
1867
|
+
/**
|
|
1868
|
+
* Define a dynamic tool.
|
|
1869
|
+
*/
|
|
1870
|
+
declare function dynamicTool(tool: Omit<DynamicTool<unknown, unknown, Context>, 'type'>): DynamicTool<unknown, unknown, Context>;
|
|
1871
|
+
|
|
1872
|
+
/**
|
|
1873
|
+
* A provider-defined tool is a tool for which the provider defines the input
|
|
1874
|
+
* and output schemas, but does not execute the tool.
|
|
1875
|
+
*/
|
|
1876
|
+
type ProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}> = <OUTPUT>(options: ARGS & {
|
|
1877
|
+
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1878
|
+
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
1879
|
+
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
1880
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1881
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1882
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1883
|
+
}) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
|
|
1884
|
+
declare function createProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, }: {
|
|
1885
|
+
id: `${string}.${string}`;
|
|
1886
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
1887
|
+
}): ProviderDefinedToolFactory<INPUT, ARGS, CONTEXT>;
|
|
1888
|
+
type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
|
|
1889
|
+
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1890
|
+
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
1891
|
+
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
1892
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1893
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1894
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1895
|
+
}) => ProviderDefinedTool<INPUT, OUTPUT, CONTEXT>;
|
|
1896
|
+
declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, }: {
|
|
1897
|
+
id: `${string}.${string}`;
|
|
1898
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
1899
|
+
outputSchema: FlexibleSchema<OUTPUT>;
|
|
1900
|
+
}): ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS, CONTEXT>;
|
|
1901
|
+
|
|
1902
|
+
/**
|
|
1903
|
+
* A provider-executed tool is a tool for which the provider executes the tool.
|
|
1904
|
+
*/
|
|
1905
|
+
type ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
|
|
1906
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1907
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1908
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1909
|
+
}) => ProviderExecutedTool<INPUT, OUTPUT, CONTEXT>;
|
|
1910
|
+
declare function createProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
|
|
1911
|
+
id: `${string}.${string}`;
|
|
1912
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
1913
|
+
outputSchema: FlexibleSchema<OUTPUT>;
|
|
1914
|
+
/**
|
|
1915
|
+
* Whether this provider-executed tool supports deferred results.
|
|
1916
|
+
*
|
|
1917
|
+
* When true, the tool result may not be returned in the same turn as the
|
|
1918
|
+
* tool call (e.g., when using programmatic tool calling where a server tool
|
|
1919
|
+
* triggers a client-executed tool, and the server tool's result is deferred
|
|
1920
|
+
* until the client tool is resolved).
|
|
1921
|
+
*
|
|
1922
|
+
* @default false
|
|
1923
|
+
*/
|
|
1924
|
+
supportsDeferredResults?: boolean;
|
|
1925
|
+
}): ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS, CONTEXT>;
|
|
1926
|
+
|
|
1927
|
+
/**
|
|
1928
|
+
* Cancels a response body to release the underlying connection.
|
|
1929
|
+
*
|
|
1930
|
+
* When a fetch Response is rejected without consuming its body (e.g. a failed
|
|
1931
|
+
* status code, an open-redirect rejection, or a Content-Length that exceeds the
|
|
1932
|
+
* size limit), the underlying TCP socket is not returned to the connection pool
|
|
1933
|
+
* and may stay open until the process runs out of file descriptors. Cancelling
|
|
1934
|
+
* the body avoids this leak.
|
|
1935
|
+
*
|
|
1936
|
+
* Errors thrown while cancelling are ignored: the body may already be locked,
|
|
1937
|
+
* disturbed, or absent, none of which should mask the original rejection.
|
|
1938
|
+
*/
|
|
1939
|
+
declare function cancelResponseBody(response: Response): Promise<void>;
|
|
1940
|
+
|
|
1941
|
+
/**
|
|
1942
|
+
* Default maximum download size: 2 GiB.
|
|
1943
|
+
*
|
|
1944
|
+
* `fetch().arrayBuffer()` has ~2x peak memory overhead (undici buffers the
|
|
1945
|
+
* body internally, then creates the JS ArrayBuffer), so very large downloads
|
|
1946
|
+
* risk exceeding the default V8 heap limit on 64-bit systems and terminating
|
|
1947
|
+
* the process with an out-of-memory error.
|
|
1948
|
+
*
|
|
1949
|
+
* Setting this limit converts an unrecoverable OOM crash into a catchable
|
|
1950
|
+
* `DownloadError`.
|
|
1951
|
+
*/
|
|
1952
|
+
declare const DEFAULT_MAX_DOWNLOAD_SIZE: number;
|
|
1953
|
+
/**
|
|
1954
|
+
* Reads a fetch Response body with a size limit to prevent memory exhaustion.
|
|
1955
|
+
*
|
|
1956
|
+
* Checks the Content-Length header for early rejection, then reads the body
|
|
1957
|
+
* incrementally via ReadableStream and aborts with a DownloadError when the
|
|
1958
|
+
* limit is exceeded.
|
|
1959
|
+
*
|
|
1960
|
+
* @param response - The fetch Response to read.
|
|
1961
|
+
* @param url - The URL being downloaded (used in error messages).
|
|
1962
|
+
* @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
|
|
1963
|
+
* @returns A Uint8Array containing the response body.
|
|
1964
|
+
* @throws DownloadError if the response exceeds maxBytes.
|
|
1965
|
+
*/
|
|
1966
|
+
declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
1967
|
+
response: Response;
|
|
1968
|
+
url: string;
|
|
1969
|
+
maxBytes?: number;
|
|
1970
|
+
}): Promise<Uint8Array>;
|
|
1971
|
+
|
|
1972
|
+
/**
|
|
1973
|
+
* Removes entries from a record where the value is null or undefined.
|
|
1974
|
+
* @param record - The input object whose entries may be null or undefined.
|
|
1975
|
+
* @returns A new object containing only entries with non-null and non-undefined values.
|
|
1976
|
+
*/
|
|
1977
|
+
declare function removeUndefinedEntries<T>(record: Record<string, T | undefined>): Record<string, T>;
|
|
1978
|
+
|
|
1979
|
+
/**
|
|
1980
|
+
* A value or a lazy provider of a value, each of which may be synchronous or asynchronous.
|
|
1981
|
+
*
|
|
1982
|
+
* @template T The resolved type after {@link resolve} runs.
|
|
1983
|
+
*
|
|
1984
|
+
* One of:
|
|
1985
|
+
* - A plain value of type {@link T}
|
|
1986
|
+
* - A {@link PromiseLike} of {@link T} (e.g. a `Promise<T>`)
|
|
1987
|
+
* - A zero-argument function that returns a plain {@link T}
|
|
1988
|
+
* - A zero-argument function that returns a {@link PromiseLike} of {@link T}
|
|
1989
|
+
*
|
|
1990
|
+
* The function form is only invoked when passed to {@link resolve}; it is not distinguished from
|
|
1991
|
+
* a {@link T} that happens to be a function—callers should wrap function values if disambiguation
|
|
1992
|
+
* is required.
|
|
1993
|
+
*/
|
|
1994
|
+
type Resolvable<T> = MaybePromiseLike<T> | (() => MaybePromiseLike<T>);
|
|
1995
|
+
/**
|
|
1996
|
+
* Resolves a value that could be a raw value, a Promise, a function returning a value,
|
|
1997
|
+
* or a function returning a Promise.
|
|
1998
|
+
*/
|
|
1999
|
+
declare function resolve<T>(value: Resolvable<T>): Promise<T>;
|
|
2000
|
+
|
|
2001
|
+
/**
|
|
2002
|
+
* Resolves a file part's media type to a full `type/subtype` form required by
|
|
2003
|
+
* providers whose API demands the full IANA media type.
|
|
2004
|
+
*
|
|
2005
|
+
* - If `part.mediaType` is already a full media type (e.g. `image/png`), it is
|
|
2006
|
+
* returned as-is.
|
|
2007
|
+
* - Otherwise, when inline bytes are available (`part.data.type === 'data'`),
|
|
2008
|
+
* the subtype is sniffed from the bytes using the signature table that
|
|
2009
|
+
* corresponds to the top-level segment.
|
|
2010
|
+
* - When neither applies (e.g. top-level-only with a URL source, or bytes that
|
|
2011
|
+
* cannot be detected), an `UnsupportedFunctionalityError` is thrown.
|
|
2012
|
+
*/
|
|
2013
|
+
declare function resolveFullMediaType({ part, }: {
|
|
2014
|
+
part: LanguageModelV4FilePart;
|
|
2015
|
+
}): string;
|
|
2016
|
+
|
|
2017
|
+
/**
|
|
2018
|
+
* Resolves a provider reference to the provider-specific identifier for the
|
|
2019
|
+
* given provider. Throws `NoSuchProviderReferenceError` if the provider is not
|
|
2020
|
+
* found in the reference mapping.
|
|
2021
|
+
*/
|
|
2022
|
+
declare function resolveProviderReference({ reference, provider, }: {
|
|
2023
|
+
reference: SharedV4ProviderReference;
|
|
2024
|
+
provider: string;
|
|
2025
|
+
}): string;
|
|
2026
|
+
|
|
2027
|
+
/**
|
|
2028
|
+
* Serializes a model instance for workflow step boundaries.
|
|
2029
|
+
* Returns the `modelId` plus the JSON-serializable config properties.
|
|
2030
|
+
*
|
|
2031
|
+
* Non-serializable values are omitted. As a special case, a
|
|
2032
|
+
* function-valued `headers` property is resolved during serialization
|
|
2033
|
+
* and included if the returned value is JSON-serializable.
|
|
2034
|
+
*
|
|
2035
|
+
* Used as the body of `static [WORKFLOW_SERIALIZE]` in provider models.
|
|
2036
|
+
*
|
|
2037
|
+
* @example
|
|
2038
|
+
* ```ts
|
|
2039
|
+
* static [WORKFLOW_SERIALIZE](model: MyLanguageModel) {
|
|
2040
|
+
* return serializeModelOptions({
|
|
2041
|
+
* modelId: model.modelId,
|
|
2042
|
+
* config: model.config,
|
|
2043
|
+
* });
|
|
2044
|
+
* }
|
|
2045
|
+
* ```
|
|
2046
|
+
*/
|
|
2047
|
+
declare function serializeModelOptions<CONFIG extends {
|
|
2048
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
2049
|
+
}>(options: {
|
|
2050
|
+
modelId: string;
|
|
2051
|
+
config: CONFIG;
|
|
2052
|
+
}): {
|
|
2053
|
+
modelId: string;
|
|
2054
|
+
config: JSONObject;
|
|
2055
|
+
};
|
|
2056
|
+
|
|
2057
|
+
/**
|
|
2058
|
+
* Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
|
|
2059
|
+
*/
|
|
2060
|
+
interface StreamingToolCallDelta {
|
|
2061
|
+
index?: number | null;
|
|
2062
|
+
id?: string | null;
|
|
2063
|
+
type?: string | null;
|
|
2064
|
+
function?: {
|
|
2065
|
+
name?: string | null;
|
|
2066
|
+
arguments?: string | null;
|
|
2067
|
+
} | null;
|
|
2068
|
+
}
|
|
2069
|
+
interface StreamingToolCallTrackerOptions<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
2070
|
+
/**
|
|
2071
|
+
* ID generator function for tool call IDs.
|
|
2072
|
+
* Defaults to the standard generateId.
|
|
2073
|
+
*/
|
|
2074
|
+
generateId?: () => string;
|
|
2075
|
+
/**
|
|
2076
|
+
* How to validate the `type` field on new tool call deltas.
|
|
2077
|
+
* - `'none'`: no validation (default)
|
|
2078
|
+
* - `'if-present'`: throw if type is present and not `'function'`
|
|
2079
|
+
* - `'required'`: throw if type is not exactly `'function'`
|
|
2080
|
+
*/
|
|
2081
|
+
typeValidation?: 'none' | 'if-present' | 'required';
|
|
2082
|
+
/**
|
|
2083
|
+
* Extract provider-specific metadata from a tool call delta.
|
|
2084
|
+
* Called once when a new tool call is detected.
|
|
2085
|
+
* The returned metadata is stored on the tool call and passed to
|
|
2086
|
+
* `buildToolCallProviderMetadata` when the tool call is finalized.
|
|
2087
|
+
*/
|
|
2088
|
+
extractMetadata?: (delta: DELTA) => SharedV4ProviderMetadata | undefined;
|
|
2089
|
+
/**
|
|
2090
|
+
* Build the `providerMetadata` object for a `tool-call` event.
|
|
2091
|
+
* Receives the metadata previously extracted via `extractMetadata`.
|
|
2092
|
+
* If `undefined` is returned, no `providerMetadata` is included in the event.
|
|
2093
|
+
*/
|
|
2094
|
+
buildToolCallProviderMetadata?: (metadata: SharedV4ProviderMetadata | undefined) => SharedV4ProviderMetadata | undefined;
|
|
2095
|
+
}
|
|
2096
|
+
type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<LanguageModelV4StreamPart>, 'enqueue'>;
|
|
2097
|
+
/**
|
|
2098
|
+
* Tracks streaming tool call state across multiple deltas from an
|
|
2099
|
+
* OpenAI-compatible chat completion stream. Handles argument accumulation,
|
|
2100
|
+
* emits tool-input-start/delta/end and tool-call events, and finalizes
|
|
2101
|
+
* unfinished tool calls on flush.
|
|
2102
|
+
*
|
|
2103
|
+
* Used by openai, openai-compatible, groq, deepseek, and alibaba providers.
|
|
2104
|
+
*/
|
|
2105
|
+
declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
2106
|
+
private toolCalls;
|
|
2107
|
+
private readonly controller;
|
|
2108
|
+
private readonly _generateId;
|
|
2109
|
+
private readonly typeValidation;
|
|
2110
|
+
private readonly extractMetadata?;
|
|
2111
|
+
private readonly buildToolCallProviderMetadata?;
|
|
2112
|
+
constructor(controller: StreamingToolCallTrackerController, options?: StreamingToolCallTrackerOptions<DELTA>);
|
|
2113
|
+
/**
|
|
2114
|
+
* Process a tool call delta from a streaming response chunk.
|
|
2115
|
+
* Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
|
|
2116
|
+
* events as appropriate.
|
|
2117
|
+
*/
|
|
2118
|
+
processDelta(toolCallDelta: DELTA): void;
|
|
2119
|
+
/**
|
|
2120
|
+
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
2121
|
+
* flush handler to ensure all tool calls are properly completed.
|
|
2122
|
+
*/
|
|
2123
|
+
flush(): void;
|
|
2124
|
+
private processNewToolCall;
|
|
2125
|
+
private processExistingToolCall;
|
|
2126
|
+
private finishToolCall;
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
/**
|
|
2130
|
+
* Strips file extension segments from a filename.
|
|
2131
|
+
*
|
|
2132
|
+
* Examples:
|
|
2133
|
+
* - "report.pdf" -> "report"
|
|
2134
|
+
* - "archive.tar.gz" -> "archive"
|
|
2135
|
+
* - "filename" -> "filename"
|
|
2136
|
+
*/
|
|
2137
|
+
declare function stripFileExtension(filename: string): string;
|
|
2138
|
+
|
|
2139
|
+
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
2140
|
+
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
2141
|
+
declare function convertToBase64(value: string | Uint8Array): string;
|
|
2142
|
+
|
|
2143
|
+
/**
|
|
2144
|
+
* Validates that a URL is safe to download from, blocking private/internal addresses
|
|
2145
|
+
* to prevent SSRF attacks.
|
|
2146
|
+
*
|
|
2147
|
+
* Note: this performs string/literal-IP checks only. It does not resolve DNS, so a
|
|
2148
|
+
* hostname that resolves to a private address is not blocked here (see callers, which
|
|
2149
|
+
* should additionally constrain egress at the network layer when handling untrusted URLs).
|
|
2150
|
+
*
|
|
2151
|
+
* @param url - The URL string to validate.
|
|
2152
|
+
* @throws DownloadError if the URL is unsafe.
|
|
2153
|
+
*/
|
|
2154
|
+
declare function validateDownloadUrl(url: string): void;
|
|
2155
|
+
|
|
2156
|
+
/**
|
|
2157
|
+
* Validates the types of an unknown object using a schema and
|
|
2158
|
+
* return a strongly-typed object.
|
|
2159
|
+
*
|
|
2160
|
+
* @template T - The type of the object to validate.
|
|
2161
|
+
* @param {string} options.value - The object to validate.
|
|
2162
|
+
* @param {Validator<T>} options.schema - The schema to use for validating the JSON.
|
|
2163
|
+
* @param {TypeValidationContext} options.context - Optional context about what is being validated.
|
|
2164
|
+
* @returns {Promise<T>} - The typed object.
|
|
2165
|
+
*/
|
|
2166
|
+
declare function validateTypes<OBJECT>({ value, schema, context, }: {
|
|
2167
|
+
value: unknown;
|
|
2168
|
+
schema: FlexibleSchema<OBJECT>;
|
|
2169
|
+
context?: TypeValidationContext;
|
|
2170
|
+
}): Promise<OBJECT>;
|
|
2171
|
+
/**
|
|
2172
|
+
* Safely validates the types of an unknown object using a schema and
|
|
2173
|
+
* return a strongly-typed object.
|
|
2174
|
+
*
|
|
2175
|
+
* @template T - The type of the object to validate.
|
|
2176
|
+
* @param {string} options.value - The JSON object to validate.
|
|
2177
|
+
* @param {Validator<T>} options.schema - The schema to use for validating the JSON.
|
|
2178
|
+
* @param {TypeValidationContext} options.context - Optional context about what is being validated.
|
|
2179
|
+
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
|
2180
|
+
*/
|
|
2181
|
+
declare function safeValidateTypes<OBJECT>({ value, schema, context, }: {
|
|
2182
|
+
value: unknown;
|
|
2183
|
+
schema: FlexibleSchema<OBJECT>;
|
|
2184
|
+
context?: TypeValidationContext;
|
|
2185
|
+
}): Promise<{
|
|
2186
|
+
success: true;
|
|
2187
|
+
value: OBJECT;
|
|
2188
|
+
rawValue: unknown;
|
|
2189
|
+
} | {
|
|
2190
|
+
success: false;
|
|
2191
|
+
error: TypeValidationError;
|
|
2192
|
+
rawValue: unknown;
|
|
2193
|
+
}>;
|
|
2194
|
+
|
|
2195
|
+
declare const VERSION: string;
|
|
2196
|
+
|
|
2197
|
+
/**
|
|
2198
|
+
* Appends suffix parts to the `user-agent` header.
|
|
2199
|
+
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
|
2200
|
+
* If no `user-agent` header exists, a new one is created with the suffix parts.
|
|
2201
|
+
* Automatically removes undefined entries from the headers.
|
|
2202
|
+
*
|
|
2203
|
+
* @param headers - The original headers.
|
|
2204
|
+
* @param userAgentSuffixParts - The parts to append to the `user-agent` header.
|
|
2205
|
+
* @returns The new headers with the `user-agent` header set or updated.
|
|
2206
|
+
*/
|
|
2207
|
+
declare function withUserAgentSuffix(headers: HeadersInit | Record<string, string | undefined> | undefined, ...userAgentSuffixParts: string[]): Record<string, string>;
|
|
2208
|
+
|
|
2209
|
+
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
|
2210
|
+
|
|
2211
|
+
/**
|
|
2212
|
+
* Detects the `any` type so untyped tools can be treated as having no explicit
|
|
2213
|
+
* context type.
|
|
2214
|
+
*/
|
|
2215
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
2216
|
+
/**
|
|
2217
|
+
* Detects exact empty object contexts, including `{}` combined with
|
|
2218
|
+
* `undefined`, which do not provide tool-specific context properties.
|
|
2219
|
+
*/
|
|
2220
|
+
type IsEmptyObject<T> = keyof NonNullable<T> extends never ? true : false;
|
|
2221
|
+
/**
|
|
2222
|
+
* Detects context types that come from omitted or broad context declarations
|
|
2223
|
+
* rather than a concrete tool context schema.
|
|
2224
|
+
*/
|
|
2225
|
+
type IsUntypedContext<CONTEXT> = IsAny<CONTEXT> extends true ? true : unknown extends CONTEXT ? true : IsEmptyObject<CONTEXT> extends true ? true : string extends keyof CONTEXT ? CONTEXT extends Context ? true : false : false;
|
|
2226
|
+
/**
|
|
2227
|
+
* Infer the context type of a tool.
|
|
2228
|
+
*/
|
|
2229
|
+
type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ? IsUntypedContext<CONTEXT> extends true ? never : CONTEXT : never;
|
|
2230
|
+
|
|
2231
|
+
/**
|
|
2232
|
+
* Infer the input type of a tool.
|
|
2233
|
+
*/
|
|
2234
|
+
type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer INPUT, any, any> ? INPUT : never;
|
|
2235
|
+
|
|
2236
|
+
/**
|
|
2237
|
+
* Infer the output type of a tool.
|
|
2238
|
+
*/
|
|
2239
|
+
type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
|
|
2240
|
+
|
|
2241
|
+
/**
|
|
2242
|
+
* Executes a tool function and normalizes its results into a stream of outputs.
|
|
2243
|
+
*
|
|
2244
|
+
* - If the tool's `execute` function returns an `AsyncIterable`, each yielded value is emitted as
|
|
2245
|
+
* `{ type: "preliminary", output }`. After iteration completes, the last yielded value is emitted
|
|
2246
|
+
* again as `{ type: "final", output }`.
|
|
2247
|
+
* - If the tool returns a direct value or Promise, a single `{ type: "final", output }` is yielded.
|
|
2248
|
+
*
|
|
2249
|
+
* @param params.tool The tool whose `execute` function should be invoked.
|
|
2250
|
+
* @param params.input The input value to pass to the tool.
|
|
2251
|
+
* @param params.options Additional options for tool execution.
|
|
2252
|
+
* @yields A preliminary output for each streamed value, followed by a final output, or a single final
|
|
2253
|
+
* output for non-streaming tools.
|
|
2254
|
+
*/
|
|
2255
|
+
declare function executeTool<TOOL extends Tool>({ tool, input, options, }: {
|
|
2256
|
+
tool: ExecutableTool<TOOL>;
|
|
2257
|
+
input: InferToolInput<TOOL>;
|
|
2258
|
+
options: ToolExecutionOptions<InferToolContext<TOOL>>;
|
|
2259
|
+
}): AsyncGenerator<{
|
|
2260
|
+
type: 'preliminary';
|
|
2261
|
+
output: InferToolOutput<TOOL>;
|
|
2262
|
+
} | {
|
|
2263
|
+
type: 'final';
|
|
2264
|
+
output: InferToolOutput<TOOL>;
|
|
2265
|
+
}>;
|
|
2266
|
+
|
|
2267
|
+
/**
|
|
2268
|
+
* A mapping of tool names to tool definitions.
|
|
2269
|
+
*/
|
|
2270
|
+
type ToolSet = Record<string, (Tool<never, never, any> | Tool<any, any, any> | Tool<any, never, any> | Tool<never, any, any>) & Pick<Tool<any, any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta' | 'needsApproval'>>;
|
|
2271
|
+
|
|
2272
|
+
/**
|
|
2273
|
+
* Builds the required portion of the tool context map for tools whose context
|
|
2274
|
+
* type does not include `undefined`.
|
|
2275
|
+
*/
|
|
2276
|
+
type RequiredToolSetContext<TOOLS extends ToolSet> = {
|
|
2277
|
+
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? never : K]: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
2278
|
+
};
|
|
2279
|
+
/**
|
|
2280
|
+
* Builds the optional portion of the tool context map for tools whose context
|
|
2281
|
+
* object itself may be `undefined`.
|
|
2282
|
+
*/
|
|
2283
|
+
type OptionalToolSetContext<TOOLS extends ToolSet> = {
|
|
2284
|
+
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? K : never]?: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
2285
|
+
};
|
|
2286
|
+
/**
|
|
2287
|
+
* Flattens intersected mapped types so type equality assertions and editor
|
|
2288
|
+
* hovers show the resulting object shape.
|
|
2289
|
+
*/
|
|
2290
|
+
type Normalize<OBJECT> = {
|
|
2291
|
+
[KEY in keyof OBJECT]: OBJECT[KEY];
|
|
2292
|
+
};
|
|
2293
|
+
/**
|
|
2294
|
+
* Infer the context type for a tool set.
|
|
2295
|
+
*
|
|
2296
|
+
* The inferred type maps each contextual tool name to its context type.
|
|
2297
|
+
*
|
|
2298
|
+
* Tools without concrete context are omitted. Tool contexts that include
|
|
2299
|
+
* `undefined` are represented as optional properties.
|
|
2300
|
+
*/
|
|
2301
|
+
type InferToolSetContext<TOOLS extends ToolSet> = Normalize<RequiredToolSetContext<TOOLS> & OptionalToolSetContext<TOOLS>>;
|
|
2302
|
+
|
|
2303
|
+
/**
|
|
2304
|
+
* Typed tool call that is returned by generateText and streamText.
|
|
2305
|
+
* It contains the tool call ID, the tool name, and the tool arguments.
|
|
2306
|
+
*/
|
|
2307
|
+
interface ToolCall<NAME extends string, INPUT> {
|
|
2308
|
+
/**
|
|
2309
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
2310
|
+
*/
|
|
2311
|
+
toolCallId: string;
|
|
2312
|
+
/**
|
|
2313
|
+
* Name of the tool that is being called.
|
|
2314
|
+
*/
|
|
2315
|
+
toolName: NAME;
|
|
2316
|
+
/**
|
|
2317
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
2318
|
+
*/
|
|
2319
|
+
input: INPUT;
|
|
2320
|
+
/**
|
|
2321
|
+
* Whether the tool call will be executed by the provider.
|
|
2322
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
|
2323
|
+
*/
|
|
2324
|
+
providerExecuted?: boolean;
|
|
2325
|
+
/**
|
|
2326
|
+
* Whether the tool is dynamic.
|
|
2327
|
+
*/
|
|
2328
|
+
dynamic?: boolean;
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
/**
|
|
2332
|
+
* Typed tool result that is returned by `generateText` and `streamText`.
|
|
2333
|
+
* It contains the tool call ID, the tool name, the tool arguments, and the tool result.
|
|
2334
|
+
*/
|
|
2335
|
+
interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
2336
|
+
/**
|
|
2337
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
2338
|
+
*/
|
|
2339
|
+
toolCallId: string;
|
|
2340
|
+
/**
|
|
2341
|
+
* Name of the tool that was called.
|
|
2342
|
+
*/
|
|
2343
|
+
toolName: NAME;
|
|
2344
|
+
/**
|
|
2345
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
2346
|
+
*/
|
|
2347
|
+
input: INPUT;
|
|
2348
|
+
/**
|
|
2349
|
+
* Result of the tool call. This is the result of the tool's execution.
|
|
2350
|
+
*/
|
|
2351
|
+
output: OUTPUT;
|
|
2352
|
+
/**
|
|
2353
|
+
* Whether the tool result has been executed by the provider.
|
|
2354
|
+
*/
|
|
2355
|
+
providerExecuted?: boolean;
|
|
2356
|
+
/**
|
|
2357
|
+
* Whether the tool is dynamic.
|
|
2358
|
+
*/
|
|
2359
|
+
dynamic?: boolean;
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asArray, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|