Files
plugins/packages/grok/package.json
T
moxuunandyetone 01fdc091c0 grok 0.1.13: import a CLIProxyAPI (CPA) xAI account from its file (#92)
* grok 0.1.13: import a CLIProxyAPI (CPA) xAI account from its file

CPA (CLIProxyAPI) keeps each of its accounts in ~/.cli-proxy-api as a flat
JSON file: {type: "xai", auth_kind: "oauth", access_token, refresh_token,
expired, last_refresh, sub, email, disabled, …}. Its xAI accounts sign in
with the same OAuth client Grok Build does, so such an account is a sign-in
Grok Build can hold — but the plugin could only take the CLI's own sign-in
or make a new one, so an account that lives in CPA could not be used here.

The third sign-in method takes the path to one of those files, reads it and
writes Grok Build's own shape (key, auth_mode: "oidc", create_time,
user_id, email, refresh_token, expires_at, oidc_issuer, oidc_client_id)
into a home of the plugin's own, as a device-code sign-in does. The
imported file is only read, and only the fields above are carried over:
base_url is not honored and expires_in is not turned into a lifetime
measured from the import.

A file is refused, before any home is made, when it is not an enabled
(type xai, auth_kind oauth, not disabled) xAI account with tokens, identity
and timestamps, or when the token's own iss/aud are not the Grok Build
xAI ones. The refresh token rotates and both clients would spend it, so the
prompt and the README say to stop using the account in CPA first. Nothing
here refreshes a live token or touches CPA.

bun test: 39 pass on the grok package (4 new in import.test.mjs: the
translated home, the refusals, no Grok Build, and a home that can't be
made). bun scripts/check.mjs grok and node --check pass.

* grok: string timestamps, and import.test.mjs off POSIX

`Date.parse` coerces, so a `last_refresh` or `expired` that was a list or an
object read as a date: the file must say a string before it is parsed.

The test's fake CLI is named for the platform (`grok.exe` on Windows), PATH
joins with the platform delimiter, and the 0600 file is only checked where
POSIX gives it. The mkdir that fails is what the last test covers, not the
cleanup after a write that fails, and it now says so.

* grok: the import's placeholder names the file CPA writes, xai-<email>.json (review of #92)

CLIProxyAPI's xAI sign-in saves each account as xai-<email>.json
(internal/auth/xai/token.go CredentialFileName), not cpa_*.json.
Text only; import.test.mjs still 5 pass.

---------

Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-12 18:16:23 +08:00

17 lines
537 B
JSON

{
"name": "@magpie-community/opencode-grok-auth",
"version": "0.1.13",
"description": "OpenCode provider plugin: Grok (SuperGrok / X Premium+) through the Grok Build CLI's sign-in",
"type": "module",
"main": "./index.mjs",
"exports": "./index.mjs",
"files": ["index.mjs", "README.md"],
"keywords": ["opencode", "opencode-plugin", "grok", "xai", "supergrok"],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/magpie-community/plugins.git",
"directory": "packages/grok"
}
}