@loonylabs/llm-middleware 2.8.1 โ†’ 2.9.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/.env.example CHANGED
@@ -15,6 +15,10 @@ MODEL1_TOKEN=your_model1_token_here # Optional: For authenticated providers
15
15
  ANTHROPIC_API_KEY=your_anthropic_api_key_here # Your Anthropic API key
16
16
  ANTHROPIC_MODEL=claude-3-5-sonnet-20241022 # Default: claude-3-5-sonnet-20241022
17
17
 
18
+ # Google Gemini API Configuration (Optional)
19
+ GEMINI_API_KEY=your_gemini_api_key_here # Your Google Gemini API key
20
+ GEMINI_MODEL=gemini-1.5-pro # Default: gemini-1.5-pro
21
+
18
22
  # Authentication (Optional)
19
23
  AUTH_VALIDATION_TYPE=none
20
24
  STATIC_API_KEY=your_static_api_key_here
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # ๐Ÿš€ LLM Middleware
4
4
 
5
- *A comprehensive TypeScript middleware library for building robust multi-provider LLM backends. Currently supports Ollama and Anthropic Claude, with OpenAI and Google planned. Features advanced JSON cleaning, logging, error handling, and more.*
5
+ *A comprehensive TypeScript middleware library for building robust multi-provider LLM backends. Currently supports Ollama, Anthropic Claude, and Google Gemini, with OpenAI planned. Features advanced JSON cleaning, logging, error handling, and more.*
6
6
 
7
7
  <!-- Horizontal Badge Navigation Bar -->
