@wengine-ai/ccr-provider-codex 1.0.11 → 1.0.12

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.
Files changed (2) hide show
  1. package/dist/plugin.js +52 -3
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -1423,6 +1423,32 @@ var CodexAuthService = class {
1423
1423
  const data = await this.ensureLoaded();
1424
1424
  return this.latestCooldown(data) !== void 0;
1425
1425
  }
1426
+ /**
1427
+ * Data-plane success channel: clears non-sticky failure residue once the
1428
+ * upstream produced real output. Without this a single rejected request
1429
+ * (e.g. a 400 on an unsupported payload) latches status="error" on the card
1430
+ * until the next re-login — users experience that as "the login keeps
1431
+ * dropping" even though the token was never invalid. The sticky reauth
1432
+ * marker survives: one good request cannot prove the saved sign-in healthy
1433
+ * again, so only a fresh login clears it. rateLimitCooldownUntil is a
1434
+ * separate quota-window truth with its own expiry and is left alone.
1435
+ * Serialized on the mutation queue like every account write; silently
1436
+ * ignored when disconnected or on a write failure (bookkeeping never breaks
1437
+ * the response path).
1438
+ */
1439
+ noteRequestSuccess() {
1440
+ return this.enqueueMutation(async () => {
1441
+ const current = await this.store.load().catch(() => null);
1442
+ if (!current) return;
1443
+ if (!current.account.lastError && !current.account.cooldownUntil) return;
1444
+ if (current.account.lastError?.code === "codex_reauth_required") return;
1445
+ await this.saveData({
1446
+ ...current,
1447
+ account: { ...current.account, lastError: null, cooldownUntil: null }
1448
+ });
1449
+ }).catch(() => {
1450
+ });
1451
+ }
1426
1452
  /** Data-plane error channel (usage_limit_reached, 401, …). Never throws. */
1427
1453
  noteUpstreamError(info) {
1428
1454
  return this.enqueueMutation(async () => {
@@ -1595,6 +1621,7 @@ function normalizeItem(item, boundCallIds) {
1595
1621
  if (item.type === "item_reference") return null;
1596
1622
  const next = { ...item };
1597
1623
  delete next.id;
1624
+ delete next.thinking;
1598
1625
  if (next.role === "system") next.role = "developer";
1599
1626
  if (next.call_id !== void 0) {
1600
1627
  const bounded = boundCallId(next.call_id);
@@ -1861,7 +1888,7 @@ var CodexTransformer = class {
1861
1888
  async transformResponseOut(response, context) {
1862
1889
  this.observeHeaderRateLimits(response);
1863
1890
  const contentType = response.headers.get("content-type") ?? "";
1864
- if (!contentType.includes("text/event-stream") || !response.body) {
1891
+ if (!response.body || contentType.toLowerCase().includes("application/json")) {
1865
1892
  return response;
1866
1893
  }
1867
1894
  return this.inspectStream(response, context);
@@ -1879,6 +1906,20 @@ var CodexTransformer = class {
1879
1906
  } catch {
1880
1907
  }
1881
1908
  }
1909
+ /**
1910
+ * Clear non-sticky failure residue once the upstream produced real output:
1911
+ * a recovered account must not keep reporting its last rejection/quota
1912
+ * marker as a permanent error while requests succeed. Fire-and-forget;
1913
+ * bookkeeping never blocks or breaks the response path.
1914
+ */
1915
+ noteRequestSuccess() {
1916
+ try {
1917
+ const result = this.service.noteRequestSuccess?.();
1918
+ if (result && typeof result.then === "function") result.then(void 0, () => {
1919
+ });
1920
+ } catch {
1921
+ }
1922
+ }
1882
1923
  observeHeaderRateLimits(response) {
1883
1924
  const limits = readCodexRateLimitHeaders(response.headers);
1884
1925
  if (limits) this.reportRateLimits(limits);
@@ -1891,16 +1932,16 @@ var CodexTransformer = class {
1891
1932
  * After the prefix, bytes pass through untouched, including [DONE] and
1892
1933
  * comments; a client cancel propagates to the upstream reader.
1893
1934
  */
1894
- inspectStream(response, context) {
1935
+ inspectStream(response, _context) {
1895
1936
  const reader = response.body.getReader();
1896
1937
  const decoder = new TextDecoder();
1897
1938
  const chunks = [];
1898
1939
  let pending = "";
1899
1940
  let scanned = 0;
1900
1941
  let committed = false;
1901
- let finished = false;
1902
1942
  let rateLimitsSeen = false;
1903
1943
  let sawOutput = false;
1944
+ let successNoted = false;
1904
1945
  const handleEvent = async (data) => {
1905
1946
  if (data === "[DONE]") return true;
1906
1947
  let event;
@@ -1941,11 +1982,19 @@ var CodexTransformer = class {
1941
1982
  }
1942
1983
  if (typeof event?.type === "string" && (event.type.startsWith("response.output_text") || event.type.startsWith("response.function_call_arguments") || event.type.startsWith("response.reasoning") || event.type === "response.output_item.done")) {
1943
1984
  sawOutput = true;
1985
+ if (!successNoted) {
1986
+ successNoted = true;
1987
+ this.noteRequestSuccess();
1988
+ }
1944
1989
  return true;
1945
1990
  }
1946
1991
  if (event.type === "response.completed") {
1947
1992
  if (sawOutput || responseHasOutput(event.response)) {
1948
1993
  sawOutput = true;
1994
+ if (!successNoted) {
1995
+ successNoted = true;
1996
+ this.noteRequestSuccess();
1997
+ }
1949
1998
  return true;
1950
1999
  }
1951
2000
  throw codexEmptyAnswerError();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wengine-ai/ccr-provider-codex",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
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",
@@ -30,4 +30,4 @@
30
30
  "dist/*.json",
31
31
  "dist/*.md"
32
32
  ]
33
- }
33
+ }