CodeBuddy Code was wired on the Agents page, but nothing read its session files, so a call it made straight to its vendor never reached the usage ledger. Only the calls it made through magpie's gateway showed, logged by the gateway. CodeBuddy Code writes its sessions the way WorkBuddy does: projects/<cwd>/<id>.jsonl under $CODEBUDDY_CONFIG_DIR, else ~/.codebuddy. A reply's usage sits in providerData.usage on its function_call or assistant message line, keyed by providerData.messageId, and models.json has the same format. So WorkBuddy's reader is now parameterized by agent: - buddyFiles(agent, dir) lists the files. - buddyGateway(dir, id) reads that agent's own models.json. Its stamp cache is kept per path. - readWorkBuddyCalls takes the agent from the file. "codebuddy" is registered in callSources and wholeCallReaders. A model CodeBuddy asks for as custom-local:<id>, where models.json names <id> with vendor "magpie", went to the gateway, and is skipped as WorkBuddy's are. The fixtures in testdata/codebuddy are CodeBuddy Code 2.164.0's own files (npm @tencent-ai/codebuddy-code), with only the cwd path shortened. They come from two `codebuddy -p` runs in a sandbox HOME against a local OpenAI fake: one on a model the user added for another vendor (counted: two replies, 521 in + 26496 cache read, 115 out), and one on a vendor "magpie" entry (skipped). Run: - TestCodeBuddyCalls goes red (0 calls) with codebuddyCallFiles taken out of callSources, and green with it in. - TestCodeBuddyGatewayIsItsOwn checks that each agent's models.json is its own. - go test ./internal/sessions passes. - gofmt, go vet, Linux nogui vet and Windows vet are clean. - Sandboxed go test ./... at the rebased head. Not done: - The Sessions page still doesn't list CodeBuddy Code's sessions. This commit is the Usage side only. - Reasoning tokens (outputTokensDetails) aren't recorded, as for WorkBuddy. - Not run against the reporter's China-edition session (47 calls). The line shapes match those in the issue.
2 lines
510 B
JSON
2 lines
510 B
JSON
{"models":[{"id":"fake-m1","name":"Fake M1","vendor":"fakevendor","apiKey":"k-fake","url":"http://127.0.0.1:3971/v1/chat/completions","maxInputTokens":128000,"maxOutputTokens":8192,"supportsToolCall":true,"supportsImages":false},{"id":"deepseek/pro","name":"DeepSeek Pro","vendor":"magpie","apiKey":"magpie-codebuddy","url":"http://127.0.0.1:3425/v1/chat/completions","maxInputTokens":128000,"maxOutputTokens":8192,"supportsToolCall":true,"supportsImages":false}],"availableModels":["fake-m1","deepseek/pro"]}
|