march-cli 0.1.24 → 0.1.26
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/bin/march.mjs +13 -13
- package/package.json +49 -49
- package/src/agent/command-exec-tool.mjs +172 -172
- package/src/agent/context-stats-tool.mjs +57 -57
- package/src/agent/editing/diff-apply.mjs +28 -28
- package/src/agent/editing/diff-format.mjs +57 -57
- package/src/agent/editing/lsp-report.mjs +69 -69
- package/src/agent/file-edit-tool.mjs +250 -250
- package/src/agent/file-tools/read-file-tool.mjs +112 -112
- package/src/agent/file-tools/read-image-tool.mjs +76 -76
- package/src/agent/model-payload-dumper.mjs +208 -208
- package/src/agent/pi-session/pi-session-sidecar-failure.mjs +10 -10
- package/src/agent/provider/payload-messages.mjs +138 -138
- package/src/agent/runner/codex-large-context-guard.mjs +87 -87
- package/src/agent/runner/codex-transport-compression.mjs +180 -180
- package/src/agent/runner/codex-transport-debug.mjs +113 -113
- package/src/agent/runner/codex-websocket-event-debug.mjs +130 -130
- package/src/agent/runner/fast-model.mjs +36 -36
- package/src/agent/runner/runner-cleanup.mjs +12 -12
- package/src/agent/runner/runner-init.mjs +15 -15
- package/src/agent/runner/runner-session-state.mjs +40 -40
- package/src/agent/runner/runner-utils.mjs +24 -24
- package/src/agent/runner.mjs +299 -299
- package/src/agent/runtime/ipc/ipc-peer.mjs +99 -99
- package/src/agent/runtime/ipc/process-ipc-transport.mjs +16 -16
- package/src/agent/runtime/remote-runner-client.mjs +73 -73
- package/src/agent/runtime/remote-ui-client.mjs +20 -20
- package/src/agent/runtime/runner-ipc-target.mjs +125 -125
- package/src/agent/runtime/runner-process-client.mjs +47 -47
- package/src/agent/runtime/runner-process-entry.mjs +11 -11
- package/src/agent/runtime/runner-process-factory.mjs +111 -108
- package/src/agent/runtime/runner-runtime-host.mjs +79 -79
- package/src/agent/runtime/runtime-factory.mjs +42 -42
- package/src/agent/runtime/runtime-host.mjs +34 -34
- package/src/agent/runtime/ui-event-bridge.mjs +95 -95
- package/src/agent/screen-tools/list-windows-tool.mjs +39 -39
- package/src/agent/screen-tools/screen-tool.mjs +49 -49
- package/src/agent/screen-tools/windows-screen.mjs +133 -133
- package/src/agent/session/session-auto-name.mjs +41 -41
- package/src/agent/session/session-binding.mjs +12 -12
- package/src/agent/session/session-options.mjs +47 -47
- package/src/agent/tool-names.mjs +1 -1
- package/src/agent/tool-result.mjs +3 -3
- package/src/agent/tool-summary.mjs +112 -112
- package/src/agent/tools.mjs +58 -58
- package/src/agent/turn/turn-events.mjs +111 -111
- package/src/agent/turn/turn-logging.mjs +30 -30
- package/src/agent/turn/turn-runner.mjs +196 -196
- package/src/agent/vision-capability.mjs +14 -14
- package/src/auth/login-command.mjs +90 -90
- package/src/auth/storage.mjs +34 -34
- package/src/cli/args.mjs +96 -79
- package/src/cli/commands/copy-command.mjs +87 -87
- package/src/cli/commands/export-command.mjs +206 -206
- package/src/cli/commands/extensions-command.mjs +53 -53
- package/src/cli/commands/help-command.mjs +7 -7
- package/src/cli/commands/model-command.mjs +141 -141
- package/src/cli/commands/paste-image-command.mjs +43 -43
- package/src/cli/commands/provider-command.mjs +59 -59
- package/src/cli/commands/status-command.mjs +196 -194
- package/src/cli/commands/thinking-command.mjs +87 -87
- package/src/cli/fallback-ui.mjs +156 -156
- package/src/cli/input/attachment-tokens.mjs +20 -20
- package/src/cli/input/autocomplete.mjs +74 -74
- package/src/cli/input/external-editor.mjs +39 -39
- package/src/cli/input/file-search/index.mjs +160 -160
- package/src/cli/input/history-store.mjs +35 -35
- package/src/cli/input/image-clipboard.mjs +55 -55
- package/src/cli/input/keybinding-dispatch.mjs +76 -76
- package/src/cli/input/keybindings.mjs +96 -96
- package/src/cli/input/mode-state.mjs +43 -43
- package/src/cli/input/prompt-templates.mjs +84 -84
- package/src/cli/input/select-with-keyboard.mjs +86 -86
- package/src/cli/permissions.mjs +103 -103
- package/src/cli/repl-commands.mjs +86 -86
- package/src/cli/repl-loop.mjs +183 -183
- package/src/cli/selector-list.mjs +21 -21
- package/src/cli/session/pi-session-switch-command.mjs +41 -41
- package/src/cli/session/session-command.mjs +23 -23
- package/src/cli/session/session-list-command.mjs +68 -68
- package/src/cli/session/session-name-command.mjs +26 -26
- package/src/cli/session/session-source-command.mjs +89 -89
- package/src/cli/session/session-switch-command.mjs +1 -1
- package/src/cli/shell/shell-command.mjs +55 -55
- package/src/cli/shell/shell-drawer-controls.mjs +33 -33
- package/src/cli/shell/shell-drawer.mjs +192 -192
- package/src/cli/shell/shell-split-layout.mjs +70 -70
- package/src/cli/slash-commands.mjs +192 -192
- package/src/cli/startup/create-runtime-runner.mjs +61 -61
- package/src/cli/startup/runtime-close.mjs +23 -23
- package/src/cli/startup/startup-banner.mjs +71 -71
- package/src/cli/startup/startup-session.mjs +51 -51
- package/src/cli/status-line-updater.mjs +75 -75
- package/src/cli/tool-output.mjs +9 -9
- package/src/cli/tui/editor/external-editor-runner.mjs +24 -24
- package/src/cli/tui/input/mouse-selection-controller.mjs +91 -91
- package/src/cli/tui/input/mouse-tracking.mjs +20 -20
- package/src/cli/tui/layout/main-pane-layout.mjs +47 -47
- package/src/cli/tui/layout/safe-render-boundary.mjs +46 -46
- package/src/cli/tui/markdown-renderer.mjs +285 -285
- package/src/cli/tui/output/scroll-state.mjs +79 -79
- package/src/cli/tui/output/text-line-renderer.mjs +50 -50
- package/src/cli/tui/output/tool-card-renderer.mjs +59 -59
- package/src/cli/tui/output/visible-lines.mjs +8 -8
- package/src/cli/tui/output-buffer.mjs +293 -293
- package/src/cli/tui/permission-request-ui.mjs +18 -18
- package/src/cli/tui/recall-rendering.mjs +28 -25
- package/src/cli/tui/render/render-scheduler.mjs +26 -26
- package/src/cli/tui/render/stream-delta-buffer.mjs +46 -46
- package/src/cli/tui/select/editor-select-list.mjs +111 -111
- package/src/cli/tui/selection-screen.mjs +269 -269
- package/src/cli/tui/status/retry-status.mjs +72 -72
- package/src/cli/tui/status/spinner-status.mjs +42 -42
- package/src/cli/tui/status/status-bar.mjs +225 -225
- package/src/cli/tui/syntax/highlighting.mjs +260 -260
- package/src/cli/tui/syntax/languages.mjs +91 -91
- package/src/cli/tui/syntax/tree-sitter/bash.highlights.scm +261 -261
- package/src/cli/tui/syntax/tree-sitter/c.highlights.scm +341 -341
- package/src/cli/tui/syntax/tree-sitter/cpp.highlights.scm +268 -268
- package/src/cli/tui/syntax/tree-sitter/csharp.highlights.scm +577 -577
- package/src/cli/tui/syntax/tree-sitter/css.highlights.scm +109 -109
- package/src/cli/tui/syntax/tree-sitter/diff.highlights.scm +49 -49
- package/src/cli/tui/syntax/tree-sitter/go.highlights.scm +254 -254
- package/src/cli/tui/syntax/tree-sitter/html.highlights.scm +13 -13
- package/src/cli/tui/syntax/tree-sitter/java.highlights.scm +330 -330
- package/src/cli/tui/syntax/tree-sitter/json.highlights.scm +38 -38
- package/src/cli/tui/syntax/tree-sitter/php.highlights.scm +203 -203
- package/src/cli/tui/syntax/tree-sitter/python.highlights.scm +137 -137
- package/src/cli/tui/syntax/tree-sitter/ruby.highlights.scm +309 -309
- package/src/cli/tui/syntax/tree-sitter/rust.highlights.scm +531 -531
- package/src/cli/tui/syntax/tree-sitter/toml.highlights.scm +39 -39
- package/src/cli/tui/syntax/tree-sitter/tsx.highlights.scm +35 -35
- package/src/cli/tui/syntax/tree-sitter/typescript.highlights.scm +35 -35
- package/src/cli/tui/syntax/tree-sitter/yaml.highlights.scm +99 -99
- package/src/cli/tui/tool-rendering.mjs +87 -87
- package/src/cli/tui/tui-diff-rendering.mjs +157 -157
- package/src/cli/tui/tui-handlers.mjs +111 -111
- package/src/cli/tui/tui-input-controller.mjs +61 -61
- package/src/cli/tui/ui-theme.mjs +157 -157
- package/src/cli/ui.mjs +297 -297
- package/src/config/config-json.mjs +108 -84
- package/src/config/dotenv.mjs +20 -20
- package/src/config/features.mjs +75 -75
- package/src/config/loader.mjs +156 -143
- package/src/config/settings-command.mjs +97 -97
- package/src/context/engine.mjs +199 -198
- package/src/context/injections.mjs +26 -26
- package/src/context/profiles.mjs +39 -39
- package/src/context/project-context.mjs +20 -20
- package/src/context/session-status.mjs +25 -17
- package/src/context/shell-layers.mjs +23 -23
- package/src/context/system-core/base.md +51 -50
- package/src/context/system-core/prompts/deepseek-v4-pro.md +3 -3
- package/src/context/system-core/prompts/default.md +3 -3
- package/src/context/system-core.mjs +35 -35
- package/src/debug/logger.mjs +141 -141
- package/src/debug/model-context-dumper.mjs +52 -52
- package/src/extensions/discovery.mjs +40 -40
- package/src/extensions/lifecycle-adapter.mjs +210 -210
- package/src/extensions/lifecycle-manifest.mjs +69 -69
- package/src/image-gen/index.mjs +7 -7
- package/src/image-gen/provider.mjs +231 -231
- package/src/image-gen/tool.mjs +84 -84
- package/src/lsp/client.mjs +257 -257
- package/src/lsp/diagnostic-store.mjs +42 -42
- package/src/lsp/diagnostics-format.mjs +72 -72
- package/src/lsp/managed-node-server.mjs +99 -99
- package/src/lsp/path-match.mjs +10 -10
- package/src/lsp/server-definitions.mjs +188 -188
- package/src/lsp/servers.mjs +165 -165
- package/src/lsp/service.mjs +110 -110
- package/src/lsp/status-message.mjs +9 -9
- package/src/lsp/typescript-project-resolver.mjs +186 -186
- package/src/main.mjs +294 -299
- package/src/mcp/client.mjs +195 -195
- package/src/mcp/config.mjs +130 -130
- package/src/mcp/index.mjs +48 -48
- package/src/mcp/tools.mjs +98 -98
- package/src/memory/command.mjs +120 -0
- package/src/memory/markdown/markdown-delete.mjs +23 -23
- package/src/memory/markdown/markdown-format.mjs +128 -128
- package/src/memory/markdown/markdown-recall.mjs +28 -28
- package/src/memory/markdown/ripgrep.mjs +16 -16
- package/src/memory/markdown/sqlite-index.mjs +87 -87
- package/src/memory/markdown-store.mjs +272 -286
- package/src/memory/markdown-tools.mjs +174 -103
- package/src/memory/remote/client.mjs +68 -0
- package/src/memory/remote/config.mjs +52 -0
- package/src/memory/remote/server.mjs +99 -0
- package/src/memory/search.mjs +183 -0
- package/src/network/environment.mjs +131 -131
- package/src/notification/desktop-notifier.mjs +262 -262
- package/src/platform/open-file.mjs +28 -28
- package/src/platform/spawn-command.mjs +27 -27
- package/src/provider/accept-command.mjs +89 -89
- package/src/provider/command.mjs +21 -21
- package/src/provider/config-command.mjs +129 -129
- package/src/provider/custom-provider.mjs +113 -113
- package/src/provider/hosted-tools.mjs +111 -111
- package/src/provider/presets.mjs +72 -72
- package/src/provider/share-command.mjs +79 -79
- package/src/provider/share-payload.mjs +52 -52
- package/src/session/attachment-display.mjs +16 -16
- package/src/session/attachment-references.mjs +65 -65
- package/src/session/attachments.mjs +140 -140
- package/src/session/persist.mjs +1 -1
- package/src/session/pi-manager.mjs +34 -34
- package/src/session/session-utils.mjs +16 -16
- package/src/session/sidecar-sync.mjs +19 -19
- package/src/session/sidecar.mjs +69 -69
- package/src/session/transcript.mjs +83 -83
- package/src/session/tree.mjs +42 -42
- package/src/shell/cli-runtime.mjs +11 -11
- package/src/shell/hints.mjs +12 -12
- package/src/shell/node-pty-adapter.mjs +81 -81
- package/src/shell/runtime-state.mjs +126 -126
- package/src/shell/runtime.mjs +252 -252
- package/src/shell/screen-buffer.mjs +136 -136
- package/src/shell/tool-read.mjs +74 -74
- package/src/shell/tools.mjs +299 -299
- package/src/supergrok/actions/image-generate.mjs +60 -60
- package/src/supergrok/actions/search.mjs +78 -78
- package/src/supergrok/auth.mjs +36 -36
- package/src/supergrok/constants.mjs +18 -18
- package/src/supergrok/oauth-provider.mjs +278 -278
- package/src/supergrok/provider.mjs +35 -35
- package/src/supergrok/response.mjs +76 -76
- package/src/supergrok/tool.mjs +61 -61
- package/src/text/ansi.mjs +3 -3
- package/src/web/config-command.mjs +43 -43
- package/src/web/fetch.mjs +78 -78
- package/src/web/presets.mjs +16 -16
- package/src/web/search.mjs +83 -83
- package/src/web/tools.mjs +107 -107
|
@@ -1,278 +1,278 @@
|
|
|
1
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
-
import http from "node:http";
|
|
3
|
-
import { registerOAuthProvider } from "@earendil-works/pi-ai/oauth";
|
|
4
|
-
import {
|
|
5
|
-
SUPERGROK_OAUTH_PROVIDER_ID,
|
|
6
|
-
XAI_BASE_URL,
|
|
7
|
-
XAI_OAUTH_CLIENT_ID,
|
|
8
|
-
XAI_OAUTH_DISCOVERY_URL,
|
|
9
|
-
XAI_OAUTH_REDIRECT_HOST,
|
|
10
|
-
XAI_OAUTH_REDIRECT_PATH,
|
|
11
|
-
XAI_OAUTH_REDIRECT_PORT,
|
|
12
|
-
XAI_OAUTH_SCOPE,
|
|
13
|
-
XAI_OAUTH_COMPAT_PROVIDER_ID,
|
|
14
|
-
} from "./constants.mjs";
|
|
15
|
-
|
|
16
|
-
export function registerSuperGrokOAuthProvider() {
|
|
17
|
-
registerOAuthProvider(superGrokOAuthProvider);
|
|
18
|
-
registerOAuthProvider({ ...superGrokOAuthProvider, id: XAI_OAUTH_COMPAT_PROVIDER_ID });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const superGrokOAuthProvider = {
|
|
22
|
-
id: SUPERGROK_OAUTH_PROVIDER_ID,
|
|
23
|
-
name: "SuperGrok OAuth (xAI Subscription)",
|
|
24
|
-
usesCallbackServer: true,
|
|
25
|
-
async login(callbacks) {
|
|
26
|
-
return loginSuperGrok(callbacks);
|
|
27
|
-
},
|
|
28
|
-
async refreshToken(credentials) {
|
|
29
|
-
return refreshSuperGrokToken(credentials);
|
|
30
|
-
},
|
|
31
|
-
getApiKey(credentials) {
|
|
32
|
-
return credentials.access;
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
async function loginSuperGrok(callbacks) {
|
|
37
|
-
const discovery = await discoverXaiOAuth();
|
|
38
|
-
const verifier = createCodeVerifier();
|
|
39
|
-
const challenge = createCodeChallenge(verifier);
|
|
40
|
-
const state = randomBytes(16).toString("hex");
|
|
41
|
-
const nonce = randomBytes(16).toString("hex");
|
|
42
|
-
const redirectUri = `http://${XAI_OAUTH_REDIRECT_HOST}:${XAI_OAUTH_REDIRECT_PORT}${XAI_OAUTH_REDIRECT_PATH}`;
|
|
43
|
-
const server = await startCallbackServer(state);
|
|
44
|
-
const authorizeUrl = buildAuthorizeUrl({
|
|
45
|
-
authorizationEndpoint: discovery.authorization_endpoint,
|
|
46
|
-
redirectUri,
|
|
47
|
-
codeChallenge: challenge,
|
|
48
|
-
state,
|
|
49
|
-
nonce,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
callbacks.onAuth({
|
|
53
|
-
url: authorizeUrl,
|
|
54
|
-
instructions: `Complete the xAI authorization. Waiting for callback on ${redirectUri}`,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
let code = null;
|
|
59
|
-
if (callbacks.onManualCodeInput) {
|
|
60
|
-
let manualInput;
|
|
61
|
-
let manualError;
|
|
62
|
-
const manualPromise = callbacks.onManualCodeInput()
|
|
63
|
-
.then((input) => {
|
|
64
|
-
manualInput = input;
|
|
65
|
-
server.cancelWait();
|
|
66
|
-
})
|
|
67
|
-
.catch((err) => {
|
|
68
|
-
manualError = err instanceof Error ? err : new Error(String(err));
|
|
69
|
-
server.cancelWait();
|
|
70
|
-
});
|
|
71
|
-
const callback = await server.waitForCode();
|
|
72
|
-
if (manualError) throw manualError;
|
|
73
|
-
if (callback?.code) code = callback.code;
|
|
74
|
-
if (!code && manualInput) code = parseAuthorizationInput(manualInput, state).code;
|
|
75
|
-
if (!code) {
|
|
76
|
-
await manualPromise;
|
|
77
|
-
if (manualError) throw manualError;
|
|
78
|
-
if (manualInput) code = parseAuthorizationInput(manualInput, state).code;
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
const callback = await server.waitForCode();
|
|
82
|
-
if (callback?.code) code = callback.code;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!code) {
|
|
86
|
-
const input = await callbacks.onPrompt({ message: "Paste the xAI redirect URL or authorization code" });
|
|
87
|
-
code = parseAuthorizationInput(input, state).code;
|
|
88
|
-
}
|
|
89
|
-
if (!code) throw new Error("Missing xAI authorization code");
|
|
90
|
-
|
|
91
|
-
const token = await exchangeAuthorizationCode({
|
|
92
|
-
tokenEndpoint: discovery.token_endpoint,
|
|
93
|
-
code,
|
|
94
|
-
verifier,
|
|
95
|
-
redirectUri,
|
|
96
|
-
});
|
|
97
|
-
return normalizeTokenCredentials(token, {
|
|
98
|
-
tokenEndpoint: discovery.token_endpoint,
|
|
99
|
-
redirectUri,
|
|
100
|
-
});
|
|
101
|
-
} finally {
|
|
102
|
-
server.close();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function discoverXaiOAuth(fetchImpl = fetch) {
|
|
107
|
-
const response = await fetchImpl(XAI_OAUTH_DISCOVERY_URL, { headers: { Accept: "application/json" } });
|
|
108
|
-
if (!response.ok) throw new Error(`xAI OIDC discovery failed (${response.status})`);
|
|
109
|
-
const data = await response.json();
|
|
110
|
-
const authorizationEndpoint = String(data.authorization_endpoint || "").trim();
|
|
111
|
-
const tokenEndpoint = String(data.token_endpoint || "").trim();
|
|
112
|
-
if (!authorizationEndpoint || !tokenEndpoint) throw new Error("xAI OIDC discovery missing endpoints");
|
|
113
|
-
validateXaiAuthEndpoint(authorizationEndpoint, "authorization_endpoint");
|
|
114
|
-
validateXaiAuthEndpoint(tokenEndpoint, "token_endpoint");
|
|
115
|
-
return { authorization_endpoint: authorizationEndpoint, token_endpoint: tokenEndpoint };
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function buildAuthorizeUrl({ authorizationEndpoint, redirectUri, codeChallenge, state, nonce }) {
|
|
119
|
-
const url = new URL(authorizationEndpoint);
|
|
120
|
-
url.searchParams.set("response_type", "code");
|
|
121
|
-
url.searchParams.set("client_id", XAI_OAUTH_CLIENT_ID);
|
|
122
|
-
url.searchParams.set("redirect_uri", redirectUri);
|
|
123
|
-
url.searchParams.set("scope", XAI_OAUTH_SCOPE);
|
|
124
|
-
url.searchParams.set("code_challenge", codeChallenge);
|
|
125
|
-
url.searchParams.set("code_challenge_method", "S256");
|
|
126
|
-
url.searchParams.set("state", state);
|
|
127
|
-
url.searchParams.set("nonce", nonce);
|
|
128
|
-
url.searchParams.set("plan", "generic");
|
|
129
|
-
url.searchParams.set("referrer", "hermes-agent");
|
|
130
|
-
return url.toString();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async function exchangeAuthorizationCode({ tokenEndpoint, code, verifier, redirectUri, fetchImpl = fetch }) {
|
|
134
|
-
validateXaiAuthEndpoint(tokenEndpoint, "token_endpoint");
|
|
135
|
-
const response = await fetchImpl(tokenEndpoint, {
|
|
136
|
-
method: "POST",
|
|
137
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
138
|
-
body: new URLSearchParams({
|
|
139
|
-
grant_type: "authorization_code",
|
|
140
|
-
code,
|
|
141
|
-
redirect_uri: redirectUri,
|
|
142
|
-
client_id: XAI_OAUTH_CLIENT_ID,
|
|
143
|
-
code_verifier: verifier,
|
|
144
|
-
}),
|
|
145
|
-
});
|
|
146
|
-
if (!response.ok) {
|
|
147
|
-
const text = await response.text().catch(() => "");
|
|
148
|
-
throw new Error(`xAI token exchange failed (${response.status}): ${text || response.statusText}`);
|
|
149
|
-
}
|
|
150
|
-
return response.json();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export async function refreshSuperGrokToken(credentials, { fetchImpl = fetch } = {}) {
|
|
154
|
-
const refreshToken = credentials.refresh || credentials.refresh_token;
|
|
155
|
-
if (!refreshToken) throw new Error("SuperGrok OAuth is missing a refresh token");
|
|
156
|
-
const tokenEndpoint = String(credentials.tokenEndpoint || "").trim() || (await discoverXaiOAuth(fetchImpl)).token_endpoint;
|
|
157
|
-
validateXaiAuthEndpoint(tokenEndpoint, "token_endpoint");
|
|
158
|
-
const response = await fetchImpl(tokenEndpoint, {
|
|
159
|
-
method: "POST",
|
|
160
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
161
|
-
body: new URLSearchParams({
|
|
162
|
-
grant_type: "refresh_token",
|
|
163
|
-
client_id: XAI_OAUTH_CLIENT_ID,
|
|
164
|
-
refresh_token: refreshToken,
|
|
165
|
-
}),
|
|
166
|
-
});
|
|
167
|
-
if (!response.ok) {
|
|
168
|
-
const text = await response.text().catch(() => "");
|
|
169
|
-
throw new Error(`xAI token refresh failed (${response.status}): ${text || response.statusText}`);
|
|
170
|
-
}
|
|
171
|
-
const token = await response.json();
|
|
172
|
-
return normalizeTokenCredentials(token, {
|
|
173
|
-
tokenEndpoint,
|
|
174
|
-
redirectUri: credentials.redirectUri,
|
|
175
|
-
previousRefresh: refreshToken,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function normalizeTokenCredentials(token, { tokenEndpoint, redirectUri, previousRefresh = "" } = {}) {
|
|
180
|
-
const access = String(token.access_token || token.access || "").trim();
|
|
181
|
-
const refresh = String(token.refresh_token || token.refresh || previousRefresh || "").trim();
|
|
182
|
-
if (!access) throw new Error("xAI token response missing access_token");
|
|
183
|
-
if (!refresh) throw new Error("xAI token response missing refresh_token");
|
|
184
|
-
const expiresIn = Number(token.expires_in || 3600);
|
|
185
|
-
return {
|
|
186
|
-
access,
|
|
187
|
-
refresh,
|
|
188
|
-
expires: Date.now() + Math.max(60, expiresIn) * 1000,
|
|
189
|
-
idToken: String(token.id_token || token.idToken || ""),
|
|
190
|
-
tokenType: String(token.token_type || token.tokenType || "Bearer"),
|
|
191
|
-
tokenEndpoint,
|
|
192
|
-
redirectUri,
|
|
193
|
-
baseUrl: XAI_BASE_URL,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function startCallbackServer(expectedState) {
|
|
198
|
-
let settle;
|
|
199
|
-
const waitForCodePromise = new Promise((resolve) => {
|
|
200
|
-
settle = resolve;
|
|
201
|
-
});
|
|
202
|
-
const server = http.createServer((req, res) => {
|
|
203
|
-
const url = new URL(req.url || "/", `http://${XAI_OAUTH_REDIRECT_HOST}:${XAI_OAUTH_REDIRECT_PORT}`);
|
|
204
|
-
if (url.pathname !== XAI_OAUTH_REDIRECT_PATH) {
|
|
205
|
-
res.writeHead(404, { "Content-Type": "text/html; charset=utf-8" });
|
|
206
|
-
res.end("Callback route not found.");
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
if (url.searchParams.get("state") !== expectedState) {
|
|
210
|
-
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
211
|
-
res.end("State mismatch.");
|
|
212
|
-
settle(null);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const code = url.searchParams.get("code");
|
|
216
|
-
const error = url.searchParams.get("error");
|
|
217
|
-
if (!code && error) {
|
|
218
|
-
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
219
|
-
res.end(`xAI authorization failed: ${error}`);
|
|
220
|
-
settle(null);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
224
|
-
res.end("SuperGrok authentication completed. You can close this window.");
|
|
225
|
-
settle({ code });
|
|
226
|
-
});
|
|
227
|
-
return new Promise((resolve) => {
|
|
228
|
-
server.listen(XAI_OAUTH_REDIRECT_PORT, XAI_OAUTH_REDIRECT_HOST, () => {
|
|
229
|
-
resolve({
|
|
230
|
-
close: () => server.close(),
|
|
231
|
-
cancelWait: () => settle(null),
|
|
232
|
-
waitForCode: () => waitForCodePromise,
|
|
233
|
-
});
|
|
234
|
-
}).on("error", () => {
|
|
235
|
-
settle(null);
|
|
236
|
-
resolve({ close: () => {}, cancelWait: () => settle(null), waitForCode: () => waitForCodePromise });
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function parseAuthorizationInput(input, expectedState) {
|
|
242
|
-
const value = String(input || "").trim();
|
|
243
|
-
if (!value) return {};
|
|
244
|
-
try {
|
|
245
|
-
const url = new URL(value);
|
|
246
|
-
const state = url.searchParams.get("state") || undefined;
|
|
247
|
-
if (state && state !== expectedState) throw new Error("State mismatch");
|
|
248
|
-
return { code: url.searchParams.get("code") || undefined };
|
|
249
|
-
} catch (err) {
|
|
250
|
-
if (err.message === "State mismatch") throw err;
|
|
251
|
-
}
|
|
252
|
-
if (value.includes("code=")) {
|
|
253
|
-
const params = new URLSearchParams(value);
|
|
254
|
-
const state = params.get("state") || undefined;
|
|
255
|
-
if (state && state !== expectedState) throw new Error("State mismatch");
|
|
256
|
-
return { code: params.get("code") || undefined };
|
|
257
|
-
}
|
|
258
|
-
return { code: value };
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function createCodeVerifier() {
|
|
262
|
-
return base64Url(randomBytes(32));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function createCodeChallenge(verifier) {
|
|
266
|
-
return base64Url(createHash("sha256").update(verifier).digest());
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function base64Url(buffer) {
|
|
270
|
-
return Buffer.from(buffer).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function validateXaiAuthEndpoint(value, field) {
|
|
274
|
-
const url = new URL(value);
|
|
275
|
-
if (url.protocol !== "https:" || !url.hostname.endsWith("x.ai")) {
|
|
276
|
-
throw new Error(`Invalid xAI OAuth ${field}: ${value}`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import { registerOAuthProvider } from "@earendil-works/pi-ai/oauth";
|
|
4
|
+
import {
|
|
5
|
+
SUPERGROK_OAUTH_PROVIDER_ID,
|
|
6
|
+
XAI_BASE_URL,
|
|
7
|
+
XAI_OAUTH_CLIENT_ID,
|
|
8
|
+
XAI_OAUTH_DISCOVERY_URL,
|
|
9
|
+
XAI_OAUTH_REDIRECT_HOST,
|
|
10
|
+
XAI_OAUTH_REDIRECT_PATH,
|
|
11
|
+
XAI_OAUTH_REDIRECT_PORT,
|
|
12
|
+
XAI_OAUTH_SCOPE,
|
|
13
|
+
XAI_OAUTH_COMPAT_PROVIDER_ID,
|
|
14
|
+
} from "./constants.mjs";
|
|
15
|
+
|
|
16
|
+
export function registerSuperGrokOAuthProvider() {
|
|
17
|
+
registerOAuthProvider(superGrokOAuthProvider);
|
|
18
|
+
registerOAuthProvider({ ...superGrokOAuthProvider, id: XAI_OAUTH_COMPAT_PROVIDER_ID });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const superGrokOAuthProvider = {
|
|
22
|
+
id: SUPERGROK_OAUTH_PROVIDER_ID,
|
|
23
|
+
name: "SuperGrok OAuth (xAI Subscription)",
|
|
24
|
+
usesCallbackServer: true,
|
|
25
|
+
async login(callbacks) {
|
|
26
|
+
return loginSuperGrok(callbacks);
|
|
27
|
+
},
|
|
28
|
+
async refreshToken(credentials) {
|
|
29
|
+
return refreshSuperGrokToken(credentials);
|
|
30
|
+
},
|
|
31
|
+
getApiKey(credentials) {
|
|
32
|
+
return credentials.access;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
async function loginSuperGrok(callbacks) {
|
|
37
|
+
const discovery = await discoverXaiOAuth();
|
|
38
|
+
const verifier = createCodeVerifier();
|
|
39
|
+
const challenge = createCodeChallenge(verifier);
|
|
40
|
+
const state = randomBytes(16).toString("hex");
|
|
41
|
+
const nonce = randomBytes(16).toString("hex");
|
|
42
|
+
const redirectUri = `http://${XAI_OAUTH_REDIRECT_HOST}:${XAI_OAUTH_REDIRECT_PORT}${XAI_OAUTH_REDIRECT_PATH}`;
|
|
43
|
+
const server = await startCallbackServer(state);
|
|
44
|
+
const authorizeUrl = buildAuthorizeUrl({
|
|
45
|
+
authorizationEndpoint: discovery.authorization_endpoint,
|
|
46
|
+
redirectUri,
|
|
47
|
+
codeChallenge: challenge,
|
|
48
|
+
state,
|
|
49
|
+
nonce,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
callbacks.onAuth({
|
|
53
|
+
url: authorizeUrl,
|
|
54
|
+
instructions: `Complete the xAI authorization. Waiting for callback on ${redirectUri}`,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
let code = null;
|
|
59
|
+
if (callbacks.onManualCodeInput) {
|
|
60
|
+
let manualInput;
|
|
61
|
+
let manualError;
|
|
62
|
+
const manualPromise = callbacks.onManualCodeInput()
|
|
63
|
+
.then((input) => {
|
|
64
|
+
manualInput = input;
|
|
65
|
+
server.cancelWait();
|
|
66
|
+
})
|
|
67
|
+
.catch((err) => {
|
|
68
|
+
manualError = err instanceof Error ? err : new Error(String(err));
|
|
69
|
+
server.cancelWait();
|
|
70
|
+
});
|
|
71
|
+
const callback = await server.waitForCode();
|
|
72
|
+
if (manualError) throw manualError;
|
|
73
|
+
if (callback?.code) code = callback.code;
|
|
74
|
+
if (!code && manualInput) code = parseAuthorizationInput(manualInput, state).code;
|
|
75
|
+
if (!code) {
|
|
76
|
+
await manualPromise;
|
|
77
|
+
if (manualError) throw manualError;
|
|
78
|
+
if (manualInput) code = parseAuthorizationInput(manualInput, state).code;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
const callback = await server.waitForCode();
|
|
82
|
+
if (callback?.code) code = callback.code;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!code) {
|
|
86
|
+
const input = await callbacks.onPrompt({ message: "Paste the xAI redirect URL or authorization code" });
|
|
87
|
+
code = parseAuthorizationInput(input, state).code;
|
|
88
|
+
}
|
|
89
|
+
if (!code) throw new Error("Missing xAI authorization code");
|
|
90
|
+
|
|
91
|
+
const token = await exchangeAuthorizationCode({
|
|
92
|
+
tokenEndpoint: discovery.token_endpoint,
|
|
93
|
+
code,
|
|
94
|
+
verifier,
|
|
95
|
+
redirectUri,
|
|
96
|
+
});
|
|
97
|
+
return normalizeTokenCredentials(token, {
|
|
98
|
+
tokenEndpoint: discovery.token_endpoint,
|
|
99
|
+
redirectUri,
|
|
100
|
+
});
|
|
101
|
+
} finally {
|
|
102
|
+
server.close();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function discoverXaiOAuth(fetchImpl = fetch) {
|
|
107
|
+
const response = await fetchImpl(XAI_OAUTH_DISCOVERY_URL, { headers: { Accept: "application/json" } });
|
|
108
|
+
if (!response.ok) throw new Error(`xAI OIDC discovery failed (${response.status})`);
|
|
109
|
+
const data = await response.json();
|
|
110
|
+
const authorizationEndpoint = String(data.authorization_endpoint || "").trim();
|
|
111
|
+
const tokenEndpoint = String(data.token_endpoint || "").trim();
|
|
112
|
+
if (!authorizationEndpoint || !tokenEndpoint) throw new Error("xAI OIDC discovery missing endpoints");
|
|
113
|
+
validateXaiAuthEndpoint(authorizationEndpoint, "authorization_endpoint");
|
|
114
|
+
validateXaiAuthEndpoint(tokenEndpoint, "token_endpoint");
|
|
115
|
+
return { authorization_endpoint: authorizationEndpoint, token_endpoint: tokenEndpoint };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function buildAuthorizeUrl({ authorizationEndpoint, redirectUri, codeChallenge, state, nonce }) {
|
|
119
|
+
const url = new URL(authorizationEndpoint);
|
|
120
|
+
url.searchParams.set("response_type", "code");
|
|
121
|
+
url.searchParams.set("client_id", XAI_OAUTH_CLIENT_ID);
|
|
122
|
+
url.searchParams.set("redirect_uri", redirectUri);
|
|
123
|
+
url.searchParams.set("scope", XAI_OAUTH_SCOPE);
|
|
124
|
+
url.searchParams.set("code_challenge", codeChallenge);
|
|
125
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
126
|
+
url.searchParams.set("state", state);
|
|
127
|
+
url.searchParams.set("nonce", nonce);
|
|
128
|
+
url.searchParams.set("plan", "generic");
|
|
129
|
+
url.searchParams.set("referrer", "hermes-agent");
|
|
130
|
+
return url.toString();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function exchangeAuthorizationCode({ tokenEndpoint, code, verifier, redirectUri, fetchImpl = fetch }) {
|
|
134
|
+
validateXaiAuthEndpoint(tokenEndpoint, "token_endpoint");
|
|
135
|
+
const response = await fetchImpl(tokenEndpoint, {
|
|
136
|
+
method: "POST",
|
|
137
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
138
|
+
body: new URLSearchParams({
|
|
139
|
+
grant_type: "authorization_code",
|
|
140
|
+
code,
|
|
141
|
+
redirect_uri: redirectUri,
|
|
142
|
+
client_id: XAI_OAUTH_CLIENT_ID,
|
|
143
|
+
code_verifier: verifier,
|
|
144
|
+
}),
|
|
145
|
+
});
|
|
146
|
+
if (!response.ok) {
|
|
147
|
+
const text = await response.text().catch(() => "");
|
|
148
|
+
throw new Error(`xAI token exchange failed (${response.status}): ${text || response.statusText}`);
|
|
149
|
+
}
|
|
150
|
+
return response.json();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function refreshSuperGrokToken(credentials, { fetchImpl = fetch } = {}) {
|
|
154
|
+
const refreshToken = credentials.refresh || credentials.refresh_token;
|
|
155
|
+
if (!refreshToken) throw new Error("SuperGrok OAuth is missing a refresh token");
|
|
156
|
+
const tokenEndpoint = String(credentials.tokenEndpoint || "").trim() || (await discoverXaiOAuth(fetchImpl)).token_endpoint;
|
|
157
|
+
validateXaiAuthEndpoint(tokenEndpoint, "token_endpoint");
|
|
158
|
+
const response = await fetchImpl(tokenEndpoint, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
161
|
+
body: new URLSearchParams({
|
|
162
|
+
grant_type: "refresh_token",
|
|
163
|
+
client_id: XAI_OAUTH_CLIENT_ID,
|
|
164
|
+
refresh_token: refreshToken,
|
|
165
|
+
}),
|
|
166
|
+
});
|
|
167
|
+
if (!response.ok) {
|
|
168
|
+
const text = await response.text().catch(() => "");
|
|
169
|
+
throw new Error(`xAI token refresh failed (${response.status}): ${text || response.statusText}`);
|
|
170
|
+
}
|
|
171
|
+
const token = await response.json();
|
|
172
|
+
return normalizeTokenCredentials(token, {
|
|
173
|
+
tokenEndpoint,
|
|
174
|
+
redirectUri: credentials.redirectUri,
|
|
175
|
+
previousRefresh: refreshToken,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function normalizeTokenCredentials(token, { tokenEndpoint, redirectUri, previousRefresh = "" } = {}) {
|
|
180
|
+
const access = String(token.access_token || token.access || "").trim();
|
|
181
|
+
const refresh = String(token.refresh_token || token.refresh || previousRefresh || "").trim();
|
|
182
|
+
if (!access) throw new Error("xAI token response missing access_token");
|
|
183
|
+
if (!refresh) throw new Error("xAI token response missing refresh_token");
|
|
184
|
+
const expiresIn = Number(token.expires_in || 3600);
|
|
185
|
+
return {
|
|
186
|
+
access,
|
|
187
|
+
refresh,
|
|
188
|
+
expires: Date.now() + Math.max(60, expiresIn) * 1000,
|
|
189
|
+
idToken: String(token.id_token || token.idToken || ""),
|
|
190
|
+
tokenType: String(token.token_type || token.tokenType || "Bearer"),
|
|
191
|
+
tokenEndpoint,
|
|
192
|
+
redirectUri,
|
|
193
|
+
baseUrl: XAI_BASE_URL,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function startCallbackServer(expectedState) {
|
|
198
|
+
let settle;
|
|
199
|
+
const waitForCodePromise = new Promise((resolve) => {
|
|
200
|
+
settle = resolve;
|
|
201
|
+
});
|
|
202
|
+
const server = http.createServer((req, res) => {
|
|
203
|
+
const url = new URL(req.url || "/", `http://${XAI_OAUTH_REDIRECT_HOST}:${XAI_OAUTH_REDIRECT_PORT}`);
|
|
204
|
+
if (url.pathname !== XAI_OAUTH_REDIRECT_PATH) {
|
|
205
|
+
res.writeHead(404, { "Content-Type": "text/html; charset=utf-8" });
|
|
206
|
+
res.end("Callback route not found.");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (url.searchParams.get("state") !== expectedState) {
|
|
210
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
211
|
+
res.end("State mismatch.");
|
|
212
|
+
settle(null);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const code = url.searchParams.get("code");
|
|
216
|
+
const error = url.searchParams.get("error");
|
|
217
|
+
if (!code && error) {
|
|
218
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
219
|
+
res.end(`xAI authorization failed: ${error}`);
|
|
220
|
+
settle(null);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
224
|
+
res.end("SuperGrok authentication completed. You can close this window.");
|
|
225
|
+
settle({ code });
|
|
226
|
+
});
|
|
227
|
+
return new Promise((resolve) => {
|
|
228
|
+
server.listen(XAI_OAUTH_REDIRECT_PORT, XAI_OAUTH_REDIRECT_HOST, () => {
|
|
229
|
+
resolve({
|
|
230
|
+
close: () => server.close(),
|
|
231
|
+
cancelWait: () => settle(null),
|
|
232
|
+
waitForCode: () => waitForCodePromise,
|
|
233
|
+
});
|
|
234
|
+
}).on("error", () => {
|
|
235
|
+
settle(null);
|
|
236
|
+
resolve({ close: () => {}, cancelWait: () => settle(null), waitForCode: () => waitForCodePromise });
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function parseAuthorizationInput(input, expectedState) {
|
|
242
|
+
const value = String(input || "").trim();
|
|
243
|
+
if (!value) return {};
|
|
244
|
+
try {
|
|
245
|
+
const url = new URL(value);
|
|
246
|
+
const state = url.searchParams.get("state") || undefined;
|
|
247
|
+
if (state && state !== expectedState) throw new Error("State mismatch");
|
|
248
|
+
return { code: url.searchParams.get("code") || undefined };
|
|
249
|
+
} catch (err) {
|
|
250
|
+
if (err.message === "State mismatch") throw err;
|
|
251
|
+
}
|
|
252
|
+
if (value.includes("code=")) {
|
|
253
|
+
const params = new URLSearchParams(value);
|
|
254
|
+
const state = params.get("state") || undefined;
|
|
255
|
+
if (state && state !== expectedState) throw new Error("State mismatch");
|
|
256
|
+
return { code: params.get("code") || undefined };
|
|
257
|
+
}
|
|
258
|
+
return { code: value };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function createCodeVerifier() {
|
|
262
|
+
return base64Url(randomBytes(32));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function createCodeChallenge(verifier) {
|
|
266
|
+
return base64Url(createHash("sha256").update(verifier).digest());
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function base64Url(buffer) {
|
|
270
|
+
return Buffer.from(buffer).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function validateXaiAuthEndpoint(value, field) {
|
|
274
|
+
const url = new URL(value);
|
|
275
|
+
if (url.protocol !== "https:" || !url.hostname.endsWith("x.ai")) {
|
|
276
|
+
throw new Error(`Invalid xAI OAuth ${field}: ${value}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { DEFAULT_SUPERGROK_MODEL, SUPERGROK_OAUTH_PROVIDER_ID, XAI_BASE_URL, XAI_OAUTH_COMPAT_PROVIDER_ID } from "./constants.mjs";
|
|
2
|
-
import { registerSuperGrokOAuthProvider, superGrokOAuthProvider } from "./oauth-provider.mjs";
|
|
3
|
-
|
|
4
|
-
const GROK_MODELS = [
|
|
5
|
-
{ id: "grok-4.3", name: "Grok 4.3", contextWindow: 1000000, maxTokens: 128000 },
|
|
6
|
-
{ id: "grok-4.20-reasoning", name: "Grok 4.20 Reasoning", contextWindow: 2000000, maxTokens: 128000 },
|
|
7
|
-
{ id: "grok-4.20-non-reasoning", name: "Grok 4.20 Non Reasoning", contextWindow: 2000000, maxTokens: 128000 },
|
|
8
|
-
{ id: "grok-4.20-multi-agent", name: "Grok 4.20 Multi Agent", contextWindow: 2000000, maxTokens: 128000 },
|
|
9
|
-
{ id: "grok-code-fast-1", name: "Grok Code Fast 1", contextWindow: 256000, maxTokens: 128000 },
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
export function registerSuperGrokProvider(modelRegistry) {
|
|
13
|
-
registerSuperGrokOAuthProvider();
|
|
14
|
-
if (!modelRegistry?.registerProvider) return;
|
|
15
|
-
for (const providerId of [SUPERGROK_OAUTH_PROVIDER_ID, XAI_OAUTH_COMPAT_PROVIDER_ID]) {
|
|
16
|
-
modelRegistry.registerProvider(providerId, {
|
|
17
|
-
name: providerId === SUPERGROK_OAUTH_PROVIDER_ID ? "SuperGrok" : "xAI OAuth",
|
|
18
|
-
baseUrl: XAI_BASE_URL,
|
|
19
|
-
api: "openai-responses",
|
|
20
|
-
oauth: { ...superGrokOAuthProvider, id: providerId },
|
|
21
|
-
models: GROK_MODELS.map((model) => ({
|
|
22
|
-
...model,
|
|
23
|
-
api: "openai-responses",
|
|
24
|
-
baseUrl: XAI_BASE_URL,
|
|
25
|
-
reasoning: false,
|
|
26
|
-
input: ["text"],
|
|
27
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
28
|
-
compat: { supportsLongCacheRetention: true },
|
|
29
|
-
})),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function getDefaultSuperGrokModelId() {
|
|
35
|
-
return DEFAULT_SUPERGROK_MODEL;
|
|
1
|
+
import { DEFAULT_SUPERGROK_MODEL, SUPERGROK_OAUTH_PROVIDER_ID, XAI_BASE_URL, XAI_OAUTH_COMPAT_PROVIDER_ID } from "./constants.mjs";
|
|
2
|
+
import { registerSuperGrokOAuthProvider, superGrokOAuthProvider } from "./oauth-provider.mjs";
|
|
3
|
+
|
|
4
|
+
const GROK_MODELS = [
|
|
5
|
+
{ id: "grok-4.3", name: "Grok 4.3", contextWindow: 1000000, maxTokens: 128000 },
|
|
6
|
+
{ id: "grok-4.20-reasoning", name: "Grok 4.20 Reasoning", contextWindow: 2000000, maxTokens: 128000 },
|
|
7
|
+
{ id: "grok-4.20-non-reasoning", name: "Grok 4.20 Non Reasoning", contextWindow: 2000000, maxTokens: 128000 },
|
|
8
|
+
{ id: "grok-4.20-multi-agent", name: "Grok 4.20 Multi Agent", contextWindow: 2000000, maxTokens: 128000 },
|
|
9
|
+
{ id: "grok-code-fast-1", name: "Grok Code Fast 1", contextWindow: 256000, maxTokens: 128000 },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export function registerSuperGrokProvider(modelRegistry) {
|
|
13
|
+
registerSuperGrokOAuthProvider();
|
|
14
|
+
if (!modelRegistry?.registerProvider) return;
|
|
15
|
+
for (const providerId of [SUPERGROK_OAUTH_PROVIDER_ID, XAI_OAUTH_COMPAT_PROVIDER_ID]) {
|
|
16
|
+
modelRegistry.registerProvider(providerId, {
|
|
17
|
+
name: providerId === SUPERGROK_OAUTH_PROVIDER_ID ? "SuperGrok" : "xAI OAuth",
|
|
18
|
+
baseUrl: XAI_BASE_URL,
|
|
19
|
+
api: "openai-responses",
|
|
20
|
+
oauth: { ...superGrokOAuthProvider, id: providerId },
|
|
21
|
+
models: GROK_MODELS.map((model) => ({
|
|
22
|
+
...model,
|
|
23
|
+
api: "openai-responses",
|
|
24
|
+
baseUrl: XAI_BASE_URL,
|
|
25
|
+
reasoning: false,
|
|
26
|
+
input: ["text"],
|
|
27
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
28
|
+
compat: { supportsLongCacheRetention: true },
|
|
29
|
+
})),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getDefaultSuperGrokModelId() {
|
|
35
|
+
return DEFAULT_SUPERGROK_MODEL;
|
|
36
36
|
}
|