* agents: omp's subagents and small role pick their own models, through magpie too * agents: omp keeps a role's thinking level and the model it had before magpie, and offers the slow and designer roles A role set to "anthropic/claude-opus-5:max" and switched to a magpie model lost its ":max", and resetting it deleted the key rather than putting the user's model back. The level now goes with the new model (omp clamps one the model lacks, never fails), the model the role had before magpie is stashed and restored, and the reviewer's @slow and the designer's @designer roles are fields beside subagents and small. * gui: omp's slow and designer roles follow the model, as its subagents do Unset, both roles take the session's model, yet the picker offered them omp's Default and no typed model. They are now squares beside subagents, with Same as model first and a model typed in taken as it is. * agents: omp's thinking level no longer hides a role's model from magpie, and the model alone clears it — magpie omp magpie/x/y:high is taken, a role moved back to omp's own is drift, a list of models comes back on reset, and designer (gone in omp 18.1.5) goes A role on "magpie/deepseek/pro:max" matched the picker only through the option offered for its level beside the model, and only for the value in the file now. So the CLI refused a model typed at a level, a recorded value at a level the current one didn't share wasn't known for magpie's (no "replaced" drift), and a level could never be taken away: a model picked without one took the old one on. An agent may now say what it keeps after the model (Agent.SplitSuffix; omp's is its level). Drift, Reseat, RenameProvider, Spell and the CLI's field-for-value match the model and put the suffix back after the one they move to; agents without it are unchanged. The option at the level stays: it keeps the level. Another model keeps it too; the same model picked alone clears it. A role omp falls back through (a YAML list, or the comma list omp joins it into, settings.ts modelRoleValueFromUnknown) read as nothing, so it wasn't stashed and a reset deleted it. It reads as that comma list now, is stashed and comes back; a list has no level of its own. omp 18.1.5 removed the designer role (CHANGELOG), so its field goes. The smol role, like task and slow, gives its agents the session's model when unset; its field is labelled smol, as omp names it, so the GUI can show it as the others without touching other agents' "small". * gui: omp's smol role follows the model as its subagents and slow role do, and designer goes smol unset gives omp's scout and sonic the session's model, so it is a square after the pickers with "Same as model" first, as subagents and slow are (a feather). Its label is smol, not small: OpenCode's, Crush's and OpenChamber's small model stays a picker. designer, a role omp 18.1.5 removed, leaves FOLLOWS_MODEL, the glyphs and i18n. * agents: the note on omp's fallback chains says their keys are roles, and from omp 18 models too ompRefKeys' comment had retry.fallbackChains keyed by model. omp 16.3.5 takes only a role's name there (session/agent-session.ts: "a mapping of role names to selector arrays"); omp 18.4.4 takes a role's name or a model selector (session/retry-fallback-chains.ts). Walking the keys stays: a role's name is no magpie model and is passed over. Follow-up to the review of #340. * agents: omp reads whether it is on magpie one way, and a role at a level that a fallback chain names too is renamed once in each Rebased on #340, one scan over omp's config (ompRefs) answers both questions: magpie's provider stays in models.yml while anything under ompRefKeys is on magpie, as #340 has it, and Check looks at the wiring while any role under modelRoles is, as this PR had it; a fallback chain or enabledModels alone keeps the provider without being checked. A provider renamed moves a role at a thinking level through SplitSuffix first, then RenameRefs the rest, which finds no old name left in the roles: each place moves once, the level kept. * agents: a fallback chain alone on magpie has omp's wiring checked, and a role set off magpie mends it Check now reads the same keys dropMagpie does (ompRefKeys: every role, retry.fallbackChains, enabledModels, task.agentModelOverrides): whatever keeps magpie's provider in models.yml has its baseUrl checked, so a chain on magpie whose wiring something else moved no longer fails its fallback silently. Applying again sets the model role, which may be omp's own; a role set off magpie while something else still names it now writes magpie's provider afresh instead of leaving it as it is, so that mends the wiring. Review of #325. * agents: an omp role that is a list of models stays the user's own, even starting on one of magpie's, and comes back as it was written A role omp falls back through ([magpie/deepseek/flash, openai/gpt-6], or the same as a comma-separated string) was taken for one of magpie's models because it started with magpie/: magpie taking the role over stashed nothing, and a reset deleted it. Only one model, no comma, is magpie's now: SplitSuffix answers whether a value is one model, and Spell, drift (magpieValue), Reseat, RenameProvider and the CLI's fieldForValue leave a list alone. The stash keeps a YAML list as the YAML it was written in (edit.GetYAMLText), and a reset puts it back so, flow or block; a comma-separated string comes back a string. A provider renamed moves the names inside a list through RenameRefs, once, and in the lists the stash keeps too. Review of #325. * gui: a test holds omp's subagents, smol and slow roles as squares that follow the model, and OpenCode's small model a picker omp-roles.test.cjs, in Chromium and WebKit, English and Chinese, API faked: the three roles are squares after the model's picker, unset named "same as model" (「同主模型」) and set naming their model; smol's picker opens on "Same as model" with the model beside it, and a pick sends it and shows it. OpenCode's small model stays a picker. With smol and slow taken out of FOLLOWS_MODEL it fails at "small is a square". Review of #325. * gateway: a Claude Code run whose subagent ended on StructuredOutput is let go, and runs left waiting on tool calls are bounded (#345) — a workflow's subagents end on StructuredOutput, which the client answers itself, so the bridge's claude -p waited 30 minutes for a result that never came, one process per subagent. Such a run now waits 30s (for a schema error the client sends at once) and ends; of other runs waiting 5 minutes or more on their caller's tools, 16 are kept, the longest waiting let go first (one that then gets its results starts anew with the whole conversation). TestClaudeRunEndsAfterStructuredOutput and TestClaudeParkedRunsAreBounded fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. * plugins: a built-in moved onto its plugin looks and works as it did (你确保插件版的订阅 provider 和其对应的内置的…都保持一模一样了吗?) — moved onto its plugin, a built-in lost pieces: its tile's name, icon, plans and risk note went to the plugin's own, "Add account" still opened the built-in's sign-in (in the app, on the server and in `magpie accounts add`), an agent's own sign-in the built-in still found showed a second usage card of the same account, the account's plan badge went, WorkBuddy's daily check-in stopped, the provider's icon and site were the plugin's, WorkBuddy AI's card was named WorkBuddy, and Devin, which had no card of its own, lost the plugin's. Now a moved built-in keeps its tile and risk sheet and signs in through its plugin; its cards take the built-in's place and name, and it has none of its own; the plan the plugin tells stays with the account; WorkBuddy checks in through the plugin, which signs the call; a card is left out only where its built-in's slot showed it. TestMovedBuiltinQuiet, TestWorkBuddyCheckinThroughPlugin, TestMoveToPlugin (Devin-like card) and TestPluginUsage (plan kept) fail without the change. Command Code and Devin moved and back in a sandbox HOME: one card each, plan, name. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; plugin-move, plugin-signin, commandcode-risk, old-webkit pass; click-scroll's WebKit fails the same on origin/main under this load. * provider: the Providers and Gateway pages no longer wait on `claude --version` (deluxe on Discord: on Omarchy the two pages never loaded) — on Omarchy `claude` is a mise wrapper that installs or updates Claude Code before it answers, which on a slow network takes minutes or never ends; magpie asked it with no limit and with a lock held, so /api/providers (fetching the Claude account's models) and every Claude request waited with it. The CLI is now asked in the background, given a minute, and a caller waits at most 3s before the version it has stands in; a late answer is taken once it comes. Reproduced on an Omarchy VM (/api/providers unanswered after 100s on v0.1.516, 3.7s with the change). TestClaudeVersionDoesNotWaitForAStalledCLI and TestClaudeVersionTakenWhenItComes fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. * plugins: a plugin's account behaves as its built-in's (the user: 插件版的订阅 provider 和内置的…保持一模一样了吗) — a plugin's failed sign-in now says why ("the sign-in failed: the sign-in page expired") instead of a bare failure; a plugin account the provider refuses with 401 is marked lapsed, "<user>'s <provider> sign-in has expired — sign in again", beside the account and on its usage card as a built-in's is, and the mark goes when it answers again or is signed in anew; a Devin or Command Code account taken from the agent's CLI moves to the plugin marked as the CLI's and back as the agent's own, so the one it follows stays the one the CLI is signed in to. TestPluginProvider (lapsed), TestMoveSideState (cli) and TestPluginSignIn (reason) fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. * agents: "Hide all" in an agent's model list keeps its line, and an uninstalled Gemini CLI goes from the Agents page (#356, #230) — the line under an agent ("Showing 0 / N models") came only when a picker still listed one of magpie's models, so hiding them all took away the one way back; it now stays while any is hidden. Gemini CLI was taken as present from what it leaves in ~/.gemini (settings.json, .env, installation_id…), which stays after it is uninstalled, so its row stayed, offering to set up a CLI that can't run; it is now its gemini binary. TestAgentModelLineAllHidden and TestGeminiNotAntigravity fail without the change; agent-models-all-hidden.test.cjs (Chromium, WebKit, en/zh) added. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./internal/agent ./internal/gui ./internal/library ./internal/provider pass; agent-models, click-scroll, old-webkit pass. * gateway: Codex's Responses Lite tools reach SuperGrok and every other backend, and a group moves on when a member can't read a request (#350) — Codex sends a Lite model's tools as an additional_tools input item, its own functions in a "functions" namespace; magpie relayed the item to xAI, which 422s on it (unknown item type), and translated routes (Cursor, Anthropic, Chat…) dropped it, so the model had no tools. Outside OpenAI the item's tools now go in tools, the functions namespace opened into plain tools and earlier calls un-namespaced; OpenAI and the ChatGPT account still get Codex's own form. A 400/422 over the request's shape (failed to deserialize, unknown item type/parameter…) now moves to the group's next member, each asked once, the member not resting; the Routing page says so. TestAdditionalToolsRelayed, TestAdditionalToolsTranslated and TestGroupFailsOverARequestShape fail without the change; routing-shape.test.cjs (Chromium, WebKit, en/zh) added. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; click-scroll, old-webkit, routing-wb-refused pass. --------- Co-authored-by: yetone <yetoneful@gmail.com>
433 lines
16 KiB
Go
433 lines
16 KiB
Go
package agent
|
|
|
|
// omp (oh-my-pi, a fork of Pi) keeps its settings in ~/.omp/agent/config.yml
|
|
// (or where ompDir says its variables move it),
|
|
// the model of each role under modelRoles as "provider/model", and providers
|
|
// of the user's own in models.yml beside it. magpie adds itself there as the
|
|
// provider "magpie", keyless (auth: none), with the catalog as its models; a
|
|
// model through magpie is "magpie/<provider>/<model>", which omp matches
|
|
// whole against provider/id. The other roles, the fallback chains and the
|
|
// like may name them as well (ompRefKeys); magpie stays while any does.
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// ompEfforts are the thinking levels omp knows.
|
|
var ompEfforts = []string{"minimal", "low", "medium", "high", "xhigh", "max"}
|
|
|
|
// ompRefKeys are where omp's config names models: each role (a list to try
|
|
// in order, "a,b" or a sequence), the retry fallback chains (a list of
|
|
// models under each key; the key is a role's name, the only kind omp 16
|
|
// takes (agent-session.ts), or from omp 18 a model selector as well
|
|
// (retry-fallback-chains.ts) — a role's name read with them is no model of
|
|
// magpie's and is passed over), the models it cycles through (enabledModels,
|
|
// also scoped to paths) and the models of task agents. An entry may end in a
|
|
// thinking level ("magpie/deepseek/pro:max").
|
|
var ompRefKeys = []string{"modelRoles", "retry.fallbackChains", "enabledModels", "task.agentModelOverrides"}
|
|
|
|
// ompRefs calls fn on each model of a value under ompRefKeys, the spaces
|
|
// after a comma kept, and answers the value with fn's answers in place.
|
|
func ompRefs(v string, fn func(string) string) string {
|
|
parts := strings.Split(v, ",")
|
|
for i, p := range parts {
|
|
lead := len(p) - len(strings.TrimLeft(p, " \t"))
|
|
parts[i] = p[:lead] + fn(p[lead:])
|
|
}
|
|
return strings.Join(parts, ",")
|
|
}
|
|
|
|
// ompLevel splits a role's model from the thinking level omp reads off its
|
|
// end, "provider/model:level" (model-resolver.ts), the level returned with
|
|
// its colon: one of the efforts, off, or auto, omp's own pick each turn.
|
|
// Anything else after a colon is part of the model id (ollama's qwen3:8b),
|
|
// and a list of models omp falls back through ("a,b:high") has no level of
|
|
// its own, each of its models its own.
|
|
func ompLevel(v string) (model, level string) {
|
|
if i := strings.LastIndexByte(v, ':'); i > 0 && !strings.Contains(v, ",") {
|
|
if l := v[i+1:]; l == "off" || l == "auto" || slices.Contains(ompEfforts, l) {
|
|
return v[:i], v[i:]
|
|
}
|
|
}
|
|
return v, ""
|
|
}
|
|
|
|
// ompSplit is omp's SplitSuffix: a role's model and its thinking level
|
|
// (ompLevel), one false for a list of models omp falls back through ("a,b",
|
|
// or a YAML list, read as one), which is the user's own whatever it names.
|
|
func ompSplit(v string) (model, level string, one bool) {
|
|
if strings.Contains(v, ",") {
|
|
return v, "", false
|
|
}
|
|
model, level = ompLevel(v)
|
|
return model, level, true
|
|
}
|
|
|
|
// ompOnMagpie: a role's value is one of magpie's models, at a level or not.
|
|
func ompOnMagpie(v string) bool {
|
|
_, _, one := ompSplit(v)
|
|
return one && usesMagpie(v)
|
|
}
|
|
|
|
// ompYAMLList: a value the stash keeps is a list as the YAML it was written
|
|
// in ("[a, b]", "- a"), which no model reads as.
|
|
func ompYAMLList(v string) bool { return strings.HasPrefix(v, "[") || strings.HasPrefix(v, "- ") }
|
|
|
|
// ompProfileName is a profile name omp takes (pi-utils dirs.ts,
|
|
// normalizeProfileName); it refuses any other.
|
|
var ompProfileName = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,63}$`)
|
|
|
|
// ompDir is omp's agent folder, found as omp's pi-utils (dirs.ts) finds it:
|
|
// under ~/.omp, or ~/$PI_CONFIG_DIR; a profile's (OMP_PROFILE, else
|
|
// PI_PROFILE; "default" is none) is profiles/<name>/agent there; with none,
|
|
// PI_CODING_AGENT_DIR — the variable Pi reads — moves it, else it is
|
|
// agent there. omp takes that variable as given, without expanding "~".
|
|
func ompDir(home string) string {
|
|
root := filepath.Join(home, ".omp")
|
|
if d := os.Getenv("PI_CONFIG_DIR"); d != "" {
|
|
root = filepath.Join(home, d)
|
|
}
|
|
p, set := os.LookupEnv("OMP_PROFILE")
|
|
if !set {
|
|
p = os.Getenv("PI_PROFILE")
|
|
}
|
|
if p = strings.TrimSpace(p); p != "" && p != "default" && ompProfileName.MatchString(p) && !strings.HasSuffix(p, ".") {
|
|
return filepath.Join(root, "profiles", p, "agent")
|
|
}
|
|
if d := os.Getenv("PI_CODING_AGENT_DIR"); filepath.IsAbs(d) {
|
|
return filepath.Clean(d)
|
|
}
|
|
return filepath.Join(root, "agent")
|
|
}
|
|
|
|
func omp(home string) *Agent {
|
|
dir := ompDir(home)
|
|
// omp reads the .yml and falls back to the .yaml
|
|
pick := func(name string) string {
|
|
yml := filepath.Join(dir, name+".yml")
|
|
if _, err := os.Stat(yml); err != nil {
|
|
if _, err := os.Stat(filepath.Join(dir, name+".yaml")); err == nil {
|
|
return filepath.Join(dir, name+".yaml")
|
|
}
|
|
}
|
|
return yml
|
|
}
|
|
path := pick("config")
|
|
roleGet := func(name string) func() string {
|
|
return func() string {
|
|
k := "modelRoles." + name
|
|
if v, ok := edit.GetYAML(path, k); ok {
|
|
return v
|
|
}
|
|
// a YAML list of models omp falls back through reads as the
|
|
// comma-separated string it takes for one too: what the stash
|
|
// keeps, and a reset writes back
|
|
return strings.Join(edit.GetYAMLList(path, k), ",")
|
|
}
|
|
}
|
|
// onMagpie: a role, a fallback chain, … (ompRefKeys) still names one of
|
|
// magpie's models
|
|
onMagpie := func() (used bool, err error) {
|
|
err = edit.EditYAMLStrings(path, ompRefKeys, func(v string) string {
|
|
ompRefs(v, func(m string) string { used = used || usesMagpie(m); return m })
|
|
return v
|
|
})
|
|
return used, err
|
|
}
|
|
writeMagpie := func() error {
|
|
models := pick("models")
|
|
if _, err := os.Stat(models); err != nil {
|
|
// omp moves an older models.json to models.yml only while there is
|
|
// no models.yml, so one magpie writes first has to carry it over
|
|
if err := edit.JSONToYAML(filepath.Join(dir, "models.json"), models); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return edit.SetYAML(models, edit.KV{Path: "providers." + magpieID, Value: ompProvider()})
|
|
}
|
|
// dropMagpie takes magpie's provider out of models.yml once nothing in
|
|
// the config is on magpie; while something is (a fallback chain, another
|
|
// role), it writes it afresh instead, so a role set off magpie — applying
|
|
// again what Check found — mends the wiring that is left.
|
|
dropMagpie := func() error {
|
|
used, err := onMagpie()
|
|
switch {
|
|
case err != nil:
|
|
return err
|
|
case used:
|
|
return writeMagpie()
|
|
}
|
|
return edit.DelYAML(pick("models"), "providers."+magpieID)
|
|
}
|
|
// was are the stash's keys for the roles, one each
|
|
var was []string
|
|
// role is the field for one of omp's model roles: one of magpie's brings
|
|
// magpie's provider into models.yml, and it goes once nothing is on it.
|
|
// What the user had there before magpie took the role over is stashed,
|
|
// and resetting the role puts it back: a list of models as the YAML it
|
|
// was written in, a flow list flow and a block one block.
|
|
role := func(key, label, name string, quiet bool) Field {
|
|
k := "modelRoles." + name
|
|
get := roleGet(name)
|
|
w := "omp:" + path + ":" + k
|
|
was = append(was, w)
|
|
kept := func() string {
|
|
if v, ok := edit.GetYAML(path, k); ok {
|
|
return v
|
|
}
|
|
v, _ := edit.GetYAMLText(path, k)
|
|
return v
|
|
}
|
|
return Field{
|
|
Key: key, Label: label, Quiet: quiet,
|
|
Get: get,
|
|
Set: func(v string) error {
|
|
cur := get()
|
|
if v == "" {
|
|
if ompOnMagpie(cur) {
|
|
v = unstash(w)
|
|
}
|
|
if v == "" {
|
|
if err := edit.DelYAML(path, k); err != nil {
|
|
return err
|
|
}
|
|
return dropMagpie()
|
|
}
|
|
if ompYAMLList(v) {
|
|
if err := edit.SetYAML(path, edit.KV{Path: k, Value: edit.YAMLText(v)}); err != nil {
|
|
return err
|
|
}
|
|
return dropMagpie()
|
|
}
|
|
} else if _, level, one := ompSplit(v); one && level == "" {
|
|
// another model keeps the role's thinking level; omp
|
|
// clamps one the model lacks to the highest it has below
|
|
// it (its lowest when none is) and drops it for a model
|
|
// that doesn't reason (pi-catalog model-thinking.ts),
|
|
// never fails.
|
|
// The same model picked without one is the way to have
|
|
// none: its option with the level beside it keeps it
|
|
if model, level := ompLevel(cur); level != "" && model != v {
|
|
v += level
|
|
}
|
|
}
|
|
model, _, one := ompSplit(v)
|
|
if ref, ok := strings.CutPrefix(model, magpieID+"/"); one && ok && isMagpie(ref) {
|
|
if !ompOnMagpie(cur) {
|
|
stash(map[string]string{w: kept()})
|
|
}
|
|
if err := writeMagpie(); err != nil {
|
|
return err
|
|
}
|
|
return edit.SetYAML(path, edit.KV{Path: k, Value: v})
|
|
}
|
|
forget(w)
|
|
if err := edit.SetYAML(path, edit.KV{Path: k, Value: v}); err != nil {
|
|
return err
|
|
}
|
|
return dropMagpie()
|
|
},
|
|
Options: func(cur map[string]string) []Option {
|
|
opts := append(ownOptions("", cur[key]), viaMagpie("omp", magpieID+"/")...)
|
|
// a catalog model with a thinking level is offered as it
|
|
// reads, beside the model: that keeps the level, the model
|
|
// alone clears it
|
|
if model, level := ompLevel(cur[key]); level != "" {
|
|
if i := slices.IndexFunc(opts, func(o Option) bool { return o.Ref != "" && o.Value == model }); i >= 0 {
|
|
o := opts[i]
|
|
o.Value, o.Label = cur[key], o.Label+" · "+level[1:]
|
|
opts = slices.Insert(opts, i+1, o)
|
|
}
|
|
}
|
|
return opts
|
|
},
|
|
}
|
|
}
|
|
return &Agent{
|
|
ID: "omp", Name: "omp", Icon: "omp", Aliases: []string{"oh-my-pi"},
|
|
UA: []string{"oh-my-pi"},
|
|
Bin: "omp", Dir: dir, Path: path,
|
|
// a role's thinking level is omp's, after whichever model it is on;
|
|
// a list of models is the user's own
|
|
SplitSuffix: ompSplit,
|
|
Sync: func() error {
|
|
return syncYAML(pick("models"), "providers."+magpieID, func() any { return ompProvider() })
|
|
},
|
|
// a provider renamed takes its models' ids in models.yml with it; a
|
|
// name left on the old one omp would pass over, with a warning. So
|
|
// does what a role had before magpie (a list may name magpie's
|
|
// models), which a reset puts back
|
|
RenameRefs: func(from, to string) (bool, error) {
|
|
old, now := magpieID+"/"+from+"/", magpieID+"/"+to+"/"
|
|
move := func(v string) string {
|
|
return ompRefs(v, func(m string) string {
|
|
if rest, ok := strings.CutPrefix(m, old); ok {
|
|
return now + rest
|
|
}
|
|
return m
|
|
})
|
|
}
|
|
moved := false
|
|
if err := edit.EditYAMLStrings(path, ompRefKeys, func(v string) string {
|
|
nv := move(v)
|
|
moved = moved || nv != v
|
|
return nv
|
|
}); err != nil {
|
|
return moved, err
|
|
}
|
|
for _, w := range was {
|
|
s := stashLoad()[w]
|
|
ns := move(s)
|
|
if ompYAMLList(s) {
|
|
t, err := edit.EditYAMLTextStrings(edit.YAMLText(s), move)
|
|
if err != nil {
|
|
return moved, err
|
|
}
|
|
ns = string(t)
|
|
}
|
|
if ns != s {
|
|
stash(map[string]string{w: ns})
|
|
}
|
|
}
|
|
return moved, nil
|
|
},
|
|
Notice: func() string {
|
|
if Running(`(^|/)omp( |$)`, `@oh-my-pi/pi-coding-agent`) {
|
|
return "omp reads its settings at start-up — restart open omp sessions to use this."
|
|
}
|
|
return ""
|
|
},
|
|
Check: func() string {
|
|
// whatever keeps magpie's provider in models.yml has its wiring
|
|
// checked, a fallback chain alone as much as a role
|
|
if used, _ := onMagpie(); !used {
|
|
return ""
|
|
}
|
|
models := pick("models")
|
|
return wiringOff("omp", models, func(k string) (string, bool) { return edit.GetYAML(models, "providers."+magpieID+"."+k) },
|
|
"baseUrl", gatewayV1())
|
|
},
|
|
Fields: []Field{
|
|
role("model", "model", "default", false),
|
|
// omp's own agents run on its roles (src/task/agents.ts,
|
|
// prompts/agents): task on @task; scout and sonic on @smol;
|
|
// reviewer on @slow, also the eval tool's "slow" tier. Unset,
|
|
// task gives its agent the parent session's model, and smol
|
|
// and slow take the default role's (model-resolver.ts,
|
|
// shouldInheritDefaultBeforePriority). The designer role went
|
|
// in omp 18.1.5. smol is labelled as omp names it: "small" is
|
|
// other agents' picker of its own
|
|
role("subagent", "subagents", "task", true),
|
|
role("small", "smol", "smol", true),
|
|
role("slow", "slow", "slow", true),
|
|
{
|
|
// the thinking level sessions start with, as omp's settings save
|
|
// it; unset omp takes high. auto has omp pick a level each turn:
|
|
// not a level a model lists, so it is offered here and kept out of
|
|
// ompEfforts, which a model's thinking levels are filtered by. First,
|
|
// as omp's own picker has it (16.3.5 and 18.4.4 alike)
|
|
Key: "effort", Label: "thinking",
|
|
Get: func() string { v, _ := edit.GetYAML(path, "defaultThinkingLevel"); return v },
|
|
Set: func(v string) error {
|
|
if v == "" {
|
|
return edit.DelYAML(path, "defaultThinkingLevel")
|
|
}
|
|
return edit.SetYAML(path, edit.KV{Path: "defaultThinkingLevel", Value: v})
|
|
},
|
|
Options: func(map[string]string) []Option { return static(append([]string{"auto"}, ompEfforts...)...) },
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
type ompModel struct {
|
|
ID string `yaml:"id"`
|
|
Name string `yaml:"name,omitempty"`
|
|
API string `yaml:"api,omitempty"`
|
|
BaseURL string `yaml:"baseUrl,omitempty"`
|
|
Reasoning bool `yaml:"reasoning"`
|
|
Thinking *ompThinking `yaml:"thinking,omitempty"`
|
|
Context int `yaml:"contextWindow,omitempty"`
|
|
MaxTokens int `yaml:"maxTokens,omitempty"`
|
|
Input []string `yaml:"input,omitempty"`
|
|
}
|
|
|
|
type ompThinking struct {
|
|
Mode string `yaml:"mode"`
|
|
Efforts []string `yaml:"efforts"`
|
|
}
|
|
|
|
type ompProviderEntry struct {
|
|
BaseURL string `yaml:"baseUrl"`
|
|
API string `yaml:"api"`
|
|
Auth string `yaml:"auth"`
|
|
// Headers name omp to the gateway: omp 16.x asks with Bun's User-Agent
|
|
// and only a later one with its own (omp/18.4.4), so its requests went
|
|
// to "Bun" in usage and past omp's own rules and stand-ins
|
|
Headers map[string]string `yaml:"headers,omitempty"`
|
|
Models []ompModel `yaml:"models"`
|
|
}
|
|
|
|
// ompProvider is magpie's entry in models.yml. The thinking efforts are the
|
|
// levels omp offers for the model; on Chat it sends them as
|
|
// reasoning_effort.
|
|
//
|
|
// As for Pi, each model is asked on the API its provider speaks natively, so
|
|
// the gateway relays what omp sent as it is instead of translating Chat: a
|
|
// Claude over Chat lost its thinking's signatures between tool turns, as
|
|
// Chat has no place for them. One served on OpenAI's Responses API goes to
|
|
// baseUrl/responses; one on Anthropic's Messages API to the gateway's
|
|
// /v1/messages (omp adds the /v1). That one thinks adaptively when it takes
|
|
// nothing else, else on a budget: omp's anthropic-budget-effort would also
|
|
// send output_config.effort, which Sonnet 4.5 and Haiku 4.5 refuse.
|
|
func ompProvider() ompProviderEntry {
|
|
ms := []ompModel{}
|
|
for _, m := range magpieModels("omp") {
|
|
e := ompModel{ID: m.ID, Name: m.Name, Context: m.Context, MaxTokens: maxTokens(m)}
|
|
mode := "effort"
|
|
switch {
|
|
case slices.Contains(m.APIs, string(provider.Responses)):
|
|
e.API = "openai-responses"
|
|
case slices.Contains(m.APIs, string(provider.Anthropic)):
|
|
e.API, e.BaseURL = "anthropic-messages", gateway.URL()
|
|
mode = "budget"
|
|
if gateway.AdaptiveThinking(m.ID) {
|
|
mode = "anthropic-adaptive"
|
|
}
|
|
}
|
|
// Without input omp takes it from a bundled model its fuzzy id match
|
|
// finds, else text only; a model the source never answered for is
|
|
// left to that guess.
|
|
switch {
|
|
case m.Images:
|
|
e.Input = []string{"text", "image"}
|
|
case m.ImageInput != nil:
|
|
e.Input = []string{"text"}
|
|
}
|
|
var efforts []string
|
|
for _, x := range ompEfforts { // in omp's order
|
|
// a model's efforts stop at xhigh (omp 16.3.5 turns the whole
|
|
// file away over a max): a model whose top is max offers xhigh,
|
|
// which the gateway fits to max
|
|
if x == "xhigh" && slices.Contains(m.Efforts, "max") || x != "max" && slices.Contains(m.Efforts, x) {
|
|
efforts = append(efforts, x)
|
|
}
|
|
}
|
|
if len(efforts) > 0 {
|
|
e.Reasoning = true
|
|
e.Thinking = &ompThinking{Mode: mode, Efforts: efforts}
|
|
}
|
|
ms = append(ms, e)
|
|
}
|
|
return ompProviderEntry{BaseURL: gatewayV1(), API: "openai-completions", Auth: "none",
|
|
Headers: map[string]string{"User-Agent": "omp"}, Models: ms}
|
|
}
|