@wengine-ai/ccr-provider-codex 1.0.16 → 1.0.17
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/dist/card.js +2 -0
- package/dist/plugin.js +190 -98
- package/dist/plugin.json +1 -1
- package/package.json +1 -1
package/dist/card.js
CHANGED
|
@@ -367,6 +367,7 @@ var codexLocales = {
|
|
|
367
367
|
codex_request_rejected: "Codex rejected the request.",
|
|
368
368
|
codex_upstream_error: "Codex upstream request failed.",
|
|
369
369
|
reset_failed: "The usage reset failed. Please try again.",
|
|
370
|
+
codex_reset_account_changed: "The connected account changed. Check the available resets again.",
|
|
370
371
|
codex_reset_busy: "A usage reset is already running \u2014 wait for it to finish.",
|
|
371
372
|
codex_reset_no_credit: "No usage resets are available.",
|
|
372
373
|
codex_reset_unavailable: "The reset service is unavailable right now. Please try again.",
|
|
@@ -474,6 +475,7 @@ var codexLocales = {
|
|
|
474
475
|
codex_request_rejected: "Codex \u62D2\u7EDD\u4E86\u8BE5\u8BF7\u6C42\u3002",
|
|
475
476
|
codex_upstream_error: "Codex \u4E0A\u6E38\u8BF7\u6C42\u5931\u8D25\u3002",
|
|
476
477
|
reset_failed: "\u7528\u91CF\u91CD\u7F6E\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002",
|
|
478
|
+
codex_reset_account_changed: "\u5DF2\u5207\u6362\u8FDE\u63A5\u8D26\u6237\uFF0C\u8BF7\u91CD\u65B0\u67E5\u8BE2\u53EF\u7528\u91CD\u7F6E\u5361\u3002",
|
|
477
479
|
codex_reset_busy: "\u5DF2\u6709\u7528\u91CF\u91CD\u7F6E\u6B63\u5728\u8FDB\u884C\u2014\u2014\u8BF7\u7B49\u5F85\u5B8C\u6210\u3002",
|
|
478
480
|
codex_reset_no_credit: "\u6CA1\u6709\u53EF\u7528\u7684\u7528\u91CF\u91CD\u7F6E\u673A\u4F1A\u3002",
|
|
479
481
|
codex_reset_unavailable: "\u91CD\u7F6E\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
|
package/dist/plugin.js
CHANGED
|
@@ -405,25 +405,32 @@ function rateLimitsSaturated(limits, now) {
|
|
|
405
405
|
}
|
|
406
406
|
return false;
|
|
407
407
|
}
|
|
408
|
+
function isCodexResetCreditId(value) {
|
|
409
|
+
return typeof value === "string" && value.length <= 256 && !!value.trim() && !/[\x00-\x1f\x7f-\x9f]/.test(value);
|
|
410
|
+
}
|
|
411
|
+
function isCodexAccountRevision(value) {
|
|
412
|
+
return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(value);
|
|
413
|
+
}
|
|
408
414
|
var RESET_CREDIT_TITLES = {
|
|
409
415
|
codex_rate_limits: "Full reset"
|
|
410
416
|
};
|
|
411
|
-
function parseResetCredit(raw) {
|
|
417
|
+
function parseResetCredit(raw, confirmedCreditId) {
|
|
412
418
|
if (!raw || typeof raw !== "object") return null;
|
|
413
|
-
if (
|
|
419
|
+
if (!isCodexResetCreditId(raw.id)) return null;
|
|
414
420
|
if (typeof raw.status !== "string" || !raw.status || raw.status.length > 32) return null;
|
|
415
|
-
const expires = typeof raw.expires_at === "string"
|
|
421
|
+
const expires = typeof raw.expires_at === "string" ? Date.parse(raw.expires_at) : NaN;
|
|
422
|
+
if (raw.id === confirmedCreditId && raw.expires_at != null && !Number.isFinite(expires)) return null;
|
|
416
423
|
const title = typeof raw.title === "string" && raw.title.trim() ? raw.title.trim().slice(0, 200) : RESET_CREDIT_TITLES[typeof raw.reset_type === "string" ? raw.reset_type : ""];
|
|
417
424
|
const description = typeof raw.description === "string" && raw.description.trim() ? raw.description.trim().slice(0, 300) : void 0;
|
|
418
425
|
return {
|
|
419
426
|
id: raw.id,
|
|
420
427
|
status: raw.status,
|
|
421
|
-
...Number.isFinite(expires)
|
|
428
|
+
...Number.isFinite(expires) ? { expiresAt: expires } : {},
|
|
422
429
|
...title ? { title } : {},
|
|
423
430
|
...description ? { description } : {}
|
|
424
431
|
};
|
|
425
432
|
}
|
|
426
|
-
function parseCodexResetCredits(raw) {
|
|
433
|
+
function parseCodexResetCredits(raw, confirmedCreditId) {
|
|
427
434
|
if (!raw || typeof raw !== "object") return null;
|
|
428
435
|
const r = raw;
|
|
429
436
|
const availableCount = typeof r.available_count === "number" && Number.isFinite(r.available_count) ? Math.max(0, Math.floor(r.available_count)) : null;
|
|
@@ -432,7 +439,7 @@ function parseCodexResetCredits(raw) {
|
|
|
432
439
|
if (Array.isArray(r.credits)) {
|
|
433
440
|
if (r.credits.length > 256) return null;
|
|
434
441
|
for (const item of r.credits) {
|
|
435
|
-
const credit = parseResetCredit(item);
|
|
442
|
+
const credit = parseResetCredit(item, confirmedCreditId);
|
|
436
443
|
if (!credit) return null;
|
|
437
444
|
credits.push(credit);
|
|
438
445
|
}
|
|
@@ -481,7 +488,7 @@ async function fetchCodexResetCredits(params) {
|
|
|
481
488
|
fetchImpl: params.fetchImpl
|
|
482
489
|
});
|
|
483
490
|
if (!res.ok) return null;
|
|
484
|
-
return parseCodexResetCredits(res.json);
|
|
491
|
+
return parseCodexResetCredits(res.json, params.confirmedCreditId);
|
|
485
492
|
}
|
|
486
493
|
async function consumeCodexResetCredit(params) {
|
|
487
494
|
const origin = params.origin ?? CODEX_CHATGPT_ORIGIN;
|
|
@@ -584,6 +591,9 @@ var LAST_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
584
591
|
function boundedString(value, max, min = 1) {
|
|
585
592
|
return typeof value === "string" && value.length >= min && value.length <= max && !/[\x00-\x1f\x7f]/.test(value);
|
|
586
593
|
}
|
|
594
|
+
function sameCodexAccount(a, b) {
|
|
595
|
+
return a?.accountId === b?.accountId && a?.connectedAt === b?.connectedAt;
|
|
596
|
+
}
|
|
587
597
|
function normalizeRateLimits(raw) {
|
|
588
598
|
if (!raw || typeof raw !== "object") return null;
|
|
589
599
|
const r = raw;
|
|
@@ -750,20 +760,16 @@ var CodexAuthService = class {
|
|
|
750
760
|
refreshFlight = null;
|
|
751
761
|
forceRefreshRequested = false;
|
|
752
762
|
usageCache = null;
|
|
753
|
-
/** Reject quota reads overtaken by a
|
|
763
|
+
/** Reject quota reads overtaken by a reset or a data-plane observation. */
|
|
754
764
|
quotaRevision = 0;
|
|
755
765
|
usageFlight = null;
|
|
756
|
-
/** Reset-credit listing cache (same short-TTL shape as usage). */
|
|
757
766
|
resetCache = null;
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
resetFlight =
|
|
762
|
-
/**
|
|
763
|
-
|
|
764
|
-
* terminal outcome (upstream dedupes per key — a lost response therefore
|
|
765
|
-
* cannot double-spend). Cleared on terminal outcomes and disconnect. */
|
|
766
|
-
pendingReset = null;
|
|
767
|
+
resetRevision = 0;
|
|
768
|
+
accountRevision = randomUUID();
|
|
769
|
+
/** Reject concurrent reset confirmations instead of queueing a second spend. */
|
|
770
|
+
resetFlight = false;
|
|
771
|
+
/** Unsettled redeem keys for the current account, indexed by selected credit. */
|
|
772
|
+
pendingReset = /* @__PURE__ */ new Map();
|
|
767
773
|
/** Locally marked spent credits: written only on a CONFIRMED terminal
|
|
768
774
|
* outcome; prevents re-consumption of a known-spent credit within this
|
|
769
775
|
* service lifetime. Upstream stays authoritative. */
|
|
@@ -811,12 +817,31 @@ var CodexAuthService = class {
|
|
|
811
817
|
// ---------------------------------------------------------------- loading --
|
|
812
818
|
async ensureLoaded(force = false) {
|
|
813
819
|
if (this.loaded && !force) return this.data;
|
|
814
|
-
const
|
|
815
|
-
this.
|
|
816
|
-
|
|
820
|
+
const previous = this.data;
|
|
821
|
+
const epoch = this.epoch;
|
|
822
|
+
let data;
|
|
823
|
+
try {
|
|
824
|
+
data = await this.store.load();
|
|
825
|
+
} catch {
|
|
826
|
+
if (this.data === previous && this.epoch === epoch) this.loaded = false;
|
|
827
|
+
return null;
|
|
828
|
+
}
|
|
829
|
+
if (this.data === previous && this.epoch === epoch) {
|
|
830
|
+
this.applyLoaded(data);
|
|
831
|
+
this.loaded = true;
|
|
832
|
+
} else if (this.epoch === epoch && !sameCodexAccount(data?.account, this.data?.account)) {
|
|
833
|
+
return this.ensureLoaded(true);
|
|
834
|
+
}
|
|
817
835
|
return this.data;
|
|
818
836
|
}
|
|
819
837
|
applyLoaded(data) {
|
|
838
|
+
if (!sameCodexAccount(this.data?.account, data?.account)) {
|
|
839
|
+
this.accountRevision = randomUUID();
|
|
840
|
+
if (this.data?.account) this.invalidateUsage();
|
|
841
|
+
this.invalidateResetCredits();
|
|
842
|
+
this.pendingReset.clear();
|
|
843
|
+
this.spentResetCredits.clear();
|
|
844
|
+
}
|
|
820
845
|
this.data = data;
|
|
821
846
|
this.instructions.clear();
|
|
822
847
|
for (const m of data?.models ?? []) {
|
|
@@ -825,9 +850,7 @@ var CodexAuthService = class {
|
|
|
825
850
|
}
|
|
826
851
|
async saveData(data) {
|
|
827
852
|
await this.store.save(data);
|
|
828
|
-
this.data
|
|
829
|
-
this.instructions.clear();
|
|
830
|
-
for (const m of data.models) if (m.instructions) this.instructions.set(m.slug, m.instructions);
|
|
853
|
+
this.applyLoaded(data);
|
|
831
854
|
}
|
|
832
855
|
// ------------------------------------------------------------------ status -
|
|
833
856
|
async getStatus() {
|
|
@@ -1399,10 +1422,6 @@ var CodexAuthService = class {
|
|
|
1399
1422
|
}
|
|
1400
1423
|
this.refreshFlight = null;
|
|
1401
1424
|
this.forceRefreshRequested = false;
|
|
1402
|
-
this.usageCache = null;
|
|
1403
|
-
this.resetCache = null;
|
|
1404
|
-
this.spentResetCredits.clear();
|
|
1405
|
-
this.pendingReset = null;
|
|
1406
1425
|
const result = { status: "connected", models: registered, modelCount: registered.length };
|
|
1407
1426
|
job.result = result;
|
|
1408
1427
|
this.lastResult.set(job.loginId, result);
|
|
@@ -1576,11 +1595,16 @@ var CodexAuthService = class {
|
|
|
1576
1595
|
if (this.usageFlight === flight) this.usageFlight = null;
|
|
1577
1596
|
}
|
|
1578
1597
|
}
|
|
1598
|
+
invalidateUsage() {
|
|
1599
|
+
this.quotaRevision++;
|
|
1600
|
+
this.usageCache = null;
|
|
1601
|
+
this.usageFlight = null;
|
|
1602
|
+
}
|
|
1579
1603
|
async readUsageAndReconcile() {
|
|
1580
|
-
const revision = this.quotaRevision;
|
|
1581
1604
|
const epoch = this.epoch;
|
|
1582
1605
|
const data = await this.ensureLoaded();
|
|
1583
|
-
if (!data?.account) return null;
|
|
1606
|
+
if (!data?.account || this.epoch !== epoch || !sameCodexAccount(data.account, this.data?.account)) return null;
|
|
1607
|
+
const revision = this.quotaRevision;
|
|
1584
1608
|
if (this.usageCache && this.now - this.usageCache.at < USAGE_CACHE_MS) {
|
|
1585
1609
|
return this.usageCache.value;
|
|
1586
1610
|
}
|
|
@@ -1625,85 +1649,136 @@ var CodexAuthService = class {
|
|
|
1625
1649
|
return usage;
|
|
1626
1650
|
}
|
|
1627
1651
|
// ------------------------------------------------------ reset credits -
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1652
|
+
invalidateResetCredits() {
|
|
1653
|
+
this.resetRevision++;
|
|
1654
|
+
this.resetCache = null;
|
|
1655
|
+
}
|
|
1656
|
+
fetchResetCredits(account, confirmedCreditId) {
|
|
1657
|
+
return fetchCodexResetCredits({
|
|
1658
|
+
confirmedCreditId,
|
|
1659
|
+
accessToken: account.accessToken,
|
|
1660
|
+
accountId: account.accountId || void 0,
|
|
1661
|
+
fetchImpl: (url, init) => this.directFetch(url, init)
|
|
1662
|
+
}).catch(() => null);
|
|
1663
|
+
}
|
|
1664
|
+
cacheResetListing(listing) {
|
|
1665
|
+
const value = listing && {
|
|
1666
|
+
...listing,
|
|
1667
|
+
// Desktop displays positive epoch milliseconds. Historical expiries cannot be redeemed.
|
|
1668
|
+
credits: listing.credits.filter((c) => !this.spentResetCredits.has(c.id) && (c.expiresAt === void 0 || c.expiresAt > 0)),
|
|
1669
|
+
accountRevision: this.accountRevision
|
|
1670
|
+
};
|
|
1671
|
+
this.resetCache = { at: this.now, value };
|
|
1672
|
+
return value;
|
|
1673
|
+
}
|
|
1674
|
+
/** Available gifted resets, cached briefly for display. */
|
|
1633
1675
|
async getResetCredits() {
|
|
1634
|
-
const
|
|
1635
|
-
|
|
1676
|
+
const epoch = this.epoch;
|
|
1677
|
+
const data = await this.ensureLoaded(true);
|
|
1678
|
+
if (!data?.account || this.epoch !== epoch) return null;
|
|
1679
|
+
const revision = this.resetRevision;
|
|
1680
|
+
const isCurrent = () => this.epoch === epoch && this.resetRevision === revision && sameCodexAccount(data.account, this.data?.account);
|
|
1636
1681
|
if (this.resetCache && this.now - this.resetCache.at < USAGE_CACHE_MS) {
|
|
1637
1682
|
return this.resetCache.value;
|
|
1638
1683
|
}
|
|
1639
1684
|
const accessToken = await this.getAccessToken().catch(() => null);
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
const listing = await
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
fetchImpl: (url, init) => this.directFetch(url, init)
|
|
1646
|
-
}).catch(() => null);
|
|
1647
|
-
const value = listing && listing.credits.length ? { ...listing, credits: listing.credits.filter((c) => !this.spentResetCredits.has(c.id)) } : listing;
|
|
1648
|
-
this.resetCache = { at: this.now, value };
|
|
1649
|
-
return value;
|
|
1685
|
+
const account = this.data?.account;
|
|
1686
|
+
if (!accessToken || !account || account.accessToken !== accessToken || !isCurrent()) return null;
|
|
1687
|
+
const listing = await this.fetchResetCredits(account);
|
|
1688
|
+
if (!isCurrent()) return null;
|
|
1689
|
+
return this.cacheResetListing(listing);
|
|
1650
1690
|
}
|
|
1651
|
-
/**
|
|
1652
|
-
* Consume ONE gifted reset credit. Explicit user action only — never called
|
|
1653
|
-
* by mount/poll/refresh. Single-flight: a second concurrent consume is
|
|
1654
|
-
* rejected (two queued consumes could redeem two credits). The idempotency
|
|
1655
|
-
* key is minted here at confirmation time and retained across user-initiated
|
|
1656
|
-
* retries of the same confirmation (upstream dedupes on it), so a lost
|
|
1657
|
-
* response cannot double-spend. Outcomes map to the upstream taxonomy;
|
|
1658
|
-
* `reset`/`already_redeemed` clear the usage cache and locally mark the
|
|
1659
|
-
* credit spent, then the caller re-lists for the authoritative count.
|
|
1660
|
-
*/
|
|
1691
|
+
/** Legacy route preserves optional credit selection and the authoritative recount. */
|
|
1661
1692
|
async consumeResetCredit(creditId) {
|
|
1693
|
+
return this.redeemResetCredit(creditId);
|
|
1694
|
+
}
|
|
1695
|
+
async consumeConfirmedResetCredit(creditId, accountRevision) {
|
|
1696
|
+
if (!isCodexResetCreditId(creditId) || !isCodexAccountRevision(accountRevision)) {
|
|
1697
|
+
throw codexAdminError("codex_reset_invalid", 422);
|
|
1698
|
+
}
|
|
1699
|
+
return this.redeemResetCredit(creditId, accountRevision);
|
|
1700
|
+
}
|
|
1701
|
+
async redeemResetCredit(creditId, accountRevision) {
|
|
1662
1702
|
if (this.resetFlight) throw codexAdminError("codex_reset_busy", 429);
|
|
1663
|
-
|
|
1664
|
-
const
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1703
|
+
this.resetFlight = true;
|
|
1704
|
+
const epoch = this.epoch;
|
|
1705
|
+
const confirmed = accountRevision !== void 0;
|
|
1706
|
+
const assertConfirmedRevision = () => {
|
|
1707
|
+
if (confirmed && (accountRevision !== this.accountRevision || this.epoch !== epoch)) {
|
|
1708
|
+
throw codexAdminError("codex_reset_account_changed", 409);
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
try {
|
|
1712
|
+
await this.mutationTail;
|
|
1713
|
+
const data = await this.ensureLoaded(true);
|
|
1714
|
+
assertConfirmedRevision();
|
|
1715
|
+
if (!data?.account || this.epoch !== epoch) throw codexAdminError("codex_not_connected", 409);
|
|
1716
|
+
const revision = this.resetRevision;
|
|
1717
|
+
const assertCurrentAccount = () => {
|
|
1718
|
+
assertConfirmedRevision();
|
|
1719
|
+
if (this.epoch !== epoch || this.resetRevision !== revision || !sameCodexAccount(data.account, this.data?.account)) {
|
|
1720
|
+
throw codexAdminError("codex_not_connected", 409);
|
|
1670
1721
|
}
|
|
1671
|
-
|
|
1722
|
+
};
|
|
1723
|
+
if (creditId && this.spentResetCredits.has(creditId)) throw codexAdminError("codex_reset_no_credit", 409);
|
|
1724
|
+
const accessToken = await this.getAccessToken();
|
|
1725
|
+
const account = this.data?.account;
|
|
1726
|
+
assertCurrentAccount();
|
|
1727
|
+
if (!account || account.accessToken !== accessToken || confirmed && !account.accountId) {
|
|
1728
|
+
throw codexAdminError("codex_not_connected", 409);
|
|
1729
|
+
}
|
|
1730
|
+
const pendingKey = this.pendingReset.get(creditId);
|
|
1731
|
+
if (confirmed) {
|
|
1732
|
+
const listing = await this.fetchResetCredits(account, creditId);
|
|
1733
|
+
await this.mutationTail;
|
|
1672
1734
|
const fresh = await this.ensureLoaded(true);
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
if (error?.code === "codex_upstream_error") throw codexAdminError("codex_reset_unavailable", 502);
|
|
1684
|
-
throw error;
|
|
1735
|
+
assertCurrentAccount();
|
|
1736
|
+
if (!fresh?.account) throw codexAdminError("codex_not_connected", 409);
|
|
1737
|
+
if (!listing) throw codexAdminError("codex_reset_unavailable", 502);
|
|
1738
|
+
const selected = listing.credits.filter((c) => c.id === creditId);
|
|
1739
|
+
if (!listing.availableCount || selected.length !== 1 || selected[0].status !== "available" || selected[0].expiresAt !== void 0 && selected[0].expiresAt <= this.now) {
|
|
1740
|
+
this.invalidateResetCredits();
|
|
1741
|
+
this.cacheResetListing({ ...listing, credits: listing.credits.filter((c) => c.id !== creditId || c.status !== "available") });
|
|
1742
|
+
if (pendingKey) throw codexAdminError("codex_reset_unavailable", 502);
|
|
1743
|
+
throw codexAdminError("codex_reset_no_credit", 409);
|
|
1744
|
+
}
|
|
1685
1745
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1746
|
+
const redeemRequest = pendingKey ?? randomUUID();
|
|
1747
|
+
this.pendingReset.set(creditId, redeemRequest);
|
|
1748
|
+
const result = await consumeCodexResetCredit({
|
|
1749
|
+
redeemRequest,
|
|
1750
|
+
creditId,
|
|
1751
|
+
accessToken: account.accessToken,
|
|
1752
|
+
accountId: account.accountId || void 0,
|
|
1753
|
+
fetchImpl: (url, init) => this.directFetch(url, init)
|
|
1754
|
+
}).catch((error) => {
|
|
1755
|
+
if (!confirmed || error?.code === "codex_reauth_required") throw error;
|
|
1756
|
+
throw codexAdminError("codex_reset_unavailable", 502);
|
|
1757
|
+
});
|
|
1758
|
+
assertCurrentAccount();
|
|
1759
|
+
this.pendingReset.delete(creditId);
|
|
1691
1760
|
if (result.outcome === "reset" || result.outcome === "already_redeemed") {
|
|
1692
1761
|
if (creditId) this.spentResetCredits.add(creditId);
|
|
1693
|
-
this.
|
|
1694
|
-
this.
|
|
1762
|
+
this.invalidateUsage();
|
|
1763
|
+
this.invalidateResetCredits();
|
|
1764
|
+
if (!confirmed) {
|
|
1765
|
+
const listing = await this.getResetCredits().catch(() => null);
|
|
1766
|
+
if (this.epoch === epoch && sameCodexAccount(data.account, this.data?.account) && listing) {
|
|
1767
|
+
return { ...result, availableCount: listing.availableCount };
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1695
1770
|
} else if (result.outcome === "no_credit") {
|
|
1696
|
-
this.
|
|
1697
|
-
|
|
1698
|
-
this.pendingReset = null;
|
|
1699
|
-
let availableCount;
|
|
1700
|
-
if (result.outcome === "reset" || result.outcome === "already_redeemed") {
|
|
1701
|
-
const listing = await this.getResetCredits().catch(() => null);
|
|
1702
|
-
availableCount = listing?.availableCount;
|
|
1771
|
+
this.invalidateResetCredits();
|
|
1772
|
+
if (!confirmed) this.cacheResetListing({ credits: [], availableCount: 0 });
|
|
1703
1773
|
}
|
|
1704
|
-
return
|
|
1774
|
+
return result;
|
|
1775
|
+
} catch (error) {
|
|
1776
|
+
assertConfirmedRevision();
|
|
1777
|
+
if (error?.code === "codex_reauth_required") throw codexAdminError("codex_reauth_required", 422);
|
|
1778
|
+
if (error?.code === "codex_upstream_error") throw codexAdminError("codex_reset_unavailable", 502);
|
|
1779
|
+
throw error;
|
|
1705
1780
|
} finally {
|
|
1706
|
-
|
|
1781
|
+
this.resetFlight = false;
|
|
1707
1782
|
}
|
|
1708
1783
|
}
|
|
1709
1784
|
// -------------------------------------------------------------- cooling/... -
|
|
@@ -1841,10 +1916,6 @@ var CodexAuthService = class {
|
|
|
1841
1916
|
this.loaded = true;
|
|
1842
1917
|
this.refreshFlight = null;
|
|
1843
1918
|
this.forceRefreshRequested = false;
|
|
1844
|
-
this.usageCache = null;
|
|
1845
|
-
this.resetCache = null;
|
|
1846
|
-
this.spentResetCredits.clear();
|
|
1847
|
-
this.pendingReset = null;
|
|
1848
1919
|
return { success: true };
|
|
1849
1920
|
});
|
|
1850
1921
|
}
|
|
@@ -2636,6 +2707,7 @@ function registerCodexAdminRoutes(app, deps) {
|
|
|
2636
2707
|
codex_models_fetch_failed: 422,
|
|
2637
2708
|
codex_reauth_required: 422,
|
|
2638
2709
|
codex_model_invalid: 422,
|
|
2710
|
+
codex_reset_account_changed: 409,
|
|
2639
2711
|
codex_reset_busy: 429,
|
|
2640
2712
|
codex_reset_no_credit: 409,
|
|
2641
2713
|
codex_reset_unavailable: 502,
|
|
@@ -2864,6 +2936,24 @@ function registerCodexAdminRoutes(app, deps) {
|
|
|
2864
2936
|
return codexRouteError(error, reply, "reset-credits/consume", "codex_reset_failed");
|
|
2865
2937
|
}
|
|
2866
2938
|
});
|
|
2939
|
+
app.post("/api/codex/reset-credits/consume-confirmed-v2", async (req, reply) => {
|
|
2940
|
+
try {
|
|
2941
|
+
assertLocalCodexRequest(req);
|
|
2942
|
+
const service = deps.getService();
|
|
2943
|
+
if (!service) {
|
|
2944
|
+
reply.status(503);
|
|
2945
|
+
return { ok: false, success: false, error: "codex_request_failed" };
|
|
2946
|
+
}
|
|
2947
|
+
const { creditId, accountRevision } = req.body ?? {};
|
|
2948
|
+
if (!isCodexResetCreditId(creditId) || !isCodexAccountRevision(accountRevision)) {
|
|
2949
|
+
throw codexAdminError("codex_reset_invalid", 422);
|
|
2950
|
+
}
|
|
2951
|
+
const result = await service.consumeConfirmedResetCredit(creditId, accountRevision);
|
|
2952
|
+
return { ok: true, success: true, ...result };
|
|
2953
|
+
} catch (error) {
|
|
2954
|
+
return codexRouteError(error, reply, "reset-credits/consume-confirmed-v2", "codex_reset_failed");
|
|
2955
|
+
}
|
|
2956
|
+
});
|
|
2867
2957
|
app.post("/api/codex/disconnect", async (req, reply) => {
|
|
2868
2958
|
try {
|
|
2869
2959
|
assertLocalCodexRequest(req);
|
|
@@ -2980,6 +3070,7 @@ var codexLocales = {
|
|
|
2980
3070
|
codex_request_rejected: "Codex rejected the request.",
|
|
2981
3071
|
codex_upstream_error: "Codex upstream request failed.",
|
|
2982
3072
|
reset_failed: "The usage reset failed. Please try again.",
|
|
3073
|
+
codex_reset_account_changed: "The connected account changed. Check the available resets again.",
|
|
2983
3074
|
codex_reset_busy: "A usage reset is already running \u2014 wait for it to finish.",
|
|
2984
3075
|
codex_reset_no_credit: "No usage resets are available.",
|
|
2985
3076
|
codex_reset_unavailable: "The reset service is unavailable right now. Please try again.",
|
|
@@ -3087,6 +3178,7 @@ var codexLocales = {
|
|
|
3087
3178
|
codex_request_rejected: "Codex \u62D2\u7EDD\u4E86\u8BE5\u8BF7\u6C42\u3002",
|
|
3088
3179
|
codex_upstream_error: "Codex \u4E0A\u6E38\u8BF7\u6C42\u5931\u8D25\u3002",
|
|
3089
3180
|
reset_failed: "\u7528\u91CF\u91CD\u7F6E\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002",
|
|
3181
|
+
codex_reset_account_changed: "\u5DF2\u5207\u6362\u8FDE\u63A5\u8D26\u6237\uFF0C\u8BF7\u91CD\u65B0\u67E5\u8BE2\u53EF\u7528\u91CD\u7F6E\u5361\u3002",
|
|
3090
3182
|
codex_reset_busy: "\u5DF2\u6709\u7528\u91CF\u91CD\u7F6E\u6B63\u5728\u8FDB\u884C\u2014\u2014\u8BF7\u7B49\u5F85\u5B8C\u6210\u3002",
|
|
3091
3183
|
codex_reset_no_credit: "\u6CA1\u6709\u53EF\u7528\u7684\u7528\u91CF\u91CD\u7F6E\u673A\u4F1A\u3002",
|
|
3092
3184
|
codex_reset_unavailable: "\u91CD\u7F6E\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
|
|
@@ -3168,7 +3260,7 @@ function replaceCodexTokenMaintenance(next) {
|
|
|
3168
3260
|
// src/plugin.ts
|
|
3169
3261
|
var manifest = {
|
|
3170
3262
|
name: "codex",
|
|
3171
|
-
version: "1.0.
|
|
3263
|
+
version: "1.0.17",
|
|
3172
3264
|
coreApi: "1",
|
|
3173
3265
|
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."
|
|
3174
3266
|
};
|
package/dist/plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
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.17",
|
|
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",
|