diff --git a/packages/grok/README.md b/packages/grok/README.md index 5f1db7f..01d6c3a 100644 --- a/packages/grok/README.md +++ b/packages/grok/README.md @@ -10,6 +10,13 @@ curl -fsSL https://x.ai/cli/install.sh | bash # macOS, Linux irm https://x.ai/cli/install.ps1 | iex # Windows ``` +It is found in the installer's folder (`GROK_BIN_DIR`, `GROK_HOME/bin`, +`~/.grok/bin`), or on `PATH` when it lives under a `.grok` folder, so that +another program named `grok` isn't taken for it. Where the installer can't +run, such as a container without curl, put the binary in a folder of your +own and set `GROK_BIN_DIR` to it. magpie installs Grok Build itself, as +the installer does, before a sign-in that needs it. + ## Sign in - **Sign in with Grok Build (device code)** runs `grok login --device-auth` diff --git a/packages/grok/import.test.mjs b/packages/grok/import.test.mjs index d83fcac..78368d3 100644 --- a/packages/grok/import.test.mjs +++ b/packages/grok/import.test.mjs @@ -148,6 +148,8 @@ test("what isn't an enabled CPA xAI OAuth account is refused, with no home made" test("no Grok Build to refresh the sign-in with is refused first", async () => { sandbox({ exe: false }) await expect(importFrom(cpaFile())).rejects.toThrow("install Grok Build first") + // one put in a folder of the user's choosing (magpie in Docker) is named too + await expect(importFrom(cpaFile())).rejects.toThrow("set GROK_BIN_DIR to the folder holding its grok binary") }) test("a token that has already ended is still taken, its renewal left to the CLI", async () => { diff --git a/packages/grok/index.mjs b/packages/grok/index.mjs index 207bb0f..2b9afe7 100644 --- a/packages/grok/index.mjs +++ b/packages/grok/index.mjs @@ -23,6 +23,11 @@ const REFRESH_MARGIN = 5 * 60 * 1000 // a token this close to its end is renewed const LEAD_MS = REFRESH_MARGIN // and this close, magpie renews it ahead of time (auth.refresh) const LINK_WAIT = 30 * 1000 const INSTALL = process.platform === "win32" ? "irm https://x.ai/cli/install.ps1 | iex" : "curl -fsSL https://x.ai/cli/install.sh | bash" +// NO_CLI is what a sign-in without Grok Build says: how to install it, and +// that one put somewhere else by hand (a container with no shell to run the +// installer) is taken from GROK_BIN_DIR, as the installer's own folder is, +// while one found on PATH has to be under a .grok folder (yetone/magpie#2223) +const NO_CLI = `install Grok Build first: ${INSTALL}; or set GROK_BIN_DIR to the folder holding its grok binary` // the tool types Grok's backend takes; it turns the whole request away over another const TOOLS = new Set(["function", "web_search", "x_search", "image_generation", "collections_search", "file_search", @@ -487,7 +492,7 @@ function newHome() { // sign-in stays as it is. async function signIn() { const exe = executable() - if (!exe) throw new Error(`install Grok Build first: ${INSTALL}`) + if (!exe) throw new Error(NO_CLI) const own = !!credential(cliHome()) const home = own ? newHome() : cliHome() const { child, link, done, tail } = login(exe, home, own) @@ -566,7 +571,7 @@ function cpaAuthFromFile(file) { } async function importCPA(inputs) { - if (!executable()) throw new Error(`install Grok Build first: ${INSTALL}`) + if (!executable()) throw new Error(NO_CLI) const rawPath = String(inputs?.path ?? "").trim() const file = resolve(rawPath === "~" ? homedir() : rawPath.startsWith("~/") ? join(homedir(), rawPath.slice(2)) : rawPath) if (!isFile(file)) throw new Error("choose a CPA Grok account JSON file") @@ -596,7 +601,7 @@ function saved(home, c) { // current takes the sign-in the CLI already has, as it is. async function current() { - if (!executable()) throw new Error(`install Grok Build first: ${INSTALL}`) + if (!executable()) throw new Error(NO_CLI) const home = cliHome() if (!credential(home)) throw new Error("Grok Build is not signed in; run `grok login`, or sign in with the device code") const c = await token(home, false) diff --git a/packages/grok/package.json b/packages/grok/package.json index 86a4481..9525147 100644 --- a/packages/grok/package.json +++ b/packages/grok/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-grok-auth", - "version": "0.1.14", + "version": "0.1.15", "description": "OpenCode provider plugin: Grok (SuperGrok / X Premium+) through the Grok Build CLI's sign-in", "type": "module", "main": "./index.mjs",