@ai-sdk/google 4.0.18 → 4.0.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 +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +14 -5
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/google-language-model.ts +17 -9
package/package.json
CHANGED
|
@@ -414,7 +414,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
414
414
|
|
|
415
415
|
const usageMetadata = response.usageMetadata;
|
|
416
416
|
|
|
417
|
-
// Associates
|
|
417
|
+
// Associates code execution results with their preceding call.
|
|
418
418
|
let lastCodeExecutionToolCallId: string | undefined;
|
|
419
419
|
// Associates a server-side tool response with its preceding call (tool combination).
|
|
420
420
|
let lastServerToolCallId: string | undefined;
|
|
@@ -435,7 +435,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
435
435
|
} else if ('codeExecutionResult' in part && part.codeExecutionResult) {
|
|
436
436
|
content.push({
|
|
437
437
|
type: 'tool-result',
|
|
438
|
-
//
|
|
438
|
+
// Results correspond to the most recent executable code part.
|
|
439
439
|
toolCallId: lastCodeExecutionToolCallId!,
|
|
440
440
|
toolName: 'code_execution',
|
|
441
441
|
result: {
|
|
@@ -443,8 +443,6 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
443
443
|
output: part.codeExecutionResult.output ?? '',
|
|
444
444
|
},
|
|
445
445
|
});
|
|
446
|
-
// Clear the ID after use to avoid accidental reuse.
|
|
447
|
-
lastCodeExecutionToolCallId = undefined;
|
|
448
446
|
} else if ('text' in part && part.text != null) {
|
|
449
447
|
const thoughtSignatureMetadata = part.thoughtSignature
|
|
450
448
|
? wrapProviderMetadata({
|
|
@@ -569,7 +567,8 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
569
567
|
} satisfies GoogleProviderMetadata),
|
|
570
568
|
request: { body: args },
|
|
571
569
|
response: {
|
|
572
|
-
// TODO timestamp, model id
|
|
570
|
+
// TODO timestamp, model id
|
|
571
|
+
id: response.responseId ?? undefined,
|
|
573
572
|
headers: responseHeaders,
|
|
574
573
|
body: rawResponse,
|
|
575
574
|
},
|
|
@@ -615,6 +614,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
615
614
|
|
|
616
615
|
const generateId = this.config.generateId;
|
|
617
616
|
let hasToolCalls = false;
|
|
617
|
+
let hasEmittedResponseMetadata = false;
|
|
618
618
|
|
|
619
619
|
// Track active blocks to group consecutive parts of same type
|
|
620
620
|
let currentTextBlockId: string | null = null;
|
|
@@ -623,7 +623,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
623
623
|
|
|
624
624
|
// Track emitted sources to prevent duplicates
|
|
625
625
|
const emittedSourceUrls = new Set<string>();
|
|
626
|
-
// Associates
|
|
626
|
+
// Associates code execution results with their preceding call.
|
|
627
627
|
let lastCodeExecutionToolCallId: string | undefined;
|
|
628
628
|
// Associates a server-side tool response with its preceding call (tool combination).
|
|
629
629
|
let lastServerToolCallId: string | undefined;
|
|
@@ -693,6 +693,14 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
693
693
|
|
|
694
694
|
const value = chunk.value;
|
|
695
695
|
|
|
696
|
+
if (!hasEmittedResponseMetadata && value.responseId != null) {
|
|
697
|
+
hasEmittedResponseMetadata = true;
|
|
698
|
+
controller.enqueue({
|
|
699
|
+
type: 'response-metadata',
|
|
700
|
+
id: value.responseId,
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
|
|
696
704
|
const usageMetadata = value.usageMetadata;
|
|
697
705
|
|
|
698
706
|
if (usageMetadata != null) {
|
|
@@ -751,7 +759,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
751
759
|
'codeExecutionResult' in part &&
|
|
752
760
|
part.codeExecutionResult
|
|
753
761
|
) {
|
|
754
|
-
//
|
|
762
|
+
// Results correspond to the most recent executable code part.
|
|
755
763
|
const toolCallId = lastCodeExecutionToolCallId;
|
|
756
764
|
|
|
757
765
|
if (toolCallId) {
|
|
@@ -764,8 +772,6 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
764
772
|
output: part.codeExecutionResult.output ?? '',
|
|
765
773
|
},
|
|
766
774
|
});
|
|
767
|
-
// Clear the ID after use.
|
|
768
|
-
lastCodeExecutionToolCallId = undefined;
|
|
769
775
|
}
|
|
770
776
|
} else if ('text' in part && part.text != null) {
|
|
771
777
|
const thoughtSignatureMetadata = part.thoughtSignature
|
|
@@ -1531,6 +1537,7 @@ export const getUrlContextMetadataSchema = () =>
|
|
|
1531
1537
|
const responseSchema = lazySchema(() =>
|
|
1532
1538
|
zodSchema(
|
|
1533
1539
|
z.object({
|
|
1540
|
+
responseId: z.string().nullish(),
|
|
1534
1541
|
candidates: z.array(
|
|
1535
1542
|
z.object({
|
|
1536
1543
|
content: getContentSchema().nullish().or(z.object({}).strict()),
|
|
@@ -1577,6 +1584,7 @@ export type UsageMetadataSchema = NonNullable<
|
|
|
1577
1584
|
const chunkSchema = lazySchema(() =>
|
|
1578
1585
|
zodSchema(
|
|
1579
1586
|
z.object({
|
|
1587
|
+
responseId: z.string().nullish(),
|
|
1580
1588
|
candidates: z
|
|
1581
1589
|
.array(
|
|
1582
1590
|
z.object({
|