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:修复历史消息折叠后的滚动加载、集群模式恢复及刷新态数据转换问题

xiaoyao4225b2aebbdc1f
diff --git a/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/MessageItem.tsx b/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/MessageItem.tsx
index 7003057bd3..8a429a88fd 100644
--- a/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/MessageItem.tsx
+++ b/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/MessageItem.tsx
@@ -136,6 +136,19 @@ export function MessageItem({ message, autoSpeak = false }: MessageItemProps) {
}
}, [autoSpeak, role, isStreaming, hasAutoSpoken, content, handleSpeak]);
+ useEffect(() => {
+ return () => {
+ stopGeneratedAudio();
+ };
+ }, [stopGeneratedAudio]);
+
+ useEffect(() => {
+ return onTtsStop(() => {
+ stopGeneratedAudio();
+ stop();
+ });
+ }, [stopGeneratedAudio, stop]);
+
// 工具调用/结果消息
if (role === 'tool') {
return (
@@ -355,19 +368,6 @@ export function MessageItem({ message, autoSpeak = false }: MessageItemProps) {
const showCopy = Boolean(content) && !isStreaming;
const isPlaying = audioBase64 ? isAudioPlaying : isSpeaking;
- useEffect(() => {
- return () => {
- stopGeneratedAudio();
- };
- }, [stopGeneratedAudio]);
-
- useEffect(() => {
- return onTtsStop(() => {
- stopGeneratedAudio();
- stop();
- });
- }, [stopGeneratedAudio, stop]);
-
return (
<div className={clsx(
'flex mb-3 animate-rise',
@@ -485,4 +485,4 @@ export function MessageItem({ message, autoSpeak = false }: MessageItemProps) {
</div>
</div>
);
-}
\ No newline at end of file
+}
diff --git a/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/MessageList.tsx b/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/MessageList.tsx
index 26c250c805..a10935adde 100644
--- a/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/MessageList.tsx
+++ b/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/MessageList.tsx
@@ -73,7 +73,7 @@ function buildTimelineItems(
.filter((msg) => msg.role !== 'tool')
.map((message, index) => ({
type: 'message',
- key: `message-${message.id}`,
+ key: `message-${message.id}-${index}`,
timestampMs: toTimestampMs(message.timestamp),
sourceIndex: index,
message,
diff --git a/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/index.tsx b/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/index.tsx
index e15164507d..213dbca867 100644
--- a/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/index.tsx
+++ b/jiuwenclaw/channels/web/frontend/src/components/ChatPanel/index.tsx
@@ -98,7 +98,7 @@ export function ChatPanel({
userScrolledUpRef.current = !atBottom;
// 当滚动到顶部且有更多历史消息时,加载更多
- if (el.scrollTop === 0 && historyPager && historyPager.loadedPages < historyPager.totalPages && !historyPager.loadingMore) {
+ if (el.scrollTop <= 8 && historyPager && historyPager.loadedPages < historyPager.totalPages && !historyPager.loadingMore) {
void historyPager.onLoadMore();
}
}, [historyPager]);
@@ -109,7 +109,7 @@ export function ChatPanel({
if (e.deltaY < 0 && historyPager && historyPager.loadedPages < historyPager.totalPages && !historyPager.loadingMore) {
// 检查是否已经在顶部(没有滚动条时 scrollTop 始终为 0)
const el = scrollContainerRef.current;
- if (el && el.scrollTop === 0) {
+ if (el && el.scrollTop <= 8) {
void historyPager.onLoadMore();
}
}
diff --git a/jiuwenclaw/channels/web/frontend/src/features/historyRestore.ts b/jiuwenclaw/channels/web/frontend/src/features/historyRestore.ts
index 96ff573cb5..7d996ef5f8 100644
--- a/jiuwenclaw/channels/web/frontend/src/features/historyRestore.ts
+++ b/jiuwenclaw/channels/web/frontend/src/features/historyRestore.ts
@@ -11,6 +11,7 @@ const ALLOWED_ASSISTANT_EVENT_TYPES = new Set([
'chat.tool_call',
'chat.tool_result',
'chat.usage_summary',
+ 'team.message',
]);
/** 后端约定:最后一帧 `history.message` 使用 `payload.status: done`(兼容旧版 `payload.content: done`) */
@@ -149,8 +150,12 @@ function recordTimestampIso(record: Record<string, unknown>): string {
return new Date().toISOString();
}
+function isTeamModeRecord(record: Record<string, unknown>): boolean {
+ return typeof record.mode === 'string' && record.mode.trim().toLowerCase() === 'team';
+}
+
const _HISTORY_RECORD_META_KEYS = new Set([
- 'id', 'role', 'request_id', 'channel_id', 'timestamp', 'event_type', 'event_payload',
+ 'id', 'role', 'request_id', 'channel_id', 'timestamp', 'event_type', 'event_payload', 'mode',
]);
/** 合并 event_payload 与顶层 content,供 final / tool 解析 */
@@ -211,6 +216,23 @@ function parseHistoryTimelineEntry(
return null;
}
+ if (eventType === 'team.message') {
+ if (!isRecord(record.event)) {
+ return null;
+ }
+ const teamPayload = { event: record.event };
+ const id = pickFirstString(record.event, ['message_id'])!;
+ return {
+ kind: 'message',
+ message: {
+ id,
+ role: 'system',
+ content: `team.event:${JSON.stringify(teamPayload)}`,
+ timestamp: at,
+ },
+ };
+ }
+
const payload = buildEventPayloadForRecord(record);
if (eventType === 'chat.final') {
@@ -220,6 +242,20 @@ function parseHistoryTimelineEntry(
}
const id =
pickFirstString(record, ['id', 'message_id', 'msg_id']) ?? `hist-final-${sessionId}-${at}`;
+ if (isTeamModeRecord(record)) {
+ return {
+ kind: 'message',
+ message: {
+ id: `team-leader-${id}`,
+ role: 'system',
+ content: `team.leader:${JSON.stringify({
+ content,
+ timestamp: Date.parse(at),
+ })}`,
+ timestamp: at,
+ },
+ };
+ }
return {
kind: 'message',
message: { id, role: 'assistant', content, timestamp: at },
@@ -539,4 +575,4 @@ export function fetchHistoryPage(options: FetchHistoryPageOptions): HistoryResto
activeRestore = handle;
activePageFetchDispose = dispose;
return handle;
-}
\ No newline at end of file
+}
diff --git a/jiuwenclaw/server/runtime/session/session_history.py b/jiuwenclaw/server/runtime/session/session_history.py
index bb331ea26a..ffd1b31d9c 100644
--- a/jiuwenclaw/server/runtime/session/session_history.py
+++ b/jiuwenclaw/server/runtime/session/session_history.py
@@ -118,6 +118,8 @@ def append_history_record(
serialized_extra = _serialize_value(extra)
if isinstance(serialized_extra, dict):
item.update(serialized_extra)
+ if mode:
+ item["mode"] = str(mode)
_ensure_worker_started()
try: