mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
feat(chat,seahorse): persist and display model_name across history (#2897)
* feat(chat,seahorse): persist and display model_name across history * test(seahorse): fix lint regressions in repair coverage * fix(pico): preserve model_name in live updates * fix(pico): preserve model_name through live stream wrappers
This commit is contained in:
@@ -50,6 +50,7 @@ type sessionChatMessage struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
Kind string `json:"kind,omitempty"`
|
||||
ModelName string `json:"model_name,omitempty"`
|
||||
Media []string `json:"media,omitempty"`
|
||||
Attachments []sessionChatAttachment `json:"attachments,omitempty"`
|
||||
ToolCalls []utils.VisibleToolCall `json:"tool_calls,omitempty"`
|
||||
@@ -510,6 +511,7 @@ func sessionTranscriptMessages(
|
||||
chatMsg := sessionChatMessage{
|
||||
Role: "user",
|
||||
Content: msg.Content,
|
||||
ModelName: msg.ModelName,
|
||||
Media: append([]string(nil), msg.Media...),
|
||||
Attachments: attachments,
|
||||
}
|
||||
@@ -529,9 +531,10 @@ func sessionTranscriptMessages(
|
||||
|
||||
toolCallsMsg, hasToolCallsMsg := assistantToolCallsMessage(
|
||||
msg.ToolCalls,
|
||||
msg.ModelName,
|
||||
toolFeedbackMaxArgsLength,
|
||||
)
|
||||
visibleToolMessages := visibleAssistantToolMessages(msg.ToolCalls)
|
||||
visibleToolMessages := visibleAssistantToolMessages(msg.ToolCalls, msg.ModelName)
|
||||
|
||||
// Pico web chat can persist both visible `message` tool output and a
|
||||
// later plain assistant reply in the same turn. Hide only the fixed
|
||||
@@ -556,6 +559,7 @@ func sessionTranscriptMessages(
|
||||
chatMsg := sessionChatMessage{
|
||||
Role: "assistant",
|
||||
Content: content,
|
||||
ModelName: msg.ModelName,
|
||||
Media: append([]string(nil), msg.Media...),
|
||||
Attachments: attachments,
|
||||
}
|
||||
@@ -682,14 +686,16 @@ func assistantThoughtMessage(msg providers.Message) (sessionChatMessage, bool) {
|
||||
return sessionChatMessage{}, false
|
||||
}
|
||||
return sessionChatMessage{
|
||||
Role: "assistant",
|
||||
Content: reasoning,
|
||||
Kind: "thought",
|
||||
Role: "assistant",
|
||||
Content: reasoning,
|
||||
Kind: "thought",
|
||||
ModelName: msg.ModelName,
|
||||
}, true
|
||||
}
|
||||
|
||||
func assistantToolCallsMessage(
|
||||
toolCalls []providers.ToolCall,
|
||||
modelName string,
|
||||
toolFeedbackMaxArgsLength int,
|
||||
) (sessionChatMessage, bool) {
|
||||
if len(toolCalls) == 0 {
|
||||
@@ -707,6 +713,7 @@ func assistantToolCallsMessage(
|
||||
return sessionChatMessage{
|
||||
Role: "assistant",
|
||||
Kind: "tool_calls",
|
||||
ModelName: modelName,
|
||||
ToolCalls: visibleToolCalls,
|
||||
}, true
|
||||
}
|
||||
@@ -718,7 +725,7 @@ func visibleAssistantToolArgsPreview(
|
||||
return utils.VisibleToolCallArgumentsPreview(tc, toolFeedbackMaxArgsLength)
|
||||
}
|
||||
|
||||
func visibleAssistantToolMessages(toolCalls []providers.ToolCall) []sessionChatMessage {
|
||||
func visibleAssistantToolMessages(toolCalls []providers.ToolCall, modelName string) []sessionChatMessage {
|
||||
if len(toolCalls) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -734,8 +741,9 @@ func visibleAssistantToolMessages(toolCalls []providers.ToolCall) []sessionChatM
|
||||
continue
|
||||
}
|
||||
messages = append(messages, sessionChatMessage{
|
||||
Role: "assistant",
|
||||
Content: content,
|
||||
Role: "assistant",
|
||||
Content: content,
|
||||
ModelName: modelName,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -564,7 +564,7 @@ func TestHandleGetSession_ReconstructsThoughtFromAssistantReasoningContent(t *te
|
||||
sessionKey := picoSessionPrefix + "detail-reasoning-content"
|
||||
for _, msg := range []providers.Message{
|
||||
{Role: "user", Content: "hello"},
|
||||
{Role: "assistant", Content: "final visible answer", ReasoningContent: "internal chain of thought"},
|
||||
{Role: "assistant", Content: "final visible answer", ModelName: "gpt-5.4", ReasoningContent: "internal chain of thought"},
|
||||
} {
|
||||
if err := store.AddFullMessage(nil, sessionKey, msg); err != nil {
|
||||
t.Fatalf("AddFullMessage() error = %v", err)
|
||||
@@ -597,9 +597,15 @@ func TestHandleGetSession_ReconstructsThoughtFromAssistantReasoningContent(t *te
|
||||
resp.Messages[1].Kind != "thought" {
|
||||
t.Fatalf("thought message = %#v, want assistant thought/internal chain of thought", resp.Messages[1])
|
||||
}
|
||||
if resp.Messages[1].ModelName != "gpt-5.4" {
|
||||
t.Fatalf("thought model_name = %q, want %q", resp.Messages[1].ModelName, "gpt-5.4")
|
||||
}
|
||||
if resp.Messages[2].Role != "assistant" || resp.Messages[2].Content != "final visible answer" {
|
||||
t.Fatalf("final message = %#v, want assistant/final visible answer", resp.Messages[2])
|
||||
}
|
||||
if resp.Messages[2].ModelName != "gpt-5.4" {
|
||||
t.Fatalf("final model_name = %q, want %q", resp.Messages[2].ModelName, "gpt-5.4")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetSession_ReconstructsRefreshMatrixForThoughtAndToolSummary(t *testing.T) {
|
||||
@@ -725,8 +731,9 @@ func TestHandleGetSession_ReconstructsVisibleMessageToolOutputWithoutDuplicateSu
|
||||
for _, msg := range []providers.Message{
|
||||
{Role: "user", Content: "test"},
|
||||
{
|
||||
Role: "assistant",
|
||||
Content: "",
|
||||
Role: "assistant",
|
||||
Content: "",
|
||||
ModelName: "gpt-5.4-mini",
|
||||
ToolCalls: []providers.ToolCall{
|
||||
{
|
||||
ID: "call_1",
|
||||
@@ -771,9 +778,15 @@ func TestHandleGetSession_ReconstructsVisibleMessageToolOutputWithoutDuplicateSu
|
||||
t.Fatalf("first message = %#v, want user/test", resp.Messages[0])
|
||||
}
|
||||
assertVisibleToolCallMessage(t, resp.Messages[1], "message")
|
||||
if resp.Messages[1].ModelName != "gpt-5.4-mini" {
|
||||
t.Fatalf("tool_calls model_name = %q, want %q", resp.Messages[1].ModelName, "gpt-5.4-mini")
|
||||
}
|
||||
if resp.Messages[2].Role != "assistant" || resp.Messages[2].Content != "visible tool output" {
|
||||
t.Fatalf("assistant message = %#v, want visible tool output", resp.Messages[2])
|
||||
}
|
||||
if resp.Messages[2].ModelName != "gpt-5.4-mini" {
|
||||
t.Fatalf("visible tool output model_name = %q, want %q", resp.Messages[2].ModelName, "gpt-5.4-mini")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetSession_PreservesFinalAssistantReplyAfterMessageToolOutput(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user