@magpie-community/opencode-factory-auth 0.1.27 → 0.1.29
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/index.mjs +103 -58
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -54,11 +54,8 @@ const MODELS = [
|
|
|
54
54
|
["claude-fable-5.1", "Fable 5.1", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
55
55
|
["claude-fable-5", "Fable 5", ANTHROPIC, "anthropic", 867000, 128000, E5, true],
|
|
56
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],
|
|
58
57
|
["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],
|
|
60
58
|
["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],
|
|
62
59
|
["claude-sonnet-5-5", "Sonnet 5.5", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
|
|
63
60
|
["claude-sonnet-5", "Sonnet 5", ANTHROPIC, "anthropic", 872000, 128000, E5, true],
|
|
64
61
|
["claude-sonnet-4-6", "Sonnet 4.6", ANTHROPIC, "anthropic", 931000, 64000, ["low", "medium", "high", "max"], true],
|
|
@@ -72,11 +69,8 @@ const MODELS = [
|
|
|
72
69
|
["gpt-5.6-terra", "GPT-5.6 Terra", RESPONSES, "openai", 1050000, 128000, E6, true],
|
|
73
70
|
["gpt-5.6-luna", "GPT-5.6 Luna", RESPONSES, "openai", 1050000, 128000, E6, true],
|
|
74
71
|
["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],
|
|
76
72
|
["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],
|
|
78
73
|
["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],
|
|
80
74
|
["grok-4.7", "Grok 4.7", RESPONSES, "xai", 500000, 63356, E4, true],
|
|
81
75
|
["grok-4.6", "Grok 4.6", RESPONSES, "xai", 200000, 63356, E4, true],
|
|
82
76
|
// reasoning is mandatory on GLM-5.3 and GLM-5.3-Flash (Fireworks turns
|
|
@@ -100,6 +94,18 @@ const MODELS = [
|
|
|
100
94
|
["gemini-3.6-flash", "Gemini 3.6 Flash", GEMINI, "google", 1000000, 65536, ["low", "medium", "high"], true],
|
|
101
95
|
["gemini-3.5-flash", "Gemini 3.5 Flash", GEMINI, "google", 1000000, 65536, ["minimal", "low", "medium", "high"], true],
|
|
102
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],
|
|
103
109
|
].map(([id, name, wire, upstream, context, output, efforts, images]) => ({ id, name, wire, upstream, context, output, efforts, images }))
|
|
104
110
|
|
|
105
111
|
const byId = new Map(MODELS.map((m) => [m.id, m]))
|
|
@@ -376,27 +382,38 @@ function piSummary(text) {
|
|
|
376
382
|
return text
|
|
377
383
|
}
|
|
378
384
|
|
|
379
|
-
// promptOpenings adapts
|
|
380
|
-
//
|
|
381
|
-
//
|
|
382
|
-
//
|
|
383
|
-
|
|
385
|
+
// promptOpenings adapts the messages of msgs (chat completions' messages,
|
|
386
|
+
// Responses' input) as anthropicBody adapts a Messages request's: pi's
|
|
387
|
+
// opening and Claude Code's fixed phrases in the system and developer
|
|
388
|
+
// messages (the first of chat's as a system prompt, when prompt), pi's
|
|
389
|
+
// summary and Claude Code's reminders in user messages, and client phrases
|
|
390
|
+
// quoted in tool output (chat's tool messages, Responses'
|
|
391
|
+
// function_call_output). String content or text parts change, nothing else:
|
|
392
|
+
// false when nothing changed.
|
|
393
|
+
function promptOpenings(msgs, prompt = false) {
|
|
384
394
|
let changed = false
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
395
|
+
const list = Array.isArray(msgs) ? msgs : []
|
|
396
|
+
list.forEach((m, i) => {
|
|
397
|
+
if (!m || typeof m !== "object") return
|
|
398
|
+
let adapt, field = "content"
|
|
399
|
+
if (m.role === "system" || m.role === "developer") adapt = prompt && i === 0 && m.role === "system" ? promptText : systemMessageText
|
|
400
|
+
else if (m.role === "user") adapt = (t) => userText(piSummary(t))
|
|
401
|
+
else if (m.role === "tool") adapt = (t) => quotedToolText(t)
|
|
402
|
+
else if (m.type === "function_call_output") (adapt = (t) => quotedToolText(t)), (field = "output")
|
|
403
|
+
else return
|
|
404
|
+
const c = m[field]
|
|
405
|
+
if (typeof c === "string") {
|
|
406
|
+
const adapted = adapt(c)
|
|
407
|
+
if (adapted !== c) (m[field] = adapted), (changed = true)
|
|
408
|
+
} else if (Array.isArray(c)) {
|
|
409
|
+
for (const p of c) {
|
|
394
410
|
if (!p || typeof p !== "object" || typeof p.text !== "string") continue
|
|
395
|
-
|
|
411
|
+
// a part is a block of its own: no joined reminders to look into
|
|
412
|
+
const adapted = m.role === "user" ? userBlockText(piSummary(p.text)) : adapt(p.text)
|
|
396
413
|
if (adapted !== p.text) (p.text = adapted), (changed = true)
|
|
397
414
|
}
|
|
398
415
|
}
|
|
399
|
-
}
|
|
416
|
+
})
|
|
400
417
|
return changed
|
|
401
418
|
}
|
|
402
419
|
|
|
@@ -453,13 +470,13 @@ function droidBody(path, body) {
|
|
|
453
470
|
const v = m.instructions
|
|
454
471
|
if (v !== undefined && v !== null && typeof v !== "string") return body // not something droid sends
|
|
455
472
|
const opened = promptOpenings(m.input)
|
|
456
|
-
const ins =
|
|
473
|
+
const ins = promptText(v ?? "")
|
|
457
474
|
if (!ins.startsWith(DROID_LINE)) m.instructions = ins.trim() === "" ? DROID_LINE : DROID_LINE + "\n" + ins
|
|
458
475
|
else if (ins !== v || opened) m.instructions = ins
|
|
459
476
|
else return body
|
|
460
477
|
} else if (path.endsWith("/chat/completions")) {
|
|
461
478
|
if (!Array.isArray(m.messages)) return body
|
|
462
|
-
const opened = promptOpenings(m.messages)
|
|
479
|
+
const opened = promptOpenings(m.messages, true)
|
|
463
480
|
if (!droidChat(m.messages) && !opened) return body
|
|
464
481
|
} else return body
|
|
465
482
|
return JSON.stringify(m)
|
|
@@ -1185,6 +1202,62 @@ function quotedToolText(text, prefix = QUOTED_TOOL_PREFIX) {
|
|
|
1185
1202
|
return prefix + encoded
|
|
1186
1203
|
}
|
|
1187
1204
|
|
|
1205
|
+
// The adapters below are shared by both of Factory's routes. Claude Code's
|
|
1206
|
+
// request reaches /api/llm/a as Messages, but a model Factory serves on
|
|
1207
|
+
// /api/llm/o (GLM, Kimi and other chat models) gets it translated by magpie
|
|
1208
|
+
// into chat completions or Responses, carrying the same fixed phrases.
|
|
1209
|
+
// Factory refuses them there too (Echoo on magpie's Discord: GLM-5.3-Flash,
|
|
1210
|
+
// Claude Code 403 while Codex worked on the same account).
|
|
1211
|
+
|
|
1212
|
+
// claudeIdentity opens text with droid's line in place of Claude Code's
|
|
1213
|
+
// fixed first line, when text is that line alone or opens with it.
|
|
1214
|
+
function claudeIdentity(text) {
|
|
1215
|
+
const identity = [...CLAUDE_IDENTITIES].find((line) => text === line || text.startsWith(line + "\n"))
|
|
1216
|
+
return identity ? DROID_LINE + text.slice(identity.length) : text
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// promptText adapts a system prompt's text.
|
|
1220
|
+
function promptText(text) {
|
|
1221
|
+
return clientOpening(systemModelLine(claudeIdentity(text)))
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// systemMessageText adapts a system message's text after the prompt.
|
|
1225
|
+
function systemMessageText(text) {
|
|
1226
|
+
return bareSkills(clientOpening(systemContext(text)))
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
// userBlockText adapts one text block of a user turn.
|
|
1230
|
+
function userBlockText(text) {
|
|
1231
|
+
const compacted = compactContext(text)
|
|
1232
|
+
if (compacted !== text) return compacted
|
|
1233
|
+
if (text.startsWith(INSTRUCTIONS_REMINDER) && text.includes(GLOBAL_INSTRUCTIONS)) return text.replaceAll(GLOBAL_INSTRUCTIONS, "(global instructions)")
|
|
1234
|
+
// a system message folded into the user's turn on its way here
|
|
1235
|
+
if (HOOK_OUTPUT.test(text) || SYSTEM_ENV_CONTEXT.test(text)) return systemContext(text)
|
|
1236
|
+
if (ENV_REMINDER.test(text)) {
|
|
1237
|
+
return text.replace("# Environment", "# Runtime context")
|
|
1238
|
+
.replace("You have been invoked in the following environment:", "The session environment is:")
|
|
1239
|
+
}
|
|
1240
|
+
if (MODEL_REMINDER.test(text)) {
|
|
1241
|
+
return text.replace("You are powered by the model named", "Current model name:")
|
|
1242
|
+
.replace("You are powered by the model", "Current model:")
|
|
1243
|
+
.replace("The exact model ID is", "Model ID:")
|
|
1244
|
+
.replace("Assistant knowledge cutoff is", "Model knowledge cutoff:")
|
|
1245
|
+
}
|
|
1246
|
+
if (SKILL_REMINDER.test(text)) return text.replace("\n" + CONFIG_SKILL_METADATA, "\n" + CONFIG_SKILL_COMPAT)
|
|
1247
|
+
return text
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// A chat completions user message is one string: magpie joins a Messages
|
|
1251
|
+
// turn's text blocks with nothing between them, so a reminder block and the
|
|
1252
|
+
// user's words arrive as one text. Adapted whole first, then each complete
|
|
1253
|
+
// reminder in it as the block it was; the rest stays as it is.
|
|
1254
|
+
const REMINDER_BLOCK = /<system-reminder>\n[\s\S]*?\n<\/system-reminder>/g
|
|
1255
|
+
function userText(text) {
|
|
1256
|
+
const adapted = userBlockText(text)
|
|
1257
|
+
if (adapted !== text || !text.includes("<system-reminder>\n")) return adapted
|
|
1258
|
+
return text.replace(REMINDER_BLOCK, (block) => userBlockText(block))
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1188
1261
|
function anthropicBody(body) {
|
|
1189
1262
|
let request
|
|
1190
1263
|
try {
|
|
@@ -1220,9 +1293,7 @@ function anthropicBody(body) {
|
|
|
1220
1293
|
if (block?.type === "text") {
|
|
1221
1294
|
// The gateway may join the identity and instructions into one block.
|
|
1222
1295
|
// Only the complete fixed first line is metadata; keep the rest.
|
|
1223
|
-
const
|
|
1224
|
-
const text = identity ? DROID_LINE + block.text.slice(identity.length) : block.text
|
|
1225
|
-
const adapted = clientOpening(systemModelLine(text))
|
|
1296
|
+
const adapted = promptText(block.text)
|
|
1226
1297
|
if (adapted !== block.text) {
|
|
1227
1298
|
block.text = adapted
|
|
1228
1299
|
changed = true
|
|
@@ -1250,7 +1321,7 @@ function anthropicBody(body) {
|
|
|
1250
1321
|
|
|
1251
1322
|
for (const message of request.messages) {
|
|
1252
1323
|
if (message?.role === "system" && typeof message.content === "string") {
|
|
1253
|
-
const adapted =
|
|
1324
|
+
const adapted = systemMessageText(message.content)
|
|
1254
1325
|
if (adapted !== message.content) {
|
|
1255
1326
|
message.content = adapted
|
|
1256
1327
|
changed = true
|
|
@@ -1263,7 +1334,7 @@ function anthropicBody(body) {
|
|
|
1263
1334
|
if (message?.role === "system" && Array.isArray(message.content)) {
|
|
1264
1335
|
for (const block of message.content) {
|
|
1265
1336
|
if (block?.type !== "text" || typeof block.text !== "string") continue
|
|
1266
|
-
const adapted =
|
|
1337
|
+
const adapted = systemMessageText(block.text)
|
|
1267
1338
|
if (adapted !== block.text) {
|
|
1268
1339
|
block.text = adapted
|
|
1269
1340
|
changed = true
|
|
@@ -1302,36 +1373,10 @@ function anthropicBody(body) {
|
|
|
1302
1373
|
continue
|
|
1303
1374
|
}
|
|
1304
1375
|
if (block?.type !== "text" || typeof block.text !== "string") continue
|
|
1305
|
-
const
|
|
1306
|
-
if (
|
|
1307
|
-
block.text =
|
|
1308
|
-
changed = true
|
|
1309
|
-
} else if (block.text.startsWith(INSTRUCTIONS_REMINDER) && block.text.includes(GLOBAL_INSTRUCTIONS)) {
|
|
1310
|
-
block.text = block.text.replaceAll(GLOBAL_INSTRUCTIONS, "(global instructions)")
|
|
1311
|
-
changed = true
|
|
1312
|
-
} else if (HOOK_OUTPUT.test(block.text) || SYSTEM_ENV_CONTEXT.test(block.text)) {
|
|
1313
|
-
// a system message folded into the user's turn on its way here
|
|
1314
|
-
const adapted = systemContext(block.text)
|
|
1315
|
-
if (adapted !== block.text) {
|
|
1316
|
-
block.text = adapted
|
|
1317
|
-
changed = true
|
|
1318
|
-
}
|
|
1319
|
-
} else if (ENV_REMINDER.test(block.text)) {
|
|
1320
|
-
block.text = block.text.replace("# Environment", "# Runtime context")
|
|
1321
|
-
.replace("You have been invoked in the following environment:", "The session environment is:")
|
|
1322
|
-
changed = true
|
|
1323
|
-
} else if (MODEL_REMINDER.test(block.text)) {
|
|
1324
|
-
block.text = block.text.replace("You are powered by the model named", "Current model name:")
|
|
1325
|
-
.replace("You are powered by the model", "Current model:")
|
|
1326
|
-
.replace("The exact model ID is", "Model ID:")
|
|
1327
|
-
.replace("Assistant knowledge cutoff is", "Model knowledge cutoff:")
|
|
1376
|
+
const adapted = userBlockText(block.text)
|
|
1377
|
+
if (adapted !== block.text) {
|
|
1378
|
+
block.text = adapted
|
|
1328
1379
|
changed = true
|
|
1329
|
-
} else if (SKILL_REMINDER.test(block.text)) {
|
|
1330
|
-
const adapted = block.text.replace("\n" + CONFIG_SKILL_METADATA, "\n" + CONFIG_SKILL_COMPAT)
|
|
1331
|
-
if (adapted !== block.text) {
|
|
1332
|
-
block.text = adapted
|
|
1333
|
-
changed = true
|
|
1334
|
-
}
|
|
1335
1380
|
}
|
|
1336
1381
|
}
|
|
1337
1382
|
}
|