@magpie-community/opencode-factory-auth 0.1.26 → 0.1.27
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 +59 -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,13 +45,20 @@ 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],
|
|
52
56
|
["claude-opus-5-5", "Opus 5.5", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
|
|
57
|
+
["claude-opus-5-5-fast", "Opus 5.5 Fast Mode", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
|
|
53
58
|
["claude-opus-5", "Opus 5", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
59
|
+
["claude-opus-5-fast", "Opus 5 Fast Mode", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
54
60
|
["claude-opus-4-8", "Opus 4.8", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
61
|
+
["claude-opus-4-8-fast", "Opus 4.8 Fast Mode", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
55
62
|
["claude-sonnet-5-5", "Sonnet 5.5", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
|
|
56
63
|
["claude-sonnet-5", "Sonnet 5", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
|
|
57
64
|
["claude-sonnet-4-6", "Sonnet 4.6", ANTHROPIC, "anthropic", 931000, 64000, ["low", "medium", "high", "max"], true],
|
|
@@ -65,8 +72,11 @@ const MODELS = [
|
|
|
65
72
|
["gpt-5.6-terra", "GPT-5.6 Terra", RESPONSES, "openai", 1050000, 128000, E6, true],
|
|
66
73
|
["gpt-5.6-luna", "GPT-5.6 Luna", RESPONSES, "openai", 1050000, 128000, E6, true],
|
|
67
74
|
["gpt-5.5", "GPT-5.5", RESPONSES, "openai", 1050000, 128000, E4, true],
|
|
75
|
+
["gpt-5.5-fast", "GPT-5.5 Fast Mode", RESPONSES, "openai", 1050000, 128000, E4, true],
|
|
68
76
|
["gpt-5.4", "GPT-5.4", RESPONSES, "openai", 1050000, 128000, E4, true],
|
|
77
|
+
["gpt-5.4-fast", "GPT-5.4 Fast Mode", RESPONSES, "openai", 1050000, 128000, E4, true],
|
|
69
78
|
["gpt-5.3-codex", "GPT-5.3-Codex", RESPONSES, "openai", 400000, 128000, E4, true],
|
|
79
|
+
["gpt-5.3-codex-fast", "GPT-5.3-Codex Fast Mode", RESPONSES, "openai", 400000, 128000, E4, true],
|
|
70
80
|
["grok-4.7", "Grok 4.7", RESPONSES, "xai", 500000, 63356, E4, true],
|
|
71
81
|
["grok-4.6", "Grok 4.6", RESPONSES, "xai", 200000, 63356, E4, true],
|
|
72
82
|
// reasoning is mandatory on GLM-5.3 and GLM-5.3-Flash (Fireworks turns
|
|
@@ -94,6 +104,46 @@ const MODELS = [
|
|
|
94
104
|
|
|
95
105
|
const byId = new Map(MODELS.map((m) => [m.id, m]))
|
|
96
106
|
|
|
107
|
+
// A Fast Mode model is its base model served faster for more credits.
|
|
108
|
+
// droid sends the Fast Mode id itself as the model; on Anthropic's wire with
|
|
109
|
+
// speed "fast" and the fast-mode beta (anthropicFastMode), on OpenAI's with
|
|
110
|
+
// service_tier "priority" (its apiRequest). FAST_OF is a base model's Fast
|
|
111
|
+
// Mode id.
|
|
112
|
+
const FAST_BETA = "fast-mode-2026-02-01"
|
|
113
|
+
const FAST_OF = new Map(MODELS.filter((m) => m.id.endsWith("-fast")).map((m) => [m.id.slice(0, -"-fast".length), m.id]))
|
|
114
|
+
|
|
115
|
+
// fastBody sends a Fast Mode model as droid does. A request that asks its
|
|
116
|
+
// base model for fast (Claude Code's speed "fast", or service_tier
|
|
117
|
+
// "priority" on Responses) goes to the base model's Fast Mode model, as
|
|
118
|
+
// droid's own fast toggle switches to it: asked of the base model, Factory
|
|
119
|
+
// answered at standard speed, fast asked and standard served with nothing
|
|
120
|
+
// said (#119). Beta is
|
|
121
|
+
// whether the request needs the fast-mode beta.
|
|
122
|
+
function fastBody(path, body) {
|
|
123
|
+
const anthropic = path.includes("/llm/a/") && path.endsWith("/messages")
|
|
124
|
+
const responses = path.includes("/llm/o/") && path.endsWith("/responses")
|
|
125
|
+
if (!anthropic && !responses) return { body, beta: false }
|
|
126
|
+
const text = bodyText(body)
|
|
127
|
+
if (text == null) return { body, beta: false }
|
|
128
|
+
let m
|
|
129
|
+
try {
|
|
130
|
+
m = JSON.parse(text)
|
|
131
|
+
} catch {
|
|
132
|
+
return { body, beta: false }
|
|
133
|
+
}
|
|
134
|
+
if (!m || typeof m !== "object" || Array.isArray(m) || typeof m.model !== "string") return { body, beta: false }
|
|
135
|
+
const asked = anthropic ? m.speed === "fast" : m.service_tier === "priority"
|
|
136
|
+
const model = asked && FAST_OF.has(m.model) ? FAST_OF.get(m.model) : m.model
|
|
137
|
+
const fast = byId.get(model)
|
|
138
|
+
if (!fast || !model.endsWith("-fast") || fast.wire !== (anthropic ? ANTHROPIC : RESPONSES)) return { body, beta: false }
|
|
139
|
+
if (anthropic && model === m.model && m.speed === "fast") return { body, beta: true }
|
|
140
|
+
if (responses && model === m.model && m.service_tier === "priority") return { body, beta: false }
|
|
141
|
+
m.model = model
|
|
142
|
+
if (anthropic) m.speed = "fast"
|
|
143
|
+
else m.service_tier = "priority"
|
|
144
|
+
return { body: JSON.stringify(m), beta: anthropic }
|
|
145
|
+
}
|
|
146
|
+
|
|
97
147
|
// variant is what the AI SDK package a model is on is given for an effort.
|
|
98
148
|
function variant(npm, effort) {
|
|
99
149
|
if (npm === ANTHROPIC.npm) return { effort }
|
|
@@ -1595,8 +1645,14 @@ export const FactoryAuthPlugin = async ({ client }) => {
|
|
|
1595
1645
|
// the AI SDK's Google package's, with OpenCode's placeholder key
|
|
1596
1646
|
h.delete("x-goog-api-key")
|
|
1597
1647
|
factoryHeaders(h, c)
|
|
1598
|
-
const model = byId.get(bodyModel(body))
|
|
1599
1648
|
const path = new URL(url).pathname
|
|
1649
|
+
const sped = fastBody(path, body)
|
|
1650
|
+
body = sped.body
|
|
1651
|
+
if (sped.beta) {
|
|
1652
|
+
const betas = (h.get("anthropic-beta") ?? "").split(",").map((b) => b.trim()).filter(Boolean)
|
|
1653
|
+
if (!betas.includes(FAST_BETA)) h.set("anthropic-beta", [...betas, FAST_BETA].join(","))
|
|
1654
|
+
}
|
|
1655
|
+
const model = byId.get(bodyModel(body))
|
|
1600
1656
|
const upstream = model ? model.upstream : path.includes("/llm/o/") ? "openai" : "anthropic"
|
|
1601
1657
|
h.set("x-api-provider", upstream)
|
|
1602
1658
|
h.set("x-session-id", session)
|
|
@@ -1672,4 +1728,4 @@ export const FactoryAuthPlugin = async ({ client }) => {
|
|
|
1672
1728
|
}
|
|
1673
1729
|
|
|
1674
1730
|
// for tests
|
|
1675
|
-
export const _internal = { limitWindows, windowEnd, dollars, vendorError, CORE, droidBody, DROID_LINE, geminiBody, leaveOutAttachments, LEFT_OUT, TOO_LARGE_HINT }
|
|
1731
|
+
export const _internal = { fastBody, FAST_BETA, limitWindows, windowEnd, dollars, vendorError, CORE, droidBody, DROID_LINE, geminiBody, leaveOutAttachments, LEFT_OUT, TOO_LARGE_HINT }
|