fix(chat): update tool_calls structure and ensure kind is always set
This commit is contained in:
parent
1b9e7e32bd
commit
d6b38c4236
3 changed files with 12 additions and 6 deletions
|
|
@ -1214,7 +1214,7 @@ func TestSendWithRetry_ToolCallsPlaceholderDeleteAndFallsThroughToSend(t *testin
|
|||
ChatID: "123",
|
||||
Raw: map[string]string{
|
||||
"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"}}]`,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import {
|
||||
parseToolCallsFromContent,
|
||||
parseToolCallsValue,
|
||||
} from "@/features/chat/tool-calls.ts"
|
||||
import type { AssistantMessageKind, ChatMessage } from "@/store/chat.ts"
|
||||
} from "@/features/chat/tool-calls"
|
||||
import type { AssistantMessageKind, ChatMessage } from "@/store/chat"
|
||||
|
||||
type AssistantToolCalls = ChatMessage["toolCalls"]
|
||||
type ExistingAssistantMessageState = Pick<ChatMessage, "kind" | "toolCalls">
|
||||
|
|
@ -15,7 +15,7 @@ export interface AssistantMessageCreateState {
|
|||
|
||||
export interface AssistantMessageUpdateState {
|
||||
content: string
|
||||
kind?: AssistantMessageKind
|
||||
kind: AssistantMessageKind
|
||||
toolCalls?: AssistantToolCalls
|
||||
}
|
||||
|
||||
|
|
@ -100,9 +100,13 @@ export function parseAssistantMessageUpdateState(
|
|||
if (existing?.toolCalls) {
|
||||
return {
|
||||
content,
|
||||
kind: existing.kind ?? "normal",
|
||||
toolCalls: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
return { content }
|
||||
return {
|
||||
content,
|
||||
kind: existing?.kind ?? "normal",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ function parseLegacyToolFeedbackContent(
|
|||
const body = match[2]?.trim() ?? ""
|
||||
const codeFence = /```(?:json)?\r?\n([\s\S]*?)\r?\n```/m.exec(body)
|
||||
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 [
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue