@linxiraos/pi-catalog 1.0.0
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/CHANGELOG.md +999 -0
- package/README.md +43 -0
- package/dist/types/build.d.ts +14 -0
- package/dist/types/compat/anthropic.d.ts +18 -0
- package/dist/types/compat/apply.d.ts +7 -0
- package/dist/types/compat/bedrock.d.ts +3 -0
- package/dist/types/compat/devin.d.ts +9 -0
- package/dist/types/compat/openai.d.ts +26 -0
- package/dist/types/discovery/antigravity.d.ts +70 -0
- package/dist/types/discovery/codex.d.ts +36 -0
- package/dist/types/discovery/cursor-gen/agent_pb.d.ts +16769 -0
- package/dist/types/discovery/cursor.d.ts +23 -0
- package/dist/types/discovery/devin-gen/buf/validate/validate_pb.d.ts +1715 -0
- package/dist/types/discovery/devin-gen/exa/analytics_pb/analytics_pb.d.ts +693 -0
- package/dist/types/discovery/devin-gen/exa/api_server_pb/api_server_pb.d.ts +9158 -0
- package/dist/types/discovery/devin-gen/exa/auth_pb/auth_pb.d.ts +52 -0
- package/dist/types/discovery/devin-gen/exa/auto_cascade_common_pb/auto_cascade_common_pb.d.ts +276 -0
- package/dist/types/discovery/devin-gen/exa/bug_checker_pb/bug_checker_pb.d.ts +78 -0
- package/dist/types/discovery/devin-gen/exa/cascade_plugins_pb/cascade_plugins_pb.d.ts +999 -0
- package/dist/types/discovery/devin-gen/exa/chat_pb/chat_pb.d.ts +1704 -0
- package/dist/types/discovery/devin-gen/exa/code_edit/code_edit_pb/code_edit_pb.d.ts +656 -0
- package/dist/types/discovery/devin-gen/exa/codeium_common_pb/codeium_common_pb.d.ts +15014 -0
- package/dist/types/discovery/devin-gen/exa/context_module_pb/context_module_pb.d.ts +607 -0
- package/dist/types/discovery/devin-gen/exa/cortex_pb/cortex_pb.d.ts +11830 -0
- package/dist/types/discovery/devin-gen/exa/diff_action_pb/diff_action_pb.d.ts +248 -0
- package/dist/types/discovery/devin-gen/exa/index_pb/index_pb.d.ts +1747 -0
- package/dist/types/discovery/devin-gen/exa/knowledge_base_pb/knowledge_base_pb.d.ts +509 -0
- package/dist/types/discovery/devin-gen/exa/language_server_pb/language_server_pb.d.ts +9048 -0
- package/dist/types/discovery/devin-gen/exa/opensearch_clients_pb/opensearch_clients_pb.d.ts +1760 -0
- package/dist/types/discovery/devin-gen/exa/prompt_pb/prompt_pb.d.ts +286 -0
- package/dist/types/discovery/devin-gen/exa/reactive_component_pb/reactive_component_pb.d.ts +405 -0
- package/dist/types/discovery/devin-gen/exa/trust_pb/trust_pb.d.ts +582 -0
- package/dist/types/discovery/devin.d.ts +24 -0
- package/dist/types/discovery/gemini.d.ts +25 -0
- package/dist/types/discovery/gitlab-duo-workflow.d.ts +30 -0
- package/dist/types/discovery/index.d.ts +5 -0
- package/dist/types/discovery/openai-compatible.d.ts +74 -0
- package/dist/types/effort.d.ts +10 -0
- package/dist/types/fireworks-model-id.d.ts +23 -0
- package/dist/types/hosts.d.ts +164 -0
- package/dist/types/identity/bundled.d.ts +3 -0
- package/dist/types/identity/classify.d.ts +69 -0
- package/dist/types/identity/dialect.d.ts +3 -0
- package/dist/types/identity/family.d.ts +181 -0
- package/dist/types/identity/id.d.ts +12 -0
- package/dist/types/identity/index.d.ts +8 -0
- package/dist/types/identity/markers.d.ts +4 -0
- package/dist/types/identity/priority.d.ts +1 -0
- package/dist/types/identity/reference.d.ts +29 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/model-cache.d.ts +23 -0
- package/dist/types/model-manager.d.ts +77 -0
- package/dist/types/model-thinking.d.ts +66 -0
- package/dist/types/models.d.ts +12 -0
- package/dist/types/provider-models/bundled-references.d.ts +13 -0
- package/dist/types/provider-models/cache-provider-id.d.ts +9 -0
- package/dist/types/provider-models/descriptor-types.d.ts +76 -0
- package/dist/types/provider-models/descriptors.d.ts +504 -0
- package/dist/types/provider-models/google.d.ts +27 -0
- package/dist/types/provider-models/index.d.ts +7 -0
- package/dist/types/provider-models/ollama.d.ts +22 -0
- package/dist/types/provider-models/openai-compat.d.ts +599 -0
- package/dist/types/provider-models/special.d.ts +53 -0
- package/dist/types/types.d.ts +811 -0
- package/dist/types/utils.d.ts +20 -0
- package/dist/types/variant-collapse.d.ts +133 -0
- package/dist/types/wire/alibaba-token-plan.d.ts +22 -0
- package/dist/types/wire/codex.d.ts +42 -0
- package/dist/types/wire/coreweave.d.ts +12 -0
- package/dist/types/wire/gemini-headers.d.ts +37 -0
- package/dist/types/wire/github-copilot.d.ts +39 -0
- package/package.json +101 -0
- package/src/build.ts +94 -0
- package/src/compat/anthropic.ts +179 -0
- package/src/compat/apply.ts +15 -0
- package/src/compat/bedrock.ts +153 -0
- package/src/compat/devin.ts +12 -0
- package/src/compat/openai.ts +796 -0
- package/src/discovery/antigravity.ts +253 -0
- package/src/discovery/codex.ts +346 -0
- package/src/discovery/cursor-gen/agent_pb.ts +19513 -0
- package/src/discovery/cursor.ts +396 -0
- package/src/discovery/devin-gen/buf/validate/validate_pb.ts +1862 -0
- package/src/discovery/devin-gen/exa/analytics_pb/analytics_pb.ts +871 -0
- package/src/discovery/devin-gen/exa/api_server_pb/api_server_pb.ts +11083 -0
- package/src/discovery/devin-gen/exa/auth_pb/auth_pb.ts +71 -0
- package/src/discovery/devin-gen/exa/auto_cascade_common_pb/auto_cascade_common_pb.ts +348 -0
- package/src/discovery/devin-gen/exa/bug_checker_pb/bug_checker_pb.ts +103 -0
- package/src/discovery/devin-gen/exa/cascade_plugins_pb/cascade_plugins_pb.ts +1198 -0
- package/src/discovery/devin-gen/exa/chat_pb/chat_pb.ts +2063 -0
- package/src/discovery/devin-gen/exa/code_edit/code_edit_pb/code_edit_pb.ts +810 -0
- package/src/discovery/devin-gen/exa/codeium_common_pb/codeium_common_pb.ts +18354 -0
- package/src/discovery/devin-gen/exa/context_module_pb/context_module_pb.ts +732 -0
- package/src/discovery/devin-gen/exa/cortex_pb/cortex_pb.ts +14277 -0
- package/src/discovery/devin-gen/exa/diff_action_pb/diff_action_pb.ts +312 -0
- package/src/discovery/devin-gen/exa/index_pb/index_pb.ts +2106 -0
- package/src/discovery/devin-gen/exa/knowledge_base_pb/knowledge_base_pb.ts +623 -0
- package/src/discovery/devin-gen/exa/language_server_pb/language_server_pb.ts +10918 -0
- package/src/discovery/devin-gen/exa/opensearch_clients_pb/opensearch_clients_pb.ts +2125 -0
- package/src/discovery/devin-gen/exa/prompt_pb/prompt_pb.ts +361 -0
- package/src/discovery/devin-gen/exa/reactive_component_pb/reactive_component_pb.ts +450 -0
- package/src/discovery/devin-gen/exa/trust_pb/trust_pb.ts +712 -0
- package/src/discovery/devin.ts +151 -0
- package/src/discovery/gemini.ts +260 -0
- package/src/discovery/gitlab-duo-workflow.ts +859 -0
- package/src/discovery/index.ts +5 -0
- package/src/discovery/openai-compatible.ts +249 -0
- package/src/effort.ts +18 -0
- package/src/fireworks-model-id.ts +50 -0
- package/src/hosts.ts +155 -0
- package/src/identity/bundled.ts +28 -0
- package/src/identity/classify.ts +219 -0
- package/src/identity/dialect.ts +42 -0
- package/src/identity/family.ts +366 -0
- package/src/identity/id.ts +81 -0
- package/src/identity/index.ts +8 -0
- package/src/identity/markers.ts +49 -0
- package/src/identity/priority.ts +59 -0
- package/src/identity/reference.ts +167 -0
- package/src/index.ts +17 -0
- package/src/model-cache.ts +285 -0
- package/src/model-manager.ts +672 -0
- package/src/model-thinking.ts +821 -0
- package/src/models.json +106099 -0
- package/src/models.json.d.ts +9 -0
- package/src/models.ts +93 -0
- package/src/provider-models/bundled-references.ts +75 -0
- package/src/provider-models/cache-provider-id.ts +68 -0
- package/src/provider-models/descriptor-types.ts +85 -0
- package/src/provider-models/descriptors.ts +584 -0
- package/src/provider-models/google.ts +107 -0
- package/src/provider-models/index.ts +7 -0
- package/src/provider-models/ollama.ts +204 -0
- package/src/provider-models/openai-compat.ts +5991 -0
- package/src/provider-models/special.ts +213 -0
- package/src/types.ts +952 -0
- package/src/utils.ts +69 -0
- package/src/variant-collapse.ts +1225 -0
- package/src/wire/alibaba-token-plan.ts +54 -0
- package/src/wire/codex.ts +60 -0
- package/src/wire/coreweave.ts +51 -0
- package/src/wire/gemini-headers.ts +74 -0
- package/src/wire/github-copilot.ts +115 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* International (Singapore) Token Plan endpoint. Default region; keys issued by
|
|
3
|
+
* the international product authenticate only here.
|
|
4
|
+
*/
|
|
5
|
+
export const ALIBABA_TOKEN_PLAN_BASE_URL = "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1";
|
|
6
|
+
/**
|
|
7
|
+
* China (Beijing) Token Plan endpoint (百炼 Token Plan). Keys are region-locked:
|
|
8
|
+
* a Beijing-issued key is rejected by the international endpoint with
|
|
9
|
+
* `invalid_api_key`, and vice versa (#6682).
|
|
10
|
+
*/
|
|
11
|
+
export const ALIBABA_TOKEN_PLAN_CN_BASE_URL = "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1";
|
|
12
|
+
|
|
13
|
+
export interface AlibabaTokenPlanCredential {
|
|
14
|
+
token: string;
|
|
15
|
+
cookie?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Region base URL the key authenticates against. Absent means the default
|
|
18
|
+
* international endpoint ({@link ALIBABA_TOKEN_PLAN_BASE_URL}).
|
|
19
|
+
*/
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const TOKEN_PATTERN = /^sk-[A-Za-z0-9._~+/-]+={0,2}$/;
|
|
24
|
+
|
|
25
|
+
export function parseAlibabaTokenPlanCredential(value: string): AlibabaTokenPlanCredential | null {
|
|
26
|
+
const trimmed = value.trim();
|
|
27
|
+
if (!trimmed) return null;
|
|
28
|
+
if (!trimmed.startsWith("{")) return TOKEN_PATTERN.test(trimmed) ? { token: trimmed } : null;
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(trimmed) as { token?: unknown; cookie?: unknown; baseUrl?: unknown };
|
|
31
|
+
if (typeof parsed.token !== "string" || !TOKEN_PATTERN.test(parsed.token.trim())) return null;
|
|
32
|
+
if (parsed.cookie !== undefined && typeof parsed.cookie !== "string") return null;
|
|
33
|
+
if (parsed.baseUrl !== undefined && typeof parsed.baseUrl !== "string") return null;
|
|
34
|
+
const token = parsed.token.trim();
|
|
35
|
+
const cookie = parsed.cookie?.trim();
|
|
36
|
+
const baseUrl = parsed.baseUrl?.trim();
|
|
37
|
+
const credential: AlibabaTokenPlanCredential = { token };
|
|
38
|
+
if (cookie) credential.cookie = cookie;
|
|
39
|
+
if (baseUrl) credential.baseUrl = baseUrl;
|
|
40
|
+
return credential;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function serializeAlibabaTokenPlanCredential(token: string, cookie: string, baseUrl?: string): string {
|
|
47
|
+
const trimmedCookie = cookie.trim();
|
|
48
|
+
const trimmedBaseUrl = baseUrl?.trim();
|
|
49
|
+
if (!trimmedCookie && !trimmedBaseUrl) return token;
|
|
50
|
+
const payload: { token: string; cookie?: string; baseUrl?: string } = { token };
|
|
51
|
+
if (trimmedCookie) payload.cookie = trimmedCookie;
|
|
52
|
+
if (trimmedBaseUrl) payload.baseUrl = trimmedBaseUrl;
|
|
53
|
+
return JSON.stringify(payload);
|
|
54
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for OpenAI Codex (ChatGPT OAuth) backend
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pinned OpenAI Codex client version (corresponds to @openai/codex package version).
|
|
9
|
+
*/
|
|
10
|
+
export const CODEX_CLIENT_VERSION = "0.144.1";
|
|
11
|
+
|
|
12
|
+
export const OPENAI_HEADERS = {
|
|
13
|
+
BETA: "OpenAI-Beta",
|
|
14
|
+
ACCOUNT_ID: "chatgpt-account-id",
|
|
15
|
+
ORIGINATOR: "originator",
|
|
16
|
+
VERSION: "version",
|
|
17
|
+
SESSION_ID: "session_id",
|
|
18
|
+
CONVERSATION_ID: "conversation_id",
|
|
19
|
+
SCOPED_SESSION_ID: "session-id",
|
|
20
|
+
THREAD_ID: "thread-id",
|
|
21
|
+
INSTALLATION_ID: "x-codex-installation-id",
|
|
22
|
+
WINDOW_ID: "x-codex-window-id",
|
|
23
|
+
TURN_METADATA: "x-codex-turn-metadata",
|
|
24
|
+
PARENT_THREAD_ID: "x-codex-parent-thread-id",
|
|
25
|
+
SUBAGENT: "x-openai-subagent",
|
|
26
|
+
/** Responses Lite transport marker (codex-rs `add_responses_lite_header`); value is always `"true"`. */
|
|
27
|
+
RESPONSES_LITE: "x-openai-internal-codex-responses-lite",
|
|
28
|
+
/** DeviceCheck attestation envelope (codex-rs `X_OAI_ATTESTATION_HEADER`); sent on ChatGPT-OAuth requests. */
|
|
29
|
+
ATTESTATION: "x-oai-attestation",
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
export const OPENAI_HEADER_VALUES = {
|
|
33
|
+
BETA_RESPONSES: "responses=experimental",
|
|
34
|
+
BETA_RESPONSES_WEBSOCKETS_V2: "responses_websockets=2026-02-06",
|
|
35
|
+
ORIGINATOR_CODEX: "pi",
|
|
36
|
+
} as const;
|
|
37
|
+
|
|
38
|
+
export const URL_PATHS = {
|
|
39
|
+
RESPONSES: "/responses",
|
|
40
|
+
CODEX_RESPONSES: "/codex/responses",
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
export const JWT_CLAIM_PATH = "https://api.openai.com/auth" as const;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Extract account ID from a Codex JWT access token.
|
|
47
|
+
* Returns undefined if the token is not a valid Codex JWT.
|
|
48
|
+
*/
|
|
49
|
+
export function getCodexAccountId(accessToken: string): string | undefined {
|
|
50
|
+
try {
|
|
51
|
+
const parts = accessToken.split(".");
|
|
52
|
+
if (parts.length !== 3) return undefined;
|
|
53
|
+
const decoded = Buffer.from(parts[1] ?? "", "base64").toString("utf-8");
|
|
54
|
+
const payload = JSON.parse(decoded) as Record<string, unknown>;
|
|
55
|
+
const auth = payload[JWT_CLAIM_PATH] as { chatgpt_account_id?: string } | undefined;
|
|
56
|
+
return auth?.chatgpt_account_id ?? undefined;
|
|
57
|
+
} catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const COREWEAVE_PROJECT_HEADER = "OpenAI-Project" as const;
|
|
2
|
+
|
|
3
|
+
export interface CoreWeaveProjectEnv {
|
|
4
|
+
[key: string]: string | undefined;
|
|
5
|
+
COREWEAVE_PROJECT?: string;
|
|
6
|
+
WANDB_INFERENCE_PROJECT?: string;
|
|
7
|
+
WANDB_ENTITY?: string;
|
|
8
|
+
WANDB_PROJECT?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function cleanEnvValue(value: string | undefined): string | undefined {
|
|
12
|
+
const trimmed = value?.trim();
|
|
13
|
+
return trimmed ? trimmed : undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function resolveCoreWeaveProject(env: CoreWeaveProjectEnv): string | undefined {
|
|
17
|
+
const explicitProject = cleanEnvValue(env.COREWEAVE_PROJECT) ?? cleanEnvValue(env.WANDB_INFERENCE_PROJECT);
|
|
18
|
+
if (explicitProject) {
|
|
19
|
+
return explicitProject;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const wandbProject = cleanEnvValue(env.WANDB_PROJECT);
|
|
23
|
+
if (!wandbProject) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
if (wandbProject.includes("/")) {
|
|
27
|
+
return wandbProject;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const wandbEntity = cleanEnvValue(env.WANDB_ENTITY);
|
|
31
|
+
return wandbEntity ? `${wandbEntity}/${wandbProject}` : undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function coreWeaveProjectHeaders(env: CoreWeaveProjectEnv): Record<string, string> | undefined {
|
|
35
|
+
const project = resolveCoreWeaveProject(env);
|
|
36
|
+
return project ? { [COREWEAVE_PROJECT_HEADER]: project } : undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function hasCoreWeaveProjectHeader(headers: Record<string, string>): boolean {
|
|
40
|
+
const normalized = COREWEAVE_PROJECT_HEADER.toLowerCase();
|
|
41
|
+
return Object.entries(headers).some(([header, value]) => header.toLowerCase() === normalized && value.trim() !== "");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function removeBlankCoreWeaveProjectHeaders(headers: Record<string, string>): void {
|
|
45
|
+
const normalized = COREWEAVE_PROJECT_HEADER.toLowerCase();
|
|
46
|
+
for (const [header, value] of Object.entries(headers)) {
|
|
47
|
+
if (header.toLowerCase() === normalized && value.trim() === "") {
|
|
48
|
+
delete headers[header];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a User-Agent string that identifies as Gemini CLI to unlock higher rate limits.
|
|
3
|
+
* Uses the same format as the official Gemini CLI (v0.35+):
|
|
4
|
+
* GeminiCLI/VERSION/MODEL (PLATFORM; ARCH; SURFACE)
|
|
5
|
+
*/
|
|
6
|
+
export function getGeminiCliUserAgent(modelId = "gemini-3.1-pro-preview"): string {
|
|
7
|
+
const version = process.env.PI_AI_GEMINI_CLI_VERSION || "0.46.0";
|
|
8
|
+
const platform = process.platform === "win32" ? "win32" : process.platform;
|
|
9
|
+
const arch = process.arch === "x64" ? "x64" : process.arch;
|
|
10
|
+
return `GeminiCLI/${version}/${modelId} (${platform}; ${arch}; terminal)`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const getGeminiCliHeaders = (modelId?: string) => ({
|
|
14
|
+
"User-Agent": getGeminiCliUserAgent(modelId),
|
|
15
|
+
"Client-Metadata": "ideType=IDE_UNSPECIFIED,platform=PLATFORM_UNSPECIFIED,pluginType=GEMINI",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const ANTIGRAVITY_SYSTEM_INSTRUCTION =
|
|
19
|
+
"You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding." +
|
|
20
|
+
"You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question." +
|
|
21
|
+
"**Absolute paths only**" +
|
|
22
|
+
"**Proactiveness**";
|
|
23
|
+
/**
|
|
24
|
+
* Antigravity / Cloud Code Assist user agent. Lives in its own file so discovery
|
|
25
|
+
* and usage code can read it without pulling the heavy google-gemini-cli provider
|
|
26
|
+
* (and its @google/genai → google-auth-library dependency chain) into the startup
|
|
27
|
+
* parse graph.
|
|
28
|
+
*/
|
|
29
|
+
export let getAntigravityUserAgent = () => {
|
|
30
|
+
const DEFAULT_ANTIGRAVITY_VERSION = "2.1.4";
|
|
31
|
+
const version = process.env.PI_AI_ANTIGRAVITY_VERSION || DEFAULT_ANTIGRAVITY_VERSION;
|
|
32
|
+
// Map Node.js platform/arch to Antigravity's expected format.
|
|
33
|
+
// Verified against Antigravity source: _qn() and wqn() in main.js.
|
|
34
|
+
// process.platform: win32→windows, others pass through (darwin, linux)
|
|
35
|
+
// process.arch: x64→amd64, ia32→386, others pass through (arm64)
|
|
36
|
+
const os = process.platform === "win32" ? "windows" : process.platform;
|
|
37
|
+
const arch = process.arch === "x64" ? "amd64" : process.arch === "ia32" ? "386" : process.arch;
|
|
38
|
+
const userAgent = `antigravity/hub/${version} ${os}/${arch}`;
|
|
39
|
+
getAntigravityUserAgent = () => userAgent;
|
|
40
|
+
return userAgent;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Per-wire-id Antigravity Cloud Code Assist request constants, captured from the
|
|
45
|
+
* real `antigravity/hub` client against `daily-cloudcode-pa`. `modelEnum` is the
|
|
46
|
+
* opaque `labels.model_enum` token the client tags each request with — optional
|
|
47
|
+
* because Anthropic-backed wire ids (e.g. `claude-sonnet-4-6`,
|
|
48
|
+
* `claude-opus-4-6-thinking`) are accepted without one; the label is purely
|
|
49
|
+
* telemetry. `maxOutputTokens` is the fixed `generationConfig.maxOutputTokens`
|
|
50
|
+
* the backend enforces regardless of the thinking budget (Claude caps at
|
|
51
|
+
* 64000, Gemini accepts the discovered cap). Keyed by the routed upstream wire
|
|
52
|
+
* id (post effort-routing), not the collapsed logical id. Checkpoint-only ids
|
|
53
|
+
* (e.g. `gemini-3.1-flash-lite`) are intentionally absent — this provider only
|
|
54
|
+
* emits agent requests.
|
|
55
|
+
*/
|
|
56
|
+
export interface AntigravityModelWireProfile {
|
|
57
|
+
modelEnum?: string;
|
|
58
|
+
maxOutputTokens: number;
|
|
59
|
+
}
|
|
60
|
+
export const ANTIGRAVITY_MODEL_WIRE_PROFILES: Readonly<Record<string, AntigravityModelWireProfile>> = {
|
|
61
|
+
"gemini-3.5-flash-extra-low": { modelEnum: "MODEL_PLACEHOLDER_M187", maxOutputTokens: 65536 },
|
|
62
|
+
"gemini-3.5-flash-low": { modelEnum: "MODEL_PLACEHOLDER_M20", maxOutputTokens: 65536 },
|
|
63
|
+
"gemini-3-flash-agent": { modelEnum: "MODEL_PLACEHOLDER_M132", maxOutputTokens: 65536 },
|
|
64
|
+
"gemini-3.1-pro-low": { modelEnum: "MODEL_PLACEHOLDER_M36", maxOutputTokens: 65535 },
|
|
65
|
+
"gemini-pro-agent": { modelEnum: "MODEL_PLACEHOLDER_M16", maxOutputTokens: 65535 },
|
|
66
|
+
// Claude on `daily-cloudcode-pa` rejects `maxOutputTokens > 64000` with a
|
|
67
|
+
// 400 (`Request contains an invalid argument`). The model_enum label is
|
|
68
|
+
// untracked for these ids; the backend does not require it.
|
|
69
|
+
"claude-sonnet-4-6": { maxOutputTokens: 64000 },
|
|
70
|
+
"claude-opus-4-6-thinking": { maxOutputTokens: 64000 },
|
|
71
|
+
};
|
|
72
|
+
export function getAntigravityModelWireProfile(wireModelId: string): AntigravityModelWireProfile | undefined {
|
|
73
|
+
return ANTIGRAVITY_MODEL_WIRE_PROFILES[wireModelId];
|
|
74
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Copilot wire metadata: API-key envelope parsing and endpoint
|
|
3
|
+
* derivation shared by catalog discovery and the pi-ai OAuth flow. The device
|
|
4
|
+
* login / token refresh flow lives in `@linxiraos/pi-ai`'s registry.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const COPILOT_USER_AGENT = "opencode/1.3.15" as const;
|
|
8
|
+
|
|
9
|
+
export const OPENCODE_HEADERS = {
|
|
10
|
+
"User-Agent": COPILOT_USER_AGENT,
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copilot API version sent on `api.githubcopilot.com` requests (`/models`,
|
|
15
|
+
* chat endpoints). Newer versions unlock tiered context metadata: `/models`
|
|
16
|
+
* reports the full long-context window in `capabilities.limits` plus per-tier
|
|
17
|
+
* boundaries/prices under `billing.token_prices.{default,long_context}`.
|
|
18
|
+
* Without it the endpoint serves default-tier limits only (e.g. 264k instead
|
|
19
|
+
* of 1M for Claude Opus). Never send this to `api.github.com` REST endpoints —
|
|
20
|
+
* they validate `X-GitHub-Api-Version` against the REST version vocabulary.
|
|
21
|
+
*/
|
|
22
|
+
export const COPILOT_API_VERSION = "2026-06-01" as const;
|
|
23
|
+
|
|
24
|
+
/** Headers for `api.githubcopilot.com` (capi) requests: discovery, chat, policy. */
|
|
25
|
+
export const COPILOT_API_HEADERS = {
|
|
26
|
+
...OPENCODE_HEADERS,
|
|
27
|
+
"X-GitHub-Api-Version": COPILOT_API_VERSION,
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
type GitHubCopilotApiKeyPayload = {
|
|
31
|
+
token?: unknown;
|
|
32
|
+
enterpriseUrl?: unknown;
|
|
33
|
+
apiEndpoint?: unknown;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ParsedGitHubCopilotApiKey = {
|
|
37
|
+
accessToken: string;
|
|
38
|
+
enterpriseUrl?: string;
|
|
39
|
+
apiEndpoint?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const PUBLIC_GITHUB_HOSTS = new Set(["api.github.com", "github.com", "www.github.com"]);
|
|
43
|
+
|
|
44
|
+
export function isPublicGitHubHost(host: string): boolean {
|
|
45
|
+
return PUBLIC_GITHUB_HOSTS.has(host.trim().toLowerCase());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Canonical personal-Copilot API host. */
|
|
49
|
+
export const PERSONAL_GITHUB_COPILOT_BASE_URL = "https://api.githubcopilot.com" as const;
|
|
50
|
+
|
|
51
|
+
/** `true` when the resolved base URL is the canonical personal-Copilot host. */
|
|
52
|
+
export function isPersonalGitHubCopilotBaseUrl(baseUrl: string | undefined): boolean {
|
|
53
|
+
return baseUrl === PERSONAL_GITHUB_COPILOT_BASE_URL;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function normalizeGitHubCopilotEnterpriseDomain(input: string | undefined): string | undefined {
|
|
57
|
+
const trimmed = input?.trim();
|
|
58
|
+
if (!trimmed) return undefined;
|
|
59
|
+
const normalized = normalizeDomain(trimmed) ?? trimmed.toLowerCase();
|
|
60
|
+
if (!normalized || isPublicGitHubHost(normalized)) return undefined;
|
|
61
|
+
return normalized;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function normalizeGitHubCopilotApiEndpoint(input: string | undefined): string | undefined {
|
|
65
|
+
const trimmed = input?.trim();
|
|
66
|
+
if (!trimmed?.startsWith("https://")) return undefined;
|
|
67
|
+
try {
|
|
68
|
+
const url = new URL(trimmed);
|
|
69
|
+
if (url.protocol !== "https:" || !url.hostname) return undefined;
|
|
70
|
+
return trimmed.replace(/\/+$/, "");
|
|
71
|
+
} catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function parseGitHubCopilotApiKey(apiKeyRaw: string): ParsedGitHubCopilotApiKey {
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(apiKeyRaw) as GitHubCopilotApiKeyPayload;
|
|
79
|
+
if (typeof parsed.token === "string") {
|
|
80
|
+
return {
|
|
81
|
+
accessToken: parsed.token,
|
|
82
|
+
enterpriseUrl:
|
|
83
|
+
typeof parsed.enterpriseUrl === "string"
|
|
84
|
+
? normalizeGitHubCopilotEnterpriseDomain(parsed.enterpriseUrl)
|
|
85
|
+
: undefined,
|
|
86
|
+
apiEndpoint:
|
|
87
|
+
typeof parsed.apiEndpoint === "string"
|
|
88
|
+
? normalizeGitHubCopilotApiEndpoint(parsed.apiEndpoint)
|
|
89
|
+
: undefined,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
} catch {}
|
|
93
|
+
|
|
94
|
+
return { accessToken: apiKeyRaw };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function normalizeDomain(input: string): string | null {
|
|
98
|
+
const trimmed = input.trim();
|
|
99
|
+
if (!trimmed) return null;
|
|
100
|
+
try {
|
|
101
|
+
const url = trimmed.includes("://") ? new URL(trimmed) : new URL(`https://${trimmed}`);
|
|
102
|
+
return url.hostname;
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function getGitHubCopilotBaseUrl(enterpriseDomain?: string): string {
|
|
109
|
+
const normalizedEnterpriseDomain = normalizeGitHubCopilotEnterpriseDomain(enterpriseDomain);
|
|
110
|
+
if (!normalizedEnterpriseDomain) return "https://api.githubcopilot.com";
|
|
111
|
+
const host = normalizedEnterpriseDomain.startsWith("copilot-api.")
|
|
112
|
+
? normalizedEnterpriseDomain
|
|
113
|
+
: `copilot-api.${normalizedEnterpriseDomain}`;
|
|
114
|
+
return `https://${host}`;
|
|
115
|
+
}
|