@magpie-community/opencode-factory-auth 0.1.44 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/index.mjs +38 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,6 +59,16 @@ see [Claude Code through magpie](#claude-code-through-magpie) below.
|
|
|
59
59
|
|
|
60
60
|
## Models
|
|
61
61
|
|
|
62
|
+
In magpie's Factory plugin options, enable **Group models by company** to
|
|
63
|
+
list Anthropic's Fable, Opus, Sonnet and Haiku families together, followed
|
|
64
|
+
by OpenAI, Google and the other model makers. Versions within each family
|
|
65
|
+
sort newest first; Fast Mode follows its base model. This groups by model
|
|
66
|
+
maker, not the API hosting company. Refresh the model list after changing
|
|
67
|
+
the option. It is off by default, preserving the existing order and default
|
|
68
|
+
first 24 models; enabling it also changes which models occupy those slots.
|
|
69
|
+
Names with the same version sort in descending natural name order, for
|
|
70
|
+
example GPT-5.6 Terra before Sol and GLM-5.3-Flash before GLM-5.3.
|
|
71
|
+
|
|
62
72
|
Each model is served on the one API droid uses for it:
|
|
63
73
|
|
|
64
74
|
| API | Models |
|
package/index.mjs
CHANGED
|
@@ -137,6 +137,28 @@ const MODELS = [
|
|
|
137
137
|
["glm-5.2-fast", "GLM-5.2 Fast", CHAT, "baseten", 524288, 131072, ["none", "high", "max"], false, 0.84],
|
|
138
138
|
].map(([id, name, wire, upstream, context, output, efforts, images, rate]) => ({ id, name, wire, upstream, context, output, efforts, images, rate }))
|
|
139
139
|
|
|
140
|
+
// Model makers, not API hosts: e.g. GLM and Kimi both use Fireworks.
|
|
141
|
+
const MODEL_FAMILIES = [
|
|
142
|
+
"claude-fable-", "claude-opus-", "claude-sonnet-", "claude-haiku-",
|
|
143
|
+
"gpt-", "gemini-", "grok-", "glm-", "kimi-", "deepseek-", "qwen",
|
|
144
|
+
"minimax-", "mistral-", "nemotron-", "muse-", "inkling", "beam-",
|
|
145
|
+
]
|
|
146
|
+
const MODEL_ORDER = "group_models_by_company"
|
|
147
|
+
function groupedModels(models) {
|
|
148
|
+
const family = (id) => {
|
|
149
|
+
const index = MODEL_FAMILIES.findIndex((prefix) => id.startsWith(prefix))
|
|
150
|
+
return index < 0 ? MODEL_FAMILIES.length : index
|
|
151
|
+
}
|
|
152
|
+
const base = (id) => id.replace(/-fast$/, "")
|
|
153
|
+
return Object.fromEntries(Object.entries(models).sort(([a], [b]) => {
|
|
154
|
+
const group = family(a) - family(b)
|
|
155
|
+
if (group) return group
|
|
156
|
+
const aa = base(a), bb = base(b)
|
|
157
|
+
if (aa === bb) return Number(a.endsWith("-fast")) - Number(b.endsWith("-fast"))
|
|
158
|
+
return bb.localeCompare(aa, "en", { numeric: true })
|
|
159
|
+
}))
|
|
160
|
+
}
|
|
161
|
+
|
|
140
162
|
const byId = new Map(MODELS.map((m) => [m.id, m]))
|
|
141
163
|
|
|
142
164
|
// A Fast Mode model is its base model served faster for more credits.
|
|
@@ -1782,6 +1804,14 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
|
|
1782
1804
|
return false
|
|
1783
1805
|
}
|
|
1784
1806
|
}
|
|
1807
|
+
const orderModels = (models) => {
|
|
1808
|
+
try {
|
|
1809
|
+
if (magpie?.option?.(PROVIDER, MODEL_ORDER) === true) return groupedModels(models)
|
|
1810
|
+
} catch {
|
|
1811
|
+
// Hosts without plugin options keep the existing picker order.
|
|
1812
|
+
}
|
|
1813
|
+
return models
|
|
1814
|
+
}
|
|
1785
1815
|
// the session id this process's requests carry
|
|
1786
1816
|
const session = crypto.randomUUID()
|
|
1787
1817
|
// serializes checking, rotating and saving tokens: WorkOS rotates the
|
|
@@ -2004,7 +2034,7 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
|
|
2004
2034
|
provider: {
|
|
2005
2035
|
id: PROVIDER,
|
|
2006
2036
|
async models(provider) {
|
|
2007
|
-
return providerModels(provider)
|
|
2037
|
+
return orderModels(providerModels(provider))
|
|
2008
2038
|
},
|
|
2009
2039
|
},
|
|
2010
2040
|
config: async (config) => {
|
|
@@ -2015,7 +2045,7 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
|
|
2015
2045
|
npm: CHAT.npm,
|
|
2016
2046
|
api: CHAT.api,
|
|
2017
2047
|
...was,
|
|
2018
|
-
models: { ...configModels(), ...(was.models ?? {}) },
|
|
2048
|
+
models: orderModels({ ...configModels(), ...(was.models ?? {}) }),
|
|
2019
2049
|
}
|
|
2020
2050
|
},
|
|
2021
2051
|
auth: {
|
|
@@ -2032,6 +2062,11 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
|
|
2032
2062
|
// magpie's own switches (input.magpie.option), read at each usage
|
|
2033
2063
|
// reading
|
|
2034
2064
|
options: [
|
|
2065
|
+
{
|
|
2066
|
+
key: MODEL_ORDER,
|
|
2067
|
+
label: "Group models by company",
|
|
2068
|
+
description: "Groups models by maker: Anthropic, OpenAI, Google, then others. Newer versions come first within each family, with Fast Mode beside its base model. Off preserves the default order and first 24 models. Refresh the model list after changing this option.",
|
|
2069
|
+
},
|
|
2035
2070
|
{
|
|
2036
2071
|
key: STANDARD_ONLY,
|
|
2037
2072
|
label: "Standard usage only",
|
|
@@ -2045,6 +2080,7 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
|
|
2045
2080
|
// spend one refresh token; that check stays for OpenCode, which
|
|
2046
2081
|
// doesn't call this
|
|
2047
2082
|
refreshLead: MAGPIE_LEAD,
|
|
2083
|
+
rotating: true,
|
|
2048
2084
|
async refresh(auth) {
|
|
2049
2085
|
if (auth?.type !== "oauth" || !auth.access || !auth.refresh) return undefined
|
|
2050
2086
|
return locked(async () => {
|