Skip to content

Commit e4c2f6c

Browse files
committed
refactor(ui): 更新工具和模型配置的UI文本及说明
feat(core): 重构ToolErrorType枚举,增加更细粒度的错误类型 refactor(core): 修改read_file工具参数从absolute_path为file_path refactor(core): 优化shell命令解析逻辑,增加子命令拆分和重定向检查 refactor(core): 移除SessionTokenLimitExceeded事件,改用ContextWindowWillOverflow refactor(core): 更新tokenLimit实现为switch-case模式 refactor(core): 重构ContentGenerator直接使用GoogleGenAI SDK refactor(core): 优化ToolRegistry注册逻辑,增加discoverAllTools和sortTools refactor(core): 更新ToolInvocation接口,简化参数和返回值结构 refactor(core): 重构CoreToolScheduler调度逻辑,整合PolicyEngine决策 docs: 更新UI中的工具数量和认证方式说明
1 parent 271e005 commit e4c2f6c

24 files changed

Lines changed: 2375 additions & 9356 deletions

src/pages/AIToolInteraction.tsx

Lines changed: 228 additions & 1002 deletions
Large diffs are not rendered by default.

src/pages/Animation.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function Introduction({ isExpanded, onToggle }: { isExpanded: boolean; onToggle:
6666
<div className="text-[var(--text-muted)]">// 主循环入口</div>
6767
<div>packages/core/src/core/geminiChat.ts</div>
6868
<div className="text-[var(--text-muted)] mt-1">// 工具调度</div>
69-
<div>packages/core/src/tools/toolScheduler.ts</div>
69+
<div>packages/core/src/core/coreToolScheduler.ts</div>
7070
</div>
7171
</div>
7272

@@ -131,9 +131,9 @@ const animSteps = [
131131
message: 'generateContentStream + tools',
132132
messageColor: 'bg-[var(--cyber-blue)]/10',
133133
extra: `{
134-
// Gemini SDK 格式 (内部会转换为 OpenAI 格式)
134+
// Gemini SDK (GenerateContent) 请求结构(上游主线没有 OpenAI 兼容层转换)
135135
contents: [{ role: "user", parts: [...] }],
136-
tools: [{ functionDeclarations: [read_file, edit, shell, ...] }]
136+
tools: [{ functionDeclarations: [ /* FunctionDeclaration[] */ ] }]
137137
}`,
138138
},
139139
{
@@ -143,10 +143,10 @@ const animSteps = [
143143
message: 'FunctionCall: read_file',
144144
messageColor: 'bg-[var(--purple)]/10',
145145
extra: `{
146-
// StreamingToolCallParser 解析流式 JSON
146+
// SDK chunk 里可直接读取 functionCalls(由 candidates.parts 推导的 getter)
147147
functionCalls: [{
148148
name: "read_file",
149-
args: { absolute_path: "/path/to/package.json" }
149+
args: { file_path: "package.json" }
150150
}],
151151
finishReason: "TOOL_USE"
152152
}`,
@@ -177,10 +177,9 @@ const animSteps = [
177177
to: '🔧 工具',
178178
message: '执行 read_file 工具',
179179
messageColor: 'bg-[var(--amber)]/10',
180-
extra: `// ToolInvocation.execute()
181-
ReadFileToolInvocation.execute({
182-
absolute_path: "/path/to/package.json"
183-
})`,
180+
extra: `// tool.build(args) → invocation.execute()
181+
const invocation = readFileTool.build({ file_path: "package.json" });
182+
await invocation.execute(signal);`,
184183
},
185184
{
186185
from: '← CLI',
@@ -232,7 +231,7 @@ const stepDescriptions = [
232231
'$ 点击播放开始演示',
233232
'> 用户输入问题:帮我读取 package.json',
234233
'> CLI 调用 generateContentStream,发送用户消息和工具定义',
235-
'< AI 返回 FunctionCall,StreamingToolCallParser 解析流式响应',
234+
'< AI 返回 FunctionCall(functionCalls getter 可直接读取)',
236235
'? CLI 检查 shouldConfirmExecute(),需要用户确认',
237236
'✓ 用户批准执行工具',
238237
'> CLI 调用 ReadFileToolInvocation.execute()',

src/pages/ChatCompression.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ async function runConversationLoop(chat: Chat) {
500500
<HighlightBox title="性能考虑" color="green">
501501
<ul className="text-sm text-[var(--text-secondary)] space-y-1">
502502
<li>• 压缩会产生额外 LLM 调用</li>
503-
<li>• Token 计算使用 tiktoken 缓存</li>
503+
<li>• Token 预估使用 ASCII/CJK 启发式 + countTokens(媒体)</li>
504504
<li>• 摘要模型可配置为更快的模型</li>
505505
</ul>
506506
</HighlightBox>

src/pages/CommandInjectionDetectionAnimation.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,16 @@ export default function CommandInjectionDetectionAnimation() {
110110
return false;
111111
};
112112

113-
// 1) 解析是否可控(上游用 shell parser;这里用“引号平衡”做近似演示)
113+
// 1) 解析是否可控(上游用 splitCommands()/parseCommandDetails;这里用“引号平衡”做近似演示)
114114
const parseOk = hasBalancedQuotes(cmd);
115115
checks.push({
116116
name: 'parseCommandDetails()',
117117
passed: parseOk,
118-
detail: parseOk ? 'Parsed (simulated) OK' : 'Parse failed (simulated): unbalanced quotes',
119-
severity: parseOk ? 'safe' : 'blocked',
118+
detail: parseOk
119+
? 'Parsed (simulated) OK'
120+
: 'Parse failed (simulated): unbalanced quotes → 上游会回退为 ASK_USER(更保守)',
121+
// 上游 parse 失败不会直接 DENY,而是回退为 ASK_USER(需要确认)
122+
severity: parseOk ? 'safe' : 'warning',
120123
});
121124

122125
// 2) tools.exclude(blocklist,优先级最高)
@@ -159,6 +162,7 @@ export default function CommandInjectionDetectionAnimation() {
159162
});
160163

161164
// 4) PolicyEngine:含重定向时默认把 ALLOW 降级为 ASK_USER(除非 allowRedirection=true)
165+
// 上游 hasRedirection() 会尽量用 shell 解析器(PowerShell / tree-sitter bash),失败时回退到 /[><]/。
162166
const hasRedirection = /[><]/.test(cmd);
163167
const needsRedirectionConfirm = hasRedirection && !EXAMPLE_ALLOW_REDIRECTION;
164168

src/pages/ContentGeneratorDetails.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ return this.config.getContentGenerator().generateContentStream(
246246
{
247247
"name": "read_file",
248248
"description": "读取文件内容",
249-
"parameters": {
249+
"parametersJsonSchema": {
250250
"type": "object",
251251
"properties": {
252-
"absolute_path": { "type": "string" }
252+
"file_path": { "type": "string" }
253253
}
254254
}
255255
}
@@ -283,7 +283,7 @@ return this.config.getContentGenerator().generateContentStream(
283283
"parameters": {
284284
"type": "object",
285285
"properties": {
286-
"absolute_path": { "type": "string" }
286+
"file_path": { "type": "string" }
287287
}
288288
}
289289
}

0 commit comments

Comments
 (0)