pullfrog 0.1.65 → 0.1.67
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 +1 -0
- package/dist/cli.mjs +10320 -5269
- package/dist/external.d.ts +7 -0
- package/dist/index.js +9891 -5130
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal.js +267 -25
- package/dist/models.d.ts +2 -0
- package/dist/utils/apiKeys.d.ts +15 -0
- package/dist/utils/codexHome.d.ts +21 -0
- package/dist/utils/codexOAuth.d.ts +7 -20
- package/dist/utils/codexRefreshDetect.d.ts +44 -0
- package/dist/utils/github.d.ts +6 -0
- package/dist/utils/oauthShared.d.ts +39 -0
- package/dist/utils/payload.d.ts +2 -0
- package/dist/utils/token.d.ts +6 -0
- package/dist/utils/xaiOAuth.d.ts +74 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-stdlib (fetch) xAI/Grok OAuth: device-code login + refresh.
|
|
3
|
+
*
|
|
4
|
+
* Lives here (not in a CLI module) so the Next.js server side can import it
|
|
5
|
+
* via pullfrog/internal without dragging in node:child_process. Used by:
|
|
6
|
+
* - action/commands/auth.ts (`pullfrog auth grok` device-code login)
|
|
7
|
+
* - action/utils/codexHome.ts (materialize into opencode's auth.json)
|
|
8
|
+
* - utils/xaiSecretRotation.ts (server-side rotation at run-context)
|
|
9
|
+
*
|
|
10
|
+
* We talk to xAI's OAuth endpoints directly rather than shelling out to the
|
|
11
|
+
* Grok CLI the way `auth codex` shells out to `codex login`. The Grok CLI is
|
|
12
|
+
* a curl|bash install that nothing else in the flow needs, and the device
|
|
13
|
+
* grant is ~60 lines of fetch — requiring a second CLI to obtain a
|
|
14
|
+
* credential opencode consumes natively would be gratuitous.
|
|
15
|
+
*
|
|
16
|
+
* See wiki/grok-auth.md.
|
|
17
|
+
*/
|
|
18
|
+
export interface XaiAuthBody {
|
|
19
|
+
auth_mode: "grok";
|
|
20
|
+
tokens: {
|
|
21
|
+
access_token: string;
|
|
22
|
+
refresh_token: string;
|
|
23
|
+
};
|
|
24
|
+
last_refresh?: string;
|
|
25
|
+
/**
|
|
26
|
+
* ISO timestamp of an `invalid_grant` rejection. xAI rotates the refresh
|
|
27
|
+
* token on every use, so a rejection is PERMANENT until the user re-runs
|
|
28
|
+
* `pullfrog auth grok`. Without the latch the server re-issues the same
|
|
29
|
+
* doomed refresh on every run, each holding a Postgres row lock across an
|
|
30
|
+
* external call — the failure mode measured for Codex in
|
|
31
|
+
* [#1101](https://github.com/pullfrog/app/issues/1101). Cleared implicitly:
|
|
32
|
+
* `pullfrog auth grok` and `PUT /api/runtime/secret` write a fresh blob
|
|
33
|
+
* without it, which re-arms rotation.
|
|
34
|
+
*/
|
|
35
|
+
refresh_rejected_at?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Public Grok-CLI OAuth client. Identical to the `oidc_client_id` the Grok
|
|
38
|
+
* CLI writes into its own `~/.grok/auth.json` and to opencode's XaiAuthPlugin
|
|
39
|
+
* CLIENT_ID — one chain, so a token minted here refreshes anywhere. */
|
|
40
|
+
export declare const XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
41
|
+
export declare const XAI_OAUTH_TOKEN_URL = "https://auth.x.ai/oauth2/token";
|
|
42
|
+
export declare const XAI_DEVICE_CODE_URL = "https://auth.x.ai/oauth2/device/code";
|
|
43
|
+
export declare const XAI_DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
44
|
+
/** `api:access` is the scope that lets the subscription token authorize
|
|
45
|
+
* api.x.ai — without it the credential logs in but cannot infer. */
|
|
46
|
+
export declare const XAI_OAUTH_SCOPE = "openid profile email offline_access grok-cli:access api:access";
|
|
47
|
+
/** force one refresh round-trip against xAI. returns the rotated blob; does
|
|
48
|
+
* NOT persist — the caller writes it back wherever the token lives.
|
|
49
|
+
*
|
|
50
|
+
* The 10s timeout matters server-side: `maybeRotateXaiSecret` holds a DB row
|
|
51
|
+
* lock across this call, so the cap keeps us inside the enclosing transaction
|
|
52
|
+
* budget and guarantees queued callers get a turn. Real latency is sub-second. */
|
|
53
|
+
export declare function refreshXaiAuthBody(body: XaiAuthBody): Promise<XaiAuthBody>;
|
|
54
|
+
/** parse + validate a stored Grok blob. returns null on any shape mismatch —
|
|
55
|
+
* caller treats null as "no grok auth". */
|
|
56
|
+
export declare function parseXaiAuthBody(raw: string): XaiAuthBody | null;
|
|
57
|
+
/** serialize to the canonical stored form. */
|
|
58
|
+
export declare function stringifyXaiAuthBody(body: XaiAuthBody): string;
|
|
59
|
+
export interface XaiDeviceCode {
|
|
60
|
+
deviceCode: string;
|
|
61
|
+
userCode: string;
|
|
62
|
+
/** pre-filled URL when xAI supplies one, else the bare verification URL. */
|
|
63
|
+
verificationUrl: string;
|
|
64
|
+
intervalMs: number;
|
|
65
|
+
expiresAtMs: number;
|
|
66
|
+
}
|
|
67
|
+
/** RFC 8628 step 1: ask xAI for a device code. The user approves in a browser
|
|
68
|
+
* on any device — no loopback callback server, so this works unchanged from a
|
|
69
|
+
* container, an SSH session, or a locked-down workstation. */
|
|
70
|
+
export declare function startXaiDeviceAuth(): Promise<XaiDeviceCode>;
|
|
71
|
+
/** RFC 8628 step 2: long-poll the token endpoint until the user approves.
|
|
72
|
+
* Honors the spec's `authorization_pending` / `slow_down` back-off. Resolves
|
|
73
|
+
* with the minted chain, or throws on denial / expiry. */
|
|
74
|
+
export declare function pollXaiDeviceAuth(device: XaiDeviceCode): Promise<XaiAuthBody>;
|