@kindgi/adapter-model-gemini 0.1.4 → 0.1.5-rc.0
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 +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +11 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +86 -20
- package/dist/provider.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/provider.ts +103 -33
package/README.md
CHANGED
|
@@ -55,6 +55,7 @@ One non-streaming `models.generateContent` call per `invoke`:
|
|
|
55
55
|
- `metadata.region` as the location (`unspecified` means `global`);
|
|
56
56
|
- an optional `secret_ref` holding a service-account key.
|
|
57
57
|
- **`vertexTarget(input)`**: the project and location a registration names, as the factory reads them.
|
|
58
|
+
- **`geminiAdapterEntry`**: the `AdapterFactoryEntry` a runtime registers, `geminiAdapterFactory` plus **`geminiCheckConfig(input)`**. The check reports what the factory would throw on (`adapter_config.api`, `secret_ref` on the Developer API, `adapter_config.project`, `metadata.region`) with the factory's own messages, without building anything.
|
|
58
59
|
- **Cost helpers**: `computeCostUsd(usage, rates)`, `toFrameworkUsage(usageMetadata)`, `GeminiCostRates`, `GeminiModelInfo`, `DEFAULT_CACHED_PROMPT_MULTIPLIER`.
|
|
59
60
|
- **Translation helpers**: `toGeminiRequest(messages)`, `toGeminiFunctions(tools)`, `fromGeminiResponse(response)`, `mapFinishReason(reason)`, `checkFunctionName(name)`.
|
|
60
61
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { GEMINI_ADAPTER_ID, createGeminiProvider, geminiAdapterFactory, vertexTarget, } from './provider.js';
|
|
1
|
+
export { GEMINI_ADAPTER_ID, createGeminiProvider, geminiAdapterEntry, geminiAdapterFactory, geminiCheckConfig, vertexTarget, } from './provider.js';
|
|
2
2
|
export type { GeminiClient, GeminiProviderOptions } from './provider.js';
|
|
3
3
|
export { DEFAULT_CACHED_PROMPT_MULTIPLIER, computeCostUsd, toFrameworkUsage } from './cost.js';
|
|
4
4
|
export type { GeminiCostRates, GeminiModelInfo } from './cost.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC/F,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC/F,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
-
export { GEMINI_ADAPTER_ID, createGeminiProvider, geminiAdapterFactory, vertexTarget, } from './provider.js';
|
|
3
|
+
export { GEMINI_ADAPTER_ID, createGeminiProvider, geminiAdapterEntry, geminiAdapterFactory, geminiCheckConfig, vertexTarget, } from './provider.js';
|
|
4
4
|
export { DEFAULT_CACHED_PROMPT_MULTIPLIER, computeCostUsd, toFrameworkUsage } from './cost.js';
|
|
5
5
|
export { checkFunctionName, fromGeminiResponse, mapFinishReason, toGeminiFunctions, toGeminiRequest, } from './translate.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,GACb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gCAAgC,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE/F,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,GACb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gCAAgC,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE/F,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type GenerateContentParameters, type GenerateContentResponse } from '@google/genai';
|
|
2
|
-
import type { AdapterFactory, ModelProvider, ProviderMetadata } from '@kindgi/capabilities';
|
|
2
|
+
import type { AdapterConfigCheckInput, AdapterConfigProblem, AdapterFactory, AdapterFactoryEntry, ModelProvider, ProviderMetadata } from '@kindgi/capabilities';
|
|
3
3
|
import { type GeminiModelInfo } from './cost.js';
|
|
4
4
|
/** The adapter id servers register `geminiAdapterFactory` under. */
|
|
5
5
|
export declare const GEMINI_ADAPTER_ID = "@kindgi/adapter-model-gemini";
|
|
@@ -73,6 +73,16 @@ export declare function parseServiceAccountKey(key: string): Record<string, stri
|
|
|
73
73
|
* - `secret_ref` (required) — a Gemini API key from Google AI Studio.
|
|
74
74
|
*/
|
|
75
75
|
export declare const geminiAdapterFactory: AdapterFactory;
|
|
76
|
+
/**
|
|
77
|
+
* What's wrong with a registration for this adapter, read without building
|
|
78
|
+
* it (`AdapterFactoryEntry.checkConfig`): its API, its Gemini API key on
|
|
79
|
+
* the Developer API, its Vertex project and location. Each problem's
|
|
80
|
+
* message is the error the factory throws for it: both read the
|
|
81
|
+
* registration through the same functions.
|
|
82
|
+
*/
|
|
83
|
+
export declare function geminiCheckConfig(input: AdapterConfigCheckInput): readonly AdapterConfigProblem[];
|
|
84
|
+
/** The entry a runtime registers: the factory, and its static check. */
|
|
85
|
+
export declare const geminiAdapterEntry: AdapterFactoryEntry;
|
|
76
86
|
/** The Vertex project and location a registration names (see `geminiAdapterFactory`). */
|
|
77
87
|
export declare function vertexTarget(input: Parameters<AdapterFactory>[0]): NonNullable<GeminiProviderOptions['vertex']>;
|
|
78
88
|
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAG7B,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,cAAc,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAG7B,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EAInB,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAAE,KAAK,eAAe,EAAoC,MAAM,WAAW,CAAC;AAGnF,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,iCAAiC,CAAC;AAEhE,wEAAwE;AACxE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE;QACf,eAAe,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;KACtF,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,GAAG;QACpD,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;KAC7C,CAAC;IACF;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1E;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACtD;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,oGAAoG;IACpG,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;CAChC;AAaD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,aAAa,CAmHlF;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiC1E;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAYlC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,uBAAuB,GAAG,SAAS,oBAAoB,EAAE,CAQjG;AAED,wEAAwE;AACxE,eAAO,MAAM,kBAAkB,EAAE,mBAKhC,CAAC;AAkCF,yFAAyF;AACzF,wBAAgB,YAAY,CAC1B,KAAK,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GACnC,WAAW,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAM9C"}
|
package/dist/provider.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright (C) 2026 Kindgi Inc.
|
|
3
3
|
import { GoogleGenAI, } from '@google/genai';
|
|
4
|
-
import { samplingFor } from '@kindgi/capabilities';
|
|
4
|
+
import { adapterConfigError, samplingFor } from '@kindgi/capabilities';
|
|
5
5
|
import { createAttemptCounter } from '@kindgi/capabilities/attempts';
|
|
6
6
|
import { computeCostUsd, toFrameworkUsage } from './cost.js';
|
|
7
7
|
import { fromGeminiResponse, toGeminiFunctions, toGeminiRequest } from './translate.js';
|
|
@@ -97,6 +97,11 @@ export function createGeminiProvider(options) {
|
|
|
97
97
|
}),
|
|
98
98
|
...(maxOutputTokens !== undefined && { maxOutputTokens }),
|
|
99
99
|
...(input.abortSignal !== undefined && { abortSignal: input.abortSignal }),
|
|
100
|
+
// A header on this request only, when the caller sets it (the
|
|
101
|
+
// provider's registration opted in); merged into the client's.
|
|
102
|
+
...(input.traceparent !== undefined && {
|
|
103
|
+
httpOptions: { headers: { traceparent: input.traceparent } },
|
|
104
|
+
}),
|
|
100
105
|
};
|
|
101
106
|
const client = await resolveClient();
|
|
102
107
|
const counted = await attempts.count(() => client.models.generateContent({
|
|
@@ -179,34 +184,87 @@ export function parseServiceAccountKey(key) {
|
|
|
179
184
|
*/
|
|
180
185
|
export const geminiAdapterFactory = (input) => {
|
|
181
186
|
const metadata = input.metadata;
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
throw new Error(`${GEMINI_ADAPTER_ID}: provider "${input.metadata.id}" uses the Gemini Developer API (adapter_config.api "developer") and needs secret_ref: its Gemini API key.`);
|
|
186
|
-
}
|
|
187
|
+
const hasSecretRef = input.resolveApiKey !== undefined;
|
|
188
|
+
throwIf(input.metadata.id, apiProblem(input) ?? developerKeyProblem(input, hasSecretRef));
|
|
189
|
+
if (apiOf(input) === 'developer') {
|
|
187
190
|
return createGeminiProvider({ metadata, apiKey: input.resolveApiKey });
|
|
188
191
|
}
|
|
189
|
-
if (api !== 'vertex') {
|
|
190
|
-
throw new Error(`${GEMINI_ADAPTER_ID}: provider "${input.metadata.id}" adapter_config.api must be "vertex" or "developer", got ${JSON.stringify(api)}.`);
|
|
191
|
-
}
|
|
192
192
|
return createGeminiProvider({
|
|
193
193
|
metadata,
|
|
194
194
|
vertex: vertexTarget(input),
|
|
195
195
|
...(input.resolveApiKey !== undefined && { credentials: input.resolveApiKey }),
|
|
196
196
|
});
|
|
197
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* What's wrong with a registration for this adapter, read without building
|
|
200
|
+
* it (`AdapterFactoryEntry.checkConfig`): its API, its Gemini API key on
|
|
201
|
+
* the Developer API, its Vertex project and location. Each problem's
|
|
202
|
+
* message is the error the factory throws for it: both read the
|
|
203
|
+
* registration through the same functions.
|
|
204
|
+
*/
|
|
205
|
+
export function geminiCheckConfig(input) {
|
|
206
|
+
const api = apiProblem(input);
|
|
207
|
+
if (api !== undefined)
|
|
208
|
+
return [api];
|
|
209
|
+
if (apiOf(input) === 'developer') {
|
|
210
|
+
const key = developerKeyProblem(input, input.hasSecretRef);
|
|
211
|
+
return key !== undefined ? [key] : [];
|
|
212
|
+
}
|
|
213
|
+
return vertexTargetProblems(input);
|
|
214
|
+
}
|
|
215
|
+
/** The entry a runtime registers: the factory, and its static check. */
|
|
216
|
+
export const geminiAdapterEntry = {
|
|
217
|
+
adapterId: GEMINI_ADAPTER_ID,
|
|
218
|
+
capabilityKind: 'llm-inference',
|
|
219
|
+
factory: geminiAdapterFactory,
|
|
220
|
+
checkConfig: geminiCheckConfig,
|
|
221
|
+
};
|
|
222
|
+
function throwIf(providerId, problem) {
|
|
223
|
+
if (problem !== undefined)
|
|
224
|
+
throw adapterConfigError(GEMINI_ADAPTER_ID, providerId, problem);
|
|
225
|
+
}
|
|
226
|
+
function apiOf(input) {
|
|
227
|
+
return input.config?.api ?? 'vertex';
|
|
228
|
+
}
|
|
229
|
+
function apiProblem(input) {
|
|
230
|
+
const api = apiOf(input);
|
|
231
|
+
if (api === 'vertex' || api === 'developer')
|
|
232
|
+
return undefined;
|
|
233
|
+
return {
|
|
234
|
+
path: '/adapter_config/api',
|
|
235
|
+
message: `adapter_config.api must be "vertex" or "developer", got ${JSON.stringify(api)}.`,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function developerKeyProblem(input, hasSecretRef) {
|
|
239
|
+
if (apiOf(input) !== 'developer' || hasSecretRef)
|
|
240
|
+
return undefined;
|
|
241
|
+
return {
|
|
242
|
+
path: '/secret_ref',
|
|
243
|
+
message: 'uses the Gemini Developer API (adapter_config.api "developer") and needs secret_ref: its Gemini API key.',
|
|
244
|
+
};
|
|
245
|
+
}
|
|
198
246
|
/** The Vertex project and location a registration names (see `geminiAdapterFactory`). */
|
|
199
247
|
export function vertexTarget(input) {
|
|
248
|
+
throwIf(input.metadata.id, vertexTargetProblems(input)[0]);
|
|
249
|
+
return {
|
|
250
|
+
project: input.config?.project,
|
|
251
|
+
location: locationOf(input),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function locationOf(input) {
|
|
255
|
+
return input.metadata.region === 'unspecified' ? 'global' : input.metadata.region;
|
|
256
|
+
}
|
|
257
|
+
function vertexTargetProblems(input) {
|
|
200
258
|
const project = input.config?.project;
|
|
201
259
|
if (typeof project !== 'string' || project.length === 0) {
|
|
202
|
-
|
|
260
|
+
return [
|
|
261
|
+
{
|
|
262
|
+
path: '/adapter_config/project',
|
|
263
|
+
message: 'needs adapter_config.project (the Vertex AI project).',
|
|
264
|
+
},
|
|
265
|
+
];
|
|
203
266
|
}
|
|
204
|
-
|
|
205
|
-
project,
|
|
206
|
-
location: input.metadata.region === 'unspecified' ? 'global' : input.metadata.region,
|
|
207
|
-
};
|
|
208
|
-
checkVertexTarget(input.metadata.id, target);
|
|
209
|
-
return target;
|
|
267
|
+
return vertexTargetProblemsOf({ project, location: locationOf(input) });
|
|
210
268
|
}
|
|
211
269
|
/** A provider names exactly one target: Vertex AI, or a Gemini API key. */
|
|
212
270
|
function checkTarget(providerId, options) {
|
|
@@ -214,7 +272,7 @@ function checkTarget(providerId, options) {
|
|
|
214
272
|
throw new Error(`${GEMINI_ADAPTER_ID}: provider "${providerId}" needs exactly one of vertex (a Vertex AI project) or apiKey (a Gemini Developer API key).`);
|
|
215
273
|
}
|
|
216
274
|
if (options.vertex !== undefined)
|
|
217
|
-
|
|
275
|
+
throwIf(providerId, vertexTargetProblemsOf(options.vertex)[0]);
|
|
218
276
|
}
|
|
219
277
|
/**
|
|
220
278
|
* The SDK puts the project in the request path and builds the hostname
|
|
@@ -222,13 +280,21 @@ function checkTarget(providerId, options) {
|
|
|
222
280
|
* anything but a project id and one DNS label could move the request,
|
|
223
281
|
* with the server's credentials, to another host.
|
|
224
282
|
*/
|
|
225
|
-
function
|
|
283
|
+
function vertexTargetProblemsOf(vertex) {
|
|
284
|
+
const problems = [];
|
|
226
285
|
if (!VERTEX_PROJECT.test(vertex.project)) {
|
|
227
|
-
|
|
286
|
+
problems.push({
|
|
287
|
+
path: '/adapter_config/project',
|
|
288
|
+
message: 'adapter_config.project must be a Google Cloud project id or number.',
|
|
289
|
+
});
|
|
228
290
|
}
|
|
229
291
|
if (!VERTEX_LOCATION.test(vertex.location)) {
|
|
230
|
-
|
|
292
|
+
problems.push({
|
|
293
|
+
path: '/metadata/region',
|
|
294
|
+
message: 'metadata.region must be a Vertex AI location (one DNS label, e.g. us-central1).',
|
|
295
|
+
});
|
|
231
296
|
}
|
|
297
|
+
return problems;
|
|
232
298
|
}
|
|
233
299
|
/** A Google Cloud project id (6–30: lowercase, digits, hyphens) or project number. */
|
|
234
300
|
const VERTEX_PROJECT = /^(?:[a-z][a-z0-9-]{4,28}[a-z0-9]|[0-9]{1,20})$/;
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EAIL,WAAW,GAEZ,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EAIL,WAAW,GAEZ,MAAM,eAAe,CAAC;AAYvB,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,EAAwB,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,g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AC,MAAM,KAAK,SAAS,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CACb,GAAG,iBAAiB,eAAe,UAAU,6FAA6F,CAC3I,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,CAAC,UAAU,EAAE,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnG,CAAC;AAED;;;;;GAKG;AACH,SAAS,sBAAsB,CAC7B,MAAoD;IAEpD,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,yBAAyB;YAC/B,OAAO,EAAE,qEAAqE;SAC/E,CAAC,CAAC;IACL,CAAC;IACD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3C,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,kBAAkB;YACxB,OAAO,EAAE,iFAAiF;SAC3F,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,sFAAsF;AACtF,MAAM,cAAc,GAAG,gDAAgD,CAAC;AACxE,2CAA2C;AAC3C,MAAM,eAAe,GAAG,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kindgi/adapter-model-gemini",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5-rc.0",
|
|
4
4
|
"description": "Gemini ModelProvider for @kindgi/capabilities, on Vertex AI. Wraps @google/genai with the framework's provider-neutral interface: message-trail ↔ generateContent translation, function calling with thought signatures, token and cost accounting including thinking tokens, and Google Application Default Credentials (or a service-account key from the secret store). Non-streaming, tool-use enabled.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@kindgi/capabilities": "0.1.
|
|
31
|
+
"@kindgi/capabilities": "0.1.5-rc.0",
|
|
32
32
|
"@google/genai": "^2.24.0"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
package/src/index.ts
CHANGED
package/src/provider.ts
CHANGED
|
@@ -9,13 +9,17 @@ import {
|
|
|
9
9
|
type ThinkingLevel,
|
|
10
10
|
} from '@google/genai';
|
|
11
11
|
import type {
|
|
12
|
+
AdapterConfigCheckInput,
|
|
13
|
+
AdapterConfigProblem,
|
|
12
14
|
AdapterFactory,
|
|
15
|
+
AdapterFactoryEntry,
|
|
16
|
+
AdapterFactoryInput,
|
|
13
17
|
ModelCallInput,
|
|
14
18
|
ModelCallResult,
|
|
15
19
|
ModelProvider,
|
|
16
20
|
ProviderMetadata,
|
|
17
21
|
} from '@kindgi/capabilities';
|
|
18
|
-
import { samplingFor } from '@kindgi/capabilities';
|
|
22
|
+
import { adapterConfigError, samplingFor } from '@kindgi/capabilities';
|
|
19
23
|
import { createAttemptCounter } from '@kindgi/capabilities/attempts';
|
|
20
24
|
|
|
21
25
|
import { type GeminiModelInfo, computeCostUsd, toFrameworkUsage } from './cost.js';
|
|
@@ -158,6 +162,11 @@ export function createGeminiProvider(options: GeminiProviderOptions): ModelProvi
|
|
|
158
162
|
}),
|
|
159
163
|
...(maxOutputTokens !== undefined && { maxOutputTokens }),
|
|
160
164
|
...(input.abortSignal !== undefined && { abortSignal: input.abortSignal }),
|
|
165
|
+
// A header on this request only, when the caller sets it (the
|
|
166
|
+
// provider's registration opted in); merged into the client's.
|
|
167
|
+
...(input.traceparent !== undefined && {
|
|
168
|
+
httpOptions: { headers: { traceparent: input.traceparent } },
|
|
169
|
+
}),
|
|
161
170
|
};
|
|
162
171
|
|
|
163
172
|
const client = await resolveClient();
|
|
@@ -250,19 +259,10 @@ export function parseServiceAccountKey(key: string): Record<string, string> {
|
|
|
250
259
|
*/
|
|
251
260
|
export const geminiAdapterFactory: AdapterFactory = (input) => {
|
|
252
261
|
const metadata = input.metadata as GeminiProviderOptions['metadata'];
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
`${GEMINI_ADAPTER_ID}: provider "${input.metadata.id}" uses the Gemini Developer API (adapter_config.api "developer") and needs secret_ref: its Gemini API key.`,
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
return createGeminiProvider({ metadata, apiKey: input.resolveApiKey });
|
|
261
|
-
}
|
|
262
|
-
if (api !== 'vertex') {
|
|
263
|
-
throw new Error(
|
|
264
|
-
`${GEMINI_ADAPTER_ID}: provider "${input.metadata.id}" adapter_config.api must be "vertex" or "developer", got ${JSON.stringify(api)}.`,
|
|
265
|
-
);
|
|
262
|
+
const hasSecretRef = input.resolveApiKey !== undefined;
|
|
263
|
+
throwIf(input.metadata.id, apiProblem(input) ?? developerKeyProblem(input, hasSecretRef));
|
|
264
|
+
if (apiOf(input) === 'developer') {
|
|
265
|
+
return createGeminiProvider({ metadata, apiKey: input.resolveApiKey as () => Promise<string> });
|
|
266
266
|
}
|
|
267
267
|
return createGeminiProvider({
|
|
268
268
|
metadata,
|
|
@@ -271,22 +271,89 @@ export const geminiAdapterFactory: AdapterFactory = (input) => {
|
|
|
271
271
|
});
|
|
272
272
|
};
|
|
273
273
|
|
|
274
|
+
/**
|
|
275
|
+
* What's wrong with a registration for this adapter, read without building
|
|
276
|
+
* it (`AdapterFactoryEntry.checkConfig`): its API, its Gemini API key on
|
|
277
|
+
* the Developer API, its Vertex project and location. Each problem's
|
|
278
|
+
* message is the error the factory throws for it: both read the
|
|
279
|
+
* registration through the same functions.
|
|
280
|
+
*/
|
|
281
|
+
export function geminiCheckConfig(input: AdapterConfigCheckInput): readonly AdapterConfigProblem[] {
|
|
282
|
+
const api = apiProblem(input);
|
|
283
|
+
if (api !== undefined) return [api];
|
|
284
|
+
if (apiOf(input) === 'developer') {
|
|
285
|
+
const key = developerKeyProblem(input, input.hasSecretRef);
|
|
286
|
+
return key !== undefined ? [key] : [];
|
|
287
|
+
}
|
|
288
|
+
return vertexTargetProblems(input);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** The entry a runtime registers: the factory, and its static check. */
|
|
292
|
+
export const geminiAdapterEntry: AdapterFactoryEntry = {
|
|
293
|
+
adapterId: GEMINI_ADAPTER_ID,
|
|
294
|
+
capabilityKind: 'llm-inference',
|
|
295
|
+
factory: geminiAdapterFactory,
|
|
296
|
+
checkConfig: geminiCheckConfig,
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
/** What the checks read of a registration. */
|
|
300
|
+
type Registration = Pick<AdapterFactoryInput, 'metadata' | 'config'>;
|
|
301
|
+
|
|
302
|
+
function throwIf(providerId: string, problem: AdapterConfigProblem | undefined): void {
|
|
303
|
+
if (problem !== undefined) throw adapterConfigError(GEMINI_ADAPTER_ID, providerId, problem);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function apiOf(input: Registration): unknown {
|
|
307
|
+
return input.config?.api ?? 'vertex';
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function apiProblem(input: Registration): AdapterConfigProblem | undefined {
|
|
311
|
+
const api = apiOf(input);
|
|
312
|
+
if (api === 'vertex' || api === 'developer') return undefined;
|
|
313
|
+
return {
|
|
314
|
+
path: '/adapter_config/api',
|
|
315
|
+
message: `adapter_config.api must be "vertex" or "developer", got ${JSON.stringify(api)}.`,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function developerKeyProblem(
|
|
320
|
+
input: Registration,
|
|
321
|
+
hasSecretRef: boolean,
|
|
322
|
+
): AdapterConfigProblem | undefined {
|
|
323
|
+
if (apiOf(input) !== 'developer' || hasSecretRef) return undefined;
|
|
324
|
+
return {
|
|
325
|
+
path: '/secret_ref',
|
|
326
|
+
message:
|
|
327
|
+
'uses the Gemini Developer API (adapter_config.api "developer") and needs secret_ref: its Gemini API key.',
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
274
331
|
/** The Vertex project and location a registration names (see `geminiAdapterFactory`). */
|
|
275
332
|
export function vertexTarget(
|
|
276
333
|
input: Parameters<AdapterFactory>[0],
|
|
277
334
|
): NonNullable<GeminiProviderOptions['vertex']> {
|
|
335
|
+
throwIf(input.metadata.id, vertexTargetProblems(input)[0]);
|
|
336
|
+
return {
|
|
337
|
+
project: input.config?.project as string,
|
|
338
|
+
location: locationOf(input),
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function locationOf(input: Registration): string {
|
|
343
|
+
return input.metadata.region === 'unspecified' ? 'global' : input.metadata.region;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function vertexTargetProblems(input: Registration): AdapterConfigProblem[] {
|
|
278
347
|
const project = input.config?.project;
|
|
279
348
|
if (typeof project !== 'string' || project.length === 0) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
349
|
+
return [
|
|
350
|
+
{
|
|
351
|
+
path: '/adapter_config/project',
|
|
352
|
+
message: 'needs adapter_config.project (the Vertex AI project).',
|
|
353
|
+
},
|
|
354
|
+
];
|
|
283
355
|
}
|
|
284
|
-
|
|
285
|
-
project,
|
|
286
|
-
location: input.metadata.region === 'unspecified' ? 'global' : input.metadata.region,
|
|
287
|
-
};
|
|
288
|
-
checkVertexTarget(input.metadata.id, target);
|
|
289
|
-
return target;
|
|
356
|
+
return vertexTargetProblemsOf({ project, location: locationOf(input) });
|
|
290
357
|
}
|
|
291
358
|
|
|
292
359
|
/** A provider names exactly one target: Vertex AI, or a Gemini API key. */
|
|
@@ -296,7 +363,7 @@ function checkTarget(providerId: string, options: GeminiProviderOptions): void {
|
|
|
296
363
|
`${GEMINI_ADAPTER_ID}: provider "${providerId}" needs exactly one of vertex (a Vertex AI project) or apiKey (a Gemini Developer API key).`,
|
|
297
364
|
);
|
|
298
365
|
}
|
|
299
|
-
if (options.vertex !== undefined)
|
|
366
|
+
if (options.vertex !== undefined) throwIf(providerId, vertexTargetProblemsOf(options.vertex)[0]);
|
|
300
367
|
}
|
|
301
368
|
|
|
302
369
|
/**
|
|
@@ -305,20 +372,23 @@ function checkTarget(providerId: string, options: GeminiProviderOptions): void {
|
|
|
305
372
|
* anything but a project id and one DNS label could move the request,
|
|
306
373
|
* with the server's credentials, to another host.
|
|
307
374
|
*/
|
|
308
|
-
function
|
|
309
|
-
providerId: string,
|
|
375
|
+
function vertexTargetProblemsOf(
|
|
310
376
|
vertex: NonNullable<GeminiProviderOptions['vertex']>,
|
|
311
|
-
):
|
|
377
|
+
): AdapterConfigProblem[] {
|
|
378
|
+
const problems: AdapterConfigProblem[] = [];
|
|
312
379
|
if (!VERTEX_PROJECT.test(vertex.project)) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
380
|
+
problems.push({
|
|
381
|
+
path: '/adapter_config/project',
|
|
382
|
+
message: 'adapter_config.project must be a Google Cloud project id or number.',
|
|
383
|
+
});
|
|
316
384
|
}
|
|
317
385
|
if (!VERTEX_LOCATION.test(vertex.location)) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
386
|
+
problems.push({
|
|
387
|
+
path: '/metadata/region',
|
|
388
|
+
message: 'metadata.region must be a Vertex AI location (one DNS label, e.g. us-central1).',
|
|
389
|
+
});
|
|
321
390
|
}
|
|
391
|
+
return problems;
|
|
322
392
|
}
|
|
323
393
|
|
|
324
394
|
/** A Google Cloud project id (6–30: lowercase, digits, hyphens) or project number. */
|