mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: save media message type to db (#23427)
We had a bug where computer use base64-encoded screenshots would not be interpreted as screenshots anymore once saved to the db, loaded back into memory, and sent to Anthropic. Instead, they would be interpreted as regular text. Once a computer use agent made enough screenshots and stopped, and you tried sending it another message, you'd get an out of context error: <img width="808" height="367" alt="Screenshot 2026-03-23 at 12 02 54" src="https://github.com/user-attachments/assets/f0bf6be2-4863-47ca-a7a9-9e6d9dfceeed" /> This PR fixes that.
This commit is contained in:
+6
-1
@@ -159,6 +159,7 @@ type ChatMessagePart struct {
|
||||
Result json.RawMessage `json:"result,omitempty" variants:"tool-result?"`
|
||||
ResultDelta string `json:"result_delta,omitempty"`
|
||||
IsError bool `json:"is_error,omitempty" variants:"tool-result?"`
|
||||
IsMedia bool `json:"is_media,omitempty" variants:"tool-result?"`
|
||||
SourceID string `json:"source_id,omitempty" variants:"source?"`
|
||||
URL string `json:"url" variants:"source"`
|
||||
Title string `json:"title,omitempty" variants:"source?"`
|
||||
@@ -241,13 +242,17 @@ func ChatMessageToolCall(toolCallID, toolName string, args json.RawMessage) Chat
|
||||
}
|
||||
|
||||
// ChatMessageToolResult builds a tool-result chat message part.
|
||||
func ChatMessageToolResult(toolCallID, toolName string, result json.RawMessage, isError bool) ChatMessagePart {
|
||||
// The isMedia flag marks the result as carrying binary media content
|
||||
// (e.g. a screenshot) so that round-trip reconstruction preserves
|
||||
// the media type instead of sending raw base64 as text tokens.
|
||||
func ChatMessageToolResult(toolCallID, toolName string, result json.RawMessage, isError bool, isMedia bool) ChatMessagePart {
|
||||
return ChatMessagePart{
|
||||
Type: ChatMessagePartTypeToolResult,
|
||||
ToolCallID: toolCallID,
|
||||
ToolName: toolName,
|
||||
Result: result,
|
||||
IsError: isError,
|
||||
IsMedia: isMedia,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user