Files
magpie/internal/provider/peak.go
T
yetone 8921ef8056 provider: the Command Code plan prices DeepSeek V4.1 Flash, with its peak hours (treeman on Discord)
treeman_26897 (#help): in the price editor the Command Code plan's
deepseek/deepseek-v4.1-flash showed empty boxes, and typing a price lost
the peak/off-peak split.

What was wrong, on the plan (served by its plugin since the retire):
- No price at all. models.dev's DeepSeek now lists V4.1 Flash only as
  deepseek-flash, by the dated canonical deepseek/deepseek-v4.1-flash-1017,
  so no maker price matches the undated id, and the plugin's own model list
  gives cost 0 (none). Its calls were counted unpriced, at nothing, and the
  editor had no list price to show. models.dev's own "commandcode" catalog
  does list it ($0.15/$0.60, cache read $0.003); the Command Code API-key
  preset already read it through its endpoint, the plan didn't.
  ListPrice now falls back to that catalog for the plan (vendorListPrice),
  after the maker's price, so a model DeepSeek prices keeps DeepSeek's.
- No peak hours. PeakOf judged the vendor by the provider's URLs, and a
  plugin provider's are plugin://, which matched nothing. plugin:// URLs
  are now left out, so the plan is told by its id as before.
- A user's own price was flat at every hour. It is now the off-peak base,
  doubled in the peak hours of a vendor that bills by the hour (DeepSeek,
  Command Code's DeepSeek V4, OpenCode Go's two), as the vendor does to
  its own price. Chosen over a second "peak price" field: smaller, no new
  UI. The editor's hint says it ("Off-peak price, the list's or one set
  here: ... doubles it", en/zh/zh-TW/ja/de).
  Behaviour change for existing users: a price already set on such a model
  now counts double in those hours on the Usage page. It was not left
  alone because the vendor itself doubles whatever the off-peak price is;
  a price set for every other model is unchanged (tested: OpenCode Zen and
  an OpenAI model hold at every hour).

Tests:
- TestCommandCodePlanPrice (new, models.dev's bytes of 2026-10-30): the
  plan's plugin provider lists 0.15/0.6/0.003, 0.30 at peak; DeepSeek V4
  Pro keeps DeepSeek's 0.66; a set price is 0.1 off-peak, 0.2 at peak; a
  relay doesn't take Command Code's catalog.
- TestPeakOf: the plan with plugin:// URLs, its flash-fast, another plugin.
- TestPriceOfPeak: a set price doubles at peak; Zen and OpenAI set prices
  don't.
- model-price-edit.test.cjs: the hint names a price set here.

Broken by hand (each red, then put back):
- peak.go at origin/main: TestPeakOf plugin case and four
  TestCommandCodePlanPrice checks red.
- vendorListPrice off: "list price ... false", "unpriced".
- the user price's Peak line removed: TestPriceOfPeak (3 keys) and
  TestCommandCodePlanPrice (2 keys) red.
- origin/main's app.js with the new GUI test: model-price-edit red.

Run:
- mote-run go test ./... -timeout 45m -count=1 at acdc85ac8 + this change:
  every package ok but internal/gui, whose 10 reds are its real-window
  AppKit tests (TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt,
  TestMainWindowCorners, ...) killed at their deadlines while pboard was
  down on mote (pgrep pboard empty, crash reports 10-29 22:45): #4125.
  The size budgets in it passed.
- mote-run GOOS=linux go vet ./internal/provider, GOOS=windows go vet
  ./internal/provider ./internal/gui: ok.
- wsl-run model-price-edit.test.cjs: Chromium 2/2, WebKit 2/2.
- wsl-run, Chromium and WebKit: i18n-keys, gui-ja, gui-zh-tw,
  model-price-edit, model-price-tiers, provider-price-rate,
  usage-unpriced-names, usage-unpriced-sum, commandcode-risk.
  Each engine 27 pass, 1 fail: gui-ja's "ja has every zh string", on
  the Routing plugin's connection-check string from da3c5e0c0, red on
  origin/main a0cb8b646 too; fixed in the next commit (gui-ja and
  i18n-keys 7/7 after it).
- After rebasing onto origin/main 2df46e3c8 (which added i18n.js lines):
  mote-run go test ./internal/provider: ok; internal/gui -run
  'Budget|Size': ok; wsl-run i18n-keys, gui-ja, gui-zh-tw,
  model-price-edit with the next commit: 14/14.

Not tried:
- No real Command Code bill compared with magpie's count, and no real
  plan account used: the prices are models.dev's, the hours are the
  ones 9e73f69af already uses for Command Code.
- The whole GUI suite: the WSL box had ten other suites running (some for
  4h+); it runs after this push and is reported separately.
- Not checked against the real catalog: whether another relay with no
  catalog of its own that serves the undated deepseek-v4.1-flash is
  unpriced the same way since models.dev's dated canonical.
2026-10-30 23:00:01 +08:00

69 lines
2.9 KiB
Go

package provider
import (
"cmp"
"slices"
"strings"
"github.com/yetone/magpie/internal/catalog"
)
// peakBill is a vendor that bills DeepSeek's models by the hour a call is
// made at: its list price is the off-peak one, doubled in the peak hours
// (catalog.Peak). Each one's own pricing page says so, and so does its
// models.dev entry's cost multiplier, which models.dev's api.json leaves
// out. Others that resell DeepSeek's models keep one price at every hour:
// OpenCode Zen lists deepseek-v4.1-flash at $0.30/$1.20 flat
// (https://opencode.ai/docs/zen); a relay's price is its own.
type peakBill struct {
// at is whether a base URL is the vendor's API
at func(base string) bool
// ids are its preset's id and its subscription's: how a provider with
// no URL of its own (a plugin's, one removed since) is told
ids []string
peak catalog.Peak
// models are the ids it bills so, without a maker's prefix
// ("deepseek/"); nil: every model it serves
models []string
}
var peakBills = []peakBill{
// DeepSeek's own API, every model: "Off-peak rates are half of the
// peak rates" (https://api-docs.deepseek.com/quick_start/pricing)
{at: func(b string) bool { return HostOf(b) == "api.deepseek.com" }, ids: []string{"deepseek"}, peak: catalog.PeakDeepSeek},
// Command Code's DeepSeek V4 models, its Provider API's and its plan's
// (https://commandcode.ai/docs/resources/pricing-limits): its
// deepseek-v4-flash-fast is one price at every hour
{at: func(b string) bool { return HostOf(b) == "api.commandcode.ai" }, ids: []string{"commandcode", CommandCodePlanID}, peak: catalog.PeakWeekdays,
models: []string{"deepseek-v4.1-flash", "deepseek-v4.1-flash-fast", "deepseek-v4-flash", "deepseek-v4-flash-vision-exp", "deepseek-v4-pro"}},
// OpenCode Go's (https://opencode.ai/docs/go): Off-Peak and Peak rows
{at: func(b string) bool { return openCodeGateway(b) == "go" }, ids: []string{"opencode-go"}, peak: catalog.PeakWeekdays,
models: []string{"deepseek-v4.1-flash", "deepseek-v4-pro"}},
}
// PeakOf is the hours a call to model at p is billed double in, by the
// vendor p sends it to: its base URLs say which, and only a provider with
// none is told by its preset or id. A plugin's base (plugin://) names no
// vendor, so the Command Code plan its plugin serves is told by its id
// (treeman on Discord: its DeepSeek models showed no peak hours). Empty
// for any other provider or model.
func (p Provider) PeakOf(model string) catalog.Peak {
urls := slices.DeleteFunc([]string{p.Chat, p.Responses, p.Anthropic}, func(u string) bool {
return strings.TrimSpace(u) == "" || strings.HasPrefix(u, pluginBase)
})
m := strings.ToLower(strings.TrimSpace(model))
m = m[strings.LastIndexByte(m, '/')+1:]
for _, b := range peakBills {
var is bool
if len(urls) > 0 {
is = slices.ContainsFunc(urls, b.at)
} else {
is = slices.Contains(b.ids, cmp.Or(p.Preset, p.ID))
}
if is && (b.models == nil || slices.Contains(b.models, m)) {
return b.peak
}
}
return ""
}