@ai-sdk/google 4.0.53 → 4.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.ts +69 -9
- package/dist/index.js +614 -65
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +7 -6
- package/dist/internal/index.js +59 -37
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/google-language-model.ts +71 -34
- package/src/google-provider.ts +27 -0
- package/src/index.ts +5 -0
- package/src/transcription/google-transcription-model-options.ts +50 -0
- package/src/transcription/google-transcription-model.ts +714 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -232,7 +232,8 @@ declare const getUrlContextMetadataSchema: () => z.ZodObject<{
|
|
|
232
232
|
}, z.core.$strip>>>>;
|
|
233
233
|
}, z.core.$strip>;
|
|
234
234
|
declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
235
|
-
|
|
235
|
+
responseId?: string | null | undefined;
|
|
236
|
+
candidates?: {
|
|
236
237
|
content?: Record<string, never> | {
|
|
237
238
|
parts?: ({
|
|
238
239
|
functionCall: {
|
|
@@ -348,8 +349,7 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
348
349
|
urlRetrievalStatus: string;
|
|
349
350
|
}[] | null | undefined;
|
|
350
351
|
} | null | undefined;
|
|
351
|
-
}[];
|
|
352
|
-
responseId?: string | null | undefined;
|
|
352
|
+
}[] | null | undefined;
|
|
353
353
|
usageMetadata?: {
|
|
354
354
|
cachedContentTokenCount?: number | null | undefined;
|
|
355
355
|
thoughtsTokenCount?: number | null | undefined;
|
|
@@ -379,9 +379,10 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
379
379
|
}[] | null | undefined;
|
|
380
380
|
} | null | undefined;
|
|
381
381
|
}>;
|
|
382
|
-
type
|
|
383
|
-
type
|
|
384
|
-
type
|
|
382
|
+
type CandidateSchema = NonNullable<InferSchema<typeof responseSchema>['candidates']>[number];
|
|
383
|
+
type GroundingMetadataSchema = NonNullable<CandidateSchema['groundingMetadata']>;
|
|
384
|
+
type UrlContextMetadataSchema = NonNullable<CandidateSchema['urlContextMetadata']>;
|
|
385
|
+
type SafetyRatingSchema = NonNullable<CandidateSchema['safetyRatings']>[number];
|
|
385
386
|
type PromptFeedbackSchema = NonNullable<InferSchema<typeof responseSchema>['promptFeedback']>;
|
|
386
387
|
type UsageMetadataSchema = NonNullable<InferSchema<typeof responseSchema>['usageMetadata']>;
|
|
387
388
|
|
package/dist/internal/index.js
CHANGED
|
@@ -1761,18 +1761,21 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1761
1761
|
warnings,
|
|
1762
1762
|
providerOptionsNames
|
|
1763
1763
|
}) {
|
|
1764
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1764
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
1765
1765
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
1766
1766
|
providerOptionsNames.map((name) => [name, payload])
|
|
1767
1767
|
);
|
|
1768
|
-
const candidate = response.candidates[0];
|
|
1768
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1769
|
+
const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
1770
|
+
const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
|
|
1771
|
+
const rawFinishReason = (_d = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : promptBlockReason) != null ? _d : void 0;
|
|
1769
1772
|
const content = [];
|
|
1770
|
-
const parts = (
|
|
1773
|
+
const parts = (_f = (_e = candidate == null ? void 0 : candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
|
|
1771
1774
|
const usageMetadata = response.usageMetadata;
|
|
1772
1775
|
let lastCodeExecutionToolCallId;
|
|
1773
1776
|
let lastServerToolCallId;
|
|
1774
1777
|
for (const part of parts) {
|
|
1775
|
-
if ("executableCode" in part && ((
|
|
1778
|
+
if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
|
|
1776
1779
|
const toolCallId = this.config.generateId();
|
|
1777
1780
|
lastCodeExecutionToolCallId = toolCallId;
|
|
1778
1781
|
content.push({
|
|
@@ -1790,7 +1793,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1790
1793
|
toolName: "code_execution",
|
|
1791
1794
|
result: {
|
|
1792
1795
|
outcome: part.codeExecutionResult.outcome,
|
|
1793
|
-
output: (
|
|
1796
|
+
output: (_h = part.codeExecutionResult.output) != null ? _h : ""
|
|
1794
1797
|
}
|
|
1795
1798
|
});
|
|
1796
1799
|
} else if ("text" in part && part.text != null) {
|
|
@@ -1814,7 +1817,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1814
1817
|
type: "tool-call",
|
|
1815
1818
|
toolCallId: part.functionCall.id || this.config.generateId(),
|
|
1816
1819
|
toolName: part.functionCall.name,
|
|
1817
|
-
input: JSON.stringify((
|
|
1820
|
+
input: JSON.stringify((_i = part.functionCall.args) != null ? _i : {}),
|
|
1818
1821
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1819
1822
|
thoughtSignature: part.thoughtSignature
|
|
1820
1823
|
}) : void 0
|
|
@@ -1837,7 +1840,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1837
1840
|
type: "tool-call",
|
|
1838
1841
|
toolCallId,
|
|
1839
1842
|
toolName: `server:${part.toolCall.toolType}`,
|
|
1840
|
-
input: JSON.stringify((
|
|
1843
|
+
input: JSON.stringify((_j = part.toolCall.args) != null ? _j : {}),
|
|
1841
1844
|
providerExecuted: true,
|
|
1842
1845
|
dynamic: true,
|
|
1843
1846
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -1855,7 +1858,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1855
1858
|
type: "tool-result",
|
|
1856
1859
|
toolCallId: responseToolCallId,
|
|
1857
1860
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
1858
|
-
result: (
|
|
1861
|
+
result: (_k = part.toolResponse.response) != null ? _k : {},
|
|
1859
1862
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
1860
1863
|
thoughtSignature: part.thoughtSignature,
|
|
1861
1864
|
serverToolCallId: responseToolCallId,
|
|
@@ -1868,39 +1871,39 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1868
1871
|
lastServerToolCallId = void 0;
|
|
1869
1872
|
}
|
|
1870
1873
|
}
|
|
1871
|
-
const sources = (
|
|
1872
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
1874
|
+
const sources = (_l = extractSources({
|
|
1875
|
+
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
1873
1876
|
generateId: this.config.generateId
|
|
1874
|
-
})) != null ?
|
|
1877
|
+
})) != null ? _l : [];
|
|
1875
1878
|
for (const source of sources) {
|
|
1876
1879
|
content.push(source);
|
|
1877
1880
|
}
|
|
1878
1881
|
return {
|
|
1879
1882
|
content,
|
|
1880
1883
|
finishReason: {
|
|
1881
|
-
unified: mapGoogleFinishReason({
|
|
1882
|
-
finishReason:
|
|
1884
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleFinishReason({
|
|
1885
|
+
finishReason: rawFinishReason,
|
|
1883
1886
|
// Only count client-executed tool calls for finish reason determination.
|
|
1884
1887
|
hasToolCalls: content.some(
|
|
1885
1888
|
(part) => part.type === "tool-call" && !part.providerExecuted
|
|
1886
1889
|
)
|
|
1887
1890
|
}),
|
|
1888
|
-
raw:
|
|
1891
|
+
raw: rawFinishReason
|
|
1889
1892
|
},
|
|
1890
1893
|
usage: convertGoogleUsage(usageMetadata),
|
|
1891
1894
|
warnings,
|
|
1892
1895
|
providerMetadata: wrapProviderMetadata({
|
|
1893
|
-
promptFeedback: (
|
|
1894
|
-
groundingMetadata: (
|
|
1895
|
-
urlContextMetadata: (
|
|
1896
|
-
safetyRatings: (
|
|
1896
|
+
promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
|
|
1897
|
+
groundingMetadata: (_n = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _n : null,
|
|
1898
|
+
urlContextMetadata: (_o = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _o : null,
|
|
1899
|
+
safetyRatings: (_p = candidate == null ? void 0 : candidate.safetyRatings) != null ? _p : null,
|
|
1897
1900
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
1898
|
-
finishMessage: (
|
|
1899
|
-
serviceTier: (
|
|
1901
|
+
finishMessage: (_q = candidate == null ? void 0 : candidate.finishMessage) != null ? _q : null,
|
|
1902
|
+
serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
|
|
1900
1903
|
}),
|
|
1901
1904
|
response: {
|
|
1902
1905
|
// TODO timestamp, model id
|
|
1903
|
-
id: (
|
|
1906
|
+
id: (_s = response.responseId) != null ? _s : void 0
|
|
1904
1907
|
}
|
|
1905
1908
|
};
|
|
1906
1909
|
}
|
|
@@ -2015,7 +2018,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2015
2018
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2016
2019
|
},
|
|
2017
2020
|
transform(chunk, controller) {
|
|
2018
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2021
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2019
2022
|
if (options.includeRawChunks) {
|
|
2020
2023
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2021
2024
|
}
|
|
@@ -2037,6 +2040,22 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2037
2040
|
}
|
|
2038
2041
|
const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
|
|
2039
2042
|
if (candidate == null) {
|
|
2043
|
+
const promptBlockReason2 = (_b = value.promptFeedback) == null ? void 0 : _b.blockReason;
|
|
2044
|
+
if (promptBlockReason2 != null) {
|
|
2045
|
+
finishReason = {
|
|
2046
|
+
unified: "content-filter",
|
|
2047
|
+
raw: promptBlockReason2
|
|
2048
|
+
};
|
|
2049
|
+
providerMetadata = wrapProviderMetadata({
|
|
2050
|
+
promptFeedback: (_c = value.promptFeedback) != null ? _c : null,
|
|
2051
|
+
groundingMetadata: lastGroundingMetadata,
|
|
2052
|
+
urlContextMetadata: lastUrlContextMetadata,
|
|
2053
|
+
safetyRatings: null,
|
|
2054
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2055
|
+
finishMessage: null,
|
|
2056
|
+
serviceTier: (_d = usage == null ? void 0 : usage.serviceTier) != null ? _d : null
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2040
2059
|
return;
|
|
2041
2060
|
}
|
|
2042
2061
|
const content = candidate.content;
|
|
@@ -2059,9 +2078,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2059
2078
|
}
|
|
2060
2079
|
}
|
|
2061
2080
|
if (content != null) {
|
|
2062
|
-
const parts = (
|
|
2081
|
+
const parts = (_e = content.parts) != null ? _e : [];
|
|
2063
2082
|
for (const part of parts) {
|
|
2064
|
-
if ("executableCode" in part && ((
|
|
2083
|
+
if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
|
|
2065
2084
|
const toolCallId = generateId2();
|
|
2066
2085
|
lastCodeExecutionToolCallId = toolCallId;
|
|
2067
2086
|
controller.enqueue({
|
|
@@ -2080,7 +2099,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2080
2099
|
toolName: "code_execution",
|
|
2081
2100
|
result: {
|
|
2082
2101
|
outcome: part.codeExecutionResult.outcome,
|
|
2083
|
-
output: (
|
|
2102
|
+
output: (_g = part.codeExecutionResult.output) != null ? _g : ""
|
|
2084
2103
|
}
|
|
2085
2104
|
});
|
|
2086
2105
|
}
|
|
@@ -2180,7 +2199,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2180
2199
|
type: "tool-call",
|
|
2181
2200
|
toolCallId,
|
|
2182
2201
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2183
|
-
input: JSON.stringify((
|
|
2202
|
+
input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
|
|
2184
2203
|
providerExecuted: true,
|
|
2185
2204
|
dynamic: true,
|
|
2186
2205
|
providerMetadata: serverMeta
|
|
@@ -2196,7 +2215,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2196
2215
|
type: "tool-result",
|
|
2197
2216
|
toolCallId: responseToolCallId,
|
|
2198
2217
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2199
|
-
result: (
|
|
2218
|
+
result: (_i = part.toolResponse.response) != null ? _i : {},
|
|
2200
2219
|
providerMetadata: serverMeta
|
|
2201
2220
|
});
|
|
2202
2221
|
lastServerToolCallId = void 0;
|
|
@@ -2263,7 +2282,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2263
2282
|
} else if (isCompleteCall) {
|
|
2264
2283
|
const toolCallId = part.functionCall.id || generateId2();
|
|
2265
2284
|
const toolName = part.functionCall.name;
|
|
2266
|
-
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((
|
|
2285
|
+
const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_j = part.functionCall.args) != null ? _j : {});
|
|
2267
2286
|
controller.enqueue({
|
|
2268
2287
|
type: "tool-input-start",
|
|
2269
2288
|
id: toolCallId,
|
|
@@ -2314,22 +2333,25 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2314
2333
|
}
|
|
2315
2334
|
}
|
|
2316
2335
|
}
|
|
2317
|
-
|
|
2336
|
+
const promptBlockReason = (_k = value.promptFeedback) == null ? void 0 : _k.blockReason;
|
|
2337
|
+
const isPromptBlocked = candidate.finishReason == null && promptBlockReason != null;
|
|
2338
|
+
const rawFinishReason = (_m = (_l = candidate.finishReason) != null ? _l : promptBlockReason) != null ? _m : void 0;
|
|
2339
|
+
if (rawFinishReason != null) {
|
|
2318
2340
|
finishReason = {
|
|
2319
|
-
unified: mapGoogleFinishReason({
|
|
2320
|
-
finishReason:
|
|
2341
|
+
unified: isPromptBlocked ? "content-filter" : mapGoogleFinishReason({
|
|
2342
|
+
finishReason: rawFinishReason,
|
|
2321
2343
|
hasToolCalls
|
|
2322
2344
|
}),
|
|
2323
|
-
raw:
|
|
2345
|
+
raw: rawFinishReason
|
|
2324
2346
|
};
|
|
2325
2347
|
providerMetadata = wrapProviderMetadata({
|
|
2326
|
-
promptFeedback: (
|
|
2348
|
+
promptFeedback: (_n = value.promptFeedback) != null ? _n : null,
|
|
2327
2349
|
groundingMetadata: lastGroundingMetadata,
|
|
2328
2350
|
urlContextMetadata: lastUrlContextMetadata,
|
|
2329
|
-
safetyRatings: (
|
|
2351
|
+
safetyRatings: (_o = candidate.safetyRatings) != null ? _o : null,
|
|
2330
2352
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2331
|
-
finishMessage: (
|
|
2332
|
-
serviceTier: (
|
|
2353
|
+
finishMessage: (_p = candidate.finishMessage) != null ? _p : null,
|
|
2354
|
+
serviceTier: (_q = usage == null ? void 0 : usage.serviceTier) != null ? _q : null
|
|
2333
2355
|
});
|
|
2334
2356
|
}
|
|
2335
2357
|
},
|
|
@@ -2697,7 +2719,7 @@ var responseSchema = lazySchema3(
|
|
|
2697
2719
|
groundingMetadata: getGroundingMetadataSchema().nullish(),
|
|
2698
2720
|
urlContextMetadata: getUrlContextMetadataSchema().nullish()
|
|
2699
2721
|
})
|
|
2700
|
-
),
|
|
2722
|
+
).nullish(),
|
|
2701
2723
|
usageMetadata: usageSchema.nullish(),
|
|
2702
2724
|
promptFeedback: z3.object({
|
|
2703
2725
|
blockReason: z3.string().nullish(),
|