@flink-app/gemini-adapter 2.0.0-alpha.100

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
+ The MIT License
2
+
3
+ Copyright (c) Frost Experience AB https://www.frost.se
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
13
+ all 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
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @flink-app/gemini-adapter
2
+
3
+ Google Gemini adapter for the [Flink AI framework](https://github.com/FrostDigital/flink-framework).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @flink-app/gemini-adapter @google/generative-ai
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { GeminiAdapter } from "@flink-app/gemini-adapter";
15
+ import { FlinkApp } from "@flink-app/flink";
16
+
17
+ const app = new FlinkApp({
18
+ ai: {
19
+ llms: {
20
+ default: new GeminiAdapter({
21
+ apiKey: process.env.GOOGLE_AI_API_KEY!,
22
+ model: "gemini-2.0-flash",
23
+ }),
24
+ },
25
+ },
26
+ });
27
+ ```
28
+
29
+ ## Configuration
30
+
31
+ | Option | Type | Required | Description |
32
+ |---------|-----------|----------|--------------------------------------------------------------------|
33
+ | apiKey | `string` | Yes | Google AI API key |
34
+ | model | `string` | Yes | Gemini model name (e.g. `"gemini-2.0-flash"`, `"gemini-1.5-pro"`) |
35
+ | debug | `boolean` | No | Enable debug logging (default: `false`) |
36
+
37
+ ## Supported Models
38
+
39
+ - `gemini-2.0-flash` — Fast, cost-effective (recommended default)
40
+ - `gemini-1.5-pro` — High capability, longer context
41
+ - `gemini-1.5-flash` — Fast, balanced capability
42
+ - `gemini-2.5-pro-preview-03-25` — Latest preview model
43
+
44
+ ## Features
45
+
46
+ - ✅ Tool calling support
47
+ - ✅ Streaming responses (SSE / NDJSON)
48
+ - ✅ Alternating turn enforcement (consecutive same-role messages are merged)
49
+ - ✅ System instruction handling
50
+ - ✅ JSON Schema sanitization for Gemini compatibility
51
+ - ✅ Token usage tracking
52
+ - ✅ Debug logging
53
+
54
+ ## Using with FlinkAgent
55
+
56
+ ```typescript
57
+ import { FlinkAgent } from "@flink-app/flink";
58
+ import { GeminiAdapter } from "@flink-app/gemini-adapter";
59
+
60
+ export default class CarAgent extends FlinkAgent<AppContext> {
61
+ instructions = "You are a helpful car assistant.";
62
+ llm = new GeminiAdapter({
63
+ apiKey: process.env.GOOGLE_AI_API_KEY!,
64
+ model: "gemini-2.0-flash",
65
+ });
66
+ }
67
+ ```
68
+
69
+ ## License
70
+
71
+ MIT
@@ -0,0 +1,125 @@
1
+ import type { FlinkToolSchema, LLMAdapter, LLMMessage, LLMStreamChunk } from "@flink-app/flink/ai";
2
+ export interface GeminiAdapterOptions {
3
+ /**
4
+ * Google AI API key
5
+ */
6
+ apiKey: string;
7
+ /**
8
+ * Model to use (e.g., "gemini-2.0-flash", "gemini-1.5-pro", "gemini-2.5-pro-preview-03-25")
9
+ */
10
+ model: string;
11
+ /**
12
+ * Optional: Enable debug logging for development and troubleshooting
13
+ *
14
+ * When enabled, logs:
15
+ * - Full request parameters sent to Gemini
16
+ * - Tool call decisions made by the LLM
17
+ * - Token usage and performance metrics
18
+ *
19
+ * @default false
20
+ */
21
+ debug?: boolean;
22
+ }
23
+ /**
24
+ * Google Gemini adapter for Flink AI framework
25
+ *
26
+ * Provides integration with Google's Gemini models via the Generative AI API.
27
+ * Supports tool calling, handles message formatting between Flink's standardized
28
+ * format and Gemini's API format, and provides streaming support.
29
+ *
30
+ * ## Architecture
31
+ *
32
+ * This adapter implements the LLMAdapter interface and handles:
33
+ * - Message conversion from Flink format to Gemini format (user/model roles)
34
+ * - System instructions passed as separate systemInstruction parameter
35
+ * - Tool schema sanitization for Gemini compatibility
36
+ * - Streaming event processing via generateContentStream()
37
+ * - Consecutive same-role message merging (Gemini requires alternating turns)
38
+ *
39
+ * ## Basic Usage
40
+ * ```typescript
41
+ * import { GeminiAdapter } from "@flink-app/gemini-adapter";
42
+ * import { FlinkApp } from "@flink-app/flink";
43
+ *
44
+ * const app = new FlinkApp({
45
+ * ai: {
46
+ * llms: {
47
+ * default: new GeminiAdapter({
48
+ * apiKey: process.env.GOOGLE_AI_API_KEY!,
49
+ * model: "gemini-2.0-flash"
50
+ * }),
51
+ * },
52
+ * },
53
+ * });
54
+ * ```
55
+ *
56
+ * ## Features
57
+ * - ✅ Full tool calling support
58
+ * - ✅ Streaming with event-based updates
59
+ * - ✅ Proper message conversion and system instruction handling
60
+ * - ✅ Schema sanitization for Gemini compatibility
61
+ * - ✅ Alternating turn enforcement (merges consecutive same-role messages)
62
+ * - ✅ Token usage tracking
63
+ * - ✅ Debug logging for tool calls
64
+ */
65
+ export declare class GeminiAdapter implements LLMAdapter<FlinkToolSchema> {
66
+ private apiKey;
67
+ private model;
68
+ debug: boolean;
69
+ constructor(options: GeminiAdapterOptions);
70
+ constructor(apiKey: string, model: string);
71
+ stream(params: {
72
+ instructions: string;
73
+ messages: LLMMessage[];
74
+ tools: FlinkToolSchema[];
75
+ maxTokens: number;
76
+ temperature: number;
77
+ providerMetadata?: Record<string, any>;
78
+ }): AsyncGenerator<LLMStreamChunk>;
79
+ /**
80
+ * Convert Flink messages to Gemini format
81
+ *
82
+ * Gemini requires:
83
+ * 1. System instructions as separate systemInstruction parameter (not in messages)
84
+ * 2. Messages with role "user" or "model" (assistant → model)
85
+ * 3. Strictly alternating user/model turns — consecutive same-role messages must be merged
86
+ * 4. Tool results as user messages with functionResponse parts
87
+ */
88
+ private convertMessagesToGeminiFormat;
89
+ /**
90
+ * Convert a single Flink message's content to Gemini Part[]
91
+ */
92
+ private convertContentToGeminiParts;
93
+ /**
94
+ * Convert Flink tools to Gemini format
95
+ *
96
+ * Gemini uses:
97
+ * { functionDeclarations: [{ name, description, parameters: JSONSchema }] }
98
+ */
99
+ private convertToolsToGeminiFormat;
100
+ /**
101
+ * Sanitize JSON Schema for Gemini's tool use
102
+ *
103
+ * Gemini has stricter JSON Schema requirements than Anthropic/OpenAI:
104
+ * - Does not support $schema, $defs, $ref (must be inline)
105
+ * - Does not support additionalProperties
106
+ * - Limited format support
107
+ * - Does not support default values in schemas
108
+ */
109
+ private sanitizeSchemaForGemini;
110
+ /**
111
+ * Normalize Gemini finish reason to Flink format
112
+ *
113
+ * Maps Gemini's finishReason values:
114
+ * - "STOP" → "end_turn"
115
+ * - "MAX_TOKENS" → "max_tokens"
116
+ * - "SAFETY" / others → "end_turn"
117
+ */
118
+ private normalizeStopReason;
119
+ /**
120
+ * Generate a unique ID for tool calls
121
+ * Gemini doesn't provide tool call IDs natively, so we generate them
122
+ */
123
+ private generateToolCallId;
124
+ }
125
+ //# sourceMappingURL=GeminiAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeminiAdapter.d.ts","sourceRoot":"","sources":["../src/GeminiAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAmB,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEpH,MAAM,WAAW,oBAAoB;IACjC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBAAa,aAAc,YAAW,UAAU,CAAC,eAAe,CAAC;IAC7D,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACf,KAAK,EAAE,OAAO,CAAC;gBAEV,OAAO,EAAE,oBAAoB;gBAC7B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAalC,MAAM,CAAC,MAAM,EAAE;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,UAAU,EAAE,CAAC;QACvB,KAAK,EAAE,eAAe,EAAE,CAAC;QACzB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC1C,GAAG,cAAc,CAAC,cAAc,CAAC;IAsGlC;;;;;;;;OAQG;IACH,OAAO,CAAC,6BAA6B;IAwBrC;;OAEG;IACH,OAAO,CAAC,2BAA2B;IA6DnC;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IAYlC;;;;;;;;OAQG;IACH,OAAO,CAAC,uBAAuB;IAsC/B;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;CAG7B"}
@@ -0,0 +1,329 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeminiAdapter = void 0;
4
+ const generative_ai_1 = require("@google/generative-ai");
5
+ const flink_1 = require("@flink-app/flink");
6
+ /**
7
+ * Google Gemini adapter for Flink AI framework
8
+ *
9
+ * Provides integration with Google's Gemini models via the Generative AI API.
10
+ * Supports tool calling, handles message formatting between Flink's standardized
11
+ * format and Gemini's API format, and provides streaming support.
12
+ *
13
+ * ## Architecture
14
+ *
15
+ * This adapter implements the LLMAdapter interface and handles:
16
+ * - Message conversion from Flink format to Gemini format (user/model roles)
17
+ * - System instructions passed as separate systemInstruction parameter
18
+ * - Tool schema sanitization for Gemini compatibility
19
+ * - Streaming event processing via generateContentStream()
20
+ * - Consecutive same-role message merging (Gemini requires alternating turns)
21
+ *
22
+ * ## Basic Usage
23
+ * ```typescript
24
+ * import { GeminiAdapter } from "@flink-app/gemini-adapter";
25
+ * import { FlinkApp } from "@flink-app/flink";
26
+ *
27
+ * const app = new FlinkApp({
28
+ * ai: {
29
+ * llms: {
30
+ * default: new GeminiAdapter({
31
+ * apiKey: process.env.GOOGLE_AI_API_KEY!,
32
+ * model: "gemini-2.0-flash"
33
+ * }),
34
+ * },
35
+ * },
36
+ * });
37
+ * ```
38
+ *
39
+ * ## Features
40
+ * - ✅ Full tool calling support
41
+ * - ✅ Streaming with event-based updates
42
+ * - ✅ Proper message conversion and system instruction handling
43
+ * - ✅ Schema sanitization for Gemini compatibility
44
+ * - ✅ Alternating turn enforcement (merges consecutive same-role messages)
45
+ * - ✅ Token usage tracking
46
+ * - ✅ Debug logging for tool calls
47
+ */
48
+ class GeminiAdapter {
49
+ constructor(optionsOrApiKey, model) {
50
+ if (typeof optionsOrApiKey === "string") {
51
+ this.apiKey = optionsOrApiKey;
52
+ this.model = model;
53
+ this.debug = false;
54
+ }
55
+ else {
56
+ this.apiKey = optionsOrApiKey.apiKey;
57
+ this.model = optionsOrApiKey.model;
58
+ this.debug = optionsOrApiKey.debug ?? false;
59
+ }
60
+ }
61
+ async *stream(params) {
62
+ try {
63
+ const genAI = new generative_ai_1.GoogleGenerativeAI(this.apiKey);
64
+ const geminiMessages = this.convertMessagesToGeminiFormat(params.messages);
65
+ const geminiTools = params.tools.length > 0 ? this.convertToolsToGeminiFormat(params.tools) : undefined;
66
+ const geminiModel = genAI.getGenerativeModel({
67
+ model: this.model,
68
+ systemInstruction: params.instructions || undefined,
69
+ });
70
+ const result = await geminiModel.generateContentStream({
71
+ contents: geminiMessages,
72
+ tools: geminiTools,
73
+ generationConfig: {
74
+ maxOutputTokens: params.maxTokens,
75
+ temperature: params.temperature,
76
+ },
77
+ });
78
+ // Accumulate tool calls across chunks (Gemini may split across chunks)
79
+ const pendingToolCalls = [];
80
+ for await (const chunk of result.stream) {
81
+ const candidate = chunk.candidates?.[0];
82
+ if (!candidate?.content?.parts)
83
+ continue;
84
+ for (const part of candidate.content.parts) {
85
+ if (part.text) {
86
+ yield { type: "text", delta: part.text };
87
+ }
88
+ else if (part.functionCall) {
89
+ pendingToolCalls.push({
90
+ name: part.functionCall.name,
91
+ args: part.functionCall.args ?? {},
92
+ });
93
+ }
94
+ }
95
+ }
96
+ // Yield completed tool calls after stream finishes
97
+ for (const tc of pendingToolCalls) {
98
+ if (this.debug) {
99
+ flink_1.log.debug(`[Gemini Stream] LLM decided to call tool:`, JSON.stringify({ name: tc.name, input: tc.args }, null, 2));
100
+ }
101
+ yield {
102
+ type: "tool_call",
103
+ toolCall: {
104
+ id: this.generateToolCallId(),
105
+ name: tc.name,
106
+ input: tc.args,
107
+ },
108
+ };
109
+ }
110
+ // Get final response for usage metadata
111
+ const response = await result.response;
112
+ const usageMeta = response.usageMetadata;
113
+ yield {
114
+ type: "usage",
115
+ usage: {
116
+ inputTokens: usageMeta?.promptTokenCount ?? 0,
117
+ outputTokens: usageMeta?.candidatesTokenCount ?? 0,
118
+ },
119
+ };
120
+ const finishReason = response.candidates?.[0]?.finishReason;
121
+ yield {
122
+ type: "done",
123
+ stopReason: this.normalizeStopReason(finishReason ?? "STOP"),
124
+ };
125
+ }
126
+ catch (error) {
127
+ if (error.status === 400) {
128
+ throw new Error(`Gemini API error (400 Bad Request): ${error.message || "Invalid request"}. ` +
129
+ `Common causes: invalid model name, malformed messages, or invalid tool schemas. ` +
130
+ `Model: ${this.model}`);
131
+ }
132
+ else if (error.status === 401 || error.status === 403) {
133
+ throw new Error(`Gemini API authentication error (${error.status}): Invalid API key or insufficient permissions. ` +
134
+ `Verify your GOOGLE_AI_API_KEY environment variable is set correctly.`);
135
+ }
136
+ else if (error.status === 429) {
137
+ throw new Error(`Gemini API rate limit exceeded (429 Too Many Requests): ${error.message || "Rate limit hit"}. ` +
138
+ `Consider implementing retry logic with exponential backoff or upgrading your quota.`);
139
+ }
140
+ else if (error.status === 500 || error.status === 503) {
141
+ throw new Error(`Gemini API server error (${error.status}): ${error.message || "Internal server error"}. ` +
142
+ `This is a temporary issue with Google's servers. Please retry your request.`);
143
+ }
144
+ throw error;
145
+ }
146
+ }
147
+ /**
148
+ * Convert Flink messages to Gemini format
149
+ *
150
+ * Gemini requires:
151
+ * 1. System instructions as separate systemInstruction parameter (not in messages)
152
+ * 2. Messages with role "user" or "model" (assistant → model)
153
+ * 3. Strictly alternating user/model turns — consecutive same-role messages must be merged
154
+ * 4. Tool results as user messages with functionResponse parts
155
+ */
156
+ convertMessagesToGeminiFormat(messages) {
157
+ const geminiMessages = [];
158
+ for (const msg of messages) {
159
+ // System messages are handled via systemInstruction — skip here
160
+ if (msg.role === "system")
161
+ continue;
162
+ const role = msg.role === "assistant" ? "model" : "user";
163
+ const parts = this.convertContentToGeminiParts(msg);
164
+ if (parts.length === 0)
165
+ continue;
166
+ // Merge consecutive same-role messages (Gemini requires alternating turns)
167
+ const last = geminiMessages[geminiMessages.length - 1];
168
+ if (last && last.role === role) {
169
+ last.parts.push(...parts);
170
+ }
171
+ else {
172
+ geminiMessages.push({ role, parts });
173
+ }
174
+ }
175
+ return geminiMessages;
176
+ }
177
+ /**
178
+ * Convert a single Flink message's content to Gemini Part[]
179
+ */
180
+ convertContentToGeminiParts(msg) {
181
+ if (msg.role === "system")
182
+ return [];
183
+ const content = msg.content;
184
+ if (typeof content === "string") {
185
+ return [{ text: content }];
186
+ }
187
+ const parts = [];
188
+ const blocks = content;
189
+ for (const block of blocks) {
190
+ if (block.type === "text") {
191
+ parts.push({ text: block.text });
192
+ }
193
+ else if (block.type === "image") {
194
+ if (block.url.startsWith("data:")) {
195
+ const match = block.url.match(/^data:(.+?);base64,(.+)$/);
196
+ if (match) {
197
+ parts.push({
198
+ inlineData: {
199
+ mimeType: match[1],
200
+ data: match[2],
201
+ },
202
+ });
203
+ }
204
+ }
205
+ else {
206
+ // Gemini supports fileData for non-base64 URLs (Google Cloud Storage)
207
+ parts.push({
208
+ fileData: {
209
+ mimeType: "image/jpeg", // Default; ideally caller specifies mime type
210
+ fileUri: block.url,
211
+ },
212
+ });
213
+ }
214
+ }
215
+ else if (block.type === "tool_use") {
216
+ // Assistant tool use → functionCall part
217
+ parts.push({
218
+ functionCall: {
219
+ name: block.name,
220
+ args: block.input,
221
+ },
222
+ });
223
+ }
224
+ else if (block.type === "tool_result") {
225
+ // Tool result → functionResponse part (goes in user message)
226
+ parts.push({
227
+ functionResponse: {
228
+ name: block.tool_use_id, // Gemini matches by function name, not ID
229
+ response: {
230
+ content: block.is_error
231
+ ? { error: block.content }
232
+ : { result: block.content },
233
+ },
234
+ },
235
+ });
236
+ }
237
+ }
238
+ return parts;
239
+ }
240
+ /**
241
+ * Convert Flink tools to Gemini format
242
+ *
243
+ * Gemini uses:
244
+ * { functionDeclarations: [{ name, description, parameters: JSONSchema }] }
245
+ */
246
+ convertToolsToGeminiFormat(tools) {
247
+ return [
248
+ {
249
+ functionDeclarations: tools.map((tool) => ({
250
+ name: tool.name,
251
+ description: tool.description,
252
+ parameters: this.sanitizeSchemaForGemini(tool.inputSchema),
253
+ })),
254
+ },
255
+ ];
256
+ }
257
+ /**
258
+ * Sanitize JSON Schema for Gemini's tool use
259
+ *
260
+ * Gemini has stricter JSON Schema requirements than Anthropic/OpenAI:
261
+ * - Does not support $schema, $defs, $ref (must be inline)
262
+ * - Does not support additionalProperties
263
+ * - Limited format support
264
+ * - Does not support default values in schemas
265
+ */
266
+ sanitizeSchemaForGemini(schema) {
267
+ const sanitized = JSON.parse(JSON.stringify(schema));
268
+ const sanitizeNode = (node) => {
269
+ if (!node || typeof node !== "object")
270
+ return;
271
+ // Remove unsupported keywords
272
+ delete node.$schema;
273
+ delete node.$defs;
274
+ delete node.$ref;
275
+ delete node.additionalProperties;
276
+ delete node.default;
277
+ delete node.$id;
278
+ if (node.properties) {
279
+ for (const key in node.properties) {
280
+ sanitizeNode(node.properties[key]);
281
+ }
282
+ }
283
+ if (node.items) {
284
+ if (Array.isArray(node.items)) {
285
+ node.items.forEach(sanitizeNode);
286
+ }
287
+ else {
288
+ sanitizeNode(node.items);
289
+ }
290
+ }
291
+ if (node.allOf)
292
+ node.allOf.forEach(sanitizeNode);
293
+ if (node.anyOf)
294
+ node.anyOf.forEach(sanitizeNode);
295
+ if (node.oneOf)
296
+ node.oneOf.forEach(sanitizeNode);
297
+ if (node.not)
298
+ sanitizeNode(node.not);
299
+ };
300
+ sanitizeNode(sanitized);
301
+ return sanitized;
302
+ }
303
+ /**
304
+ * Normalize Gemini finish reason to Flink format
305
+ *
306
+ * Maps Gemini's finishReason values:
307
+ * - "STOP" → "end_turn"
308
+ * - "MAX_TOKENS" → "max_tokens"
309
+ * - "SAFETY" / others → "end_turn"
310
+ */
311
+ normalizeStopReason(finishReason) {
312
+ switch (finishReason) {
313
+ case "MAX_TOKENS":
314
+ return "max_tokens";
315
+ case "STOP":
316
+ default:
317
+ return "end_turn";
318
+ }
319
+ }
320
+ /**
321
+ * Generate a unique ID for tool calls
322
+ * Gemini doesn't provide tool call IDs natively, so we generate them
323
+ */
324
+ generateToolCallId() {
325
+ return `tc_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
326
+ }
327
+ }
328
+ exports.GeminiAdapter = GeminiAdapter;
329
+ //# sourceMappingURL=GeminiAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeminiAdapter.js","sourceRoot":"","sources":["../src/GeminiAdap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kB;QACtB,OAAO,MAAM,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IACxE,CAAC;CACJ;AA3TD,sCA2TC"}
@@ -0,0 +1,2 @@
1
+ export { GeminiAdapter, type GeminiAdapterOptions } from "./GeminiAdapter";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeminiAdapter = void 0;
4
+ var GeminiAdapter_1 = require("./GeminiAdapter");
5
+ Object.defineProperty(exports, "GeminiAdapter", { enumerable: true, get: function () { return GeminiAdapter_1.GeminiAdapter; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA2E;AAAlE,8GAAA,aAAa,OAAA"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@flink-app/gemini-adapter",
3
+ "version": "2.0.0-alpha.100",
4
+ "description": "Google Gemini adapter for Flink AI framework",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "keywords": [
8
+ "flink",
9
+ "gemini",
10
+ "google",
11
+ "ai",
12
+ "llm",
13
+ "adapter"
14
+ ],
15
+ "author": "Frost Digital",
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "@google/generative-ai": "^0.24.0"
19
+ },
20
+ "peerDependencies": {
21
+ "@flink-app/flink": ">=2.0.0-alpha.100"
22
+ },
23
+ "peerDependenciesMeta": {
24
+ "@flink-app/flink": {
25
+ "optional": false
26
+ }
27
+ },
28
+ "devDependencies": {
29
+ "@types/jasmine": "^3.7.1",
30
+ "ts-node": "^10.9.2",
31
+ "typescript": "^5.6.2",
32
+ "@flink-app/flink": "2.0.0-alpha.100"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/FrostDigital/flink-framework.git",
41
+ "directory": "packages/gemini-adapter"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc --project tsconfig.dist.json",
45
+ "watch": "tsc --project tsconfig.dist.json --watch",
46
+ "test": "../../node_modules/.bin/jasmine-ts --config=./spec/support/jasmine.json",
47
+ "clean": "rm -rf dist"
48
+ }
49
+ }