@ai-sdk/google 4.0.50 → 4.0.53
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 +30 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1154 -577
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +147 -6
- package/dist/internal/index.js +86 -42
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +71 -0
- package/package.json +6 -6
- package/src/convert-json-schema-to-openapi-schema.ts +13 -1
- package/src/google-batch.ts +670 -0
- package/src/google-files.ts +27 -2
- package/src/google-language-model.ts +58 -35
- package/src/google-prepare-tools.ts +45 -21
- package/src/google-provider.ts +7 -6
- package/src/interactions/build-google-interactions-stream-transform.ts +13 -5
package/docs/15-google.mdx
CHANGED
|
@@ -1064,6 +1064,77 @@ The following Zod features are known to not work with Google:
|
|
|
1064
1064
|
available provider model ID as a string if needed.
|
|
1065
1065
|
</Note>
|
|
1066
1066
|
|
|
1067
|
+
### Text Batches
|
|
1068
|
+
|
|
1069
|
+
<Note type="warning">
|
|
1070
|
+
Text batch support is experimental and the API may change in patch releases.
|
|
1071
|
+
</Note>
|
|
1072
|
+
|
|
1073
|
+
The Google provider supports asynchronous text generation through the
|
|
1074
|
+
[Gemini Batch API](https://ai.google.dev/gemini-api/docs/batch-api). Use the
|
|
1075
|
+
experimental text batch APIs to start a batch, poll its status, and stream its
|
|
1076
|
+
results:
|
|
1077
|
+
|
|
1078
|
+
```ts
|
|
1079
|
+
import { google } from '@ai-sdk/google';
|
|
1080
|
+
import {
|
|
1081
|
+
experimental_getBatchResults as getBatchResults,
|
|
1082
|
+
experimental_getBatchStatus as getBatchStatus,
|
|
1083
|
+
experimental_startTextBatch as startTextBatch,
|
|
1084
|
+
} from 'ai';
|
|
1085
|
+
import { setTimeout } from 'node:timers/promises';
|
|
1086
|
+
|
|
1087
|
+
const model = google('gemini-3.6-flash');
|
|
1088
|
+
|
|
1089
|
+
const batch = await startTextBatch({
|
|
1090
|
+
model,
|
|
1091
|
+
requests: [
|
|
1092
|
+
{ id: 'capital-france', prompt: 'What is the capital of France?' },
|
|
1093
|
+
{ id: 'capital-germany', prompt: 'What is the capital of Germany?' },
|
|
1094
|
+
],
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
let status = batch.status;
|
|
1098
|
+
while (status === 'pending') {
|
|
1099
|
+
await setTimeout(60_000);
|
|
1100
|
+
({ status } = await getBatchStatus({ model, batch }));
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
for await (const item of getBatchResults({ model, batch })) {
|
|
1104
|
+
if (item.status === 'succeeded') {
|
|
1105
|
+
console.log(item.id, item.text);
|
|
1106
|
+
} else {
|
|
1107
|
+
console.error(item.id, item.error);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
`startTextBatch` returns a serializable batch reference. Persist this reference
|
|
1113
|
+
to check the batch status or retrieve its results from another process. Results
|
|
1114
|
+
can arrive in a different order from the input requests, so match each result by
|
|
1115
|
+
its `id`.
|
|
1116
|
+
|
|
1117
|
+
#### Webhooks
|
|
1118
|
+
|
|
1119
|
+
You can pass a `webhookUrl` to receive a notification when the batch reaches a terminal state:
|
|
1120
|
+
|
|
1121
|
+
```ts
|
|
1122
|
+
const batch = await startTextBatch({
|
|
1123
|
+
model,
|
|
1124
|
+
requests: [
|
|
1125
|
+
{ id: 'capital-france', prompt: 'What is the capital of France?' },
|
|
1126
|
+
{ id: 'capital-germany', prompt: 'What is the capital of Germany?' },
|
|
1127
|
+
],
|
|
1128
|
+
webhookUrl: 'https://example.com/api/google-batch-webhook',
|
|
1129
|
+
});
|
|
1130
|
+
```
|
|
1131
|
+
|
|
1132
|
+
Google sends a thin event to the webhook URL. After receiving and verifying the event, use the persisted batch reference with `getBatchStatus` or `getBatchResults`. Your application is responsible for handling the webhook and [verifying Google's dynamic webhook signature](https://ai.google.dev/gemini-api/docs/webhooks#verify_dynamic_signatures_jwks).
|
|
1133
|
+
|
|
1134
|
+
#### Large Batches
|
|
1135
|
+
|
|
1136
|
+
When the serialized batch creation body is under 20 MB, the provider sends the requests inline. At 20 MB or more, it uploads a JSONL input file through the Gemini Files API.
|
|
1137
|
+
|
|
1067
1138
|
## Realtime Models
|
|
1068
1139
|
|
|
1069
1140
|
<Note type="warning">Realtime is an experimental feature.</Note>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,16 +35,16 @@
|
|
|
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.8",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.32"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
+
"@ai-sdk/test-server": "2.0.1",
|
|
42
43
|
"@types/node": "22.19.19",
|
|
44
|
+
"@vercel/ai-tsconfig": "0.0.0",
|
|
43
45
|
"tsup": "^8.5.1",
|
|
44
46
|
"typescript": "5.8.3",
|
|
45
|
-
"zod": "3.25.76"
|
|
46
|
-
"@ai-sdk/test-server": "2.0.1",
|
|
47
|
-
"@vercel/ai-tsconfig": "0.0.0"
|
|
47
|
+
"zod": "3.25.76"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"zod": "^3.25.76 || ^4.1.8"
|
|
@@ -14,6 +14,18 @@ type ReferenceContext = {
|
|
|
14
14
|
resolvingReferences: ReadonlySet<string>;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
const recursiveReferenceFunctionalityPrefix =
|
|
18
|
+
'recursive JSON Schema reference:';
|
|
19
|
+
|
|
20
|
+
export function isRecursiveJSONSchemaReferenceError(
|
|
21
|
+
error: unknown,
|
|
22
|
+
): error is UnsupportedFunctionalityError {
|
|
23
|
+
return (
|
|
24
|
+
UnsupportedFunctionalityError.isInstance(error) &&
|
|
25
|
+
error.functionality.startsWith(recursiveReferenceFunctionalityPrefix)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
/**
|
|
18
30
|
* Converts JSON Schema 7 to OpenAPI Schema 3.0
|
|
19
31
|
*/
|
|
@@ -205,7 +217,7 @@ function convertJSONSchemaReference({
|
|
|
205
217
|
|
|
206
218
|
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
207
219
|
throw new UnsupportedFunctionalityError({
|
|
208
|
-
functionality:
|
|
220
|
+
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
209
221
|
message:
|
|
210
222
|
'Google schema conversion does not support recursive JSON Schema references.',
|
|
211
223
|
});
|