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
feat:会话新增session_result事件,新增能气泡框
openJiuwen-bot06946fe0b0e0
diff --git a/jiuwenclaw/channel/web_channel.py b/jiuwenclaw/channel/web_channel.pyindex 1dc1befea0..d0fd6ab24e 100644--- a/jiuwenclaw/channel/web_channel.py+++ b/jiuwenclaw/channel/web_channel.py@@ -305,7 +305,8 @@ class WebChannel(BaseChannel):# 对于需要传递完整结构化数据的事件类型if event_name in ("connection.ack", "todo.updated", "chat.tool_call", "chat.tool_result","chat.processing_status", "chat.interrupt_result", "chat.error", "heartbeat.relay",- "context.compressed", "chat.ask_user_question", "chat.subtask_update"):+ "context.compressed", "chat.ask_user_question", "chat.subtask_update",+ "chat.session_result"):# 传递完整 payload,保留所有字段payload = {**msg.payload}# 确保包含 session_iddiff --git a/jiuwenclaw/schema/message.py b/jiuwenclaw/schema/message.pyindex 7ab429c198..674006ac2f 100644--- a/jiuwenclaw/schema/message.py+++ b/jiuwenclaw/schema/message.py@@ -79,6 +79,7 @@ class EventType(Enum):CHAT_INTERRUPT_RESULT = "chat.interrupt_result"CHAT_SUBTASK_UPDATE = "chat.subtask_update"CHAT_ASK_USER_QUESTION = "chat.ask_user_question"+ CHAT_SESSION_RESULT = "chat.session_result"HEARTBEAT_RELAY = "heartbeat.relay"diff --git a/jiuwenclaw/web/src/components/ChatPanel/MessageItem.tsx b/jiuwenclaw/web/src/components/ChatPanel/MessageItem.tsxindex f98c303f95..c2d3942d83 100644--- a/jiuwenclaw/web/src/components/ChatPanel/MessageItem.tsx+++ b/jiuwenclaw/web/src/components/ChatPanel/MessageItem.tsx@@ -36,6 +36,7 @@ export function MessageItem({ message, autoSpeak = false }: MessageItemProps) {} = message;const [hasAutoSpoken, setHasAutoSpoken] = useState(false);const [isAudioPlaying, setIsAudioPlaying] = useState(false);+ const [isExpanded, setIsExpanded] = useState(false);const audioRef = useRef<HTMLAudioElement | null>(null);// TTS@@ -146,6 +147,69 @@ export function MessageItem({ message, autoSpeak = false }: MessageItemProps) {// 系统消息if (role === 'system') {+ // 检查是否为 chat.session_result 事件+ if (content && content.startsWith('chat.session_result:')) {+ console.log('chat.session_result event:', content);+ const [, jsonStr] = content.split('chat.session_result:');+ try {+ const sessionData = JSON.parse(jsonStr);+ console.log('Parsed session data:', sessionData);+ const { description, result } = sessionData;++ return (+ <div className="chat-tool-card animate-rise">+ <div+ className="cursor-pointer"+ onClick={() => setIsExpanded(!isExpanded)}+ >+ <div className="flex items-center gap-2">+ <span className="w-5 h-5 rounded bg-accent-2-subtle text-accent-2 flex items-center justify-center text-sm">+ <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" strokeWidth={2}>+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 12h3.75M9 15h3.75M9 18h3.75m3 .75H18a2.25 2.25 0 002.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 00-1.123-.08m-5.801 0c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75 2.25 2.25 0 00-.1-.664m-5.8 0A2.251 2.251 0 0113.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V19.5a2.25 2.25 0 002.25 2.25h.75m0-3h-3.75m0 0h-3.75m0 0H9m1.5 3h3.75m-3.75 0H9m1.5 3h3.75m-3.75 0H9m1.5 3h3.75m-3.75 0H9" />+ </svg>+ </span>+ <span className="font-mono text-sm font-medium text-text">+ 会话任务:【{description || '未知任务'}】已完成+ </span>+ <span className="text-text-muted text-sm">+ {isExpanded ? '▼' : '▶'}+ </span>+ </div>+ </div>+ {isExpanded && (+ <div className="mt-2 p-2 rounded-md bg-card border border-border">+ {description && (+ <div className="mb-2">+ <div className="font-mono text-xs text-text-muted mb-1">Description:</div>+ <pre className="font-mono text-sm text-text overflow-x-auto whitespace-pre-wrap">+ {description}+ </pre>+ </div>+ )}+ {result && (+ <div>+ <div className="font-mono text-xs text-text-muted mb-1">Result:</div>+ <pre className="font-mono text-sm text-text overflow-x-auto whitespace-pre-wrap max-h-60">+ {result}+ </pre>+ </div>+ )}+ </div>+ )}+ </div>+ );+ } catch (e) {+ // 如果解析失败,显示原始内容+ return (+ <div className="flex justify-center my-4 animate-fade-in">+ <div className="px-4 py-2 rounded-full bg-secondary border border-border text-text-muted text-sm">+ {content}+ </div>+ </div>+ );+ }+ }+return (<div className="flex justify-center my-4 animate-fade-in"><div className="px-4 py-2 rounded-full bg-secondary border border-border text-text-muted text-sm">diff --git a/jiuwenclaw/web/src/components/ChatPanel/ToolCallDisplay.tsx b/jiuwenclaw/web/src/components/ChatPanel/ToolCallDisplay.tsxindex e53f89a04a..b54d4afae3 100644--- a/jiuwenclaw/web/src/components/ChatPanel/ToolCallDisplay.tsx+++ b/jiuwenclaw/web/src/components/ChatPanel/ToolCallDisplay.tsx@@ -20,13 +20,14 @@ export function ToolCallDisplay({ toolCall, toolResult }: ToolCallDisplayProps)const [isExpanded, setIsExpanded] = useState(false);if (toolCall) {- // 使用格式化的描述或默认显示工具名- const displayTitle = toolCall.description- ? `${toolCall.name}: ${toolCall.description}`- : toolCall.name;+ // session 类型:仅显示 会话任务:【description】,不显示 "session" 名称+ const isSession = toolCall.name === 'session';+ const displayTitle = isSession+ ? (toolCall.formatted_args || '会话任务已完成')+ : (toolCall.description ? `${toolCall.name}: ${toolCall.description}` : toolCall.name);- // 使用格式化的参数摘要- const displaySubtitle = toolCall.formatted_args || '';+ // 使用格式化的参数摘要(session 类型时 subtitle 已融入 title,不再重复显示)+ const displaySubtitle = isSession ? '' : (toolCall.formatted_args || '');return (<div className="chat-tool-card animate-rise">@@ -63,10 +64,12 @@ export function ToolCallDisplay({ toolCall, toolResult }: ToolCallDisplayProps)}if (toolResult) {- // 使用格式化的摘要或默认显示+ // 使用格式化的摘要或默认显示(session 类型优先用 summary,避免出现 "session 完成")const displaySummary = toolResult.summary? toolResult.summary- : `${toolResult.toolName} ${toolResult.success ? t('chatUi.toolResult.success') : t('chatUi.toolResult.failed')}`;+ : (toolResult.toolName === 'session'+ ? (toolResult.success ? t('chatUi.toolGroup.sessionCompleted') : t('chatUi.toolGroup.sessionFailed'))+ : `${toolResult.toolName} ${toolResult.success ? t('chatUi.toolResult.success') : t('chatUi.toolResult.failed')}`);return (<div className="chat-tool-card animate-rise">diff --git a/jiuwenclaw/web/src/components/ChatPanel/ToolGroupDisplay.tsx b/jiuwenclaw/web/src/components/ChatPanel/ToolGroupDisplay.tsxindex 1575c566b3..77d503817f 100644--- a/jiuwenclaw/web/src/components/ChatPanel/ToolGroupDisplay.tsx+++ b/jiuwenclaw/web/src/components/ChatPanel/ToolGroupDisplay.tsx@@ -58,8 +58,14 @@ export function ToolExecutionItem({ execution }: { execution: ToolExecution }) {)}</span>- <span className="tool-pair-name">{toolCall.name}</span>- {subtitle && <span className="tool-pair-summary">{subtitle}</span>}+ {toolCall.name === 'session' ? (+ <span className="tool-pair-name">{subtitle || t('chatUi.toolGroup.sessionCompleted')}</span>+ ) : (+ <>+ <span className="tool-pair-name">{toolCall.name}</span>+ {subtitle && <span className="tool-pair-summary">{subtitle}</span>}+ </>+ )}{hasResult && (<span className={clsx(@@ -106,6 +112,7 @@ export function ToolGroupDisplay({ executions }: ToolGroupDisplayProps) {const totalPairs = executions.length;const pendingCount = executions.filter((e) => e.status === 'pending').length;const timeoutCount = executions.filter((e) => e.status === 'timeout').length;+ const allSessionType = totalPairs > 0 && executions.every((e) => e.toolCall.name === 'session');useEffect(() => {if (!import.meta.env.DEV) {@@ -156,7 +163,9 @@ export function ToolGroupDisplay({ executions }: ToolGroupDisplayProps) {<path strokeLinecap="round" strokeLinejoin="round" d="M11.42 15.17L17.25 21A2.652 2.652 0 0021 17.25l-5.877-5.877M11.42 15.17l2.496-3.03c.317-.384.74-.626 1.208-.766M11.42 15.17l-4.655 5.653a2.548 2.548 0 11-3.586-3.586l6.837-5.63m5.108-.233c.55-.164 1.163-.188 1.743-.14a4.5 4.5 0 004.486-6.336l-3.276 3.277a3.004 3.004 0 01-2.25-2.25l3.276-3.276a4.5 4.5 0 00-6.336 4.486c.091 1.076-.071 2.264-.904 2.95l-.102.085m-1.745 1.437L5.909 7.5H4.5L2.25 3.75l1.5-1.5L7.5 4.5v1.409l4.26 4.26m-1.745 1.437l1.745-1.437m6.615 8.206L15.75 15.75M4.867 19.125h.008v.008h-.008v-.008z" /></svg><span>- {t('chatUi.toolGroup.executed', { totalPairs })}+ {allSessionType+ ? t('chatUi.toolGroup.sessionExecuted', { count: totalPairs })+ : t('chatUi.toolGroup.executed', { totalPairs })}{pendingCount > 0 && <span className="tool-group-pending"> ({t('chatUi.toolGroup.pending', { pendingCount })})</span>}{timeoutCount > 0 && <span className="tool-group-pending warning"> ({t('chatUi.toolGroup.timeout', { timeoutCount })})</span>}</span>diff --git a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx b/jiuwenclaw/web/src/components/ConfigPanel/index.tsxindex 00a80445fc..e809856cc5 100644--- a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx+++ b/jiuwenclaw/web/src/components/ConfigPanel/index.tsx@@ -18,7 +18,6 @@ const MODEL_DEFAULT_KEYS = new Set(["api_base", "api_key", "model", "model_proviconst MODEL_VIDEO_KEYS = new Set(["video_api_base", "video_api_key", "video_model", "video_provider"]);const MODEL_AUDIO_KEYS = new Set(["audio_api_base", "audio_api_key", "audio_model", "audio_provider"]);const MODEL_VISION_KEYS = new Set(["vision_api_base", "vision_api_key", "vision_model", "vision_provider"]);-const MODEL_KEYS = new Set([...MODEL_DEFAULT_KEYS, ...MODEL_VIDEO_KEYS, ...MODEL_AUDIO_KEYS, ...MODEL_VISION_KEYS]);const EMBED_KEYS = new Set(["embed_api_base", "embed_api_key", "embed_model"]);const EMAIL_KEYS = new Set(["email_address", "email_token"]);const THIRD_PARTY_API_KEYS = new Set([diff --git a/jiuwenclaw/web/src/hooks/useWebSocket.ts b/jiuwenclaw/web/src/hooks/useWebSocket.tsindex 5886a76817..d13409b045 100644--- a/jiuwenclaw/web/src/hooks/useWebSocket.ts+++ b/jiuwenclaw/web/src/hooks/useWebSocket.ts@@ -19,6 +19,8 @@ import {MediaItem,AgentMode,Session,+ ToolResult,+ ToolCall,} from '../types';import { useChatStore, useTodoStore, useSessionStore } from '../stores';import { webClient } from '../services/webClient';@@ -791,6 +793,76 @@ export function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {if (!shouldHandleSessionEvent(payload)) return;setPendingQuestion(payload as unknown as AskUserQuestionPayload);}),+ // 同时监听 session_result 事件,以处理后端可能发送的不同格式+ webClient.on('session_result', ({ payload }) => {+ setThinking(false);+ const sessionId =+ typeof payload.session_id === 'string' ? payload.session_id : '';+ const description =+ typeof payload.description === 'string' ? payload.description : '';+ const result = typeof payload.result === 'string' ? payload.result : '';+ // 创建工具调用对象+ const toolCallId = `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;+ const sessionToolCall: ToolCall = {+ id: toolCallId,+ name: 'session',+ arguments: {+ session_id: sessionId,+ description: description,+ },+ description: description || '会话完成',+ formatted_args: `会话任务:【${description || '未知任务'}】`,+ };+ addToolCall(sessionToolCall);+ // 组合 description 和 result 作为完整结果+ const fullResult = description+ ? `描述: ${description}\n\n结果: ${result}`+ : result;+ const sessionResult: ToolResult = {+ toolName: 'session',+ result: fullResult,+ success: true,+ toolCallId: toolCallId,+ summary: '完成',+ };+ addToolResult(sessionResult);+ }),+ webClient.on('chat.session_result', ({ payload }) => {+ if (shouldDropDuplicatedEvent('chat.session_result', payload)) {+ return;+ }+ setThinking(false);+ const sessionId =+ typeof payload.session_id === 'string' ? payload.session_id : '';+ const description =+ typeof payload.description === 'string' ? payload.description : '';+ const result = typeof payload.result === 'string' ? payload.result : '';+ // 创建工具调用对象+ const toolCallId = `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;+ const sessionToolCall: ToolCall = {+ id: toolCallId,+ name: 'session',+ arguments: {+ session_id: sessionId,+ description: description,+ },+ description: description || '会话完成',+ formatted_args: `会话任务:【${description || '未知任务'}】`,+ };+ addToolCall(sessionToolCall);+ // 组合 description 和 result 作为完整结果+ const fullResult = description+ ? `描述: ${description}\n\n结果: ${result}`+ : result;+ const sessionResult: ToolResult = {+ toolName: 'session',+ result: fullResult,+ success: true,+ toolCallId: toolCallId,+ summary: '完成',+ };+ addToolResult(sessionResult);+ }),];return () => {diff --git a/jiuwenclaw/web/src/i18n/locales/en.json b/jiuwenclaw/web/src/i18n/locales/en.jsonindex ab3d0f5e8e..d3c71bce64 100644--- a/jiuwenclaw/web/src/i18n/locales/en.json+++ b/jiuwenclaw/web/src/i18n/locales/en.json@@ -599,6 +599,9 @@},"toolGroup": {"executed": "{{totalPairs}} tool calls executed",+ "sessionExecuted": "{{count}} session tasks completed",+ "sessionCompleted": "Session task completed",+ "sessionFailed": "Session failed","pending": "{{pendingCount}} running","timeout": "{{timeoutCount}} timed out","latest": "↓ Latest"diff --git a/jiuwenclaw/web/src/i18n/locales/zh.json b/jiuwenclaw/web/src/i18n/locales/zh.jsonindex 59acb33523..de3e03be6b 100644--- a/jiuwenclaw/web/src/i18n/locales/zh.json+++ b/jiuwenclaw/web/src/i18n/locales/zh.json@@ -599,6 +599,9 @@},"toolGroup": {"executed": "已执行 {{totalPairs}} 次工具调用",+ "sessionExecuted": "{{count}} 个会话任务已完成",+ "sessionCompleted": "会话任务已完成",+ "sessionFailed": "会话失败","pending": "{{pendingCount}} 个执行中","timeout": "{{timeoutCount}} 个超时","latest": "↓ 最新"diff --git a/jiuwenclaw/web/src/index.css b/jiuwenclaw/web/src/index.cssindex 68c456f992..2f520688fc 100644--- a/jiuwenclaw/web/src/index.css+++ b/jiuwenclaw/web/src/index.css@@ -1103,6 +1103,31 @@ select {color: var(--warn);}+ .tool-pair-icon.session {+ background: var(--accent-subtle);+ color: var(--accent);+ }++ .tool-pair-item-session {+ background: rgba(96, 165, 250, 0.05);+ border-bottom: 1px solid rgba(96, 165, 250, 0.15);+ }++ .tool-pair-pre-session {+ background: rgba(96, 165, 250, 0.08);+ border-color: rgba(96, 165, 250, 0.3);+ }++ :root[data-theme="light"] .tool-pair-item-session {+ background: rgba(96, 165, 250, 0.08);+ border-bottom: 1px solid rgba(96, 165, 250, 0.2);+ }++ :root[data-theme="light"] .tool-pair-pre-session {+ background: rgba(96, 165, 250, 0.12);+ border-color: rgba(96, 165, 250, 0.4);+ }+.tool-pair-name {font-family: var(--mono);font-size: 13px;