39 Commits

Author SHA1 Message Date
oudecheng
0f60b02ede chore(log): 缩减 INFO 日志量,高频诊断日志降级/删除
1. 删除缓存诊断日志 4 处(openai.rs):排查已完结,字段已补齐,每次 LLM 调用都刷屏。
2. 删除 AgentPromptProvider 模型配置日志(agent_prompt_provider.rs):排查遗留,每次请求刷。
3. AgentFactory 创建日志 info→debug(agent_factory.rs):每轮对话刷,降级保留供偶发排查。
4. Calling tool / Tool calls detected info→debug(agent_loop.rs):每次工具调用都刷,全量参数打印开销大,tracing 在未启用级别时不评估字段。
5. LoadTaskMessages 3 条日志 info→debug(load_task_messages.rs):每次前端 trigger 都刷,一次 3 条。
6. 旧结果诊断日志 info→debug(execution.rs):每条消息首次 agent 迭代都触发。
7. pending subagents 日志 info→debug(processor.rs):子代理运行期高频率重复触发。
8. Updating current_session_id 仅变化时打(ws.rs):old==new 时每条消息都刷,无信息量。
编译通过,测试全绿。
2026-08-15 23:10:39 +08:00
oudecheng
011b23b54e feat(provider): 缓存命中诊断日志与两种 usage 缓存格式解析测试
排查平台有缓存命中但前端占比为 0 的问题:set_usage/非流式/回退三处输出 cache diagnostics 日志;新增 DeepSeek 顶层与 OpenAI 嵌套缓存字段解析回归测试
2026-08-15 20:17:30 +08:00
oudecheng
b26a2c2512 feat(token): 新增缓存占比统计,聚合查询收敛到共享列清单
- 解析: OpenAIUsage 支持 DeepSeek prompt_cache_hit_tokens + OpenAI prompt_tokens_details.cached_tokens fallback;Anthropic 接入 cache_read_input_tokens

- 存储: messages 表新增 cached_tokens 列(幂等迁移),贯穿 INSERT/SELECT/聚合

- 解耦加固: 抽取 MESSAGE_LOAD_COLUMNS 收敛 6 处消息加载 SELECT;抽取 USAGE_SUM_COLUMNS + read_usage_sum_row 收敛 topic/session 两份重复 SUM 聚合

- 协议: SessionTokenStats/TopicTokenStats 新增 cached_tokens 字段

