@ai-sdk/google 4.0.0-canary.63 → 4.0.0-canary.64
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.ts +1 -0
- package/dist/index.js +44 -29
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +43 -28
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/convert-to-google-messages.ts +20 -2
- package/src/google-language-model.ts +5 -4
- package/src/google-prompt.ts +5 -1
package/package.json
CHANGED
|
@@ -64,6 +64,7 @@ function appendToolResultParts(
|
|
|
64
64
|
LanguageModelV4ToolResultOutput,
|
|
65
65
|
{ type: 'content' }
|
|
66
66
|
>['value'],
|
|
67
|
+
toolCallId?: string,
|
|
67
68
|
): void {
|
|
68
69
|
const functionResponseParts: GoogleFunctionResponsePart[] = [];
|
|
69
70
|
const responseTextParts: string[] = [];
|
|
@@ -106,6 +107,7 @@ function appendToolResultParts(
|
|
|
106
107
|
|
|
107
108
|
parts.push({
|
|
108
109
|
functionResponse: {
|
|
110
|
+
...(toolCallId != null ? { id: toolCallId } : {}),
|
|
109
111
|
name: toolName,
|
|
110
112
|
response: {
|
|
111
113
|
name: toolName,
|
|
@@ -133,12 +135,14 @@ function appendLegacyToolResultParts(
|
|
|
133
135
|
LanguageModelV4ToolResultOutput,
|
|
134
136
|
{ type: 'content' }
|
|
135
137
|
>['value'],
|
|
138
|
+
toolCallId?: string,
|
|
136
139
|
): void {
|
|
137
140
|
for (const contentPart of outputValue) {
|
|
138
141
|
switch (contentPart.type) {
|
|
139
142
|
case 'text':
|
|
140
143
|
parts.push({
|
|
141
144
|
functionResponse: {
|
|
145
|
+
...(toolCallId != null ? { id: toolCallId } : {}),
|
|
142
146
|
name: toolName,
|
|
143
147
|
response: {
|
|
144
148
|
name: toolName,
|
|
@@ -447,6 +451,9 @@ export function convertToGoogleMessages(
|
|
|
447
451
|
|
|
448
452
|
return {
|
|
449
453
|
functionCall: {
|
|
454
|
+
...(part.toolCallId != null
|
|
455
|
+
? { id: part.toolCallId }
|
|
456
|
+
: {}),
|
|
450
457
|
name: part.toolName,
|
|
451
458
|
args: part.input,
|
|
452
459
|
},
|
|
@@ -533,13 +540,24 @@ export function convertToGoogleMessages(
|
|
|
533
540
|
|
|
534
541
|
if (output.type === 'content') {
|
|
535
542
|
if (supportsFunctionResponseParts) {
|
|
536
|
-
appendToolResultParts(
|
|
543
|
+
appendToolResultParts(
|
|
544
|
+
parts,
|
|
545
|
+
part.toolName,
|
|
546
|
+
output.value,
|
|
547
|
+
part.toolCallId,
|
|
548
|
+
);
|
|
537
549
|
} else {
|
|
538
|
-
appendLegacyToolResultParts(
|
|
550
|
+
appendLegacyToolResultParts(
|
|
551
|
+
parts,
|
|
552
|
+
part.toolName,
|
|
553
|
+
output.value,
|
|
554
|
+
part.toolCallId,
|
|
555
|
+
);
|
|
539
556
|
}
|
|
540
557
|
} else {
|
|
541
558
|
parts.push({
|
|
542
559
|
functionResponse: {
|
|
560
|
+
...(part.toolCallId != null ? { id: part.toolCallId } : {}),
|
|
543
561
|
name: part.toolName,
|
|
544
562
|
response: {
|
|
545
563
|
name: part.toolName,
|
|
@@ -387,7 +387,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
387
387
|
} else if ('functionCall' in part && part.functionCall.name != null) {
|
|
388
388
|
content.push({
|
|
389
389
|
type: 'tool-call' as const,
|
|
390
|
-
toolCallId: this.config.generateId(),
|
|
390
|
+
toolCallId: part.functionCall.id ?? this.config.generateId(),
|
|
391
391
|
toolName: part.functionCall.name,
|
|
392
392
|
input: JSON.stringify(part.functionCall.args ?? {}),
|
|
393
393
|
providerMetadata: part.thoughtSignature
|
|
@@ -838,7 +838,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
838
838
|
part.functionCall.name != null &&
|
|
839
839
|
part.functionCall.willContinue === true
|
|
840
840
|
) {
|
|
841
|
-
const toolCallId = generateId();
|
|
841
|
+
const toolCallId = part.functionCall.id ?? generateId();
|
|
842
842
|
const accumulator = new GoogleJSONAccumulator();
|
|
843
843
|
activeStreamingToolCalls.push({
|
|
844
844
|
toolCallId,
|
|
@@ -920,7 +920,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
920
920
|
|
|
921
921
|
hasToolCalls = true;
|
|
922
922
|
} else if (isCompleteCall) {
|
|
923
|
-
const toolCallId = generateId();
|
|
923
|
+
const toolCallId = part.functionCall.id ?? generateId();
|
|
924
924
|
const toolName = part.functionCall.name!;
|
|
925
925
|
const args =
|
|
926
926
|
typeof part.functionCall.args === 'string'
|
|
@@ -957,7 +957,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
957
957
|
|
|
958
958
|
hasToolCalls = true;
|
|
959
959
|
} else if (isNoArgsCompleteCall) {
|
|
960
|
-
const toolCallId = generateId();
|
|
960
|
+
const toolCallId = part.functionCall.id ?? generateId();
|
|
961
961
|
const toolName = part.functionCall.name!;
|
|
962
962
|
|
|
963
963
|
controller.enqueue({
|
|
@@ -1333,6 +1333,7 @@ const getContentSchema = () =>
|
|
|
1333
1333
|
// note: order matters since text can be fully empty
|
|
1334
1334
|
z.object({
|
|
1335
1335
|
functionCall: z.object({
|
|
1336
|
+
id: z.string().nullish(),
|
|
1336
1337
|
name: z.string().nullish(),
|
|
1337
1338
|
args: z.unknown().nullish(),
|
|
1338
1339
|
partialArgs: z.array(partialArgSchema).nullish(),
|
package/src/google-prompt.ts
CHANGED
|
@@ -27,9 +27,13 @@ export type GoogleContentPart =
|
|
|
27
27
|
thought?: boolean;
|
|
28
28
|
thoughtSignature?: string;
|
|
29
29
|
}
|
|
30
|
-
| {
|
|
30
|
+
| {
|
|
31
|
+
functionCall: { id?: string; name: string; args: unknown };
|
|
32
|
+
thoughtSignature?: string;
|
|
33
|
+
}
|
|
31
34
|
| {
|
|
32
35
|
functionResponse: {
|
|
36
|
+
id?: string;
|
|
33
37
|
name: string;
|
|
34
38
|
response: unknown;
|
|
35
39
|
parts?: Array<GoogleFunctionResponsePart>;
|