24 Commits

Author SHA1 Message Date
oudecheng
0159227828 perf: 第二批性能修复——blocking 线程池隔离、HTTP 客户端复用、前端 memo 与流式节流
- 同步阻塞操作(附件处理、历史加载、scheduler/memory_search 的 SQLite 调用)
  移入 spawn_blocking,避免占用 async worker
- LLM Provider reqwest::Client 按超时配置缓存复用,减少 TLS/连接开销
- agent loop:图片过滤加廉价预判避免全量深拷贝;请求克隆改借用;工具定义 Arc 化
- 定向 COUNT/LIMIT 1 查询替代全量加载计数(wait_coordinator、task session 重建)
- 前端:面板/侧栏/聊天组件 memo 化;merged_tool 对象按值复用缓存;
  流式 delta rAF 节流批量 flush;useMemo 缓存分组排序结果
2026-08-18 06:55:21 +08:00
oudecheng
5a292d60ec fix(providers): Anthropic 型 provider max_tokens 留空兜底提高至 8192
- max_tokens 未配置时兜底值由 1024 调整为 8192,避免长回复被过早截断

- 同步设置页提示:留空则不传该字段(Anthropic 型 provider 回退为 8192),并移除 Temperature 的误导性占位符 0.7
2026-08-17 17:52:28 +08:00
oudecheng
2ab9c2d404 fix(providers): 模型未配置 Temperature 时请求体不再携带该字段
- AnthropicRequest.temperature 增加 skip_serializing_if:留空时不再序列化出 temperature:null,而是完全省略该键,交由模型服务端使用默认值(OpenAI 型 provider 此前已是该行为)

- 新增两个序列化回归测试:temperature 为 None 时请求体不含该键,为 Some 时正常输出

- 同步设置页提示文案:Temperature 留空不传该字段;Max Tokens 留空不传(Anthropic 型 provider 回退为 1024)
2026-08-17 16:45:12 +08:00
oudecheng
1019dbe8cc refactor(code-quality): 清理 clippy 存量告警(unwrap/clone/redundant 等)
- 移除无用克隆与冗余引用,减少不必要内存分配
- 规范 unwrap/expect 使用,修复可提前失败路径
- 修复 anthropic provider llm_timeout_secs 死代码并补全超时日志
- cargo fmt 统一格式
2026-08-16 23:22:22 +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
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
f26ec49182 chore: 修复 release 构建的编译器警告
- 为 regex::Captures 补全显式生命周期标注
- 将仅用于 debug 日志的局部变量 (media_count/len/total) 用 cfg(debug_assertions) 条件化
- 为仅 debug 读取的 AnthropicProvider::llm_timeout_secs 字段添加 cfg_attr allow(dead_code)
2026-08-07 14:36:27 +08:00
oudecheng
510520e08e refactor: 提取公共工具函数,修复飞书正则重复编译和网关路由DRY问题,添加CI安全审计 2026-08-07 08:33:15 +08:00
oudecheng
5eec77ae10 perf: 减少热路径无谓拷贝与重复正则编译,并跳过已完成迁移
- agent_loop::filter_images_by_age_and_count 改返回 Cow<[ChatMessage]>,
  无图片或无需过滤时零拷贝返回原切片引用,避免每次 LLM 调用都完整克隆消息列表
- anthropic::convert_image_url_to_anthropic 用 OnceLock 缓存 data URL 正则,
  避免每次图片转换都重新编译正则
- memory_scope_key 迁移用 PRAGMA user_version 记录已迁移版本,
  避免每次启动都执行全表 DELETE + UPDATE
2026-08-05 08:10:36 +08:00
oudecheng
cd314742ad fix(test): 修复 anthropic 错误链嵌套测试为真正的 source 链
对抗性审查发现 test_format_error_chain_nested 是无效测试:
声称测嵌套错误链但实际没构造 source 链,inner 变量被 let _ 抑制。
改用 thiserror 构造真正的 #[source] 嵌套错误,验证 'caused by' 拼接。
2026-08-03 23:47:43 +08:00
oudecheng
e6b2fcfb6d docs+test: 补充架构文档与 anthropic provider 单测
P3 文档:
- 新增 ARCHITECTURE.md,聚焦数据流与 7 个关键设计决策
  (MessageBus 解耦/SessionPool 隔离/AgentLoop 循环/SQLite 池化/重启机制/嵌入静态文件/Safety Guard)
- 不写代码导读,只写'为什么这样设计',代码是唯一真相源

P2 测试:
- src/providers/anthropic.rs 曾零测试(396 行),补 15 个纯函数单测
- 覆盖:data URL 解析、图片过滤逻辑、内部字段过滤、响应反序列化、错误链格式化
- providers 模块测试密度 31% -> 提升,重点补齐 anthropic 空白
2026-08-03 23:45:41 +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
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
44d9171b86 feat: 更新内容处理逻辑,支持图片转换为通知文本并添加模型支持检查 2026-05-23 14:08:06 +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
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
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
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
8b1e6e7e06 实现基本的模型调用 2026-04-05 17:11:42 +08:00