35 Commits

Author SHA1 Message Date
oudecheng
e0313ab8f3 fix: 增强 panic 安全与计算器健壮性
- agent_loop/processor: catch_unwind 隔离 panic,防止消息静默丢失
- calculator: 拒绝 NaN/Infinity 输入,修复阶乘溢出(上限 34),拒绝非有限表达式结果
- message: 修复 sanitize 两阶段删除索引未排序导致的越界 panic
- utils: 新增 panic_payload_message 提取可读 panic 消息
- .gitignore: 忽略 artifacts/ 测试产物目录
2026-08-13 08:38:36 +08:00
oudecheng
29060315a3 feat(observability): 端到端可观测性整改,修复 trace_id 断链与指标配对
- 传播 trace_id:BusToolCallEmitter/SubAgentEmitter/processor 全链路设置

- AgentEnd 配对:补发 5 个 cancel/defensive 路径,闭合 AgentStart 指标

- LLM 计时修正:attempt_start 移入 retry 循环,排除退避等待时间

- /metrics auth:非 loopback 部署时纳入 Bearer token 校验

- recorder 复用:OnceLock 缓存 PrometheusHandle,热重启后不再返回 503

- 结构化日志:新增 tracing_ctx + JSON 日志格式支持
2026-08-12 08:26:42 +08:00
oudecheng
510520e08e refactor: 提取公共工具函数,修复飞书正则重复编译和网关路由DRY问题,添加CI安全审计 2026-08-07 08:33:15 +08:00
oudecheng
2e4b1931a6 feat(tokens): 添加 topic 维度 token 消耗与上下文窗口占用统计
后端:
- openai provider 流式响应启用 stream_options.include_usage,从 SSE 末帧捕获 usage
- ChatMessage 新增 MessageUsage(prompt/completion/total/context_window_tokens)
- agent_loop 三处 LLM 调用点持久化 usage,含 context_window_tokens
- storage 新增 context_window_tokens 列及 migration,batch_session_token_stats 聚合查询
- last_prompt_tokens 查询过滤 prompt_tokens IS NOT NULL,跳过 error/cancel 消息
- build_topic_summaries 简化签名,context_window_tokens 从消息记录读取
- protocol 扩展 TopicTokenStats,按 session_id 聚合天然隔离子代理

前端:
- protocol.ts 新增 TopicTokenStats 类型
- useTopics 映射 token_stats 到 Topic
- TopicList 展示总 token 消耗与上下文占用百分比(绿/黄/红三色)

测试:outbound_dispatcher 4 个测试修复(drop(bus) 不关闭 bus,改用 abort)
2026-08-04 17:01:54 +08:00
oudecheng
cda14360af chore: 建立工程化基线(rustfmt + clippy + CI + eslint + prettier)
配置:
- rustfmt.toml: 固化 max_width=100 / 4 空格缩进,cargo fmt 全量格式化
- Cargo.toml: 配置 [lints.rust] 与 [lints.clippy] 渐进式规则
- .github/workflows/ci.yml: Rust(fmt+clippy+test) + 前端(eslint+tsc+test) 双平台 CI
- Makefile: 新增 check/fmt/fix 目标,clippy 对齐 --all-targets --all-features
- web: eslint flat config + prettier 配置 + package.json 脚本与依赖
- src/main.rs: loop→while 修复 clippy::never_loop

