@anvia/gemini 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Indra Zulfi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @anvia/gemini
2
+
3
+ Gemini and Vertex AI provider adapter for Anvia.
4
+
5
+ Use this package when you want Anvia agents, extractors, pipelines, embeddings, image generation, or transcription to run on Google's Gemini APIs.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add @anvia/gemini @anvia/core
11
+ ```
12
+
13
+ In this monorepo, the package is available through the workspace:
14
+
15
+ ```sh
16
+ pnpm --filter @anvia/gemini build
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { AgentBuilder } from "@anvia/core";
23
+ import { GeminiClient } from "@anvia/gemini";
24
+
25
+ const client = new GeminiClient({
26
+ apiKey,
27
+ });
28
+
29
+ const model = client.completionModel("gemini-2.5-flash");
30
+
31
+ const agent = new AgentBuilder("assistant", model)
32
+ .instructions("Answer clearly and concisely.")
33
+ .build();
34
+
35
+ const response = await agent.prompt("Summarize Anvia in one sentence.").send();
36
+
37
+ console.log(response.output);
38
+ ```
39
+
40
+ ## Vertex AI
41
+
42
+ Use Vertex AI by passing `vertexai: true` with a Google Cloud project and location:
43
+
44
+ ```ts
45
+ import { GeminiClient } from "@anvia/gemini";
46
+
47
+ const client = new GeminiClient({
48
+ vertexai: true,
49
+ project: "my-gcp-project",
50
+ location: "us-central1",
51
+ });
52
+
53
+ const model = client.completionModel("gemini-2.5-flash");
54
+ ```
55
+
56
+ ## Embeddings
57
+
58
+ ```ts
59
+ const embeddings = client.embeddingModel("gemini-embedding-001");
60
+ const vectors = await embeddings.embedTexts(["Anvia is a TypeScript AI runtime."]);
61
+ ```
62
+
63
+ ## Image Generation
64
+
65
+ `imageGenerationModel()` uses Gemini native image generation models such as Nano Banana.
66
+ Use `imagenGenerationModel()` when you specifically want Imagen.
67
+
68
+ ```ts
69
+ import { GEMINI_2_5_FLASH_IMAGE, IMAGEN_4_GENERATE, GeminiClient } from "@anvia/gemini";
70
+
71
+ const client = new GeminiClient({ apiKey });
72
+
73
+ const nativeImageModel = client.imageGenerationModel(GEMINI_2_5_FLASH_IMAGE);
74
+ const imagenModel = client.imagenGenerationModel(IMAGEN_4_GENERATE);
75
+ ```
76
+
77
+ ## Exports
78
+
79
+ - `GeminiClient`
80
+ - `GeminiCompletionModel`
81
+ - `GeminiEmbeddingModel`
82
+ - `GeminiImageGenerationModel`
83
+ - `GeminiImagenGenerationModel`
84
+ - `GeminiTranscriptionModel`
85
+ - `GEMINI_2_5_FLASH_IMAGE`
86
+ - `GEMINI_3_PRO_IMAGE_PREVIEW`
87
+ - `IMAGEN_4_GENERATE`
88
+ - `gemini`
89
+
90
+ ## Development
91
+
92
+ ```sh
93
+ pnpm --filter @anvia/gemini typecheck
94
+ pnpm --filter @anvia/gemini test
95
+ pnpm --filter @anvia/gemini build
96
+ ```
@@ -0,0 +1,110 @@
1
+ import { GoogleGenAI } from '@google/genai';
2
+ import { StreamingCompletionModel, CompletionModelCapabilities, CompletionRequest, CompletionResponse, CompletionStreamEvent } from '@anvia/core/completion';
3
+ import { EmbeddingModel, Embedding } from '@anvia/core/embeddings';
4
+ import { ImageGenerationModel, ImageGenerationRequest, ImageGenerationResponse } from '@anvia/core/image-generation';
5
+ import { TranscriptionModel, TranscriptionRequest, TranscriptionResponse } from '@anvia/core/transcription';
6
+
7
+ declare class GeminiCompletionModel implements StreamingCompletionModel {
8
+ private readonly client;
9
+ readonly defaultModel: string;
10
+ readonly provider = "gemini";
11
+ readonly capabilities: CompletionModelCapabilities;
12
+ constructor(client: GoogleGenAI, defaultModel?: string);
13
+ completion(request: CompletionRequest): Promise<CompletionResponse>;
14
+ streamCompletion(request: CompletionRequest): AsyncIterable<CompletionStreamEvent>;
15
+ }
16
+
17
+ type GeminiEmbeddingTaskType = "TASK_TYPE_UNSPECIFIED" | "RETRIEVAL_QUERY" | "RETRIEVAL_DOCUMENT" | "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY";
18
+ type GeminiEmbeddingModelOptions = {
19
+ dimensions?: number | undefined;
20
+ maxBatchSize?: number | undefined;
21
+ taskType?: GeminiEmbeddingTaskType | undefined;
22
+ title?: string | undefined;
23
+ };
24
+ declare class GeminiEmbeddingModel implements EmbeddingModel {
25
+ private readonly client;
26
+ private readonly model;
27
+ readonly dimensions: number | undefined;
28
+ readonly maxBatchSize: number;
29
+ private readonly taskType;
30
+ private readonly title;
31
+ constructor(client: GoogleGenAI, model: string, options?: GeminiEmbeddingModelOptions);
32
+ embedTexts(texts: string[]): Promise<Embedding[]>;
33
+ private embedBatch;
34
+ private embeddingConfig;
35
+ }
36
+
37
+ declare const GEMINI_2_5_FLASH_IMAGE = "gemini-2.5-flash-image";
38
+ declare const GEMINI_3_PRO_IMAGE_PREVIEW = "gemini-3-pro-image-preview";
39
+ declare const IMAGEN_4_GENERATE = "imagen-4.0-generate-001";
40
+ declare class GeminiImageGenerationModel implements ImageGenerationModel {
41
+ private readonly client;
42
+ readonly defaultModel: string;
43
+ readonly provider = "gemini";
44
+ constructor(client: GoogleGenAI, defaultModel?: string);
45
+ imageGeneration(request: ImageGenerationRequest): Promise<ImageGenerationResponse<unknown>>;
46
+ }
47
+ declare class GeminiImagenGenerationModel implements ImageGenerationModel {
48
+ private readonly client;
49
+ readonly defaultModel: string;
50
+ readonly provider = "gemini";
51
+ constructor(client: GoogleGenAI, defaultModel?: string);
52
+ imageGeneration(request: ImageGenerationRequest): Promise<ImageGenerationResponse<unknown>>;
53
+ }
54
+
55
+ declare class GeminiTranscriptionModel implements TranscriptionModel {
56
+ private readonly client;
57
+ readonly defaultModel: string;
58
+ readonly provider = "gemini";
59
+ constructor(client: GoogleGenAI, defaultModel?: string);
60
+ transcription(request: TranscriptionRequest): Promise<TranscriptionResponse<unknown>>;
61
+ }
62
+
63
+ type GeminiApiClientOptions = {
64
+ apiKey?: string | undefined;
65
+ vertexai?: false | undefined;
66
+ project?: never;
67
+ location?: never;
68
+ };
69
+ type VertexClientOptions = {
70
+ vertexai: true;
71
+ project?: string | undefined;
72
+ location?: string | undefined;
73
+ apiKey?: never;
74
+ };
75
+ type GeminiClientOptions = (GeminiApiClientOptions | VertexClientOptions) & {
76
+ client?: GoogleGenAI | undefined;
77
+ };
78
+ declare class GeminiClient {
79
+ readonly client: GoogleGenAI;
80
+ constructor(options?: GeminiClientOptions);
81
+ completionModel(model?: string): GeminiCompletionModel;
82
+ embeddingModel(model?: string, options?: GeminiEmbeddingModelOptions): GeminiEmbeddingModel;
83
+ imageGenerationModel(model?: string): GeminiImageGenerationModel;
84
+ imagenGenerationModel(model?: string): GeminiImagenGenerationModel;
85
+ transcriptionModel(model?: string): GeminiTranscriptionModel;
86
+ }
87
+
88
+ declare const index_GEMINI_2_5_FLASH_IMAGE: typeof GEMINI_2_5_FLASH_IMAGE;
89
+ declare const index_GEMINI_3_PRO_IMAGE_PREVIEW: typeof GEMINI_3_PRO_IMAGE_PREVIEW;
90
+ type index_GeminiClient = GeminiClient;
91
+ declare const index_GeminiClient: typeof GeminiClient;
92
+ type index_GeminiClientOptions = GeminiClientOptions;
93
+ type index_GeminiCompletionModel = GeminiCompletionModel;
94
+ declare const index_GeminiCompletionModel: typeof GeminiCompletionModel;
95
+ type index_GeminiEmbeddingModel = GeminiEmbeddingModel;
96
+ declare const index_GeminiEmbeddingModel: typeof GeminiEmbeddingModel;
97
+ type index_GeminiEmbeddingModelOptions = GeminiEmbeddingModelOptions;
98
+ type index_GeminiEmbeddingTaskType = GeminiEmbeddingTaskType;
99
+ type index_GeminiImageGenerationModel = GeminiImageGenerationModel;
100
+ declare const index_GeminiImageGenerationModel: typeof GeminiImageGenerationModel;
101
+ type index_GeminiImagenGenerationModel = GeminiImagenGenerationModel;
102
+ declare const index_GeminiImagenGenerationModel: typeof GeminiImagenGenerationModel;
103
+ type index_GeminiTranscriptionModel = GeminiTranscriptionModel;
104
+ declare const index_GeminiTranscriptionModel: typeof GeminiTranscriptionModel;
105
+ declare const index_IMAGEN_4_GENERATE: typeof IMAGEN_4_GENERATE;
106
+ declare namespace index {
107
+ export { index_GEMINI_2_5_FLASH_IMAGE as GEMINI_2_5_FLASH_IMAGE, index_GEMINI_3_PRO_IMAGE_PREVIEW as GEMINI_3_PRO_IMAGE_PREVIEW, index_GeminiClient as GeminiClient, type index_GeminiClientOptions as GeminiClientOptions, index_GeminiCompletionModel as GeminiCompletionModel, index_GeminiEmbeddingModel as GeminiEmbeddingModel, type index_GeminiEmbeddingModelOptions as GeminiEmbeddingModelOptions, type index_GeminiEmbeddingTaskType as GeminiEmbeddingTaskType, index_GeminiImageGenerationModel as GeminiImageGenerationModel, index_GeminiImagenGenerationModel as GeminiImagenGenerationModel, index_GeminiTranscriptionModel as GeminiTranscriptionModel, index_IMAGEN_4_GENERATE as IMAGEN_4_GENERATE };
108
+ }
109
+
110
+ export { GEMINI_2_5_FLASH_IMAGE, GEMINI_3_PRO_IMAGE_PREVIEW, GeminiClient, type GeminiClientOptions, GeminiCompletionModel, GeminiEmbeddingModel, type GeminiEmbeddingModelOptions, type GeminiEmbeddingTaskType, GeminiImageGenerationModel, GeminiImagenGenerationModel, GeminiTranscriptionModel, IMAGEN_4_GENERATE, index as gemini };
package/dist/index.js ADDED
@@ -0,0 +1,857 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/gemini/index.ts
8
+ var gemini_exports = {};
9
+ __export(gemini_exports, {
10
+ GEMINI_2_5_FLASH_IMAGE: () => GEMINI_2_5_FLASH_IMAGE,
11
+ GEMINI_3_PRO_IMAGE_PREVIEW: () => GEMINI_3_PRO_IMAGE_PREVIEW,
12
+ GeminiClient: () => GeminiClient,
13
+ GeminiCompletionModel: () => GeminiCompletionModel,
14
+ GeminiEmbeddingModel: () => GeminiEmbeddingModel,
15
+ GeminiImageGenerationModel: () => GeminiImageGenerationModel,
16
+ GeminiImagenGenerationModel: () => GeminiImagenGenerationModel,
17
+ GeminiTranscriptionModel: () => GeminiTranscriptionModel,
18
+ IMAGEN_4_GENERATE: () => IMAGEN_4_GENERATE
19
+ });
20
+
21
+ // src/gemini/client.ts
22
+ import { GoogleGenAI } from "@google/genai";
23
+
24
+ // src/gemini/completion.ts
25
+ import {
26
+ AssistantContent,
27
+ assertCompletionRequestSupported,
28
+ Usage
29
+ } from "@anvia/core/completion";
30
+
31
+ // src/request-messages.ts
32
+ import {
33
+ normalizeDocuments
34
+ } from "@anvia/core/completion";
35
+ function orderedRequestMessages(request) {
36
+ const messages = [];
37
+ messages.push(...request.chatHistory.filter((message) => message.role === "system"));
38
+ const documents = normalizeDocuments(request.documents);
39
+ if (documents !== void 0) {
40
+ messages.push(documents);
41
+ }
42
+ messages.push(...request.chatHistory.filter((message) => message.role !== "system"));
43
+ return messages;
44
+ }
45
+
46
+ // src/gemini/completion.ts
47
+ var GeminiCompletionModel = class {
48
+ constructor(client, defaultModel = "gemini-2.5-flash") {
49
+ this.client = client;
50
+ this.defaultModel = defaultModel;
51
+ }
52
+ client;
53
+ defaultModel;
54
+ provider = "gemini";
55
+ capabilities = {
56
+ streaming: true,
57
+ tools: true,
58
+ toolChoice: true,
59
+ imageInput: true,
60
+ documentInput: true,
61
+ outputSchema: true,
62
+ reasoning: true
63
+ };
64
+ async completion(request) {
65
+ assertCompletionRequestSupported(this, request);
66
+ const params = toGeminiGenerateContentParams(this.defaultModel, request);
67
+ const response = await this.client.models.generateContent(params);
68
+ return fromGeminiGenerateContentResponse(response);
69
+ }
70
+ async *streamCompletion(request) {
71
+ assertCompletionRequestSupported(this, request, { streaming: true });
72
+ const params = toGeminiGenerateContentParams(this.defaultModel, request);
73
+ const stream = await this.client.models.generateContentStream(params);
74
+ for await (const chunk of stream) {
75
+ for (const event of fromGeminiGenerateContentStreamChunk(chunk)) {
76
+ yield event;
77
+ }
78
+ }
79
+ }
80
+ };
81
+ function toGeminiGenerateContentParams(defaultModel, request) {
82
+ const messages = requestMessages(request);
83
+ const config = geminiConfig(request, messages);
84
+ const params = {
85
+ model: request.model ?? defaultModel,
86
+ contents: messagesToGeminiContents(messages),
87
+ config
88
+ };
89
+ if (request.additionalParams !== void 0 && isPlainObject(request.additionalParams)) {
90
+ const { config: additionalConfig, ...additionalTopLevel } = request.additionalParams;
91
+ Object.assign(params, additionalTopLevel);
92
+ if (isPlainObject(additionalConfig)) {
93
+ params.config = { ...config, ...additionalConfig };
94
+ }
95
+ }
96
+ return params;
97
+ }
98
+ function requestMessages(request) {
99
+ return orderedRequestMessages(request);
100
+ }
101
+ function geminiConfig(request, messages) {
102
+ const config = {};
103
+ const systemInstruction = systemInstructionFrom(request, messages);
104
+ if (systemInstruction !== void 0) {
105
+ config.systemInstruction = systemInstruction;
106
+ }
107
+ if (request.temperature !== void 0) {
108
+ config.temperature = request.temperature;
109
+ }
110
+ if (request.maxTokens !== void 0) {
111
+ config.maxOutputTokens = request.maxTokens;
112
+ }
113
+ if (request.tools.length > 0) {
114
+ config.tools = [{ functionDeclarations: request.tools.map(toolDefinitionToGemini) }];
115
+ }
116
+ if (request.toolChoice !== void 0) {
117
+ config.toolConfig = toolChoiceToGemini(request.toolChoice);
118
+ }
119
+ if (request.outputSchema !== void 0) {
120
+ config.responseMimeType = "application/json";
121
+ config.responseJsonSchema = request.outputSchema;
122
+ }
123
+ return config;
124
+ }
125
+ function systemInstructionFrom(request, messages) {
126
+ const systemMessages = messages.flatMap(
127
+ (message) => message.role === "system" ? [message.content] : []
128
+ );
129
+ if (request.instructions !== void 0) {
130
+ systemMessages.unshift(request.instructions);
131
+ }
132
+ return systemMessages.length === 0 ? void 0 : systemMessages.join("\n\n");
133
+ }
134
+ function messagesToGeminiContents(messages) {
135
+ const toolNamesById = /* @__PURE__ */ new Map();
136
+ const contents = [];
137
+ for (const message of messages) {
138
+ if (message.role === "system") {
139
+ continue;
140
+ }
141
+ if (message.role === "assistant") {
142
+ const content2 = assistantMessageToGeminiContent(message);
143
+ for (const item of message.content) {
144
+ if (item.type === "tool_call") {
145
+ toolNamesById.set(item.id, item.function.name);
146
+ if (item.callId !== void 0) {
147
+ toolNamesById.set(item.callId, item.function.name);
148
+ }
149
+ }
150
+ }
151
+ if (content2.parts.length > 0) {
152
+ contents.push(content2);
153
+ }
154
+ continue;
155
+ }
156
+ const content = message.role === "tool" ? toolMessageToGeminiContent(message, toolNamesById) : userMessageToGeminiContent(message);
157
+ if (content.parts.length > 0) {
158
+ contents.push(content);
159
+ }
160
+ }
161
+ return contents;
162
+ }
163
+ function userMessageToGeminiContent(message) {
164
+ return {
165
+ role: "user",
166
+ parts: message.content.map(userContentToGeminiPart)
167
+ };
168
+ }
169
+ function toolMessageToGeminiContent(message, toolNamesById) {
170
+ return {
171
+ role: "user",
172
+ parts: message.content.map((content) => toolContentToGeminiPart(content, toolNamesById))
173
+ };
174
+ }
175
+ function assistantMessageToGeminiContent(message) {
176
+ return {
177
+ role: "model",
178
+ parts: message.content.flatMap((content) => {
179
+ if (content.type === "text") {
180
+ const part = { text: content.text };
181
+ if (content.signature !== void 0) {
182
+ part.thoughtSignature = content.signature;
183
+ }
184
+ return [part];
185
+ }
186
+ if (content.type === "tool_call") {
187
+ const functionCall = {
188
+ name: content.function.name,
189
+ args: content.function.arguments ?? {}
190
+ };
191
+ if (content.callId !== void 0) {
192
+ functionCall.id = content.callId;
193
+ }
194
+ const part = { functionCall };
195
+ if (content.signature !== void 0) {
196
+ part.thoughtSignature = content.signature;
197
+ }
198
+ return [part];
199
+ }
200
+ if (content.type === "reasoning" && content.content !== void 0) {
201
+ return content.content.flatMap((reasoning) => {
202
+ if (reasoning.type !== "text" && reasoning.type !== "summary") {
203
+ return [];
204
+ }
205
+ const part = { text: reasoning.text, thought: true };
206
+ if (reasoning.type === "text" && reasoning.signature !== void 0) {
207
+ part.thoughtSignature = reasoning.signature;
208
+ }
209
+ return [part];
210
+ });
211
+ }
212
+ if (content.type === "image") {
213
+ throw new Error("Gemini does not support image content in assistant history yet");
214
+ }
215
+ return [];
216
+ })
217
+ };
218
+ }
219
+ function userContentToGeminiPart(content) {
220
+ if (content.type === "text") {
221
+ return { text: content.text };
222
+ }
223
+ if (content.type === "image") {
224
+ return imageContentToGeminiPart(content);
225
+ }
226
+ return documentContentToGeminiPart(content);
227
+ }
228
+ function imageContentToGeminiPart(content) {
229
+ if (content.source.type === "base64") {
230
+ return {
231
+ inlineData: {
232
+ mimeType: content.source.mediaType,
233
+ data: content.source.data
234
+ }
235
+ };
236
+ }
237
+ return {
238
+ fileData: {
239
+ fileUri: content.source.url,
240
+ mimeType: mimeTypeFromImageUrl(content.source.url)
241
+ }
242
+ };
243
+ }
244
+ function mimeTypeFromImageUrl(url) {
245
+ const pathname = safeUrlPathname(url).toLowerCase();
246
+ if (pathname.endsWith(".jpg") || pathname.endsWith(".jpeg")) return "image/jpeg";
247
+ if (pathname.endsWith(".webp")) return "image/webp";
248
+ if (pathname.endsWith(".gif")) return "image/gif";
249
+ if (pathname.endsWith(".bmp")) return "image/bmp";
250
+ if (pathname.endsWith(".heic")) return "image/heic";
251
+ if (pathname.endsWith(".heif")) return "image/heif";
252
+ return "image/png";
253
+ }
254
+ function safeUrlPathname(url) {
255
+ try {
256
+ return new URL(url).pathname;
257
+ } catch {
258
+ return url;
259
+ }
260
+ }
261
+ function documentContentToGeminiPart(content) {
262
+ if (content.source.type === "text") {
263
+ return { text: content.source.text };
264
+ }
265
+ if (content.source.type === "base64") {
266
+ return {
267
+ inlineData: {
268
+ mimeType: content.source.mediaType,
269
+ data: content.source.data
270
+ }
271
+ };
272
+ }
273
+ return {
274
+ fileData: {
275
+ fileUri: content.source.url,
276
+ mimeType: content.source.mediaType
277
+ }
278
+ };
279
+ }
280
+ function toolContentToGeminiPart(content, toolNamesById) {
281
+ const id = content.callId ?? content.id;
282
+ const functionResponse = {
283
+ name: toolNamesById.get(id) ?? content.id,
284
+ response: toolResultResponse(content.content)
285
+ };
286
+ if (content.callId !== void 0) {
287
+ functionResponse.id = content.callId;
288
+ }
289
+ return { functionResponse };
290
+ }
291
+ function toolResultResponse(content) {
292
+ return {
293
+ content: content.map((item) => item.type === "text" ? item.text : item.data).join("\n")
294
+ };
295
+ }
296
+ function toolDefinitionToGemini(tool) {
297
+ return {
298
+ name: tool.name,
299
+ description: tool.description,
300
+ parametersJsonSchema: tool.parameters
301
+ };
302
+ }
303
+ function toolChoiceToGemini(toolChoice) {
304
+ if (toolChoice === "auto") {
305
+ return { functionCallingConfig: { mode: "AUTO" } };
306
+ }
307
+ if (toolChoice === "required") {
308
+ return { functionCallingConfig: { mode: "ANY" } };
309
+ }
310
+ if (toolChoice === "none") {
311
+ return { functionCallingConfig: { mode: "NONE" } };
312
+ }
313
+ return {
314
+ functionCallingConfig: {
315
+ mode: "ANY",
316
+ allowedFunctionNames: [toolChoice.name]
317
+ }
318
+ };
319
+ }
320
+ function fromGeminiGenerateContentResponse(response) {
321
+ const raw = response;
322
+ const choice = assistantContentFromGeminiResponse(raw);
323
+ const result = {
324
+ choice,
325
+ usage: usageFromGemini(raw.usageMetadata),
326
+ rawResponse: response
327
+ };
328
+ const id = stringFrom(raw.responseId) ?? stringFrom(raw.id);
329
+ if (id !== void 0) {
330
+ result.messageId = id;
331
+ }
332
+ return result;
333
+ }
334
+ function fromGeminiGenerateContentStreamChunk(chunk) {
335
+ if (!isPlainObject(chunk)) {
336
+ return [];
337
+ }
338
+ const events = [];
339
+ const directText = typeof chunk.text === "string" ? chunk.text : "";
340
+ if (directText.length > 0 && candidateParts(chunk).length === 0) {
341
+ events.push({ type: "text_delta", delta: directText });
342
+ }
343
+ for (const part of candidateParts(chunk)) {
344
+ if (typeof part.text === "string" && part.text.length > 0) {
345
+ if (part.thought === true) {
346
+ events.push({ type: "reasoning_delta", delta: part.text, contentType: "summary" });
347
+ } else {
348
+ events.push({ type: "text_delta", delta: part.text });
349
+ }
350
+ }
351
+ }
352
+ for (const call of functionCallsFromGeminiResponse(chunk)) {
353
+ events.push(
354
+ toolCallDelta(call.id ?? call.name, {
355
+ callId: call.id,
356
+ name: call.name,
357
+ signature: call.signature
358
+ })
359
+ );
360
+ events.push(
361
+ toolCallDelta(call.id ?? call.name, {
362
+ callId: call.id,
363
+ argumentsDelta: JSON.stringify(call.args ?? {})
364
+ })
365
+ );
366
+ }
367
+ const id = stringFrom(chunk.responseId) ?? stringFrom(chunk.id);
368
+ if (id !== void 0) {
369
+ events.push({ type: "message_id", id });
370
+ }
371
+ if (isPlainObject(chunk.usageMetadata)) {
372
+ events.push({ type: "final", response: fromGeminiGenerateContentResponse(chunk) });
373
+ }
374
+ return events;
375
+ }
376
+ function assistantContentFromGeminiResponse(response) {
377
+ const parts = candidateParts(response);
378
+ if (parts.length === 0) {
379
+ const text = textFromGeminiResponse(response);
380
+ return text.length > 0 ? [AssistantContent.text(text)] : [];
381
+ }
382
+ const choice = [];
383
+ for (const part of parts) {
384
+ if (typeof part.text === "string" && part.text.length > 0) {
385
+ if (part.thought === true) {
386
+ choice.push(AssistantContent.reasoningSummary(part.text));
387
+ } else {
388
+ const text = AssistantContent.text(part.text);
389
+ const signature = thoughtSignatureFrom(part);
390
+ if (signature !== void 0) {
391
+ text.signature = signature;
392
+ }
393
+ choice.push(text);
394
+ }
395
+ }
396
+ if (isPlainObject(part.functionCall)) {
397
+ const call = functionCallFromGeminiPart(part.functionCall, part);
398
+ if (call !== void 0) {
399
+ const toolCall = AssistantContent.toolCall(
400
+ call.id ?? crypto.randomUUID(),
401
+ call.name,
402
+ call.args,
403
+ call.id
404
+ );
405
+ if (call.signature !== void 0) {
406
+ toolCall.signature = call.signature;
407
+ }
408
+ choice.push(toolCall);
409
+ }
410
+ }
411
+ }
412
+ return choice;
413
+ }
414
+ function textFromGeminiResponse(response) {
415
+ if (typeof response.text === "string") {
416
+ return response.text;
417
+ }
418
+ return candidateParts(response).flatMap((part) => part.thought !== true && typeof part.text === "string" ? [part.text] : []).join("");
419
+ }
420
+ function functionCallsFromGeminiResponse(response) {
421
+ const directCalls = Array.isArray(response.functionCalls) ? response.functionCalls : Array.isArray(response.function_calls) ? response.function_calls : [];
422
+ const partCalls = candidateParts(response).flatMap((part) => {
423
+ if (!isPlainObject(part.functionCall)) {
424
+ return [];
425
+ }
426
+ const call = functionCallFromGeminiPart(part.functionCall, part);
427
+ return call === void 0 ? [] : [call];
428
+ });
429
+ const normalizedDirectCalls = directCalls.flatMap((call) => {
430
+ if (!isPlainObject(call) || typeof call.name !== "string") {
431
+ return [];
432
+ }
433
+ const normalized = {
434
+ name: call.name,
435
+ args: toJsonValue(call.args ?? {})
436
+ };
437
+ const id = stringFrom(call.id);
438
+ const signature = thoughtSignatureFrom(call);
439
+ if (id !== void 0) {
440
+ normalized.id = id;
441
+ }
442
+ if (signature !== void 0) {
443
+ normalized.signature = signature;
444
+ }
445
+ return [normalized];
446
+ });
447
+ return [...normalizedDirectCalls, ...partCalls];
448
+ }
449
+ function functionCallFromGeminiPart(call, part) {
450
+ if (typeof call.name !== "string") {
451
+ return void 0;
452
+ }
453
+ const normalized = {
454
+ name: call.name,
455
+ args: toJsonValue(call.args ?? {})
456
+ };
457
+ const id = stringFrom(call.id);
458
+ const signature = thoughtSignatureFrom(part) ?? thoughtSignatureFrom(call);
459
+ if (id !== void 0) {
460
+ normalized.id = id;
461
+ }
462
+ if (signature !== void 0) {
463
+ normalized.signature = signature;
464
+ }
465
+ return normalized;
466
+ }
467
+ function candidateParts(response) {
468
+ const candidates = Array.isArray(response.candidates) ? response.candidates : [];
469
+ return candidates.flatMap((candidate) => {
470
+ if (!isPlainObject(candidate) || !isPlainObject(candidate.content)) {
471
+ return [];
472
+ }
473
+ return Array.isArray(candidate.content.parts) ? candidate.content.parts.filter(isPlainObject) : [];
474
+ });
475
+ }
476
+ function usageFromGemini(usage) {
477
+ const raw = isPlainObject(usage) ? usage : {};
478
+ const inputTokens = numberFrom(raw.promptTokenCount);
479
+ const outputTokens = numberFrom(raw.candidatesTokenCount);
480
+ return {
481
+ ...Usage.empty(),
482
+ inputTokens,
483
+ outputTokens,
484
+ totalTokens: numberFrom(raw.totalTokenCount) || inputTokens + outputTokens,
485
+ cachedInputTokens: numberFrom(raw.cachedContentTokenCount)
486
+ };
487
+ }
488
+ function toJsonValue(value) {
489
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || Array.isArray(value) || isPlainObject(value)) {
490
+ return value;
491
+ }
492
+ return String(value);
493
+ }
494
+ function isPlainObject(value) {
495
+ return typeof value === "object" && value !== null && !Array.isArray(value);
496
+ }
497
+ function numberFrom(value) {
498
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
499
+ }
500
+ function stringFrom(value) {
501
+ return typeof value === "string" ? value : void 0;
502
+ }
503
+ function thoughtSignatureFrom(value) {
504
+ return stringFrom(value.thoughtSignature) ?? stringFrom(value.thought_signature);
505
+ }
506
+ function toolCallDelta(id, values) {
507
+ const event = { type: "tool_call_delta", id };
508
+ if (values.callId !== void 0) event.callId = values.callId;
509
+ if (values.name !== void 0) event.name = values.name;
510
+ if (values.argumentsDelta !== void 0) event.argumentsDelta = values.argumentsDelta;
511
+ if (values.signature !== void 0) event.signature = values.signature;
512
+ return event;
513
+ }
514
+
515
+ // src/gemini/embedding.ts
516
+ var GeminiEmbeddingModel = class {
517
+ constructor(client, model, options = {}) {
518
+ this.client = client;
519
+ this.model = model;
520
+ this.dimensions = options.dimensions;
521
+ this.maxBatchSize = options.maxBatchSize ?? 100;
522
+ this.taskType = options.taskType;
523
+ this.title = options.title;
524
+ }
525
+ client;
526
+ model;
527
+ dimensions;
528
+ maxBatchSize;
529
+ taskType;
530
+ title;
531
+ async embedTexts(texts) {
532
+ const embeddings = [];
533
+ for (let index = 0; index < texts.length; index += this.maxBatchSize) {
534
+ const batch = texts.slice(index, index + this.maxBatchSize);
535
+ embeddings.push(...await this.embedBatch(batch));
536
+ }
537
+ return embeddings;
538
+ }
539
+ async embedBatch(texts) {
540
+ if (texts.length === 0) {
541
+ return [];
542
+ }
543
+ const response = await this.client.models.embedContent({
544
+ model: this.model,
545
+ contents: texts,
546
+ config: this.embeddingConfig()
547
+ });
548
+ const rawEmbeddings = embeddingsFromResponse(response);
549
+ if (rawEmbeddings.length !== texts.length) {
550
+ throw new Error(
551
+ `Embedding response length ${rawEmbeddings.length} did not match input length ${texts.length}`
552
+ );
553
+ }
554
+ return rawEmbeddings.map((vector, index) => ({
555
+ document: texts[index],
556
+ vector
557
+ }));
558
+ }
559
+ embeddingConfig() {
560
+ const config = {};
561
+ if (this.dimensions !== void 0) config.outputDimensionality = this.dimensions;
562
+ if (this.taskType !== void 0) config.taskType = this.taskType;
563
+ if (this.title !== void 0) config.title = this.title;
564
+ return config;
565
+ }
566
+ };
567
+ function embeddingsFromResponse(response) {
568
+ const raw = response;
569
+ if (Array.isArray(raw.embeddings)) {
570
+ return raw.embeddings.map(vectorFromEmbedding);
571
+ }
572
+ if (raw.embedding !== void 0) {
573
+ return [vectorFromEmbedding(raw.embedding)];
574
+ }
575
+ return [];
576
+ }
577
+ function vectorFromEmbedding(embedding) {
578
+ const raw = embedding;
579
+ return Array.isArray(raw.values) ? raw.values.filter((value) => typeof value === "number") : [];
580
+ }
581
+
582
+ // src/gemini/image-generation.ts
583
+ import { Buffer as Buffer2 } from "buffer";
584
+ var GEMINI_2_5_FLASH_IMAGE = "gemini-2.5-flash-image";
585
+ var GEMINI_3_PRO_IMAGE_PREVIEW = "gemini-3-pro-image-preview";
586
+ var IMAGEN_4_GENERATE = "imagen-4.0-generate-001";
587
+ var GeminiImageGenerationModel = class {
588
+ constructor(client, defaultModel = GEMINI_2_5_FLASH_IMAGE) {
589
+ this.client = client;
590
+ this.defaultModel = defaultModel;
591
+ }
592
+ client;
593
+ defaultModel;
594
+ provider = "gemini";
595
+ async imageGeneration(request) {
596
+ const params = {
597
+ model: this.defaultModel,
598
+ contents: request.prompt,
599
+ config: {
600
+ responseModalities: ["TEXT", "IMAGE"],
601
+ imageConfig: { aspectRatio: aspectRatio(request.width, request.height) }
602
+ }
603
+ };
604
+ if (isPlainObject2(request.additionalParams)) {
605
+ const { config, ...topLevel } = request.additionalParams;
606
+ Object.assign(params, topLevel);
607
+ if (isPlainObject2(config)) {
608
+ params.config = { ...params.config, ...config };
609
+ }
610
+ }
611
+ const response = await this.client.models.generateContent(params);
612
+ return nativeImageResponseFromGemini(response);
613
+ }
614
+ };
615
+ var GeminiImagenGenerationModel = class {
616
+ constructor(client, defaultModel = IMAGEN_4_GENERATE) {
617
+ this.client = client;
618
+ this.defaultModel = defaultModel;
619
+ }
620
+ client;
621
+ defaultModel;
622
+ provider = "gemini";
623
+ async imageGeneration(request) {
624
+ const params = {
625
+ model: this.defaultModel,
626
+ prompt: request.prompt,
627
+ config: { aspectRatio: aspectRatio(request.width, request.height) }
628
+ };
629
+ if (isPlainObject2(request.additionalParams)) {
630
+ const { config, ...topLevel } = request.additionalParams;
631
+ Object.assign(params, topLevel);
632
+ if (isPlainObject2(config)) {
633
+ params.config = { ...params.config, ...config };
634
+ }
635
+ }
636
+ const response = await this.client.models.generateImages(params);
637
+ return imagenResponseFromGemini(response);
638
+ }
639
+ };
640
+ function nativeImageResponseFromGemini(response) {
641
+ const raw = response;
642
+ const candidates = Array.isArray(raw.candidates) ? raw.candidates : [];
643
+ const images = candidates.flatMap((candidate) => {
644
+ if (!isPlainObject2(candidate) || !isPlainObject2(candidate.content)) {
645
+ return [];
646
+ }
647
+ const parts = Array.isArray(candidate.content.parts) ? candidate.content.parts : [];
648
+ return parts.flatMap((part) => {
649
+ if (!isPlainObject2(part) || !isPlainObject2(part.inlineData)) {
650
+ return [];
651
+ }
652
+ const data = part.inlineData.data;
653
+ if (typeof data !== "string") {
654
+ return [];
655
+ }
656
+ return [
657
+ {
658
+ data: new Uint8Array(Buffer2.from(data, "base64")),
659
+ mediaType: typeof part.inlineData.mimeType === "string" ? part.inlineData.mimeType : "image/png"
660
+ }
661
+ ];
662
+ });
663
+ });
664
+ const image = images[0]?.data;
665
+ if (image === void 0) {
666
+ throw new Error("Gemini image generation response contained no inline image data.");
667
+ }
668
+ return {
669
+ image,
670
+ images,
671
+ mediaType: images[0]?.mediaType,
672
+ rawResponse: response
673
+ };
674
+ }
675
+ function imagenResponseFromGemini(response) {
676
+ const raw = response;
677
+ const images = (Array.isArray(raw.generatedImages) ? raw.generatedImages : []).flatMap(
678
+ (item) => {
679
+ if (!isPlainObject2(item) || !isPlainObject2(item.image)) {
680
+ return [];
681
+ }
682
+ const imageBytes = item.image.imageBytes;
683
+ if (typeof imageBytes !== "string") {
684
+ return [];
685
+ }
686
+ return [
687
+ {
688
+ data: new Uint8Array(Buffer2.from(imageBytes, "base64")),
689
+ mediaType: typeof item.image.mimeType === "string" ? item.image.mimeType : "image/png"
690
+ }
691
+ ];
692
+ }
693
+ );
694
+ const image = images[0]?.data;
695
+ if (image === void 0) {
696
+ throw new Error("Gemini image generation response contained no base64 images.");
697
+ }
698
+ return {
699
+ image,
700
+ images,
701
+ mediaType: images[0]?.mediaType,
702
+ rawResponse: response
703
+ };
704
+ }
705
+ function aspectRatio(width, height) {
706
+ const normalizedWidth = Math.max(1, Math.trunc(width));
707
+ const normalizedHeight = Math.max(1, Math.trunc(height));
708
+ const divisor = gcd(normalizedWidth, normalizedHeight);
709
+ return `${normalizedWidth / divisor}:${normalizedHeight / divisor}`;
710
+ }
711
+ function gcd(left, right) {
712
+ let a = left;
713
+ let b = right;
714
+ while (b !== 0) {
715
+ const next = a % b;
716
+ a = b;
717
+ b = next;
718
+ }
719
+ return a;
720
+ }
721
+ function isPlainObject2(value) {
722
+ return typeof value === "object" && value !== null && !Array.isArray(value);
723
+ }
724
+
725
+ // src/gemini/transcription.ts
726
+ import { Buffer as Buffer3 } from "buffer";
727
+ var TRANSCRIPTION_PREAMBLE = "Translate the provided audio exactly. Do not add additional information.";
728
+ var GeminiTranscriptionModel = class {
729
+ constructor(client, defaultModel = "gemini-2.5-flash") {
730
+ this.client = client;
731
+ this.defaultModel = defaultModel;
732
+ }
733
+ client;
734
+ defaultModel;
735
+ provider = "gemini";
736
+ async transcription(request) {
737
+ const config = {};
738
+ if (request.temperature !== void 0) {
739
+ config.temperature = request.temperature;
740
+ }
741
+ if (isPlainObject3(request.additionalParams)) {
742
+ Object.assign(config, request.additionalParams);
743
+ }
744
+ const response = await this.client.models.generateContent({
745
+ model: this.defaultModel,
746
+ contents: [
747
+ {
748
+ role: "user",
749
+ parts: [
750
+ {
751
+ inlineData: {
752
+ mimeType: mimeTypeFromFilename(request.filename),
753
+ data: Buffer3.from(request.data).toString("base64")
754
+ }
755
+ }
756
+ ]
757
+ }
758
+ ],
759
+ config: {
760
+ ...config,
761
+ systemInstruction: request.prompt === void 0 ? TRANSCRIPTION_PREAMBLE : `${TRANSCRIPTION_PREAMBLE}
762
+
763
+ ${request.prompt}`
764
+ }
765
+ });
766
+ return {
767
+ text: textFromGenerateContentResponse(response),
768
+ rawResponse: response
769
+ };
770
+ }
771
+ };
772
+ function textFromGenerateContentResponse(response) {
773
+ const raw = response;
774
+ if (typeof raw.text === "string") {
775
+ return raw.text;
776
+ }
777
+ const candidates = Array.isArray(raw.candidates) ? raw.candidates : [];
778
+ for (const candidate of candidates) {
779
+ if (!isPlainObject3(candidate) || !isPlainObject3(candidate.content)) {
780
+ continue;
781
+ }
782
+ const parts = Array.isArray(candidate.content.parts) ? candidate.content.parts : [];
783
+ for (const part of parts) {
784
+ if (isPlainObject3(part) && typeof part.text === "string") {
785
+ return part.text;
786
+ }
787
+ }
788
+ }
789
+ throw new Error("Gemini transcription response contained no text.");
790
+ }
791
+ function mimeTypeFromFilename(filename) {
792
+ const lower = filename.toLowerCase();
793
+ if (lower.endsWith(".wav")) return "audio/wav";
794
+ if (lower.endsWith(".aac")) return "audio/aac";
795
+ if (lower.endsWith(".ogg")) return "audio/ogg";
796
+ if (lower.endsWith(".flac")) return "audio/flac";
797
+ if (lower.endsWith(".m4a")) return "audio/m4a";
798
+ if (lower.endsWith(".opus")) return "audio/opus";
799
+ return "audio/mpeg";
800
+ }
801
+ function isPlainObject3(value) {
802
+ return typeof value === "object" && value !== null && !Array.isArray(value);
803
+ }
804
+
805
+ // src/gemini/client.ts
806
+ var GeminiClient = class {
807
+ client;
808
+ constructor(options = {}) {
809
+ this.client = options.client ?? new GoogleGenAI(toGoogleGenAIOptions(options));
810
+ }
811
+ completionModel(model = "gemini-2.5-flash") {
812
+ return new GeminiCompletionModel(this.client, model);
813
+ }
814
+ embeddingModel(model = "gemini-embedding-001", options = {}) {
815
+ return new GeminiEmbeddingModel(this.client, model, options);
816
+ }
817
+ imageGenerationModel(model = GEMINI_2_5_FLASH_IMAGE) {
818
+ return new GeminiImageGenerationModel(this.client, model);
819
+ }
820
+ imagenGenerationModel(model = IMAGEN_4_GENERATE) {
821
+ return new GeminiImagenGenerationModel(this.client, model);
822
+ }
823
+ transcriptionModel(model = "gemini-2.5-flash") {
824
+ return new GeminiTranscriptionModel(this.client, model);
825
+ }
826
+ };
827
+ function toGoogleGenAIOptions(options) {
828
+ if (options.vertexai === true) {
829
+ return {
830
+ vertexai: true,
831
+ project: requireOption(options.project, "project", "Vertex Gemini"),
832
+ location: requireOption(options.location, "location", "Vertex Gemini")
833
+ };
834
+ }
835
+ return {
836
+ apiKey: requireOption(options.apiKey, "apiKey", "Gemini")
837
+ };
838
+ }
839
+ function requireOption(value, name, label) {
840
+ if (value === void 0 || value.length === 0) {
841
+ throw new Error(`Missing ${label} ${name}. Pass ${name} when constructing GeminiClient.`);
842
+ }
843
+ return value;
844
+ }
845
+ export {
846
+ GEMINI_2_5_FLASH_IMAGE,
847
+ GEMINI_3_PRO_IMAGE_PREVIEW,
848
+ GeminiClient,
849
+ GeminiCompletionModel,
850
+ GeminiEmbeddingModel,
851
+ GeminiImageGenerationModel,
852
+ GeminiImagenGenerationModel,
853
+ GeminiTranscriptionModel,
854
+ IMAGEN_4_GENERATE,
855
+ gemini_exports as gemini
856
+ };
857
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gemini/index.ts","../src/gemini/client.ts","../src/gemini/completion.ts","../src/request-messages.ts","../src/gemini/embedding.ts","../src/gemini/image-generation.ts","../src/gemini/transcription.ts"],"sourcesContent":["export { GeminiClient, type GeminiClientOptions } from \"./client\";\nexport { GeminiCompletionModel } from \"./completion\";\nexport {\n GeminiEmbeddingModel,\n type GeminiEmbeddingModelOptions,\n type GeminiEmbeddingTaskType,\n} from \"./embedding\";\nexport {\n GEMINI_2_5_FLASH_IMAGE,\n GEMINI_3_PRO_IMAGE_PREVIEW,\n GeminiImageGenerationModel,\n GeminiImagenGenerationModel,\n IMAGEN_4_GENERATE,\n} from \"./image-generation\";\nexport { GeminiTranscriptionModel } from \"./transcription\";\n","import { GoogleGenAI } from \"@google/genai\";\nimport { GeminiCompletionModel } from \"./completion\";\nimport { GeminiEmbeddingModel, type GeminiEmbeddingModelOptions } from \"./embedding\";\nimport {\n GEMINI_2_5_FLASH_IMAGE,\n GeminiImageGenerationModel,\n GeminiImagenGenerationModel,\n IMAGEN_4_GENERATE,\n} from \"./image-generation\";\nimport { GeminiTranscriptionModel } from \"./transcription\";\n\ntype GeminiApiClientOptions = {\n apiKey?: string | undefined;\n vertexai?: false | undefined;\n project?: never;\n location?: never;\n};\n\ntype VertexClientOptions = {\n vertexai: true;\n project?: string | undefined;\n location?: string | undefined;\n apiKey?: never;\n};\n\nexport type GeminiClientOptions = (GeminiApiClientOptions | VertexClientOptions) & {\n client?: GoogleGenAI | undefined;\n};\n\nexport class GeminiClient {\n readonly client: GoogleGenAI;\n\n constructor(options: GeminiClientOptions = {}) {\n this.client = options.client ?? new GoogleGenAI(toGoogleGenAIOptions(options));\n }\n\n completionModel(model = \"gemini-2.5-flash\"): GeminiCompletionModel {\n return new GeminiCompletionModel(this.client, model);\n }\n\n embeddingModel(\n model = \"gemini-embedding-001\",\n options: GeminiEmbeddingModelOptions = {},\n ): GeminiEmbeddingModel {\n return new GeminiEmbeddingModel(this.client, model, options);\n }\n\n imageGenerationModel(model = GEMINI_2_5_FLASH_IMAGE): GeminiImageGenerationModel {\n return new GeminiImageGenerationModel(this.client, model);\n }\n\n imagenGenerationModel(model = IMAGEN_4_GENERATE): GeminiImagenGenerationModel {\n return new GeminiImagenGenerationModel(this.client, model);\n }\n\n transcriptionModel(model = \"gemini-2.5-flash\"): GeminiTranscriptionModel {\n return new GeminiTranscriptionModel(this.client, model);\n }\n}\n\nexport function toGoogleGenAIOptions(options: GeminiClientOptions): Record<string, unknown> {\n if (options.vertexai === true) {\n return {\n vertexai: true,\n project: requireOption(options.project, \"project\", \"Vertex Gemini\"),\n location: requireOption(options.location, \"location\", \"Vertex Gemini\"),\n };\n }\n\n return {\n apiKey: requireOption(options.apiKey, \"apiKey\", \"Gemini\"),\n };\n}\n\nfunction requireOption(value: string | undefined, name: string, label: string): string {\n if (value === undefined || value.length === 0) {\n throw new Error(`Missing ${label} ${name}. Pass ${name} when constructing GeminiClient.`);\n }\n\n return value;\n}\n","import {\n AssistantContent,\n type AssistantContent as AssistantContentType,\n assertCompletionRequestSupported,\n type CompletionModelCapabilities,\n type CompletionRequest,\n type CompletionResponse,\n type CompletionStreamEvent,\n type JsonValue,\n type Message as MessageType,\n type StreamingCompletionModel,\n type ToolChoice,\n type ToolContent,\n type ToolDefinition,\n Usage,\n type UserContent,\n} from \"@anvia/core/completion\";\nimport type { GoogleGenAI } from \"@google/genai\";\nimport { orderedRequestMessages } from \"../request-messages\";\n\ntype GeminiGenerateParams = Record<string, unknown>;\ntype GeminiConfig = Record<string, unknown>;\ntype GeminiContent = {\n role: \"user\" | \"model\";\n parts: GeminiPart[];\n};\ntype GeminiPart = Record<string, unknown>;\n\nexport class GeminiCompletionModel implements StreamingCompletionModel {\n readonly provider = \"gemini\";\n readonly capabilities: CompletionModelCapabilities = {\n streaming: true,\n tools: true,\n toolChoice: true,\n imageInput: true,\n documentInput: true,\n outputSchema: true,\n reasoning: true,\n };\n\n constructor(\n private readonly client: GoogleGenAI,\n readonly defaultModel = \"gemini-2.5-flash\",\n ) {}\n\n async completion(request: CompletionRequest): Promise<CompletionResponse> {\n assertCompletionRequestSupported(this, request);\n const params = toGeminiGenerateContentParams(this.defaultModel, request);\n const response = await this.client.models.generateContent(params as never);\n return fromGeminiGenerateContentResponse(response);\n }\n\n async *streamCompletion(request: CompletionRequest): AsyncIterable<CompletionStreamEvent> {\n assertCompletionRequestSupported(this, request, { streaming: true });\n const params = toGeminiGenerateContentParams(this.defaultModel, request);\n const stream = await this.client.models.generateContentStream(params as never);\n for await (const chunk of stream as unknown as AsyncIterable<unknown>) {\n for (const event of fromGeminiGenerateContentStreamChunk(chunk)) {\n yield event;\n }\n }\n }\n}\n\nexport function toGeminiGenerateContentParams(\n defaultModel: string,\n request: CompletionRequest,\n): GeminiGenerateParams {\n const messages = requestMessages(request);\n const config = geminiConfig(request, messages);\n const params: GeminiGenerateParams = {\n model: request.model ?? defaultModel,\n contents: messagesToGeminiContents(messages),\n config,\n };\n\n if (request.additionalParams !== undefined && isPlainObject(request.additionalParams)) {\n const { config: additionalConfig, ...additionalTopLevel } = request.additionalParams;\n Object.assign(params, additionalTopLevel);\n if (isPlainObject(additionalConfig)) {\n params.config = { ...config, ...additionalConfig };\n }\n }\n\n return params;\n}\n\nfunction requestMessages(request: CompletionRequest): MessageType[] {\n return orderedRequestMessages(request);\n}\n\nfunction geminiConfig(request: CompletionRequest, messages: MessageType[]): GeminiConfig {\n const config: GeminiConfig = {};\n const systemInstruction = systemInstructionFrom(request, messages);\n if (systemInstruction !== undefined) {\n config.systemInstruction = systemInstruction;\n }\n if (request.temperature !== undefined) {\n config.temperature = request.temperature;\n }\n if (request.maxTokens !== undefined) {\n config.maxOutputTokens = request.maxTokens;\n }\n if (request.tools.length > 0) {\n config.tools = [{ functionDeclarations: request.tools.map(toolDefinitionToGemini) }];\n }\n if (request.toolChoice !== undefined) {\n config.toolConfig = toolChoiceToGemini(request.toolChoice);\n }\n if (request.outputSchema !== undefined) {\n config.responseMimeType = \"application/json\";\n config.responseJsonSchema = request.outputSchema;\n }\n return config;\n}\n\nfunction systemInstructionFrom(\n request: CompletionRequest,\n messages: MessageType[],\n): string | undefined {\n const systemMessages = messages.flatMap((message) =>\n message.role === \"system\" ? [message.content] : [],\n );\n if (request.instructions !== undefined) {\n systemMessages.unshift(request.instructions);\n }\n return systemMessages.length === 0 ? undefined : systemMessages.join(\"\\n\\n\");\n}\n\nexport function messagesToGeminiContents(messages: MessageType[]): GeminiContent[] {\n const toolNamesById = new Map<string, string>();\n const contents: GeminiContent[] = [];\n\n for (const message of messages) {\n if (message.role === \"system\") {\n continue;\n }\n\n if (message.role === \"assistant\") {\n const content = assistantMessageToGeminiContent(message);\n for (const item of message.content) {\n if (item.type === \"tool_call\") {\n toolNamesById.set(item.id, item.function.name);\n if (item.callId !== undefined) {\n toolNamesById.set(item.callId, item.function.name);\n }\n }\n }\n if (content.parts.length > 0) {\n contents.push(content);\n }\n continue;\n }\n\n const content =\n message.role === \"tool\"\n ? toolMessageToGeminiContent(message, toolNamesById)\n : userMessageToGeminiContent(message);\n if (content.parts.length > 0) {\n contents.push(content);\n }\n }\n\n return contents;\n}\n\nfunction userMessageToGeminiContent(\n message: Extract<MessageType, { role: \"user\" }>,\n): GeminiContent {\n return {\n role: \"user\",\n parts: message.content.map(userContentToGeminiPart),\n };\n}\n\nfunction toolMessageToGeminiContent(\n message: Extract<MessageType, { role: \"tool\" }>,\n toolNamesById: Map<string, string>,\n): GeminiContent {\n return {\n role: \"user\",\n parts: message.content.map((content) => toolContentToGeminiPart(content, toolNamesById)),\n };\n}\n\nfunction assistantMessageToGeminiContent(\n message: Extract<MessageType, { role: \"assistant\" }>,\n): GeminiContent {\n return {\n role: \"model\",\n parts: message.content.flatMap((content): GeminiPart[] => {\n if (content.type === \"text\") {\n const part: GeminiPart = { text: content.text };\n if (content.signature !== undefined) {\n part.thoughtSignature = content.signature;\n }\n return [part];\n }\n if (content.type === \"tool_call\") {\n const functionCall: Record<string, unknown> = {\n name: content.function.name,\n args: content.function.arguments ?? {},\n };\n if (content.callId !== undefined) {\n functionCall.id = content.callId;\n }\n const part: GeminiPart = { functionCall };\n if (content.signature !== undefined) {\n part.thoughtSignature = content.signature;\n }\n return [part];\n }\n if (content.type === \"reasoning\" && content.content !== undefined) {\n return content.content.flatMap((reasoning): GeminiPart[] => {\n if (reasoning.type !== \"text\" && reasoning.type !== \"summary\") {\n return [];\n }\n const part: GeminiPart = { text: reasoning.text, thought: true };\n if (reasoning.type === \"text\" && reasoning.signature !== undefined) {\n part.thoughtSignature = reasoning.signature;\n }\n return [part];\n });\n }\n if (content.type === \"image\") {\n throw new Error(\"Gemini does not support image content in assistant history yet\");\n }\n return [];\n }),\n };\n}\n\nfunction userContentToGeminiPart(content: UserContent): GeminiPart {\n if (content.type === \"text\") {\n return { text: content.text };\n }\n if (content.type === \"image\") {\n return imageContentToGeminiPart(content);\n }\n return documentContentToGeminiPart(content);\n}\n\nfunction imageContentToGeminiPart(content: Extract<UserContent, { type: \"image\" }>): GeminiPart {\n if (content.source.type === \"base64\") {\n return {\n inlineData: {\n mimeType: content.source.mediaType,\n data: content.source.data,\n },\n };\n }\n\n return {\n fileData: {\n fileUri: content.source.url,\n mimeType: mimeTypeFromImageUrl(content.source.url),\n },\n };\n}\n\nfunction mimeTypeFromImageUrl(url: string): string {\n const pathname = safeUrlPathname(url).toLowerCase();\n if (pathname.endsWith(\".jpg\") || pathname.endsWith(\".jpeg\")) return \"image/jpeg\";\n if (pathname.endsWith(\".webp\")) return \"image/webp\";\n if (pathname.endsWith(\".gif\")) return \"image/gif\";\n if (pathname.endsWith(\".bmp\")) return \"image/bmp\";\n if (pathname.endsWith(\".heic\")) return \"image/heic\";\n if (pathname.endsWith(\".heif\")) return \"image/heif\";\n return \"image/png\";\n}\n\nfunction safeUrlPathname(url: string): string {\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n}\n\nfunction documentContentToGeminiPart(\n content: Extract<UserContent, { type: \"document\" }>,\n): GeminiPart {\n if (content.source.type === \"text\") {\n return { text: content.source.text };\n }\n\n if (content.source.type === \"base64\") {\n return {\n inlineData: {\n mimeType: content.source.mediaType,\n data: content.source.data,\n },\n };\n }\n\n return {\n fileData: {\n fileUri: content.source.url,\n mimeType: content.source.mediaType,\n },\n };\n}\n\nfunction toolContentToGeminiPart(\n content: ToolContent,\n toolNamesById: Map<string, string>,\n): GeminiPart {\n const id = content.callId ?? content.id;\n const functionResponse: Record<string, unknown> = {\n name: toolNamesById.get(id) ?? content.id,\n response: toolResultResponse(content.content),\n };\n if (content.callId !== undefined) {\n functionResponse.id = content.callId;\n }\n return { functionResponse };\n}\n\nfunction toolResultResponse(\n content: Array<\n { type: \"text\"; text: string } | { type: \"image\"; data: string; mediaType?: string }\n >,\n): Record<string, unknown> {\n return {\n content: content.map((item) => (item.type === \"text\" ? item.text : item.data)).join(\"\\n\"),\n };\n}\n\nfunction toolDefinitionToGemini(tool: ToolDefinition): GeminiPart {\n return {\n name: tool.name,\n description: tool.description,\n parametersJsonSchema: tool.parameters,\n };\n}\n\nfunction toolChoiceToGemini(toolChoice: ToolChoice): GeminiPart {\n if (toolChoice === \"auto\") {\n return { functionCallingConfig: { mode: \"AUTO\" } };\n }\n if (toolChoice === \"required\") {\n return { functionCallingConfig: { mode: \"ANY\" } };\n }\n if (toolChoice === \"none\") {\n return { functionCallingConfig: { mode: \"NONE\" } };\n }\n return {\n functionCallingConfig: {\n mode: \"ANY\",\n allowedFunctionNames: [toolChoice.name],\n },\n };\n}\n\nexport function fromGeminiGenerateContentResponse(response: unknown): CompletionResponse {\n const raw = response as Record<string, unknown>;\n const choice = assistantContentFromGeminiResponse(raw);\n\n const result: CompletionResponse = {\n choice,\n usage: usageFromGemini(raw.usageMetadata),\n rawResponse: response,\n };\n const id = stringFrom(raw.responseId) ?? stringFrom(raw.id);\n if (id !== undefined) {\n result.messageId = id;\n }\n return result;\n}\n\nexport function fromGeminiGenerateContentStreamChunk(chunk: unknown): CompletionStreamEvent[] {\n if (!isPlainObject(chunk)) {\n return [];\n }\n\n const events: CompletionStreamEvent[] = [];\n const directText = typeof chunk.text === \"string\" ? chunk.text : \"\";\n if (directText.length > 0 && candidateParts(chunk).length === 0) {\n events.push({ type: \"text_delta\", delta: directText });\n }\n for (const part of candidateParts(chunk)) {\n if (typeof part.text === \"string\" && part.text.length > 0) {\n if (part.thought === true) {\n events.push({ type: \"reasoning_delta\", delta: part.text, contentType: \"summary\" });\n } else {\n events.push({ type: \"text_delta\", delta: part.text });\n }\n }\n }\n for (const call of functionCallsFromGeminiResponse(chunk)) {\n events.push(\n toolCallDelta(call.id ?? call.name, {\n callId: call.id,\n name: call.name,\n signature: call.signature,\n }),\n );\n events.push(\n toolCallDelta(call.id ?? call.name, {\n callId: call.id,\n argumentsDelta: JSON.stringify(call.args ?? {}),\n }),\n );\n }\n const id = stringFrom(chunk.responseId) ?? stringFrom(chunk.id);\n if (id !== undefined) {\n events.push({ type: \"message_id\", id });\n }\n if (isPlainObject(chunk.usageMetadata)) {\n events.push({ type: \"final\", response: fromGeminiGenerateContentResponse(chunk) });\n }\n return events;\n}\n\nfunction assistantContentFromGeminiResponse(\n response: Record<string, unknown>,\n): AssistantContentType[] {\n const parts = candidateParts(response);\n if (parts.length === 0) {\n const text = textFromGeminiResponse(response);\n return text.length > 0 ? [AssistantContent.text(text)] : [];\n }\n\n const choice: AssistantContentType[] = [];\n for (const part of parts) {\n if (typeof part.text === \"string\" && part.text.length > 0) {\n if (part.thought === true) {\n choice.push(AssistantContent.reasoningSummary(part.text));\n } else {\n const text = AssistantContent.text(part.text);\n const signature = thoughtSignatureFrom(part);\n if (signature !== undefined) {\n text.signature = signature;\n }\n choice.push(text);\n }\n }\n if (isPlainObject(part.functionCall)) {\n const call = functionCallFromGeminiPart(part.functionCall, part);\n if (call !== undefined) {\n const toolCall = AssistantContent.toolCall(\n call.id ?? crypto.randomUUID(),\n call.name,\n call.args,\n call.id,\n );\n if (call.signature !== undefined) {\n toolCall.signature = call.signature;\n }\n choice.push(toolCall);\n }\n }\n }\n return choice;\n}\n\nfunction textFromGeminiResponse(response: Record<string, unknown>): string {\n if (typeof response.text === \"string\") {\n return response.text;\n }\n return candidateParts(response)\n .flatMap((part) => (part.thought !== true && typeof part.text === \"string\" ? [part.text] : []))\n .join(\"\");\n}\n\nfunction functionCallsFromGeminiResponse(\n response: Record<string, unknown>,\n): Array<{ id?: string | undefined; name: string; args: JsonValue; signature?: string }> {\n const directCalls = Array.isArray(response.functionCalls)\n ? response.functionCalls\n : Array.isArray(response.function_calls)\n ? response.function_calls\n : [];\n const partCalls = candidateParts(response).flatMap((part) => {\n if (!isPlainObject(part.functionCall)) {\n return [];\n }\n const call = functionCallFromGeminiPart(part.functionCall, part);\n return call === undefined ? [] : [call];\n });\n\n const normalizedDirectCalls = directCalls.flatMap((call) => {\n if (!isPlainObject(call) || typeof call.name !== \"string\") {\n return [];\n }\n const normalized: { id?: string; name: string; args: JsonValue; signature?: string } = {\n name: call.name,\n args: toJsonValue(call.args ?? {}),\n };\n const id = stringFrom(call.id);\n const signature = thoughtSignatureFrom(call);\n if (id !== undefined) {\n normalized.id = id;\n }\n if (signature !== undefined) {\n normalized.signature = signature;\n }\n return [normalized];\n });\n\n return [...normalizedDirectCalls, ...partCalls];\n}\n\nfunction functionCallFromGeminiPart(\n call: Record<string, unknown>,\n part: Record<string, unknown>,\n): { id?: string | undefined; name: string; args: JsonValue; signature?: string } | undefined {\n if (typeof call.name !== \"string\") {\n return undefined;\n }\n const normalized: { id?: string; name: string; args: JsonValue; signature?: string } = {\n name: call.name,\n args: toJsonValue(call.args ?? {}),\n };\n const id = stringFrom(call.id);\n const signature = thoughtSignatureFrom(part) ?? thoughtSignatureFrom(call);\n if (id !== undefined) {\n normalized.id = id;\n }\n if (signature !== undefined) {\n normalized.signature = signature;\n }\n return normalized;\n}\n\nfunction candidateParts(response: Record<string, unknown>): Array<Record<string, unknown>> {\n const candidates = Array.isArray(response.candidates) ? response.candidates : [];\n return candidates.flatMap((candidate) => {\n if (!isPlainObject(candidate) || !isPlainObject(candidate.content)) {\n return [];\n }\n return Array.isArray(candidate.content.parts)\n ? candidate.content.parts.filter(isPlainObject)\n : [];\n });\n}\n\nfunction usageFromGemini(usage: unknown): Usage {\n const raw = isPlainObject(usage) ? usage : {};\n const inputTokens = numberFrom(raw.promptTokenCount);\n const outputTokens = numberFrom(raw.candidatesTokenCount);\n return {\n ...Usage.empty(),\n inputTokens,\n outputTokens,\n totalTokens: numberFrom(raw.totalTokenCount) || inputTokens + outputTokens,\n cachedInputTokens: numberFrom(raw.cachedContentTokenCount),\n };\n}\n\nfunction toJsonValue(value: unknown): JsonValue {\n if (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n Array.isArray(value) ||\n isPlainObject(value)\n ) {\n return value as JsonValue;\n }\n\n return String(value);\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction numberFrom(value: unknown): number {\n return typeof value === \"number\" && Number.isFinite(value) ? value : 0;\n}\n\nfunction stringFrom(value: unknown): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n}\n\nfunction thoughtSignatureFrom(value: Record<string, unknown>): string | undefined {\n return stringFrom(value.thoughtSignature) ?? stringFrom(value.thought_signature);\n}\n\nfunction toolCallDelta(\n id: string,\n values: {\n callId?: string | undefined;\n name?: string | undefined;\n argumentsDelta?: string | undefined;\n signature?: string | undefined;\n },\n): CompletionStreamEvent {\n const event: CompletionStreamEvent = { type: \"tool_call_delta\", id };\n if (values.callId !== undefined) event.callId = values.callId;\n if (values.name !== undefined) event.name = values.name;\n if (values.argumentsDelta !== undefined) event.argumentsDelta = values.argumentsDelta;\n if (values.signature !== undefined) event.signature = values.signature;\n return event;\n}\n","import {\n type CompletionRequest,\n type Message as MessageType,\n normalizeDocuments,\n} from \"@anvia/core/completion\";\n\nexport function orderedRequestMessages(request: CompletionRequest): MessageType[] {\n const messages: MessageType[] = [];\n messages.push(...request.chatHistory.filter((message) => message.role === \"system\"));\n const documents = normalizeDocuments(request.documents);\n if (documents !== undefined) {\n messages.push(documents);\n }\n messages.push(...request.chatHistory.filter((message) => message.role !== \"system\"));\n return messages;\n}\n","import type { Embedding, EmbeddingModel } from \"@anvia/core/embeddings\";\nimport type { GoogleGenAI } from \"@google/genai\";\n\nexport type GeminiEmbeddingTaskType =\n | \"TASK_TYPE_UNSPECIFIED\"\n | \"RETRIEVAL_QUERY\"\n | \"RETRIEVAL_DOCUMENT\"\n | \"SEMANTIC_SIMILARITY\"\n | \"CLASSIFICATION\"\n | \"CLUSTERING\"\n | \"QUESTION_ANSWERING\"\n | \"FACT_VERIFICATION\"\n | \"CODE_RETRIEVAL_QUERY\";\n\nexport type GeminiEmbeddingModelOptions = {\n dimensions?: number | undefined;\n maxBatchSize?: number | undefined;\n taskType?: GeminiEmbeddingTaskType | undefined;\n title?: string | undefined;\n};\n\nexport class GeminiEmbeddingModel implements EmbeddingModel {\n readonly dimensions: number | undefined;\n readonly maxBatchSize: number;\n private readonly taskType: GeminiEmbeddingTaskType | undefined;\n private readonly title: string | undefined;\n\n constructor(\n private readonly client: GoogleGenAI,\n private readonly model: string,\n options: GeminiEmbeddingModelOptions = {},\n ) {\n this.dimensions = options.dimensions;\n this.maxBatchSize = options.maxBatchSize ?? 100;\n this.taskType = options.taskType;\n this.title = options.title;\n }\n\n async embedTexts(texts: string[]): Promise<Embedding[]> {\n const embeddings: Embedding[] = [];\n for (let index = 0; index < texts.length; index += this.maxBatchSize) {\n const batch = texts.slice(index, index + this.maxBatchSize);\n embeddings.push(...(await this.embedBatch(batch)));\n }\n return embeddings;\n }\n\n private async embedBatch(texts: string[]): Promise<Embedding[]> {\n if (texts.length === 0) {\n return [];\n }\n\n const response = await this.client.models.embedContent({\n model: this.model,\n contents: texts,\n config: this.embeddingConfig(),\n } as never);\n const rawEmbeddings = embeddingsFromResponse(response);\n if (rawEmbeddings.length !== texts.length) {\n throw new Error(\n `Embedding response length ${rawEmbeddings.length} did not match input length ${texts.length}`,\n );\n }\n\n return rawEmbeddings.map((vector, index) => ({\n document: texts[index] as string,\n vector,\n }));\n }\n\n private embeddingConfig(): Record<string, unknown> {\n const config: Record<string, unknown> = {};\n if (this.dimensions !== undefined) config.outputDimensionality = this.dimensions;\n if (this.taskType !== undefined) config.taskType = this.taskType;\n if (this.title !== undefined) config.title = this.title;\n return config;\n }\n}\n\nfunction embeddingsFromResponse(response: unknown): number[][] {\n const raw = response as Record<string, unknown>;\n if (Array.isArray(raw.embeddings)) {\n return raw.embeddings.map(vectorFromEmbedding);\n }\n if (raw.embedding !== undefined) {\n return [vectorFromEmbedding(raw.embedding)];\n }\n return [];\n}\n\nfunction vectorFromEmbedding(embedding: unknown): number[] {\n const raw = embedding as Record<string, unknown>;\n return Array.isArray(raw.values)\n ? raw.values.filter((value): value is number => typeof value === \"number\")\n : [];\n}\n","import { Buffer } from \"node:buffer\";\nimport type {\n GeneratedImage,\n ImageGenerationModel,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@anvia/core/image-generation\";\nimport type { GoogleGenAI } from \"@google/genai\";\n\nexport const GEMINI_2_5_FLASH_IMAGE = \"gemini-2.5-flash-image\";\nexport const GEMINI_3_PRO_IMAGE_PREVIEW = \"gemini-3-pro-image-preview\";\nexport const IMAGEN_4_GENERATE = \"imagen-4.0-generate-001\";\n\nexport class GeminiImageGenerationModel implements ImageGenerationModel {\n readonly provider = \"gemini\";\n\n constructor(\n private readonly client: GoogleGenAI,\n readonly defaultModel = GEMINI_2_5_FLASH_IMAGE,\n ) {}\n\n async imageGeneration(\n request: ImageGenerationRequest,\n ): Promise<ImageGenerationResponse<unknown>> {\n const params: Record<string, unknown> = {\n model: this.defaultModel,\n contents: request.prompt,\n config: {\n responseModalities: [\"TEXT\", \"IMAGE\"],\n imageConfig: { aspectRatio: aspectRatio(request.width, request.height) },\n },\n };\n\n if (isPlainObject(request.additionalParams)) {\n const { config, ...topLevel } = request.additionalParams;\n Object.assign(params, topLevel);\n if (isPlainObject(config)) {\n params.config = { ...(params.config as Record<string, unknown>), ...config };\n }\n }\n\n const response = await this.client.models.generateContent(params as never);\n return nativeImageResponseFromGemini(response);\n }\n}\n\nexport class GeminiImagenGenerationModel implements ImageGenerationModel {\n readonly provider = \"gemini\";\n\n constructor(\n private readonly client: GoogleGenAI,\n readonly defaultModel = IMAGEN_4_GENERATE,\n ) {}\n\n async imageGeneration(\n request: ImageGenerationRequest,\n ): Promise<ImageGenerationResponse<unknown>> {\n const params: Record<string, unknown> = {\n model: this.defaultModel,\n prompt: request.prompt,\n config: { aspectRatio: aspectRatio(request.width, request.height) },\n };\n\n if (isPlainObject(request.additionalParams)) {\n const { config, ...topLevel } = request.additionalParams;\n Object.assign(params, topLevel);\n if (isPlainObject(config)) {\n params.config = { ...(params.config as Record<string, unknown>), ...config };\n }\n }\n\n const response = await this.client.models.generateImages(params as never);\n return imagenResponseFromGemini(response);\n }\n}\n\nexport function nativeImageResponseFromGemini(response: unknown): ImageGenerationResponse<unknown> {\n const raw = response as Record<string, unknown>;\n const candidates = Array.isArray(raw.candidates) ? raw.candidates : [];\n const images = candidates.flatMap((candidate): GeneratedImage[] => {\n if (!isPlainObject(candidate) || !isPlainObject(candidate.content)) {\n return [];\n }\n const parts = Array.isArray(candidate.content.parts) ? candidate.content.parts : [];\n return parts.flatMap((part): GeneratedImage[] => {\n if (!isPlainObject(part) || !isPlainObject(part.inlineData)) {\n return [];\n }\n const data = part.inlineData.data;\n if (typeof data !== \"string\") {\n return [];\n }\n return [\n {\n data: new Uint8Array(Buffer.from(data, \"base64\")),\n mediaType:\n typeof part.inlineData.mimeType === \"string\" ? part.inlineData.mimeType : \"image/png\",\n },\n ];\n });\n });\n\n const image = images[0]?.data;\n if (image === undefined) {\n throw new Error(\"Gemini image generation response contained no inline image data.\");\n }\n\n return {\n image,\n images,\n mediaType: images[0]?.mediaType,\n rawResponse: response,\n };\n}\n\nexport function imagenResponseFromGemini(response: unknown): ImageGenerationResponse<unknown> {\n const raw = response as Record<string, unknown>;\n const images = (Array.isArray(raw.generatedImages) ? raw.generatedImages : []).flatMap(\n (item): GeneratedImage[] => {\n if (!isPlainObject(item) || !isPlainObject(item.image)) {\n return [];\n }\n const imageBytes = item.image.imageBytes;\n if (typeof imageBytes !== \"string\") {\n return [];\n }\n return [\n {\n data: new Uint8Array(Buffer.from(imageBytes, \"base64\")),\n mediaType: typeof item.image.mimeType === \"string\" ? item.image.mimeType : \"image/png\",\n },\n ];\n },\n );\n\n const image = images[0]?.data;\n if (image === undefined) {\n throw new Error(\"Gemini image generation response contained no base64 images.\");\n }\n\n return {\n image,\n images,\n mediaType: images[0]?.mediaType,\n rawResponse: response,\n };\n}\n\nexport function aspectRatio(width: number, height: number): string {\n const normalizedWidth = Math.max(1, Math.trunc(width));\n const normalizedHeight = Math.max(1, Math.trunc(height));\n const divisor = gcd(normalizedWidth, normalizedHeight);\n return `${normalizedWidth / divisor}:${normalizedHeight / divisor}`;\n}\n\nfunction gcd(left: number, right: number): number {\n let a = left;\n let b = right;\n while (b !== 0) {\n const next = a % b;\n a = b;\n b = next;\n }\n return a;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","import { Buffer } from \"node:buffer\";\nimport type {\n TranscriptionModel,\n TranscriptionRequest,\n TranscriptionResponse,\n} from \"@anvia/core/transcription\";\nimport type { GoogleGenAI } from \"@google/genai\";\n\nconst TRANSCRIPTION_PREAMBLE =\n \"Translate the provided audio exactly. Do not add additional information.\";\n\nexport class GeminiTranscriptionModel implements TranscriptionModel {\n readonly provider = \"gemini\";\n\n constructor(\n private readonly client: GoogleGenAI,\n readonly defaultModel = \"gemini-2.5-flash\",\n ) {}\n\n async transcription(request: TranscriptionRequest): Promise<TranscriptionResponse<unknown>> {\n const config: Record<string, unknown> = {};\n if (request.temperature !== undefined) {\n config.temperature = request.temperature;\n }\n if (isPlainObject(request.additionalParams)) {\n Object.assign(config, request.additionalParams);\n }\n\n const response = await this.client.models.generateContent({\n model: this.defaultModel,\n contents: [\n {\n role: \"user\",\n parts: [\n {\n inlineData: {\n mimeType: mimeTypeFromFilename(request.filename),\n data: Buffer.from(request.data).toString(\"base64\"),\n },\n },\n ],\n },\n ],\n config: {\n ...config,\n systemInstruction:\n request.prompt === undefined\n ? TRANSCRIPTION_PREAMBLE\n : `${TRANSCRIPTION_PREAMBLE}\\n\\n${request.prompt}`,\n },\n } as never);\n\n return {\n text: textFromGenerateContentResponse(response),\n rawResponse: response,\n };\n }\n}\n\nexport function textFromGenerateContentResponse(response: unknown): string {\n const raw = response as Record<string, unknown>;\n if (typeof raw.text === \"string\") {\n return raw.text;\n }\n const candidates = Array.isArray(raw.candidates) ? raw.candidates : [];\n for (const candidate of candidates) {\n if (!isPlainObject(candidate) || !isPlainObject(candidate.content)) {\n continue;\n }\n const parts = Array.isArray(candidate.content.parts) ? candidate.content.parts : [];\n for (const part of parts) {\n if (isPlainObject(part) && typeof part.text === \"string\") {\n return part.text;\n }\n }\n }\n throw new Error(\"Gemini transcription response contained no text.\");\n}\n\nfunction mimeTypeFromFilename(filename: string): string {\n const lower = filename.toLowerCase();\n if (lower.endsWith(\".wav\")) return \"audio/wav\";\n if (lower.endsWith(\".aac\")) return \"audio/aac\";\n if (lower.endsWith(\".ogg\")) return \"audio/ogg\";\n if (lower.endsWith(\".flac\")) return \"audio/flac\";\n if (lower.endsWith(\".m4a\")) return \"audio/m4a\";\n if (lower.endsWith(\".opus\")) return \"audio/opus\";\n return \"audio/mpeg\";\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,SAAS,mBAAmB;;;ACA5B;AAAA,EACE;AAAA,EAEA;AAAA,EAWA;AAAA,OAEK;;;AChBP;AAAA,EAGE;AAAA,OACK;AAEA,SAAS,uBAAuB,SAA2C;AAChF,QAAM,WAA0B,CAAC;AACjC,WAAS,KAAK,GAAG,QAAQ,YAAY,OAAO,CAAC,YAAY,QAAQ,SAAS,QAAQ,CAAC;AACnF,QAAM,YAAY,mBAAmB,QAAQ,SAAS;AACtD,MAAI,cAAc,QAAW;AAC3B,aAAS,KAAK,SAAS;AAAA,EACzB;AACA,WAAS,KAAK,GAAG,QAAQ,YAAY,OAAO,CAAC,YAAY,QAAQ,SAAS,QAAQ,CAAC;AACnF,SAAO;AACT;;;ADaO,IAAM,wBAAN,MAAgE;AAAA,EAYrE,YACmB,QACR,eAAe,oBACxB;AAFiB;AACR;AAAA,EAC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AAqB,OAAO,CAAC;AAAA,EAC/E;AAAA,EAEA,gBAAgB,QAAQ,oBAA2C;AACjE,WAAO,IAAI,sBAAsB,KAAK,QAAQ,KAAK;AAAA,EACrD;AAAA,EAEA,eACE,QAAQ,wBACR,UAAuC,CAAC,GAClB;AACtB,WAAO,IAAI,qBAAqB,KAAK,QAAQ,OAAO,OAAO;AAAA,EAC7D;AAAA,EAEA,qBAAqB,QAAQ,wBAAoD;AAC/E,WAAO,IAAI,2BAA2B,KAAK,QAAQ,KAAK;AAAA,EAC1D;AAAA,EAEA,sBAAsB,QAAQ,mBAAgD;AAC5E,WAAO,IAAI,4BAA4B,KAAK,QAAQ,KAAK;AAAA,EAC3D;AAAA,EAEA,mBAAmB,QAAQ,oBAA8C;AACvE,WAAO,IAAI,yBAAyB,KAAK,QAAQ,KAAK;AAAA,EACxD;AACF;AAEO,SAAS,qBAAqB,SAAuD;AAC1F,MAAI,QAAQ,aAAa,MAAM;AAC7B,WAAO;AAAA,MACL,UAAU;AAAA,MACV,SAAS,cAAc,QAAQ,SAAS,WAAW,eAAe;AAAA,MAClE,UAAU,cAAc,QAAQ,UAAU,YAAY,eAAe;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AAAA,IACL,QAAQ,cAAc,QAAQ,QAAQ,UAAU,QAAQ;AAAA,EAC1D;AACF;AAEA,SAAS,cAAc,OAA2B,MAAc,OAAuB;AACrF,MAAI,UAAU,UAAa,MAAM,WAAW,GAAG;AAC7C,UAAM,IAAI,MAAM,WAAW,KAAK,IAAI,IAAI,UAAU,IAAI,kCAAkC;AAAA,EAC1F;AAEA,SAAO;AACT;","names":["content","Buffer","isPlainObject","Buffer","isPlainObject"]}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@anvia/gemini",
3
+ "version": "0.1.0",
4
+ "description": "Gemini provider adapter for Anvia.",
5
+ "author": "anvia",
6
+ "maintainer": "Indra Zulfi",
7
+ "license": "MIT",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "dependencies": {
21
+ "@google/genai": "^1.51.0",
22
+ "@anvia/core": "0.1.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^24.9.1",
26
+ "tsup": "^8.5.0",
27
+ "typescript": "^5.9.3",
28
+ "vitest": "^4.0.8"
29
+ },
30
+ "scripts": {
31
+ "build": "tsup src/index.ts --format esm --dts --sourcemap --clean",
32
+ "test": "vitest run",
33
+ "typecheck": "tsc --noEmit"
34
+ }
35
+ }