feat: v3.0 Tool Calling — AI 本地文件操作系统

新增文件:
- src/main/tool-security.ts: 路径白名单/黑名单、命令安全检查
- src/main/tool-handlers.ts: 7个工具实现(read/write/list/search/create/delete/run)
- src/renderer/services/tool-registry.ts: 工具注册调度中心
- src/renderer/services/agent-engine.ts: Agent Loop 流式多轮工具调用引擎
- src/renderer/components/tool-confirm-modal.ts: 高风险操作确认对话框

修改文件:
- types.d.ts: 新增 ToolCall/ToolResult/ToolCallRecord 等类型
- ollama.ts: chatStream 支持 tools 参数
- ipc.ts: 新增 tool:execute/getConfig/setAllowedDirs IPC
- preload.ts: 暴露 tool API
- chat-area.ts: 渲染工具调用卡片
- input-area.ts: 集成 Agent Loop 引擎
- settings-modal.ts: 工具调用开关设置
- index.html: 工具调用设置面板 + 确认对话框 HTML
- style.css: 工具调用卡片、确认对话框样式
- main.ts: 初始化工具调用配置
This commit is contained in:
thzxx
2026-04-06 13:29:43 +08:00
parent 0a1397771e
commit 5bfb137a8a
15 changed files with 1609 additions and 6 deletions
+213
View File
@@ -2181,3 +2181,216 @@ html, body {
margin: 8px 0;
color: var(--text-secondary);
}
/* ═══════════════════════════════════════════════════════════════
Tool Calling 工具调用卡片
═══════════════════════════════════════════════════════════════ */
.tool-calls-container {
margin-top: 8px;
}
.tool-call-card {
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
margin: 8px 0;
overflow: hidden;
background: rgba(255, 255, 255, 0.03);
font-size: 13px;
}
.tool-call-header {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.tool-call-icon {
font-size: 15px;
}
.tool-call-name {
font-weight: 600;
color: var(--accent-cyan, #00f5d4);
}
.tool-call-status {
margin-left: auto;
font-size: 12px;
color: var(--text-secondary, rgba(255, 255, 255, 0.6));
}
.tool-call-params {
padding: 6px 12px;
font-size: 12px;
color: rgba(255, 255, 255, 0.6);
}
.tool-call-params code {
background: rgba(0, 0, 0, 0.3);
padding: 1px 6px;
border-radius: 4px;
font-family: 'Cascadia Code', 'Consolas', monospace;
font-size: 12px;
color: var(--accent-cyan, #00f5d4);
}
.tool-param {
margin: 2px 0;
}
.tool-call-result {
padding: 8px 12px;
border-top: 1px solid rgba(255, 255, 255, 0.06);
max-height: 300px;
overflow-y: auto;
}
.tool-result-content {
background: rgba(0, 0, 0, 0.3);
padding: 8px 10px;
border-radius: 6px;
font-family: 'Cascadia Code', 'Consolas', monospace;
font-size: 12px;
line-height: 1.5;
white-space: pre-wrap;
word-break: break-all;
margin: 0;
color: rgba(255, 255, 255, 0.85);
max-height: 200px;
overflow-y: auto;
}
.tool-result-stderr {
color: #ff6b6b;
border-left: 3px solid #ff6b6b;
}
.tool-result-entry {
padding: 2px 0;
font-size: 12px;
color: rgba(255, 255, 255, 0.75);
}
.tool-result-entry code {
background: rgba(0, 0, 0, 0.3);
padding: 1px 6px;
border-radius: 4px;
font-family: 'Cascadia Code', 'Consolas', monospace;
font-size: 11px;
}
.tool-result-meta {
margin-top: 6px;
font-size: 11px;
color: rgba(255, 255, 255, 0.4);
}
.tool-result-error {
color: #ff6b6b;
}
/* 状态颜色 */
.tool-call-pending {
border-color: rgba(255, 165, 0, 0.4);
}
.tool-call-running {
border-color: rgba(0, 245, 212, 0.4);
}
.tool-call-success {
border-color: rgba(0, 200, 83, 0.3);
}
.tool-call-error {
border-color: rgba(255, 82, 82, 0.4);
}
.tool-call-cancelled {
border-color: rgba(150, 150, 150, 0.4);
}
/* 执行中 spinner */
.tool-call-running .tool-call-header::after {
content: '';
width: 14px;
height: 14px;
border: 2px solid rgba(0, 245, 212, 0.3);
border-top-color: var(--accent-cyan, #00f5d4);
border-radius: 50%;
animation: tool-spin 0.8s linear infinite;
margin-left: auto;
}
@keyframes tool-spin {
to { transform: rotate(360deg); }
}
/* ── 工具调用设置 ── */
.tool-list {
display: flex;
flex-direction: column;
gap: 4px;
}
.tool-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 4px 8px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.03);
font-size: 12px;
}
.tool-item span:first-child {
color: var(--text-primary, #fff);
}
/* ── 工具确认对话框 ── */
.tool-confirm-info {
font-size: 13px;
}
.tool-confirm-row {
display: flex;
gap: 8px;
margin: 6px 0;
align-items: baseline;
}
.tool-confirm-label {
color: var(--text-secondary, rgba(255, 255, 255, 0.6));
white-space: nowrap;
min-width: 60px;
}
.tool-confirm-row code {
background: rgba(0, 0, 0, 0.3);
padding: 2px 8px;
border-radius: 4px;
font-family: 'Cascadia Code', 'Consolas', monospace;
font-size: 12px;
color: var(--accent-cyan, #00f5d4);
word-break: break-all;
}
.tool-confirm-preview {
background: rgba(0, 0, 0, 0.3);
padding: 8px 10px;
border-radius: 6px;
font-family: 'Cascadia Code', 'Consolas', monospace;
font-size: 11px;
line-height: 1.5;
white-space: pre-wrap;
word-break: break-all;
margin: 4px 0 0;
max-height: 150px;
overflow-y: auto;
color: rgba(255, 255, 255, 0.75);
}