Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions internal/protocol/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,23 @@ func decodeBridgeRequest(protocol Protocol, input map[string]any) (bridgeRequest
CallID: jsonutil.StringAt(item, "call_id"),
Result: item["output"],
})
case "custom_tool_call":
// Codex declares apply_patch as a Responses custom tool, so its
// replayed history carries custom_tool_call items. Chat and
// Anthropic only carry JSON tool arguments, so the freeform input
// is preserved under an "input" key.
appendBridgeBlock(&request.Messages, "assistant", bridgeBlock{
Kind: "tool_call",
ID: jsonutil.FirstString(jsonutil.StringAt(item, "call_id"), jsonutil.StringAt(item, "id")),
Name: jsonutil.StringAt(item, "name"),
ArgumentsJSON: customToolCallArguments(item["input"]),
})
case "custom_tool_call_output":
appendBridgeBlock(&request.Messages, "user", bridgeBlock{
Kind: "tool_result",
CallID: jsonutil.StringAt(item, "call_id"),
Result: item["output"],
})
case "message", "":
role := jsonutil.StringAt(item, "role")
blocks, err := decodeOpenAIBlocksChecked(item["content"])
Expand Down Expand Up @@ -661,6 +678,21 @@ func decodeBridgeRequest(protocol Protocol, input map[string]any) (bridgeRequest
return request, nil
}

// customToolCallArguments encodes a Responses custom tool call's freeform input
// as JSON arguments. The Chat and Anthropic bridges only carry JSON tool
// arguments, so the original text is preserved under an "input" key and the
// turn stays meaningful when auto-compaction replays it.
func customToolCallArguments(input any) string {
if input == nil {
return "{}"
}
encoded, err := jsonutil.Marshal(map[string]any{"input": input})
if err != nil {
return "{}"
}
return string(encoded)
}

// appendBridgeBlock adds blocks decoded from a standalone Responses item. It
// joins adjacent assistant items into one turn, including interleaved text,
// reasoning and tool calls. Tool results join only a preceding tool-only user
Expand Down