@ai-sdk/provider-utils 3.0.39 → 3.0.41
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 +14 -0
- package/dist/index.d.mts +107 -8
- package/dist/index.d.ts +107 -8
- package/dist/index.js +410 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +410 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 3.0.41
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2b1c2df: Keep default Node.js downloads protected by DNS validation and connection pinning when frameworks or instrumentation wrap global fetch before or after the SDK loads.
|
|
8
|
+
- 2b1c2df: fix(mcp): prevent SSRF in OAuth metadata discovery
|
|
9
|
+
- 2b1c2df: fix(provider-utils): make lazy Undici import visible to deployment tracers
|
|
10
|
+
|
|
11
|
+
## 3.0.40
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 14810cb: fix(provider-utils): preserve streamed tool calls with unreliable IDs and indices
|
|
16
|
+
|
|
3
17
|
## 3.0.39
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AISDKError, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
|
|
1
|
+
import { AISDKError, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart, LanguageModelV2StreamPart, SharedV2ProviderMetadata } from '@ai-sdk/provider';
|
|
2
2
|
import * as z4 from 'zod/v4';
|
|
3
3
|
import { ZodType } from 'zod/v4';
|
|
4
4
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
@@ -80,6 +80,30 @@ declare class DownloadError extends AISDKError {
|
|
|
80
80
|
*/
|
|
81
81
|
declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Fetch function type (standardizes the version of fetch used).
|
|
85
|
+
*/
|
|
86
|
+
type FetchFunction = typeof globalThis.fetch;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Fetches one validated URL without following redirects.
|
|
90
|
+
*
|
|
91
|
+
* On Node.js, the default fetch validates and pins DNS results at connect time.
|
|
92
|
+
* An injected fetch is responsible for equivalent connect-time validation.
|
|
93
|
+
* Redirects are rejected by default. Callers using `redirect: 'manual'` must
|
|
94
|
+
* validate the Location target before issuing another request.
|
|
95
|
+
*/
|
|
96
|
+
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
|
|
97
|
+
url: string | URL;
|
|
98
|
+
init?: RequestInit;
|
|
99
|
+
fetch?: FetchFunction;
|
|
100
|
+
/**
|
|
101
|
+
* A developer-configured origin that may legitimately resolve to a private
|
|
102
|
+
* address. This must never be derived from untrusted response data.
|
|
103
|
+
*/
|
|
104
|
+
trustedOrigin?: string;
|
|
105
|
+
redirect?: 'error' | 'manual';
|
|
106
|
+
}): Promise<Response>;
|
|
83
107
|
/**
|
|
84
108
|
* Fetches a URL while enforcing the SSRF download guard on every hop.
|
|
85
109
|
*
|
|
@@ -97,6 +121,13 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
|
97
121
|
* runtime we cannot validate the hop, so we fail closed rather than follow it
|
|
98
122
|
* blindly and bypass the SSRF guard.
|
|
99
123
|
*
|
|
124
|
+
* A hop that is same-origin with `trustedOrigin` (the developer-configured
|
|
125
|
+
* endpoint) skips target validation: that origin is exactly what an
|
|
126
|
+
* unvalidated, config-derived request would fetch anyway, and validating it
|
|
127
|
+
* would break legitimate self-hosted / localhost deployments whose response
|
|
128
|
+
* URLs point back at the configured host. Hops on any other origin are always
|
|
129
|
+
* validated.
|
|
130
|
+
*
|
|
100
131
|
* The returned response is the final (non-redirect) response. The caller is
|
|
101
132
|
* responsible for checking `response.ok` and reading the body.
|
|
102
133
|
*
|
|
@@ -108,11 +139,17 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
|
108
139
|
* @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
|
|
109
140
|
* a redirect cannot be validated on a non-browser runtime.
|
|
110
141
|
*/
|
|
111
|
-
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, }: {
|
|
142
|
+
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin, }: {
|
|
112
143
|
url: string;
|
|
113
144
|
headers?: HeadersInit;
|
|
114
145
|
abortSignal?: AbortSignal;
|
|
115
146
|
maxRedirects?: number;
|
|
147
|
+
fetch?: FetchFunction;
|
|
148
|
+
/**
|
|
149
|
+
* A developer-configured origin whose hops skip target validation. Must
|
|
150
|
+
* never be derived from response data.
|
|
151
|
+
*/
|
|
152
|
+
trustedOrigin?: string;
|
|
116
153
|
}): Promise<Response>;
|
|
117
154
|
|
|
118
155
|
/**
|
|
@@ -156,11 +193,6 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
|
156
193
|
maxBytes?: number;
|
|
157
194
|
}): Promise<Uint8Array>;
|
|
158
195
|
|
|
159
|
-
/**
|
|
160
|
-
* Fetch function type (standardizes the version of fetch used).
|
|
161
|
-
*/
|
|
162
|
-
type FetchFunction = typeof globalThis.fetch;
|
|
163
|
-
|
|
164
196
|
/**
|
|
165
197
|
Creates an ID generator.
|
|
166
198
|
The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
@@ -950,6 +982,73 @@ declare function resolve<T>(value: Resolvable<T>): Promise<T>;
|
|
|
950
982
|
|
|
951
983
|
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
|
952
984
|
|
|
985
|
+
/**
|
|
986
|
+
* Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
|
|
987
|
+
*/
|
|
988
|
+
interface StreamingToolCallDelta {
|
|
989
|
+
index?: number | null;
|
|
990
|
+
id?: string | null;
|
|
991
|
+
type?: string | null;
|
|
992
|
+
function?: {
|
|
993
|
+
name?: string | null;
|
|
994
|
+
arguments?: string | null;
|
|
995
|
+
} | null;
|
|
996
|
+
}
|
|
997
|
+
interface StreamingToolCallTrackerOptions<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
998
|
+
/**
|
|
999
|
+
* ID generator function for tool call IDs.
|
|
1000
|
+
* Blank or repeated outputs are converted to usable unique IDs.
|
|
1001
|
+
* Defaults to the standard generateId.
|
|
1002
|
+
*/
|
|
1003
|
+
generateId?: () => string;
|
|
1004
|
+
/**
|
|
1005
|
+
* How to validate the `type` field on new tool call deltas.
|
|
1006
|
+
* - `'none'`: no validation (default)
|
|
1007
|
+
* - `'if-present'`: throw if type is present and not `'function'`
|
|
1008
|
+
* - `'required'`: throw if type is not exactly `'function'`
|
|
1009
|
+
*/
|
|
1010
|
+
typeValidation?: 'none' | 'if-present' | 'required';
|
|
1011
|
+
/**
|
|
1012
|
+
* Extract provider-specific metadata from a tool call delta.
|
|
1013
|
+
* Called once when a new tool call is detected.
|
|
1014
|
+
*/
|
|
1015
|
+
extractMetadata?: (delta: DELTA) => SharedV2ProviderMetadata | undefined;
|
|
1016
|
+
/**
|
|
1017
|
+
* Build the `providerMetadata` object for a `tool-call` event.
|
|
1018
|
+
*/
|
|
1019
|
+
buildToolCallProviderMetadata?: (metadata: SharedV2ProviderMetadata | undefined) => SharedV2ProviderMetadata | undefined;
|
|
1020
|
+
}
|
|
1021
|
+
type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<LanguageModelV2StreamPart>, 'enqueue'>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Tracks streaming tool call state across multiple deltas from an
|
|
1024
|
+
* OpenAI-compatible chat completion stream.
|
|
1025
|
+
*/
|
|
1026
|
+
declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
1027
|
+
private toolCalls;
|
|
1028
|
+
private toolCallsById;
|
|
1029
|
+
private toolCallsByIndex;
|
|
1030
|
+
private usedToolCallIds;
|
|
1031
|
+
private nextGeneratedIdSuffixes;
|
|
1032
|
+
private readonly controller;
|
|
1033
|
+
private readonly _generateId;
|
|
1034
|
+
private readonly typeValidation;
|
|
1035
|
+
private readonly extractMetadata?;
|
|
1036
|
+
private readonly buildToolCallProviderMetadata?;
|
|
1037
|
+
constructor(controller: StreamingToolCallTrackerController, options?: StreamingToolCallTrackerOptions<DELTA>);
|
|
1038
|
+
processDelta(toolCallDelta: DELTA): void;
|
|
1039
|
+
flush(): void;
|
|
1040
|
+
private resolveToolCall;
|
|
1041
|
+
private filterToolCallsByName;
|
|
1042
|
+
private resolveMatchingToolCall;
|
|
1043
|
+
private processNewToolCall;
|
|
1044
|
+
private associateWireId;
|
|
1045
|
+
private associateIndex;
|
|
1046
|
+
private createToolCallId;
|
|
1047
|
+
private getNonBlankString;
|
|
1048
|
+
private processExistingToolCall;
|
|
1049
|
+
private finishToolCall;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
953
1052
|
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
954
1053
|
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
955
1054
|
declare function convertToBase64(value: string | Uint8Array): string;
|
|
@@ -1098,4 +1197,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1098
1197
|
dynamic?: boolean;
|
|
1099
1198
|
}
|
|
1100
1199
|
|
|
1101
|
-
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isParsableJson, isSameOrigin, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1200
|
+
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isParsableJson, isSameOrigin, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AISDKError, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart } from '@ai-sdk/provider';
|
|
1
|
+
import { AISDKError, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV2Prompt, JSONSchema7, SharedV2ProviderOptions, LanguageModelV2ToolResultOutput, LanguageModelV2ToolResultPart, LanguageModelV2StreamPart, SharedV2ProviderMetadata } from '@ai-sdk/provider';
|
|
2
2
|
import * as z4 from 'zod/v4';
|
|
3
3
|
import { ZodType } from 'zod/v4';
|
|
4
4
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
@@ -80,6 +80,30 @@ declare class DownloadError extends AISDKError {
|
|
|
80
80
|
*/
|
|
81
81
|
declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Fetch function type (standardizes the version of fetch used).
|
|
85
|
+
*/
|
|
86
|
+
type FetchFunction = typeof globalThis.fetch;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Fetches one validated URL without following redirects.
|
|
90
|
+
*
|
|
91
|
+
* On Node.js, the default fetch validates and pins DNS results at connect time.
|
|
92
|
+
* An injected fetch is responsible for equivalent connect-time validation.
|
|
93
|
+
* Redirects are rejected by default. Callers using `redirect: 'manual'` must
|
|
94
|
+
* validate the Location target before issuing another request.
|
|
95
|
+
*/
|
|
96
|
+
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
|
|
97
|
+
url: string | URL;
|
|
98
|
+
init?: RequestInit;
|
|
99
|
+
fetch?: FetchFunction;
|
|
100
|
+
/**
|
|
101
|
+
* A developer-configured origin that may legitimately resolve to a private
|
|
102
|
+
* address. This must never be derived from untrusted response data.
|
|
103
|
+
*/
|
|
104
|
+
trustedOrigin?: string;
|
|
105
|
+
redirect?: 'error' | 'manual';
|
|
106
|
+
}): Promise<Response>;
|
|
83
107
|
/**
|
|
84
108
|
* Fetches a URL while enforcing the SSRF download guard on every hop.
|
|
85
109
|
*
|
|
@@ -97,6 +121,13 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
|
97
121
|
* runtime we cannot validate the hop, so we fail closed rather than follow it
|
|
98
122
|
* blindly and bypass the SSRF guard.
|
|
99
123
|
*
|
|
124
|
+
* A hop that is same-origin with `trustedOrigin` (the developer-configured
|
|
125
|
+
* endpoint) skips target validation: that origin is exactly what an
|
|
126
|
+
* unvalidated, config-derived request would fetch anyway, and validating it
|
|
127
|
+
* would break legitimate self-hosted / localhost deployments whose response
|
|
128
|
+
* URLs point back at the configured host. Hops on any other origin are always
|
|
129
|
+
* validated.
|
|
130
|
+
*
|
|
100
131
|
* The returned response is the final (non-redirect) response. The caller is
|
|
101
132
|
* responsible for checking `response.ok` and reading the body.
|
|
102
133
|
*
|
|
@@ -108,11 +139,17 @@ declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
|
108
139
|
* @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
|
|
109
140
|
* a redirect cannot be validated on a non-browser runtime.
|
|
110
141
|
*/
|
|
111
|
-
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, }: {
|
|
142
|
+
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin, }: {
|
|
112
143
|
url: string;
|
|
113
144
|
headers?: HeadersInit;
|
|
114
145
|
abortSignal?: AbortSignal;
|
|
115
146
|
maxRedirects?: number;
|
|
147
|
+
fetch?: FetchFunction;
|
|
148
|
+
/**
|
|
149
|
+
* A developer-configured origin whose hops skip target validation. Must
|
|
150
|
+
* never be derived from response data.
|
|
151
|
+
*/
|
|
152
|
+
trustedOrigin?: string;
|
|
116
153
|
}): Promise<Response>;
|
|
117
154
|
|
|
118
155
|
/**
|
|
@@ -156,11 +193,6 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
|
156
193
|
maxBytes?: number;
|
|
157
194
|
}): Promise<Uint8Array>;
|
|
158
195
|
|
|
159
|
-
/**
|
|
160
|
-
* Fetch function type (standardizes the version of fetch used).
|
|
161
|
-
*/
|
|
162
|
-
type FetchFunction = typeof globalThis.fetch;
|
|
163
|
-
|
|
164
196
|
/**
|
|
165
197
|
Creates an ID generator.
|
|
166
198
|
The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
@@ -950,6 +982,73 @@ declare function resolve<T>(value: Resolvable<T>): Promise<T>;
|
|
|
950
982
|
|
|
951
983
|
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
|
952
984
|
|
|
985
|
+
/**
|
|
986
|
+
* Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
|
|
987
|
+
*/
|
|
988
|
+
interface StreamingToolCallDelta {
|
|
989
|
+
index?: number | null;
|
|
990
|
+
id?: string | null;
|
|
991
|
+
type?: string | null;
|
|
992
|
+
function?: {
|
|
993
|
+
name?: string | null;
|
|
994
|
+
arguments?: string | null;
|
|
995
|
+
} | null;
|
|
996
|
+
}
|
|
997
|
+
interface StreamingToolCallTrackerOptions<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
998
|
+
/**
|
|
999
|
+
* ID generator function for tool call IDs.
|
|
1000
|
+
* Blank or repeated outputs are converted to usable unique IDs.
|
|
1001
|
+
* Defaults to the standard generateId.
|
|
1002
|
+
*/
|
|
1003
|
+
generateId?: () => string;
|
|
1004
|
+
/**
|
|
1005
|
+
* How to validate the `type` field on new tool call deltas.
|
|
1006
|
+
* - `'none'`: no validation (default)
|
|
1007
|
+
* - `'if-present'`: throw if type is present and not `'function'`
|
|
1008
|
+
* - `'required'`: throw if type is not exactly `'function'`
|
|
1009
|
+
*/
|
|
1010
|
+
typeValidation?: 'none' | 'if-present' | 'required';
|
|
1011
|
+
/**
|
|
1012
|
+
* Extract provider-specific metadata from a tool call delta.
|
|
1013
|
+
* Called once when a new tool call is detected.
|
|
1014
|
+
*/
|
|
1015
|
+
extractMetadata?: (delta: DELTA) => SharedV2ProviderMetadata | undefined;
|
|
1016
|
+
/**
|
|
1017
|
+
* Build the `providerMetadata` object for a `tool-call` event.
|
|
1018
|
+
*/
|
|
1019
|
+
buildToolCallProviderMetadata?: (metadata: SharedV2ProviderMetadata | undefined) => SharedV2ProviderMetadata | undefined;
|
|
1020
|
+
}
|
|
1021
|
+
type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<LanguageModelV2StreamPart>, 'enqueue'>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Tracks streaming tool call state across multiple deltas from an
|
|
1024
|
+
* OpenAI-compatible chat completion stream.
|
|
1025
|
+
*/
|
|
1026
|
+
declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
1027
|
+
private toolCalls;
|
|
1028
|
+
private toolCallsById;
|
|
1029
|
+
private toolCallsByIndex;
|
|
1030
|
+
private usedToolCallIds;
|
|
1031
|
+
private nextGeneratedIdSuffixes;
|
|
1032
|
+
private readonly controller;
|
|
1033
|
+
private readonly _generateId;
|
|
1034
|
+
private readonly typeValidation;
|
|
1035
|
+
private readonly extractMetadata?;
|
|
1036
|
+
private readonly buildToolCallProviderMetadata?;
|
|
1037
|
+
constructor(controller: StreamingToolCallTrackerController, options?: StreamingToolCallTrackerOptions<DELTA>);
|
|
1038
|
+
processDelta(toolCallDelta: DELTA): void;
|
|
1039
|
+
flush(): void;
|
|
1040
|
+
private resolveToolCall;
|
|
1041
|
+
private filterToolCallsByName;
|
|
1042
|
+
private resolveMatchingToolCall;
|
|
1043
|
+
private processNewToolCall;
|
|
1044
|
+
private associateWireId;
|
|
1045
|
+
private associateIndex;
|
|
1046
|
+
private createToolCallId;
|
|
1047
|
+
private getNonBlankString;
|
|
1048
|
+
private processExistingToolCall;
|
|
1049
|
+
private finishToolCall;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
953
1052
|
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
954
1053
|
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
955
1054
|
declare function convertToBase64(value: string | Uint8Array): string;
|
|
@@ -1098,4 +1197,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1098
1197
|
dynamic?: boolean;
|
|
1099
1198
|
}
|
|
1100
1199
|
|
|
1101
|
-
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isParsableJson, isSameOrigin, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1200
|
+
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isParsableJson, isSameOrigin, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|