@magpie-community/opencode-factory-auth 0.1.26 → 0.1.28
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 +12 -2
- package/index.mjs +65 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,8 +63,8 @@ Each model is served on the one API droid uses for it:
|
|
|
63
63
|
|
|
64
64
|
| API | Models |
|
|
65
65
|
|---|---|
|
|
66
|
-
| Anthropic Messages (`/api/llm/a`) | Fable 5.1, Fable 5, Opus 5.5, Opus 5, Opus 4.8, Sonnet 5.5, Sonnet 5, Sonnet 4.6, Haiku 5.5, Haiku 4.5, MiniMax M2.7 |
|
|
67
|
-
| OpenAI Responses (`/api/llm/o/v1`) | GPT-6.1 Sol, GPT-6 Sol/Astra/Luna, GPT-5.6 Sol/Terra/Luna, GPT-5.5, GPT-5.4, GPT-5.3-Codex, Grok 4.7, Grok 4.6 |
|
|
66
|
+
| Anthropic Messages (`/api/llm/a`) | Fable 5.1, Fable 5, Opus 5.5, Opus 5, Opus 4.8 (each also in Fast Mode), Sonnet 5.5, Sonnet 5, Sonnet 4.6, Haiku 5.5, Haiku 4.5, MiniMax M2.7 |
|
|
67
|
+
| OpenAI Responses (`/api/llm/o/v1`) | GPT-6.1 Sol, GPT-6 Sol/Astra/Luna, GPT-5.6 Sol/Terra/Luna, GPT-5.5, GPT-5.4, GPT-5.3-Codex (each also in Fast Mode), Grok 4.7, Grok 4.6 |
|
|
68
68
|
| Chat completions (`/api/llm/o/v1`) | GLM-5.3, GLM-5.3-Flash, GLM-5.2, Kimi K3, DeepSeek V4.1 Flash, Qwen3.8 Max, MiniMax M3, Mistral Large 4, Mistral Medium 3.5, Nemotron 3 Ultra |
|
|
69
69
|
| Gemini generate (`/api/llm/g/v1/generate`) | Gemini 4 Argon, Gemini 3.1 Pro, Gemini 3.8/3.7/3.6/3.5 Flash, Gemini 3 Flash |
|
|
70
70
|
|
|
@@ -78,6 +78,16 @@ body, droid's line opening the system instruction. Gemini 4 Argon is behind
|
|
|
78
78
|
a Factory feature flag in droid 0.241.1, so an account it isn't on for may
|
|
79
79
|
be refused it.
|
|
80
80
|
|
|
81
|
+
A Fast Mode model (`claude-opus-5-5-fast`, `gpt-5.5-fast`, …) is its base
|
|
82
|
+
model served faster, for more of the plan's credits. It goes out as droid
|
|
83
|
+
sends it: its own id, with `speed: "fast"` and the `fast-mode-2026-02-01`
|
|
84
|
+
beta on Anthropic's API, at `service_tier: "priority"` on OpenAI's. A request
|
|
85
|
+
that asks the base model for fast (Claude Code's `speed: "fast"`, a
|
|
86
|
+
Responses request's `service_tier: "priority"`) is sent to its Fast Mode
|
|
87
|
+
model, as droid's own fast toggle does: asked of the base model, Factory
|
|
88
|
+
answered at standard speed (#119). Opus 4.6/4.7 Fast, GPT-5.4 Mini Fast, GPT-5.6 Sol Fast (unreleased)
|
|
89
|
+
and GLM-5.2 Fast (behind a feature flag) are not included.
|
|
90
|
+
|
|
81
91
|
auto is not included: droid picks it on the client side.
|
|
82
92
|
|
|
83
93
|
## Requests too large
|
package/index.mjs
CHANGED
|
@@ -45,7 +45,11 @@ const E4 = ["low", "medium", "high", "xhigh"]
|
|
|
45
45
|
// (explicitOptInRequirement). Gemini's are droid 0.241.1's, as magpie's
|
|
46
46
|
// built-in has them (yetone/magpie#2080); Gemini 4 Argon is behind a
|
|
47
47
|
// feature flag of Factory's there, so an account it isn't on for may be
|
|
48
|
-
// refused it.
|
|
48
|
+
// refused it. The Fast Mode models are droid 0.240.0's (fastBody; testdata/
|
|
49
|
+
// droid-0.240.0-fast.txt), at their base model's limits and efforts as
|
|
50
|
+
// droid has them. Left out: Opus 4.6/4.7 Fast and GPT-5.4 Mini Fast (their
|
|
51
|
+
// base models aren't offered), GPT-5.6 Sol Fast (unreleased:!0) and
|
|
52
|
+
// GLM-5.2 Fast (behind a feature flag, on a Baseten model id of its own).
|
|
49
53
|
const MODELS = [
|
|
50
54
|
["claude-fable-5.1", "Fable 5.1", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
51
55
|
["claude-fable-5", "Fable 5", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
@@ -90,10 +94,62 @@ const MODELS = [
|
|
|
90
94
|
["gemini-3.6-flash", "Gemini 3.6 Flash", GEMINI, "google", 1000000, 65536, ["low", "medium", "high"], true],
|
|
91
95
|
["gemini-3.5-flash", "Gemini 3.5 Flash", GEMINI, "google", 1000000, 65536, ["minimal", "low", "medium", "high"], true],
|
|
92
96
|
["gemini-3-flash-preview", "Gemini 3 Flash", GEMINI, "google", 1000000, 65536, ["minimal", "low", "medium", "high"], true],
|
|
97
|
+
// The Fast Mode models come last: magpie shows a provider with no models
|
|
98
|
+
// picked only the first 24 of its list, and placed beside their base
|
|
99
|
+
// models in 0.1.27 they pushed GPT-5.3-Codex, Grok 4.7, Grok 4.6, GLM-5.3
|
|
100
|
+
// and GLM-5.3-Flash out of it (#119, psylch). A Fast Mode model costs more credits, so it is the one
|
|
101
|
+
// to pick; asking its base model for fast reaches it all the same
|
|
102
|
+
// (fastBody).
|
|
103
|
+
["claude-opus-5-5-fast", "Opus 5.5 Fast Mode", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
|
|
104
|
+
["claude-opus-5-fast", "Opus 5 Fast Mode", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
105
|
+
["claude-opus-4-8-fast", "Opus 4.8 Fast Mode", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
106
|
+
["gpt-5.5-fast", "GPT-5.5 Fast Mode", RESPONSES, "openai", 1050000, 128000, E4, true],
|
|
107
|
+
["gpt-5.4-fast", "GPT-5.4 Fast Mode", RESPONSES, "openai", 1050000, 128000, E4, true],
|
|
108
|
+
["gpt-5.3-codex-fast", "GPT-5.3-Codex Fast Mode", RESPONSES, "openai", 400000, 128000, E4, true],
|
|
93
109
|
].map(([id, name, wire, upstream, context, output, efforts, images]) => ({ id, name, wire, upstream, context, output, efforts, images }))
|
|
94
110
|
|
|
95
111
|
const byId = new Map(MODELS.map((m) => [m.id, m]))
|
|
96
112
|
|
|
113
|
+
// A Fast Mode model is its base model served faster for more credits.
|
|
114
|
+
// droid sends the Fast Mode id itself as the model; on Anthropic's wire with
|
|
115
|
+
// speed "fast" and the fast-mode beta (anthropicFastMode), on OpenAI's with
|
|
116
|
+
// service_tier "priority" (its apiRequest). FAST_OF is a base model's Fast
|
|
117
|
+
// Mode id.
|
|
118
|
+
const FAST_BETA = "fast-mode-2026-02-01"
|
|
119
|
+
const FAST_OF = new Map(MODELS.filter((m) => m.id.endsWith("-fast")).map((m) => [m.id.slice(0, -"-fast".length), m.id]))
|
|
120
|
+
|
|
121
|
+
// fastBody sends a Fast Mode model as droid does. A request that asks its
|
|
122
|
+
// base model for fast (Claude Code's speed "fast", or service_tier
|
|
123
|
+
// "priority" on Responses) goes to the base model's Fast Mode model, as
|
|
124
|
+
// droid's own fast toggle switches to it: asked of the base model, Factory
|
|
125
|
+
// answered at standard speed, fast asked and standard served with nothing
|
|
126
|
+
// said (#119). Beta is
|
|
127
|
+
// whether the request needs the fast-mode beta.
|
|
128
|
+
function fastBody(path, body) {
|
|
129
|
+
const anthropic = path.includes("/llm/a/") && path.endsWith("/messages")
|
|
130
|
+
const responses = path.includes("/llm/o/") && path.endsWith("/responses")
|
|
131
|
+
if (!anthropic && !responses) return { body, beta: false }
|
|
132
|
+
const text = bodyText(body)
|
|
133
|
+
if (text == null) return { body, beta: false }
|
|
134
|
+
let m
|
|
135
|
+
try {
|
|
136
|
+
m = JSON.parse(text)
|
|
137
|
+
} catch {
|
|
138
|
+
return { body, beta: false }
|
|
139
|
+
}
|
|
140
|
+
if (!m || typeof m !== "object" || Array.isArray(m) || typeof m.model !== "string") return { body, beta: false }
|
|
141
|
+
const asked = anthropic ? m.speed === "fast" : m.service_tier === "priority"
|
|
142
|
+
const model = asked && FAST_OF.has(m.model) ? FAST_OF.get(m.model) : m.model
|
|
143
|
+
const fast = byId.get(model)
|
|
144
|
+
if (!fast || !model.endsWith("-fast") || fast.wire !== (anthropic ? ANTHROPIC : RESPONSES)) return { body, beta: false }
|
|
145
|
+
if (anthropic && model === m.model && m.speed === "fast") return { body, beta: true }
|
|
146
|
+
if (responses && model === m.model && m.service_tier === "priority") return { body, beta: false }
|
|
147
|
+
m.model = model
|
|
148
|
+
if (anthropic) m.speed = "fast"
|
|
149
|
+
else m.service_tier = "priority"
|
|
150
|
+
return { body: JSON.stringify(m), beta: anthropic }
|
|
151
|
+
}
|
|
152
|
+
|
|
97
153
|
// variant is what the AI SDK package a model is on is given for an effort.
|
|
98
154
|
function variant(npm, effort) {
|
|
99
155
|
if (npm === ANTHROPIC.npm) return { effort }
|
|
@@ -1595,8 +1651,14 @@ export const FactoryAuthPlugin = async ({ client }) => {
|
|
|
1595
1651
|
// the AI SDK's Google package's, with OpenCode's placeholder key
|
|
1596
1652
|
h.delete("x-goog-api-key")
|
|
1597
1653
|
factoryHeaders(h, c)
|
|
1598
|
-
const model = byId.get(bodyModel(body))
|
|
1599
1654
|
const path = new URL(url).pathname
|
|
1655
|
+
const sped = fastBody(path, body)
|
|
1656
|
+
body = sped.body
|
|
1657
|
+
if (sped.beta) {
|
|
1658
|
+
const betas = (h.get("anthropic-beta") ?? "").split(",").map((b) => b.trim()).filter(Boolean)
|
|
1659
|
+
if (!betas.includes(FAST_BETA)) h.set("anthropic-beta", [...betas, FAST_BETA].join(","))
|
|
1660
|
+
}
|
|
1661
|
+
const model = byId.get(bodyModel(body))
|
|
1600
1662
|
const upstream = model ? model.upstream : path.includes("/llm/o/") ? "openai" : "anthropic"
|
|
1601
1663
|
h.set("x-api-provider", upstream)
|
|
1602
1664
|
h.set("x-session-id", session)
|
|
@@ -1672,4 +1734,4 @@ export const FactoryAuthPlugin = async ({ client }) => {
|
|
|
1672
1734
|
}
|
|
1673
1735
|
|
|
1674
1736
|
// for tests
|
|
1675
|
-
export const _internal = { limitWindows, windowEnd, dollars, vendorError, CORE, droidBody, DROID_LINE, geminiBody, leaveOutAttachments, LEFT_OUT, TOO_LARGE_HINT }
|
|
1737
|
+
export const _internal = { fastBody, FAST_BETA, limitWindows, windowEnd, dollars, vendorError, CORE, droidBody, DROID_LINE, geminiBody, leaveOutAttachments, LEFT_OUT, TOO_LARGE_HINT }
|