Compare commits

...

3 Commits

5 changed files with 150 additions and 39 deletions

View File

@ -27,8 +27,8 @@ const TODO_WRITE_INSTRUCTIONS: &str = r#"
- todo - todo
### merge ### merge
- `merge: false` todo - `merge: true` **使**
- `merge: true` **使 merge=true** - `merge: false` todo
### ###
- `pending` - `pending`

View File

@ -26,6 +26,7 @@ pub(crate) fn ws_outbound_from_chat_message(message: &ChatMessage) -> Vec<WsOutb
topic_id: None, topic_id: None,
timestamp: None, timestamp: None,
reasoning_content: message.reasoning_content.clone(), reasoning_content: message.reasoning_content.clone(),
user_message_id: None,
}); });
} }
@ -42,6 +43,7 @@ pub(crate) fn ws_outbound_from_chat_message(message: &ChatMessage) -> Vec<WsOutb
topic_id: None, topic_id: None,
timestamp: None, timestamp: None,
reasoning_content: tc_reasoning.clone(), reasoning_content: tc_reasoning.clone(),
user_message_id: None,
})); }));
outbound outbound
} else { } else {
@ -54,6 +56,7 @@ pub(crate) fn ws_outbound_from_chat_message(message: &ChatMessage) -> Vec<WsOutb
topic_id: None, topic_id: None,
timestamp: None, timestamp: None,
reasoning_content: message.reasoning_content.clone(), reasoning_content: message.reasoning_content.clone(),
user_message_id: None,
}] }]
} }
} }

View File

