From ac14d8e7c53e43340275f5af491c6613248f3f1e Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 9 Jun 2026 05:05:28 +0000 Subject: [PATCH] feat: add fixwikihub codex pool profile --- config/platform-infra/sub2api-codex-pool.yaml | 5 +++ docs/reference/cli.md | 2 +- docs/reference/platform-infra.md | 9 +++++ scripts/src/platform-infra-sub2api-codex.ts | 34 ++++++++++++++++--- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/config/platform-infra/sub2api-codex-pool.yaml b/config/platform-infra/sub2api-codex-pool.yaml index c8fc058d..b97a04ab 100644 --- a/config/platform-infra/sub2api-codex-pool.yaml +++ b/config/platform-infra/sub2api-codex-pool.yaml @@ -24,6 +24,11 @@ profiles: accountName: unidesk-codex-pinche configFile: config.toml.pinche authFile: auth.json.pinche + - profile: fixwikihub + accountName: unidesk-codex-fixwikihub + configFile: config.toml.fixwikihub + authFile: auth.json.fixwikihub + openaiResponsesWebSocketsV2Mode: ctx_pool publicExposure: enabled: true proxyName: platform-infra-sub2api diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 7e9f4ac9..62717c38 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -68,7 +68,7 @@ CI/CD、GitOps、rollout、artifact 发布、PR 合并后的 runtime lane 滚动 - `hwlab g14 git-mirror status|apply|sync|flush [--dry-run|--confirm]` 是 `devops-infra` git mirror/relay 的受控维护入口:`apply` 渲染并 server-side apply `devops-infra/git-mirror.yaml`,同时删除遗留 `git-mirror-hwlab-sync` CronJob;`sync` 创建一次性 manual Job,把 GitHub allowlist refs 拉入本地 mirror;`flush` 创建一次性 manual Job,把本地 `v0.2-gitops` 快进推回 GitHub。 `status` 返回 read/write URL、last sync/write/flush、本地 ref、GitHub staging ref 和 pending flush 状态,并在 `cache.summary` 给出 `localV02`、`localGitops`、`githubGitops`、`pendingFlush`、`flushNeeded`、`githubInSync` 和下一条受控 `flushCommand`。confirmed `sync` 和 `flush` 默认创建 `.state/jobs/` 异步 job 并立刻返回可查询状态,只有现场同步调试才显式加 `--wait`;mirror 不设置 CronJob。 如果 PipelineRun 的 `gitops-promote` 阶段报 git mirror 控制面漂移或 refs 不一致,先执行 `hwlab g14 git-mirror apply --confirm` 重新应用当前 `devops-infra/git-mirror.yaml` hook/ConfigMap,再执行 `hwlab g14 git-mirror sync --confirm --wait` 复核 refs;失败的同名 PipelineRun 只能通过 `hwlab g14 control-plane cleanup-runs --lane --pipeline-run --confirm` 受控清理后重试,不要用原生 `kubectl delete` 或手工改 mirror hook。修复后仍必须用 `control-plane status --pipeline-run ` 和 `git-mirror status` 分别确认 runtime closeout 与 GitHub flush。 -- `platform-infra sub2api plan|apply|status|validate|codex-pool` 是 G14 `platform-infra` namespace 内 Sub2API 的受控入口。镜像版本由 `config/platform-infra/sub2api.yaml` 控制,Codex 上游池、统一 API key Secret、FRP 公网端口和 master `~/.codex` 消费端由 `config/platform-infra/sub2api-codex-pool.yaml` 控制;`codex-pool sync --confirm` 从 YAML 指定的 `~/.codex/config.toml*`/`auth.json*` 导入四个上游账号到同一 Sub2API group,统一消费 key 固定存放在 `platform-infra/sub2api-codex-pool-api-key.API_KEY`。`codex-pool expose --confirm` 只新增明确 FRPS allow port 和 `platform-infra/sub2api-frpc`,不得扩大端口段;`codex-pool configure-local --confirm` 先把当前 `~/.codex/config.toml`、`auth.json` 备份成 `*.pre-sub2api`,再把默认 provider 指向 master 本机 FRP 入口。所有输出只允许打印 key preview/fingerprint、字节数和 Secret 路径,不打印完整 API key。 +- `platform-infra sub2api plan|apply|status|validate|codex-pool` 是 G14 `platform-infra` namespace 内 Sub2API 的受控入口。镜像版本由 `config/platform-infra/sub2api.yaml` 控制,Codex 上游池、统一 API key Secret、FRP 公网端口和 master `~/.codex` 消费端由 `config/platform-infra/sub2api-codex-pool.yaml` 控制;`codex-pool sync --confirm` 从 YAML 指定的 `~/.codex/config.toml*`/`auth.json*` 导入 YAML 声明的上游账号到同一 Sub2API group,统一消费 key 固定存放在 `platform-infra/sub2api-codex-pool-api-key.API_KEY`。`profiles.entries[].openaiResponsesWebSocketsV2Mode` 用于对接需要 Responses WebSocket v2 的 OpenAI-compatible 上游,新增或调整上游优先改 YAML 后 `codex-pool sync --confirm`,不改代码、不走 CI/CD。`codex-pool expose --confirm` 只新增明确 FRPS allow port 和 `platform-infra/sub2api-frpc`,不得扩大端口段;`codex-pool configure-local --confirm` 先把当前 `~/.codex/config.toml`、`auth.json` 备份成 `*.pre-sub2api`,再把默认 provider 指向 master 本机 FRP 入口。`validate`/`codex-pool validate` 是按需验收,不是连续可用性探针;完整 namespace 边界、路由和探针口径见 `docs/reference/platform-infra.md`。所有输出只允许打印 key preview/fingerprint、字节数和 Secret 路径,不打印完整 API key。 - `hwlab g14 observability status|apply|query|targets|boundary|closeout [--lane v02] [--promql ] [--expect-count N] [--expect-value V] [--dry-run|--confirm]` 是 G14 `devops-infra` 共享监控基础设施和 HWLAB v0.2 监控 closeout 的受控入口。`apply` 固定安装 Prometheus Operator `v0.91.0`、Prometheus `v3.12.0`、Prometheus 发现 RBAC、`devops-infra` 内 Prometheus 实例和 ClusterIP query Service,并给被允许发现的 workload namespace 打低风险 label;它不把 Prometheus、Grafana 或 Alertmanager 部署到 `hwlab-v02`,也不接管 HWLAB runtime Deployment/Service。`status` 只读汇总 CRD、operator Deployment、Prometheus CR/pod/service、`hwlab-v02` ServiceMonitor/PrometheusRule 和 bounded `up` 查询;`query` 只通过 Kubernetes service proxy 查询 Prometheus,支持 `--expect-count` / `--expect-value` 输出 `assertion`、bad values 和 missing/extra series;`targets` 汇总 ServiceMonitor/PrometheusRule、metrics sidecar readiness/restart、三层指标值和 `metrics.k8s.io` 当前 CPU/内存资源快照;`boundary` 验证 workload namespace 没有 Prometheus/Alertmanager,并对 `19666/19667` 公网 `/metrics` 做负向验证;`closeout` 聚合平台 ready、scrape reachable、sidecar serving、business health probe、resource snapshot、namespace boundary 和 public metrics exposure 语义结论。长期边界见 `docs/reference/g14-observability-infra.md`。 - `hwlab g14 tools-image status|build --name ci-node-tools --tag [--dockerfile deploy/ci/hwlab-ci-node-tools.Dockerfile] [--dry-run|--confirm]` 是 G14 固定 HWLAB CI tools image 的受控 host build/push 入口;构建和 push 只发生在 G14 host 与本地 registry,不在 master server 构建,也不把 `apk add`/runtime install 塞进 Tekton PipelineRun。 - `trans gh:/owner/repo ...` 把 GitHub issue/PR 映射成只读/受控写入的虚拟文本目录,适合日报、PR 正文和 issue 正文的小补丁维护:`trans gh:/pikasTech/HWLAB ls` 展示 `pr/` 与 `issue/`,`trans gh:/pikasTech/HWLAB/pr ls [--limit N] [--full]` 和 `trans gh:/pikasTech/HWLAB/issue ls [--limit N] [--full]` 展示条目状态、楼层数、正文长度和标题,`trans gh:/pikasTech/HWLAB/pr/507 ls` 展示单个 PR 的一楼正文文件,`trans gh:/pikasTech/HWLAB/505/1 cat|rg|patch-apply` 兼容旧式 issue/PR number route。`patch-apply` 使用 UniDesk 默认 apply-patch v2 的虚拟文件 executor,把正文一楼映射为 `body.md`,写回仍走 `bun scripts/cli.ts gh issue/pr update` 的 guard/concurrency 规则;`rm` 对正文一楼结构化拒绝,避免误删 issue/PR 正文。大正文读取必须展开 UniDesk gh dump 文件,否则 `cat/rg/patch-apply` 会误读为空,这是 `gh:` 虚拟文件接口的 P0 可见性契约。 diff --git a/docs/reference/platform-infra.md b/docs/reference/platform-infra.md index 34221aa0..b0dbe440 100644 --- a/docs/reference/platform-infra.md +++ b/docs/reference/platform-infra.md @@ -25,6 +25,7 @@ - `pool.groupName` names the Sub2API group that represents the pool. - `pool.apiKeySecretName` and `pool.apiKeySecretKey` name the k3s Secret that stores the single consumer API key. - `profiles.entries` selects local Codex profile files from `~/.codex/` and maps them to Sub2API account names. +- `profiles.entries[].openaiResponsesWebSocketsV2Mode` is the account-level Responses WebSocket v2 switch for OpenAI-compatible upstreams that require WebSocket transport. Allowed values are `off`, `ctx_pool`, and `passthrough`; omit the field unless that upstream needs it. - `publicExposure` controls the optional FRP bridge from master server to the G14 ClusterIP service. - `localCodex` controls how the master server's current `~/.codex` consumer files are backed up and rewritten. @@ -36,8 +37,16 @@ The request path is: 4. Sub2API validates the unified key and resolves its `group_id`. 5. Accounts listed in `profiles.entries` are bound to the same group via `group_ids`, so Sub2API dispatches through that group using its own account selection semantics. +Adding an upstream should be a fast YAML operation: create the corresponding local `~/.codex/config.toml.` and `auth.json.` inputs, add one `profiles.entries` item, then run `platform-infra sub2api codex-pool plan|sync --confirm`. Do not add code or CI/CD for ordinary pool membership changes. Code changes are only appropriate when the YAML schema needs a new reusable capability such as account-level WebSocket mode. + After `codex-pool configure-local --confirm`, the default upstream profile must not recursively import the just-created Sub2API consumer endpoint as an upstream account. Keep the default source profile pointed at `config.toml.` and `auth.json.`; fallback to the current default files is only for first bootstrap before backups exist. +## Public FRP Boundary + +When `publicExposure.enabled` is true, the same FRP TCP bridge exposes both OpenAI-compatible API paths and the built-in Sub2API management frontend. The management UI is reachable at the configured `publicExposure.publicBaseUrl` and its `/login` route; do not allocate a second public port unless a separate YAML-controlled exposure decision exists. + +The public management UI is an operations endpoint. Keep Sub2API itself in `platform-infra`, keep the Kubernetes Service as ClusterIP, and treat FRP as the only public bridge unless a later decision explicitly changes the exposure model. + ## Availability And Probes Kubernetes readiness is not the same as pool availability: diff --git a/scripts/src/platform-infra-sub2api-codex.ts b/scripts/src/platform-infra-sub2api-codex.ts index a84e40da..6359633a 100644 --- a/scripts/src/platform-infra-sub2api-codex.ts +++ b/scripts/src/platform-infra-sub2api-codex.ts @@ -44,11 +44,14 @@ interface CodexProfile { envKey: string | null; apiKey: string | null; apiKeySource: "auth-json" | "env" | null; + openaiResponsesWebSocketsV2Mode: OpenAIResponsesWebSocketsV2Mode | null; authOpenAIKeyShape: string; ok: boolean; error: string | null; } +type OpenAIResponsesWebSocketsV2Mode = "off" | "ctx_pool" | "passthrough"; + interface CodexPoolConfig { groupName: string; apiKeyName: string; @@ -67,6 +70,7 @@ interface CodexPoolProfileConfig { authFile: string; fallbackConfigFile: string | null; fallbackAuthFile: string | null; + openaiResponsesWebSocketsV2Mode: OpenAIResponsesWebSocketsV2Mode | null; } interface CodexPoolPublicExposureConfig { @@ -232,6 +236,7 @@ async function codexPoolSync(config: UniDeskConfig, options: SyncOptions): Promi apiKey: profile.apiKey, apiKeySource: profile.apiKeySource, apiKeyFingerprint: fingerprint(profile.apiKey ?? ""), + openaiResponsesWebSocketsV2Mode: profile.openaiResponsesWebSocketsV2Mode, })), }; const result = await capture(config, g14K3sRoute, ["script"], syncScript(payload, pool)); @@ -412,6 +417,7 @@ function collectCodexProfiles(): CodexProfile[] { envKey: null, apiKey: null, apiKeySource: null, + openaiResponsesWebSocketsV2Mode: entry.openaiResponsesWebSocketsV2Mode, authOpenAIKeyShape: existsSync(authPath) ? "unknown" : "missing", ok: false, error: null, @@ -474,6 +480,7 @@ function discoverCodexProfileConfigs(codexDir: string): CodexPoolProfileConfig[] authFile: suffix === "" ? "auth.json" : `auth.json.${suffix}`, fallbackConfigFile: null, fallbackAuthFile: null, + openaiResponsesWebSocketsV2Mode: null, }; }); } @@ -568,6 +575,7 @@ function readProfileConfig(value: unknown, defaults: CodexPoolProfileConfig[]): const fallbackAuthFile = stringValue(entry.fallbackAuthFile); if (fallbackConfigFile !== null) validateCodexFileName(fallbackConfigFile, `profiles.entries[${index}].fallbackConfigFile`); if (fallbackAuthFile !== null) validateCodexFileName(fallbackAuthFile, `profiles.entries[${index}].fallbackAuthFile`); + const openaiResponsesWebSocketsV2Mode = readOpenAIResponsesWebSocketsV2Mode(entry.openaiResponsesWebSocketsV2Mode, `profiles.entries[${index}].openaiResponsesWebSocketsV2Mode`); return { profile, accountName, @@ -575,10 +583,19 @@ function readProfileConfig(value: unknown, defaults: CodexPoolProfileConfig[]): authFile, fallbackConfigFile, fallbackAuthFile, + openaiResponsesWebSocketsV2Mode, }; }); } +function readOpenAIResponsesWebSocketsV2Mode(value: unknown, key: string): OpenAIResponsesWebSocketsV2Mode | null { + if (value === undefined || value === null) return null; + const text = stringValue(value); + if (text === null) throw new Error(`${codexPoolConfigPath}.${key} must be a string`); + if (text === "off" || text === "ctx_pool" || text === "passthrough") return text; + throw new Error(`${codexPoolConfigPath}.${key} must be one of off, ctx_pool, passthrough`); +} + function readPublicExposureConfig(value: unknown, defaults: CodexPoolPublicExposureConfig): CodexPoolPublicExposureConfig { if (!isRecord(value)) return defaults; const masterFrpsValue = isRecord(value.masterFrps) ? value.masterFrps : {}; @@ -678,6 +695,7 @@ function redactProfile(profile: CodexProfile): Record { model: profile.model, envKey: profile.envKey, apiKeySource: profile.apiKeySource, + openaiResponsesWebSocketsV2Mode: profile.openaiResponsesWebSocketsV2Mode, apiKeyPresent: profile.apiKey !== null && profile.apiKey.length > 0, apiKeyBytes: profile.apiKey === null ? 0 : Buffer.byteLength(profile.apiKey, "utf8"), apiKeyFingerprint: profile.apiKey === null ? null : fingerprint(profile.apiKey), @@ -1423,6 +1441,15 @@ def list_accounts(token): return extract_items(data) def account_payload(profile, group_id): + extra = { + "openai_responses_mode": "force_responses", + "unidesk_codex_profile": profile["profile"], + "unidesk_managed": True, + } + ws_mode = profile.get("openaiResponsesWebSocketsV2Mode") + if ws_mode: + extra["openai_apikey_responses_websockets_v2_mode"] = ws_mode + extra["openai_apikey_responses_websockets_v2_enabled"] = ws_mode != "off" return { "name": profile["accountName"], "notes": f"UniDesk-managed Codex profile {profile['profile']} from {profile['configFile']} and {profile['authFile']}; secret source={profile['apiKeySource']}; fingerprint={profile['apiKeyFingerprint']}.", @@ -1432,11 +1459,7 @@ def account_payload(profile, group_id): "api_key": profile["apiKey"], "base_url": profile["baseUrl"], }, - "extra": { - "openai_responses_mode": "force_responses", - "unidesk_codex_profile": profile["profile"], - "unidesk_managed": True, - }, + "extra": extra, "concurrency": 1, "priority": 1, "rate_multiplier": 1, @@ -1469,6 +1492,7 @@ def ensure_accounts(token, profiles, group_id): "baseUrl": profile["baseUrl"], "apiKeySource": profile["apiKeySource"], "apiKeyFingerprint": profile["apiKeyFingerprint"], + "openaiResponsesWebSocketsV2Mode": profile.get("openaiResponsesWebSocketsV2Mode"), "valuesPrinted": False, }) return results