8
8
  [![npm version](https://img.shields.io/npm/v/@loonylabs/llm-middleware.svg?style=for-the-badge&logo=npm&logoColor=white)](https://www.npmjs.com/package/@loonylabs/llm-middleware)
@@ -41,7 +41,8 @@
41
41
  - ๐Ÿค– **Multi-Provider Architecture**: Extensible provider system with strategy pattern
42
42
  - โœ… **Ollama**: Fully supported with comprehensive parameter control
43
43
  - โœ… **Anthropic Claude**: Complete support for Claude models (Opus, Sonnet, Haiku)
44
- - ๐Ÿ”œ **OpenAI, Google**: Planned for future releases
44
+ - โœ… **Google Gemini**: Complete support for Gemini models (Pro, Flash)
45
+ - ๐Ÿ”œ **OpenAI**: Planned for future releases
45
46
  - ๐Ÿ”Œ **Pluggable**: Easy to add custom providers - see [LLM Providers Guide](docs/LLM_PROVIDERS.md)
46
47
  - ๐Ÿงน **JSON Cleaning**: Recipe-based JSON repair system with automatic strategy selection
47
48
  - โœจ **v2.4.0**: Enhanced array extraction support - properly handles JSON arrays `[...]` in addition to objects `{...}`
@@ -125,7 +126,7 @@ class MyAnthropicChatUseCase extends MyChatUseCase {
125
126
  <summary><strong>๐Ÿ”Œ Using the Multi-Provider Architecture</strong></summary>
126
127
 
127
128
  ```typescript
128
- import { llmService, LLMProvider, ollamaProvider, anthropicProvider } from '@loonylabs/llm-middleware';
129
+ import { llmService, LLMProvider, ollamaProvider, anthropicProvider, geminiProvider } from '@loonylabs/llm-middleware';
129
130
 
130
131
  // Option 1: Use the LLM Service orchestrator (recommended for flexibility)
131
132
  const response1 = await llmService.call(
@@ -149,8 +150,20 @@ const response2 = await llmService.call(
149
150
  }
150
151
  );
151
152
 
153
+ // Use Google Gemini
154
+ const response3 = await llmService.call(
155
+ "What is machine learning?",
156
+ {
157
+ provider: LLMProvider.GOOGLE,
158
+ model: "gemini-1.5-pro",
159
+ authToken: process.env.GEMINI_API_KEY,
160
+ maxTokens: 1024,
161
+ temperature: 0.7
162
+ }
163
+ );
164
+
152
165
  // Option 2: Use provider directly for provider-specific features
153
- const response3 = await ollamaProvider.callWithSystemMessage(
166
+ const response4 = await ollamaProvider.callWithSystemMessage(
154
167
  "Write a haiku about coding",
155
168
  "You are a creative poet",
156
169
  {
@@ -163,7 +176,7 @@ const response3 = await ollamaProvider.callWithSystemMessage(
163
176
  );
164
177
 
165
178
  // Or use Anthropic provider directly
166
- const response4 = await anthropicProvider.call(
179
+ const response5 = await anthropicProvider.call(
167
180
  "Write a haiku about coding",
168
181
  {
169
182
  model: "claude-3-5-sonnet-20241022",
@@ -172,11 +185,21 @@ const response4 = await anthropicProvider.call(
172
185
  }
173
186
  );
174
187
 
188
+ // Or use Gemini provider directly
189
+ const response6 = await geminiProvider.call(
190
+ "Write a haiku about coding",
191
+ {
192
+ model: "gemini-1.5-pro",
193
+ authToken: process.env.GEMINI_API_KEY,
194
+ maxOutputTokens: 1024
195
+ }
196
+ );
197
+
175
198
  // Set default provider for your application
176
199
  llmService.setDefaultProvider(LLMProvider.OLLAMA);
177
200
 
178
201
  // Now calls use Ollama by default
179
- const response5 = await llmService.call("Hello!", { model: "llama2" });
202
+ const response7 = await llmService.call("Hello!", { model: "llama2" });
180
203
  ```
181
204
 
182
205
  For more details on the multi-provider system, see the [LLM Providers Guide](docs/LLM_PROVIDERS.md).
@@ -294,9 +317,13 @@ MODEL1_TOKEN=optional-auth-token # Optional: For authenticated providers
294
317
  # Anthropic API Configuration (Optional)
295
318
  ANTHROPIC_API_KEY=your_anthropic_api_key_here # Your Anthropic API key
296
319
  ANTHROPIC_MODEL=claude-3-5-sonnet-20241022 # Default Claude model
320
+
321
+ # Google Gemini API Configuration (Optional)
322
+ GEMINI_API_KEY=your_gemini_api_key_here # Your Google Gemini API key
323
+ GEMINI_MODEL=gemini-1.5-pro # Default Gemini model
297
324
  ```
298
325
 
299
- **Multi-Provider Support:** The middleware is fully integrated with **Ollama** and **Anthropic Claude**. Support for OpenAI and Google is planned. See the [LLM Providers Guide](docs/LLM_PROVIDERS.md) for details on the provider system and how to use or add providers.
326
+ **Multi-Provider Support:** The middleware is fully integrated with **Ollama**, **Anthropic Claude**, and **Google Gemini**. Support for OpenAI is planned. See the [LLM Providers Guide](docs/LLM_PROVIDERS.md) for details on the provider system and how to use or add providers.
300
327
 
301
328
  </details>
302
329
 
@@ -1 +1 @@
1
- {"version":3,"file":"llm.service.d.ts","sourceRoot":"","sources":["../../../../src/middleware/services/llm/llm.service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,M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,qBAAqB,CAChC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,gBAAgB,GAAG;QAAE,QAAQ,CAAC,EAAE,WAAW,CAAA;KAAO,GAC1D,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAMpC;;;OAGG;IACU,IAAI,CACf,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,gBAAgB,GAAG;QAAE,QAAQ,CAAC,EAAE,WAAW,CAAA;KAAO,GAC1D,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAMpC;;OAEG;IACI,qBAAqB,IAAI,WAAW,EAAE;CAG9C;AAGD,eAAO,MAAM,UAAU,YAAmB,CAAC"}
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.llmService = exports.LLMService = void 0;
8
8
  const ollama_provider_1 = require("./providers/ollama-provider");
9
9
  const anthropic_provider_1 = require("./providers/anthropic-provider");
10
+ const gemini_provider_1 = require("./providers/gemini-provider");
10
11
  const types_1 = require("./types");
11
12
  class LLMService {
12
13
  constructor() {
@@ -15,6 +16,7 @@ class LLMService {
15
16
  // Initialize available providers
16
17
  this.providers.set(types_1.LLMProvider.OLLAMA, new ollama_provider_1.OllamaProvider());
17
18
  this.providers.set(types_1.LLMProvider.ANTHROPIC, new anthropic_provider_1.AnthropicProvider());
19
+ this.providers.set(types_1.LLMProvider.GOOGLE, new gemini_provider_1.GeminiProvider());
18
20
  }
19
21
  /**
20
22
  * Get a specific provider instance
@@ -1 +1 @@
1
- {"version":3,"file":"llm.service.js","sourceRoot":"","sources":["../../../../src/middleware/services/llm/llm.service.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,iEAA6D;AAC7D,uEAAmE;AACnE,mCAA2E;AAE3E,MAAa,UAAU;IAIrB;QAFQ,oBAAe,GAAgB,mBAAW,CAAC,MAAM,CAAC;QAGxD,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B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AqB;QAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAzED,gCAyEC;AAED,4BAA4B;AACf,QAAA,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { BaseLLMProvider } from './base-llm-provider';
2
+ import { CommonLLMResponse } from '../types';
3
+ import { GeminiRequestOptions } from '../types/gemini.types';
4
+ /**
5
+ * Google Gemini provider implementation with advanced features:
6
+ * - Comprehensive debugging and logging
7
+ * - Error handling with retry logic
8
+ * - Session management
9
+ * - Parameter handling
10
+ */
11
+ export declare class GeminiProvider extends BaseLLMProvider {
12
+ private dataFlowLogger;
13
+ private readonly BASE_URL;
14
+ constructor();
15
+ /**
16
+ * Call the Google Gemini API with a custom system message
17
+ * @param userPrompt - The user's prompt for the model
18
+ * @param systemMessage - The system message defining AI behavior
19
+ * @param options - Options for the API call
20
+ * @returns The API response or null on error
21
+ */
22
+ callWithSystemMessage(userPrompt: string, systemMessage: string, options?: GeminiRequestOptions): Promise<CommonLLMResponse | null>;
23
+ }
24
+ export declare const geminiProvider: GeminiProvider;
25
+ //# sourceMappingURL=gemini-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini-provider.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/providers/gemini-provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAe,iBAAiB,EAAc,MAAM,UAAU,CAAC;AACtE,OAAO,EACL,oBAAoB,EAKrB,MAAM,uBAAuB,CAAC;AAI/B;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,eAAe;IACjD,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsD;;IAO/E;;;;;;OAMG;IACU,qBAAqB,CAChC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CAkQrC;AAGD,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.geminiProvider = exports.GeminiProvider = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const uuid_1 = require("uuid");
9
+ const logging_utils_1 = require("../../../shared/utils/logging.utils");
10
+ const base_llm_provider_1 = require("./base-llm-provider");
11
+ const types_1 = require("../types");
12
+ const debug_llm_utils_1 = require("../utils/debug-llm.utils");
13
+ const data_flow_logger_1 = require("../../data-flow-logger");
14
+ /**
15
+ * Google Gemini provider implementation with advanced features:
16
+ * - Comprehensive debugging and logging
17
+ * - Error handling with retry logic
18
+ * - Session management
19
+ * - Parameter handling
20
+ */
21
+ class GeminiProvider extends base_llm_provider_1.BaseLLMProvider {
22
+ constructor() {
23
+ super(types_1.LLMProvider.GOOGLE);
24
+ this.BASE_URL = 'https://generativelanguage.googleapis.com/v1beta';
25
+ this.dataFlowLogger = data_flow_logger_1.DataFlowLoggerService.getInstance();
26
+ }
27
+ /**
28
+ * Call the Google Gemini API with a custom system message
29
+ * @param userPrompt - The user's prompt for the model
30
+ * @param systemMessage - The system message defining AI behavior
31
+ * @param options - Options for the API call
32
+ * @returns The API response or null on error
33
+ */
34
+ async callWithSystemMessage(userPrompt, systemMessage, options = {}) {
35
+ const { authToken = process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY, model = process.env.GEMINI_MODEL || 'gemini-1.5-pro', temperature = 0.7, maxTokens, maxOutputTokens = maxTokens || 4096, topP, topK, stopSequences, candidateCount = 1, debugContext, sessionId = (0, uuid_1.v4)(), chapterNumber, pageNumber, pageName } = options;
36
+ // Validate that API key is provided
37
+ if (!authToken) {
38
+ throw new Error('Google Gemini API key is required but not provided. ' +
39
+ 'Please set GEMINI_API_KEY or GOOGLE_API_KEY in your .env file or pass authToken in options.');
40
+ }
41
+ // Validate that model is provided
42
+ if (!model) {
43
+ throw new Error('Model name is required but not provided. ' +
44
+ 'Please set GEMINI_MODEL in your .env file or pass model in options.');
45
+ }
46
+ // Build generation config
47
+ const generationConfig = {
48
+ temperature: temperature,
49
+ maxOutputTokens: maxOutputTokens,
50
+ ...(topP !== undefined && { topP }),
51
+ ...(topK !== undefined && { topK }),
52
+ ...(stopSequences && { stopSequences }),
53
+ ...(candidateCount !== undefined && { candidateCount })
54
+ };
55
+ // Build the request payload
56
+ const requestPayload = {
57
+ contents: [
58
+ {
59
+ role: 'user',
60
+ parts: [{ text: userPrompt }]
61
+ }
62
+ ],
63
+ generationConfig: generationConfig,
64
+ systemInstruction: {
65
+ parts: [{ text: systemMessage }]
66
+ }
67
+ };
68
+ // Get client request body from global scope
69
+ let clientRequestBody = undefined;
70
+ try {
71
+ clientRequestBody = global.currentRequestBody;
72
+ }
73
+ catch (error) {
74
+ // Ignore as it's optional
75
+ }
76
+ // Prepare debug info
77
+ const debugInfo = {
78
+ timestamp: new Date(),
79
+ provider: this.providerName,
80
+ model: model,
81
+ baseUrl: this.BASE_URL,
82
+ systemMessage: systemMessage,
83
+ userMessage: userPrompt,
84
+ requestData: requestPayload,
85
+ useCase: debugContext,
86
+ clientRequestBody: clientRequestBody,
87
+ sessionId: sessionId,
88
+ chapterNumber: chapterNumber,
89
+ pageNumber: pageNumber,
90
+ pageName: pageName
91
+ };
92
+ // Log request
93
+ await debug_llm_utils_1.LLMDebugger.logRequest(debugInfo);
94
+ // Log to data flow logger
95
+ const contextForLogger = {
96
+ currentChapterNr: chapterNumber,
97
+ currentPage: pageNumber,
98
+ debugContext
99
+ };
100
+ const requestId = this.dataFlowLogger.startRequest(debugContext || 'gemini-direct', contextForLogger);
101
+ this.dataFlowLogger.logLLMRequest({
102
+ stage: debugContext || 'gemini-direct',
103
+ prompt: userPrompt,
104
+ systemMessage: systemMessage,
105
+ modelName: model,
106
+ temperature: temperature,
107
+ contextInfo: {
108
+ sessionId,
109
+ chapterNumber,
110
+ pageNumber,
111
+ pageName,
112
+ parameters: {
113
+ maxOutputTokens,
114
+ topP,
115
+ topK,
116
+ stopSequences,
117
+ candidateCount
118
+ }
119
+ }
120
+ }, contextForLogger, requestId);
121
+ const requestStartTime = Date.now();
122
+ try {
123
+ // Construct the API endpoint URL
124
+ const endpoint = `${this.BASE_URL}/models/${model}:generateContent`;
125
+ logging_utils_1.logger.info('Sending request to Google Gemini API', {
126
+ context: 'GeminiProvider',
127
+ metadata: {
128
+ url: endpoint,
129
+ model: model,
130
+ promptLength: userPrompt.length,
131
+ maxOutputTokens: maxOutputTokens
132
+ }
133
+ });
134
+ const response = await axios_1.default.post(endpoint, requestPayload, {
135
+ params: {
136
+ key: authToken
137
+ },
138
+ headers: {
139
+ 'Content-Type': 'application/json'
140
+ },
141
+ timeout: 90000 // 90 second timeout
142
+ });
143
+ const requestDuration = Date.now() - requestStartTime;
144
+ if (response && response.status === 200) {
145
+ const apiResponse = response.data;
146
+ // Check if we have candidates
147
+ if (!apiResponse.candidates || apiResponse.candidates.length === 0) {
148
+ throw new Error('No candidates returned from Gemini API');
149
+ }
150
+ // Get the first candidate's content
151
+ const candidate = apiResponse.candidates[0];
152
+ const responseText = candidate.content.parts
153
+ .map(part => part.text)
154
+ .join('\n');
155
+ // Normalize token usage to provider-agnostic format
156
+ const tokenUsage = apiResponse.usageMetadata
157
+ ? {
158
+ inputTokens: apiResponse.usageMetadata.promptTokenCount,
159
+ outputTokens: apiResponse.usageMetadata.candidatesTokenCount,
160
+ totalTokens: apiResponse.usageMetadata.totalTokenCount
161
+ }
162
+ : undefined;
163
+ // Build normalized response
164
+ const normalizedResponse = {
165
+ message: {
166
+ content: responseText
167
+ },
168
+ sessionId: sessionId,
169
+ metadata: {
170
+ provider: this.providerName,
171
+ model: model,
172
+ tokensUsed: tokenUsage?.totalTokens,
173
+ processingTime: requestDuration
174
+ },
175
+ usage: tokenUsage
176
+ };
177
+ logging_utils_1.logger.info('Successfully received response from Gemini API', {
178
+ context: 'GeminiProvider',
179
+ metadata: {
180
+ model: model,
181
+ responseLength: responseText.length,
182
+ tokensUsed: tokenUsage?.totalTokens,
183
+ processingTime: requestDuration,
184
+ finishReason: candidate.finishReason
185
+ }
186
+ });
187
+ // Update debug info with response
188
+ debugInfo.response = responseText;
189
+ debugInfo.responseTimestamp = new Date();
190
+ debugInfo.rawResponseData = apiResponse;
191
+ await debug_llm_utils_1.LLMDebugger.logResponse(debugInfo);
192
+ // Log to data flow logger
193
+ this.dataFlowLogger.logLLMResponse(debugContext || 'gemini-direct', {
194
+ rawResponse: responseText,
195
+ processingTime: requestDuration
196
+ }, contextForLogger, requestId);
197
+ return normalizedResponse;
198
+ }
199
+ else {
200
+ throw new Error(`Unexpected status code: ${response.status}`);
201
+ }
202
+ }
203
+ catch (error) {
204
+ const requestDuration = Date.now() - requestStartTime;
205
+ logging_utils_1.logger.error('Error calling Gemini API', {
206
+ context: 'GeminiProvider',
207
+ metadata: {
208
+ error: error.message,
209
+ model: model,
210
+ processingTime: requestDuration,
211
+ errorDetails: error.response?.data
212
+ }
213
+ });
214
+ // Update debug info with error
215
+ debugInfo.error = {
216
+ message: error.message,
217
+ details: error.response?.data || error
218
+ };
219
+ debugInfo.responseTimestamp = new Date();
220
+ await debug_llm_utils_1.LLMDebugger.logResponse(debugInfo);
221
+ // Log error to data flow logger
222
+ this.dataFlowLogger.logLLMResponse(debugContext || 'gemini-direct', {
223
+ rawResponse: '',
224
+ processingTime: requestDuration,
225
+ error: error
226
+ }, contextForLogger, requestId);
227
+ throw error;
228
+ }
229
+ }
230
+ }
231
+ exports.GeminiProvider = GeminiProvider;
232
+ // Export singleton instance
233
+ exports.geminiProvider = new GeminiProvider();
234
+ //# sourceMappingURL=gemini-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini-provider.js","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/providers/gemini-provider.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,+BAAoC;AACpC,uEAA6D;AAC7D,2DAAsD;AACtD,oCAAsE;AAQtE,8DAAqE;AACrE,6DAA+D;AAE/D;;;;;;GAMG;AACH,MAAa,cAAe,SAAQ,mCAAe;IAIjD;QACE,KAAK,CAAC,mBAAW,CAAC,MAAM,CAAC,CAAC;QAHX,aAAQ,GAAG,kDAAkD,CAAC;QAI7E,IAAI,CAAC,cAAc,GAAG,wCAAqB,CAAC,WAAW,EAAE,CAAC;IAC5D,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,qBAAqB,CAChC,UAAkB,EAClB,aAAqB,EACrB,UAAgC,EAAE;QAElC,MAAM,EACJ,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EACpE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,gBAAgB,EACpD,WAAW,GAAG,GAAG,EACjB,SAAS,EACT,eAAe,GAAG,SAAS,IAAI,IAAI,EACnC,IAAI,EACJ,IAAI,EACJ,aAAa,EACb,cAAc,GAAG,CAAC,EAClB,YAAY,EACZ,SAAS,GAAG,IAAA,SAAM,GAAE,EACpB,aAAa,EACb,UAAU,EACV,QAAQ,EACT,GAAG,OAAO,CAAC;QAEZ,oCAAoC;QACpC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,sDAAsD;gBACtD,6FAA6F,CAC9F,CAAC;QACJ,CAAC;QAED,kCAAkC;QAClC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CACb,2CAA2C;gBAC3C,qEAAqE,CACtE,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,MAAM,gBAAgB,GAA2B;YAC/C,WAAW,EAAE,WAAW;YACx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AAK,CAAC,OAAO;gBACtB,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,IAAI,KAAK;aACvC,CAAC;YACF,SAAS,CAAC,iBAAiB,GAAG,IAAI,IAAI,EAAE,CAAC;YACzC,MAAM,6BAAW,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;YAEzC,gCAAgC;YAChC,IAAI,CAAC,cAAc,CAAC,cAAc,CAChC,YAAY,IAAI,eAAe,EAC/B;gBACE,WAAW,EAAE,EAAE;gBACf,cAAc,EAAE,eAAe;gBAC/B,KAAK,EAAE,KAAK;aACb,EACD,gBAAgB,EAChB,SAAS,CACV,CAAC;YAEF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAtRD,wCAsRC;AAED,4BAA4B;AACf,QAAA,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './base-llm-provider';
2
2
  export * from './ollama-provider';
3
3
  export * from './anthropic-provider';
4
+ export * from './gemini-provider';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/providers/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AAGpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/providers/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AAGpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
@@ -19,7 +19,7 @@ __exportStar(require("./base-llm-provider"), exports);
19
19
  // Concrete providers
20
20
  __exportStar(require("./ollama-provider"), exports);
21
21
  __exportStar(require("./anthropic-provider"), exports);
22
+ __exportStar(require("./gemini-provider"), exports);
22
23
  // Future providers will be added here:
23
24
  // export * from './openai-provider';
24
- // export * from './google-provider';
25
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gBAAgB;AAChB,sDAAoC;AAEpC,qBAAqB;AACrB,oDAAkC;AAClC,uDAAqC;AAErC,uCAAuC;AACvC,qCAAqC;AACrC,qCAAqC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gBAAgB;AAChB,sDAAoC;AAEpC,qBAAqB;AACrB,oDAAkC;AAClC,uDAAqC;AACrC,oDAAkC;AAElC,uCAAuC;AACvC,qCAAqC"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Google Gemini-specific types and interfaces
3
+ * Based on Google Gemini API: https://ai.google.dev/api/rest
4
+ */
5
+ import { CommonLLMOptions, CommonLLMResponse } from './common.types';
6
+ /**
7
+ * Gemini-specific request options
8
+ * Extends common options with Gemini-specific parameters
9
+ */
10
+ export interface GeminiRequestOptions extends CommonLLMOptions {
11
+ /** Top-p sampling (nucleus sampling) - Range: 0.0 to 1.0 */
12
+ topP?: number;
13
+ /** Top-k sampling - Only sample from top K options */
14
+ topK?: number;
15
+ /** Stop sequences that will cause the model to stop generating */
16
+ stopSequences?: string[];
17
+ /** Candidate count - number of response variations to generate */
18
+ candidateCount?: number;
19
+ /** Maximum number of tokens to generate (Gemini uses maxOutputTokens) */
20
+ maxOutputTokens?: number;
21
+ }
22
+ /**
23
+ * Gemini content part (text or other types)
24
+ */
25
+ export interface GeminiPart {
26
+ text: string;
27
+ }
28
+ /**
29
+ * Gemini message content
30
+ */
31
+ export interface GeminiContent {
32
+ role: 'user' | 'model';
33
+ parts: GeminiPart[];
34
+ }
35
+ /**
36
+ * Gemini generation configuration
37
+ */
38
+ export interface GeminiGenerationConfig {
39
+ temperature?: number;
40
+ topP?: number;
41
+ topK?: number;
42
+ candidateCount?: number;
43
+ maxOutputTokens?: number;
44
+ stopSequences?: string[];
45
+ }
46
+ /**
47
+ * Gemini safety settings
48
+ */
49
+ export interface GeminiSafetySetting {
50
+ category: string;
51
+ threshold: string;
52
+ }
53
+ /**
54
+ * Gemini API request payload
55
+ */
56
+ export interface GeminiAPIRequest {
57
+ contents: GeminiContent[];
58
+ generationConfig?: GeminiGenerationConfig;
59
+ safetySettings?: GeminiSafetySetting[];
60
+ systemInstruction?: {
61
+ parts: GeminiPart[];
62
+ };
63
+ }
64
+ /**
65
+ * Gemini candidate response
66
+ */
67
+ export interface GeminiCandidate {
68
+ content: GeminiContent;
69
+ finishReason?: string;
70
+ index: number;
71
+ safetyRatings?: Array<{
72
+ category: string;
73
+ probability: string;
74
+ }>;
75
+ }
76
+ /**
77
+ * Gemini usage metadata
78
+ */
79
+ export interface GeminiUsageMetadata {
80
+ promptTokenCount: number;
81
+ candidatesTokenCount: number;
82
+ totalTokenCount: number;
83
+ }
84
+ /**
85
+ * Gemini API response format
86
+ */
87
+ export interface GeminiAPIResponse {
88
+ candidates: GeminiCandidate[];
89
+ usageMetadata?: GeminiUsageMetadata;
90
+ promptFeedback?: {
91
+ safetyRatings?: Array<{
92
+ category: string;
93
+ probability: string;
94
+ }>;
95
+ };
96
+ }
97
+ /**
98
+ * Gemini-specific response format (normalized to CommonLLMResponse)
99
+ */
100
+ export interface GeminiResponse extends CommonLLMResponse {
101
+ finishReason?: string;
102
+ safetyRatings?: Array<{
103
+ category: string;
104
+ probability: string;
105
+ }>;
106
+ }
107
+ //# sourceMappingURL=gemini.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini.types.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/types/gemini.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAErE;;;GAGG;AACH,MAAM,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C;IACd,aAAa,CAAC,EAAE,KAAK,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,cAAc,CAAC,EAAE;QACf,aAAa,CAAC,EAAE,KAAK,CAAC;YACpB,QAAQ,EAAE,MAAM,CAAC;YACjB,WAAW,EAAE,MAAM,CAAC;SACrB,CAAC,CAAC;KACJ,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,iBAAiB;IAEvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,KAAK,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;CACJ"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Google Gemini-specific types and interfaces
4
+ * Based on Google Gemini API: https://ai.google.dev/api/rest
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=gemini.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini.types.js","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/types/gemini.types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -1,4 +1,5 @@
1
1
  export * from './common.types';
2
2
  export * from './ollama.types';
3
3
  export * from './anthropic.types';
4
+ export * from './gemini.types';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/types/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAG/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/types/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAG/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
@@ -19,4 +19,5 @@ __exportStar(require("./common.types"), exports);
19
19
  // Provider-specific types
20
20
  __exportStar(require("./ollama.types"), exports);
21
21
  __exportStar(require("./anthropic.types"), exports);
22
+ __exportStar(require("./gemini.types"), exports);
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,eAAe;AACf,iDAA+B;AAE/B,0BAA0B;AAC1B,iDAA+B;AAC/B,oDAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,eAAe;AACf,iDAA+B;AAE/B,0BAA0B;AAC1B,iDAA+B;AAC/B,oDAAkC;AAClC,iDAA+B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loonylabs/llm-middleware",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "Complete middleware infrastructure for LLM-based backends with multi-provider support (Ollama, Anthropic, OpenAI, Google)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",