@ai-sdk/provider-utils 4.0.10 → 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 +8 -0
- package/dist/index.d.mts +170 -166
- package/dist/index.d.ts +170 -166
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -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/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
|
@@ -2,21 +2,21 @@ import { FilePart, ImagePart, TextPart } from './content-part';
|
|
|
2
2
|
import { ProviderOptions } from './provider-options';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
A user message. It can contain text or a combination of text and images.
|
|
5
|
+
* A user message. It can contain text or a combination of text and images.
|
|
6
6
|
*/
|
|
7
7
|
export type UserModelMessage = {
|
|
8
8
|
role: 'user';
|
|
9
9
|
content: UserContent;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
* Additional provider-specific metadata. They are passed through
|
|
13
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
14
|
+
* functionality that can be fully encapsulated in the provider.
|
|
15
|
+
*/
|
|
16
16
|
providerOptions?: ProviderOptions;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
* Content of a user message. It can be a string or an array of text and image parts.
|
|
21
|
+
*/
|
|
22
22
|
export type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
package/src/validate-types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypeValidationError } from '@ai-sdk/provider';
|
|
1
|
+
import { TypeValidationContext, TypeValidationError } from '@ai-sdk/provider';
|
|
2
2
|
import { FlexibleSchema, asSchema } from './schema';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -8,19 +8,22 @@ import { FlexibleSchema, asSchema } from './schema';
|
|
|
8
8
|
* @template T - The type of the object to validate.
|
|
9
9
|
* @param {string} options.value - The object to validate.
|
|
10
10
|
* @param {Validator<T>} options.schema - The schema to use for validating the JSON.
|
|
11
|
+
* @param {TypeValidationContext} options.context - Optional context about what is being validated.
|
|
11
12
|
* @returns {Promise<T>} - The typed object.
|
|
12
13
|
*/
|
|
13
14
|
export async function validateTypes<OBJECT>({
|
|
14
15
|
value,
|
|
15
16
|
schema,
|
|
17
|
+
context,
|
|
16
18
|
}: {
|
|
17
19
|
value: unknown;
|
|
18
20
|
schema: FlexibleSchema<OBJECT>;
|
|
21
|
+
context?: TypeValidationContext;
|
|
19
22
|
}): Promise<OBJECT> {
|
|
20
|
-
const result = await safeValidateTypes({ value, schema });
|
|
23
|
+
const result = await safeValidateTypes({ value, schema, context });
|
|
21
24
|
|
|
22
25
|
if (!result.success) {
|
|
23
|
-
throw TypeValidationError.wrap({ value, cause: result.error });
|
|
26
|
+
throw TypeValidationError.wrap({ value, cause: result.error, context });
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
return result.value;
|
|
@@ -33,14 +36,17 @@ export async function validateTypes<OBJECT>({
|
|
|
33
36
|
* @template T - The type of the object to validate.
|
|
34
37
|
* @param {string} options.value - The JSON object to validate.
|
|
35
38
|
* @param {Validator<T>} options.schema - The schema to use for validating the JSON.
|
|
39
|
+
* @param {TypeValidationContext} options.context - Optional context about what is being validated.
|
|
36
40
|
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
|
37
41
|
*/
|
|
38
42
|
export async function safeValidateTypes<OBJECT>({
|
|
39
43
|
value,
|
|
40
44
|
schema,
|
|
45
|
+
context,
|
|
41
46
|
}: {
|
|
42
47
|
value: unknown;
|
|
43
48
|
schema: FlexibleSchema<OBJECT>;
|
|
49
|
+
context?: TypeValidationContext;
|
|
44
50
|
}): Promise<
|
|
45
51
|
| {
|
|
46
52
|
success: true;
|
|
@@ -68,13 +74,13 @@ export async function safeValidateTypes<OBJECT>({
|
|
|
68
74
|
|
|
69
75
|
return {
|
|
70
76
|
success: false,
|
|
71
|
-
error: TypeValidationError.wrap({ value, cause: result.error }),
|
|
77
|
+
error: TypeValidationError.wrap({ value, cause: result.error, context }),
|
|
72
78
|
rawValue: value,
|
|
73
79
|
};
|
|
74
80
|
} catch (error) {
|
|
75
81
|
return {
|
|
76
82
|
success: false,
|
|
77
|
-
error: TypeValidationError.wrap({ value, cause: error }),
|
|
83
|
+
error: TypeValidationError.wrap({ value, cause: error, context }),
|
|
78
84
|
rawValue: value,
|
|
79
85
|
};
|
|
80
86
|
}
|