@magpie-community/opencode-grok-auth 0.1.13 → 0.1.15
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 +7 -0
- package/index.mjs +13 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,13 @@ curl -fsSL https://x.ai/cli/install.sh | bash # macOS, Linux
|
|
|
10
10
|
irm https://x.ai/cli/install.ps1 | iex # Windows
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
It is found in the installer's folder (`GROK_BIN_DIR`, `GROK_HOME/bin`,
|
|
14
|
+
`~/.grok/bin`), or on `PATH` when it lives under a `.grok` folder, so that
|
|
15
|
+
another program named `grok` isn't taken for it. Where the installer can't
|
|
16
|
+
run, such as a container without curl, put the binary in a folder of your
|
|
17
|
+
own and set `GROK_BIN_DIR` to it. magpie installs Grok Build itself, as
|
|
18
|
+
the installer does, before a sign-in that needs it.
|
|
19
|
+
|
|
13
20
|
## Sign in
|
|
14
21
|
|
|
15
22
|
- **Sign in with Grok Build (device code)** runs `grok login --device-auth`
|
package/index.mjs
CHANGED
|
@@ -23,6 +23,11 @@ const REFRESH_MARGIN = 5 * 60 * 1000 // a token this close to its end is renewed
|
|
|
23
23
|
const LEAD_MS = REFRESH_MARGIN // and this close, magpie renews it ahead of time (auth.refresh)
|
|
24
24
|
const LINK_WAIT = 30 * 1000
|
|
25
25
|
const INSTALL = process.platform === "win32" ? "irm https://x.ai/cli/install.ps1 | iex" : "curl -fsSL https://x.ai/cli/install.sh | bash"
|
|
26
|
+
// NO_CLI is what a sign-in without Grok Build says: how to install it, and
|
|
27
|
+
// that one put somewhere else by hand (a container with no shell to run the
|
|
28
|
+
// installer) is taken from GROK_BIN_DIR, as the installer's own folder is,
|
|
29
|
+
// while one found on PATH has to be under a .grok folder (yetone/magpie#2223)
|
|
30
|
+
const NO_CLI = `install Grok Build first: ${INSTALL}; or set GROK_BIN_DIR to the folder holding its grok binary`
|
|
26
31
|
|
|
27
32
|
// the tool types Grok's backend takes; it turns the whole request away over another
|
|
28
33
|
const TOOLS = new Set(["function", "web_search", "x_search", "image_generation", "collections_search", "file_search",
|
|
@@ -421,11 +426,12 @@ function windowsOf(d, efforts) {
|
|
|
421
426
|
// grok-4.7@500k is grok-4.7 at 500000 tokens. The header is what the CLI
|
|
422
427
|
// sends as x-grok-context-window. The proxy serves up to its largest
|
|
423
428
|
// window either way and refuses past it; the header names the window the
|
|
424
|
-
// caller asked to compact against.
|
|
429
|
+
// caller asked to compact against. A window no multiple of 1000 is named
|
|
430
|
+
// by its digits alone (grok-4.7@131072), as labelOf writes it.
|
|
425
431
|
function modelOf(id) {
|
|
426
|
-
const at = typeof id === "string" ? id.match(/^(
|
|
427
|
-
if (!at) return { model: id, window: 0 }
|
|
428
|
-
return { model: at[1], window: Number(at[2]) * 1000 }
|
|
432
|
+
const at = typeof id === "string" ? id.match(/^(.+)@(\d+)(k?)$/) : null
|
|
433
|
+
if (!at || !(Number(at[2]) > 0)) return { model: id, window: 0 }
|
|
434
|
+
return { model: at[1], window: Number(at[2]) * (at[3] ? 1000 : 1) }
|
|
429
435
|
}
|
|
430
436
|
|
|
431
437
|
// ---- sign-in ------------------------------------------------------------------
|
|
@@ -486,7 +492,7 @@ function newHome() {
|
|
|
486
492
|
// sign-in stays as it is.
|
|
487
493
|
async function signIn() {
|
|
488
494
|
const exe = executable()
|
|
489
|
-
if (!exe) throw new Error(
|
|
495
|
+
if (!exe) throw new Error(NO_CLI)
|
|
490
496
|
const own = !!credential(cliHome())
|
|
491
497
|
const home = own ? newHome() : cliHome()
|
|
492
498
|
const { child, link, done, tail } = login(exe, home, own)
|
|
@@ -565,7 +571,7 @@ function cpaAuthFromFile(file) {
|
|
|
565
571
|
}
|
|
566
572
|
|
|
567
573
|
async function importCPA(inputs) {
|
|
568
|
-
if (!executable()) throw new Error(
|
|
574
|
+
if (!executable()) throw new Error(NO_CLI)
|
|
569
575
|
const rawPath = String(inputs?.path ?? "").trim()
|
|
570
576
|
const file = resolve(rawPath === "~" ? homedir() : rawPath.startsWith("~/") ? join(homedir(), rawPath.slice(2)) : rawPath)
|
|
571
577
|
if (!isFile(file)) throw new Error("choose a CPA Grok account JSON file")
|
|
@@ -595,7 +601,7 @@ function saved(home, c) {
|
|
|
595
601
|
|
|
596
602
|
// current takes the sign-in the CLI already has, as it is.
|
|
597
603
|
async function current() {
|
|
598
|
-
if (!executable()) throw new Error(
|
|
604
|
+
if (!executable()) throw new Error(NO_CLI)
|
|
599
605
|
const home = cliHome()
|
|
600
606
|
if (!credential(home)) throw new Error("Grok Build is not signed in; run `grok login`, or sign in with the device code")
|
|
601
607
|
const c = await token(home, false)
|
package/package.json
CHANGED