@ai-sdk/google 3.0.53 → 3.0.55
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 +5 -5
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.55
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bdde9d4: feat(provider/google): support combining built-in tools with function calling on Gemini 3
|
|
8
|
+
|
|
9
|
+
## 3.0.54
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 4e22c2c: feat(provider/google): add support for service tier parameter
|
|
14
|
+
|
|
3
15
|
## 3.0.53
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -39,6 +39,7 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
39
39
|
longitude: number;
|
|
40
40
|
} | undefined;
|
|
41
41
|
} | undefined;
|
|
42
|
+
serviceTier?: "SERVICE_TIER_STANDARD" | "SERVICE_TIER_FLEX" | "SERVICE_TIER_PRIORITY" | undefined;
|
|
42
43
|
}>;
|
|
43
44
|
type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
|
|
44
45
|
|
|
@@ -58,6 +59,20 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
58
59
|
};
|
|
59
60
|
thought?: boolean | null | undefined;
|
|
60
61
|
thoughtSignature?: string | null | undefined;
|
|
62
|
+
} | {
|
|
63
|
+
toolCall: {
|
|
64
|
+
toolType: string;
|
|
65
|
+
id: string;
|
|
66
|
+
args?: unknown;
|
|
67
|
+
};
|
|
68
|
+
thoughtSignature?: string | null | undefined;
|
|
69
|
+
} | {
|
|
70
|
+
toolResponse: {
|
|
71
|
+
toolType: string;
|
|
72
|
+
id: string;
|
|
73
|
+
response?: unknown;
|
|
74
|
+
};
|
|
75
|
+
thoughtSignature?: string | null | undefined;
|
|
61
76
|
} | {
|
|
62
77
|
executableCode?: {
|
|
63
78
|
language: string;
|
|
@@ -155,6 +170,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
155
170
|
blocked?: boolean | null | undefined;
|
|
156
171
|
}[] | null | undefined;
|
|
157
172
|
} | null | undefined;
|
|
173
|
+
serviceTier?: string | null | undefined;
|
|
158
174
|
}>;
|
|
159
175
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
160
176
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
@@ -174,6 +190,7 @@ interface GoogleGenerativeAIProviderMetadata {
|
|
|
174
190
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
175
191
|
usageMetadata: GoogleGenerativeAIUsageMetadata | null;
|
|
176
192
|
finishMessage: string | null;
|
|
193
|
+
serviceTier: string | null;
|
|
177
194
|
}
|
|
178
195
|
|
|
179
196
|
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
|
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ declare const googleLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
39
39
|
longitude: number;
|
|
40
40
|
} | undefined;
|
|
41
41
|
} | undefined;
|
|
42
|
+
serviceTier?: "SERVICE_TIER_STANDARD" | "SERVICE_TIER_FLEX" | "SERVICE_TIER_PRIORITY" | undefined;
|
|
42
43
|
}>;
|
|
43
44
|
type GoogleLanguageModelOptions = InferSchema<typeof googleLanguageModelOptions>;
|
|
44
45
|
|
|
@@ -58,6 +59,20 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
58
59
|
};
|
|
59
60
|
thought?: boolean | null | undefined;
|
|
60
61
|
thoughtSignature?: string | null | undefined;
|
|
62
|
+
} | {
|
|
63
|
+
toolCall: {
|
|
64
|
+
toolType: string;
|
|
65
|
+
id: string;
|
|
66
|
+
args?: unknown;
|
|
67
|
+
};
|
|
68
|
+
thoughtSignature?: string | null | undefined;
|
|
69
|
+
} | {
|
|
70
|
+
toolResponse: {
|
|
71
|
+
toolType: string;
|
|
72
|
+
id: string;
|
|
73
|
+
response?: unknown;
|
|
74
|
+
};
|
|
75
|
+
thoughtSignature?: string | null | undefined;
|
|
61
76
|
} | {
|
|
62
77
|
executableCode?: {
|
|
63
78
|
language: string;
|
|
@@ -155,6 +170,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
155
170
|
blocked?: boolean | null | undefined;
|
|
156
171
|
}[] | null | undefined;
|
|
157
172
|
} | null | undefined;
|
|
173
|
+
serviceTier?: string | null | undefined;
|
|
158
174
|
}>;
|
|
159
175
|
type GroundingMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['groundingMetadata']>;
|
|
160
176
|
type UrlContextMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['candidates'][number]['urlContextMetadata']>;
|
|
@@ -174,6 +190,7 @@ interface GoogleGenerativeAIProviderMetadata {
|
|
|
174
190
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
175
191
|
usageMetadata: GoogleGenerativeAIUsageMetadata | null;
|
|
176
192
|
finishMessage: string | null;
|
|
193
|
+
serviceTier: string | null;
|
|
177
194
|
}
|
|
178
195
|
|
|
179
196
|
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.55" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -505,7 +505,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
|
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
508
|
-
var _a, _b, _c, _d;
|
|
508
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
509
509
|
const systemInstructionParts = [];
|
|
510
510
|
const contents = [];
|
|
511
511
|
let systemMessagesAllowed = true;
|
|
@@ -592,6 +592,18 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
592
592
|
};
|
|
593
593
|
}
|
|
594
594
|
case "tool-call": {
|
|
595
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
596
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
597
|
+
if (serverToolCallId && serverToolType) {
|
|
598
|
+
return {
|
|
599
|
+
toolCall: {
|
|
600
|
+
toolType: serverToolType,
|
|
601
|
+
args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
|
|
602
|
+
id: serverToolCallId
|
|
603
|
+
},
|
|
604
|
+
thoughtSignature
|
|
605
|
+
};
|
|
606
|
+
}
|
|
595
607
|
return {
|
|
596
608
|
functionCall: {
|
|
597
609
|
name: part.toolName,
|
|
@@ -600,6 +612,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
600
612
|
thoughtSignature
|
|
601
613
|
};
|
|
602
614
|
}
|
|
615
|
+
case "tool-result": {
|
|
616
|
+
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
617
|
+
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
618
|
+
if (serverToolCallId && serverToolType) {
|
|
619
|
+
return {
|
|
620
|
+
toolResponse: {
|
|
621
|
+
toolType: serverToolType,
|
|
622
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
623
|
+
id: serverToolCallId
|
|
624
|
+
},
|
|
625
|
+
thoughtSignature
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
return void 0;
|
|
629
|
+
}
|
|
603
630
|
}
|
|
604
631
|
}).filter((part) => part !== void 0)
|
|
605
632
|
});
|
|
@@ -612,6 +639,26 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
612
639
|
if (part.type === "tool-approval-response") {
|
|
613
640
|
continue;
|
|
614
641
|
}
|
|
642
|
+
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;
|
|
643
|
+
const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
|
|
644
|
+
const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
|
|
645
|
+
if (serverToolCallId && serverToolType) {
|
|
646
|
+
const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
|
|
647
|
+
if (contents.length > 0) {
|
|
648
|
+
const lastContent = contents[contents.length - 1];
|
|
649
|
+
if (lastContent.role === "model") {
|
|
650
|
+
lastContent.parts.push({
|
|
651
|
+
toolResponse: {
|
|
652
|
+
toolType: serverToolType,
|
|
653
|
+
response: part.output.type === "json" ? part.output.value : {},
|
|
654
|
+
id: serverToolCallId
|
|
655
|
+
},
|
|
656
|
+
thoughtSignature: serverThoughtSignature
|
|
657
|
+
});
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
615
662
|
const output = part.output;
|
|
616
663
|
if (output.type === "content") {
|
|
617
664
|
if (supportsFunctionResponseParts) {
|
|
@@ -625,7 +672,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
625
672
|
name: part.toolName,
|
|
626
673
|
response: {
|
|
627
674
|
name: part.toolName,
|
|
628
|
-
content: output.type === "execution-denied" ? (
|
|
675
|
+
content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
|
|
629
676
|
}
|
|
630
677
|
}
|
|
631
678
|
});
|
|
@@ -771,7 +818,15 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
771
818
|
latitude: import_v44.z.number(),
|
|
772
819
|
longitude: import_v44.z.number()
|
|
773
820
|
}).optional()
|
|
774
|
-
}).optional()
|
|
821
|
+
}).optional(),
|
|
822
|
+
/**
|
|
823
|
+
* Optional. The service tier to use for the request.
|
|
824
|
+
*/
|
|
825
|
+
serviceTier: import_v44.z.enum([
|
|
826
|
+
"SERVICE_TIER_STANDARD",
|
|
827
|
+
"SERVICE_TIER_FLEX",
|
|
828
|
+
"SERVICE_TIER_PRIORITY"
|
|
829
|
+
]).optional()
|
|
775
830
|
})
|
|
776
831
|
)
|
|
777
832
|
);
|
|
@@ -783,7 +838,7 @@ function prepareTools({
|
|
|
783
838
|
toolChoice,
|
|
784
839
|
modelId
|
|
785
840
|
}) {
|
|
786
|
-
var _a;
|
|
841
|
+
var _a, _b;
|
|
787
842
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
788
843
|
const toolWarnings = [];
|
|
789
844
|
const isLatest = [
|
|
@@ -792,13 +847,14 @@ function prepareTools({
|
|
|
792
847
|
"gemini-pro-latest"
|
|
793
848
|
].some((id) => id === modelId);
|
|
794
849
|
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
850
|
+
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
795
851
|
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
796
852
|
if (tools == null) {
|
|
797
853
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
798
854
|
}
|
|
799
855
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
800
856
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
801
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
857
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
802
858
|
toolWarnings.push({
|
|
803
859
|
type: "unsupported",
|
|
804
860
|
feature: `combination of function and provider-defined tools`
|
|
@@ -903,6 +959,45 @@ function prepareTools({
|
|
|
903
959
|
break;
|
|
904
960
|
}
|
|
905
961
|
});
|
|
962
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
|
|
963
|
+
const functionDeclarations2 = [];
|
|
964
|
+
for (const tool of tools) {
|
|
965
|
+
if (tool.type === "function") {
|
|
966
|
+
functionDeclarations2.push({
|
|
967
|
+
name: tool.name,
|
|
968
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
969
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
const combinedToolConfig = {
|
|
974
|
+
functionCallingConfig: { mode: "VALIDATED" },
|
|
975
|
+
includeServerSideToolInvocations: true
|
|
976
|
+
};
|
|
977
|
+
if (toolChoice != null) {
|
|
978
|
+
switch (toolChoice.type) {
|
|
979
|
+
case "auto":
|
|
980
|
+
break;
|
|
981
|
+
case "none":
|
|
982
|
+
combinedToolConfig.functionCallingConfig = { mode: "NONE" };
|
|
983
|
+
break;
|
|
984
|
+
case "required":
|
|
985
|
+
combinedToolConfig.functionCallingConfig = { mode: "ANY" };
|
|
986
|
+
break;
|
|
987
|
+
case "tool":
|
|
988
|
+
combinedToolConfig.functionCallingConfig = {
|
|
989
|
+
mode: "ANY",
|
|
990
|
+
allowedFunctionNames: [toolChoice.toolName]
|
|
991
|
+
};
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return {
|
|
996
|
+
tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
|
|
997
|
+
toolConfig: combinedToolConfig,
|
|
998
|
+
toolWarnings
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
906
1001
|
return {
|
|
907
1002
|
tools: googleTools2.length > 0 ? googleTools2 : void 0,
|
|
908
1003
|
toolConfig: void 0,
|
|
@@ -916,7 +1011,7 @@ function prepareTools({
|
|
|
916
1011
|
case "function":
|
|
917
1012
|
functionDeclarations.push({
|
|
918
1013
|
name: tool.name,
|
|
919
|
-
description: (
|
|
1014
|
+
description: (_b = tool.description) != null ? _b : "",
|
|
920
1015
|
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
921
1016
|
});
|
|
922
1017
|
if (tool.strict === true) {
|
|
@@ -1125,14 +1220,15 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1125
1220
|
retrievalConfig: googleOptions.retrievalConfig
|
|
1126
1221
|
} : googleToolConfig,
|
|
1127
1222
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
|
|
1128
|
-
labels: googleOptions == null ? void 0 : googleOptions.labels
|
|
1223
|
+
labels: googleOptions == null ? void 0 : googleOptions.labels,
|
|
1224
|
+
serviceTier: googleOptions == null ? void 0 : googleOptions.serviceTier
|
|
1129
1225
|
},
|
|
1130
1226
|
warnings: [...warnings, ...toolWarnings],
|
|
1131
1227
|
providerOptionsName
|
|
1132
1228
|
};
|
|
1133
1229
|
}
|
|
1134
1230
|
async doGenerate(options) {
|
|
1135
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1231
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1136
1232
|
const { args, warnings, providerOptionsName } = await this.getArgs(options);
|
|
1137
1233
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
|
1138
1234
|
await (0, import_provider_utils6.resolve)(this.config.headers),
|
|
@@ -1158,6 +1254,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1158
1254
|
const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
1159
1255
|
const usageMetadata = response.usageMetadata;
|
|
1160
1256
|
let lastCodeExecutionToolCallId;
|
|
1257
|
+
let lastServerToolCallId;
|
|
1161
1258
|
for (const part of parts) {
|
|
1162
1259
|
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
|
1163
1260
|
const toolCallId = this.config.generateId();
|
|
@@ -1225,12 +1322,56 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1225
1322
|
}
|
|
1226
1323
|
} : void 0
|
|
1227
1324
|
});
|
|
1325
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1326
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
|
|
1327
|
+
lastServerToolCallId = toolCallId;
|
|
1328
|
+
content.push({
|
|
1329
|
+
type: "tool-call",
|
|
1330
|
+
toolCallId,
|
|
1331
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1332
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1333
|
+
providerExecuted: true,
|
|
1334
|
+
dynamic: true,
|
|
1335
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1336
|
+
[providerOptionsName]: {
|
|
1337
|
+
thoughtSignature: part.thoughtSignature,
|
|
1338
|
+
serverToolCallId: toolCallId,
|
|
1339
|
+
serverToolType: part.toolCall.toolType
|
|
1340
|
+
}
|
|
1341
|
+
} : {
|
|
1342
|
+
[providerOptionsName]: {
|
|
1343
|
+
serverToolCallId: toolCallId,
|
|
1344
|
+
serverToolType: part.toolCall.toolType
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1349
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
|
|
1350
|
+
content.push({
|
|
1351
|
+
type: "tool-result",
|
|
1352
|
+
toolCallId: responseToolCallId,
|
|
1353
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1354
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1355
|
+
providerMetadata: part.thoughtSignature ? {
|
|
1356
|
+
[providerOptionsName]: {
|
|
1357
|
+
thoughtSignature: part.thoughtSignature,
|
|
1358
|
+
serverToolCallId: responseToolCallId,
|
|
1359
|
+
serverToolType: part.toolResponse.toolType
|
|
1360
|
+
}
|
|
1361
|
+
} : {
|
|
1362
|
+
[providerOptionsName]: {
|
|
1363
|
+
serverToolCallId: responseToolCallId,
|
|
1364
|
+
serverToolType: part.toolResponse.toolType
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
lastServerToolCallId = void 0;
|
|
1228
1369
|
}
|
|
1229
1370
|
}
|
|
1230
|
-
const sources = (
|
|
1371
|
+
const sources = (_i = extractSources({
|
|
1231
1372
|
groundingMetadata: candidate.groundingMetadata,
|
|
1232
1373
|
generateId: this.config.generateId
|
|
1233
|
-
})) != null ?
|
|
1374
|
+
})) != null ? _i : [];
|
|
1234
1375
|
for (const source of sources) {
|
|
1235
1376
|
content.push(source);
|
|
1236
1377
|
}
|
|
@@ -1244,18 +1385,19 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1244
1385
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1245
1386
|
)
|
|
1246
1387
|
}),
|
|
1247
|
-
raw: (
|
|
1388
|
+
raw: (_j = candidate.finishReason) != null ? _j : void 0
|
|
1248
1389
|
},
|
|
1249
1390
|
usage: convertGoogleGenerativeAIUsage(usageMetadata),
|
|
1250
1391
|
warnings,
|
|
1251
1392
|
providerMetadata: {
|
|
1252
1393
|
[providerOptionsName]: {
|
|
1253
|
-
promptFeedback: (
|
|
1254
|
-
groundingMetadata: (
|
|
1255
|
-
urlContextMetadata: (
|
|
1256
|
-
safetyRatings: (
|
|
1394
|
+
promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
|
|
1395
|
+
groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
|
|
1396
|
+
urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
|
|
1397
|
+
safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
|
|
1257
1398
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1258
|
-
finishMessage: (
|
|
1399
|
+
finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
|
|
1400
|
+
serviceTier: (_p = response.serviceTier) != null ? _p : null
|
|
1259
1401
|
}
|
|
1260
1402
|
},
|
|
1261
1403
|
request: { body: args },
|
|
@@ -1291,6 +1433,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1291
1433
|
let providerMetadata = void 0;
|
|
1292
1434
|
let lastGroundingMetadata = null;
|
|
1293
1435
|
let lastUrlContextMetadata = null;
|
|
1436
|
+
let serviceTier = null;
|
|
1294
1437
|
const generateId3 = this.config.generateId;
|
|
1295
1438
|
let hasToolCalls = false;
|
|
1296
1439
|
let currentTextBlockId = null;
|
|
@@ -1298,6 +1441,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1298
1441
|
let blockCounter = 0;
|
|
1299
1442
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
|
1300
1443
|
let lastCodeExecutionToolCallId;
|
|
1444
|
+
let lastServerToolCallId;
|
|
1301
1445
|
return {
|
|
1302
1446
|
stream: response.pipeThrough(
|
|
1303
1447
|
new TransformStream({
|
|
@@ -1305,7 +1449,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1305
1449
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1306
1450
|
},
|
|
1307
1451
|
transform(chunk, controller) {
|
|
1308
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1452
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1309
1453
|
if (options.includeRawChunks) {
|
|
1310
1454
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1311
1455
|
}
|
|
@@ -1318,6 +1462,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1318
1462
|
if (usageMetadata != null) {
|
|
1319
1463
|
usage = usageMetadata;
|
|
1320
1464
|
}
|
|
1465
|
+
if (value.serviceTier != null) {
|
|
1466
|
+
serviceTier = value.serviceTier;
|
|
1467
|
+
}
|
|
1321
1468
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
1322
1469
|
if (candidate == null) {
|
|
1323
1470
|
return;
|
|
@@ -1457,6 +1604,42 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1457
1604
|
data: part.inlineData.data,
|
|
1458
1605
|
providerMetadata: fileMeta
|
|
1459
1606
|
});
|
|
1607
|
+
} else if ("toolCall" in part && part.toolCall) {
|
|
1608
|
+
const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId3();
|
|
1609
|
+
lastServerToolCallId = toolCallId;
|
|
1610
|
+
const serverMeta = {
|
|
1611
|
+
[providerOptionsName]: {
|
|
1612
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1613
|
+
serverToolCallId: toolCallId,
|
|
1614
|
+
serverToolType: part.toolCall.toolType
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
controller.enqueue({
|
|
1618
|
+
type: "tool-call",
|
|
1619
|
+
toolCallId,
|
|
1620
|
+
toolName: `server:${part.toolCall.toolType}`,
|
|
1621
|
+
input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
|
|
1622
|
+
providerExecuted: true,
|
|
1623
|
+
dynamic: true,
|
|
1624
|
+
providerMetadata: serverMeta
|
|
1625
|
+
});
|
|
1626
|
+
} else if ("toolResponse" in part && part.toolResponse) {
|
|
1627
|
+
const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId3();
|
|
1628
|
+
const serverMeta = {
|
|
1629
|
+
[providerOptionsName]: {
|
|
1630
|
+
...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
|
|
1631
|
+
serverToolCallId: responseToolCallId,
|
|
1632
|
+
serverToolType: part.toolResponse.toolType
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
controller.enqueue({
|
|
1636
|
+
type: "tool-result",
|
|
1637
|
+
toolCallId: responseToolCallId,
|
|
1638
|
+
toolName: `server:${part.toolResponse.toolType}`,
|
|
1639
|
+
result: (_h = part.toolResponse.response) != null ? _h : {},
|
|
1640
|
+
providerMetadata: serverMeta
|
|
1641
|
+
});
|
|
1642
|
+
lastServerToolCallId = void 0;
|
|
1460
1643
|
}
|
|
1461
1644
|
}
|
|
1462
1645
|
const toolCallDeltas = getToolCallsFromParts({
|
|
@@ -1504,12 +1687,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1504
1687
|
};
|
|
1505
1688
|
providerMetadata = {
|
|
1506
1689
|
[providerOptionsName]: {
|
|
1507
|
-
promptFeedback: (
|
|
1690
|
+
promptFeedback: (_i = value.promptFeedback) != null ? _i : null,
|
|
1508
1691
|
groundingMetadata: lastGroundingMetadata,
|
|
1509
1692
|
urlContextMetadata: lastUrlContextMetadata,
|
|
1510
|
-
safetyRatings: (
|
|
1693
|
+
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
|
1511
1694
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1512
|
-
finishMessage: (
|
|
1695
|
+
finishMessage: (_k = candidate.finishMessage) != null ? _k : null,
|
|
1696
|
+
serviceTier
|
|
1513
1697
|
}
|
|
1514
1698
|
};
|
|
1515
1699
|
}
|
|
@@ -1723,6 +1907,22 @@ var getContentSchema = () => import_v45.z.object({
|
|
|
1723
1907
|
thought: import_v45.z.boolean().nullish(),
|
|
1724
1908
|
thoughtSignature: import_v45.z.string().nullish()
|
|
1725
1909
|
}),
|
|
1910
|
+
import_v45.z.object({
|
|
1911
|
+
toolCall: import_v45.z.object({
|
|
1912
|
+
toolType: import_v45.z.string(),
|
|
1913
|
+
args: import_v45.z.unknown().nullish(),
|
|
1914
|
+
id: import_v45.z.string()
|
|
1915
|
+
}),
|
|
1916
|
+
thoughtSignature: import_v45.z.string().nullish()
|
|
1917
|
+
}),
|
|
1918
|
+
import_v45.z.object({
|
|
1919
|
+
toolResponse: import_v45.z.object({
|
|
1920
|
+
toolType: import_v45.z.string(),
|
|
1921
|
+
response: import_v45.z.unknown().nullish(),
|
|
1922
|
+
id: import_v45.z.string()
|
|
1923
|
+
}),
|
|
1924
|
+
thoughtSignature: import_v45.z.string().nullish()
|
|
1925
|
+
}),
|
|
1726
1926
|
import_v45.z.object({
|
|
1727
1927
|
executableCode: import_v45.z.object({
|
|
1728
1928
|
language: import_v45.z.string(),
|
|
@@ -1781,7 +1981,8 @@ var responseSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1781
1981
|
promptFeedback: import_v45.z.object({
|
|
1782
1982
|
blockReason: import_v45.z.string().nullish(),
|
|
1783
1983
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
|
|
1784
|
-
}).nullish()
|
|
1984
|
+
}).nullish(),
|
|
1985
|
+
serviceTier: import_v45.z.string().nullish()
|
|
1785
1986
|
})
|
|
1786
1987
|
)
|
|
1787
1988
|
);
|
|
@@ -1802,7 +2003,8 @@ var chunkSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
1802
2003
|
promptFeedback: import_v45.z.object({
|
|
1803
2004
|
blockReason: import_v45.z.string().nullish(),
|
|
1804
2005
|
safetyRatings: import_v45.z.array(getSafetyRatingSchema()).nullish()
|
|
1805
|
-
}).nullish()
|
|
2006
|
+
}).nullish(),
|
|
2007
|
+
serviceTier: import_v45.z.string().nullish()
|
|
1806
2008
|
})
|
|
1807
2009
|
)
|
|
1808
2010
|
);
|