Usage's split by agent counts the gateway's calls and the calls the agents' session files record (sessions.Calls). MiniMax Code had no session reader at all, so a MiniMax Code on its own MiniMax sign-in or a relay of the user's never showed in it. What @minimax-ai/code 0.6.8 really writes, run in a sandbox HOME and MINIMAX_DATA_DIR against a fake Anthropic upstream: each session is a folder under <data dir>/v2/sessions/<yyyy>/<mm>/<dd>/, named <time>-session_<base64 of its mvs_ id>, its messages in messages.jsonl. An assistant line names the provider and model that answered, its usage (input without the cache, output, cacheRead, cacheWrite, as pi's ai package counts them) and the time in ms. The new reader (calls_minimax.go) is a whole-file call source (callSources, wholeCallReaders), and the folder is watched (Dirs). A call through magpie's own entry (custom_provider:magpie) is skipped; the gateway already counted it, with the account that answered. A reply is keyed by its message_id, so one copied into another generation of the history counts once. Gateway side: magpie's entry sets User-Agent minimax-code, and the sandbox run showed it reaching the upstream on /v1/messages and count_tokens. 0.6.8 without that header (a provider pointed at magpie by hand) sends "MiniMaxCode", which now names minimax-code too. The class check: StepCode, jcode, Prime Agent, Snow and every other built-in agent are named by their own gateway key (TokenFor); TestEveryAgentNamedByItsKey guards that for all of Clients(). Their direct, non-gateway calls are not read yet, and neither are those of pi, Cline, Qoder, Grok, Droid, omp, Cursor, Hermes and Alma, which the Sessions page reads (filed as #1607). Run: TestMiniMaxCodeCalls (the two real messages.jsonl files, verbatim: three calls through magpie's entry and one on a relay; under ~/.minimax and under MINIMAX_DATA_DIR) passes; dropping the gateway skip by hand turns it red (4 calls). TestAgentOf (MiniMaxCode, minimax-code), TestEveryAgentNamedByItsKey. go test ./internal/sessions ./internal/usage, the agent tests named above, gofmt -l, GOOS=linux and GOOS=windows go vet. Not tried: MiniMax Code on Windows or in WSL (WSL distros' MiniMax sessions are not read), a call on the MiniMax sign-in itself (provider name taken from the file whatever it is), or a session after compaction.
58 lines
2.2 KiB
Go
58 lines
2.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/usage"
|
|
)
|
|
|
|
// Every agent's requests are told by what its own description says.
|
|
func TestAgentOf(t *testing.T) {
|
|
cases := map[string]string{
|
|
"claude-cli/2.1.0 (external, cli)": "claude",
|
|
"codex_cli_rs/0.40.0 (Mac OS 26.0; arm64)": "codex",
|
|
"GeminiCLI/0.9.0 (darwin; arm64)": "gemini",
|
|
"opencode/1.2.3": "opencode",
|
|
"mimocode/1.2.3": "mimocode",
|
|
"curl/8.4.0": "curl",
|
|
"oh-my-pi/1.0": "omp",
|
|
"command-code/2.0": "commandcode",
|
|
"deepseek-harness/0.3.1": "dsh",
|
|
"dsh": "dsh", // a record kept by an id already
|
|
"pi": "pi",
|
|
"grok-pager/0.2.1": "grok",
|
|
"ZCode/3.10.1": "zcode",
|
|
"Alma/1.2.0": "alma",
|
|
"HanaAgent/1.0": "hanako",
|
|
"hanako": "hanako", // its key
|
|
"atomcode/5.2.1": "atomcode",
|
|
"cline ai-sdk/openai-compatible/3.0.37": "cline",
|
|
"minimax-code": "minimax-code", // what magpie's entry sends
|
|
"MiniMaxCode": "minimax-code", // 0.6.8's own (#1605)
|
|
"": "other",
|
|
}
|
|
for ua, want := range cases {
|
|
if got := usage.AgentOf(ua); got != want {
|
|
t.Errorf("%q: got %q want %q", ua, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Every agent's own gateway key (gateway.TokenFor) names it in usage: the
|
|
// ones that send no User-Agent of their own (StepCode, jcode, Prime Agent,
|
|
// Snow…) are told by that key alone (#1605's check of the class).
|
|
func TestEveryAgentNamedByItsKey(t *testing.T) {
|
|
seen := map[string]bool{}
|
|
for _, a := range Clients() {
|
|
seen[a.ID] = true
|
|
if got := usage.AgentOf(a.ID); got != a.ID {
|
|
t.Errorf("%s's key names %q", a.ID, got)
|
|
}
|
|
}
|
|
for _, id := range []string{"minimax-code", "stepcode", "jcode", "prime-agent", "snow"} {
|
|
if !seen[id] {
|
|
t.Errorf("%s isn't among the agents usage knows", id)
|
|
}
|
|
}
|
|
}
|