@ai-sdk/google 4.0.98 → 4.0.99
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.ts.map +1 -1
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +23 -2
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/google-error.ts +9 -6
- package/src/google-language-model.ts +28 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.99",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.29",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.62"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.4",
|
package/src/google-error.ts
CHANGED
|
@@ -6,15 +6,18 @@ import {
|
|
|
6
6
|
} from '@ai-sdk/provider-utils';
|
|
7
7
|
import { z } from 'zod/v4';
|
|
8
8
|
|
|
9
|
+
export const getGoogleErrorSchema = () =>
|
|
10
|
+
z.object({
|
|
11
|
+
code: z.number().nullable(),
|
|
12
|
+
message: z.string(),
|
|
13
|
+
status: z.string(),
|
|
14
|
+
details: z.array(z.unknown()).nullish(),
|
|
15
|
+
});
|
|
16
|
+
|
|
9
17
|
const googleErrorDataSchema = lazySchema(() =>
|
|
10
18
|
zodSchema(
|
|
11
19
|
z.object({
|
|
12
|
-
error:
|
|
13
|
-
code: z.number().nullable(),
|
|
14
|
-
message: z.string(),
|
|
15
|
-
status: z.string(),
|
|
16
|
-
details: z.array(z.unknown()).nullish(),
|
|
17
|
-
}),
|
|
20
|
+
error: getGoogleErrorSchema(),
|
|
18
21
|
}),
|
|
19
22
|
),
|
|
20
23
|
);
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
createToolNameMapping,
|
|
19
19
|
createEventSourceResponseHandler,
|
|
20
20
|
createJsonResponseHandler,
|
|
21
|
+
createProviderStreamError,
|
|
21
22
|
generateId,
|
|
22
23
|
isCustomReasoning,
|
|
23
24
|
lazySchema,
|
|
@@ -45,7 +46,10 @@ import {
|
|
|
45
46
|
import { convertToGoogleMessages } from './convert-to-google-messages';
|
|
46
47
|
import { downloadToolResultFiles } from './download-tool-result-files';
|
|
47
48
|
import { getModelPath } from './get-model-path';
|
|
48
|
-
import {
|
|
49
|
+
import {
|
|
50
|
+
getGoogleErrorSchema,
|
|
51
|
+
googleFailedResponseHandler,
|
|
52
|
+
} from './google-error';
|
|
49
53
|
import { sanitizeResponseJsonSchema } from './sanitize-response-json-schema';
|
|
50
54
|
import {
|
|
51
55
|
googleLanguageModelOptions,
|
|
@@ -995,6 +999,28 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
995
999
|
|
|
996
1000
|
const value = chunk.value;
|
|
997
1001
|
|
|
1002
|
+
if (value.error != null) {
|
|
1003
|
+
finishReason = { unified: 'error', raw: undefined };
|
|
1004
|
+
const error = value.error;
|
|
1005
|
+
controller.enqueue({
|
|
1006
|
+
type: 'error',
|
|
1007
|
+
error: createProviderStreamError({
|
|
1008
|
+
message: error.message,
|
|
1009
|
+
type: error.status,
|
|
1010
|
+
code: error.code ?? undefined,
|
|
1011
|
+
statusCode: error.code ?? undefined,
|
|
1012
|
+
isRetryable:
|
|
1013
|
+
error.code != null &&
|
|
1014
|
+
(error.code === 408 ||
|
|
1015
|
+
error.code === 409 ||
|
|
1016
|
+
error.code === 429 ||
|
|
1017
|
+
error.code >= 500),
|
|
1018
|
+
data: error,
|
|
1019
|
+
}),
|
|
1020
|
+
});
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
998
1024
|
if (!hasEmittedResponseMetadata && value.responseId != null) {
|
|
999
1025
|
hasEmittedResponseMetadata = true;
|
|
1000
1026
|
controller.enqueue({
|
|
@@ -2012,6 +2038,7 @@ export type UsageMetadataSchema = NonNullable<
|
|
|
2012
2038
|
const chunkSchema = lazySchema(() =>
|
|
2013
2039
|
zodSchema(
|
|
2014
2040
|
z.object({
|
|
2041
|
+
error: getGoogleErrorSchema().nullish(),
|
|
2015
2042
|
responseId: z.string().nullish(),
|
|
2016
2043
|
candidates: z
|
|
2017
2044
|
.array(
|