feat(web): 用户侧体验补齐——思维链/工具卡数据源 + 图片附件 + 语音上行 + home/vision/voice 真表现
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 打通 thinking/tool_call 运行时数据源:openai 发 thinking_*(reasoning_content)/tool_call_*
  (delta.tool_calls 累积重新组装 Args 非 JSON 串);anthropic_stream 发 thinking_*(content_block
  thinking start/delta/stop)。ws_bridge 已映射 thinking.*/tool_call.*,前端渲染活。
- 前端消息模型 + 附件:ChatMessage 加 image?;ChatInput 加附件按钮(file→base64)、预览/移除、
  image-aware onSend(text,image);VisionMessageBody 升级图像卡+识别 chip;VoiceMessageBody
  升级通话控制卡(live2D预留/波形/静音/挂断);HomeMessageBody 读真实 deviceUpdates(去掉
  sampleDevices 猜)。
- 激活 voice_input:ChatShell onVoice 不再 no-op → sendUp voice_input + 切 voice mode。
- addTool 改按工具名 upsert(修复 tool_call.start/end 重复卡);ws_mode_switch 应用 agent 驱动
  mode;addUserMessage/beginAssistant 带 image/mode;chatStream/useChat.send 带 image。
- 新增 image/phone 图标。

已知限制(标注):图片仅前端收集(后端 chatRequest 无 image 字段未接真推理);流式工具卡无真实
工具名(StreamEvent 只带 ID,回退 tool_<id前缀>);mode 由 agent 驱动但后端未逐消息下发 mode
(mode_switch 回显+默认当前 mode 兜底);voice 为 UI+voice_input 上行(真实通话后置)。
go build/vet/test + 前端 tsc 绿。
This commit is contained in:
Aska committed 2026-09-06 17:43:03 +08:00
1 parent b0bd93b15c
commit 2248ddce15
14 files changed
+576 -102

No files matched your search

+92
View File
@@ -260,3 +260,95 @@ func TestOpenAIChat_Chat_NoModel(t *testing.T) {
t.Fatalf("err = %v, want ErrNoModel", err)
}
}
func TestOpenAIChat_ChatStream_ReasoningAndText(t *testing.T) {
t.Parallel()
sse := strings.Join([]string{
`data: {"model":"gpt-test","choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":"Let me th"}}]}`,
``,
`data: {"choices":[{"delta":{"reasoning_content":"ink about it"}}]}`,
``,
`data: {"choices":[{"delta":{"content":"Hel"}}]}`,
``,
`data: {"choices":[{"delta":{"content":"lo"}}]}`,
``,
`data: {"choices":[],"usage":{"prompt_tokens":5,"completion_tokens":2,"total_tokens":7}}`,
``,
`data: [DONE]`,
``,
}, "\n")
srv := newCompletionServer(t, http.StatusOK, "text/event-stream", sse, nil)
ad := NewOpenAIChat(config.LLMConfig{BaseURL: srv.URL, Model: "gpt-test"})
var events []StreamEvent
resp, err := ad.ChatStream(context.Background(),
Request{Messages: []Message{TextMessage(RoleUser, "hi")}, Model: "gpt-test"},
func(ev StreamEvent) { events = append(events, ev) })
if err != nil {
t.Fatalf("ChatStream error: %v", err)
}
if resp.Content != "Hello" {
t.Errorf("resp.Content = %q, want Hello (reasoning must not leak into body content)", resp.Content)
}
wantEvents := []StreamEvent{
{Kind: StreamKindThinkingStart},
{Kind: StreamKindThinkingDelta, Delta: "Let me th"},
{Kind: StreamKindThinkingDelta, Delta: "ink about it"},
{Kind: StreamKindThinkingEnd},
{Kind: StreamKindTextStart},
{Kind: StreamKindTextDelta, Delta: "Hel"},
{Kind: StreamKindTextDelta, Delta: "lo"},
{Kind: StreamKindTextEnd},
}
if !reflect.DeepEqual(events, wantEvents) {
t.Errorf("events = %+v, want %+v", events, wantEvents)
}
}
func TestOpenAIChat_ChatStream_ToolCall(t *testing.T) {
t.Parallel()
sse := strings.Join([]string{
`data: {"model":"gpt-test","choices":[{"index":0,"delta":{"role":"assistant","tool_calls":[{"index":0,"id":"call_1","function":{"name":"lookup","arguments":"{\"loc"}}]}}]}`,
``,
`data: {"choices":[{"delta":{"tool_calls":[{"index":0,"function":{"arguments":"ation\":\"Paris\"}"}}]}}]}`,
``,
`data: {"choices":[{"delta":{},"finish_reason":"tool_calls"}]}`,
``,
`data: {"choices":[],"usage":{"prompt_tokens":5,"completion_tokens":6,"total_tokens":11}}`,
``,
`data: [DONE]`,
``,
}, "\n")
srv := newCompletionServer(t, http.StatusOK, "text/event-stream", sse, nil)
ad := NewOpenAIChat(config.LLMConfig{BaseURL: srv.URL, Model: "gpt-test"})
var events []StreamEvent
resp, err := ad.ChatStream(context.Background(),
Request{Messages: []Message{TextMessage(RoleUser, "hi")}, Model: "gpt-test"},
func(ev StreamEvent) { events = append(events, ev) })
if err != nil {
t.Fatalf("ChatStream error: %v", err)
}
if len(resp.ToolCalls) != 1 {
t.Fatalf("resp.ToolCalls = %+v, want 1", resp.ToolCalls)
}
tc := resp.ToolCalls[0]
if tc.Name != "lookup" {
t.Errorf("tool call name = %q, want lookup", tc.Name)
}
if tc.Args["location"] != "Paris" {
t.Errorf("tool call args.location = %v, want Paris (reassembled from argument fragments)", tc.Args["location"])
}
if resp.Content != "" {
t.Errorf("resp.Content = %q, want empty (tool-only response)", resp.Content)
}
wantEvents := []StreamEvent{
{Kind: StreamKindToolCallStart, Index: 0, ID: "call_1"},
{Kind: StreamKindToolCallDelta, Index: 0, ID: "call_1", Delta: `{"loc`},
{Kind: StreamKindToolCallDelta, Index: 0, ID: "call_1", Delta: `ation":"Paris"}`},
{Kind: StreamKindToolCallEnd, Index: 0, ID: "call_1"},
}
if !reflect.DeepEqual(events, wantEvents) {
t.Errorf("events = %+v, want %+v", events, wantEvents)
}
}