@aituber-onair/chat 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +8 -2
- package/README.md +9 -2
- package/dist/cjs/constants/gemini.d.ts +11 -0
- package/dist/cjs/constants/gemini.d.ts.map +1 -1
- package/dist/cjs/constants/gemini.js +24 -7
- package/dist/cjs/constants/gemini.js.map +1 -1
- package/dist/cjs/services/providers/gemini/GeminiChatService.js +1 -1
- package/dist/cjs/services/providers/gemini/GeminiChatServiceProvider.d.ts.map +1 -1
- package/dist/cjs/services/providers/gemini/GeminiChatServiceProvider.js +2 -15
- package/dist/cjs/services/providers/gemini/GeminiChatServiceProvider.js.map +1 -1
- package/dist/esm/constants/gemini.d.ts +11 -0
- package/dist/esm/constants/gemini.d.ts.map +1 -1
- package/dist/esm/constants/gemini.js +23 -6
- package/dist/esm/constants/gemini.js.map +1 -1
- package/dist/esm/services/providers/gemini/GeminiChatService.js +2 -2
- package/dist/esm/services/providers/gemini/GeminiChatServiceProvider.d.ts.map +1 -1
- package/dist/esm/services/providers/gemini/GeminiChatServiceProvider.js +3 -16
- package/dist/esm/services/providers/gemini/GeminiChatServiceProvider.js.map +1 -1
- package/dist/umd/aituber-onair-chat.js +19 -21
- package/dist/umd/aituber-onair-chat.min.js +7 -7
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -527,10 +527,16 @@ const claudeService = ChatServiceFactory.createChatService('claude', {
|
|
|
527
527
|
```typescript
|
|
528
528
|
const geminiService = ChatServiceFactory.createChatService('gemini', {
|
|
529
529
|
apiKey: process.env.GOOGLE_API_KEY,
|
|
530
|
-
model: 'gemini-3.1-flash-lite
|
|
530
|
+
model: 'gemini-3.1-flash-lite'
|
|
531
531
|
});
|
|
532
532
|
```
|
|
533
533
|
|
|
534
|
+
`gemini-3.1-flash-lite` が推奨の安定版 Flash-Lite モデルです。
|
|
535
|
+
`gemini-3.1-flash-lite-preview`、`gemini-3-pro-preview`、
|
|
536
|
+
`gemini-2.0-flash`、`gemini-2.0-flash-lite` などの preview /
|
|
537
|
+
shutdown 予定モデルは後方互換のため明示的な model string では利用できますが、
|
|
538
|
+
本番用途では新しいモデルへ移行してください。
|
|
539
|
+
|
|
534
540
|
#### OpenRouter
|
|
535
541
|
|
|
536
542
|
```typescript
|
|
@@ -947,7 +953,7 @@ console.log(modelLevel); // 'unknown'
|
|
|
947
953
|
|
|
948
954
|
- **OpenAI**: GPT-5.5、GPT-5.4 Pro、GPT-5.4、GPT-5.4 Mini、GPT-5.4 Nano、GPT-5.1、GPT-5(Nano/Mini/Standard)、GPT-4.1(miniとnanoを含む), GPT-4, GPT-4o-mini, O3-mini, o1, o1-miniのモデルをサポート
|
|
949
955
|
- **OpenAI-Compatible**: OpenAI互換 endpoint 経由で任意のローカル/セルフホスト model ID を利用できます。vision 対応可否は endpoint ごとに差があるため、原則 `unknown` 扱いです
|
|
950
|
-
- **Gemini**: Gemini 3.1
|
|
956
|
+
- **Gemini**: Gemini 3.1 Flash-Lite、Gemini 3.1 Pro Preview、Gemini 3 Flash Preview、Gemini 2.5 Pro、Gemini 2.5 Flash、Gemini 2.5 Flash Lite、Gemma 4 31B IT、Gemma 4 26B A4B IT などの推奨モデルをサポート。Gemini 3.1 Flash-Lite Preview、Gemini 3 Pro Preview、Gemini 2.0 Flash、Gemini 2.0 Flash-Lite などの lifecycle 上 deprecated なモデルは明示指定用に export を残していますが、shutdown 前に移行してください
|
|
951
957
|
- **Claude**: Claude Opus 4.7, Claude Opus 4.6, Claude Opus 4.5, Claude Sonnet 4.6, Claude Sonnet 4.5, Claude Haiku 4.5 に加え、まだ利用可能だが非推奨の Claude 4 Opus, Claude 4 Sonnet, Claude 3 Haiku をサポート
|
|
952
958
|
- **OpenRouter**: OpenRouterのキュレーション済みモデル一覧(OpenAI/Claude/Gemini/Z.ai/Kimi)をサポート。モデルIDはOpenRouter節を参照してください
|
|
953
959
|
- **Z.ai**: GLM-5/GLM-5-Turbo(テキスト)、GLM-4.7/4.6(テキスト)、GLM-4.6V系(ビジョン)をサポート
|
package/README.md
CHANGED
|
@@ -542,10 +542,17 @@ const claudeService = ChatServiceFactory.createChatService('claude', {
|
|
|
542
542
|
```typescript
|
|
543
543
|
const geminiService = ChatServiceFactory.createChatService('gemini', {
|
|
544
544
|
apiKey: process.env.GOOGLE_API_KEY,
|
|
545
|
-
model: 'gemini-3.1-flash-lite
|
|
545
|
+
model: 'gemini-3.1-flash-lite'
|
|
546
546
|
});
|
|
547
547
|
```
|
|
548
548
|
|
|
549
|
+
`gemini-3.1-flash-lite` is the recommended stable Flash-Lite model. Deprecated
|
|
550
|
+
preview and shutdown-scheduled models such as `gemini-3.1-flash-lite-preview`,
|
|
551
|
+
`gemini-3-pro-preview`, `gemini-2.0-flash`, and
|
|
552
|
+
`gemini-2.0-flash-lite` remain usable by explicit model string for backward
|
|
553
|
+
compatibility, but are no longer advertised in the standard supported-model
|
|
554
|
+
list for production use.
|
|
555
|
+
|
|
549
556
|
#### OpenRouter
|
|
550
557
|
|
|
551
558
|
```typescript
|
|
@@ -962,7 +969,7 @@ Currently, the following AI providers are built-in:
|
|
|
962
969
|
|
|
963
970
|
- **OpenAI**: Supports models like GPT-5.5, GPT-5.4 Pro, GPT-5.4, GPT-5.4 Mini, GPT-5.4 Nano, GPT-5.1, GPT-5 (Nano/Mini/Standard), GPT-4.1 (including mini and nano), GPT-4, GPT-4o-mini, O3-mini, o1, o1-mini
|
|
964
971
|
- **OpenAI-Compatible**: Supports arbitrary local/self-hosted model IDs via OpenAI-compatible endpoints. Vision capability is treated as `unknown` unless your app knows the endpoint-specific model catalog.
|
|
965
|
-
- **Gemini**: Supports models like Gemini 3.1
|
|
972
|
+
- **Gemini**: Supports recommended models like Gemini 3.1 Flash-Lite, Gemini 3.1 Pro Preview, Gemini 3 Flash Preview, Gemini 2.5 Pro, Gemini 2.5 Flash, Gemini 2.5 Flash Lite, Gemma 4 31B IT, and Gemma 4 26B A4B IT. Deprecated lifecycle models such as Gemini 3.1 Flash-Lite Preview, Gemini 3 Pro Preview, Gemini 2.0 Flash, and Gemini 2.0 Flash-Lite remain exported for explicit use, but should be migrated before shutdown.
|
|
966
973
|
- **Claude**: Supports current Claude API model IDs including Claude Opus 4.7, Claude Opus 4.6, Claude Opus 4.5, Claude Sonnet 4.6, Claude Sonnet 4.5, Claude Haiku 4.5, plus deprecated-but-still-available Claude 4 Opus, Claude 4 Sonnet, and Claude 3 Haiku
|
|
967
974
|
- **OpenRouter**: Supports a curated OpenRouter model list (OpenAI/Claude/Gemini/Z.ai/Kimi). See the OpenRouter section for model IDs.
|
|
968
975
|
- **Z.ai**: Supports GLM-5/GLM-5-Turbo (text), GLM-4.7/4.6 (text), and GLM-4.6V family (vision)
|
|
@@ -2,14 +2,25 @@ export declare const ENDPOINT_GEMINI_API = "https://generativelanguage.googleapi
|
|
|
2
2
|
export declare const MODEL_GEMMA_4_31B_IT = "gemma-4-31b-it";
|
|
3
3
|
export declare const MODEL_GEMMA_4_26B_A4B_IT = "gemma-4-26b-a4b-it";
|
|
4
4
|
export declare const MODEL_GEMINI_3_1_PRO_PREVIEW = "gemini-3.1-pro-preview";
|
|
5
|
+
export declare const MODEL_GEMINI_3_1_FLASH_LITE = "gemini-3.1-flash-lite";
|
|
6
|
+
/** @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE instead. */
|
|
5
7
|
export declare const MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW = "gemini-3.1-flash-lite-preview";
|
|
8
|
+
/** @deprecated Use MODEL_GEMINI_3_1_PRO_PREVIEW instead. */
|
|
6
9
|
export declare const MODEL_GEMINI_3_PRO_PREVIEW = "gemini-3-pro-preview";
|
|
7
10
|
export declare const MODEL_GEMINI_3_FLASH_PREVIEW = "gemini-3-flash-preview";
|
|
8
11
|
export declare const MODEL_GEMINI_2_5_PRO = "gemini-2.5-pro";
|
|
9
12
|
export declare const MODEL_GEMINI_2_5_FLASH = "gemini-2.5-flash";
|
|
10
13
|
export declare const MODEL_GEMINI_2_5_FLASH_LITE = "gemini-2.5-flash-lite";
|
|
14
|
+
/** @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE instead. */
|
|
11
15
|
export declare const MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17 = "gemini-2.5-flash-lite-preview-06-17";
|
|
16
|
+
/** @deprecated Use MODEL_GEMINI_2_5_FLASH instead. */
|
|
12
17
|
export declare const MODEL_GEMINI_2_0_FLASH = "gemini-2.0-flash";
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE or
|
|
20
|
+
* MODEL_GEMINI_2_5_FLASH_LITE instead.
|
|
21
|
+
*/
|
|
13
22
|
export declare const MODEL_GEMINI_2_0_FLASH_LITE = "gemini-2.0-flash-lite";
|
|
23
|
+
export declare const GEMINI_RECOMMENDED_MODELS: string[];
|
|
24
|
+
export declare const GEMINI_DEPRECATED_MODELS: string[];
|
|
14
25
|
export declare const GEMINI_VISION_SUPPORTED_MODELS: string[];
|
|
15
26
|
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/constants/gemini.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB,8CAA8C,CAAC;AAG/E,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAC7D,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AACrE,eAAO,MAAM,mCAAmC,kCACf,CAAC;AAClC,eAAO,MAAM,0BAA0B,yBAAyB,CAAC;AACjE,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AACrE,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AACnE,eAAO,MAAM,yCAAyC,wCACf,CAAC;AACxC,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/constants/gemini.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB,8CAA8C,CAAC;AAG/E,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAC7D,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AACrE,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AACnE,2DAA2D;AAC3D,eAAO,MAAM,mCAAmC,kCACf,CAAC;AAClC,4DAA4D;AAC5D,eAAO,MAAM,0BAA0B,yBAAyB,CAAC;AACjE,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AACrE,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AACnE,2DAA2D;AAC3D,eAAO,MAAM,yCAAyC,wCACf,CAAC;AACxC,sDAAsD;AACtD,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD;;;GAGG;AACH,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AAEnE,eAAO,MAAM,yBAAyB,UASrC,CAAC;AAEF,eAAO,MAAM,wBAAwB,UAMpC,CAAC;AAIF,eAAO,MAAM,8BAA8B,UAG1C,CAAC"}
|
|
@@ -1,34 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GEMINI_VISION_SUPPORTED_MODELS = exports.MODEL_GEMINI_2_0_FLASH_LITE = exports.MODEL_GEMINI_2_0_FLASH = exports.MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17 = exports.MODEL_GEMINI_2_5_FLASH_LITE = exports.MODEL_GEMINI_2_5_FLASH = exports.MODEL_GEMINI_2_5_PRO = exports.MODEL_GEMINI_3_FLASH_PREVIEW = exports.MODEL_GEMINI_3_PRO_PREVIEW = exports.MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW = exports.MODEL_GEMINI_3_1_PRO_PREVIEW = exports.MODEL_GEMMA_4_26B_A4B_IT = exports.MODEL_GEMMA_4_31B_IT = exports.ENDPOINT_GEMINI_API = void 0;
|
|
3
|
+
exports.GEMINI_VISION_SUPPORTED_MODELS = exports.GEMINI_DEPRECATED_MODELS = exports.GEMINI_RECOMMENDED_MODELS = exports.MODEL_GEMINI_2_0_FLASH_LITE = exports.MODEL_GEMINI_2_0_FLASH = exports.MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17 = exports.MODEL_GEMINI_2_5_FLASH_LITE = exports.MODEL_GEMINI_2_5_FLASH = exports.MODEL_GEMINI_2_5_PRO = exports.MODEL_GEMINI_3_FLASH_PREVIEW = exports.MODEL_GEMINI_3_PRO_PREVIEW = exports.MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW = exports.MODEL_GEMINI_3_1_FLASH_LITE = exports.MODEL_GEMINI_3_1_PRO_PREVIEW = exports.MODEL_GEMMA_4_26B_A4B_IT = exports.MODEL_GEMMA_4_31B_IT = exports.ENDPOINT_GEMINI_API = void 0;
|
|
4
4
|
// API Endpoints
|
|
5
5
|
exports.ENDPOINT_GEMINI_API = 'https://generativelanguage.googleapis.com';
|
|
6
6
|
// Gemini / Gemma models
|
|
7
7
|
exports.MODEL_GEMMA_4_31B_IT = 'gemma-4-31b-it';
|
|
8
8
|
exports.MODEL_GEMMA_4_26B_A4B_IT = 'gemma-4-26b-a4b-it';
|
|
9
9
|
exports.MODEL_GEMINI_3_1_PRO_PREVIEW = 'gemini-3.1-pro-preview';
|
|
10
|
+
exports.MODEL_GEMINI_3_1_FLASH_LITE = 'gemini-3.1-flash-lite';
|
|
11
|
+
/** @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE instead. */
|
|
10
12
|
exports.MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW = 'gemini-3.1-flash-lite-preview';
|
|
13
|
+
/** @deprecated Use MODEL_GEMINI_3_1_PRO_PREVIEW instead. */
|
|
11
14
|
exports.MODEL_GEMINI_3_PRO_PREVIEW = 'gemini-3-pro-preview';
|
|
12
15
|
exports.MODEL_GEMINI_3_FLASH_PREVIEW = 'gemini-3-flash-preview';
|
|
13
16
|
exports.MODEL_GEMINI_2_5_PRO = 'gemini-2.5-pro';
|
|
14
17
|
exports.MODEL_GEMINI_2_5_FLASH = 'gemini-2.5-flash';
|
|
15
18
|
exports.MODEL_GEMINI_2_5_FLASH_LITE = 'gemini-2.5-flash-lite';
|
|
19
|
+
/** @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE instead. */
|
|
16
20
|
exports.MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17 = 'gemini-2.5-flash-lite-preview-06-17';
|
|
21
|
+
/** @deprecated Use MODEL_GEMINI_2_5_FLASH instead. */
|
|
17
22
|
exports.MODEL_GEMINI_2_0_FLASH = 'gemini-2.0-flash';
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE or
|
|
25
|
+
* MODEL_GEMINI_2_5_FLASH_LITE instead.
|
|
26
|
+
*/
|
|
18
27
|
exports.MODEL_GEMINI_2_0_FLASH_LITE = 'gemini-2.0-flash-lite';
|
|
19
|
-
|
|
20
|
-
exports.
|
|
21
|
-
exports.MODEL_GEMMA_4_31B_IT,
|
|
22
|
-
exports.MODEL_GEMMA_4_26B_A4B_IT,
|
|
28
|
+
exports.GEMINI_RECOMMENDED_MODELS = [
|
|
29
|
+
exports.MODEL_GEMINI_3_1_FLASH_LITE,
|
|
23
30
|
exports.MODEL_GEMINI_3_1_PRO_PREVIEW,
|
|
24
|
-
exports.MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
25
|
-
exports.MODEL_GEMINI_3_PRO_PREVIEW,
|
|
26
31
|
exports.MODEL_GEMINI_3_FLASH_PREVIEW,
|
|
27
32
|
exports.MODEL_GEMINI_2_5_PRO,
|
|
28
33
|
exports.MODEL_GEMINI_2_5_FLASH,
|
|
29
34
|
exports.MODEL_GEMINI_2_5_FLASH_LITE,
|
|
35
|
+
exports.MODEL_GEMMA_4_31B_IT,
|
|
36
|
+
exports.MODEL_GEMMA_4_26B_A4B_IT,
|
|
37
|
+
];
|
|
38
|
+
exports.GEMINI_DEPRECATED_MODELS = [
|
|
39
|
+
exports.MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
40
|
+
exports.MODEL_GEMINI_3_PRO_PREVIEW,
|
|
30
41
|
exports.MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17,
|
|
31
42
|
exports.MODEL_GEMINI_2_0_FLASH,
|
|
32
43
|
exports.MODEL_GEMINI_2_0_FLASH_LITE,
|
|
33
44
|
];
|
|
45
|
+
// Vision support for Gemini models. Deprecated entries remain for explicit
|
|
46
|
+
// model-string compatibility, but are omitted from recommended model lists.
|
|
47
|
+
exports.GEMINI_VISION_SUPPORTED_MODELS = [
|
|
48
|
+
...exports.GEMINI_RECOMMENDED_MODELS,
|
|
49
|
+
...exports.GEMINI_DEPRECATED_MODELS,
|
|
50
|
+
];
|
|
34
51
|
//# sourceMappingURL=gemini.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/constants/gemini.ts"],"names":[],"mappings":";;;AAAA,gBAAgB;AACH,QAAA,mBAAmB,GAAG,2CAA2C,CAAC;AAE/E,wBAAwB;AACX,QAAA,oBAAoB,GAAG,gBAAgB,CAAC;AACxC,QAAA,wBAAwB,GAAG,oBAAoB,CAAC;AAChD,QAAA,4BAA4B,GAAG,wBAAwB,CAAC;AACxD,QAAA,mCAAmC,GAC9C,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/constants/gemini.ts"],"names":[],"mappings":";;;AAAA,gBAAgB;AACH,QAAA,mBAAmB,GAAG,2CAA2C,CAAC;AAE/E,wBAAwB;AACX,QAAA,oBAAoB,GAAG,gBAAgB,CAAC;AACxC,QAAA,wBAAwB,GAAG,oBAAoB,CAAC;AAChD,QAAA,4BAA4B,GAAG,wBAAwB,CAAC;AACxD,QAAA,2BAA2B,GAAG,uBAAuB,CAAC;AACnE,2DAA2D;AAC9C,QAAA,mCAAmC,GAC9C,+BAA+B,CAAC;AAClC,4DAA4D;AAC/C,QAAA,0BAA0B,GAAG,sBAAsB,CAAC;AACpD,QAAA,4BAA4B,GAAG,wBAAwB,CAAC;AACxD,QAAA,oBAAoB,GAAG,gBAAgB,CAAC;AACxC,QAAA,sBAAsB,GAAG,kBAAkB,CAAC;AAC5C,QAAA,2BAA2B,GAAG,uBAAuB,CAAC;AACnE,2DAA2D;AAC9C,QAAA,yCAAyC,GACpD,qCAAqC,CAAC;AACxC,sDAAsD;AACzC,QAAA,sBAAsB,GAAG,kBAAkB,CAAC;AACzD;;;GAGG;AACU,QAAA,2BAA2B,GAAG,uBAAuB,CAAC;AAEtD,QAAA,yBAAyB,GAAG;IACvC,mCAA2B;IAC3B,oCAA4B;IAC5B,oCAA4B;IAC5B,4BAAoB;IACpB,8BAAsB;IACtB,mCAA2B;IAC3B,4BAAoB;IACpB,gCAAwB;CACzB,CAAC;AAEW,QAAA,wBAAwB,GAAG;IACtC,2CAAmC;IACnC,kCAA0B;IAC1B,iDAAyC;IACzC,8BAAsB;IACtB,mCAA2B;CAC5B,CAAC;AAEF,2EAA2E;AAC3E,4EAA4E;AAC/D,QAAA,8BAA8B,GAAG;IAC5C,GAAG,iCAAyB;IAC5B,GAAG,gCAAwB;CAC5B,CAAC"}
|
|
@@ -72,7 +72,7 @@ class GeminiChatService {
|
|
|
72
72
|
* @param tools Array of tool definitions
|
|
73
73
|
* @param mcpServers Array of MCP server configurations
|
|
74
74
|
*/
|
|
75
|
-
constructor(apiKey, model = constants_1.
|
|
75
|
+
constructor(apiKey, model = constants_1.MODEL_GEMINI_3_1_FLASH_LITE, visionModel = constants_1.MODEL_GEMINI_3_1_FLASH_LITE, tools = [], mcpServers = [], responseLength) {
|
|
76
76
|
/** Provider name */
|
|
77
77
|
this.provider = 'gemini';
|
|
78
78
|
this.mcpToolSchemas = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/gemini/GeminiChatServiceProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GeminiChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/gemini/GeminiChatServiceProvider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,wBAAwB,CAAC;AAGhC;;GAEG;AACH,qBAAa,yBACX,YAAW,mBAAmB,CAAC,wBAAwB,CAAC;IAExD;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,WAAW;IAqBjE;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,cAAc,IAAI,OAAO;IAIzB,qBAAqB,IAAI,kBAAkB;IAI3C;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C,6BAA6B,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB;CAGjE"}
|
|
@@ -37,27 +37,14 @@ class GeminiChatServiceProvider {
|
|
|
37
37
|
* @returns Array of supported model names
|
|
38
38
|
*/
|
|
39
39
|
getSupportedModels() {
|
|
40
|
-
return [
|
|
41
|
-
constants_1.MODEL_GEMMA_4_31B_IT,
|
|
42
|
-
constants_1.MODEL_GEMMA_4_26B_A4B_IT,
|
|
43
|
-
constants_1.MODEL_GEMINI_3_1_PRO_PREVIEW,
|
|
44
|
-
constants_1.MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
45
|
-
constants_1.MODEL_GEMINI_3_PRO_PREVIEW,
|
|
46
|
-
constants_1.MODEL_GEMINI_3_FLASH_PREVIEW,
|
|
47
|
-
constants_1.MODEL_GEMINI_2_5_PRO,
|
|
48
|
-
constants_1.MODEL_GEMINI_2_5_FLASH,
|
|
49
|
-
constants_1.MODEL_GEMINI_2_5_FLASH_LITE,
|
|
50
|
-
constants_1.MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17,
|
|
51
|
-
constants_1.MODEL_GEMINI_2_0_FLASH,
|
|
52
|
-
constants_1.MODEL_GEMINI_2_0_FLASH_LITE,
|
|
53
|
-
];
|
|
40
|
+
return [...constants_1.GEMINI_RECOMMENDED_MODELS];
|
|
54
41
|
}
|
|
55
42
|
/**
|
|
56
43
|
* Get the default model
|
|
57
44
|
* @returns Default model name
|
|
58
45
|
*/
|
|
59
46
|
getDefaultModel() {
|
|
60
|
-
return constants_1.
|
|
47
|
+
return constants_1.MODEL_GEMINI_3_1_FLASH_LITE;
|
|
61
48
|
}
|
|
62
49
|
/**
|
|
63
50
|
* Check if this provider supports vision (image processing)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/gemini/GeminiChatServiceProvider.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"GeminiChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/gemini/GeminiChatServiceProvider.ts"],"names":[],"mappings":";;;AAAA,kDAI4B;AAE5B,2DAAwD;AAMxD,0CAAoD;AAEpD;;GAEG;AACH,MAAa,yBAAyB;IAGpC;;;;OAIG;IACH,iBAAiB,CAAC,OAAiC;QACjD,gFAAgF;QAChF,MAAM,WAAW,GAAG,IAAA,0BAAkB,EAAC;YACrC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,kBAAkB,EAAE,IAAI,CAAC,eAAe,EAAE;YAC1C,sBAAsB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC;YACrE,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QAEH,OAAO,IAAI,qCAAiB,CAC1B,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,EACvC,WAAW,EACX,OAAO,CAAC,KAAK,IAAI,EAAE,EACnB,OAAO,CAAC,UAAU,IAAI,EAAE,EACxB,OAAO,CAAC,cAAc,CACvB,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,kBAAkB;QAChB,OAAO,CAAC,GAAG,qCAAyB,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,OAAO,uCAA2B,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,qBAAqB,EAAE,KAAK,aAAa,CAAC;IACxD,CAAC;IAED,qBAAqB;QACnB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,sBAAsB,CAAC,KAAa;QAClC,OAAO,0CAA8B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,6BAA6B,CAAC,KAAa;QACzC,OAAO,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC;IAC1E,CAAC;CACF;AA7ED,8DA6EC"}
|
|
@@ -2,14 +2,25 @@ export declare const ENDPOINT_GEMINI_API = "https://generativelanguage.googleapi
|
|
|
2
2
|
export declare const MODEL_GEMMA_4_31B_IT = "gemma-4-31b-it";
|
|
3
3
|
export declare const MODEL_GEMMA_4_26B_A4B_IT = "gemma-4-26b-a4b-it";
|
|
4
4
|
export declare const MODEL_GEMINI_3_1_PRO_PREVIEW = "gemini-3.1-pro-preview";
|
|
5
|
+
export declare const MODEL_GEMINI_3_1_FLASH_LITE = "gemini-3.1-flash-lite";
|
|
6
|
+
/** @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE instead. */
|
|
5
7
|
export declare const MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW = "gemini-3.1-flash-lite-preview";
|
|
8
|
+
/** @deprecated Use MODEL_GEMINI_3_1_PRO_PREVIEW instead. */
|
|
6
9
|
export declare const MODEL_GEMINI_3_PRO_PREVIEW = "gemini-3-pro-preview";
|
|
7
10
|
export declare const MODEL_GEMINI_3_FLASH_PREVIEW = "gemini-3-flash-preview";
|
|
8
11
|
export declare const MODEL_GEMINI_2_5_PRO = "gemini-2.5-pro";
|
|
9
12
|
export declare const MODEL_GEMINI_2_5_FLASH = "gemini-2.5-flash";
|
|
10
13
|
export declare const MODEL_GEMINI_2_5_FLASH_LITE = "gemini-2.5-flash-lite";
|
|
14
|
+
/** @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE instead. */
|
|
11
15
|
export declare const MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17 = "gemini-2.5-flash-lite-preview-06-17";
|
|
16
|
+
/** @deprecated Use MODEL_GEMINI_2_5_FLASH instead. */
|
|
12
17
|
export declare const MODEL_GEMINI_2_0_FLASH = "gemini-2.0-flash";
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE or
|
|
20
|
+
* MODEL_GEMINI_2_5_FLASH_LITE instead.
|
|
21
|
+
*/
|
|
13
22
|
export declare const MODEL_GEMINI_2_0_FLASH_LITE = "gemini-2.0-flash-lite";
|
|
23
|
+
export declare const GEMINI_RECOMMENDED_MODELS: string[];
|
|
24
|
+
export declare const GEMINI_DEPRECATED_MODELS: string[];
|
|
14
25
|
export declare const GEMINI_VISION_SUPPORTED_MODELS: string[];
|
|
15
26
|
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/constants/gemini.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB,8CAA8C,CAAC;AAG/E,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAC7D,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AACrE,eAAO,MAAM,mCAAmC,kCACf,CAAC;AAClC,eAAO,MAAM,0BAA0B,yBAAyB,CAAC;AACjE,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AACrE,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AACnE,eAAO,MAAM,yCAAyC,wCACf,CAAC;AACxC,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/constants/gemini.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB,8CAA8C,CAAC;AAG/E,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAC7D,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AACrE,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AACnE,2DAA2D;AAC3D,eAAO,MAAM,mCAAmC,kCACf,CAAC;AAClC,4DAA4D;AAC5D,eAAO,MAAM,0BAA0B,yBAAyB,CAAC;AACjE,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AACrE,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AACnE,2DAA2D;AAC3D,eAAO,MAAM,yCAAyC,wCACf,CAAC;AACxC,sDAAsD;AACtD,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD;;;GAGG;AACH,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AAEnE,eAAO,MAAM,yBAAyB,UASrC,CAAC;AAEF,eAAO,MAAM,wBAAwB,UAMpC,CAAC;AAIF,eAAO,MAAM,8BAA8B,UAG1C,CAAC"}
|
|
@@ -4,28 +4,45 @@ export const ENDPOINT_GEMINI_API = 'https://generativelanguage.googleapis.com';
|
|
|
4
4
|
export const MODEL_GEMMA_4_31B_IT = 'gemma-4-31b-it';
|
|
5
5
|
export const MODEL_GEMMA_4_26B_A4B_IT = 'gemma-4-26b-a4b-it';
|
|
6
6
|
export const MODEL_GEMINI_3_1_PRO_PREVIEW = 'gemini-3.1-pro-preview';
|
|
7
|
+
export const MODEL_GEMINI_3_1_FLASH_LITE = 'gemini-3.1-flash-lite';
|
|
8
|
+
/** @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE instead. */
|
|
7
9
|
export const MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW = 'gemini-3.1-flash-lite-preview';
|
|
10
|
+
/** @deprecated Use MODEL_GEMINI_3_1_PRO_PREVIEW instead. */
|
|
8
11
|
export const MODEL_GEMINI_3_PRO_PREVIEW = 'gemini-3-pro-preview';
|
|
9
12
|
export const MODEL_GEMINI_3_FLASH_PREVIEW = 'gemini-3-flash-preview';
|
|
10
13
|
export const MODEL_GEMINI_2_5_PRO = 'gemini-2.5-pro';
|
|
11
14
|
export const MODEL_GEMINI_2_5_FLASH = 'gemini-2.5-flash';
|
|
12
15
|
export const MODEL_GEMINI_2_5_FLASH_LITE = 'gemini-2.5-flash-lite';
|
|
16
|
+
/** @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE instead. */
|
|
13
17
|
export const MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17 = 'gemini-2.5-flash-lite-preview-06-17';
|
|
18
|
+
/** @deprecated Use MODEL_GEMINI_2_5_FLASH instead. */
|
|
14
19
|
export const MODEL_GEMINI_2_0_FLASH = 'gemini-2.0-flash';
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use MODEL_GEMINI_3_1_FLASH_LITE or
|
|
22
|
+
* MODEL_GEMINI_2_5_FLASH_LITE instead.
|
|
23
|
+
*/
|
|
15
24
|
export const MODEL_GEMINI_2_0_FLASH_LITE = 'gemini-2.0-flash-lite';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
MODEL_GEMMA_4_31B_IT,
|
|
19
|
-
MODEL_GEMMA_4_26B_A4B_IT,
|
|
25
|
+
export const GEMINI_RECOMMENDED_MODELS = [
|
|
26
|
+
MODEL_GEMINI_3_1_FLASH_LITE,
|
|
20
27
|
MODEL_GEMINI_3_1_PRO_PREVIEW,
|
|
21
|
-
MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
22
|
-
MODEL_GEMINI_3_PRO_PREVIEW,
|
|
23
28
|
MODEL_GEMINI_3_FLASH_PREVIEW,
|
|
24
29
|
MODEL_GEMINI_2_5_PRO,
|
|
25
30
|
MODEL_GEMINI_2_5_FLASH,
|
|
26
31
|
MODEL_GEMINI_2_5_FLASH_LITE,
|
|
32
|
+
MODEL_GEMMA_4_31B_IT,
|
|
33
|
+
MODEL_GEMMA_4_26B_A4B_IT,
|
|
34
|
+
];
|
|
35
|
+
export const GEMINI_DEPRECATED_MODELS = [
|
|
36
|
+
MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
37
|
+
MODEL_GEMINI_3_PRO_PREVIEW,
|
|
27
38
|
MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17,
|
|
28
39
|
MODEL_GEMINI_2_0_FLASH,
|
|
29
40
|
MODEL_GEMINI_2_0_FLASH_LITE,
|
|
30
41
|
];
|
|
42
|
+
// Vision support for Gemini models. Deprecated entries remain for explicit
|
|
43
|
+
// model-string compatibility, but are omitted from recommended model lists.
|
|
44
|
+
export const GEMINI_VISION_SUPPORTED_MODELS = [
|
|
45
|
+
...GEMINI_RECOMMENDED_MODELS,
|
|
46
|
+
...GEMINI_DEPRECATED_MODELS,
|
|
47
|
+
];
|
|
31
48
|
//# sourceMappingURL=gemini.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/constants/gemini.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,MAAM,CAAC,MAAM,mBAAmB,GAAG,2CAA2C,CAAC;AAE/E,wBAAwB;AACxB,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,oBAAoB,CAAC;AAC7D,MAAM,CAAC,MAAM,4BAA4B,GAAG,wBAAwB,CAAC;AACrE,MAAM,CAAC,MAAM,mCAAmC,GAC9C,+BAA+B,CAAC;AAClC,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AACjE,MAAM,CAAC,MAAM,4BAA4B,GAAG,wBAAwB,CAAC;AACrE,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AACzD,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAC;AACnE,MAAM,CAAC,MAAM,yCAAyC,GACpD,qCAAqC,CAAC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AACzD,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAC;AAEnE,
|
|
1
|
+
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/constants/gemini.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,MAAM,CAAC,MAAM,mBAAmB,GAAG,2CAA2C,CAAC;AAE/E,wBAAwB;AACxB,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,oBAAoB,CAAC;AAC7D,MAAM,CAAC,MAAM,4BAA4B,GAAG,wBAAwB,CAAC;AACrE,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAC;AACnE,2DAA2D;AAC3D,MAAM,CAAC,MAAM,mCAAmC,GAC9C,+BAA+B,CAAC;AAClC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AACjE,MAAM,CAAC,MAAM,4BAA4B,GAAG,wBAAwB,CAAC;AACrE,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AACzD,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAC;AACnE,2DAA2D;AAC3D,MAAM,CAAC,MAAM,yCAAyC,GACpD,qCAAqC,CAAC;AACxC,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AACzD;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAC;AAEnE,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,2BAA2B;IAC3B,4BAA4B;IAC5B,4BAA4B;IAC5B,oBAAoB;IACpB,sBAAsB;IACtB,2BAA2B;IAC3B,oBAAoB;IACpB,wBAAwB;CACzB,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,mCAAmC;IACnC,0BAA0B;IAC1B,yCAAyC;IACzC,sBAAsB;IACtB,2BAA2B;CAC5B,CAAC;AAEF,2EAA2E;AAC3E,4EAA4E;AAC5E,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,GAAG,yBAAyB;IAC5B,GAAG,wBAAwB;CAC5B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ENDPOINT_GEMINI_API,
|
|
1
|
+
import { ENDPOINT_GEMINI_API, MODEL_GEMINI_3_1_FLASH_LITE, GEMINI_VISION_SUPPORTED_MODELS, } from '../../../constants';
|
|
2
2
|
import { getMaxTokensForResponseLength, } from '../../../constants/chat';
|
|
3
3
|
import { StreamTextAccumulator } from '../../../utils/streamTextAccumulator';
|
|
4
4
|
import { ChatServiceHttpClient } from '../../../utils/chatServiceHttpClient';
|
|
@@ -69,7 +69,7 @@ export class GeminiChatService {
|
|
|
69
69
|
* @param tools Array of tool definitions
|
|
70
70
|
* @param mcpServers Array of MCP server configurations
|
|
71
71
|
*/
|
|
72
|
-
constructor(apiKey, model =
|
|
72
|
+
constructor(apiKey, model = MODEL_GEMINI_3_1_FLASH_LITE, visionModel = MODEL_GEMINI_3_1_FLASH_LITE, tools = [], mcpServers = [], responseLength) {
|
|
73
73
|
/** Provider name */
|
|
74
74
|
this.provider = 'gemini';
|
|
75
75
|
this.mcpToolSchemas = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/gemini/GeminiChatServiceProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GeminiChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/gemini/GeminiChatServiceProvider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,wBAAwB,CAAC;AAGhC;;GAEG;AACH,qBAAa,yBACX,YAAW,mBAAmB,CAAC,wBAAwB,CAAC;IAExD;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,WAAW;IAqBjE;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,cAAc,IAAI,OAAO;IAIzB,qBAAqB,IAAI,kBAAkB;IAI3C;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C,6BAA6B,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB;CAGjE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GEMINI_VISION_SUPPORTED_MODELS, GEMINI_RECOMMENDED_MODELS, MODEL_GEMINI_3_1_FLASH_LITE, } from '../../../constants';
|
|
2
2
|
import { GeminiChatService } from './GeminiChatService';
|
|
3
3
|
import { resolveVisionModel } from '../../../utils';
|
|
4
4
|
/**
|
|
@@ -34,27 +34,14 @@ export class GeminiChatServiceProvider {
|
|
|
34
34
|
* @returns Array of supported model names
|
|
35
35
|
*/
|
|
36
36
|
getSupportedModels() {
|
|
37
|
-
return [
|
|
38
|
-
MODEL_GEMMA_4_31B_IT,
|
|
39
|
-
MODEL_GEMMA_4_26B_A4B_IT,
|
|
40
|
-
MODEL_GEMINI_3_1_PRO_PREVIEW,
|
|
41
|
-
MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
42
|
-
MODEL_GEMINI_3_PRO_PREVIEW,
|
|
43
|
-
MODEL_GEMINI_3_FLASH_PREVIEW,
|
|
44
|
-
MODEL_GEMINI_2_5_PRO,
|
|
45
|
-
MODEL_GEMINI_2_5_FLASH,
|
|
46
|
-
MODEL_GEMINI_2_5_FLASH_LITE,
|
|
47
|
-
MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17,
|
|
48
|
-
MODEL_GEMINI_2_0_FLASH,
|
|
49
|
-
MODEL_GEMINI_2_0_FLASH_LITE,
|
|
50
|
-
];
|
|
37
|
+
return [...GEMINI_RECOMMENDED_MODELS];
|
|
51
38
|
}
|
|
52
39
|
/**
|
|
53
40
|
* Get the default model
|
|
54
41
|
* @returns Default model name
|
|
55
42
|
*/
|
|
56
43
|
getDefaultModel() {
|
|
57
|
-
return
|
|
44
|
+
return MODEL_GEMINI_3_1_FLASH_LITE;
|
|
58
45
|
}
|
|
59
46
|
/**
|
|
60
47
|
* Check if this provider supports vision (image processing)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/gemini/GeminiChatServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"GeminiChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/gemini/GeminiChatServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAMxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,yBAAyB;IAGpC;;;;OAIG;IACH,iBAAiB,CAAC,OAAiC;QACjD,gFAAgF;QAChF,MAAM,WAAW,GAAG,kBAAkB,CAAC;YACrC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,kBAAkB,EAAE,IAAI,CAAC,eAAe,EAAE;YAC1C,sBAAsB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC;YACrE,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QAEH,OAAO,IAAI,iBAAiB,CAC1B,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,EACvC,WAAW,EACX,OAAO,CAAC,KAAK,IAAI,EAAE,EACnB,OAAO,CAAC,UAAU,IAAI,EAAE,EACxB,OAAO,CAAC,cAAc,CACvB,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,kBAAkB;QAChB,OAAO,CAAC,GAAG,yBAAyB,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,qBAAqB,EAAE,KAAK,aAAa,CAAC;IACxD,CAAC;IAED,qBAAqB;QACnB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,sBAAsB,CAAC,KAAa;QAClC,OAAO,8BAA8B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,6BAA6B,CAAC,KAAa;QACzC,OAAO,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC;IAC1E,CAAC;CACF"}
|
|
@@ -41,7 +41,9 @@ var AITuberOnAirChat = (() => {
|
|
|
41
41
|
ENDPOINT_XAI_CHAT_COMPLETIONS_API: () => ENDPOINT_XAI_CHAT_COMPLETIONS_API,
|
|
42
42
|
ENDPOINT_ZAI_CHAT_COMPLETIONS_API: () => ENDPOINT_ZAI_CHAT_COMPLETIONS_API,
|
|
43
43
|
EmotionParser: () => EmotionParser,
|
|
44
|
+
GEMINI_DEPRECATED_MODELS: () => GEMINI_DEPRECATED_MODELS,
|
|
44
45
|
GEMINI_NANO_MAX_CONTEXT_MESSAGES: () => GEMINI_NANO_MAX_CONTEXT_MESSAGES,
|
|
46
|
+
GEMINI_RECOMMENDED_MODELS: () => GEMINI_RECOMMENDED_MODELS,
|
|
45
47
|
GEMINI_VISION_SUPPORTED_MODELS: () => GEMINI_VISION_SUPPORTED_MODELS,
|
|
46
48
|
GPT5_PRESETS: () => GPT5_PRESETS,
|
|
47
49
|
GPT_5_MODELS: () => GPT_5_MODELS,
|
|
@@ -79,6 +81,7 @@ var AITuberOnAirChat = (() => {
|
|
|
79
81
|
MODEL_GEMINI_2_5_FLASH_LITE: () => MODEL_GEMINI_2_5_FLASH_LITE,
|
|
80
82
|
MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17: () => MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17,
|
|
81
83
|
MODEL_GEMINI_2_5_PRO: () => MODEL_GEMINI_2_5_PRO,
|
|
84
|
+
MODEL_GEMINI_3_1_FLASH_LITE: () => MODEL_GEMINI_3_1_FLASH_LITE,
|
|
82
85
|
MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW: () => MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
83
86
|
MODEL_GEMINI_3_1_PRO_PREVIEW: () => MODEL_GEMINI_3_1_PRO_PREVIEW,
|
|
84
87
|
MODEL_GEMINI_3_FLASH_PREVIEW: () => MODEL_GEMINI_3_FLASH_PREVIEW,
|
|
@@ -268,6 +271,7 @@ var AITuberOnAirChat = (() => {
|
|
|
268
271
|
var MODEL_GEMMA_4_31B_IT = "gemma-4-31b-it";
|
|
269
272
|
var MODEL_GEMMA_4_26B_A4B_IT = "gemma-4-26b-a4b-it";
|
|
270
273
|
var MODEL_GEMINI_3_1_PRO_PREVIEW = "gemini-3.1-pro-preview";
|
|
274
|
+
var MODEL_GEMINI_3_1_FLASH_LITE = "gemini-3.1-flash-lite";
|
|
271
275
|
var MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW = "gemini-3.1-flash-lite-preview";
|
|
272
276
|
var MODEL_GEMINI_3_PRO_PREVIEW = "gemini-3-pro-preview";
|
|
273
277
|
var MODEL_GEMINI_3_FLASH_PREVIEW = "gemini-3-flash-preview";
|
|
@@ -277,20 +281,27 @@ var AITuberOnAirChat = (() => {
|
|
|
277
281
|
var MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17 = "gemini-2.5-flash-lite-preview-06-17";
|
|
278
282
|
var MODEL_GEMINI_2_0_FLASH = "gemini-2.0-flash";
|
|
279
283
|
var MODEL_GEMINI_2_0_FLASH_LITE = "gemini-2.0-flash-lite";
|
|
280
|
-
var
|
|
281
|
-
|
|
282
|
-
MODEL_GEMMA_4_26B_A4B_IT,
|
|
284
|
+
var GEMINI_RECOMMENDED_MODELS = [
|
|
285
|
+
MODEL_GEMINI_3_1_FLASH_LITE,
|
|
283
286
|
MODEL_GEMINI_3_1_PRO_PREVIEW,
|
|
284
|
-
MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
285
|
-
MODEL_GEMINI_3_PRO_PREVIEW,
|
|
286
287
|
MODEL_GEMINI_3_FLASH_PREVIEW,
|
|
287
288
|
MODEL_GEMINI_2_5_PRO,
|
|
288
289
|
MODEL_GEMINI_2_5_FLASH,
|
|
289
290
|
MODEL_GEMINI_2_5_FLASH_LITE,
|
|
291
|
+
MODEL_GEMMA_4_31B_IT,
|
|
292
|
+
MODEL_GEMMA_4_26B_A4B_IT
|
|
293
|
+
];
|
|
294
|
+
var GEMINI_DEPRECATED_MODELS = [
|
|
295
|
+
MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
296
|
+
MODEL_GEMINI_3_PRO_PREVIEW,
|
|
290
297
|
MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17,
|
|
291
298
|
MODEL_GEMINI_2_0_FLASH,
|
|
292
299
|
MODEL_GEMINI_2_0_FLASH_LITE
|
|
293
300
|
];
|
|
301
|
+
var GEMINI_VISION_SUPPORTED_MODELS = [
|
|
302
|
+
...GEMINI_RECOMMENDED_MODELS,
|
|
303
|
+
...GEMINI_DEPRECATED_MODELS
|
|
304
|
+
];
|
|
294
305
|
|
|
295
306
|
// src/constants/claude.ts
|
|
296
307
|
var ENDPOINT_CLAUDE_API = "https://api.anthropic.com/v1/messages";
|
|
@@ -1760,7 +1771,7 @@ If it's in another language, summarize in that language.
|
|
|
1760
1771
|
* @param tools Array of tool definitions
|
|
1761
1772
|
* @param mcpServers Array of MCP server configurations
|
|
1762
1773
|
*/
|
|
1763
|
-
constructor(apiKey, model =
|
|
1774
|
+
constructor(apiKey, model = MODEL_GEMINI_3_1_FLASH_LITE, visionModel = MODEL_GEMINI_3_1_FLASH_LITE, tools = [], mcpServers = [], responseLength) {
|
|
1764
1775
|
/** Provider name */
|
|
1765
1776
|
this.provider = "gemini";
|
|
1766
1777
|
this.mcpToolSchemas = [];
|
|
@@ -2404,27 +2415,14 @@ If it's in another language, summarize in that language.
|
|
|
2404
2415
|
* @returns Array of supported model names
|
|
2405
2416
|
*/
|
|
2406
2417
|
getSupportedModels() {
|
|
2407
|
-
return [
|
|
2408
|
-
MODEL_GEMMA_4_31B_IT,
|
|
2409
|
-
MODEL_GEMMA_4_26B_A4B_IT,
|
|
2410
|
-
MODEL_GEMINI_3_1_PRO_PREVIEW,
|
|
2411
|
-
MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW,
|
|
2412
|
-
MODEL_GEMINI_3_PRO_PREVIEW,
|
|
2413
|
-
MODEL_GEMINI_3_FLASH_PREVIEW,
|
|
2414
|
-
MODEL_GEMINI_2_5_PRO,
|
|
2415
|
-
MODEL_GEMINI_2_5_FLASH,
|
|
2416
|
-
MODEL_GEMINI_2_5_FLASH_LITE,
|
|
2417
|
-
MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17,
|
|
2418
|
-
MODEL_GEMINI_2_0_FLASH,
|
|
2419
|
-
MODEL_GEMINI_2_0_FLASH_LITE
|
|
2420
|
-
];
|
|
2418
|
+
return [...GEMINI_RECOMMENDED_MODELS];
|
|
2421
2419
|
}
|
|
2422
2420
|
/**
|
|
2423
2421
|
* Get the default model
|
|
2424
2422
|
* @returns Default model name
|
|
2425
2423
|
*/
|
|
2426
2424
|
getDefaultModel() {
|
|
2427
|
-
return
|
|
2425
|
+
return MODEL_GEMINI_3_1_FLASH_LITE;
|
|
2428
2426
|
}
|
|
2429
2427
|
/**
|
|
2430
2428
|
* Check if this provider supports vision (image processing)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var AITuberOnAirChat=(()=>{var
|
|
1
|
+
"use strict";var AITuberOnAirChat=(()=>{var Lt=Object.defineProperty;var Ro=Object.getOwnPropertyDescriptor;var bo=Object.getOwnPropertyNames;var Do=Object.prototype.hasOwnProperty;var No=(r,e)=>{for(var t in e)Lt(r,t,{get:e[t],enumerable:!0})},wo=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of bo(e))!Do.call(r,s)&&s!==t&&Lt(r,s,{get:()=>e[s],enumerable:!(o=Ro(e,s))||o.enumerable});return r};var Vo=r=>wo(Lt({},"__esModule",{value:!0}),r);var ps={};No(ps,{CHAT_RESPONSE_LENGTH:()=>C,CLAUDE_VISION_SUPPORTED_MODELS:()=>Le,ChatServiceFactory:()=>Se,ChatServiceHttpClient:()=>_,ClaudeChatService:()=>ae,ClaudeChatServiceProvider:()=>le,DEFAULT_MAX_TOKENS:()=>Xt,DEFAULT_SUMMARY_PROMPT_TEMPLATE:()=>Bo,DEFAULT_VISION_PROMPT:()=>Ko,EMOTION_TAG_CLEANUP_REGEX:()=>Yt,EMOTION_TAG_REGEX:()=>Oo,ENDPOINT_CLAUDE_API:()=>Vt,ENDPOINT_GEMINI_API:()=>wt,ENDPOINT_KIMI_CHAT_COMPLETIONS_API:()=>ie,ENDPOINT_OPENAI_CHAT_COMPLETIONS_API:()=>Z,ENDPOINT_OPENAI_RESPONSES_API:()=>x,ENDPOINT_OPENROUTER_API:()=>Pe,ENDPOINT_XAI_CHAT_COMPLETIONS_API:()=>Ie,ENDPOINT_ZAI_CHAT_COMPLETIONS_API:()=>xe,EmotionParser:()=>ne,GEMINI_DEPRECATED_MODELS:()=>go,GEMINI_NANO_MAX_CONTEXT_MESSAGES:()=>Zt,GEMINI_RECOMMENDED_MODELS:()=>we,GEMINI_VISION_SUPPORTED_MODELS:()=>ye,GPT5_PRESETS:()=>Jt,GPT_5_MODELS:()=>to,GeminiChatService:()=>pe,GeminiChatServiceProvider:()=>ce,GeminiNanoChatService:()=>ue,GeminiNanoChatServiceProvider:()=>he,HttpError:()=>F,KIMI_VISION_SUPPORTED_MODELS:()=>Mo,KimiChatService:()=>de,KimiChatServiceProvider:()=>me,MAX_TOKENS_BY_LENGTH:()=>Ct,MODEL_ANTHROPIC_CLAUDE_3_5_SONNET:()=>kt,MODEL_ANTHROPIC_CLAUDE_3_7_SONNET:()=>at,MODEL_ANTHROPIC_CLAUDE_4_5_HAIKU:()=>lt,MODEL_ANTHROPIC_CLAUDE_HAIKU_LATEST:()=>it,MODEL_ANTHROPIC_CLAUDE_OPUS_4:()=>rt,MODEL_ANTHROPIC_CLAUDE_SONNET_4:()=>nt,MODEL_ANTHROPIC_CLAUDE_SONNET_LATEST:()=>st,MODEL_CLAUDE_3_5_HAIKU:()=>Go,MODEL_CLAUDE_3_5_SONNET:()=>ko,MODEL_CLAUDE_3_7_SONNET:()=>Fo,MODEL_CLAUDE_3_HAIKU:()=>Ve,MODEL_CLAUDE_4_5_HAIKU:()=>I,MODEL_CLAUDE_4_5_OPUS:()=>Ue,MODEL_CLAUDE_4_5_SONNET:()=>Fe,MODEL_CLAUDE_4_6_OPUS:()=>We,MODEL_CLAUDE_4_6_SONNET:()=>He,MODEL_CLAUDE_4_7_OPUS:()=>Ke,MODEL_CLAUDE_4_OPUS:()=>ke,MODEL_CLAUDE_4_SONNET:()=>Ge,MODEL_GEMINI_2_0_FLASH:()=>ho,MODEL_GEMINI_2_0_FLASH_LITE:()=>mo,MODEL_GEMINI_2_5_FLASH:()=>po,MODEL_GEMINI_2_5_FLASH_LITE:()=>co,MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17:()=>uo,MODEL_GEMINI_2_5_PRO:()=>lo,MODEL_GEMINI_3_1_FLASH_LITE:()=>q,MODEL_GEMINI_3_1_FLASH_LITE_PREVIEW:()=>ro,MODEL_GEMINI_3_1_PRO_PREVIEW:()=>io,MODEL_GEMINI_3_FLASH_PREVIEW:()=>ao,MODEL_GEMINI_3_PRO_PREVIEW:()=>no,MODEL_GEMINI_NANO:()=>J,MODEL_GEMMA_4_26B_A4B_IT:()=>so,MODEL_GEMMA_4_31B_IT:()=>oo,MODEL_GLM_4_6:()=>qt,MODEL_GLM_4_6V:()=>gt,MODEL_GLM_4_6V_FLASH:()=>X,MODEL_GLM_4_6V_FLASHX:()=>_t,MODEL_GLM_4_7:()=>te,MODEL_GLM_4_7_FLASH:()=>jt,MODEL_GLM_4_7_FLASHX:()=>$t,MODEL_GLM_5:()=>Kt,MODEL_GLM_5_TURBO:()=>Bt,MODEL_GOOGLE_GEMINI_2_5_FLASH:()=>ht,MODEL_GOOGLE_GEMINI_2_5_FLASH_LITE_PREVIEW_09_2025:()=>dt,MODEL_GOOGLE_GEMINI_2_5_PRO:()=>ut,MODEL_GOOGLE_GEMINI_FLASH_LATEST:()=>ct,MODEL_GOOGLE_GEMINI_PRO_LATEST:()=>pt,MODEL_GPT_4O:()=>Ne,MODEL_GPT_4O_MINI:()=>$,MODEL_GPT_4_1:()=>Re,MODEL_GPT_4_1_MINI:()=>be,MODEL_GPT_4_1_NANO:()=>De,MODEL_GPT_5:()=>Q,MODEL_GPT_5_1:()=>W,MODEL_GPT_5_4:()=>w,MODEL_GPT_5_4_MINI:()=>K,MODEL_GPT_5_4_NANO:()=>B,MODEL_GPT_5_4_PRO:()=>G,MODEL_GPT_5_5:()=>V,MODEL_GPT_5_MINI:()=>Y,MODEL_GPT_5_NANO:()=>H,MODEL_GPT_OSS_20B_FREE:()=>k,MODEL_GROK_4_1_FAST_NON_REASONING:()=>R,MODEL_GROK_4_1_FAST_REASONING:()=>Ot,MODEL_GROK_4_20_NON_REASONING:()=>Mt,MODEL_GROK_4_20_REASONING:()=>vt,MODEL_GROK_4_3:()=>ft,MODEL_KIMI_K2_5:()=>Et,MODEL_KIMI_K2_6:()=>b,MODEL_MOONSHOTAI_KIMI_K2_5:()=>Be,MODEL_MOONSHOTAI_KIMI_LATEST:()=>$e,MODEL_O1:()=>It,MODEL_O1_MINI:()=>xt,MODEL_O3_MINI:()=>Pt,MODEL_OPENAI_GPT_4O:()=>et,MODEL_OPENAI_GPT_4_1_MINI:()=>tt,MODEL_OPENAI_GPT_4_1_NANO:()=>ot,MODEL_OPENAI_GPT_5_1_CHAT:()=>Je,MODEL_OPENAI_GPT_5_1_CODEX:()=>Ze,MODEL_OPENAI_GPT_5_5:()=>Xe,MODEL_OPENAI_GPT_5_5_PRO:()=>ze,MODEL_OPENAI_GPT_5_MINI:()=>Ye,MODEL_OPENAI_GPT_5_NANO:()=>Qe,MODEL_OPENAI_GPT_LATEST:()=>je,MODEL_OPENAI_GPT_MINI_LATEST:()=>qe,MODEL_OPENROUTER_AUTO:()=>Gt,MODEL_ZAI_GLM_4_5_AIR:()=>Ut,MODEL_ZAI_GLM_4_5_AIR_FREE:()=>mt,MODEL_ZAI_GLM_4_7_FLASH:()=>Ft,OPENROUTER_CREDITS_THRESHOLD:()=>Wo,OPENROUTER_FREE_DAILY_LIMIT_HIGH_CREDITS:()=>Ho,OPENROUTER_FREE_DAILY_LIMIT_LOW_CREDITS:()=>Uo,OPENROUTER_FREE_MODELS:()=>Ht,OPENROUTER_FREE_RATE_LIMIT_PER_MINUTE:()=>Wt,OPENROUTER_VISION_SUPPORTED_MODELS:()=>_o,OpenAIChatService:()=>U,OpenAIChatServiceProvider:()=>_e,OpenAICompatibleChatServiceProvider:()=>ge,OpenRouterChatService:()=>fe,OpenRouterChatServiceProvider:()=>ve,StreamTextAccumulator:()=>v,VISION_SUPPORTED_MODELS:()=>Te,XAIChatService:()=>Me,XAIChatServiceProvider:()=>Oe,XAI_VISION_SUPPORTED_MODELS:()=>vo,ZAIChatService:()=>Ee,ZAIChatServiceProvider:()=>Ce,ZAI_VISION_SUPPORTED_MODELS:()=>fo,allowsReasoningLow:()=>Nt,allowsReasoningMinimal:()=>Dt,allowsReasoningNone:()=>bt,allowsReasoningXHigh:()=>Rt,buildOpenAICompatibleTools:()=>L,getDefaultReasoningEffortForGPT5Model:()=>A,getMaxTokensForResponseLength:()=>O,installGASFetch:()=>Io,isGPT5Model:()=>j,isKimiVisionModel:()=>re,isOpenRouterFreeModel:()=>z,isOpenRouterVisionModel:()=>ee,isResponsesOnlyGPT5Model:()=>At,isXaiVisionModel:()=>se,isZaiToolStreamModel:()=>zt,isZaiVisionModel:()=>oe,parseOpenAICompatibleOneShot:()=>y,parseOpenAICompatibleTextStream:()=>S,parseOpenAICompatibleToolStream:()=>T,processChatWithOptionalTools:()=>f,refreshOpenRouterFreeModels:()=>is,resolveVisionModel:()=>E,runOnceText:()=>zo,screenplayToText:()=>qo,textToScreenplay:()=>Eo,textsToScreenplay:()=>jo});var Z="https://api.openai.com/v1/chat/completions",x="https://api.openai.com/v1/responses",H="gpt-5-nano",Y="gpt-5-mini",Q="gpt-5",W="gpt-5.1",w="gpt-5.4",V="gpt-5.5",K="gpt-5.4-mini",B="gpt-5.4-nano",G="gpt-5.4-pro",Re="gpt-4.1",be="gpt-4.1-mini",De="gpt-4.1-nano",$="gpt-4o-mini",Ne="gpt-4o",Pt="o3-mini",xt="o1-mini",It="o1",Te=[H,Y,Q,W,w,V,K,B,G,Re,be,De,$,Ne,"o1"],to=[H,Y,Q,W,w,V,K,B,G];function j(r){return to.includes(r)}function At(r){return r===G}function Rt(r){return r===V||r===w||r===K||r===B||r===G}function bt(r){return r===W||r===w||r===V||r===K||r===B}function Dt(r){return r===H||r===Y||r===Q}function Nt(r){return r!==G}function A(r){return r===W||r===w||r===V?"none":"medium"}var wt="https://generativelanguage.googleapis.com",oo="gemma-4-31b-it",so="gemma-4-26b-a4b-it",io="gemini-3.1-pro-preview",q="gemini-3.1-flash-lite",ro="gemini-3.1-flash-lite-preview",no="gemini-3-pro-preview",ao="gemini-3-flash-preview",lo="gemini-2.5-pro",po="gemini-2.5-flash",co="gemini-2.5-flash-lite",uo="gemini-2.5-flash-lite-preview-06-17",ho="gemini-2.0-flash",mo="gemini-2.0-flash-lite",we=[q,io,ao,lo,po,co,oo,so],go=[ro,no,uo,ho,mo],ye=[...we,...go];var Vt="https://api.anthropic.com/v1/messages",Ve="claude-3-haiku-20240307",Go="claude-3-5-haiku-20241022",ko="claude-3-5-sonnet-20241022",Fo="claude-3-7-sonnet-20250219",Ge="claude-sonnet-4-20250514",ke="claude-opus-4-20250514",Fe="claude-sonnet-4-5-20250929",I="claude-haiku-4-5-20251001",Ue="claude-opus-4-5-20251101",He="claude-sonnet-4-6",We="claude-opus-4-6",Ke="claude-opus-4-7",Le=[Ve,Ge,ke,Fe,I,Ue,He,We,Ke];var Pe="https://openrouter.ai/api/v1/chat/completions",Gt="openrouter/auto",k="openai/gpt-oss-20b:free",Be="moonshotai/kimi-k2.5",$e="~moonshotai/kimi-latest",je="~openai/gpt-latest",qe="~openai/gpt-mini-latest",ze="openai/gpt-5.5-pro",Xe="openai/gpt-5.5",Je="openai/gpt-5.1-chat",Ze="openai/gpt-5.1-codex",Ye="openai/gpt-5-mini",Qe="openai/gpt-5-nano",et="openai/gpt-4o",tt="openai/gpt-4.1-mini",ot="openai/gpt-4.1-nano",st="~anthropic/claude-sonnet-latest",it="~anthropic/claude-haiku-latest",rt="anthropic/claude-opus-4",nt="anthropic/claude-sonnet-4",at="anthropic/claude-3.7-sonnet",kt="anthropic/claude-3.5-sonnet",lt="anthropic/claude-haiku-4.5",pt="~google/gemini-pro-latest",ct="~google/gemini-flash-latest",ut="google/gemini-2.5-pro",ht="google/gemini-2.5-flash",dt="google/gemini-2.5-flash-lite-preview-09-2025",Ft="z-ai/glm-4.7-flash",Ut="z-ai/glm-4.5-air",mt="z-ai/glm-4.5-air:free",Ht=[k,mt],_o=[$e,je,qe,ze,Xe,Je,Ze,Ye,Qe,et,tt,ot,st,it,rt,nt,at,lt,pt,ct,ut,ht,dt,Be],Wt=20,Uo=50,Ho=1e3,Wo=10;function z(r){return r.trim().endsWith(":free")}function ee(r){return _o.some(e=>r.includes(e))}var xe="https://api.z.ai/api/paas/v4/chat/completions",Kt="glm-5",Bt="glm-5-turbo",te="glm-4.7",$t="glm-4.7-FlashX",jt="glm-4.7-Flash",qt="glm-4.6",gt="glm-4.6V",_t="glm-4.6V-FlashX",X="glm-4.6V-Flash",fo=[gt,_t,X];function oe(r){return fo.includes(r)}function zt(r){return r.toLowerCase().startsWith("glm-4.6")}var Ie="https://api.x.ai/v1/chat/completions",ft="grok-4.3",vt="grok-4.20-0309-reasoning",Mt="grok-4.20-0309-non-reasoning",Ot="grok-4-1-fast-reasoning",R="grok-4-1-fast-non-reasoning",vo=[ft,vt,Mt,Ot,R];function se(r){return vo.includes(r)}var ie="https://api.moonshot.ai/v1/chat/completions",b="kimi-k2.6",Et="kimi-k2.5",Mo=[b,Et];function re(r){return Mo.includes(r)}var C={VERY_SHORT:"veryShort",SHORT:"short",MEDIUM:"medium",LONG:"long",VERY_LONG:"veryLong",DEEP:"deep"},Ct={[C.VERY_SHORT]:40,[C.SHORT]:100,[C.MEDIUM]:200,[C.LONG]:300,[C.VERY_LONG]:1e3,[C.DEEP]:5e3},Xt=5e3,Jt={casual:{reasoning_effort:"minimal",verbosity:"low",description:"Fast responses for casual chat, quick questions (GPT-4 like experience)"},balanced:{reasoning_effort:"medium",verbosity:"medium",description:"Balanced reasoning for business tasks, learning, general problem solving"},expert:{reasoning_effort:"high",verbosity:"high",description:"Deep reasoning for research, complex analysis, expert-level tasks"}};function O(r){return r?Ct[r]??Xt:Xt}var Ko="You are a friendly AI avatar. Comment on the situation based on the broadcast screen.",Bo=`You are a skilled summarizing assistant.
|
|
2
2
|
Analyze the following conversation and produce a summary in the **same language** as the majority of the conversation:
|
|
3
3
|
- Summaries should highlight key points
|
|
4
4
|
- Stay concise (around {maxLength} characters if possible)
|
|
@@ -7,15 +7,15 @@ Analyze the following conversation and produce a summary in the **same language*
|
|
|
7
7
|
If the conversation is in Japanese, summarize in Japanese.
|
|
8
8
|
If it's in English, summarize in English.
|
|
9
9
|
If it's in another language, summarize in that language.
|
|
10
|
-
`;var J="gemini-nano",
|
|
11
|
-
`);s=l.pop()||"";for(let h of l){let m=h.trim();if(!m||m.startsWith(":")||!m.startsWith("data:"))continue;let p=m.slice(5).trim();if(p==="[DONE]"){i=!0;break}e(p)}}};async function
|
|
12
|
-
`))!==-1;){let p=a.slice(0,m).trim();if(a=a.slice(m+1),!p.startsWith("data:"))continue;let d=p.slice(5).trim();if(d==="[DONE]")break;let c=JSON.parse(d);if(c.type==="content_block_delta"&&c.delta?.text&&(t(c.delta.text),i.push({type:"text",text:c.delta.text})),c.type==="content_block_start"&&c.content_block?.type==="tool_use"?n.set(c.index,{id:c.content_block.id,name:c.content_block.name,args:""}):c.type==="content_block_start"&&c.content_block?.type==="mcp_tool_use"?n.set(c.index,{id:c.content_block.id,name:c.content_block.name,args:"",server_name:c.content_block.server_name}):c.type==="content_block_start"&&c.content_block?.type==="tool_result"?i.push({type:"tool_result",tool_use_id:c.content_block.tool_use_id,content:c.content_block.content??""}):c.type==="content_block_start"&&c.content_block?.type==="mcp_tool_result"&&i.push({type:"mcp_tool_result",tool_use_id:c.content_block.tool_use_id,is_error:c.content_block.is_error??!1,content:c.content_block.content??[]}),c.type==="content_block_delta"&&c.delta?.type==="input_json_delta"){let u=n.get(c.index);u&&(u.args+=c.delta.partial_json||"")}if(c.type==="content_block_stop"&&n.has(c.index)){let{id:u,name:M,args:P,server_name:g}=n.get(c.index);g?i.push({type:"mcp_tool_use",id:u,name:M,server_name:g,input:JSON.parse(P||"{}")}):i.push({type:"tool_use",id:u,name:M,input:JSON.parse(P||"{}")}),n.delete(c.index)}}}return{blocks:i,stop_reason:i.some(l=>l.type==="tool_use"||l.type==="mcp_tool_use")?"tool_use":"end"}}async parsePureStream(e,t){let{blocks:o}=await this.parseStream(e,t);return o.filter(s=>s.type==="text").map(s=>s.text).join("")}parseOneShot(e){let t=[];return(e.content??[]).forEach(o=>{o.type==="text"?t.push({type:"text",text:o.text}):o.type==="tool_use"?t.push({type:"tool_use",id:o.id,name:o.name,input:o.input??{}}):o.type==="mcp_tool_use"?t.push({type:"mcp_tool_use",id:o.id,name:o.name,server_name:o.server_name,input:o.input??{}}):o.type==="tool_result"?t.push({type:"tool_result",tool_use_id:o.tool_use_id,content:o.content??""}):o.type==="mcp_tool_result"&&t.push({type:"mcp_tool_result",tool_use_id:o.tool_use_id,is_error:o.is_error??!1,content:o.content??[]})}),{blocks:t,stop_reason:t.some(o=>o.type==="tool_use"||o.type==="mcp_tool_use")?"tool_use":"end"}}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callClaude(e,this.model,t,s),n=t?await this.parseStream(i,o):this.parseOneShot(await i.json());return this.convertToStandardCompletion(n)}async visionChatOnce(e,t=!1,o=()=>{},s){let i=await this.callClaude(e,this.visionModel,t,s),n=t?await this.parseStream(i,o):this.parseOneShot(await i.json());return this.convertToStandardCompletion(n)}convertToStandardCompletion(e){return{blocks:e.blocks.filter(o=>o.type==="text"||o.type==="tool_use"||o.type==="tool_result"),stop_reason:e.stop_reason}}};var le=class{createChatService(e){let t=E({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:o=>this.supportsVisionForModel(o),validate:"resolved"});return new ae(e.apiKey,e.model||this.getDefaultModel(),t,e.tools??[],e.mcpServers??[],e.responseLength)}getProviderName(){return"claude"}getSupportedModels(){return[qe,ze,Xe,x,Je,Ze,Ye,Qe,je]}getDefaultModel(){return x}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return Le.includes(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}};var Nt=class{static async fetchToolSchemas(e){try{let t={"Content-Type":"application/json"};e.authorization_token&&(t.Authorization=`Bearer ${e.authorization_token}`);let s=await(await _.post(`${e.url}/tools`,{},t)).json();return Array.isArray(s.tools)?s.tools.map(i=>({name:`mcp_${e.name}_${i.name}`,description:i.description||`Tool from ${e.name} MCP server`,parameters:i.inputSchema||{type:"object",properties:{},required:[]}})):[{name:`mcp_${e.name}_search`,description:`Search using ${e.name} MCP server`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}}]}catch(t){return console.warn(`Failed to fetch MCP schemas from ${e.name}:`,t),[{name:`mcp_${e.name}_search`,description:`Search using ${e.name} MCP server (schema fetch failed)`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}}]}}static async fetchAllToolSchemas(e){let t=[];for(let o of e)try{let s=await this.fetchToolSchemas(o);t.push(...s)}catch(s){console.error(`Failed to fetch schemas from ${o.name}:`,s)}return t}};var pe=class{constructor(e,t=k,o=k,s=[],i=[],n){this.provider="gemini";this.mcpToolSchemas=[];this.mcpSchemasInitialized=!1;this.callIdMap=new Map;if(this.apiKey=e,this.model=t,this.responseLength=n,!ye.includes(o))throw new Error(`Model ${o} does not support vision capabilities.`);this.visionModel=o,this.tools=s,this.mcpServers=i}safeJsonParse(e){try{return JSON.parse(e)}catch{return e}}normalizeToolResult(e){return e===null?{content:null}:typeof e=="object"?e:{content:e}}isGemma4Model(e){return/^gemma-4-/.test(e)}shouldExposeTextPart(e,t){return!(!e.text||this.isGemma4Model(t)&&e.thought===!0)}adaptKeysForApi(e){let t={toolConfig:"tool_config",functionCallingConfig:"function_calling_config",functionDeclarations:"function_declarations",functionCall:"function_call",functionResponse:"function_response"};return Array.isArray(e)?e.map(o=>this.adaptKeysForApi(o)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([o,s])=>[t[o]??o,this.adaptKeysForApi(s)])):e}getModel(){return this.model}getVisionModel(){return this.visionModel}getMCPServers(){return this.mcpServers}addMCPServer(e){this.mcpServers.push(e),this.mcpSchemasInitialized=!1}removeMCPServer(e){this.mcpServers=this.mcpServers.filter(t=>t.name!==e),this.mcpSchemasInitialized=!1}hasMCPServers(){return this.mcpServers.length>0}async initializeMCPSchemas(){if(!(this.mcpSchemasInitialized||this.mcpServers.length===0))try{let e=new Promise((o,s)=>setTimeout(()=>s(new Error("MCP schema fetch timeout")),5e3)),t=Nt.fetchAllToolSchemas(this.mcpServers);this.mcpToolSchemas=await Promise.race([t,e]),this.mcpSchemasInitialized=!0}catch(e){console.warn("Failed to initialize MCP schemas, using fallback:",e),this.mcpToolSchemas=this.mcpServers.map(t=>({name:`mcp_${t.name}_search`,description:`Search using ${t.name} MCP server (fallback)`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}})),this.mcpSchemasInitialized=!0}}async processChat(e,t,o){try{await f({hasTools:this.tools.length>0||this.mcpServers.length>0,runWithoutTools:async()=>{let s=await this.callGemini(e,this.model,!0),{blocks:i}=await this.parseStream(s,t,this.model);return v.getFullText(i)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"Received functionCall. Use chatOnce() loop when tools are enabled."})}catch(s){throw console.error("Error in processChat:",s),s}}async processVisionChat(e,t,o){try{await f({hasTools:this.tools.length>0||this.mcpServers.length>0,runWithoutTools:async()=>{let s=await this.callGemini(e,this.visionModel,!0),{blocks:i}=await this.parseStream(s,t,this.visionModel);return v.getFullText(i)},runWithTools:()=>this.visionChatOnce(e),onToolBlocks:s=>{s.filter(i=>i.type==="text").forEach(i=>t(i.text))},onCompleteResponse:o,toolErrorMessage:"Received functionCall. Use visionChatOnce() loop when tools are enabled."})}catch(s){throw console.error("Error in processVisionChat:",s),s}}convertMessagesToGeminiFormat(e){let t=[],o=null,s=[],i=()=>{o&&s.length&&(t.push({role:o,parts:[...s]}),s=[])};for(let n of e){let a=this.mapRoleToGemini(n.role);if(n.tool_calls){i();for(let l of n.tool_calls)this.callIdMap.set(l.id,l.function.name),t.push({role:"model",parts:[{functionCall:{name:l.function.name,args:JSON.parse(l.function.arguments||"{}")}}]});continue}if(n.role==="tool"){i();let l=n.name??this.callIdMap.get(n.tool_call_id)??"result";t.push({role:"user",parts:[{functionResponse:{name:l,response:this.normalizeToolResult(this.safeJsonParse(n.content))}}]});continue}a!==o&&i(),o=a,s.push({text:n.content})}return i(),t}async callGemini(e,t,o=!1,s){let a={contents:e.some(g=>Array.isArray(g.content)&&g.content.some(D=>D?.type==="image_url"||D?.inlineData))?await this.convertVisionMessagesToGeminiFormat(e):this.convertMessagesToGeminiFormat(e),generationConfig:{maxOutputTokens:s!==void 0?s:O(this.responseLength)}};this.isGemma4Model(t)&&(a.generationConfig.thinkingConfig={includeThoughts:!1,thinkingLevel:"minimal"});let l=[];if(this.tools.length>0&&l.push(...this.tools.map(g=>({name:g.name,description:g.description,parameters:g.parameters}))),this.mcpServers.length>0)try{await this.initializeMCPSchemas(),l.push(...this.mcpToolSchemas.map(g=>({name:g.name,description:g.description,parameters:g.parameters})))}catch(g){console.warn("MCP initialization failed, skipping MCP tools:",g)}l.length>0&&(a.tools=[{functionDeclarations:l}],a.toolConfig={functionCallingConfig:{mode:"AUTO"}});let h=async(g,D)=>{let N=o?"streamGenerateContent":"generateContent",co=o?"?alt=sse":"",Po=`${$t}/${g}/models/${t}:${N}${co}${co?"&":"?"}key=${this.apiKey}`;return _.post(Po,D)},m=/flash[-_]lite/.test(t),p=this.isGemma4Model(t),d=/gemini-2\.5/.test(t),c=/^gemini-3(?:\.[0-9]+)?-.*preview/.test(t),u=m||p||d||c,M=u?"v1beta":"v1",P=async()=>{try{let g=M==="v1"?a:this.adaptKeysForApi(a);return await h(M,g)}catch(g){let D=/Unknown name|Cannot find field|404/.test(g?.message||"")||g?.status===404;if(!u&&D)return await h("v1beta",this.adaptKeysForApi(a));throw g}};try{return await P()}catch(g){throw g.body&&(console.error("Gemini API Error Details:",g.body),console.error("Request Body:",JSON.stringify(a,null,2))),g}}async convertVisionMessagesToGeminiFormat(e){let t=[],o=null,s=[];for(let i of e){let n=this.mapRoleToGemini(i.role);if(i.tool_calls){for(let a of i.tool_calls)t.push({role:"model",parts:[{functionCall:{name:a.function.name,args:JSON.parse(a.function.arguments||"{}")}}]});continue}if(i.role==="tool"){let a=i.name??this.callIdMap.get(i.tool_call_id)??"result";t.push({role:"user",parts:[{functionResponse:{name:a,response:this.normalizeToolResult(this.safeJsonParse(i.content))}}]});continue}if(n!==o&&s.length>0&&(t.push({role:o,parts:[...s]}),s=[]),o=n,typeof i.content=="string")s.push({text:i.content});else if(Array.isArray(i.content)){for(let a of i.content)if(a.type==="text")s.push({text:a.text});else if(a.type==="image_url")try{let h=await(await _.get(a.image_url.url)).blob(),m=await this.blobToBase64(h);s.push({inlineData:{mimeType:h.type||"image/jpeg",data:m.split(",")[1]}})}catch(l){throw console.error("Error processing image:",l),new Error(`Failed to process image: ${l.message}`)}}}return o&&s.length>0&&t.push({role:o,parts:[...s]}),t}blobToBase64(e){return new Promise((t,o)=>{let s=new FileReader;s.onloadend=()=>t(s.result),s.onerror=o,s.readAsDataURL(e)})}mapRoleToGemini(e){switch(e){case"system":return"model";case"user":return"user";case"assistant":return"model";default:return"user"}}async parseStream(e,t,o){let s=e.body.getReader(),i=new TextDecoder,n=[],a=[],l="",h=p=>{if(!p||p==="[DONE]")return;let d;try{d=JSON.parse(p)}catch{return}for(let c of d.candidates??[])for(let u of c.content?.parts??[])this.shouldExposeTextPart(u,o)&&(t(u.text),v.addTextBlock(n,u.text)),u.functionCall&&a.push({type:"tool_use",id:this.genUUID(),name:u.functionCall.name,input:u.functionCall.args??{}}),u.functionResponse&&a.push({type:"tool_result",tool_use_id:u.functionResponse.name,content:JSON.stringify(u.functionResponse.response)})};for(;;){let{done:p,value:d}=await s.read();if(p)break;l+=i.decode(d,{stream:!0});let c;for(;(c=l.indexOf(`
|
|
13
|
-
`))!==-1;){let u=l.slice(0,c);if(l=l.slice(c+1),u.endsWith("\r")&&(u=u.slice(0,-1)),!u.trim()){h("");continue}u.startsWith("data:")&&(u=u.slice(5).trim()),u&&h(u)}}return l&&h(l),{blocks:[...n,...a],stop_reason:a.some(p=>p.type==="tool_use")?"tool_use":"end"}}parseOneShot(e,t){let o=[],s=[];for(let n of e.candidates??[])for(let a of n.content?.parts??[])this.shouldExposeTextPart(a,t)&&o.push({type:"text",text:a.text}),a.functionCall&&s.push({type:"tool_use",id:this.genUUID(),name:a.functionCall.name,input:a.functionCall.args??{}}),a.functionResponse&&s.push({type:"tool_result",tool_use_id:a.functionResponse.name,content:JSON.stringify(a.functionResponse.response)});return{blocks:[...o,...s],stop_reason:s.some(n=>n.type==="tool_use")?"tool_use":"end"}}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callGemini(e,this.model,t,s);return t?this.parseStream(i,o,this.model):this.parseOneShot(await i.json(),this.model)}async visionChatOnce(e,t=!1,o=()=>{},s){let i=await this.callGemini(e,this.visionModel,t,s);return t?this.parseStream(i,o,this.visionModel):this.parseOneShot(await i.json(),this.visionModel)}genUUID(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}};var ce=class{createChatService(e){let t=E({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:o=>this.supportsVisionForModel(o),validate:"resolved"});return new pe(e.apiKey,e.model||this.getDefaultModel(),t,e.tools||[],e.mcpServers||[],e.responseLength)}getProviderName(){return"gemini"}getSupportedModels(){return[we
|
|
10
|
+
`;var J="gemini-nano",Zt=20;var F=class extends Error{constructor(t,o,s){super(`HTTP ${t}: ${o}`);this.status=t;this.statusText=o;this.body=s;this.name="HttpError"}},Ae=class Ae{static setFetch(e){this.fetchImpl=e}static async post(e,t,o={},s={}){let{timeout:i=3e4,retries:n=0,retryDelay:a=1e3}=s,h={...{"Content-Type":"application/json"},...o},m=null;for(let p=0;p<=n;p++)try{let d=typeof AbortController<"u",c=d?new AbortController:void 0,u=d?setTimeout(()=>c.abort(),i):void 0,M=await Ae.fetchImpl(e,{method:"POST",headers:h,body:typeof t=="string"?t:JSON.stringify(t),...c?{signal:c.signal}:{}});if(u&&clearTimeout(u),!M.ok){let P=await M.text();throw new F(M.status,M.statusText,P)}return M}catch(d){if(m=d,d instanceof F&&d.status>=400&&d.status<500)throw d;if(d instanceof Error&&d.name==="AbortError")throw new Error(`Request timeout after ${i}ms`);p<n&&await new Promise(c=>setTimeout(c,a*(p+1)))}throw m||new Error("Request failed")}static async handleErrorResponse(e){let t=await e.text();throw new F(e.status,e.statusText,t)}static async get(e,t={},o={}){let{timeout:s=3e4,retries:i=0,retryDelay:n=1e3}=o,a=null;for(let l=0;l<=i;l++)try{let h=typeof AbortController<"u",m=h?new AbortController:void 0,p=h?setTimeout(()=>m.abort(),s):void 0,d=await Ae.fetchImpl(e,{method:"GET",headers:t,...m?{signal:m.signal}:{}});if(p&&clearTimeout(p),!d.ok){let c=await d.text();throw new F(d.status,d.statusText,c)}return d}catch(h){if(a=h,h instanceof F&&h.status>=400&&h.status<500)throw h;if(h instanceof Error&&h.name==="AbortError")throw new Error(`Request timeout after ${s}ms`);l<i&&await new Promise(m=>setTimeout(m,n*(l+1)))}throw a||new Error("Request failed")}};Ae.fetchImpl=(e,t)=>fetch(e,t);var _=Ae;var v=class{static append(e,t){if(!t)return;let o=e[e.length-1];o&&o.type==="text"?o.text+=t:e.push({type:"text",text:t})}static getFullText(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}static addTextBlock(e,t){t&&e.push({type:"text",text:t})}};var $o=["happy","sad","angry","surprised","neutral"],Oo=/\[([a-z]+)\]/i,Yt=/\[[a-z]+\]\s*/gi,ne=class{static extractEmotion(e){let t=e.match(Oo);if(t){let o=t[1].toLowerCase(),s=e.replace(Yt,"").trim();return{emotion:o,cleanText:s}}return{cleanText:e}}static isValidEmotion(e){return $o.includes(e)}static cleanEmotionTags(e){return e.replace(Yt,"").trim()}static addEmotionTag(e,t){return`[${e}] ${t}`}};function Eo(r){let{emotion:e,cleanText:t}=ne.extractEmotion(r);return e?{emotion:e,text:t}:{text:t}}function jo(r){return r.map(e=>Eo(e))}function qo(r){return r.emotion?ne.addEmotionTag(r.emotion,r.text):r.text}async function zo(r,e){let{blocks:t}=await r.chatOnce(e,!1,()=>{});return v.getFullText(t)}var Co=(r,e)=>{try{return JSON.parse(r)}catch(t){if(e){e(r,t);return}throw t}},So=async(r,e)=>{let t=r.body?.getReader();if(!t)throw new Error("Response body is null.");let o=new TextDecoder,s="",i=!1;for(;!i;){let{done:n,value:a}=await t.read();if(n)break;s+=o.decode(a,{stream:!0});let l=s.split(`
|
|
11
|
+
`);s=l.pop()||"";for(let h of l){let m=h.trim();if(!m||m.startsWith(":")||!m.startsWith("data:"))continue;let p=m.slice(5).trim();if(p==="[DONE]"){i=!0;break}e(p)}}};async function S(r,e,t={}){let o="";return await So(r,s=>{let i=Co(s,t.onJsonError);if(!i)return;let n=i.choices?.[0]?.delta?.content||"";n&&(e(n),o+=n)}),o}async function T(r,e,t={}){let o=[],s=new Map,i,n,a=t.appendTextBlock??v.append;await So(r,m=>{let p=Co(m,t.onJsonError);if(!p)return;let d=p.choices?.[0];typeof d?.finish_reason=="string"&&(i=d.finish_reason),p.usage&&(n=p.usage);let c=d?.delta;c?.content&&(e(c.content),a(o,c.content)),c?.tool_calls&&c.tool_calls.forEach(u=>{let M=s.get(u.index)??{id:u.id,name:u.function?.name,args:""};M.args+=u.function?.arguments||"",s.set(u.index,M)})});let l=Array.from(s.entries()).sort((m,p)=>m[0]-p[0]).map(([m,p])=>({type:"tool_use",id:p.id,name:p.name,input:JSON.parse(p.args||"{}")}));return{blocks:[...o,...l],stop_reason:l.length?"tool_use":"end",truncated:i==="length",finish_reason:i,usage:n}}function y(r){let e=r?.choices?.[0],t=[];return e?.message?.tool_calls?.length?e.message.tool_calls.forEach(o=>t.push({type:"tool_use",id:o.id,name:o.function?.name,input:JSON.parse(o.function?.arguments||"{}")})):e?.message?.content&&t.push({type:"text",text:e.message.content}),{blocks:t,stop_reason:e?.finish_reason==="tool_calls"||t.some(o=>o.type==="tool_use")?"tool_use":"end",truncated:e?.finish_reason==="length",finish_reason:e?.finish_reason,usage:r?.usage}}var L=(r,e="chat-completions")=>r.length===0?[]:e==="responses"?r.map(t=>({type:"function",name:t.name,description:t.description,parameters:t.parameters})):r.map(t=>({type:"function",function:{name:t.name,description:t.description,parameters:t.parameters}}));async function f(r){if(!r.hasTools){let t=await r.runWithoutTools();await r.onCompleteResponse(t);return}let e=await r.runWithTools();if(r.onToolBlocks&&r.onToolBlocks(e.blocks),e.stop_reason==="end"){let t=v.getFullText(e.blocks);await r.onCompleteResponse(t);return}throw new Error(r.toolErrorMessage)}var E=r=>{let e=r.model??r.defaultModel,t=r.visionModel??(r.supportsVisionForModel(e)?e:r.defaultVisionModel);if(r.validate==="explicit"&&r.visionModel&&!r.supportsVisionForModel(r.visionModel))throw new Error(`Model ${r.visionModel} does not support vision capabilities.`);if(r.validate==="resolved"&&!r.supportsVisionForModel(t))throw new Error(`Model ${t} does not support vision capabilities.`);return t};var Xo="https://openrouter.ai/api/v1/models",Jo=2,Zo=12e3,Yo=1,Qo=10;function Qt(r){return r instanceof Error?r.message:String(r)}function St(r,e){return typeof r!="number"||!Number.isFinite(r)?e:Math.max(1,Math.floor(r))}function es(r){let e=new Set,t=[];for(let o of r){let s=o.trim();!s||e.has(s)||(e.add(s),t.push(s))}return t}async function To(r,e,t){if(!(typeof AbortController<"u"))return fetch(r,e);let s=new AbortController,i=setTimeout(()=>s.abort(),t);try{return await fetch(r,{...e,signal:s.signal})}catch(n){throw n instanceof Error&&n.name==="AbortError"?new Error(`Timeout after ${t}ms`):n}finally{clearTimeout(i)}}async function yo(r){let e=`HTTP ${r.status} ${r.statusText}`.trim(),t="";try{t=await r.text()}catch{return e}let o=t.replace(/\s+/g," ").trim().slice(0,200);return o?`${e}: ${o}`:e}function ts(r){if(!r||typeof r!="object")throw new Error("Invalid models response shape");let e=r,t=Array.isArray(e.data)?e.data:Array.isArray(e.models)?e.models:[];if(t.length===0)return[];let o=t.map(s=>s.id).filter(s=>typeof s=="string");return es(o)}async function os({modelId:r,apiKey:e,endpoint:t,timeoutMs:o,appName:s,appUrl:i}){let n={Authorization:`Bearer ${e}`,"Content-Type":"application/json"};s&&(n["X-Title"]=s),i&&(n["HTTP-Referer"]=i);try{let a=await To(t,{method:"POST",headers:n,body:JSON.stringify({model:r,messages:[{role:"user",content:"Reply only with OK."}],stream:!1})},o);if(!a.ok)return{id:r,ok:!1,reason:await yo(a)};try{await a.json()}catch(l){return{id:r,ok:!1,reason:`JSON parse failed: ${Qt(l)}`}}return{id:r,ok:!0}}catch(a){return{id:r,ok:!1,reason:Qt(a)}}}async function ss(r,e,t){if(r.length===0)return[];let o=new Array(r.length),s=0,i=Math.min(e,r.length);return await Promise.all(Array.from({length:i},async()=>{for(;s<r.length;){let n=s;s+=1,o[n]=await t(r[n])}})),o}async function is(r){let e=r.apiKey.trim();if(!e)throw new Error("OpenRouter API key is required.");let t=r.modelsEndpoint||Xo,o=r.endpoint||Pe,s=St(r.timeoutMs,Zo),i=St(r.concurrency,Jo),n=St(r.maxCandidates,Yo),a=St(r.maxWorking,Qo),l=await To(t,{method:"GET"},s);if(!l.ok)throw new Error(await yo(l));let h;try{h=await l.json()}catch(u){throw new Error(`JSON parse failed: ${Qt(u)}`)}let m=ts(h).filter(u=>z(u)).slice(0,n),p=await ss(m,i,u=>os({modelId:u,apiKey:e,endpoint:o,timeoutMs:s,appName:r.appName,appUrl:r.appUrl})),d=p.filter(u=>u.ok).map(u=>u.id).slice(0,a),c=p.filter(u=>!u.ok).map(u=>({id:u.id,reason:u.reason||"Unknown error"}));return{working:d,failed:c,fetchedAt:Date.now()}}var ae=class{constructor(e,t=I,o=I,s=[],i=[],n){this.provider="claude";if(this.apiKey=e,this.model=t||I,this.visionModel=o||I,this.tools=s,this.mcpServers=i,this.responseLength=n,!Le.includes(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`)}getModel(){return this.model}getVisionModel(){return this.visionModel}getMCPServers(){return this.mcpServers}addMCPServer(e){this.mcpServers.push(e)}removeMCPServer(e){this.mcpServers=this.mcpServers.filter(t=>t.name!==e)}hasMCPServers(){return this.mcpServers.length>0}async processChat(e,t,o){await f({hasTools:this.tools.length>0||this.mcpServers.length>0,runWithoutTools:async()=>{let s=await this.callClaude(e,this.model,!0);return this.parsePureStream(s,t)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){await f({hasTools:this.tools.length>0||this.mcpServers.length>0,runWithoutTools:async()=>{let s=await this.callClaude(e,this.visionModel,!0);return this.parsePureStream(s,t)},runWithTools:()=>this.visionChatOnce(e),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}convertMessagesToClaudeFormat(e){return e.map(t=>({role:this.mapRoleToClaude(t.role),content:t.content}))}convertVisionMessagesToClaudeFormat(e){return e.map(t=>{if(typeof t.content=="string")return{role:this.mapRoleToClaude(t.role),content:[{type:"text",text:t.content}]};if(Array.isArray(t.content)){let o=t.content.map(s=>{if(s.type==="image_url"){if(s.image_url.url.startsWith("data:")){let i=s.image_url.url.match(/^data:([^;]+);base64,(.+)$/);return i?{type:"image",source:{type:"base64",media_type:i[1],data:i[2]}}:null}return{type:"image",source:{type:"url",url:s.image_url.url,media_type:this.getMimeTypeFromUrl(s.image_url.url)}}}return s}).filter(s=>s);return{role:this.mapRoleToClaude(t.role),content:o}}return{role:this.mapRoleToClaude(t.role),content:[]}})}mapRoleToClaude(e){switch(e){case"system":return"system";case"user":return"user";case"assistant":return"assistant";default:return"user"}}getMimeTypeFromUrl(e){switch(e.split(".").pop()?.toLowerCase()){case"jpg":case"jpeg":return"image/jpeg";case"png":return"image/png";case"gif":return"image/gif";case"webp":return"image/webp";default:return"image/jpeg"}}async callClaude(e,t,o,s){let i=e.find(p=>p.role==="system")?.content??"",n=e.filter(p=>p.role!=="system"),a=n.some(p=>Array.isArray(p.content)&&p.content.some(d=>d.type==="image_url"||d.type==="image")),l={model:t,system:i,messages:a?this.convertVisionMessagesToClaudeFormat(n):this.convertMessagesToClaudeFormat(n),stream:o,max_tokens:s!==void 0?s:O(this.responseLength)};this.tools.length&&(l.tools=this.tools.map(p=>({name:p.name,description:p.description,input_schema:p.parameters})),l.tool_choice={type:"auto"}),this.mcpServers.length>0&&(l.mcp_servers=this.mcpServers);let h={"Content-Type":"application/json","x-api-key":this.apiKey,"anthropic-version":"2023-06-01","anthropic-dangerous-direct-browser-access":"true"};return this.mcpServers.length>0&&(h["anthropic-beta"]="mcp-client-2025-04-04"),await _.post(Vt,l,h)}async parseStream(e,t){let o=e.body.getReader(),s=new TextDecoder,i=[],n=new Map,a="";for(;;){let{done:l,value:h}=await o.read();if(l)break;a+=s.decode(h,{stream:!0});let m;for(;(m=a.indexOf(`
|
|
12
|
+
`))!==-1;){let p=a.slice(0,m).trim();if(a=a.slice(m+1),!p.startsWith("data:"))continue;let d=p.slice(5).trim();if(d==="[DONE]")break;let c=JSON.parse(d);if(c.type==="content_block_delta"&&c.delta?.text&&(t(c.delta.text),i.push({type:"text",text:c.delta.text})),c.type==="content_block_start"&&c.content_block?.type==="tool_use"?n.set(c.index,{id:c.content_block.id,name:c.content_block.name,args:""}):c.type==="content_block_start"&&c.content_block?.type==="mcp_tool_use"?n.set(c.index,{id:c.content_block.id,name:c.content_block.name,args:"",server_name:c.content_block.server_name}):c.type==="content_block_start"&&c.content_block?.type==="tool_result"?i.push({type:"tool_result",tool_use_id:c.content_block.tool_use_id,content:c.content_block.content??""}):c.type==="content_block_start"&&c.content_block?.type==="mcp_tool_result"&&i.push({type:"mcp_tool_result",tool_use_id:c.content_block.tool_use_id,is_error:c.content_block.is_error??!1,content:c.content_block.content??[]}),c.type==="content_block_delta"&&c.delta?.type==="input_json_delta"){let u=n.get(c.index);u&&(u.args+=c.delta.partial_json||"")}if(c.type==="content_block_stop"&&n.has(c.index)){let{id:u,name:M,args:P,server_name:g}=n.get(c.index);g?i.push({type:"mcp_tool_use",id:u,name:M,server_name:g,input:JSON.parse(P||"{}")}):i.push({type:"tool_use",id:u,name:M,input:JSON.parse(P||"{}")}),n.delete(c.index)}}}return{blocks:i,stop_reason:i.some(l=>l.type==="tool_use"||l.type==="mcp_tool_use")?"tool_use":"end"}}async parsePureStream(e,t){let{blocks:o}=await this.parseStream(e,t);return o.filter(s=>s.type==="text").map(s=>s.text).join("")}parseOneShot(e){let t=[];return(e.content??[]).forEach(o=>{o.type==="text"?t.push({type:"text",text:o.text}):o.type==="tool_use"?t.push({type:"tool_use",id:o.id,name:o.name,input:o.input??{}}):o.type==="mcp_tool_use"?t.push({type:"mcp_tool_use",id:o.id,name:o.name,server_name:o.server_name,input:o.input??{}}):o.type==="tool_result"?t.push({type:"tool_result",tool_use_id:o.tool_use_id,content:o.content??""}):o.type==="mcp_tool_result"&&t.push({type:"mcp_tool_result",tool_use_id:o.tool_use_id,is_error:o.is_error??!1,content:o.content??[]})}),{blocks:t,stop_reason:t.some(o=>o.type==="tool_use"||o.type==="mcp_tool_use")?"tool_use":"end"}}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callClaude(e,this.model,t,s),n=t?await this.parseStream(i,o):this.parseOneShot(await i.json());return this.convertToStandardCompletion(n)}async visionChatOnce(e,t=!1,o=()=>{},s){let i=await this.callClaude(e,this.visionModel,t,s),n=t?await this.parseStream(i,o):this.parseOneShot(await i.json());return this.convertToStandardCompletion(n)}convertToStandardCompletion(e){return{blocks:e.blocks.filter(o=>o.type==="text"||o.type==="tool_use"||o.type==="tool_result"),stop_reason:e.stop_reason}}};var le=class{createChatService(e){let t=E({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:o=>this.supportsVisionForModel(o),validate:"resolved"});return new ae(e.apiKey,e.model||this.getDefaultModel(),t,e.tools??[],e.mcpServers??[],e.responseLength)}getProviderName(){return"claude"}getSupportedModels(){return[Ge,ke,Fe,I,Ue,He,We,Ke,Ve]}getDefaultModel(){return I}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return Le.includes(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}};var Tt=class{static async fetchToolSchemas(e){try{let t={"Content-Type":"application/json"};e.authorization_token&&(t.Authorization=`Bearer ${e.authorization_token}`);let s=await(await _.post(`${e.url}/tools`,{},t)).json();return Array.isArray(s.tools)?s.tools.map(i=>({name:`mcp_${e.name}_${i.name}`,description:i.description||`Tool from ${e.name} MCP server`,parameters:i.inputSchema||{type:"object",properties:{},required:[]}})):[{name:`mcp_${e.name}_search`,description:`Search using ${e.name} MCP server`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}}]}catch(t){return console.warn(`Failed to fetch MCP schemas from ${e.name}:`,t),[{name:`mcp_${e.name}_search`,description:`Search using ${e.name} MCP server (schema fetch failed)`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}}]}}static async fetchAllToolSchemas(e){let t=[];for(let o of e)try{let s=await this.fetchToolSchemas(o);t.push(...s)}catch(s){console.error(`Failed to fetch schemas from ${o.name}:`,s)}return t}};var pe=class{constructor(e,t=q,o=q,s=[],i=[],n){this.provider="gemini";this.mcpToolSchemas=[];this.mcpSchemasInitialized=!1;this.callIdMap=new Map;if(this.apiKey=e,this.model=t,this.responseLength=n,!ye.includes(o))throw new Error(`Model ${o} does not support vision capabilities.`);this.visionModel=o,this.tools=s,this.mcpServers=i}safeJsonParse(e){try{return JSON.parse(e)}catch{return e}}normalizeToolResult(e){return e===null?{content:null}:typeof e=="object"?e:{content:e}}isGemma4Model(e){return/^gemma-4-/.test(e)}shouldExposeTextPart(e,t){return!(!e.text||this.isGemma4Model(t)&&e.thought===!0)}adaptKeysForApi(e){let t={toolConfig:"tool_config",functionCallingConfig:"function_calling_config",functionDeclarations:"function_declarations",functionCall:"function_call",functionResponse:"function_response"};return Array.isArray(e)?e.map(o=>this.adaptKeysForApi(o)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([o,s])=>[t[o]??o,this.adaptKeysForApi(s)])):e}getModel(){return this.model}getVisionModel(){return this.visionModel}getMCPServers(){return this.mcpServers}addMCPServer(e){this.mcpServers.push(e),this.mcpSchemasInitialized=!1}removeMCPServer(e){this.mcpServers=this.mcpServers.filter(t=>t.name!==e),this.mcpSchemasInitialized=!1}hasMCPServers(){return this.mcpServers.length>0}async initializeMCPSchemas(){if(!(this.mcpSchemasInitialized||this.mcpServers.length===0))try{let e=new Promise((o,s)=>setTimeout(()=>s(new Error("MCP schema fetch timeout")),5e3)),t=Tt.fetchAllToolSchemas(this.mcpServers);this.mcpToolSchemas=await Promise.race([t,e]),this.mcpSchemasInitialized=!0}catch(e){console.warn("Failed to initialize MCP schemas, using fallback:",e),this.mcpToolSchemas=this.mcpServers.map(t=>({name:`mcp_${t.name}_search`,description:`Search using ${t.name} MCP server (fallback)`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}})),this.mcpSchemasInitialized=!0}}async processChat(e,t,o){try{await f({hasTools:this.tools.length>0||this.mcpServers.length>0,runWithoutTools:async()=>{let s=await this.callGemini(e,this.model,!0),{blocks:i}=await this.parseStream(s,t,this.model);return v.getFullText(i)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"Received functionCall. Use chatOnce() loop when tools are enabled."})}catch(s){throw console.error("Error in processChat:",s),s}}async processVisionChat(e,t,o){try{await f({hasTools:this.tools.length>0||this.mcpServers.length>0,runWithoutTools:async()=>{let s=await this.callGemini(e,this.visionModel,!0),{blocks:i}=await this.parseStream(s,t,this.visionModel);return v.getFullText(i)},runWithTools:()=>this.visionChatOnce(e),onToolBlocks:s=>{s.filter(i=>i.type==="text").forEach(i=>t(i.text))},onCompleteResponse:o,toolErrorMessage:"Received functionCall. Use visionChatOnce() loop when tools are enabled."})}catch(s){throw console.error("Error in processVisionChat:",s),s}}convertMessagesToGeminiFormat(e){let t=[],o=null,s=[],i=()=>{o&&s.length&&(t.push({role:o,parts:[...s]}),s=[])};for(let n of e){let a=this.mapRoleToGemini(n.role);if(n.tool_calls){i();for(let l of n.tool_calls)this.callIdMap.set(l.id,l.function.name),t.push({role:"model",parts:[{functionCall:{name:l.function.name,args:JSON.parse(l.function.arguments||"{}")}}]});continue}if(n.role==="tool"){i();let l=n.name??this.callIdMap.get(n.tool_call_id)??"result";t.push({role:"user",parts:[{functionResponse:{name:l,response:this.normalizeToolResult(this.safeJsonParse(n.content))}}]});continue}a!==o&&i(),o=a,s.push({text:n.content})}return i(),t}async callGemini(e,t,o=!1,s){let a={contents:e.some(g=>Array.isArray(g.content)&&g.content.some(D=>D?.type==="image_url"||D?.inlineData))?await this.convertVisionMessagesToGeminiFormat(e):this.convertMessagesToGeminiFormat(e),generationConfig:{maxOutputTokens:s!==void 0?s:O(this.responseLength)}};this.isGemma4Model(t)&&(a.generationConfig.thinkingConfig={includeThoughts:!1,thinkingLevel:"minimal"});let l=[];if(this.tools.length>0&&l.push(...this.tools.map(g=>({name:g.name,description:g.description,parameters:g.parameters}))),this.mcpServers.length>0)try{await this.initializeMCPSchemas(),l.push(...this.mcpToolSchemas.map(g=>({name:g.name,description:g.description,parameters:g.parameters})))}catch(g){console.warn("MCP initialization failed, skipping MCP tools:",g)}l.length>0&&(a.tools=[{functionDeclarations:l}],a.toolConfig={functionCallingConfig:{mode:"AUTO"}});let h=async(g,D)=>{let N=o?"streamGenerateContent":"generateContent",eo=o?"?alt=sse":"",Ao=`${wt}/${g}/models/${t}:${N}${eo}${eo?"&":"?"}key=${this.apiKey}`;return _.post(Ao,D)},m=/flash[-_]lite/.test(t),p=this.isGemma4Model(t),d=/gemini-2\.5/.test(t),c=/^gemini-3(?:\.[0-9]+)?-.*preview/.test(t),u=m||p||d||c,M=u?"v1beta":"v1",P=async()=>{try{let g=M==="v1"?a:this.adaptKeysForApi(a);return await h(M,g)}catch(g){let D=/Unknown name|Cannot find field|404/.test(g?.message||"")||g?.status===404;if(!u&&D)return await h("v1beta",this.adaptKeysForApi(a));throw g}};try{return await P()}catch(g){throw g.body&&(console.error("Gemini API Error Details:",g.body),console.error("Request Body:",JSON.stringify(a,null,2))),g}}async convertVisionMessagesToGeminiFormat(e){let t=[],o=null,s=[];for(let i of e){let n=this.mapRoleToGemini(i.role);if(i.tool_calls){for(let a of i.tool_calls)t.push({role:"model",parts:[{functionCall:{name:a.function.name,args:JSON.parse(a.function.arguments||"{}")}}]});continue}if(i.role==="tool"){let a=i.name??this.callIdMap.get(i.tool_call_id)??"result";t.push({role:"user",parts:[{functionResponse:{name:a,response:this.normalizeToolResult(this.safeJsonParse(i.content))}}]});continue}if(n!==o&&s.length>0&&(t.push({role:o,parts:[...s]}),s=[]),o=n,typeof i.content=="string")s.push({text:i.content});else if(Array.isArray(i.content)){for(let a of i.content)if(a.type==="text")s.push({text:a.text});else if(a.type==="image_url")try{let h=await(await _.get(a.image_url.url)).blob(),m=await this.blobToBase64(h);s.push({inlineData:{mimeType:h.type||"image/jpeg",data:m.split(",")[1]}})}catch(l){throw console.error("Error processing image:",l),new Error(`Failed to process image: ${l.message}`)}}}return o&&s.length>0&&t.push({role:o,parts:[...s]}),t}blobToBase64(e){return new Promise((t,o)=>{let s=new FileReader;s.onloadend=()=>t(s.result),s.onerror=o,s.readAsDataURL(e)})}mapRoleToGemini(e){switch(e){case"system":return"model";case"user":return"user";case"assistant":return"model";default:return"user"}}async parseStream(e,t,o){let s=e.body.getReader(),i=new TextDecoder,n=[],a=[],l="",h=p=>{if(!p||p==="[DONE]")return;let d;try{d=JSON.parse(p)}catch{return}for(let c of d.candidates??[])for(let u of c.content?.parts??[])this.shouldExposeTextPart(u,o)&&(t(u.text),v.addTextBlock(n,u.text)),u.functionCall&&a.push({type:"tool_use",id:this.genUUID(),name:u.functionCall.name,input:u.functionCall.args??{}}),u.functionResponse&&a.push({type:"tool_result",tool_use_id:u.functionResponse.name,content:JSON.stringify(u.functionResponse.response)})};for(;;){let{done:p,value:d}=await s.read();if(p)break;l+=i.decode(d,{stream:!0});let c;for(;(c=l.indexOf(`
|
|
13
|
+
`))!==-1;){let u=l.slice(0,c);if(l=l.slice(c+1),u.endsWith("\r")&&(u=u.slice(0,-1)),!u.trim()){h("");continue}u.startsWith("data:")&&(u=u.slice(5).trim()),u&&h(u)}}return l&&h(l),{blocks:[...n,...a],stop_reason:a.some(p=>p.type==="tool_use")?"tool_use":"end"}}parseOneShot(e,t){let o=[],s=[];for(let n of e.candidates??[])for(let a of n.content?.parts??[])this.shouldExposeTextPart(a,t)&&o.push({type:"text",text:a.text}),a.functionCall&&s.push({type:"tool_use",id:this.genUUID(),name:a.functionCall.name,input:a.functionCall.args??{}}),a.functionResponse&&s.push({type:"tool_result",tool_use_id:a.functionResponse.name,content:JSON.stringify(a.functionResponse.response)});return{blocks:[...o,...s],stop_reason:s.some(n=>n.type==="tool_use")?"tool_use":"end"}}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callGemini(e,this.model,t,s);return t?this.parseStream(i,o,this.model):this.parseOneShot(await i.json(),this.model)}async visionChatOnce(e,t=!1,o=()=>{},s){let i=await this.callGemini(e,this.visionModel,t,s);return t?this.parseStream(i,o,this.visionModel):this.parseOneShot(await i.json(),this.visionModel)}genUUID(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}};var ce=class{createChatService(e){let t=E({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:o=>this.supportsVisionForModel(o),validate:"resolved"});return new pe(e.apiKey,e.model||this.getDefaultModel(),t,e.tools||[],e.mcpServers||[],e.responseLength)}getProviderName(){return"gemini"}getSupportedModels(){return[...we]}getDefaultModel(){return q}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return ye.includes(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}};function rs(){if(typeof globalThis<"u"&&"LanguageModel"in globalThis)return globalThis.LanguageModel}var ue=class{constructor(e={}){this.provider="gemini-nano";this.expectedInputLanguages=e.expectedInputLanguages??["ja"],this.expectedOutputLanguages=e.expectedOutputLanguages??["ja"],this._responseLength=e.responseLength}getModel(){return J}getVisionModel(){return J}async processChat(e,t,o){let s=await this.generateResponse(e);t(s),await o(s)}async processVisionChat(e,t,o){throw new Error("Gemini Nano does not support vision capabilities.")}async chatOnce(e,t=!1,o=()=>{},s){let i=await this.generateResponse(e);return o(i),{blocks:[{type:"text",text:i}],stop_reason:"end"}}async visionChatOnce(e,t=!1,o=()=>{},s){throw new Error("Gemini Nano does not support vision capabilities.")}async generateResponse(e){let t=rs();if(!t)throw new Error("Gemini Nano is not available in this environment. Chrome 138+ with Prompt API enabled is required.");let o=await t.availability();if(o!=="available"&&o!=="downloadable")throw new Error(`Gemini Nano Prompt API is not ready in this environment. LanguageModel.availability() returned "${o}". Expected "available" or "downloadable".`);let i=e.filter(h=>h.role==="system").map(h=>h.content).join(`
|
|
14
14
|
`),n=e.filter(h=>h.role!=="system").slice(-20),a=[...n].reverse().find(h=>h.role==="user");if(!a)throw new Error("No user message found in the provided messages.");let l=await this.createSession(t,i,n);try{return await l.prompt(a.content)}finally{try{l.destroy()}catch{}}}async createSession(e,t,o){let s=this.buildSystemPrompt(t),i=o.slice(0,-1);if(i.length>0){let n=i.map(a=>`${a.role==="user"?"User":"Assistant"}: ${a.content}`).join(`
|
|
15
15
|
`);s+=`
|
|
16
16
|
|
|
17
17
|
The following is the prior conversation history. Use it as context for your response:
|
|
18
18
|
`+n}return e.create({systemPrompt:s,expectedInputs:[{type:"text",languages:this.expectedInputLanguages}],expectedOutputs:[{type:"text",languages:this.expectedOutputLanguages}]})}buildSystemPrompt(e){let t=[];e&&t.push(e);let o=this.getResponseLengthInstruction();return o&&t.push(o),t.join(`
|
|
19
19
|
|
|
20
|
-
`)}getResponseLengthInstruction(){if(!this._responseLength)return;let e=
|
|
21
|
-
`);h=M.pop()||"";for(let P=0;P<M.length;P++){let g=M[P].trim();if(g.startsWith("event:"))c=g.slice(6).trim();else if(g.startsWith("data:"))u=g.slice(5).trim();else if(g===""&&c&&u){try{let D=JSON.parse(u);ss(c,D,e,s,i,N=>{N.responseStatus!==void 0&&(n=N.responseStatus),N.incompleteDetails!==void 0&&(a=N.incompleteDetails),N.usage!==void 0&&(l=N.usage)})}catch{console.warn("Failed to parse SSE data:",u)}c="",u=""}}}let m=Array.from(i.values()).map(p=>({type:"tool_use",id:p.id,name:p.name,input:p.input||{}}));return{blocks:[...s,...m],stop_reason:m.length?"tool_use":"end",truncated:n==="incomplete",response_status:n,incomplete_details:a,usage:l}}function ss(r,e,t,o,s,i){switch(r){case"response.output_item.added":e.item?.type==="message"&&Array.isArray(e.item.content)?e.item.content.forEach(n=>{n.type==="output_text"&&n.text&&(t(n.text),v.append(o,n.text))}):e.item?.type==="function_call"&&s.set(e.item.id,{id:e.item.id,name:e.item.name,input:e.item.arguments?JSON.parse(e.item.arguments):{}});break;case"response.content_part.added":e.part?.type==="output_text"&&typeof e.part.text=="string"&&(t(e.part.text),v.append(o,e.part.text));break;case"response.output_text.delta":case"response.content_part.delta":{let n=typeof e.delta=="string"?e.delta:e.delta?.text??"";n&&(t(n),v.append(o,n));break}case"response.output_text.done":case"response.content_part.done":case"response.reasoning.started":case"response.reasoning.delta":case"response.reasoning.done":break;case"response.completed":i(Co(e,"completed"));break;case"response.incomplete":i(Co(e,"incomplete"));break;default:break}}function Co(r,e){let t=r?.response??r;return{responseStatus:t?.status??e,incompleteDetails:t?.incomplete_details??null,usage:t?.usage}}function To(r){let e=[];return r.output&&Array.isArray(r.output)&&r.output.forEach(t=>{t.type==="message"&&t.content&&t.content.forEach(o=>{o.type==="output_text"&&o.text&&e.push({type:"text",text:o.text})}),t.type==="function_call"&&e.push({type:"tool_use",id:t.id,name:t.name,input:t.arguments?JSON.parse(t.arguments):{}})}),{blocks:e,stop_reason:e.some(t=>t.type==="tool_use")?"tool_use":"end",truncated:r?.status==="incomplete",response_status:r?.status,incomplete_details:r?.incomplete_details??null,usage:r?.usage}}var is={[S.VERY_SHORT]:800,[S.SHORT]:1200,[S.MEDIUM]:2e3,[S.LONG]:3e3,[S.VERY_LONG]:8e3,[S.DEEP]:25e3},rs={none:1200,minimal:1600,low:2500,medium:4e3,high:8e3,xhigh:12e3},H=class{constructor(e,t=j,o=j,s,i=Z,n=[],a,l,h,m=!1,p="openai",d=!0){if(this.provider=p,this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.mcpServers=n,this.responseLength=a,this.verbosity=l,this.reasoning_effort=h,this.enableReasoningSummary=m,d&&!Te.includes(o))throw new Error(`Model ${o} does not support vision capabilities.`);this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async processChat(e,t,o){await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callOpenAI(e,this.model,!0),i=this.endpoint===I;try{if(i){let n=await wt(s,t);return v.getFullText(n.blocks)}return this.handleStream(s,t)}catch(n){throw console.error("[processChat] Error in streaming/completion:",n),n}},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){try{await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callOpenAI(e,this.visionModel,!0),i=this.endpoint===I;try{if(i){let n=await wt(s,t);return v.getFullText(n.blocks)}return this.handleStream(s,t)}catch(n){throw console.error("[processVisionChat] Error in streaming/completion:",n),n}},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}catch(s){throw console.error("Error in processVisionChat:",s),s}}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callOpenAI(e,this.model,t,s);return this.parseResponse(i,t,o)}async visionChatOnce(e,t=!1,o=()=>{},s){let i=await this.callOpenAI(e,this.visionModel,t,s);return this.parseResponse(i,t,o)}async parseResponse(e,t,o){return this.endpoint===I?t?wt(e,o):To(await e.json()):t?this.parseStream(e,o):this.parseOneShot(await e.json())}async callOpenAI(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s),n={};return(this.provider!=="openai-compatible"||this.apiKey.trim()!=="")&&(n.Authorization=`Bearer ${this.apiKey}`),await _.post(this.endpoint,i,n)}buildRequestBody(e,t,o,s){let i=this.endpoint===I;this.validateMCPCompatibility();let n={model:t,stream:o},a=this.resolveTokenLimit(t,s);i?a!==void 0&&(n.max_output_tokens=a):a!==void 0&&(this.provider==="openai-compatible"?n.max_tokens=a:n.max_completion_tokens=a),i?n.input=this.cleanMessagesForResponsesAPI(e):n.messages=e,q(t)&&(i?(this.reasoning_effort&&(n.reasoning={...n.reasoning,effort:this.reasoning_effort},this.enableReasoningSummary&&(n.reasoning.summary="auto")),this.verbosity&&(n.text={...n.text,format:{type:"text"},verbosity:this.verbosity})):(this.reasoning_effort&&(n.reasoning_effort=this.reasoning_effort),this.verbosity&&(n.verbosity=this.verbosity)));let l=this.buildToolsDefinition();return l.length>0&&(n.tools=l,i||(n.tool_choice="auto")),n}resolveTokenLimit(e,t){if(t!==void 0)return t;let o=this.provider==="openai-compatible"?this.responseLength!==void 0?O(this.responseLength):void 0:O(this.responseLength);if(this.provider!=="openai"||!q(e)||this.responseLength===void 0)return o;let s=this.reasoning_effort??A(e);return Math.max(o??0,is[this.responseLength],rs[s])}validateMCPCompatibility(){if(this.mcpServers.length>0&&this.endpoint===Z)throw new Error(`MCP servers are not supported with Chat Completions API. Current endpoint: ${this.endpoint}. Please use OpenAI Responses API endpoint: ${I}. MCP tools are only available in the Responses API endpoint.`)}cleanMessagesForResponsesAPI(e){return e.map(t=>{let s={role:t.role==="tool"?"user":t.role};return typeof t.content=="string"?s.content=t.content:Array.isArray(t.content)?s.content=t.content.map(i=>i.type==="text"?{type:"input_text",text:i.text}:i.type==="image_url"?{type:"input_image",image_url:i.image_url.url}:i):s.content=t.content,s})}buildToolsDefinition(){let e=this.endpoint===I,t=[];return this.tools.length>0&&t.push(...L(this.tools,e?"responses":"chat-completions")),this.mcpServers.length>0&&e&&t.push(...this.buildMCPToolsDefinition()),t}buildMCPToolsDefinition(){return this.mcpServers.map(e=>{let t={type:"mcp",server_label:e.name,server_url:e.url};return e.require_approval&&(t.require_approval=e.require_approval),e.tool_configuration?.allowed_tools&&(t.allowed_tools=e.tool_configuration.allowed_tools),e.authorization_token&&(t.headers={Authorization:`Bearer ${e.authorization_token}`}),t})}async handleStream(e,t){return C(e,t)}async parseStream(e,t){return T(e,t,{appendTextBlock:v.addTextBlock})}parseOneShot(e){return y(e)}};var ge=class{createChatService(e){return this.validateRequiredOptions(e),new H(e.apiKey?.trim()??"",e.model,e.visionModel??e.model,e.tools,e.endpoint,[],e.responseLength,e.verbosity,e.reasoning_effort,e.enableReasoningSummary,this.getProviderName(),!1)}getProviderName(){return"openai-compatible"}getSupportedModels(){return[]}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"unknown"}supportsVisionForModel(e){return!0}getVisionSupportLevelForModel(e){return"unknown"}getDefaultModel(){return"local-model"}validateRequiredOptions(e){if(e.mcpServers!==void 0)throw new Error("openai-compatible provider does not support mcpServers.");let t=e.endpoint?.trim();if(!t)throw new Error("openai-compatible provider requires endpoint (full URL).");let o;try{o=new URL(t)}catch{throw new Error("openai-compatible provider requires endpoint to be a full URL.")}if(o.protocol!=="http:"&&o.protocol!=="https:")throw new Error("openai-compatible provider requires endpoint to be a full URL.");if(!e.model?.trim())throw new Error("openai-compatible provider requires model.")}};var _e=class{createChatService(e){let t=this.optimizeGPT5Options(e),o=E({model:t.model,visionModel:t.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:h=>this.supportsVisionForModel(h),validate:"resolved"}),s=t.tools,i=t.mcpServers??[],n=t.model||this.getDefaultModel(),a=!1;i.length>0||Ut(n)?a=!0:q(n)&&(a=(t.gpt5EndpointPreference||"chat")==="responses");let l=t.endpoint||(a?I:Z);return new H(t.apiKey,n,o,s,l,i,t.responseLength,t.verbosity,t.reasoning_effort,t.enableReasoningSummary,this.getProviderName())}getProviderName(){return"openai"}getSupportedModels(){return[W,Y,Q,B,w,V,K,$,G,Re,be,De,j,Ne,Gt,kt,"o1"]}getDefaultModel(){return W}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return Te.includes(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}optimizeGPT5Options(e){let t=e.model||this.getDefaultModel();if(!q(t))return e;let o={...e};if(e.gpt5Preset){let s=no[e.gpt5Preset];o.reasoning_effort=s.reasoning_effort,o.verbosity=s.verbosity}else e.reasoning_effort||(o.reasoning_effort=A(t));return o.reasoning_effort=this.normalizeReasoningEffort(t,o.reasoning_effort),o}normalizeReasoningEffort(e,t){if(t)return t==="none"&&!Wt(e)?A(e):t==="minimal"&&!Bt(e)?A(e):t==="low"&&!Kt(e)?A(e):t==="xhigh"&&!Ht(e)?A(e):t}};var fe=class{constructor(e,t=F,o=F,s,i=Pe,n,a,l,h,m,p){this.provider="openrouter";this.lastRequestTime=0;this.requestCount=0;this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=n,this.appName=a,this.appUrl=l,this.reasoning_effort=h,this.includeReasoning=m,this.reasoningMaxTokens=p,this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async applyRateLimiting(){if(!z(this.model))return;let e=Date.now(),t=e-this.lastRequestTime;if(t>6e4&&(this.requestCount=0),this.requestCount>=Yt){let o=6e4-t;o>0&&(console.log(`Rate limit reached for free tier. Waiting ${o}ms...`),await new Promise(s=>setTimeout(s,o)),this.requestCount=0)}this.lastRequestTime=e,this.requestCount++}async processChat(e,t,o){await this.applyRateLimiting(),await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callOpenRouter(e,this.model,!0);return this.handleStream(s,t)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){if(!ee(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await this.applyRateLimiting();try{await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callOpenRouter(e,this.visionModel,!0);return this.handleStream(s,t)},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}catch(s){throw console.error("Error in processVisionChat:",s),s}}async chatOnce(e,t=!0,o=()=>{},s){await this.applyRateLimiting();let i=await this.callOpenRouter(e,this.model,t,s);return t?this.parseStream(i,o):this.parseOneShot(await i.json())}async visionChatOnce(e,t=!1,o=()=>{},s){if(!ee(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await this.applyRateLimiting();let i=await this.callOpenRouter(e,this.visionModel,t,s);return t?this.parseStream(i,o):this.parseOneShot(await i.json())}async callOpenRouter(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s),n={Authorization:`Bearer ${this.apiKey}`};return this.appUrl&&(n["HTTP-Referer"]=this.appUrl),this.appName&&(n["X-Title"]=this.appName),await _.post(this.endpoint,i,n)}buildRequestBody(e,t,o,s){let i={model:t,messages:e,stream:o};if((s!==void 0?s:O(this.responseLength))&&console.warn("OpenRouter: Token limits are not supported for gpt-oss-20b model due to known issues. Using unlimited tokens instead."),this.reasoning_effort!==void 0||this.includeReasoning!==void 0||this.reasoningMaxTokens){if(i.reasoning={},this.reasoning_effort&&this.reasoning_effort!=="none"){let a=this.reasoning_effort==="minimal"?"low":this.reasoning_effort;i.reasoning.effort=a}(this.reasoning_effort==="none"||this.includeReasoning!==!0)&&(i.reasoning.exclude=!0),this.reasoningMaxTokens&&(i.reasoning.max_tokens=this.reasoningMaxTokens)}else i.reasoning={exclude:!0};return this.tools.length>0&&(i.tools=L(this.tools,"chat-completions"),i.tool_choice="auto"),i}async handleStream(e,t){return C(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return T(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return y(e)}};var ve=class{createChatService(e){let t=E({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:e.model||this.getDefaultModel(),supportsVisionForModel:n=>this.supportsVisionForModel(n),validate:"explicit"}),o=e.tools,s=e.appName,i=e.appUrl;return new fe(e.apiKey,e.model||this.getDefaultModel(),t,o,e.endpoint,e.responseLength,s,i,e.reasoning_effort,e.includeReasoning,e.reasoningMaxTokens)}getProviderName(){return"openrouter"}getSupportedModels(){return[qt,F,Tt,ot,st,it,rt,nt,at,lt,pt,ct,ut,ht,dt,mt,gt,_t,ft,zt,vt,Mt,Ot,Et,St,Ct,Xt,Jt,tt,et]}getDefaultModel(){return F}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return this.getSupportedModels().some(e=>this.supportsVisionForModel(e))?"supported":"unsupported"}supportsVisionForModel(e){return ee(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}getFreeModels(){return Zt}isModelFree(e){return z(e)}};var Me=class{constructor(e,t=R,o=R,s,i=xe,n){this.provider="xai";this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=n,this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async processChat(e,t,o){await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callXAI(e,this.model,!0);return this.handleStream(s,t)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){if(!se(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callXAI(e,this.visionModel,!0);return this.handleStream(s,t)},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callXAI(e,this.model,t,s);return this.parseResponse(i,t,o)}async visionChatOnce(e,t=!1,o=()=>{},s){if(!se(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);let i=await this.callXAI(e,this.visionModel,t,s);return this.parseResponse(i,t,o)}async parseResponse(e,t,o){return t?this.parseStream(e,o):this.parseOneShot(await e.json())}async callXAI(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s);return await _.post(this.endpoint,i,{Authorization:`Bearer ${this.apiKey}`})}buildRequestBody(e,t,o,s){let i={model:t,stream:o,messages:e},n=s!==void 0?s:O(this.responseLength);n!==void 0&&(i.max_tokens=n);let a=this.buildToolsDefinition();return a.length>0&&(i.tools=a,i.tool_choice="auto"),i}buildToolsDefinition(){return L(this.tools,"chat-completions")}async handleStream(e,t){return C(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return T(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return y(e)}};var Oe=class{createChatService(e){let t=e.model||this.getDefaultModel(),o=E({model:t,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultVisionModel(),supportsVisionForModel:i=>this.supportsVisionForModel(i),validate:"explicit"}),s=e.tools;return new Me(e.apiKey,t,o,s,e.endpoint||xe,e.responseLength)}getProviderName(){return"xai"}getSupportedModels(){return[Pt,It,xt,At,R]}getDefaultModel(){return R}getDefaultVisionModel(){return R}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return se(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}};var Ee=class{constructor(e,t=te,o=X,s,i=Ie,n,a,l){this.provider="zai";this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=n,this.responseFormat=a,this.thinking=l??{type:"disabled"},this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async processChat(e,t,o){await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callZAI(e,this.model,!0);return this.handleStream(s,t)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){if(!oe(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callZAI(e,this.visionModel,!0);return this.handleStream(s,t)},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callZAI(e,this.model,t,s);return this.parseResponse(i,t,o)}async visionChatOnce(e,t=!1,o=()=>{},s){if(!oe(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);let i=await this.callZAI(e,this.visionModel,t,s);return this.parseResponse(i,t,o)}async parseResponse(e,t,o){return t?this.parseStream(e,o):this.parseOneShot(await e.json())}async callZAI(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s);return await _.post(this.endpoint,i,{Authorization:`Bearer ${this.apiKey}`})}buildRequestBody(e,t,o,s){let i={model:t,stream:o,messages:e},n=s!==void 0?s:O(this.responseLength);n!==void 0&&(i.max_tokens=n),this.responseFormat&&(i.response_format=this.responseFormat),this.thinking&&(i.thinking=this.thinking);let a=this.buildToolsDefinition();return a.length>0&&(i.tools=a,i.tool_choice="auto",o&&io(t)&&(i.tool_stream=!0)),i}buildToolsDefinition(){return L(this.tools,"chat-completions")}async handleStream(e,t){return C(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return T(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return y(e)}};var Se=class{createChatService(e){let t=e.model||this.getDefaultModel(),o=E({model:t,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultVisionModel(),supportsVisionForModel:n=>this.supportsVisionForModel(n),validate:"explicit"}),s=e.tools,i=e.thinking??{type:"disabled"};return new Ee(e.apiKey,t,o,s,e.endpoint||Ie,e.responseLength,e.responseFormat,i)}getProviderName(){return"zai"}getSupportedModels(){return[Qt,eo,te,to,oo,so,yt,Lt,X]}getDefaultModel(){return te}getDefaultVisionModel(){return X}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return oe(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}};var yo=[new _e,new ge,new ce,new he,new le,new ve,new Se,new Oe,new me];var Ce=class{static registerProvider(e){this.providers.set(e.getProviderName(),e)}static createChatService(e,t){let o=this.providers.get(e);if(!o)throw new Error(`Unknown chat provider: ${e}`);return o.createChatService(t)}static getProviders(){return this.providers}static getAvailableProviders(){return Array.from(this.providers.keys())}static getSupportedModels(e){let t=this.providers.get(e);return t?t.getSupportedModels():[]}static getVisionSupportLevel(e){let t=this.providers.get(e);return t?t.getVisionSupportLevel():"unsupported"}static getVisionSupportLevelForModel(e,t){let o=this.providers.get(e);return o?o.getVisionSupportLevelForModel?o.getVisionSupportLevelForModel(t):o.supportsVisionForModel?o.supportsVisionForModel(t)?"supported":"unsupported":o.getVisionSupportLevel():"unsupported"}};Ce.providers=new Map;yo.forEach(r=>Ce.registerProvider(r));function Lo(){_.setFetch(async(r,e={})=>{let t=(e.method||"GET").toString().toUpperCase(),o=e.headers,s={};if(Array.isArray(o))for(let[p,d]of o)s[p]=String(d);else if(o&&typeof o=="object")for(let[p,d]of Object.entries(o))s[p]=String(d);let i={method:t,headers:s,muteHttpExceptions:!0},n=e.body;typeof n=="string"?i.payload=n:n!=null&&(s["Content-Type"]||(s["Content-Type"]="application/json"),i.payload=JSON.stringify(n));let a=UrlFetchApp.fetch(r,i),l=a.getResponseCode(),h=a.getContentText();return{ok:l>=200&&l<300,status:l,statusText:String(l),text:async()=>h,json:async()=>h?JSON.parse(h):null}})}return Do(ns);})();
|
|
20
|
+
`)}getResponseLengthInstruction(){if(!this._responseLength)return;let e=Ct[this._responseLength];if(e)return`Please keep your response concise, within approximately ${e} tokens.`}};var he=class{createChatService(e){return new ue({expectedInputLanguages:e.expectedInputLanguages,expectedOutputLanguages:e.expectedOutputLanguages,responseLength:e.responseLength})}getProviderName(){return"gemini-nano"}getSupportedModels(){return[J]}getDefaultModel(){return J}supportsVision(){return!1}getVisionSupportLevel(){return"unsupported"}};var de=class{constructor(e,t=b,o=b,s,i=ie,n,a,l){this.provider="kimi";this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=n,this.responseFormat=a,this.thinking=l??{type:"enabled"},this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async processChat(e,t,o){await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callKimi(e,this.model,!0);return this.handleStream(s,t)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){if(!re(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callKimi(e,this.visionModel,!0);return this.handleStream(s,t)},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callKimi(e,this.model,t,s);return this.parseResponse(i,t,o)}async visionChatOnce(e,t=!1,o=()=>{},s){if(!re(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);let i=await this.callKimi(e,this.visionModel,t,s);return this.parseResponse(i,t,o)}async parseResponse(e,t,o){return t?this.parseStream(e,o):this.parseOneShot(await e.json())}async callKimi(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s);return await _.post(this.endpoint,i,{Authorization:`Bearer ${this.apiKey}`})}buildRequestBody(e,t,o,s){let i={model:t,stream:o,messages:e},n=s!==void 0?s:O(this.responseLength);n!==void 0&&(i.max_tokens=n),this.responseFormat&&(i.response_format=this.responseFormat);let a=this.tools.length>0?{type:"disabled"}:this.thinking;a&&(this.isSelfHostedEndpoint()?a.type==="disabled"&&(i.chat_template_kwargs={thinking:!1}):i.thinking=a);let l=this.buildToolsDefinition();return l.length>0&&(i.tools=l,i.tool_choice="auto"),i}isSelfHostedEndpoint(){return this.normalizeEndpoint(this.endpoint)!==this.normalizeEndpoint(ie)}normalizeEndpoint(e){return e.replace(/\/+$/,"")}buildToolsDefinition(){return L(this.tools,"chat-completions")}async handleStream(e,t){return S(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return T(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return y(e)}};var me=class{createChatService(e){let t=this.resolveEndpoint(e),o=e.model||this.getDefaultModel(),s=E({model:o,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultVisionModel(),supportsVisionForModel:l=>this.supportsVisionForModel(l),validate:"explicit"}),i=e.tools,n=e.thinking??{type:"enabled"},a=i&&i.length>0?{type:"disabled"}:n;return new de(e.apiKey,o,s,i,t,e.responseLength,e.responseFormat,a)}getProviderName(){return"kimi"}getSupportedModels(){return[b,Et]}getDefaultModel(){return b}getDefaultVisionModel(){return b}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return re(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}resolveEndpoint(e){if(e.endpoint)return this.normalizeEndpoint(e.endpoint);if(e.baseUrl){let t=this.normalizeEndpoint(e.baseUrl);return t.endsWith("/chat/completions")?t:`${t}/chat/completions`}return ie}normalizeEndpoint(e){return e.replace(/\/+$/,"")}};async function yt(r,e){let t=r.body.getReader(),o=new TextDecoder,s=[],i=new Map,n,a,l,h="";for(;;){let{done:p,value:d}=await t.read();if(p)break;h+=o.decode(d,{stream:!0});let c="",u="",M=h.split(`
|
|
21
|
+
`);h=M.pop()||"";for(let P=0;P<M.length;P++){let g=M[P].trim();if(g.startsWith("event:"))c=g.slice(6).trim();else if(g.startsWith("data:"))u=g.slice(5).trim();else if(g===""&&c&&u){try{let D=JSON.parse(u);ns(c,D,e,s,i,N=>{N.responseStatus!==void 0&&(n=N.responseStatus),N.incompleteDetails!==void 0&&(a=N.incompleteDetails),N.usage!==void 0&&(l=N.usage)})}catch{console.warn("Failed to parse SSE data:",u)}c="",u=""}}}let m=Array.from(i.values()).map(p=>({type:"tool_use",id:p.id,name:p.name,input:p.input||{}}));return{blocks:[...s,...m],stop_reason:m.length?"tool_use":"end",truncated:n==="incomplete",response_status:n,incomplete_details:a,usage:l}}function ns(r,e,t,o,s,i){switch(r){case"response.output_item.added":e.item?.type==="message"&&Array.isArray(e.item.content)?e.item.content.forEach(n=>{n.type==="output_text"&&n.text&&(t(n.text),v.append(o,n.text))}):e.item?.type==="function_call"&&s.set(e.item.id,{id:e.item.id,name:e.item.name,input:e.item.arguments?JSON.parse(e.item.arguments):{}});break;case"response.content_part.added":e.part?.type==="output_text"&&typeof e.part.text=="string"&&(t(e.part.text),v.append(o,e.part.text));break;case"response.output_text.delta":case"response.content_part.delta":{let n=typeof e.delta=="string"?e.delta:e.delta?.text??"";n&&(t(n),v.append(o,n));break}case"response.output_text.done":case"response.content_part.done":case"response.reasoning.started":case"response.reasoning.delta":case"response.reasoning.done":break;case"response.completed":i(Lo(e,"completed"));break;case"response.incomplete":i(Lo(e,"incomplete"));break;default:break}}function Lo(r,e){let t=r?.response??r;return{responseStatus:t?.status??e,incompleteDetails:t?.incomplete_details??null,usage:t?.usage}}function Po(r){let e=[];return r.output&&Array.isArray(r.output)&&r.output.forEach(t=>{t.type==="message"&&t.content&&t.content.forEach(o=>{o.type==="output_text"&&o.text&&e.push({type:"text",text:o.text})}),t.type==="function_call"&&e.push({type:"tool_use",id:t.id,name:t.name,input:t.arguments?JSON.parse(t.arguments):{}})}),{blocks:e,stop_reason:e.some(t=>t.type==="tool_use")?"tool_use":"end",truncated:r?.status==="incomplete",response_status:r?.status,incomplete_details:r?.incomplete_details??null,usage:r?.usage}}var as={[C.VERY_SHORT]:800,[C.SHORT]:1200,[C.MEDIUM]:2e3,[C.LONG]:3e3,[C.VERY_LONG]:8e3,[C.DEEP]:25e3},ls={none:1200,minimal:1600,low:2500,medium:4e3,high:8e3,xhigh:12e3},U=class{constructor(e,t=$,o=$,s,i=Z,n=[],a,l,h,m=!1,p="openai",d=!0){if(this.provider=p,this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.mcpServers=n,this.responseLength=a,this.verbosity=l,this.reasoning_effort=h,this.enableReasoningSummary=m,d&&!Te.includes(o))throw new Error(`Model ${o} does not support vision capabilities.`);this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async processChat(e,t,o){await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callOpenAI(e,this.model,!0),i=this.endpoint===x;try{if(i){let n=await yt(s,t);return v.getFullText(n.blocks)}return this.handleStream(s,t)}catch(n){throw console.error("[processChat] Error in streaming/completion:",n),n}},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){try{await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callOpenAI(e,this.visionModel,!0),i=this.endpoint===x;try{if(i){let n=await yt(s,t);return v.getFullText(n.blocks)}return this.handleStream(s,t)}catch(n){throw console.error("[processVisionChat] Error in streaming/completion:",n),n}},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}catch(s){throw console.error("Error in processVisionChat:",s),s}}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callOpenAI(e,this.model,t,s);return this.parseResponse(i,t,o)}async visionChatOnce(e,t=!1,o=()=>{},s){let i=await this.callOpenAI(e,this.visionModel,t,s);return this.parseResponse(i,t,o)}async parseResponse(e,t,o){return this.endpoint===x?t?yt(e,o):Po(await e.json()):t?this.parseStream(e,o):this.parseOneShot(await e.json())}async callOpenAI(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s),n={};return(this.provider!=="openai-compatible"||this.apiKey.trim()!=="")&&(n.Authorization=`Bearer ${this.apiKey}`),await _.post(this.endpoint,i,n)}buildRequestBody(e,t,o,s){let i=this.endpoint===x;this.validateMCPCompatibility();let n={model:t,stream:o},a=this.resolveTokenLimit(t,s);i?a!==void 0&&(n.max_output_tokens=a):a!==void 0&&(this.provider==="openai-compatible"?n.max_tokens=a:n.max_completion_tokens=a),i?n.input=this.cleanMessagesForResponsesAPI(e):n.messages=e,j(t)&&(i?(this.reasoning_effort&&(n.reasoning={...n.reasoning,effort:this.reasoning_effort},this.enableReasoningSummary&&(n.reasoning.summary="auto")),this.verbosity&&(n.text={...n.text,format:{type:"text"},verbosity:this.verbosity})):(this.reasoning_effort&&(n.reasoning_effort=this.reasoning_effort),this.verbosity&&(n.verbosity=this.verbosity)));let l=this.buildToolsDefinition();return l.length>0&&(n.tools=l,i||(n.tool_choice="auto")),n}resolveTokenLimit(e,t){if(t!==void 0)return t;let o=this.provider==="openai-compatible"?this.responseLength!==void 0?O(this.responseLength):void 0:O(this.responseLength);if(this.provider!=="openai"||!j(e)||this.responseLength===void 0)return o;let s=this.reasoning_effort??A(e);return Math.max(o??0,as[this.responseLength],ls[s])}validateMCPCompatibility(){if(this.mcpServers.length>0&&this.endpoint===Z)throw new Error(`MCP servers are not supported with Chat Completions API. Current endpoint: ${this.endpoint}. Please use OpenAI Responses API endpoint: ${x}. MCP tools are only available in the Responses API endpoint.`)}cleanMessagesForResponsesAPI(e){return e.map(t=>{let s={role:t.role==="tool"?"user":t.role};return typeof t.content=="string"?s.content=t.content:Array.isArray(t.content)?s.content=t.content.map(i=>i.type==="text"?{type:"input_text",text:i.text}:i.type==="image_url"?{type:"input_image",image_url:i.image_url.url}:i):s.content=t.content,s})}buildToolsDefinition(){let e=this.endpoint===x,t=[];return this.tools.length>0&&t.push(...L(this.tools,e?"responses":"chat-completions")),this.mcpServers.length>0&&e&&t.push(...this.buildMCPToolsDefinition()),t}buildMCPToolsDefinition(){return this.mcpServers.map(e=>{let t={type:"mcp",server_label:e.name,server_url:e.url};return e.require_approval&&(t.require_approval=e.require_approval),e.tool_configuration?.allowed_tools&&(t.allowed_tools=e.tool_configuration.allowed_tools),e.authorization_token&&(t.headers={Authorization:`Bearer ${e.authorization_token}`}),t})}async handleStream(e,t){return S(e,t)}async parseStream(e,t){return T(e,t,{appendTextBlock:v.addTextBlock})}parseOneShot(e){return y(e)}};var ge=class{createChatService(e){return this.validateRequiredOptions(e),new U(e.apiKey?.trim()??"",e.model,e.visionModel??e.model,e.tools,e.endpoint,[],e.responseLength,e.verbosity,e.reasoning_effort,e.enableReasoningSummary,this.getProviderName(),!1)}getProviderName(){return"openai-compatible"}getSupportedModels(){return[]}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"unknown"}supportsVisionForModel(e){return!0}getVisionSupportLevelForModel(e){return"unknown"}getDefaultModel(){return"local-model"}validateRequiredOptions(e){if(e.mcpServers!==void 0)throw new Error("openai-compatible provider does not support mcpServers.");let t=e.endpoint?.trim();if(!t)throw new Error("openai-compatible provider requires endpoint (full URL).");let o;try{o=new URL(t)}catch{throw new Error("openai-compatible provider requires endpoint to be a full URL.")}if(o.protocol!=="http:"&&o.protocol!=="https:")throw new Error("openai-compatible provider requires endpoint to be a full URL.");if(!e.model?.trim())throw new Error("openai-compatible provider requires model.")}};var _e=class{createChatService(e){let t=this.optimizeGPT5Options(e),o=E({model:t.model,visionModel:t.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:h=>this.supportsVisionForModel(h),validate:"resolved"}),s=t.tools,i=t.mcpServers??[],n=t.model||this.getDefaultModel(),a=!1;i.length>0||At(n)?a=!0:j(n)&&(a=(t.gpt5EndpointPreference||"chat")==="responses");let l=t.endpoint||(a?x:Z);return new U(t.apiKey,n,o,s,l,i,t.responseLength,t.verbosity,t.reasoning_effort,t.enableReasoningSummary,this.getProviderName())}getProviderName(){return"openai"}getSupportedModels(){return[H,Y,Q,W,w,V,K,B,G,Re,be,De,$,Ne,Pt,xt,"o1"]}getDefaultModel(){return H}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return Te.includes(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}optimizeGPT5Options(e){let t=e.model||this.getDefaultModel();if(!j(t))return e;let o={...e};if(e.gpt5Preset){let s=Jt[e.gpt5Preset];o.reasoning_effort=s.reasoning_effort,o.verbosity=s.verbosity}else e.reasoning_effort||(o.reasoning_effort=A(t));return o.reasoning_effort=this.normalizeReasoningEffort(t,o.reasoning_effort),o}normalizeReasoningEffort(e,t){if(t)return t==="none"&&!bt(e)?A(e):t==="minimal"&&!Dt(e)?A(e):t==="low"&&!Nt(e)?A(e):t==="xhigh"&&!Rt(e)?A(e):t}};var fe=class{constructor(e,t=k,o=k,s,i=Pe,n,a,l,h,m,p){this.provider="openrouter";this.lastRequestTime=0;this.requestCount=0;this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=n,this.appName=a,this.appUrl=l,this.reasoning_effort=h,this.includeReasoning=m,this.reasoningMaxTokens=p,this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async applyRateLimiting(){if(!z(this.model))return;let e=Date.now(),t=e-this.lastRequestTime;if(t>6e4&&(this.requestCount=0),this.requestCount>=Wt){let o=6e4-t;o>0&&(console.log(`Rate limit reached for free tier. Waiting ${o}ms...`),await new Promise(s=>setTimeout(s,o)),this.requestCount=0)}this.lastRequestTime=e,this.requestCount++}async processChat(e,t,o){await this.applyRateLimiting(),await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callOpenRouter(e,this.model,!0);return this.handleStream(s,t)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){if(!ee(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await this.applyRateLimiting();try{await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callOpenRouter(e,this.visionModel,!0);return this.handleStream(s,t)},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}catch(s){throw console.error("Error in processVisionChat:",s),s}}async chatOnce(e,t=!0,o=()=>{},s){await this.applyRateLimiting();let i=await this.callOpenRouter(e,this.model,t,s);return t?this.parseStream(i,o):this.parseOneShot(await i.json())}async visionChatOnce(e,t=!1,o=()=>{},s){if(!ee(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await this.applyRateLimiting();let i=await this.callOpenRouter(e,this.visionModel,t,s);return t?this.parseStream(i,o):this.parseOneShot(await i.json())}async callOpenRouter(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s),n={Authorization:`Bearer ${this.apiKey}`};return this.appUrl&&(n["HTTP-Referer"]=this.appUrl),this.appName&&(n["X-Title"]=this.appName),await _.post(this.endpoint,i,n)}buildRequestBody(e,t,o,s){let i={model:t,messages:e,stream:o};if((s!==void 0?s:O(this.responseLength))&&console.warn("OpenRouter: Token limits are not supported for gpt-oss-20b model due to known issues. Using unlimited tokens instead."),this.reasoning_effort!==void 0||this.includeReasoning!==void 0||this.reasoningMaxTokens){if(i.reasoning={},this.reasoning_effort&&this.reasoning_effort!=="none"){let a=this.reasoning_effort==="minimal"?"low":this.reasoning_effort;i.reasoning.effort=a}(this.reasoning_effort==="none"||this.includeReasoning!==!0)&&(i.reasoning.exclude=!0),this.reasoningMaxTokens&&(i.reasoning.max_tokens=this.reasoningMaxTokens)}else i.reasoning={exclude:!0};return this.tools.length>0&&(i.tools=L(this.tools,"chat-completions"),i.tool_choice="auto"),i}async handleStream(e,t){return S(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return T(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return y(e)}};var ve=class{createChatService(e){let t=E({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:e.model||this.getDefaultModel(),supportsVisionForModel:n=>this.supportsVisionForModel(n),validate:"explicit"}),o=e.tools,s=e.appName,i=e.appUrl;return new fe(e.apiKey,e.model||this.getDefaultModel(),t,o,e.endpoint,e.responseLength,s,i,e.reasoning_effort,e.includeReasoning,e.reasoningMaxTokens)}getProviderName(){return"openrouter"}getSupportedModels(){return[Gt,k,mt,je,qe,ze,Xe,Je,Ze,Ye,Qe,et,tt,ot,st,it,rt,nt,at,kt,lt,pt,ct,ut,ht,dt,Ft,Ut,$e,Be]}getDefaultModel(){return k}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return this.getSupportedModels().some(e=>this.supportsVisionForModel(e))?"supported":"unsupported"}supportsVisionForModel(e){return ee(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}getFreeModels(){return Ht}isModelFree(e){return z(e)}};var Me=class{constructor(e,t=R,o=R,s,i=Ie,n){this.provider="xai";this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=n,this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async processChat(e,t,o){await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callXAI(e,this.model,!0);return this.handleStream(s,t)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){if(!se(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callXAI(e,this.visionModel,!0);return this.handleStream(s,t)},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callXAI(e,this.model,t,s);return this.parseResponse(i,t,o)}async visionChatOnce(e,t=!1,o=()=>{},s){if(!se(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);let i=await this.callXAI(e,this.visionModel,t,s);return this.parseResponse(i,t,o)}async parseResponse(e,t,o){return t?this.parseStream(e,o):this.parseOneShot(await e.json())}async callXAI(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s);return await _.post(this.endpoint,i,{Authorization:`Bearer ${this.apiKey}`})}buildRequestBody(e,t,o,s){let i={model:t,stream:o,messages:e},n=s!==void 0?s:O(this.responseLength);n!==void 0&&(i.max_tokens=n);let a=this.buildToolsDefinition();return a.length>0&&(i.tools=a,i.tool_choice="auto"),i}buildToolsDefinition(){return L(this.tools,"chat-completions")}async handleStream(e,t){return S(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return T(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return y(e)}};var Oe=class{createChatService(e){let t=e.model||this.getDefaultModel(),o=E({model:t,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultVisionModel(),supportsVisionForModel:i=>this.supportsVisionForModel(i),validate:"explicit"}),s=e.tools;return new Me(e.apiKey,t,o,s,e.endpoint||Ie,e.responseLength)}getProviderName(){return"xai"}getSupportedModels(){return[ft,vt,Mt,Ot,R]}getDefaultModel(){return R}getDefaultVisionModel(){return R}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return se(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}};var Ee=class{constructor(e,t=te,o=X,s,i=xe,n,a,l){this.provider="zai";this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=n,this.responseFormat=a,this.thinking=l??{type:"disabled"},this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async processChat(e,t,o){await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callZAI(e,this.model,!0);return this.handleStream(s,t)},runWithTools:()=>this.chatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled."})}async processVisionChat(e,t,o){if(!oe(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);await f({hasTools:this.tools.length>0,runWithoutTools:async()=>{let s=await this.callZAI(e,this.visionModel,!0);return this.handleStream(s,t)},runWithTools:()=>this.visionChatOnce(e,!0,t),onCompleteResponse:o,toolErrorMessage:"processVisionChat received tool_calls. ChatProcessor must use visionChatOnce() loop when tools are enabled."})}async chatOnce(e,t=!0,o=()=>{},s){let i=await this.callZAI(e,this.model,t,s);return this.parseResponse(i,t,o)}async visionChatOnce(e,t=!1,o=()=>{},s){if(!oe(this.visionModel))throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);let i=await this.callZAI(e,this.visionModel,t,s);return this.parseResponse(i,t,o)}async parseResponse(e,t,o){return t?this.parseStream(e,o):this.parseOneShot(await e.json())}async callZAI(e,t,o=!1,s){let i=this.buildRequestBody(e,t,o,s);return await _.post(this.endpoint,i,{Authorization:`Bearer ${this.apiKey}`})}buildRequestBody(e,t,o,s){let i={model:t,stream:o,messages:e},n=s!==void 0?s:O(this.responseLength);n!==void 0&&(i.max_tokens=n),this.responseFormat&&(i.response_format=this.responseFormat),this.thinking&&(i.thinking=this.thinking);let a=this.buildToolsDefinition();return a.length>0&&(i.tools=a,i.tool_choice="auto",o&&zt(t)&&(i.tool_stream=!0)),i}buildToolsDefinition(){return L(this.tools,"chat-completions")}async handleStream(e,t){return S(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return T(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return y(e)}};var Ce=class{createChatService(e){let t=e.model||this.getDefaultModel(),o=E({model:t,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultVisionModel(),supportsVisionForModel:n=>this.supportsVisionForModel(n),validate:"explicit"}),s=e.tools,i=e.thinking??{type:"disabled"};return new Ee(e.apiKey,t,o,s,e.endpoint||xe,e.responseLength,e.responseFormat,i)}getProviderName(){return"zai"}getSupportedModels(){return[Kt,Bt,te,$t,jt,qt,gt,_t,X]}getDefaultModel(){return te}getDefaultVisionModel(){return X}supportsVision(){return this.getVisionSupportLevel()!=="unsupported"}getVisionSupportLevel(){return"supported"}supportsVisionForModel(e){return oe(e)}getVisionSupportLevelForModel(e){return this.supportsVisionForModel(e)?"supported":"unsupported"}};var xo=[new _e,new ge,new ce,new he,new le,new ve,new Ce,new Oe,new me];var Se=class{static registerProvider(e){this.providers.set(e.getProviderName(),e)}static createChatService(e,t){let o=this.providers.get(e);if(!o)throw new Error(`Unknown chat provider: ${e}`);return o.createChatService(t)}static getProviders(){return this.providers}static getAvailableProviders(){return Array.from(this.providers.keys())}static getSupportedModels(e){let t=this.providers.get(e);return t?t.getSupportedModels():[]}static getVisionSupportLevel(e){let t=this.providers.get(e);return t?t.getVisionSupportLevel():"unsupported"}static getVisionSupportLevelForModel(e,t){let o=this.providers.get(e);return o?o.getVisionSupportLevelForModel?o.getVisionSupportLevelForModel(t):o.supportsVisionForModel?o.supportsVisionForModel(t)?"supported":"unsupported":o.getVisionSupportLevel():"unsupported"}};Se.providers=new Map;xo.forEach(r=>Se.registerProvider(r));function Io(){_.setFetch(async(r,e={})=>{let t=(e.method||"GET").toString().toUpperCase(),o=e.headers,s={};if(Array.isArray(o))for(let[p,d]of o)s[p]=String(d);else if(o&&typeof o=="object")for(let[p,d]of Object.entries(o))s[p]=String(d);let i={method:t,headers:s,muteHttpExceptions:!0},n=e.body;typeof n=="string"?i.payload=n:n!=null&&(s["Content-Type"]||(s["Content-Type"]="application/json"),i.payload=JSON.stringify(n));let a=UrlFetchApp.fetch(r,i),l=a.getResponseCode(),h=a.getContentText();return{ok:l>=200&&l<300,status:l,statusText:String(l),text:async()=>h,json:async()=>h?JSON.parse(h):null}})}return Vo(ps);})();
|