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:1.会话页右下角上下文压缩刷新不重置2.channel排版折叠3.配置信息配置国际化4.滚动展示历史会话样式修改

openJiuwen-botb27539fc5b47
diff --git a/jiuwenclaw/web/src/App.tsx b/jiuwenclaw/web/src/App.tsx
index db0e31c399..888ec8ab67 100644
--- a/jiuwenclaw/web/src/App.tsx
+++ b/jiuwenclaw/web/src/App.tsx
@@ -608,6 +608,7 @@ function AppContent() {
historyRestoreFromPanelHintRef.current = false;
restoreHandle.dispose();
historyRestoreHandleRef.current = null;
+ // 发生错误时,设置 historyPagerMeta 为 null,显示欢迎信息
setHistoryPagerMeta(null);
console.error('Failed to load history:', error);
// 忽略 "invalid page_idx or session history not found" 错误,因为这是新会话的正常情况
diff --git a/jiuwenclaw/web/src/components/ChannelsPanel/index.tsx b/jiuwenclaw/web/src/components/ChannelsPanel/index.tsx
index 428386932d..15e36d6427 100644
--- a/jiuwenclaw/web/src/components/ChannelsPanel/index.tsx
+++ b/jiuwenclaw/web/src/components/ChannelsPanel/index.tsx
@@ -1595,19 +1595,19 @@ export function ChannelsPanel({ isConnected }: ChannelsPanelProps) {
: 'border-border bg-card text-text hover:bg-bg-hover'
}`}
>
- <div className="flex items-center justify-between gap-3">
- <div className="flex items-center gap-3 min-w-0">
- <span className="text-xs px-2.5 py-1 rounded-full border border-border bg-secondary text-text-muted font-medium">
+ <div className="flex items-center justify-between gap-3 w-full">
+ <div className="flex items-center gap-3 min-w-0 flex-1">
+ <span className="text-xs px-2.5 py-1 rounded-full border border-border bg-secondary text-text-muted font-medium flex-shrink-0">
#{index + 1}
</span>
<ChannelLogo channel={channel} label={label} />
- <span className="text-sm font-medium text-text">{label}</span>
- <span className="mono text-xs px-2.5 py-1 rounded-md border border-border bg-secondary text-text-muted">
+ <span className="text-sm font-medium text-text flex-1 min-w-0 truncate">{label}</span>
+ <span className="mono text-xs px-2.5 py-1 rounded-md border border-border bg-secondary text-text-muted flex-shrink-0">
{channel.channel_id}
</span>
</div>
<span
- className={`text-xs px-2.5 py-1 rounded-full border font-medium ${
+ className={`text-xs px-2.5 py-1 rounded-full border font-medium flex-shrink-0 ${
isAdapting
? 'text-text-muted border-border bg-secondary'
: channel.enabled
diff --git a/jiuwenclaw/web/src/components/ChatPanel/HistoryPagerBar.tsx b/jiuwenclaw/web/src/components/ChatPanel/HistoryPagerBar.tsx
index d96168ec90..c4eb9b2ab0 100644
--- a/jiuwenclaw/web/src/components/ChatPanel/HistoryPagerBar.tsx
+++ b/jiuwenclaw/web/src/components/ChatPanel/HistoryPagerBar.tsx
@@ -1,4 +1,5 @@
import { useTranslation } from 'react-i18next';
+import { useState, useEffect } from 'react';
export interface HistoryPagerBarProps {
loadedPages: number;
@@ -15,33 +16,62 @@ export function HistoryPagerBar({
}: HistoryPagerBarProps) {
const { t } = useTranslation();
const hasMore = loadedPages < totalPages;
+ const [showLoadedMessage, setShowLoadedMessage] = useState(false);
- const handleWheel = (e: React.WheelEvent<HTMLDivElement>) => {
- // 只在有更多内容且未加载中时处理
+ // 监听 loadingMore 状态变化,当从 true 变为 false 时,显示加载完成消息
+ useEffect(() => {
+ if (!loadingMore && loadedPages > 0) {
+ setShowLoadedMessage(true);
+ // 3秒后关闭消息
+ const timer = setTimeout(() => {
+ setShowLoadedMessage(false);
+ }, 3000);
+ return () => clearTimeout(timer);
+ }
+ }, [loadingMore, loadedPages]);
+
+ // 当开始加载新内容时,隐藏已加载消息
+ useEffect(() => {
+ if (loadingMore) {
+ setShowLoadedMessage(false);
+ }
+ }, [loadingMore]);
+
+ const handleClick = () => {
if (hasMore && !loadingMore) {
- // 向上滚动触发加载更多
- if (e.deltaY < 0) {
- e.preventDefault();
- void onLoadMore();
- }
+ void onLoadMore();
}
};
return (
<div
- className="history-pager-bar mb-3 rounded-lg border border-white/10 bg-secondary/50 px-3 py-2.5 flex flex-wrap items-center justify-between gap-2 text-sm cursor-pointer"
- onWheel={handleWheel}
- title={t('chat.historyPager.wheelToLoadMore')}
+ className="history-pager-bar mb-3 rounded-lg border border-white/10 bg-secondary/50 px-3 py-2.5 flex flex-col items-center justify-center gap-2 text-sm cursor-pointer"
+ onClick={handleClick}
+ title={t('chat.historyPager.clickOrScrollToLoadMore')}
>
- <span className="text-text-muted tabular-nums">
- {t('chat.historyPager.loadedOfTotal', { loaded: loadedPages, total: totalPages })}
- </span>
- {hasMore ? (
- <span className="text-xs text-text-muted shrink-0">
- {loadingMore ? t('chat.historyPager.loadingMore') : t('chat.historyPager.wheelToLoadMore')}
+ {/* 加载完成消息 */}
+ {showLoadedMessage && (
+ <span className="text-text-muted tabular-nums animate-fade-in">
+ {t('chat.historyPager.loadedOfTotal', { loaded: loadedPages, total: totalPages })}
</span>
+ )}
+
+ {/* 加载状态或提示文本 */}
+ {loadingMore ? (
+ <div className="flex justify-center items-center py-2">
+ <svg className="animate-spin -ml-1 mr-2 h-4 w-4 text-text-muted" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
+ <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
+ </svg>
+ </div>
) : (
- <span className="text-xs text-text-muted shrink-0">{t('chat.historyPager.allLoaded')}</span>
+ hasMore ? (
+ <span className="text-xs text-text-muted">
+ {t('chat.historyPager.clickOrScrollToLoadMore')}
+ </span>
+ ) : (
+ <span className="text-xs text-text-muted">{t('chat.historyPager.allLoaded')}</span>
+ )
)}
</div>
);
diff --git a/jiuwenclaw/web/src/components/ChatPanel/index.tsx b/jiuwenclaw/web/src/components/ChatPanel/index.tsx
index dcb6abfb61..6a7d21f3b3 100644
--- a/jiuwenclaw/web/src/components/ChatPanel/index.tsx
+++ b/jiuwenclaw/web/src/components/ChatPanel/index.tsx
@@ -4,7 +4,7 @@
* 聊天面板,包含消息列表和输入区域
*/
-import { useRef, useEffect, useLayoutEffect, useCallback } from 'react';
+import React, { useRef, useEffect, useLayoutEffect, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useChatStore } from '../../stores';
import { AgentMode, UserAnswer } from '../../types';
@@ -95,7 +95,24 @@ export function ChatPanel({
// 检查是否在底部(有 40px 的阈值)
const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 40;
userScrolledUpRef.current = !atBottom;
- }, []);
+
+ // 当滚动到顶部且有更多历史消息时,加载更多
+ if (el.scrollTop === 0 && historyPager && historyPager.loadedPages < historyPager.totalPages && !historyPager.loadingMore) {
+ void historyPager.onLoadMore();
+ }
+ }, [historyPager]);
+
+ // 检测鼠标滚轮事件,即使没有滚动条也能触发加载更多
+ const handleWheel = useCallback((e: React.WheelEvent<HTMLDivElement>) => {
+ // 只有向上滚动时才触发
+ if (e.deltaY < 0 && historyPager && historyPager.loadedPages < historyPager.totalPages && !historyPager.loadingMore) {
+ // 检查是否已经在顶部(没有滚动条时 scrollTop 始终为 0)
+ const el = scrollContainerRef.current;
+ if (el && el.scrollTop === 0) {
+ void historyPager.onLoadMore();
+ }
+ }
+ }, [historyPager]);
useEffect(() => {
if (suppressNextScrollToEndRef.current) {
@@ -145,16 +162,35 @@ export function ChatPanel({
return (
<div className="flex flex-col h-full" data-testid="chat-panel">
- <div ref={scrollContainerRef} className="flex-1 overflow-y-auto px-3 py-4" onScroll={handleScroll}>
- {historyPager && messages.length > 0 ? (
- <HistoryPagerBar
- loadedPages={historyPager.loadedPages}
- totalPages={historyPager.totalPages}
- loadingMore={historyPager.loadingMore}
- onLoadMore={historyPager.onLoadMore}
- />
- ) : null}
- {messages.length === 0 ? (
+ <div ref={scrollContainerRef} className="flex-1 overflow-y-auto px-3 py-4" onScroll={handleScroll} onWheel={handleWheel}>
+ {historyPager || messages.length > 0 ? (
+ <>
+ {historyPager && (
+ <HistoryPagerBar
+ loadedPages={historyPager.loadedPages}
+ totalPages={historyPager.totalPages}
+ loadingMore={historyPager.loadingMore}
+ onLoadMore={historyPager.onLoadMore}
+ />
+ )}
+ {messages.length > 0 ? (
+ <>
+ <MessageList messages={messages} />
+ <SubtaskProgress />
+ {/* 内联审批卡片(演进审批 & 权限审批共用) */}
+ <InlineQuestionCard onSubmit={onUserAnswer} />
+ {/* 思考中指示器 */}
+ {isThinking && <ThinkingIndicator />}
+ </>
+ ) : (
+ <div className="flex items-center justify-center h-32">
+ <div className="text-text-muted text-sm">
+ {t('connection.loadingConfig')}
+ </div>
+ </div>
+ )}
+ </>
+ ) : (
<div className="chat-welcome">
<img src="/logo.png" alt={t('chat.welcomeLogoAlt')} className="chat-welcome__logo" />
<h2 className="chat-welcome__heading">{t('chat.welcomeHeading')}</h2>
@@ -167,15 +203,6 @@ export function ChatPanel({
))}
</div>
</div>
- ) : (
- <>
- <MessageList messages={messages} />
- <SubtaskProgress />
- {/* 内联审批卡片(演进审批 & 权限审批共用) */}
- <InlineQuestionCard onSubmit={onUserAnswer} />
- {/* 思考中指示器 */}
- {isThinking && <ThinkingIndicator />}
- </>
)}
<div ref={messagesEndRef} />
</div>
diff --git a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx b/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
index d1bebef65f..9656de9167 100644
--- a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
+++ b/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
@@ -144,11 +144,14 @@ function parseBoolValue(value: string): boolean {
return value.toLowerCase() === "true" || value === "1";
}
-const BOOL_KEY_LABELS: Record<string, string> = {
- evolution_auto_scan: "自动检测可演进信号",
- context_engine_enabled: "启用",
- permissions_enabled: "启用",
-};
+function getBooleanKeyLabel(key: string, t: (key: string) => string): string {
+ const labels: Record<string, string> = {
+ evolution_auto_scan: t('config.booleanLabels.evolutionAutoScan'),
+ context_engine_enabled: t('config.booleanLabels.enabled'),
+ permissions_enabled: t('config.booleanLabels.enabled'),
+ };
+ return labels[key] ?? key;
+}
function isSensitiveKey(key: string): boolean {
const lower = key.toLowerCase();
@@ -197,10 +200,10 @@ function isProviderKey(key: string): boolean {
}
/** 表格列显示用:video_api_base -> api_base,避免与分组标题重复 */
-function getKeyDisplayLabel(key: string): string {
+function getKeyDisplayLabel(key: string, t: (key: string) => string): string {
const m = key.match(/^(video|audio|vision)_(.+)$/);
if (m) return m[2];
- return BOOL_KEY_LABELS[key] ?? key;
+ return getBooleanKeyLabel(key, t) ?? key;
}
function GroupSection({
@@ -270,7 +273,7 @@ function GroupSection({
<tbody>
{group.keys.map(([key, value]) => (
<tr key={key} className="border-t border-border first:border-t-0 even:bg-secondary/10 hover:bg-secondary/25 transition-colors">
- <td className="px-4 py-2.5 align-middle mono text-xs text-text-muted w-[32%]" title={key}>{getKeyDisplayLabel(key)}</td>
+ <td className="px-4 py-2.5 align-middle mono text-xs text-text-muted w-[32%]" title={key}>{getKeyDisplayLabel(key, t)}</td>
<td className="px-4 py-2.5 break-all text-[13px] align-middle">
{isBooleanKey(key) ? (
<div className="flex items-center gap-2">
@@ -288,7 +291,7 @@ function GroupSection({
role="switch"
aria-checked={parseBoolValue(draftValues[key] ?? value)}
onClick={() => onChange(key, parseBoolValue(draftValues[key] ?? value) ? "false" : "true")}
- title={BOOL_KEY_LABELS[key] ?? key}
+ title={getBooleanKeyLabel(key, t) ?? key}
className={`relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none ${
parseBoolValue(draftValues[key] ?? value) ? "bg-ok" : "bg-secondary"
}`}
diff --git a/jiuwenclaw/web/src/components/ToolPanel/index.tsx b/jiuwenclaw/web/src/components/ToolPanel/index.tsx
index 0fc92a05cf..3b00384b5e 100644
--- a/jiuwenclaw/web/src/components/ToolPanel/index.tsx
+++ b/jiuwenclaw/web/src/components/ToolPanel/index.tsx
@@ -95,9 +95,16 @@ export function ToolPanel() {
: `${memoryUsage.rssMb.toFixed(1)} MB${memoryUsage.usedPercent == null ? '' : ` (${memoryUsage.usedPercent.toFixed(1)}%)`}`;
const beforeK = ((contextCompressionBefore ?? 0) / 1000).toFixed(1);
const afterK = ((contextCompressionAfter ?? 0) / 1000).toFixed(1);
- const compressionRateDisplay = Number.isFinite(contextCompressionRate)
- ? contextCompressionRate.toFixed(1)
- : '0.0';
+ let compressionRateDisplay;
+ if (contextCompressionBefore === 0) {
+ compressionRateDisplay = '0.0';
+ } else if (contextCompressionAfter === contextCompressionBefore) {
+ compressionRateDisplay = '100.0';
+ } else {
+ compressionRateDisplay = Number.isFinite(contextCompressionRate)
+ ? contextCompressionRate.toFixed(1)
+ : '0.0';
+ }
const compressionDisplay = `${afterK}K/${beforeK}K (${compressionRateDisplay}%)`;
return (
diff --git a/jiuwenclaw/web/src/hooks/useWebSocket.ts b/jiuwenclaw/web/src/hooks/useWebSocket.ts
index eb2204f728..19e4b6086d 100644
--- a/jiuwenclaw/web/src/hooks/useWebSocket.ts
+++ b/jiuwenclaw/web/src/hooks/useWebSocket.ts
@@ -441,9 +441,10 @@ export function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {
activeSessionIdRef.current = activeSessionId;
}, [activeSessionId]);
- useEffect(() => {
- setContextCompressionStats(null);
- }, [activeSessionId, setContextCompressionStats]);
+ // 会话切换时不再重置上下文压缩信息,保持本地存储的状态
+ // useEffect(() => {
+ // setContextCompressionStats(null);
+ // }, [activeSessionId, setContextCompressionStats]);
useEffect(() => {
onConnectRef.current = onConnect;
@@ -877,7 +878,8 @@ export function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {
clearTodos();
clearSubtasks();
setConnected(false);
- setContextCompressionStats(null);
+ // 不再重置上下文压缩信息,保持本地存储的状态
+ // setContextCompressionStats(null);
setHeartbeatStatus('unknown', null, null);
setConnectionStats({ state: 'closed', inflight: 0 });
};
diff --git a/jiuwenclaw/web/src/i18n/locales/en.json b/jiuwenclaw/web/src/i18n/locales/en.json
index bdb1e63e4e..438855531c 100644
--- a/jiuwenclaw/web/src/i18n/locales/en.json
+++ b/jiuwenclaw/web/src/i18n/locales/en.json
@@ -60,10 +60,12 @@
"send": "Send (Enter)",
"newSessionDisabled": "Cannot create session while processing or recording",
"historyPager": {
- "loadedOfTotal": "History loaded {{loaded}} / {{total}} pages",
- "loadingMore": "Loading…",
- "allLoaded": "All history loaded",
- "wheelToLoadMore": "Scroll up to load more"
+ "loadedOfTotal": "Loaded {{loaded}} / {{total}} pages",
+ "loadingMore": "Loading...",
+ "allLoaded": "All history shown",
+ "wheelToLoadMore": "Scroll up to load more",
+ "clickToLoadMore": "Click to load more",
+ "clickOrScrollToLoadMore": "Click or scroll up to load more"
}
},
"connection": {
@@ -390,6 +392,10 @@
"email": { "label": "Email Settings", "hint": "Email account and token settings" },
"other": { "label": "Other Settings", "hint": "Unclassified extended parameters" }
},
+ "booleanLabels": {
+ "evolutionAutoScan": "Auto-detect evolution signals",
+ "enabled": "Enable"
+ },
"errors": {
"requiredModelFields": "These model fields are required: {{fields}}. Complete them before saving and restarting.",
"saveFailed": "Save failed, please try again later",
diff --git a/jiuwenclaw/web/src/i18n/locales/zh.json b/jiuwenclaw/web/src/i18n/locales/zh.json
index b3ddb4d969..8cc669f9e1 100644
--- a/jiuwenclaw/web/src/i18n/locales/zh.json
+++ b/jiuwenclaw/web/src/i18n/locales/zh.json
@@ -63,7 +63,9 @@
"loadedOfTotal": "历史已加载 {{loaded}} / {{total}} 页",
"loadingMore": "加载中…",
"allLoaded": "已显示全部历史",
- "wheelToLoadMore": "向上滚动加载更多"
+ "wheelToLoadMore": "向上滚动加载更多",
+ "clickToLoadMore": "点击加载更多",
+ "clickOrScrollToLoadMore": "点击或向上滚动加载更多"
}
},
"connection": {
@@ -389,6 +391,10 @@
"email": { "label": "邮箱配置", "hint": "邮件账号与令牌参数" },
"other": { "label": "其他配置", "hint": "未归类的扩展参数" }
},
+ "booleanLabels": {
+ "evolutionAutoScan": "自动检测可演进信号",
+ "enabled": "启用"
+ },
"errors": {
"requiredModelFields": "模型配置为必填:{{fields}}。请完整填写后再保存并重启。",
"saveFailed": "保存失败,请稍后重试",
diff --git a/jiuwenclaw/web/src/stores/sessionStore.ts b/jiuwenclaw/web/src/stores/sessionStore.ts
index 8ff7b242a0..42d12f61c1 100644
--- a/jiuwenclaw/web/src/stores/sessionStore.ts
+++ b/jiuwenclaw/web/src/stores/sessionStore.ts
@@ -5,6 +5,28 @@
import { create } from 'zustand';
import { Session, AgentMode, WebConnectionState } from '../types';
+const STORAGE_KEY = 'jiuwenclaw_context_compression';
+
+function loadFromStorage() {
+ try {
+ const stored = localStorage.getItem(STORAGE_KEY);
+ if (stored) {
+ return JSON.parse(stored);
+ }
+ } catch (error) {
+ console.error('Error loading context compression from storage:', error);
+ }
+ return null;
+}
+
+function saveToStorage(data: any) {
+ try {
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
+ } catch (error) {
+ console.error('Error saving context compression to storage:', error);
+ }
+}
+
const DEFAULT_MODE: AgentMode = 'plan';
function normalizeAgentMode(mode: unknown): AgentMode {
@@ -92,9 +114,9 @@ export const useSessionStore = create<SessionState>((set) => ({
inflight: 0,
lastError: null,
},
- contextCompressionRate: 0,
- contextCompressionBefore: null,
- contextCompressionAfter: null,
+ contextCompressionRate: loadFromStorage()?.rate || 0,
+ contextCompressionBefore: loadFromStorage()?.beforeCompressed || null,
+ contextCompressionAfter: loadFromStorage()?.afterCompressed || null,
memoryUsage: {
rssMb: null,
usedPercent: null,
@@ -181,6 +203,7 @@ export const useSessionStore = create<SessionState>((set) => ({
contextCompressionBefore: null,
contextCompressionAfter: null,
});
+ saveToStorage(null);
return;
}
@@ -197,11 +220,19 @@ export const useSessionStore = create<SessionState>((set) => ({
? Math.max(Math.round(stats.afterCompressed), 0)
: null;
+ const contextCompressionData = {
+ rate: normalizedRate,
+ beforeCompressed: normalizedBefore,
+ afterCompressed: normalizedAfter
+ };
+
set({
contextCompressionRate: normalizedRate,
contextCompressionBefore: normalizedBefore,
contextCompressionAfter: normalizedAfter,
});
+
+ saveToStorage(contextCompressionData);
},
setMemoryUsage: (memoryUsage) => {