对抗性审查发现并修复:
- eslint 缺 caughtErrorsIgnorePattern 导致 catch(_) 误报为 error
- 前端 lint 未接入 CI,现已补上 Lint 步骤
- Makefile 与 CI 的 clippy flags 不一致,已对齐
2026-08-03 23:24:02 +08:00
oudecheng
303f6d83e3 feat: 添加工具调用序列的前向检查,确保工具消息紧随助手消息后 2026-07-15 16:36:13 +08:00
oudecheng
994db87f11 feat: 新增 ExecutionCompleted 信号修复发送按钮状态
- 后端 OutboundEventKind/WsOutbound 新增 ExecutionCompleted 变体
- processor 在 handle_message 完成后发送该信号
- 飞书/微信通道过滤该信号(不发送)
- 前端 useChat 移除 stream_delta/assistant_response 的 isLoading=false
- 改由 execution_completed 事件统一设置 isLoading=false,确保智能体迭代期间按钮保持停止态
2026-07-03 19:32:14 +08:00
oudecheng
97c0e46348 feat(tests): 增加工具调用序列清理的单元测试,确保孤立工具结果的正确处理 2026-06-16 16:52:00 +08:00
fc7df67474 feat(streaming): 支持流式文本增量与结束信号功能
- 新增 StreamDelta 和 StreamEnd 类型,支持流式数据增量传输
- 扩展 LLMProvider trait,添加带回调的 chat_with_streaming 接口
- 修改 OpenAI Provider 实现,支持流式聊天回调传输增量数据
- Agent 流处理改为异步消费增量消息并传递给前端
- 保证流式增量和最终消息使用相同消息 ID 以便前端替换
- 修改消息总线和协议层,支持携带和识别流式消息的消息 ID
- 客户端 CLI 通过增量输出实现交互式流式响应显示
- Web 前端接收流式增量消息,追加到对应消息,实现实时显示
- 各通道(飞书、微信)支持转发流式增量和结束消息
- 任务工具运行时添加消息 ID 支持,保持消息一致性
- 统一消息构造函数新增流式增量和结束信号的构建方法
2026-06-14 10:24:52 +08:00
oudecheng
4487f1a490 feat: 添加思考过程显示功能,允许用户选择是否展示助手的思考内容 2026-06-11 17:15:03 +08:00
oudecheng
6ff5907616 feat: 添加 reasoning_content 字段到多个消息结构,支持思考过程展示 2026-06-11 14:33:29 +08:00
oudecheng
0ce89a0e4e feat: 添加 reasoning_content 字段到多个消息结构,支持思考过程展示 2026-06-11 12:04:52 +08:00
oudecheng
2f529e96d0 feat: 添加滚动控制功能,支持回到顶部和回到底部的按钮 2026-06-04 16:00:43 +08:00
e8a3a47ac7 feat: 添加 TaskStarted 事件,支持任务开始通知功能 2026-06-03 21:53:37 +08:00
oudecheng
4d6d989247 feat: 添加工具执行时长字段,增强消息处理功能 2026-06-02 16:52:47 +08:00
oudecheng
44e82e8473 feat: 附件通过 base64 内容实现前端直接下载
- MediaItem/MediaSummary 新增 content_base64 和 file_name 字段
- 解析附件时读取文件内容并 base64 编码(限 50MB),前端 Blob 下载
- 创建 Session 后返回完整 topics 列表,前端侧边栏实时同步
- 简化话题历史加载逻辑,不再回退到 session 消息

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-28 14:01:37 +08:00
oudecheng
8f82009c32 feat: 重命名工具名称,简化工具调用接口 2026-05-19 15:18:04 +08:00
oudecheng
025c0b5d7f feat: 添加 session_id 支持到 OutboundMessage,优化会话管理 2026-05-15 10:00:17 +08:00
597881f72e feat: Implement WeChatBot SDK with error handling and message protocol
- Add WeChatBotError enum for error handling with various error types.
- Create a Result type alias for easier error management.
- Implement ILinkClient for low-level API interactions including QR code generation, message sending, and updates retrieval.
- Define message types and structures for handling incoming messages and media content.
- Add tests for error handling and message parsing to ensure reliability.

Co-authored-by: Copilot <copilot@github.com>
2026-05-06 14:18:47 +08:00
af7860f2fd feat: 重构消息模块,添加 ContentBlock 和 ToolCall 结构,优化消息处理逻辑
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 14:04:59 +08:00
73dab09bfe Refactor code for improved readability and consistency
- Adjusted formatting and indentation in various files for better clarity.
- Consolidated multi-line statements into single lines where appropriate.
- Enhanced error handling messages for better debugging.
- Added a new InboundProcessor struct to handle inbound messages more effectively.
- Updated test cases to ensure they align with the new code structure.
2026-04-28 10:33:31 +08:00
4e1b831948 feat: 优化工具调用内容格式,简化空参数处理并改进参数输出格式 2026-04-27 17:15:52 +08:00
3045a6b596 feat: Enhance ChatMessage with system context and background compaction
- Added `system_context` field to `ChatMessage` for better message context handling.
- Introduced constants for system context prompts in `message.rs`.
- Updated `Session` to manage background history compaction, including methods to start and finish compaction.
- Implemented logic to schedule background compaction after message processing in `SessionManager`.
- Enhanced database schema to support new `system_context` field in messages.
- Added functionality to compact active history, preserving system messages and summaries.
- Updated tests to validate new compaction logic and ensure message integrity.
- Removed unused functions and cleaned up code in various modules for better maintainability.

