Compare commits

..

No commits in common. "bf724b133cf4f9002d72e0b8e3f89c7fef63edec" and "2607ca4aa4a9533722f364ae817ea7944fe7d866" have entirely different histories.

6 changed files with 218 additions and 337 deletions

View File

@ -144,8 +144,12 @@ fn reconstruct_task_from_db(
})
.unwrap_or_default();
// Extract subagent_type and description from title
let (subagent_type, description) = parse_subagent_title(&record.title);
// Extract description from title: "Subagent: {description}"
let description = record
.title
.strip_prefix("Subagent: ")
.unwrap_or(&record.title)
.to_string();
let now = record.updated_at;
@ -157,7 +161,7 @@ fn reconstruct_task_from_db(
parent_chat_id: record.chat_id.clone(),
parent_channel_name: record.channel_name.clone(),
description,
subagent_type,
subagent_type: "general".to_string(),
state: TaskSessionState::Completed,
created_at: record.created_at,
updated_at: now,
@ -165,18 +169,3 @@ fn reconstruct_task_from_db(
error: None,
}))
}
/// Parse subagent title to extract type and description.
/// New format: "Subagent [type]: description"
/// Legacy format: "Subagent: description" (defaults to "general")
fn parse_subagent_title(title: &str) -> (String, String) {
if let Some(rest) = title.strip_prefix("Subagent [") {
if let Some(bracket_pos) = rest.find("]: ") {
let agent_type = rest[..bracket_pos].to_string();
let desc = rest[bracket_pos + 3..].to_string();
return (agent_type, desc);
}
}
let desc = title.strip_prefix("Subagent: ").unwrap_or(title).to_string();
("general".to_string(), desc)
}

View File

