@wengine-ai/ccr-provider-codex 1.0.7 → 1.0.8

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/README.md CHANGED
@@ -14,6 +14,8 @@ The callback binds `127.0.0.1:1455`, then registered fallback `1457`. If both ar
14
14
 
15
15
  After authorization, account-specific models are fetched dynamically. **Sync models** refreshes them. Login/model sync adds or updates only the `codex-subscription` managed provider; it never selects a Router default or changes unrelated providers (including a user-owned provider named `codex`). Choose routing explicitly in CCR. **Disconnect** removes this plugin's credential file and managed provider; Router references are intentionally not rewritten.
16
16
 
17
+ Models can be hidden from the card (the ✕ on a model chip): the blacklist persists in `codex-credentials.json`, survives sync and re-login, and removes the model from the managed provider's registered list without touching Router. Hidden models are restorable individually or all at once from the card's hidden-models list.
18
+
17
19
  ## Credentials and transport
18
20
 
19
21
  Tokens live in `<CCR_CONFIG_DIR>/codex-credentials.json`, atomically written with POSIX mode `0600`. They are not stored in ordinary provider config or returned in admin/status payloads. Protect this directory and its backups. Windows permission semantics differ.
package/dist/README.md CHANGED
@@ -14,6 +14,8 @@ The callback binds `127.0.0.1:1455`, then registered fallback `1457`. If both ar
14
14
 
15
15
  After authorization, account-specific models are fetched dynamically. **Sync models** refreshes them. Login/model sync adds or updates only the `codex-subscription` managed provider; it never selects a Router default or changes unrelated providers (including a user-owned provider named `codex`). Choose routing explicitly in CCR. **Disconnect** removes this plugin's credential file and managed provider; Router references are intentionally not rewritten.
16
16
 
17
+ Models can be hidden from the card (the ✕ on a model chip): the blacklist persists in `codex-credentials.json`, survives sync and re-login, and removes the model from the managed provider's registered list without touching Router. Hidden models are restorable individually or all at once from the card's hidden-models list.
18
+
17
19
  ## Credentials and transport
18
20
 
19
21
  Tokens live in `<CCR_CONFIG_DIR>/codex-credentials.json`, atomically written with POSIX mode `0600`. They are not stored in ordinary provider config or returned in admin/status payloads. Protect this directory and its backups. Windows permission semantics differ.
