@wengine-ai/ccr-provider-codex 1.0.8 → 1.0.10
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 +1 -1
- package/dist/README.md +1 -1
- package/dist/card.js +40 -7
- package/dist/plugin.js +106 -67
- package/dist/plugin.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ 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
|
|
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. Matching Router default references move to the first remaining visible model (or become empty if none remain); matching scenario, model-alias and family-default references are cleared. Fallback stages and per-project routing are unchanged. Hidden models are restorable individually or all at once from the card's hidden-models list.
|
|
18
18
|
|
|
19
19
|
## Credentials and transport
|
|
20
20
|
|
package/dist/README.md
CHANGED
|
@@ -14,7 +14,7 @@ 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
|
|
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. Matching Router default references move to the first remaining visible model (or become empty if none remain); matching scenario, model-alias and family-default references are cleared. Fallback stages and per-project routing are unchanged. Hidden models are restorable individually or all at once from the card's hidden-models list.
|
|
18
18
|
|
|
19
19
|
## Credentials and transport
|
|
20
20
|
|
package/dist/card.js
CHANGED
|
@@ -202,6 +202,35 @@ function clearCodexUsageCache() {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
// src/router.ts
|
|
206
|
+
var record = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
207
|
+
function clearCodexRouterRefs(router, hidden, firstVisible) {
|
|
208
|
+
if (!record(router)) return router;
|
|
209
|
+
const next = structuredClone(router);
|
|
210
|
+
const hit = (value) => {
|
|
211
|
+
if (typeof value !== "string") return false;
|
|
212
|
+
const parts = value.split(",").map((part) => part.trim());
|
|
213
|
+
return parts.length === 2 && parts[0] === CODEX_PROVIDER_NAME && hidden.has(parts[1]);
|
|
214
|
+
};
|
|
215
|
+
if (hit(next.default)) next.default = firstVisible ? `${CODEX_PROVIDER_NAME},${firstVisible}` : "";
|
|
216
|
+
for (const [key, value] of Object.entries(next)) {
|
|
217
|
+
if (["default", "models", "families", "fallback"].includes(key)) continue;
|
|
218
|
+
if (hit(value)) next[key] = "";
|
|
219
|
+
else if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
220
|
+
next[key] = value.filter((item) => !hit(item));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (record(next.models)) {
|
|
224
|
+
for (const [key, value] of Object.entries(next.models)) if (hit(value)) delete next.models[key];
|
|
225
|
+
}
|
|
226
|
+
if (record(next.families)) {
|
|
227
|
+
for (const family of Object.values(next.families)) {
|
|
228
|
+
if (record(family) && hit(family.default)) family.default = "";
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return next;
|
|
232
|
+
}
|
|
233
|
+
|
|
205
234
|
// src/locales.ts
|
|
206
235
|
var codexLocales = {
|
|
207
236
|
en: {
|
|
@@ -248,13 +277,13 @@ var codexLocales = {
|
|
|
248
277
|
synced: "Synced {{count}} Codex models.",
|
|
249
278
|
disconnected: "Disconnected.",
|
|
250
279
|
hide_model: "Hide {{model}}",
|
|
251
|
-
hidden_models: "Hidden models ({{count}})",
|
|
280
|
+
hidden_models: "Hidden models ({{count}}) \u2014 routing references cleared",
|
|
252
281
|
restore: "Restore",
|
|
253
282
|
restore_all: "Restore all",
|
|
254
283
|
hidden_toast: "Hidden {{model}}.",
|
|
255
284
|
restored_toast: "Restored {{model}}.",
|
|
256
285
|
restored_all_toast: "Restored {{count}} hidden models.",
|
|
257
|
-
hidden_note: "Hidden models stay hidden across sync and re-authorization
|
|
286
|
+
hidden_note: "Hidden models stay hidden across sync and re-authorization. Matching routing references are cleared; default moves to the first visible model or becomes empty when none remain. Restore models here; restoring does not restore old routes.",
|
|
258
287
|
disconnect_title: "Disconnect Codex?",
|
|
259
288
|
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.",
|
|
260
289
|
usage_title: "Plan quota",
|
|
@@ -334,13 +363,13 @@ var codexLocales = {
|
|
|
334
363
|
synced: "\u5DF2\u540C\u6B65 {{count}} \u4E2A Codex \u6A21\u578B\u3002",
|
|
335
364
|
disconnected: "\u5DF2\u65AD\u5F00\u8FDE\u63A5\u3002",
|
|
336
365
|
hide_model: "\u9690\u85CF {{model}}",
|
|
337
|
-
hidden_models: "\u5DF2\u9690\u85CF\u6A21\u578B\uFF08{{count}}\uFF09",
|
|
366
|
+
hidden_models: "\u5DF2\u9690\u85CF\u6A21\u578B\uFF08{{count}}\uFF09\u2014 \u5DF2\u6E05\u7406\u8DEF\u7531\u5F15\u7528",
|
|
338
367
|
restore: "\u6062\u590D",
|
|
339
368
|
restore_all: "\u6062\u590D\u5168\u90E8",
|
|
340
369
|
hidden_toast: "\u5DF2\u9690\u85CF {{model}}\u3002",
|
|
341
370
|
restored_toast: "\u5DF2\u6062\u590D {{model}}\u3002",
|
|
342
371
|
restored_all_toast: "\u5DF2\u6062\u590D {{count}} \u4E2A\u9690\u85CF\u6A21\u578B\u3002",
|
|
343
|
-
hidden_note: "\u9690\u85CF\
|
|
372
|
+
hidden_note: "\u9690\u85CF\u6A21\u578B\u5728\u540C\u6B65\u548C\u91CD\u65B0\u6388\u6743\u540E\u4FDD\u6301\u9690\u85CF\u3002\u76F8\u5173\u8DEF\u7531\u5F15\u7528\u4F1A\u88AB\u6E05\u7406\uFF0C\u9ED8\u8BA4\u8DEF\u7531\u6539\u4E3A\u9996\u4E2A\u53EF\u89C1\u6A21\u578B\uFF1B\u82E5\u5168\u90E8\u9690\u85CF\u5219\u6E05\u7A7A\u9ED8\u8BA4\u8DEF\u7531\u3002\u53EF\u5728\u6B64\u6062\u590D\u6A21\u578B\uFF0C\u4F46\u4E0D\u4F1A\u6062\u590D\u65E7\u8DEF\u7531\u3002",
|
|
344
373
|
disconnect_title: "\u65AD\u5F00 Codex\uFF1F",
|
|
345
374
|
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",
|
|
346
375
|
usage_title: "\u8BA2\u9605\u914D\u989D",
|
|
@@ -660,10 +689,14 @@ function mount(el, props) {
|
|
|
660
689
|
if (!parsed) throw Object.assign(new Error("invalid status"), { reason: "request_failed" });
|
|
661
690
|
return parsed;
|
|
662
691
|
};
|
|
663
|
-
const settle = async (id) => {
|
|
692
|
+
const settle = async (id, hidden, visible = []) => {
|
|
664
693
|
let failed = false;
|
|
665
694
|
try {
|
|
666
|
-
await props.refreshConfig?.((current, server) =>
|
|
695
|
+
await props.refreshConfig?.((current, server) => {
|
|
696
|
+
const merged = mergeCodexProvider(current, server);
|
|
697
|
+
if (hidden && "Router" in merged) merged.Router = clearCodexRouterRefs(merged.Router, hidden, visible[0] ?? null);
|
|
698
|
+
return merged;
|
|
699
|
+
});
|
|
667
700
|
} catch {
|
|
668
701
|
failed = true;
|
|
669
702
|
}
|
|
@@ -799,7 +832,7 @@ function mount(el, props) {
|
|
|
799
832
|
if (alive && generation === id) errorKey = result.error ?? "hide_failed";
|
|
800
833
|
return;
|
|
801
834
|
}
|
|
802
|
-
const { reconcileFailed: failed } = await settle(id);
|
|
835
|
+
const { reconcileFailed: failed } = await settle(id, /* @__PURE__ */ new Set([...status?.hiddenModels ?? [], model]), result.models ?? []);
|
|
803
836
|
if (!alive || generation !== id) return;
|
|
804
837
|
reconcileFailed = failed;
|
|
805
838
|
toast = t("hidden_toast", { model });
|
package/dist/plugin.js
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
// src/card-types.ts
|
|
2
|
+
var CODEX_PROVIDER_NAME = "codex-subscription";
|
|
3
|
+
var CODEX_USAGE_CACHE_TTL_MS = 10 * 6e4;
|
|
4
|
+
|
|
5
|
+
// src/router.ts
|
|
6
|
+
var record = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
function clearCodexRouterRefs(router, hidden, firstVisible) {
|
|
8
|
+
if (!record(router)) return router;
|
|
9
|
+
const next = structuredClone(router);
|
|
10
|
+
const hit = (value) => {
|
|
11
|
+
if (typeof value !== "string") return false;
|
|
12
|
+
const parts = value.split(",").map((part) => part.trim());
|
|
13
|
+
return parts.length === 2 && parts[0] === CODEX_PROVIDER_NAME && hidden.has(parts[1]);
|
|
14
|
+
};
|
|
15
|
+
if (hit(next.default)) next.default = firstVisible ? `${CODEX_PROVIDER_NAME},${firstVisible}` : "";
|
|
16
|
+
for (const [key, value] of Object.entries(next)) {
|
|
17
|
+
if (["default", "models", "families", "fallback"].includes(key)) continue;
|
|
18
|
+
if (hit(value)) next[key] = "";
|
|
19
|
+
else if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
20
|
+
next[key] = value.filter((item) => !hit(item));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (record(next.models)) {
|
|
24
|
+
for (const [key, value] of Object.entries(next.models)) if (hit(value)) delete next.models[key];
|
|
25
|
+
}
|
|
26
|
+
if (record(next.families)) {
|
|
27
|
+
for (const family of Object.values(next.families)) {
|
|
28
|
+
if (record(family) && hit(family.default)) family.default = "";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return next;
|
|
32
|
+
}
|
|
33
|
+
|
|
1
34
|
// src/auth-service.ts
|
|
2
35
|
import { createServer } from "node:http";
|
|
3
36
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
@@ -6,7 +39,7 @@ import { dirname, join } from "node:path";
|
|
|
6
39
|
|
|
7
40
|
// src/protocol.ts
|
|
8
41
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
9
|
-
var
|
|
42
|
+
var CODEX_PROVIDER_NAME2 = "codex-subscription";
|
|
10
43
|
var CODEX_TRANSFORMER_NAME = "codex";
|
|
11
44
|
var CODEX_TRANSFORMER_CHAIN = ["openai-responses", CODEX_TRANSFORMER_NAME];
|
|
12
45
|
var CODEX_API_KEY = "ccr-managed-codex";
|
|
@@ -371,12 +404,12 @@ function isCodexManagedConfigProvider(p) {
|
|
|
371
404
|
if (p?.codex_managed === true || p?.codexManaged === true) return true;
|
|
372
405
|
const name = typeof p?.name === "string" ? p.name : "";
|
|
373
406
|
const key = typeof p?.api_key === "string" ? p.api_key : typeof p?.apiKey === "string" ? p.apiKey : "";
|
|
374
|
-
return name ===
|
|
407
|
+
return name === CODEX_PROVIDER_NAME2 && key === CODEX_API_KEY;
|
|
375
408
|
}
|
|
376
409
|
function lockCodexProvider(p) {
|
|
377
410
|
return {
|
|
378
411
|
...p,
|
|
379
|
-
name:
|
|
412
|
+
name: CODEX_PROVIDER_NAME2,
|
|
380
413
|
codex_managed: true,
|
|
381
414
|
codexManaged: true,
|
|
382
415
|
api_base_url: CODEX_BACKEND_BASE,
|
|
@@ -402,12 +435,12 @@ function protectCodexConfig(next, prev) {
|
|
|
402
435
|
}
|
|
403
436
|
}
|
|
404
437
|
function isCodexRuntime(p) {
|
|
405
|
-
if (p?.codexManaged === true && p?.name ===
|
|
438
|
+
if (p?.codexManaged === true && p?.name === CODEX_PROVIDER_NAME2) return true;
|
|
406
439
|
const base = typeof p?.baseUrl === "string" ? p.baseUrl : typeof p?.api_base_url === "string" ? p.api_base_url : "";
|
|
407
440
|
if (/(?:^|\/\/)chatgpt\.com\/backend-api\/codex(?:\/|$)/.test(base) && Array.isArray(p?.transformer?.use) && p.transformer.use.some((t) => (typeof t === "string" ? t : t?.name) === CODEX_TRANSFORMER_NAME)) {
|
|
408
441
|
return true;
|
|
409
442
|
}
|
|
410
|
-
return p?.name ===
|
|
443
|
+
return p?.name === CODEX_PROVIDER_NAME2 && (p?.apiKey === CODEX_API_KEY || p?.api_key === CODEX_API_KEY);
|
|
411
444
|
}
|
|
412
445
|
function responseHasOutput(response) {
|
|
413
446
|
const output = response?.output;
|
|
@@ -675,7 +708,7 @@ var CodexAuthService = class {
|
|
|
675
708
|
const account = data?.account;
|
|
676
709
|
const now = this.now;
|
|
677
710
|
if (!account) {
|
|
678
|
-
return { status: "not_connected", providerName:
|
|
711
|
+
return { status: "not_connected", providerName: CODEX_PROVIDER_NAME2, models, modelCount: models.length, hiddenModels: [] };
|
|
679
712
|
}
|
|
680
713
|
const coolingUntil = this.latestCooldown(data);
|
|
681
714
|
let status = "connected";
|
|
@@ -683,7 +716,7 @@ var CodexAuthService = class {
|
|
|
683
716
|
else if (typeof account.accessExp === "number" && account.accessExp <= now) status = "expired";
|
|
684
717
|
return {
|
|
685
718
|
status,
|
|
686
|
-
providerName:
|
|
719
|
+
providerName: CODEX_PROVIDER_NAME2,
|
|
687
720
|
...account.accountId ? { accountId: account.accountId } : {},
|
|
688
721
|
...account.email ? { email: account.email } : {},
|
|
689
722
|
...account.plan ? { plan: account.plan } : {},
|
|
@@ -729,7 +762,7 @@ var CodexAuthService = class {
|
|
|
729
762
|
}
|
|
730
763
|
}
|
|
731
764
|
/**
|
|
732
|
-
* Raw read → upsert
|
|
765
|
+
* Raw read → upsert the managed entry (plus explicit hide cleanup) → write →
|
|
733
766
|
* reload. `protectCodexConfig` is defence in depth; unrelated providers are
|
|
734
767
|
* never rewritten. With `create: false` (hide/restore path) a missing
|
|
735
768
|
* managed entry is left alone — hiding a model must never resurrect a
|
|
@@ -739,7 +772,6 @@ var CodexAuthService = class {
|
|
|
739
772
|
async upsertManagedProvider(models, opts = {}) {
|
|
740
773
|
const config = await this.options.host.readRawConfig?.().catch(() => null) ?? await this.options.host.readConfig().catch(() => ({}));
|
|
741
774
|
const previousConfig = structuredClone(config ?? {});
|
|
742
|
-
const routerBefore = JSON.stringify((config ?? {}).Router ?? null);
|
|
743
775
|
let list = [];
|
|
744
776
|
let usedKey = "Providers";
|
|
745
777
|
let found = false;
|
|
@@ -763,36 +795,41 @@ var CodexAuthService = class {
|
|
|
763
795
|
list[index] = lockCodexProvider({ ...existing, models, enabled });
|
|
764
796
|
} else {
|
|
765
797
|
if (opts.create === false) return false;
|
|
766
|
-
list.push(lockCodexProvider({ name:
|
|
798
|
+
list.push(lockCodexProvider({ name: CODEX_PROVIDER_NAME2, models, enabled: true }));
|
|
767
799
|
}
|
|
768
800
|
config[usedKey] = list;
|
|
769
|
-
|
|
801
|
+
if (opts.hidden && "Router" in config) {
|
|
802
|
+
config.Router = clearCodexRouterRefs(config.Router, opts.hidden, models[0] ?? null);
|
|
803
|
+
}
|
|
804
|
+
const expectedRouter = JSON.stringify(config.Router ?? null);
|
|
770
805
|
try {
|
|
806
|
+
protectCodexConfig(config, config);
|
|
771
807
|
await this.options.host.writeConfig(config);
|
|
808
|
+
if (JSON.stringify(config.Router ?? null) !== expectedRouter) {
|
|
809
|
+
throw codexAdminError("codex_config_write_failed", 500);
|
|
810
|
+
}
|
|
811
|
+
await this.options.host.reloadRuntime?.(config);
|
|
772
812
|
} catch {
|
|
773
813
|
try {
|
|
774
814
|
await this.options.host.writeConfig(previousConfig);
|
|
815
|
+
} catch {
|
|
816
|
+
this.log.error("[codex] configuration rollback write failed / \u914D\u7F6E\u56DE\u6EDA\u5199\u5165\u5931\u8D25");
|
|
817
|
+
}
|
|
818
|
+
try {
|
|
775
819
|
await this.options.host.reloadRuntime?.(previousConfig);
|
|
776
820
|
} catch {
|
|
777
|
-
this.log.error("[codex]
|
|
821
|
+
this.log.error("[codex] configuration rollback reload failed / \u914D\u7F6E\u56DE\u6EDA\u91CD\u8F7D\u5931\u8D25");
|
|
778
822
|
}
|
|
779
823
|
throw codexAdminError("codex_config_write_failed", 500);
|
|
780
824
|
}
|
|
781
|
-
if (JSON.stringify(config.Router ?? null) !== routerBefore) {
|
|
782
|
-
throw codexAdminError("codex_config_write_failed", 500);
|
|
783
|
-
}
|
|
784
|
-
await this.options.host.reloadRuntime?.(config);
|
|
785
825
|
return true;
|
|
786
826
|
}
|
|
787
827
|
// ------------------------------------------------------- hide / restore ---
|
|
788
828
|
/**
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
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.
|
|
829
|
+
* Persist the blacklist and remove hidden models from registration. Clear
|
|
830
|
+
* matching Router refs and migrate default to the first visible model (or
|
|
831
|
+
* empty when none remain), matching WorkBuddy. Roll back config/runtime
|
|
832
|
+
* before credentials on failure. Repeated hides are idempotent.
|
|
796
833
|
*/
|
|
797
834
|
async hideModel(model) {
|
|
798
835
|
if (!isCodexModelId(model)) throw codexAdminError("codex_model_invalid", 422);
|
|
@@ -803,9 +840,9 @@ var CodexAuthService = class {
|
|
|
803
840
|
const visible = await this.computeVisibleModels(data.models.map((m) => m.slug), hidden);
|
|
804
841
|
try {
|
|
805
842
|
await this.saveData({ ...data, hiddenModels: [...hidden] });
|
|
806
|
-
await this.upsertManagedProvider(visible, { create: false });
|
|
843
|
+
await this.upsertManagedProvider(visible, { create: false, hidden });
|
|
807
844
|
} catch (error) {
|
|
808
|
-
await this.saveData(data).catch(() => this.log.error("[codex] hide rollback failed"));
|
|
845
|
+
await this.saveData(data).catch(() => this.log.error("[codex] hide credential rollback failed / \u9690\u85CF\u51ED\u636E\u56DE\u6EDA\u5931\u8D25"));
|
|
809
846
|
if (error?.code === "codex_config_write_failed") throw error;
|
|
810
847
|
throw codexAdminError("codex_config_write_failed", 500);
|
|
811
848
|
}
|
|
@@ -836,7 +873,7 @@ var CodexAuthService = class {
|
|
|
836
873
|
await this.saveData({ ...data, hiddenModels: [...hidden] });
|
|
837
874
|
await this.upsertManagedProvider(visible, { create: false });
|
|
838
875
|
} catch (error) {
|
|
839
|
-
await this.saveData(data).catch(() => this.log.error("[codex] restore rollback failed"));
|
|
876
|
+
await this.saveData(data).catch(() => this.log.error("[codex] restore credential rollback failed / \u6062\u590D\u51ED\u636E\u56DE\u6EDA\u5931\u8D25"));
|
|
840
877
|
if (error?.code === "codex_config_write_failed") throw error;
|
|
841
878
|
throw codexAdminError("codex_config_write_failed", 500);
|
|
842
879
|
}
|
|
@@ -1177,46 +1214,45 @@ var CodexAuthService = class {
|
|
|
1177
1214
|
const cause = error?.cause?.code ?? error?.cause?.message ?? "";
|
|
1178
1215
|
this.log.warn(`[codex] model discovery after login failed: ${error?.code ?? error?.name ?? "upstream"} ${cause} ${String(error?.message ?? "").slice(0, 120)}`);
|
|
1179
1216
|
}
|
|
1180
|
-
|
|
1181
|
-
const hidden = new Set(previous?.hiddenModels ?? []);
|
|
1182
|
-
const data = {
|
|
1183
|
-
version: 1,
|
|
1184
|
-
kind: "codex-subscription",
|
|
1185
|
-
account: {
|
|
1186
|
-
accessToken: tokens.accessToken,
|
|
1187
|
-
refreshToken: tokens.refreshToken,
|
|
1188
|
-
idToken: tokens.idToken,
|
|
1189
|
-
accountId: claims.accountId,
|
|
1190
|
-
email: claims.email,
|
|
1191
|
-
plan: claims.plan,
|
|
1192
|
-
connectedAt: new Date(this.now).toISOString(),
|
|
1193
|
-
accessExp,
|
|
1194
|
-
lastError: null,
|
|
1195
|
-
cooldownUntil: null,
|
|
1196
|
-
rateLimitCooldownUntil: null
|
|
1197
|
-
},
|
|
1198
|
-
models: models.map((m) => ({
|
|
1199
|
-
slug: m.slug,
|
|
1200
|
-
displayName: m.displayName,
|
|
1201
|
-
...m.instructions ? { instructions: m.instructions } : {}
|
|
1202
|
-
})),
|
|
1203
|
-
hiddenModels: [...hidden],
|
|
1204
|
-
rateLimits: null
|
|
1205
|
-
};
|
|
1206
|
-
const slugs = models.map((m) => m.slug);
|
|
1207
|
-
const registered = slugs.filter((s) => !hidden.has(s));
|
|
1217
|
+
let registered = [];
|
|
1208
1218
|
try {
|
|
1209
1219
|
await this.enqueueMutation(async () => {
|
|
1210
1220
|
if (this.epoch !== epoch) throw codexAdminError("codex_login_cancelled", 409);
|
|
1221
|
+
const previous = await this.store.load().catch(() => null);
|
|
1222
|
+
const hidden = new Set(previous?.hiddenModels ?? []);
|
|
1223
|
+
const data = {
|
|
1224
|
+
version: 1,
|
|
1225
|
+
kind: "codex-subscription",
|
|
1226
|
+
account: {
|
|
1227
|
+
accessToken: tokens.accessToken,
|
|
1228
|
+
refreshToken: tokens.refreshToken,
|
|
1229
|
+
idToken: tokens.idToken,
|
|
1230
|
+
accountId: claims.accountId,
|
|
1231
|
+
email: claims.email,
|
|
1232
|
+
plan: claims.plan,
|
|
1233
|
+
connectedAt: new Date(this.now).toISOString(),
|
|
1234
|
+
accessExp,
|
|
1235
|
+
lastError: null,
|
|
1236
|
+
cooldownUntil: null,
|
|
1237
|
+
rateLimitCooldownUntil: null
|
|
1238
|
+
},
|
|
1239
|
+
models: models.map((m) => ({
|
|
1240
|
+
slug: m.slug,
|
|
1241
|
+
displayName: m.displayName,
|
|
1242
|
+
...m.instructions ? { instructions: m.instructions } : {}
|
|
1243
|
+
})),
|
|
1244
|
+
hiddenModels: [...hidden],
|
|
1245
|
+
rateLimits: null
|
|
1246
|
+
};
|
|
1247
|
+
const slugs = models.map((m) => m.slug);
|
|
1248
|
+
registered = slugs.filter((s) => !hidden.has(s));
|
|
1211
1249
|
await this.saveData(data);
|
|
1212
1250
|
if (this.epoch !== epoch) throw codexAdminError("codex_login_cancelled", 409);
|
|
1213
1251
|
try {
|
|
1214
1252
|
await this.upsertManagedProvider(registered);
|
|
1215
1253
|
} catch (error) {
|
|
1216
|
-
if (previous) await this.store.save(previous).catch(() =>
|
|
1217
|
-
|
|
1218
|
-
else await this.store.delete().catch(() => {
|
|
1219
|
-
});
|
|
1254
|
+
if (previous) await this.store.save(previous).catch(() => this.log.error("[codex] login credential rollback failed / \u767B\u5F55\u51ED\u636E\u56DE\u6EDA\u5931\u8D25"));
|
|
1255
|
+
else await this.store.delete().catch(() => this.log.error("[codex] login credential rollback failed / \u767B\u5F55\u51ED\u636E\u56DE\u6EDA\u5931\u8D25"));
|
|
1220
1256
|
this.loaded = false;
|
|
1221
1257
|
throw error;
|
|
1222
1258
|
}
|
|
@@ -1534,8 +1570,10 @@ function conversationKey(instructions, input, sessionId) {
|
|
|
1534
1570
|
const parts = [];
|
|
1535
1571
|
if (instructions) parts.push(instructions);
|
|
1536
1572
|
for (const item of input) {
|
|
1537
|
-
|
|
1538
|
-
|
|
1573
|
+
if (item?.role === "user") {
|
|
1574
|
+
parts.push(JSON.stringify(item));
|
|
1575
|
+
break;
|
|
1576
|
+
}
|
|
1539
1577
|
}
|
|
1540
1578
|
const digest = sha256Hex(sessionId + "\0" + parts.join("\0"));
|
|
1541
1579
|
return [
|
|
@@ -1658,10 +1696,11 @@ function codexFinalizeBody(body, options = {}) {
|
|
|
1658
1696
|
let { input } = finalizeInput(out.input);
|
|
1659
1697
|
input = finalizeInstructions(out, input, options.modelInstructions);
|
|
1660
1698
|
out.input = input;
|
|
1699
|
+
const stableInstructions = typeof options.modelInstructions === "string" && options.modelInstructions.trim() !== "" && out.instructions === options.modelInstructions ? out.instructions : "";
|
|
1661
1700
|
if (typeof out.prompt_cache_key !== "string" || out.prompt_cache_key.trim() === "") {
|
|
1662
|
-
const seed = typeof options.sessionId === "string" && options.sessionId ? options.sessionId :
|
|
1701
|
+
const seed = typeof options.sessionId === "string" && options.sessionId ? options.sessionId : "";
|
|
1663
1702
|
out.prompt_cache_key = conversationKey(
|
|
1664
|
-
|
|
1703
|
+
stableInstructions,
|
|
1665
1704
|
input,
|
|
1666
1705
|
seed
|
|
1667
1706
|
);
|
|
@@ -2416,13 +2455,13 @@ var codexLocales = {
|
|
|
2416
2455
|
synced: "Synced {{count}} Codex models.",
|
|
2417
2456
|
disconnected: "Disconnected.",
|
|
2418
2457
|
hide_model: "Hide {{model}}",
|
|
2419
|
-
hidden_models: "Hidden models ({{count}})",
|
|
2458
|
+
hidden_models: "Hidden models ({{count}}) \u2014 routing references cleared",
|
|
2420
2459
|
restore: "Restore",
|
|
2421
2460
|
restore_all: "Restore all",
|
|
2422
2461
|
hidden_toast: "Hidden {{model}}.",
|
|
2423
2462
|
restored_toast: "Restored {{model}}.",
|
|
2424
2463
|
restored_all_toast: "Restored {{count}} hidden models.",
|
|
2425
|
-
hidden_note: "Hidden models stay hidden across sync and re-authorization
|
|
2464
|
+
hidden_note: "Hidden models stay hidden across sync and re-authorization. Matching routing references are cleared; default moves to the first visible model or becomes empty when none remain. Restore models here; restoring does not restore old routes.",
|
|
2426
2465
|
disconnect_title: "Disconnect Codex?",
|
|
2427
2466
|
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.",
|
|
2428
2467
|
usage_title: "Plan quota",
|
|
@@ -2502,13 +2541,13 @@ var codexLocales = {
|
|
|
2502
2541
|
synced: "\u5DF2\u540C\u6B65 {{count}} \u4E2A Codex \u6A21\u578B\u3002",
|
|
2503
2542
|
disconnected: "\u5DF2\u65AD\u5F00\u8FDE\u63A5\u3002",
|
|
2504
2543
|
hide_model: "\u9690\u85CF {{model}}",
|
|
2505
|
-
hidden_models: "\u5DF2\u9690\u85CF\u6A21\u578B\uFF08{{count}}\uFF09",
|
|
2544
|
+
hidden_models: "\u5DF2\u9690\u85CF\u6A21\u578B\uFF08{{count}}\uFF09\u2014 \u5DF2\u6E05\u7406\u8DEF\u7531\u5F15\u7528",
|
|
2506
2545
|
restore: "\u6062\u590D",
|
|
2507
2546
|
restore_all: "\u6062\u590D\u5168\u90E8",
|
|
2508
2547
|
hidden_toast: "\u5DF2\u9690\u85CF {{model}}\u3002",
|
|
2509
2548
|
restored_toast: "\u5DF2\u6062\u590D {{model}}\u3002",
|
|
2510
2549
|
restored_all_toast: "\u5DF2\u6062\u590D {{count}} \u4E2A\u9690\u85CF\u6A21\u578B\u3002",
|
|
2511
|
-
hidden_note: "\u9690\u85CF\
|
|
2550
|
+
hidden_note: "\u9690\u85CF\u6A21\u578B\u5728\u540C\u6B65\u548C\u91CD\u65B0\u6388\u6743\u540E\u4FDD\u6301\u9690\u85CF\u3002\u76F8\u5173\u8DEF\u7531\u5F15\u7528\u4F1A\u88AB\u6E05\u7406\uFF0C\u9ED8\u8BA4\u8DEF\u7531\u6539\u4E3A\u9996\u4E2A\u53EF\u89C1\u6A21\u578B\uFF1B\u82E5\u5168\u90E8\u9690\u85CF\u5219\u6E05\u7A7A\u9ED8\u8BA4\u8DEF\u7531\u3002\u53EF\u5728\u6B64\u6062\u590D\u6A21\u578B\uFF0C\u4F46\u4E0D\u4F1A\u6062\u590D\u65E7\u8DEF\u7531\u3002",
|
|
2512
2551
|
disconnect_title: "\u65AD\u5F00 Codex\uFF1F",
|
|
2513
2552
|
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",
|
|
2514
2553
|
usage_title: "\u8BA2\u9605\u914D\u989D",
|
|
@@ -2549,7 +2588,7 @@ var codexLocales = {
|
|
|
2549
2588
|
// src/plugin.ts
|
|
2550
2589
|
var manifest = {
|
|
2551
2590
|
name: "codex",
|
|
2552
|
-
version: "1.0.
|
|
2591
|
+
version: "1.0.10",
|
|
2553
2592
|
coreApi: "1",
|
|
2554
2593
|
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."
|
|
2555
2594
|
};
|
package/dist/plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
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.
|
|
3
|
+
"version": "1.0.10",
|
|
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",
|