Skip to content

Commit 1e5fa3d

Browse files
authored
Merge pull request #1152 from chrisae9/split/1019-02-selector-initialization
feat(codex): initialize account picker selectors
2 parents 44dce33 + 440432b commit 1e5fa3d

13 files changed

Lines changed: 323 additions & 18 deletions

File tree

‎docs-site/src/content/docs/ja/reference/configuration/providers.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ selector 名はユーザーが選ぶ公開 label であり、opencodex はアカ
3131
`codexAccountNamespaces` のキーは長さ 1〜64 文字、先頭と末尾は ASCII
3232
英数字、内部には英数字、`.`、`_`、`-` を使用でき、予約済み JavaScript object 名は拒否されます。
3333
値は有効な pool account id(内部 `__main__` は不可)、または Codex Desktop アカウントを示す
34-
`"@main"` です。provider と予約済み `openai` / `combo` との衝突は大文字小文字を区別せず検査され、
35-
namespace 付き combo alias はその namespace prefix に selector を再利用できません。設定済み pool id
34+
`"@main"` です。provider と予約済み `openai` / `combo` / `policy` との衝突は大文字小文字を区別せず検査され、
35+
namespace 付き combo または routing-profile alias はその namespace prefix に selector を再利用できません。設定済み pool id
3636
や他の selector target も selector と再利用できません。raw account id と email は
3737
非公開のままにし、selector を公開名として使ってください。明示的な選択の動作と優先順位は
3838
[ルーティング構成](/reference/configuration/routing/)を参照してください。

‎docs-site/src/content/docs/ko/reference/configuration/providers.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ selector 이름은 사용자가 정하는 공개 label이며, opencodex는 여
3131
`codexAccountNamespaces` 키는 길이가 1~64자이고 시작과 끝은 ASCII 영숫자여야
3232
하며, 내부에는 영숫자, `.`, `_`, `-`를 사용할 수 있습니다. 예약된 JavaScript object 이름은 거부됩니다.
3333
값은 유효한 pool account id(내부 `__main__` 제외)이거나 Codex Desktop 계정을 나타내는 `"@main"`입니다.
34-
provider 및 예약된 `openai` / `combo` 충돌은 대소문자를 구분하지 않고 검사하며, namespace가 있는
35-
combo alias는 selector를 namespace prefix로 재사용할 수 없습니다. 설정된 pool id와 다른 selector
34+
provider 및 예약된 `openai` / `combo` / `policy` 충돌은 대소문자를 구분하지 않고 검사하며, namespace가 있는
35+
combo 또는 routing-profile alias는 selector를 namespace prefix로 재사용할 수 없습니다. 설정된 pool id와 다른 selector
3636
target도 selector로 재사용할 수 없습니다. raw account id와 email은 비공개로
3737
유지하고 selector를 공개 이름으로 사용하세요. 명시적 선택 동작과 우선순위는
3838
[라우팅 설정](/ko/reference/configuration/routing/)을 참고하십시오.

‎docs-site/src/content/docs/reference/configuration/providers.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ Selector names are user-chosen public labels; opencodex assigns no account-role
3333
`codexAccountNamespaces` keys are 1–64 characters, starting and ending with an
3434
ASCII letter or number, with letters, numbers, `.`, `_`, or `-` inside. Reserved JavaScript object
3535
names are rejected. Each value is a valid pool-account id (never internal `__main__`) or `"@main"`
36-
for the Codex Desktop account. Provider and reserved `openai` / `combo` collisions are checked
37-
case-insensitively; a namespaced combo alias cannot reuse a selector as its namespace prefix, and
38-
configured pool ids or selector targets also cannot reuse a selector. Keep raw account ids and
39-
emails private; the selector is the public name. See [Routing Configuration](/reference/configuration/routing/)
36+
for the Codex Desktop account. Provider and reserved `openai` / `combo` / `policy` collisions are
37+
checked case-insensitively; a namespaced combo or routing-profile alias cannot reuse a selector as
38+
its namespace prefix, and configured pool ids or selector targets also cannot reuse a selector. Keep
39+
raw account ids and emails private; the selector is the public name. See [Routing Configuration](/reference/configuration/routing/)
4040
for exact-selection behavior and precedence.
4141

4242
## Reserved OpenAI providers

‎docs-site/src/content/docs/ru/reference/configuration/providers.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ description: Записи провайдеров, аутентификация,
3232
аккаунтов. Ключи `codexAccountNamespaces` имеют длину 1–64 символа. Они должны начинаться и
3333
заканчиваться ASCII-буквой или цифрой; внутри разрешены буквы, цифры, `.`, `_` и `-`. Зарезервированные
3434
имена объектов JavaScript запрещены. Значение — допустимый id аккаунта пула (кроме внутреннего `__main__`)
35-
либо `"@main"` для аккаунта Codex Desktop. Коллизии с provider и зарезервированными `openai` / `combo`
36-
проверяются без учёта регистра; namespace-префикс namespaced combo alias не может повторять селектор.
35+
либо `"@main"` для аккаунта Codex Desktop. Коллизии с provider и зарезервированными `openai` / `combo` / `policy`
36+
проверяются без учёта регистра; namespace-префикс namespaced combo или routing-profile alias не может повторять селектор.
3737
Настроенные id пула и цели других селекторов также нельзя повторно использовать как селектор. Сохраняйте
3838
raw id аккаунтов и email приватными, а селектор используйте как публичное имя. Поведение и приоритет
3939
явного выбора описаны в разделе [Конфигурация маршрутизации](/reference/configuration/routing/).

