Codex compacting on any Open Design model got 400 "[code=upstream_error] Provider returned error" from amr-link, while other providers compacted. Codex's compaction is its one request with "tools": [], and the summary ask adds tool_choice and parallel_tool_calls beside them (#292). Since plugins 0.1.13 /48f976402the Responses body is relayed to amr-link as written, and an OpenAI-style validator refuses empty tools and a lone tool_choice. - passthrough: a Responses request to Open Design (its plugin, or a provider at amr-link.open-design.ai) goes without an empty tools list and the tool_choice/parallel_tool_calls beside it (withoutEmptyTools). A body that declares a tool is unchanged; every other upstream is sent Codex's shape as before. - codexCompact: amr-link's "[code=upstream_error]" counts as upstreamFailed, so a summary still refused is asked as sent, then as text, then made locally, never handed to Codex as the 400. upstreamFailed is only used by the compaction ladder. Run (mote; the suite at54117164c, then rebased on1bfa8d5a1and -run 'OpenDesign|Compact' ./internal/gateway run again there: ok): - TestOpenDesignCompactionSendsNoEmptyTools and TestOpenDesignCompactionRefusedAsksAsText, built from Codex Desktop 26.1007's real compaction (testdata/codex-26.1007-compaction.json) through the fake plugin as opendesign: both red on the old gateway.go/codex_backend.go with the reporter's 400, green with them. - go test -run 'OpenDesign|Compact|LoneToolChoice|ToolsOff' ./internal/gateway ok. - go test -timeout 45m ./...: every package ok. - go vet (darwin), GOOS=linux -tags nogui and GOOS=windows vet of internal/gateway ok; gofmt -l clean. Not tried: a real Open Design account (none here). Which of the empty tools, the lone choices or the history's calls amr-link refuses is not confirmed; the second change covers whichever it is.
56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/yetone/magpie/internal/lazyre"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Open Design Cloud's amr-link answers a request it, or the vendor behind
|
|
// it, turns away with a 400 "[code=upstream_error]" and often no more than
|
|
// "Provider returned error". Codex's compaction is the one request Codex
|
|
// makes with no tools ("tools": [], codex-26.1007-compaction.json), and
|
|
// magpie's summary ask for it adds the tool_choice and parallel_tool_calls
|
|
// a relay of the ChatGPT backend checks for (#292): every model of the
|
|
// plan answered that summary 400 upstream_error while the turns around it,
|
|
// tools declared, went through (Mugenrikka on X). With no tools those two
|
|
// ask nothing, and a Chat API (OpenAI's own) refuses them, and an empty
|
|
// tools list, outright; so none of the three goes to amr-link.
|
|
|
|
// openDesign is whether p is Open Design Cloud: its plugin, or a provider
|
|
// at amr-link's address.
|
|
func openDesign(p provider.Provider) bool {
|
|
if p.PluginProvider() == "opendesign" {
|
|
return true
|
|
}
|
|
for _, proto := range []provider.Protocol{provider.Responses, provider.Chat, provider.Anthropic} {
|
|
if provider.HostOf(p.Base(proto)) == "amr-link.open-design.ai" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// withoutEmptyTools is a Responses or Chat body without an empty tools
|
|
// list and the tool_choice and parallel_tool_calls beside it; a body
|
|
// that declares a tool goes as it came.
|
|
func withoutEmptyTools(body []byte) []byte {
|
|
if !bodyHas(body, `"tools"`) && !bodyHas(body, `"tool_choice"`) && !bodyHas(body, `"parallel_tool_calls"`) {
|
|
return body
|
|
}
|
|
var q struct {
|
|
Tools []json.RawMessage `json:"tools"`
|
|
}
|
|
if decodeJSON(body, &q) != nil || len(q.Tools) > 0 {
|
|
return body
|
|
}
|
|
return withoutFields(body, "tools", "tool_choice", "parallel_tool_calls")
|
|
}
|
|
|
|
// vendorUnsaidWords is amr-link's word for a refusal it passes on from the
|
|
// vendor behind it, said or not why: a summary ask so refused is asked
|
|
// again with the roles as Codex sent them, then as text, then made
|
|
// locally (codexCompact), as for a relay's "Upstream request failed".
|
|
var vendorUnsaidWords = lazyre.New(`(?i)\[code=upstream_error\]`)
|