fix(claude-kiro): 修复工具调用token计算和web搜索工具过滤问题
- 过滤web_search/websearch工具调用 - 将工具调用的name和input内容计入totalContent用于token计算 - 调整总上下文token限制为160k - 禁用provider_pools.json.example中所有provider的健康检查 - 更新api-potluck插件描述添加管理端和用户端链接
This commit is contained in:
parent
ff3be72c49
commit
340d6f9e10
3 changed files with 46 additions and 20 deletions
|
|
@ -5,7 +5,7 @@
|
|||
"OPENAI_API_KEY": "sk-openai-key1",
|
||||
"OPENAI_BASE_URL": "https://api.openai.com/v1",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"notSupportedModels": ["gpt-4-turbo"],
|
||||
"uuid": "2f579c65-d3c5-41b1-9985-9f6e3d7bf39c",
|
||||
"isHealthy": true,
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
"OPENAI_API_KEY": "sk-openai-key2",
|
||||
"OPENAI_BASE_URL": "https://api.openai.com/v1",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"notSupportedModels": ["gpt-4-turbo", "gpt-4"],
|
||||
"uuid": "e284628d-302f-456d-91f3-6095386fb3b8",
|
||||
"isHealthy": true,
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
"OPENAI_API_KEY": "sk-openai-key",
|
||||
"OPENAI_BASE_URL": "https://api.openai.com/v1",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"uuid": "e284628d-302f-456d-91f3-609538678968",
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
"GEMINI_OAUTH_CREDS_FILE_PATH": "./credentials1.json",
|
||||
"PROJECT_ID": "your-project-id-1",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"uuid": "ac200154-26b8-4f5f-8650-e8cc738b06e3",
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
"GEMINI_OAUTH_CREDS_FILE_PATH": "./credentials2.json",
|
||||
"PROJECT_ID": "your-project-id-2",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"uuid": "4f8afcc2-a9bb-4b96-bb50-3b9667a71f54",
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
|
|
@ -83,7 +83,7 @@
|
|||
"CLAUDE_API_KEY": "sk-claude-key1",
|
||||
"CLAUDE_BASE_URL": "https://api.anthropic.com",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"uuid": "bb87047a-3b1d-4249-adbb-1087ecd58128",
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
|
|
@ -97,7 +97,7 @@
|
|||
"CLAUDE_API_KEY": "sk-claude-key2",
|
||||
"CLAUDE_BASE_URL": "https://api.anthropic.com",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"uuid": "7c2002c6-122a-4db0-af06-8a0ff433801a",
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
|
|
@ -113,7 +113,7 @@
|
|||
"KIRO_OAUTH_CREDS_FILE_PATH": "./kiro_creds1.json",
|
||||
"uuid": "2c69d0ac-b86f-43d8-9d17-0d300afc5cfd",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
"lastUsed": null,
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
"KIRO_OAUTH_CREDS_FILE_PATH": "./kiro_creds2.json",
|
||||
"uuid": "7482abe6-8083-4288-bb7d-d8ecb7c461e2",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
"lastUsed": null,
|
||||
|
|
@ -141,7 +141,7 @@
|
|||
"QWEN_OAUTH_CREDS_FILE_PATH": "./qwen_creds.json",
|
||||
"uuid": "658a2114-c4c9-d713-b8d4-ceabf0e0bf18",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
"lastUsed": null,
|
||||
|
|
@ -157,7 +157,7 @@
|
|||
"PROJECT_ID": "antigravity-project-1",
|
||||
"uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
"lastUsed": null,
|
||||
|
|
@ -171,7 +171,7 @@
|
|||
"PROJECT_ID": "antigravity-project-2",
|
||||
"uuid": "f0e9d8c7-b6a5-4321-fedc-ba9876543210",
|
||||
"checkModelName": null,
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
"lastUsed": null,
|
||||
|
|
@ -187,7 +187,7 @@
|
|||
"IFLOW_BASE_URL": "https://apis.iflow.cn/v1",
|
||||
"uuid": "11223344-5566-7788-99aa-bbccddeeff00",
|
||||
"checkModelName": "gpt-4o",
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
"lastUsed": null,
|
||||
|
|
@ -201,7 +201,7 @@
|
|||
"IFLOW_BASE_URL": "https://apis.iflow.cn/v1",
|
||||
"uuid": "aabbccdd-eeff-0011-2233-445566778899",
|
||||
"checkModelName": "gpt-4o",
|
||||
"checkHealth": true,
|
||||
"checkHealth": false,
|
||||
"isHealthy": true,
|
||||
"isDisabled": false,
|
||||
"lastUsed": null,
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import { handlePotluckApiRoutes, handlePotluckUserApiRoutes, startHealthCheckSch
|
|||
const apiPotluckPlugin = {
|
||||
name: 'api-potluck',
|
||||
version: '1.0.1',
|
||||
description: 'API 大锅饭 - Key 管理和用量统计插件',
|
||||
description: 'API 大锅饭 - Key 管理和用量统计插件<br>管理端:<a href="potluck.html" target="_blank">potluck.html</a><br>用户端:<a href="potluck-user.html" target="_blank">potluck-user.html</a>',
|
||||
|
||||
// 插件类型:认证插件
|
||||
type: 'auth',
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ const KIRO_CONSTANTS = {
|
|||
AUTH_METHOD_SOCIAL: 'social',
|
||||
CHAT_TRIGGER_TYPE_MANUAL: 'MANUAL',
|
||||
ORIGIN_AI_EDITOR: 'AI_EDITOR',
|
||||
TOTAL_CONTEXT_TOKENS: 200000, // 总上下文 200k tokens
|
||||
TOTAL_CONTEXT_TOKENS: 160000, // 总上下文 160k tokens
|
||||
};
|
||||
|
||||
// 从 provider-models.js 获取支持的模型列表
|
||||
|
|
@ -631,9 +631,23 @@ async initializeAuth(forceRefresh = false) {
|
|||
|
||||
const codewhispererModel = MODEL_MAPPING[model] || MODEL_MAPPING[this.modelName];
|
||||
|
||||
// 动态压缩 tools(保留全部工具)
|
||||
// 动态压缩 tools(保留全部工具,但过滤掉 web_search/websearch)
|
||||
let toolsContext = {};
|
||||
if (tools && Array.isArray(tools) && tools.length > 0) {
|
||||
// 过滤掉 web_search 或 websearch 工具(忽略大小写)
|
||||
const filteredTools = tools.filter(tool => {
|
||||
const name = (tool.name || '').toLowerCase();
|
||||
const shouldIgnore = name === 'web_search' || name === 'websearch';
|
||||
if (shouldIgnore) {
|
||||
console.log(`[Kiro] Ignoring tool: ${tool.name}`);
|
||||
}
|
||||
return !shouldIgnore;
|
||||
});
|
||||
|
||||
if (filteredTools.length === 0) {
|
||||
// 所有工具都被过滤掉了,不添加 tools 上下文
|
||||
console.log('[Kiro] All tools were filtered out');
|
||||
} else {
|
||||
const TARGET_SIZE = 20000;
|
||||
|
||||
const simplifySchema = (schema) => {
|
||||
|
|
@ -653,7 +667,7 @@ async initializeAuth(forceRefresh = false) {
|
|||
};
|
||||
|
||||
const buildTools = (maxDescLen, useSimplifiedSchema) => {
|
||||
return tools.map(tool => {
|
||||
return filteredTools.map(tool => {
|
||||
let desc = tool.description || "";
|
||||
if (maxDescLen !== null && desc.length > maxDescLen) {
|
||||
desc = desc.substring(0, maxDescLen) + "...";
|
||||
|
|
@ -701,10 +715,11 @@ async initializeAuth(forceRefresh = false) {
|
|||
size = JSON.stringify(kiroTools).length;
|
||||
}
|
||||
}
|
||||
console.log(`[Kiro] Tools compressed: ${originalSize} -> ${size} bytes (${tools.length} tools)`);
|
||||
console.log(`[Kiro] Tools compressed: ${originalSize} -> ${size} bytes (${filteredTools.length} tools)`);
|
||||
}
|
||||
|
||||
toolsContext = { tools: kiroTools };
|
||||
}
|
||||
}
|
||||
|
||||
const history = [];
|
||||
|
|
@ -1562,6 +1577,13 @@ async initializeAuth(forceRefresh = false) {
|
|||
console.log(`[Kiro] Received contextUsagePercentage: ${contextUsagePercentage}%`);
|
||||
} else if (event.type === 'toolUse') {
|
||||
const tc = event.toolUse;
|
||||
// 统计工具调用的内容到 totalContent(用于 token 计算)
|
||||
if (tc.name) {
|
||||
totalContent += tc.name;
|
||||
}
|
||||
if (tc.input) {
|
||||
totalContent += tc.input;
|
||||
}
|
||||
// 工具调用事件(包含 name 和 toolUseId)
|
||||
if (tc.name && tc.toolUseId) {
|
||||
// 检查是否是同一个工具调用的续传(相同 toolUseId)
|
||||
|
|
@ -1597,6 +1619,10 @@ async initializeAuth(forceRefresh = false) {
|
|||
}
|
||||
} else if (event.type === 'toolUseInput') {
|
||||
// 工具调用的 input 续传事件
|
||||
// 统计 input 内容到 totalContent(用于 token 计算)
|
||||
if (event.input) {
|
||||
totalContent += event.input;
|
||||
}
|
||||
if (currentToolCall) {
|
||||
currentToolCall.input += event.input || '';
|
||||
}
|
||||
|
|
@ -1672,7 +1698,7 @@ async initializeAuth(forceRefresh = false) {
|
|||
// 如果有 contextUsagePercentage,使用它来计算 token
|
||||
// 总上下文 200k tokens,通过百分比计算总使用量,再减去输入 token 得到输出 token
|
||||
let totalTokens = 0;
|
||||
if (contextUsagePercentage !== null && contextUsagePercentage > 0) {
|
||||
if (contextUsagePercentage !== null && contextUsagePercentage > 0 && true) {
|
||||
const totalContextTokens = KIRO_CONSTANTS.TOTAL_CONTEXT_TOKENS;
|
||||
// totalUsedTokens 就是通过百分比计算出的总使用量,直接作为 total_tokens
|
||||
totalTokens = Math.round(totalContextTokens * contextUsagePercentage / 100);
|
||||
|
|
|
|||
Loading…
Reference in a new issue