package/dist/card.js CHANGED
@@ -32,6 +32,8 @@ function parseCodexStatus(value) {
32
32
  if (typeof value.accountId === "string" && value.accountId) next.accountId = value.accountId;
33
33
  if (typeof value.email === "string" && value.email) next.email = value.email;
34
34
  if (typeof value.plan === "string" && value.plan) next.plan = value.plan;
35
+ const hiddenModels = stringArray(value.hiddenModels);
36
+ if (hiddenModels) next.hiddenModels = hiddenModels;
35
37
  const coolingUntil = finiteNumber(value.coolingUntil);
36
38
  if (coolingUntil !== null) next.coolingUntil = coolingUntil;
37
39
  if (typeof value.lastError === "string") next.lastError = value.lastError;
@@ -245,6 +247,14 @@ var codexLocales = {
245
247
  login_success_unknown: "Connected.",
246
248
  synced: "Synced {{count}} Codex models.",
247
249
  disconnected: "Disconnected.",
250
+ hide_model: "Hide {{model}}",
251
+ hidden_models: "Hidden models ({{count}})",
252
+ restore: "Restore",
253
+ restore_all: "Restore all",
254
+ hidden_toast: "Hidden {{model}}.",
255
+ restored_toast: "Restored {{model}}.",
256
+ restored_all_toast: "Restored {{count}} hidden models.",
257
+ hidden_note: "Hidden models stay hidden across sync and re-authorization and are excluded from the managed provider; restore them here at any time.",
248
258
  disconnect_title: "Disconnect Codex?",
249
259
  disconnect_warning: "The managed provider entry and stored authorization are removed. Your OpenAI plan itself is not touched, and Router/other providers are preserved. You can reconnect anytime.",
250
260
  usage_title: "Plan quota",
@@ -272,6 +282,8 @@ var codexLocales = {
272
282
  login_cancelled: "Login cancelled.",
273
283
  sync_failed: "Model sync failed.",
274
284
  disconnect_failed: "Disconnect failed.",
285
+ hide_failed: "Hiding the model failed.",
286
+ restore_failed: "Restoring the model failed.",
275
287
  callback_invalid: "That does not look like a valid callback URL (expected code and state parameters).",
276
288
  callback_rejected: "The callback was rejected. Please copy the full address and try again.",
277
289
  reconciliation_failed: "Applied, but the local settings draft could not be refreshed \u2014 reload the page to see the change."
@@ -321,6 +333,14 @@ var codexLocales = {
321
333
  login_success_unknown: "\u5DF2\u8FDE\u63A5\u3002",
322
334
  synced: "\u5DF2\u540C\u6B65 {{count}} \u4E2A Codex \u6A21\u578B\u3002",
323
335
  disconnected: "\u5DF2\u65AD\u5F00\u8FDE\u63A5\u3002",
336
+ hide_model: "\u9690\u85CF {{model}}",
337
+ hidden_models: "\u5DF2\u9690\u85CF\u6A21\u578B\uFF08{{count}}\uFF09",
338
+ restore: "\u6062\u590D",
339
+ restore_all: "\u6062\u590D\u5168\u90E8",
340
+ hidden_toast: "\u5DF2\u9690\u85CF {{model}}\u3002",
341
+ restored_toast: "\u5DF2\u6062\u590D {{model}}\u3002",
342
+ restored_all_toast: "\u5DF2\u6062\u590D {{count}} \u4E2A\u9690\u85CF\u6A21\u578B\u3002",
343
+ hidden_note: "\u9690\u85CF\u7684\u6A21\u578B\u5728\u540C\u6B65\u548C\u91CD\u65B0\u6388\u6743\u540E\u4FDD\u6301\u9690\u85CF\uFF0C\u4E0D\u4F1A\u6CE8\u518C\u5230\u6258\u7BA1\u4F9B\u5E94\u5546\uFF1B\u53EF\u968F\u65F6\u5728\u6B64\u6062\u590D\u3002",
324
344
  disconnect_title: "\u65AD\u5F00 Codex\uFF1F",
325
345
  disconnect_warning: "\u5C06\u79FB\u9664\u53D7\u7BA1\u4F9B\u5E94\u5546\u6761\u76EE\u548C\u5DF2\u5B58\u7684\u6388\u6743\u3002\u4E0D\u4F1A\u5F71\u54CD\u4F60\u7684 OpenAI \u8BA2\u9605\u672C\u8EAB\uFF0CRouter \u4E0E\u5176\u4ED6\u4F9B\u5E94\u5546\u4FDD\u6301\u4E0D\u53D8\u3002\u4E4B\u540E\u53EF\u968F\u65F6\u91CD\u65B0\u8FDE\u63A5\u3002",
326
346
  usage_title: "\u8BA2\u9605\u914D\u989D",
@@ -348,6 +368,8 @@ var codexLocales = {
348
368
  login_cancelled: "\u5DF2\u53D6\u6D88\u767B\u5F55\u3002",
349
369
  sync_failed: "\u6A21\u578B\u540C\u6B65\u5931\u8D25\u3002",
350
370
  disconnect_failed: "\u65AD\u5F00\u8FDE\u63A5\u5931\u8D25\u3002",
371
+ hide_failed: "\u9690\u85CF\u6A21\u578B\u5931\u8D25\u3002",
372
+ restore_failed: "\u6062\u590D\u6A21\u578B\u5931\u8D25\u3002",
351
373
  callback_invalid: "\u8FD9\u770B\u8D77\u6765\u4E0D\u662F\u6709\u6548\u7684\u56DE\u8C03\u5730\u5740\uFF08\u5E94\u5305\u542B code \u4E0E state \u53C2\u6570\uFF09\u3002",
352
374
  callback_rejected: "\u56DE\u8C03\u88AB\u62D2\u7EDD\uFF0C\u8BF7\u590D\u5236\u5B8C\u6574\u5730\u5740\u540E\u91CD\u8BD5\u3002",
353
375
  reconciliation_failed: "\u5DF2\u751F\u6548\uFF0C\u4F46\u672C\u5730\u8BBE\u7F6E\u8349\u7A3F\u672A\u80FD\u5237\u65B0\u2014\u2014\u5237\u65B0\u9875\u9762\u5373\u53EF\u770B\u5230\u53D8\u66F4\u3002"
@@ -673,7 +695,7 @@ function mount(el, props) {
673
695
  if (!background) props.onBusy?.(false);
674
696
  if (alive && generation === id) {
675
697
  locked = false;
676
- if (action === "usage") action = null;
698
+ if (action?.kind === "usage") action = null;
677
699
  }
678
700
  if (alive) render();
679
701
  }
@@ -689,11 +711,11 @@ function mount(el, props) {
689
711
  const id = generation;
690
712
  await readUsage(id, true);
691
713
  };
692
- const run = async (kind) => {
714
+ const run = async (kind, argument) => {
693
715
  if (!alive || locked || loading || props.disabled) return;
694
716
  if (kind === "usage") {
695
717
  locked = true;
696
- action = "usage";
718
+ action = { kind };
697
719
  usagePhase = "reading";
698
720
  errorKey = null;
699
721
  render();
@@ -710,7 +732,7 @@ function mount(el, props) {
710
732
  locked = true;
711
733
  const id = ++generation;
712
734
  props.onBusy?.(true);
713
- action = kind;
735
+ action = { kind, model: argument };
714
736
  errorKey = null;
715
737
  toast = null;
716
738
  reconcileFailed = false;
@@ -769,6 +791,29 @@ function mount(el, props) {
769
791
  reconcileFailed = failed;
770
792
  toast = t("synced", { count: result.modelCount ?? result.models?.length ?? 0 });
771
793
  if (fresh) usagePhase = "idle";
794
+ } else if (kind === "hide") {
795
+ const model = argument ?? "";
796
+ if (!model) return;
797
+ const result = parseCodexMutation(await post("/models/hide", { model }));
798
+ if (!result.success) {
799
+ if (alive && generation === id) errorKey = result.error ?? "hide_failed";
800
+ return;
801
+ }
802
+ const { reconcileFailed: failed } = await settle(id);
803
+ if (!alive || generation !== id) return;
804
+ reconcileFailed = failed;
805
+ toast = t("hidden_toast", { model });
806
+ } else if (kind === "restore") {
807
+ const hiddenCount = status?.hiddenModels?.length ?? 0;
808
+ const result = parseCodexMutation(await post("/models/restore", argument ? { model: argument } : {}));
809
+ if (!result.success) {
810
+ if (alive && generation === id) errorKey = result.error ?? "restore_failed";
811
+ return;
812
+ }
813
+ const { reconcileFailed: failed } = await settle(id);
814
+ if (!alive || generation !== id) return;
815
+ reconcileFailed = failed;
816
+ toast = argument ? t("restored_toast", { model: argument }) : t("restored_all_toast", { count: hiddenCount });
772
817
  } else {
773
818
  const result = parseCodexMutation(await post("/disconnect", {}));
774
819
  if (!result.success) {
@@ -787,7 +832,7 @@ function mount(el, props) {
787
832
  } catch (error) {
788
833
  if (alive && generation === id) {
789
834
  const reason = error?.reason;
790
- errorKey = sanitizeCodexErrorCode(typeof reason === "string" ? reason : null) ?? (kind === "login" ? "login_failed" : kind === "sync" ? "sync_failed" : "disconnect_failed");
835
+ errorKey = sanitizeCodexErrorCode(typeof reason === "string" ? reason : null) ?? (kind === "login" ? "login_failed" : kind === "sync" ? "sync_failed" : kind === "hide" ? "hide_failed" : kind === "restore" ? "restore_failed" : "disconnect_failed");
791
836
  }
792
837
  } finally {
793
838
  endBusy();
@@ -850,6 +895,7 @@ function mount(el, props) {
850
895
  const canDisconnect = !!status && (status.status !== "not_connected" || status.models.length > 0);
851
896
  const busy = loading || action !== null;
852
897
  const disabled = busy || props.disabled;
898
+ const pendingHide = (model) => action?.kind === "hide" && action.model === model;
853
899
  const card = styled("div", "glass-card rounded-2xl overflow-hidden mb-4");
854
900
  card.setAttribute("role", "group");
855
901
  card.setAttribute("aria-busy", String(busy));
@@ -893,13 +939,37 @@ function mount(el, props) {
893
939
  );
894
940
  }
895
941
  body.append(rows);
942
+ const hiddenModels = status.hiddenModels ?? [];
896
943
  if (status.models.length > 0) {
897
944
  const chips = styled("div", "flex flex-wrap gap-2 pt-1");
898
945
  for (const model of status.models) {
899
- chips.append(styled("span", "inline-flex max-w-full items-center gap-1 break-all whitespace-normal rounded-lg border border-white/5 bg-white/5 px-2 py-0.5 text-[10px] font-bold text-muted-foreground", model));
946
+ const chip = styled("span", "inline-flex max-w-full items-center gap-1 break-all whitespace-normal rounded-lg border border-white/5 bg-white/5 px-2 py-0.5 text-[10px] font-bold text-muted-foreground", model);
947
+ const hide = styled("button", "rounded p-0.5 text-muted-foreground/60 transition-colors hover:bg-white/10 hover:text-foreground disabled:opacity-40");
948
+ hide.type = "button";
949
+ hide.disabled = disabled;
950
+ hide.setAttribute("aria-label", t("hide_model", { model }));
951
+ hide.setAttribute("aria-busy", String(pendingHide(model)));
952
+ hide.append(xIcon("h-3 w-3"));
953
+ hide.onclick = () => void run("hide", model);
954
+ chip.append(hide);
955
+ chips.append(chip);
900
956
  }
901
957
  body.append(chips);
902
958
  }
959
+ if (hiddenModels.length > 0) {
960
+ const details = styled("details", "max-w-md text-xs text-muted-foreground");
961
+ details.append(styled("summary", "cursor-pointer select-none font-medium", t("hidden_models", { count: hiddenModels.length })));
962
+ const list = styled("ul", "mt-2 space-y-1");
963
+ for (const model of hiddenModels) {
964
+ const item = styled("li", "flex items-center justify-between gap-2");
965
+ item.append(styled("span", "break-all font-mono", model));
966
+ button(item, t("restore"), () => void run("restore", model), disabled, "outline", "h-6 shrink-0 px-2 text-[11px]");
967
+ list.append(item);
968
+ }
969
+ details.append(list);
970
+ button(details, t("restore_all"), () => void run("restore"), disabled, "outline", "mt-2 h-7 px-2 text-[11px]");
971
+ body.append(details);
972
+ }
903
973
  const usageBox = styled("div", "max-w-md space-y-1 rounded-lg border border-white/5 bg-white/5 px-3 py-2 text-xs");
904
974
  const usageHeader = styled("div", "flex flex-wrap items-center justify-between gap-2");
905
975
  usageHeader.append(styled("p", "font-medium text-foreground", t("usage_title")));
@@ -983,6 +1053,7 @@ function mount(el, props) {
983
1053
  about.append(styled("summary", "cursor-pointer select-none font-medium", t("about")));
984
1054
  const aboutBody = styled("div", "mt-2 space-y-1 leading-relaxed");
985
1055
  aboutBody.append(styled("p", "", t("about_body")));
1056
+ aboutBody.append(styled("p", "", t("hidden_note")));
986
1057
  aboutBody.append(styled("p", "", t("disclaimer")));
987
1058
  about.append(aboutBody);
988
1059
  body.append(about);
@@ -990,7 +1061,7 @@ function mount(el, props) {
990
1061
  const actions = styled("div", "flex shrink-0 flex-col gap-2 sm:w-[210px]");
991
1062
  button(
992
1063
  actions,
993
- action === "login" ? t("working") : connected || state === "needs_relogin" ? t("reconnect") : t("browser_login"),
1064
+ action?.kind === "login" ? t("working") : connected || state === "needs_relogin" ? t("reconnect") : t("browser_login"),
994
1065
  () => void run("login"),
995
1066
  disabled,
996
1067
  "primary",
@@ -1004,7 +1075,7 @@ function mount(el, props) {
1004
1075
  disabled || !connected,
1005
1076
  "outline",
1006
1077
  "h-8 w-full text-xs",
1007
- refreshCwIcon(`mr-1 h-3.5 w-3.5 ${action === "sync" ? "animate-spin" : ""}`)
1078
+ refreshCwIcon(`mr-1 h-3.5 w-3.5 ${action?.kind === "sync" ? "animate-spin" : ""}`)
1008
1079
  );
1009
1080
  button(actions, t("disconnect"), () => {
1010
1081
  confirmDisconnect = true;
package/dist/plugin.js CHANGED
@@ -364,6 +364,9 @@ function rateLimitsSaturated(limits, now) {
364
364
  }
365
365
  return false;
366
366
  }
367
+ function isCodexModelId(value) {
368
+ return typeof value === "string" && value.length > 0 && value.length <= 256 && !/[\x00-\x1f\x7f,]/.test(value);
369
+ }
367
370
  function isCodexManagedConfigProvider(p) {
368
371
  if (p?.codex_managed === true || p?.codexManaged === true) return true;
369
372
  const name = typeof p?.name === "string" ? p.name : "";
@@ -502,6 +505,14 @@ function normalizeCodexCredentialData(raw) {
502
505
  }
503
506
  }
504
507
  const rateLimits = normalizeRateLimits(raw.rateLimits);
508
+ const hiddenModels = [];
509
+ if (Array.isArray(raw.hiddenModels)) {
510
+ if (raw.hiddenModels.length > 256) throw invalid();
511
+ for (const m of raw.hiddenModels) {
512
+ if (!isCodexModelId(m) || hiddenModels.includes(m)) continue;
513
+ hiddenModels.push(m);
514
+ }
515
+ }
505
516
  return {
506
517
  version: 1,
507
518
  kind: "codex-subscription",
@@ -519,6 +530,7 @@ function normalizeCodexCredentialData(raw) {
519
530
  rateLimitCooldownUntil: cooldown(a.rateLimitCooldownUntil)
520
531
  },
521
532
  models,
533
+ hiddenModels,
522
534
  rateLimits
523
535
  };
524
536
  }
@@ -658,11 +670,12 @@ var CodexAuthService = class {
658
670
  // ------------------------------------------------------------------ status -
659
671
  async getStatus() {
660
672
  const data = await this.ensureLoaded();
661
- const models = await this.configManagedModels();
673
+ const hidden = new Set(data?.hiddenModels ?? []);
674
+ const models = (await this.configManagedModels()).filter((m) => !hidden.has(m));
662
675
  const account = data?.account;
663
676
  const now = this.now;
664
677
  if (!account) {
665
- return { status: "not_connected", providerName: CODEX_PROVIDER_NAME, models, modelCount: models.length };
678
+ return { status: "not_connected", providerName: CODEX_PROVIDER_NAME, models, modelCount: models.length, hiddenModels: [] };
666
679
  }
667
680
  const coolingUntil = this.latestCooldown(data);
668
681
  let status = "connected";
@@ -676,6 +689,7 @@ var CodexAuthService = class {
676
689
  ...account.plan ? { plan: account.plan } : {},
677
690
  models,
678
691
  modelCount: models.length,
692
+ hiddenModels: [...data?.hiddenModels ?? []],
679
693
  ...coolingUntil ? { coolingUntil } : {},
680
694
  lastError: account.lastError ? CODEX_SAFE_MESSAGES[account.lastError.code] ?? null : null
681
695
  };
@@ -717,22 +731,28 @@ var CodexAuthService = class {
717
731
  /**
718
732
  * Raw read → upsert only the managed entry (Router untouched) → write →
719
733
  * reload. `protectCodexConfig` is defence in depth; unrelated providers are
720
- * never rewritten.
734
+ * never rewritten. With `create: false` (hide/restore path) a missing
735
+ * managed entry is left alone — hiding a model must never resurrect a
736
+ * provider the user removed; the store-only change still stands (workbuddy
737
+ * parity: `if (providerIndex >= 0)`).
721
738
  */
722
- async upsertManagedProvider(models) {
739
+ async upsertManagedProvider(models, opts = {}) {
723
740
  const config = await this.options.host.readRawConfig?.().catch(() => null) ?? await this.options.host.readConfig().catch(() => ({}));
724
741
  const previousConfig = structuredClone(config ?? {});
725
742
  const routerBefore = JSON.stringify((config ?? {}).Router ?? null);
726
743
  let list = [];
727
744
  let usedKey = "Providers";
745
+ let found = false;
728
746
  for (const key of PROVIDER_KEYS) {
729
747
  if (Array.isArray(config?.[key])) {
730
748
  usedKey = key;
731
749
  list = config[key];
750
+ found = true;
732
751
  break;
733
752
  }
734
753
  }
735
- if (!Array.isArray(config?.[usedKey])) {
754
+ if (!found) {
755
+ if (opts.create === false) return false;
736
756
  if (!config || typeof config !== "object") throw codexAdminError("codex_config_write_failed", 500);
737
757
  config[usedKey] = list = [];
738
758
  }
@@ -742,6 +762,7 @@ var CodexAuthService = class {
742
762
  const enabled = existing.enabled !== false;
743
763
  list[index] = lockCodexProvider({ ...existing, models, enabled });
744
764
  } else {
765
+ if (opts.create === false) return false;
745
766
  list.push(lockCodexProvider({ name: CODEX_PROVIDER_NAME, models, enabled: true }));
746
767
  }
747
768
  config[usedKey] = list;
@@ -761,6 +782,78 @@ var CodexAuthService = class {
761
782
  throw codexAdminError("codex_config_write_failed", 500);
762
783
  }
763
784
  await this.options.host.reloadRuntime?.(config);
785
+ return true;
786
+ }
787
+ // ------------------------------------------------------- hide / restore ---
788
+ /**
789
+ * Workbuddy-style hide (§16 semantics without the Router rewriting): the
790
+ * blacklist is persisted in codex-credentials.json (survives sync/re-login),
791
+ * the model leaves the managed provider's registered models immediately, and
792
+ * Router is NEVER touched — re-wiring remains the user's explicit action.
793
+ * Store+config rollback on write failure. Idempotent: hiding twice keeps one
794
+ * blacklist entry. Hiding the LAST visible model is allowed (the provider
795
+ * then registers an empty list) — workbuddy behaves the same way.
796
+ */
797
+ async hideModel(model) {
798
+ if (!isCodexModelId(model)) throw codexAdminError("codex_model_invalid", 422);
799
+ return this.enqueueMutation(async () => {
800
+ const data = await this.store.load().catch(() => null);
801
+ if (!data?.account) throw codexAdminError("codex_not_connected", 409);
802
+ const hidden = /* @__PURE__ */ new Set([...data.hiddenModels, model]);
803
+ const visible = await this.computeVisibleModels(data.models.map((m) => m.slug), hidden);
804
+ try {
805
+ await this.saveData({ ...data, hiddenModels: [...hidden] });
806
+ await this.upsertManagedProvider(visible, { create: false });
807
+ } catch (error) {
808
+ await this.saveData(data).catch(() => this.log.error("[codex] hide rollback failed"));
809
+ if (error?.code === "codex_config_write_failed") throw error;
810
+ throw codexAdminError("codex_config_write_failed", 500);
811
+ }
812
+ return { success: true, model, models: visible, hiddenModels: [...hidden] };
813
+ });
814
+ }
815
+ /**
816
+ * Workbuddy-style restore: `model` omitted = restore ALL hidden models.
817
+ * Updates the blacklist + registered provider models ONLY — never Router.
818
+ * An unknown name is a successful no-op (idempotent), never an error.
819
+ */
820
+ async restoreModels(model) {
821
+ if (model !== void 0 && !isCodexModelId(model)) throw codexAdminError("codex_model_invalid", 422);
822
+ return this.enqueueMutation(async () => {
823
+ const data = await this.store.load().catch(() => null);
824
+ if (!data?.account) throw codexAdminError("codex_not_connected", 409);
825
+ const hidden = new Set(data.hiddenModels);
826
+ const restored = [];
827
+ if (model === void 0) {
828
+ restored.push(...hidden);
829
+ hidden.clear();
830
+ } else if (hidden.has(model)) {
831
+ hidden.delete(model);
832
+ restored.push(model);
833
+ }
834
+ const visible = await this.computeVisibleModels(data.models.map((m) => m.slug), hidden);
835
+ try {
836
+ await this.saveData({ ...data, hiddenModels: [...hidden] });
837
+ await this.upsertManagedProvider(visible, { create: false });
838
+ } catch (error) {
839
+ await this.saveData(data).catch(() => this.log.error("[codex] restore rollback failed"));
840
+ if (error?.code === "codex_config_write_failed") throw error;
841
+ throw codexAdminError("codex_config_write_failed", 500);
842
+ }
843
+ return { success: true, restored, models: visible, hiddenModels: [...hidden] };
844
+ });
845
+ }
846
+ /**
847
+ * Union of the stored credential models and whatever the managed provider
848
+ * currently registers, minus the hidden set. The union is what makes a
849
+ * restored model reappear even when the provider list was hand-edited.
850
+ */
851
+ async computeVisibleModels(storedSlugs, hidden) {
852
+ const config = await this.readRawConfig();
853
+ const provider = this.findManaged(config);
854
+ const registered = Array.isArray(provider?.models) ? provider.models.filter((m) => typeof m === "string") : [];
855
+ const union = /* @__PURE__ */ new Set([...storedSlugs, ...registered]);
856
+ return [...union].filter((m) => !hidden.has(m));
764
857
  }
765
858
  // ---------------------------------------------------------- browser login --
766
859
  async startLogin() {
@@ -1085,6 +1178,7 @@ var CodexAuthService = class {
1085
1178
  this.log.warn(`[codex] model discovery after login failed: ${error?.code ?? error?.name ?? "upstream"} ${cause} ${String(error?.message ?? "").slice(0, 120)}`);
1086
1179
  }
1087
1180
  const previous = await this.store.load().catch(() => null);
1181
+ const hidden = new Set(previous?.hiddenModels ?? []);
1088
1182
  const data = {
1089
1183
  version: 1,
1090
1184
  kind: "codex-subscription",
@@ -1106,16 +1200,18 @@ var CodexAuthService = class {
1106
1200
  displayName: m.displayName,
1107
1201
  ...m.instructions ? { instructions: m.instructions } : {}
1108
1202
  })),
1203
+ hiddenModels: [...hidden],
1109
1204
  rateLimits: null
1110
1205
  };
1111
1206
  const slugs = models.map((m) => m.slug);
1207
+ const registered = slugs.filter((s) => !hidden.has(s));
1112
1208
  try {
1113
1209
  await this.enqueueMutation(async () => {
1114
1210
  if (this.epoch !== epoch) throw codexAdminError("codex_login_cancelled", 409);
1115
1211
  await this.saveData(data);
1116
1212
  if (this.epoch !== epoch) throw codexAdminError("codex_login_cancelled", 409);
1117
1213
  try {
1118
- await this.upsertManagedProvider(slugs);
1214
+ await this.upsertManagedProvider(registered);
1119
1215
  } catch (error) {
1120
1216
  if (previous) await this.store.save(previous).catch(() => {
1121
1217
  });
@@ -1133,7 +1229,7 @@ var CodexAuthService = class {
1133
1229
  this.refreshFlight = null;
1134
1230
  this.forceRefreshRequested = false;
1135
1231
  this.usageCache = null;
1136
- const result = { status: "connected", models: slugs, modelCount: slugs.length };
1232
+ const result = { status: "connected", models: registered, modelCount: registered.length };
1137
1233
  job.result = result;
1138
1234
  this.lastResult.set(job.loginId, result);
1139
1235
  if (this.pending === job) this.pending = null;
@@ -1245,9 +1341,12 @@ var CodexAuthService = class {
1245
1341
  const visible = selectCodexModels(models);
1246
1342
  const slugs = visible.map((m) => m.slug);
1247
1343
  if (!slugs.length) throw codexAdminError("codex_models_fetch_failed", 502);
1344
+ let registered = slugs;
1248
1345
  await this.enqueueMutation(async () => {
1249
1346
  const current = await this.store.load().catch(() => null);
1250
1347
  if (!current) throw codexAdminError("codex_not_connected", 409);
1348
+ const hidden = new Set(current.hiddenModels);
1349
+ registered = slugs.filter((s) => !hidden.has(s));
1251
1350
  await this.saveData({
1252
1351
  ...current,
1253
1352
  account: { ...current.account, lastError: null },
@@ -1257,9 +1356,9 @@ var CodexAuthService = class {
1257
1356
  ...m.instructions ? { instructions: m.instructions } : {}
1258
1357
  }))
1259
1358
  });
1260
- await this.upsertManagedProvider(slugs);
1359
+ await this.upsertManagedProvider(registered);
1261
1360
  });
1262
- return { success: true, models: slugs, modelCount: slugs.length };
1361
+ return { success: true, models: registered, modelCount: registered.length };
1263
1362
  }
1264
1363
  /** Stable synchronous getter over the in-memory per-model instruction cache. */
1265
1364
  getModelInstructions(model) {
@@ -2085,7 +2184,8 @@ function registerCodexAdminRoutes(app, deps) {
2085
2184
  codex_credential_unreadable: 500,
2086
2185
  codex_config_write_failed: 500,
2087
2186
  codex_models_fetch_failed: 422,
2088
- codex_reauth_required: 422
2187
+ codex_reauth_required: 422,
2188
+ codex_model_invalid: 422
2089
2189
  };
2090
2190
  const isCodexErrorCode = (value) => typeof value === "string" && Object.prototype.hasOwnProperty.call(CODEX_ERROR_STATUS, value);
2091
2191
  function codexRouteError(error, reply, route, fallbackCode) {
@@ -2198,6 +2298,48 @@ function registerCodexAdminRoutes(app, deps) {
2198
2298
  return codexRouteError(error, reply, "sync", "codex_request_failed");
2199
2299
  }
2200
2300
  });
2301
+ app.post("/api/codex/models/hide", async (req, reply) => {
2302
+ try {
2303
+ assertLocalCodexRequest(req);
2304
+ const service = deps.getService();
2305
+ if (!service) {
2306
+ reply.status(503);
2307
+ return { ok: false, success: false, error: "codex_request_failed" };
2308
+ }
2309
+ const model = req.body?.model;
2310
+ if (!isCodexModelId(model)) {
2311
+ reply.status(422);
2312
+ return { ok: false, success: false, error: "codex_model_invalid" };
2313
+ }
2314
+ const result = await service.hideModel(model);
2315
+ return { ok: true, ...result };
2316
+ } catch (error) {
2317
+ return codexRouteError(error, reply, "models/hide", "codex_model_hide_failed");
2318
+ }
2319
+ });
2320
+ app.post("/api/codex/models/restore", async (req, reply) => {
2321
+ try {
2322
+ assertLocalCodexRequest(req);
2323
+ const service = deps.getService();
2324
+ if (!service) {
2325
+ reply.status(503);
2326
+ return { ok: false, success: false, error: "codex_request_failed" };
2327
+ }
2328
+ const raw = req.body?.model;
2329
+ let model;
2330
+ if (raw !== void 0 && raw !== null && raw !== "") {
2331
+ if (!isCodexModelId(raw)) {
2332
+ reply.status(422);
2333
+ return { ok: false, success: false, error: "codex_model_invalid" };
2334
+ }
2335
+ model = raw;
2336
+ }
2337
+ const result = await service.restoreModels(model);
2338
+ return { ok: true, ...result };
2339
+ } catch (error) {
2340
+ return codexRouteError(error, reply, "models/restore", "codex_model_restore_failed");
2341
+ }
2342
+ });
2201
2343
  app.post("/api/codex/usage", async (req, reply) => {
2202
2344
  try {
2203
2345
  assertLocalCodexRequest(req);
@@ -2273,6 +2415,14 @@ var codexLocales = {
2273
2415
  login_success_unknown: "Connected.",
2274
2416
  synced: "Synced {{count}} Codex models.",
2275
2417
  disconnected: "Disconnected.",
2418
+ hide_model: "Hide {{model}}",
2419
+ hidden_models: "Hidden models ({{count}})",
2420
+ restore: "Restore",
2421
+ restore_all: "Restore all",
2422
+ hidden_toast: "Hidden {{model}}.",
2423
+ restored_toast: "Restored {{model}}.",
2424
+ restored_all_toast: "Restored {{count}} hidden models.",
2425
+ hidden_note: "Hidden models stay hidden across sync and re-authorization and are excluded from the managed provider; restore them here at any time.",
2276
2426
  disconnect_title: "Disconnect Codex?",
2277
2427
  disconnect_warning: "The managed provider entry and stored authorization are removed. Your OpenAI plan itself is not touched, and Router/other providers are preserved. You can reconnect anytime.",
2278
2428
  usage_title: "Plan quota",
@@ -2300,6 +2450,8 @@ var codexLocales = {
2300
2450
  login_cancelled: "Login cancelled.",
2301
2451
  sync_failed: "Model sync failed.",
2302
2452
  disconnect_failed: "Disconnect failed.",
2453
+ hide_failed: "Hiding the model failed.",
2454
+ restore_failed: "Restoring the model failed.",
2303
2455
  callback_invalid: "That does not look like a valid callback URL (expected code and state parameters).",
2304
2456
  callback_rejected: "The callback was rejected. Please copy the full address and try again.",
2305
2457
  reconciliation_failed: "Applied, but the local settings draft could not be refreshed \u2014 reload the page to see the change."
@@ -2349,6 +2501,14 @@ var codexLocales = {
2349
2501
  login_success_unknown: "\u5DF2\u8FDE\u63A5\u3002",
2350
2502
  synced: "\u5DF2\u540C\u6B65 {{count}} \u4E2A Codex \u6A21\u578B\u3002",
2351
2503
  disconnected: "\u5DF2\u65AD\u5F00\u8FDE\u63A5\u3002",
2504
+ hide_model: "\u9690\u85CF {{model}}",
2505
+ hidden_models: "\u5DF2\u9690\u85CF\u6A21\u578B\uFF08{{count}}\uFF09",
2506
+ restore: "\u6062\u590D",
2507
+ restore_all: "\u6062\u590D\u5168\u90E8",
2508
+ hidden_toast: "\u5DF2\u9690\u85CF {{model}}\u3002",
2509
+ restored_toast: "\u5DF2\u6062\u590D {{model}}\u3002",
2510
+ restored_all_toast: "\u5DF2\u6062\u590D {{count}} \u4E2A\u9690\u85CF\u6A21\u578B\u3002",
2511
+ hidden_note: "\u9690\u85CF\u7684\u6A21\u578B\u5728\u540C\u6B65\u548C\u91CD\u65B0\u6388\u6743\u540E\u4FDD\u6301\u9690\u85CF\uFF0C\u4E0D\u4F1A\u6CE8\u518C\u5230\u6258\u7BA1\u4F9B\u5E94\u5546\uFF1B\u53EF\u968F\u65F6\u5728\u6B64\u6062\u590D\u3002",
2352
2512
  disconnect_title: "\u65AD\u5F00 Codex\uFF1F",
2353
2513
  disconnect_warning: "\u5C06\u79FB\u9664\u53D7\u7BA1\u4F9B\u5E94\u5546\u6761\u76EE\u548C\u5DF2\u5B58\u7684\u6388\u6743\u3002\u4E0D\u4F1A\u5F71\u54CD\u4F60\u7684 OpenAI \u8BA2\u9605\u672C\u8EAB\uFF0CRouter \u4E0E\u5176\u4ED6\u4F9B\u5E94\u5546\u4FDD\u6301\u4E0D\u53D8\u3002\u4E4B\u540E\u53EF\u968F\u65F6\u91CD\u65B0\u8FDE\u63A5\u3002",
2354
2514
  usage_title: "\u8BA2\u9605\u914D\u989D",
@@ -2376,6 +2536,8 @@ var codexLocales = {
2376
2536
  login_cancelled: "\u5DF2\u53D6\u6D88\u767B\u5F55\u3002",
2377
2537
  sync_failed: "\u6A21\u578B\u540C\u6B65\u5931\u8D25\u3002",
2378
2538
  disconnect_failed: "\u65AD\u5F00\u8FDE\u63A5\u5931\u8D25\u3002",
2539
+ hide_failed: "\u9690\u85CF\u6A21\u578B\u5931\u8D25\u3002",
2540
+ restore_failed: "\u6062\u590D\u6A21\u578B\u5931\u8D25\u3002",
2379
2541
  callback_invalid: "\u8FD9\u770B\u8D77\u6765\u4E0D\u662F\u6709\u6548\u7684\u56DE\u8C03\u5730\u5740\uFF08\u5E94\u5305\u542B code \u4E0E state \u53C2\u6570\uFF09\u3002",
2380
2542
  callback_rejected: "\u56DE\u8C03\u88AB\u62D2\u7EDD\uFF0C\u8BF7\u590D\u5236\u5B8C\u6574\u5730\u5740\u540E\u91CD\u8BD5\u3002",
2381
2543
  reconciliation_failed: "\u5DF2\u751F\u6548\uFF0C\u4F46\u672C\u5730\u8BBE\u7F6E\u8349\u7A3F\u672A\u80FD\u5237\u65B0\u2014\u2014\u5237\u65B0\u9875\u9762\u5373\u53EF\u770B\u5230\u53D8\u66F4\u3002"
@@ -2387,7 +2549,7 @@ var codexLocales = {
2387
2549
  // src/plugin.ts
2388
2550
  var manifest = {
2389
2551
  name: "codex",
2390
- version: "1.0.7",
2552
+ version: "1.0.8",
2391
2553
  coreApi: "1",
2392
2554
  description: "Codex subscription managed provider: chatgpt.com backend-api/codex data plane, browser OAuth login (PKCE, loopback 1455/1457 + paste), model sync, usage and admin routes."
2393
2555
  };
package/dist/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "coreApi": "1",
5
5
  "description": "Codex subscription managed provider: chatgpt.com backend-api/codex data plane, browser OAuth login (PKCE, loopback 1455/1457 + paste), model sync, usage and admin routes."
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wengine-ai/ccr-provider-codex",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Codex subscription provider plugin for claude-code-router: browser OAuth login, fixed-origin responses data plane, transformer, managed runtime, admin routes, config protector and UI card.",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",