fix(chat): update tool_calls structure and ensure kind is always set

This commit is contained in:
lc6464 2026-04-26 20:13:13 +08:00
parent 1b9e7e32bd
commit d6b38c4236
No known key found for this signature in database
GPG key ID: 53C61B42FEC71D6D
3 changed files with 12 additions and 6 deletions

View file

@ -1214,7 +1214,7 @@ func TestSendWithRetry_ToolCallsPlaceholderDeleteAndFallsThroughToSend(t *testin
ChatID: "123", ChatID: "123",
Raw: map[string]string{ Raw: map[string]string{
"message_kind": "tool_calls", "message_kind": "tool_calls",
"tool_calls": `[{"tool_feedback_explanation":"Looking up config","function":{"name":"read_file","arguments":"{}"}}]`, "tool_calls": `[{"id":"call_1","type":"function","function":{"name":"read_file","arguments":"{}"},"extra_content":{"tool_feedback_explanation":"Looking up config"}}]`,
}, },
}, },
}) })

View file

@ -1,8 +1,8 @@
import { import {
parseToolCallsFromContent, parseToolCallsFromContent,
parseToolCallsValue, parseToolCallsValue,
} from "@/features/chat/tool-calls.ts" } from "@/features/chat/tool-calls"
import type { AssistantMessageKind, ChatMessage } from "@/store/chat.ts" import type { AssistantMessageKind, ChatMessage } from "@/store/chat"
type AssistantToolCalls = ChatMessage["toolCalls"] type AssistantToolCalls = ChatMessage["toolCalls"]
type ExistingAssistantMessageState = Pick<ChatMessage, "kind" | "toolCalls"> type ExistingAssistantMessageState = Pick<ChatMessage, "kind" | "toolCalls">
@ -15,7 +15,7 @@ export interface AssistantMessageCreateState {
export interface AssistantMessageUpdateState { export interface AssistantMessageUpdateState {
content: string content: string
kind?: AssistantMessageKind kind: AssistantMessageKind
toolCalls?: AssistantToolCalls toolCalls?: AssistantToolCalls
} }
@ -100,9 +100,13 @@ export function parseAssistantMessageUpdateState(
if (existing?.toolCalls) { if (existing?.toolCalls) {
return { return {
content, content,
kind: existing.kind ?? "normal",
toolCalls: undefined, toolCalls: undefined,
} }
} }
return { content } return {
content,
kind: existing?.kind ?? "normal",
}
} }

View file

@ -14,7 +14,9 @@ function parseLegacyToolFeedbackContent(
const body = match[2]?.trim() ?? "" const body = match[2]?.trim() ?? ""
const codeFence = /```(?:json)?\r?\n([\s\S]*?)\r?\n```/m.exec(body) const codeFence = /```(?:json)?\r?\n([\s\S]*?)\r?\n```/m.exec(body)
const argumentsText = codeFence?.[1]?.trim() ?? "" const argumentsText = codeFence?.[1]?.trim() ?? ""
const explanation = body.replace(/```(?:json)?\r?\n[\s\S]*?\r?\n```/gm, "").trim() const explanation = body
.replace(/```(?:json)?\r?\n[\s\S]*?\r?\n```/gm, "")
.trim()
return [ return [
{ {