@ai-sdk/provider-utils 5.0.0-beta.7 → 5.0.0-beta.8
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 +9 -0
- package/dist/index.d.mts +98 -58
- package/dist/index.d.ts +98 -58
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/provider-tool-factory.ts +43 -32
- package/src/types/context.ts +4 -0
- package/src/types/execute-tool.ts +24 -4
- package/src/types/index.ts +5 -9
- package/src/types/infer-tool-context.ts +7 -0
- package/src/types/infer-tool-input.ts +7 -0
- package/src/types/infer-tool-output.ts +7 -0
- package/src/types/tool.ts +55 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.0-beta.8
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 986c6fd: feat(ai): change type of experimental_context from unknown to generic
|
|
8
|
+
- 493295c: Remove the deprecated `ToolCallOptions` export.
|
|
9
|
+
|
|
10
|
+
Use `ToolExecutionOptions` instead.
|
|
11
|
+
|
|
3
12
|
## 5.0.0-beta.7
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1052,9 +1052,14 @@ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
|
|
1052
1052
|
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
|
1053
1053
|
|
|
1054
1054
|
/**
|
|
1055
|
-
*
|
|
1055
|
+
* A context object that is passed into tool execution.
|
|
1056
1056
|
*/
|
|
1057
|
-
|
|
1057
|
+
type Context = Record<string, unknown>;
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Additional options that are sent into each tool execution.
|
|
1061
|
+
*/
|
|
1062
|
+
interface ToolExecutionOptions<CONTEXT extends Context> {
|
|
1058
1063
|
/**
|
|
1059
1064
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1060
1065
|
*/
|
|
@@ -1080,12 +1085,12 @@ interface ToolExecutionOptions {
|
|
|
1080
1085
|
*
|
|
1081
1086
|
* Experimental (can break in patch releases).
|
|
1082
1087
|
*/
|
|
1083
|
-
experimental_context
|
|
1088
|
+
experimental_context: CONTEXT;
|
|
1084
1089
|
}
|
|
1085
1090
|
/**
|
|
1086
1091
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
1087
1092
|
*/
|
|
1088
|
-
type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: {
|
|
1093
|
+
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (input: INPUT, options: {
|
|
1089
1094
|
/**
|
|
1090
1095
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1091
1096
|
*/
|
|
@@ -1100,11 +1105,17 @@ type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: {
|
|
|
1100
1105
|
*
|
|
1101
1106
|
* Experimental (can break in patch releases).
|
|
1102
1107
|
*/
|
|
1103
|
-
experimental_context
|
|
1108
|
+
experimental_context: CONTEXT;
|
|
1104
1109
|
}) => boolean | PromiseLike<boolean>;
|
|
1105
|
-
|
|
1110
|
+
/**
|
|
1111
|
+
* Function that executes the tool and returns either a single result or a stream of results.
|
|
1112
|
+
*/
|
|
1113
|
+
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1106
1114
|
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
|
1107
|
-
|
|
1115
|
+
/**
|
|
1116
|
+
* Helper type to determine the output properties of a tool.
|
|
1117
|
+
*/
|
|
1118
|
+
type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context> = NeverOptional<OUTPUT, {
|
|
1108
1119
|
/**
|
|
1109
1120
|
* An async function that is called with the arguments from the tool call and produces a result.
|
|
1110
1121
|
* If not provided, the tool will not be executed automatically.
|
|
@@ -1112,7 +1123,7 @@ type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
|
|
|
1112
1123
|
* @args is the input of the tool call.
|
|
1113
1124
|
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
1114
1125
|
*/
|
|
1115
|
-
execute: ToolExecuteFunction<INPUT, OUTPUT>;
|
|
1126
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1116
1127
|
outputSchema?: FlexibleSchema<OUTPUT>;
|
|
1117
1128
|
} | {
|
|
1118
1129
|
outputSchema: FlexibleSchema<OUTPUT>;
|
|
@@ -1124,7 +1135,7 @@ type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
|
|
|
1124
1135
|
*
|
|
1125
1136
|
* The tool can also contain an optional execute function for the actual execution function of the tool.
|
|
1126
1137
|
*/
|
|
1127
|
-
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any> = {
|
|
1138
|
+
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context = Context> = {
|
|
1128
1139
|
/**
|
|
1129
1140
|
* An optional description of what the tool does.
|
|
1130
1141
|
* Will be used by the language model to decide whether to use the tool.
|
|
@@ -1156,10 +1167,18 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1156
1167
|
inputExamples?: Array<{
|
|
1157
1168
|
input: NoInfer<INPUT>;
|
|
1158
1169
|
}>;
|
|
1170
|
+
/**
|
|
1171
|
+
* An optional schema describing the context that the tool expects.
|
|
1172
|
+
*
|
|
1173
|
+
* The context is passed to execute function as part of the execution options.
|
|
1174
|
+
*/
|
|
1175
|
+
contextSchema?: FlexibleSchema<CONTEXT>;
|
|
1159
1176
|
/**
|
|
1160
1177
|
* Whether the tool needs approval before it can be executed.
|
|
1161
1178
|
*/
|
|
1162
|
-
needsApproval?: boolean | ToolNeedsApprovalFunction<[
|
|
1179
|
+
needsApproval?: boolean | ToolNeedsApprovalFunction<[
|
|
1180
|
+
INPUT
|
|
1181
|
+
] extends [never] ? unknown : INPUT, NoInfer<CONTEXT>>;
|
|
1163
1182
|
/**
|
|
1164
1183
|
* Strict mode setting for the tool.
|
|
1165
1184
|
*
|
|
@@ -1172,22 +1191,22 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1172
1191
|
* Optional function that is called when the argument streaming starts.
|
|
1173
1192
|
* Only called when the tool is used in a streaming context.
|
|
1174
1193
|
*/
|
|
1175
|
-
onInputStart?: (options: ToolExecutionOptions) => void | PromiseLike<void>;
|
|
1194
|
+
onInputStart?: (options: ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1176
1195
|
/**
|
|
1177
1196
|
* Optional function that is called when an argument streaming delta is available.
|
|
1178
1197
|
* Only called when the tool is used in a streaming context.
|
|
1179
1198
|
*/
|
|
1180
1199
|
onInputDelta?: (options: {
|
|
1181
1200
|
inputTextDelta: string;
|
|
1182
|
-
} & ToolExecutionOptions) => void | PromiseLike<void>;
|
|
1201
|
+
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1183
1202
|
/**
|
|
1184
1203
|
* Optional function that is called when a tool call can be started,
|
|
1185
1204
|
* even if the execute function is not provided.
|
|
1186
1205
|
*/
|
|
1187
1206
|
onInputAvailable?: (options: {
|
|
1188
1207
|
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
1189
|
-
} & ToolExecutionOptions) => void | PromiseLike<void>;
|
|
1190
|
-
} & ToolOutputProperties<INPUT, OUTPUT
|
|
1208
|
+
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1209
|
+
} & ToolOutputProperties<INPUT, OUTPUT, NoInfer<CONTEXT>> & {
|
|
1191
1210
|
/**
|
|
1192
1211
|
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1193
1212
|
*
|
|
@@ -1248,21 +1267,13 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1248
1267
|
*/
|
|
1249
1268
|
supportsDeferredResults?: boolean;
|
|
1250
1269
|
});
|
|
1251
|
-
/**
|
|
1252
|
-
* Infer the input type of a tool.
|
|
1253
|
-
*/
|
|
1254
|
-
type InferToolInput<TOOL extends Tool> = TOOL extends Tool<infer INPUT, any> ? INPUT : never;
|
|
1255
|
-
/**
|
|
1256
|
-
* Infer the output type of a tool.
|
|
1257
|
-
*/
|
|
1258
|
-
type InferToolOutput<TOOL extends Tool> = TOOL extends Tool<any, infer OUTPUT> ? OUTPUT : never;
|
|
1259
1270
|
/**
|
|
1260
1271
|
* Helper function for inferring the execute args of a tool.
|
|
1261
1272
|
*/
|
|
1262
|
-
declare function tool<INPUT, OUTPUT>(tool: Tool<INPUT, OUTPUT>): Tool<INPUT, OUTPUT>;
|
|
1263
|
-
declare function tool<INPUT>(tool: Tool<INPUT, never>): Tool<INPUT, never>;
|
|
1264
|
-
declare function tool<OUTPUT>(tool: Tool<never, OUTPUT>): Tool<never, OUTPUT>;
|
|
1265
|
-
declare function tool(tool: Tool<never, never>): Tool<never, never>;
|
|
1273
|
+
declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT>): Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1274
|
+
declare function tool<INPUT, CONTEXT extends Context>(tool: Tool<INPUT, never, CONTEXT>): Tool<INPUT, never, CONTEXT>;
|
|
1275
|
+
declare function tool<OUTPUT, CONTEXT extends Context>(tool: Tool<never, OUTPUT, CONTEXT>): Tool<never, OUTPUT, CONTEXT>;
|
|
1276
|
+
declare function tool<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>): Tool<never, never, CONTEXT>;
|
|
1266
1277
|
/**
|
|
1267
1278
|
* Defines a dynamic tool.
|
|
1268
1279
|
*/
|
|
@@ -1271,7 +1282,7 @@ declare function dynamicTool(tool: {
|
|
|
1271
1282
|
title?: string;
|
|
1272
1283
|
providerOptions?: ProviderOptions;
|
|
1273
1284
|
inputSchema: FlexibleSchema<unknown>;
|
|
1274
|
-
execute: ToolExecuteFunction<unknown, unknown>;
|
|
1285
|
+
execute: ToolExecuteFunction<unknown, unknown, Context>;
|
|
1275
1286
|
/**
|
|
1276
1287
|
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1277
1288
|
*
|
|
@@ -1294,32 +1305,32 @@ declare function dynamicTool(tool: {
|
|
|
1294
1305
|
/**
|
|
1295
1306
|
* Whether the tool needs approval before it can be executed.
|
|
1296
1307
|
*/
|
|
1297
|
-
needsApproval?: boolean | ToolNeedsApprovalFunction<unknown>;
|
|
1298
|
-
}): Tool<unknown, unknown> & {
|
|
1308
|
+
needsApproval?: boolean | ToolNeedsApprovalFunction<unknown, Context>;
|
|
1309
|
+
}): Tool<unknown, unknown, Context> & {
|
|
1299
1310
|
type: 'dynamic';
|
|
1300
1311
|
};
|
|
1301
1312
|
|
|
1302
|
-
type ProviderToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options: ARGS & {
|
|
1303
|
-
execute?: ToolExecuteFunction<INPUT, OUTPUT>;
|
|
1304
|
-
needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
|
|
1305
|
-
toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
|
|
1306
|
-
onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
|
|
1307
|
-
onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
|
|
1308
|
-
onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
|
|
1309
|
-
}) => Tool<INPUT, OUTPUT>;
|
|
1310
|
-
declare function createProviderToolFactory<INPUT, ARGS extends object>({ id, inputSchema, }: {
|
|
1313
|
+
type ProviderToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}> = <OUTPUT>(options: ARGS & {
|
|
1314
|
+
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1315
|
+
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
1316
|
+
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
1317
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1318
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1319
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1320
|
+
}) => Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1321
|
+
declare function createProviderToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, }: {
|
|
1311
1322
|
id: `${string}.${string}`;
|
|
1312
1323
|
inputSchema: FlexibleSchema<INPUT>;
|
|
1313
|
-
}): ProviderToolFactory<INPUT, ARGS>;
|
|
1314
|
-
type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & {
|
|
1315
|
-
execute?: ToolExecuteFunction<INPUT, OUTPUT>;
|
|
1316
|
-
needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
|
|
1317
|
-
toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
|
|
1318
|
-
onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
|
|
1319
|
-
onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
|
|
1320
|
-
onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
|
|
1321
|
-
}) => Tool<INPUT, OUTPUT>;
|
|
1322
|
-
declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
|
|
1324
|
+
}): ProviderToolFactory<INPUT, ARGS, CONTEXT>;
|
|
1325
|
+
type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
|
|
1326
|
+
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1327
|
+
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
1328
|
+
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
1329
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1330
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1331
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1332
|
+
}) => Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1333
|
+
declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
|
|
1323
1334
|
id: `${string}.${string}`;
|
|
1324
1335
|
inputSchema: FlexibleSchema<INPUT>;
|
|
1325
1336
|
outputSchema: FlexibleSchema<OUTPUT>;
|
|
@@ -1334,7 +1345,7 @@ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS e
|
|
|
1334
1345
|
* @default false
|
|
1335
1346
|
*/
|
|
1336
1347
|
supportsDeferredResults?: boolean;
|
|
1337
|
-
}): ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS>;
|
|
1348
|
+
}): ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS, CONTEXT>;
|
|
1338
1349
|
|
|
1339
1350
|
/**
|
|
1340
1351
|
* Removes entries from a record where the value is null or undefined.
|
|
@@ -1428,10 +1439,29 @@ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, strin
|
|
|
1428
1439
|
|
|
1429
1440
|
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
|
1430
1441
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1442
|
+
/**
|
|
1443
|
+
* Executes a tool function, supporting both synchronous and streaming/asynchronous results.
|
|
1444
|
+
*
|
|
1445
|
+
* This generator yields intermediate ("preliminary") outputs as they're produced, allowing callers
|
|
1446
|
+
* to stream partial tool results before completion. When execution is finished, it yields a final output,
|
|
1447
|
+
* ensuring all consumers receive a conclusive result.
|
|
1448
|
+
*
|
|
1449
|
+
* - If the tool's `execute` function returns an `AsyncIterable`, all intermediate values are yielded
|
|
1450
|
+
* as `{ type: "preliminary", output }` except the last, which is yielded as `{ type: "final", output }`.
|
|
1451
|
+
* - If the tool returns a direct value or Promise, a single `{ type: "final", output }` is yielded.
|
|
1452
|
+
*
|
|
1453
|
+
* @template INPUT Input type for the tool execution.
|
|
1454
|
+
* @template OUTPUT Output type for the tool execution.
|
|
1455
|
+
* @template CONTEXT Context object extension for execution (extends Context).
|
|
1456
|
+
* @param params.execute The tool execute function.
|
|
1457
|
+
* @param params.input Input value to pass to the execute function.
|
|
1458
|
+
* @param params.options Additional options for tool execution.
|
|
1459
|
+
* @yields An object containing either a preliminary or final output from the tool.
|
|
1460
|
+
*/
|
|
1461
|
+
declare function executeTool<INPUT, OUTPUT, CONTEXT extends Context>({ execute, input, options, }: {
|
|
1462
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1433
1463
|
input: INPUT;
|
|
1434
|
-
options: ToolExecutionOptions
|
|
1464
|
+
options: ToolExecutionOptions<NoInfer<CONTEXT>>;
|
|
1435
1465
|
}): AsyncGenerator<{
|
|
1436
1466
|
type: 'preliminary';
|
|
1437
1467
|
output: OUTPUT;
|
|
@@ -1440,6 +1470,21 @@ declare function executeTool<INPUT, OUTPUT>({ execute, input, options, }: {
|
|
|
1440
1470
|
output: OUTPUT;
|
|
1441
1471
|
}>;
|
|
1442
1472
|
|
|
1473
|
+
/**
|
|
1474
|
+
* Infer the context type of a tool.
|
|
1475
|
+
*/
|
|
1476
|
+
type InferToolContext<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, any, infer CONTEXT> ? CONTEXT : never;
|
|
1477
|
+
|
|
1478
|
+
/**
|
|
1479
|
+
* Infer the input type of a tool.
|
|
1480
|
+
*/
|
|
1481
|
+
type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer INPUT, any, any> ? INPUT : never;
|
|
1482
|
+
|
|
1483
|
+
/**
|
|
1484
|
+
* Infer the output type of a tool.
|
|
1485
|
+
*/
|
|
1486
|
+
type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
|
|
1487
|
+
|
|
1443
1488
|
/**
|
|
1444
1489
|
* Typed tool call that is returned by generateText and streamText.
|
|
1445
1490
|
* It contains the tool call ID, the tool name, and the tool arguments.
|
|
@@ -1499,9 +1544,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1499
1544
|
dynamic?: boolean;
|
|
1500
1545
|
}
|
|
1501
1546
|
|
|
1502
|
-
|
|
1503
|
-
* @deprecated Use ToolExecutionOptions instead.
|
|
1504
|
-
*/
|
|
1505
|
-
type ToolCallOptions = ToolExecutionOptions;
|
|
1506
|
-
|
|
1507
|
-
export { type AssistantContent, type AssistantModelMessage, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, 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 ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, 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, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1547
|
+
export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, 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 UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1052,9 +1052,14 @@ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
|
|
1052
1052
|
type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
|
1053
1053
|
|
|
1054
1054
|
/**
|
|
1055
|
-
*
|
|
1055
|
+
* A context object that is passed into tool execution.
|
|
1056
1056
|
*/
|
|
1057
|
-
|
|
1057
|
+
type Context = Record<string, unknown>;
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Additional options that are sent into each tool execution.
|
|
1061
|
+
*/
|
|
1062
|
+
interface ToolExecutionOptions<CONTEXT extends Context> {
|
|
1058
1063
|
/**
|
|
1059
1064
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1060
1065
|
*/
|
|
@@ -1080,12 +1085,12 @@ interface ToolExecutionOptions {
|
|
|
1080
1085
|
*
|
|
1081
1086
|
* Experimental (can break in patch releases).
|
|
1082
1087
|
*/
|
|
1083
|
-
experimental_context
|
|
1088
|
+
experimental_context: CONTEXT;
|
|
1084
1089
|
}
|
|
1085
1090
|
/**
|
|
1086
1091
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
1087
1092
|
*/
|
|
1088
|
-
type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: {
|
|
1093
|
+
type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (input: INPUT, options: {
|
|
1089
1094
|
/**
|
|
1090
1095
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
1091
1096
|
*/
|
|
@@ -1100,11 +1105,17 @@ type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: {
|
|
|
1100
1105
|
*
|
|
1101
1106
|
* Experimental (can break in patch releases).
|
|
1102
1107
|
*/
|
|
1103
|
-
experimental_context
|
|
1108
|
+
experimental_context: CONTEXT;
|
|
1104
1109
|
}) => boolean | PromiseLike<boolean>;
|
|
1105
|
-
|
|
1110
|
+
/**
|
|
1111
|
+
* Function that executes the tool and returns either a single result or a stream of results.
|
|
1112
|
+
*/
|
|
1113
|
+
type ToolExecuteFunction<INPUT, OUTPUT, CONTEXT extends Context> = (input: INPUT, options: ToolExecutionOptions<CONTEXT>) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
1106
1114
|
type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
|
1107
|
-
|
|
1115
|
+
/**
|
|
1116
|
+
* Helper type to determine the output properties of a tool.
|
|
1117
|
+
*/
|
|
1118
|
+
type ToolOutputProperties<INPUT, OUTPUT, CONTEXT extends Context> = NeverOptional<OUTPUT, {
|
|
1108
1119
|
/**
|
|
1109
1120
|
* An async function that is called with the arguments from the tool call and produces a result.
|
|
1110
1121
|
* If not provided, the tool will not be executed automatically.
|
|
@@ -1112,7 +1123,7 @@ type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
|
|
|
1112
1123
|
* @args is the input of the tool call.
|
|
1113
1124
|
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
1114
1125
|
*/
|
|
1115
|
-
execute: ToolExecuteFunction<INPUT, OUTPUT>;
|
|
1126
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1116
1127
|
outputSchema?: FlexibleSchema<OUTPUT>;
|
|
1117
1128
|
} | {
|
|
1118
1129
|
outputSchema: FlexibleSchema<OUTPUT>;
|
|
@@ -1124,7 +1135,7 @@ type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
|
|
|
1124
1135
|
*
|
|
1125
1136
|
* The tool can also contain an optional execute function for the actual execution function of the tool.
|
|
1126
1137
|
*/
|
|
1127
|
-
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any> = {
|
|
1138
|
+
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any, CONTEXT extends Context = Context> = {
|
|
1128
1139
|
/**
|
|
1129
1140
|
* An optional description of what the tool does.
|
|
1130
1141
|
* Will be used by the language model to decide whether to use the tool.
|
|
@@ -1156,10 +1167,18 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1156
1167
|
inputExamples?: Array<{
|
|
1157
1168
|
input: NoInfer<INPUT>;
|
|
1158
1169
|
}>;
|
|
1170
|
+
/**
|
|
1171
|
+
* An optional schema describing the context that the tool expects.
|
|
1172
|
+
*
|
|
1173
|
+
* The context is passed to execute function as part of the execution options.
|
|
1174
|
+
*/
|
|
1175
|
+
contextSchema?: FlexibleSchema<CONTEXT>;
|
|
1159
1176
|
/**
|
|
1160
1177
|
* Whether the tool needs approval before it can be executed.
|
|
1161
1178
|
*/
|
|
1162
|
-
needsApproval?: boolean | ToolNeedsApprovalFunction<[
|
|
1179
|
+
needsApproval?: boolean | ToolNeedsApprovalFunction<[
|
|
1180
|
+
INPUT
|
|
1181
|
+
] extends [never] ? unknown : INPUT, NoInfer<CONTEXT>>;
|
|
1163
1182
|
/**
|
|
1164
1183
|
* Strict mode setting for the tool.
|
|
1165
1184
|
*
|
|
@@ -1172,22 +1191,22 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1172
1191
|
* Optional function that is called when the argument streaming starts.
|
|
1173
1192
|
* Only called when the tool is used in a streaming context.
|
|
1174
1193
|
*/
|
|
1175
|
-
onInputStart?: (options: ToolExecutionOptions) => void | PromiseLike<void>;
|
|
1194
|
+
onInputStart?: (options: ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1176
1195
|
/**
|
|
1177
1196
|
* Optional function that is called when an argument streaming delta is available.
|
|
1178
1197
|
* Only called when the tool is used in a streaming context.
|
|
1179
1198
|
*/
|
|
1180
1199
|
onInputDelta?: (options: {
|
|
1181
1200
|
inputTextDelta: string;
|
|
1182
|
-
} & ToolExecutionOptions) => void | PromiseLike<void>;
|
|
1201
|
+
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1183
1202
|
/**
|
|
1184
1203
|
* Optional function that is called when a tool call can be started,
|
|
1185
1204
|
* even if the execute function is not provided.
|
|
1186
1205
|
*/
|
|
1187
1206
|
onInputAvailable?: (options: {
|
|
1188
1207
|
input: [INPUT] extends [never] ? unknown : INPUT;
|
|
1189
|
-
} & ToolExecutionOptions) => void | PromiseLike<void>;
|
|
1190
|
-
} & ToolOutputProperties<INPUT, OUTPUT
|
|
1208
|
+
} & ToolExecutionOptions<NoInfer<CONTEXT>>) => void | PromiseLike<void>;
|
|
1209
|
+
} & ToolOutputProperties<INPUT, OUTPUT, NoInfer<CONTEXT>> & {
|
|
1191
1210
|
/**
|
|
1192
1211
|
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1193
1212
|
*
|
|
@@ -1248,21 +1267,13 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
|
|
|
1248
1267
|
*/
|
|
1249
1268
|
supportsDeferredResults?: boolean;
|
|
1250
1269
|
});
|
|
1251
|
-
/**
|
|
1252
|
-
* Infer the input type of a tool.
|
|
1253
|
-
*/
|
|
1254
|
-
type InferToolInput<TOOL extends Tool> = TOOL extends Tool<infer INPUT, any> ? INPUT : never;
|
|
1255
|
-
/**
|
|
1256
|
-
* Infer the output type of a tool.
|
|
1257
|
-
*/
|
|
1258
|
-
type InferToolOutput<TOOL extends Tool> = TOOL extends Tool<any, infer OUTPUT> ? OUTPUT : never;
|
|
1259
1270
|
/**
|
|
1260
1271
|
* Helper function for inferring the execute args of a tool.
|
|
1261
1272
|
*/
|
|
1262
|
-
declare function tool<INPUT, OUTPUT>(tool: Tool<INPUT, OUTPUT>): Tool<INPUT, OUTPUT>;
|
|
1263
|
-
declare function tool<INPUT>(tool: Tool<INPUT, never>): Tool<INPUT, never>;
|
|
1264
|
-
declare function tool<OUTPUT>(tool: Tool<never, OUTPUT>): Tool<never, OUTPUT>;
|
|
1265
|
-
declare function tool(tool: Tool<never, never>): Tool<never, never>;
|
|
1273
|
+
declare function tool<INPUT, OUTPUT, CONTEXT extends Context>(tool: Tool<INPUT, OUTPUT, CONTEXT>): Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1274
|
+
declare function tool<INPUT, CONTEXT extends Context>(tool: Tool<INPUT, never, CONTEXT>): Tool<INPUT, never, CONTEXT>;
|
|
1275
|
+
declare function tool<OUTPUT, CONTEXT extends Context>(tool: Tool<never, OUTPUT, CONTEXT>): Tool<never, OUTPUT, CONTEXT>;
|
|
1276
|
+
declare function tool<CONTEXT extends Context>(tool: Tool<never, never, CONTEXT>): Tool<never, never, CONTEXT>;
|
|
1266
1277
|
/**
|
|
1267
1278
|
* Defines a dynamic tool.
|
|
1268
1279
|
*/
|
|
@@ -1271,7 +1282,7 @@ declare function dynamicTool(tool: {
|
|
|
1271
1282
|
title?: string;
|
|
1272
1283
|
providerOptions?: ProviderOptions;
|
|
1273
1284
|
inputSchema: FlexibleSchema<unknown>;
|
|
1274
|
-
execute: ToolExecuteFunction<unknown, unknown>;
|
|
1285
|
+
execute: ToolExecuteFunction<unknown, unknown, Context>;
|
|
1275
1286
|
/**
|
|
1276
1287
|
* Optional conversion function that maps the tool result to an output that can be used by the language model.
|
|
1277
1288
|
*
|
|
@@ -1294,32 +1305,32 @@ declare function dynamicTool(tool: {
|
|
|
1294
1305
|
/**
|
|
1295
1306
|
* Whether the tool needs approval before it can be executed.
|
|
1296
1307
|
*/
|
|
1297
|
-
needsApproval?: boolean | ToolNeedsApprovalFunction<unknown>;
|
|
1298
|
-
}): Tool<unknown, unknown> & {
|
|
1308
|
+
needsApproval?: boolean | ToolNeedsApprovalFunction<unknown, Context>;
|
|
1309
|
+
}): Tool<unknown, unknown, Context> & {
|
|
1299
1310
|
type: 'dynamic';
|
|
1300
1311
|
};
|
|
1301
1312
|
|
|
1302
|
-
type ProviderToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options: ARGS & {
|
|
1303
|
-
execute?: ToolExecuteFunction<INPUT, OUTPUT>;
|
|
1304
|
-
needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
|
|
1305
|
-
toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
|
|
1306
|
-
onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
|
|
1307
|
-
onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
|
|
1308
|
-
onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
|
|
1309
|
-
}) => Tool<INPUT, OUTPUT>;
|
|
1310
|
-
declare function createProviderToolFactory<INPUT, ARGS extends object>({ id, inputSchema, }: {
|
|
1313
|
+
type ProviderToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}> = <OUTPUT>(options: ARGS & {
|
|
1314
|
+
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1315
|
+
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
1316
|
+
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
1317
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1318
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1319
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1320
|
+
}) => Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1321
|
+
declare function createProviderToolFactory<INPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, }: {
|
|
1311
1322
|
id: `${string}.${string}`;
|
|
1312
1323
|
inputSchema: FlexibleSchema<INPUT>;
|
|
1313
|
-
}): ProviderToolFactory<INPUT, ARGS>;
|
|
1314
|
-
type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & {
|
|
1315
|
-
execute?: ToolExecuteFunction<INPUT, OUTPUT>;
|
|
1316
|
-
needsApproval?: Tool<INPUT, OUTPUT>['needsApproval'];
|
|
1317
|
-
toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput'];
|
|
1318
|
-
onInputStart?: Tool<INPUT, OUTPUT>['onInputStart'];
|
|
1319
|
-
onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
|
|
1320
|
-
onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
|
|
1321
|
-
}) => Tool<INPUT, OUTPUT>;
|
|
1322
|
-
declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
|
|
1324
|
+
}): ProviderToolFactory<INPUT, ARGS, CONTEXT>;
|
|
1325
|
+
type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}> = (options: ARGS & {
|
|
1326
|
+
execute?: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1327
|
+
needsApproval?: Tool<INPUT, OUTPUT, CONTEXT>['needsApproval'];
|
|
1328
|
+
toModelOutput?: Tool<INPUT, OUTPUT, CONTEXT>['toModelOutput'];
|
|
1329
|
+
onInputStart?: Tool<INPUT, OUTPUT, CONTEXT>['onInputStart'];
|
|
1330
|
+
onInputDelta?: Tool<INPUT, OUTPUT, CONTEXT>['onInputDelta'];
|
|
1331
|
+
onInputAvailable?: Tool<INPUT, OUTPUT, CONTEXT>['onInputAvailable'];
|
|
1332
|
+
}) => Tool<INPUT, OUTPUT, CONTEXT>;
|
|
1333
|
+
declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object, CONTEXT extends Context = {}>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
|
|
1323
1334
|
id: `${string}.${string}`;
|
|
1324
1335
|
inputSchema: FlexibleSchema<INPUT>;
|
|
1325
1336
|
outputSchema: FlexibleSchema<OUTPUT>;
|
|
@@ -1334,7 +1345,7 @@ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS e
|
|
|
1334
1345
|
* @default false
|
|
1335
1346
|
*/
|
|
1336
1347
|
supportsDeferredResults?: boolean;
|
|
1337
|
-
}): ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS>;
|
|
1348
|
+
}): ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS, CONTEXT>;
|
|
1338
1349
|
|
|
1339
1350
|
/**
|
|
1340
1351
|
* Removes entries from a record where the value is null or undefined.
|
|
@@ -1428,10 +1439,29 @@ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, strin
|
|
|
1428
1439
|
|
|
1429
1440
|
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
|
1430
1441
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1442
|
+
/**
|
|
1443
|
+
* Executes a tool function, supporting both synchronous and streaming/asynchronous results.
|
|
1444
|
+
*
|
|
1445
|
+
* This generator yields intermediate ("preliminary") outputs as they're produced, allowing callers
|
|
1446
|
+
* to stream partial tool results before completion. When execution is finished, it yields a final output,
|
|
1447
|
+
* ensuring all consumers receive a conclusive result.
|
|
1448
|
+
*
|
|
1449
|
+
* - If the tool's `execute` function returns an `AsyncIterable`, all intermediate values are yielded
|
|
1450
|
+
* as `{ type: "preliminary", output }` except the last, which is yielded as `{ type: "final", output }`.
|
|
1451
|
+
* - If the tool returns a direct value or Promise, a single `{ type: "final", output }` is yielded.
|
|
1452
|
+
*
|
|
1453
|
+
* @template INPUT Input type for the tool execution.
|
|
1454
|
+
* @template OUTPUT Output type for the tool execution.
|
|
1455
|
+
* @template CONTEXT Context object extension for execution (extends Context).
|
|
1456
|
+
* @param params.execute The tool execute function.
|
|
1457
|
+
* @param params.input Input value to pass to the execute function.
|
|
1458
|
+
* @param params.options Additional options for tool execution.
|
|
1459
|
+
* @yields An object containing either a preliminary or final output from the tool.
|
|
1460
|
+
*/
|
|
1461
|
+
declare function executeTool<INPUT, OUTPUT, CONTEXT extends Context>({ execute, input, options, }: {
|
|
1462
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
1433
1463
|
input: INPUT;
|
|
1434
|
-
options: ToolExecutionOptions
|
|
1464
|
+
options: ToolExecutionOptions<NoInfer<CONTEXT>>;
|
|
1435
1465
|
}): AsyncGenerator<{
|
|
1436
1466
|
type: 'preliminary';
|
|
1437
1467
|
output: OUTPUT;
|
|
@@ -1440,6 +1470,21 @@ declare function executeTool<INPUT, OUTPUT>({ execute, input, options, }: {
|
|
|
1440
1470
|
output: OUTPUT;
|
|
1441
1471
|
}>;
|
|
1442
1472
|
|
|
1473
|
+
/**
|
|
1474
|
+
* Infer the context type of a tool.
|
|
1475
|
+
*/
|
|
1476
|
+
type InferToolContext<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, any, infer CONTEXT> ? CONTEXT : never;
|
|
1477
|
+
|
|
1478
|
+
/**
|
|
1479
|
+
* Infer the input type of a tool.
|
|
1480
|
+
*/
|
|
1481
|
+
type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer INPUT, any, any> ? INPUT : never;
|
|
1482
|
+
|
|
1483
|
+
/**
|
|
1484
|
+
* Infer the output type of a tool.
|
|
1485
|
+
*/
|
|
1486
|
+
type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
|
|
1487
|
+
|
|
1443
1488
|
/**
|
|
1444
1489
|
* Typed tool call that is returned by generateText and streamText.
|
|
1445
1490
|
* It contains the tool call ID, the tool name, and the tool arguments.
|
|
@@ -1499,9 +1544,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1499
1544
|
dynamic?: boolean;
|
|
1500
1545
|
}
|
|
1501
1546
|
|
|
1502
|
-
|
|
1503
|
-
* @deprecated Use ToolExecutionOptions instead.
|
|
1504
|
-
*/
|
|
1505
|
-
type ToolCallOptions = ToolExecutionOptions;
|
|
1506
|
-
|
|
1507
|
-
export { type AssistantContent, type AssistantModelMessage, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, 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 ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, 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, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
1547
|
+
export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, 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 UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -676,7 +676,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
676
676
|
}
|
|
677
677
|
|
|
678
678
|
// src/version.ts
|
|
679
|
-
var VERSION = true ? "5.0.0-beta.
|
|
679
|
+
var VERSION = true ? "5.0.0-beta.8" : "0.0.0-test";
|
|
680
680
|
|
|
681
681
|
// src/get-from-api.ts
|
|
682
682
|
var getOriginalFetch = () => globalThis.fetch;
|