- 前端: 面板新增缓存命中行 + 缓存命中率进度条(命中率越高越绿,与 ctx 占用方向相反)
2026-08-15 19:21:51 +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
0aa9050b12 fix: 修复 3 个失败测试 - agent_md_template 写入模板内容/StreamingAccumulator BTreeMap 保序/source_order 断言补全 2026-08-03 14:26:20 +08:00
oudecheng
141ffda1ee feat: 实现聊天消息的串行锁,确保同一聊天的消息处理串行执行 2026-07-15 17:47:52 +08:00
oudecheng
303f6d83e3 feat: 添加工具调用序列的前向检查,确保工具消息紧随助手消息后 2026-07-15 16:36:13 +08:00
oudecheng
f264a7b307 fix: 兼容 base_url 末尾斜杠,避免拼接产生双斜杠导致 404
anthropic.rs 和 openai.rs 在构造时 trim_end_matches('/'),兼容如 https://opencode.ai/zen/go/v1/ 带末尾斜杠的 base_url。
2026-07-07 14:14:20 +08:00
oudecheng
95cf152ab9 fix(agent): 修复工具调用消息序列的完整性问题
- 在历史压缩时,移除保留消息中不完整的工具调用序列,防止API 400错误
- 压缩后对当前历史消息再次进行工具调用序列清理,确保消息序列有效性
- OpenAI请求构建中,增加位置感知的工具调用和结果配对验证
- 跳过含有不完整工具调用序列的助手消息,避免发送非法请求
- 剥离不完整助手消息的工具调用字段,作为普通助手消息序列化
- 跟踪并警告不完整工具调用序列和被跳过的消息索引
2026-06-23 08:44:48 +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
e4bc8153a0 feat: 更新测试用例中的技能描述,提供更准确的技能定义 2026-06-07 22:00:09 +08:00
oudecheng
b3dc207ad1 fix: 移除 temperature 和 max_tokens 的硬编码默认值
如果配置中没有设置 temperature 或 max_tokens,不再传递这些参数给模型,
让模型使用自己的默认值,而不是硬编码 0.7。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 12:58:15 +08:00
44d9171b86 feat: 更新内容处理逻辑,支持图片转换为通知文本并添加模型支持检查 2026-05-23 14:08:06 +08:00
oudecheng
c817b1dde1 feat: 优化会话消息处理逻辑,支持在话题切换时正确保存消息并更新内存历史 2026-05-21 18:04:11 +08:00
oudecheng
32a9e2946e feat: 优化 MemorySearchTool 的查询参数处理,支持多种格式的查询输入 2026-05-21 11:35:17 +08:00
oudecheng
9adaa93ecc feat: 优化 StreamingAccumulator 中工具调用的 ID 和名称更新逻辑,确保空值不会覆盖有效数据,并添加相关单元测试 2026-05-21 08:50:41 +08:00
oudecheng
018c104592 feat: 更新 reqwest 依赖以支持流式响应,添加流式处理相关结构和实现 2026-05-20 11:32:46 +08:00
oudecheng
7540828397 Revert "feat: 添加流式聊天支持,更新相关依赖和接口以实现流式响应"
This reverts commit cb48ef09b22ef72798a15ff3485c8e21f77e59f4.
2026-05-20 09:20:26 +08:00
oudecheng
cb48ef09b2 feat: 添加流式聊天支持,更新相关依赖和接口以实现流式响应 2026-05-20 09:10:47 +08:00
oudecheng
84b3fd064c feat: 修复 JSON 字符串处理逻辑,确保字符串格式的有效性 2026-05-13 10:39:32 +08:00
oudecheng
9d3d8b812c feat: 优化工具参数序列化逻辑,确保字符串格式的有效性 2026-05-13 10:07:14 +08:00
04fc2c0710 feat: 添加记忆维护的错误处理逻辑,优化传输错误的上下文信息
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 18:10:23 +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
ed45ec54ed feat: 增强错误处理,添加format_error_chain函数以格式化错误链,优化日志记录 2026-04-27 09:35:10 +08:00
9e17cd35da feat: 增强OpenAIProvider以支持工具调用参数的JSON格式,优化请求体构建逻辑,排除内部模型额外键 2026-04-27 09:21:50 +08:00
c83d697f93 feat: 增强OpenAIProvider以支持JSON工具参数,优化调度管理工具的参数验证和错误处理 2026-04-26 23:05:34 +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
f3f369b329 feat: add llm_timeout_secs to provider configuration and implement timeout handling
- Introduced llm_timeout_secs in ProviderConfig and LLMProviderConfig to specify timeout for LLM requests.
- Updated OpenAIProvider and AnthropicProvider to utilize the timeout setting when creating HTTP clients.
- Enhanced error handling for API responses to include timeout information.
- Modified SessionManager to support agent-specific provider configurations, allowing for more flexible agent management.
- Added tests to verify the correct behavior of timeout settings and agent task validation.
2026-04-23 09:23:15 +08:00
ef601107ac feat: 添加工具调用支持,优化消息处理和持久化 2026-04-18 14:17:23 +08:00
a4399037ac fix: use char-based slicing instead of byte-based to handle UTF-8
Byte index slicing like `&text[..100.min(text.len())]` panics when the
byte index falls inside a multi-byte UTF-8 character (e.g., Chinese).
Changed to `text.chars().take(100).collect::<String>()` for safe
character-based truncation.
2026-04-08 08:49:52 +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
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
8b1e6e7e06 实现基本的模型调用 2026-04-05 17:11:42 +08:00