@ai-sdk/provider-utils 4.0.9 → 4.0.11
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 +170 -166
- package/dist/index.d.ts +170 -166
- package/dist/index.js +37 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/extract-response-headers.ts +5 -5
- package/src/generate-id.ts +11 -11
- package/src/handle-fetch-error.ts +33 -0
- package/src/types/assistant-model-message.ts +6 -6
- package/src/types/content-part.ts +70 -70
- package/src/types/data-content.ts +1 -1
- package/src/types/model-message.ts +2 -2
- package/src/types/provider-options.ts +4 -4
- package/src/types/system-model-message.ts +9 -9
- package/src/types/tool-call.ts +7 -7
- package/src/types/tool-model-message.ts +5 -5
- package/src/types/tool-result.ts +8 -8
- package/src/types/tool.ts +28 -28
- package/src/types/user-model-message.ts +7 -7
- package/src/validate-types.ts +11 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/provider-utils",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.11",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@standard-schema/spec": "^1.1.0",
|
|
37
37
|
"eventsource-parser": "^3.0.6",
|
|
38
|
-
"@ai-sdk/provider": "3.0.
|
|
38
|
+
"@ai-sdk/provider": "3.0.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "20.17.24",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
Extracts the headers from a response object and returns them as a key-value object.
|
|
3
|
-
|
|
4
|
-
@param response - The response object to extract headers from.
|
|
5
|
-
@returns The headers as a key-value object.
|
|
6
|
-
*/
|
|
2
|
+
* Extracts the headers from a response object and returns them as a key-value object.
|
|
3
|
+
*
|
|
4
|
+
* @param response - The response object to extract headers from.
|
|
5
|
+
* @returns The headers as a key-value object.
|
|
6
|
+
*/
|
|
7
7
|
export function extractResponseHeaders(response: Response) {
|
|
8
8
|
return Object.fromEntries<string>([...response.headers]);
|
|
9
9
|
}
|
package/src/generate-id.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { InvalidArgumentError } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
Creates an ID generator.
|
|
5
|
-
The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
6
|
-
Not cryptographically secure.
|
|
7
|
-
|
|
8
|
-
@param alphabet - The alphabet to use for the ID. Default: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
|
|
9
|
-
@param prefix - The prefix of the ID to generate. Optional.
|
|
10
|
-
@param separator - The separator between the prefix and the random part of the ID. Default: '-'.
|
|
11
|
-
@param size - The size of the random part of the ID to generate. Default: 16.
|
|
4
|
+
* Creates an ID generator.
|
|
5
|
+
* The total length of the ID is the sum of the prefix, separator, and random part length.
|
|
6
|
+
* Not cryptographically secure.
|
|
7
|
+
*
|
|
8
|
+
* @param alphabet - The alphabet to use for the ID. Default: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
|
|
9
|
+
* @param prefix - The prefix of the ID to generate. Optional.
|
|
10
|
+
* @param separator - The separator between the prefix and the random part of the ID. Default: '-'.
|
|
11
|
+
* @param size - The size of the random part of the ID to generate. Default: 16.
|
|
12
12
|
*/
|
|
13
13
|
export const createIdGenerator = ({
|
|
14
14
|
prefix,
|
|
@@ -46,12 +46,12 @@ export const createIdGenerator = ({
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
A function that generates an ID.
|
|
49
|
+
* A function that generates an ID.
|
|
50
50
|
*/
|
|
51
51
|
export type IdGenerator = () => string;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
Generates a 16-character random string to use for IDs.
|
|
55
|
-
Not cryptographically secure.
|
|
54
|
+
* Generates a 16-character random string to use for IDs.
|
|
55
|
+
* Not cryptographically secure.
|
|
56
56
|
*/
|
|
57
57
|
export const generateId = createIdGenerator();
|
|
@@ -3,6 +3,29 @@ import { isAbortError } from './is-abort-error';
|
|
|
3
3
|
|
|
4
4
|
const FETCH_FAILED_ERROR_MESSAGES = ['fetch failed', 'failed to fetch'];
|
|
5
5
|
|
|
6
|
+
const BUN_ERROR_CODES = [
|
|
7
|
+
'ConnectionRefused',
|
|
8
|
+
'ConnectionClosed',
|
|
9
|
+
'FailedToOpenSocket',
|
|
10
|
+
'ECONNRESET',
|
|
11
|
+
'ECONNREFUSED',
|
|
12
|
+
'ETIMEDOUT',
|
|
13
|
+
'EPIPE',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
function isBunNetworkError(error: unknown): error is Error & { code?: string } {
|
|
17
|
+
if (!(error instanceof Error)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const code = (error as any).code;
|
|
22
|
+
if (typeof code === 'string' && BUN_ERROR_CODES.includes(code)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
6
29
|
export function handleFetchError({
|
|
7
30
|
error,
|
|
8
31
|
url,
|
|
@@ -35,5 +58,15 @@ export function handleFetchError({
|
|
|
35
58
|
}
|
|
36
59
|
}
|
|
37
60
|
|
|
61
|
+
if (isBunNetworkError(error)) {
|
|
62
|
+
return new APICallError({
|
|
63
|
+
message: `Cannot connect to API: ${error.message}`,
|
|
64
|
+
cause: error,
|
|
65
|
+
url,
|
|
66
|
+
requestBodyValues,
|
|
67
|
+
isRetryable: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
38
71
|
return error;
|
|
39
72
|
}
|
|
@@ -9,23 +9,23 @@ import { ProviderOptions } from './provider-options';
|
|
|
9
9
|
import { ToolApprovalRequest } from './tool-approval-request';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
|
12
|
+
* An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
|
13
13
|
*/
|
|
14
14
|
export type AssistantModelMessage = {
|
|
15
15
|
role: 'assistant';
|
|
16
16
|
content: AssistantContent;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
* Additional provider-specific metadata. They are passed through
|
|
20
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
21
|
+
* functionality that can be fully encapsulated in the provider.
|
|
22
22
|
*/
|
|
23
23
|
providerOptions?: ProviderOptions;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
Content of an assistant message.
|
|
28
|
-
It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
|
27
|
+
* Content of an assistant message.
|
|
28
|
+
* It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
|
|
29
29
|
*/
|
|
30
30
|
export type AssistantContent =
|
|
31
31
|
| string
|
|
@@ -3,84 +3,84 @@ import { DataContent } from './data-content';
|
|
|
3
3
|
import { ProviderOptions } from './provider-options';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
Text content part of a prompt. It contains a string of text.
|
|
6
|
+
* Text content part of a prompt. It contains a string of text.
|
|
7
7
|
*/
|
|
8
8
|
export interface TextPart {
|
|
9
9
|
type: 'text';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
The text content.
|
|
12
|
+
* The text content.
|
|
13
13
|
*/
|
|
14
14
|
text: string;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
Additional provider-specific metadata. They are passed through
|
|
18
|
-
to the provider from the AI SDK and enable provider-specific
|
|
19
|
-
functionality that can be fully encapsulated in the provider.
|
|
20
|
-
|
|
17
|
+
* Additional provider-specific metadata. They are passed through
|
|
18
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
19
|
+
* functionality that can be fully encapsulated in the provider.
|
|
20
|
+
*/
|
|
21
21
|
providerOptions?: ProviderOptions;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
Image content part of a prompt. It contains an image.
|
|
25
|
+
* Image content part of a prompt. It contains an image.
|
|
26
26
|
*/
|
|
27
27
|
export interface ImagePart {
|
|
28
28
|
type: 'image';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
Image data. Can either be:
|
|
32
|
-
|
|
33
|
-
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
34
|
-
- URL: a URL that points to the image
|
|
31
|
+
* Image data. Can either be:
|
|
32
|
+
*
|
|
33
|
+
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
34
|
+
* - URL: a URL that points to the image
|
|
35
35
|
*/
|
|
36
36
|
image: DataContent | URL;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
Optional IANA media type of the image.
|
|
40
|
-
|
|
41
|
-
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
39
|
+
* Optional IANA media type of the image.
|
|
40
|
+
*
|
|
41
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
42
42
|
*/
|
|
43
43
|
mediaType?: string;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
Additional provider-specific metadata. They are passed through
|
|
47
|
-
to the provider from the AI SDK and enable provider-specific
|
|
48
|
-
functionality that can be fully encapsulated in the provider.
|
|
49
|
-
|
|
46
|
+
* Additional provider-specific metadata. They are passed through
|
|
47
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
48
|
+
* functionality that can be fully encapsulated in the provider.
|
|
49
|
+
*/
|
|
50
50
|
providerOptions?: ProviderOptions;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
File content part of a prompt. It contains a file.
|
|
54
|
+
* File content part of a prompt. It contains a file.
|
|
55
55
|
*/
|
|
56
56
|
export interface FilePart {
|
|
57
57
|
type: 'file';
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
File data. Can either be:
|
|
61
|
-
|
|
62
|
-
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
63
|
-
- URL: a URL that points to the image
|
|
60
|
+
* File data. Can either be:
|
|
61
|
+
*
|
|
62
|
+
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
63
|
+
* - URL: a URL that points to the image
|
|
64
64
|
*/
|
|
65
65
|
data: DataContent | URL;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
Optional filename of the file.
|
|
68
|
+
* Optional filename of the file.
|
|
69
69
|
*/
|
|
70
70
|
filename?: string;
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
IANA media type of the file.
|
|
74
|
-
|
|
75
|
-
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
73
|
+
* IANA media type of the file.
|
|
74
|
+
*
|
|
75
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
76
76
|
*/
|
|
77
77
|
mediaType: string;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
Additional provider-specific metadata. They are passed through
|
|
81
|
-
to the provider from the AI SDK and enable provider-specific
|
|
82
|
-
functionality that can be fully encapsulated in the provider.
|
|
83
|
-
|
|
80
|
+
* Additional provider-specific metadata. They are passed through
|
|
81
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
82
|
+
* functionality that can be fully encapsulated in the provider.
|
|
83
|
+
*/
|
|
84
84
|
providerOptions?: ProviderOptions;
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -91,78 +91,78 @@ export interface ReasoningPart {
|
|
|
91
91
|
type: 'reasoning';
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
The reasoning text.
|
|
94
|
+
* The reasoning text.
|
|
95
95
|
*/
|
|
96
96
|
text: string;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
Additional provider-specific metadata. They are passed through
|
|
100
|
-
to the provider from the AI SDK and enable provider-specific
|
|
101
|
-
functionality that can be fully encapsulated in the provider.
|
|
102
|
-
|
|
99
|
+
* Additional provider-specific metadata. They are passed through
|
|
100
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
101
|
+
* functionality that can be fully encapsulated in the provider.
|
|
102
|
+
*/
|
|
103
103
|
providerOptions?: ProviderOptions;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
107
|
+
* Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
|
108
108
|
*/
|
|
109
109
|
export interface ToolCallPart {
|
|
110
110
|
type: 'tool-call';
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
114
|
-
|
|
113
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
114
|
+
*/
|
|
115
115
|
toolCallId: string;
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
Name of the tool that is being called.
|
|
119
|
-
|
|
118
|
+
* Name of the tool that is being called.
|
|
119
|
+
*/
|
|
120
120
|
toolName: string;
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
123
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
124
124
|
*/
|
|
125
125
|
input: unknown;
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
Additional provider-specific metadata. They are passed through
|
|
129
|
-
to the provider from the AI SDK and enable provider-specific
|
|
130
|
-
functionality that can be fully encapsulated in the provider.
|
|
131
|
-
|
|
128
|
+
* Additional provider-specific metadata. They are passed through
|
|
129
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
130
|
+
* functionality that can be fully encapsulated in the provider.
|
|
131
|
+
*/
|
|
132
132
|
providerOptions?: ProviderOptions;
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
Whether the tool call was executed by the provider.
|
|
136
|
-
|
|
135
|
+
* Whether the tool call was executed by the provider.
|
|
136
|
+
*/
|
|
137
137
|
providerExecuted?: boolean;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
|
-
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
|
141
|
+
* Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
|
142
142
|
*/
|
|
143
143
|
export interface ToolResultPart {
|
|
144
144
|
type: 'tool-result';
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
ID of the tool call that this result is associated with.
|
|
148
|
-
|
|
147
|
+
* ID of the tool call that this result is associated with.
|
|
148
|
+
*/
|
|
149
149
|
toolCallId: string;
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
|
-
Name of the tool that generated this result.
|
|
153
|
-
|
|
152
|
+
* Name of the tool that generated this result.
|
|
153
|
+
*/
|
|
154
154
|
toolName: string;
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
|
-
Result of the tool call. This is a JSON-serializable object.
|
|
157
|
+
* Result of the tool call. This is a JSON-serializable object.
|
|
158
158
|
*/
|
|
159
159
|
output: ToolResultOutput;
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
|
-
Additional provider-specific metadata. They are passed through
|
|
163
|
-
to the provider from the AI SDK and enable provider-specific
|
|
164
|
-
functionality that can be fully encapsulated in the provider.
|
|
165
|
-
|
|
162
|
+
* Additional provider-specific metadata. They are passed through
|
|
163
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
164
|
+
* functionality that can be fully encapsulated in the provider.
|
|
165
|
+
*/
|
|
166
166
|
providerOptions?: ProviderOptions;
|
|
167
167
|
}
|
|
168
168
|
|
|
@@ -232,8 +232,8 @@ export type ToolResultOutput =
|
|
|
232
232
|
type: 'text';
|
|
233
233
|
|
|
234
234
|
/**
|
|
235
|
-
Text content.
|
|
236
|
-
*/
|
|
235
|
+
* Text content.
|
|
236
|
+
*/
|
|
237
237
|
text: string;
|
|
238
238
|
|
|
239
239
|
/**
|
|
@@ -253,14 +253,14 @@ Text content.
|
|
|
253
253
|
type: 'file-data';
|
|
254
254
|
|
|
255
255
|
/**
|
|
256
|
-
Base-64 encoded media data.
|
|
257
|
-
*/
|
|
256
|
+
* Base-64 encoded media data.
|
|
257
|
+
*/
|
|
258
258
|
data: string;
|
|
259
259
|
|
|
260
260
|
/**
|
|
261
|
-
IANA media type.
|
|
262
|
-
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
263
|
-
*/
|
|
261
|
+
* IANA media type.
|
|
262
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
263
|
+
*/
|
|
264
264
|
mediaType: string;
|
|
265
265
|
|
|
266
266
|
/**
|
|
@@ -311,14 +311,14 @@ IANA media type.
|
|
|
311
311
|
type: 'image-data';
|
|
312
312
|
|
|
313
313
|
/**
|
|
314
|
-
Base-64 encoded image data.
|
|
315
|
-
*/
|
|
314
|
+
* Base-64 encoded image data.
|
|
315
|
+
*/
|
|
316
316
|
data: string;
|
|
317
317
|
|
|
318
318
|
/**
|
|
319
|
-
IANA media type.
|
|
320
|
-
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
321
|
-
*/
|
|
319
|
+
* IANA media type.
|
|
320
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
321
|
+
*/
|
|
322
322
|
mediaType: string;
|
|
323
323
|
|
|
324
324
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
|
2
|
+
* Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
|
3
3
|
*/
|
|
4
4
|
export type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
@@ -4,8 +4,8 @@ import { ToolModelMessage } from './tool-model-message';
|
|
|
4
4
|
import { UserModelMessage } from './user-model-message';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
A message that can be used in the `messages` field of a prompt.
|
|
8
|
-
It can be a user message, an assistant message, or a tool message.
|
|
7
|
+
* A message that can be used in the `messages` field of a prompt.
|
|
8
|
+
* It can be a user message, an assistant message, or a tool message.
|
|
9
9
|
*/
|
|
10
10
|
export type ModelMessage =
|
|
11
11
|
| SystemModelMessage
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SharedV3ProviderOptions } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
Additional provider-specific options.
|
|
5
|
-
|
|
6
|
-
They are passed through to the provider from the AI SDK and enable
|
|
7
|
-
provider-specific functionality that can be fully encapsulated in the provider.
|
|
4
|
+
* Additional provider-specific options.
|
|
5
|
+
*
|
|
6
|
+
* They are passed through to the provider from the AI SDK and enable
|
|
7
|
+
* provider-specific functionality that can be fully encapsulated in the provider.
|
|
8
8
|
*/
|
|
9
9
|
export type ProviderOptions = SharedV3ProviderOptions;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { ProviderOptions } from './provider-options';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
A system message. It can contain system information.
|
|
5
|
-
|
|
6
|
-
Note: using the "system" part of the prompt is strongly preferred
|
|
7
|
-
to increase the resilience against prompt injection attacks,
|
|
8
|
-
and because not all providers support several system messages.
|
|
4
|
+
* A system message. It can contain system information.
|
|
5
|
+
*
|
|
6
|
+
* Note: using the "system" part of the prompt is strongly preferred
|
|
7
|
+
* to increase the resilience against prompt injection attacks,
|
|
8
|
+
* and because not all providers support several system messages.
|
|
9
9
|
*/
|
|
10
10
|
export type SystemModelMessage = {
|
|
11
11
|
role: 'system';
|
|
12
12
|
content: string;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
* Additional provider-specific metadata. They are passed through
|
|
16
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
17
|
+
* functionality that can be fully encapsulated in the provider.
|
|
18
|
+
*/
|
|
19
19
|
providerOptions?: ProviderOptions;
|
|
20
20
|
};
|
package/src/types/tool-call.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
Typed tool call that is returned by generateText and streamText.
|
|
3
|
-
It contains the tool call ID, the tool name, and the tool arguments.
|
|
2
|
+
* Typed tool call that is returned by generateText and streamText.
|
|
3
|
+
* It contains the tool call ID, the tool name, and the tool arguments.
|
|
4
4
|
*/
|
|
5
5
|
export interface ToolCall<NAME extends string, INPUT> {
|
|
6
6
|
/**
|
|
7
|
-
ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
8
|
-
|
|
7
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
8
|
+
*/
|
|
9
9
|
toolCallId: string;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
Name of the tool that is being called.
|
|
13
|
-
|
|
12
|
+
* Name of the tool that is being called.
|
|
13
|
+
*/
|
|
14
14
|
toolName: NAME;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
17
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
18
18
|
*/
|
|
19
19
|
input: INPUT;
|
|
20
20
|
|
|
@@ -3,21 +3,21 @@ import { ProviderOptions } from './provider-options';
|
|
|
3
3
|
import { ToolApprovalResponse } from './tool-approval-response';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
A tool message. It contains the result of one or more tool calls.
|
|
6
|
+
* A tool message. It contains the result of one or more tool calls.
|
|
7
7
|
*/
|
|
8
8
|
export type ToolModelMessage = {
|
|
9
9
|
role: 'tool';
|
|
10
10
|
content: ToolContent;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
* Additional provider-specific metadata. They are passed through
|
|
14
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
15
|
+
* functionality that can be fully encapsulated in the provider.
|
|
16
16
|
*/
|
|
17
17
|
providerOptions?: ProviderOptions;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
Content of a tool message. It is an array of tool result parts.
|
|
21
|
+
* Content of a tool message. It is an array of tool result parts.
|
|
22
22
|
*/
|
|
23
23
|
export type ToolContent = Array<ToolResultPart | ToolApprovalResponse>;
|
package/src/types/tool-result.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
Typed tool result that is returned by `generateText` and `streamText`.
|
|
3
|
-
It contains the tool call ID, the tool name, the tool arguments, and the tool result.
|
|
2
|
+
* Typed tool result that is returned by `generateText` and `streamText`.
|
|
3
|
+
* It contains the tool call ID, the tool name, the tool arguments, and the tool result.
|
|
4
4
|
*/
|
|
5
5
|
export interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
6
6
|
/**
|
|
7
|
-
ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
7
|
+
* ID of the tool call. This ID is used to match the tool call with the tool result.
|
|
8
8
|
*/
|
|
9
9
|
toolCallId: string;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
Name of the tool that was called.
|
|
12
|
+
* Name of the tool that was called.
|
|
13
13
|
*/
|
|
14
14
|
toolName: NAME;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
18
|
-
|
|
17
|
+
* Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
|
18
|
+
*/
|
|
19
19
|
input: INPUT;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
Result of the tool call. This is the result of the tool's execution.
|
|
23
|
-
|
|
22
|
+
* Result of the tool call. This is the result of the tool's execution.
|
|
23
|
+
*/
|
|
24
24
|
output: OUTPUT;
|
|
25
25
|
|
|
26
26
|
/**
|