@ai-sdk/google 4.0.68 → 4.0.70
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 +25 -0
- package/dist/index.js +173 -329
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +9 -4
- package/dist/internal/index.js +159 -322
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/download-tool-result-files.ts +124 -0
- package/src/google-language-model.ts +32 -13
- package/src/google-prepare-tools.ts +3 -23
- package/src/realtime/google-realtime-event-mapper.ts +24 -3
- package/src/sanitize-response-json-schema.ts +65 -0
- package/src/convert-json-schema-to-openapi-schema.ts +0 -456
package/dist/internal/index.d.ts
CHANGED
|
@@ -79,6 +79,12 @@ type GoogleLanguageModelConfig = {
|
|
|
79
79
|
* The supported URLs for the model.
|
|
80
80
|
*/
|
|
81
81
|
supportedUrls?: () => LanguageModelV4['supportedUrls'];
|
|
82
|
+
/**
|
|
83
|
+
* Settings for downloading remote files in tool results before conversion.
|
|
84
|
+
*/
|
|
85
|
+
downloadToolResultFiles?: {
|
|
86
|
+
maxBytes: number;
|
|
87
|
+
};
|
|
82
88
|
};
|
|
83
89
|
declare class GoogleLanguageModel implements LanguageModelV4 {
|
|
84
90
|
readonly specificationVersion = "v4";
|
|
@@ -96,7 +102,7 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
96
102
|
constructor(modelId: GoogleModelId, config: GoogleLanguageModelConfig);
|
|
97
103
|
get provider(): string;
|
|
98
104
|
get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
99
|
-
static prepareRequest({ modelId, config, options: { prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, }, isStreaming, }: {
|
|
105
|
+
static prepareRequest({ modelId, config, options: { prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, abortSignal, }, isStreaming, }: {
|
|
100
106
|
modelId: GoogleModelId;
|
|
101
107
|
config: GoogleLanguageModelConfig;
|
|
102
108
|
options: LanguageModelV4CallOptions;
|
|
@@ -131,7 +137,7 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
131
137
|
stopSequences: string[] | undefined;
|
|
132
138
|
seed: number | undefined;
|
|
133
139
|
responseMimeType: string | undefined;
|
|
134
|
-
|
|
140
|
+
responseJsonSchema: _ai_sdk_provider.JSONSchema7 | undefined;
|
|
135
141
|
};
|
|
136
142
|
contents: GoogleContent[];
|
|
137
143
|
systemInstruction: GoogleSystemInstruction | undefined;
|
|
@@ -143,8 +149,7 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
143
149
|
functionDeclarations: {
|
|
144
150
|
name: string;
|
|
145
151
|
description: string;
|
|
146
|
-
|
|
147
|
-
parametersJsonSchema?: unknown;
|
|
152
|
+
parametersJsonSchema: unknown;
|
|
148
153
|
}[];
|
|
149
154
|
} | Record<string, any>)[] | undefined;
|
|
150
155
|
toolConfig: {
|
package/dist/internal/index.js
CHANGED
|
@@ -46,289 +46,9 @@ function convertGoogleUsage(usage) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
// src/convert-json-schema-to-openapi-schema.ts
|
|
50
|
-
import {
|
|
51
|
-
UnsupportedFunctionalityError
|
|
52
|
-
} from "@ai-sdk/provider";
|
|
53
|
-
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
54
|
-
function isRecursiveJSONSchemaReferenceError(error) {
|
|
55
|
-
return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
56
|
-
}
|
|
57
|
-
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
58
|
-
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
59
|
-
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
60
|
-
definitions: rootSchema == null ? void 0 : rootSchema.definitions,
|
|
61
|
-
dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
|
|
62
|
-
resolvingReferences: /* @__PURE__ */ new Set()
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
66
|
-
if (jsonSchema == null) {
|
|
67
|
-
return void 0;
|
|
68
|
-
}
|
|
69
|
-
if (typeof jsonSchema === "boolean") {
|
|
70
|
-
return { type: "boolean", properties: {} };
|
|
71
|
-
}
|
|
72
|
-
if (jsonSchema.$ref != null) {
|
|
73
|
-
return convertJSONSchemaReference({
|
|
74
|
-
jsonSchema,
|
|
75
|
-
reference: jsonSchema.$ref,
|
|
76
|
-
isRoot,
|
|
77
|
-
referenceContext
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
if (isEmptyObjectSchema(jsonSchema)) {
|
|
81
|
-
if (isRoot) {
|
|
82
|
-
return void 0;
|
|
83
|
-
}
|
|
84
|
-
if (jsonSchema.description) {
|
|
85
|
-
return { type: "object", description: jsonSchema.description };
|
|
86
|
-
}
|
|
87
|
-
return { type: "object" };
|
|
88
|
-
}
|
|
89
|
-
const {
|
|
90
|
-
type,
|
|
91
|
-
description,
|
|
92
|
-
required,
|
|
93
|
-
properties,
|
|
94
|
-
items,
|
|
95
|
-
allOf,
|
|
96
|
-
anyOf,
|
|
97
|
-
oneOf,
|
|
98
|
-
format,
|
|
99
|
-
const: constValue,
|
|
100
|
-
minLength,
|
|
101
|
-
minItems,
|
|
102
|
-
maxItems,
|
|
103
|
-
enum: enumValues
|
|
104
|
-
} = jsonSchema;
|
|
105
|
-
const result = {};
|
|
106
|
-
if (description) result.description = description;
|
|
107
|
-
if (required) result.required = required;
|
|
108
|
-
if (format) result.format = format;
|
|
109
|
-
if (type) {
|
|
110
|
-
if (Array.isArray(type)) {
|
|
111
|
-
const hasNull = type.includes("null");
|
|
112
|
-
const nonNullTypes = type.filter((t) => t !== "null");
|
|
113
|
-
if (nonNullTypes.length === 0) {
|
|
114
|
-
result.type = "null";
|
|
115
|
-
} else {
|
|
116
|
-
result.anyOf = nonNullTypes.map((t) => ({ type: t }));
|
|
117
|
-
if (hasNull) {
|
|
118
|
-
result.nullable = true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
result.type = type;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
|
|
126
|
-
if (values !== void 0) {
|
|
127
|
-
addEnumToSchema({ values, type, result });
|
|
128
|
-
}
|
|
129
|
-
if (properties != null) {
|
|
130
|
-
result.properties = Object.entries(properties).reduce(
|
|
131
|
-
(acc, [key, value]) => {
|
|
132
|
-
acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
|
|
133
|
-
return acc;
|
|
134
|
-
},
|
|
135
|
-
{}
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
if (items) {
|
|
139
|
-
result.items = Array.isArray(items) ? items.map(
|
|
140
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
141
|
-
) : convertJSONSchemaDefinition(items, false, referenceContext);
|
|
142
|
-
}
|
|
143
|
-
if (allOf) {
|
|
144
|
-
result.allOf = allOf.map(
|
|
145
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
if (anyOf) {
|
|
149
|
-
if (anyOf.some(
|
|
150
|
-
(schema) => typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null"
|
|
151
|
-
)) {
|
|
152
|
-
const nonNullSchemas = anyOf.filter(
|
|
153
|
-
(schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
|
|
154
|
-
);
|
|
155
|
-
if (nonNullSchemas.length === 1) {
|
|
156
|
-
const converted = convertJSONSchemaDefinition(
|
|
157
|
-
nonNullSchemas[0],
|
|
158
|
-
false,
|
|
159
|
-
referenceContext
|
|
160
|
-
);
|
|
161
|
-
if (typeof converted === "object") {
|
|
162
|
-
result.nullable = true;
|
|
163
|
-
Object.assign(result, converted);
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
result.anyOf = nonNullSchemas.map(
|
|
167
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
168
|
-
);
|
|
169
|
-
result.nullable = true;
|
|
170
|
-
}
|
|
171
|
-
} else {
|
|
172
|
-
result.anyOf = anyOf.map(
|
|
173
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (oneOf) {
|
|
178
|
-
result.oneOf = oneOf.map(
|
|
179
|
-
(item) => convertJSONSchemaDefinition(item, false, referenceContext)
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
if (minLength !== void 0) {
|
|
183
|
-
result.minLength = minLength;
|
|
184
|
-
}
|
|
185
|
-
if (minItems !== void 0) {
|
|
186
|
-
result.minItems = minItems;
|
|
187
|
-
}
|
|
188
|
-
if (maxItems !== void 0) {
|
|
189
|
-
result.maxItems = maxItems;
|
|
190
|
-
}
|
|
191
|
-
return result;
|
|
192
|
-
}
|
|
193
|
-
function convertJSONSchemaReference({
|
|
194
|
-
jsonSchema,
|
|
195
|
-
reference,
|
|
196
|
-
isRoot,
|
|
197
|
-
referenceContext
|
|
198
|
-
}) {
|
|
199
|
-
const { definition, referenceKey } = getReferencedDefinition(
|
|
200
|
-
reference,
|
|
201
|
-
referenceContext
|
|
202
|
-
);
|
|
203
|
-
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
204
|
-
throw new UnsupportedFunctionalityError({
|
|
205
|
-
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
206
|
-
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
const resolvingReferences = new Set(referenceContext.resolvingReferences);
|
|
210
|
-
resolvingReferences.add(referenceKey);
|
|
211
|
-
const { $ref: _reference, ...siblingSchema } = jsonSchema;
|
|
212
|
-
const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
|
|
213
|
-
return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
|
|
214
|
-
...referenceContext,
|
|
215
|
-
resolvingReferences
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
function getReferencedDefinition(reference, referenceContext) {
|
|
219
|
-
const definitionSources = [
|
|
220
|
-
{
|
|
221
|
-
prefix: "#/$defs/",
|
|
222
|
-
definitions: referenceContext.dollarDefinitions
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
prefix: "#/definitions/",
|
|
226
|
-
definitions: referenceContext.definitions
|
|
227
|
-
}
|
|
228
|
-
];
|
|
229
|
-
const source = definitionSources.find(
|
|
230
|
-
({ prefix }) => reference.startsWith(prefix)
|
|
231
|
-
);
|
|
232
|
-
const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
|
|
233
|
-
if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
|
|
234
|
-
throwUnsupportedReference(reference);
|
|
235
|
-
}
|
|
236
|
-
let decodedDefinitionName;
|
|
237
|
-
try {
|
|
238
|
-
decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
|
|
239
|
-
} catch (e) {
|
|
240
|
-
throwUnsupportedReference(reference);
|
|
241
|
-
}
|
|
242
|
-
if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
|
|
243
|
-
throwUnsupportedReference(reference);
|
|
244
|
-
}
|
|
245
|
-
const definitionName = decodedDefinitionName.replace(
|
|
246
|
-
/~[01]/g,
|
|
247
|
-
(match) => match === "~1" ? "/" : "~"
|
|
248
|
-
);
|
|
249
|
-
if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
|
|
250
|
-
throwUnsupportedReference(reference);
|
|
251
|
-
}
|
|
252
|
-
return {
|
|
253
|
-
definition: source.definitions[definitionName],
|
|
254
|
-
referenceKey: `${source.prefix}${definitionName}`
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
function throwUnsupportedReference(reference) {
|
|
258
|
-
throw new UnsupportedFunctionalityError({
|
|
259
|
-
functionality: `JSON Schema reference: ${reference}`,
|
|
260
|
-
message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
function addEnumToSchema({
|
|
264
|
-
values,
|
|
265
|
-
type,
|
|
266
|
-
result
|
|
267
|
-
}) {
|
|
268
|
-
const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
|
|
269
|
-
const enumValues = nullable ? values.filter((value) => value !== null) : values;
|
|
270
|
-
if (values.length > 0 && values.every((value) => value === null)) {
|
|
271
|
-
const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
|
|
272
|
-
if (typeAllowsNull) {
|
|
273
|
-
result.type = "null";
|
|
274
|
-
if (Array.isArray(type)) {
|
|
275
|
-
delete result.anyOf;
|
|
276
|
-
}
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const enumType = getEnumType({ values: enumValues, type });
|
|
281
|
-
if (enumType === void 0) {
|
|
282
|
-
throw new UnsupportedFunctionalityError({
|
|
283
|
-
functionality: "JSON Schema enum with mixed or unsupported values",
|
|
284
|
-
message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
result.type = enumType;
|
|
288
|
-
if (Array.isArray(type)) {
|
|
289
|
-
delete result.anyOf;
|
|
290
|
-
}
|
|
291
|
-
if (nullable) {
|
|
292
|
-
result.nullable = true;
|
|
293
|
-
}
|
|
294
|
-
if (enumType === "string") {
|
|
295
|
-
result.enum = enumValues;
|
|
296
|
-
} else {
|
|
297
|
-
result.format = "enum";
|
|
298
|
-
result.enum = enumValues.map(String);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
function getEnumType({
|
|
302
|
-
values,
|
|
303
|
-
type
|
|
304
|
-
}) {
|
|
305
|
-
if (values.length === 0) {
|
|
306
|
-
return void 0;
|
|
307
|
-
}
|
|
308
|
-
const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
|
|
309
|
-
if (typeAllows("string") && values.every((value) => typeof value === "string")) {
|
|
310
|
-
return "string";
|
|
311
|
-
}
|
|
312
|
-
if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
313
|
-
if (typeAllows("number")) {
|
|
314
|
-
return "number";
|
|
315
|
-
}
|
|
316
|
-
if (values.every((value) => Number.isInteger(value))) {
|
|
317
|
-
return "integer";
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
|
|
321
|
-
return "boolean";
|
|
322
|
-
}
|
|
323
|
-
return void 0;
|
|
324
|
-
}
|
|
325
|
-
function isEmptyObjectSchema(jsonSchema) {
|
|
326
|
-
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
49
|
// src/convert-to-google-messages.ts
|
|
330
50
|
import {
|
|
331
|
-
UnsupportedFunctionalityError
|
|
51
|
+
UnsupportedFunctionalityError
|
|
332
52
|
} from "@ai-sdk/provider";
|
|
333
53
|
import {
|
|
334
54
|
convertToBase64,
|
|
@@ -485,7 +205,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
485
205
|
switch (role) {
|
|
486
206
|
case "system": {
|
|
487
207
|
if (!systemMessagesAllowed) {
|
|
488
|
-
throw new
|
|
208
|
+
throw new UnsupportedFunctionalityError({
|
|
489
209
|
functionality: "system messages are only supported at the beginning of the conversation"
|
|
490
210
|
});
|
|
491
211
|
}
|
|
@@ -514,7 +234,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
514
234
|
}
|
|
515
235
|
case "reference": {
|
|
516
236
|
if (isVertexLike) {
|
|
517
|
-
throw new
|
|
237
|
+
throw new UnsupportedFunctionalityError({
|
|
518
238
|
functionality: "file parts with provider references"
|
|
519
239
|
});
|
|
520
240
|
}
|
|
@@ -582,7 +302,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
582
302
|
case "reasoning-file": {
|
|
583
303
|
switch (part.data.type) {
|
|
584
304
|
case "url": {
|
|
585
|
-
throw new
|
|
305
|
+
throw new UnsupportedFunctionalityError({
|
|
586
306
|
functionality: "File data URLs in assistant messages are not supported"
|
|
587
307
|
});
|
|
588
308
|
}
|
|
@@ -602,13 +322,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
602
322
|
case "file": {
|
|
603
323
|
switch (part.data.type) {
|
|
604
324
|
case "url": {
|
|
605
|
-
throw new
|
|
325
|
+
throw new UnsupportedFunctionalityError({
|
|
606
326
|
functionality: "File data URLs in assistant messages are not supported"
|
|
607
327
|
});
|
|
608
328
|
}
|
|
609
329
|
case "reference": {
|
|
610
330
|
if (isVertexLike) {
|
|
611
|
-
throw new
|
|
331
|
+
throw new UnsupportedFunctionalityError({
|
|
612
332
|
functionality: "file parts with provider references"
|
|
613
333
|
});
|
|
614
334
|
}
|
|
@@ -787,6 +507,90 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
787
507
|
};
|
|
788
508
|
}
|
|
789
509
|
|
|
510
|
+
// src/download-tool-result-files.ts
|
|
511
|
+
import {
|
|
512
|
+
detectMediaType,
|
|
513
|
+
downloadBlob,
|
|
514
|
+
isFullMediaType as isFullMediaType2
|
|
515
|
+
} from "@ai-sdk/provider-utils";
|
|
516
|
+
async function downloadToolResultFiles(prompt, {
|
|
517
|
+
abortSignal,
|
|
518
|
+
maxBytes
|
|
519
|
+
}) {
|
|
520
|
+
const result = [];
|
|
521
|
+
for (const message of prompt) {
|
|
522
|
+
if (message.role === "assistant") {
|
|
523
|
+
const content = [];
|
|
524
|
+
for (const part of message.content) {
|
|
525
|
+
content.push(
|
|
526
|
+
part.type === "tool-result" ? {
|
|
527
|
+
...part,
|
|
528
|
+
output: await downloadToolResultOutput(part.output, {
|
|
529
|
+
abortSignal,
|
|
530
|
+
maxBytes
|
|
531
|
+
})
|
|
532
|
+
} : part
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
result.push({ ...message, content });
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
if (message.role === "tool") {
|
|
539
|
+
const content = [];
|
|
540
|
+
for (const part of message.content) {
|
|
541
|
+
if (part.type !== "tool-result") {
|
|
542
|
+
content.push(part);
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
content.push({
|
|
546
|
+
...part,
|
|
547
|
+
output: await downloadToolResultOutput(part.output, {
|
|
548
|
+
abortSignal,
|
|
549
|
+
maxBytes
|
|
550
|
+
})
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
result.push({ ...message, content });
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
result.push(message);
|
|
557
|
+
}
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
async function downloadToolResultOutput(output, {
|
|
561
|
+
abortSignal,
|
|
562
|
+
maxBytes
|
|
563
|
+
}) {
|
|
564
|
+
if (output.type !== "content") {
|
|
565
|
+
return output;
|
|
566
|
+
}
|
|
567
|
+
const value = [];
|
|
568
|
+
for (const part of output.value) {
|
|
569
|
+
if (part.type !== "file" || part.data.type !== "url") {
|
|
570
|
+
value.push(part);
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
const blob = await downloadBlob(part.data.url.toString(), {
|
|
574
|
+
abortSignal,
|
|
575
|
+
maxBytes
|
|
576
|
+
});
|
|
577
|
+
const data = new Uint8Array(await blob.arrayBuffer());
|
|
578
|
+
const detectedMediaType = detectMediaType({
|
|
579
|
+
data,
|
|
580
|
+
topLevelType: "image"
|
|
581
|
+
});
|
|
582
|
+
value.push({
|
|
583
|
+
...part,
|
|
584
|
+
data: { type: "data", data },
|
|
585
|
+
mediaType: detectedMediaType != null ? detectedMediaType : blob.type && !isFullMediaType2(part.mediaType) ? blob.type : part.mediaType
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
return {
|
|
589
|
+
...output,
|
|
590
|
+
value
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
790
594
|
// src/get-model-path.ts
|
|
791
595
|
function getModelPath(modelId) {
|
|
792
596
|
return modelId.includes("/") ? modelId : `models/${modelId}`;
|
|
@@ -816,6 +620,44 @@ var googleFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
816
620
|
errorToMessage: (data) => data.error.message
|
|
817
621
|
});
|
|
818
622
|
|
|
623
|
+
// src/sanitize-response-json-schema.ts
|
|
624
|
+
function sanitizeResponseJsonSchema(schema) {
|
|
625
|
+
const {
|
|
626
|
+
const: constValue,
|
|
627
|
+
properties,
|
|
628
|
+
items,
|
|
629
|
+
additionalProperties,
|
|
630
|
+
anyOf,
|
|
631
|
+
oneOf,
|
|
632
|
+
...result
|
|
633
|
+
} = schema;
|
|
634
|
+
return {
|
|
635
|
+
...result,
|
|
636
|
+
...constValue !== void 0 ? { enum: [constValue] } : {},
|
|
637
|
+
...properties != null ? { properties: sanitizeDefinitions(properties) } : {},
|
|
638
|
+
...items != null ? {
|
|
639
|
+
items: Array.isArray(items) ? items.map(sanitizeDefinition) : sanitizeDefinition(items)
|
|
640
|
+
} : {},
|
|
641
|
+
...additionalProperties != null ? {
|
|
642
|
+
additionalProperties: typeof additionalProperties === "boolean" ? additionalProperties : sanitizeDefinition(additionalProperties)
|
|
643
|
+
} : {},
|
|
644
|
+
...anyOf != null ? { anyOf: anyOf.map(sanitizeDefinition) } : {},
|
|
645
|
+
...oneOf != null ? { oneOf: oneOf.map(sanitizeDefinition) } : {},
|
|
646
|
+
...result.$defs != null ? { $defs: sanitizeDefinitions(result.$defs) } : {}
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
function sanitizeDefinitions(definitions) {
|
|
650
|
+
return Object.fromEntries(
|
|
651
|
+
Object.entries(definitions).map(([name, definition]) => [
|
|
652
|
+
name,
|
|
653
|
+
sanitizeDefinition(definition)
|
|
654
|
+
])
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
function sanitizeDefinition(definition) {
|
|
658
|
+
return typeof definition === "boolean" ? definition : sanitizeResponseJsonSchema(definition);
|
|
659
|
+
}
|
|
660
|
+
|
|
819
661
|
// src/google-language-model-options.ts
|
|
820
662
|
import {
|
|
821
663
|
lazySchema as lazySchema2,
|
|
@@ -1030,7 +872,7 @@ function getGoogleModelCapabilities(modelId) {
|
|
|
1030
872
|
|
|
1031
873
|
// src/google-prepare-tools.ts
|
|
1032
874
|
import {
|
|
1033
|
-
UnsupportedFunctionalityError as
|
|
875
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
1034
876
|
} from "@ai-sdk/provider";
|
|
1035
877
|
function prepareTools({
|
|
1036
878
|
tools,
|
|
@@ -1260,7 +1102,7 @@ function prepareTools({
|
|
|
1260
1102
|
};
|
|
1261
1103
|
default: {
|
|
1262
1104
|
const _exhaustiveCheck = type;
|
|
1263
|
-
throw new
|
|
1105
|
+
throw new UnsupportedFunctionalityError2({
|
|
1264
1106
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1265
1107
|
});
|
|
1266
1108
|
}
|
|
@@ -1268,24 +1110,11 @@ function prepareTools({
|
|
|
1268
1110
|
}
|
|
1269
1111
|
function prepareFunctionDeclaration(tool) {
|
|
1270
1112
|
var _a;
|
|
1271
|
-
|
|
1113
|
+
return {
|
|
1272
1114
|
name: tool.name,
|
|
1273
|
-
description: (_a = tool.description) != null ? _a : ""
|
|
1115
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
1116
|
+
parametersJsonSchema: tool.inputSchema
|
|
1274
1117
|
};
|
|
1275
|
-
try {
|
|
1276
|
-
return {
|
|
1277
|
-
...declaration,
|
|
1278
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1279
|
-
};
|
|
1280
|
-
} catch (error) {
|
|
1281
|
-
if (!isRecursiveJSONSchemaReferenceError(error)) {
|
|
1282
|
-
throw error;
|
|
1283
|
-
}
|
|
1284
|
-
return {
|
|
1285
|
-
...declaration,
|
|
1286
|
-
parametersJsonSchema: tool.inputSchema
|
|
1287
|
-
};
|
|
1288
|
-
}
|
|
1289
1118
|
}
|
|
1290
1119
|
|
|
1291
1120
|
// src/google-json-accumulator.ts
|
|
@@ -1604,7 +1433,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1604
1433
|
tools,
|
|
1605
1434
|
toolChoice,
|
|
1606
1435
|
reasoning,
|
|
1607
|
-
providerOptions
|
|
1436
|
+
providerOptions,
|
|
1437
|
+
abortSignal
|
|
1608
1438
|
},
|
|
1609
1439
|
isStreaming = false
|
|
1610
1440
|
}) {
|
|
@@ -1701,14 +1531,21 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1701
1531
|
});
|
|
1702
1532
|
}
|
|
1703
1533
|
const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
1704
|
-
const
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1534
|
+
const promptWithDownloadedToolResultFiles = config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
|
|
1535
|
+
abortSignal,
|
|
1536
|
+
maxBytes: config.downloadToolResultFiles.maxBytes
|
|
1537
|
+
}) : prompt;
|
|
1538
|
+
const { contents, systemInstruction } = convertToGoogleMessages(
|
|
1539
|
+
promptWithDownloadedToolResultFiles,
|
|
1540
|
+
{
|
|
1541
|
+
isGemmaModel,
|
|
1542
|
+
isGemini3Model: usesGemini3Features,
|
|
1543
|
+
onWarning: (warning) => warnings.push(warning),
|
|
1544
|
+
providerOptionsNames,
|
|
1545
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1546
|
+
includeFunctionCallIds: !isVertexProvider
|
|
1547
|
+
}
|
|
1548
|
+
);
|
|
1712
1549
|
const {
|
|
1713
1550
|
tools: googleTools2,
|
|
1714
1551
|
toolConfig: googleToolConfig,
|
|
@@ -1763,10 +1600,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1763
1600
|
seed,
|
|
1764
1601
|
// response format:
|
|
1765
1602
|
responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
|
|
1766
|
-
|
|
1767
|
-
// so this is needed as an escape hatch:
|
|
1603
|
+
responseJsonSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google does not support all JSON Schema features in
|
|
1604
|
+
// responseJsonSchema, so this is needed as an escape hatch:
|
|
1768
1605
|
// TODO convert into provider option
|
|
1769
|
-
((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ?
|
|
1606
|
+
((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ? sanitizeResponseJsonSchema(responseFormat.schema) : void 0,
|
|
1770
1607
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
|
1771
1608
|
audioTimestamp: googleOptions.audioTimestamp
|
|
1772
1609
|
},
|
|
@@ -4066,7 +3903,7 @@ function buildGoogleInteractionsStreamTransform({
|
|
|
4066
3903
|
import {
|
|
4067
3904
|
convertToBase64 as convertToBase642,
|
|
4068
3905
|
getTopLevelMediaType as getTopLevelMediaType2,
|
|
4069
|
-
isFullMediaType as
|
|
3906
|
+
isFullMediaType as isFullMediaType3,
|
|
4070
3907
|
resolveFullMediaType as resolveFullMediaType2,
|
|
4071
3908
|
resolveProviderReference as resolveProviderReference2,
|
|
4072
3909
|
secureJsonParse as secureJsonParse2
|
|
@@ -4275,7 +4112,7 @@ function convertFilePartToContent({
|
|
|
4275
4112
|
return {
|
|
4276
4113
|
type: kind,
|
|
4277
4114
|
uri: part.data.url.toString(),
|
|
4278
|
-
...
|
|
4115
|
+
...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {},
|
|
4279
4116
|
...resolutionField,
|
|
4280
4117
|
...processingField
|
|
4281
4118
|
};
|
|
@@ -4288,7 +4125,7 @@ function convertFilePartToContent({
|
|
|
4288
4125
|
return {
|
|
4289
4126
|
type: kind,
|
|
4290
4127
|
uri,
|
|
4291
|
-
...
|
|
4128
|
+
...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {},
|
|
4292
4129
|
...resolutionField,
|
|
4293
4130
|
...processingField
|
|
4294
4131
|
};
|
|
@@ -4443,7 +4280,7 @@ function filePartToImageBlock({
|
|
|
4443
4280
|
}) {
|
|
4444
4281
|
switch (part.data.type) {
|
|
4445
4282
|
case "data": {
|
|
4446
|
-
const mimeType =
|
|
4283
|
+
const mimeType = isFullMediaType3(part.mediaType) ? part.mediaType : resolveFullMediaType2({
|
|
4447
4284
|
part: {
|
|
4448
4285
|
type: "file",
|
|
4449
4286
|
mediaType: part.mediaType,
|
|
@@ -4460,7 +4297,7 @@ function filePartToImageBlock({
|
|
|
4460
4297
|
return {
|
|
4461
4298
|
type: "image",
|
|
4462
4299
|
uri: part.data.url.toString(),
|
|
4463
|
-
...
|
|
4300
|
+
...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {}
|
|
4464
4301
|
};
|
|
4465
4302
|
case "reference": {
|
|
4466
4303
|
const uri = resolveProviderReference2({
|
|
@@ -4470,7 +4307,7 @@ function filePartToImageBlock({
|
|
|
4470
4307
|
return {
|
|
4471
4308
|
type: "image",
|
|
4472
4309
|
uri,
|
|
4473
|
-
...
|
|
4310
|
+
...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {}
|
|
4474
4311
|
};
|
|
4475
4312
|
}
|
|
4476
4313
|
case "text": {
|