A signed-in Claude Code is now offered as a provider (claude/…) like Codex and Copilot. Anthropic classifies another agent's system prompt as third-party traffic even over Claude Code's OAuth, so magpie drives the real local claude binary for every generation: the caller's tools are bridged in over MCP (magpie claude-mcp-helper), and tool results resume the same Claude Code turn. Token counting is estimated locally so the OAuth token takes no side path. No model list is compiled in any more. The built-in catalog, preset defaults and Claude Code's alias list are gone; the picker shows the models.dev catalog (refreshed in the background when stale) layered with each vendor's own /models answer, and signed-in accounts fetch theirs at start-up. Whether a model rejects temperature/top_p now comes from models.dev rather than a name prefix. The gateway retries a Chat request on the Responses endpoint when the model is Responses-only, and remembers that. Recent calls keep the first 256 KB of request and response bodies, viewable in the call list. The Usage tab shows subscription allowances (Claude, Codex, Copilot) as the vendors report them.
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package gateway
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
)
|
|
|
|
// Recent-call bodies are diagnostics, not an unbounded traffic log. Keeping the
|
|
// first 256 KiB is enough to inspect ordinary prompts and responses while
|
|
// preventing images or long streams from multiplying into tens of MiB across
|
|
// 40 calls.
|
|
const callBodyLimit = 256 << 10
|
|
|
|
type capturedBody struct {
|
|
buf bytes.Buffer
|
|
truncated bool
|
|
}
|
|
|
|
func (c *capturedBody) add(p []byte) {
|
|
if c.buf.Len() >= callBodyLimit {
|
|
c.truncated = c.truncated || len(p) > 0
|
|
return
|
|
}
|
|
n := min(len(p), callBodyLimit-c.buf.Len())
|
|
_, _ = c.buf.Write(p[:n])
|
|
if n < len(p) {
|
|
c.truncated = true
|
|
}
|
|
}
|
|
|
|
func (c *capturedBody) text() string { return c.buf.String() }
|
|
|
|
func captureRequestBody(p []byte) (string, bool) {
|
|
var c capturedBody
|
|
c.add(p)
|
|
return c.text(), c.truncated
|
|
}
|
|
|
|
type captureResponseWriter struct {
|
|
http.ResponseWriter
|
|
body capturedBody
|
|
}
|
|
|
|
func (w *captureResponseWriter) Write(p []byte) (int, error) {
|
|
w.body.add(p)
|
|
return w.ResponseWriter.Write(p)
|
|
}
|
|
|
|
func (w *captureResponseWriter) Flush() {
|
|
if f, ok := w.ResponseWriter.(http.Flusher); ok {
|
|
f.Flush()
|
|
}
|
|
}
|