mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-19 21:52:21 +03:00
* test: resolve typescript strictness complaints in unit tests * Update Claude Code obfuscation to version 2.1.114 (#1403) * fix(cloud-code): scope thinking stripping to executor boundaries (#1401) * fix(cloud-code): scope thinking stripping to executors * fix(cloud-code): guard antigravity normalized body * Update Claude Code obfuscation to version 2.1.114 - Update Claude Code version from 2.1.87 to 2.1.114 - Update X-Stainless-Package-Version from 0.80.0 to 0.81.0 - Add new beta flags: redact-thinking-2026-02-12, advisor-tool-2026-03-01, advanced-tool-use-2025-11-20 - Add missing headers: anthropic-version, anthropic-dangerous-direct-browser-access, x-app, X-Stainless-Timeout - Add all X-Stainless-* headers (Arch, Lang, OS, Runtime, Runtime-Version, Retry-Count) - Fix accept-encoding header: identity -> gzip, deflate, br, zstd - Add connection: keep-alive header - Update tool name mapping: add lsp, apply_patch, websearch These changes ensure that requests from OpenCode through Omniroute are indistinguishable from genuine Claude Code 2.1.114 requests, allowing proper authentication with Anthropic's API without triggering extra credits errors. * fix: resolve CodeQL password hash alert and TruffleHog CI failure --------- Co-authored-by: Randi <55005611+rdself@users.noreply.github.com> Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com> Co-authored-by: Nikolay Popov <ekklesio.dev@gmail.com> Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com> * fix(claude-code): scope obfuscation to cli clients and fix tests * docs(workflows): enforce PR merge instead of manual close * docs(changelog): update 3.6.9 notes with missing PR 1403 and fixes * docs(workflows): update generate-release to use full changelog for PR body * fix(tsc): silence baseUrl deprecation warnings for TS 5.5+ * fix(chatcore): apply proactive compression before provider translation (#1406) Integrated into release/v3.6.9 * docs(changelog): add PR 1406 * Makes text visible in dark-mode (#1409) Integrated into release/v3.6.9 * docs(changelog): add PR 1409 * chore: save local work * chore(release): sync version references to 3.6.9 * fix(codex): prevent proactive token refresh consumption and strip background parameter * ci: shard long-running suites and relax timeouts * ci: allow manual CI dispatch for release branches * feat(skills): provider-aware marketplace UX, scored AUTO injection, and memory pipeline hardening (#1411) * fix/400 for GeminiCLI(add "ref" in GEMINI_UNSUPPORTED_SCHEMA_KEYS) * feat(cc-compatible): align request shape with Claude CLI * fix(cc-compatible): add Claude CLI system skeleton for OpenAI input * preserve reasoning when translating chat to responses (#1414) Integrated into release/v3.6.9 * fix(skills): optimize AUTO scoring and include Responses input context (#1418) Integrated into release/v3.6.9 * chore: fix TS errors and update review-prs workflow * fix(api): stop sending unsupported Gemini and Codex parameters Prevent Gemini request translation from injecting default thoughtSignature values that the upstream API strictly validates and rejects. Only preserve real signatures resolved from prior upstream responses, and strip additionalProperties from Gemini function schemas to avoid 400 "Unknown name" errors. Also remove fallback-injected session_id and conversation_id fields before sending Codex requests, and restore compatibility with the legacy OUTBOUND_SSRF_GUARD_ENABLED flag when determining whether private provider URLs are allowed. Updates the Gemini translator and regression tests for issue #1410 and related 400 error cases. * fix(core): stabilization fixes for token refresh, usage translation, and testing - Update Codex token refresh detection logic - Mark provider connections invalid on unrecoverable refresh error - Fix Claude usage translation under-reporting cached tokens - Update test expectations - Update CHANGELOG.md for v3.6.9 * fix(auth): reload fresh token state and unify expiry persistence Refresh checks now re-read the latest stored provider connection before attempting rotation so they do not use stale refresh tokens captured by an earlier sweep. Token updates also persist both expiresAt and tokenExpiresAt across the health check, usage-limit refresh path, and SSE refresh flow. This keeps known token expiry metadata in sync and avoids interval-based refreshes for connections whose tokens are still valid well into the future. * fix: resolve SSRF environment static evaluation bug (#1427) Fix import aliases and strict TS typings for tests and ACP agents. * test: resolve remaining strict type errors in test files * test: fix provider service assertion for anthropic-compatible header * fix(codex): respect openaiStoreEnabled setting during native passthrough (#1432) * fix(codex): fix token refresh unrecoverable detection for expired tokens * fix(ci): restore release v3.6.9 build and flaky tests * fix(cc-compatible): trim default OpenAI system skeleton (#1433) Integrated into release/v3.6.9 * fix: prevent masked API keys from being written to CLI tool configs (#1435) * feat: mark Qwen provider as deprecated and add deprecation warning to CLI tool (#1437) * docs(changelog): comprehensive v3.6.9 update with all 59 commits since v3.6.8 * test(ci): align qwen guide settings assertions * fix(security): resolve CodeQL alert 163 for incomplete URL sanitization in Qwen CLI settings --------- Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com> Co-authored-by: Nikolay Popov <74762779+nikolay-popov-ideogram@users.noreply.github.com> Co-authored-by: Randi <55005611+rdself@users.noreply.github.com> Co-authored-by: Nikolay Popov <ekklesio.dev@gmail.com> Co-authored-by: Paijo <14921983+oyi77@users.noreply.github.com> Co-authored-by: Tim Massey <tim-massey@users.noreply.github.com> Co-authored-by: Paijo <oyi77@users.noreply.github.com> Co-authored-by: dail45 <dail45@yandex.ru> Co-authored-by: R.D. <rogerproself@gmail.com>
365 lines
9.2 KiB
TypeScript
365 lines
9.2 KiB
TypeScript
/**
|
|
* CLI Fingerprint Definitions
|
|
*
|
|
* Defines per-provider "fingerprints" that control the exact ordering of HTTP headers
|
|
* and JSON body fields to match the native CLI tools exactly.
|
|
*
|
|
* When `cliCompatMode` is enabled for a provider, OmniRoute reorders outgoing requests
|
|
* to be indistinguishable from the real CLI binary, reducing account flagging risk.
|
|
*
|
|
* Header order and body field order were captured via mitmproxy traffic analysis.
|
|
*/
|
|
import { isClaudeCodeCompatible } from "../services/provider.ts";
|
|
import {
|
|
getAntigravityUserAgent,
|
|
GITHUB_COPILOT_CHAT_USER_AGENT,
|
|
getQwenOauthHeaders,
|
|
} from "./providerHeaderProfiles.ts";
|
|
|
|
export interface CliFingerprint {
|
|
/** Ordered list of header names (case-sensitive). Unlisted headers are appended. */
|
|
headerOrder: string[];
|
|
/** Ordered list of top-level JSON body fields. Unlisted fields are appended. */
|
|
bodyFieldOrder: string[];
|
|
/** User-Agent string to inject (overrides default) */
|
|
userAgent?: string;
|
|
/** Extra headers to add */
|
|
extraHeaders?: Record<string, string>;
|
|
}
|
|
|
|
/**
|
|
* Fingerprint registry - keyed by provider alias (lowercase).
|
|
* Based on mitmproxy traffic captures from native CLI tools.
|
|
*/
|
|
export const CLI_FINGERPRINTS: Record<string, CliFingerprint> = {
|
|
codex: {
|
|
headerOrder: [
|
|
"Host",
|
|
"Content-Type",
|
|
"Authorization",
|
|
"Accept",
|
|
"User-Agent",
|
|
"Accept-Encoding",
|
|
],
|
|
bodyFieldOrder: [
|
|
"model",
|
|
"messages",
|
|
"temperature",
|
|
"top_p",
|
|
"max_tokens",
|
|
"stream",
|
|
"tools",
|
|
"tool_choice",
|
|
"response_format",
|
|
"n",
|
|
"stop",
|
|
],
|
|
userAgent: "codex-cli",
|
|
},
|
|
claude: {
|
|
headerOrder: [
|
|
"Host",
|
|
"Content-Type",
|
|
"x-api-key",
|
|
"anthropic-version",
|
|
"anthropic-beta",
|
|
"anthropic-dangerous-direct-browser-access",
|
|
"x-app",
|
|
"User-Agent",
|
|
"X-Claude-Code-Session-Id",
|
|
"x-client-request-id",
|
|
"X-Stainless-Retry-Count",
|
|
"X-Stainless-Timeout",
|
|
"X-Stainless-Lang",
|
|
"X-Stainless-Package-Version",
|
|
"X-Stainless-OS",
|
|
"X-Stainless-Arch",
|
|
"X-Stainless-Runtime",
|
|
"X-Stainless-Runtime-Version",
|
|
"Accept",
|
|
"accept-language",
|
|
"accept-encoding",
|
|
"sec-fetch-mode",
|
|
"Connection",
|
|
],
|
|
bodyFieldOrder: [
|
|
"model",
|
|
"messages",
|
|
"system",
|
|
"tools",
|
|
"tool_choice",
|
|
"metadata",
|
|
"max_tokens",
|
|
"thinking",
|
|
"context_management",
|
|
"output_config",
|
|
"stream",
|
|
],
|
|
},
|
|
"claude-code-compatible": {
|
|
headerOrder: [
|
|
"Host",
|
|
"Content-Type",
|
|
"Authorization",
|
|
"anthropic-version",
|
|
"anthropic-beta",
|
|
"anthropic-dangerous-direct-browser-access",
|
|
"x-app",
|
|
"User-Agent",
|
|
"X-Claude-Code-Session-Id",
|
|
"X-Stainless-Retry-Count",
|
|
"X-Stainless-Timeout",
|
|
"X-Stainless-Lang",
|
|
"X-Stainless-Package-Version",
|
|
"X-Stainless-OS",
|
|
"X-Stainless-Arch",
|
|
"X-Stainless-Runtime",
|
|
"X-Stainless-Runtime-Version",
|
|
"Accept",
|
|
"accept-encoding",
|
|
"Connection",
|
|
],
|
|
bodyFieldOrder: [
|
|
"model",
|
|
"messages",
|
|
"system",
|
|
"tools",
|
|
"tool_choice",
|
|
"metadata",
|
|
"max_tokens",
|
|
"thinking",
|
|
"output_config",
|
|
"stream",
|
|
],
|
|
},
|
|
github: {
|
|
headerOrder: [
|
|
"Host",
|
|
"Authorization",
|
|
"X-Request-Id",
|
|
"Vscode-Sessionid",
|
|
"Vscode-Machineid",
|
|
"Editor-Version",
|
|
"Editor-Plugin-Version",
|
|
"Copilot-Integration-Id",
|
|
"Openai-Organization",
|
|
"Openai-Intent",
|
|
"Content-Type",
|
|
"User-Agent",
|
|
"Accept",
|
|
"Accept-Encoding",
|
|
],
|
|
bodyFieldOrder: [
|
|
"messages",
|
|
"model",
|
|
"temperature",
|
|
"top_p",
|
|
"max_tokens",
|
|
"n",
|
|
"stream",
|
|
"intent",
|
|
"intent_threshold",
|
|
"intent_content",
|
|
],
|
|
userAgent: GITHUB_COPILOT_CHAT_USER_AGENT,
|
|
},
|
|
antigravity: {
|
|
headerOrder: [
|
|
"Host",
|
|
"Content-Type",
|
|
"Authorization",
|
|
"User-Agent",
|
|
"Accept",
|
|
"Accept-Encoding",
|
|
],
|
|
bodyFieldOrder: ["project", "model", "userAgent", "requestType", "requestId", "request"],
|
|
userAgent: getAntigravityUserAgent(),
|
|
},
|
|
qwen: {
|
|
headerOrder: [
|
|
"Host",
|
|
"Content-Type",
|
|
"Authorization",
|
|
"User-Agent",
|
|
"X-Dashscope-AuthType",
|
|
"X-Dashscope-CacheControl",
|
|
"X-Dashscope-UserAgent",
|
|
"X-Stainless-Arch",
|
|
"X-Stainless-Lang",
|
|
"X-Stainless-Os",
|
|
"X-Stainless-Package-Version",
|
|
"X-Stainless-Retry-Count",
|
|
"X-Stainless-Runtime",
|
|
"X-Stainless-Runtime-Version",
|
|
"Connection",
|
|
"Accept",
|
|
"Accept-Language",
|
|
"Sec-Fetch-Mode",
|
|
"Accept-Encoding",
|
|
],
|
|
bodyFieldOrder: [
|
|
"model",
|
|
"messages",
|
|
"temperature",
|
|
"top_p",
|
|
"max_tokens",
|
|
"stream",
|
|
"tools",
|
|
"tool_choice",
|
|
"response_format",
|
|
"n",
|
|
"stop",
|
|
],
|
|
userAgent: getQwenOauthHeaders()["User-Agent"],
|
|
extraHeaders: getQwenOauthHeaders(),
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Reorder an object's keys according to a specified order.
|
|
* Keys not in the order list are appended at the end in their original order.
|
|
*/
|
|
export function orderFields<T extends Record<string, unknown>>(obj: T, fieldOrder: string[]): T {
|
|
if (!fieldOrder?.length || !obj || typeof obj !== "object") return obj;
|
|
|
|
const result: Record<string, unknown> = {};
|
|
const remaining = new Set(Object.keys(obj));
|
|
|
|
// First, add fields in the specified order
|
|
for (const key of fieldOrder) {
|
|
if (key in obj) {
|
|
result[key] = obj[key];
|
|
remaining.delete(key);
|
|
}
|
|
}
|
|
|
|
// Then append remaining fields in original order
|
|
for (const key of remaining) {
|
|
result[key] = obj[key];
|
|
}
|
|
|
|
return result as T;
|
|
}
|
|
|
|
/**
|
|
* Reorder HTTP headers according to a fingerprint.
|
|
* Returns a new object with headers in the specified order.
|
|
*/
|
|
export function orderHeaders(
|
|
headers: Record<string, string>,
|
|
headerOrder: string[]
|
|
): Record<string, string> {
|
|
if (!headerOrder?.length || !headers) return headers;
|
|
|
|
const result: Record<string, string> = {};
|
|
const remaining = new Map<string, string>();
|
|
|
|
// Build case-insensitive lookup
|
|
const headerMap = new Map<string, [string, string]>();
|
|
for (const [key, value] of Object.entries(headers)) {
|
|
headerMap.set(key.toLowerCase(), [key, value]);
|
|
}
|
|
|
|
// Add ordered headers first
|
|
for (const orderedKey of headerOrder) {
|
|
const entry = headerMap.get(orderedKey.toLowerCase());
|
|
if (entry) {
|
|
result[entry[0]] = entry[1];
|
|
headerMap.delete(orderedKey.toLowerCase());
|
|
}
|
|
}
|
|
|
|
// Add remaining headers
|
|
for (const [, [key, value]] of headerMap) {
|
|
result[key] = value;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Apply a CLI fingerprint to headers and body.
|
|
* Returns { headers, bodyString } with the correct ordering.
|
|
*/
|
|
export function applyFingerprint(
|
|
provider: string,
|
|
headers: Record<string, string>,
|
|
body: unknown
|
|
): { headers: Record<string, string>; bodyString: string } {
|
|
const fingerprintKey = isClaudeCodeCompatible(provider)
|
|
? "claude-code-compatible"
|
|
: provider?.toLowerCase();
|
|
const fingerprint = CLI_FINGERPRINTS[fingerprintKey];
|
|
|
|
if (!fingerprint) {
|
|
return { headers, bodyString: JSON.stringify(body) };
|
|
}
|
|
|
|
// Apply user agent override
|
|
if (fingerprint.userAgent) {
|
|
headers["User-Agent"] = fingerprint.userAgent;
|
|
}
|
|
|
|
// Apply extra headers
|
|
if (fingerprint.extraHeaders) {
|
|
Object.assign(headers, fingerprint.extraHeaders);
|
|
}
|
|
|
|
// Reorder headers
|
|
const orderedHeaders = orderHeaders(headers, fingerprint.headerOrder);
|
|
|
|
// Reorder body fields
|
|
const orderedBody =
|
|
body && typeof body === "object" && !Array.isArray(body)
|
|
? orderFields(body as Record<string, unknown>, fingerprint.bodyFieldOrder)
|
|
: body;
|
|
|
|
return {
|
|
headers: orderedHeaders,
|
|
bodyString: JSON.stringify(orderedBody),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Runtime cache for CLI compat providers set via Settings UI.
|
|
* Updated by the settings API when users toggle providers.
|
|
*/
|
|
let _cliCompatProviders: Set<string> = new Set();
|
|
|
|
/**
|
|
* Update the runtime cache of CLI-compat-enabled providers.
|
|
* Called from the settings API when cliCompatProviders is updated.
|
|
*/
|
|
export function setCliCompatProviders(providers: string[]): void {
|
|
_cliCompatProviders = new Set((providers || []).map((p) => p.toLowerCase()));
|
|
}
|
|
|
|
/**
|
|
* Get the current list of CLI-compat-enabled providers.
|
|
*/
|
|
export function getCliCompatProviders(): string[] {
|
|
return Array.from(_cliCompatProviders);
|
|
}
|
|
|
|
/**
|
|
* Check if CLI compatibility mode is enabled for a provider.
|
|
* Reads from: 1) Runtime cache (Settings UI), 2) Environment variables.
|
|
*/
|
|
export function isCliCompatEnabled(provider: string): boolean {
|
|
if (isClaudeCodeCompatible(provider)) return true;
|
|
|
|
const key = provider?.toLowerCase().replace(/[^a-z0-9]/g, "_");
|
|
|
|
// 1. Check runtime cache (set via Settings UI)
|
|
if (_cliCompatProviders.has(provider?.toLowerCase())) return true;
|
|
|
|
// 2. Check environment variable: CLI_COMPAT_<PROVIDER>=1
|
|
const envKey = `CLI_COMPAT_${key?.toUpperCase()}`;
|
|
if (process.env[envKey] === "1" || process.env[envKey] === "true") return true;
|
|
|
|
// 3. Global enable: CLI_COMPAT_ALL=1
|
|
if (process.env.CLI_COMPAT_ALL === "1" || process.env.CLI_COMPAT_ALL === "true") return true;
|
|
|
|
return false;
|
|
}
|