@aituber-onair/chat 0.11.1 → 0.12.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 CHANGED
@@ -194,7 +194,7 @@ const openRouterService = ChatServiceFactory.createChatService('openrouter', {
194
194
  ```typescript
195
195
  const zaiService = ChatServiceFactory.createChatService('zai', {
196
196
  apiKey: process.env.ZAI_API_KEY,
197
- model: 'glm-4.7',
197
+ model: 'glm-5',
198
198
  visionModel: 'glm-4.6V-Flash', // 任意: ビジョン対応モデル
199
199
  responseFormat: { type: 'json_object' } // 任意: JSONモード
200
200
  });
@@ -202,6 +202,8 @@ const zaiService = ChatServiceFactory.createChatService('zai', {
202
202
 
203
203
  注意:
204
204
  - Z.aiはOpenAI互換のChat Completionsを利用します。
205
+ - テキスト対応モデル: `glm-5`, `glm-4.7`, `glm-4.7-FlashX`, `glm-4.7-Flash`, `glm-4.6`
206
+ - ビジョン対応モデル: `glm-4.6V`, `glm-4.6V-FlashX`, `glm-4.6V-Flash`
205
207
  - `thinking` はデフォルトで無効化しています。
206
208
 
207
209
  #### Kimi(Moonshot)
@@ -458,7 +460,7 @@ type ChatResponseLength = 'veryShort' | 'short' | 'medium' | 'long' | 'veryLong'
458
460
  - **Gemini**: Gemini 2.5 Pro, Gemini 2.5 Flash, Gemini 2.5 Flash Lite Preview, Gemini 2.0 Flash, Gemini 2.0 Flash-Liteのモデルをサポート
459
461
  - **Claude**: Claude Opus 4.6, Claude Opus 4.5, Claude Sonnet 4.5, Claude Haiku 4.5, Claude 4 Sonnet, Claude 4 Opus, Claude 3.7 Sonnet, Claude 3.5 Haiku/Sonnet, Claude 3 Haikuのモデルをサポート
460
462
  - **OpenRouter**: OpenRouterのキュレーション済みモデル一覧(OpenAI/Claude/Gemini/Z.ai/Kimi)をサポート。モデルIDはOpenRouter節を参照してください
461
- - **Z.ai**: GLM-4.7(Flash/FlashX含む)とGLM-4.6V-Flash(ビジョン)をサポート
463
+ - **Z.ai**: GLM-5(テキスト)、GLM-4.7/4.6(テキスト)、GLM-4.6V系(ビジョン)をサポート
462
464
  - **Kimi**: Kimi K2.5(`kimi-k2.5`、ビジョン対応)をサポート
463
465
 
464
466
  ## ライセンス
package/README.md CHANGED
@@ -194,7 +194,7 @@ const openRouterService = ChatServiceFactory.createChatService('openrouter', {
194
194
  ```typescript
195
195
  const zaiService = ChatServiceFactory.createChatService('zai', {
196
196
  apiKey: process.env.ZAI_API_KEY,
197
- model: 'glm-4.7',
197
+ model: 'glm-5',
198
198
  visionModel: 'glm-4.6V-Flash', // Optional: vision-capable model
199
199
  responseFormat: { type: 'json_object' } // Optional JSON mode
200
200
  });
@@ -202,6 +202,8 @@ const zaiService = ChatServiceFactory.createChatService('zai', {
202
202
 
203
203
  Notes:
204
204
  - Z.ai uses OpenAI-compatible Chat Completions.
205
+ - Supported text models: `glm-5`, `glm-4.7`, `glm-4.7-FlashX`, `glm-4.7-Flash`, `glm-4.6`
206
+ - Supported vision models: `glm-4.6V`, `glm-4.6V-FlashX`, `glm-4.6V-Flash`
205
207
  - `thinking` is disabled by default to match fast response behavior.
206
208
 
207
209
  #### Kimi (Moonshot)
@@ -458,7 +460,7 @@ Currently, the following AI providers are built-in:
458
460
  - **Gemini**: Supports models like Gemini 2.5 Pro, Gemini 2.5 Flash, Gemini 2.5 Flash Lite Preview, Gemini 2.0 Flash, Gemini 2.0 Flash-Lite
459
461
  - **Claude**: Supports models like Claude Opus 4.6, Claude Opus 4.5, Claude Sonnet 4.5, Claude Haiku 4.5, Claude 4 Sonnet, Claude 4 Opus, Claude 3.7 Sonnet, Claude 3.5 Haiku/Sonnet, Claude 3 Haiku
460
462
  - **OpenRouter**: Supports a curated OpenRouter model list (OpenAI/Claude/Gemini/Z.ai/Kimi). See the OpenRouter section for model IDs.
461
- - **Z.ai**: Supports GLM-4.7 (including Flash/FlashX) and GLM-4.6V-Flash (vision)
463
+ - **Z.ai**: Supports GLM-5 (text), GLM-4.7/4.6 (text), and GLM-4.6V family (vision)
462
464
  - **Kimi**: Supports Kimi K2.5 (`kimi-k2.5`) with vision support
463
465
 
464
466
  ## License
@@ -1,4 +1,5 @@
1
1
  export declare const ENDPOINT_ZAI_CHAT_COMPLETIONS_API = "https://api.z.ai/api/paas/v4/chat/completions";
2
+ export declare const MODEL_GLM_5 = "glm-5";
2
3
  export declare const MODEL_GLM_4_7 = "glm-4.7";
3
4
  export declare const MODEL_GLM_4_7_FLASHX = "glm-4.7-FlashX";
4
5
  export declare const MODEL_GLM_4_7_FLASH = "glm-4.7-Flash";
@@ -1 +1 @@
1
- {"version":3,"file":"zai.d.ts","sourceRoot":"","sources":["../../../src/constants/zai.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iCAAiC,kDACG,CAAC;AAGlD,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AACvD,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAGrD,eAAO,MAAM,2BAA2B,UAIvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE3D"}
1
+ {"version":3,"file":"zai.d.ts","sourceRoot":"","sources":["../../../src/constants/zai.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iCAAiC,kDACG,CAAC;AAGlD,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AACvD,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAGrD,eAAO,MAAM,2BAA2B,UAIvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE3D"}
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZAI_VISION_SUPPORTED_MODELS = exports.MODEL_GLM_4_6V_FLASH = exports.MODEL_GLM_4_6V_FLASHX = exports.MODEL_GLM_4_6V = exports.MODEL_GLM_4_6 = exports.MODEL_GLM_4_7_FLASH = exports.MODEL_GLM_4_7_FLASHX = exports.MODEL_GLM_4_7 = exports.ENDPOINT_ZAI_CHAT_COMPLETIONS_API = void 0;
3
+ exports.ZAI_VISION_SUPPORTED_MODELS = exports.MODEL_GLM_4_6V_FLASH = exports.MODEL_GLM_4_6V_FLASHX = exports.MODEL_GLM_4_6V = exports.MODEL_GLM_4_6 = exports.MODEL_GLM_4_7_FLASH = exports.MODEL_GLM_4_7_FLASHX = exports.MODEL_GLM_4_7 = exports.MODEL_GLM_5 = exports.ENDPOINT_ZAI_CHAT_COMPLETIONS_API = void 0;
4
4
  exports.isZaiVisionModel = isZaiVisionModel;
5
5
  exports.isZaiToolStreamModel = isZaiToolStreamModel;
6
6
  exports.ENDPOINT_ZAI_CHAT_COMPLETIONS_API = 'https://api.z.ai/api/paas/v4/chat/completions';
7
7
  // Z.ai GLM models
8
+ exports.MODEL_GLM_5 = 'glm-5';
8
9
  exports.MODEL_GLM_4_7 = 'glm-4.7';
9
10
  exports.MODEL_GLM_4_7_FLASHX = 'glm-4.7-FlashX';
10
11
  exports.MODEL_GLM_4_7_FLASH = 'glm-4.7-Flash';
@@ -1 +1 @@
1
- {"version":3,"file":"zai.js","sourceRoot":"","sources":["../../../src/constants/zai.ts"],"names":[],"mappings":";;;AAsBA,4CAEC;AAKD,oDAEC;AA/BY,QAAA,iCAAiC,GAC5C,+CAA+C,CAAC;AAElD,kBAAkB;AACL,QAAA,aAAa,GAAG,SAAS,CAAC;AAC1B,QAAA,oBAAoB,GAAG,gBAAgB,CAAC;AACxC,QAAA,mBAAmB,GAAG,eAAe,CAAC;AACtC,QAAA,aAAa,GAAG,SAAS,CAAC;AAC1B,QAAA,cAAc,GAAG,UAAU,CAAC;AAC5B,QAAA,qBAAqB,GAAG,iBAAiB,CAAC;AAC1C,QAAA,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,4BAA4B;AACf,QAAA,2BAA2B,GAAG;IACzC,sBAAc;IACd,6BAAqB;IACrB,4BAAoB;CACrB,CAAC;AAEF;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,OAAO,mCAA2B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,KAAa;IAChD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AACnD,CAAC"}
1
+ {"version":3,"file":"zai.js","sourceRoot":"","sources":["../../../src/constants/zai.ts"],"names":[],"mappings":";;;AAuBA,4CAEC;AAKD,oDAEC;AAhCY,QAAA,iCAAiC,GAC5C,+CAA+C,CAAC;AAElD,kBAAkB;AACL,QAAA,WAAW,GAAG,OAAO,CAAC;AACtB,QAAA,aAAa,GAAG,SAAS,CAAC;AAC1B,QAAA,oBAAoB,GAAG,gBAAgB,CAAC;AACxC,QAAA,mBAAmB,GAAG,eAAe,CAAC;AACtC,QAAA,aAAa,GAAG,SAAS,CAAC;AAC1B,QAAA,cAAc,GAAG,UAAU,CAAC;AAC5B,QAAA,qBAAqB,GAAG,iBAAiB,CAAC;AAC1C,QAAA,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,4BAA4B;AACf,QAAA,2BAA2B,GAAG;IACzC,sBAAc;IACd,6BAAqB;IACrB,4BAAoB;CACrB,CAAC;AAEF;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,OAAO,mCAA2B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,KAAa;IAChD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AACnD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ZAIChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/zai/ZAIChatServiceProvider.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAIhC;;GAEG;AACH,qBAAa,sBACX,YAAW,mBAAmB,CAAC,qBAAqB,CAAC;IAErD;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,WAAW;IA2B9D;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAY9B;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;OAEG;IACH,cAAc,IAAI,OAAO;IAIzB;;OAEG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAG/C"}
1
+ {"version":3,"file":"ZAIChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/zai/ZAIChatServiceProvider.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAIhC;;GAEG;AACH,qBAAa,sBACX,YAAW,mBAAmB,CAAC,qBAAqB,CAAC;IAErD;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,WAAW;IA2B9D;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAa9B;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;OAEG;IACH,cAAc,IAAI,OAAO;IAIzB;;OAEG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAG/C"}
@@ -36,6 +36,7 @@ class ZAIChatServiceProvider {
36
36
  */
37
37
  getSupportedModels() {
38
38
  return [
39
+ zai_1.MODEL_GLM_5,
39
40
  zai_1.MODEL_GLM_4_7,
40
41
  zai_1.MODEL_GLM_4_7_FLASHX,
41
42
  zai_1.MODEL_GLM_4_7_FLASH,
@@ -1 +1 @@
1
- {"version":3,"file":"ZAIChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/zai/ZAIChatServiceProvider.ts"],"names":[],"mappings":";;;AAAA,gDAUgC;AAEhC,qDAAkD;AAMlD,0CAAoD;AAEpD;;GAEG;AACH,MAAa,sBAAsB;IAGjC;;OAEG;IACH,iBAAiB,CAAC,OAA8B;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QACtD,MAAM,WAAW,GAAG,IAAA,0BAAkB,EAAC;YACrC,KAAK;YACL,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,kBAAkB,EAAE,IAAI,CAAC,qBAAqB,EAAE;YAChD,sBAAsB,EAAE,CAAC,WAAW,EAAE,EAAE,CACtC,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC;YAC1C,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QAEH,MAAM,KAAK,GAAiC,OAAO,CAAC,KAAK,CAAC;QAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,IAAI,EAAE,UAAmB,EAAE,CAAC;QAEnE,OAAO,IAAI,+BAAc,CACvB,OAAO,CAAC,MAAM,EACd,KAAK,EACL,WAAW,EACX,KAAK,EACL,OAAO,CAAC,QAAQ,IAAI,uCAAiC,EACrD,OAAO,CAAC,cAAc,EACtB,OAAO,CAAC,cAAc,EACtB,QAAQ,CACT,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO;YACL,mBAAa;YACb,0BAAoB;YACpB,yBAAmB;YACnB,mBAAa;YACb,oBAAc;YACd,2BAAqB;YACrB,0BAAoB;SACrB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,mBAAa,CAAC;IACvB,CAAC;IAED;;OAEG;IACK,qBAAqB;QAC3B,OAAO,0BAAoB,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,sBAAsB,CAAC,KAAa;QAClC,OAAO,IAAA,sBAAgB,EAAC,KAAK,CAAC,CAAC;IACjC,CAAC;CACF;AAlFD,wDAkFC"}
1
+ {"version":3,"file":"ZAIChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/zai/ZAIChatServiceProvider.ts"],"names":[],"mappings":";;;AAAA,gDAWgC;AAEhC,qDAAkD;AAMlD,0CAAoD;AAEpD;;GAEG;AACH,MAAa,sBAAsB;IAGjC;;OAEG;IACH,iBAAiB,CAAC,OAA8B;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QACtD,MAAM,WAAW,GAAG,IAAA,0BAAkB,EAAC;YACrC,KAAK;YACL,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,kBAAkB,EAAE,IAAI,CAAC,qBAAqB,EAAE;YAChD,sBAAsB,EAAE,CAAC,WAAW,EAAE,EAAE,CACtC,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC;YAC1C,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QAEH,MAAM,KAAK,GAAiC,OAAO,CAAC,KAAK,CAAC;QAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,IAAI,EAAE,UAAmB,EAAE,CAAC;QAEnE,OAAO,IAAI,+BAAc,CACvB,OAAO,CAAC,MAAM,EACd,KAAK,EACL,WAAW,EACX,KAAK,EACL,OAAO,CAAC,QAAQ,IAAI,uCAAiC,EACrD,OAAO,CAAC,cAAc,EACtB,OAAO,CAAC,cAAc,EACtB,QAAQ,CACT,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO;YACL,iBAAW;YACX,mBAAa;YACb,0BAAoB;YACpB,yBAAmB;YACnB,mBAAa;YACb,oBAAc;YACd,2BAAqB;YACrB,0BAAoB;SACrB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,mBAAa,CAAC;IACvB,CAAC;IAED;;OAEG;IACK,qBAAqB;QAC3B,OAAO,0BAAoB,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,sBAAsB,CAAC,KAAa;QAClC,OAAO,IAAA,sBAAgB,EAAC,KAAK,CAAC,CAAC;IACjC,CAAC;CACF;AAnFD,wDAmFC"}
@@ -1,4 +1,5 @@
1
1
  export declare const ENDPOINT_ZAI_CHAT_COMPLETIONS_API = "https://api.z.ai/api/paas/v4/chat/completions";
2
+ export declare const MODEL_GLM_5 = "glm-5";
2
3
  export declare const MODEL_GLM_4_7 = "glm-4.7";
3
4
  export declare const MODEL_GLM_4_7_FLASHX = "glm-4.7-FlashX";
4
5
  export declare const MODEL_GLM_4_7_FLASH = "glm-4.7-Flash";
@@ -1 +1 @@
1
- {"version":3,"file":"zai.d.ts","sourceRoot":"","sources":["../../../src/constants/zai.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iCAAiC,kDACG,CAAC;AAGlD,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AACvD,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAGrD,eAAO,MAAM,2BAA2B,UAIvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE3D"}
1
+ {"version":3,"file":"zai.d.ts","sourceRoot":"","sources":["../../../src/constants/zai.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iCAAiC,kDACG,CAAC;AAGlD,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AACvD,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAGrD,eAAO,MAAM,2BAA2B,UAIvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE3D"}
@@ -1,5 +1,6 @@
1
1
  export const ENDPOINT_ZAI_CHAT_COMPLETIONS_API = 'https://api.z.ai/api/paas/v4/chat/completions';
2
2
  // Z.ai GLM models
3
+ export const MODEL_GLM_5 = 'glm-5';
3
4
  export const MODEL_GLM_4_7 = 'glm-4.7';
4
5
  export const MODEL_GLM_4_7_FLASHX = 'glm-4.7-FlashX';
5
6
  export const MODEL_GLM_4_7_FLASH = 'glm-4.7-Flash';
@@ -1 +1 @@
1
- {"version":3,"file":"zai.js","sourceRoot":"","sources":["../../../src/constants/zai.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iCAAiC,GAC5C,+CAA+C,CAAC;AAElD,kBAAkB;AAClB,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AACvD,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,4BAA4B;AAC5B,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,cAAc;IACd,qBAAqB;IACrB,oBAAoB;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,2BAA2B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AACnD,CAAC"}
1
+ {"version":3,"file":"zai.js","sourceRoot":"","sources":["../../../src/constants/zai.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iCAAiC,GAC5C,+CAA+C,CAAC;AAElD,kBAAkB;AAClB,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AACnC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AACvD,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,4BAA4B;AAC5B,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,cAAc;IACd,qBAAqB;IACrB,oBAAoB;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,2BAA2B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AACnD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ZAIChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/zai/ZAIChatServiceProvider.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAIhC;;GAEG;AACH,qBAAa,sBACX,YAAW,mBAAmB,CAAC,qBAAqB,CAAC;IAErD;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,WAAW;IA2B9D;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAY9B;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;OAEG;IACH,cAAc,IAAI,OAAO;IAIzB;;OAEG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAG/C"}
1
+ {"version":3,"file":"ZAIChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/zai/ZAIChatServiceProvider.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAIhC;;GAEG;AACH,qBAAa,sBACX,YAAW,mBAAmB,CAAC,qBAAqB,CAAC;IAErD;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,qBAAqB,GAAG,WAAW;IA2B9D;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAa9B;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;OAEG;IACH,cAAc,IAAI,OAAO;IAIzB;;OAEG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAG/C"}
@@ -1,4 +1,4 @@
1
- import { ENDPOINT_ZAI_CHAT_COMPLETIONS_API, MODEL_GLM_4_7, MODEL_GLM_4_7_FLASHX, MODEL_GLM_4_7_FLASH, MODEL_GLM_4_6, MODEL_GLM_4_6V, MODEL_GLM_4_6V_FLASHX, MODEL_GLM_4_6V_FLASH, isZaiVisionModel, } from '../../../constants/zai';
1
+ import { ENDPOINT_ZAI_CHAT_COMPLETIONS_API, MODEL_GLM_5, MODEL_GLM_4_7, MODEL_GLM_4_7_FLASHX, MODEL_GLM_4_7_FLASH, MODEL_GLM_4_6, MODEL_GLM_4_6V, MODEL_GLM_4_6V_FLASHX, MODEL_GLM_4_6V_FLASH, isZaiVisionModel, } from '../../../constants/zai';
2
2
  import { ZAIChatService } from './ZAIChatService';
3
3
  import { resolveVisionModel } from '../../../utils';
4
4
  /**
@@ -33,6 +33,7 @@ export class ZAIChatServiceProvider {
33
33
  */
34
34
  getSupportedModels() {
35
35
  return [
36
+ MODEL_GLM_5,
36
37
  MODEL_GLM_4_7,
37
38
  MODEL_GLM_4_7_FLASHX,
38
39
  MODEL_GLM_4_7_FLASH,
@@ -1 +1 @@
1
- {"version":3,"file":"ZAIChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/zai/ZAIChatServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAGjC;;OAEG;IACH,iBAAiB,CAAC,OAA8B;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QACtD,MAAM,WAAW,GAAG,kBAAkB,CAAC;YACrC,KAAK;YACL,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,kBAAkB,EAAE,IAAI,CAAC,qBAAqB,EAAE;YAChD,sBAAsB,EAAE,CAAC,WAAW,EAAE,EAAE,CACtC,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC;YAC1C,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QAEH,MAAM,KAAK,GAAiC,OAAO,CAAC,KAAK,CAAC;QAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,IAAI,EAAE,UAAmB,EAAE,CAAC;QAEnE,OAAO,IAAI,cAAc,CACvB,OAAO,CAAC,MAAM,EACd,KAAK,EACL,WAAW,EACX,KAAK,EACL,OAAO,CAAC,QAAQ,IAAI,iCAAiC,EACrD,OAAO,CAAC,cAAc,EACtB,OAAO,CAAC,cAAc,EACtB,QAAQ,CACT,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO;YACL,aAAa;YACb,oBAAoB;YACpB,mBAAmB;YACnB,aAAa;YACb,cAAc;YACd,qBAAqB;YACrB,oBAAoB;SACrB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;OAEG;IACK,qBAAqB;QAC3B,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,sBAAsB,CAAC,KAAa;QAClC,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;CACF"}
1
+ {"version":3,"file":"ZAIChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/zai/ZAIChatServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAGjC;;OAEG;IACH,iBAAiB,CAAC,OAA8B;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QACtD,MAAM,WAAW,GAAG,kBAAkB,CAAC;YACrC,KAAK;YACL,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,kBAAkB,EAAE,IAAI,CAAC,qBAAqB,EAAE;YAChD,sBAAsB,EAAE,CAAC,WAAW,EAAE,EAAE,CACtC,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC;YAC1C,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QAEH,MAAM,KAAK,GAAiC,OAAO,CAAC,KAAK,CAAC;QAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,IAAI,EAAE,UAAmB,EAAE,CAAC;QAEnE,OAAO,IAAI,cAAc,CACvB,OAAO,CAAC,MAAM,EACd,KAAK,EACL,WAAW,EACX,KAAK,EACL,OAAO,CAAC,QAAQ,IAAI,iCAAiC,EACrD,OAAO,CAAC,cAAc,EACtB,OAAO,CAAC,cAAc,EACtB,QAAQ,CACT,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO;YACL,WAAW;YACX,aAAa;YACb,oBAAoB;YACpB,mBAAmB;YACnB,aAAa;YACb,cAAc;YACd,qBAAqB;YACrB,oBAAoB;SACrB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;OAEG;IACK,qBAAqB;QAC3B,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,sBAAsB,CAAC,KAAa;QAClC,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;CACF"}
@@ -78,6 +78,7 @@ var AITuberOnAirChat = (() => {
78
78
  MODEL_GLM_4_7: () => MODEL_GLM_4_7,
79
79
  MODEL_GLM_4_7_FLASH: () => MODEL_GLM_4_7_FLASH,
80
80
  MODEL_GLM_4_7_FLASHX: () => MODEL_GLM_4_7_FLASHX,
81
+ MODEL_GLM_5: () => MODEL_GLM_5,
81
82
  MODEL_GOOGLE_GEMINI_2_5_FLASH: () => MODEL_GOOGLE_GEMINI_2_5_FLASH,
82
83
  MODEL_GOOGLE_GEMINI_2_5_FLASH_LITE_PREVIEW_09_2025: () => MODEL_GOOGLE_GEMINI_2_5_FLASH_LITE_PREVIEW_09_2025,
83
84
  MODEL_GOOGLE_GEMINI_2_5_PRO: () => MODEL_GOOGLE_GEMINI_2_5_PRO,
@@ -290,6 +291,7 @@ var AITuberOnAirChat = (() => {
290
291
 
291
292
  // src/constants/zai.ts
292
293
  var ENDPOINT_ZAI_CHAT_COMPLETIONS_API = "https://api.z.ai/api/paas/v4/chat/completions";
294
+ var MODEL_GLM_5 = "glm-5";
293
295
  var MODEL_GLM_4_7 = "glm-4.7";
294
296
  var MODEL_GLM_4_7_FLASHX = "glm-4.7-FlashX";
295
297
  var MODEL_GLM_4_7_FLASH = "glm-4.7-Flash";
@@ -3463,6 +3465,7 @@ If it's in another language, summarize in that language.
3463
3465
  */
3464
3466
  getSupportedModels() {
3465
3467
  return [
3468
+ MODEL_GLM_5,
3466
3469
  MODEL_GLM_4_7,
3467
3470
  MODEL_GLM_4_7_FLASHX,
3468
3471
  MODEL_GLM_4_7_FLASH,
@@ -1,4 +1,4 @@
1
- "use strict";var AITuberOnAirChat=(()=>{var Ye=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Rt=Object.prototype.hasOwnProperty;var At=(n,e)=>{for(var t in e)Ye(n,t,{get:e[t],enumerable:!0})},wt=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Dt(e))!Rt.call(n,s)&&s!==t&&Ye(n,s,{get:()=>e[s],enumerable:!(o=bt(e,s))||o.enumerable});return n};var Nt=n=>wt(Ye({},"__esModule",{value:!0}),n);var jt={};At(jt,{CHAT_RESPONSE_LENGTH:()=>k,CLAUDE_VISION_SUPPORTED_MODELS:()=>pe,ChatServiceFactory:()=>ie,ChatServiceHttpClient:()=>_,ClaudeChatService:()=>$,ClaudeChatServiceProvider:()=>z,DEFAULT_MAX_TOKENS:()=>gt,DEFAULT_SUMMARY_PROMPT_TEMPLATE:()=>Ut,DEFAULT_VISION_PROMPT:()=>Ft,EMOTION_TAG_CLEANUP_REGEX:()=>vt,EMOTION_TAG_REGEX:()=>Tt,ENDPOINT_CLAUDE_API:()=>rt,ENDPOINT_GEMINI_API:()=>it,ENDPOINT_KIMI_CHAT_COMPLETIONS_API:()=>W,ENDPOINT_OPENAI_CHAT_COMPLETIONS_API:()=>V,ENDPOINT_OPENAI_RESPONSES_API:()=>E,ENDPOINT_OPENROUTER_API:()=>nt,ENDPOINT_ZAI_CHAT_COMPLETIONS_API:()=>he,EmotionParser:()=>j,GEMINI_VISION_SUPPORTED_MODELS:()=>le,GPT5_PRESETS:()=>ft,GPT_5_MODELS:()=>Mt,GeminiChatService:()=>q,GeminiChatServiceProvider:()=>J,HttpError:()=>A,KIMI_VISION_SUPPORTED_MODELS:()=>Et,KimiChatService:()=>Z,KimiChatServiceProvider:()=>X,MAX_TOKENS_BY_LENGTH:()=>yt,MODEL_ANTHROPIC_CLAUDE_3_5_SONNET:()=>at,MODEL_ANTHROPIC_CLAUDE_3_7_SONNET:()=>Be,MODEL_ANTHROPIC_CLAUDE_4_5_HAIKU:()=>We,MODEL_ANTHROPIC_CLAUDE_OPUS_4:()=>Ue,MODEL_ANTHROPIC_CLAUDE_SONNET_4:()=>He,MODEL_CLAUDE_3_5_HAIKU:()=>ye,MODEL_CLAUDE_3_5_SONNET:()=>Te,MODEL_CLAUDE_3_7_SONNET:()=>Se,MODEL_CLAUDE_3_HAIKU:()=>y,MODEL_CLAUDE_4_5_HAIKU:()=>Le,MODEL_CLAUDE_4_5_OPUS:()=>be,MODEL_CLAUDE_4_5_SONNET:()=>Ie,MODEL_CLAUDE_4_6_OPUS:()=>De,MODEL_CLAUDE_4_OPUS:()=>xe,MODEL_CLAUDE_4_SONNET:()=>Pe,MODEL_GEMINI_2_0_FLASH:()=>Ee,MODEL_GEMINI_2_0_FLASH_LITE:()=>D,MODEL_GEMINI_2_5_FLASH:()=>Me,MODEL_GEMINI_2_5_FLASH_LITE:()=>Ce,MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17:()=>Oe,MODEL_GEMINI_2_5_PRO:()=>ve,MODEL_GLM_4_6:()=>dt,MODEL_GLM_4_6V:()=>qe,MODEL_GLM_4_6V_FLASH:()=>N,MODEL_GLM_4_6V_FLASHX:()=>Je,MODEL_GLM_4_7:()=>H,MODEL_GLM_4_7_FLASH:()=>ut,MODEL_GLM_4_7_FLASHX:()=>mt,MODEL_GOOGLE_GEMINI_2_5_FLASH:()=>je,MODEL_GOOGLE_GEMINI_2_5_FLASH_LITE_PREVIEW_09_2025:()=>$e,MODEL_GOOGLE_GEMINI_2_5_PRO:()=>Ke,MODEL_GPT_4O:()=>ge,MODEL_GPT_4O_MINI:()=>w,MODEL_GPT_4_1:()=>ue,MODEL_GPT_4_1_MINI:()=>de,MODEL_GPT_4_1_NANO:()=>_e,MODEL_GPT_4_5_PREVIEW:()=>fe,MODEL_GPT_5:()=>ne,MODEL_GPT_5_1:()=>b,MODEL_GPT_5_MINI:()=>re,MODEL_GPT_5_NANO:()=>G,MODEL_GPT_OSS_20B_FREE:()=>R,MODEL_KIMI_K2_5:()=>T,MODEL_MOONSHOTAI_KIMI_K2_5:()=>Re,MODEL_O1:()=>tt,MODEL_O1_MINI:()=>et,MODEL_O3_MINI:()=>Qe,MODEL_OPENAI_GPT_4O:()=>Ve,MODEL_OPENAI_GPT_4_1_MINI:()=>Ge,MODEL_OPENAI_GPT_4_1_NANO:()=>Fe,MODEL_OPENAI_GPT_5_1_CHAT:()=>Ae,MODEL_OPENAI_GPT_5_1_CODEX:()=>we,MODEL_OPENAI_GPT_5_MINI:()=>Ne,MODEL_OPENAI_GPT_5_NANO:()=>ke,MODEL_ZAI_GLM_4_5_AIR:()=>pt,MODEL_ZAI_GLM_4_5_AIR_FREE:()=>ze,MODEL_ZAI_GLM_4_7_FLASH:()=>lt,OPENROUTER_CREDITS_THRESHOLD:()=>Gt,OPENROUTER_FREE_DAILY_LIMIT_HIGH_CREDITS:()=>Vt,OPENROUTER_FREE_DAILY_LIMIT_LOW_CREDITS:()=>kt,OPENROUTER_FREE_MODELS:()=>ce,OPENROUTER_FREE_RATE_LIMIT_PER_MINUTE:()=>ct,OPENROUTER_VISION_SUPPORTED_MODELS:()=>Ct,OpenAIChatService:()=>Y,OpenAIChatServiceProvider:()=>Q,OpenRouterChatService:()=>ee,OpenRouterChatServiceProvider:()=>te,StreamTextAccumulator:()=>g,VISION_SUPPORTED_MODELS:()=>ae,ZAIChatService:()=>oe,ZAIChatServiceProvider:()=>se,ZAI_VISION_SUPPORTED_MODELS:()=>Ot,allowsReasoningMinimal:()=>st,allowsReasoningNone:()=>ot,buildOpenAICompatibleTools:()=>I,getMaxTokensForResponseLength:()=>M,installGASFetch:()=>Lt,isGPT5Model:()=>F,isKimiVisionModel:()=>K,isOpenRouterFreeModel:()=>ht,isOpenRouterVisionModel:()=>U,isZaiToolStreamModel:()=>_t,isZaiVisionModel:()=>B,parseOpenAICompatibleOneShot:()=>x,parseOpenAICompatibleTextStream:()=>S,parseOpenAICompatibleToolStream:()=>P,processChatWithOptionalTools:()=>f,resolveVisionModel:()=>C,runOnceText:()=>Kt,screenplayToText:()=>Wt,textToScreenplay:()=>St,textsToScreenplay:()=>Bt});var V="https://api.openai.com/v1/chat/completions",E="https://api.openai.com/v1/responses",G="gpt-5-nano",re="gpt-5-mini",ne="gpt-5",b="gpt-5.1",ue="gpt-4.1",de="gpt-4.1-mini",_e="gpt-4.1-nano",w="gpt-4o-mini",ge="gpt-4o",Qe="o3-mini",et="o1-mini",tt="o1",fe="gpt-4.5-preview",ae=[G,re,ne,b,ue,de,_e,w,ge,fe,"o1"],Mt=[G,re,ne,b];function F(n){return Mt.includes(n)}function ot(n){return n===b}function st(n){return n!==b}var it="https://generativelanguage.googleapis.com",ve="gemini-2.5-pro",Me="gemini-2.5-flash",Ce="gemini-2.5-flash-lite",Oe="gemini-2.5-flash-lite-preview-06-17",Ee="gemini-2.0-flash",D="gemini-2.0-flash-lite",le=[ve,Me,Ce,Oe,Ee,D];var rt="https://api.anthropic.com/v1/messages",y="claude-3-haiku-20240307",ye="claude-3-5-haiku-20241022",Te="claude-3-5-sonnet-20241022",Se="claude-3-7-sonnet-20250219",Pe="claude-4-sonnet-20250514",xe="claude-4-opus-20250514",Ie="claude-sonnet-4-5-20250929",Le="claude-haiku-4-5-20251001",be="claude-opus-4-5-20251101",De="claude-opus-4-6",pe=[y,ye,Te,Se,Pe,xe,Ie,Le,be,De];var nt="https://openrouter.ai/api/v1/chat/completions",R="openai/gpt-oss-20b:free",Re="moonshotai/kimi-k2.5",Ae="openai/gpt-5.1-chat",we="openai/gpt-5.1-codex",Ne="openai/gpt-5-mini",ke="openai/gpt-5-nano",Ve="openai/gpt-4o",Ge="openai/gpt-4.1-mini",Fe="openai/gpt-4.1-nano",Ue="anthropic/claude-opus-4",He="anthropic/claude-sonnet-4",Be="anthropic/claude-3.7-sonnet",at="anthropic/claude-3.5-sonnet",We="anthropic/claude-haiku-4.5",Ke="google/gemini-2.5-pro",je="google/gemini-2.5-flash",$e="google/gemini-2.5-flash-lite-preview-09-2025",lt="z-ai/glm-4.7-flash",pt="z-ai/glm-4.5-air",ze="z-ai/glm-4.5-air:free",ce=[R,ze],Ct=[Ae,we,Ne,ke,Ve,Ge,Fe,Ue,He,Be,We,Ke,je,$e,Re],ct=20,kt=50,Vt=1e3,Gt=10;function ht(n){return ce.some(e=>n.includes(e))}function U(n){return Ct.some(e=>n.includes(e))}var he="https://api.z.ai/api/paas/v4/chat/completions",H="glm-4.7",mt="glm-4.7-FlashX",ut="glm-4.7-Flash",dt="glm-4.6",qe="glm-4.6V",Je="glm-4.6V-FlashX",N="glm-4.6V-Flash",Ot=[qe,Je,N];function B(n){return Ot.includes(n)}function _t(n){return n.toLowerCase().startsWith("glm-4.6")}var W="https://api.moonshot.ai/v1/chat/completions",T="kimi-k2.5",Et=[T];function K(n){return Et.includes(n)}var k={VERY_SHORT:"veryShort",SHORT:"short",MEDIUM:"medium",LONG:"long",VERY_LONG:"veryLong",DEEP:"deep"},yt={[k.VERY_SHORT]:40,[k.SHORT]:100,[k.MEDIUM]:200,[k.LONG]:300,[k.VERY_LONG]:1e3,[k.DEEP]:5e3},gt=5e3,ft={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 M(n){return n?yt[n]??gt:gt}var Ft="You are a friendly AI avatar. Comment on the situation based on the broadcast screen.",Ut=`You are a skilled summarizing assistant.
1
+ "use strict";var AITuberOnAirChat=(()=>{var Ye=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var At=Object.prototype.hasOwnProperty;var wt=(n,e)=>{for(var t in e)Ye(n,t,{get:e[t],enumerable:!0})},Nt=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Rt(e))!At.call(n,s)&&s!==t&&Ye(n,s,{get:()=>e[s],enumerable:!(o=Dt(e,s))||o.enumerable});return n};var kt=n=>Nt(Ye({},"__esModule",{value:!0}),n);var $t={};wt($t,{CHAT_RESPONSE_LENGTH:()=>k,CLAUDE_VISION_SUPPORTED_MODELS:()=>pe,ChatServiceFactory:()=>ie,ChatServiceHttpClient:()=>_,ClaudeChatService:()=>$,ClaudeChatServiceProvider:()=>z,DEFAULT_MAX_TOKENS:()=>ft,DEFAULT_SUMMARY_PROMPT_TEMPLATE:()=>Ht,DEFAULT_VISION_PROMPT:()=>Ut,EMOTION_TAG_CLEANUP_REGEX:()=>Mt,EMOTION_TAG_REGEX:()=>St,ENDPOINT_CLAUDE_API:()=>rt,ENDPOINT_GEMINI_API:()=>it,ENDPOINT_KIMI_CHAT_COMPLETIONS_API:()=>W,ENDPOINT_OPENAI_CHAT_COMPLETIONS_API:()=>V,ENDPOINT_OPENAI_RESPONSES_API:()=>E,ENDPOINT_OPENROUTER_API:()=>nt,ENDPOINT_ZAI_CHAT_COMPLETIONS_API:()=>he,EmotionParser:()=>j,GEMINI_VISION_SUPPORTED_MODELS:()=>le,GPT5_PRESETS:()=>vt,GPT_5_MODELS:()=>Ct,GeminiChatService:()=>q,GeminiChatServiceProvider:()=>J,HttpError:()=>A,KIMI_VISION_SUPPORTED_MODELS:()=>yt,KimiChatService:()=>Z,KimiChatServiceProvider:()=>X,MAX_TOKENS_BY_LENGTH:()=>Tt,MODEL_ANTHROPIC_CLAUDE_3_5_SONNET:()=>at,MODEL_ANTHROPIC_CLAUDE_3_7_SONNET:()=>Be,MODEL_ANTHROPIC_CLAUDE_4_5_HAIKU:()=>We,MODEL_ANTHROPIC_CLAUDE_OPUS_4:()=>Ue,MODEL_ANTHROPIC_CLAUDE_SONNET_4:()=>He,MODEL_CLAUDE_3_5_HAIKU:()=>ye,MODEL_CLAUDE_3_5_SONNET:()=>Te,MODEL_CLAUDE_3_7_SONNET:()=>Se,MODEL_CLAUDE_3_HAIKU:()=>y,MODEL_CLAUDE_4_5_HAIKU:()=>Le,MODEL_CLAUDE_4_5_OPUS:()=>be,MODEL_CLAUDE_4_5_SONNET:()=>Ie,MODEL_CLAUDE_4_6_OPUS:()=>De,MODEL_CLAUDE_4_OPUS:()=>xe,MODEL_CLAUDE_4_SONNET:()=>Pe,MODEL_GEMINI_2_0_FLASH:()=>Ee,MODEL_GEMINI_2_0_FLASH_LITE:()=>D,MODEL_GEMINI_2_5_FLASH:()=>Me,MODEL_GEMINI_2_5_FLASH_LITE:()=>Ce,MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17:()=>Oe,MODEL_GEMINI_2_5_PRO:()=>ve,MODEL_GLM_4_6:()=>_t,MODEL_GLM_4_6V:()=>qe,MODEL_GLM_4_6V_FLASH:()=>N,MODEL_GLM_4_6V_FLASHX:()=>Je,MODEL_GLM_4_7:()=>H,MODEL_GLM_4_7_FLASH:()=>dt,MODEL_GLM_4_7_FLASHX:()=>ut,MODEL_GLM_5:()=>mt,MODEL_GOOGLE_GEMINI_2_5_FLASH:()=>je,MODEL_GOOGLE_GEMINI_2_5_FLASH_LITE_PREVIEW_09_2025:()=>$e,MODEL_GOOGLE_GEMINI_2_5_PRO:()=>Ke,MODEL_GPT_4O:()=>ge,MODEL_GPT_4O_MINI:()=>w,MODEL_GPT_4_1:()=>ue,MODEL_GPT_4_1_MINI:()=>de,MODEL_GPT_4_1_NANO:()=>_e,MODEL_GPT_4_5_PREVIEW:()=>fe,MODEL_GPT_5:()=>ne,MODEL_GPT_5_1:()=>b,MODEL_GPT_5_MINI:()=>re,MODEL_GPT_5_NANO:()=>G,MODEL_GPT_OSS_20B_FREE:()=>R,MODEL_KIMI_K2_5:()=>T,MODEL_MOONSHOTAI_KIMI_K2_5:()=>Re,MODEL_O1:()=>tt,MODEL_O1_MINI:()=>et,MODEL_O3_MINI:()=>Qe,MODEL_OPENAI_GPT_4O:()=>Ve,MODEL_OPENAI_GPT_4_1_MINI:()=>Ge,MODEL_OPENAI_GPT_4_1_NANO:()=>Fe,MODEL_OPENAI_GPT_5_1_CHAT:()=>Ae,MODEL_OPENAI_GPT_5_1_CODEX:()=>we,MODEL_OPENAI_GPT_5_MINI:()=>Ne,MODEL_OPENAI_GPT_5_NANO:()=>ke,MODEL_ZAI_GLM_4_5_AIR:()=>pt,MODEL_ZAI_GLM_4_5_AIR_FREE:()=>ze,MODEL_ZAI_GLM_4_7_FLASH:()=>lt,OPENROUTER_CREDITS_THRESHOLD:()=>Ft,OPENROUTER_FREE_DAILY_LIMIT_HIGH_CREDITS:()=>Gt,OPENROUTER_FREE_DAILY_LIMIT_LOW_CREDITS:()=>Vt,OPENROUTER_FREE_MODELS:()=>ce,OPENROUTER_FREE_RATE_LIMIT_PER_MINUTE:()=>ct,OPENROUTER_VISION_SUPPORTED_MODELS:()=>Ot,OpenAIChatService:()=>Y,OpenAIChatServiceProvider:()=>Q,OpenRouterChatService:()=>ee,OpenRouterChatServiceProvider:()=>te,StreamTextAccumulator:()=>g,VISION_SUPPORTED_MODELS:()=>ae,ZAIChatService:()=>oe,ZAIChatServiceProvider:()=>se,ZAI_VISION_SUPPORTED_MODELS:()=>Et,allowsReasoningMinimal:()=>st,allowsReasoningNone:()=>ot,buildOpenAICompatibleTools:()=>I,getMaxTokensForResponseLength:()=>M,installGASFetch:()=>bt,isGPT5Model:()=>F,isKimiVisionModel:()=>K,isOpenRouterFreeModel:()=>ht,isOpenRouterVisionModel:()=>U,isZaiToolStreamModel:()=>gt,isZaiVisionModel:()=>B,parseOpenAICompatibleOneShot:()=>x,parseOpenAICompatibleTextStream:()=>S,parseOpenAICompatibleToolStream:()=>P,processChatWithOptionalTools:()=>f,resolveVisionModel:()=>C,runOnceText:()=>jt,screenplayToText:()=>Kt,textToScreenplay:()=>Pt,textsToScreenplay:()=>Wt});var V="https://api.openai.com/v1/chat/completions",E="https://api.openai.com/v1/responses",G="gpt-5-nano",re="gpt-5-mini",ne="gpt-5",b="gpt-5.1",ue="gpt-4.1",de="gpt-4.1-mini",_e="gpt-4.1-nano",w="gpt-4o-mini",ge="gpt-4o",Qe="o3-mini",et="o1-mini",tt="o1",fe="gpt-4.5-preview",ae=[G,re,ne,b,ue,de,_e,w,ge,fe,"o1"],Ct=[G,re,ne,b];function F(n){return Ct.includes(n)}function ot(n){return n===b}function st(n){return n!==b}var it="https://generativelanguage.googleapis.com",ve="gemini-2.5-pro",Me="gemini-2.5-flash",Ce="gemini-2.5-flash-lite",Oe="gemini-2.5-flash-lite-preview-06-17",Ee="gemini-2.0-flash",D="gemini-2.0-flash-lite",le=[ve,Me,Ce,Oe,Ee,D];var rt="https://api.anthropic.com/v1/messages",y="claude-3-haiku-20240307",ye="claude-3-5-haiku-20241022",Te="claude-3-5-sonnet-20241022",Se="claude-3-7-sonnet-20250219",Pe="claude-4-sonnet-20250514",xe="claude-4-opus-20250514",Ie="claude-sonnet-4-5-20250929",Le="claude-haiku-4-5-20251001",be="claude-opus-4-5-20251101",De="claude-opus-4-6",pe=[y,ye,Te,Se,Pe,xe,Ie,Le,be,De];var nt="https://openrouter.ai/api/v1/chat/completions",R="openai/gpt-oss-20b:free",Re="moonshotai/kimi-k2.5",Ae="openai/gpt-5.1-chat",we="openai/gpt-5.1-codex",Ne="openai/gpt-5-mini",ke="openai/gpt-5-nano",Ve="openai/gpt-4o",Ge="openai/gpt-4.1-mini",Fe="openai/gpt-4.1-nano",Ue="anthropic/claude-opus-4",He="anthropic/claude-sonnet-4",Be="anthropic/claude-3.7-sonnet",at="anthropic/claude-3.5-sonnet",We="anthropic/claude-haiku-4.5",Ke="google/gemini-2.5-pro",je="google/gemini-2.5-flash",$e="google/gemini-2.5-flash-lite-preview-09-2025",lt="z-ai/glm-4.7-flash",pt="z-ai/glm-4.5-air",ze="z-ai/glm-4.5-air:free",ce=[R,ze],Ot=[Ae,we,Ne,ke,Ve,Ge,Fe,Ue,He,Be,We,Ke,je,$e,Re],ct=20,Vt=50,Gt=1e3,Ft=10;function ht(n){return ce.some(e=>n.includes(e))}function U(n){return Ot.some(e=>n.includes(e))}var he="https://api.z.ai/api/paas/v4/chat/completions",mt="glm-5",H="glm-4.7",ut="glm-4.7-FlashX",dt="glm-4.7-Flash",_t="glm-4.6",qe="glm-4.6V",Je="glm-4.6V-FlashX",N="glm-4.6V-Flash",Et=[qe,Je,N];function B(n){return Et.includes(n)}function gt(n){return n.toLowerCase().startsWith("glm-4.6")}var W="https://api.moonshot.ai/v1/chat/completions",T="kimi-k2.5",yt=[T];function K(n){return yt.includes(n)}var k={VERY_SHORT:"veryShort",SHORT:"short",MEDIUM:"medium",LONG:"long",VERY_LONG:"veryLong",DEEP:"deep"},Tt={[k.VERY_SHORT]:40,[k.SHORT]:100,[k.MEDIUM]:200,[k.LONG]:300,[k.VERY_LONG]:1e3,[k.DEEP]:5e3},ft=5e3,vt={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 M(n){return n?Tt[n]??ft:ft}var Ut="You are a friendly AI avatar. Comment on the situation based on the broadcast screen.",Ht=`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,8 +7,8 @@ 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 A=class extends Error{constructor(t,o,s){super(`HTTP ${t}: ${o}`);this.status=t;this.statusText=o;this.body=s;this.name="HttpError"}},me=class me{static setFetch(e){this.fetchImpl=e}static async post(e,t,o={},s={}){let{timeout:i=3e4,retries:r=0,retryDelay:a=1e3}=s,h={...{"Content-Type":"application/json"},...o},c=null;for(let m=0;m<=r;m++)try{let u=typeof AbortController<"u",p=u?new AbortController:void 0,d=u?setTimeout(()=>p.abort(),i):void 0,v=await me.fetchImpl(e,{method:"POST",headers:h,body:typeof t=="string"?t:JSON.stringify(t),...p?{signal:p.signal}:{}});if(d&&clearTimeout(d),!v.ok){let O=await v.text();throw new A(v.status,v.statusText,O)}return v}catch(u){if(c=u,u instanceof A&&u.status>=400&&u.status<500)throw u;if(u instanceof Error&&u.name==="AbortError")throw new Error(`Request timeout after ${i}ms`);m<r&&await new Promise(p=>setTimeout(p,a*(m+1)))}throw c||new Error("Request failed")}static async handleErrorResponse(e){let t=await e.text();throw new A(e.status,e.statusText,t)}static async get(e,t={},o={}){let{timeout:s=3e4,retries:i=0,retryDelay:r=1e3}=o,a=null;for(let l=0;l<=i;l++)try{let h=typeof AbortController<"u",c=h?new AbortController:void 0,m=h?setTimeout(()=>c.abort(),s):void 0,u=await me.fetchImpl(e,{method:"GET",headers:t,...c?{signal:c.signal}:{}});if(m&&clearTimeout(m),!u.ok){let p=await u.text();throw new A(u.status,u.statusText,p)}return u}catch(h){if(a=h,h instanceof A&&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(c=>setTimeout(c,r*(l+1)))}throw a||new Error("Request failed")}};me.fetchImpl=(e,t)=>fetch(e,t);var _=me;var g=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 Ht=["happy","sad","angry","surprised","neutral"],Tt=/\[([a-z]+)\]/i,vt=/\[[a-z]+\]\s*/gi,j=class{static extractEmotion(e){let t=e.match(Tt);if(t){let o=t[1].toLowerCase(),s=e.replace(vt,"").trim();return{emotion:o,cleanText:s}}return{cleanText:e}}static isValidEmotion(e){return Ht.includes(e)}static cleanEmotionTags(e){return e.replace(vt,"").trim()}static addEmotionTag(e,t){return`[${e}] ${t}`}};function St(n){let{emotion:e,cleanText:t}=j.extractEmotion(n);return e?{emotion:e,text:t}:{text:t}}function Bt(n){return n.map(e=>St(e))}function Wt(n){return n.emotion?j.addEmotionTag(n.emotion,n.text):n.text}async function Kt(n,e){let{blocks:t}=await n.chatOnce(e,!1,()=>{});return g.getFullText(t)}var Pt=(n,e)=>{try{return JSON.parse(n)}catch(t){if(e){e(n,t);return}throw t}},xt=async(n,e)=>{let t=n.body?.getReader();if(!t)throw new Error("Response body is null.");let o=new TextDecoder,s="",i=!1;for(;!i;){let{done:r,value:a}=await t.read();if(r)break;s+=o.decode(a,{stream:!0});let l=s.split(`
11
- `);s=l.pop()||"";for(let h of l){let c=h.trim();if(!c||c.startsWith(":")||!c.startsWith("data:"))continue;let m=c.slice(5).trim();if(m==="[DONE]"){i=!0;break}e(m)}}};async function S(n,e,t={}){let o="";return await xt(n,s=>{let i=Pt(s,t.onJsonError);if(!i)return;let r=i.choices?.[0]?.delta?.content||"";r&&(e(r),o+=r)}),o}async function P(n,e,t={}){let o=[],s=new Map,i=t.appendTextBlock??g.append;await xt(n,l=>{let h=Pt(l,t.onJsonError);if(!h)return;let c=h.choices?.[0]?.delta;c?.content&&(e(c.content),i(o,c.content)),c?.tool_calls&&c.tool_calls.forEach(m=>{let u=s.get(m.index)??{id:m.id,name:m.function?.name,args:""};u.args+=m.function?.arguments||"",s.set(m.index,u)})});let r=Array.from(s.entries()).sort((l,h)=>l[0]-h[0]).map(([l,h])=>({type:"tool_use",id:h.id,name:h.name,input:JSON.parse(h.args||"{}")}));return{blocks:[...o,...r],stop_reason:r.length?"tool_use":"end"}}function x(n){let e=n?.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"}}var I=(n,e="chat-completions")=>n.length===0?[]:e==="responses"?n.map(t=>({type:"function",name:t.name,description:t.description,parameters:t.parameters})):n.map(t=>({type:"function",function:{name:t.name,description:t.description,parameters:t.parameters}}));async function f(n){if(!n.hasTools){let t=await n.runWithoutTools();await n.onCompleteResponse(t);return}let e=await n.runWithTools();if(n.onToolBlocks&&n.onToolBlocks(e.blocks),e.stop_reason==="end"){let t=g.getFullText(e.blocks);await n.onCompleteResponse(t);return}throw new Error(n.toolErrorMessage)}var C=n=>{let e=n.model??n.defaultModel,t=n.visionModel??(n.supportsVisionForModel(e)?e:n.defaultVisionModel);if(n.validate==="explicit"&&n.visionModel&&!n.supportsVisionForModel(n.visionModel))throw new Error(`Model ${n.visionModel} does not support vision capabilities.`);if(n.validate==="resolved"&&!n.supportsVisionForModel(t))throw new Error(`Model ${t} does not support vision capabilities.`);return t};var $=class{constructor(e,t=y,o=y,s=[],i=[],r){this.provider="claude";if(this.apiKey=e,this.model=t||y,this.visionModel=o||y,this.tools=s,this.mcpServers=i,this.responseLength=r,!pe.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(m=>m.role==="system")?.content??"",r=e.filter(m=>m.role!=="system"),a=r.some(m=>Array.isArray(m.content)&&m.content.some(u=>u.type==="image_url"||u.type==="image")),l={model:t,system:i,messages:a?this.convertVisionMessagesToClaudeFormat(r):this.convertMessagesToClaudeFormat(r),stream:o,max_tokens:s!==void 0?s:M(this.responseLength)};this.tools.length&&(l.tools=this.tools.map(m=>({name:m.name,description:m.description,input_schema:m.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(rt,l,h)}async parseStream(e,t){let o=e.body.getReader(),s=new TextDecoder,i=[],r=new Map,a="";for(;;){let{done:l,value:h}=await o.read();if(l)break;a+=s.decode(h,{stream:!0});let c;for(;(c=a.indexOf(`
10
+ `;var A=class extends Error{constructor(t,o,s){super(`HTTP ${t}: ${o}`);this.status=t;this.statusText=o;this.body=s;this.name="HttpError"}},me=class me{static setFetch(e){this.fetchImpl=e}static async post(e,t,o={},s={}){let{timeout:i=3e4,retries:r=0,retryDelay:a=1e3}=s,h={...{"Content-Type":"application/json"},...o},c=null;for(let m=0;m<=r;m++)try{let u=typeof AbortController<"u",p=u?new AbortController:void 0,d=u?setTimeout(()=>p.abort(),i):void 0,v=await me.fetchImpl(e,{method:"POST",headers:h,body:typeof t=="string"?t:JSON.stringify(t),...p?{signal:p.signal}:{}});if(d&&clearTimeout(d),!v.ok){let O=await v.text();throw new A(v.status,v.statusText,O)}return v}catch(u){if(c=u,u instanceof A&&u.status>=400&&u.status<500)throw u;if(u instanceof Error&&u.name==="AbortError")throw new Error(`Request timeout after ${i}ms`);m<r&&await new Promise(p=>setTimeout(p,a*(m+1)))}throw c||new Error("Request failed")}static async handleErrorResponse(e){let t=await e.text();throw new A(e.status,e.statusText,t)}static async get(e,t={},o={}){let{timeout:s=3e4,retries:i=0,retryDelay:r=1e3}=o,a=null;for(let l=0;l<=i;l++)try{let h=typeof AbortController<"u",c=h?new AbortController:void 0,m=h?setTimeout(()=>c.abort(),s):void 0,u=await me.fetchImpl(e,{method:"GET",headers:t,...c?{signal:c.signal}:{}});if(m&&clearTimeout(m),!u.ok){let p=await u.text();throw new A(u.status,u.statusText,p)}return u}catch(h){if(a=h,h instanceof A&&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(c=>setTimeout(c,r*(l+1)))}throw a||new Error("Request failed")}};me.fetchImpl=(e,t)=>fetch(e,t);var _=me;var g=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 Bt=["happy","sad","angry","surprised","neutral"],St=/\[([a-z]+)\]/i,Mt=/\[[a-z]+\]\s*/gi,j=class{static extractEmotion(e){let t=e.match(St);if(t){let o=t[1].toLowerCase(),s=e.replace(Mt,"").trim();return{emotion:o,cleanText:s}}return{cleanText:e}}static isValidEmotion(e){return Bt.includes(e)}static cleanEmotionTags(e){return e.replace(Mt,"").trim()}static addEmotionTag(e,t){return`[${e}] ${t}`}};function Pt(n){let{emotion:e,cleanText:t}=j.extractEmotion(n);return e?{emotion:e,text:t}:{text:t}}function Wt(n){return n.map(e=>Pt(e))}function Kt(n){return n.emotion?j.addEmotionTag(n.emotion,n.text):n.text}async function jt(n,e){let{blocks:t}=await n.chatOnce(e,!1,()=>{});return g.getFullText(t)}var xt=(n,e)=>{try{return JSON.parse(n)}catch(t){if(e){e(n,t);return}throw t}},It=async(n,e)=>{let t=n.body?.getReader();if(!t)throw new Error("Response body is null.");let o=new TextDecoder,s="",i=!1;for(;!i;){let{done:r,value:a}=await t.read();if(r)break;s+=o.decode(a,{stream:!0});let l=s.split(`
11
+ `);s=l.pop()||"";for(let h of l){let c=h.trim();if(!c||c.startsWith(":")||!c.startsWith("data:"))continue;let m=c.slice(5).trim();if(m==="[DONE]"){i=!0;break}e(m)}}};async function S(n,e,t={}){let o="";return await It(n,s=>{let i=xt(s,t.onJsonError);if(!i)return;let r=i.choices?.[0]?.delta?.content||"";r&&(e(r),o+=r)}),o}async function P(n,e,t={}){let o=[],s=new Map,i=t.appendTextBlock??g.append;await It(n,l=>{let h=xt(l,t.onJsonError);if(!h)return;let c=h.choices?.[0]?.delta;c?.content&&(e(c.content),i(o,c.content)),c?.tool_calls&&c.tool_calls.forEach(m=>{let u=s.get(m.index)??{id:m.id,name:m.function?.name,args:""};u.args+=m.function?.arguments||"",s.set(m.index,u)})});let r=Array.from(s.entries()).sort((l,h)=>l[0]-h[0]).map(([l,h])=>({type:"tool_use",id:h.id,name:h.name,input:JSON.parse(h.args||"{}")}));return{blocks:[...o,...r],stop_reason:r.length?"tool_use":"end"}}function x(n){let e=n?.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"}}var I=(n,e="chat-completions")=>n.length===0?[]:e==="responses"?n.map(t=>({type:"function",name:t.name,description:t.description,parameters:t.parameters})):n.map(t=>({type:"function",function:{name:t.name,description:t.description,parameters:t.parameters}}));async function f(n){if(!n.hasTools){let t=await n.runWithoutTools();await n.onCompleteResponse(t);return}let e=await n.runWithTools();if(n.onToolBlocks&&n.onToolBlocks(e.blocks),e.stop_reason==="end"){let t=g.getFullText(e.blocks);await n.onCompleteResponse(t);return}throw new Error(n.toolErrorMessage)}var C=n=>{let e=n.model??n.defaultModel,t=n.visionModel??(n.supportsVisionForModel(e)?e:n.defaultVisionModel);if(n.validate==="explicit"&&n.visionModel&&!n.supportsVisionForModel(n.visionModel))throw new Error(`Model ${n.visionModel} does not support vision capabilities.`);if(n.validate==="resolved"&&!n.supportsVisionForModel(t))throw new Error(`Model ${t} does not support vision capabilities.`);return t};var $=class{constructor(e,t=y,o=y,s=[],i=[],r){this.provider="claude";if(this.apiKey=e,this.model=t||y,this.visionModel=o||y,this.tools=s,this.mcpServers=i,this.responseLength=r,!pe.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(m=>m.role==="system")?.content??"",r=e.filter(m=>m.role!=="system"),a=r.some(m=>Array.isArray(m.content)&&m.content.some(u=>u.type==="image_url"||u.type==="image")),l={model:t,system:i,messages:a?this.convertVisionMessagesToClaudeFormat(r):this.convertMessagesToClaudeFormat(r),stream:o,max_tokens:s!==void 0?s:M(this.responseLength)};this.tools.length&&(l.tools=this.tools.map(m=>({name:m.name,description:m.description,input_schema:m.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(rt,l,h)}async parseStream(e,t){let o=e.body.getReader(),s=new TextDecoder,i=[],r=new Map,a="";for(;;){let{done:l,value:h}=await o.read();if(l)break;a+=s.decode(h,{stream:!0});let c;for(;(c=a.indexOf(`
12
12
  `))!==-1;){let m=a.slice(0,c).trim();if(a=a.slice(c+1),!m.startsWith("data:"))continue;let u=m.slice(5).trim();if(u==="[DONE]")break;let p=JSON.parse(u);if(p.type==="content_block_delta"&&p.delta?.text&&(t(p.delta.text),i.push({type:"text",text:p.delta.text})),p.type==="content_block_start"&&p.content_block?.type==="tool_use"?r.set(p.index,{id:p.content_block.id,name:p.content_block.name,args:""}):p.type==="content_block_start"&&p.content_block?.type==="mcp_tool_use"?r.set(p.index,{id:p.content_block.id,name:p.content_block.name,args:"",server_name:p.content_block.server_name}):p.type==="content_block_start"&&p.content_block?.type==="tool_result"?i.push({type:"tool_result",tool_use_id:p.content_block.tool_use_id,content:p.content_block.content??""}):p.type==="content_block_start"&&p.content_block?.type==="mcp_tool_result"&&i.push({type:"mcp_tool_result",tool_use_id:p.content_block.tool_use_id,is_error:p.content_block.is_error??!1,content:p.content_block.content??[]}),p.type==="content_block_delta"&&p.delta?.type==="input_json_delta"){let d=r.get(p.index);d&&(d.args+=p.delta.partial_json||"")}if(p.type==="content_block_stop"&&r.has(p.index)){let{id:d,name:v,args:O,server_name:L}=r.get(p.index);L?i.push({type:"mcp_tool_use",id:d,name:v,server_name:L,input:JSON.parse(O||"{}")}):i.push({type:"tool_use",id:d,name:v,input:JSON.parse(O||"{}")}),r.delete(p.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),r=t?await this.parseStream(i,o):this.parseOneShot(await i.json());return this.convertToStandardCompletion(r)}async visionChatOnce(e,t=!1,o=()=>{},s){let i=await this.callClaude(e,this.visionModel,t,s),r=t?await this.parseStream(i,o):this.parseOneShot(await i.json());return this.convertToStandardCompletion(r)}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 z=class{createChatService(e){let t=C({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:o=>this.supportsVisionForModel(o),validate:"resolved"});return new $(e.apiKey,e.model||this.getDefaultModel(),t,e.tools??[],e.mcpServers??[],e.responseLength)}getProviderName(){return"claude"}getSupportedModels(){return[y,ye,Te,Se,Pe,xe,Ie,Le,be,De]}getDefaultModel(){return y}supportsVision(){return!0}supportsVisionForModel(e){return pe.includes(e)}};var Ze=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 q=class{constructor(e,t=D,o=D,s=[],i=[],r){this.provider="gemini";this.mcpToolSchemas=[];this.mcpSchemasInitialized=!1;this.callIdMap=new Map;if(this.apiKey=e,this.model=t,this.responseLength=r,!le.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}}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=Ze.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);return g.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);return g.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 r of e){let a=this.mapRoleToGemini(r.role);if(r.tool_calls){i();for(let l of r.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(r.role==="tool"){i();let l=r.name??this.callIdMap.get(r.tool_call_id)??"result";t.push({role:"user",parts:[{functionResponse:{name:l,response:this.normalizeToolResult(this.safeJsonParse(r.content))}}]});continue}a!==o&&i(),o=a,s.push({text:r.content})}return i(),t}async callGemini(e,t,o=!1,s){let a={contents:e.some(d=>Array.isArray(d.content)&&d.content.some(v=>v?.type==="image_url"||v?.inlineData))?await this.convertVisionMessagesToGeminiFormat(e):this.convertMessagesToGeminiFormat(e),generationConfig:{maxOutputTokens:s!==void 0?s:M(this.responseLength)}},l=[];if(this.tools.length>0&&l.push(...this.tools.map(d=>({name:d.name,description:d.description,parameters:d.parameters}))),this.mcpServers.length>0)try{await this.initializeMCPSchemas(),l.push(...this.mcpToolSchemas.map(d=>({name:d.name,description:d.description,parameters:d.parameters})))}catch(d){console.warn("MCP initialization failed, skipping MCP tools:",d)}l.length>0&&(a.tools=[{functionDeclarations:l}],a.toolConfig={functionCallingConfig:{mode:"AUTO"}});let h=async(d,v)=>{let O=o?"streamGenerateContent":"generateContent",L=o?"?alt=sse":"",Xe=`${it}/${d}/models/${t}:${O}${L}${L?"&":"?"}key=${this.apiKey}`;return _.post(Xe,v)},c=/flash[-_]lite/.test(t),m=/gemini-2\.5/.test(t),u=c||m?"v1beta":"v1",p=async()=>{try{let d=u==="v1"?a:this.adaptKeysForApi(a);return await h(u,d)}catch(d){if(!(c||m)&&/Unknown name|Cannot find field|404/.test(d.message))return await h("v1beta",this.adaptKeysForApi(a));throw d}};try{return await p()}catch(d){throw d.body&&(console.error("Gemini API Error Details:",d.body),console.error("Request Body:",JSON.stringify(a,null,2))),d}}async convertVisionMessagesToGeminiFormat(e){let t=[],o=null,s=[];for(let i of e){let r=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(r!==o&&s.length>0&&(t.push({role:o,parts:[...s]}),s=[]),o=r,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(),c=await this.blobToBase64(h);s.push({inlineData:{mimeType:h.type||"image/jpeg",data:c.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){let o=e.body.getReader(),s=new TextDecoder,i=[],r=[],a="",l=c=>{if(!c||c==="[DONE]")return;let m;try{m=JSON.parse(c)}catch{return}for(let u of m.candidates??[])for(let p of u.content?.parts??[])p.text&&(t(p.text),g.addTextBlock(i,p.text)),p.functionCall&&r.push({type:"tool_use",id:this.genUUID(),name:p.functionCall.name,input:p.functionCall.args??{}}),p.functionResponse&&r.push({type:"tool_result",tool_use_id:p.functionResponse.name,content:JSON.stringify(p.functionResponse.response)})};for(;;){let{done:c,value:m}=await o.read();if(c)break;a+=s.decode(m,{stream:!0});let u;for(;(u=a.indexOf(`
13
13
  `))!==-1;){let p=a.slice(0,u);if(a=a.slice(u+1),p.endsWith("\r")&&(p=p.slice(0,-1)),!p.trim()){l("");continue}p.startsWith("data:")&&(p=p.slice(5).trim()),p&&l(p)}}return a&&l(a),{blocks:[...i,...r],stop_reason:r.some(c=>c.type==="tool_use")?"tool_use":"end"}}parseOneShot(e){let t=[],o=[];for(let i of e.candidates??[])for(let r of i.content?.parts??[])r.text&&t.push({type:"text",text:r.text}),r.functionCall&&o.push({type:"tool_use",id:this.genUUID(),name:r.functionCall.name,input:r.functionCall.args??{}}),r.functionResponse&&o.push({type:"tool_result",tool_use_id:r.functionResponse.name,content:JSON.stringify(r.functionResponse.response)});return{blocks:[...t,...o],stop_reason:o.some(i=>i.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.parseOneShot(await i.json())}async visionChatOnce(e,t=!1,o=()=>{},s){let i=await this.callGemini(e,this.visionModel,t,s);return t?this.parseStream(i,o):this.parseOneShot(await i.json())}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 J=class{createChatService(e){let t=C({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:o=>this.supportsVisionForModel(o),validate:"resolved"});return new q(e.apiKey,e.model||this.getDefaultModel(),t,e.tools||[],e.mcpServers||[],e.responseLength)}getProviderName(){return"gemini"}getSupportedModels(){return[ve,Me,Ce,Oe,Ee,D]}getDefaultModel(){return D}supportsVision(){return!0}supportsVisionForModel(e){return le.includes(e)}};var Z=class{constructor(e,t=T,o=T,s,i=W,r,a,l){this.provider="kimi";this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=r,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(!K(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(!K(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},r=s!==void 0?s:M(this.responseLength);r!==void 0&&(i.max_tokens=r),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(W)}normalizeEndpoint(e){return e.replace(/\/+$/,"")}buildToolsDefinition(){return I(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 P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return x(e)}};var X=class{createChatService(e){let t=this.resolveEndpoint(e),o=e.model||this.getDefaultModel(),s=C({model:o,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultVisionModel(),supportsVisionForModel:l=>this.supportsVisionForModel(l),validate:"explicit"}),i=e.tools,r=e.thinking??{type:"enabled"},a=i&&i.length>0?{type:"disabled"}:r;return new Z(e.apiKey,o,s,i,t,e.responseLength,e.responseFormat,a)}getProviderName(){return"kimi"}getSupportedModels(){return[T]}getDefaultModel(){return T}getDefaultVisionModel(){return T}supportsVision(){return!0}supportsVisionForModel(e){return K(e)}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 W}normalizeEndpoint(e){return e.replace(/\/+$/,"")}};var Y=class{constructor(e,t=w,o=w,s,i=V,r=[],a,l,h,c=!1){this.provider="openai";if(this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.mcpServers=r,this.responseLength=a,this.verbosity=l,this.reasoning_effort=h,this.enableReasoningSummary=c,!ae.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===E;try{if(i){let r=await this.parseResponsesStream(s,t);return g.getFullText(r.blocks)}return this.handleStream(s,t)}catch(r){throw console.error("[processChat] Error in streaming/completion:",r),r}},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===E;try{if(i){let r=await this.parseResponsesStream(s,t);return g.getFullText(r.blocks)}return this.handleStream(s,t)}catch(r){throw console.error("[processVisionChat] Error in streaming/completion:",r),r}},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===E?t?this.parseResponsesStream(e,o):this.parseResponsesOneShot(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);return await _.post(this.endpoint,i,{Authorization:`Bearer ${this.apiKey}`})}buildRequestBody(e,t,o,s){let i=this.endpoint===E;this.validateMCPCompatibility();let r={model:t,stream:o},a=s!==void 0?s:M(this.responseLength);i?r.max_output_tokens=a:r.max_completion_tokens=a,i?r.input=this.cleanMessagesForResponsesAPI(e):r.messages=e,F(t)&&(i?(this.reasoning_effort&&(r.reasoning={...r.reasoning,effort:this.reasoning_effort},this.enableReasoningSummary&&(r.reasoning.summary="auto")),this.verbosity&&(r.text={...r.text,format:{type:"text"},verbosity:this.verbosity})):(this.reasoning_effort&&(r.reasoning_effort=this.reasoning_effort),this.verbosity&&(r.verbosity=this.verbosity)));let l=this.buildToolsDefinition();return l.length>0&&(r.tools=l,i||(r.tool_choice="auto")),r}validateMCPCompatibility(){if(this.mcpServers.length>0&&this.endpoint===V)throw new Error(`MCP servers are not supported with Chat Completions API. Current endpoint: ${this.endpoint}. Please use OpenAI Responses API endpoint: ${E}. 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===E,t=[];return this.tools.length>0&&t.push(...I(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 P(e,t,{appendTextBlock:g.addTextBlock})}parseOneShot(e){return x(e)}async parseResponsesStream(e,t){let o=e.body.getReader(),s=new TextDecoder,i=[],r=new Map,a="";for(;;){let{done:c,value:m}=await o.read();if(c)break;a+=s.decode(m,{stream:!0});let u="",p="",d=a.split(`
14
- `);a=d.pop()||"";for(let v=0;v<d.length;v++){let O=d[v].trim();if(O.startsWith("event:"))u=O.slice(6).trim();else if(O.startsWith("data:"))p=O.slice(5).trim();else if(O===""&&u&&p){try{let L=JSON.parse(p),Xe=this.handleResponsesSSEEvent(u,L,t,i,r)}catch{console.warn("Failed to parse SSE data:",p)}u="",p=""}}}let l=Array.from(r.values()).map(c=>({type:"tool_use",id:c.id,name:c.name,input:c.input||{}}));return{blocks:[...i,...l],stop_reason:l.length?"tool_use":"end"}}handleResponsesSSEEvent(e,t,o,s,i){switch(e){case"response.output_item.added":t.item?.type==="message"&&Array.isArray(t.item.content)?t.item.content.forEach(r=>{r.type==="output_text"&&r.text&&(o(r.text),g.append(s,r.text))}):t.item?.type==="function_call"&&i.set(t.item.id,{id:t.item.id,name:t.item.name,input:t.item.arguments?JSON.parse(t.item.arguments):{}});break;case"response.content_part.added":t.part?.type==="output_text"&&typeof t.part.text=="string"&&(o(t.part.text),g.append(s,t.part.text));break;case"response.output_text.delta":case"response.content_part.delta":{let r=typeof t.delta=="string"?t.delta:t.delta?.text??"";r&&(o(r),g.append(s,r))}break;case"response.output_text.done":case"response.content_part.done":break;case"response.completed":return"completed";case"response.reasoning.started":case"response.reasoning.delta":case"response.reasoning.done":break;default:break}}parseResponsesOneShot(e){let t=[];return e.output&&Array.isArray(e.output)&&e.output.forEach(o=>{o.type==="message"&&o.content&&o.content.forEach(s=>{s.type==="output_text"&&s.text&&t.push({type:"text",text:s.text})}),o.type==="function_call"&&t.push({type:"tool_use",id:o.id,name:o.name,input:o.arguments?JSON.parse(o.arguments):{}})}),{blocks:t,stop_reason:t.some(o=>o.type==="tool_use")?"tool_use":"end"}}};var Q=class{createChatService(e){let t=this.optimizeGPT5Options(e),o=C({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??[],r=t.model||this.getDefaultModel(),a=!1;i.length>0?a=!0:F(r)&&(a=(t.gpt5EndpointPreference||"chat")==="responses");let l=t.endpoint||(a?E:V);return new Y(t.apiKey,r,o,s,l,i,t.responseLength,t.verbosity,t.reasoning_effort,t.enableReasoningSummary)}getProviderName(){return"openai"}getSupportedModels(){return[G,re,ne,b,ue,de,_e,w,ge,Qe,et,"o1",fe]}getDefaultModel(){return G}supportsVision(){return!0}supportsVisionForModel(e){return ae.includes(e)}optimizeGPT5Options(e){let t=e.model||this.getDefaultModel();if(!F(t))return e;let o={...e};if(e.gpt5Preset){let s=ft[e.gpt5Preset];o.reasoning_effort=s.reasoning_effort,o.verbosity=s.verbosity}else e.reasoning_effort||(o.reasoning_effort=this.getDefaultReasoningEffortForModel(t));return o.reasoning_effort=this.normalizeReasoningEffort(t,o.reasoning_effort),o}getDefaultReasoningEffortForModel(e){return e===b?"none":"medium"}normalizeReasoningEffort(e,t){if(t)return t==="none"&&!ot(e)?this.getDefaultReasoningEffortForModel(e):t==="minimal"&&!st(e)?"none":t}};var ee=class{constructor(e,t=R,o=R,s,i=nt,r,a,l,h,c,m){this.provider="openrouter";this.lastRequestTime=0;this.requestCount=0;this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=r,this.appName=a,this.appUrl=l,this.reasoning_effort=h,this.includeReasoning=c,this.reasoningMaxTokens=m,this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async applyRateLimiting(){if(!ht(this.model))return;let e=Date.now(),t=e-this.lastRequestTime;if(t>6e4&&(this.requestCount=0),this.requestCount>=ct){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(!U(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(!U(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),r={Authorization:`Bearer ${this.apiKey}`};return this.appUrl&&(r["HTTP-Referer"]=this.appUrl),this.appName&&(r["X-Title"]=this.appName),await _.post(this.endpoint,i,r)}buildRequestBody(e,t,o,s){let i={model:t,messages:e,stream:o};if((s!==void 0?s:M(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=I(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 P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return x(e)}};var te=class{createChatService(e){let t=C({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:e.model||this.getDefaultModel(),supportsVisionForModel:r=>this.supportsVisionForModel(r),validate:"explicit"}),o=e.tools,s=e.appName,i=e.appUrl;return new ee(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[R,ze,Ae,we,Ne,ke,Ve,Ge,Fe,Ue,He,Be,at,We,Ke,je,$e,lt,pt,Re]}getDefaultModel(){return R}supportsVision(){return this.getSupportedModels().some(e=>this.supportsVisionForModel(e))}supportsVisionForModel(e){return U(e)}getFreeModels(){return ce}isModelFree(e){return ce.includes(e)||e.endsWith(":free")}};var oe=class{constructor(e,t=H,o=N,s,i=he,r,a,l){this.provider="zai";this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=r,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(!B(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(!B(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},r=s!==void 0?s:M(this.responseLength);r!==void 0&&(i.max_tokens=r),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&&_t(t)&&(i.tool_stream=!0)),i}buildToolsDefinition(){return I(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 P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return x(e)}};var se=class{createChatService(e){let t=e.model||this.getDefaultModel(),o=C({model:t,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultVisionModel(),supportsVisionForModel:r=>this.supportsVisionForModel(r),validate:"explicit"}),s=e.tools,i=e.thinking??{type:"disabled"};return new oe(e.apiKey,t,o,s,e.endpoint||he,e.responseLength,e.responseFormat,i)}getProviderName(){return"zai"}getSupportedModels(){return[H,mt,ut,dt,qe,Je,N]}getDefaultModel(){return H}getDefaultVisionModel(){return N}supportsVision(){return!0}supportsVisionForModel(e){return B(e)}};var It=[new Q,new J,new z,new te,new se,new X];var ie=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():[]}};ie.providers=new Map;It.forEach(n=>ie.registerProvider(n));function Lt(){_.setFetch(async(n,e={})=>{let t=(e.method||"GET").toString().toUpperCase(),o=e.headers,s={};if(Array.isArray(o))for(let[m,u]of o)s[m]=String(u);else if(o&&typeof o=="object")for(let[m,u]of Object.entries(o))s[m]=String(u);let i={method:t,headers:s,muteHttpExceptions:!0},r=e.body;typeof r=="string"?i.payload=r:r!=null&&(s["Content-Type"]||(s["Content-Type"]="application/json"),i.payload=JSON.stringify(r));let a=UrlFetchApp.fetch(n,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 Nt(jt);})();
14
+ `);a=d.pop()||"";for(let v=0;v<d.length;v++){let O=d[v].trim();if(O.startsWith("event:"))u=O.slice(6).trim();else if(O.startsWith("data:"))p=O.slice(5).trim();else if(O===""&&u&&p){try{let L=JSON.parse(p),Xe=this.handleResponsesSSEEvent(u,L,t,i,r)}catch{console.warn("Failed to parse SSE data:",p)}u="",p=""}}}let l=Array.from(r.values()).map(c=>({type:"tool_use",id:c.id,name:c.name,input:c.input||{}}));return{blocks:[...i,...l],stop_reason:l.length?"tool_use":"end"}}handleResponsesSSEEvent(e,t,o,s,i){switch(e){case"response.output_item.added":t.item?.type==="message"&&Array.isArray(t.item.content)?t.item.content.forEach(r=>{r.type==="output_text"&&r.text&&(o(r.text),g.append(s,r.text))}):t.item?.type==="function_call"&&i.set(t.item.id,{id:t.item.id,name:t.item.name,input:t.item.arguments?JSON.parse(t.item.arguments):{}});break;case"response.content_part.added":t.part?.type==="output_text"&&typeof t.part.text=="string"&&(o(t.part.text),g.append(s,t.part.text));break;case"response.output_text.delta":case"response.content_part.delta":{let r=typeof t.delta=="string"?t.delta:t.delta?.text??"";r&&(o(r),g.append(s,r))}break;case"response.output_text.done":case"response.content_part.done":break;case"response.completed":return"completed";case"response.reasoning.started":case"response.reasoning.delta":case"response.reasoning.done":break;default:break}}parseResponsesOneShot(e){let t=[];return e.output&&Array.isArray(e.output)&&e.output.forEach(o=>{o.type==="message"&&o.content&&o.content.forEach(s=>{s.type==="output_text"&&s.text&&t.push({type:"text",text:s.text})}),o.type==="function_call"&&t.push({type:"tool_use",id:o.id,name:o.name,input:o.arguments?JSON.parse(o.arguments):{}})}),{blocks:t,stop_reason:t.some(o=>o.type==="tool_use")?"tool_use":"end"}}};var Q=class{createChatService(e){let t=this.optimizeGPT5Options(e),o=C({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??[],r=t.model||this.getDefaultModel(),a=!1;i.length>0?a=!0:F(r)&&(a=(t.gpt5EndpointPreference||"chat")==="responses");let l=t.endpoint||(a?E:V);return new Y(t.apiKey,r,o,s,l,i,t.responseLength,t.verbosity,t.reasoning_effort,t.enableReasoningSummary)}getProviderName(){return"openai"}getSupportedModels(){return[G,re,ne,b,ue,de,_e,w,ge,Qe,et,"o1",fe]}getDefaultModel(){return G}supportsVision(){return!0}supportsVisionForModel(e){return ae.includes(e)}optimizeGPT5Options(e){let t=e.model||this.getDefaultModel();if(!F(t))return e;let o={...e};if(e.gpt5Preset){let s=vt[e.gpt5Preset];o.reasoning_effort=s.reasoning_effort,o.verbosity=s.verbosity}else e.reasoning_effort||(o.reasoning_effort=this.getDefaultReasoningEffortForModel(t));return o.reasoning_effort=this.normalizeReasoningEffort(t,o.reasoning_effort),o}getDefaultReasoningEffortForModel(e){return e===b?"none":"medium"}normalizeReasoningEffort(e,t){if(t)return t==="none"&&!ot(e)?this.getDefaultReasoningEffortForModel(e):t==="minimal"&&!st(e)?"none":t}};var ee=class{constructor(e,t=R,o=R,s,i=nt,r,a,l,h,c,m){this.provider="openrouter";this.lastRequestTime=0;this.requestCount=0;this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=r,this.appName=a,this.appUrl=l,this.reasoning_effort=h,this.includeReasoning=c,this.reasoningMaxTokens=m,this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async applyRateLimiting(){if(!ht(this.model))return;let e=Date.now(),t=e-this.lastRequestTime;if(t>6e4&&(this.requestCount=0),this.requestCount>=ct){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(!U(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(!U(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),r={Authorization:`Bearer ${this.apiKey}`};return this.appUrl&&(r["HTTP-Referer"]=this.appUrl),this.appName&&(r["X-Title"]=this.appName),await _.post(this.endpoint,i,r)}buildRequestBody(e,t,o,s){let i={model:t,messages:e,stream:o};if((s!==void 0?s:M(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=I(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 P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return x(e)}};var te=class{createChatService(e){let t=C({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:e.model||this.getDefaultModel(),supportsVisionForModel:r=>this.supportsVisionForModel(r),validate:"explicit"}),o=e.tools,s=e.appName,i=e.appUrl;return new ee(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[R,ze,Ae,we,Ne,ke,Ve,Ge,Fe,Ue,He,Be,at,We,Ke,je,$e,lt,pt,Re]}getDefaultModel(){return R}supportsVision(){return this.getSupportedModels().some(e=>this.supportsVisionForModel(e))}supportsVisionForModel(e){return U(e)}getFreeModels(){return ce}isModelFree(e){return ce.includes(e)||e.endsWith(":free")}};var oe=class{constructor(e,t=H,o=N,s,i=he,r,a,l){this.provider="zai";this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.responseLength=r,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(!B(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(!B(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},r=s!==void 0?s:M(this.responseLength);r!==void 0&&(i.max_tokens=r),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&&gt(t)&&(i.tool_stream=!0)),i}buildToolsDefinition(){return I(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 P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return x(e)}};var se=class{createChatService(e){let t=e.model||this.getDefaultModel(),o=C({model:t,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultVisionModel(),supportsVisionForModel:r=>this.supportsVisionForModel(r),validate:"explicit"}),s=e.tools,i=e.thinking??{type:"disabled"};return new oe(e.apiKey,t,o,s,e.endpoint||he,e.responseLength,e.responseFormat,i)}getProviderName(){return"zai"}getSupportedModels(){return[mt,H,ut,dt,_t,qe,Je,N]}getDefaultModel(){return H}getDefaultVisionModel(){return N}supportsVision(){return!0}supportsVisionForModel(e){return B(e)}};var Lt=[new Q,new J,new z,new te,new se,new X];var ie=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():[]}};ie.providers=new Map;Lt.forEach(n=>ie.registerProvider(n));function bt(){_.setFetch(async(n,e={})=>{let t=(e.method||"GET").toString().toUpperCase(),o=e.headers,s={};if(Array.isArray(o))for(let[m,u]of o)s[m]=String(u);else if(o&&typeof o=="object")for(let[m,u]of Object.entries(o))s[m]=String(u);let i={method:t,headers:s,muteHttpExceptions:!0},r=e.body;typeof r=="string"?i.payload=r:r!=null&&(s["Content-Type"]||(s["Content-Type"]="application/json"),i.payload=JSON.stringify(r));let a=UrlFetchApp.fetch(n,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 kt($t);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aituber-onair/chat",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "Chat and LLM API integration library for AITuber OnAir",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",