@aituber-onair/chat 0.15.0 → 0.16.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/dist/cjs/constants/openai.d.ts +0 -1
- package/dist/cjs/constants/openai.d.ts.map +1 -1
- package/dist/cjs/constants/openai.js +1 -4
- package/dist/cjs/constants/openai.js.map +1 -1
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.d.ts.map +1 -1
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.js +0 -1
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.js.map +1 -1
- package/dist/esm/constants/openai.d.ts +0 -1
- package/dist/esm/constants/openai.d.ts.map +1 -1
- package/dist/esm/constants/openai.js +0 -3
- package/dist/esm/constants/openai.js.map +1 -1
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.d.ts.map +1 -1
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.js +1 -2
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.js.map +1 -1
- package/dist/umd/aituber-onair-chat.js +1 -5
- package/dist/umd/aituber-onair-chat.min.js +6 -6
- package/package.json +1 -1
|
@@ -12,7 +12,6 @@ export declare const MODEL_GPT_4O = "gpt-4o";
|
|
|
12
12
|
export declare const MODEL_O3_MINI = "o3-mini";
|
|
13
13
|
export declare const MODEL_O1_MINI = "o1-mini";
|
|
14
14
|
export declare const MODEL_O1 = "o1";
|
|
15
|
-
export declare const MODEL_GPT_4_5_PREVIEW = "gpt-4.5-preview";
|
|
16
15
|
export declare const VISION_SUPPORTED_MODELS: string[];
|
|
17
16
|
export declare const GPT_5_MODELS: string[];
|
|
18
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/constants/openai.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oCAAoC,+CACH,CAAC;AAC/C,eAAO,MAAM,6BAA6B,wCACH,CAAC;AAGx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AM,GAAG,OAAO,CAElD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GPT_5_MODELS = exports.VISION_SUPPORTED_MODELS = exports.
|
|
3
|
+
exports.GPT_5_MODELS = exports.VISION_SUPPORTED_MODELS = exports.MODEL_O1 = exports.MODEL_O1_MINI = exports.MODEL_O3_MINI = exports.MODEL_GPT_4O = exports.MODEL_GPT_4O_MINI = exports.MODEL_GPT_4_1_NANO = exports.MODEL_GPT_4_1_MINI = exports.MODEL_GPT_4_1 = exports.MODEL_GPT_5_1 = exports.MODEL_GPT_5 = exports.MODEL_GPT_5_MINI = exports.MODEL_GPT_5_NANO = exports.ENDPOINT_OPENAI_RESPONSES_API = exports.ENDPOINT_OPENAI_CHAT_COMPLETIONS_API = void 0;
|
|
4
4
|
exports.isGPT5Model = isGPT5Model;
|
|
5
5
|
exports.allowsReasoningNone = allowsReasoningNone;
|
|
6
6
|
exports.allowsReasoningMinimal = allowsReasoningMinimal;
|
|
@@ -19,8 +19,6 @@ exports.MODEL_GPT_4O = 'gpt-4o';
|
|
|
19
19
|
exports.MODEL_O3_MINI = 'o3-mini';
|
|
20
20
|
exports.MODEL_O1_MINI = 'o1-mini';
|
|
21
21
|
exports.MODEL_O1 = 'o1';
|
|
22
|
-
// deprecated
|
|
23
|
-
exports.MODEL_GPT_4_5_PREVIEW = 'gpt-4.5-preview';
|
|
24
22
|
// Vision support for models
|
|
25
23
|
exports.VISION_SUPPORTED_MODELS = [
|
|
26
24
|
exports.MODEL_GPT_5_NANO,
|
|
@@ -32,7 +30,6 @@ exports.VISION_SUPPORTED_MODELS = [
|
|
|
32
30
|
exports.MODEL_GPT_4_1_NANO,
|
|
33
31
|
exports.MODEL_GPT_4O_MINI,
|
|
34
32
|
exports.MODEL_GPT_4O,
|
|
35
|
-
exports.MODEL_GPT_4_5_PREVIEW,
|
|
36
33
|
exports.MODEL_O1,
|
|
37
34
|
// MODEL_O3_MINI and MODEL_O1_MINI are not included as they don't support vision
|
|
38
35
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/constants/openai.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/constants/openai.ts"],"names":[],"mappings":";;;AAkDA,kCAEC;AAMD,kDAEC;AAMD,wDAEC;AApEY,QAAA,oCAAoC,GAC/C,4CAA4C,CAAC;AAClC,QAAA,6BAA6B,GACxC,qCAAqC,CAAC;AAExC,YAAY;AACC,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAChC,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAChC,QAAA,WAAW,GAAG,OAAO,CAAC;AACtB,QAAA,aAAa,GAAG,SAAS,CAAC;AAE1B,QAAA,aAAa,GAAG,SAAS,CAAC;AAC1B,QAAA,kBAAkB,GAAG,cAAc,CAAC;AACpC,QAAA,kBAAkB,GAAG,cAAc,CAAC;AAEpC,QAAA,iBAAiB,GAAG,aAAa,CAAC;AAClC,QAAA,YAAY,GAAG,QAAQ,CAAC;AACxB,QAAA,aAAa,GAAG,SAAS,CAAC;AAE1B,QAAA,aAAa,GAAG,SAAS,CAAC;AAC1B,QAAA,QAAQ,GAAG,IAAI,CAAC;AAE7B,4BAA4B;AACf,QAAA,uBAAuB,GAAG;IACrC,wBAAgB;IAChB,wBAAgB;IAChB,mBAAW;IACX,qBAAa;IACb,qBAAa;IACb,0BAAkB;IAClB,0BAAkB;IAClB,yBAAiB;IACjB,oBAAY;IACZ,gBAAQ;IACR,gFAAgF;CACjF,CAAC;AAEF,oBAAoB;AACP,QAAA,YAAY,GAAG;IAC1B,wBAAgB;IAChB,wBAAgB;IAChB,mBAAW;IACX,qBAAa;CACd,CAAC;AAEF;;;;GAIG;AACH,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,oBAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,KAAa;IAC/C,OAAO,KAAK,KAAK,qBAAa,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,SAAgB,sBAAsB,CAAC,KAAa;IAClD,OAAO,KAAK,KAAK,qBAAa,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAIChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/openai/OpenAIChatServiceProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenAIChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/openai/OpenAIChatServiceProvider.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAIhC;;GAEG;AACH,qBAAa,yBACX,YAAW,mBAAmB,CAAC,wBAAwB,CAAC;IAExD;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,WAAW;IAqDjE;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAiB9B;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,cAAc,IAAI,OAAO;IAIzB;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAoC3B;;;OAGG;IACH,OAAO,CAAC,iCAAiC;IASzC,OAAO,CAAC,wBAAwB;CAkBjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAIChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/openai/OpenAIChatServiceProvider.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"OpenAIChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/openai/OpenAIChatServiceProvider.ts"],"names":[],"mappings":";;;AAAA,kDAmB4B;AAC5B,kDAAuD;AAEvD,2DAAwD;AAMxD,0CAAoD;AAEpD;;GAEG;AACH,MAAa,yBAAyB;IAGpC;;;;OAIG;IACH,iBAAiB,CAAC,OAAiC;QACjD,sCAAsC;QACtC,MAAM,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC3D,gFAAgF;QAChF,MAAM,WAAW,GAAG,IAAA,0BAAkB,EAAC;YACrC,KAAK,EAAE,gBAAgB,CAAC,KAAK;YAC7B,WAAW,EAAE,gBAAgB,CAAC,WAAW;YACzC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,kBAAkB,EAAE,IAAI,CAAC,eAAe,EAAE;YAC1C,sBAAsB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC;YACrE,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QAEH,mBAAmB;QACnB,MAAM,KAAK,GAAiC,gBAAgB,CAAC,KAAK,CAAC;QAEnE,4EAA4E;QAC5E,MAAM,UAAU,GAAG,gBAAgB,CAAC,UAAU,IAAI,EAAE,CAAC;QACrD,MAAM,SAAS,GAAG,gBAAgB,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QAEnE,gCAAgC;QAChC,IAAI,qBAAqB,GAAG,KAAK,CAAC;QAElC,iDAAiD;QACjD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,qBAAqB,GAAG,IAAI,CAAC;QAC/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AM,KAAK,SAAS,IAAI,CAAC,IAAA,kCAAsB,EAAC,SAAS,CAAC,EAAE,CAAC;YAC/D,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA3LD,8DA2LC"}
|
|
@@ -12,7 +12,6 @@ export declare const MODEL_GPT_4O = "gpt-4o";
|
|
|
12
12
|
export declare const MODEL_O3_MINI = "o3-mini";
|
|
13
13
|
export declare const MODEL_O1_MINI = "o1-mini";
|
|
14
14
|
export declare const MODEL_O1 = "o1";
|
|
15
|
-
export declare const MODEL_GPT_4_5_PREVIEW = "gpt-4.5-preview";
|
|
16
15
|
export declare const VISION_SUPPORTED_MODELS: string[];
|
|
17
16
|
export declare const GPT_5_MODELS: string[];
|
|
18
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/constants/openai.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oCAAoC,+CACH,CAAC;AAC/C,eAAO,MAAM,6BAA6B,wCACH,CAAC;AAGxC,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AACjD,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAC/C,eAAO,MAAM,YAAY,WAAW,CAAC;AACrC,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,QAAQ,OAAO,CAAC;AAG7B,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/constants/openai.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oCAAoC,+CACH,CAAC;AAC/C,eAAO,MAAM,6BAA6B,wCACH,CAAC;AAGxC,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AACjD,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAC/C,eAAO,MAAM,YAAY,WAAW,CAAC;AACrC,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,QAAQ,OAAO,CAAC;AAG7B,eAAO,MAAM,uBAAuB,UAYnC,CAAC;AAGF,eAAO,MAAM,YAAY,UAKxB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
|
@@ -13,8 +13,6 @@ export const MODEL_GPT_4O = 'gpt-4o';
|
|
|
13
13
|
export const MODEL_O3_MINI = 'o3-mini';
|
|
14
14
|
export const MODEL_O1_MINI = 'o1-mini';
|
|
15
15
|
export const MODEL_O1 = 'o1';
|
|
16
|
-
// deprecated
|
|
17
|
-
export const MODEL_GPT_4_5_PREVIEW = 'gpt-4.5-preview';
|
|
18
16
|
// Vision support for models
|
|
19
17
|
export const VISION_SUPPORTED_MODELS = [
|
|
20
18
|
MODEL_GPT_5_NANO,
|
|
@@ -26,7 +24,6 @@ export const VISION_SUPPORTED_MODELS = [
|
|
|
26
24
|
MODEL_GPT_4_1_NANO,
|
|
27
25
|
MODEL_GPT_4O_MINI,
|
|
28
26
|
MODEL_GPT_4O,
|
|
29
|
-
MODEL_GPT_4_5_PREVIEW,
|
|
30
27
|
MODEL_O1,
|
|
31
28
|
// MODEL_O3_MINI and MODEL_O1_MINI are not included as they don't support vision
|
|
32
29
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/constants/openai.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oCAAoC,GAC/C,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,6BAA6B,GACxC,qCAAqC,CAAC;AAExC,YAAY;AACZ,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAC7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AACnC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAEjD,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AACrC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAE7B,
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/constants/openai.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oCAAoC,GAC/C,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,6BAA6B,GACxC,qCAAq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AAK,aAAa,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAIChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/openai/OpenAIChatServiceProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenAIChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/openai/OpenAIChatServiceProvider.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAIhC;;GAEG;AACH,qBAAa,yBACX,YAAW,mBAAmB,CAAC,wBAAwB,CAAC;IAExD;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,WAAW;IAqDjE;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAiB9B;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,cAAc,IAAI,OAAO;IAIzB;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAoC3B;;;OAGG;IACH,OAAO,CAAC,iCAAiC;IASzC,OAAO,CAAC,wBAAwB;CAkBjC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ENDPOINT_OPENAI_CHAT_COMPLETIONS_API, ENDPOINT_OPENAI_RESPONSES_API, MODEL_GPT_5_NANO, MODEL_GPT_5_MINI, MODEL_GPT_5, MODEL_GPT_5_1, MODEL_GPT_4_1, MODEL_GPT_4_1_MINI, MODEL_GPT_4_1_NANO, MODEL_GPT_4O_MINI, MODEL_GPT_4O, MODEL_O3_MINI, MODEL_O1_MINI, MODEL_O1,
|
|
1
|
+
import { ENDPOINT_OPENAI_CHAT_COMPLETIONS_API, ENDPOINT_OPENAI_RESPONSES_API, MODEL_GPT_5_NANO, MODEL_GPT_5_MINI, MODEL_GPT_5, MODEL_GPT_5_1, MODEL_GPT_4_1, MODEL_GPT_4_1_MINI, MODEL_GPT_4_1_NANO, MODEL_GPT_4O_MINI, MODEL_GPT_4O, MODEL_O3_MINI, MODEL_O1_MINI, MODEL_O1, VISION_SUPPORTED_MODELS, isGPT5Model, allowsReasoningNone, allowsReasoningMinimal, } from '../../../constants';
|
|
2
2
|
import { GPT5_PRESETS } from '../../../constants/chat';
|
|
3
3
|
import { OpenAIChatService } from './OpenAIChatService';
|
|
4
4
|
import { resolveVisionModel } from '../../../utils';
|
|
@@ -70,7 +70,6 @@ export class OpenAIChatServiceProvider {
|
|
|
70
70
|
MODEL_O3_MINI,
|
|
71
71
|
MODEL_O1_MINI,
|
|
72
72
|
MODEL_O1,
|
|
73
|
-
MODEL_GPT_4_5_PREVIEW,
|
|
74
73
|
];
|
|
75
74
|
}
|
|
76
75
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAIChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/openai/OpenAIChatServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oCAAoC,EACpC,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"OpenAIChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/openai/OpenAIChatServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oCAAoC,EACpC,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,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AAC;QAChB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -91,7 +91,6 @@ var AITuberOnAirChat = (() => {
|
|
|
91
91
|
MODEL_GPT_4_1: () => MODEL_GPT_4_1,
|
|
92
92
|
MODEL_GPT_4_1_MINI: () => MODEL_GPT_4_1_MINI,
|
|
93
93
|
MODEL_GPT_4_1_NANO: () => MODEL_GPT_4_1_NANO,
|
|
94
|
-
MODEL_GPT_4_5_PREVIEW: () => MODEL_GPT_4_5_PREVIEW,
|
|
95
94
|
MODEL_GPT_5: () => MODEL_GPT_5,
|
|
96
95
|
MODEL_GPT_5_1: () => MODEL_GPT_5_1,
|
|
97
96
|
MODEL_GPT_5_MINI: () => MODEL_GPT_5_MINI,
|
|
@@ -165,7 +164,6 @@ var AITuberOnAirChat = (() => {
|
|
|
165
164
|
var MODEL_O3_MINI = "o3-mini";
|
|
166
165
|
var MODEL_O1_MINI = "o1-mini";
|
|
167
166
|
var MODEL_O1 = "o1";
|
|
168
|
-
var MODEL_GPT_4_5_PREVIEW = "gpt-4.5-preview";
|
|
169
167
|
var VISION_SUPPORTED_MODELS = [
|
|
170
168
|
MODEL_GPT_5_NANO,
|
|
171
169
|
MODEL_GPT_5_MINI,
|
|
@@ -176,7 +174,6 @@ var AITuberOnAirChat = (() => {
|
|
|
176
174
|
MODEL_GPT_4_1_NANO,
|
|
177
175
|
MODEL_GPT_4O_MINI,
|
|
178
176
|
MODEL_GPT_4O,
|
|
179
|
-
MODEL_GPT_4_5_PREVIEW,
|
|
180
177
|
MODEL_O1
|
|
181
178
|
// MODEL_O3_MINI and MODEL_O1_MINI are not included as they don't support vision
|
|
182
179
|
];
|
|
@@ -2929,8 +2926,7 @@ If it's in another language, summarize in that language.
|
|
|
2929
2926
|
MODEL_GPT_4O,
|
|
2930
2927
|
MODEL_O3_MINI,
|
|
2931
2928
|
MODEL_O1_MINI,
|
|
2932
|
-
MODEL_O1
|
|
2933
|
-
MODEL_GPT_4_5_PREVIEW
|
|
2929
|
+
MODEL_O1
|
|
2934
2930
|
];
|
|
2935
2931
|
}
|
|
2936
2932
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var AITuberOnAirChat=(()=>{var
|
|
1
|
+
"use strict";var AITuberOnAirChat=(()=>{var ot=Object.defineProperty;var Vt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Ft=Object.prototype.hasOwnProperty;var Ut=(n,e)=>{for(var t in e)ot(n,t,{get:e[t],enumerable:!0})},Ht=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Gt(e))!Ft.call(n,s)&&s!==t&&ot(n,s,{get:()=>e[s],enumerable:!(o=Vt(e,s))||o.enumerable});return n};var Bt=n=>Ht(ot({},"__esModule",{value:!0}),n);var Yt={};Ut(Yt,{CHAT_RESPONSE_LENGTH:()=>V,CLAUDE_VISION_SUPPORTED_MODELS:()=>ce,ChatServiceFactory:()=>re,ChatServiceHttpClient:()=>_,ClaudeChatService:()=>q,ClaudeChatServiceProvider:()=>z,DEFAULT_MAX_TOKENS:()=>Ot,DEFAULT_SUMMARY_PROMPT_TEMPLATE:()=>qt,DEFAULT_VISION_PROMPT:()=>$t,EMOTION_TAG_CLEANUP_REGEX:()=>yt,EMOTION_TAG_REGEX:()=>bt,ENDPOINT_CLAUDE_API:()=>pt,ENDPOINT_GEMINI_API:()=>lt,ENDPOINT_KIMI_CHAT_COMPLETIONS_API:()=>K,ENDPOINT_OPENAI_CHAT_COMPLETIONS_API:()=>G,ENDPOINT_OPENAI_RESPONSES_API:()=>y,ENDPOINT_OPENROUTER_API:()=>ct,ENDPOINT_ZAI_CHAT_COMPLETIONS_API:()=>me,EmotionParser:()=>$,GEMINI_VISION_SUPPORTED_MODELS:()=>pe,GPT5_PRESETS:()=>Et,GPT_5_MODELS:()=>Tt,GeminiChatService:()=>J,GeminiChatServiceProvider:()=>Z,HttpError:()=>A,KIMI_VISION_SUPPORTED_MODELS:()=>It,KimiChatService:()=>X,KimiChatServiceProvider:()=>Y,MAX_TOKENS_BY_LENGTH:()=>Lt,MODEL_ANTHROPIC_CLAUDE_3_5_SONNET:()=>ht,MODEL_ANTHROPIC_CLAUDE_3_7_SONNET:()=>$e,MODEL_ANTHROPIC_CLAUDE_4_5_HAIKU:()=>qe,MODEL_ANTHROPIC_CLAUDE_OPUS_4:()=>Ke,MODEL_ANTHROPIC_CLAUDE_SONNET_4:()=>je,MODEL_CLAUDE_3_5_HAIKU:()=>Pe,MODEL_CLAUDE_3_5_SONNET:()=>xe,MODEL_CLAUDE_3_7_SONNET:()=>Ie,MODEL_CLAUDE_3_HAIKU:()=>S,MODEL_CLAUDE_4_5_HAIKU:()=>Re,MODEL_CLAUDE_4_5_OPUS:()=>Ae,MODEL_CLAUDE_4_5_SONNET:()=>De,MODEL_CLAUDE_4_6_OPUS:()=>Ne,MODEL_CLAUDE_4_6_SONNET:()=>we,MODEL_CLAUDE_4_OPUS:()=>be,MODEL_CLAUDE_4_SONNET:()=>Le,MODEL_GEMINI_2_0_FLASH:()=>Te,MODEL_GEMINI_2_0_FLASH_LITE:()=>D,MODEL_GEMINI_2_5_FLASH:()=>Ee,MODEL_GEMINI_2_5_FLASH_LITE:()=>ye,MODEL_GEMINI_2_5_FLASH_LITE_PREVIEW_06_17:()=>Se,MODEL_GEMINI_2_5_PRO:()=>Oe,MODEL_GEMINI_3_1_PRO_PREVIEW:()=>ve,MODEL_GEMINI_3_FLASH_PREVIEW:()=>Ce,MODEL_GEMINI_3_PRO_PREVIEW:()=>Me,MODEL_GLM_4_6:()=>Mt,MODEL_GLM_4_6V:()=>Ye,MODEL_GLM_4_6V_FLASH:()=>k,MODEL_GLM_4_6V_FLASHX:()=>Qe,MODEL_GLM_4_7:()=>B,MODEL_GLM_4_7_FLASH:()=>vt,MODEL_GLM_4_7_FLASHX:()=>ft,MODEL_GLM_5:()=>gt,MODEL_GOOGLE_GEMINI_2_5_FLASH:()=>Je,MODEL_GOOGLE_GEMINI_2_5_FLASH_LITE_PREVIEW_09_2025:()=>Ze,MODEL_GOOGLE_GEMINI_2_5_PRO:()=>ze,MODEL_GPT_4O:()=>fe,MODEL_GPT_4O_MINI:()=>N,MODEL_GPT_4_1:()=>de,MODEL_GPT_4_1_MINI:()=>_e,MODEL_GPT_4_1_NANO:()=>ge,MODEL_GPT_5:()=>ae,MODEL_GPT_5_1:()=>b,MODEL_GPT_5_MINI:()=>ne,MODEL_GPT_5_NANO:()=>F,MODEL_GPT_OSS_20B_FREE:()=>R,MODEL_KIMI_K2_5:()=>T,MODEL_MOONSHOTAI_KIMI_K2_5:()=>ke,MODEL_O1:()=>rt,MODEL_O1_MINI:()=>it,MODEL_O3_MINI:()=>st,MODEL_OPENAI_GPT_4O:()=>He,MODEL_OPENAI_GPT_4_1_MINI:()=>Be,MODEL_OPENAI_GPT_4_1_NANO:()=>We,MODEL_OPENAI_GPT_5_1_CHAT:()=>Ve,MODEL_OPENAI_GPT_5_1_CODEX:()=>Ge,MODEL_OPENAI_GPT_5_MINI:()=>Fe,MODEL_OPENAI_GPT_5_NANO:()=>Ue,MODEL_ZAI_GLM_4_5_AIR:()=>ut,MODEL_ZAI_GLM_4_5_AIR_FREE:()=>Xe,MODEL_ZAI_GLM_4_7_FLASH:()=>mt,OPENROUTER_CREDITS_THRESHOLD:()=>jt,OPENROUTER_FREE_DAILY_LIMIT_HIGH_CREDITS:()=>Kt,OPENROUTER_FREE_DAILY_LIMIT_LOW_CREDITS:()=>Wt,OPENROUTER_FREE_MODELS:()=>he,OPENROUTER_FREE_RATE_LIMIT_PER_MINUTE:()=>dt,OPENROUTER_VISION_SUPPORTED_MODELS:()=>Pt,OpenAIChatService:()=>w,OpenAIChatServiceProvider:()=>ee,OpenAICompatibleChatServiceProvider:()=>Q,OpenRouterChatService:()=>te,OpenRouterChatServiceProvider:()=>oe,StreamTextAccumulator:()=>g,VISION_SUPPORTED_MODELS:()=>le,ZAIChatService:()=>se,ZAIChatServiceProvider:()=>ie,ZAI_VISION_SUPPORTED_MODELS:()=>xt,allowsReasoningMinimal:()=>at,allowsReasoningNone:()=>nt,buildOpenAICompatibleTools:()=>L,getMaxTokensForResponseLength:()=>C,installGASFetch:()=>Nt,isGPT5Model:()=>U,isKimiVisionModel:()=>j,isOpenRouterFreeModel:()=>_t,isOpenRouterVisionModel:()=>H,isZaiToolStreamModel:()=>Ct,isZaiVisionModel:()=>W,parseOpenAICompatibleOneShot:()=>I,parseOpenAICompatibleTextStream:()=>P,parseOpenAICompatibleToolStream:()=>x,processChatWithOptionalTools:()=>f,resolveVisionModel:()=>O,runOnceText:()=>Xt,screenplayToText:()=>Zt,textToScreenplay:()=>Dt,textsToScreenplay:()=>Jt});var G="https://api.openai.com/v1/chat/completions",y="https://api.openai.com/v1/responses",F="gpt-5-nano",ne="gpt-5-mini",ae="gpt-5",b="gpt-5.1",de="gpt-4.1",_e="gpt-4.1-mini",ge="gpt-4.1-nano",N="gpt-4o-mini",fe="gpt-4o",st="o3-mini",it="o1-mini",rt="o1",le=[F,ne,ae,b,de,_e,ge,N,fe,"o1"],Tt=[F,ne,ae,b];function U(n){return Tt.includes(n)}function nt(n){return n===b}function at(n){return n!==b}var lt="https://generativelanguage.googleapis.com",ve="gemini-3.1-pro-preview",Me="gemini-3-pro-preview",Ce="gemini-3-flash-preview",Oe="gemini-2.5-pro",Ee="gemini-2.5-flash",ye="gemini-2.5-flash-lite",Se="gemini-2.5-flash-lite-preview-06-17",Te="gemini-2.0-flash",D="gemini-2.0-flash-lite",pe=[ve,Me,Ce,Oe,Ee,ye,Se,Te,D];var pt="https://api.anthropic.com/v1/messages",S="claude-3-haiku-20240307",Pe="claude-3-5-haiku-20241022",xe="claude-3-5-sonnet-20241022",Ie="claude-3-7-sonnet-20250219",Le="claude-4-sonnet-20250514",be="claude-4-opus-20250514",De="claude-sonnet-4-5-20250929",Re="claude-haiku-4-5-20251001",Ae="claude-opus-4-5-20251101",we="claude-sonnet-4-6",Ne="claude-opus-4-6",ce=[S,Pe,xe,Ie,Le,be,De,Re,Ae,we,Ne];var ct="https://openrouter.ai/api/v1/chat/completions",R="openai/gpt-oss-20b:free",ke="moonshotai/kimi-k2.5",Ve="openai/gpt-5.1-chat",Ge="openai/gpt-5.1-codex",Fe="openai/gpt-5-mini",Ue="openai/gpt-5-nano",He="openai/gpt-4o",Be="openai/gpt-4.1-mini",We="openai/gpt-4.1-nano",Ke="anthropic/claude-opus-4",je="anthropic/claude-sonnet-4",$e="anthropic/claude-3.7-sonnet",ht="anthropic/claude-3.5-sonnet",qe="anthropic/claude-haiku-4.5",ze="google/gemini-2.5-pro",Je="google/gemini-2.5-flash",Ze="google/gemini-2.5-flash-lite-preview-09-2025",mt="z-ai/glm-4.7-flash",ut="z-ai/glm-4.5-air",Xe="z-ai/glm-4.5-air:free",he=[R,Xe],Pt=[Ve,Ge,Fe,Ue,He,Be,We,Ke,je,$e,qe,ze,Je,Ze,ke],dt=20,Wt=50,Kt=1e3,jt=10;function _t(n){return he.some(e=>n.includes(e))}function H(n){return Pt.some(e=>n.includes(e))}var me="https://api.z.ai/api/paas/v4/chat/completions",gt="glm-5",B="glm-4.7",ft="glm-4.7-FlashX",vt="glm-4.7-Flash",Mt="glm-4.6",Ye="glm-4.6V",Qe="glm-4.6V-FlashX",k="glm-4.6V-Flash",xt=[Ye,Qe,k];function W(n){return xt.includes(n)}function Ct(n){return n.toLowerCase().startsWith("glm-4.6")}var K="https://api.moonshot.ai/v1/chat/completions",T="kimi-k2.5",It=[T];function j(n){return It.includes(n)}var V={VERY_SHORT:"veryShort",SHORT:"short",MEDIUM:"medium",LONG:"long",VERY_LONG:"veryLong",DEEP:"deep"},Lt={[V.VERY_SHORT]:40,[V.SHORT]:100,[V.MEDIUM]:200,[V.LONG]:300,[V.VERY_LONG]:1e3,[V.DEEP]:5e3},Ot=5e3,Et={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 C(n){return n?Lt[n]??Ot:Ot}var $t="You are a friendly AI avatar. Comment on the situation based on the broadcast screen.",qt=`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"}},ue=class ue{static setFetch(e){this.fetchImpl=e}static async post(e,t,o={},s={}){let{timeout:i=3e4,retries:r=0,retryDelay:a=1e3}=s,c={...{"Content-Type":"application/json"},...o},h=null;for(let m=0;m<=r;m++)try{let u=typeof AbortController<"u",p=u?new AbortController:void 0,v=u?setTimeout(()=>p.abort(),i):void 0,M=await ue.fetchImpl(e,{method:"POST",headers:c,body:typeof t=="string"?t:JSON.stringify(t),...p?{signal:p.signal}:{}});if(v&&clearTimeout(v),!M.ok){let d=await M.text();throw new A(M.status,M.statusText,d)}return M}catch(u){if(h=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 h||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 c=typeof AbortController<"u",h=c?new AbortController:void 0,m=c?setTimeout(()=>h.abort(),s):void 0,u=await ue.fetchImpl(e,{method:"GET",headers:t,...h?{signal:h.signal}:{}});if(m&&clearTimeout(m),!u.ok){let p=await u.text();throw new A(u.status,u.statusText,p)}return u}catch(c){if(a=c,c instanceof A&&c.status>=400&&c.status<500)throw c;if(c instanceof Error&&c.name==="AbortError")throw new Error(`Request timeout after ${s}ms`);l<i&&await new Promise(h=>setTimeout(h,r*(l+1)))}throw a||new Error("Request failed")}};ue.fetchImpl=(e,t)=>fetch(e,t);var _=ue;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
|
|
11
|
-
`);s=l.pop()||"";for(let c of l){let h=c.trim();if(!h||h.startsWith(":")||!h.startsWith("data:"))continue;let m=h.slice(5).trim();if(m==="[DONE]"){i=!0;break}e(m)}}};async function P(n,e,t={}){let o="";return await
|
|
12
|
-
`))!==-1;){let m=a.slice(0,h).trim();if(a=a.slice(h+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 v=r.get(p.index);v&&(v.args+=p.delta.partial_json||"")}if(p.type==="content_block_stop"&&r.has(p.index)){let{id:v,name:M,args:d,server_name:E}=r.get(p.index);E?i.push({type:"mcp_tool_use",id:v,name:M,server_name:E,input:JSON.parse(d||"{}")}):i.push({type:"tool_use",id:v,name:M,input:JSON.parse(d||"{}")}),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=O({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"claude"}getSupportedModels(){return[S,xe,Ie,Le,be,De,Re,Ae,we,Ne,ke]}getDefaultModel(){return S}supportsVision(){return!0}supportsVisionForModel(e){return ce.includes(e)}};var tt=class{static async fetchToolSchemas(e){try{let t={"Content-Type":"application/json"};e.authorization_token&&(t.Authorization=`Bearer ${e.authorization_token}`);let s=await(await _.post(`${e.url}/tools`,{},t)).json();return Array.isArray(s.tools)?s.tools.map(i=>({name:`mcp_${e.name}_${i.name}`,description:i.description||`Tool from ${e.name} MCP server`,parameters:i.inputSchema||{type:"object",properties:{},required:[]}})):[{name:`mcp_${e.name}_search`,description:`Search using ${e.name} MCP server`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}}]}catch(t){return console.warn(`Failed to fetch MCP schemas from ${e.name}:`,t),[{name:`mcp_${e.name}_search`,description:`Search using ${e.name} MCP server (schema fetch failed)`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}}]}}static async fetchAllToolSchemas(e){let t=[];for(let o of e)try{let s=await this.fetchToolSchemas(o);t.push(...s)}catch(s){console.error(`Failed to fetch schemas from ${o.name}:`,s)}return t}};var J=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,!pe.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=tt.fetchAllToolSchemas(this.mcpServers);this.mcpToolSchemas=await Promise.race([t,e]),this.mcpSchemasInitialized=!0}catch(e){console.warn("Failed to initialize MCP schemas, using fallback:",e),this.mcpToolSchemas=this.mcpServers.map(t=>({name:`mcp_${t.name}_search`,description:`Search using ${t.name} MCP server (fallback)`,parameters:{type:"object",properties:{query:{type:"string",description:"Search query"}},required:["query"]}})),this.mcpSchemasInitialized=!0}}async processChat(e,t,o){try{await f({hasTools:this.tools.length>0||this.mcpServers.length>0,runWithoutTools:async()=>{let s=await this.callGemini(e,this.model,!0),{blocks:i}=await this.parseStream(s,t);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(E=>E?.type==="image_url"||E?.inlineData))?await this.convertVisionMessagesToGeminiFormat(e):this.convertMessagesToGeminiFormat(e),generationConfig:{maxOutputTokens:s!==void 0?s:C(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 c=async(d,E)=>{let ot=o?"streamGenerateContent":"generateContent",Tt=o?"?alt=sse":"",Vt=`${pt}/${d}/models/${t}:${ot}${Tt}${Tt?"&":"?"}key=${this.apiKey}`;return _.post(Vt,E)},h=/flash[-_]lite/.test(t),m=/gemini-2\.5/.test(t),u=/^gemini-3(?:\.[0-9]+)?-.*preview/.test(t),p=h||m||u,v=p?"v1beta":"v1",M=async()=>{try{let d=v==="v1"?a:this.adaptKeysForApi(a);return await c(v,d)}catch(d){let E=/Unknown name|Cannot find field|404/.test(d?.message||"")||d?.status===404;if(!p&&E)return await c("v1beta",this.adaptKeysForApi(a));throw d}};try{return await M()}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 c=await(await _.get(a.image_url.url)).blob(),h=await this.blobToBase64(c);s.push({inlineData:{mimeType:c.type||"image/jpeg",data:h.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=h=>{if(!h||h==="[DONE]")return;let m;try{m=JSON.parse(h)}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:h,value:m}=await o.read();if(h)break;a+=s.decode(m,{stream:!0});let u;for(;(u=a.indexOf(`
|
|
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(h=>h.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 Z=class{createChatService(e){let t=O({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:o=>this.supportsVisionForModel(o),validate:"resolved"});return new J(e.apiKey,e.model||this.getDefaultModel(),t,e.tools||[],e.mcpServers||[],e.responseLength)}getProviderName(){return"gemini"}getSupportedModels(){return[Me,Ce,Oe,Ee,ye,Se,Te,
|
|
14
|
-
`);a=v.pop()||"";for(let M=0;M<v.length;M++){let d=v[M].trim();if(d.startsWith("event:"))u=d.slice(6).trim();else if(d.startsWith("data:"))p=d.slice(5).trim();else if(d===""&&u&&p){try{let E=JSON.parse(p),ot=this.handleResponsesSSEEvent(u,E,t,i,r)}catch{console.warn("Failed to parse SSE data:",p)}u="",p=""}}}let l=Array.from(r.values()).map(h=>({type:"tool_use",id:h.id,name:h.name,input:h.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){return this.validateRequiredOptions(e),new w(e.apiKey?.trim()??"",e.model,e.visionModel??e.model,e.tools,e.endpoint,[],e.responseLength,e.verbosity,e.reasoning_effort,e.enableReasoningSummary,this.getProviderName(),!1)}getProviderName(){return"openai-compatible"}getSupportedModels(){return[]}supportsVision(){return!1}getDefaultModel(){return"local-model"}validateRequiredOptions(e){if(e.mcpServers!==void 0)throw new Error("openai-compatible provider does not support mcpServers.");let t=e.endpoint?.trim();if(!t)throw new Error("openai-compatible provider requires endpoint (full URL).");let o;try{o=new URL(t)}catch{throw new Error("openai-compatible provider requires endpoint to be a full URL.")}if(o.protocol!=="http:"&&o.protocol!=="https:")throw new Error("openai-compatible provider requires endpoint to be a full URL.");if(!e.model?.trim())throw new Error("openai-compatible provider requires model.")}};var ee=class{createChatService(e){let t=this.optimizeGPT5Options(e),o=O({model:t.model,visionModel:t.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:c=>this.supportsVisionForModel(c),validate:"resolved"}),s=t.tools,i=t.mcpServers??[],r=t.model||this.getDefaultModel(),a=!1;i.length>0?a=!0:U(r)&&(a=(t.gpt5EndpointPreference||"chat")==="responses");let l=t.endpoint||(a?y:G);return new w(t.apiKey,r,o,s,l,i,t.responseLength,t.verbosity,t.reasoning_effort,t.enableReasoningSummary,this.getProviderName())}getProviderName(){return"openai"}getSupportedModels(){return[F,ne,ae,b,de,_e,ge,N,fe,it,rt,"o1",ve]}getDefaultModel(){return F}supportsVision(){return!0}supportsVisionForModel(e){return le.includes(e)}optimizeGPT5Options(e){let t=e.model||this.getDefaultModel();if(!U(t))return e;let o={...e};if(e.gpt5Preset){let s=yt[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"&&!at(e)?this.getDefaultReasoningEffortForModel(e):t==="minimal"&&!lt(e)?"none":t}};var te=class{constructor(e,t=R,o=R,s,i=ht,r,a,l,c,h,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=c,this.includeReasoning=h,this.reasoningMaxTokens=m,this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async applyRateLimiting(){if(!gt(this.model))return;let e=Date.now(),t=e-this.lastRequestTime;if(t>6e4&&(this.requestCount=0),this.requestCount>=_t){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(!H(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(!H(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:C(this.responseLength))&&console.warn("OpenRouter: Token limits are not supported for gpt-oss-20b model due to known issues. Using unlimited tokens instead."),this.reasoning_effort!==void 0||this.includeReasoning!==void 0||this.reasoningMaxTokens){if(i.reasoning={},this.reasoning_effort&&this.reasoning_effort!=="none"){let a=this.reasoning_effort==="minimal"?"low":this.reasoning_effort;i.reasoning.effort=a}(this.reasoning_effort==="none"||this.includeReasoning!==!0)&&(i.reasoning.exclude=!0),this.reasoningMaxTokens&&(i.reasoning.max_tokens=this.reasoningMaxTokens)}else i.reasoning={exclude:!0};return this.tools.length>0&&(i.tools=L(this.tools,"chat-completions"),i.tool_choice="auto"),i}async handleStream(e,t){return P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return x(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return I(e)}};var oe=class{createChatService(e){let t=O({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 te(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,Ye,Ge,Fe,Ue,He,We,Be,Ke,je,$e,qe,mt,ze,Je,Ze,Xe,ut,dt,Ve]}getDefaultModel(){return R}supportsVision(){return this.getSupportedModels().some(e=>this.supportsVisionForModel(e))}supportsVisionForModel(e){return H(e)}getFreeModels(){return he}isModelFree(e){return he.includes(e)||e.endsWith(":free")}};var se=class{constructor(e,t=W,o=k,s,i=me,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:C(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&&Ot(t)&&(i.tool_stream=!0)),i}buildToolsDefinition(){return L(this.tools,"chat-completions")}async handleStream(e,t){return P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return x(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return I(e)}};var ie=class{createChatService(e){let t=e.model||this.getDefaultModel(),o=O({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 se(e.apiKey,t,o,s,e.endpoint||me,e.responseLength,e.responseFormat,i)}getProviderName(){return"zai"}getSupportedModels(){return[ft,W,vt,Mt,Ct,Qe,et,k]}getDefaultModel(){return W}getDefaultVisionModel(){return k}supportsVision(){return!0}supportsVisionForModel(e){return B(e)}};var Nt=[new ee,new Q,new Z,new z,new oe,new ie,new Y];var re=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():[]}};re.providers=new Map;Nt.forEach(n=>re.registerProvider(n));function kt(){_.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(),c=a.getContentText();return{ok:l>=200&&l<300,status:l,statusText:String(l),text:async()=>c,json:async()=>c?JSON.parse(c):null}})}return Bt(Qt);})();
|
|
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"}},ue=class ue{static setFetch(e){this.fetchImpl=e}static async post(e,t,o={},s={}){let{timeout:i=3e4,retries:r=0,retryDelay:a=1e3}=s,c={...{"Content-Type":"application/json"},...o},h=null;for(let m=0;m<=r;m++)try{let u=typeof AbortController<"u",p=u?new AbortController:void 0,v=u?setTimeout(()=>p.abort(),i):void 0,M=await ue.fetchImpl(e,{method:"POST",headers:c,body:typeof t=="string"?t:JSON.stringify(t),...p?{signal:p.signal}:{}});if(v&&clearTimeout(v),!M.ok){let d=await M.text();throw new A(M.status,M.statusText,d)}return M}catch(u){if(h=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 h||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 c=typeof AbortController<"u",h=c?new AbortController:void 0,m=c?setTimeout(()=>h.abort(),s):void 0,u=await ue.fetchImpl(e,{method:"GET",headers:t,...h?{signal:h.signal}:{}});if(m&&clearTimeout(m),!u.ok){let p=await u.text();throw new A(u.status,u.statusText,p)}return u}catch(c){if(a=c,c instanceof A&&c.status>=400&&c.status<500)throw c;if(c instanceof Error&&c.name==="AbortError")throw new Error(`Request timeout after ${s}ms`);l<i&&await new Promise(h=>setTimeout(h,r*(l+1)))}throw a||new Error("Request failed")}};ue.fetchImpl=(e,t)=>fetch(e,t);var _=ue;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 zt=["happy","sad","angry","surprised","neutral"],bt=/\[([a-z]+)\]/i,yt=/\[[a-z]+\]\s*/gi,$=class{static extractEmotion(e){let t=e.match(bt);if(t){let o=t[1].toLowerCase(),s=e.replace(yt,"").trim();return{emotion:o,cleanText:s}}return{cleanText:e}}static isValidEmotion(e){return zt.includes(e)}static cleanEmotionTags(e){return e.replace(yt,"").trim()}static addEmotionTag(e,t){return`[${e}] ${t}`}};function Dt(n){let{emotion:e,cleanText:t}=$.extractEmotion(n);return e?{emotion:e,text:t}:{text:t}}function Jt(n){return n.map(e=>Dt(e))}function Zt(n){return n.emotion?$.addEmotionTag(n.emotion,n.text):n.text}async function Xt(n,e){let{blocks:t}=await n.chatOnce(e,!1,()=>{});return g.getFullText(t)}var Rt=(n,e)=>{try{return JSON.parse(n)}catch(t){if(e){e(n,t);return}throw t}},At=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 c of l){let h=c.trim();if(!h||h.startsWith(":")||!h.startsWith("data:"))continue;let m=h.slice(5).trim();if(m==="[DONE]"){i=!0;break}e(m)}}};async function P(n,e,t={}){let o="";return await At(n,s=>{let i=Rt(s,t.onJsonError);if(!i)return;let r=i.choices?.[0]?.delta?.content||"";r&&(e(r),o+=r)}),o}async function x(n,e,t={}){let o=[],s=new Map,i=t.appendTextBlock??g.append;await At(n,l=>{let c=Rt(l,t.onJsonError);if(!c)return;let h=c.choices?.[0]?.delta;h?.content&&(e(h.content),i(o,h.content)),h?.tool_calls&&h.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,c)=>l[0]-c[0]).map(([l,c])=>({type:"tool_use",id:c.id,name:c.name,input:JSON.parse(c.args||"{}")}));return{blocks:[...o,...r],stop_reason:r.length?"tool_use":"end"}}function I(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 L=(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 O=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 q=class{constructor(e,t=S,o=S,s=[],i=[],r){this.provider="claude";if(this.apiKey=e,this.model=t||S,this.visionModel=o||S,this.tools=s,this.mcpServers=i,this.responseLength=r,!ce.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:C(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 c={"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&&(c["anthropic-beta"]="mcp-client-2025-04-04"),await _.post(pt,l,c)}async parseStream(e,t){let o=e.body.getReader(),s=new TextDecoder,i=[],r=new Map,a="";for(;;){let{done:l,value:c}=await o.read();if(l)break;a+=s.decode(c,{stream:!0});let h;for(;(h=a.indexOf(`
|
|
12
|
+
`))!==-1;){let m=a.slice(0,h).trim();if(a=a.slice(h+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 v=r.get(p.index);v&&(v.args+=p.delta.partial_json||"")}if(p.type==="content_block_stop"&&r.has(p.index)){let{id:v,name:M,args:d,server_name:E}=r.get(p.index);E?i.push({type:"mcp_tool_use",id:v,name:M,server_name:E,input:JSON.parse(d||"{}")}):i.push({type:"tool_use",id:v,name:M,input:JSON.parse(d||"{}")}),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=O({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"claude"}getSupportedModels(){return[S,Pe,xe,Ie,Le,be,De,Re,Ae,we,Ne]}getDefaultModel(){return S}supportsVision(){return!0}supportsVisionForModel(e){return ce.includes(e)}};var et=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 J=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,!pe.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=et.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(E=>E?.type==="image_url"||E?.inlineData))?await this.convertVisionMessagesToGeminiFormat(e):this.convertMessagesToGeminiFormat(e),generationConfig:{maxOutputTokens:s!==void 0?s:C(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 c=async(d,E)=>{let tt=o?"streamGenerateContent":"generateContent",St=o?"?alt=sse":"",kt=`${lt}/${d}/models/${t}:${tt}${St}${St?"&":"?"}key=${this.apiKey}`;return _.post(kt,E)},h=/flash[-_]lite/.test(t),m=/gemini-2\.5/.test(t),u=/^gemini-3(?:\.[0-9]+)?-.*preview/.test(t),p=h||m||u,v=p?"v1beta":"v1",M=async()=>{try{let d=v==="v1"?a:this.adaptKeysForApi(a);return await c(v,d)}catch(d){let E=/Unknown name|Cannot find field|404/.test(d?.message||"")||d?.status===404;if(!p&&E)return await c("v1beta",this.adaptKeysForApi(a));throw d}};try{return await M()}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 c=await(await _.get(a.image_url.url)).blob(),h=await this.blobToBase64(c);s.push({inlineData:{mimeType:c.type||"image/jpeg",data:h.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=h=>{if(!h||h==="[DONE]")return;let m;try{m=JSON.parse(h)}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:h,value:m}=await o.read();if(h)break;a+=s.decode(m,{stream:!0});let u;for(;(u=a.indexOf(`
|
|
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(h=>h.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 Z=class{createChatService(e){let t=O({model:e.model,visionModel:e.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:o=>this.supportsVisionForModel(o),validate:"resolved"});return new J(e.apiKey,e.model||this.getDefaultModel(),t,e.tools||[],e.mcpServers||[],e.responseLength)}getProviderName(){return"gemini"}getSupportedModels(){return[ve,Me,Ce,Oe,Ee,ye,Se,Te,D]}getDefaultModel(){return D}supportsVision(){return!0}supportsVisionForModel(e){return pe.includes(e)}};var X=class{constructor(e,t=T,o=T,s,i=K,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(!j(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(!j(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:C(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(K)}normalizeEndpoint(e){return e.replace(/\/+$/,"")}buildToolsDefinition(){return L(this.tools,"chat-completions")}async handleStream(e,t){return P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return x(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return I(e)}};var Y=class{createChatService(e){let t=this.resolveEndpoint(e),o=e.model||this.getDefaultModel(),s=O({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 X(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 j(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 K}normalizeEndpoint(e){return e.replace(/\/+$/,"")}};var w=class{constructor(e,t=N,o=N,s,i=G,r=[],a,l,c,h=!1,m="openai",u=!0){if(this.provider=m,this.apiKey=e,this.model=t,this.tools=s||[],this.endpoint=i,this.mcpServers=r,this.responseLength=a,this.verbosity=l,this.reasoning_effort=c,this.enableReasoningSummary=h,u&&!le.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===y;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===y;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===y?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),r={};return(this.provider!=="openai-compatible"||this.apiKey.trim()!=="")&&(r.Authorization=`Bearer ${this.apiKey}`),await _.post(this.endpoint,i,r)}buildRequestBody(e,t,o,s){let i=this.endpoint===y;this.validateMCPCompatibility();let r={model:t,stream:o},a=s!==void 0?s:this.provider==="openai-compatible"?this.responseLength!==void 0?C(this.responseLength):void 0:C(this.responseLength);i?a!==void 0&&(r.max_output_tokens=a):a!==void 0&&(this.provider==="openai-compatible"?r.max_tokens=a:r.max_completion_tokens=a),i?r.input=this.cleanMessagesForResponsesAPI(e):r.messages=e,U(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===G)throw new Error(`MCP servers are not supported with Chat Completions API. Current endpoint: ${this.endpoint}. Please use OpenAI Responses API endpoint: ${y}. 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===y,t=[];return this.tools.length>0&&t.push(...L(this.tools,e?"responses":"chat-completions")),this.mcpServers.length>0&&e&&t.push(...this.buildMCPToolsDefinition()),t}buildMCPToolsDefinition(){return this.mcpServers.map(e=>{let t={type:"mcp",server_label:e.name,server_url:e.url};return e.require_approval&&(t.require_approval=e.require_approval),e.tool_configuration?.allowed_tools&&(t.allowed_tools=e.tool_configuration.allowed_tools),e.authorization_token&&(t.headers={Authorization:`Bearer ${e.authorization_token}`}),t})}async handleStream(e,t){return P(e,t)}async parseStream(e,t){return x(e,t,{appendTextBlock:g.addTextBlock})}parseOneShot(e){return I(e)}async parseResponsesStream(e,t){let o=e.body.getReader(),s=new TextDecoder,i=[],r=new Map,a="";for(;;){let{done:h,value:m}=await o.read();if(h)break;a+=s.decode(m,{stream:!0});let u="",p="",v=a.split(`
|
|
14
|
+
`);a=v.pop()||"";for(let M=0;M<v.length;M++){let d=v[M].trim();if(d.startsWith("event:"))u=d.slice(6).trim();else if(d.startsWith("data:"))p=d.slice(5).trim();else if(d===""&&u&&p){try{let E=JSON.parse(p),tt=this.handleResponsesSSEEvent(u,E,t,i,r)}catch{console.warn("Failed to parse SSE data:",p)}u="",p=""}}}let l=Array.from(r.values()).map(h=>({type:"tool_use",id:h.id,name:h.name,input:h.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){return this.validateRequiredOptions(e),new w(e.apiKey?.trim()??"",e.model,e.visionModel??e.model,e.tools,e.endpoint,[],e.responseLength,e.verbosity,e.reasoning_effort,e.enableReasoningSummary,this.getProviderName(),!1)}getProviderName(){return"openai-compatible"}getSupportedModels(){return[]}supportsVision(){return!1}getDefaultModel(){return"local-model"}validateRequiredOptions(e){if(e.mcpServers!==void 0)throw new Error("openai-compatible provider does not support mcpServers.");let t=e.endpoint?.trim();if(!t)throw new Error("openai-compatible provider requires endpoint (full URL).");let o;try{o=new URL(t)}catch{throw new Error("openai-compatible provider requires endpoint to be a full URL.")}if(o.protocol!=="http:"&&o.protocol!=="https:")throw new Error("openai-compatible provider requires endpoint to be a full URL.");if(!e.model?.trim())throw new Error("openai-compatible provider requires model.")}};var ee=class{createChatService(e){let t=this.optimizeGPT5Options(e),o=O({model:t.model,visionModel:t.visionModel,defaultModel:this.getDefaultModel(),defaultVisionModel:this.getDefaultModel(),supportsVisionForModel:c=>this.supportsVisionForModel(c),validate:"resolved"}),s=t.tools,i=t.mcpServers??[],r=t.model||this.getDefaultModel(),a=!1;i.length>0?a=!0:U(r)&&(a=(t.gpt5EndpointPreference||"chat")==="responses");let l=t.endpoint||(a?y:G);return new w(t.apiKey,r,o,s,l,i,t.responseLength,t.verbosity,t.reasoning_effort,t.enableReasoningSummary,this.getProviderName())}getProviderName(){return"openai"}getSupportedModels(){return[F,ne,ae,b,de,_e,ge,N,fe,st,it,"o1"]}getDefaultModel(){return F}supportsVision(){return!0}supportsVisionForModel(e){return le.includes(e)}optimizeGPT5Options(e){let t=e.model||this.getDefaultModel();if(!U(t))return e;let o={...e};if(e.gpt5Preset){let s=Et[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"&&!nt(e)?this.getDefaultReasoningEffortForModel(e):t==="minimal"&&!at(e)?"none":t}};var te=class{constructor(e,t=R,o=R,s,i=ct,r,a,l,c,h,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=c,this.includeReasoning=h,this.reasoningMaxTokens=m,this.visionModel=o}getModel(){return this.model}getVisionModel(){return this.visionModel}async applyRateLimiting(){if(!_t(this.model))return;let e=Date.now(),t=e-this.lastRequestTime;if(t>6e4&&(this.requestCount=0),this.requestCount>=dt){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(!H(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(!H(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:C(this.responseLength))&&console.warn("OpenRouter: Token limits are not supported for gpt-oss-20b model due to known issues. Using unlimited tokens instead."),this.reasoning_effort!==void 0||this.includeReasoning!==void 0||this.reasoningMaxTokens){if(i.reasoning={},this.reasoning_effort&&this.reasoning_effort!=="none"){let a=this.reasoning_effort==="minimal"?"low":this.reasoning_effort;i.reasoning.effort=a}(this.reasoning_effort==="none"||this.includeReasoning!==!0)&&(i.reasoning.exclude=!0),this.reasoningMaxTokens&&(i.reasoning.max_tokens=this.reasoningMaxTokens)}else i.reasoning={exclude:!0};return this.tools.length>0&&(i.tools=L(this.tools,"chat-completions"),i.tool_choice="auto"),i}async handleStream(e,t){return P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return x(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return I(e)}};var oe=class{createChatService(e){let t=O({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 te(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,Xe,Ve,Ge,Fe,Ue,He,Be,We,Ke,je,$e,ht,qe,ze,Je,Ze,mt,ut,ke]}getDefaultModel(){return R}supportsVision(){return this.getSupportedModels().some(e=>this.supportsVisionForModel(e))}supportsVisionForModel(e){return H(e)}getFreeModels(){return he}isModelFree(e){return he.includes(e)||e.endsWith(":free")}};var se=class{constructor(e,t=B,o=k,s,i=me,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(!W(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(!W(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:C(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&&Ct(t)&&(i.tool_stream=!0)),i}buildToolsDefinition(){return L(this.tools,"chat-completions")}async handleStream(e,t){return P(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}async parseStream(e,t){return x(e,t,{onJsonError:o=>console.debug("Failed to parse SSE data:",o)})}parseOneShot(e){return I(e)}};var ie=class{createChatService(e){let t=e.model||this.getDefaultModel(),o=O({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 se(e.apiKey,t,o,s,e.endpoint||me,e.responseLength,e.responseFormat,i)}getProviderName(){return"zai"}getSupportedModels(){return[gt,B,ft,vt,Mt,Ye,Qe,k]}getDefaultModel(){return B}getDefaultVisionModel(){return k}supportsVision(){return!0}supportsVisionForModel(e){return W(e)}};var wt=[new ee,new Q,new Z,new z,new oe,new ie,new Y];var re=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():[]}};re.providers=new Map;wt.forEach(n=>re.registerProvider(n));function Nt(){_.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(),c=a.getContentText();return{ok:l>=200&&l<300,status:l,statusText:String(l),text:async()=>c,json:async()=>c?JSON.parse(c):null}})}return Bt(Yt);})();
|