Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opencodex-desktop"
version = "2.65.0-vadymhimself.21"
version = "2.65.0-vadymhimself.22"
description = "OpenCodex desktop shell"
authors = ["OpenCodex contributors"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "OpenCodex",
"version": "2.65.0-vadymhimself.21",
"version": "2.65.0-vadymhimself.22",
"identifier": "com.opencodex.desktop",
"build": {
"frontendDist": "../ui",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitkyc08/opencodex",
"version": "2.65.0-vadymhimself.21",
"version": "2.65.0-vadymhimself.22",
"description": "Universal provider proxy for OpenAI Codex & Claude Code — use any LLM with Codex CLI/App/SDK and Claude Code",
"type": "module",
"main": "./bin/package-main.mjs",
Expand Down
7 changes: 5 additions & 2 deletions src/server/responses/core-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export interface ConsumedComboFailure {

/** AgentRadar image patch: trusted per-request account pin, set only by the authenticated bridge. */
export const AGENTRADAR_PIN = Symbol.for("agentradar.accountPin");
export interface AgentRadarAccountPin { provider: "claude" | "codex" | "grok" | "kimi"; accountId: string }
/** AgentRadar sign-in provider -> the OCX OAuth provider whose stored account a pin may serve (codex rides its own pool). */
export const AGENTRADAR_PIN_PROVIDERS = { claude: "anthropic", grok: "xai", kimi: "kimi", copilot: "github-copilot", cursor: "cursor", devin: "devin" } as const;
export interface AgentRadarAccountPin { provider: keyof typeof AGENTRADAR_PIN_PROVIDERS | "codex"; accountId: string }
/** undefined = no pin; null = malformed pin, which must be refused rather than served unpinned. */
export function agentRadarAccountPin(headers: Headers): AgentRadarAccountPin | null | undefined {
const accountId = headers.get("x-agentradar-account-id");
Expand All @@ -65,7 +67,8 @@ export function agentRadarAccountPin(headers: Headers): AgentRadarAccountPin | n
// Only an AgentRadar gateway (OPENCODEX_AGENTRADAR=1) trusts the pin; elsewhere it is refused, never ignored.
if (process.env.OPENCODEX_AGENTRADAR !== "1") return null;
if (!accountId || !/^[!-~]{1,256}$/.test(accountId)) return null; // printable ASCII, no spaces
return provider === "claude" || provider === "codex" || provider === "grok" || provider === "kimi" ? { provider, accountId } : null;
return provider === "codex" || (provider !== null && Object.hasOwn(AGENTRADAR_PIN_PROVIDERS, provider))
? { provider: provider as AgentRadarAccountPin["provider"], accountId } : null;
}
/**
* Names the stored account that served the turn (an opaque pool id, never an email or token) so
Expand Down
3 changes: 2 additions & 1 deletion src/server/responses/request-prepare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ResponsesRequestContext, ResponsesAdmissionState, ResponsesDispatchers } from "./core-options";
import { AGENTRADAR_PIN_PROVIDERS } from "./core-options";
import {
agentTaskRecoveryConfig,
restoreCachedEncryptedAgentTasks,
Expand Down Expand Up @@ -468,7 +469,7 @@ export async function prepareResponsesRequest(
const served = !candidate.combo && (pin.provider === "codex"
? candidate.providerName === OPENAI_CODEX_PROVIDER_ID && candidate.codexAccountMode !== undefined
: candidate.provider.authMode === "oauth"
&& candidate.providerName === (pin.provider === "claude" ? "anthropic" : pin.provider === "grok" ? "xai" : "kimi"));
&& candidate.providerName === AGENTRADAR_PIN_PROVIDERS[pin.provider]);
if (!served) throw new Error("AgentRadar pinned account cannot serve this route");
if (pin.provider === "codex") {
Object.assign(candidate, { codexAccountMode: "pool", codexAccountId: pin.accountId, codexAccountNamespace: undefined });
Expand Down
17 changes: 13 additions & 4 deletions tests/server/agentradar-account-pin-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const fake = Bun.serve({
const tools: any[] = path === "/v1/messages" ? JSON.parse(body).tools ?? [] : [];
// The helper's own call carries Anthropic's native search tool; the turn it serves carries OCX's web_search function.
const search = tools.some(t => t.type === "web_search_20250305");
if (path === "/v1/messages" || path === "/backend-api/codex/responses" || path.startsWith("/xai/") || path.startsWith("/kimi/")) {
if (path === "/v1/messages" || path === "/backend-api/codex/responses" || path.startsWith("/xai/") || path.startsWith("/kimi/") || path.startsWith("/copilot/")) {
seen.push({ path, auth, account: req.headers.get("chatgpt-account-id"), internal: [...req.headers.keys()].filter(k => k.startsWith("x-agentradar-")), search, image: body.includes('"type":"image"') });
}
if (path === "/v1/messages") {
Expand All @@ -56,7 +56,7 @@ const fake = Bun.serve({
["message_stop", {}],
]);
}
if (path.startsWith("/xai/") || path.startsWith("/kimi/")) return rateLimited(retryAfter);
if (path.startsWith("/xai/") || path.startsWith("/kimi/") || path.startsWith("/copilot/")) return rateLimited(retryAfter);
if (path === "/backend-api/codex/responses") {
const item = { type: "message", id: "msg_fake", role: "assistant", status: "completed", content: [{ type: "output_text", text: "ok", annotations: [] }] };
const response = { id: "resp_fake", object: "response", model: "gpt-5.5", status: "in_progress", output: [] };
Expand Down Expand Up @@ -90,7 +90,7 @@ async function startOcx(auth: object, config: object) {
globalThis.fetch = ((input: any, init?: any) => {
const u = new URL(input instanceof Request ? input.url : String(input));
if (u.hostname === "127.0.0.1" || u.hostname === "localhost") return real(input, init);
const base = ${JSON.stringify(FAKE)} + (u.hostname === "api.x.ai" || u.hostname === "cli-chat-proxy.grok.com" ? "/xai" : u.hostname === "api.kimi.com" ? "/kimi" : "");
const base = ${JSON.stringify(FAKE)} + (u.hostname === "api.x.ai" || u.hostname === "cli-chat-proxy.grok.com" ? "/xai" : u.hostname === "api.kimi.com" ? "/kimi" : u.hostname === "api.githubcopilot.com" ? "/copilot" : "");
return real(new Request(base + u.pathname + u.search, new Request(input, init)));
}) as typeof fetch;
`);
Expand Down Expand Up @@ -153,6 +153,7 @@ test("an AgentRadar account pin serves exactly its own stored account (pin.check
{ id: "D", credential: cred("atD") }, { id: "E", credential: cred("atE") }] },
xai: { activeAccountId: "gB", accounts: ["gA", "gB", "gC"].map(id => ({ id, credential: cred(`t${id}`) })) },
kimi: { activeAccountId: "kB", accounts: ["kA", "kB"].map(id => ({ id, credential: cred(`t${id}`) })) },
"github-copilot": { activeAccountId: "cB", accounts: ["cA", "cB"].map(id => ({ id, credential: cred(`t${id}`) })) },
}, {
defaultProvider: "anthropic", activeCodexAccountId: "acct2",
clientIntegrations: { codex: false },
Expand All @@ -162,6 +163,7 @@ test("an AgentRadar account pin serves exactly its own stored account (pin.check
anthropic: { adapter: "anthropic", baseUrl: FAKE, authMode: "oauth", allowPrivateNetwork: true, models: ["claude-stub", "claude-blind"], modelCapabilities: { "claude-blind": { inputModalities: ["text"] } } },
xai: { adapter: "openai-chat", baseUrl: `${FAKE}/xai`, authMode: "oauth", allowPrivateNetwork: true, models: ["grok-stub"] },
kimi: { adapter: "openai-chat", baseUrl: `${FAKE}/kimi`, authMode: "oauth", allowPrivateNetwork: true, models: ["kimi-stub"] },
"github-copilot": { adapter: "openai-chat", baseUrl: "https://api.githubcopilot.com", authMode: "oauth", models: ["copilot-stub"] },
openai: { adapter: "openai-responses", baseUrl: "https://chatgpt.com/backend-api/codex", authMode: "forward", codexAccountMode: "pool" },
},
codexAccounts: [1, 2].map(n => ({ id: `acct${n}`, email: `c${n}@example.invalid`, isMain: false, chatgptAccountId: `cga${n}` })),
Expand Down Expand Up @@ -194,7 +196,7 @@ test("an AgentRadar account pin serves exactly its own stored account (pin.check
assert.equal(r.served, null);
}
// A pin cannot be spent on another provider's route.
for (const h of [pin("grok", "gA"), pin("kimi", "kA"), pin("codex", "acct1")]) {
for (const h of [pin("grok", "gA"), pin("kimi", "kA"), pin("copilot", "cA"), pin("cursor", "cA"), pin("devin", "cA"), pin("codex", "acct1")]) {
r = await msg(ocx, h);
assert.equal(r.status, 404, r.text); assert.deepEqual(inference(r), []);
}
Expand Down Expand Up @@ -270,6 +272,13 @@ test("an AgentRadar account pin serves exactly its own stored account (pin.check
r = await chat(ocx, "xai/grok-stub", pin("kimi", "kA"));
assert.equal(r.status, 404, r.text); assert.deepEqual(inference(r), []);

// GitHub Copilot (AGE-2323, every call 429s): the pinned account alone, the active account stays, and its pin buys no other route.
r = await chat(ocx, "github-copilot/copilot-stub", pin("copilot", "cA"));
assert.equal(r.status, 429, `${r.text}\n${JSON.stringify(r.upstream)}`); assert.deepEqual(tokens(r, "/copilot/"), ["Bearer tcA"]);
assert.equal((await accounts(ocx, "github-copilot")).activeAccountId, "cB");
r = await chat(ocx, "kimi/kimi-stub", pin("copilot", "cA"));
assert.equal(r.status, 404, r.text); assert.deepEqual(inference(r), []);

// Codex: OCX's exact-account route serves the pinned account; the active account is untouched.
for (const n of [1, 2]) {
r = await chat(ocx, "openai/gpt-5.5", pin("codex", `acct${n}`));
Expand Down
Loading