refactor: 移除多余依赖,统一 MUI 为唯一 UI 库
- 移除 radix-ui、clsx、tailwind-merge、class-variance-authority、react-router-dom - 前后端全面适配 MUI 组件,清理残留 Tailwind 工具类引用 - 优化 Agent Loop 引擎、IPC 处理器、Provider Adapter 等后端模块 - 新增 Agent 网络工具通用设计文档 v2
This commit is contained in:
@@ -41,8 +41,24 @@ export function useAgentStream(): void {
|
||||
|
||||
// 每次收到迭代号时同步更新
|
||||
if (data.iteration != null && data.iteration !== getStore().currentIteration) {
|
||||
console.log(`[useAgentStream] iteration: ${getStore().currentIteration} → ${data.iteration} (event: ${data.type})`);
|
||||
const prevIteration = getStore().currentIteration;
|
||||
getStore().setCurrentIteration(data.iteration);
|
||||
|
||||
// 迭代号增大 → 新一轮 ReAct 迭代开始,创建新的 assistant 消息卡片
|
||||
if (data.iteration > prevIteration && prevIteration > 0) {
|
||||
const messages = getStore().messages;
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
// 仅当上一条 assistant 消息已有内容时才创建新消息(避免空消息堆叠)
|
||||
if (lastMsg?.role === 'assistant' && (lastMsg.content || lastMsg.toolCalls?.length || lastMsg.reasoningContent)) {
|
||||
getStore().addMessage({
|
||||
id: `msg_${Date.now()}_assistant`,
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
timestamp: Date.now(),
|
||||
iteration: data.iteration,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (data.type) {
|
||||
@@ -62,7 +78,7 @@ export function useAgentStream(): void {
|
||||
const messages = getStore().messages;
|
||||
const lastMsg = messages[messages.length - 1];
|
||||
if (lastMsg?.role === 'assistant') {
|
||||
// 追加到最后一条 assistant 消息
|
||||
// 追加到最后一条 assistant 消息(不可变更新)
|
||||
getStore().updateMessage(lastMsg.id, {
|
||||
reasoningContent: (lastMsg.reasoningContent ?? '') + data.delta,
|
||||
});
|
||||
@@ -74,6 +90,7 @@ export function useAgentStream(): void {
|
||||
content: '',
|
||||
reasoningContent: data.delta,
|
||||
timestamp: Date.now(),
|
||||
iteration: data.iteration ?? getStore().currentIteration,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -129,7 +146,7 @@ export function useAgentStream(): void {
|
||||
if (data.toolResult) {
|
||||
const msgs = getStore().messages;
|
||||
const lastMsg = msgs[msgs.length - 1];
|
||||
if (lastMsg?.toolCalls) {
|
||||
if (lastMsg?.role === 'assistant' && lastMsg?.toolCalls) {
|
||||
const updatedToolCalls = lastMsg.toolCalls.map((tc) =>
|
||||
tc.id === data.toolResult!.toolCallId
|
||||
? {
|
||||
@@ -150,10 +167,11 @@ export function useAgentStream(): void {
|
||||
// Token 使用统计
|
||||
case 'usage':
|
||||
if (data.usage) {
|
||||
const cur = getStore().tokenUsage;
|
||||
getStore().updateTokenUsage({
|
||||
inputTokens: data.usage.inputTokens ?? 0,
|
||||
outputTokens: data.usage.outputTokens ?? 0,
|
||||
totalTokens: data.usage.totalTokens ?? 0,
|
||||
inputTokens: cur.inputTokens + (data.usage.inputTokens ?? 0),
|
||||
outputTokens: cur.outputTokens + (data.usage.outputTokens ?? 0),
|
||||
totalTokens: cur.totalTokens + (data.usage.totalTokens ?? 0),
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user