@gullabs/google 0.5.2 → 0.6.1
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/README.md +25 -4
- package/dist/index.cjs +264 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +265 -59
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -44,13 +44,33 @@ const result = await client.generate(
|
|
|
44
44
|
## What it maps
|
|
45
45
|
|
|
46
46
|
- `serviceTier: 'flex'` → Gemini Flex service tier when the model descriptor supports it
|
|
47
|
+
- omitted `serviceTier` → provider-default request behavior
|
|
47
48
|
- `reasoning.includeThoughts` → `thinkingConfig.includeThoughts`; thought parts become `reasoningText`
|
|
48
|
-
- `reasoning.effort` → `thinkingBudget` (
|
|
49
|
+
- `reasoning.effort` → `thinkingBudget` (Gemini 2.5) or `thinkingLevel` (Gemini 3 / Gemma 4)
|
|
50
|
+
- `reasoning.budgetTokens` → admitted only on Gemini 2.5 budget-api models; strict descriptors reject it on level-api models
|
|
49
51
|
- `output.jsonSchema` → `responseMimeType: 'application/json'` + verbatim `responseSchema` when native structured output is enabled; the engine returns parsed output and `outputParsed` without validating shape
|
|
50
|
-
- `providerOptions.google.*` →
|
|
52
|
+
- `providerOptions.google.*` → typed provider-extension lane for admitted keys such as `cachedContent`, `safetySettings`, and exact tool declarations
|
|
51
53
|
- Usage: `promptTokenCount`→`inputTokens`, `candidatesTokenCount`+`thoughtsTokenCount`→`outputTokens` (GROSS)
|
|
52
54
|
- Errors: `401/403`→`invalid_auth`, `429`→`rate_limited`, `5xx`→`server`, timeouts, safety blocks
|
|
53
55
|
|
|
56
|
+
## Strict model-config expectations
|
|
57
|
+
|
|
58
|
+
This adapter expects config that has already been parsed through the selected
|
|
59
|
+
descriptor boundary:
|
|
60
|
+
|
|
61
|
+
- `descriptor.configSchema` is the runtime source of truth.
|
|
62
|
+
- `descriptor.configJsonSchema` is the derived form/UI schema.
|
|
63
|
+
- `providerOptions.google` is not a caller-wins override lane for
|
|
64
|
+
`serviceTier`, sampling, reasoning, or response schema.
|
|
65
|
+
- `priority` stays rejected even though Google documents it, because the
|
|
66
|
+
library has not yet shipped the matching schema, pricing, served-tier
|
|
67
|
+
recording, and tests.
|
|
68
|
+
|
|
69
|
+
For structured output with built-in tools, follow the exact public
|
|
70
|
+
`generateContent` evidence: the current docs only admit that combination for
|
|
71
|
+
`gemini-3.1-pro-preview` and `gemini-3.5-flash`. Other models should fail early
|
|
72
|
+
instead of relying on adapter repair or provider-side surprises.
|
|
73
|
+
|
|
54
74
|
## Gemma 4
|
|
55
75
|
|
|
56
76
|
The default registry includes two API-verified Gemma 4 models: `gemma-4-31b-it`
|
|
@@ -72,8 +92,9 @@ This follows the library-wide **reject, don't map** rule: unsupported or incorre
|
|
|
72
92
|
typed `bad_request` `LlmError` at validation time rather than being silently clamped or coerced
|
|
73
93
|
into something the model happens to accept.
|
|
74
94
|
|
|
75
|
-
Gemma 4 models
|
|
76
|
-
|
|
95
|
+
Gemma 4 models are intentionally unpriced (`cost.microUsd` will be `null`), and
|
|
96
|
+
the strict contract does not admit any `serviceTier` for them until the public
|
|
97
|
+
docs and live evidence line up on that field.
|
|
77
98
|
|
|
78
99
|
## Learn more
|
|
79
100
|
|
package/dist/index.cjs
CHANGED
|
@@ -3,14 +3,22 @@
|
|
|
3
3
|
var core = require('@gullabs/core');
|
|
4
4
|
|
|
5
5
|
// src/adapter.ts
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
function requireApiKey(auth) {
|
|
7
|
+
if (!("apiKey" in auth) || typeof auth.apiKey !== "string" || auth.apiKey.trim() === "") {
|
|
8
|
+
throw new core.LlmError("@gullabs/google requires auth.apiKey", {
|
|
9
|
+
kind: "invalid_auth",
|
|
10
|
+
retryable: false,
|
|
11
|
+
provider: "google"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return auth.apiKey;
|
|
15
|
+
}
|
|
8
16
|
var FLEX_DEFAULT_TIMEOUT_MS = 15e5;
|
|
9
17
|
var STANDARD_DEFAULT_TIMEOUT_MS = 3e5;
|
|
10
18
|
var TRANSPORT_TIMEOUT_BUFFER_MS = 5e3;
|
|
11
19
|
async function buildGoogleClient(auth) {
|
|
12
20
|
const { GoogleGenAI } = await import('@google/genai');
|
|
13
|
-
const ai = new GoogleGenAI({ apiKey: auth
|
|
21
|
+
const ai = new GoogleGenAI({ apiKey: requireApiKey(auth) });
|
|
14
22
|
return {
|
|
15
23
|
models: {
|
|
16
24
|
async generateContent(params) {
|
|
@@ -21,6 +29,14 @@ async function buildGoogleClient(auth) {
|
|
|
21
29
|
};
|
|
22
30
|
}
|
|
23
31
|
|
|
32
|
+
// src/reasoning-budget.ts
|
|
33
|
+
var GOOGLE_REASONING_EFFORT_BUDGET = {
|
|
34
|
+
none: 0,
|
|
35
|
+
low: 1024,
|
|
36
|
+
medium: 8192,
|
|
37
|
+
high: 24576
|
|
38
|
+
};
|
|
39
|
+
|
|
24
40
|
// src/flex-fallback.ts
|
|
25
41
|
var CAPACITY_PATTERNS = [
|
|
26
42
|
/capacity/i,
|
|
@@ -51,6 +67,231 @@ function isGeminiCapacityError(err) {
|
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
// src/adapter.ts
|
|
70
|
+
var ALLOWED_GOOGLE_PROVIDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
71
|
+
"cachedContent",
|
|
72
|
+
"httpOptions",
|
|
73
|
+
"safetySettings",
|
|
74
|
+
"tools"
|
|
75
|
+
]);
|
|
76
|
+
var ALLOWED_GOOGLE_HTTP_OPTION_KEYS = /* @__PURE__ */ new Set(["timeout"]);
|
|
77
|
+
var RESERVED_GOOGLE_PROVIDER_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
78
|
+
"abortSignal",
|
|
79
|
+
"imageConfig",
|
|
80
|
+
"maxOutputTokens",
|
|
81
|
+
"mediaResolution",
|
|
82
|
+
"responseFormat",
|
|
83
|
+
"responseMimeType",
|
|
84
|
+
"responseModalities",
|
|
85
|
+
"responseSchema",
|
|
86
|
+
"responseJsonSchema",
|
|
87
|
+
"serviceTier",
|
|
88
|
+
"speechConfig",
|
|
89
|
+
"stopSequences",
|
|
90
|
+
"temperature",
|
|
91
|
+
"thinkingConfig",
|
|
92
|
+
"topK",
|
|
93
|
+
"topP",
|
|
94
|
+
"_responseJsonSchema"
|
|
95
|
+
]);
|
|
96
|
+
var GOOGLE_SEARCH_SUPPORTED_MODELS = /* @__PURE__ */ new Set([
|
|
97
|
+
"gemini-2.5-flash",
|
|
98
|
+
"gemini-2.5-flash-lite",
|
|
99
|
+
"gemini-2.5-pro",
|
|
100
|
+
"gemini-3-flash-preview",
|
|
101
|
+
"gemini-3.1-flash-lite",
|
|
102
|
+
"gemini-3.1-pro-preview",
|
|
103
|
+
"gemini-3.5-flash"
|
|
104
|
+
]);
|
|
105
|
+
var STRUCTURED_OUTPUT_GOOGLE_SEARCH_ALLOWLIST = /* @__PURE__ */ new Set([
|
|
106
|
+
"gemini-3.1-pro-preview",
|
|
107
|
+
"gemini-3.5-flash"
|
|
108
|
+
]);
|
|
109
|
+
function isPlainRecord(value) {
|
|
110
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
111
|
+
}
|
|
112
|
+
function isEmptyPlainObject(value) {
|
|
113
|
+
return isPlainRecord(value) && Object.keys(value).length === 0;
|
|
114
|
+
}
|
|
115
|
+
function badGoogleProviderOptions(message) {
|
|
116
|
+
return new core.LlmError(message, { kind: "bad_request", retryable: false });
|
|
117
|
+
}
|
|
118
|
+
function parseGoogleTool(tool, model) {
|
|
119
|
+
if (!isPlainRecord(tool)) {
|
|
120
|
+
throw badGoogleProviderOptions(
|
|
121
|
+
`providerOptions.google.tools entries must be objects for model "${model}".`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
const keys = Object.keys(tool);
|
|
125
|
+
if (keys.length !== 1) {
|
|
126
|
+
throw badGoogleProviderOptions(
|
|
127
|
+
`providerOptions.google.tools entries must have exactly one supported tool key for model "${model}".`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
const key = keys[0];
|
|
131
|
+
switch (key) {
|
|
132
|
+
case "googleSearch": {
|
|
133
|
+
if (!isEmptyPlainObject(tool["googleSearch"])) {
|
|
134
|
+
throw badGoogleProviderOptions(
|
|
135
|
+
`providerOptions.google.tools[].googleSearch must be an empty object for model "${model}".`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return { googleSearch: {} };
|
|
139
|
+
}
|
|
140
|
+
default:
|
|
141
|
+
throw badGoogleProviderOptions(
|
|
142
|
+
`providerOptions.google.tools[].${key} is not supported for model "${model}".`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function parseGoogleSafetySetting(setting, index, model) {
|
|
147
|
+
if (!isPlainRecord(setting)) {
|
|
148
|
+
throw badGoogleProviderOptions(
|
|
149
|
+
`providerOptions.google.safetySettings[${index}] must be an object for model "${model}".`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const keys = Object.keys(setting);
|
|
153
|
+
const unknownKeys = keys.filter((key) => key !== "category" && key !== "threshold");
|
|
154
|
+
if (unknownKeys.length > 0) {
|
|
155
|
+
throw badGoogleProviderOptions(
|
|
156
|
+
`providerOptions.google.safetySettings[${index}] contains unsupported keys [${unknownKeys.join(
|
|
157
|
+
", "
|
|
158
|
+
)}] for model "${model}". Allowed keys: category, threshold.`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
if (typeof setting["category"] !== "string" || setting["category"].length === 0) {
|
|
162
|
+
throw badGoogleProviderOptions(
|
|
163
|
+
`providerOptions.google.safetySettings[${index}].category must be a non-empty string for model "${model}".`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (typeof setting["threshold"] !== "string" || setting["threshold"].length === 0) {
|
|
167
|
+
throw badGoogleProviderOptions(
|
|
168
|
+
`providerOptions.google.safetySettings[${index}].threshold must be a non-empty string for model "${model}".`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
category: setting["category"],
|
|
173
|
+
threshold: setting["threshold"]
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function mapGoogleProviderOptions(googleOpts, model, structuredOutputRequested, descriptorGrounding) {
|
|
177
|
+
if (googleOpts === void 0) {
|
|
178
|
+
return {};
|
|
179
|
+
}
|
|
180
|
+
if (!isPlainRecord(googleOpts)) {
|
|
181
|
+
throw badGoogleProviderOptions(
|
|
182
|
+
`providerOptions.google must be an object for model "${model}".`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const reservedKeys = Object.keys(googleOpts).filter(
|
|
186
|
+
(key) => RESERVED_GOOGLE_PROVIDER_OPTION_KEYS.has(key)
|
|
187
|
+
);
|
|
188
|
+
if (reservedKeys.length > 0) {
|
|
189
|
+
throw badGoogleProviderOptions(
|
|
190
|
+
`providerOptions.google reserves keys [${reservedKeys.join(
|
|
191
|
+
", "
|
|
192
|
+
)}] for typed model config on "${model}".`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
const unknownKeys = Object.keys(googleOpts).filter(
|
|
196
|
+
(key) => !ALLOWED_GOOGLE_PROVIDER_OPTION_KEYS.has(key) && !RESERVED_GOOGLE_PROVIDER_OPTION_KEYS.has(key)
|
|
197
|
+
);
|
|
198
|
+
if (unknownKeys.length > 0) {
|
|
199
|
+
throw badGoogleProviderOptions(
|
|
200
|
+
`providerOptions.google contains unsupported keys [${unknownKeys.join(
|
|
201
|
+
", "
|
|
202
|
+
)}] for model "${model}". Allowed keys: cachedContent, httpOptions, safetySettings, tools.`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
const mapped = {};
|
|
206
|
+
if (googleOpts["cachedContent"] !== void 0) {
|
|
207
|
+
if (typeof googleOpts["cachedContent"] !== "string" || googleOpts["cachedContent"].length === 0) {
|
|
208
|
+
throw badGoogleProviderOptions(
|
|
209
|
+
`providerOptions.google.cachedContent must be a non-empty string for model "${model}".`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
mapped.cachedContent = googleOpts["cachedContent"];
|
|
213
|
+
}
|
|
214
|
+
if (googleOpts["httpOptions"] !== void 0) {
|
|
215
|
+
if (!isPlainRecord(googleOpts["httpOptions"])) {
|
|
216
|
+
throw badGoogleProviderOptions(
|
|
217
|
+
`providerOptions.google.httpOptions must be an object for model "${model}".`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
const unknownHttpOptionKeys = Object.keys(googleOpts["httpOptions"]).filter(
|
|
221
|
+
(key) => !ALLOWED_GOOGLE_HTTP_OPTION_KEYS.has(key)
|
|
222
|
+
);
|
|
223
|
+
if (unknownHttpOptionKeys.length > 0) {
|
|
224
|
+
throw badGoogleProviderOptions(
|
|
225
|
+
`providerOptions.google.httpOptions contains unsupported keys [${unknownHttpOptionKeys.join(
|
|
226
|
+
", "
|
|
227
|
+
)}] for model "${model}". Allowed keys: timeout.`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const timeout = googleOpts["httpOptions"]["timeout"];
|
|
231
|
+
if (timeout !== void 0) {
|
|
232
|
+
if (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout <= 0) {
|
|
233
|
+
throw badGoogleProviderOptions(
|
|
234
|
+
`providerOptions.google.httpOptions.timeout must be a positive integer for model "${model}".`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
mapped.httpOptions = { timeout };
|
|
238
|
+
} else {
|
|
239
|
+
mapped.httpOptions = {};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (googleOpts["safetySettings"] !== void 0) {
|
|
243
|
+
if (!Array.isArray(googleOpts["safetySettings"])) {
|
|
244
|
+
throw badGoogleProviderOptions(
|
|
245
|
+
`providerOptions.google.safetySettings must be an array for model "${model}".`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
mapped.safetySettings = googleOpts["safetySettings"].map(
|
|
249
|
+
(setting, index) => parseGoogleSafetySetting(setting, index, model)
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
if (googleOpts["tools"] !== void 0) {
|
|
253
|
+
if (!Array.isArray(googleOpts["tools"])) {
|
|
254
|
+
throw badGoogleProviderOptions(
|
|
255
|
+
`providerOptions.google.tools must be an array for model "${model}".`
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
const tools = googleOpts["tools"].map((tool) => parseGoogleTool(tool, model));
|
|
259
|
+
const groundingSupported = descriptorGrounding === true || descriptorGrounding === void 0 && GOOGLE_SEARCH_SUPPORTED_MODELS.has(model);
|
|
260
|
+
if (!groundingSupported) {
|
|
261
|
+
throw badGoogleProviderOptions(
|
|
262
|
+
`providerOptions.google.tools is not supported for model "${model}".`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (structuredOutputRequested && !STRUCTURED_OUTPUT_GOOGLE_SEARCH_ALLOWLIST.has(model)) {
|
|
266
|
+
throw badGoogleProviderOptions(
|
|
267
|
+
`Structured output with googleSearch is supported only for models "gemini-3.1-pro-preview" and "gemini-3.5-flash"; got "${model}".`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
mapped.tools = tools;
|
|
271
|
+
}
|
|
272
|
+
return mapped;
|
|
273
|
+
}
|
|
274
|
+
function assertSamplingAllowed(config, model, sampling) {
|
|
275
|
+
if (sampling !== "fixed") {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const offendingSampling = [];
|
|
279
|
+
if ("temperature" in config) {
|
|
280
|
+
offendingSampling.push("temperature");
|
|
281
|
+
}
|
|
282
|
+
if ("topP" in config) {
|
|
283
|
+
offendingSampling.push("topP");
|
|
284
|
+
}
|
|
285
|
+
if ("topK" in config) {
|
|
286
|
+
offendingSampling.push("topK");
|
|
287
|
+
}
|
|
288
|
+
if (offendingSampling.length > 0) {
|
|
289
|
+
throw new core.LlmError(
|
|
290
|
+
`Sampling parameters [${offendingSampling.join(", ")}] are not supported for model "${model}" (fixed sampling).`,
|
|
291
|
+
{ kind: "bad_request", retryable: false }
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
54
295
|
function mapFinishReason(raw) {
|
|
55
296
|
if (raw === void 0) return void 0;
|
|
56
297
|
switch (raw) {
|
|
@@ -172,12 +413,6 @@ function geminiAdapter(opts) {
|
|
|
172
413
|
);
|
|
173
414
|
}
|
|
174
415
|
config.serviceTier = explicit;
|
|
175
|
-
} else {
|
|
176
|
-
if (req.modelDescriptor === void 0) {
|
|
177
|
-
config.serviceTier = "flex";
|
|
178
|
-
} else if (supported?.includes("flex") === true) {
|
|
179
|
-
config.serviceTier = "flex";
|
|
180
|
-
}
|
|
181
416
|
}
|
|
182
417
|
const reasoning = genConfig.reasoning;
|
|
183
418
|
if (reasoning !== void 0) {
|
|
@@ -189,7 +424,7 @@ function geminiAdapter(opts) {
|
|
|
189
424
|
);
|
|
190
425
|
}
|
|
191
426
|
if (reasoningApi === "budget") {
|
|
192
|
-
const budget = reasoning.budgetTokens !== void 0 ? reasoning.budgetTokens : reasoning.effort !== void 0 ?
|
|
427
|
+
const budget = reasoning.budgetTokens !== void 0 ? reasoning.budgetTokens : reasoning.effort !== void 0 ? GOOGLE_REASONING_EFFORT_BUDGET[reasoning.effort] : void 0;
|
|
193
428
|
config.thinkingConfig = {
|
|
194
429
|
...budget !== void 0 ? { thinkingBudget: budget } : {},
|
|
195
430
|
...reasoning.includeThoughts === true ? { includeThoughts: true } : {}
|
|
@@ -239,54 +474,25 @@ function geminiAdapter(opts) {
|
|
|
239
474
|
config.responseSchema = req.outputJsonSchema;
|
|
240
475
|
}
|
|
241
476
|
}
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
477
|
+
const googleProviderConfig = mapGoogleProviderOptions(
|
|
478
|
+
genConfig.providerOptions?.["google"],
|
|
479
|
+
model,
|
|
480
|
+
structuredOutputRequested,
|
|
481
|
+
req.modelDescriptor?.capabilities?.grounding
|
|
482
|
+
);
|
|
483
|
+
if (googleProviderConfig.cachedContent !== void 0) {
|
|
484
|
+
config.cachedContent = googleProviderConfig.cachedContent;
|
|
245
485
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const supportedAfterMerge = req.modelDescriptor.capabilities?.serviceTiers;
|
|
249
|
-
if (supportedAfterMerge === void 0 || !supportedAfterMerge.includes(mergedServiceTier)) {
|
|
250
|
-
throw new core.LlmError(
|
|
251
|
-
`serviceTier "${mergedServiceTier}" is not supported for model "${model}".`,
|
|
252
|
-
{ kind: "bad_request", retryable: false }
|
|
253
|
-
);
|
|
254
|
-
}
|
|
486
|
+
if (googleProviderConfig.httpOptions !== void 0) {
|
|
487
|
+
config.httpOptions = googleProviderConfig.httpOptions;
|
|
255
488
|
}
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
if ("temperature" in config) {
|
|
259
|
-
offendingSampling.push("temperature");
|
|
260
|
-
}
|
|
261
|
-
if ("topP" in config) {
|
|
262
|
-
offendingSampling.push("topP");
|
|
263
|
-
}
|
|
264
|
-
if ("topK" in config) {
|
|
265
|
-
offendingSampling.push("topK");
|
|
266
|
-
}
|
|
267
|
-
if (offendingSampling.length > 0) {
|
|
268
|
-
throw new core.LlmError(
|
|
269
|
-
`Sampling parameters [${offendingSampling.join(
|
|
270
|
-
", "
|
|
271
|
-
)}] are not supported for model "${model}" (fixed sampling); they were supplied via providerOptions.google.`,
|
|
272
|
-
{ kind: "bad_request", retryable: false }
|
|
273
|
-
);
|
|
274
|
-
}
|
|
489
|
+
if (googleProviderConfig.safetySettings !== void 0) {
|
|
490
|
+
config.safetySettings = googleProviderConfig.safetySettings;
|
|
275
491
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (t !== null && typeof t === "object") {
|
|
279
|
-
const tool = t;
|
|
280
|
-
return "googleSearch" in tool || "googleSearchRetrieval" in tool;
|
|
281
|
-
}
|
|
282
|
-
return false;
|
|
283
|
-
});
|
|
284
|
-
if (groundingRequested && structuredOutputRequested) {
|
|
285
|
-
throw new core.LlmError(
|
|
286
|
-
"Grounding (googleSearch) cannot be combined with structured output (output.jsonSchema) on Gemini; choose one.",
|
|
287
|
-
{ kind: "bad_request", retryable: false }
|
|
288
|
-
);
|
|
492
|
+
if (googleProviderConfig.tools !== void 0) {
|
|
493
|
+
config.tools = googleProviderConfig.tools;
|
|
289
494
|
}
|
|
495
|
+
assertSamplingAllowed(config, model, req.modelDescriptor?.capabilities?.sampling);
|
|
290
496
|
let tierTimeoutHandle;
|
|
291
497
|
const clearTierTimeout = () => {
|
|
292
498
|
if (tierTimeoutHandle !== void 0) {
|
|
@@ -473,11 +679,11 @@ var DEFAULT_TIMEOUT_MS = 3e5;
|
|
|
473
679
|
var realSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
474
680
|
async function buildFilesClient(auth) {
|
|
475
681
|
const { GoogleGenAI } = await import('@google/genai');
|
|
476
|
-
const ai = new GoogleGenAI({ apiKey: auth
|
|
682
|
+
const ai = new GoogleGenAI({ apiKey: requireApiKey(auth) });
|
|
477
683
|
return {
|
|
478
684
|
async upload(params) {
|
|
479
685
|
const fileArg = params.file instanceof Uint8Array ? new Blob(
|
|
480
|
-
[params.file],
|
|
686
|
+
[Uint8Array.from(params.file)],
|
|
481
687
|
params.config?.mimeType !== void 0 && params.config.mimeType.length > 0 ? { type: params.config.mimeType } : {}
|
|
482
688
|
) : params.file;
|
|
483
689
|
const result = await ai.files.upload({
|
|
@@ -660,7 +866,7 @@ var DEFAULT_SKEW_SECONDS = 30;
|
|
|
660
866
|
var DEFAULT_EXTENSION_SECONDS = 3600;
|
|
661
867
|
async function buildCachesClient(auth) {
|
|
662
868
|
const { GoogleGenAI } = await import('@google/genai');
|
|
663
|
-
const ai = new GoogleGenAI({ apiKey: auth
|
|
869
|
+
const ai = new GoogleGenAI({ apiKey: requireApiKey(auth) });
|
|
664
870
|
return {
|
|
665
871
|
async create(params) {
|
|
666
872
|
const result = await ai.caches.create(params);
|
|
@@ -915,5 +1121,6 @@ exports.buildGoogleClient = buildGoogleClient;
|
|
|
915
1121
|
exports.geminiAdapter = geminiAdapter;
|
|
916
1122
|
exports.isGeminiCapacityError = isGeminiCapacityError;
|
|
917
1123
|
exports.normalizeGroundingCitations = normalizeGroundingCitations;
|
|
1124
|
+
exports.requireApiKey = requireApiKey;
|
|
918
1125
|
//# sourceMappingURL=index.cjs.map
|
|
919
1126
|
//# sourceMappingURL=index.cjs.map
|