agents: Qoder is known as Qoder, not Bun — Qoder CLI is a Bun single-file build whose requests carry Bun's User-Agent and nothing of Qoder's, so magpie's provider in Qoder (and Qoder CN) now carries the key magpie-qoder (magpie-qoder-cn), which the gateway knows an agent by before its User-Agent: usage, the routing view and the models it is shown say Qoder. A Qoder wired before with the key magpie is still magpie's and gets the new key on the next sync, as magpie starts
This commit is contained in:
+11
-3
@@ -61,7 +61,7 @@ func qoderSite(home string, b qoderBuild) *Agent {
|
||||
get := func(k string) string { v, _ := edit.GetJSON(path, k); return v }
|
||||
onMagpie := func() bool {
|
||||
_, ok := cutMagpie(get("model.name"))
|
||||
return ok && get(slot+".apiKey") == gateway.Token
|
||||
return ok && qoderKeyed(get(slot+".apiKey"), b.id)
|
||||
}
|
||||
return &Agent{
|
||||
ID: b.id, Name: b.name, Icon: "qoder", Aliases: b.aliases,
|
||||
@@ -100,7 +100,7 @@ func qoderSite(home string, b qoderBuild) *Agent {
|
||||
}
|
||||
// out of magpie: its provider goes, and the model the user
|
||||
// had comes back when none is asked for
|
||||
if onMagpie() || get(slot+".apiKey") == gateway.Token {
|
||||
if onMagpie() || qoderKeyed(get(slot+".apiKey"), b.id) {
|
||||
if err := edit.DelJSON(path, slot); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -163,5 +163,13 @@ func qoderProvider(agent, model string) map[string]any {
|
||||
ms = append(ms, e)
|
||||
}
|
||||
return map[string]any{"displayName": "magpie", "protocol": "openai", "baseUrl": gatewayV1(),
|
||||
"apiKey": gateway.Token, "model": model, "models": ms}
|
||||
"apiKey": gateway.TokenFor(agent), "model": model, "models": ms}
|
||||
}
|
||||
|
||||
// qoderKeyed: key is one magpie gives Qoder's provider — its own,
|
||||
// gateway.TokenFor, since Qoder's requests carry Bun's User-Agent and
|
||||
// nothing of Qoder's, or gateway.Token, which it was given before; a sync
|
||||
// gives it the new one.
|
||||
func qoderKeyed(key, agent string) bool {
|
||||
return key == gateway.TokenFor(agent) || key == gateway.Token
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@ import (
|
||||
|
||||
"github.com/tidwall/jsonc"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
)
|
||||
|
||||
func TestQoder(t *testing.T) {
|
||||
@@ -66,7 +68,7 @@ func testQoder(t *testing.T, mk func(string) *Agent, rel string) {
|
||||
}
|
||||
c, raw := read()
|
||||
p := c.Providers[magpieID]
|
||||
if !strings.Contains(raw, "// the user's") || c.Model["name"] != "magpie/deepseek/pro" || p["baseUrl"] != gatewayV1() || p["apiKey"] != gateway.Token ||
|
||||
if !strings.Contains(raw, "// the user's") || c.Model["name"] != "magpie/deepseek/pro" || p["baseUrl"] != gatewayV1() || p["apiKey"] != gateway.TokenFor(a.ID) ||
|
||||
p["protocol"] != "openai" || p["model"] != "deepseek/pro" || c.Providers["mine"]["apiKey"] != "sk-m" || c.Theme != "dark" {
|
||||
t.Fatalf("magpie:\n%s", raw)
|
||||
}
|
||||
@@ -108,6 +110,20 @@ func testQoder(t *testing.T, mk func(string) *Agent, rel string) {
|
||||
t.Fatalf("own:\n%s", raw)
|
||||
}
|
||||
|
||||
// wired before Qoder had a key of its own: still magpie's, and a sync
|
||||
// gives it Qoder's key, which the gateway knows it by (not Bun's UA)
|
||||
f.Set("magpie/deepseek/pro")
|
||||
edit.SetJSON(path, edit.KV{Path: "providers." + magpieID + ".apiKey", Value: gateway.Token})
|
||||
if a.Check() != "" {
|
||||
t.Fatalf("old key: %q", a.Check())
|
||||
}
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c, raw = read(); c.Providers[magpieID]["apiKey"] != gateway.TokenFor(a.ID) || usage.AgentOf(a.ID) != a.ID {
|
||||
t.Fatalf("synced key:\n%s", raw)
|
||||
}
|
||||
|
||||
// no settings before: a new file with magpie's provider
|
||||
os.Remove(path)
|
||||
if err := f.Set("magpie/deepseek/pro"); err != nil {
|
||||
|
||||
@@ -74,6 +74,7 @@ func TestAgentOf(t *testing.T) {
|
||||
for _, c := range []struct{ auth, key, ua, want string }{
|
||||
{"Bearer " + TokenFor("alma"), "", "ai-sdk/openai/2.0.52 ai-sdk/provider-utils/3.0.12 runtime/node.js/v22", "alma"},
|
||||
{"", TokenFor("alma"), "ai-sdk/anthropic/2.0.1", "alma"},
|
||||
{"Bearer " + TokenFor("qoder"), "", "Bun/1.4.2", "qoder"},
|
||||
{"Bearer " + Token, "", "claude-cli/2.1.0 (external, cli)", "claude-cli"},
|
||||
{"Bearer " + Token, "", "ai-sdk/openai/2.0.52", "ai-sdk"},
|
||||
{"Bearer " + Token + "-", "", "codex_cli_rs/0.40.0", "codex_cli_rs"},
|
||||
|
||||
Reference in New Issue
Block a user