@ai-sdk/provider-utils 5.0.0-beta.26 → 5.0.0-beta.28
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 +19 -0
- package/dist/index.d.ts +103 -18
- package/dist/index.js +52 -24
- package/dist/index.js.map +1 -1
- package/dist/test/index.d.ts +2 -1
- package/dist/test/index.js +15 -1
- package/dist/test/index.js.map +1 -1
- package/package.json +7 -5
- package/src/index.ts +9 -5
- package/src/maybe-promise-like.ts +3 -0
- package/src/{provider-tool-factory.ts → provider-defined-tool-factory.ts} +12 -20
- package/src/provider-executed-tool-factory.ts +70 -0
- package/src/streaming-tool-call-tracker.ts +34 -36
- package/src/test/is-node-version.ts +22 -1
- package/src/types/index.ts +1 -0
- package/src/types/sensitive-context.ts +9 -0
- package/src/types/tool-approval-request.ts +7 -0
- package/src/types/tool.ts +58 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.0-beta.28
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9f0e36c: trigger release for all packages after provenance setup
|
|
8
|
+
- Updated dependencies [9f0e36c]
|
|
9
|
+
- @ai-sdk/provider@4.0.0-beta.13
|
|
10
|
+
|
|
11
|
+
## 5.0.0-beta.27
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 785fe16: feat: distinguish provider-defined and provider-executed tools
|
|
16
|
+
- 67df0a0: feat: add sensitiveContext property to Tool
|
|
17
|
+
- befb78c: refactoring: remove real-time delays in unit tests
|
|
18
|
+
- 0458559: fix: deprecate needsApproval on Tool
|
|
19
|
+
- 5852c0a: refactoring(provider-utils): add controller as property to StreamingToolCallTracker
|
|
20
|
+
- fc92055: feat(ai): automatic tool approval
|
|
21
|
+
|
|
3
22
|
## 5.0.0-beta.26
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModelV4File, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, LanguageModelV4FilePart, SharedV4ProviderReference, LanguageModelV4CallOptions, SharedV4Warning, SharedV4ProviderOptions, JSONObject,
|
|
1
|
+
import { ImageModelV4File, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, LanguageModelV4FilePart, SharedV4ProviderReference, LanguageModelV4CallOptions, SharedV4Warning, SharedV4ProviderOptions, JSONObject, LanguageModelV4StreamPart, SharedV4ProviderMetadata, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
export { getErrorMessage } from '@ai-sdk/provider';
|
|
3
3
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
4
4
|
export * from '@standard-schema/spec';
|
|
@@ -489,6 +489,9 @@ declare function mapReasoningToProviderBudget({ reasoning, maxOutputTokens, maxR
|
|
|
489
489
|
warnings: SharedV4Warning[];
|
|
490
490
|
}): number | undefined;
|
|
491
491
|
|
|
492
|
+
/**
|
|
493
|
+
* A value that can be provided either synchronously or as a promise-like.
|
|
494
|
+
*/
|
|
492
495
|
type MaybePromiseLike<T> = T | PromiseLike<T>;
|
|
493
496
|
|
|
494
497
|
/**
|
|
@@ -970,6 +973,11 @@ type ToolResultOutput = {
|
|
|
970
973
|
}>;
|
|
971
974
|
};
|
|
972
975
|
|
|
976
|
+
/**
|
|
977
|
+
* A context object that is passed into tool execution.
|
|
978
|
+
*/
|
|
979
|
+
type Context = Record<string, unknown>;
|
|
980
|
+
|
|
973
981
|
/**
|
|
974
982
|
* Tool approval request prompt part.
|
|
975
983
|
*/
|
|
@@ -983,6 +991,12 @@ type ToolApprovalRequest = {
|
|
|
983
991
|
* ID of the tool call that the approval request is for.
|
|
984
992
|
*/
|
|
985
993
|
toolCallId: string;
|
|
994
|
+
/**
|
|
995
|
+
* Flag indicating whether the tool was automatically approved or denied.
|
|
996
|
+
*
|
|
997
|
+
* @default false
|
|
998
|
+
*/
|
|
999
|
+
isAutomatic?: boolean;
|
|
986
1000
|
};
|
|
987
1001
|
|
|
988
1002
|
/**
|
|
@@ -1089,9 +1103,12 @@ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
|
|
1089
1103
|
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
|
1090
1104
|
|
|
1091
1105
|
/**
|
|
1092
|
-
*
|
|
1106
|
+
* Top-level context properties that contain sensitive data and should be
|
|
1107
|
+
* excluded from telemetry.
|
|
1093
1108
|
*/
|
|
1094
|
-
type Context =
|
|
1109
|
+
type SensitiveContext<CONTEXT extends Context | unknown | never> = {
|
|
1110
|
+
[KEY in keyof CONTEXT]?: boolean;
|
|
1111
|
+
} | undefined;
|
|
1095
1112
|
|
|
1096
1113
|
/**
|
|
1097
1114
|
* Additional options that are sent into each tool execution.
|
|
@@ -1111,7 +1128,8 @@ interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
|
|
|
1111
1128
|
*/
|
|
1112
1129
|
abortSignal?: AbortSignal;
|
|
1113
1130
|
/**
|
|
1114
|
-
*
|
|
1131
|
+
* Tool context as defined by the tool's context schema.
|
|
1132
|
+
* The tool context is specific to the tool and is passed to the tool execution.
|
|
1115
1133
|
*
|
|
1116
1134
|
* Treat the context object as immutable inside tools.
|
|
1117
1135
|
* Mutating the context object can lead to race conditions and unexpected results
|
|
@@ -1124,6 +1142,8 @@ interface ToolExecutionOptions<CONTEXT extends Context | unknown | never> {
|
|
|
1124
1142
|
}
|
|
1125
1143
|
/**
|
|
1126
1144
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
1145
|
+
*
|
|
1146
|
+
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
1127
1147
|
*/
|
|
1128
1148
|
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never> = (input: INPUT, options: {
|
|
1129
1149
|
/**
|
|
@@ -1136,7 +1156,8 @@ type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context | unknown | never>
|
|
|
1136
1156
|
*/
|
|
1137
1157
|
messages: ModelMessage[];
|
|
1138
1158
|
/**
|
|
1139
|
-
*
|
|
1159
|
+
* Tool context as defined by the tool's context schema.
|
|
1160
|
+
* The tool context is specific to the tool and is passed to the tool execution.
|
|
1140
1161
|
*
|
|
1141
1162
|
* Treat the context object as immutable inside tools.
|
|
1142
1163
|
* Mutating the context object can lead to race conditions and unexpected results
|
|
@@ -1164,8 +1185,14 @@ type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context | unknown | nev
|
|
|
1164
1185
|
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
1165
1186
|
*/
|
|
1166
1187
|
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1188
|
+
/**
|
|
1189
|
+
* The schema of the output that the tool produces.
|
|
1190
|
+
*/
|
|
1167
1191
|
outputSchema?: FlexibleSchema<OUTPUT>;
|
|
1168
1192
|
} | {
|
|
1193
|
+
/**
|
|
1194
|
+
* The schema of the output that the tool produces.
|
|
1195
|
+
*/
|
|
1169
1196
|
outputSchema: FlexibleSchema<OUTPUT>;
|
|
1170
1197
|
execute?: never;
|
|
1171
1198
|
}>;
|
|
@@ -1213,8 +1240,15 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1213
1240
|
* The context is passed to execute function as part of the execution options.
|
|
1214
1241
|
*/
|
|
1215
1242
|
contextSchema?: FlexibleSchema<CONTEXT>;
|
|
1243
|
+
/**
|
|
1244
|
+
* Marks top-level context properties that contain sensitive data and should be excluded from telemetry.
|
|
1245
|
+
* Properties marked as `true` are omitted from telemetry integrations.
|
|
1246
|
+
*/
|
|
1247
|
+
sensitiveContext?: SensitiveContext<CONTEXT>;
|
|
1216
1248
|
/**
|
|
1217
1249
|
* Whether the tool needs approval before it can be executed.
|
|
1250
|
+
*
|
|
1251
|
+
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
1218
1252
|
*/
|
|
1219
1253
|
needsApproval?: boolean | ToolNeedsApprovalFunction<[
|
|
1220
1254
|
INPUT
|
|
@@ -1288,6 +1322,10 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1288
1322
|
* The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
|
|
1289
1323
|
*/
|
|
1290
1324
|
id: `${string}.${string}`;
|
|
1325
|
+
/**
|
|
1326
|
+
* Flag that indicates whether the tool is executed by the provider.
|
|
1327
|
+
*/
|
|
1328
|
+
isProviderExecuted: boolean;
|
|
1291
1329
|
/**
|
|
1292
1330
|
* The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
|
1293
1331
|
*/
|
|
@@ -1318,10 +1356,37 @@ declare function tool<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>
|
|
|
1318
1356
|
* Defines a dynamic tool.
|
|
1319
1357
|
*/
|
|
1320
1358
|
declare function dynamicTool(tool: {
|
|
1359
|
+
/**
|
|
1360
|
+
* An optional description of what the tool does.
|
|
1361
|
+
* Will be used by the language model to decide whether to use the tool.
|
|
1362
|
+
* Not used for provider-defined tools.
|
|
1363
|
+
*/
|
|
1321
1364
|
description?: string;
|
|
1365
|
+
/**
|
|
1366
|
+
* An optional title of the tool.
|
|
1367
|
+
*/
|
|
1322
1368
|
title?: string;
|
|
1369
|
+
/**
|
|
1370
|
+
* Additional provider-specific metadata. They are passed through
|
|
1371
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
1372
|
+
* functionality that can be fully encapsulated in the provider.
|
|
1373
|
+
*/
|
|
1323
1374
|
providerOptions?: ProviderOptions;
|
|
1375
|
+
/**
|
|
1376
|
+
* The schema of the input that the tool expects.
|
|
1377
|
+
* The language model will use this to generate the input.
|
|
1378
|
+
* It is also used to validate the output of the language model.
|
|
1379
|
+
*
|
|
1380
|
+
* You can use descriptions on the schema properties to make the input understandable for the language model.
|
|
1381
|
+
*/
|
|
1324
1382
|
inputSchema: FlexibleSchema<unknown>;
|
|
1383
|
+
/**
|
|
1384
|
+
* An async function that is called with the arguments from the tool call and produces a result.
|
|
1385
|
+
* If not provided, the tool will not be executed automatically.
|
|
1386
|
+
*
|
|
1387
|
+
* @args is the input of the tool call.
|
|
1388
|
+
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
1389
|
+
*/
|
|
1325
1390
|
execute: ToolExecuteFunction<unknown, unknown, Context>;
|
|
1326
1391
|
/**
|
|
1327
1392
|
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
@@ -1350,7 +1415,11 @@ declare function dynamicTool(tool: {
|
|
|
1350
1415
|
type: 'dynamic';
|
|
1351
1416
|
};
|
|
1352
1417
|
|
|
1353
|
-
|
|
1418
|
+
/**
|
|
1419
|
+
* A provider-defined tool is a tool for which the provider defines the input
|
|
1420
|
+
* and output schemas, but does not execute the tool.
|
|
1421
|
+
*/
|
|
1422
|
+
type ProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}> = <OUTPUT>(options: ARGS & {
|
|
1354
1423
|
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1355
1424
|
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
1356
1425
|
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
@@ -1358,11 +1427,11 @@ type ProviderToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {
|
|
|
1358
1427
|
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1359
1428
|
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1360
1429
|
}) => Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1361
|
-
declare function
|
|
1430
|
+
declare function createProviderDefinedToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, }: {
|
|
1362
1431
|
id: `${string}.${string}`;
|
|
1363
1432
|
inputSchema: FlexibleSchema<INPUT>;
|
|
1364
|
-
}):
|
|
1365
|
-
type
|
|
1433
|
+
}): ProviderDefinedToolFactory<INPUT, ARGS, CONTEXT>;
|
|
1434
|
+
type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
|
|
1366
1435
|
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1367
1436
|
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
1368
1437
|
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
@@ -1370,7 +1439,21 @@ type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CON
|
|
|
1370
1439
|
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1371
1440
|
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1372
1441
|
}) => Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1373
|
-
declare function
|
|
1442
|
+
declare function createProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, }: {
|
|
1443
|
+
id: `${string}.${string}`;
|
|
1444
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
1445
|
+
outputSchema: FlexibleSchema<OUTPUT>;
|
|
1446
|
+
}): ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS, CONTEXT>;
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* A provider-executed tool is a tool for which the provider executes the tool.
|
|
1450
|
+
*/
|
|
1451
|
+
type ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
|
|
1452
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1453
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1454
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1455
|
+
}) => Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1456
|
+
declare function createProviderExecutedToolFactory<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
|
|
1374
1457
|
id: `${string}.${string}`;
|
|
1375
1458
|
inputSchema: FlexibleSchema<INPUT>;
|
|
1376
1459
|
outputSchema: FlexibleSchema<OUTPUT>;
|
|
@@ -1385,7 +1468,7 @@ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS e
|
|
|
1385
1468
|
* @default false
|
|
1386
1469
|
*/
|
|
1387
1470
|
supportsDeferredResults?: boolean;
|
|
1388
|
-
}):
|
|
1471
|
+
}): ProviderExecutedToolFactory<INPUT, OUTPUT, ARGS, CONTEXT>;
|
|
1389
1472
|
|
|
1390
1473
|
/**
|
|
1391
1474
|
* Default maximum download size: 2 GiB.
|
|
@@ -1499,7 +1582,7 @@ interface StreamingToolCallDelta {
|
|
|
1499
1582
|
arguments?: string | null;
|
|
1500
1583
|
} | null;
|
|
1501
1584
|
}
|
|
1502
|
-
interface StreamingToolCallTrackerOptions {
|
|
1585
|
+
interface StreamingToolCallTrackerOptions<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
1503
1586
|
/**
|
|
1504
1587
|
* ID generator function for tool call IDs.
|
|
1505
1588
|
* Defaults to the standard generateId.
|
|
@@ -1518,7 +1601,7 @@ interface StreamingToolCallTrackerOptions {
|
|
|
1518
1601
|
* The returned metadata is stored on the tool call and passed to
|
|
1519
1602
|
* `buildToolCallProviderMetadata` when the tool call is finalized.
|
|
1520
1603
|
*/
|
|
1521
|
-
extractMetadata?: (delta:
|
|
1604
|
+
extractMetadata?: (delta: DELTA) => SharedV4ProviderMetadata | undefined;
|
|
1522
1605
|
/**
|
|
1523
1606
|
* Build the `providerMetadata` object for a `tool-call` event.
|
|
1524
1607
|
* Receives the metadata previously extracted via `extractMetadata`.
|
|
@@ -1526,6 +1609,7 @@ interface StreamingToolCallTrackerOptions {
|
|
|
1526
1609
|
*/
|
|
1527
1610
|
buildToolCallProviderMetadata?: (metadata: SharedV4ProviderMetadata | undefined) => SharedV4ProviderMetadata | undefined;
|
|
1528
1611
|
}
|
|
1612
|
+
type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<LanguageModelV4StreamPart>, 'enqueue'>;
|
|
1529
1613
|
/**
|
|
1530
1614
|
* Tracks streaming tool call state across multiple deltas from an
|
|
1531
1615
|
* OpenAI-compatible chat completion stream. Handles argument accumulation,
|
|
@@ -1534,24 +1618,25 @@ interface StreamingToolCallTrackerOptions {
|
|
|
1534
1618
|
*
|
|
1535
1619
|
* Used by openai, openai-compatible, groq, deepseek, and alibaba providers.
|
|
1536
1620
|
*/
|
|
1537
|
-
declare class StreamingToolCallTracker {
|
|
1621
|
+
declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
1538
1622
|
private toolCalls;
|
|
1623
|
+
private readonly controller;
|
|
1539
1624
|
private readonly _generateId;
|
|
1540
1625
|
private readonly typeValidation;
|
|
1541
1626
|
private readonly extractMetadata?;
|
|
1542
1627
|
private readonly buildToolCallProviderMetadata?;
|
|
1543
|
-
constructor(options?: StreamingToolCallTrackerOptions);
|
|
1628
|
+
constructor(controller: StreamingToolCallTrackerController, options?: StreamingToolCallTrackerOptions<DELTA>);
|
|
1544
1629
|
/**
|
|
1545
1630
|
* Process a tool call delta from a streaming response chunk.
|
|
1546
1631
|
* Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
|
|
1547
1632
|
* events as appropriate.
|
|
1548
1633
|
*/
|
|
1549
|
-
processDelta(toolCallDelta:
|
|
1634
|
+
processDelta(toolCallDelta: DELTA): void;
|
|
1550
1635
|
/**
|
|
1551
1636
|
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
1552
1637
|
* flush handler to ensure all tool calls are properly completed.
|
|
1553
1638
|
*/
|
|
1554
|
-
flush(
|
|
1639
|
+
flush(): void;
|
|
1555
1640
|
private processNewToolCall;
|
|
1556
1641
|
private processExistingToolCall;
|
|
1557
1642
|
private finishToolCall;
|
|
@@ -1762,4 +1847,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1762
1847
|
dynamic?: boolean;
|
|
1763
1848
|
}
|
|
1764
1849
|
|
|
1765
|
-
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type ExecutableTool, type FetchFunction, type FilePart, type FlexibleSchema, 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
|
|
1850
|
+
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type ExecutableTool, type FetchFunction, type FilePart, type FlexibleSchema, 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 ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SensitiveContext, 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, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isExecutableTool, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -576,7 +576,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
576
576
|
}
|
|
577
577
|
|
|
578
578
|
// src/version.ts
|
|
579
|
-
var VERSION = true ? "5.0.0-beta.
|
|
579
|
+
var VERSION = true ? "5.0.0-beta.28" : "0.0.0-test";
|
|
580
580
|
|
|
581
581
|
// src/get-from-api.ts
|
|
582
582
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -2501,8 +2501,8 @@ function dynamicTool(tool2) {
|
|
|
2501
2501
|
return { ...tool2, type: "dynamic" };
|
|
2502
2502
|
}
|
|
2503
2503
|
|
|
2504
|
-
// src/provider-tool-factory.ts
|
|
2505
|
-
function
|
|
2504
|
+
// src/provider-defined-tool-factory.ts
|
|
2505
|
+
function createProviderDefinedToolFactory({
|
|
2506
2506
|
id,
|
|
2507
2507
|
inputSchema
|
|
2508
2508
|
}) {
|
|
@@ -2517,6 +2517,7 @@ function createProviderToolFactory({
|
|
|
2517
2517
|
...args
|
|
2518
2518
|
}) => tool({
|
|
2519
2519
|
type: "provider",
|
|
2520
|
+
isProviderExecuted: false,
|
|
2520
2521
|
id,
|
|
2521
2522
|
args,
|
|
2522
2523
|
inputSchema,
|
|
@@ -2529,11 +2530,10 @@ function createProviderToolFactory({
|
|
|
2529
2530
|
onInputAvailable
|
|
2530
2531
|
});
|
|
2531
2532
|
}
|
|
2532
|
-
function
|
|
2533
|
+
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
2533
2534
|
id,
|
|
2534
2535
|
inputSchema,
|
|
2535
|
-
outputSchema
|
|
2536
|
-
supportsDeferredResults
|
|
2536
|
+
outputSchema
|
|
2537
2537
|
}) {
|
|
2538
2538
|
return ({
|
|
2539
2539
|
execute,
|
|
@@ -2545,6 +2545,7 @@ function createProviderToolFactoryWithOutputSchema({
|
|
|
2545
2545
|
...args
|
|
2546
2546
|
}) => tool({
|
|
2547
2547
|
type: "provider",
|
|
2548
|
+
isProviderExecuted: false,
|
|
2548
2549
|
id,
|
|
2549
2550
|
args,
|
|
2550
2551
|
inputSchema,
|
|
@@ -2554,6 +2555,31 @@ function createProviderToolFactoryWithOutputSchema({
|
|
|
2554
2555
|
toModelOutput,
|
|
2555
2556
|
onInputStart,
|
|
2556
2557
|
onInputDelta,
|
|
2558
|
+
onInputAvailable
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2562
|
+
// src/provider-executed-tool-factory.ts
|
|
2563
|
+
function createProviderExecutedToolFactory({
|
|
2564
|
+
id,
|
|
2565
|
+
inputSchema,
|
|
2566
|
+
outputSchema,
|
|
2567
|
+
supportsDeferredResults
|
|
2568
|
+
}) {
|
|
2569
|
+
return ({
|
|
2570
|
+
onInputStart,
|
|
2571
|
+
onInputDelta,
|
|
2572
|
+
onInputAvailable,
|
|
2573
|
+
...args
|
|
2574
|
+
}) => tool({
|
|
2575
|
+
type: "provider",
|
|
2576
|
+
isProviderExecuted: true,
|
|
2577
|
+
id,
|
|
2578
|
+
args,
|
|
2579
|
+
inputSchema,
|
|
2580
|
+
outputSchema,
|
|
2581
|
+
onInputStart,
|
|
2582
|
+
onInputDelta,
|
|
2557
2583
|
onInputAvailable,
|
|
2558
2584
|
supportsDeferredResults
|
|
2559
2585
|
});
|
|
@@ -2780,9 +2806,10 @@ import {
|
|
|
2780
2806
|
InvalidResponseDataError
|
|
2781
2807
|
} from "@ai-sdk/provider";
|
|
2782
2808
|
var StreamingToolCallTracker = class {
|
|
2783
|
-
constructor(options = {}) {
|
|
2809
|
+
constructor(controller, options = {}) {
|
|
2784
2810
|
this.toolCalls = [];
|
|
2785
2811
|
var _a2, _b2;
|
|
2812
|
+
this.controller = controller;
|
|
2786
2813
|
this._generateId = (_a2 = options.generateId) != null ? _a2 : generateId;
|
|
2787
2814
|
this.typeValidation = (_b2 = options.typeValidation) != null ? _b2 : "none";
|
|
2788
2815
|
this.extractMetadata = options.extractMetadata;
|
|
@@ -2793,27 +2820,27 @@ var StreamingToolCallTracker = class {
|
|
|
2793
2820
|
* Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
|
|
2794
2821
|
* events as appropriate.
|
|
2795
2822
|
*/
|
|
2796
|
-
processDelta(toolCallDelta
|
|
2823
|
+
processDelta(toolCallDelta) {
|
|
2797
2824
|
var _a2;
|
|
2798
2825
|
const index = (_a2 = toolCallDelta.index) != null ? _a2 : this.toolCalls.length;
|
|
2799
2826
|
if (this.toolCalls[index] == null) {
|
|
2800
|
-
this.processNewToolCall(index, toolCallDelta
|
|
2827
|
+
this.processNewToolCall(index, toolCallDelta);
|
|
2801
2828
|
} else {
|
|
2802
|
-
this.processExistingToolCall(index, toolCallDelta
|
|
2829
|
+
this.processExistingToolCall(index, toolCallDelta);
|
|
2803
2830
|
}
|
|
2804
2831
|
}
|
|
2805
2832
|
/**
|
|
2806
2833
|
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
2807
2834
|
* flush handler to ensure all tool calls are properly completed.
|
|
2808
2835
|
*/
|
|
2809
|
-
flush(
|
|
2836
|
+
flush() {
|
|
2810
2837
|
for (const toolCall of this.toolCalls) {
|
|
2811
2838
|
if (!toolCall.hasFinished) {
|
|
2812
|
-
this.finishToolCall(toolCall
|
|
2839
|
+
this.finishToolCall(toolCall);
|
|
2813
2840
|
}
|
|
2814
2841
|
}
|
|
2815
2842
|
}
|
|
2816
|
-
processNewToolCall(index, toolCallDelta
|
|
2843
|
+
processNewToolCall(index, toolCallDelta) {
|
|
2817
2844
|
var _a2, _b2, _c;
|
|
2818
2845
|
if (this.typeValidation === "required") {
|
|
2819
2846
|
if (toolCallDelta.type !== "function") {
|
|
@@ -2842,7 +2869,7 @@ var StreamingToolCallTracker = class {
|
|
|
2842
2869
|
message: `Expected 'function.name' to be a string.`
|
|
2843
2870
|
});
|
|
2844
2871
|
}
|
|
2845
|
-
enqueue({
|
|
2872
|
+
this.controller.enqueue({
|
|
2846
2873
|
type: "tool-input-start",
|
|
2847
2874
|
id: toolCallDelta.id,
|
|
2848
2875
|
toolName: toolCallDelta.function.name
|
|
@@ -2860,17 +2887,17 @@ var StreamingToolCallTracker = class {
|
|
|
2860
2887
|
};
|
|
2861
2888
|
const toolCall = this.toolCalls[index];
|
|
2862
2889
|
if (toolCall.function.arguments.length > 0) {
|
|
2863
|
-
enqueue({
|
|
2890
|
+
this.controller.enqueue({
|
|
2864
2891
|
type: "tool-input-delta",
|
|
2865
2892
|
id: toolCall.id,
|
|
2866
2893
|
delta: toolCall.function.arguments
|
|
2867
2894
|
});
|
|
2868
2895
|
}
|
|
2869
2896
|
if (isParsableJson(toolCall.function.arguments)) {
|
|
2870
|
-
this.finishToolCall(toolCall
|
|
2897
|
+
this.finishToolCall(toolCall);
|
|
2871
2898
|
}
|
|
2872
2899
|
}
|
|
2873
|
-
processExistingToolCall(index, toolCallDelta
|
|
2900
|
+
processExistingToolCall(index, toolCallDelta) {
|
|
2874
2901
|
var _a2;
|
|
2875
2902
|
const toolCall = this.toolCalls[index];
|
|
2876
2903
|
if (toolCall.hasFinished) {
|
|
@@ -2878,19 +2905,19 @@ var StreamingToolCallTracker = class {
|
|
|
2878
2905
|
}
|
|
2879
2906
|
if (((_a2 = toolCallDelta.function) == null ? void 0 : _a2.arguments) != null) {
|
|
2880
2907
|
toolCall.function.arguments += toolCallDelta.function.arguments;
|
|
2881
|
-
enqueue({
|
|
2908
|
+
this.controller.enqueue({
|
|
2882
2909
|
type: "tool-input-delta",
|
|
2883
2910
|
id: toolCall.id,
|
|
2884
2911
|
delta: toolCallDelta.function.arguments
|
|
2885
2912
|
});
|
|
2886
2913
|
}
|
|
2887
2914
|
if (isParsableJson(toolCall.function.arguments)) {
|
|
2888
|
-
this.finishToolCall(toolCall
|
|
2915
|
+
this.finishToolCall(toolCall);
|
|
2889
2916
|
}
|
|
2890
2917
|
}
|
|
2891
|
-
finishToolCall(toolCall
|
|
2918
|
+
finishToolCall(toolCall) {
|
|
2892
2919
|
var _a2, _b2;
|
|
2893
|
-
enqueue({
|
|
2920
|
+
this.controller.enqueue({
|
|
2894
2921
|
type: "tool-input-end",
|
|
2895
2922
|
id: toolCall.id
|
|
2896
2923
|
});
|
|
@@ -2898,7 +2925,7 @@ var StreamingToolCallTracker = class {
|
|
|
2898
2925
|
this,
|
|
2899
2926
|
toolCall.metadata
|
|
2900
2927
|
);
|
|
2901
|
-
enqueue({
|
|
2928
|
+
this.controller.enqueue({
|
|
2902
2929
|
type: "tool-call",
|
|
2903
2930
|
toolCallId: (_b2 = toolCall.id) != null ? _b2 : this._generateId(),
|
|
2904
2931
|
toolName: toolCall.function.name,
|
|
@@ -2977,8 +3004,9 @@ export {
|
|
|
2977
3004
|
createIdGenerator,
|
|
2978
3005
|
createJsonErrorResponseHandler,
|
|
2979
3006
|
createJsonResponseHandler,
|
|
2980
|
-
|
|
2981
|
-
|
|
3007
|
+
createProviderDefinedToolFactory,
|
|
3008
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3009
|
+
createProviderExecutedToolFactory,
|
|
2982
3010
|
createStatusCodeErrorResponseHandler,
|
|
2983
3011
|
createToolNameMapping,
|
|
2984
3012
|
delay,
|