Co-authored-by: Copilot <copilot@github.com>
2026-04-26 09:31:13 +08:00
95c53fa830 feat: 添加推理内容支持到聊天消息,增强消息处理能力 2026-04-24 17:42:19 +08:00
302e6ef6b9 feat(gateway): 添加 show_tool_results 配置以控制工具结果显示
feat(session): 更新 BusToolCallEmitter 以支持工具结果显示控制
feat(ws): 更新 WsToolCallEmitter 以支持工具结果显示控制
2026-04-22 16:14:27 +08:00
038b5eccc6 feat: Enhance tool execution handling with pending user action state
- Introduced ToolMessageState enum to represent tool execution states (Completed, PendingUserAction).
- Updated ChatMessage struct to include tool_state for tracking tool execution status.
- Modified AgentLoop to handle tool results and pending actions, providing appropriate responses to users.
- Enhanced BashTool to detect when commands require user interaction, returning a pending state with hints.
- Updated WebSocket protocol to support tool pending messages, allowing clients to handle pending actions effectively.
- Refactored related tests to ensure proper functionality of new pending state handling.
2026-04-22 14:49:50 +08:00
4725b5406e feat: 添加实时工具调用消息处理,优化消息格式化和传递逻辑 2026-04-22 09:01:56 +08:00
2f47a8a273 feat(ws): 移除工具结果的处理逻辑,优化消息输出 2026-04-22 08:42:50 +08:00
d35e89a44c # 2026-04-22 06:57:22 +08:00
ef601107ac feat: 添加工具调用支持,优化消息处理和持久化 2026-04-18 14:17:23 +08:00
21b4e60c44 feat(feishu): add reaction handling and metadata forwarding in messages 2026-04-08 10:24:15 +08:00
2dada36bc6 feat: introduce multimodal content handling with media support
- Added ContentBlock enum for multimodal content representation (text, image).
- Enhanced ChatMessage struct to include media references.
- Updated InboundMessage and OutboundMessage to use MediaItem for media handling.
- Implemented media download and upload functionality in FeishuChannel.
- Modified message processing in the gateway to handle media items.
- Improved logging for message processing and media handling in debug mode.
- Refactored message serialization for LLM providers to support content blocks.
2026-04-07 23:09:31 +08:00
a051f83050 Refactor AgentLoop to manage history externally via SessionManager
- Removed internal history management from AgentLoop.
- Updated process method to accept conversation history as a parameter.
- Adjusted continue_with_tool_results to work with external history.
- Added OutboundDispatcher for handling outbound messages from MessageBus.
- Introduced InboundMessage and OutboundMessage structs for message handling.
- Updated Channel trait to include message handling and publishing to MessageBus.
- Refactored Session to manage chat histories instead of AgentLoop instances.
- Enhanced GatewayState to start message processing loops for inbound and outbound messages.
2026-04-07 21:53:37 +08:00
9834bd75cf feat: add calculator tool and integrate with agent loop
- Introduced a new CalculatorTool for performing various arithmetic and statistical calculations.
- Enhanced the AgentLoop to support tool execution, including handling tool calls in the process flow.
- Updated ChatMessage structure to include optional fields for tool call identification and names.
- Modified the Session and SessionManager to manage tool registrations and pass them to agents.
- Updated the OpenAIProvider to serialize tool-related message fields.
- Added a ToolRegistry for managing multiple tools and their definitions.
- Implemented tests for the CalculatorTool to ensure functionality and correctness.
2026-04-06 23:43:45 +08:00
35d201f206 重构项目结构,添加代理、网关和客户端模块,更新配置以支持默认网关设置,增强错误处理,添加 WebSocket 支持 2026-04-06 16:36:17 +08:00