feat: Phase 1+2 架构进化 — 连续思考链/主动消息决策/情感状态机/离线自主思考 (86文件)
Phase 1 (基础设施): - ThinkChain 思考链连续性 + 差异化思考提示词 (persistent) - AutonomousToolPolicy 工具安全策略 (safe/unsafe/conditional) - MessageScheduler 自适应消息节奏 (Idle/Available/Busy) - SessionEnrichmentStore 渐进式上下文丰富 (5层) - ConversationBus 事件总线 + ResponseCache (dedup) - pkg/logger 统一日志 + 所有 handler 替换 fmt.Printf - NPE 守卫/链路优化/数据库表修复/Go workspace Phase 2 (人格交互): - EmotionState/EmotionTracker 情感状态机 (5种心情, 情绪衰减) - ProactiveGuard 主动消息多维决策 (静默时段/紧急度/频率/校验) - Gateway↔ai-core 在线状态感知链路 (presence notification) - 离线思考频率控制 + 重连问候 + 离线消息排队 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -152,12 +152,46 @@ export function MessageBubble({
|
||||
}: MessageBubbleProps) {
|
||||
const isUser = role === 'user';
|
||||
const isAction = role === 'action' || msgType === 'action';
|
||||
const isThinking = msgType === 'thinking';
|
||||
const isToolProgress = msgType === 'tool_progress';
|
||||
const isSystemInfo = msgType === 'system_info';
|
||||
|
||||
// 动作消息使用独立的渲染方式
|
||||
if (isAction) {
|
||||
return <ActionMessageBubble content={content} timestamp={timestamp} />;
|
||||
}
|
||||
|
||||
// 思考内容 — 可折叠面板
|
||||
if (isThinking) {
|
||||
return (
|
||||
<details className="mx-4 my-1 px-3 py-2 bg-gray-50 dark:bg-gray-800 rounded border border-gray-200 dark:border-gray-700 text-xs text-gray-500 dark:text-gray-400 italic">
|
||||
<summary className="cursor-pointer select-none">昔涟正在思考...</summary>
|
||||
<p className="mt-1 whitespace-pre-wrap">{content}</p>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
|
||||
// 工具进度 — 紧凑进度行
|
||||
if (isToolProgress) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 mx-4 my-1 px-3 py-1 text-xs text-gray-400 dark:text-gray-500">
|
||||
<span className="inline-block w-2 h-2 rounded-full bg-blue-400 animate-pulse" />
|
||||
<span>{content}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 系统信息 — 居中 Toast 风格
|
||||
if (isSystemInfo) {
|
||||
return (
|
||||
<div className="flex justify-center my-1">
|
||||
<span className="text-xs text-gray-400 dark:text-gray-500 bg-gray-100 dark:bg-gray-800 px-3 py-1 rounded-full">
|
||||
{content}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const [lightboxIndex, setLightboxIndex] = useState<number | null>(null);
|
||||
const time = new Date(timestamp).toLocaleTimeString('zh-CN', {
|
||||
hour: '2-digit',
|
||||
|
||||
@@ -364,6 +364,45 @@ function handleServerMessage(msg: WSServerMessage) {
|
||||
});
|
||||
break;
|
||||
|
||||
case 'thinking':
|
||||
if (msg.thinking_content) {
|
||||
addMessage({
|
||||
id: msg.message_id || 'think_' + Date.now(),
|
||||
role: 'assistant',
|
||||
content: msg.thinking_content,
|
||||
timestamp: msg.timestamp || Date.now(),
|
||||
msgType: 'thinking',
|
||||
isStreaming: false,
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tool_progress':
|
||||
if (msg.tool_progress) {
|
||||
addMessage({
|
||||
id: msg.message_id || 'tool_' + Date.now(),
|
||||
role: 'system',
|
||||
content: `${msg.tool_progress.tool_name}: ${msg.tool_progress.message}`,
|
||||
timestamp: msg.timestamp || Date.now(),
|
||||
msgType: 'tool_progress',
|
||||
isStreaming: false,
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case 'system_info':
|
||||
if (msg.system_info) {
|
||||
addMessage({
|
||||
id: msg.message_id || 'sys_' + Date.now(),
|
||||
role: 'system',
|
||||
content: msg.system_info.message,
|
||||
timestamp: msg.timestamp || Date.now(),
|
||||
msgType: 'system_info',
|
||||
isStreaming: false,
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case 'pong':
|
||||
break;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
export type MessageRole = 'user' | 'assistant' | 'system' | 'action';
|
||||
|
||||
/** 消息显示类型 (区分聊天消息与动作消息) */
|
||||
export type MessageDisplayType = 'chat' | 'action' | 'system';
|
||||
export type MessageDisplayType = 'chat' | 'action' | 'system' | 'thinking' | 'tool_progress' | 'system_info';
|
||||
|
||||
/** 对话模式 */
|
||||
export type ChatMode = 'text' | 'voice_msg' | 'voice_assistant';
|
||||
@@ -122,7 +122,7 @@ export interface AppNotification extends NotificationData {
|
||||
|
||||
/** WebSocket 服务端消息 */
|
||||
export interface WSServerMessage {
|
||||
type: 'stream_start' | 'response' | 'segment' | 'audio' | 'error' | 'device_update' | 'pong' | 'history_response' | 'stream_chunk' | 'stream_end' | 'background_thinking' | 'notification' | 'multi_message' | 'stream_segments' | 'review';
|
||||
type: 'stream_start' | 'response' | 'segment' | 'audio' | 'error' | 'device_update' | 'pong' | 'history_response' | 'stream_chunk' | 'stream_end' | 'background_thinking' | 'notification' | 'multi_message' | 'stream_segments' | 'review' | 'thinking' | 'tool_progress' | 'system_info';
|
||||
message_id?: string;
|
||||
text?: string;
|
||||
content?: string;
|
||||
@@ -140,10 +140,29 @@ export interface WSServerMessage {
|
||||
review_messages?: ReviewMessage[];
|
||||
devices?: IoTDevice[];
|
||||
thinking_status?: BackgroundThinkingStatus;
|
||||
thinking_content?: string;
|
||||
notification?: NotificationData;
|
||||
tool_progress?: ToolProgressInfo;
|
||||
system_info?: SystemInfoPayload;
|
||||
protocol_version?: number;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
/** 工具进度信息 */
|
||||
export interface ToolProgressInfo {
|
||||
tool_name: string;
|
||||
status: string; // started, running, completed, failed
|
||||
progress: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
/** 系统信息负载 */
|
||||
export interface SystemInfoPayload {
|
||||
level: string; // info, warning, error
|
||||
message: string;
|
||||
action?: string;
|
||||
}
|
||||
|
||||
/** 工具调用 */
|
||||
export interface ToolCall {
|
||||
name: string;
|
||||
|
||||
Reference in New Issue
Block a user