Files
plugins/packages/factory/models.test.mjs
T
yetone 2170a3781e factory 0.1.27: droid's Fast Mode models, and fast asked of their base model goes to them (#119)
psylch on #119 (plugin 0.1.26): claude-opus-5-5-fast answered "Factory:
Not found.", and Opus 5.5 asked with speed "fast" was recorded as
tier_asked fast, tier_served standard, with nothing said.

The plugin now offers droid 0.240.0's Fast Mode models: Opus 5.5/5/4.8
Fast on Anthropic's API, GPT-5.5/5.4/5.3-Codex Fast on Responses, each
at its base model's limits and efforts. They go out as droid 0.240.0
sends them (read from its binary, saved in testdata/droid-0.240.0-fast.txt):
the Fast Mode id itself as the model, with speed "fast" and the
fast-mode-2026-02-01 beta for anthropicFastMode models, at service_tier
"priority" for the GPT ones (their apiRequest Ee). A request asking a base
model for fast (speed "fast" on Messages, service_tier "priority" on
Responses) is sent to its Fast Mode model, as droid's fast toggle
switches to it. A model with no Fast Mode model is sent as asked. Left
out: Opus 4.6/4.7 Fast and GPT-5.4 Mini Fast (base not offered), GPT-5.6
Sol Fast (unreleased:!0), GLM-5.2 Fast (feature flag, a Baseten id).

Run: the full bun test (1222 pass, 0 fail) with a sandbox HOME; the new
fast.test.mjs and the picker test fail on the old index.mjs (4 fail).
Not tried: a real Factory account (none signed in here), so whether
Factory serves the Fast Mode ids at fast speed to a plan, and what its
usage says about speed, is unverified. A non-stream request magpie
translates for a plugin account drops speed before the plugin sees it,
so there only the -fast ids reach fast.
2026-10-14 17:53:22 +08:00

112 lines
6.0 KiB
JavaScript

