feat: 移除所有工具结果截断,确保内容完整传给AI

删除TOOL_MAX_RESULT_SIZE配置表和formatDefaultToolResult截断; read_file移除2000行/100KB截断; read_multiple_files移除10000字符截断; list_directory移除2000条目上限; search_files移除10条匹配和50结果限制; run_command移除512KB输出截断; browser_extract移除15000字符截断; session_read移除50条消息限制; session_list移除20条限制; memory search移除8条限制; web_search移除10条结果限制; SearXNG HTML移除内容截断; 版本号升级至0.14.11; 实现工具三档执行模式(auto/confirm/disabled)
This commit is contained in:
thzxx
2026-07-09 22:31:04 +08:00
parent ea82c64f4b
commit e3b44a0357
15 changed files with 311 additions and 193 deletions
+53 -32
View File
@@ -1,16 +1,37 @@
/**
* ToolsModal - 工具面板模态框
* 展示所有可用工具的详细信息。Tool Calling 始终开启,不可关闭。
* 支持三档开关(auto/confirm/disabled)的工具统一管理。
*/
import { state, KEYS } from '../state/state.js';
import { setToolEnabled, setRunCommandMode } from '../services/tool-registry.js';
import { setToolMode, getToolMode, type ToolMode } from '../services/tool-registry.js';
import { showToast } from './toast.js';
import { logInfo, logWarn } from '../services/log-service.js';
import { logInfo } from '../services/log-service.js';
import type { ChatDB } from '../db/chat-db.js';
let modalEl: HTMLElement;
const MODE_NAMES: Record<ToolMode, string> = {
auto: '自动执行',
confirm: '需确认',
disabled: '已禁用',
};
const BADGE_MAP: Record<ToolMode, { text: string; cls: string }> = {
auto: { text: '自动', cls: 'auto' },
confirm: { text: '需确认', cls: 'confirm' },
disabled: { text: '禁用', cls: 'disabled' },
};
function updateToolBadge(toolName: string, mode: ToolMode): void {
const badge = modalEl.querySelector(`#badge_${toolName}`) as HTMLElement;
if (!badge) return;
const info = BADGE_MAP[mode];
badge.textContent = info.text;
badge.className = `tool-card-badge ${info.cls}`;
}
export function initToolsModal(): void {
modalEl = document.querySelector('#toolsModal')!;
@@ -21,42 +42,42 @@ export function initToolsModal(): void {
if (e.target === modalEl) closeToolsModal();
});
// run_command 模式下拉框
const selectMode = modalEl.querySelector('#selectRunCommandMode') as HTMLSelectElement;
if (selectMode) {
selectMode.addEventListener('change', async () => {
// 所有带 .tool-mode-select 的下拉框统一绑定 change 事件
const selects = modalEl.querySelectorAll<HTMLSelectElement>('.tool-mode-select');
selects.forEach(selectEl => {
selectEl.addEventListener('change', async () => {
const toolName = selectEl.dataset.tool;
if (!toolName) return;
const mode = selectEl.value as ToolMode;
const db = state.get<ChatDB | null>(KEYS.DB);
const mode = selectMode.value as 'auto' | 'confirm' | 'disabled';
state.set('runCommandMode', mode);
if (db) await db.saveSetting('runCommandMode', mode);
setRunCommandMode(mode);
updateRunCommandBadge(mode);
const modeNames: Record<string, string> = { auto: '自动执行', confirm: '需确认', disabled: '已禁用' };
showToast(`命令执行模式:${modeNames[mode]}`, 'info');
logInfo(`命令执行模式已切换: ${mode}`);
// 更新运行时模式
setToolMode(toolName, mode);
updateToolBadge(toolName, mode);
// 持久化到数据库(所有工具模式合并存储为 JSON)
const allModes = state.get<Record<string, ToolMode>>('toolModes', {});
allModes[toolName] = mode;
state.set('toolModes', allModes);
if (db) await db.saveSetting('toolModes', allModes);
showToast(`${toolName}${MODE_NAMES[mode]}`, 'info');
logInfo(`工具模式切换: ${toolName}${mode}`);
});
}
}
function updateRunCommandBadge(mode: string): void {
const badge = modalEl.querySelector('#runCommandBadge') as HTMLElement;
if (!badge) return;
const map: Record<string, { text: string; cls: string }> = {
auto: { text: '自动', cls: 'auto' },
confirm: { text: '需确认', cls: 'confirm' },
disabled: { text: '禁用', cls: 'disabled' }
};
const info = map[mode] || map.confirm;
badge.textContent = info.text;
badge.className = `tool-card-badge ${info.cls}`;
});
}
export function openToolsModal(): void {
const runCommandMode = state.get<string>('runCommandMode', 'confirm');
const selectMode = modalEl.querySelector('#selectRunCommandMode') as HTMLSelectElement;
if (selectMode) selectMode.value = runCommandMode;
updateRunCommandBadge(runCommandMode);
// 从 state 读取所有工具模式,同步 UI
const allModes = state.get<Record<string, ToolMode>>('toolModes', {});
const selects = modalEl.querySelectorAll<HTMLSelectElement>('.tool-mode-select');
selects.forEach(selectEl => {
const toolName = selectEl.dataset.tool;
if (!toolName) return;
const mode = allModes[toolName] || getToolMode(toolName);
selectEl.value = mode;
updateToolBadge(toolName, mode);
});
modalEl.style.display = '';
}