@ -509,7 +509,7 @@ impl SubAgentRuntime for DefaultSubAgentRuntime {
);
// 4. 在 sessions 表中创建子智能体会话(确保外键约束满足)
let session_title = format!("Subagent [{}]: {}", session.subagent_type, task.description);
let session_title = format!("Subagent: {}", task.description);
if let Err(e) = self.conversation_repository.ensure_session(
&session.session_id,
&session.parent_channel_name,
@ -638,7 +638,7 @@ impl SubAgentRuntime for DefaultSubAgentRuntime {
}
// 3. 确保 sessions 表中存在子智能体会话记录
let session_title = format!("Subagent [{}]: {}", session.subagent_type, session.description);
let session_title = format!("Subagent: {}", session.description);
if let Err(e) = self.conversation_repository.ensure_session(
&session.session_id,
&session.parent_channel_name,

View File

@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { Zap, ArrowLeft, Bot, Clock, Sun, Moon, PanelRightOpen, X, Brain, Settings as SettingsIcon, ChevronRight } from 'lucide-react'
import { Zap, ArrowLeft, Bot, Clock, Sun, Moon, PanelRightOpen, X, Brain, Settings as SettingsIcon } from 'lucide-react'
import { ChatContainer } from './components/Chat/ChatContainer'
import { TopicList } from './components/Sidebar/TopicList'
import { SchedulerJobList } from './components/Sidebar/SchedulerJobList'
@ -40,7 +40,6 @@ function App() {
isReadOnly,
// 子智能体视图
subAgentView,
subAgentStack,
// 记忆
memories,
requestMemoryList,
@ -86,7 +85,6 @@ function App() {
topicRefreshTrigger,
enterSubAgentView,
exitSubAgentView,
navigateToSubAgentLevel,
handleStop,
} = useChat()
@ -609,66 +607,45 @@ function App() {
</div>
</div>
)}
{/* Sub-agent breadcrumb bar */}
{/* Sub-agent back bar */}
{subAgentView && (
<div className="shrink-0 border-b border-[var(--border-color)] bg-[var(--bg-secondary)]/80 px-4 py-2 flex items-center gap-2">
<div className="shrink-0 border-b border-[var(--border-color)] bg-[var(--bg-secondary)]/80 px-4 py-2 flex items-center gap-4">
<button
onClick={handleExitSubAgentView}
className="flex items-center gap-1 text-sm text-[var(--accent-cyan)] hover:text-[var(--accent-cyan)]/80 transition-colors shrink-0"
title="返回上一级"
className="flex items-center gap-1.5 text-sm text-[var(--accent-cyan)] hover:text-[var(--accent-cyan)]/80 transition-colors"
>
<ArrowLeft className="h-4 w-4" />
<span></span>
</button>
{/* Breadcrumb: 主会话 */}
<button
onClick={() => navigateToSubAgentLevel(-1)}
className="flex items-center gap-1 text-sm text-[var(--text-muted)] hover:text-[var(--accent-cyan)] transition-colors shrink-0"
title="返回主会话"
>
<Bot className="h-3.5 w-3.5" />
<span></span>
</button>
{/* Breadcrumb: each sub-agent level */}
{subAgentStack.map((level, idx) => {
const isLast = idx === subAgentStack.length - 1
const statusText =
level.status === 'completed' ? '已完成' :
level.status === 'failed' ? '失败' :
level.status === 'timeout' ? '超时' :
level.status === 'running' ? '执行中' :
level.status === 'loading' ? '加载中...' :
level.status
const statusColor =
level.status === 'completed' ? 'text-emerald-400' :
level.status === 'failed' ? 'text-red-400' :
level.status === 'timeout' ? 'text-amber-400' :
level.status === 'running' ? 'text-amber-400' :
<div className="h-4 w-px bg-[var(--divider-color)]" />
<div className="flex items-center gap-1.5 text-sm text-[var(--text-secondary)]">
<Bot className="h-4 w-4 text-violet-400" />
<span className="text-[var(--text-muted)]">:</span>
<span className="text-[var(--text-primary)] font-medium">{subAgentView.description}</span>
</div>
<div className="h-4 w-px bg-[var(--divider-color)]" />
<div className="flex items-center gap-1.5 text-sm">
<span className="text-[var(--text-muted)]">:</span>
<span className="text-[var(--text-secondary)]">{subAgentView.subagentType || '...'}</span>
</div>
<div className="h-4 w-px bg-[var(--divider-color)]" />
<div className="flex items-center gap-1.5 text-sm">
<span className="text-[var(--text-muted)]">:</span>
<span className={`font-medium ${
subAgentView.status === 'completed' ? 'text-emerald-400' :
subAgentView.status === 'failed' ? 'text-red-400' :
subAgentView.status === 'timeout' ? 'text-amber-400' :
subAgentView.status === 'running' ? 'text-amber-400' :
'text-[var(--text-secondary)]'
return (
<div key={level.taskId} className="flex items-center gap-2 min-w-0">
<ChevronRight className="h-3.5 w-3.5 text-[var(--text-muted)] shrink-0" />
{isLast ? (
<div className="flex items-center gap-2 text-sm min-w-0">
<span className="text-[var(--text-primary)] font-medium truncate">{level.description}</span>
{level.subagentType && (
<span className="text-xs text-[var(--text-muted)] bg-[var(--overlay-dim)] px-1.5 py-0.5 rounded shrink-0">{level.subagentType}</span>
)}
<span className={`text-xs font-medium shrink-0 ${statusColor}`}>{statusText}</span>
}`}>
{subAgentView.status === 'completed' ? '已完成' :
subAgentView.status === 'failed' ? '失败' :
subAgentView.status === 'timeout' ? '超时' :
subAgentView.status === 'running' ? '执行中' :
subAgentView.status === 'loading' ? '加载中...' :
subAgentView.status}
</span>
</div>
) : (
<button
onClick={() => navigateToSubAgentLevel(idx)}
className="flex items-center gap-2 text-sm text-[var(--text-muted)] hover:text-[var(--accent-cyan)] transition-colors min-w-0"
>
<span className="truncate">{level.description}</span>
{level.subagentType && (
<span className="text-xs bg-[var(--overlay-dim)] px-1.5 py-0.5 rounded shrink-0">{level.subagentType}</span>
)}
</button>
)}
</div>
)
})}
</div>
)}
<div className="flex-1 min-h-0">
@ -686,13 +663,6 @@ function App() {
onNavigateToSubAgent={handleNavigateToSubAgent}
onStop={handleStopExecution}
showThinking={showThinking}
todoPanel={
<TodoPanel
todos={todos}
requestTodoList={refreshTodoList}
sendCommand={sendMemoryCommand}
/>
}
/>
</div>
</div>
@ -761,6 +731,13 @@ function App() {
)}
</div>
{/* 悬浮 Todo 面板 */}
<TodoPanel
todos={todos}
requestTodoList={refreshTodoList}
sendCommand={sendMemoryCommand}
/>
{/* 系统配置页面 */}
{configPageOpen && (
<ConfigPage onClose={() => setConfigPageOpen(false)} onSaveConnection={handleSaveConnection} />

View File

@ -11,8 +11,6 @@ interface ChatContainerProps {
onNavigateToSubAgent?: (taskId: string, description: string) => void
onStop?: () => void
showThinking?: boolean
/** 浮动待办面板,绝对定位在消息区域上方 */
todoPanel?: React.ReactNode
}
export function ChatContainer({
@ -24,13 +22,11 @@ export function ChatContainer({
onNavigateToSubAgent,
onStop,
showThinking = true,
todoPanel,
}: ChatContainerProps) {
return (
<div className="flex h-full flex-col relative">
<div className="flex-1 overflow-hidden relative">
<div className="flex h-full flex-col">
<div className="flex-1 overflow-hidden">
<MessageList messages={messages} onNavigateToSubAgent={onNavigateToSubAgent} showThinking={showThinking} />
{todoPanel}
</div>
<MessageInput
onSend={onSendMessage}

View File

@ -1,5 +1,5 @@
import { useState, useCallback, useEffect, useRef } from 'react'
import { ClipboardList, ChevronDown, RefreshCw } from 'lucide-react'
import { ClipboardList, ChevronUp, ChevronDown, Circle } from 'lucide-react'
import type { TodoItemSummary, Command } from '../../types/protocol'
interface TodoPanelProps {
@ -8,22 +8,33 @@ interface TodoPanelProps {
sendCommand: (cmd: Command) => void
}
/* ── status config ────────────────────────────────────── */
/* ── status helpers ───────────────────────────────────── */
interface StatusCfg { label: string; color: string; dot: string }
interface StatusStyle { label: string; border: string; dot: string; text: string; icon: string }
const STATUS: Record<string, StatusCfg> = {
in_progress: { label: '进行中', color: 'text-amber-400', dot: 'bg-amber-400' },
pending: { label: '待处理', color: 'text-slate-400', dot: 'bg-slate-500' },
completed: { label: '已完成', color: 'text-emerald-400', dot: 'bg-emerald-400' },
cancelled: { label: '已取消', color: 'text-slate-500', dot: 'bg-slate-600' },
const STATUS: Record<string, StatusStyle> = {
in_progress: { label: '进行中', border: 'border-amber-400/60', dot: 'bg-amber-400 shadow-[0_0_6px_#fbbf24]', text: 'text-amber-300', icon: '●' },
pending: { label: '待处理', border: 'border-slate-500/50', dot: 'bg-slate-500', text: 'text-slate-400', icon: '○' },
completed: { label: '已完成', border: 'border-emerald-400/40', dot: 'bg-emerald-400', text: 'text-emerald-400', icon: '✓' },
cancelled: { label: '已取消', border: 'border-red-400/40', dot: 'bg-red-400', text: 'text-red-400', icon: '✕' },
}
function statusCfg(s: string): StatusCfg {
return STATUS[s] ?? { label: s, color: 'text-slate-400', dot: 'bg-slate-500' }
function statusStyle(s: string): StatusStyle {
return STATUS[s] ?? { label: s, border: 'border-[var(--border-color)]', dot: 'bg-[var(--text-muted)]', text: 'text-[var(--text-muted)]', icon: '?' }
}
const PRIORITY: Record<string, string> = {
high: 'text-rose-400',
medium: 'text-amber-400',
low: 'text-slate-400',
}
function priorityDot(p: string) { return PRIORITY[p] ?? 'text-slate-400' }
/* ── group helpers ────────────────────────────────────── */
const GROUP_ORDER = ['in_progress', 'pending', 'completed', 'cancelled']
const COLLAPSED_DEFAULT = new Set(['completed', 'cancelled'])
function groupTodos(todos: TodoItemSummary[]): Map<string, TodoItemSummary[]> {
const map = new Map<string, TodoItemSummary[]>()
@ -39,49 +50,34 @@ function groupTodos(todos: TodoItemSummary[]): Map<string, TodoItemSummary[]> {
function PulseDot() {
return (
<span className="relative flex h-1.5 w-1.5 shrink-0">
<span className="relative flex h-2 w-2">
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75" />
<span className="relative inline-flex rounded-full h-1.5 w-1.5 bg-amber-400" />
<span className="relative inline-flex rounded-full h-2 w-2 bg-amber-400 shadow-[0_0_6px_#fbbf24]" />
</span>
)
}
/* ── position persistence ─────────────────────────────── */
const POS_KEY = 'picobot-todo-pos'
function loadPos(): { x: number; y: number } {
try {
const raw = localStorage.getItem(POS_KEY)
if (raw) return JSON.parse(raw)
} catch { /* ignore */ }
return { x: 0, y: 0 }
}
function savePos(pos: { x: number; y: number }) {
try { localStorage.setItem(POS_KEY, JSON.stringify(pos)) } catch { /* ignore */ }
}
/* ── TodoPanel ────────────────────────────────────────── */
export function TodoPanel({ todos, requestTodoList, sendCommand }: TodoPanelProps) {
const [expanded, setExpanded] = useState(() => {
try { return localStorage.getItem('picobot-todo-expanded') === 'true' } catch { return false }
try { return localStorage.getItem('picobot-todo-panel-open') === 'true' } catch { return false }
})
const [collapsedGroups, setCollapsedGroups] = useState<Set<string>>(() => new Set(['completed', 'cancelled']))
const [pos, setPos] = useState(loadPos)
const [collapsedGroups, setCollapsedGroups] = useState<Set<string>>(() => new Set(COLLAPSED_DEFAULT))
const prevTodoIdsRef = useRef<Set<string>>(new Set())
const dragRef = useRef<{ startX: number; startY: number; startPos: { x: number; y: number }; moved: boolean } | null>(null)
// 持久化展开状态
useEffect(() => {
localStorage.setItem('picobot-todo-expanded', String(expanded))
localStorage.setItem('picobot-todo-panel-open', String(expanded))
}, [expanded])
// auto-expand on new items
// 当有新 todo 出现时自动展开
useEffect(() => {
const newIds = new Set(todos.map(t => t.id))
const hasNewItems = todos.some(t => !prevTodoIdsRef.current.has(t.id))
if (hasNewItems && todos.length > 0) setExpanded(true)
if (hasNewItems && todos.length > 0) {
setExpanded(true)
}
prevTodoIdsRef.current = newIds
}, [todos])
@ -97,149 +93,105 @@ export function TodoPanel({ todos, requestTodoList, sendCommand }: TodoPanelProp
})
}, [])
const handleRefresh = useCallback(() => sendCommand(requestTodoList()), [sendCommand, requestTodoList])
/* ── drag handling ──────────────────────────────────── */
const handleDragStart = useCallback((e: React.MouseEvent) => {
if ((e.target as HTMLElement).closest('button')) return
e.preventDefault()
const startX = e.clientX
const startY = e.clientY
const startPos = { ...pos }
dragRef.current = { startX, startY, startPos, moved: false }
const handleMove = (ev: MouseEvent) => {
if (!dragRef.current) return
const dx = ev.clientX - dragRef.current.startX
const dy = ev.clientY - dragRef.current.startY
if (Math.abs(dx) > 3 || Math.abs(dy) > 3) dragRef.current.moved = true
setPos({
x: Math.max(0, dragRef.current.startPos.x - dx),
y: Math.max(0, dragRef.current.startPos.y + dy),
})
}
const handleUp = () => {
document.removeEventListener('mousemove', handleMove)
document.removeEventListener('mouseup', handleUp)
document.body.style.userSelect = ''
document.body.style.cursor = ''
if (dragRef.current) {
setPos(prev => { savePos(prev); return prev })
dragRef.current = null
}
}
document.addEventListener('mousemove', handleMove)
document.addEventListener('mouseup', handleUp)
document.body.style.userSelect = 'none'
document.body.style.cursor = 'grabbing'
}, [pos])
/* ── minimized: circle button ───────────────────────── */
if (!expanded) {
// ── 空状态 ──
if (totalCount === 0) {
return (
<div
className="absolute z-30"
style={{ top: `${16 + pos.y}px`, right: `${16 + pos.x}px` }}
>
<div
className="relative cursor-grab active:cursor-grabbing select-none"
onMouseDown={handleDragStart}
>
<div className="fixed bottom-4 right-4 z-50">
<button
onClick={() => { if (totalCount > 0) setExpanded(true); else handleRefresh() }}
className="relative w-12 h-12 rounded-full bg-[var(--bg-tertiary)]/90 backdrop-blur-md border border-[var(--border-color)] hover:border-[var(--accent-cyan)]/40 shadow-lg hover:shadow-[0_0_20px_var(--shadow-glow-sm)] transition-all duration-300 group"
title="待办"
onClick={() => sendCommand(requestTodoList())}
className="flex items-center gap-2 px-3 py-2 rounded-xl bg-[var(--bg-tertiary)]/70 backdrop-blur-sm border border-[var(--border-color)] text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:border-[var(--border-accent)] transition-all duration-300 shadow-lg text-xs"
title="刷新待办"
>
<div className="flex flex-col items-center justify-center">
<ClipboardList className="h-3.5 w-3.5 text-[var(--text-muted)] group-hover:text-[var(--accent-cyan)] transition-colors" />
<span className="text-[8px] font-bold text-[var(--text-muted)] group-hover:text-[var(--accent-cyan)] transition-colors mt-0.5">
ToDo
</span>
</div>
{totalCount > 0 && (
<span className={`absolute -top-1 -right-1 min-w-[18px] h-[18px] rounded-full flex items-center justify-center text-[10px] font-bold shadow-md ${
inProgressCount > 0
? 'bg-amber-400 text-black'
: 'bg-[var(--bg-secondary)] text-[var(--text-secondary)] border border-[var(--border-color)]'
}`}>
{totalCount}
</span>
)}
{inProgressCount > 0 && (
<span className="absolute inset-0 rounded-full border-2 border-amber-400/30 animate-ping" />
)}
<ClipboardList className="h-3.5 w-3.5" />
<span></span>
</button>
</div>
</div>
)
}
/* ── expanded: full card ────────────────────────────── */
// ── 折叠态 ──
if (!expanded) {
return (
<div
className="absolute z-30"
style={{ top: `${16 + pos.y}px`, right: `${16 + pos.x}px` }}
<div className="fixed bottom-4 right-4 z-50">
<button
onClick={() => setExpanded(true)}
className="flex items-center gap-2 px-3 py-2 rounded-xl bg-[var(--bg-tertiary)]/80 backdrop-blur-sm border border-[var(--border-color)] hover:border-[var(--accent-cyan)]/30 transition-all duration-300 shadow-lg group"
>
<div className="w-72 max-h-[50vh] flex flex-col rounded-xl bg-[var(--bg-tertiary)]/95 backdrop-blur-md border border-[var(--border-color)] shadow-2xl overflow-hidden">
{/* title bar (drag handle) */}
<div
className="shrink-0 flex items-center gap-2 px-3 py-2 border-b border-[var(--border-color)]/50 cursor-grab active:cursor-grabbing select-none"
onMouseDown={handleDragStart}
>
<span className="text-[var(--text-muted)]/30 text-[10px] leading-none select-none"></span>
<ClipboardList className="h-3 w-3 text-[var(--accent-cyan)]" />
<span className="text-[11px] font-semibold text-[var(--text-secondary)]"></span>
<span className="text-[10px] text-[var(--text-muted)]/70 tabular-nums">{totalCount}</span>
{inProgressCount > 0 && <PulseDot />}
<div className="ml-auto flex items-center gap-0.5">
<button onClick={handleRefresh} className="p-1 rounded text-[var(--text-muted)]/50 hover:text-[var(--accent-cyan)] transition-colors" title="刷新">
<RefreshCw className="h-3 w-3" />
</button>
<button onClick={() => setExpanded(false)} className="p-1 rounded text-[var(--text-muted)]/50 hover:text-[var(--text-secondary)] transition-colors" title="缩小">
<ChevronDown className="h-3 w-3" />
{inProgressCount > 0 ? <PulseDot /> : <ClipboardList className="h-3.5 w-3.5 text-[var(--text-muted)]" />}
<span className="text-sm font-medium text-[var(--text-secondary)] group-hover:text-[var(--accent-cyan)] transition-colors">
({totalCount})
</span>
<ChevronUp className="h-3.5 w-3.5 text-[var(--text-muted)]" />
</button>
</div>
)
}
// ── 展开态 ──
return (
<div className="fixed bottom-4 right-4 z-50 w-72 max-h-[60vh] flex flex-col rounded-xl border border-[var(--border-color)] bg-[var(--bg-tertiary)]/95 backdrop-blur-md shadow-2xl overflow-hidden transition-all duration-300">
{/* 标题栏 */}
<div className="shrink-0 flex items-center justify-between px-3 py-2.5 border-b border-[var(--border-color)]">
<div className="flex items-center gap-2">
<ClipboardList className="h-4 w-4 text-[var(--accent-cyan)]" />
<span className="text-sm font-semibold text-[var(--text-primary)]"></span>
<span className="text-[11px] text-[var(--text-muted)] tabular-nums"> {totalCount} </span>
</div>
<button
onClick={() => setExpanded(false)}
className="p-1 rounded hover:bg-[var(--overlay-subtle)] text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors"
>
<ChevronDown className="h-4 w-4" />
</button>
</div>
{/* list */}
<div className="flex-1 overflow-y-auto scrollbar-hide px-3 py-2">
{/* 列表区 */}
<div className="flex-1 overflow-y-auto scrollbar-hide px-2 py-2 space-y-2">
{GROUP_ORDER.map(status => {
const items = grouped.get(status)
if (!items || items.length === 0) return null
const cfg = statusCfg(status)
const style = statusStyle(status)
const isCollapsed = collapsedGroups.has(status)
const isTerminal = status === 'completed' || status === 'cancelled'
return (
<div key={status} className="mt-1 first:mt-0">
<div key={status}>
{/* 分组标题 */}
<button
onClick={() => toggleGroup(status)}
className="flex items-center gap-1.5 w-full py-0.5 group"
className="flex items-center gap-1.5 w-full px-1 py-1 text-xs text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors"
>
<span className={`h-1.5 w-1.5 rounded-full ${cfg.dot} shrink-0`} />
<span className={`text-[10px] font-medium ${cfg.color}`}>{cfg.label}</span>
<span className={`text-[10px] ${cfg.color} opacity-60 tabular-nums`}>{items.length}</span>
<span className="ml-auto text-[var(--text-muted)]/40">
{isCollapsed
? <ChevronDown className="h-2.5 w-2.5 rotate-[-90deg]" />
: <ChevronDown className="h-2.5 w-2.5" />
}
</span>
{isCollapsed ? (
<ChevronUp className="h-3 w-3" />
) : (
<ChevronDown className="h-3 w-3" />
)}
<span className={style.text}>{style.icon}</span>
<span>{style.label}</span>
<span className="tabular-nums">({items.length})</span>
</button>
{/* 卡片列表 */}
{!isCollapsed && (
<div className="ml-3 border-l border-[var(--border-color)]/30 pl-2 mt-0.5 space-y-px">
<div className="space-y-1">
{items.map(item => (
<div key={item.id} className="py-[3px]">
<span className="text-[12px] leading-snug text-[var(--text-primary)]/90 break-words">
{item.content}
<div
key={item.id}
className={`rounded-lg border-l-2 ${style.border} border border-[var(--border-color)] bg-[var(--overlay-hover)]/50 px-2.5 py-1.5 transition-colors hover:border-[var(--border-accent)]`}
>
<div className="flex items-start gap-2">
<span className={`mt-0.5 shrink-0 ${priorityDot(item.priority)}`}>
<Circle className="h-2 w-2 fill-current" />
</span>
<div className="min-w-0 flex-1">
<p className={`text-[13px] leading-snug text-[var(--text-primary)] break-words ${
isTerminal ? 'line-through opacity-50' : ''
}`}>
{item.content}
</p>
</div>
</div>
</div>
))}
</div>
@ -248,6 +200,15 @@ export function TodoPanel({ todos, requestTodoList, sendCommand }: TodoPanelProp
)
})}
</div>
{/* 底部刷新 */}
<div className="shrink-0 border-t border-[var(--border-color)] px-3 py-1.5">
<button
onClick={() => sendCommand(requestTodoList())}
className="text-[10px] text-[var(--text-muted)] hover:text-[var(--accent-cyan)] transition-colors"
>
</button>
</div>
</div>
)

View File

@ -59,9 +59,8 @@ interface UseChatReturn {
// 是否只读
isReadOnly: boolean
// 子智能体视图(栈结构,支持面包屑导航)
// 子智能体视图
subAgentView: SubAgentView | null
subAgentStack: SubAgentView[]
// 方法
handleMessage: (content: string, attachments?: Attachment[]) => void
@ -87,7 +86,6 @@ interface UseChatReturn {
// 子智能体导航方法
enterSubAgentView: (taskId: string, description: string) => Command
exitSubAgentView: () => void
navigateToSubAgentLevel: (index: number) => void
// 记忆状态
memories: MemorySummary[]
@ -151,8 +149,7 @@ export function useChat(): UseChatReturn {
const [topicRefreshTrigger, setTopicRefreshTrigger] = useState(0)
const [sessions, setSessions] = useState<SessionSummary[]>([])
const [selectedSessionId, setSelectedSessionId] = useState<string | null>(null)
const [subAgentStack, setSubAgentStack] = useState<SubAgentView[]>([])
const subAgentView = useMemo(() => subAgentStack.length > 0 ? subAgentStack[subAgentStack.length - 1] : null, [subAgentStack])
const [subAgentView, setSubAgentView] = useState<SubAgentView | null>(null)
const [memories, setMemories] = useState<MemorySummary[]>([])
const [skills, setSkills] = useState<SkillSummary[]>([])
const [todos, setTodos] = useState<TodoItemSummary[]>([])
@ -305,12 +302,11 @@ export function useChat(): UseChatReturn {
// stream_delta: accumulate into existing message by ID, or create new
if (message.type === 'stream_delta') {
const msg = message as StreamDelta
setSubAgentStack((prev) => {
if (prev.length === 0) return prev
const top = prev[prev.length - 1]
const existingIdx = top.messages.findIndex(m => m.id === msg.id && m.type === 'message')
setSubAgentView((prev) => {
if (!prev) return prev
const existingIdx = prev.messages.findIndex(m => m.id === msg.id && m.type === 'message')
if (existingIdx >= 0) {
const updated = [...top.messages]
const updated = [...prev.messages]
const existing = updated[existingIdx]
updated[existingIdx] = {
...existing,
@ -319,15 +315,10 @@ export function useChat(): UseChatReturn {
? (existing.reasoningContent || '') + msg.reasoning_delta
: existing.reasoningContent,
}
const newStack = [...prev]
newStack[newStack.length - 1] = { ...top, messages: updated }
return newStack
return { ...prev, messages: updated }
}
const chatMsg = serverMessageToChatMessage(message)
if (!chatMsg) return prev
const newStack = [...prev]
newStack[newStack.length - 1] = { ...top, messages: [...top.messages, chatMsg] }
return newStack
return chatMsg ? { ...prev, messages: [...prev.messages, chatMsg] } : prev
})
return
}
@ -336,22 +327,17 @@ export function useChat(): UseChatReturn {
// Other messages: assistant_response replaces streamed message by ID
const chatMsg = serverMessageToChatMessage(message)
if (chatMsg) {
setSubAgentStack((prev) => {
if (prev.length === 0) return prev
const top = prev[prev.length - 1]
setSubAgentView((prev) => {
if (!prev) return prev
if (message.type === 'assistant_response') {
const existingIdx = top.messages.findIndex(m => m.id === chatMsg.id && m.type === 'message')
const existingIdx = prev.messages.findIndex(m => m.id === chatMsg.id && m.type === 'message')
if (existingIdx >= 0) {
const updated = [...top.messages]
const updated = [...prev.messages]
updated[existingIdx] = chatMsg
const newStack = [...prev]
newStack[newStack.length - 1] = { ...top, messages: updated }
return newStack
return { ...prev, messages: updated }
}
}
const newStack = [...prev]
newStack[newStack.length - 1] = { ...top, messages: [...top.messages, chatMsg] }
return newStack
return { ...prev, messages: [...prev.messages, chatMsg] }
})
}
}
@ -380,18 +366,16 @@ export function useChat(): UseChatReturn {
if (currentSubAgentView) {
if (message.type === 'task_messages_loaded') {
const msg = message as TaskMessagesLoaded
setSubAgentStack((prev) => {
if (prev.length === 0) return prev
const top = prev[prev.length - 1]
const newStack = [...prev]
newStack[newStack.length - 1] = {
...top,
setSubAgentView((prev) =>
prev
? {
...prev,
subagentType: msg.subagent_type,
status: msg.status,
summary: msg.summary,
}
return newStack
})
: prev
)
return
}
@ -772,7 +756,7 @@ export function useChat(): UseChatReturn {
const selectTopic = useCallback((topicId: string) => {
setSelectedTopic(topicId)
setMessages([])
setSubAgentStack([])
setSubAgentView(null)
}, [])
const createTopic = useCallback((title?: string): Command => {
@ -818,7 +802,7 @@ export function useChat(): UseChatReturn {
setTopics([])
setSelectedTopic(null)
setMessages([])
setSubAgentStack([])
setSubAgentView(null)
setIsLoading(true)
}, [selectedChannel])
@ -828,7 +812,7 @@ export function useChat(): UseChatReturn {
setTopics([])
setSelectedTopic(null)
setMessages([])
setSubAgentStack([])
setSubAgentView(null)
setIsLoading(true)
}, [selectedSessionId])
@ -865,12 +849,9 @@ export function useChat(): UseChatReturn {
status: 'loading',
messages: [],
}
setSubAgentStack((prev) => {
const newStack = [...prev, newView]
// Sync ref immediately so WebSocket response routing works correctly
subAgentViewRef.current = newView
return newStack
})
setSubAgentView(newView)
return {
type: 'load_task_messages',
task_id: taskId,
@ -878,29 +859,8 @@ export function useChat(): UseChatReturn {
}, [])
const exitSubAgentView = useCallback(() => {
setSubAgentStack((prev) => {
if (prev.length <= 1) {
subAgentViewRef.current = null
return []
}
const newStack = prev.slice(0, -1)
subAgentViewRef.current = newStack[newStack.length - 1]
return newStack
})
}, [])
const navigateToSubAgentLevel = useCallback((index: number) => {
setSubAgentStack((prev) => {
if (index < 0) {
// -1 means go back to main session (clear all)
subAgentViewRef.current = null
return []
}
if (index >= prev.length) return prev
const newStack = prev.slice(0, index + 1)
subAgentViewRef.current = newStack.length > 0 ? newStack[newStack.length - 1] : null
return newStack
})
setSubAgentView(null)
}, [])
// 记忆方法
@ -997,7 +957,6 @@ export function useChat(): UseChatReturn {
channels,
selectedChannel,
subAgentView,
subAgentStack,
handleMessage,
handleCommand,
clearMessages,
@ -1015,7 +974,6 @@ export function useChat(): UseChatReturn {
selectSession,
enterSubAgentView,
exitSubAgentView,
navigateToSubAgentLevel,
memories,
requestMemoryList,
createMemory,