// JL on magpie's Discord (droid 0.240.0, plugin 0.1.24): droid and Factory
// desktop offer Haiku 5.5, droid through magpie didn't. The cases are droid
// 0.240.0's own registry entries, saved byte for byte in testdata.
import { expect, test } from "bun:test"
import { readFileSync } from "node:fs"
import { FactoryAuthPlugin } from "./index.mjs"
const DROID = readFileSync(new URL("./testdata/droid-0.240.0-models.txt", import.meta.url), "utf8")
// entry is a model's registry text in the fixture.
function entry(id) {
const line = DROID.split("\n").find((l) => l.startsWith(`"${id}":{id:"${id}",`))
if (!line) throw new Error(`${id} is not in the fixture`)
return line
}
// limits reads an entry's context and output as the plugin states them: a
// total context for P(context, output), the input for R({…}) and te({…}).
function limits(text) {
let m = text.match(/contextLimits:P\((\d+),(\d+)\)/)
if (m) return { context: +m[1], output: +m[2] }
m = text.match(/contextLimits:R\(\{maxInputTokens:(\d+),maxOutputTokens:(\d+)\}\)/)
if (m) return { context: +m[1], output: +m[2] }
m = text.match(/contextLimits:(\w+),/)
const def = DROID.match(new RegExp(`^${m[1]}=te\\(\\{[^}]*maxInputTokens:(\\d+),maxOutputTokens:(\\d+)\\}\\)`, "m"))
return { context: +def[1], output: +def[2] }
}
async function models() {
const hooks = await FactoryAuthPlugin({ client: { auth: { set: async () => {} } } })
const cfg = { provider: {} }
await hooks.config(cfg)
return cfg.provider.factory.models
}
test("Haiku 5.5 and Mistral Large 4 are offered as droid 0.240.0 has them", async () => {
const got = await models()
for (const id of ["claude-haiku-5-5", "mistral-large-4"]) {
const text = entry(id)
const m = got[id]
expect(m).toBeDefined()
expect(m.name).toBe(text.match(/,name:"([^"]+)"/)[1])
expect(m.limit).toEqual(limits(text))
// droid's "off" is the request without a level; the rest are variants
const efforts = JSON.parse(text.match(/reasoningEffort:\{supported:(\[[^\]]*\])/)[1]).filter((e) => e !== "off")
expect(Object.keys(m.variants)).toEqual(efforts)
}
expect(got["claude-haiku-5-5"].provider.npm).toBe("@ai-sdk/anthropic")
expect(got["claude-haiku-5-5"].provider.api).toBe("https://api.factory.ai/api/llm/a/v1")
expect(got["claude-haiku-5-5"].variants.medium).toEqual({ effort: "medium" })
// Mistral Large 4 is on droid's generic chat completions, images on
expect(entry("mistral-large-4")).toContain('apiModelProvider:"generic-chat-completion-api"')
expect(entry("mistral-large-4")).toContain("images:!0")
expect(got["mistral-large-4"].provider.npm).toBe("@ai-sdk/openai-compatible")
expect(got["mistral-large-4"].attachment).toBe(true)
})
test("every model in droid 0.240.0's picker is offered, or left out for a reason", async () => {
const got = await models()
const picker = JSON.parse(DROID.match(/^var y=(\[[^\]]*\]);/m)[1])
const reason = {
// droid picks these itself, client side
auto: "router", "auto-fast": "router",
// not released (unreleased:!0) or not in the registry
"garnet-07-15": "unreleased", "atlas-07-21": "unreleased", "aster-07-15": "unreleased", inkling: "unreleased",
// asks the user to accept Factory's high-cost terms first
"gpt-6-astra-ultrafast": "opt-in",
// older generations the plugin has never offered, as before
"claude-opus-4-7": "older", "claude-opus-4-6": "older", "claude-opus-4-5-20251101": "older",
"claude-sonnet-4-5-20250929": "older", "gpt-5.5-pro": "older", "gpt-5.4-mini": "older", "gpt-5.2": "older",
"gpt-5.2-codex": "older", "gpt-5.1-codex-max": "older", "grok-4.5": "older", "kimi-k2.5": "older",
"glm-5.1": "older", "glm-5": "older", "glm-4.7": "older",
"deepseek-v4-flash-0731": "older", "deepseek-v4-pro": "older",
// Fast Mode models whose base model isn't offered, unreleased, or
// behind a feature flag (fast.test.mjs)
"claude-opus-4-7-fast": "older", "claude-opus-4-6-fast": "older", "gpt-5.4-mini-fast": "older",
"gpt-5.6-sol-fast": "unreleased", "glm-5.2-fast": "flag",
}
const missing = picker.filter((id) => !got[id] && !reason[id])
expect(missing).toEqual([])
expect(entry("gpt-6-astra-ultrafast")).toContain('explicitOptInRequirement:{kind:"high_cost"')
expect(got["gpt-6-astra-ultrafast"]).toBeUndefined()
})
// yetone/magpie#2080: droid 0.241.1 offers Gemini 4 Argon; the plugin
// offered no Gemini at all. The cases are droid 0.241.1's entries.
const DROID_241 = readFileSync(new URL("./testdata/droid-0.241.1-gemini.txt", import.meta.url), "utf8")
test("droid 0.241.1's Gemini models are offered on Factory's Gemini route, as droid has them", async () => {
const got = await models()
const picker = JSON.parse(DROID_241.match(/^var y=(\[[^\]]*\]);/m)[1])
const gemini = picker.filter((id) => id.startsWith("gemini-"))
expect(gemini).toEqual(["gemini-4-argon", "gemini-3.1-pro-preview", "gemini-3.8-flash", "gemini-3.7-flash", "gemini-3.6-flash", "gemini-3.5-flash", "gemini-3-flash-preview"])
// I(total, output) states the total context, as P does in 0.240.0
expect(DROID_241).toContain("function I(o,t){return O({maxInputTokens:o-t,maxOutputTokens:t})}")
for (const id of gemini) {
const text = DROID_241.split("\n").find((l) => l.startsWith(`"${id}":{id:"${id}",`))
const m = got[id]
expect(m).toBeDefined()
expect(text).toContain('provider:"google"')
expect(m.name).toBe(text.match(/,name:"([^"]+)"/)[1])
const [, context, output] = text.match(/contextLimits:[Ik]\((\d+e\d+|\d+),(\d+)\)/)
expect(m.limit).toEqual({ context: Number(context), output: Number(output) })
expect(Object.keys(m.variants)).toEqual(JSON.parse(text.match(/reasoningEffort:\{supported:(\[[^\]]*\])/)[1]))
// droid takes images unless an entry says images:!1
expect(text).not.toContain("images:!1")
expect(m.attachment).toBe(true)
expect(m.provider).toEqual({ npm: "@ai-sdk/google", api: "https://api.factory.ai/api/llm/g/v1" })
}
expect(got["gemini-4-argon"].variants.high).toEqual({ thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } })
})