- 将 messageArea.ts 拆分为多个独立模块 - 新增 messageRenderer.ts:消息渲染逻辑 - 新增 messageStyles.ts:样式定义 - 新增 questionHandler.ts:问题处理 - 新增 segmentRenderer.ts:分段渲染 - 新增 textFormatter.ts:文本格式化 - 新增 toolHelpers.ts:工具辅助函数
107 lines
3.3 KiB
TypeScript
107 lines
3.3 KiB
TypeScript
/**
|
||
* 工具辅助函数模块
|
||
* 功能:工具图标、名称映射、VCD 路径解析
|
||
* 依赖:toolIcons
|
||
* 使用场景:工具调用显示
|
||
*/
|
||
|
||
import {
|
||
fileWriteIconSvg,
|
||
fileReadIconSvg,
|
||
fileDeleteIconSvg,
|
||
syntaxCheckIconSvg,
|
||
SearchCode,
|
||
saveKnowledgeIconSvg,
|
||
simulationIconSvg,
|
||
waveformIconSvg,
|
||
knowledgeLoadIconSvg,
|
||
stateTransitionIconSvg,
|
||
userQuestionIconSvg,
|
||
updateStageIconSvg,
|
||
successIconSvg,
|
||
} from "../constants/toolIcons";
|
||
|
||
export function getToolIcon(toolName: string): string {
|
||
const iconMap: Record<string, string> = {
|
||
file_read: fileReadIconSvg,
|
||
file_write: fileWriteIconSvg,
|
||
file_delete: fileDeleteIconSvg,
|
||
file_list: SearchCode,
|
||
syntax_check: syntaxCheckIconSvg,
|
||
simulation: simulationIconSvg,
|
||
waveform_summary: waveformIconSvg,
|
||
knowledge_save: saveKnowledgeIconSvg,
|
||
knowledge_load: knowledgeLoadIconSvg,
|
||
queryKnowledgeSummary: knowledgeLoadIconSvg,
|
||
queryRules: knowledgeLoadIconSvg,
|
||
setModule: fileWriteIconSvg,
|
||
addSignal: fileWriteIconSvg,
|
||
addSignalExample: fileWriteIconSvg,
|
||
validateKnowledgeGraph: syntaxCheckIconSvg,
|
||
querySignals: SearchCode,
|
||
addPlan: fileWriteIconSvg,
|
||
addEdge: fileWriteIconSvg,
|
||
showPlan: SearchCode,
|
||
addRule: fileWriteIconSvg,
|
||
updateNode: fileWriteIconSvg,
|
||
addStateTransition: stateTransitionIconSvg,
|
||
askUser: userQuestionIconSvg,
|
||
updatePhase: updateStageIconSvg,
|
||
iverilog: successIconSvg,
|
||
};
|
||
return iconMap[toolName] || "";
|
||
}
|
||
|
||
export function getToolDisplayName(toolName: string): string {
|
||
const toolNameMap: Record<string, string> = {
|
||
file_read: "已完成文件读取",
|
||
file_write: "已完成文件写入",
|
||
file_delete: "已完成文件删除",
|
||
file_list: "已检索代码文件",
|
||
syntax_check: "已完成语法检查",
|
||
simulation: "已完成仿真",
|
||
waveform_summary: "已完成波形分析",
|
||
knowledge_save: "已保存知识库",
|
||
knowledge_load: "已加载知识库",
|
||
queryKnowledgeSummary: "已查询知识摘要",
|
||
queryRules: "已查询规则",
|
||
setModule: "已设置模块",
|
||
addSignal: "信号分析完成",
|
||
addSignalExample: "信号示例处理完成",
|
||
validateKnowledgeGraph: "已验证知识图谱",
|
||
querySignals: "已查询信号",
|
||
addPlan: "已添加计划",
|
||
addEdge: "已添加边",
|
||
showPlan: "已显示计划",
|
||
addRule: "已添加规则",
|
||
updateNode: "已更新节点",
|
||
addStateTransition: "已添加状态转换",
|
||
spawnExplorer: "代码探索",
|
||
spawnDebugger: "波形调试",
|
||
askUser: "用户提问",
|
||
updatePhase: "已更新阶段",
|
||
iverilog: "已完成编译",
|
||
};
|
||
return toolNameMap[toolName] || toolName;
|
||
}
|
||
|
||
export function parseMultiVcdPaths(toolResult: string): Array<{ name: string; path: string }> {
|
||
if (!toolResult) return [];
|
||
const result = String(toolResult);
|
||
|
||
const vcdListMatch = result.match(/VCD 文件列表:[\s\S]*?(?=\n\n|$)/);
|
||
if (!vcdListMatch) return [];
|
||
|
||
const paths: Array<{ name: string; path: string }> = [];
|
||
const lineRegex = /- (\w+): ([^\n]+)/g;
|
||
let match;
|
||
while ((match = lineRegex.exec(vcdListMatch[0])) !== null) {
|
||
const name = match[1];
|
||
const pathOrError = match[2].trim();
|
||
if (!pathOrError.startsWith("失败")) {
|
||
paths.push({ name: name + ".vcd", path: pathOrError });
|
||
}
|
||
}
|
||
return paths;
|
||
}
|