@ai-sdk/google 3.0.95 → 3.0.97
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -6
- 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 +14 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +14 -5
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/google-generative-ai-language-model.ts +17 -9
package/package.json
CHANGED
|
@@ -375,7 +375,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
375
375
|
|
|
376
376
|
const usageMetadata = response.usageMetadata;
|
|
377
377
|
|
|
378
|
-
// Associates
|
|
378
|
+
// Associates code execution results with their preceding call.
|
|
379
379
|
let lastCodeExecutionToolCallId: string | undefined;
|
|
380
380
|
// Associates a server-side tool response with its preceding call (tool combination).
|
|
381
381
|
let lastServerToolCallId: string | undefined;
|
|
@@ -396,7 +396,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
396
396
|
} else if ('codeExecutionResult' in part && part.codeExecutionResult) {
|
|
397
397
|
content.push({
|
|
398
398
|
type: 'tool-result',
|
|
399
|
-
//
|
|
399
|
+
// Results correspond to the most recent executable code part.
|
|
400
400
|
toolCallId: lastCodeExecutionToolCallId!,
|
|
401
401
|
toolName: 'code_execution',
|
|
402
402
|
result: {
|
|
@@ -404,8 +404,6 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
404
404
|
output: part.codeExecutionResult.output ?? '',
|
|
405
405
|
},
|
|
406
406
|
});
|
|
407
|
-
// Clear the ID after use to avoid accidental reuse.
|
|
408
|
-
lastCodeExecutionToolCallId = undefined;
|
|
409
407
|
} else if ('text' in part && part.text != null) {
|
|
410
408
|
const thoughtSignatureMetadata = part.thoughtSignature
|
|
411
409
|
? {
|
|
@@ -550,7 +548,8 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
550
548
|
},
|
|
551
549
|
request: { body: args },
|
|
552
550
|
response: {
|
|
553
|
-
// TODO timestamp, model id
|
|
551
|
+
// TODO timestamp, model id
|
|
552
|
+
id: response.responseId ?? undefined,
|
|
554
553
|
headers: responseHeaders,
|
|
555
554
|
body: rawResponse,
|
|
556
555
|
},
|
|
@@ -592,6 +591,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
592
591
|
|
|
593
592
|
const generateId = this.config.generateId;
|
|
594
593
|
let hasToolCalls = false;
|
|
594
|
+
let hasEmittedResponseMetadata = false;
|
|
595
595
|
|
|
596
596
|
// Track active blocks to group consecutive parts of same type
|
|
597
597
|
let currentTextBlockId: string | null = null;
|
|
@@ -600,7 +600,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
600
600
|
|
|
601
601
|
// Track emitted sources to prevent duplicates
|
|
602
602
|
const emittedSourceUrls = new Set<string>();
|
|
603
|
-
// Associates
|
|
603
|
+
// Associates code execution results with their preceding call.
|
|
604
604
|
let lastCodeExecutionToolCallId: string | undefined;
|
|
605
605
|
// Associates a server-side tool response with its preceding call (tool combination).
|
|
606
606
|
let lastServerToolCallId: string | undefined;
|
|
@@ -670,6 +670,14 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
670
670
|
|
|
671
671
|
const value = chunk.value;
|
|
672
672
|
|
|
673
|
+
if (!hasEmittedResponseMetadata && value.responseId != null) {
|
|
674
|
+
hasEmittedResponseMetadata = true;
|
|
675
|
+
controller.enqueue({
|
|
676
|
+
type: 'response-metadata',
|
|
677
|
+
id: value.responseId,
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
|
|
673
681
|
const usageMetadata = value.usageMetadata;
|
|
674
682
|
|
|
675
683
|
if (usageMetadata != null) {
|
|
@@ -728,7 +736,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
728
736
|
'codeExecutionResult' in part &&
|
|
729
737
|
part.codeExecutionResult
|
|
730
738
|
) {
|
|
731
|
-
//
|
|
739
|
+
// Results correspond to the most recent executable code part.
|
|
732
740
|
const toolCallId = lastCodeExecutionToolCallId;
|
|
733
741
|
|
|
734
742
|
if (toolCallId) {
|
|
@@ -741,8 +749,6 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
|
|
|
741
749
|
output: part.codeExecutionResult.output ?? '',
|
|
742
750
|
},
|
|
743
751
|
});
|
|
744
|
-
// Clear the ID after use.
|
|
745
|
-
lastCodeExecutionToolCallId = undefined;
|
|
746
752
|
}
|
|
747
753
|
} else if ('text' in part && part.text != null) {
|
|
748
754
|
const thoughtSignatureMetadata = part.thoughtSignature
|
|
@@ -1456,6 +1462,7 @@ export const getUrlContextMetadataSchema = () =>
|
|
|
1456
1462
|
const responseSchema = lazySchema(() =>
|
|
1457
1463
|
zodSchema(
|
|
1458
1464
|
z.object({
|
|
1465
|
+
responseId: z.string().nullish(),
|
|
1459
1466
|
candidates: z.array(
|
|
1460
1467
|
z.object({
|
|
1461
1468
|
content: getContentSchema().nullish().or(z.object({}).strict()),
|
|
@@ -1509,6 +1516,7 @@ export type UsageMetadataSchema = NonNullable<
|
|
|
1509
1516
|
const chunkSchema = lazySchema(() =>
|
|
1510
1517
|
zodSchema(
|
|
1511
1518
|
z.object({
|
|
1519
|
+
responseId: z.string().nullish(),
|
|
1512
1520
|
candidates: z
|
|
1513
1521
|
.array(
|
|
1514
1522
|
z.object({
|