Skip to content

feat(ai): AI optimization features (issues #94-#102)#122

Merged
hrygo merged 11 commits into
mainfrom
feat/ai-optimization-router-feedback
Feb 8, 2026
Merged

feat(ai): AI optimization features (issues #94-#102)#122
hrygo merged 11 commits into
mainfrom
feat/ai-optimization-router-feedback

Conversation

@hrygo

@hrygo hrygo commented Feb 8, 2026

Copy link
Copy Markdown
Owner

概述

AI 聊天优化功能:路由反馈机制 + 流式事件处理优化 + 工具调用技术方案

关联 Issues

Resolves #94, #95, #96, #97, #98, #99, #100, #101, #102
Refs #125

主要变更

新增文档

  • docs/specs/streaming-tool-calls.md - 流式工具调用技术方案(669 行)

功能优化

  • 路由反馈机制:支持用户反馈对路由结果的调整
  • 流式事件处理:修复事件显示,移除冗余 FIFO 队列
  • i18n 修复:解决重复键和 lint 问题

文档更新

  • 添加调试经验教训文档
  • 更新 CLAUDE.md 添加关键上下文

方案要点(流式工具调用)

核心决策

  • 采用完全流式模式(DeepSeek 原生支持)
  • 渐进增强策略,保持向后兼容
  • 新增 ChatStreamWithTools 接口

分阶段交付

  1. Phase 1(1 周):核心 LLM 流式接口
  2. Phase 2(1 周):Agent 层适配
  3. Phase 3(1 周):前端体验优化

预期效果

  • 首工具调用延迟:~800ms → ~200ms(75% ↓)
  • 感知延迟:3-5s → <1s(60% ↓)

检查清单

  • 代码遵循项目规范
  • 所有测试通过
  • 技术文档完整
  • GitHub Issues 已更新

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

@hrygo hrygo force-pushed the feat/ai-optimization-router-feedback branch from 21535f6 to e07a88b Compare February 8, 2026 14:42
hotplex-ai and others added 11 commits February 8, 2026 22:46
Backend changes:
- Add four-layer intent routing (Cache → Rule → History → LLM)
- Add RuleMatcher for fast zero-latency classification
- Add router feedback collection with PostgreSQL storage
- Add Prometheus metrics and tracing support
- Add context delta builder for efficient context updates
- Add preload analyzer and scheduler for optimization
- Add sensitive input filter for security
- Add migration for router_feedback table

Frontend changes:
- Add ProgressIndicator component with phase animations
- Add QuickReplies component for suggested actions
- Add shimmer keyframe animation to default.css
- Update UnifiedMessageBlock with progress display
- Update AIChat page to support new features

i18n fixes:
- Fix zh-Hant.json: add 335 missing translation keys
- Translate ai.progress.phases to Traditional Chinese
- Ensure all locale files are synchronized

Refs #97 (Progressive Progress Feedback)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add 🔑 Critical Context section with project structure table
- Document key configuration (PostgreSQL container name, ports)
- Add i18n completeness trap warning (check-i18n doesn't check zh-Hant.json)
- Add Language-Specific Notes for TypeScript/React and Go
- Add 🚫 Code Change Boundaries section with 4 workflow patterns
- Update freshness status to v0.93.2 (2026-02-08)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Standardize field alignment in deltaStats, DeltaStats, TracingContext structs
- Improve i18n validation script with complete zh-Hant.json check
- Add cross-reference to DEBUG_LESSONS.md for migration notes
- Refine terminology: GraphQL/Proto → Proto/Schema
- Update code-reviewer agent description format

All tests pass, build successful.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unused Database import from ProgressIndicator
- Fix Navigation i18n key path to ai.knowledge-graph.title
- Merge duplicate ai.progress keys into first ai key (en.json, zh-Hans.json)
- Apply auto-formatting fixes

Refs #120

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix matchPool.Get() type assertion in sensitive.go
- Add slog error handling in analyzer.go async save
- Fix defer close error handling in exporter.go
- Fix http.NewRequest nil to http.NoBody in prometheus_test.go
- Rename testErr to errTest for staticcheck compliance
- Remove unused matchPool.Put to avoid SA6002
- Simplify regex pattern using \S* instead of [^\s]*
- Remove unused fields and imports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add "Go Lint 常见陷阱" section with:
- Type assertion must use comma-ok pattern
- Defer error checking requirements
- Error comparison with errors.Is
- HTTP nil body should use http.NoBody
- error variable naming convention
- Regex simplification patterns
- sync.Pool usage restrictions

This section captures lessons learned from fixing 18 golangci-lint issues
in commit 14900ad, preventing future repetitions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…prompts

- Update document.documentElement.lang in applyLocaleEarly()
- Update document.documentElement.lang in loadLocale()
- Map zh-Hans → zh-CN, zh-Hant → zh-TW for BCP 47 compliance

This prevents Chrome/Google from offering to translate the page when
the user's browser language matches the content language.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit fixes two issues with AI chat streaming:

1. **Tool call metadata fix**: tool_use events were incorrectly using
   response.eventData (JSON parameters) as toolName instead of
   eventMeta.toolName. Now correctly displays tool names like
   "schedule_query" instead of JSON strings.

2. **Optimistic block recreation fix**: Added blockAlreadyExists check
   to prevent recreating blocks on every SSE event, which was
   clearing the accumulated eventStream.

3. **Simplification**: Removed FIFO queue infrastructure (~250 lines)
   as SSE events are serial by nature - no concurrent updates occur.

Root causes:
- tool_use handler: toolName: response.eventData → toolMeta?.toolName
- Every SSE event triggered block recreation, resetting eventStream
- FIFO queue was over-engineering for serial SSE stream

Refs streaming UI debugging session

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds two new debug lessons:
1. Tool call metadata error - using eventData instead of eventMeta.toolName
2. Over-engineering: FIFO queue - SSE is serial, queue was always empty

Key takeaways:
- Diagnose before treating - add logs to confirm assumptions
- SSE doesn't need queuing - events are inherently serial
- Simplify over complexity - React Query has internal batching

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove console.log from eventTransformers.ts (extractToolCalls)
- Remove console.log from ChatMessages.tsx (eventStream debugging)
- Keep critical error logging in useAIQueries.ts

These debug logs were added during the streaming UI fix investigation
and are no longer needed now that the issue is resolved.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add comprehensive technical specification for implementing full streaming
tool calls (Solution A) in AI chat system.

Key decisions:
- Adopt complete streaming mode (DeepSeek native support)
- Progressive enhancement strategy with backward compatibility
- New ChatStreamWithTools interface

Expected improvements:
- First tool call latency: ~800ms → ~200ms (75% reduction)
- Perceived latency: 3-5s → <1s (60% reduction)

Refs #125

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hrygo hrygo force-pushed the feat/ai-optimization-router-feedback branch from e07a88b to 6b9e583 Compare February 8, 2026 14:47
@hrygo hrygo merged commit 90fc196 into main Feb 8, 2026
10 checks passed
@hrygo hrygo deleted the feat/ai-optimization-router-feedback branch February 8, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AI优化] 增量上下文更新 - 多轮对话性能优化

2 participants