@ai-sdk/google 4.0.0-beta.17 → 4.0.0-beta.19
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 +12 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +225 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +225 -23
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +15 -0
- package/dist/internal/index.d.ts +15 -0
- package/dist/internal/index.js +224 -22
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +224 -22
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +6 -0
- package/package.json +1 -1
- package/src/convert-to-google-generative-ai-messages.ts +87 -0
- package/src/google-generative-ai-language-model.ts +127 -0
- package/src/google-generative-ai-options.ts +11 -0
- package/src/google-generative-ai-prompt.ts +18 -1
- package/src/google-prepare-tools.ts +57 -2
|
@@ -97,6 +97,20 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
97
97
|
};
|
|
98
98
|
thought?: boolean | null | undefined;
|
|
99
99
|
thoughtSignature?: string | null | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
toolCall: {
|
|
102
|
+
toolType: string;
|
|
103
|
+
id: string;
|
|
104
|
+
args?: unknown;
|
|
105
|
+
};
|
|
106
|
+
thoughtSignature?: string | null | undefined;
|
|
107
|
+
} | {
|
|
108
|
+
toolResponse: {
|
|
109
|
+
toolType: string;
|
|
110
|
+
id: string;
|
|
111
|
+
response?: unknown;
|
|
112
|
+
};
|
|
113
|
+
thoughtSignature?: string | null | undefined;
|
|
100
114
|
} | {
|
|
101
115
|
executableCode?: {
|
|
102
116
|
language: string;
|
|
@@ -194,6 +208,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
194
208
|
blocked?: boolean | null | undefined;
|
|
195
209
|
}[] | null | undefined;
|
|
196
210
|
} | null | undefined;
|
|
211
|
+
serviceTier?: string | null | undefined;
|
|
197
212
|
}>;
|
|
198
213
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
199
214
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -97,6 +97,20 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
97
97
|
};
|
|
98
98
|
thought?: boolean | null | undefined;
|
|
99
99
|
thoughtSignature?: string | null | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
toolCall: {
|
|
102
|
+
toolType: string;
|
|
103
|
+
id: string;
|
|
104
|
+
args?: unknown;
|
|
105
|
+
};
|
|
106
|
+
thoughtSignature?: string | null | undefined;
|
|
107
|
+
} | {
|
|
108
|
+
toolResponse: {
|
|
109
|
+
toolType: string;
|
|
110
|
+
id: string;
|
|
111
|
+
response?: unknown;
|
|
112
|
+
};
|
|
113
|
+
thoughtSignature?: string | null | undefined;
|
|
100
114
|
} | {
|
|
101
115
|
executableCode?: {
|
|
102
116
|
language: string;
|
|
@@ -194,6 +208,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
194
208
|
blocked?: boolean | null | undefined;
|
|
195
209
|
}[] | null | undefined;
|
|
196
210
|
} | null | undefined;
|
|
211
|
+
serviceTier?: string | null | undefined;
|
|
197
212
|
}>;
|
|
198
213
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
199
214
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
package/dist/internal/index.js
CHANGED
|
@@ -294,7 +294,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
297
|
-
var _a, _b, _c, _d;
|
|
297
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
298
298
|
const systemInstructionParts = [];
|
|
299
299
|
const contents = [];
|
|
300
300
|
let systemMessagesAllowed = true;
|
|
@@ -396,6 +396,18 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
396
396
|
};
|
|
397
397
|
}
|
|
398
398
|
case "tool-call": {
|
|
399
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
400
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
401
|
+
if (serverToolCallId && serverToolType) {
|
|
402
|
+
return {
|
|
403
|
+
toolCall: {
|
|
404
|
+
toolType: serverToolType,
|
|
405
|
+
args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
|
|
406
|
+
id: serverToolCallId
|
|
407
|
+
},
|
|
408
|
+
thoughtSignature
|
|
409
|
+
};
|
|
410
|
+
}
|
|
399
411
|
return {
|
|
400
412
|
functionCall: {
|
|
401
413
|
name: part.toolName,
|
|
@@ -404,6 +416,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
404
416
|
thoughtSignature
|
|
405
417
|
};
|
|
406
418
|
}
|
|
419
|
+
case "tool-result": {
|
|
420
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
421
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
422
|
+
if (serverToolCallId && serverToolType) {
|
|
423
|
+
return {
|
|
424
|
+
toolResponse: {
|
|
425
|
+
toolType: serverToolType,
|
|
426
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
427
|
+
id: serverToolCallId
|
|
428
|
+
},
|
|
429
|
+
thoughtSignature
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
return void 0;
|
|
433
|
+
}
|
|
407
434
|
}
|
|
408
435
|
}).filter((part) => part !== void 0)
|
|
409
436
|
});
|
|
@@ -416,6 +443,26 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
416
443
|
if (part.type === "tool-approval-response") {
|
|
417
444
|
continue;
|
|
418
445
|
}
|
|
446
|
+
const partProviderOpts = (_g = (_d = part.providerOptions) == null ? void 0 : _d[providerOptionsName]) != null ? _g : providerOptionsName !== "google" ? (_e = part.providerOptions) == null ? void 0 : _e.google : (_f = part.providerOptions) == null ? void 0 : _f.vertex;
|
|
447
|
+
const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
448
|
+
const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
449
|
+
if (serverToolCallId && serverToolType) {
|
|
450
|
+
const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
451
|
+
if (contents.length > 0) {
|
|
452
|
+
const lastContent = contents[contents.length - 1];
|
|
453
|
+
if (lastContent.role === "model") {
|
|
454
|
+
lastContent.parts.push({
|
|
455
|
+
toolResponse: {
|
|
456
|
+
toolType: serverToolType,
|
|
457
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
458
|
+
id: serverToolCallId
|
|
459
|
+
},
|
|
460
|
+
thoughtSignature: serverThoughtSignature
|
|
461
|
+
});
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
419
466
|
const output = part.output;
|
|
420
467
|
if (output.type === "content") {
|
|
421
468
|
if (supportsFunctionResponseParts) {
|
|
@@ -429,7 +476,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
429
476
|
name: part.toolName,
|
|
430
477
|
response: {
|
|
431
478
|
name: part.toolName,
|
|
432
|
-
content: output.type === "execution-denied" ? (
|
|
479
|
+
content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
|
|
433
480
|
}
|
|
434
481
|
}
|
|
435
482
|
});
|
|
@@ -594,7 +641,15 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
594
641
|
latitude: import_v42.z.number(),
|
|
595
642
|
longitude: import_v42.z.number()
|
|
596
643
|
}).optional()
|
|
597
|
-
}).optional()
|
|
644
|
+
}).optional(),
|
|
645
|
+
/**
|
|
646
|
+
* Optional. The service tier to use for the request.
|
|
647
|
+
*/
|
|
648
|
+
serviceTier: import_v42.z.enum([
|
|
649
|
+
"SERVICE_TIER_STANDARD",
|
|
650
|
+
"SERVICE_TIER_FLEX",
|
|
651
|
+
"SERVICE_TIER_PRIORITY"
|
|
652
|
+
]).optional()
|
|
598
653
|
})
|
|
599
654
|
)
|
|
600
655
|
);
|
|
@@ -606,7 +661,7 @@ function prepareTools({
|
|
|
606
661
|
toolChoice,
|
|
607
662
|
modelId
|
|
608
663
|
}) {
|
|
609
|
-
var _a;
|
|
664
|
+
var _a, _b;
|
|
610
665
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
611
666
|
const toolWarnings = [];
|
|
612
667
|
const isLatest = [
|
|
@@ -615,13 +670,14 @@ function prepareTools({
|
|
|
615
670
|
"gemini-pro-latest"
|
|
616
671
|
].some((id) => id === modelId);
|
|
617
672
|
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
673
|
+
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
618
674
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
619
675
|
if (tools == null) {
|
|
620
676
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
621
677
|
}
|
|
622
678
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
623
679
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
624
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
680
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
625
681
|
toolWarnings.push({
|
|
626
682
|
type: "unsupported",
|
|
627
683
|
feature: `combination of function and provider-defined tools`
|
|
@@ -726,6 +782,45 @@ function prepareTools({
|
|
|
726
782
|
break;
|
|
727
783
|
}
|
|
728
784
|
});
|
|
785
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
|
|
786
|
+
const functionDeclarations2 = [];
|
|
787
|
+
for (const tool of tools) {
|
|
788
|
+
if (tool.type === "function") {
|
|
789
|
+
functionDeclarations2.push({
|
|
790
|
+
name: tool.name,
|
|
791
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
792
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
const combinedToolConfig = {
|
|
797
|
+
functionCallingConfig: { mode: "VALIDATED" },
|
|
798
|
+
includeServerSideToolInvocations: true
|
|
799
|
+
};
|
|
800
|
+
if (toolChoice != null) {
|
|
801
|
+
switch (toolChoice.type) {
|
|
802
|
+
case "auto":
|
|
803
|
+
break;
|
|
804
|
+
case "none":
|
|
805
|
+
combinedToolConfig.functionCallingConfig = { mode: "NONE" };
|
|
806
|
+
break;
|
|
807
|
+
case "required":
|
|
808
|
+
combinedToolConfig.functionCallingConfig = { mode: "ANY" };
|
|
809
|
+
break;
|
|
810
|
+
case "tool":
|
|
811
|
+
combinedToolConfig.functionCallingConfig = {
|
|
812
|
+
mode: "ANY",
|
|
813
|
+
allowedFunctionNames: [toolChoice.toolName]
|
|
814
|
+
};
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return {
|
|
819
|
+
tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
|
|
820
|
+
toolConfig: combinedToolConfig,
|
|
821
|
+
toolWarnings
|
|
822
|
+
};
|
|
823
|
+
}
|
|
729
824
|
return {
|
|
730
825
|
tools: googleTools2.length > 0 ? googleTools2 : void 0,
|
|
731
826
|
toolConfig: void 0,
|
|
@@ -739,7 +834,7 @@ function prepareTools({
|
|
|
739
834
|
case "function":
|
|
740
835
|
functionDeclarations.push({
|
|
741
836
|
name: tool.name,
|
|
742
|
-
description: (
|
|
837
|
+
description: (_b = tool.description) != null ? _b : "",
|
|
743
838
|
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
744
839
|
});
|
|
745
840
|
if (tool.strict === true) {
|
|
@@ -955,14 +1050,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
955
1050
|
retrievalConfig: googleOptions.retrievalConfig
|
|
956
1051
|
} : googleToolConfig,
|
|
957
1052
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
958
|
-
labels: googleOptions == null ? void 0 : googleOptions.labels
|
|
1053
|
+
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1054
|
+
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
959
1055
|
},
|
|
960
1056
|
warnings: [...warnings, ...toolWarnings],
|
|
961
1057
|
providerOptionsName
|
|
962
1058
|
};
|
|
963
1059
|
}
|
|
964
1060
|
async doGenerate(options) {
|
|
965
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1061
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
966
1062
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
967
1063
|
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
|
968
1064
|
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
@@ -988,6 +1084,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
988
1084
|
const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
989
1085
|
const usageMetadata = response.usageMetadata;
|
|
990
1086
|
let lastCodeExecutionToolCallId;
|
|
1087
|
+
let lastServerToolCallId;
|
|
991
1088
|
for (const part of parts) {
|
|
992
1089
|
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
993
1090
|
const toolCallId = this.config.generateId();
|
|
@@ -1054,12 +1151,56 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1054
1151
|
}
|
|
1055
1152
|
} : void 0
|
|
1056
1153
|
});
|
|
1154
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1155
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
|
|
1156
|
+
lastServerToolCallId = toolCallId;
|
|
1157
|
+
content.push({
|
|
1158
|
+
type: "tool-call",
|
|
1159
|
+
toolCallId,
|
|
1160
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1161
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1162
|
+
providerExecuted: true,
|
|
1163
|
+
dynamic: true,
|
|
1164
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1165
|
+
[providerOptionsName]: {
|
|
1166
|
+
thoughtSignature: part.thoughtSignature,
|
|
1167
|
+
serverToolCallId: toolCallId,
|
|
1168
|
+
serverToolType: part.toolCall.toolType
|
|
1169
|
+
}
|
|
1170
|
+
} : {
|
|
1171
|
+
[providerOptionsName]: {
|
|
1172
|
+
serverToolCallId: toolCallId,
|
|
1173
|
+
serverToolType: part.toolCall.toolType
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1178
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
|
|
1179
|
+
content.push({
|
|
1180
|
+
type: "tool-result",
|
|
1181
|
+
toolCallId: responseToolCallId,
|
|
1182
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1183
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1184
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1185
|
+
[providerOptionsName]: {
|
|
1186
|
+
thoughtSignature: part.thoughtSignature,
|
|
1187
|
+
serverToolCallId: responseToolCallId,
|
|
1188
|
+
serverToolType: part.toolResponse.toolType
|
|
1189
|
+
}
|
|
1190
|
+
} : {
|
|
1191
|
+
[providerOptionsName]: {
|
|
1192
|
+
serverToolCallId: responseToolCallId,
|
|
1193
|
+
serverToolType: part.toolResponse.toolType
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
lastServerToolCallId = void 0;
|
|
1057
1198
|
}
|
|
1058
1199
|
}
|
|
1059
|
-
const sources = (
|
|
1200
|
+
const sources = (_i = extractSources({
|
|
1060
1201
|
groundingMetadata: candidate.groundingMetadata,
|
|
1061
1202
|
generateId: this.config.generateId
|
|
1062
|
-
})) != null ?
|
|
1203
|
+
})) != null ? _i : [];
|
|
1063
1204
|
for (const source of sources) {
|
|
1064
1205
|
content.push(source);
|
|
1065
1206
|
}
|
|
@@ -1073,18 +1214,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1073
1214
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1074
1215
|
)
|
|
1075
1216
|
}),
|
|
1076
|
-
raw: (
|
|
1217
|
+
raw: (_j = candidate.finishReason) != null ? _j : void 0
|
|
1077
1218
|
},
|
|
1078
1219
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1079
1220
|
warnings,
|
|
1080
1221
|
providerMetadata: {
|
|
1081
1222
|
[providerOptionsName]: {
|
|
1082
|
-
promptFeedback: (
|
|
1083
|
-
groundingMetadata: (
|
|
1084
|
-
urlContextMetadata: (
|
|
1085
|
-
safetyRatings: (
|
|
1223
|
+
promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
|
|
1224
|
+
groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
|
|
1225
|
+
urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
|
|
1226
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1086
1227
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1087
|
-
finishMessage: (
|
|
1228
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1229
|
+
serviceTier: (_p = response.serviceTier) != null ? _p : null
|
|
1088
1230
|
}
|
|
1089
1231
|
},
|
|
1090
1232
|
request: { body: args },
|
|
@@ -1120,6 +1262,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1120
1262
|
let providerMetadata = void 0;
|
|
1121
1263
|
let lastGroundingMetadata = null;
|
|
1122
1264
|
let lastUrlContextMetadata = null;
|
|
1265
|
+
let serviceTier = null;
|
|
1123
1266
|
const generateId2 = this.config.generateId;
|
|
1124
1267
|
let hasToolCalls = false;
|
|
1125
1268
|
let currentTextBlockId = null;
|
|
@@ -1127,6 +1270,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1127
1270
|
let blockCounter = 0;
|
|
1128
1271
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1129
1272
|
let lastCodeExecutionToolCallId;
|
|
1273
|
+
let lastServerToolCallId;
|
|
1130
1274
|
return {
|
|
1131
1275
|
stream: response.pipeThrough(
|
|
1132
1276
|
new TransformStream({
|
|
@@ -1134,7 +1278,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1134
1278
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1135
1279
|
},
|
|
1136
1280
|
transform(chunk, controller) {
|
|
1137
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1281
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1138
1282
|
if (options.includeRawChunks) {
|
|
1139
1283
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1140
1284
|
}
|
|
@@ -1147,6 +1291,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1147
1291
|
if (usageMetadata != null) {
|
|
1148
1292
|
usage = usageMetadata;
|
|
1149
1293
|
}
|
|
1294
|
+
if (value.serviceTier != null) {
|
|
1295
|
+
serviceTier = value.serviceTier;
|
|
1296
|
+
}
|
|
1150
1297
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1151
1298
|
if (candidate == null) {
|
|
1152
1299
|
return;
|
|
@@ -1285,6 +1432,42 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1285
1432
|
data: part.inlineData.data,
|
|
1286
1433
|
providerMetadata: fileMeta
|
|
1287
1434
|
});
|
|
1435
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1436
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
|
|
1437
|
+
lastServerToolCallId = toolCallId;
|
|
1438
|
+
const serverMeta = {
|
|
1439
|
+
[providerOptionsName]: {
|
|
1440
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1441
|
+
serverToolCallId: toolCallId,
|
|
1442
|
+
serverToolType: part.toolCall.toolType
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
controller.enqueue({
|
|
1446
|
+
type: "tool-call",
|
|
1447
|
+
toolCallId,
|
|
1448
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1449
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1450
|
+
providerExecuted: true,
|
|
1451
|
+
dynamic: true,
|
|
1452
|
+
providerMetadata: serverMeta
|
|
1453
|
+
});
|
|
1454
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1455
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
|
|
1456
|
+
const serverMeta = {
|
|
1457
|
+
[providerOptionsName]: {
|
|
1458
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1459
|
+
serverToolCallId: responseToolCallId,
|
|
1460
|
+
serverToolType: part.toolResponse.toolType
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
controller.enqueue({
|
|
1464
|
+
type: "tool-result",
|
|
1465
|
+
toolCallId: responseToolCallId,
|
|
1466
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1467
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1468
|
+
providerMetadata: serverMeta
|
|
1469
|
+
});
|
|
1470
|
+
lastServerToolCallId = void 0;
|
|
1288
1471
|
}
|
|
1289
1472
|
}
|
|
1290
1473
|
const toolCallDeltas = getToolCallsFromParts({
|
|
@@ -1332,12 +1515,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1332
1515
|
};
|
|
1333
1516
|
providerMetadata = {
|
|
1334
1517
|
[providerOptionsName]: {
|
|
1335
|
-
promptFeedback: (
|
|
1518
|
+
promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
|
|
1336
1519
|
groundingMetadata: lastGroundingMetadata,
|
|
1337
1520
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1338
|
-
safetyRatings: (
|
|
1521
|
+
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
|
1339
1522
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1340
|
-
finishMessage: (
|
|
1523
|
+
finishMessage: (_k = candidate.finishMessage) != null ? _k : null,
|
|
1524
|
+
serviceTier
|
|
1341
1525
|
}
|
|
1342
1526
|
};
|
|
1343
1527
|
}
|
|
@@ -1620,6 +1804,22 @@ var getContentSchema = () => import_v43.z.object({
|
|
|
1620
1804
|
thought: import_v43.z.boolean().nullish(),
|
|
1621
1805
|
thoughtSignature: import_v43.z.string().nullish()
|
|
1622
1806
|
}),
|
|
1807
|
+
import_v43.z.object({
|
|
1808
|
+
toolCall: import_v43.z.object({
|
|
1809
|
+
toolType: import_v43.z.string(),
|
|
1810
|
+
args: import_v43.z.unknown().nullish(),
|
|
1811
|
+
id: import_v43.z.string()
|
|
1812
|
+
}),
|
|
1813
|
+
thoughtSignature: import_v43.z.string().nullish()
|
|
1814
|
+
}),
|
|
1815
|
+
import_v43.z.object({
|
|
1816
|
+
toolResponse: import_v43.z.object({
|
|
1817
|
+
toolType: import_v43.z.string(),
|
|
1818
|
+
response: import_v43.z.unknown().nullish(),
|
|
1819
|
+
id: import_v43.z.string()
|
|
1820
|
+
}),
|
|
1821
|
+
thoughtSignature: import_v43.z.string().nullish()
|
|
1822
|
+
}),
|
|
1623
1823
|
import_v43.z.object({
|
|
1624
1824
|
executableCode: import_v43.z.object({
|
|
1625
1825
|
language: import_v43.z.string(),
|
|
@@ -1678,7 +1878,8 @@ var responseSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
1678
1878
|
promptFeedback: import_v43.z.object({
|
|
1679
1879
|
blockReason: import_v43.z.string().nullish(),
|
|
1680
1880
|
safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
|
|
1681
|
-
}).nullish()
|
|
1881
|
+
}).nullish(),
|
|
1882
|
+
serviceTier: import_v43.z.string().nullish()
|
|
1682
1883
|
})
|
|
1683
1884
|
)
|
|
1684
1885
|
);
|
|
@@ -1699,7 +1900,8 @@ var chunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
1699
1900
|
promptFeedback: import_v43.z.object({
|
|
1700
1901
|
blockReason: import_v43.z.string().nullish(),
|
|
1701
1902
|
safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
|
|
1702
|
-
}).nullish()
|
|
1903
|
+
}).nullish(),
|
|
1904
|
+
serviceTier: import_v43.z.string().nullish()
|
|
1703
1905
|
})
|
|
1704
1906
|
)
|
|
1705
1907
|
);
|