@ai-sdk/google 4.0.63 → 4.0.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 +7 -0
- package/dist/index.js +54 -24
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -2
- package/dist/internal/index.js +53 -23
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/convert-json-schema-to-openapi-schema.ts +10 -0
- package/src/google-language-model.ts +35 -8
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.
|
|
10
|
+
var VERSION = true ? "4.0.64" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -283,6 +283,7 @@ function getModelPath(modelId) {
|
|
|
283
283
|
// src/google-language-model.ts
|
|
284
284
|
import {
|
|
285
285
|
combineHeaders as combineHeaders2,
|
|
286
|
+
createToolNameMapping,
|
|
286
287
|
createEventSourceResponseHandler,
|
|
287
288
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
288
289
|
generateId,
|
|
@@ -379,6 +380,8 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
379
380
|
format,
|
|
380
381
|
const: constValue,
|
|
381
382
|
minLength,
|
|
383
|
+
minItems,
|
|
384
|
+
maxItems,
|
|
382
385
|
enum: enumValues
|
|
383
386
|
} = jsonSchema;
|
|
384
387
|
const result = {};
|
|
@@ -461,6 +464,12 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
461
464
|
if (minLength !== void 0) {
|
|
462
465
|
result.minLength = minLength;
|
|
463
466
|
}
|
|
467
|
+
if (minItems !== void 0) {
|
|
468
|
+
result.minItems = minItems;
|
|
469
|
+
}
|
|
470
|
+
if (maxItems !== void 0) {
|
|
471
|
+
result.maxItems = maxItems;
|
|
472
|
+
}
|
|
464
473
|
return result;
|
|
465
474
|
}
|
|
466
475
|
function convertJSONSchemaReference({
|
|
@@ -1956,6 +1965,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1956
1965
|
modelId: this.modelId,
|
|
1957
1966
|
isVertexProvider
|
|
1958
1967
|
});
|
|
1968
|
+
const toolNameMapping = createToolNameMapping({
|
|
1969
|
+
tools,
|
|
1970
|
+
providerToolNames: {
|
|
1971
|
+
"google.code_execution": "code_execution"
|
|
1972
|
+
}
|
|
1973
|
+
});
|
|
1959
1974
|
const resolvedThinking = resolveThinkingConfig({
|
|
1960
1975
|
reasoning,
|
|
1961
1976
|
modelId: this.modelId,
|
|
@@ -2020,15 +2035,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2020
2035
|
},
|
|
2021
2036
|
warnings: [...warnings, ...toolWarnings],
|
|
2022
2037
|
providerOptionsNames,
|
|
2023
|
-
extraHeaders: vertexPaygoHeaders
|
|
2038
|
+
extraHeaders: vertexPaygoHeaders,
|
|
2039
|
+
toolNameMapping
|
|
2024
2040
|
};
|
|
2025
2041
|
}
|
|
2026
2042
|
convertGenerateContentResponse({
|
|
2027
2043
|
response,
|
|
2028
2044
|
warnings,
|
|
2029
|
-
providerOptionsNames
|
|
2045
|
+
providerOptionsNames,
|
|
2046
|
+
toolNameMapping
|
|
2030
2047
|
}) {
|
|
2031
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2048
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2032
2049
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
2033
2050
|
providerOptionsNames.map((name) => [name, payload])
|
|
2034
2051
|
);
|
|
@@ -2048,7 +2065,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2048
2065
|
content.push({
|
|
2049
2066
|
type: "tool-call",
|
|
2050
2067
|
toolCallId,
|
|
2051
|
-
toolName: "code_execution",
|
|
2068
|
+
toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
|
|
2052
2069
|
input: JSON.stringify(part.executableCode),
|
|
2053
2070
|
providerExecuted: true
|
|
2054
2071
|
});
|
|
@@ -2057,10 +2074,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2057
2074
|
type: "tool-result",
|
|
2058
2075
|
// Results correspond to the most recent executable code part.
|
|
2059
2076
|
toolCallId: lastCodeExecutionToolCallId,
|
|
2060
|
-
toolName: "code_execution",
|
|
2077
|
+
toolName: (_i = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _i : "code_execution",
|
|
2061
2078
|
result: {
|
|
2062
2079
|
outcome: part.codeExecutionResult.outcome,
|
|
2063
|
-
output: (
|
|
2080
|
+
output: (_j = part.codeExecutionResult.output) != null ? _j : ""
|
|
2064
2081
|
}
|
|
2065
2082
|
});
|
|
2066
2083
|
} else if ("text" in part && part.text != null) {
|
|
@@ -2084,7 +2101,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2084
2101
|
type: "tool-call",
|
|
2085
2102
|
toolCallId: part.functionCall.id || this.config.generateId(),
|
|
2086
2103
|
toolName: part.functionCall.name,
|
|
2087
|
-
input: JSON.stringify((
|
|
2104
|
+
input: JSON.stringify((_k = part.functionCall.args) != null ? _k : {}),
|
|
2088
2105
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
2089
2106
|
thoughtSignature: part.thoughtSignature
|
|
2090
2107
|
}) : void 0
|
|
@@ -2107,7 +2124,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2107
2124
|
type: "tool-call",
|
|
2108
2125
|
toolCallId,
|
|
2109
2126
|
toolName: `server:${part.toolCall.toolType}`,
|
|
2110
|
-
input: JSON.stringify((
|
|
2127
|
+
input: JSON.stringify((_l = part.toolCall.args) != null ? _l : {}),
|
|
2111
2128
|
providerExecuted: true,
|
|
2112
2129
|
dynamic: true,
|
|
2113
2130
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
@@ -2125,7 +2142,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2125
2142
|
type: "tool-result",
|
|
2126
2143
|
toolCallId: responseToolCallId,
|
|
2127
2144
|
toolName: `server:${part.toolResponse.toolType}`,
|
|
2128
|
-
result: (
|
|
2145
|
+
result: (_m = part.toolResponse.response) != null ? _m : {},
|
|
2129
2146
|
providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
|
|
2130
2147
|
thoughtSignature: part.thoughtSignature,
|
|
2131
2148
|
serverToolCallId: responseToolCallId,
|
|
@@ -2138,10 +2155,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2138
2155
|
lastServerToolCallId = void 0;
|
|
2139
2156
|
}
|
|
2140
2157
|
}
|
|
2141
|
-
const sources = (
|
|
2158
|
+
const sources = (_n = extractSources({
|
|
2142
2159
|
groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
|
|
2143
2160
|
generateId: this.config.generateId
|
|
2144
|
-
})) != null ?
|
|
2161
|
+
})) != null ? _n : [];
|
|
2145
2162
|
for (const source of sources) {
|
|
2146
2163
|
content.push(source);
|
|
2147
2164
|
}
|
|
@@ -2160,22 +2177,28 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2160
2177
|
usage: convertGoogleUsage(usageMetadata),
|
|
2161
2178
|
warnings,
|
|
2162
2179
|
providerMetadata: wrapProviderMetadata({
|
|
2163
|
-
promptFeedback: (
|
|
2164
|
-
groundingMetadata: (
|
|
2165
|
-
urlContextMetadata: (
|
|
2166
|
-
safetyRatings: (
|
|
2180
|
+
promptFeedback: (_o = response.promptFeedback) != null ? _o : null,
|
|
2181
|
+
groundingMetadata: (_p = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _p : null,
|
|
2182
|
+
urlContextMetadata: (_q = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _q : null,
|
|
2183
|
+
safetyRatings: (_r = candidate == null ? void 0 : candidate.safetyRatings) != null ? _r : null,
|
|
2167
2184
|
usageMetadata: usageMetadata != null ? usageMetadata : null,
|
|
2168
|
-
finishMessage: (
|
|
2169
|
-
serviceTier: (
|
|
2185
|
+
finishMessage: (_s = candidate == null ? void 0 : candidate.finishMessage) != null ? _s : null,
|
|
2186
|
+
serviceTier: (_t = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _t : null
|
|
2170
2187
|
}),
|
|
2171
2188
|
response: {
|
|
2172
2189
|
// TODO timestamp, model id
|
|
2173
|
-
id: (
|
|
2190
|
+
id: (_u = response.responseId) != null ? _u : void 0
|
|
2174
2191
|
}
|
|
2175
2192
|
};
|
|
2176
2193
|
}
|
|
2177
2194
|
async doGenerate(options) {
|
|
2178
|
-
const {
|
|
2195
|
+
const {
|
|
2196
|
+
args,
|
|
2197
|
+
warnings,
|
|
2198
|
+
providerOptionsNames,
|
|
2199
|
+
extraHeaders,
|
|
2200
|
+
toolNameMapping
|
|
2201
|
+
} = await this.getArgs(options);
|
|
2179
2202
|
const mergedHeaders = combineHeaders2(
|
|
2180
2203
|
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
2181
2204
|
options.headers,
|
|
@@ -2199,7 +2222,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2199
2222
|
const result = this.convertGenerateContentResponse({
|
|
2200
2223
|
response,
|
|
2201
2224
|
warnings,
|
|
2202
|
-
providerOptionsNames
|
|
2225
|
+
providerOptionsNames,
|
|
2226
|
+
toolNameMapping
|
|
2203
2227
|
});
|
|
2204
2228
|
return {
|
|
2205
2229
|
...result,
|
|
@@ -2212,7 +2236,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2212
2236
|
};
|
|
2213
2237
|
}
|
|
2214
2238
|
async doStream(options) {
|
|
2215
|
-
const {
|
|
2239
|
+
const {
|
|
2240
|
+
args,
|
|
2241
|
+
warnings,
|
|
2242
|
+
providerOptionsNames,
|
|
2243
|
+
extraHeaders,
|
|
2244
|
+
toolNameMapping
|
|
2245
|
+
} = await this.getArgs(options, { isStreaming: true });
|
|
2216
2246
|
const wrapProviderMetadata = (payload) => Object.fromEntries(
|
|
2217
2247
|
providerOptionsNames.map((name) => [name, payload])
|
|
2218
2248
|
);
|
|
@@ -2353,7 +2383,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2353
2383
|
controller.enqueue({
|
|
2354
2384
|
type: "tool-call",
|
|
2355
2385
|
toolCallId,
|
|
2356
|
-
toolName: "code_execution",
|
|
2386
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2357
2387
|
input: JSON.stringify(part.executableCode),
|
|
2358
2388
|
providerExecuted: true
|
|
2359
2389
|
});
|
|
@@ -2363,7 +2393,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2363
2393
|
controller.enqueue({
|
|
2364
2394
|
type: "tool-result",
|
|
2365
2395
|
toolCallId,
|
|
2366
|
-
toolName: "code_execution",
|
|
2396
|
+
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
2367
2397
|
result: {
|
|
2368
2398
|
outcome: part.codeExecutionResult.outcome,
|
|
2369
2399
|
output: (_g = part.codeExecutionResult.output) != null ? _g : ""
|