@ai-sdk/google 4.0.106 → 4.0.108
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 +27 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +87 -50
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +9 -0
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +86 -49
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +18 -2
- package/package.json +2 -2
- package/src/convert-to-google-messages.ts +16 -5
- package/src/google-json-accumulator.ts +26 -14
- package/src/google-language-model.ts +19 -14
- package/src/google-prompt.ts +15 -0
- package/src/index.ts +1 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ type GoogleContent = {
|
|
|
11
11
|
role: 'user' | 'model';
|
|
12
12
|
parts: Array<GoogleContentPart>;
|
|
13
13
|
};
|
|
14
|
+
declare const googleVideoMetadataSchema: z.ZodObject<{
|
|
15
|
+
startOffset: z.ZodOptional<z.ZodString>;
|
|
16
|
+
endOffset: z.ZodOptional<z.ZodString>;
|
|
17
|
+
fps: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/** Metadata for preprocessing video file parts. */
|
|
20
|
+
type GoogleVideoMetadata = z.infer<typeof googleVideoMetadataSchema>;
|
|
14
21
|
type GoogleContentPart = {
|
|
15
22
|
text: string;
|
|
16
23
|
thought?: boolean;
|
|
@@ -20,6 +27,7 @@ type GoogleContentPart = {
|
|
|
20
27
|
mimeType: string;
|
|
21
28
|
data: string;
|
|
22
29
|
};
|
|
30
|
+
videoMetadata?: GoogleVideoMetadata;
|
|
23
31
|
thought?: boolean;
|
|
24
32
|
thoughtSignature?: string;
|
|
25
33
|
} | {
|
|
@@ -41,6 +49,7 @@ type GoogleContentPart = {
|
|
|
41
49
|
mimeType: string;
|
|
42
50
|
fileUri: string;
|
|
43
51
|
};
|
|
52
|
+
videoMetadata?: GoogleVideoMetadata;
|
|
44
53
|
thought?: boolean;
|
|
45
54
|
thoughtSignature?: string;
|
|
46
55
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__google_prompt0.GoogleContent","_$__google_prompt0.GoogleSystemInstruction"],"sources":["../../src/google-prompt.ts","../../src/google-language-model-options.ts","../../src/google-language-model.ts","../../src/google-speech-model-options.ts","../../src/google-speech-model.ts","../../src/google-speech-input.ts","../../src/google-tools.ts","../../src/interactions/google-interactions-language-model-options.ts","../../src/interactions/google-interactions-language-model.ts","../../src/interactions/google-interactions-agent.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__google_prompt0.GoogleContent","_$__google_prompt0.GoogleSystemInstruction"],"sources":["../../src/google-prompt.ts","../../src/google-language-model-options.ts","../../src/google-language-model.ts","../../src/google-speech-model-options.ts","../../src/google-speech-model.ts","../../src/google-speech-input.ts","../../src/google-tools.ts","../../src/interactions/google-interactions-language-model-options.ts","../../src/interactions/google-interactions-language-model.ts","../../src/interactions/google-interactions-agent.ts"],"mappings":";;;;KAcY;EACV,OAAO;IAAQ;;;KAGL;EACV;EACA,OAAO,MAAM;;cAGF,2BAAyB,EAAA;;;;GAOpC,EAAA,KAAA;;KAGU,sBAAsB,EAAE,aAAa;KAErC;EACN;EAAc;EAAmB;;EAEjC;IAAc;IAAkB;;EAChC,gBAAgB;EAChB;EACA;;EAGA;IAAgB;IAAa;IAAc;;EAC3C;;EAGA;IACE;IACA;IACA;IACA,QAAQ,MAAM;;;EAIhB;IAAY;IAAkB;;EAC9B,gBAAgB;EAChB;EACA;;EAGA;IACE;IACA;IACA;;EAEF;;EAGA;IACE;IACA;IACA;;EAEF;;EAGA;IACE;IACA;;;EAIF;IACE;IACA;;;KAII;EAEN;IAAc;IAAkB;;;EAGhC;IAAY;IAAkB;;;;;KCxFxB;;;YC+EA;EACV;EAC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YACjC,mBAAmB;YAGT,sBAAsB,YAChC,mBAAmB;;;KC/hET;;;UCoBF;EACR;EACA;EACA,UAAU,WAAW;EACrB,QAAQ;EACR;IACE,oBAAoB;;;qBAQX,6BAA6B;WAsB7B,SAAS;mBACD;WAtBV;UAED,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B,SAAS;IACT,QAAQ;MACT;MAIG;EAKO,YAAA,SAAS,qBACD,QAAQ;UAGb;EAmNR,WACJ,SAAS,WAAW,kCACnB,QAAQ,QAAQ,WAAW;;;;;;;;;wBCnRhB,uBACd,MACA,OACA;EAEA;EACA;EACA,kBAAkB;;EACd;EAAc;;;;qBCLP;;;;;;;;kBAAA;oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KCQD;;;KC2CA;EACV;EACA;EACA,UAAU,WAAW;EACrB,QAAQ;EACR;EACA,sBAAsB;;KAGZ,+BACR;EACE;;EACA;;qBAEO,2CAA2C;WAC7C;WAEA;;;;;WAMA;mBAEQ;UAET,oBAAoB,OAAO;;;;;UAU3B,sBAAsB;IAC5B;IACA;IACA,QAAQ;MACT;EAQC,YAAA,cAAc,8BACd,QAAQ;MAeN;MAIA,iBAAa,eAAA,YAAA,YAAA,eAAA;UAgBH;EAiVR,WACJ,SAAS,6BACR,QAAQ;EAmIL,SACJ,SAAS,6BACR,QAAQ;UAoFG;;;;;;;;;;;;;KClrBJ"}
|
package/dist/internal/index.js
CHANGED
|
@@ -116,6 +116,16 @@ function addTokenDetails(a, b) {
|
|
|
116
116
|
}));
|
|
117
117
|
}
|
|
118
118
|
//#endregion
|
|
119
|
+
//#region src/google-prompt.ts
|
|
120
|
+
const googleVideoMetadataSchema = z.object({
|
|
121
|
+
/** Start offset as a duration in seconds, e.g. `'3.5s'`. */
|
|
122
|
+
startOffset: z.string().optional(),
|
|
123
|
+
/** End offset as a duration in seconds, e.g. `'10s'`. */
|
|
124
|
+
endOffset: z.string().optional(),
|
|
125
|
+
/** Frames per second in the range (0, 24]. Defaults to 1. */
|
|
126
|
+
fps: z.number().gt(0).max(24).optional()
|
|
127
|
+
});
|
|
128
|
+
//#endregion
|
|
119
129
|
//#region src/tool/code-execution.ts
|
|
120
130
|
const codeExecutionInputSchema = z.object({
|
|
121
131
|
language: z.string().describe("The programming language of the code."),
|
|
@@ -276,33 +286,50 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
276
286
|
case "text":
|
|
277
287
|
parts.push({ text: part.text });
|
|
278
288
|
break;
|
|
279
|
-
case "file":
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
289
|
+
case "file": {
|
|
290
|
+
const rawVideoMetadata = readProviderOpts(part)?.videoMetadata;
|
|
291
|
+
const videoMetadata = rawVideoMetadata == null ? void 0 : googleVideoMetadataSchema.parse(rawVideoMetadata);
|
|
292
|
+
switch (part.data.type) {
|
|
293
|
+
case "url":
|
|
294
|
+
parts.push({
|
|
295
|
+
fileData: {
|
|
296
|
+
mimeType: resolveFullMediaType({ part }),
|
|
297
|
+
fileUri: part.data.url.protocol === "gs:" && part.data.originalUrl != null ? part.data.originalUrl : part.data.url.toString()
|
|
298
|
+
},
|
|
299
|
+
...videoMetadata != null ? { videoMetadata } : {}
|
|
300
|
+
});
|
|
301
|
+
break;
|
|
302
|
+
case "reference":
|
|
303
|
+
if (isVertexLike) throw new UnsupportedFunctionalityError({ functionality: "file parts with provider references" });
|
|
304
|
+
parts.push({
|
|
305
|
+
fileData: {
|
|
306
|
+
mimeType: resolveFullMediaType({ part }),
|
|
307
|
+
fileUri: resolveProviderReference({
|
|
308
|
+
reference: part.data.reference,
|
|
309
|
+
provider: "google"
|
|
310
|
+
})
|
|
311
|
+
},
|
|
312
|
+
...videoMetadata != null ? { videoMetadata } : {}
|
|
313
|
+
});
|
|
314
|
+
break;
|
|
315
|
+
case "text":
|
|
316
|
+
parts.push({
|
|
317
|
+
inlineData: {
|
|
318
|
+
mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
|
|
319
|
+
data: convertToBase64(new TextEncoder().encode(part.data.text))
|
|
320
|
+
},
|
|
321
|
+
...videoMetadata != null ? { videoMetadata } : {}
|
|
322
|
+
});
|
|
323
|
+
break;
|
|
324
|
+
case "data": parts.push({
|
|
325
|
+
inlineData: {
|
|
326
|
+
mimeType: resolveFullMediaType({ part }),
|
|
327
|
+
data: convertToBase64(part.data.data)
|
|
328
|
+
},
|
|
329
|
+
...videoMetadata != null ? { videoMetadata } : {}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
break;
|
|
306
333
|
}
|
|
307
334
|
}
|
|
308
335
|
contents.push({
|
|
@@ -1057,11 +1084,16 @@ var GoogleJSONAccumulator = class {
|
|
|
1057
1084
|
const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
|
|
1058
1085
|
setNestedValue(this.accumulatedArgs, segments, existingValue + arg.stringValue);
|
|
1059
1086
|
delta += escaped;
|
|
1087
|
+
if (arg.willContinue !== true) delta += this.closeOpenString();
|
|
1060
1088
|
continue;
|
|
1061
1089
|
}
|
|
1062
1090
|
const resolved = resolvePartialArgValue(arg);
|
|
1063
1091
|
if (resolved == null) {
|
|
1064
|
-
if (existingValue !== void 0
|
|
1092
|
+
if (existingValue !== void 0) {
|
|
1093
|
+
if (typeof existingValue === "string" && arg.willContinue !== true) delta += this.closeOpenString();
|
|
1094
|
+
continue;
|
|
1095
|
+
}
|
|
1096
|
+
if (arg.willContinue === true) continue;
|
|
1065
1097
|
setNestedValue(this.accumulatedArgs, segments, isArrayTerminator ? [] : {});
|
|
1066
1098
|
delta += this.emitContainer(segments, isArrayTerminator);
|
|
1067
1099
|
continue;
|
|
@@ -1087,6 +1119,15 @@ var GoogleJSONAccumulator = class {
|
|
|
1087
1119
|
};
|
|
1088
1120
|
}
|
|
1089
1121
|
/**
|
|
1122
|
+
* Input: stringOpen=true
|
|
1123
|
+
* Output: '"' (and stringOpen=false), or '' when no string is open
|
|
1124
|
+
*/
|
|
1125
|
+
closeOpenString() {
|
|
1126
|
+
if (!this.stringOpen) return "";
|
|
1127
|
+
this.stringOpen = false;
|
|
1128
|
+
return "\"";
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1090
1131
|
* Input: pathStack=[] (first call) or pathStack=[root,...] (subsequent calls)
|
|
1091
1132
|
* Output: '{' (first call) or '' (subsequent calls)
|
|
1092
1133
|
*/
|
|
@@ -1109,11 +1150,7 @@ var GoogleJSONAccumulator = class {
|
|
|
1109
1150
|
* Output: '{"recipe":{"name":"Lasagna"'
|
|
1110
1151
|
*/
|
|
1111
1152
|
emitNavigationTo(targetSegments, arg, valueJson) {
|
|
1112
|
-
let fragment =
|
|
1113
|
-
if (this.stringOpen) {
|
|
1114
|
-
fragment += "\"";
|
|
1115
|
-
this.stringOpen = false;
|
|
1116
|
-
}
|
|
1153
|
+
let fragment = this.closeOpenString();
|
|
1117
1154
|
fragment += this.ensureRoot();
|
|
1118
1155
|
const targetContainerSegments = targetSegments.slice(0, -1);
|
|
1119
1156
|
const leafSegment = targetSegments[targetSegments.length - 1];
|
|
@@ -1132,11 +1169,7 @@ var GoogleJSONAccumulator = class {
|
|
|
1132
1169
|
* Output: '{"nested":{"tags":['
|
|
1133
1170
|
*/
|
|
1134
1171
|
emitContainer(targetSegments, isArray) {
|
|
1135
|
-
let fragment =
|
|
1136
|
-
if (this.stringOpen) {
|
|
1137
|
-
fragment += "\"";
|
|
1138
|
-
this.stringOpen = false;
|
|
1139
|
-
}
|
|
1172
|
+
let fragment = this.closeOpenString();
|
|
1140
1173
|
fragment += this.ensureRoot();
|
|
1141
1174
|
const commonDepth = this.findCommonStackDepth(targetSegments);
|
|
1142
1175
|
fragment += this.closeDownTo(commonDepth);
|
|
@@ -2209,6 +2242,14 @@ function getMaxThinkingTokensForGemini25Model(modelId) {
|
|
|
2209
2242
|
if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) return 32768;
|
|
2210
2243
|
return 24576;
|
|
2211
2244
|
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Gemini 2.5 Pro cannot disable thinking and requires a thinking budget of at
|
|
2247
|
+
* least 128 tokens. Other Gemini 2.5 models can disable thinking with a budget
|
|
2248
|
+
* of 0.
|
|
2249
|
+
*/
|
|
2250
|
+
function getMinThinkingTokensForGemini25Model(modelId) {
|
|
2251
|
+
return modelId.toLowerCase().includes("2.5-pro") ? 128 : 0;
|
|
2252
|
+
}
|
|
2212
2253
|
function resolveThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2213
2254
|
if (!isCustomReasoning(reasoning)) return;
|
|
2214
2255
|
if (getGoogleModelCapabilities(modelId).usesGemini3Features && !modelId.includes("gemini-3-pro-image")) return resolveGemini3ThinkingConfig({
|
|
@@ -2224,16 +2265,13 @@ function resolveThinkingConfig({ reasoning, modelId, warnings }) {
|
|
|
2224
2265
|
}
|
|
2225
2266
|
function resolveGemini3ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2226
2267
|
const minimumThinkingLevel = getMinimumThinkingLevelForGemini3Model(modelId);
|
|
2227
|
-
if (reasoning === "none") return { thinkingLevel: minimumThinkingLevel };
|
|
2228
2268
|
const thinkingLevel = mapReasoningToProviderEffort({
|
|
2229
2269
|
reasoning,
|
|
2230
2270
|
effortMap: {
|
|
2231
|
-
minimal:
|
|
2271
|
+
...minimumThinkingLevel === "minimal" && { minimal: "minimal" },
|
|
2232
2272
|
low: "low",
|
|
2233
2273
|
medium: "medium",
|
|
2234
|
-
high: "high"
|
|
2235
|
-
xhigh: "high",
|
|
2236
|
-
max: "high"
|
|
2274
|
+
high: "high"
|
|
2237
2275
|
},
|
|
2238
2276
|
warnings
|
|
2239
2277
|
});
|
|
@@ -2252,16 +2290,15 @@ function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
|
2252
2290
|
return majorVersion > 3 || majorVersion === 3 && minorVersion >= 7 ? "low" : "minimal";
|
|
2253
2291
|
}
|
|
2254
2292
|
function resolveGemini25ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2255
|
-
|
|
2256
|
-
|
|
2293
|
+
const minThinkingBudget = getMinThinkingTokensForGemini25Model(modelId);
|
|
2294
|
+
if (reasoning === "none" && minThinkingBudget === 0) return { thinkingBudget: 0 };
|
|
2295
|
+
return { thinkingBudget: mapReasoningToProviderBudget({
|
|
2257
2296
|
reasoning,
|
|
2258
2297
|
maxOutputTokens: getMaxOutputTokensForGemini25Model(),
|
|
2259
2298
|
maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
|
|
2260
|
-
minReasoningBudget:
|
|
2299
|
+
minReasoningBudget: minThinkingBudget,
|
|
2261
2300
|
warnings
|
|
2262
|
-
});
|
|
2263
|
-
if (thinkingBudget == null) return;
|
|
2264
|
-
return { thinkingBudget };
|
|
2301
|
+
}) };
|
|
2265
2302
|
}
|
|
2266
2303
|
function extractSources({ groundingMetadata, generateId }) {
|
|
2267
2304
|
if (!groundingMetadata?.groundingChunks) return;
|