@cortexkit/opencode-openai-auth 1.23.1 → 1.23.2
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/bin.js +7 -7
- package/dist/{index-7hy72nfy.js → index-by5wfvqm.js} +2 -2
- package/dist/index-nd2ks7er.js +2 -0
- package/dist/index-t876xhkr.js +60 -0
- package/dist/{index-p81hxfe6.js → index-v8w8j1wx.js} +1 -1
- package/dist/{index-3ya2s179.js → index-v8wrmhyp.js} +1 -1
- package/dist/{index-bd18sfjj.js → index-x00sxt2w.js} +10 -10
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/{runtime-layout-B07ApQZL.d.ts → internal-DacVgEWs.d.ts} +86 -663
- package/dist/rpc/port-file.js +1 -1
- package/dist/runtime-layout-Dcbj_Rq3.d.ts +650 -0
- package/dist/{sidebar-state--OTpRzFd.d.ts → sidebar-state-L--CdbLi.d.ts} +4 -15
- package/dist/sidebar-state.d.ts +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/tui.d.ts +5 -2
- package/dist/v2/server.d.ts +2 -1
- package/dist/v2/server.js +4 -4
- package/package.json +1 -1
- package/src/tui-compiled/raw/shared/054118b2705fdc20-ansi.js +98 -0
- package/src/tui-compiled/raw/shared/0895e780489c494d-window.js +33 -0
- package/src/tui-compiled/raw/shared/0b7d24474e2f33e9-credential-redaction.js +424 -0
- package/src/tui-compiled/raw/shared/0c9533222cb4380c-namespace.js +224 -0
- package/src/tui-compiled/raw/shared/112607e46a5b5f58-accounts.js +393 -0
- package/src/tui-compiled/raw/shared/136fa4abe48ad69d-cachekeep.js +411 -0
- package/src/tui-compiled/raw/shared/1547bd74f4214d2d-index.js +28 -0
- package/src/tui-compiled/raw/shared/1567207f323dc733-codex-http.js +44 -0
- package/src/tui-compiled/raw/shared/15f402885cbb2fb3-envelope-loss.js +151 -0
- package/src/tui-compiled/raw/shared/18df43cab4563acf-families.js +149 -0
- package/src/tui-compiled/raw/shared/1a4c289eec261e04-codex-instructions.js +59 -0
- package/src/tui-compiled/raw/shared/1afd446e190ef85c-vault-messages.js +12 -0
- package/src/tui-compiled/raw/shared/1b06ec96856ff8b9-codex-endpoint.js +17 -0
- package/src/tui-compiled/raw/shared/1e2f1a89bb34a773-vault-adapter.js +110 -0
- package/src/tui-compiled/raw/shared/2194fb8e8b42d7d5-insula-quota.js +73 -0
- package/src/tui-compiled/raw/shared/22b2bce42f2d6806-handle.js +10 -0
- package/src/tui-compiled/raw/shared/2577ec69f9973ae9-quota-normalize.js +13 -14
- package/src/tui-compiled/raw/shared/26055d4e5ad5e71f-codex-request.js +198 -0
- package/src/tui-compiled/raw/shared/26b57ac4c3b0c3f6-unconfirmed-retain-counter.js +41 -0
- package/src/tui-compiled/raw/shared/2bb681e99c2721d7-registry.js +538 -0
- package/src/tui-compiled/raw/shared/2dce6e9613993329-quota-manager.js +13 -20
- package/src/tui-compiled/raw/shared/2ec33b3e2b8ac38a-terminal.js +168 -0
- package/src/tui-compiled/raw/shared/30bcca1d1b4240a0-pool-session-pins.js +32 -0
- package/src/tui-compiled/raw/shared/3af9a210aa2ccdf2-codex-call-status.js +21 -0
- package/src/tui-compiled/raw/shared/3b31b36bf0877602-wording.js +120 -0
- package/src/tui-compiled/raw/shared/3c4c1a2d3fc92726-failure.js +59 -0
- package/src/tui-compiled/raw/shared/3dfe71eec6e0487d-presets.js +240 -0
- package/src/tui-compiled/raw/shared/43de3a5c4845cfc1-pool-adapter.js +149 -0
- package/src/tui-compiled/raw/shared/49353b63a833c8fb-session-cache-policy.js +60 -0
- package/src/tui-compiled/raw/shared/4adf46e07e025363-axes.js +7 -0
- package/src/tui-compiled/raw/shared/4ba847b77580b1eb-confirm.js +21 -0
- package/src/tui-compiled/raw/shared/4d05c2d7a531aece-oauth.js +48 -36
- package/src/tui-compiled/raw/shared/5018d4665e969588-limit-policy.js +159 -0
- package/src/tui-compiled/raw/shared/595bdf3fff13ba79-limit-identity.js +49 -0
- package/src/tui-compiled/raw/shared/59def9e82b61204a-session-cache-activity.js +35 -0
- package/src/tui-compiled/raw/shared/5d806e1a305d14f5-commands.js +879 -0
- package/src/tui-compiled/raw/shared/5fc39320fa8bd3a0-limit-registry.js +473 -0
- package/src/tui-compiled/raw/shared/63c1ee7e70e85e8d-vault.js +1 -0
- package/src/tui-compiled/raw/shared/6545ab7f757314b7-refresh-all-quota.js +237 -0
- package/src/tui-compiled/raw/shared/66937534c260d20b-stable-json.js +11 -0
- package/src/tui-compiled/raw/shared/7056acef1b021f19-bridge.js +10 -0
- package/src/tui-compiled/raw/shared/72d2ca42883809b4-marker.js +107 -0
- package/src/tui-compiled/raw/shared/775431e21f469203-record.js +3 -0
- package/src/tui-compiled/raw/shared/799f3ade4efbd1ea-opencode-v1.js +47 -0
- package/src/tui-compiled/raw/shared/7b2a0471b29e4f5e-wake.js +47 -0
- package/src/tui-compiled/raw/shared/7b5d6afff4ff32b9-select.js +159 -0
- package/src/tui-compiled/raw/shared/7bf96bf4d9249b3d-vault-billing.js +108 -0
- package/src/tui-compiled/raw/shared/7c98bde36aad4819-input-transformations.js +34 -0
- package/src/tui-compiled/raw/shared/7fb0418303f20a10-index.js +3 -0
- package/src/tui-compiled/raw/shared/806e12ccbad34388-pi-wait.js +51 -0
- package/src/tui-compiled/raw/shared/81ae201b724cac14-menu.js +73 -0
- package/src/tui-compiled/raw/shared/8349ed25dc629e97-scope.js +10 -0
- package/src/tui-compiled/raw/shared/86da3379973780b9-limit-provenance.js +60 -0
- package/src/tui-compiled/raw/shared/8aba66ed486d30a7-decide.js +425 -0
- package/src/tui-compiled/raw/shared/8c0c8df25a5dca1f-manager.js +735 -0
- package/src/tui-compiled/raw/shared/8c42bbec02f59636-vault-routing.js +212 -0
- package/src/tui-compiled/raw/shared/8ca6175bfae53e13-envelope.js +123 -0
- package/src/tui-compiled/raw/shared/8d0245e41049d83f-header-classifier.js +121 -0
- package/src/tui-compiled/raw/shared/9c162809179c7560-login.js +89 -0
- package/src/tui-compiled/raw/shared/a1f495296a4b756f-frame-turn.js +72 -0
- package/src/tui-compiled/raw/shared/a37138dcbd893f55-hold-bounds.js +5 -0
- package/src/tui-compiled/raw/shared/aa7fb10d77a2cccd-vault-account-menu.js +133 -0
- package/src/tui-compiled/raw/shared/adc5eeb5a8d28280-persistence.js +9 -0
- package/src/tui-compiled/raw/shared/b301c79e6378d1fb-vault.js +678 -0
- package/src/tui-compiled/raw/shared/b3c11de5f36e617a-reset.js +44 -0
- package/src/tui-compiled/raw/shared/ba6535c610d1edb3-pool-source-state.js +100 -0
- package/src/tui-compiled/raw/shared/bd4aef685681048c-duration.js +20 -0
- package/src/tui-compiled/raw/shared/bd5977eca210d2b8-index.js +662 -0
- package/src/tui-compiled/raw/shared/bfc46d34f4c9db33-limit-recovery.js +127 -0
- package/src/tui-compiled/raw/shared/c66495424ad84aee-hold.js +25 -0
- package/src/tui-compiled/raw/shared/c6a67b836bd5afcd-vault-command-menu.js +300 -0
- package/src/tui-compiled/raw/shared/c9340fb545c4e5de-internal.js +73 -0
- package/src/tui-compiled/raw/shared/c954c6447b7b9b64-activity.js +52 -0
- package/src/tui-compiled/raw/shared/cba8b0aee46b8526-codex-lite.js +85 -0
- package/src/tui-compiled/raw/shared/cec39ccddab4fe9c-labels.js +11 -0
- package/src/tui-compiled/raw/shared/cef0f2346957e83c-index.js +552 -0
- package/src/tui-compiled/raw/shared/cf7dedf24f902d68-dump-size.js +41 -0
- package/src/tui-compiled/raw/shared/d422d6dbc4e35199-background-quota-refresh.js +107 -0
- package/src/tui-compiled/raw/shared/d5b268767d330507-doctor.js +81 -0
- package/src/tui-compiled/raw/shared/d7ac5ca41f49121b-index.js +12 -0
- package/src/tui-compiled/raw/shared/d7fa77560855dee2-jitter.js +9 -0
- package/src/tui-compiled/raw/shared/de7f7d8803624369-path.js +31 -0
- package/src/tui-compiled/raw/shared/df0bdc74fb0c0db0-limit-mark.js +27 -0
- package/src/tui-compiled/raw/shared/e26c2bb5722ab047-routing-hold.js +23 -0
- package/src/tui-compiled/raw/shared/e2ae081583adfce3-dump.js +80 -0
- package/src/tui-compiled/raw/shared/e44ba1b3a9903f5d-reset-credits.js +483 -0
- package/src/tui-compiled/raw/shared/e5229952fc12f647-codex-models.js +34 -0
- package/src/tui-compiled/raw/shared/e8fda84e90176436-uuid-v7.js +13 -0
- package/src/tui-compiled/raw/shared/ea56007991dbf068-terminal.js +19 -0
- package/src/tui-compiled/raw/shared/ec6f1d96e7d70174-quota-refusal.js +145 -0
- package/src/tui-compiled/raw/shared/f03d7b43a214a4a1-canonical-input.js +42 -0
- package/src/tui-compiled/raw/shared/f1012265b3a768c7-merge-laws.js +31 -0
- package/src/tui-compiled/raw/shared/f2ca864fe967415a-cache-policy.js +198 -0
- package/src/tui-compiled/raw/shared/f317a4740f9d76f8-identity.js +21 -0
- package/src/tui-compiled/raw/shared/f607353c4126272a-routing-wait.js +19 -0
- package/src/tui-compiled/raw/shared/f6189f5c9aee31eb-decision.js +55 -0
- package/src/tui-compiled/raw/shared/f6d728f5e601f98b-request-history.js +120 -0
- package/src/tui-compiled/raw/shared/f981e6b15fb76cdb-codex-body.js +28 -0
- package/src/tui-compiled/raw/shared/fda579e5a0a54165-codex-effort.js +60 -0
- package/src/tui-compiled/raw/sidebar-state.js +54 -4
- package/src/tui-compiled/raw/tui/v2-dialog.js +1 -1
- package/src/tui-compiled/raw/tui.tsx +27 -5
- package/src/tui-compiled/runtime/shared/054118b2705fdc20-ansi.js +98 -0
- package/src/tui-compiled/runtime/shared/0895e780489c494d-window.js +33 -0
- package/src/tui-compiled/runtime/shared/0b7d24474e2f33e9-credential-redaction.js +424 -0
- package/src/tui-compiled/runtime/shared/0c9533222cb4380c-namespace.js +224 -0
- package/src/tui-compiled/runtime/shared/112607e46a5b5f58-accounts.js +393 -0
- package/src/tui-compiled/runtime/shared/136fa4abe48ad69d-cachekeep.js +411 -0
- package/src/tui-compiled/runtime/shared/1547bd74f4214d2d-index.js +28 -0
- package/src/tui-compiled/runtime/shared/1567207f323dc733-codex-http.js +44 -0
- package/src/tui-compiled/runtime/shared/15f402885cbb2fb3-envelope-loss.js +151 -0
- package/src/tui-compiled/runtime/shared/18df43cab4563acf-families.js +149 -0
- package/src/tui-compiled/runtime/shared/1a4c289eec261e04-codex-instructions.js +59 -0
- package/src/tui-compiled/runtime/shared/1afd446e190ef85c-vault-messages.js +12 -0
- package/src/tui-compiled/runtime/shared/1b06ec96856ff8b9-codex-endpoint.js +17 -0
- package/src/tui-compiled/runtime/shared/1e2f1a89bb34a773-vault-adapter.js +110 -0
- package/src/tui-compiled/runtime/shared/2194fb8e8b42d7d5-insula-quota.js +73 -0
- package/src/tui-compiled/runtime/shared/22b2bce42f2d6806-handle.js +10 -0
- package/src/tui-compiled/runtime/shared/2577ec69f9973ae9-quota-normalize.js +13 -14
- package/src/tui-compiled/runtime/shared/26055d4e5ad5e71f-codex-request.js +198 -0
- package/src/tui-compiled/runtime/shared/26b57ac4c3b0c3f6-unconfirmed-retain-counter.js +41 -0
- package/src/tui-compiled/runtime/shared/2bb681e99c2721d7-registry.js +538 -0
- package/src/tui-compiled/runtime/shared/2dce6e9613993329-quota-manager.js +13 -20
- package/src/tui-compiled/runtime/shared/2ec33b3e2b8ac38a-terminal.js +168 -0
- package/src/tui-compiled/runtime/shared/30bcca1d1b4240a0-pool-session-pins.js +32 -0
- package/src/tui-compiled/runtime/shared/3af9a210aa2ccdf2-codex-call-status.js +21 -0
- package/src/tui-compiled/runtime/shared/3b31b36bf0877602-wording.js +120 -0
- package/src/tui-compiled/runtime/shared/3c4c1a2d3fc92726-failure.js +59 -0
- package/src/tui-compiled/runtime/shared/3dfe71eec6e0487d-presets.js +240 -0
- package/src/tui-compiled/runtime/shared/43de3a5c4845cfc1-pool-adapter.js +149 -0
- package/src/tui-compiled/runtime/shared/49353b63a833c8fb-session-cache-policy.js +60 -0
- package/src/tui-compiled/runtime/shared/4adf46e07e025363-axes.js +7 -0
- package/src/tui-compiled/runtime/shared/4ba847b77580b1eb-confirm.js +21 -0
- package/src/tui-compiled/runtime/shared/4d05c2d7a531aece-oauth.js +48 -36
- package/src/tui-compiled/runtime/shared/5018d4665e969588-limit-policy.js +159 -0
- package/src/tui-compiled/runtime/shared/595bdf3fff13ba79-limit-identity.js +49 -0
- package/src/tui-compiled/runtime/shared/59def9e82b61204a-session-cache-activity.js +35 -0
- package/src/tui-compiled/runtime/shared/5d806e1a305d14f5-commands.js +879 -0
- package/src/tui-compiled/runtime/shared/5fc39320fa8bd3a0-limit-registry.js +473 -0
- package/src/tui-compiled/runtime/shared/63c1ee7e70e85e8d-vault.js +1 -0
- package/src/tui-compiled/runtime/shared/6545ab7f757314b7-refresh-all-quota.js +237 -0
- package/src/tui-compiled/runtime/shared/66937534c260d20b-stable-json.js +11 -0
- package/src/tui-compiled/runtime/shared/7056acef1b021f19-bridge.js +10 -0
- package/src/tui-compiled/runtime/shared/72d2ca42883809b4-marker.js +107 -0
- package/src/tui-compiled/runtime/shared/775431e21f469203-record.js +3 -0
- package/src/tui-compiled/runtime/shared/799f3ade4efbd1ea-opencode-v1.js +47 -0
- package/src/tui-compiled/runtime/shared/7b2a0471b29e4f5e-wake.js +47 -0
- package/src/tui-compiled/runtime/shared/7b5d6afff4ff32b9-select.js +159 -0
- package/src/tui-compiled/runtime/shared/7bf96bf4d9249b3d-vault-billing.js +108 -0
- package/src/tui-compiled/runtime/shared/7c98bde36aad4819-input-transformations.js +34 -0
- package/src/tui-compiled/runtime/shared/7fb0418303f20a10-index.js +3 -0
- package/src/tui-compiled/runtime/shared/806e12ccbad34388-pi-wait.js +51 -0
- package/src/tui-compiled/runtime/shared/81ae201b724cac14-menu.js +73 -0
- package/src/tui-compiled/runtime/shared/8349ed25dc629e97-scope.js +10 -0
- package/src/tui-compiled/runtime/shared/86da3379973780b9-limit-provenance.js +60 -0
- package/src/tui-compiled/runtime/shared/8aba66ed486d30a7-decide.js +425 -0
- package/src/tui-compiled/runtime/shared/8c0c8df25a5dca1f-manager.js +735 -0
- package/src/tui-compiled/runtime/shared/8c42bbec02f59636-vault-routing.js +212 -0
- package/src/tui-compiled/runtime/shared/8ca6175bfae53e13-envelope.js +123 -0
- package/src/tui-compiled/runtime/shared/8d0245e41049d83f-header-classifier.js +121 -0
- package/src/tui-compiled/runtime/shared/9c162809179c7560-login.js +89 -0
- package/src/tui-compiled/runtime/shared/a1f495296a4b756f-frame-turn.js +72 -0
- package/src/tui-compiled/runtime/shared/a37138dcbd893f55-hold-bounds.js +5 -0
- package/src/tui-compiled/runtime/shared/aa7fb10d77a2cccd-vault-account-menu.js +133 -0
- package/src/tui-compiled/runtime/shared/adc5eeb5a8d28280-persistence.js +9 -0
- package/src/tui-compiled/runtime/shared/b301c79e6378d1fb-vault.js +678 -0
- package/src/tui-compiled/runtime/shared/b3c11de5f36e617a-reset.js +44 -0
- package/src/tui-compiled/runtime/shared/ba6535c610d1edb3-pool-source-state.js +100 -0
- package/src/tui-compiled/runtime/shared/bd4aef685681048c-duration.js +20 -0
- package/src/tui-compiled/runtime/shared/bd5977eca210d2b8-index.js +662 -0
- package/src/tui-compiled/runtime/shared/bfc46d34f4c9db33-limit-recovery.js +127 -0
- package/src/tui-compiled/runtime/shared/c66495424ad84aee-hold.js +25 -0
- package/src/tui-compiled/runtime/shared/c6a67b836bd5afcd-vault-command-menu.js +300 -0
- package/src/tui-compiled/runtime/shared/c9340fb545c4e5de-internal.js +73 -0
- package/src/tui-compiled/runtime/shared/c954c6447b7b9b64-activity.js +52 -0
- package/src/tui-compiled/runtime/shared/cba8b0aee46b8526-codex-lite.js +85 -0
- package/src/tui-compiled/runtime/shared/cec39ccddab4fe9c-labels.js +11 -0
- package/src/tui-compiled/runtime/shared/cef0f2346957e83c-index.js +552 -0
- package/src/tui-compiled/runtime/shared/cf7dedf24f902d68-dump-size.js +41 -0
- package/src/tui-compiled/runtime/shared/d422d6dbc4e35199-background-quota-refresh.js +107 -0
- package/src/tui-compiled/runtime/shared/d5b268767d330507-doctor.js +81 -0
- package/src/tui-compiled/runtime/shared/d7ac5ca41f49121b-index.js +12 -0
- package/src/tui-compiled/runtime/shared/d7fa77560855dee2-jitter.js +9 -0
- package/src/tui-compiled/runtime/shared/de7f7d8803624369-path.js +31 -0
- package/src/tui-compiled/runtime/shared/df0bdc74fb0c0db0-limit-mark.js +27 -0
- package/src/tui-compiled/runtime/shared/e26c2bb5722ab047-routing-hold.js +23 -0
- package/src/tui-compiled/runtime/shared/e2ae081583adfce3-dump.js +80 -0
- package/src/tui-compiled/runtime/shared/e44ba1b3a9903f5d-reset-credits.js +483 -0
- package/src/tui-compiled/runtime/shared/e5229952fc12f647-codex-models.js +34 -0
- package/src/tui-compiled/runtime/shared/e8fda84e90176436-uuid-v7.js +13 -0
- package/src/tui-compiled/runtime/shared/ea56007991dbf068-terminal.js +19 -0
- package/src/tui-compiled/runtime/shared/ec6f1d96e7d70174-quota-refusal.js +145 -0
- package/src/tui-compiled/runtime/shared/f03d7b43a214a4a1-canonical-input.js +42 -0
- package/src/tui-compiled/runtime/shared/f1012265b3a768c7-merge-laws.js +31 -0
- package/src/tui-compiled/runtime/shared/f2ca864fe967415a-cache-policy.js +198 -0
- package/src/tui-compiled/runtime/shared/f317a4740f9d76f8-identity.js +21 -0
- package/src/tui-compiled/runtime/shared/f607353c4126272a-routing-wait.js +19 -0
- package/src/tui-compiled/runtime/shared/f6189f5c9aee31eb-decision.js +55 -0
- package/src/tui-compiled/runtime/shared/f6d728f5e601f98b-request-history.js +120 -0
- package/src/tui-compiled/runtime/shared/f981e6b15fb76cdb-codex-body.js +28 -0
- package/src/tui-compiled/runtime/shared/fda579e5a0a54165-codex-effort.js +60 -0
- package/src/tui-compiled/runtime/sidebar-state.js +54 -4
- package/src/tui-compiled/runtime/tui/v2-dialog.js +1 -1
- package/src/tui-compiled/runtime/tui.js +11 -4
- package/dist/index-0p8r7cpy.js +0 -60
- package/dist/index-px1t650b.js +0 -2
- package/dist/map-D5PHhv4z.d.ts +0 -72
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isSafeResetAccountKey
|
|
3
|
+
} from "./dbc61cd405941828-accounts.js";
|
|
4
|
+
const RESET_CREDITS_PATH = "/backend-api/wham/rate-limit-reset-credits", RESET_CREDITS_URL = `https://chatgpt.com${RESET_CREDITS_PATH}`, CONSUME_RESET_CREDIT_PATH = `${RESET_CREDITS_PATH}/consume`, CONSUME_RESET_CREDIT_URL = `https://chatgpt.com${CONSUME_RESET_CREDIT_PATH}`, RESET_IN_FLIGHT_TTL_MS = 300000, RESET_CONSUME_TIMEOUT_MS = 60000, RESET_LIST_TIMEOUT_MS = 15000, RESET_COOLDOWN_MS = 60000;
|
|
5
|
+
function storePaths(deps) {
|
|
6
|
+
return { configPath: deps.configPath, statePath: deps.statePath };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class ResetRedemptionError extends Error {
|
|
10
|
+
kind;
|
|
11
|
+
cooldownUntil;
|
|
12
|
+
constructor(kind, message, cooldownUntil) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "ResetRedemptionError";
|
|
15
|
+
this.kind = kind;
|
|
16
|
+
this.cooldownUntil = cooldownUntil;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ResetCreditError extends Error {
|
|
21
|
+
kind;
|
|
22
|
+
status;
|
|
23
|
+
constructor(kind, message, status) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "ResetCreditError";
|
|
26
|
+
this.kind = kind;
|
|
27
|
+
this.status = status;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function whamHeaders(token, targetPath, accountId) {
|
|
31
|
+
return {
|
|
32
|
+
authorization: `Bearer ${token}`,
|
|
33
|
+
...accountId ? { "chatgpt-account-id": accountId } : {},
|
|
34
|
+
"oai-client-platform": "web",
|
|
35
|
+
"oai-client-version": "0",
|
|
36
|
+
"x-openai-target-path": targetPath
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function isRecord(value) {
|
|
40
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41
|
+
}
|
|
42
|
+
function cloneResetState(state) {
|
|
43
|
+
if (!state)
|
|
44
|
+
return;
|
|
45
|
+
return {
|
|
46
|
+
...state.inFlight ? { inFlight: { ...state.inFlight } } : {},
|
|
47
|
+
...state.lastOutcome ? { lastOutcome: { ...state.lastOutcome } } : {},
|
|
48
|
+
...state.cooldownUntil !== void 0 ? { cooldownUntil: state.cooldownUntil } : {}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function validInFlight(value) {
|
|
52
|
+
if (!isRecord(value) || typeof value.redeemRequestId !== "string" || value.redeemRequestId.length === 0 || typeof value.creditId !== "string" || value.creditId.length === 0 || typeof value.startedAt !== "number" || !Number.isFinite(value.startedAt) || value.chatgptAccountId !== void 0 && (typeof value.chatgptAccountId !== "string" || value.chatgptAccountId.length === 0))
|
|
53
|
+
return;
|
|
54
|
+
return {
|
|
55
|
+
redeemRequestId: value.redeemRequestId,
|
|
56
|
+
creditId: value.creditId,
|
|
57
|
+
startedAt: value.startedAt,
|
|
58
|
+
...typeof value.chatgptAccountId === "string" ? { chatgptAccountId: value.chatgptAccountId } : {},
|
|
59
|
+
...isDefiniteRefusal(value.rejectedStatus) ? { rejectedStatus: value.rejectedStatus } : {},
|
|
60
|
+
...typeof value.unknownAnswers === "number" && Number.isSafeInteger(value.unknownAnswers) && value.unknownAnswers > 0 ? { unknownAnswers: value.unknownAnswers } : {}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function isDefiniteRefusal(status) {
|
|
64
|
+
return typeof status === "number" && status >= 400 && status < 500 && status !== 408 && status !== 409 && status !== 425 && status !== 429;
|
|
65
|
+
}
|
|
66
|
+
function isRefusedConsume(outcome) {
|
|
67
|
+
return outcome.kind === "http_error" && isDefiniteRefusal(outcome.status);
|
|
68
|
+
}
|
|
69
|
+
function mayReplaceExpiredPair(pair, chatgptAccountId) {
|
|
70
|
+
return pair.chatgptAccountId !== void 0 && pair.chatgptAccountId !== chatgptAccountId || pair.rejectedStatus !== void 0;
|
|
71
|
+
}
|
|
72
|
+
function assertPairBelongsTo(pair, chatgptAccountId) {
|
|
73
|
+
if (pair.chatgptAccountId !== void 0 && pair.chatgptAccountId !== chatgptAccountId)
|
|
74
|
+
throw new ResetRedemptionError("pair_identity_mismatch", "the saved reset redemption was started under a different ChatGPT account");
|
|
75
|
+
}
|
|
76
|
+
function hasInFlightField(state) {
|
|
77
|
+
return Boolean(state && Object.hasOwn(state, "inFlight"));
|
|
78
|
+
}
|
|
79
|
+
function isYoungerThanInFlightTtl(inFlight, now) {
|
|
80
|
+
return now - inFlight.startedAt < RESET_IN_FLIGHT_TTL_MS;
|
|
81
|
+
}
|
|
82
|
+
function resetStateForAccount(current, accountKey) {
|
|
83
|
+
if (!isSafeResetAccountKey(accountKey))
|
|
84
|
+
return;
|
|
85
|
+
return current.reset?.[accountKey];
|
|
86
|
+
}
|
|
87
|
+
function resetStateMap(current) {
|
|
88
|
+
if (!current.reset)
|
|
89
|
+
current.reset = Object.create(null);
|
|
90
|
+
return current.reset;
|
|
91
|
+
}
|
|
92
|
+
function resolveCorruptState(current, accountKey, now) {
|
|
93
|
+
if (!isSafeResetAccountKey(accountKey))
|
|
94
|
+
return;
|
|
95
|
+
const reset = resetStateMap(current), state = reset[accountKey] ?? {}, previousOutcome = state.lastOutcome;
|
|
96
|
+
delete state.inFlight;
|
|
97
|
+
state.lastOutcome = {
|
|
98
|
+
code: "ambiguous_local",
|
|
99
|
+
at: now,
|
|
100
|
+
...previousOutcome ? {
|
|
101
|
+
previousOutcome: {
|
|
102
|
+
code: previousOutcome.code,
|
|
103
|
+
at: previousOutcome.at
|
|
104
|
+
}
|
|
105
|
+
} : {}
|
|
106
|
+
};
|
|
107
|
+
reset[accountKey] = state;
|
|
108
|
+
}
|
|
109
|
+
function inspectResetState(state, now) {
|
|
110
|
+
const beforeState = cloneResetState(state), inFlight = validInFlight(state?.inFlight);
|
|
111
|
+
if (hasInFlightField(state) && !inFlight)
|
|
112
|
+
return { kind: "corrupt", beforeState };
|
|
113
|
+
if (state?.cooldownUntil !== void 0 && state.cooldownUntil > now)
|
|
114
|
+
return {
|
|
115
|
+
kind: "cooldown",
|
|
116
|
+
beforeState,
|
|
117
|
+
cooldownUntil: state.cooldownUntil
|
|
118
|
+
};
|
|
119
|
+
if (inFlight && isYoungerThanInFlightTtl(inFlight, now))
|
|
120
|
+
return {
|
|
121
|
+
kind: "claim",
|
|
122
|
+
beforeState,
|
|
123
|
+
claim: {
|
|
124
|
+
inFlight,
|
|
125
|
+
selectedCredit: { id: inFlight.creditId }
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
if (inFlight)
|
|
129
|
+
return {
|
|
130
|
+
kind: "expired_unreconciled",
|
|
131
|
+
beforeState,
|
|
132
|
+
claim: {
|
|
133
|
+
inFlight,
|
|
134
|
+
selectedCredit: { id: inFlight.creditId }
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
return { kind: "fresh", beforeState };
|
|
138
|
+
}
|
|
139
|
+
async function inspectResetAttempt(deps, accountKey) {
|
|
140
|
+
if (!isSafeResetAccountKey(accountKey))
|
|
141
|
+
return { kind: "fresh", beforeState: void 0 };
|
|
142
|
+
const current = await deps.loadAccountsFn(storePaths(deps));
|
|
143
|
+
return inspectResetState(current ? resetStateForAccount(current, accountKey) : void 0, deps.now());
|
|
144
|
+
}
|
|
145
|
+
async function resolveCorruptResetAttempt(deps, accountKey) {
|
|
146
|
+
let decision;
|
|
147
|
+
await deps.mutateAccountsFn((current) => {
|
|
148
|
+
const now = deps.now(), state = resetStateForAccount(current, accountKey);
|
|
149
|
+
decision = inspectResetState(state, now);
|
|
150
|
+
if (decision.kind === "corrupt")
|
|
151
|
+
resolveCorruptState(current, accountKey, now);
|
|
152
|
+
return current;
|
|
153
|
+
}, storePaths(deps));
|
|
154
|
+
if (!decision)
|
|
155
|
+
throw Error("corrupt reset state mutation did not run");
|
|
156
|
+
return decision;
|
|
157
|
+
}
|
|
158
|
+
export async function claimResetAttempt(deps, accountKey, credits, chatgptAccountId) {
|
|
159
|
+
if (!isSafeResetAccountKey(accountKey))
|
|
160
|
+
return { kind: "fresh", beforeState: void 0 };
|
|
161
|
+
let decision;
|
|
162
|
+
await deps.mutateAccountsFn((current) => {
|
|
163
|
+
const now = deps.now(), state = resetStateForAccount(current, accountKey), beforeState = cloneResetState(state), inFlight = validInFlight(state?.inFlight);
|
|
164
|
+
if (hasInFlightField(state) && !inFlight) {
|
|
165
|
+
resolveCorruptState(current, accountKey, now);
|
|
166
|
+
decision = { kind: "corrupt", beforeState };
|
|
167
|
+
return current;
|
|
168
|
+
}
|
|
169
|
+
if (state?.cooldownUntil !== void 0 && state.cooldownUntil > now) {
|
|
170
|
+
decision = {
|
|
171
|
+
kind: "cooldown",
|
|
172
|
+
beforeState,
|
|
173
|
+
cooldownUntil: state.cooldownUntil
|
|
174
|
+
};
|
|
175
|
+
return current;
|
|
176
|
+
}
|
|
177
|
+
if (inFlight && isYoungerThanInFlightTtl(inFlight, now)) {
|
|
178
|
+
decision = {
|
|
179
|
+
kind: "claim",
|
|
180
|
+
beforeState,
|
|
181
|
+
claim: {
|
|
182
|
+
inFlight,
|
|
183
|
+
selectedCredit: { id: inFlight.creditId }
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return current;
|
|
187
|
+
}
|
|
188
|
+
if (inFlight && !mayReplaceExpiredPair(inFlight, chatgptAccountId)) {
|
|
189
|
+
decision = {
|
|
190
|
+
kind: "expired_unreconciled",
|
|
191
|
+
beforeState,
|
|
192
|
+
claim: {
|
|
193
|
+
inFlight,
|
|
194
|
+
selectedCredit: { id: inFlight.creditId }
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
return current;
|
|
198
|
+
}
|
|
199
|
+
const selectedCredit = selectCreditToSpend(credits);
|
|
200
|
+
if (!selectedCredit) {
|
|
201
|
+
decision = { kind: "fresh", beforeState };
|
|
202
|
+
return current;
|
|
203
|
+
}
|
|
204
|
+
const claimedInFlight = {
|
|
205
|
+
redeemRequestId: deps.randomUUID(),
|
|
206
|
+
creditId: selectedCredit.id,
|
|
207
|
+
startedAt: now,
|
|
208
|
+
...chatgptAccountId === void 0 ? {} : { chatgptAccountId }
|
|
209
|
+
}, reset = resetStateMap(current);
|
|
210
|
+
reset[accountKey] = {
|
|
211
|
+
...state,
|
|
212
|
+
inFlight: claimedInFlight
|
|
213
|
+
};
|
|
214
|
+
decision = {
|
|
215
|
+
kind: "claim",
|
|
216
|
+
beforeState,
|
|
217
|
+
claim: { inFlight: claimedInFlight, selectedCredit }
|
|
218
|
+
};
|
|
219
|
+
return current;
|
|
220
|
+
}, storePaths(deps));
|
|
221
|
+
if (!decision)
|
|
222
|
+
throw Error("reset claim mutation did not run");
|
|
223
|
+
return decision;
|
|
224
|
+
}
|
|
225
|
+
export async function finalizeResetAttempt(deps, accountKey, completing, outcome, sentAs) {
|
|
226
|
+
if (!isSafeResetAccountKey(accountKey))
|
|
227
|
+
return;
|
|
228
|
+
if (!isTerminalConsumeKind(outcome.kind))
|
|
229
|
+
return recordUnreconciledAnswer(deps, accountKey, completing, outcome, sentAs);
|
|
230
|
+
await deps.mutateAccountsFn((current) => {
|
|
231
|
+
const state = resetStateForAccount(current, accountKey), persisted = validInFlight(state?.inFlight);
|
|
232
|
+
if (!state || !persisted || persisted.redeemRequestId !== completing.redeemRequestId || persisted.creditId !== completing.creditId)
|
|
233
|
+
return current;
|
|
234
|
+
const now = deps.now();
|
|
235
|
+
delete state.inFlight;
|
|
236
|
+
state.lastOutcome = { code: outcome.kind, at: now };
|
|
237
|
+
if (outcome.kind === "reset" || outcome.kind === "already_redeemed")
|
|
238
|
+
state.cooldownUntil = now + RESET_COOLDOWN_MS;
|
|
239
|
+
else
|
|
240
|
+
delete state.cooldownUntil;
|
|
241
|
+
return current;
|
|
242
|
+
}, storePaths(deps));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
function savedPairMatching(state, completing) {
|
|
246
|
+
const persisted = validInFlight(state?.inFlight);
|
|
247
|
+
return persisted && persisted.redeemRequestId === completing.redeemRequestId && persisted.creditId === completing.creditId ? persisted : void 0;
|
|
248
|
+
}
|
|
249
|
+
async function recordUnreconciledAnswer(deps, accountKey, completing, outcome, sentAs) {
|
|
250
|
+
const refusal = isRefusedConsume(outcome) ? outcome.status : void 0;
|
|
251
|
+
if (!(completing.chatgptAccountId === void 0 && sentAs !== void 0) && refusal !== void 0 && refusal === completing.rejectedStatus) {
|
|
252
|
+
const current = await deps.loadAccountsFn(storePaths(deps));
|
|
253
|
+
return savedPairMatching(current ? resetStateForAccount(current, accountKey) : void 0, completing);
|
|
254
|
+
}
|
|
255
|
+
let saved;
|
|
256
|
+
await deps.mutateAccountsFn((current) => {
|
|
257
|
+
saved = void 0;
|
|
258
|
+
const state = resetStateForAccount(current, accountKey), persisted = savedPairMatching(state, completing);
|
|
259
|
+
if (!state || !persisted)
|
|
260
|
+
return current;
|
|
261
|
+
const next = { ...persisted };
|
|
262
|
+
if (next.chatgptAccountId === void 0 && sentAs !== void 0)
|
|
263
|
+
next.chatgptAccountId = sentAs;
|
|
264
|
+
if (refusal === void 0) {
|
|
265
|
+
delete next.rejectedStatus;
|
|
266
|
+
next.unknownAnswers = (persisted.unknownAnswers ?? 0) + 1;
|
|
267
|
+
} else if ((persisted.unknownAnswers ?? 0) === (completing.unknownAnswers ?? 0))
|
|
268
|
+
next.rejectedStatus = refusal;
|
|
269
|
+
state.inFlight = next;
|
|
270
|
+
saved = next;
|
|
271
|
+
return current;
|
|
272
|
+
}, storePaths(deps));
|
|
273
|
+
return saved;
|
|
274
|
+
}
|
|
275
|
+
export function resetWindowIsExhausted(window, now) {
|
|
276
|
+
if (!window || window.usedPercent < 100)
|
|
277
|
+
return !1;
|
|
278
|
+
if (!window.resetsAt)
|
|
279
|
+
return !0;
|
|
280
|
+
const resetsAt = Date.parse(window.resetsAt);
|
|
281
|
+
return !Number.isFinite(resetsAt) || resetsAt > now;
|
|
282
|
+
}
|
|
283
|
+
export function evaluateResetPrecondition(quota, hasActiveRateLimitMark, now) {
|
|
284
|
+
if (!(hasActiveRateLimitMark || resetWindowIsExhausted(quota.primary, now) || resetWindowIsExhausted(quota.secondary, now)))
|
|
285
|
+
return { ok: !1, reason: "not exhausted" };
|
|
286
|
+
return { ok: !0 };
|
|
287
|
+
}
|
|
288
|
+
function optionalString(record, key) {
|
|
289
|
+
const value = record[key];
|
|
290
|
+
if (value === void 0 || value === null)
|
|
291
|
+
return;
|
|
292
|
+
return typeof value === "string" ? value : null;
|
|
293
|
+
}
|
|
294
|
+
function parseCredit(value) {
|
|
295
|
+
if (!isRecord(value))
|
|
296
|
+
return;
|
|
297
|
+
const grantedAt = optionalString(value, "granted_at"), resetType = optionalString(value, "reset_type");
|
|
298
|
+
if (typeof value.id !== "string" || typeof value.status !== "string" || typeof value.expires_at !== "string" || Number.isNaN(Date.parse(value.expires_at)) || typeof value.is_supported_by_plan !== "boolean" || grantedAt === null || resetType === null)
|
|
299
|
+
return;
|
|
300
|
+
return {
|
|
301
|
+
id: value.id,
|
|
302
|
+
status: value.status,
|
|
303
|
+
...grantedAt === void 0 ? {} : { grantedAt },
|
|
304
|
+
expiresAt: value.expires_at,
|
|
305
|
+
...resetType === void 0 ? {} : { resetType },
|
|
306
|
+
isSupportedByPlan: value.is_supported_by_plan
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
export async function listResetCredits(fetchImpl, token, accountId) {
|
|
310
|
+
let response;
|
|
311
|
+
try {
|
|
312
|
+
response = await fetchImpl(RESET_CREDITS_URL, {
|
|
313
|
+
method: "GET",
|
|
314
|
+
headers: whamHeaders(token, RESET_CREDITS_PATH, accountId),
|
|
315
|
+
signal: AbortSignal.timeout(RESET_LIST_TIMEOUT_MS)
|
|
316
|
+
});
|
|
317
|
+
} catch {
|
|
318
|
+
throw new ResetCreditError("http_error", "reset credit list request failed");
|
|
319
|
+
}
|
|
320
|
+
if (!response.ok)
|
|
321
|
+
throw new ResetCreditError("http_error", `reset credit list request failed: ${response.status}`, response.status);
|
|
322
|
+
let raw;
|
|
323
|
+
try {
|
|
324
|
+
raw = await response.json();
|
|
325
|
+
} catch {
|
|
326
|
+
throw new ResetCreditError("invalid_response", "reset credit list response was not valid JSON", response.status);
|
|
327
|
+
}
|
|
328
|
+
if (!isRecord(raw))
|
|
329
|
+
throw new ResetCreditError("invalid_response", "reset credit list response was not an object", response.status);
|
|
330
|
+
return {
|
|
331
|
+
credits: (Array.isArray(raw.credits) ? raw.credits : []).flatMap((value) => {
|
|
332
|
+
const parsed = parseCredit(value);
|
|
333
|
+
return parsed === void 0 ? [] : [parsed];
|
|
334
|
+
}),
|
|
335
|
+
availableCount: typeof raw.available_count === "number" && Number.isFinite(raw.available_count) ? raw.available_count : void 0
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
export function selectCreditToSpend(credits) {
|
|
339
|
+
return [...credits].filter(isResetCreditEligible).sort((left, right) => Date.parse(left.expiresAt) - Date.parse(right.expiresAt))[0];
|
|
340
|
+
}
|
|
341
|
+
export function isResetCreditEligible(credit) {
|
|
342
|
+
return credit.status === "available" && credit.isSupportedByPlan && credit.resetType === "codex_rate_limits";
|
|
343
|
+
}
|
|
344
|
+
export function countEligibleResetCredits(credits) {
|
|
345
|
+
return credits.filter(isResetCreditEligible).length;
|
|
346
|
+
}
|
|
347
|
+
function isTerminalConsumeKind(value) {
|
|
348
|
+
return value === "reset" || value === "already_redeemed" || value === "nothing_to_reset" || value === "no_credit";
|
|
349
|
+
}
|
|
350
|
+
export async function consumeResetCredit(fetchImpl, token, accountId, creditId, redeemRequestId) {
|
|
351
|
+
let response;
|
|
352
|
+
try {
|
|
353
|
+
response = await fetchImpl(CONSUME_RESET_CREDIT_URL, {
|
|
354
|
+
method: "POST",
|
|
355
|
+
headers: {
|
|
356
|
+
...whamHeaders(token, CONSUME_RESET_CREDIT_PATH, accountId),
|
|
357
|
+
"content-type": "application/json"
|
|
358
|
+
},
|
|
359
|
+
body: JSON.stringify({
|
|
360
|
+
redeem_request_id: redeemRequestId,
|
|
361
|
+
credit_id: creditId
|
|
362
|
+
}),
|
|
363
|
+
signal: AbortSignal.timeout(RESET_CONSUME_TIMEOUT_MS)
|
|
364
|
+
});
|
|
365
|
+
} catch (error) {
|
|
366
|
+
return { kind: "ambiguous", raw: error };
|
|
367
|
+
}
|
|
368
|
+
let body;
|
|
369
|
+
try {
|
|
370
|
+
body = await response.text();
|
|
371
|
+
} catch (error) {
|
|
372
|
+
return response.ok ? { kind: "ambiguous", raw: error } : { kind: "http_error", raw: error, status: response.status };
|
|
373
|
+
}
|
|
374
|
+
let raw = body, parsed = !1;
|
|
375
|
+
try {
|
|
376
|
+
raw = JSON.parse(body);
|
|
377
|
+
parsed = !0;
|
|
378
|
+
} catch {}
|
|
379
|
+
if (!response.ok)
|
|
380
|
+
return { kind: "http_error", raw, status: response.status };
|
|
381
|
+
if (!parsed || !isRecord(raw) || !isTerminalConsumeKind(raw.code))
|
|
382
|
+
return { kind: "ambiguous", raw };
|
|
383
|
+
return { kind: raw.code, raw };
|
|
384
|
+
}
|
|
385
|
+
function throwForStateDecision(decision) {
|
|
386
|
+
if (decision.kind === "cooldown")
|
|
387
|
+
throw new ResetRedemptionError("cooldown_active", "reset credit redemption is cooling down", decision.cooldownUntil);
|
|
388
|
+
throw Error(`unexpected reset state decision: ${decision.kind}`);
|
|
389
|
+
}
|
|
390
|
+
function throwExpiredUnreconciled() {
|
|
391
|
+
throw new ResetRedemptionError("expired_unreconciled", "the previous reset attempt outcome is unknown");
|
|
392
|
+
}
|
|
393
|
+
function localAmbiguousResult(target, beforeState) {
|
|
394
|
+
return {
|
|
395
|
+
target,
|
|
396
|
+
selectedCredit: void 0,
|
|
397
|
+
beforeState,
|
|
398
|
+
outcome: {
|
|
399
|
+
kind: "ambiguous_local",
|
|
400
|
+
raw: { reason: "corrupt_in_flight" }
|
|
401
|
+
},
|
|
402
|
+
retrySafety: "No request was sent because the saved redemption identity was incomplete."
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function retrySafetyFor(outcome) {
|
|
406
|
+
if (outcome.kind === "reset" || outcome.kind === "already_redeemed")
|
|
407
|
+
return "The server returned a terminal result; cooldown blocks an immediate new redemption.";
|
|
408
|
+
if (outcome.kind === "nothing_to_reset" || outcome.kind === "no_credit")
|
|
409
|
+
return "The server returned a terminal no-op. No cooldown was set; a new attempt starts fresh and remains gated by fresh preconditions.";
|
|
410
|
+
if (isRefusedConsume(outcome))
|
|
411
|
+
return "The server refused the request. A retry within five minutes reuses the same request and credit identifiers; after that, a new attempt starts fresh and remains gated by fresh preconditions.";
|
|
412
|
+
return "The outcome is uncertain. A retry within five minutes reuses the same request and credit identifiers; this does not prove the server did nothing.";
|
|
413
|
+
}
|
|
414
|
+
function unrecordedRefusalSafety(stateWriteFailed, saved) {
|
|
415
|
+
if (stateWriteFailed)
|
|
416
|
+
return "The server refused the request, but recording the refusal failed, so the saved redemption may still be treated as unknown and block a new attempt. A retry reuses the same request and credit identifiers; this does not prove the server did nothing.";
|
|
417
|
+
if (saved)
|
|
418
|
+
return "The server refused the request, but another send of the same request had an unknown outcome, so the saved redemption still blocks a new attempt until a retry settles it. A retry reuses the same request and credit identifiers; this does not prove the server did nothing.";
|
|
419
|
+
return "The server refused the request, and another attempt has already settled or replaced the saved redemption. A new attempt is gated by the current saved state and fresh preconditions.";
|
|
420
|
+
}
|
|
421
|
+
export async function runResetCreditRedemption(deps, input) {
|
|
422
|
+
if (!isSafeResetAccountKey(input.accountKey))
|
|
423
|
+
throw new ResetRedemptionError("invalid_account_key", "the reset account key is reserved");
|
|
424
|
+
const target = await deps.resolveTarget(input.accountKey);
|
|
425
|
+
if (target.chatgptAccountId !== input.expectedChatgptAccountId)
|
|
426
|
+
throw new ResetRedemptionError("identity_mismatch", "the resolved ChatGPT account identity changed before redemption");
|
|
427
|
+
const identity = target.chatgptAccountId, wireAccountId = target.accountKey === "main" ? void 0 : identity;
|
|
428
|
+
let initial = await inspectResetAttempt(deps, input.accountKey);
|
|
429
|
+
if (initial.kind === "corrupt") {
|
|
430
|
+
initial = await resolveCorruptResetAttempt(deps, input.accountKey);
|
|
431
|
+
if (initial.kind === "corrupt")
|
|
432
|
+
return localAmbiguousResult(target, initial.beforeState);
|
|
433
|
+
}
|
|
434
|
+
if (initial.kind === "cooldown")
|
|
435
|
+
throwForStateDecision(initial);
|
|
436
|
+
let claim;
|
|
437
|
+
if (initial.kind === "claim")
|
|
438
|
+
claim = initial.claim;
|
|
439
|
+
else if (initial.kind === "expired_unreconciled" && (input.retry || !mayReplaceExpiredPair(initial.claim.inFlight, identity))) {
|
|
440
|
+
if (!input.retry)
|
|
441
|
+
throwExpiredUnreconciled();
|
|
442
|
+
claim = initial.claim;
|
|
443
|
+
} else {
|
|
444
|
+
if (input.retry)
|
|
445
|
+
throw new ResetRedemptionError("retry_without_inflight", "there is no active reset credit redemption to retry");
|
|
446
|
+
const [quota, credits] = await Promise.all([
|
|
447
|
+
deps.fetchUsage(target),
|
|
448
|
+
listResetCredits(deps.fetchImpl, target.accessToken, wireAccountId)
|
|
449
|
+
]), precondition = evaluateResetPrecondition(quota, deps.hasActiveRateLimitMark(input.accountKey), deps.now());
|
|
450
|
+
if (!precondition.ok)
|
|
451
|
+
throw new ResetRedemptionError("not_exhausted", precondition.reason);
|
|
452
|
+
if (!selectCreditToSpend(credits.credits))
|
|
453
|
+
throw new ResetRedemptionError("no_eligible_credit", "no eligible reset credit was returned");
|
|
454
|
+
const claimed = await claimResetAttempt(deps, input.accountKey, credits.credits, identity);
|
|
455
|
+
if (claimed.kind === "corrupt")
|
|
456
|
+
return localAmbiguousResult(target, claimed.beforeState);
|
|
457
|
+
if (claimed.kind === "cooldown")
|
|
458
|
+
throwForStateDecision(claimed);
|
|
459
|
+
if (claimed.kind === "expired_unreconciled")
|
|
460
|
+
throwExpiredUnreconciled();
|
|
461
|
+
if (claimed.kind !== "claim")
|
|
462
|
+
throw new ResetRedemptionError("no_eligible_credit", "no eligible reset credit was available while claiming");
|
|
463
|
+
claim = claimed.claim;
|
|
464
|
+
}
|
|
465
|
+
assertPairBelongsTo(claim.inFlight, identity);
|
|
466
|
+
const outcome = await consumeResetCredit(deps.fetchImpl, target.accessToken, wireAccountId, claim.inFlight.creditId, claim.inFlight.redeemRequestId);
|
|
467
|
+
let saved, stateWriteFailed = !1;
|
|
468
|
+
try {
|
|
469
|
+
saved = await finalizeResetAttempt(deps, input.accountKey, claim.inFlight, outcome, identity);
|
|
470
|
+
} catch {
|
|
471
|
+
stateWriteFailed = !0;
|
|
472
|
+
}
|
|
473
|
+
const finalizeStateWriteFailed = stateWriteFailed && isTerminalConsumeKind(outcome.kind), refused = isRefusedConsume(outcome) && !stateWriteFailed && saved?.rejectedStatus !== void 0;
|
|
474
|
+
return {
|
|
475
|
+
target,
|
|
476
|
+
selectedCredit: claim.selectedCredit,
|
|
477
|
+
beforeState: initial.beforeState,
|
|
478
|
+
outcome,
|
|
479
|
+
retrySafety: finalizeStateWriteFailed ? "The server returned a terminal result, but the state write failed. A retry within five minutes reuses the same request and credit identifiers." : isRefusedConsume(outcome) && !refused ? unrecordedRefusalSafety(stateWriteFailed, saved) : retrySafetyFor(outcome),
|
|
480
|
+
...refused ? { refused: !0 } : {},
|
|
481
|
+
...finalizeStateWriteFailed ? { finalizeStateWriteFailed: !0 } : {}
|
|
482
|
+
};
|
|
483
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function gptModelVersion(model) {
|
|
2
|
+
return model.match(/^gpt-(\d+(?:\.\d+)?)/)?.[1];
|
|
3
|
+
}
|
|
4
|
+
export const ALLOWED_MODELS = new Set([
|
|
5
|
+
"gpt-5.5",
|
|
6
|
+
"gpt-5.3-codex-spark",
|
|
7
|
+
"gpt-5.4",
|
|
8
|
+
"gpt-5.4-mini"
|
|
9
|
+
]), DISALLOWED_MODELS = new Set([
|
|
10
|
+
"gpt-5.6",
|
|
11
|
+
"gpt-6",
|
|
12
|
+
"gpt-6.1",
|
|
13
|
+
"gpt-6.2"
|
|
14
|
+
]);
|
|
15
|
+
export function codexOAuthModelListed(apiId) {
|
|
16
|
+
if (ALLOWED_MODELS.has(apiId))
|
|
17
|
+
return !0;
|
|
18
|
+
if (DISALLOWED_MODELS.has(apiId))
|
|
19
|
+
return !1;
|
|
20
|
+
const version = gptModelVersion(apiId);
|
|
21
|
+
return version ? parseFloat(version) > 5.4 : !1;
|
|
22
|
+
}
|
|
23
|
+
export function codexOAuthModelLimit(modelId) {
|
|
24
|
+
if (modelId.includes("gpt-5.5"))
|
|
25
|
+
return { context: 400000, input: 272000, output: 128000 };
|
|
26
|
+
if (modelId.includes("gpt-5.6") || modelId.includes("gpt-6-astra") || modelId.includes("gpt-6-sol") || modelId.includes("gpt-6-luna") || modelId.includes("gpt-6.2-astra"))
|
|
27
|
+
return { context: 872000, input: 744000, output: 128000 };
|
|
28
|
+
if (modelId.includes("gpt-6.1-sol") || modelId.includes("gpt-6.1-terra") || modelId.includes("gpt-6.2-sol"))
|
|
29
|
+
return { context: 500000, input: 372000, output: 128000 };
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
export function codexOAuthModelVariantSource(modelId) {
|
|
33
|
+
return modelId === "gpt-6.1-terra" ? "gpt-6.1-sol" : void 0;
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function uuidV7() {
|
|
2
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16)), ms = Date.now();
|
|
3
|
+
bytes[0] = ms / 1099511627776 & 255;
|
|
4
|
+
bytes[1] = ms / 4294967296 & 255;
|
|
5
|
+
bytes[2] = ms / 16777216 & 255;
|
|
6
|
+
bytes[3] = ms / 65536 & 255;
|
|
7
|
+
bytes[4] = ms / 256 & 255;
|
|
8
|
+
bytes[5] = ms & 255;
|
|
9
|
+
bytes[6] = (bytes[6] ?? 0) & 15 | 112;
|
|
10
|
+
bytes[8] = (bytes[8] ?? 0) & 63 | 128;
|
|
11
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
12
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The current process's terminal, with its signals. */
|
|
2
|
+
export function processTerminal() {
|
|
3
|
+
return {
|
|
4
|
+
input: process.stdin,
|
|
5
|
+
output: process.stdout,
|
|
6
|
+
signals: process,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether keys can be read one at a time. Only the input is checked, as the
|
|
11
|
+
* plugins' menus always did: output piped to a file still gets the menu.
|
|
12
|
+
*/
|
|
13
|
+
export function isInteractive(terminal) {
|
|
14
|
+
return terminal.input.isTTY === true;
|
|
15
|
+
}
|
|
16
|
+
/** Writes one line of plain output below the menu. */
|
|
17
|
+
export function printLine(terminal, line = '') {
|
|
18
|
+
terminal.output.write(`${line}\n`);
|
|
19
|
+
}
|