@ -456,7 +456,7 @@ fn parse_attachments(value: &serde_json::Value) -> anyhow::Result<Vec<MediaItem>
return Err(anyhow!("attachment file is empty: {}", raw_path)); return Err(anyhow!("attachment file is empty: {}", raw_path));
} }
let content_base64 = (metadata.len() <= 50 * 1024 * 1024) let content_base64 = (metadata.len() <= 200 * 1024 * 1024)
.then(|| { .then(|| {
let mut file = std::fs::File::open(&resolved_path)?; let mut file = std::fs::File::open(&resolved_path)?;
let mut buf = Vec::with_capacity(metadata.len() as usize); let mut buf = Vec::with_capacity(metadata.len() as usize);

View File

@ -77,9 +77,9 @@ impl Tool for TodoWriteTool {
fn description(&self) -> &str { fn description(&self) -> &str {
"Manage a structured task list for tracking work within the current conversation. \ "Manage a structured task list for tracking work within the current conversation. \
Two modes: merge=false (default, full replacement omitted items are removed); \ Two modes: merge=true (default, incremental only send the items you want to add/update, \
merge=true (incremental only send the items you want to add/update, \ previously existing items are preserved); \
previously existing items are preserved). \ merge=false (full replacement omitted items are removed). \
Use when you have 3+ distinct steps to track. \ Use when you have 3+ distinct steps to track. \
Rules: only ONE in_progress at a time, complete work before marking completed, \ Rules: only ONE in_progress at a time, complete work before marking completed, \
every item requires an id (generate a short random string for new items)." every item requires an id (generate a short random string for new items)."
@ -91,7 +91,7 @@ impl Tool for TodoWriteTool {
"properties": { "properties": {
"merge": { "merge": {
"type": "boolean", "type": "boolean",
"description": "false (default): full replacement — todos not in the list are removed. true: incremental — only send items you want to add or update, existing items not mentioned are preserved." "description": "true (default): incremental — only send items you want to add or update, existing items not mentioned are preserved. false: full replacement — todos not in the list are removed."
}, },
"todos": { "todos": {
"type": "array", "type": "array",
@ -156,7 +156,7 @@ impl Tool for TodoWriteTool {
let merge_mode = args let merge_mode = args
.get("merge") .get("merge")
.and_then(|v| v.as_bool()) .and_then(|v| v.as_bool())
.unwrap_or(false); .unwrap_or(true);
// 3. 读锁获取旧状态 // 3. 读锁获取旧状态
let old_items = { let old_items = {
@ -754,11 +754,12 @@ mod tests {
.await .await
.unwrap(); .unwrap();
// 只传入一个任务任务B 被移除) // 全量替换:只传入一个任务任务B 被移除)
let result = tool let result = tool
.execute_with_context( .execute_with_context(
&context, &context,
json!({ json!({
"merge": false,
"todos": [ "todos": [
{"id": "i1", "content": "任务A", "status": "in_progress"} {"id": "i1", "content": "任务A", "status": "in_progress"}
] ]
@ -1054,11 +1055,12 @@ mod tests {
.await .await
.unwrap(); .unwrap();
// merge=false默认— 只传一个,另一个被删 // 显式指定 merge=false — 只传一个,另一个被删
let result = tool let result = tool
.execute_with_context( .execute_with_context(
&context, &context,
json!({ json!({
"merge": false,
"todos": [ "todos": [
{"id": "p1", "content": "任务A", "status": "in_progress"} {"id": "p1", "content": "任务A", "status": "in_progress"}
] ]
@ -1140,4 +1142,45 @@ mod tests {
assert!(!result.success); assert!(!result.success);
assert!(result.error.unwrap().contains("missing or empty 'id'")); assert!(result.error.unwrap().contains("missing or empty 'id'"));
} }
#[tokio::test]
async fn test_default_is_merge_mode() {
let state = test_state();
let tool = TodoWriteTool::new(state.clone());
let context = test_context();
// 先创建 2 个 todo
let _ = tool
.execute_with_context(
&context,
json!({
"todos": [
{"id": "x1", "content": "任务A", "status": "pending"},
{"id": "x2", "content": "任务B", "status": "pending"}
]
}),
)
.await
.unwrap();
// 不传 merge 参数,只更新一项 — 默认应为 merge=true旧项保留
let result = tool
.execute_with_context(
&context,
json!({
"todos": [
{"id": "x1", "content": "任务A", "status": "in_progress"}
]
}),
)
.await
.unwrap();
assert!(result.success);
let output: serde_json::Value = serde_json::from_str(&result.output).unwrap();
let todos = output["current_todos"].as_array().unwrap();
assert_eq!(todos.len(), 2); // 默认 merge旧项保留
let task_a = todos.iter().find(|t| t["id"] == "x1").unwrap();
assert_eq!(task_a["status"], "in_progress");
}
} }

View File

@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react' 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, PanelLeftClose, PanelLeftOpen, X, Brain, Settings as SettingsIcon, ChevronRight } from 'lucide-react'
import { ChatContainer } from './components/Chat/ChatContainer' import { ChatContainer } from './components/Chat/ChatContainer'
import { TopicList } from './components/Sidebar/TopicList' import { TopicList } from './components/Sidebar/TopicList'
import { SchedulerJobList } from './components/Sidebar/SchedulerJobList' import { SchedulerJobList } from './components/Sidebar/SchedulerJobList'
@ -120,6 +120,22 @@ function App() {
const [rightPanelTab, setRightPanelTab] = useState<'memory' | 'skill'>('memory') const [rightPanelTab, setRightPanelTab] = useState<'memory' | 'skill'>('memory')
const [sidebarCollapsed, setSidebarCollapsed] = useState(() => {
try {
return localStorage.getItem('picobot-sidebar-collapsed') === 'true'
} catch {
return false
}
})
const toggleSidebar = useCallback(() => {
setSidebarCollapsed(prev => {
const next = !prev
localStorage.setItem('picobot-sidebar-collapsed', String(next))
return next
})
}, [])
const [theme, setTheme] = useState<'dark' | 'light'>(() => { const [theme, setTheme] = useState<'dark' | 'light'>(() => {
const saved = localStorage.getItem('picobot-theme') const saved = localStorage.getItem('picobot-theme')
return saved === 'light' ? 'light' : 'dark' return saved === 'light' ? 'light' : 'dark'
@ -486,10 +502,10 @@ function App() {
} }
} }
// 过滤无实质内容的 merged_tool(无结果且非等待中) // 过滤无实质内容的 merged_toolresult 到达后才显示保留calling/pending 有 callContent 也保留
return result.filter(msg => { return result.filter(msg => {
if (msg.type !== 'merged_tool') return true if (msg.type !== 'merged_tool') return true
if (msg.status === 'pending') return true if (msg.status === 'calling' || msg.status === 'pending') return true
return !!(msg.resultContent && msg.resultContent.trim()) return !!(msg.resultContent && msg.resultContent.trim())
}) })
}, [messages]) }, [messages])
@ -562,34 +578,83 @@ function App() {
{/* Main Content */} {/* Main Content */}
<div className="flex flex-1 overflow-hidden relative"> <div className="flex flex-1 overflow-hidden relative">
{/* Left Sidebar */} {/* Left Sidebar — smooth width animation via will-change + overflow-hidden */}
<div className={`w-72 shrink-0 border-r border-[var(--border-color)] bg-[var(--bg-secondary)]/50 flex flex-col ${subAgentView || schedulerView ? 'opacity-50 pointer-events-none' : ''}`}> <div
{/* Tab 栏 */} className={`shrink-0 border-r border-[var(--border-color)] bg-[var(--bg-secondary)]/50 flex flex-col overflow-hidden ${sidebarCollapsed ? 'w-11' : 'w-72'} ${subAgentView || schedulerView ? 'opacity-50 pointer-events-none' : ''}`}
<div className="flex border-b border-[var(--border-color)]"> style={{ transition: 'width 200ms ease-out', willChange: 'width' }}
<button >
onClick={() => setSidebarTab('topics')} {/* Tab 栏 + collapse toggle */}
className={`flex-1 py-2.5 text-sm font-medium text-center transition-colors ${ <div className="flex border-b border-[var(--border-color)]" style={{ minWidth: sidebarCollapsed ? 0 : '288px' }}>
sidebarTab === 'topics' {sidebarCollapsed ? (
? 'text-[var(--accent-cyan)] border-b-2 border-[var(--accent-cyan)]' /* 收起态:紧凑竖排 tab 按钮 */
: 'text-[var(--text-muted)] hover:text-[var(--text-secondary)]' <div className="flex flex-col w-full">
}`} <button
> onClick={() => { setSidebarTab('topics'); setSidebarCollapsed(false); localStorage.setItem('picobot-sidebar-collapsed', 'false'); }}
className={`py-2 text-xs font-medium text-center transition-colors ${
</button> sidebarTab === 'topics'
<button ? 'text-[var(--accent-cyan)] bg-[var(--accent-cyan)]/10'
onClick={() => setSidebarTab('scheduler')} : 'text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:bg-[var(--overlay-hover)]'
className={`flex-1 py-2.5 text-sm font-medium text-center transition-colors ${ }`}
sidebarTab === 'scheduler' title="话题"
? 'text-[var(--accent-cyan)] border-b-2 border-[var(--accent-cyan)]' >
: 'text-[var(--text-muted)] hover:text-[var(--text-secondary)]' <br/>
}`} </button>
> <button
onClick={() => { setSidebarTab('scheduler'); setSidebarCollapsed(false); localStorage.setItem('picobot-sidebar-collapsed', 'false'); }}
</button> className={`py-2 text-xs font-medium text-center transition-colors ${
sidebarTab === 'scheduler'
? 'text-[var(--accent-cyan)] bg-[var(--accent-cyan)]/10'
: 'text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:bg-[var(--overlay-hover)]'
}`}
title="定时任务"
>
<br/>
</button>
{/* 展开按钮 */}
<button
onClick={toggleSidebar}
className="flex items-center justify-center py-2 text-[var(--text-muted)] hover:text-[var(--accent-cyan)] hover:bg-[var(--overlay-hover)] transition-colors"
title="展开侧栏"
>
<PanelLeftOpen className="h-3.5 w-3.5" />
</button>
</div>
) : (
<>
<button
onClick={() => setSidebarTab('topics')}
className={`flex-1 py-2.5 text-sm font-medium text-center transition-colors whitespace-nowrap ${
sidebarTab === 'topics'
? 'text-[var(--accent-cyan)] border-b-2 border-[var(--accent-cyan)]'
: 'text-[var(--text-muted)] hover:text-[var(--text-secondary)]'
}`}
>
</button>
<button
onClick={() => setSidebarTab('scheduler')}
className={`flex-1 py-2.5 text-sm font-medium text-center transition-colors whitespace-nowrap ${
sidebarTab === 'scheduler'
? 'text-[var(--accent-cyan)] border-b-2 border-[var(--accent-cyan)]'
: 'text-[var(--text-muted)] hover:text-[var(--text-secondary)]'
}`}
>
</button>
{/* 收起按钮 */}
<button
onClick={toggleSidebar}
className="flex items-center justify-center px-2 text-[var(--text-muted)] hover:text-[var(--accent-cyan)] hover:bg-[var(--overlay-hover)] transition-colors shrink-0"
title="收起侧栏"
>
<PanelLeftClose className="h-4 w-4" />
</button>
</>
)}
</div> </div>
<div className="flex-1 overflow-hidden"> <div className="flex-1 overflow-hidden" style={{ minWidth: sidebarCollapsed ? 0 : '288px' }}>
{sidebarTab === 'topics' ? ( {sidebarCollapsed ? null : sidebarTab === 'topics' ? (
<TopicList <TopicList
sessionId={sessionId} sessionId={sessionId}
topics={topics} topics={topics}