aicodeswitch 5.2.7 → 5.2.9
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.
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.detectRequestFormat = detectRequestFormat;
|
|
4
4
|
exports.isOfficialOpenAiApi = isOfficialOpenAiApi;
|
|
5
|
-
exports.sourceTypeToFormat = sourceTypeToFormat;
|
|
6
5
|
/**
|
|
7
6
|
* Detect the format of the incoming request based on path and body structure.
|
|
8
7
|
* Enhanced version that distinguishes between Chat Completions and Responses API.
|
|
@@ -61,23 +60,3 @@ function isOfficialOpenAiApi(apiUrl) {
|
|
|
61
60
|
const u = (apiUrl || '').toLowerCase();
|
|
62
61
|
return u.includes('api.openai.com') || u.includes('.openai.azure.com');
|
|
63
62
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Determine the upstream format from a SourceType string.
|
|
66
|
-
* Maps the legacy SourceType values to the new Format type.
|
|
67
|
-
*/
|
|
68
|
-
function sourceTypeToFormat(sourceType) {
|
|
69
|
-
switch (sourceType) {
|
|
70
|
-
case 'claude':
|
|
71
|
-
case 'claude-chat':
|
|
72
|
-
return 'claude';
|
|
73
|
-
case 'openai':
|
|
74
|
-
return 'responses';
|
|
75
|
-
case 'openai-chat':
|
|
76
|
-
return 'completions';
|
|
77
|
-
case 'gemini':
|
|
78
|
-
case 'gemini-chat':
|
|
79
|
-
return 'gemini';
|
|
80
|
-
default:
|
|
81
|
-
return 'completions';
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -15,14 +15,13 @@
|
|
|
15
15
|
* is driven by the ReasoningConfig passed through TransformRequestOptions.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.processCompactResponse = exports.prepareCompactRequest = exports.buildCompactedResponse = exports.extractSummaryFromResponse = exports.buildCompactUpstreamRequest = exports.buildCompactionPrompt = exports.COMPACTION_SYSTEM_PROMPT = exports.isCodexCompactRequest = exports.isLastClaudeMessageCompact = exports.isClaudeCompactRequest = exports.extractMessageContent = exports.extractConversationText = exports.sanitizeRequestBody = exports.getServerToolSupport = exports.getReasoningConfig = exports.isOfficialOpenAiApi = exports.
|
|
18
|
+
exports.processCompactResponse = exports.prepareCompactRequest = exports.buildCompactedResponse = exports.extractSummaryFromResponse = exports.buildCompactUpstreamRequest = exports.buildCompactionPrompt = exports.COMPACTION_SYSTEM_PROMPT = exports.isCodexCompactRequest = exports.isLastClaudeMessageCompact = exports.isClaudeCompactRequest = exports.extractMessageContent = exports.extractConversationText = exports.sanitizeRequestBody = exports.getServerToolSupport = exports.getReasoningConfig = exports.isOfficialOpenAiApi = exports.detectRequestFormat = void 0;
|
|
19
19
|
exports.transformRequest = transformRequest;
|
|
20
20
|
exports.transformResponse = transformResponse;
|
|
21
21
|
exports.createStreamConverter = createStreamConverter;
|
|
22
22
|
exports.buildTargetBody = buildTargetBody;
|
|
23
23
|
var detector_js_1 = require("./detector.js");
|
|
24
24
|
Object.defineProperty(exports, "detectRequestFormat", { enumerable: true, get: function () { return detector_js_1.detectRequestFormat; } });
|
|
25
|
-
Object.defineProperty(exports, "sourceTypeToFormat", { enumerable: true, get: function () { return detector_js_1.sourceTypeToFormat; } });
|
|
26
25
|
Object.defineProperty(exports, "isOfficialOpenAiApi", { enumerable: true, get: function () { return detector_js_1.isOfficialOpenAiApi; } });
|
|
27
26
|
var providers_js_1 = require("./thinking/providers.js");
|
|
28
27
|
Object.defineProperty(exports, "getReasoningConfig", { enumerable: true, get: function () { return providers_js_1.getReasoningConfig; } });
|
|
@@ -58,6 +58,7 @@ const stream_converter_adapter_1 = require("./conversions/stream-converter-adapt
|
|
|
58
58
|
const types_1 = require("../types");
|
|
59
59
|
const mcp_image_handler_1 = require("./mcp-image-handler");
|
|
60
60
|
const type_migration_1 = require("./type-migration");
|
|
61
|
+
const source_type_mapping_1 = require("./source-type-mapping");
|
|
61
62
|
const original_config_reader_1 = require("./original-config-reader");
|
|
62
63
|
const compact_1 = require("./conversions/compact");
|
|
63
64
|
const coding_plan_1 = require("./coding-plan");
|
|
@@ -3250,7 +3251,7 @@ class ProxyServer {
|
|
|
3250
3251
|
*/
|
|
3251
3252
|
transformRequestToUpstream(tool, source, payloadData, targetModel, providerConfig, serverToolConfig, sanitizeBody) {
|
|
3252
3253
|
const clientFormat = tool === 'codex' ? 'responses' : 'claude';
|
|
3253
|
-
const upstreamFormat = (0,
|
|
3254
|
+
const upstreamFormat = (0, source_type_mapping_1.sourceTypeToFormat)(source);
|
|
3254
3255
|
const result = (0, index_1.transformRequest)({ fromFormat: clientFormat, toFormat: upstreamFormat, body: payloadData, providerConfig, serverToolConfig, sanitizeBody });
|
|
3255
3256
|
const body = result.body;
|
|
3256
3257
|
// 模型覆盖:OpenAI 模型族保持原样,其余覆盖为 targetModel
|
|
@@ -3270,7 +3271,7 @@ class ProxyServer {
|
|
|
3270
3271
|
*/
|
|
3271
3272
|
transformResponseToTool(tool, source, responseData) {
|
|
3272
3273
|
const clientFormat = tool === 'codex' ? 'responses' : 'claude';
|
|
3273
|
-
const upstreamFormat = (0,
|
|
3274
|
+
const upstreamFormat = (0, source_type_mapping_1.sourceTypeToFormat)(source);
|
|
3274
3275
|
return (0, index_1.transformResponse)({ fromFormat: upstreamFormat, toFormat: clientFormat, response: responseData });
|
|
3275
3276
|
}
|
|
3276
3277
|
/**
|
|
@@ -3281,7 +3282,7 @@ class ProxyServer {
|
|
|
3281
3282
|
*/
|
|
3282
3283
|
transformSSEToTool(targetType, sourceType) {
|
|
3283
3284
|
const clientFormat = targetType === 'codex' ? 'responses' : 'claude';
|
|
3284
|
-
const upstreamFormat = (0,
|
|
3285
|
+
const upstreamFormat = (0, source_type_mapping_1.sourceTypeToFormat)(sourceType);
|
|
3285
3286
|
if (upstreamFormat === clientFormat) {
|
|
3286
3287
|
return { converter: null };
|
|
3287
3288
|
}
|
|
@@ -3304,7 +3305,7 @@ class ProxyServer {
|
|
|
3304
3305
|
var _a, _b, _c, _d, _e, _f;
|
|
3305
3306
|
if (!responseData)
|
|
3306
3307
|
return undefined;
|
|
3307
|
-
const format = (0,
|
|
3308
|
+
const format = (0, source_type_mapping_1.sourceTypeToFormat)(sourceType);
|
|
3308
3309
|
if (format === 'gemini') {
|
|
3309
3310
|
const usage = responseData === null || responseData === void 0 ? void 0 : responseData.usageMetadata;
|
|
3310
3311
|
if (!usage)
|
|
@@ -3879,7 +3880,7 @@ class ProxyServer {
|
|
|
3879
3880
|
const providerConfig = (0, index_1.getReasoningConfig)(service.name || '', effectiveApiUrl || '', effectiveModel || '');
|
|
3880
3881
|
const serverToolConfig = (0, index_1.getServerToolSupport)(service.name || '', effectiveApiUrl || '');
|
|
3881
3882
|
// responses→responses 直连非 OpenAI 官方端点时,需降级兼容(剥离 custom/namespace 等私有工具与非标准字段)
|
|
3882
|
-
const sanitizeBody = clientFormat === 'responses' && (0,
|
|
3883
|
+
const sanitizeBody = clientFormat === 'responses' && (0, source_type_mapping_1.sourceTypeToFormat)(sourceType) === 'responses' && !(0, index_1.isOfficialOpenAiApi)(effectiveApiUrl || '');
|
|
3883
3884
|
const transformedRequestBody = this.transformRequestToUpstream(targetType, sourceType, payloadForTransform, rule.targetModel, providerConfig, serverToolConfig, sanitizeBody);
|
|
3884
3885
|
requestBody = (_b = transformedRequestBody !== null && transformedRequestBody !== void 0 ? transformedRequestBody : this.cloneRequestBody(originalToolRequestBody)) !== null && _b !== void 0 ? _b : {};
|
|
3885
3886
|
// 对最终即将发送到上游的 Claude compact 请求再做一次兜底清理,
|
|
@@ -4740,7 +4741,7 @@ class ProxyServer {
|
|
|
4740
4741
|
const providerConfig = (0, index_1.getReasoningConfig)(service.name || '', effectiveApiUrl || '', effectiveModel || '');
|
|
4741
4742
|
const serverToolConfig = (0, index_1.getServerToolSupport)(service.name || '', effectiveApiUrl || '');
|
|
4742
4743
|
// responses→responses 直连非 OpenAI 官方端点时,需降级兼容(剥离 custom/namespace 等私有工具与非标准字段)
|
|
4743
|
-
const sanitizeBody = clientFormat === 'responses' && (0,
|
|
4744
|
+
const sanitizeBody = clientFormat === 'responses' && (0, source_type_mapping_1.sourceTypeToFormat)(sourceType) === 'responses' && !(0, index_1.isOfficialOpenAiApi)(effectiveApiUrl || '');
|
|
4744
4745
|
const transformedRequestBody = this.transformRequestByFormat(clientFormat, sourceType, payloadForTransform, rule.targetModel, providerConfig, serverToolConfig, sanitizeBody);
|
|
4745
4746
|
requestBody = (_a = transformedRequestBody !== null && transformedRequestBody !== void 0 ? transformedRequestBody : this.cloneRequestBody(requestBody)) !== null && _a !== void 0 ? _a : {};
|
|
4746
4747
|
// Compact final sanitize
|
|
@@ -4997,7 +4998,7 @@ class ProxyServer {
|
|
|
4997
4998
|
* 使用显式 clientFormat 进行请求转换(取代 tool → format 的硬编码映射)
|
|
4998
4999
|
*/
|
|
4999
5000
|
transformRequestByFormat(clientFormat, source, payloadData, targetModel, providerConfig, serverToolConfig, sanitizeBody) {
|
|
5000
|
-
const upstreamFormat = (0,
|
|
5001
|
+
const upstreamFormat = (0, source_type_mapping_1.sourceTypeToFormat)(source);
|
|
5001
5002
|
const result = (0, index_1.transformRequest)({ fromFormat: clientFormat, toFormat: upstreamFormat, body: payloadData, providerConfig, serverToolConfig, sanitizeBody });
|
|
5002
5003
|
const body = result.body;
|
|
5003
5004
|
if (targetModel) {
|
|
@@ -5012,14 +5013,14 @@ class ProxyServer {
|
|
|
5012
5013
|
* 使用显式格式进行响应转换
|
|
5013
5014
|
*/
|
|
5014
5015
|
transformResponseByFormat(upstreamFormat, clientFormat, responseData) {
|
|
5015
|
-
const upstream = (0,
|
|
5016
|
+
const upstream = (0, source_type_mapping_1.sourceTypeToFormat)(upstreamFormat);
|
|
5016
5017
|
return (0, index_1.transformResponse)({ fromFormat: upstream, toFormat: clientFormat, response: responseData });
|
|
5017
5018
|
}
|
|
5018
5019
|
/**
|
|
5019
5020
|
* 使用显式格式进行流式转换
|
|
5020
5021
|
*/
|
|
5021
5022
|
transformSSEByFormat(clientFormat, sourceType) {
|
|
5022
|
-
const upstreamFormat = (0,
|
|
5023
|
+
const upstreamFormat = (0, source_type_mapping_1.sourceTypeToFormat)(sourceType);
|
|
5023
5024
|
if (upstreamFormat === clientFormat) {
|
|
5024
5025
|
return { converter: null };
|
|
5025
5026
|
}
|
|
@@ -5069,7 +5070,7 @@ class ProxyServer {
|
|
|
5069
5070
|
return buildGeminiUrl(url);
|
|
5070
5071
|
}
|
|
5071
5072
|
// 对于标准 API 路径,直接根据上游格式拼接
|
|
5072
|
-
const upstreamFormat = (0,
|
|
5073
|
+
const upstreamFormat = (0, source_type_mapping_1.sourceTypeToFormat)(source);
|
|
5073
5074
|
switch (upstreamFormat) {
|
|
5074
5075
|
case 'claude':
|
|
5075
5076
|
return `${apiUrl}/v1/messages`;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sourceTypeToFormat = sourceTypeToFormat;
|
|
4
|
+
/**
|
|
5
|
+
* 将 SourceType 字符串映射为上游 API 的 Format 类型。
|
|
6
|
+
*
|
|
7
|
+
* 这是当前系统的适配映射(产品专有的 SourceType 词表 → 通用 Format 联合类型),
|
|
8
|
+
* 非通用转换逻辑,因此从 conversions 模块迁出独立维护。
|
|
9
|
+
*/
|
|
10
|
+
function sourceTypeToFormat(sourceType) {
|
|
11
|
+
switch (sourceType) {
|
|
12
|
+
case 'claude':
|
|
13
|
+
case 'claude-chat':
|
|
14
|
+
return 'claude';
|
|
15
|
+
case 'openai':
|
|
16
|
+
return 'responses';
|
|
17
|
+
case 'openai-chat':
|
|
18
|
+
return 'completions';
|
|
19
|
+
case 'gemini':
|
|
20
|
+
case 'gemini-chat':
|
|
21
|
+
return 'gemini';
|
|
22
|
+
default:
|
|
23
|
+
return 'completions';
|
|
24
|
+
}
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aicodeswitch",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.9",
|
|
4
4
|
"description": "A tool to help you manage AI programming tools to access large language models locally. It allows your Claude Code, Codex and other tools to no longer be limited to official models.",
|
|
5
5
|
"author": "tangshuang",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"tauri:dev": "tauri dev",
|
|
49
49
|
"tauri:start": "yarn build && node tauri/prepare-resources.js && cd tauri && cargo run",
|
|
50
50
|
"tauri:build": "tauri build && node tauri/move-bundle.js",
|
|
51
|
-
"tauri:icon": "tauri icon src/ui/assets/logo.png"
|
|
51
|
+
"tauri:icon": "tauri icon src/ui/assets/logo.png",
|
|
52
|
+
"version:sync": "node tauri/sync-version.js"
|
|
52
53
|
},
|
|
53
54
|
"standard-version": {
|
|
54
55
|
"skip": {
|