mapigate 0.5.123 → 0.5.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/adapters/anthropic/requestOpenAiToAnthropic.js +42 -5
- package/dist/core/adapters/anthropicAdapter.js +2 -2
- package/dist/core/adapters/helpers/toolCallRescue.js +6 -1
- package/dist/core/capabilities/constants.js +12 -0
- package/dist/core/capabilities/modelDictionary.js +1 -0
- package/dist/core/capabilities/patterns.js +25 -13
- package/dist/core/scanner/modelScanner.js +10 -5
- package/dist/mitm/handlers/kiro/config.js +1 -0
- package/dist/mitm/manager.js +1 -1
- package/dist/mitm/portConflict.js +38 -19
- package/dist/providers/catalog/xiaomi-tokenplan/provider.js +44 -11
- package/dist/providers/core/base/anthropicProvider.js +1 -1
- package/dist/providers/runtime/antigravity/executor.js +24 -6
- package/dist/providers/runtime/bedrock/provider.js +1 -1
- package/dist/providers/runtime/gemini-cli/provider.js +6 -1
- package/dist/providers/runtime/mimo/provider.js +43 -10
- package/dist/server/proxy/singleModelExecutor.js +7 -1
- package/dist/shared/utils/extractText.js +31 -0
- package/dist/web/assets/{CliToolsTab-D-0zU55K.js → CliToolsTab-Ck8EuOcF.js} +1 -1
- package/dist/web/assets/{CombosTab-V_ldcQni.js → CombosTab-CLPru5aK.js} +1 -1
- package/dist/web/assets/{ConfirmModal-B7vVauYn.js → ConfirmModal-1KqBoeRh.js} +1 -1
- package/dist/web/assets/{ConsoleLogTab-Byt7Fr4V.js → ConsoleLogTab-DC2FAcl1.js} +1 -1
- package/dist/web/assets/{EditAccountModal-p6rlIU5X.js → EditAccountModal-1EbG3eyM.js} +1 -1
- package/dist/web/assets/{EndpointTab-BHYn9Syj.js → EndpointTab-C-gwVRmb.js} +1 -1
- package/dist/web/assets/{MitmTab-sRzVrlgW.js → MitmTab-C2kTKbAV.js} +4 -4
- package/dist/web/assets/ModelAutocompleteInput-K8-vMnIb.js +1 -0
- package/dist/web/assets/{ProviderDetailPage-DgClsBMU.js → ProviderDetailPage-BSqwg2fW.js} +1 -1
- package/dist/web/assets/{ProvidersTab-CPMTBmXq.js → ProvidersTab-w9OOjPmA.js} +1 -1
- package/dist/web/assets/{QuotaTab-NaCPxtWq.js → QuotaTab-C43xP8JP.js} +1 -1
- package/dist/web/assets/{SettingsTab-BUKXj5iT.js → SettingsTab-BMs0BtId.js} +1 -1
- package/dist/web/assets/{UsageTab-BDTnu1v_.js → UsageTab-C5MbpcRp.js} +1 -1
- package/dist/web/assets/{index-BdD7LHGu.js → index-DVeDwPjn.js} +2 -2
- package/dist/web/assets/{metadataRegistry-7DDoxaR3.js → metadataRegistry-BMKXREeE.js} +1 -1
- package/dist/web/assets/{providersData-Br5RocnM.js → providersData-D7kilpPx.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/ModelAutocompleteInput-ClwXyzE7.js +0 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
[](LICENSE)
|
|
14
14
|
[](#)
|
|
15
15
|
[](https://www.typescriptlang.org/)
|
|
16
|
-
[](package.json)
|
|
17
17
|
|
|
18
18
|
[**What is Mapigate?**](#-what-is-mapigate) • [**Gateway API**](#-gateway-api) • [**Supported Providers**](#-supported-providers-151) • [**Quick Start**](#-quick-start-get-running-in-60s) • [**Token Saver**](#-feature-1-token-saver-modular-token-optimization) • [**Smart Routing & Combos**](#-feature-2-smart-routing--combo-engine) • [**Connect Coding Tools**](#-feature-3-one-click-connection-for-26-coding-assistants) • [**MITM Interceptor**](#-feature-4-mitm-https-interceptor-for-closed-tools) • [**Web Dashboard**](#-feature-5-web-dashboard-tour) • [**CLI Reference**](#-cli-reference-mapigate--mpg)
|
|
19
19
|
|
|
@@ -2,10 +2,42 @@ import { repairToolArguments, toolSchemaMap, extractToolNames, } from "../helper
|
|
|
2
2
|
import { rescueInlineToolCalls } from "../helpers/toolCallRescue.js";
|
|
3
3
|
import { normalizeToolParameters } from "../helpers/toolSchemaNormalize.js";
|
|
4
4
|
import { convertOpenAiContentToAnthropic } from "./imageUtils.js";
|
|
5
|
+
import { getCapabilitiesForModel } from "../../capabilities/index.js";
|
|
6
|
+
import { extractPlainTextContent } from "../../../shared/utils/extractText.js";
|
|
7
|
+
export const DEFAULT_MAX_TOKENS = 64000;
|
|
8
|
+
export const DEFAULT_MIN_TOKENS = 32000;
|
|
9
|
+
/**
|
|
10
|
+
* Adjust max_tokens based on request context and model ceiling.
|
|
11
|
+
* Parity with 9router:
|
|
12
|
+
* - Default maxTokens: 64,000 (when client does not pass max_tokens)
|
|
13
|
+
* - Tool calling floor: auto-raise to at least 32,000 to prevent truncated tool args
|
|
14
|
+
* - Thinking buffer: ensure max_tokens > thinking.budget_tokens + 1024
|
|
15
|
+
* - Clamped at model capability maxOutput ceiling
|
|
16
|
+
*/
|
|
17
|
+
export function adjustMaxTokens(body, ceiling = DEFAULT_MAX_TOKENS) {
|
|
18
|
+
let maxTokens = body.max_tokens ?? body.max_completion_tokens ?? DEFAULT_MAX_TOKENS;
|
|
19
|
+
// Auto-increase for tool calling to prevent truncated arguments (min never above ceiling)
|
|
20
|
+
if (body.tools && Array.isArray(body.tools) && body.tools.length > 0) {
|
|
21
|
+
if (maxTokens < DEFAULT_MIN_TOKENS) {
|
|
22
|
+
maxTokens = Math.min(DEFAULT_MIN_TOKENS, ceiling);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Ensure max_tokens > thinking.budget_tokens (Claude API requirement)
|
|
26
|
+
if (body.thinking?.budget_tokens && maxTokens <= body.thinking.budget_tokens) {
|
|
27
|
+
maxTokens = body.thinking.budget_tokens + 1024;
|
|
28
|
+
}
|
|
29
|
+
// Never exceed the ceiling
|
|
30
|
+
if (maxTokens > ceiling)
|
|
31
|
+
maxTokens = ceiling;
|
|
32
|
+
if (body.thinking?.budget_tokens && body.thinking.budget_tokens >= maxTokens) {
|
|
33
|
+
body.thinking.budget_tokens = Math.max(1024, maxTokens - 1024);
|
|
34
|
+
}
|
|
35
|
+
return maxTokens;
|
|
36
|
+
}
|
|
5
37
|
/**
|
|
6
38
|
* Translates OpenAI /v1/chat/completions payload to Anthropic /v1/messages payload
|
|
7
39
|
*/
|
|
8
|
-
export function translateOpenAiToAnthropic(openAiBody) {
|
|
40
|
+
export function translateOpenAiToAnthropic(openAiBody, modelOverride, providerId) {
|
|
9
41
|
let systemPrompt = "";
|
|
10
42
|
let systemCacheControl = undefined;
|
|
11
43
|
const anthropicMessages = [];
|
|
@@ -13,9 +45,11 @@ export function translateOpenAiToAnthropic(openAiBody) {
|
|
|
13
45
|
const toolNames = extractToolNames(openAiBody.tools);
|
|
14
46
|
if (Array.isArray(openAiBody.messages)) {
|
|
15
47
|
for (const msg of openAiBody.messages) {
|
|
16
|
-
if (msg.role === "system") {
|
|
17
|
-
const sysText =
|
|
18
|
-
|
|
48
|
+
if (msg.role === "system" || msg.role === "developer") {
|
|
49
|
+
const sysText = extractPlainTextContent(msg.content);
|
|
50
|
+
if (sysText) {
|
|
51
|
+
systemPrompt = systemPrompt ? `${systemPrompt}\n${sysText}` : sysText;
|
|
52
|
+
}
|
|
19
53
|
if (msg.cache_control) {
|
|
20
54
|
systemCacheControl = msg.cache_control;
|
|
21
55
|
}
|
|
@@ -216,12 +250,15 @@ export function translateOpenAiToAnthropic(openAiBody) {
|
|
|
216
250
|
},
|
|
217
251
|
];
|
|
218
252
|
}
|
|
253
|
+
const targetModel = modelOverride || openAiBody?.model;
|
|
254
|
+
const caps = getCapabilitiesForModel(providerId, targetModel);
|
|
255
|
+
const ceiling = caps?.maxOutput > 0 ? caps.maxOutput : DEFAULT_MAX_TOKENS;
|
|
219
256
|
const result = {
|
|
220
257
|
model: openAiBody.model,
|
|
221
258
|
messages: anthropicMessages,
|
|
222
259
|
system: formattedSystem,
|
|
223
260
|
tools: tools && tools.length > 0 ? tools : undefined,
|
|
224
|
-
max_tokens: openAiBody
|
|
261
|
+
max_tokens: adjustMaxTokens(openAiBody, ceiling),
|
|
225
262
|
temperature: openAiBody.temperature,
|
|
226
263
|
stream: Boolean(openAiBody.stream),
|
|
227
264
|
};
|
|
@@ -35,8 +35,8 @@ export class AnthropicAdapter {
|
|
|
35
35
|
/**
|
|
36
36
|
* Convert OpenAI /v1/chat/completions payload to Anthropic /v1/messages payload
|
|
37
37
|
*/
|
|
38
|
-
static openAiToAnthropic(openAiBody) {
|
|
39
|
-
return translateOpenAiToAnthropic(openAiBody);
|
|
38
|
+
static openAiToAnthropic(openAiBody, modelOverride, providerId) {
|
|
39
|
+
return translateOpenAiToAnthropic(openAiBody, modelOverride, providerId);
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Convert OpenAI response chunk to Anthropic SSE event format
|
|
@@ -250,7 +250,12 @@ export function parseMimoFunctionAndParameters(inner, toolNames) {
|
|
|
250
250
|
export function parseAnyToolBlock(raw, toolNames) {
|
|
251
251
|
if (!raw || typeof raw !== "string")
|
|
252
252
|
return null;
|
|
253
|
-
|
|
253
|
+
let trimmed = raw.trim();
|
|
254
|
+
// Strip wrapping <tool_call>...</tool_call> if present
|
|
255
|
+
const toolCallMatch = /^<tool_call>([\s\S]*?)<\/tool_call>$/i.exec(trimmed);
|
|
256
|
+
if (toolCallMatch) {
|
|
257
|
+
trimmed = toolCallMatch[1].trim();
|
|
258
|
+
}
|
|
254
259
|
// 1. JSON object format: {"name": ..., "arguments"|"parameters": ...}
|
|
255
260
|
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
256
261
|
const jsonCall = callFromNamedJson(trimmed, toolNames);
|
|
@@ -62,8 +62,20 @@ export const MODEL_CAPABILITIES = {
|
|
|
62
62
|
"claude-haiku-5.5": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
63
63
|
"claude-haiku-5-5": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
64
64
|
"claude-sonnet-5": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
65
|
+
"claude-opus-4.8": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
66
|
+
"claude-opus-4-8": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
67
|
+
"claude-opus-4.6": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
68
|
+
"claude-opus-4-6": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
69
|
+
"claude-sonnet-4.6": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
70
|
+
"claude-sonnet-4-6": { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 },
|
|
65
71
|
"claude-3-7-sonnet": { vision: true, reasoning: true, search: true, thinkingFormat: "claude-budget", contextWindow: 200000, maxOutput: 64000 },
|
|
66
72
|
"claude-3.7-sonnet": { vision: true, reasoning: true, search: true, thinkingFormat: "claude-budget", contextWindow: 200000, maxOutput: 64000 },
|
|
73
|
+
"claude-3-5-sonnet": { vision: true, search: true, contextWindow: 200000, maxOutput: 8192 },
|
|
74
|
+
"claude-3.5-sonnet": { vision: true, search: true, contextWindow: 200000, maxOutput: 8192 },
|
|
75
|
+
"claude-3-5-haiku": { vision: true, search: true, contextWindow: 200000, maxOutput: 8192 },
|
|
76
|
+
"claude-3.5-haiku": { vision: true, search: true, contextWindow: 200000, maxOutput: 8192 },
|
|
77
|
+
"claude-3-opus": { vision: true, contextWindow: 200000, maxOutput: 4096 },
|
|
78
|
+
"claude-3-haiku": { vision: true, contextWindow: 200000, maxOutput: 4096 },
|
|
67
79
|
// GLM vision variants
|
|
68
80
|
"glm-5.3-flash": { vision: true, videoInput: true, pdf: true, reasoning: true, thinkingFormat: "zai", thinkingCanDisable: false, contextWindow: 1000000, maxOutput: 131072 },
|
|
69
81
|
"glm-4.6v": { vision: true, videoInput: true, reasoning: true, thinkingFormat: "zai", contextWindow: 128000, maxOutput: 32768 },
|
|
@@ -239,6 +239,7 @@ export const STANDARD_MODELS = {
|
|
|
239
239
|
// ── Common MITM / Agent Modes ──
|
|
240
240
|
"auto": "Auto (Agent Mode)",
|
|
241
241
|
"simple-task": "Simple Task",
|
|
242
|
+
"permission-classifier": "Permission Classifier",
|
|
242
243
|
"gpt-oss-120b": "GPT-OSS 120B",
|
|
243
244
|
};
|
|
244
245
|
// Suffix matcher: dates (8 digits), thinking tiers (high, medium, low, extra-low, thinking), version/tags (:free, -preview, -beta, -latest, @date, etc.)
|
|
@@ -32,21 +32,33 @@ export const PATTERN_CAPABILITIES = [
|
|
|
32
32
|
{ pattern: "*claude*haiku-5-5*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
33
33
|
{ pattern: "*claude*opus-5*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
34
34
|
{ pattern: "*claude*sonnet-5*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
35
|
-
{ pattern: "*claude*opus-4.
|
|
36
|
-
{ pattern: "*claude*opus-4
|
|
37
|
-
{ pattern: "*claude*opus-4.
|
|
38
|
-
{ pattern: "*claude*
|
|
39
|
-
{ pattern: "*claude*
|
|
35
|
+
{ pattern: "*claude*opus-4.8*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
36
|
+
{ pattern: "*claude*opus-4-8*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
37
|
+
{ pattern: "*claude*opus-4.7*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
38
|
+
{ pattern: "*claude*opus-4-7*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
39
|
+
{ pattern: "*claude*opus-4.6*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
40
|
+
{ pattern: "*claude*opus-4-6*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
41
|
+
{ pattern: "*claude*sonnet-4.7*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
42
|
+
{ pattern: "*claude*sonnet-4-7*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
43
|
+
{ pattern: "*claude*sonnet-4.6*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
44
|
+
{ pattern: "*claude*sonnet-4-6*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
40
45
|
{ pattern: "*claude*haiku-6*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
41
46
|
{ pattern: "*claude*haiku-5*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
42
|
-
{ pattern: "*claude*haiku-4*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-
|
|
43
|
-
{ pattern: "*claude*
|
|
44
|
-
{ pattern: "*claude*
|
|
45
|
-
{ pattern: "*claude*sonnet*", caps: { vision: true,
|
|
46
|
-
{ pattern: "*claude*3
|
|
47
|
-
{ pattern: "*claude*3
|
|
48
|
-
{ pattern: "*claude-
|
|
49
|
-
{ pattern: "*claude*", caps: { vision: true,
|
|
47
|
+
{ pattern: "*claude*haiku-4*", caps: { vision: true, pdf: true, reasoning: true, search: true, thinkingFormat: "claude-adaptive", contextWindow: 1000000, maxOutput: 128000 } },
|
|
48
|
+
{ pattern: "*claude*3.7*", caps: { vision: true, reasoning: true, search: true, thinkingFormat: "claude-budget", contextWindow: 200000, maxOutput: 64000 } },
|
|
49
|
+
{ pattern: "*claude*3-7*", caps: { vision: true, reasoning: true, search: true, thinkingFormat: "claude-budget", contextWindow: 200000, maxOutput: 64000 } },
|
|
50
|
+
{ pattern: "*claude*3.5*sonnet*", caps: { vision: true, search: true, contextWindow: 200000, maxOutput: 8192 } },
|
|
51
|
+
{ pattern: "*claude*3-5*sonnet*", caps: { vision: true, search: true, contextWindow: 200000, maxOutput: 8192 } },
|
|
52
|
+
{ pattern: "*claude*3.5*haiku*", caps: { vision: true, search: true, contextWindow: 200000, maxOutput: 8192 } },
|
|
53
|
+
{ pattern: "*claude*3-5*haiku*", caps: { vision: true, search: true, contextWindow: 200000, maxOutput: 8192 } },
|
|
54
|
+
{ pattern: "*claude*3*opus*", caps: { vision: true, contextWindow: 200000, maxOutput: 4096 } },
|
|
55
|
+
{ pattern: "*claude*3*sonnet*", caps: { vision: true, contextWindow: 200000, maxOutput: 4096 } },
|
|
56
|
+
{ pattern: "*claude*3*haiku*", caps: { vision: true, contextWindow: 200000, maxOutput: 4096 } },
|
|
57
|
+
{ pattern: "*claude-3*", caps: { vision: true, contextWindow: 200000, maxOutput: 4096 } },
|
|
58
|
+
{ pattern: "*claude*haiku*", caps: { vision: true, reasoning: true, search: true, thinkingFormat: "claude-budget", contextWindow: 200000, maxOutput: 8192 } },
|
|
59
|
+
{ pattern: "*claude*opus*", caps: { vision: true, reasoning: true, search: true, thinkingFormat: "claude-budget", contextWindow: 200000, maxOutput: 64000 } },
|
|
60
|
+
{ pattern: "*claude*sonnet*", caps: { vision: true, reasoning: true, search: true, thinkingFormat: "claude-budget", contextWindow: 200000, maxOutput: 64000 } },
|
|
61
|
+
{ pattern: "*claude*", caps: { vision: true, reasoning: true, search: true, thinkingFormat: "claude-budget", contextWindow: 200000, maxOutput: 64000 } },
|
|
50
62
|
// ── Gemini ──
|
|
51
63
|
{ pattern: "*gemini*image*", caps: { vision: true, imageOutput: true, contextWindow: 1048576 } },
|
|
52
64
|
{ pattern: "*gemini-4*", caps: { vision: true, audioInput: true, videoInput: true, reasoning: true, search: true, thinkingFormat: "gemini-level", thinkingCanDisable: false, contextWindow: 1048576, maxOutput: 65536 } },
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderRegistry } from "../../providers/core/registry.js";
|
|
2
2
|
import { getRegistryProvider } from "../../shared/constants/providerRegistry.js";
|
|
3
|
+
import { AccountModelRepository } from "../../storage/repositories/accountModelRepo.js";
|
|
4
|
+
import { ProviderRepository } from "../../storage/repositories/providerRepo.js";
|
|
3
5
|
import { ensureFreshCredentials } from "../usage/tokenHelper.js";
|
|
4
|
-
import { ProviderRegistry } from "../../providers/core/registry.js";
|
|
5
6
|
import { resolveCandidateUrls } from "./urlResolver.js";
|
|
6
|
-
import { AccountModelRepository } from "../../storage/repositories/accountModelRepo.js";
|
|
7
7
|
export { resolveCandidateUrls } from "./urlResolver.js";
|
|
8
8
|
export { extractModelsFromPayload } from "./payloadExtractor.js";
|
|
9
9
|
/**
|
|
@@ -201,9 +201,14 @@ export async function scanProviderModels(options) {
|
|
|
201
201
|
failedAccounts: failedAccounts.length > 0 ? failedAccounts : undefined,
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
|
-
// Graceful fallback to static catalog models for Kiro / Amazon Q if available
|
|
204
|
+
// Graceful fallback to static catalog models for Kiro / Amazon Q / Gemini CLI if available
|
|
205
205
|
if (modelsById.size === 0 &&
|
|
206
|
-
(providerId === "kiro" ||
|
|
206
|
+
(providerId === "kiro" ||
|
|
207
|
+
providerId === "amazon-q" ||
|
|
208
|
+
providerId === "gemini-cli" ||
|
|
209
|
+
registryItem?.id === "kiro" ||
|
|
210
|
+
registryItem?.id === "amazon-q" ||
|
|
211
|
+
registryItem?.id === "gemini-cli") &&
|
|
207
212
|
registryItem?.models?.length) {
|
|
208
213
|
for (const m of registryItem.models) {
|
|
209
214
|
modelsById.set(m.id, {
|
package/dist/mitm/manager.js
CHANGED
|
@@ -63,7 +63,7 @@ export class MitmManager {
|
|
|
63
63
|
// Pre-flight check: is port already occupied?
|
|
64
64
|
const portOwner = await inspectPortOwner(targetPort);
|
|
65
65
|
if (portOwner.inUse) {
|
|
66
|
-
const isTimeWait = portOwner.pid === 0 || Boolean(portOwner.processName?.toLowerCase().includes("idle"));
|
|
66
|
+
const isTimeWait = Boolean(portOwner.isTransient) || portOwner.pid === 0 || Boolean(portOwner.processName?.toLowerCase().includes("idle"));
|
|
67
67
|
if (portOwner.pid === process.pid || isTimeWait) {
|
|
68
68
|
// Port is held by this Mapigate process or in transient TCP TIME_WAIT from a recent restart.
|
|
69
69
|
// Polling to let socket release cleanly.
|
|
@@ -130,6 +130,12 @@ function inspectPortOwnerNetstat(port) {
|
|
|
130
130
|
* Inspect the process currently occupying the given TCP port.
|
|
131
131
|
*/
|
|
132
132
|
export async function inspectPortOwner(port) {
|
|
133
|
+
// Fast path: Probe whether the port is free to bind on 0.0.0.0.
|
|
134
|
+
// If the socket binds successfully, no process is listening or blocking the port.
|
|
135
|
+
const isFree = await checkPortFree(port);
|
|
136
|
+
if (isFree) {
|
|
137
|
+
return { port, inUse: false };
|
|
138
|
+
}
|
|
133
139
|
const isWin = process.platform === "win32";
|
|
134
140
|
if (isWin) {
|
|
135
141
|
try {
|
|
@@ -144,6 +150,8 @@ if ($c) {
|
|
|
144
150
|
InUse = $true
|
|
145
151
|
Pid = [int]$c.OwningProcess
|
|
146
152
|
ProcessName = if ($p) { [string]$p.ProcessName } else { "" }
|
|
153
|
+
State = [string]$c.State
|
|
154
|
+
ProcessExists = [bool]$p
|
|
147
155
|
} | ConvertTo-Json -Compress
|
|
148
156
|
} else {
|
|
149
157
|
@{ InUse = $false } | ConvertTo-Json -Compress
|
|
@@ -163,8 +171,12 @@ if ($c) {
|
|
|
163
171
|
const parsed = JSON.parse(psOutput);
|
|
164
172
|
if (parsed.InUse) {
|
|
165
173
|
const pid = parsed.Pid;
|
|
166
|
-
const
|
|
167
|
-
|
|
174
|
+
const state = parsed.State || "";
|
|
175
|
+
const processExists = parsed.ProcessExists !== false;
|
|
176
|
+
const isTransientState = ["TimeWait", "FinWait1", "FinWait2", "CloseWait", "Closing", "LastAck"].includes(state);
|
|
177
|
+
const isDeadProcess = !processExists && pid > 4;
|
|
178
|
+
const isTimeWait = pid === 0 || isTransientState || isDeadProcess;
|
|
179
|
+
const processName = isTimeWait
|
|
168
180
|
? "Idle (TIME_WAIT)"
|
|
169
181
|
: parsed.ProcessName || (pid <= 4 ? "System" : "unknown");
|
|
170
182
|
const isSystemProcess = !isTimeWait && isProtectedSystemProcess(pid, processName);
|
|
@@ -176,10 +188,11 @@ if ($c) {
|
|
|
176
188
|
return {
|
|
177
189
|
port,
|
|
178
190
|
inUse: true,
|
|
179
|
-
pid,
|
|
191
|
+
pid: isTimeWait && isDeadProcess ? 0 : pid,
|
|
180
192
|
processName,
|
|
181
193
|
isSystemProcess,
|
|
182
194
|
remediationHint: hint,
|
|
195
|
+
isTransient: isTimeWait,
|
|
183
196
|
};
|
|
184
197
|
}
|
|
185
198
|
}
|
|
@@ -212,22 +225,18 @@ if ($c) {
|
|
|
212
225
|
processName,
|
|
213
226
|
isSystemProcess,
|
|
214
227
|
remediationHint: hint,
|
|
228
|
+
isTransient: isTimeWait,
|
|
215
229
|
};
|
|
216
230
|
}
|
|
217
|
-
//
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
isSystemProcess: true,
|
|
227
|
-
remediationHint: SYSTEM_REMEDIATION_HINT,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
return { port, inUse: false };
|
|
231
|
+
// Port in use but PID couldn't be resolved (likely elevated system driver HTTP.sys)
|
|
232
|
+
return {
|
|
233
|
+
port,
|
|
234
|
+
inUse: true,
|
|
235
|
+
pid: 4,
|
|
236
|
+
processName: "System",
|
|
237
|
+
isSystemProcess: true,
|
|
238
|
+
remediationHint: SYSTEM_REMEDIATION_HINT,
|
|
239
|
+
};
|
|
231
240
|
}
|
|
232
241
|
// POSIX (Linux/macOS)
|
|
233
242
|
try {
|
|
@@ -288,13 +297,23 @@ export async function killProcessByPid(pid, _force = true, knownProcessName) {
|
|
|
288
297
|
const isWin = process.platform === "win32";
|
|
289
298
|
if (isWin) {
|
|
290
299
|
await new Promise((resolve, reject) => {
|
|
291
|
-
exec(`taskkill /F /PID ${pid}`, { windowsHide: true }, (err) => {
|
|
300
|
+
exec(`taskkill /F /PID ${pid}`, { windowsHide: true }, (err, _stdout, stderr) => {
|
|
292
301
|
if (!err)
|
|
293
302
|
return resolve();
|
|
303
|
+
const errStr = `${err.message} ${stderr || ""}`.toLowerCase();
|
|
304
|
+
if (errStr.includes("not found")) {
|
|
305
|
+
// Process has already terminated
|
|
306
|
+
return resolve();
|
|
307
|
+
}
|
|
294
308
|
// Fallback to PowerShell Stop-Process
|
|
295
|
-
exec(`powershell -NoProfile -NonInteractive -Command "Stop-Process -Id ${pid} -Force"`, { windowsHide: true }, (psErr) => {
|
|
309
|
+
exec(`powershell -NoProfile -NonInteractive -Command "Stop-Process -Id ${pid} -Force"`, { windowsHide: true }, (psErr, _psOut, psStderr) => {
|
|
296
310
|
if (!psErr)
|
|
297
311
|
return resolve();
|
|
312
|
+
const psErrStr = `${psErr.message} ${psStderr || ""}`.toLowerCase();
|
|
313
|
+
if (psErrStr.includes("cannot find") || psErrStr.includes("not found")) {
|
|
314
|
+
// Process has already terminated
|
|
315
|
+
return resolve();
|
|
316
|
+
}
|
|
298
317
|
reject(new Error(`Failed to terminate PID ${pid}: ${err.message}`));
|
|
299
318
|
});
|
|
300
319
|
});
|
|
@@ -2,7 +2,7 @@ import { OpenAiCompatibleProvider } from "../../core/base/openAiProvider.js";
|
|
|
2
2
|
import { metadata } from "./metadata.js";
|
|
3
3
|
import { getMimoUsage } from "../../runtime/mimo/quota.js";
|
|
4
4
|
import { AnthropicAdapter } from "../../../core/adapters/anthropicAdapter.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createStreamToolCallRescuer, } from "../../../core/adapters/helpers/toolCallRescue.js";
|
|
6
6
|
export class XiaomiTokenplanProvider extends OpenAiCompatibleProvider {
|
|
7
7
|
id = metadata.id;
|
|
8
8
|
name = metadata.name;
|
|
@@ -19,7 +19,7 @@ export class XiaomiTokenplanProvider extends OpenAiCompatibleProvider {
|
|
|
19
19
|
return { ...context.body, model: context.targetModel };
|
|
20
20
|
}
|
|
21
21
|
return {
|
|
22
|
-
...AnthropicAdapter.openAiToAnthropic(context.body),
|
|
22
|
+
...AnthropicAdapter.openAiToAnthropic(context.body, context.targetModel, context.provider?.id || this.id),
|
|
23
23
|
model: context.targetModel,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
@@ -66,12 +66,37 @@ export class XiaomiTokenplanProvider extends OpenAiCompatibleProvider {
|
|
|
66
66
|
return chunk;
|
|
67
67
|
const choice = chunk.choices[0];
|
|
68
68
|
const delta = choice?.delta;
|
|
69
|
-
if (!delta?.content || typeof delta.content !== "string")
|
|
70
|
-
return chunk;
|
|
71
69
|
const ctx = context;
|
|
72
70
|
if (!ctx._toolRescuer) {
|
|
73
|
-
|
|
71
|
+
const tools = context.req?.body?.tools || context.body?.tools;
|
|
72
|
+
const toolNames = Array.isArray(tools)
|
|
73
|
+
? new Set(tools.map((t) => t.function?.name || t.name).filter(Boolean))
|
|
74
|
+
: undefined;
|
|
75
|
+
ctx._toolRescuer = createStreamToolCallRescuer(toolNames);
|
|
76
|
+
}
|
|
77
|
+
if (choice.finish_reason) {
|
|
78
|
+
const { calls, cleanText } = ctx._toolRescuer.flush();
|
|
79
|
+
if (calls.length > 0) {
|
|
80
|
+
if (!choice.delta)
|
|
81
|
+
choice.delta = {};
|
|
82
|
+
choice.delta.tool_calls = calls.map((c, idx) => ({
|
|
83
|
+
index: idx,
|
|
84
|
+
id: `call_mimo_${Date.now()}_${idx}`,
|
|
85
|
+
type: "function",
|
|
86
|
+
function: {
|
|
87
|
+
name: c.name,
|
|
88
|
+
arguments: c.arguments,
|
|
89
|
+
},
|
|
90
|
+
}));
|
|
91
|
+
choice.finish_reason = "tool_calls";
|
|
92
|
+
}
|
|
93
|
+
if (cleanText && choice.delta) {
|
|
94
|
+
choice.delta.content = (choice.delta.content || "") + cleanText;
|
|
95
|
+
}
|
|
96
|
+
return chunk;
|
|
74
97
|
}
|
|
98
|
+
if (!delta?.content || typeof delta.content !== "string")
|
|
99
|
+
return chunk;
|
|
75
100
|
const { calls, cleanText } = ctx._toolRescuer.feed(delta.content);
|
|
76
101
|
if (calls.length > 0) {
|
|
77
102
|
delta.tool_calls = calls.map((c, idx) => ({
|
|
@@ -92,15 +117,22 @@ export class XiaomiTokenplanProvider extends OpenAiCompatibleProvider {
|
|
|
92
117
|
delta.content = cleanText;
|
|
93
118
|
return chunk;
|
|
94
119
|
}
|
|
95
|
-
transformResponseBody(body,
|
|
120
|
+
transformResponseBody(body, context) {
|
|
96
121
|
if (!body || typeof body !== "object")
|
|
97
122
|
return body;
|
|
98
123
|
const choice = body.choices?.[0];
|
|
99
124
|
const msg = choice?.message;
|
|
100
|
-
if (msg?.content && typeof msg.content === "string"
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
125
|
+
if (msg?.content && typeof msg.content === "string") {
|
|
126
|
+
const tools = context.req?.body?.tools || context.body?.tools;
|
|
127
|
+
const toolNames = Array.isArray(tools)
|
|
128
|
+
? new Set(tools.map((t) => t.function?.name || t.name).filter(Boolean))
|
|
129
|
+
: undefined;
|
|
130
|
+
const rescuer = createStreamToolCallRescuer(toolNames);
|
|
131
|
+
const r1 = rescuer.feed(msg.content);
|
|
132
|
+
const r2 = rescuer.flush();
|
|
133
|
+
const allCalls = [...r1.calls, ...r2.calls];
|
|
134
|
+
if (allCalls.length > 0) {
|
|
135
|
+
msg.tool_calls = allCalls.map((c, idx) => ({
|
|
104
136
|
id: `call_mimo_${Date.now()}_${idx}`,
|
|
105
137
|
type: "function",
|
|
106
138
|
function: {
|
|
@@ -108,7 +140,8 @@ export class XiaomiTokenplanProvider extends OpenAiCompatibleProvider {
|
|
|
108
140
|
arguments: c.arguments,
|
|
109
141
|
},
|
|
110
142
|
}));
|
|
111
|
-
|
|
143
|
+
const combinedClean = [r1.cleanText, r2.cleanText].filter(Boolean).join("");
|
|
144
|
+
msg.content = combinedClean.trim() || null;
|
|
112
145
|
if (choice.finish_reason === "stop" || !choice.finish_reason) {
|
|
113
146
|
choice.finish_reason = "tool_calls";
|
|
114
147
|
}
|
|
@@ -43,7 +43,7 @@ export class AnthropicCompatibleProvider extends BaseProvider {
|
|
|
43
43
|
transformRequestBody(context) {
|
|
44
44
|
const modelToUse = this.resolveUpstreamModelId(context);
|
|
45
45
|
if (context.clientFormat === "openai") {
|
|
46
|
-
const converted = AnthropicAdapter.openAiToAnthropic(context.body);
|
|
46
|
+
const converted = AnthropicAdapter.openAiToAnthropic(context.body, modelToUse || context.targetModel, context.provider?.id || this.id);
|
|
47
47
|
converted.model = modelToUse;
|
|
48
48
|
return converted;
|
|
49
49
|
}
|
|
@@ -10,6 +10,7 @@ import { cleanJSONSchemaForAntigravity, normalizeGeminiContents, isGemini4Model,
|
|
|
10
10
|
export { ANTIGRAVITY_REQUEST_BLACKLIST, stripBlacklisted };
|
|
11
11
|
import { storeGeminiThoughtSignature, getGeminiThoughtSignatureSync, } from "./thoughtSignatureStore.js";
|
|
12
12
|
import { sanitizeToolArguments } from "../../../shared/utils/toolArgsSanitizer.js";
|
|
13
|
+
import { extractPlainTextContent } from "../../../shared/utils/extractText.js";
|
|
13
14
|
function resolveAccountCredentials(context) {
|
|
14
15
|
const account = context.account;
|
|
15
16
|
const rawKey = account?.rawApiKey || account?.apiKey || context.provider?.apiKey || "";
|
|
@@ -117,12 +118,29 @@ export async function executeAntigravity(context, providerInstance) {
|
|
|
117
118
|
const rawMessages = Array.isArray(body.messages) ? body.messages : [];
|
|
118
119
|
const messages = rawMessages;
|
|
119
120
|
let systemText;
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const systemParts = [];
|
|
122
|
+
for (const m of messages) {
|
|
123
|
+
if (m && (m.role === "system" || m.role === "developer")) {
|
|
124
|
+
const txt = extractPlainTextContent(m.content);
|
|
125
|
+
if (txt)
|
|
126
|
+
systemParts.push(txt);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (systemParts.length > 0) {
|
|
130
|
+
systemText = systemParts.join("\n\n");
|
|
131
|
+
}
|
|
132
|
+
else if (body.system != null) {
|
|
133
|
+
const sys = extractPlainTextContent(body.system);
|
|
134
|
+
if (sys)
|
|
135
|
+
systemText = sys;
|
|
123
136
|
}
|
|
124
|
-
else if (
|
|
125
|
-
|
|
137
|
+
else if (Array.isArray(body.systemInstruction?.parts)) {
|
|
138
|
+
const sys = body.systemInstruction.parts
|
|
139
|
+
.map((p) => (typeof p?.text === "string" ? p.text : ""))
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.join("\n\n");
|
|
142
|
+
if (sys)
|
|
143
|
+
systemText = sys;
|
|
126
144
|
}
|
|
127
145
|
if (systemText) {
|
|
128
146
|
for (const { from, to } of ANTIGRAVITY_PROMPT_REWRITES) {
|
|
@@ -151,7 +169,7 @@ export async function executeAntigravity(context, providerInstance) {
|
|
|
151
169
|
const rawContents = [];
|
|
152
170
|
for (let i = 0; i < messages.length; i++) {
|
|
153
171
|
const m = messages[i];
|
|
154
|
-
if (m.role === "system")
|
|
172
|
+
if (m.role === "system" || m.role === "developer")
|
|
155
173
|
continue;
|
|
156
174
|
if (m.role === "user") {
|
|
157
175
|
const parts = convertOpenAIContentToParts(m.content);
|
|
@@ -17,7 +17,7 @@ export class BedrockProvider extends BaseProvider {
|
|
|
17
17
|
transformRequestBody(context) {
|
|
18
18
|
let body = context.body;
|
|
19
19
|
if (context.clientFormat === "openai") {
|
|
20
|
-
body = AnthropicAdapter.openAiToAnthropic(body);
|
|
20
|
+
body = AnthropicAdapter.openAiToAnthropic(body, context.targetModel, context.provider?.id || this.id);
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
body = { ...body };
|
|
@@ -125,7 +125,12 @@ export class GeminiCliProvider extends OpenAiCompatibleProvider {
|
|
|
125
125
|
return {
|
|
126
126
|
success: true,
|
|
127
127
|
endpointUrl: ep.url,
|
|
128
|
-
|
|
128
|
+
models: metadata.models.map((m) => ({
|
|
129
|
+
id: m.id,
|
|
130
|
+
name: m.name,
|
|
131
|
+
contextLength: m.contextLength,
|
|
132
|
+
})),
|
|
133
|
+
count: metadata.models.length,
|
|
129
134
|
};
|
|
130
135
|
}
|
|
131
136
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAiCompatibleProvider } from "../../core/base/openAiProvider.js";
|
|
2
2
|
import { getMimoUsage } from "./quota.js";
|
|
3
|
-
import {
|
|
3
|
+
import { createStreamToolCallRescuer, } from "../../../core/adapters/helpers/toolCallRescue.js";
|
|
4
4
|
export class MimoProvider extends OpenAiCompatibleProvider {
|
|
5
5
|
id = "mimo";
|
|
6
6
|
name = "Xiaomi MiMo";
|
|
@@ -16,12 +16,37 @@ export class MimoProvider extends OpenAiCompatibleProvider {
|
|
|
16
16
|
return chunk;
|
|
17
17
|
const choice = chunk.choices[0];
|
|
18
18
|
const delta = choice?.delta;
|
|
19
|
-
if (!delta?.content || typeof delta.content !== "string")
|
|
20
|
-
return chunk;
|
|
21
19
|
const ctx = context;
|
|
22
20
|
if (!ctx._toolRescuer) {
|
|
23
|
-
|
|
21
|
+
const tools = context.req?.body?.tools || context.body?.tools;
|
|
22
|
+
const toolNames = Array.isArray(tools)
|
|
23
|
+
? new Set(tools.map((t) => t.function?.name || t.name).filter(Boolean))
|
|
24
|
+
: undefined;
|
|
25
|
+
ctx._toolRescuer = createStreamToolCallRescuer(toolNames);
|
|
26
|
+
}
|
|
27
|
+
if (choice.finish_reason) {
|
|
28
|
+
const { calls, cleanText } = ctx._toolRescuer.flush();
|
|
29
|
+
if (calls.length > 0) {
|
|
30
|
+
if (!choice.delta)
|
|
31
|
+
choice.delta = {};
|
|
32
|
+
choice.delta.tool_calls = calls.map((c, idx) => ({
|
|
33
|
+
index: idx,
|
|
34
|
+
id: `call_mimo_${Date.now()}_${idx}`,
|
|
35
|
+
type: "function",
|
|
36
|
+
function: {
|
|
37
|
+
name: c.name,
|
|
38
|
+
arguments: c.arguments,
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
choice.finish_reason = "tool_calls";
|
|
42
|
+
}
|
|
43
|
+
if (cleanText && choice.delta) {
|
|
44
|
+
choice.delta.content = (choice.delta.content || "") + cleanText;
|
|
45
|
+
}
|
|
46
|
+
return chunk;
|
|
24
47
|
}
|
|
48
|
+
if (!delta?.content || typeof delta.content !== "string")
|
|
49
|
+
return chunk;
|
|
25
50
|
const { calls, cleanText } = ctx._toolRescuer.feed(delta.content);
|
|
26
51
|
if (calls.length > 0) {
|
|
27
52
|
delta.tool_calls = calls.map((c, idx) => ({
|
|
@@ -42,15 +67,22 @@ export class MimoProvider extends OpenAiCompatibleProvider {
|
|
|
42
67
|
delta.content = cleanText;
|
|
43
68
|
return chunk;
|
|
44
69
|
}
|
|
45
|
-
transformResponseBody(body,
|
|
70
|
+
transformResponseBody(body, context) {
|
|
46
71
|
if (!body || typeof body !== "object")
|
|
47
72
|
return body;
|
|
48
73
|
const choice = body.choices?.[0];
|
|
49
74
|
const msg = choice?.message;
|
|
50
|
-
if (msg?.content && typeof msg.content === "string"
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
if (msg?.content && typeof msg.content === "string") {
|
|
76
|
+
const tools = context.req?.body?.tools || context.body?.tools;
|
|
77
|
+
const toolNames = Array.isArray(tools)
|
|
78
|
+
? new Set(tools.map((t) => t.function?.name || t.name).filter(Boolean))
|
|
79
|
+
: undefined;
|
|
80
|
+
const rescuer = createStreamToolCallRescuer(toolNames);
|
|
81
|
+
const r1 = rescuer.feed(msg.content);
|
|
82
|
+
const r2 = rescuer.flush();
|
|
83
|
+
const allCalls = [...r1.calls, ...r2.calls];
|
|
84
|
+
if (allCalls.length > 0) {
|
|
85
|
+
msg.tool_calls = allCalls.map((c, idx) => ({
|
|
54
86
|
id: `call_mimo_${Date.now()}_${idx}`,
|
|
55
87
|
type: "function",
|
|
56
88
|
function: {
|
|
@@ -58,7 +90,8 @@ export class MimoProvider extends OpenAiCompatibleProvider {
|
|
|
58
90
|
arguments: c.arguments,
|
|
59
91
|
},
|
|
60
92
|
}));
|
|
61
|
-
|
|
93
|
+
const combinedClean = [r1.cleanText, r2.cleanText].filter(Boolean).join("");
|
|
94
|
+
msg.content = combinedClean.trim() || null;
|
|
62
95
|
if (choice.finish_reason === "stop" || !choice.finish_reason) {
|
|
63
96
|
choice.finish_reason = "tool_calls";
|
|
64
97
|
}
|