Repository navigation
fix(provider): pass xAI's raised Grok CLI version gate #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c24d30c
fix(provider): pass xAI's raised Grok CLI version gate
kenryu42 140ecee
chore(deps): sync bun.lock peer ranges with package.json
kenryu42 4d815c9
fix(provider): look up the Grok CLI version again after HTTP 426
kenryu42 714f040
fix(provider): share one version lookup between concurrent 426 refreshes
kenryu42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,62 @@ | ||
| // Grok CLI client version. Keep it in sync with the version the official Grok | ||
| // CLI client emits (observed in captured cli-chat-proxy.grok.com traffic). | ||
| export const GROK_CLI_VERSION = '0.2.91'; | ||
| // Grok CLI release sent when the latest stable release cannot be looked up. | ||
| // Keep it at a current official release so it stays above the endpoint minimum. | ||
| export const GROK_CLI_VERSION = '1.0.46'; | ||
|
|
||
| // The version gate reads the client version out of User-Agent. The accepted | ||
| // format is the product/version pair the official clients emit — both the pager | ||
| // and shell tokens are included for parity with the native client. | ||
| export const GROK_CLI_USER_AGENT = `grok-pager/${GROK_CLI_VERSION} grok-shell/${GROK_CLI_VERSION} (macos; aarch64)`; | ||
| const STABLE_VERSION_TIMEOUT_MS = 5_000; | ||
|
|
||
| export const GROK_CLI_CLIENT_IDENTIFIER = 'grok-pager'; | ||
| export const GROK_CLI_TOKEN_AUTH = 'xai-grok-cli'; | ||
| let stableVersion: Promise<string> | undefined; | ||
|
|
||
| /** | ||
| * Static identification headers the inference endpoint requires on every | ||
| * request (the version gate rejects requests whose User-Agent carries no Grok | ||
| * version with HTTP 426 "version (none)"). | ||
| * | ||
| * These are attached to each model definition so pi-coding-agent injects them | ||
| * via `model.headers` on every request. The dynamic conversation id is added | ||
| * through the provider-scoped `before_provider_headers` hook. | ||
| * The inference endpoint rejects requests with HTTP 426 when | ||
| * `x-grok-client-version` is missing or older than its minimum supported | ||
| * release; it ignores User-Agent. Reading the latest stable release from the | ||
| * pointer the official installer uses keeps requests above a raised minimum | ||
| * without an extension release. The lookup runs once per process until a | ||
| * request is rejected by the gate. | ||
| */ | ||
| export function resolveGrokCliVersion() { | ||
| stableVersion ??= fetch(process.env.PI_GROK_CLI_VERSION_URL || 'https://x.ai/cli/stable', { | ||
| signal: AbortSignal.timeout(STABLE_VERSION_TIMEOUT_MS), | ||
| }) | ||
| .then(async (response) => { | ||
| const version = response.ok ? (await response.text()).trim() : ''; | ||
| return /^\d+\.\d+\.\d+(-[\w.]+)?$/.test(version) ? version : GROK_CLI_VERSION; | ||
| }) | ||
| .catch(() => GROK_CLI_VERSION); | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
| return stableVersion; | ||
| } | ||
|
|
||
| let refreshing: Promise<string> | undefined; | ||
|
|
||
| // Discards the cached release after the gate rejects it and looks it up again. | ||
| // Concurrent rejections share one lookup so a failed one cannot replace a newer release. | ||
| export function refreshGrokCliVersion() { | ||
| if (!refreshing) { | ||
| stableVersion = undefined; | ||
| refreshing = resolveGrokCliVersion().finally(() => { | ||
| refreshing = undefined; | ||
| }); | ||
| } | ||
| return refreshing; | ||
| } | ||
|
|
||
| /** | ||
| * Static identification headers attached to each model definition so Pi sends | ||
| * them on every request. The version headers are added per request by the | ||
| * provider stream once the version is resolved. | ||
| */ | ||
| export function grokCliModelHeaders(modelId: string): Record<string, string> { | ||
| return { | ||
| 'User-Agent': GROK_CLI_USER_AGENT, | ||
| 'x-grok-client-identifier': GROK_CLI_CLIENT_IDENTIFIER, | ||
| 'x-grok-client-version': GROK_CLI_VERSION, | ||
| 'x-xai-token-auth': GROK_CLI_TOKEN_AUTH, | ||
| 'x-grok-client-identifier': 'grok-shell', | ||
| 'x-xai-token-auth': 'xai-grok-cli', | ||
| 'x-grok-model-override': modelId, | ||
| }; | ||
| } | ||
|
|
||
| // Same format as the official Grok CLI client's own version headers. | ||
| export function grokCliVersionHeaders(version: string): Record<string, string> { | ||
| return { | ||
| 'User-Agent': `grok-shell/${version} (macos; aarch64)`, | ||
| 'x-grok-client-version': version, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.