@magpie-community/opencode-grok-auth 0.1.14 → 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.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/index.mjs +8 -3
  3. 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",
@@ -487,7 +492,7 @@ function newHome() {
487
492
  // sign-in stays as it is.
488
493
  async function signIn() {
489
494
  const exe = executable()
490
- if (!exe) throw new Error(`install Grok Build first: ${INSTALL}`)
495
+ if (!exe) throw new Error(NO_CLI)
491
496
  const own = !!credential(cliHome())
492
497
  const home = own ? newHome() : cliHome()
493
498
  const { child, link, done, tail } = login(exe, home, own)
@@ -566,7 +571,7 @@ function cpaAuthFromFile(file) {
566
571
  }
567
572
 
568
573
  async function importCPA(inputs) {
569
- if (!executable()) throw new Error(`install Grok Build first: ${INSTALL}`)
574
+ if (!executable()) throw new Error(NO_CLI)
570
575
  const rawPath = String(inputs?.path ?? "").trim()
571
576
  const file = resolve(rawPath === "~" ? homedir() : rawPath.startsWith("~/") ? join(homedir(), rawPath.slice(2)) : rawPath)
572
577
  if (!isFile(file)) throw new Error("choose a CPA Grok account JSON file")
@@ -596,7 +601,7 @@ function saved(home, c) {
596
601
 
597
602
  // current takes the sign-in the CLI already has, as it is.
598
603
  async function current() {
599
- if (!executable()) throw new Error(`install Grok Build first: ${INSTALL}`)
604
+ if (!executable()) throw new Error(NO_CLI)
600
605
  const home = cliHome()
601
606
  if (!credential(home)) throw new Error("Grok Build is not signed in; run `grok login`, or sign in with the device code")
602
607
  const c = await token(home, false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-grok-auth",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "OpenCode provider plugin: Grok (SuperGrok / X Premium+) through the Grok Build CLI's sign-in",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",