‎docs-site/src/content/docs/zh-cn/reference/configuration/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ selector 名称是用户自定的公开 label;opencodex 不会为其赋予账
3131
`codexAccountNamespaces` 的 key 长度为 1–64 个字符,首尾必须是 ASCII 字母或数字,
3232
中间可使用字母、数字、`.`、`_` 或 `-`;保留的 JavaScript object 名称会被拒绝。value 必须是有效的
3333
pool account id(不能是内部 `__main__`),或用 `"@main"` 表示 Codex Desktop 账号。与 provider 及
34-
保留的 `openai` / `combo` 冲突时不区分大小写;带 namespace 的 combo alias 不能把 selector 复用为
34+
保留的 `openai` / `combo` / `policy` 冲突时不区分大小写;带 namespace 的 combo 或 routing-profile alias 不能把 selector 复用为
3535
其 namespace prefix,已配置的 pool id 和其他 selector target 也不能复用为 selector。raw account id
3636
与 email 应保持私密,selector 才是公开名称。明确选择的行为和优先级见
3737
[路由配置](/zh-cn/reference/configuration/routing/)。

‎src/codex/account-namespaces.ts‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { CodexAccount, OcxConfig } from "../types";
22
import { COMBO_NAMESPACE } from "../combos/types";
33
import { OPENAI_CODEX_PROVIDER_ID } from "../providers/openai-tiers";
4+
import {
5+
POLICY_NAMESPACE,
6+
routingProfileAliasNamespacePrefixes,
7+
} from "../routing/profile-namespace";
48
import {
59
CODEX_ACCOUNT_LOG_LABEL_RE,
610
createCodexAccountLogLabel,
@@ -21,6 +25,7 @@ const RESERVED_NAMESPACE_KEYS = new Set([
2125
"constructor",
2226
COMBO_NAMESPACE,
2327
OPENAI_CODEX_PROVIDER_ID,
28+
POLICY_NAMESPACE,
2429
].map(codexProviderNamespaceKey));
2530
const PUBLIC_ACCOUNT_SELECTOR_MAX_ATTEMPTS = 16;
2631

@@ -68,17 +73,21 @@ function claimNamespace(requested: string, used: Set<string>): string {
6873
return namespace;
6974
}
7075

71-
function occupiedNamespaces(config: Pick<OcxConfig, "combos" | "providers">): Set<string> {
76+
/** Collect every public namespace that a generated account selector must not claim. */
77+
function occupiedNamespaces(
78+
config: Pick<OcxConfig, "combos" | "providers" | "routingProfiles">,
79+
): Set<string> {
7280
return new Set([
7381
...Object.keys(config.providers).map(codexProviderNamespaceKey),
7482
...comboAliasNamespaces(config),
83+
...routingProfileAliasNamespacePrefixes(config),
7584
...RESERVED_NAMESPACE_KEYS,
7685
]);
7786
}
7887

7988
/** Build an initial account-selector map without deriving public selectors from aliases or ids. */
8089
export function defaultCodexAccountNamespaces(
81-
config: Pick<OcxConfig, "codexAccounts" | "combos" | "providers">,
90+
config: Pick<OcxConfig, "codexAccounts" | "combos" | "providers" | "routingProfiles">,
8291
): Record<string, string> {
8392
const namespaces: Record<string, string> = {};
8493
const used = occupiedNamespaces(config);
@@ -99,13 +108,39 @@ export function defaultCodexAccountNamespaces(
99108
return namespaces;
100109
}
101110

111+
/**
112+
* Initialize generated selectors only for an explicit opt-in with no existing bindings.
113+
* A true result means the map was replaced and the caller must persist the updated config.
114+
*/
115+
export function initializeDefaultCodexAccountNamespaces(
116+
config: Pick<
117+
OcxConfig,
118+
| "codexAccountPickerEnabled"
119+
| "codexAccountNamespaces"
120+
| "codexAccounts"
121+
| "combos"
122+
| "providers"
123+
| "routingProfiles"
124+
>,
125+
): boolean {
126+
if (config.codexAccountPickerEnabled !== true
127+
|| Object.keys(config.codexAccountNamespaces ?? {}).length > 0) return false;
128+
129+
const namespaces = defaultCodexAccountNamespaces(config);
130+
config.codexAccountNamespaces = namespaces;
131+
return true;
132+
}
133+
102134
/**
103135
* Add one account to a generated map without renaming or replacing explicit existing entries.
104136
* The account-creation layer must reject a new id that already equals an existing selector key.
105137
* A true result means the map was mutated in place; callers must persist the updated config.
106138
*/
107139
export function appendDefaultCodexAccountNamespace(
108-
config: Pick<OcxConfig, "codexAccountNamespaces" | "codexAccounts" | "combos" | "providers">,
140+
config: Pick<
141+
OcxConfig,
142+
"codexAccountNamespaces" | "codexAccounts" | "combos" | "providers" | "routingProfiles"
143+
>,
109144
account: Pick<CodexAccount, "id" | "isMain" | "logLabel">,
110145
): boolean {
111146
const namespaces = config.codexAccountNamespaces;

‎src/config.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { isCodexAccountPriorityKey } from "./codex/account-priority";
3131
import { parseAccountPriority } from "./codex/pool-rotation";
3232
import { COMBO_NAMESPACE, comboConfigIssues } from "./combos/types";
3333
import { routingProfileIssues } from "./routing/profile";
34+
import { POLICY_NAMESPACE } from "./routing/profile-namespace";
3435
import {
3536
forgetEphemeralSecretPath,
3637
hardenSecretDir,
@@ -1115,6 +1116,7 @@ const configSchema = z.object({
11151116
const configuredProviderNamespaces = new Set([
11161117
COMBO_NAMESPACE,
11171118
OPENAI_CODEX_PROVIDER_ID,
1119+
POLICY_NAMESPACE,
11181120
...Object.keys(config.providers),
11191121
].map(codexProviderNamespaceKey));
11201122
const namespaceTargets = new Set(
@@ -1126,7 +1128,7 @@ const configSchema = z.object({
11261128
ctx.addIssue({
11271129
code: "custom",
11281130
path: ["codexAccountNamespaces", namespace],
1129-
message: "account selectors must not collide with configured provider or combo namespaces",
1131+
message: "account selectors must not collide with configured provider, combo, or routing policy namespaces",
11301132
});
11311133
}
11321134
if (configuredAccountIds.has(namespace) || namespaceTargets.has(namespace)) {

‎src/routing/profile-namespace.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { OcxRoutingProfileConfig } from "../types";
2+
3+
/** Canonical public namespace reserved for routing-policy model ids. */
4+
export const POLICY_NAMESPACE = "policy";
5+
6+
/** Public namespace prefixes claimed by slash-qualified routing-profile aliases. */
7+
export function routingProfileAliasNamespacePrefixes(
8+
config: { routingProfiles?: Record<string, OcxRoutingProfileConfig> },
9+
): string[] {
10+
return Object.values(config.routingProfiles ?? {}).flatMap((profile) => {
11+
const alias = typeof profile?.alias === "string" ? profile.alias.trim() : "";
12+
const slash = alias.indexOf("/");
13+
return slash > 0 ? [alias.slice(0, slash)] : [];
14+
});
15+
}

‎src/routing/profile.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import type {
1313
import { codexAccountNamespaceEntries } from "../codex/account-namespaces";
1414
import { listComboIds, resolveComboId } from "../combos";
1515
import { hasOwnProvider } from "../config";
16+
import { POLICY_NAMESPACE } from "./profile-namespace";
1617

17-
export const POLICY_NAMESPACE = "policy";
18+
export { POLICY_NAMESPACE };
1819

1920
export const POLICY_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
2021
export const POLICY_ALIAS_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}(?:\/[A-Za-z0-9][A-Za-z0-9._-]{0,63})?$/;

‎structure/03_catalog-and-subagents.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ Pool mode routes across main plus added Codex credentials. Key rules:
8383
- **A namespace is a public selector mapped to an internal target.** Generated selectors are how a
8484
caller names an account — the main login's selector is `main` (collision-suffixed if taken),
8585
which maps to the config-only sentinel `@main`; the sentinel deliberately sits outside the
86-
pool-account id grammar. Selectors must not collide with provider or combo ids
87-
(`src/codex/account-namespaces.ts`, `src/codex/account-namespace-match.ts`).
86+
pool-account id grammar. Selector initialization requires an explicit opt-in and fills only an
87+
absent or empty map; a non-empty user map keeps its object identity and insertion order. Generated
88+
selectors avoid provider, combo, routing-policy, and slash-qualified routing-profile namespaces.
89+
Collision checks normalize provider and reserved namespace keys, while account and
90+
routing-profile selector prefixes are exact-case (`src/codex/account-namespaces.ts`,
91+
`src/codex/account-namespace-match.ts`, `src/routing/profile-namespace.ts`).
8892
- **Selector labels carry no account-role semantics.** When at least one selector is advertisable,
8993
the Codex catalog clones each supported native row per selector and hides the bare picker rows;
9094
bare ids remain routable and stay in raw `/v1/models` unless explicitly disabled. Missing stored

0 commit comments

Comments
 (0)