mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-17 20:32:25 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
144 lines
4.5 KiB
TypeScript
144 lines
4.5 KiB
TypeScript
import { getRuntimeArch, getRuntimePlatform } from "./providerHeaderProfiles.ts";
|
|
|
|
export const GROK_BUILD_PROXY_BASE_URL = "https://cli-chat-proxy.grok.com/v1";
|
|
export const GROK_BUILD_RESPONSES_URL = `${GROK_BUILD_PROXY_BASE_URL}/responses`;
|
|
export const GROK_BUILD_MODELS_URL = `${GROK_BUILD_PROXY_BASE_URL}/models`;
|
|
|
|
export const GROK_BUILD_OAUTH_ISSUER = "https://auth.x.ai";
|
|
export const GROK_BUILD_DEVICE_CODE_URL = `${GROK_BUILD_OAUTH_ISSUER}/oauth2/device/code`;
|
|
export const GROK_BUILD_TOKEN_URL = `${GROK_BUILD_OAUTH_ISSUER}/oauth2/token`;
|
|
|
|
export const GROK_BUILD_DEFAULT_CLIENT_VERSION = "0.2.106";
|
|
export const GROK_BUILD_DEFAULT_CONTEXT_WINDOW = 256_000;
|
|
export const GROK_BUILD_DEFAULT_REASONING_EFFORT = "high";
|
|
export const GROK_BUILD_SUPPORTED_REASONING_EFFORTS = Object.freeze(["low", "medium", "high"]);
|
|
export const GROK_BUILD_CLIENT_IDENTIFIER = "grok-shell";
|
|
export const GROK_BUILD_TOKEN_AUTH = "xai-grok-cli";
|
|
export const GROK_BUILD_REASONING_INCLUDE = "reasoning.encrypted_content";
|
|
export const GROK_BUILD_OAUTH_REFERRER = "grok-build";
|
|
|
|
export const GROK_BUILD_OAUTH_SCOPES = Object.freeze([
|
|
"openid",
|
|
"profile",
|
|
"email",
|
|
"offline_access",
|
|
"grok-cli:access",
|
|
"api:access",
|
|
"conversations:read",
|
|
"conversations:write",
|
|
"workspaces:read",
|
|
"workspaces:write",
|
|
]);
|
|
|
|
export type GrokBuildClientMode = "headless" | "interactive";
|
|
export type GrokBuildClientSurface = "ui" | "cli" | "headless";
|
|
|
|
export type GrokBuildSessionHeaderOptions = {
|
|
token?: string | null;
|
|
model?: string | null;
|
|
stream?: boolean;
|
|
clientMode?: GrokBuildClientMode;
|
|
userId?: string | null;
|
|
email?: string | null;
|
|
principalType?: string | null;
|
|
};
|
|
|
|
function getWireEmail(email?: string | null, principalType?: string | null): string | null {
|
|
const normalizedPrincipalType = principalType?.trim().toLowerCase();
|
|
return normalizedPrincipalType === "team" || normalizedPrincipalType === "organization"
|
|
? null
|
|
: email || null;
|
|
}
|
|
|
|
function mapPlatform(platform: string): string {
|
|
if (platform === "darwin") return "macos";
|
|
if (platform === "win32") return "windows";
|
|
return platform;
|
|
}
|
|
|
|
function mapArch(arch: string): string {
|
|
if (arch === "arm64") return "aarch64";
|
|
if (arch === "x64") return "x86_64";
|
|
return arch;
|
|
}
|
|
|
|
export function getGrokBuildClientVersion(): string {
|
|
return GROK_BUILD_DEFAULT_CLIENT_VERSION;
|
|
}
|
|
|
|
export function getGrokBuildUserAgent(): string {
|
|
return `${GROK_BUILD_CLIENT_IDENTIFIER}/${getGrokBuildClientVersion()} (${mapPlatform(
|
|
getRuntimePlatform()
|
|
)}; ${mapArch(getRuntimeArch())})`;
|
|
}
|
|
|
|
export function getGrokBuildClientHeaders(
|
|
clientMode: GrokBuildClientMode = "headless"
|
|
): Record<string, string> {
|
|
return {
|
|
"x-grok-client-version": getGrokBuildClientVersion(),
|
|
"x-grok-client-identifier": GROK_BUILD_CLIENT_IDENTIFIER,
|
|
"x-grok-client-mode": clientMode,
|
|
"User-Agent": getGrokBuildUserAgent(),
|
|
};
|
|
}
|
|
|
|
export function getGrokBuildSessionHeaders({
|
|
token,
|
|
model,
|
|
stream = false,
|
|
clientMode = "headless",
|
|
userId,
|
|
email,
|
|
principalType,
|
|
}: GrokBuildSessionHeaderOptions = {}): Record<string, string> {
|
|
const wireEmail = getWireEmail(email, principalType);
|
|
return {
|
|
"Content-Type": "application/json",
|
|
Accept: stream ? "text/event-stream" : "application/json",
|
|
...getGrokBuildClientHeaders(clientMode),
|
|
"X-XAI-Token-Auth": GROK_BUILD_TOKEN_AUTH,
|
|
"x-authenticateresponse": "authenticate-response",
|
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
...(model ? { "x-grok-model-override": model } : {}),
|
|
...(userId
|
|
? {
|
|
"x-userid": userId,
|
|
"x-grok-user-id": userId,
|
|
}
|
|
: {}),
|
|
...(wireEmail ? { "x-email": wireEmail } : {}),
|
|
};
|
|
}
|
|
|
|
export function getGrokBuildOAuthHeaders(
|
|
surface: GrokBuildClientSurface = "ui"
|
|
): Record<string, string> {
|
|
return {
|
|
Accept: "application/json",
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
"x-grok-client-version": getGrokBuildClientVersion(),
|
|
"x-grok-client-surface": surface,
|
|
};
|
|
}
|
|
|
|
export function getGrokBuildModelsHeaders({
|
|
token,
|
|
userId,
|
|
email,
|
|
principalType,
|
|
}: Pick<GrokBuildSessionHeaderOptions, "token" | "userId" | "email" | "principalType">): Record<
|
|
string,
|
|
string
|
|
> {
|
|
const wireEmail = getWireEmail(email, principalType);
|
|
return {
|
|
Accept: "application/json",
|
|
...getGrokBuildClientHeaders("headless"),
|
|
"X-XAI-Token-Auth": GROK_BUILD_TOKEN_AUTH,
|
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
...(userId ? { "x-userid": userId } : {}),
|
|
...(wireEmail ? { "x-email": wireEmail } : {}),
|
|
};
|
|
}
|