HarlonWang / HarlonWang/TrendingAI
chat 模型留痕改为服务端回显,替换客户端推断(对齐 research 先例)
- Dominant language
- Kotlin
- Stars
- 258
- Forks
- 10
- Avg merge
- 2h 40m
- Merged PRs (30d)
- 29
Description
## 背景
PR #76 审查中确认的改进项:聊天记录「哪个模型答的」留痕目前由客户端推断——`selectedModelId()` 拿进程缓存的目录 + 手选值 + Pro 态,经 `resolveDisplayedChatModel` 模拟服务端决策。推断在目录就绪时是准的,但原理上与真相可能脱节(目录缓存过期瞬间、服务端未来的临时降级策略、目录未就绪窗口只能记 null)。
同 app 内 research 已是正确形态:`ResearchRunResponse.model` 由服务端回显、客户端照记(见 `ChatViewModelPersistenceTest`「生成模型随报告透传」)。chat 作为流量主路径反而是推断口径,应对齐。
## 方案
- **后端**(github-ai-trending-api):`/api/chat` SSE 流回显一帧实际使用的模型(`resolveModel` 的结果),如首帧 `data: {"model":"gpt-5.6-luna"}`。老客户端 `ChatSse.parseLine` 对不认识的 payload 返回 null 跳过,加帧是安全加法。`/api/detail-summary` 同理。
- **客户端**:`ChatSse` 新增 `Event.Model`,`ChatApi.executeStreaming` 透传,落库改用服务端回显值;`selectedModelId()` 推断链路退役(`resolveDisplayedChatModel` 仍服务于选择器 chip 展示)。
- 两侧补测试:后端断言 SSE 含 model 帧且值等于 resolveModel 结果;客户端断言回显值优先于本地推断落库。
## 顺序约束
后端先上线(加帧对老客户端零影响),客户端随后消费。
_来源:PR #76 审查意见([clean] 级);相关讨论见该 PR。_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the /api/chat and /api/detail-summary SSE handlers and their resolveModel paths, then trace ChatSse, ChatApi.executeStreaming, and persistence tests such as ChatViewModelPersistenceTest. Done means the server emits the resolved model, the client persists that echoed value instead of local inference, and both sides have coverage for the new frame and precedence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- api, backend, testing
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100