@ai-sdk/provider-utils 5.0.0-beta.25 → 5.0.0-beta.27
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 +17 -0
- package/dist/index.d.ts +103 -18
- package/dist/index.js +55 -27
- package/dist/index.js.map +1 -1
- package/dist/test/index.d.ts +2 -1
- package/dist/test/index.js +16 -2
- package/dist/test/index.js.map +1 -1
- package/package.json +4 -3
- package/src/index.ts +9 -5
- package/src/maybe-promise-like.ts +3 -0
- package/src/parse-json.ts +1 -1
- package/src/post-to-api.ts +2 -2
- 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/convert-response-stream-to-array.ts +1 -1
- 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/src/types/tool.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { JSONValue } from '@ai-sdk/provider';
|
|
2
2
|
import { FlexibleSchema } from '../schema';
|
|
3
3
|
import { ToolResultOutput } from './content-part';
|
|
4
|
+
import { Context } from './context';
|
|
4
5
|
import { ModelMessage } from './model-message';
|
|
5
6
|
import { ProviderOptions } from './provider-options';
|
|
6
|
-
import {
|
|
7
|
+
import { SensitiveContext } from './sensitive-context';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Additional options that are sent into each tool execution.
|
|
@@ -28,7 +29,8 @@ export interface ToolExecutionOptions<
|
|
|
28
29
|
abortSignal?: AbortSignal;
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
+
* Tool context as defined by the tool's context schema.
|
|
33
|
+
* The tool context is specific to the tool and is passed to the tool execution.
|
|
32
34
|
*
|
|
33
35
|
* Treat the context object as immutable inside tools.
|
|
34
36
|
* Mutating the context object can lead to race conditions and unexpected results
|
|
@@ -42,6 +44,8 @@ export interface ToolExecutionOptions<
|
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
45
49
|
*/
|
|
46
50
|
export type ToolNeedsApprovalFunction<
|
|
47
51
|
INPUT,
|
|
@@ -61,7 +65,8 @@ export type ToolNeedsApprovalFunction<
|
|
|
61
65
|
messages: ModelMessage[];
|
|
62
66
|
|
|
63
67
|
/**
|
|
64
|
-
*
|
|
68
|
+
* Tool context as defined by the tool's context schema.
|
|
69
|
+
* The tool context is specific to the tool and is passed to the tool execution.
|
|
65
70
|
*
|
|
66
71
|
* Treat the context object as immutable inside tools.
|
|
67
72
|
* Mutating the context object can lead to race conditions and unexpected results
|
|
@@ -113,9 +118,15 @@ type ToolOutputProperties<
|
|
|
113
118
|
*/
|
|
114
119
|
execute: ToolExecuteFunction<INPUT, OUTPUT, CONTEXT>;
|
|
115
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The schema of the output that the tool produces.
|
|
123
|
+
*/
|
|
116
124
|
outputSchema?: FlexibleSchema<OUTPUT>;
|
|
117
125
|
}
|
|
118
126
|
| {
|
|
127
|
+
/**
|
|
128
|
+
* The schema of the output that the tool produces.
|
|
129
|
+
*/
|
|
119
130
|
outputSchema: FlexibleSchema<OUTPUT>;
|
|
120
131
|
|
|
121
132
|
execute?: never;
|
|
@@ -174,8 +185,16 @@ export type Tool<
|
|
|
174
185
|
*/
|
|
175
186
|
contextSchema?: FlexibleSchema<CONTEXT>;
|
|
176
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Marks top-level context properties that contain sensitive data and should be excluded from telemetry.
|
|
190
|
+
* Properties marked as `true` are omitted from telemetry integrations.
|
|
191
|
+
*/
|
|
192
|
+
sensitiveContext?: SensitiveContext<CONTEXT>;
|
|
193
|
+
|
|
177
194
|
/**
|
|
178
195
|
* Whether the tool needs approval before it can be executed.
|
|
196
|
+
*
|
|
197
|
+
* @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
|
|
179
198
|
*/
|
|
180
199
|
needsApproval?:
|
|
181
200
|
| boolean
|
|
@@ -273,6 +292,11 @@ export type Tool<
|
|
|
273
292
|
*/
|
|
274
293
|
id: `${string}.${string}`;
|
|
275
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Flag that indicates whether the tool is executed by the provider.
|
|
297
|
+
*/
|
|
298
|
+
isProviderExecuted: boolean;
|
|
299
|
+
|
|
276
300
|
/**
|
|
277
301
|
* The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
|
278
302
|
*/
|
|
@@ -319,10 +343,41 @@ export function tool(tool: any): any {
|
|
|
319
343
|
* Defines a dynamic tool.
|
|
320
344
|
*/
|
|
321
345
|
export function dynamicTool(tool: {
|
|
346
|
+
/**
|
|
347
|
+
* An optional description of what the tool does.
|
|
348
|
+
* Will be used by the language model to decide whether to use the tool.
|
|
349
|
+
* Not used for provider-defined tools.
|
|
350
|
+
*/
|
|
322
351
|
description?: string;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* An optional title of the tool.
|
|
355
|
+
*/
|
|
323
356
|
title?: string;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Additional provider-specific metadata. They are passed through
|
|
360
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
361
|
+
* functionality that can be fully encapsulated in the provider.
|
|
362
|
+
*/
|
|
324
363
|
providerOptions?: ProviderOptions;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The schema of the input that the tool expects.
|
|
367
|
+
* The language model will use this to generate the input.
|
|
368
|
+
* It is also used to validate the output of the language model.
|
|
369
|
+
*
|
|
370
|
+
* You can use descriptions on the schema properties to make the input understandable for the language model.
|
|
371
|
+
*/
|
|
325
372
|
inputSchema: FlexibleSchema<unknown>;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* An async function that is called with the arguments from the tool call and produces a result.
|
|
376
|
+
* If not provided, the tool will not be executed automatically.
|
|
377
|
+
*
|
|
378
|
+
* @args is the input of the tool call.
|
|
379
|
+
* @options.abortSignal is a signal that can be used to abort the tool call.
|
|
380
|
+
*/
|
|
326
381
|
execute: ToolExecuteFunction<unknown, unknown, Context>;
|
|
327
382
|
|
|
328
383
|
/**
|