@ai-sdk/provider-utils 4.0.55 → 4.0.57
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/src/fetch-with-validated-redirects.ts +90 -3
- package/src/index.ts +9 -1
- package/src/safe-node-fetch.ts +20 -25
- package/src/streaming-tool-call-argument-state.ts +102 -0
- package/src/streaming-tool-call-tracker.ts +465 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 4.0.57
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a9cea74: 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
|
+
- a9cea74: fix(mcp): prevent SSRF in OAuth metadata discovery
|
|
9
|
+
- a9cea74: fix(provider-utils): make lazy Undici import visible to deployment tracers
|
|
10
|
+
|
|
11
|
+
## 4.0.56
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 29dc427: fix(provider-utils): preserve streamed tool calls with unreliable IDs and indices
|
|
16
|
+
|
|
3
17
|
## 4.0.55
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, SharedV3ProviderOptions, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, JSONObject, TypeValidationContext } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, SharedV3ProviderOptions, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, JSONObject, LanguageModelV3StreamPart, SharedV3ProviderMetadata, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
export * from '@standard-schema/spec';
|
|
4
4
|
import * as z3 from 'zod/v3';
|
|
@@ -225,6 +225,30 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
|
225
225
|
maxBytes?: number;
|
|
226
226
|
}): Promise<Uint8Array>;
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Fetch function type (standardizes the version of fetch used).
|
|
230
|
+
*/
|
|
231
|
+
type FetchFunction = typeof globalThis.fetch;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Fetches one validated URL without following redirects.
|
|
235
|
+
*
|
|
236
|
+
* On Node.js, the default fetch validates and pins DNS results at connect time.
|
|
237
|
+
* An injected fetch is responsible for equivalent connect-time validation.
|
|
238
|
+
* Redirects are rejected by default. Callers using `redirect: 'manual'` must
|
|
239
|
+
* validate the Location target before issuing another request.
|
|
240
|
+
*/
|
|
241
|
+
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
|
|
242
|
+
url: string | URL;
|
|
243
|
+
init?: RequestInit;
|
|
244
|
+
fetch?: FetchFunction;
|
|
245
|
+
/**
|
|
246
|
+
* A developer-configured origin that may legitimately resolve to a private
|
|
247
|
+
* address. This must never be derived from untrusted response data.
|
|
248
|
+
*/
|
|
249
|
+
trustedOrigin?: string;
|
|
250
|
+
redirect?: 'error' | 'manual';
|
|
251
|
+
}): Promise<Response>;
|
|
228
252
|
/**
|
|
229
253
|
* Fetches a URL while enforcing the SSRF download guard on every hop.
|
|
230
254
|
*
|
|
@@ -242,6 +266,13 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
|
242
266
|
* runtime we cannot validate the hop, so we fail closed rather than follow it
|
|
243
267
|
* blindly and bypass the SSRF guard.
|
|
244
268
|
*
|
|
269
|
+
* A hop that is same-origin with `trustedOrigin` (the developer-configured
|
|
270
|
+
* endpoint) skips target validation: that origin is exactly what an
|
|
271
|
+
* unvalidated, config-derived request would fetch anyway, and validating it
|
|
272
|
+
* would break legitimate self-hosted / localhost deployments whose response
|
|
273
|
+
* URLs point back at the configured host. Hops on any other origin are always
|
|
274
|
+
* validated.
|
|
275
|
+
*
|
|
245
276
|
* The returned response is the final (non-redirect) response. The caller is
|
|
246
277
|
* responsible for checking `response.ok` and reading the body.
|
|
247
278
|
*
|
|
@@ -253,18 +284,19 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
|
253
284
|
* @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
|
|
254
285
|
* a redirect cannot be validated on a non-browser runtime.
|
|
255
286
|
*/
|
|
256
|
-
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, }: {
|
|
287
|
+
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin, }: {
|
|
257
288
|
url: string;
|
|
258
289
|
headers?: HeadersInit;
|
|
259
290
|
abortSignal?: AbortSignal;
|
|
260
291
|
maxRedirects?: number;
|
|
292
|
+
fetch?: FetchFunction;
|
|
293
|
+
/**
|
|
294
|
+
* A developer-configured origin whose hops skip target validation. Must
|
|
295
|
+
* never be derived from response data.
|
|
296
|
+
*/
|
|
297
|
+
trustedOrigin?: string;
|
|
261
298
|
}): Promise<Response>;
|
|
262
299
|
|
|
263
|
-
/**
|
|
264
|
-
* Fetch function type (standardizes the version of fetch used).
|
|
265
|
-
*/
|
|
266
|
-
type FetchFunction = typeof globalThis.fetch;
|
|
267
|
-
|
|
268
300
|
/**
|
|
269
301
|
* Creates an ID generator.
|
|
270
302
|
* The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
@@ -1432,6 +1464,73 @@ declare const retryWithExponentialBackoff: ({ maxRetries, initialDelayInMs, back
|
|
|
1432
1464
|
|
|
1433
1465
|
declare function secureJsonParse(text: string): any;
|
|
1434
1466
|
|
|
1467
|
+
/**
|
|
1468
|
+
* Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
|
|
1469
|
+
*/
|
|
1470
|
+
interface StreamingToolCallDelta {
|
|
1471
|
+
index?: number | null;
|
|
1472
|
+
id?: string | null;
|
|
1473
|
+
type?: string | null;
|
|
1474
|
+
function?: {
|
|
1475
|
+
name?: string | null;
|
|
1476
|
+
arguments?: string | null;
|
|
1477
|
+
} | null;
|
|
1478
|
+
}
|
|
1479
|
+
interface StreamingToolCallTrackerOptions<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
1480
|
+
/**
|
|
1481
|
+
* ID generator function for tool call IDs.
|
|
1482
|
+
* Blank or repeated outputs are converted to usable unique IDs.
|
|
1483
|
+
* Defaults to the standard generateId.
|
|
1484
|
+
*/
|
|
1485
|
+
generateId?: () => string;
|
|
1486
|
+
/**
|
|
1487
|
+
* How to validate the `type` field on new tool call deltas.
|
|
1488
|
+
* - `'none'`: no validation (default)
|
|
1489
|
+
* - `'if-present'`: throw if type is present and not `'function'`
|
|
1490
|
+
* - `'required'`: throw if type is not exactly `'function'`
|
|
1491
|
+
*/
|
|
1492
|
+
typeValidation?: 'none' | 'if-present' | 'required';
|
|
1493
|
+
/**
|
|
1494
|
+
* Extract provider-specific metadata from a tool call delta.
|
|
1495
|
+
* Called once when a new tool call is detected.
|
|
1496
|
+
*/
|
|
1497
|
+
extractMetadata?: (delta: DELTA) => SharedV3ProviderMetadata | undefined;
|
|
1498
|
+
/**
|
|
1499
|
+
* Build the `providerMetadata` object for a `tool-call` event.
|
|
1500
|
+
*/
|
|
1501
|
+
buildToolCallProviderMetadata?: (metadata: SharedV3ProviderMetadata | undefined) => SharedV3ProviderMetadata | undefined;
|
|
1502
|
+
}
|
|
1503
|
+
type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<LanguageModelV3StreamPart>, 'enqueue'>;
|
|
1504
|
+
/**
|
|
1505
|
+
* Tracks streaming tool call state across multiple deltas from an
|
|
1506
|
+
* OpenAI-compatible chat completion stream.
|
|
1507
|
+
*/
|
|
1508
|
+
declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
1509
|
+
private toolCalls;
|
|
1510
|
+
private toolCallsById;
|
|
1511
|
+
private toolCallsByIndex;
|
|
1512
|
+
private usedToolCallIds;
|
|
1513
|
+
private nextGeneratedIdSuffixes;
|
|
1514
|
+
private readonly controller;
|
|
1515
|
+
private readonly _generateId;
|
|
1516
|
+
private readonly typeValidation;
|
|
1517
|
+
private readonly extractMetadata?;
|
|
1518
|
+
private readonly buildToolCallProviderMetadata?;
|
|
1519
|
+
constructor(controller: StreamingToolCallTrackerController, options?: StreamingToolCallTrackerOptions<DELTA>);
|
|
1520
|
+
processDelta(toolCallDelta: DELTA): void;
|
|
1521
|
+
flush(): void;
|
|
1522
|
+
private resolveToolCall;
|
|
1523
|
+
private filterToolCallsByName;
|
|
1524
|
+
private resolveMatchingToolCall;
|
|
1525
|
+
private processNewToolCall;
|
|
1526
|
+
private associateWireId;
|
|
1527
|
+
private associateIndex;
|
|
1528
|
+
private createToolCallId;
|
|
1529
|
+
private getNonBlankString;
|
|
1530
|
+
private processExistingToolCall;
|
|
1531
|
+
private finishToolCall;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1435
1534
|
/**
|
|
1436
1535
|
* Strips file extension segments from a filename.
|
|
1437
1536
|
*
|
|
@@ -1589,4 +1688,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1589
1688
|
*/
|
|
1590
1689
|
type ToolCallOptions = ToolExecutionOptions;
|
|
1591
1690
|
|
|
1592
|
-
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, EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, type EmbeddingModelProviderOptionsTransformer, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, type ShouldRetryFunction, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1691
|
+
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, EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, type EmbeddingModelProviderOptionsTransformer, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, SharedV3ProviderOptions, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, JSONObject, TypeValidationContext } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, SharedV3ProviderOptions, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, JSONObject, LanguageModelV3StreamPart, SharedV3ProviderMetadata, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
export * from '@standard-schema/spec';
|
|
4
4
|
import * as z3 from 'zod/v3';
|
|
@@ -225,6 +225,30 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
|
225
225
|
maxBytes?: number;
|
|
226
226
|
}): Promise<Uint8Array>;
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Fetch function type (standardizes the version of fetch used).
|
|
230
|
+
*/
|
|
231
|
+
type FetchFunction = typeof globalThis.fetch;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Fetches one validated URL without following redirects.
|
|
235
|
+
*
|
|
236
|
+
* On Node.js, the default fetch validates and pins DNS results at connect time.
|
|
237
|
+
* An injected fetch is responsible for equivalent connect-time validation.
|
|
238
|
+
* Redirects are rejected by default. Callers using `redirect: 'manual'` must
|
|
239
|
+
* validate the Location target before issuing another request.
|
|
240
|
+
*/
|
|
241
|
+
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
|
|
242
|
+
url: string | URL;
|
|
243
|
+
init?: RequestInit;
|
|
244
|
+
fetch?: FetchFunction;
|
|
245
|
+
/**
|
|
246
|
+
* A developer-configured origin that may legitimately resolve to a private
|
|
247
|
+
* address. This must never be derived from untrusted response data.
|
|
248
|
+
*/
|
|
249
|
+
trustedOrigin?: string;
|
|
250
|
+
redirect?: 'error' | 'manual';
|
|
251
|
+
}): Promise<Response>;
|
|
228
252
|
/**
|
|
229
253
|
* Fetches a URL while enforcing the SSRF download guard on every hop.
|
|
230
254
|
*
|
|
@@ -242,6 +266,13 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
|
242
266
|
* runtime we cannot validate the hop, so we fail closed rather than follow it
|
|
243
267
|
* blindly and bypass the SSRF guard.
|
|
244
268
|
*
|
|
269
|
+
* A hop that is same-origin with `trustedOrigin` (the developer-configured
|
|
270
|
+
* endpoint) skips target validation: that origin is exactly what an
|
|
271
|
+
* unvalidated, config-derived request would fetch anyway, and validating it
|
|
272
|
+
* would break legitimate self-hosted / localhost deployments whose response
|
|
273
|
+
* URLs point back at the configured host. Hops on any other origin are always
|
|
274
|
+
* validated.
|
|
275
|
+
*
|
|
245
276
|
* The returned response is the final (non-redirect) response. The caller is
|
|
246
277
|
* responsible for checking `response.ok` and reading the body.
|
|
247
278
|
*
|
|
@@ -253,18 +284,19 @@ declare function readResponseWithSizeLimit({ response, url, maxBytes, }: {
|
|
|
253
284
|
* @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
|
|
254
285
|
* a redirect cannot be validated on a non-browser runtime.
|
|
255
286
|
*/
|
|
256
|
-
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, }: {
|
|
287
|
+
declare function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects, fetch: customFetch, trustedOrigin, }: {
|
|
257
288
|
url: string;
|
|
258
289
|
headers?: HeadersInit;
|
|
259
290
|
abortSignal?: AbortSignal;
|
|
260
291
|
maxRedirects?: number;
|
|
292
|
+
fetch?: FetchFunction;
|
|
293
|
+
/**
|
|
294
|
+
* A developer-configured origin whose hops skip target validation. Must
|
|
295
|
+
* never be derived from response data.
|
|
296
|
+
*/
|
|
297
|
+
trustedOrigin?: string;
|
|
261
298
|
}): Promise<Response>;
|
|
262
299
|
|
|
263
|
-
/**
|
|
264
|
-
* Fetch function type (standardizes the version of fetch used).
|
|
265
|
-
*/
|
|
266
|
-
type FetchFunction = typeof globalThis.fetch;
|
|
267
|
-
|
|
268
300
|
/**
|
|
269
301
|
* Creates an ID generator.
|
|
270
302
|
* The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
@@ -1432,6 +1464,73 @@ declare const retryWithExponentialBackoff: ({ maxRetries, initialDelayInMs, back
|
|
|
1432
1464
|
|
|
1433
1465
|
declare function secureJsonParse(text: string): any;
|
|
1434
1466
|
|
|
1467
|
+
/**
|
|
1468
|
+
* Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
|
|
1469
|
+
*/
|
|
1470
|
+
interface StreamingToolCallDelta {
|
|
1471
|
+
index?: number | null;
|
|
1472
|
+
id?: string | null;
|
|
1473
|
+
type?: string | null;
|
|
1474
|
+
function?: {
|
|
1475
|
+
name?: string | null;
|
|
1476
|
+
arguments?: string | null;
|
|
1477
|
+
} | null;
|
|
1478
|
+
}
|
|
1479
|
+
interface StreamingToolCallTrackerOptions<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
1480
|
+
/**
|
|
1481
|
+
* ID generator function for tool call IDs.
|
|
1482
|
+
* Blank or repeated outputs are converted to usable unique IDs.
|
|
1483
|
+
* Defaults to the standard generateId.
|
|
1484
|
+
*/
|
|
1485
|
+
generateId?: () => string;
|
|
1486
|
+
/**
|
|
1487
|
+
* How to validate the `type` field on new tool call deltas.
|
|
1488
|
+
* - `'none'`: no validation (default)
|
|
1489
|
+
* - `'if-present'`: throw if type is present and not `'function'`
|
|
1490
|
+
* - `'required'`: throw if type is not exactly `'function'`
|
|
1491
|
+
*/
|
|
1492
|
+
typeValidation?: 'none' | 'if-present' | 'required';
|
|
1493
|
+
/**
|
|
1494
|
+
* Extract provider-specific metadata from a tool call delta.
|
|
1495
|
+
* Called once when a new tool call is detected.
|
|
1496
|
+
*/
|
|
1497
|
+
extractMetadata?: (delta: DELTA) => SharedV3ProviderMetadata | undefined;
|
|
1498
|
+
/**
|
|
1499
|
+
* Build the `providerMetadata` object for a `tool-call` event.
|
|
1500
|
+
*/
|
|
1501
|
+
buildToolCallProviderMetadata?: (metadata: SharedV3ProviderMetadata | undefined) => SharedV3ProviderMetadata | undefined;
|
|
1502
|
+
}
|
|
1503
|
+
type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<LanguageModelV3StreamPart>, 'enqueue'>;
|
|
1504
|
+
/**
|
|
1505
|
+
* Tracks streaming tool call state across multiple deltas from an
|
|
1506
|
+
* OpenAI-compatible chat completion stream.
|
|
1507
|
+
*/
|
|
1508
|
+
declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
1509
|
+
private toolCalls;
|
|
1510
|
+
private toolCallsById;
|
|
1511
|
+
private toolCallsByIndex;
|
|
1512
|
+
private usedToolCallIds;
|
|
1513
|
+
private nextGeneratedIdSuffixes;
|
|
1514
|
+
private readonly controller;
|
|
1515
|
+
private readonly _generateId;
|
|
1516
|
+
private readonly typeValidation;
|
|
1517
|
+
private readonly extractMetadata?;
|
|
1518
|
+
private readonly buildToolCallProviderMetadata?;
|
|
1519
|
+
constructor(controller: StreamingToolCallTrackerController, options?: StreamingToolCallTrackerOptions<DELTA>);
|
|
1520
|
+
processDelta(toolCallDelta: DELTA): void;
|
|
1521
|
+
flush(): void;
|
|
1522
|
+
private resolveToolCall;
|
|
1523
|
+
private filterToolCallsByName;
|
|
1524
|
+
private resolveMatchingToolCall;
|
|
1525
|
+
private processNewToolCall;
|
|
1526
|
+
private associateWireId;
|
|
1527
|
+
private associateIndex;
|
|
1528
|
+
private createToolCallId;
|
|
1529
|
+
private getNonBlankString;
|
|
1530
|
+
private processExistingToolCall;
|
|
1531
|
+
private finishToolCall;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1435
1534
|
/**
|
|
1436
1535
|
* Strips file extension segments from a filename.
|
|
1437
1536
|
*
|
|
@@ -1589,4 +1688,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1589
1688
|
*/
|
|
1590
1689
|
type ToolCallOptions = ToolExecutionOptions;
|
|
1591
1690
|
|
|
1592
|
-
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, EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, type EmbeddingModelProviderOptionsTransformer, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, type ShouldRetryFunction, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1691
|
+
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, EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, type EmbeddingModelProviderOptionsTransformer, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isNonNullable, isParsableJson, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|