Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(web): 历史回放补传 source_skill,修复刷新后来源技能标签丢失

jiangchenglin70fb2f137065
diff --git a/jiuwenswarm/channels/web/frontend/package.json b/jiuwenswarm/channels/web/frontend/package.json
index 5b6219d96a..7914cc56bd 100644
--- a/jiuwenswarm/channels/web/frontend/package.json
+++ b/jiuwenswarm/channels/web/frontend/package.json
@@ -34,6 +34,7 @@
"test:chat-store-streaming": "esbuild src/stores/chatStore.ts --bundle --platform=node --format=esm --outfile=node_modules/.cache/chat-store-streaming/chatStore.mjs --define:import.meta.env.DEV=false && node --test tests/chatStoreStreaming.test.mjs",
"test:settle-historical-tool-executions": "esbuild src/stores/chatStore.ts --bundle --platform=node --format=esm --outfile=node_modules/.cache/chat-store-streaming/chatStore.mjs --define:import.meta.env.DEV=false && node --test tests/settleHistoricalToolExecutions.test.mjs",
"test:history-pagination": "tsc src/features/historyPagination.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/history-pagination --skipLibCheck --noEmitOnError && node --test tests/historyPagination.test.mjs",
+ "test:history-restore-source-skill": "esbuild src/features/historyRestore.ts --bundle --packages=external --platform=node --format=esm --outfile=node_modules/.cache/history-restore/historyRestore.mjs --define:import.meta.env.DEV=false --define:import.meta.env.VITE_API_BASE='\"\"' --define:import.meta.env.VITE_WS_BASE='\"\"' --define:import.meta.env.VITE_JIUWENSWARM_EDITION='\"personal\"' --define:window.__JIUWEN_WEB_TRANSPORT__='\"websocket\"' --define:window.__JIUWENSWARM_EDITION__='\"personal\"' && node --test tests/historyRestoreSourceSkill.test.mjs",
"test:artifact-collection": "esbuild src/components/ArtifactsPanel/artifactCollection.ts --bundle --platform=node --format=esm --outfile=node_modules/.cache/artifact-collection/artifactCollection.mjs && node --test tests/artifactCollection.test.mjs",
"test:desktop-save": "esbuild src/utils/desktopSave.ts --bundle --platform=node --format=esm --outfile=node_modules/.cache/desktop-save/desktopSave.mjs && node --test tests/desktopSave.test.mjs",
"test:ask-user-submission": "tsc src/components/InteractionSlot/interactionSubmission.ts --target ES2020 --module ES2020 --moduleResolution Bundler --rootDir src --outDir node_modules/.cache/ask-user-submission --skipLibCheck --noEmitOnError && node --test tests/askUserSubmission.test.mjs",
diff --git a/jiuwenswarm/channels/web/frontend/src/App.tsx b/jiuwenswarm/channels/web/frontend/src/App.tsx
index 1a05bbb9eb..a103a964cd 100644
--- a/jiuwenswarm/channels/web/frontend/src/App.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/App.tsx
@@ -707,6 +707,7 @@ function AppContent() {
description: n.description,
formatted_args: n.formatted_args,
display_name: n.display_name,
+ source_skill: n.source_skill,
memberName: n.memberName,
},
{ startedAt: item.at }
@@ -1434,6 +1435,7 @@ function AppContent() {
description: n.description,
formatted_args: n.formatted_args,
display_name: n.display_name,
+ source_skill: n.source_skill,
memberName: n.memberName,
},
{ startedAt: item.at }
diff --git a/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts b/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts
index 4dcbcad539..67b591563d 100644
--- a/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts
+++ b/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts
@@ -842,6 +842,7 @@ function buildToolExecutionsFromReplay(toolReplay: HistoryToolReplayItem[]): Too
description: n.description,
formatted_args: n.formatted_args,
display_name: n.display_name,
+ source_skill: n.source_skill,
memberName: n.memberName,
},
// 与实时一致:先 pending,等 tool_result 再落终态;无 result 的孤儿在循环末尾结算。
diff --git a/jiuwenswarm/channels/web/frontend/tests/historyRestoreSourceSkill.test.mjs b/jiuwenswarm/channels/web/frontend/tests/historyRestoreSourceSkill.test.mjs
new file mode 100644
index 0000000000..09b66929a4
--- /dev/null
+++ b/jiuwenswarm/channels/web/frontend/tests/historyRestoreSourceSkill.test.mjs
@@ -0,0 +1,69 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+
+import { parseHistoryJsonFileToTimelinePreview } from '../node_modules/.cache/history-restore/historyRestore.mjs';
+
+// 历史记录字段对齐 pod 本地 history.json 的落盘结构:chat.tool_call 事件把
+// tool_call(含 source_skill)展平在 extra 里(interface.py _append_history_record)。
+const TOOL_CALL_WITH_SOURCE_SKILL = {
+ role: 'assistant',
+ request_id: 'rid-1',
+ channel_id: 'web',
+ timestamp: 1757800000,
+ event_type: 'chat.tool_call',
+ content: '',
+ tool_call: {
+ id: 'tc-1',
+ name: 'web_search',
+ arguments: { query: 'jiuwenswarm' },
+ source_skill: 'data-analysis',
+ },
+};
+
+const TOOL_RESULT_RECORD = {
+ role: 'assistant',
+ request_id: 'rid-1',
+ channel_id: 'web',
+ timestamp: 1757800001,
+ event_type: 'chat.tool_result',
+ content: '',
+ tool_result: {
+ tool_name: 'web_search',
+ tool_call_id: 'tc-1',
+ result: 'ok',
+ success: true,
+ },
+};
+
+test('history replay keeps source_skill on the rebuilt tool call', () => {
+ const { executions } = parseHistoryJsonFileToTimelinePreview(
+ [TOOL_CALL_WITH_SOURCE_SKILL, TOOL_RESULT_RECORD],
+ 'session-1',
+ );
+
+ const execution = executions.find((e) => e.toolCallId === 'tc-1');
+ assert.ok(execution, 'tool execution should be rebuilt from history');
+ assert.equal(execution.toolCall.source_skill, 'data-analysis');
+ // 实时链路依赖的其余字段也一并在场,确认重建口径完整。
+ assert.equal(execution.toolCall.name, 'web_search');
+ assert.equal(execution.status, 'completed');
+});
+
+test('history replay without source_skill stays undefined (no fake value)', () => {
+ const withoutSkill = {
+ ...TOOL_CALL_WITH_SOURCE_SKILL,
+ tool_call: {
+ id: 'tc-2',
+ name: 'web_search',
+ arguments: {},
+ },
+ };
+ const { executions } = parseHistoryJsonFileToTimelinePreview(
+ [withoutSkill],
+ 'session-2',
+ );
+
+ const execution = executions.find((e) => e.toolCallId === 'tc-2');
+ assert.ok(execution);
+ assert.equal(execution.toolCall.source_skill, undefined);
+});