@ai-sdk/google 3.0.73 → 3.0.74
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 +6 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +44 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -29
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +43 -28
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +43 -28
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/convert-to-google-generative-ai-messages.ts +20 -2
- package/src/google-generative-ai-language-model.ts +5 -4
- package/src/google-generative-ai-prompt.ts +5 -1
package/package.json
CHANGED
|
@@ -57,6 +57,7 @@ function appendToolResultParts(
|
|
|
57
57
|
type: string;
|
|
58
58
|
[key: string]: unknown;
|
|
59
59
|
}>,
|
|
60
|
+
toolCallId?: string,
|
|
60
61
|
): void {
|
|
61
62
|
const functionResponseParts: GoogleGenerativeAIFunctionResponsePart[] = [];
|
|
62
63
|
const responseTextParts: string[] = [];
|
|
@@ -99,6 +100,7 @@ function appendToolResultParts(
|
|
|
99
100
|
|
|
100
101
|
parts.push({
|
|
101
102
|
functionResponse: {
|
|
103
|
+
...(toolCallId != null ? { id: toolCallId } : {}),
|
|
102
104
|
name: toolName,
|
|
103
105
|
response: {
|
|
104
106
|
name: toolName,
|
|
@@ -126,12 +128,14 @@ function appendLegacyToolResultParts(
|
|
|
126
128
|
type: string;
|
|
127
129
|
[key: string]: unknown;
|
|
128
130
|
}>,
|
|
131
|
+
toolCallId?: string,
|
|
129
132
|
): void {
|
|
130
133
|
for (const contentPart of outputValue) {
|
|
131
134
|
switch (contentPart.type) {
|
|
132
135
|
case 'text':
|
|
133
136
|
parts.push({
|
|
134
137
|
functionResponse: {
|
|
138
|
+
...(toolCallId != null ? { id: toolCallId } : {}),
|
|
135
139
|
name: toolName,
|
|
136
140
|
response: {
|
|
137
141
|
name: toolName,
|
|
@@ -315,6 +319,9 @@ export function convertToGoogleGenerativeAIMessages(
|
|
|
315
319
|
|
|
316
320
|
return {
|
|
317
321
|
functionCall: {
|
|
322
|
+
...(part.toolCallId != null
|
|
323
|
+
? { id: part.toolCallId }
|
|
324
|
+
: {}),
|
|
318
325
|
name: part.toolName,
|
|
319
326
|
args: part.input,
|
|
320
327
|
},
|
|
@@ -405,13 +412,24 @@ export function convertToGoogleGenerativeAIMessages(
|
|
|
405
412
|
|
|
406
413
|
if (output.type === 'content') {
|
|
407
414
|
if (supportsFunctionResponseParts) {
|
|
408
|
-
appendToolResultParts(
|
|
415
|
+
appendToolResultParts(
|
|
416
|
+
parts,
|
|
417
|
+
part.toolName,
|
|
418
|
+
output.value,
|
|
419
|
+
part.toolCallId,
|
|
420
|
+
);
|
|
409
421
|
} else {
|
|
410
|
-
appendLegacyToolResultParts(
|
|
422
|
+
appendLegacyToolResultParts(
|
|
423
|
+
parts,
|
|
424
|
+
part.toolName,
|
|
425
|
+
output.value,
|
|
426
|
+
part.toolCallId,
|
|
427
|
+
);
|
|
411
428
|
}
|
|
412
429
|
} else {
|
|
413
430
|
parts.push({
|
|
414
431
|
functionResponse: {
|
|
432
|
+
...(part.toolCallId != null ? { id: part.toolCallId } : {}),
|
|
415
433
|
name: part.toolName,
|
|
416
434
|
response: {
|
|
417
435
|
name: part.toolName,
|
|
@@ -349,7 +349,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
349
349
|
} else if ('functionCall' in part && part.functionCall.name != null) {
|
|
350
350
|
content.push({
|
|
351
351
|
type: 'tool-call' as const,
|
|
352
|
-
toolCallId: this.config.generateId(),
|
|
352
|
+
toolCallId: part.functionCall.id ?? this.config.generateId(),
|
|
353
353
|
toolName: part.functionCall.name,
|
|
354
354
|
input: JSON.stringify(part.functionCall.args ?? {}),
|
|
355
355
|
providerMetadata: part.thoughtSignature
|
|
@@ -828,7 +828,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
828
828
|
part.functionCall.name != null &&
|
|
829
829
|
part.functionCall.willContinue === true
|
|
830
830
|
) {
|
|
831
|
-
const toolCallId = generateId();
|
|
831
|
+
const toolCallId = part.functionCall.id ?? generateId();
|
|
832
832
|
const accumulator = new GoogleJSONAccumulator();
|
|
833
833
|
activeStreamingToolCalls.push({
|
|
834
834
|
toolCallId,
|
|
@@ -910,7 +910,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
910
910
|
|
|
911
911
|
hasToolCalls = true;
|
|
912
912
|
} else if (isCompleteCall) {
|
|
913
|
-
const toolCallId = generateId();
|
|
913
|
+
const toolCallId = part.functionCall.id ?? generateId();
|
|
914
914
|
const toolName = part.functionCall.name!;
|
|
915
915
|
const args =
|
|
916
916
|
typeof part.functionCall.args === 'string'
|
|
@@ -947,7 +947,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
947
947
|
|
|
948
948
|
hasToolCalls = true;
|
|
949
949
|
} else if (isNoArgsCompleteCall) {
|
|
950
|
-
const toolCallId = generateId();
|
|
950
|
+
const toolCallId = part.functionCall.id ?? generateId();
|
|
951
951
|
const toolName = part.functionCall.name!;
|
|
952
952
|
|
|
953
953
|
controller.enqueue({
|
|
@@ -1257,6 +1257,7 @@ const getContentSchema = () =>
|
|
|
1257
1257
|
// note: order matters since text can be fully empty
|
|
1258
1258
|
z.object({
|
|
1259
1259
|
functionCall: z.object({
|
|
1260
|
+
id: z.string().nullish(),
|
|
1260
1261
|
name: z.string().nullish(),
|
|
1261
1262
|
args: z.unknown().nullish(),
|
|
1262
1263
|
partialArgs: z.array(partialArgSchema).nullish(),
|
|
@@ -23,9 +23,13 @@ export type GoogleGenerativeAIContent = {
|
|
|
23
23
|
export type GoogleGenerativeAIContentPart =
|
|
24
24
|
| { text: string; thought?: boolean; thoughtSignature?: string }
|
|
25
25
|
| { inlineData: { mimeType: string; data: string } }
|
|
26
|
-
| {
|
|
26
|
+
| {
|
|
27
|
+
functionCall: { id?: string; name: string; args: unknown };
|
|
28
|
+
thoughtSignature?: string;
|
|
29
|
+
}
|
|
27
30
|
| {
|
|
28
31
|
functionResponse: {
|
|
32
|
+
id?: string;
|
|
29
33
|
name: string;
|
|
30
34
|
response: unknown;
|
|
31
35
|
parts?: Array<GoogleGenerativeAIFunctionResponsePart>;
|