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.
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package sessions
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// #1605 (LukeZ1988): MiniMax Code's calls reach the usage ledger. The
|
|
// sessions are @minimax-ai/code 0.6.8's own, written in a sandbox against a
|
|
// fake Anthropic upstream: one session with a single call through magpie's
|
|
// entry, one with two through magpie's entry and then one on a relay of the
|
|
// user's own (custom_provider:relay, model m2). The calls through magpie are
|
|
// the gateway's to count; the relay's is MiniMax Code's own, read here.
|
|
func TestMiniMaxCodeCalls(t *testing.T) {
|
|
for _, viaEnv := range []bool{false, true} {
|
|
name := "~/.minimax"
|
|
if viaEnv {
|
|
name = "MINIMAX_DATA_DIR"
|
|
}
|
|
t.Run(name, func(t *testing.T) {
|
|
claude, _ := setup(t)
|
|
dir := filepath.Join(filepath.Dir(claude), "home", ".minimax")
|
|
if viaEnv {
|
|
dir = filepath.Join(filepath.Dir(claude), "elsewhere")
|
|
t.Setenv("MINIMAX_DATA_DIR", dir)
|
|
}
|
|
copyTree(t, "testdata/minimax", dir)
|
|
var got []Call
|
|
for _, c := range Calls(time.Time{}) {
|
|
if c.Agent == "minimax-code" {
|
|
got = append(got, c)
|
|
}
|
|
}
|
|
if len(got) != 1 {
|
|
t.Fatalf("want MiniMax Code's one call on its own relay, got %d: %+v", len(got), got)
|
|
}
|
|
c := got[0]
|
|
if c.Model != "m2" || c.Upstream != "custom_provider:relay" {
|
|
t.Errorf("model %q upstream %q", c.Model, c.Upstream)
|
|
}
|
|
if c.Session != "mvs_82c610ef258f4350b76250bda12cacb5" {
|
|
t.Errorf("session %q", c.Session)
|
|
}
|
|
if want := (Tokens{Input: 123, Output: 7, CacheRead: 50, CacheWrite: 20}); c.Tokens != want {
|
|
t.Errorf("tokens %+v, want %+v", c.Tokens, want)
|
|
}
|
|
if !c.Time.Equal(time.UnixMilli(1791717506102)) {
|
|
t.Errorf("time %v", c.Time)
|
|
}
|
|
if c.Msg == "" {
|
|
t.Error("no message id to count the reply once by")
|
|
}
|
|
})
|
|
}
|
|
}
|