@magpie-community/opencode-grok-auth 0.1.2 → 0.1.4
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 +38 -17
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -225,8 +225,20 @@ function rewrite(body) {
|
|
|
225
225
|
|
|
226
226
|
// ---- models -------------------------------------------------------------------
|
|
227
227
|
|
|
228
|
+
// the levels the built-in offered for grok-4.7 before Grok listed any (its
|
|
229
|
+
// maker's, as models.dev has them): kept when the list can't be read, so
|
|
230
|
+
// a move leaves an agent's reasoning level where it was
|
|
231
|
+
const DEFAULT_EFFORTS = ["low", "medium", "high", "xhigh"]
|
|
232
|
+
|
|
228
233
|
const DEFAULT_MODELS = {
|
|
229
|
-
"grok-4.7": {
|
|
234
|
+
"grok-4.7": {
|
|
235
|
+
name: "Grok 4.7",
|
|
236
|
+
attachment: true,
|
|
237
|
+
reasoning: true,
|
|
238
|
+
tool_call: true,
|
|
239
|
+
modalities: { input: ["text", "image"], output: ["text"] },
|
|
240
|
+
variants: Object.fromEntries(DEFAULT_EFFORTS.map((e) => [e, { reasoningEffort: e }])),
|
|
241
|
+
},
|
|
230
242
|
}
|
|
231
243
|
|
|
232
244
|
// listModels is what the account can use, as the CLI's backend lists it:
|
|
@@ -420,6 +432,15 @@ async function usage(key) {
|
|
|
420
432
|
return { windows: out }
|
|
421
433
|
}
|
|
422
434
|
|
|
435
|
+
// kept is res saying magpie is to leave the account's sign-in be.
|
|
436
|
+
function kept(res) {
|
|
437
|
+
const headers = new Headers(res.headers)
|
|
438
|
+
headers.delete("content-length")
|
|
439
|
+
headers.delete("content-encoding")
|
|
440
|
+
headers.set("X-Magpie-Sign-In", "kept")
|
|
441
|
+
return new Response(res.body, { status: res.status, statusText: res.statusText, headers })
|
|
442
|
+
}
|
|
443
|
+
|
|
423
444
|
// ---- the plugin ---------------------------------------------------------------
|
|
424
445
|
|
|
425
446
|
export const GrokAuthPlugin = async ({ client }) => {
|
|
@@ -461,19 +482,17 @@ export const GrokAuthPlugin = async ({ client }) => {
|
|
|
461
482
|
parsed = JSON.parse(body) ?? {}
|
|
462
483
|
} catch {}
|
|
463
484
|
}
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (res.status !== 401) return res
|
|
476
|
-
return send(true)
|
|
485
|
+
const c = await token(home, false)
|
|
486
|
+
await remember(auth, c)
|
|
487
|
+
const headers = new Headers(req.headers)
|
|
488
|
+
await sign(headers, c.key)
|
|
489
|
+
if (typeof parsed.model === "string" && parsed.model) headers.set("x-grok-model-override", parsed.model)
|
|
490
|
+
if (typeof parsed.prompt_cache_key === "string" && parsed.prompt_cache_key) headers.set("x-grok-conv-id", parsed.prompt_cache_key)
|
|
491
|
+
headers.delete("content-length")
|
|
492
|
+
// sent once, as the built-in sent it: Grok's answer goes on as
|
|
493
|
+
// it came, the account kept, as the built-in never marked a Grok
|
|
494
|
+
// account lapsed nor cleared one
|
|
495
|
+
return kept(await fetch(req.url, { ...init, method: req.method, headers, body }))
|
|
477
496
|
},
|
|
478
497
|
}
|
|
479
498
|
},
|
|
@@ -489,7 +508,9 @@ export const GrokAuthPlugin = async ({ client }) => {
|
|
|
489
508
|
authorize: current,
|
|
490
509
|
},
|
|
491
510
|
],
|
|
492
|
-
// magpie's: how much of the subscription's allowance is gone
|
|
511
|
+
// magpie's: how much of the subscription's allowance is gone; each
|
|
512
|
+
// read keeps the sign-in (signIn), as the built-in's marked no
|
|
513
|
+
// account lapsed nor cleared one
|
|
493
514
|
async usage(getAuth) {
|
|
494
515
|
const auth = await getAuth()
|
|
495
516
|
let c
|
|
@@ -497,10 +518,10 @@ export const GrokAuthPlugin = async ({ client }) => {
|
|
|
497
518
|
if (!auth || auth.type !== "oauth" || !auth.refresh) throw new Error("Grok is not signed in; run `grok login`")
|
|
498
519
|
c = await token(auth.refresh, false)
|
|
499
520
|
} catch (e) {
|
|
500
|
-
return { error: e.message, windows: [] }
|
|
521
|
+
return { error: e.message, windows: [], signIn: "kept" }
|
|
501
522
|
}
|
|
502
523
|
await remember(auth, c)
|
|
503
|
-
return usage(c.key)
|
|
524
|
+
return { ...(await usage(c.key)), signIn: "kept" }
|
|
504
525
|
},
|
|
505
526
|
},
|
|
506
527
|
|
package/package.json
CHANGED