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
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
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
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
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
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
0732b31e6b
feat: 添加主题描述生成和更新功能,优化会话信息展示
2026-05-24 08:32:34 +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
716d92a618
feat: 引入 AgentRuntimeConfig,重构相关模块以支持运行时配置
...
Co-authored-by: Copilot <copilot@github.com>
2026-04-30 22:34:22 +08:00
04fc2c0710
feat: 添加记忆维护的错误处理逻辑,优化传输错误的上下文信息
...
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 18:10:23 +08:00
8f27bd2735
feat: 重构工具和协议模块,添加工具注册和会话管理逻辑,优化消息处理
2026-04-28 14:16:30 +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