@cortexkit/opencode-openai-auth 1.23.1 → 1.23.3
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-9kges8jy.js} +2 -2
- package/dist/index-ekt6aq17.js +60 -0
- package/dist/index-nd2ks7er.js +2 -0
- package/dist/{index-p81hxfe6.js → index-vf4nn20q.js} +1 -1
- package/dist/{index-bd18sfjj.js → index-x00sxt2w.js} +10 -10
- package/dist/{index-3ya2s179.js → index-xkngfyvc.js} +1 -1
- 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,411 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CacheKeepManager,
|
|
3
|
+
normalizeCacheKeepWindow
|
|
4
|
+
} from "./7fb0418303f20a10-index.js";
|
|
5
|
+
import { orderCodexBody } from "./f981e6b15fb76cdb-codex-body.js";
|
|
6
|
+
import { sanitizeHttpFallbackInit } from "./1567207f323dc733-codex-http.js";
|
|
7
|
+
import { RESPONSES_LITE_HEADER } from "./cba8b0aee46b8526-codex-lite.js";
|
|
8
|
+
import {
|
|
9
|
+
inputTransformationsOf,
|
|
10
|
+
logInputTransformations
|
|
11
|
+
} from "./7c98bde36aad4819-input-transformations.js";
|
|
12
|
+
import { extractAccountIdFromClaims, parseJwtClaims } from "./4d05c2d7a531aece-oauth.js";
|
|
13
|
+
import { normalizeQuotaHeaders } from "./2577ec69f9973ae9-quota-normalize.js";
|
|
14
|
+
import {
|
|
15
|
+
is30MinCacheSupportedModel,
|
|
16
|
+
recordSessionCompletion,
|
|
17
|
+
ttlForModel
|
|
18
|
+
} from "./59def9e82b61204a-session-cache-activity.js";
|
|
19
|
+
import {
|
|
20
|
+
reportSessionCacheWarmed,
|
|
21
|
+
reportSessionCacheWarmStopped,
|
|
22
|
+
sessionCacheKeepPlan
|
|
23
|
+
} from "./49353b63a833c8fb-session-cache-policy.js";
|
|
24
|
+
import {
|
|
25
|
+
redactCredentialError,
|
|
26
|
+
redactCredentialResponse
|
|
27
|
+
} from "./0b7d24474e2f33e9-credential-redaction.js";
|
|
28
|
+
import { isRecord } from "./775431e21f469203-record.js";
|
|
29
|
+
export {
|
|
30
|
+
CacheKeepManager,
|
|
31
|
+
isWithinCacheKeepWindow
|
|
32
|
+
} from "./7fb0418303f20a10-index.js";
|
|
33
|
+
export const CACHE_KEEP_CAPS = Object.freeze({ maxTargets: 32, maxBytes: 8388608 });
|
|
34
|
+
export function getCacheKeepWindow(storage) {
|
|
35
|
+
return normalizeCacheKeepWindow(storage?.cachekeep);
|
|
36
|
+
}
|
|
37
|
+
const THIRTY_MIN_CACHE_TTL_MS = 1800000, THIRTY_MIN_CACHE_SUBAGENT_MAX_WARMS = 2, THIRTY_MIN_CACHE_SUBAGENT_MAX_IDLE_MS = 2 * THIRTY_MIN_CACHE_TTL_MS + 900000;
|
|
38
|
+
export function openaiCacheKeepProfile(input) {
|
|
39
|
+
if (!is30MinCacheSupportedModel(input.bodyText))
|
|
40
|
+
return;
|
|
41
|
+
if (!input.isSubagent)
|
|
42
|
+
return { ttlMs: THIRTY_MIN_CACHE_TTL_MS };
|
|
43
|
+
return {
|
|
44
|
+
ttlMs: THIRTY_MIN_CACHE_TTL_MS,
|
|
45
|
+
maxWarms: THIRTY_MIN_CACHE_SUBAGENT_MAX_WARMS,
|
|
46
|
+
maxIdleMs: THIRTY_MIN_CACHE_SUBAGENT_MAX_IDLE_MS
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function buildKeepwarmBody(bodyText) {
|
|
50
|
+
const clone = JSON.parse(bodyText);
|
|
51
|
+
clone.store = !1;
|
|
52
|
+
delete clone.max_output_tokens;
|
|
53
|
+
delete clone.max_tokens;
|
|
54
|
+
delete clone.max_completion_tokens;
|
|
55
|
+
return JSON.stringify(orderCodexBody(clone));
|
|
56
|
+
}
|
|
57
|
+
const KEEPWARM_REPLAY_HEADERS = new Set([
|
|
58
|
+
"originator",
|
|
59
|
+
"session-id",
|
|
60
|
+
"thread-id",
|
|
61
|
+
"user-agent",
|
|
62
|
+
"version",
|
|
63
|
+
"x-client-request-id",
|
|
64
|
+
"x-codex-beta-features",
|
|
65
|
+
"x-codex-turn-metadata",
|
|
66
|
+
"x-codex-window-id",
|
|
67
|
+
"x-opencode-parent-session-id",
|
|
68
|
+
"x-parent-session-id",
|
|
69
|
+
"x-session-affinity",
|
|
70
|
+
RESPONSES_LITE_HEADER
|
|
71
|
+
]);
|
|
72
|
+
export function keepwarmReplayHeaders(headers) {
|
|
73
|
+
return Object.fromEntries([...headers].filter(([name]) => KEEPWARM_REPLAY_HEADERS.has(name)));
|
|
74
|
+
}
|
|
75
|
+
export function buildKeepwarmRequest(input) {
|
|
76
|
+
const headers = new Headers;
|
|
77
|
+
for (const [name, value] of Object.entries(input.replayHeaders))
|
|
78
|
+
if (KEEPWARM_REPLAY_HEADERS.has(name.toLowerCase()))
|
|
79
|
+
headers.set(name, value);
|
|
80
|
+
headers.set("authorization", `Bearer ${input.credential.token}`);
|
|
81
|
+
if (input.credential.identity)
|
|
82
|
+
headers.set("chatgpt-account-id", input.credential.identity);
|
|
83
|
+
const request = {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers,
|
|
86
|
+
body: input.body,
|
|
87
|
+
signal: input.signal
|
|
88
|
+
};
|
|
89
|
+
return sanitizeHttpFallbackInit(request) ?? request;
|
|
90
|
+
}
|
|
91
|
+
function emptyKeepwarmUsage() {
|
|
92
|
+
return {
|
|
93
|
+
input_tokens: 0,
|
|
94
|
+
output_tokens: 0,
|
|
95
|
+
cached_tokens: 0,
|
|
96
|
+
hit_rate: null
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function extractUsageObject(usage) {
|
|
100
|
+
if (!usage || typeof usage !== "object")
|
|
101
|
+
return emptyKeepwarmUsage();
|
|
102
|
+
const usageRecord = usage, input_tokens = Number(usageRecord.input_tokens) || Number(usageRecord.prompt_tokens) || 0, output_tokens = Number(usageRecord.output_tokens) || Number(usageRecord.completion_tokens) || 0, details = usageRecord.input_tokens_details ?? usageRecord.prompt_tokens_details, cached_tokens = Number(details?.cached_tokens) || Number(usageRecord.cached_tokens) || 0, hit_rate = input_tokens > 0 ? cached_tokens / input_tokens : null;
|
|
103
|
+
return { input_tokens, output_tokens, cached_tokens, hit_rate };
|
|
104
|
+
}
|
|
105
|
+
function createKeepwarmSseReader() {
|
|
106
|
+
let partialLine = "", eventName, dataLines = [], usage, transformedResponse;
|
|
107
|
+
const flushEvent = () => {
|
|
108
|
+
if (!dataLines.length)
|
|
109
|
+
return;
|
|
110
|
+
const data = dataLines.join(`
|
|
111
|
+
`).trim();
|
|
112
|
+
dataLines = [];
|
|
113
|
+
const currentEvent = eventName;
|
|
114
|
+
eventName = void 0;
|
|
115
|
+
if (!data || data === "[DONE]")
|
|
116
|
+
return;
|
|
117
|
+
try {
|
|
118
|
+
const event = JSON.parse(data), type = event.type ?? currentEvent;
|
|
119
|
+
if (type !== "response.completed" && type !== "response.done")
|
|
120
|
+
return;
|
|
121
|
+
const response = event.response;
|
|
122
|
+
if (type === "response.completed" && inputTransformationsOf(response))
|
|
123
|
+
transformedResponse ??= response;
|
|
124
|
+
usage = extractUsageObject(response?.usage ?? event.usage);
|
|
125
|
+
} catch {}
|
|
126
|
+
}, readLine = (line) => {
|
|
127
|
+
if (line === "")
|
|
128
|
+
flushEvent();
|
|
129
|
+
else if (line.startsWith("event:"))
|
|
130
|
+
eventName = line.slice(6).trim();
|
|
131
|
+
else if (line.startsWith("data:"))
|
|
132
|
+
dataLines.push(line.slice(5).trim());
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
push(chunk) {
|
|
136
|
+
const lines = (partialLine + chunk).split(/\r?\n/);
|
|
137
|
+
partialLine = lines.pop() ?? "";
|
|
138
|
+
for (const line of lines)
|
|
139
|
+
readLine(line);
|
|
140
|
+
},
|
|
141
|
+
finish() {
|
|
142
|
+
readLine(partialLine);
|
|
143
|
+
flushEvent();
|
|
144
|
+
return {
|
|
145
|
+
isSse: !0,
|
|
146
|
+
usage: usage ?? emptyKeepwarmUsage(),
|
|
147
|
+
...transformedResponse && { transformedResponse }
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function createKeepwarmReplyReader(contentType) {
|
|
153
|
+
let sse = contentType.includes("text/event-stream") ? createKeepwarmSseReader() : void 0, text = "";
|
|
154
|
+
return {
|
|
155
|
+
push(chunk) {
|
|
156
|
+
if (sse)
|
|
157
|
+
sse.push(chunk);
|
|
158
|
+
else {
|
|
159
|
+
text += chunk;
|
|
160
|
+
if (/(^|\n)(data:|event:)/.test(text.slice(0, 200))) {
|
|
161
|
+
sse = createKeepwarmSseReader();
|
|
162
|
+
sse.push(text);
|
|
163
|
+
text = "";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
finish() {
|
|
168
|
+
if (sse)
|
|
169
|
+
return sse.finish();
|
|
170
|
+
try {
|
|
171
|
+
const parsed = JSON.parse(text);
|
|
172
|
+
return {
|
|
173
|
+
isSse: !1,
|
|
174
|
+
usage: extractUsageObject(parsed.usage),
|
|
175
|
+
...inputTransformationsOf(parsed) && {
|
|
176
|
+
transformedResponse: parsed
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
} catch {
|
|
180
|
+
return { isSse: !1, usage: emptyKeepwarmUsage() };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export function resolveCacheKeepAccountIdentity(token, knownIdentity) {
|
|
186
|
+
if (knownIdentity !== void 0)
|
|
187
|
+
return knownIdentity;
|
|
188
|
+
const claims = parseJwtClaims(token);
|
|
189
|
+
return claims ? extractAccountIdFromClaims(claims) : void 0;
|
|
190
|
+
}
|
|
191
|
+
export function createOpenAICacheKeepAdapter(options, dropTarget) {
|
|
192
|
+
const { logger: log, activeAccount } = options, observedReplies = new WeakMap;
|
|
193
|
+
return {
|
|
194
|
+
plan: sessionCacheKeepPlan,
|
|
195
|
+
onWarmed: reportSessionCacheWarmed,
|
|
196
|
+
onWarmStopped: reportSessionCacheWarmStopped,
|
|
197
|
+
buildBody: (target) => buildKeepwarmBody(target.bodyText),
|
|
198
|
+
async send({ target, body, signal }) {
|
|
199
|
+
let physicalAttempt = 0;
|
|
200
|
+
const dispatch = async (accessToken, vaultAttempt, localIdentity) => {
|
|
201
|
+
signal.throwIfAborted();
|
|
202
|
+
const check = {
|
|
203
|
+
target,
|
|
204
|
+
mode: vaultAttempt ? "vault" : "local",
|
|
205
|
+
identity: options.credentialIdentity ? options.credentialIdentity(accessToken) : resolveCacheKeepAccountIdentity(accessToken, vaultAttempt ? vaultAttempt.accountIdentity : localIdentity)
|
|
206
|
+
};
|
|
207
|
+
await options.verifyCredential?.(check);
|
|
208
|
+
const capturedIdentity = target.meta.chatgptAccountId ?? target.meta.effectiveAccountId;
|
|
209
|
+
if (check.identity !== capturedIdentity) {
|
|
210
|
+
dropTarget?.(target.sessionKey, "the account signs in as another login now");
|
|
211
|
+
throw Error("the account signs in as another login now");
|
|
212
|
+
}
|
|
213
|
+
const accountKey = await options.activity?.accountKey(check);
|
|
214
|
+
signal.throwIfAborted();
|
|
215
|
+
const dispatched = accountKey ? {
|
|
216
|
+
sessionId: target.meta.routingSessionId ?? target.sessionKey,
|
|
217
|
+
accountKey,
|
|
218
|
+
dispatchedAt: (options.now ?? Date.now)(),
|
|
219
|
+
ttlMs: ttlForModel(target.bodyText, target.ttlMs)
|
|
220
|
+
} : void 0;
|
|
221
|
+
let warmBodyShape;
|
|
222
|
+
const billing = vaultAttempt && options.observeBillingSend ? options.observeBillingSend(target, body, vaultAttempt, ++physicalAttempt) : void 0;
|
|
223
|
+
try {
|
|
224
|
+
const parsed = JSON.parse(body);
|
|
225
|
+
warmBodyShape = {
|
|
226
|
+
warmBodyKeys: Object.keys(parsed),
|
|
227
|
+
stream: parsed.stream,
|
|
228
|
+
max_output_tokens: parsed.max_output_tokens,
|
|
229
|
+
store: parsed.store,
|
|
230
|
+
has_stream_options: "stream_options" in parsed,
|
|
231
|
+
has_max_tokens: "max_tokens" in parsed,
|
|
232
|
+
model: parsed.model
|
|
233
|
+
};
|
|
234
|
+
} catch {}
|
|
235
|
+
try {
|
|
236
|
+
const headerIdentity = target.meta.chatgptAccountId === void 0 ? void 0 : check.identity, request = buildKeepwarmRequest({
|
|
237
|
+
body,
|
|
238
|
+
replayHeaders: target.meta.replayHeaders,
|
|
239
|
+
credential: { token: accessToken, identity: headerIdentity },
|
|
240
|
+
signal
|
|
241
|
+
});
|
|
242
|
+
log?.debug("cachekeep warm request", {
|
|
243
|
+
...warmBodyShape,
|
|
244
|
+
headerKeys: [...new Headers(request.headers).keys()],
|
|
245
|
+
hasChatGptAccountId: headerIdentity !== void 0
|
|
246
|
+
});
|
|
247
|
+
const received = await options.fetchImpl(target.meta.url ?? options.codexResponsesUrl, request), response = billing ? billing.response(received) : received;
|
|
248
|
+
if (vaultAttempt && target.accountId)
|
|
249
|
+
options.vault?.reportUsage(target.accountId, { headers: response.headers }, vaultAttempt);
|
|
250
|
+
const redacted = await redactCredentialResponse(response, accessToken, "event-stream");
|
|
251
|
+
if (!redacted.ok || !dispatched || !options.activity)
|
|
252
|
+
return redacted;
|
|
253
|
+
const activity = options.activity, accept = async () => {
|
|
254
|
+
const active = await activeAccount?.(target.meta.routingSessionId);
|
|
255
|
+
if (activeAccount && active !== target.accountId)
|
|
256
|
+
return;
|
|
257
|
+
const current = await activity.accountKey(check);
|
|
258
|
+
recordSessionCompletion(activity.store, dispatched, current, {
|
|
259
|
+
kind: "keep-warm",
|
|
260
|
+
status: redacted.status,
|
|
261
|
+
aborted: signal.aborted
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
if (!redacted.body) {
|
|
265
|
+
await accept();
|
|
266
|
+
return redacted;
|
|
267
|
+
}
|
|
268
|
+
const reader = redacted.body.getReader(), decoder = new TextDecoder, reply = createKeepwarmReplyReader(redacted.headers.get("content-type") ?? ""), observed = new Response(new ReadableStream({
|
|
269
|
+
async pull(controller) {
|
|
270
|
+
try {
|
|
271
|
+
const chunk = await reader.read();
|
|
272
|
+
if (chunk.done) {
|
|
273
|
+
reply.push(decoder.decode());
|
|
274
|
+
const result = reply.finish();
|
|
275
|
+
observedReplies.set(observed, result);
|
|
276
|
+
if (!result.transformedResponse)
|
|
277
|
+
await accept();
|
|
278
|
+
controller.close();
|
|
279
|
+
} else {
|
|
280
|
+
reply.push(decoder.decode(chunk.value, { stream: !0 }));
|
|
281
|
+
controller.enqueue(chunk.value);
|
|
282
|
+
}
|
|
283
|
+
} catch (error) {
|
|
284
|
+
controller.error(error);
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
cancel(reason) {
|
|
288
|
+
return reader.cancel(reason);
|
|
289
|
+
}
|
|
290
|
+
}), {
|
|
291
|
+
status: redacted.status,
|
|
292
|
+
statusText: redacted.statusText,
|
|
293
|
+
headers: redacted.headers
|
|
294
|
+
});
|
|
295
|
+
return observed;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
billing?.failed();
|
|
298
|
+
throw redactCredentialError(error, accessToken);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
if (target.accountId && options.vault?.owns(target.accountId)) {
|
|
302
|
+
const response = await options.vault.send(target.accountId, dispatch, {
|
|
303
|
+
site: "cachekeep",
|
|
304
|
+
signal
|
|
305
|
+
});
|
|
306
|
+
if (!response)
|
|
307
|
+
throw Error(`vault refused warm for ${target.accountId}`);
|
|
308
|
+
return response;
|
|
309
|
+
}
|
|
310
|
+
if (options.vault && await options.vault.authority() !== "local")
|
|
311
|
+
throw Error("local accounts are not warmed while this host is connected to the vault");
|
|
312
|
+
let accessToken, identity, onAuthFailure;
|
|
313
|
+
const resolved = options.resolveLocal ? await options.resolveLocal(target) : target.accountId && target.accountId !== "main" ? await options.refreshFallback(target.accountId) : await options.getMainToken();
|
|
314
|
+
if (typeof resolved === "string")
|
|
315
|
+
accessToken = resolved;
|
|
316
|
+
else {
|
|
317
|
+
accessToken = resolved.token;
|
|
318
|
+
identity = resolved.identity;
|
|
319
|
+
onAuthFailure = resolved.onAuthFailure;
|
|
320
|
+
}
|
|
321
|
+
if (options.vault && await options.vault.authority() !== "local")
|
|
322
|
+
throw Error("local accounts are not warmed while this host is connected to the vault");
|
|
323
|
+
const response = await dispatch(accessToken, void 0, identity);
|
|
324
|
+
if (response.status === 401)
|
|
325
|
+
await onAuthFailure?.(response.status);
|
|
326
|
+
return response;
|
|
327
|
+
},
|
|
328
|
+
readUsage({ response, text, target }) {
|
|
329
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
330
|
+
let reply = observedReplies.get(response);
|
|
331
|
+
if (!reply) {
|
|
332
|
+
const reader = createKeepwarmReplyReader(contentType);
|
|
333
|
+
reader.push(text);
|
|
334
|
+
reply = reader.finish();
|
|
335
|
+
}
|
|
336
|
+
if (reply.transformedResponse) {
|
|
337
|
+
dropTarget?.(target.sessionKey, "provider transformed input");
|
|
338
|
+
let chained;
|
|
339
|
+
try {
|
|
340
|
+
const request = JSON.parse(target.bodyText);
|
|
341
|
+
if (isRecord(request))
|
|
342
|
+
chained = "previous_response_id" in request;
|
|
343
|
+
} catch {}
|
|
344
|
+
logInputTransformations(reply.transformedResponse, "http", options.host ?? "opencode1", {
|
|
345
|
+
warm: !0,
|
|
346
|
+
chained
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
log?.debug("cachekeep warm response", {
|
|
350
|
+
status: response.status,
|
|
351
|
+
contentType,
|
|
352
|
+
bodyLen: text.length,
|
|
353
|
+
isSse: reply.isSse
|
|
354
|
+
});
|
|
355
|
+
const quota = normalizeQuotaHeaders(response.headers);
|
|
356
|
+
return {
|
|
357
|
+
...reply.usage,
|
|
358
|
+
quota_primary_pct: quota.primary?.usedPercent ?? null,
|
|
359
|
+
quota_secondary_pct: quota.secondary?.usedPercent ?? null
|
|
360
|
+
};
|
|
361
|
+
},
|
|
362
|
+
profile: openaiCacheKeepProfile,
|
|
363
|
+
...activeAccount ? {
|
|
364
|
+
activeAccount: (_sessionKey, target) => activeAccount(target.meta.routingSessionId)
|
|
365
|
+
} : {}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
export function createCacheKeepManager(options) {
|
|
369
|
+
const {
|
|
370
|
+
fetchImpl,
|
|
371
|
+
host = "opencode1",
|
|
372
|
+
observeBillingSend,
|
|
373
|
+
credentialIdentity,
|
|
374
|
+
getMainToken: _getMainToken,
|
|
375
|
+
refreshFallback: _refreshFallback,
|
|
376
|
+
resolveLocal: _resolveLocal,
|
|
377
|
+
vault,
|
|
378
|
+
codexResponsesUrl,
|
|
379
|
+
activeAccount,
|
|
380
|
+
verifyCredential,
|
|
381
|
+
activity,
|
|
382
|
+
logger,
|
|
383
|
+
...managerOptions
|
|
384
|
+
} = options, local = options.resolveLocal !== void 0 ? { resolveLocal: options.resolveLocal } : {
|
|
385
|
+
getMainToken: options.getMainToken,
|
|
386
|
+
refreshFallback: options.refreshFallback
|
|
387
|
+
}, manager = new CacheKeepManager({
|
|
388
|
+
...managerOptions,
|
|
389
|
+
logger,
|
|
390
|
+
adapter: createOpenAICacheKeepAdapter({
|
|
391
|
+
fetchImpl,
|
|
392
|
+
host,
|
|
393
|
+
observeBillingSend,
|
|
394
|
+
credentialIdentity,
|
|
395
|
+
...local,
|
|
396
|
+
vault,
|
|
397
|
+
codexResponsesUrl,
|
|
398
|
+
activeAccount,
|
|
399
|
+
verifyCredential,
|
|
400
|
+
activity,
|
|
401
|
+
now: options.now,
|
|
402
|
+
logger
|
|
403
|
+
}, (sessionKey, diagnostic) => {
|
|
404
|
+
manager.remove(sessionKey);
|
|
405
|
+
logger?.debug(`cachekeep dropped target (${diagnostic})`, {
|
|
406
|
+
sessionKey
|
|
407
|
+
});
|
|
408
|
+
})
|
|
409
|
+
});
|
|
410
|
+
return manager;
|
|
411
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { createSessionActivityStore, effectiveCacheTtlMs, } from "./c954c6447b7b9b64-activity.js";
|
|
2
|
+
export { marksAfterSuccess } from "./4adf46e07e025363-axes.js";
|
|
3
|
+
export { toOpenCode2LimitSignal } from "./7056acef1b021f19-bridge.js";
|
|
4
|
+
export { decideAfterLimit } from "./8aba66ed486d30a7-decide.js";
|
|
5
|
+
export { formatDuration, formatReset } from "./bd4aef685681048c-duration.js";
|
|
6
|
+
export { LimitsEnvelopeConflictError, LimitsEnvelopeUnsupportedError, } from "./8ca6175bfae53e13-envelope.js";
|
|
7
|
+
export { buildRefusal, ClaudeIncompleteError, retryAfterSeconds, } from "./18df43cab4563acf-families.js";
|
|
8
|
+
export { classifyHeaders, classifyRetryAfter, resolveHeaderReset, resolveRetryAfter, } from "./8d0245e41049d83f-header-classifier.js";
|
|
9
|
+
export { MAX_SAME_ACCOUNT_HOLD_MS, readMaxSameAccountWait, sameAccountHoldFacts, } from "./c66495424ad84aee-hold.js";
|
|
10
|
+
export { isIdentityCompatible, retainVerifiedIdentity, validateIdentityFence, } from "./f317a4740f9d76f8-identity.js";
|
|
11
|
+
export { holdDelayMs } from "./d7fa77560855dee2-jitter.js";
|
|
12
|
+
export { sanitizeRefusalLabel } from "./cec39ccddab4fe9c-labels.js";
|
|
13
|
+
export { ANTIGRAVITY_FAILURE_LADDER, markFromSignal, markIsActive, reduceFailureHistory, } from "./72d2ca42883809b4-marker.js";
|
|
14
|
+
export { mergeAccessState, mergeTimedMarkEntries } from "./f1012265b3a768c7-merge-laws.js";
|
|
15
|
+
export { applyLimitsCommands, createLimitsNamespace, LIMITS_HISTORY_BOUND, pruneLimitsNamespace, timedMarkKeyId, } from "./0c9533222cb4380c-namespace.js";
|
|
16
|
+
export { canonicalLimitsPath } from "./de7f7d8803624369-path.js";
|
|
17
|
+
export { LimitsPersistenceRefusal } from "./adc5eeb5a8d28280-persistence.js";
|
|
18
|
+
export { waitForPi } from "./806e12ccbad34388-pi-wait.js";
|
|
19
|
+
export { createPoolLimitsAdapter, } from "./43de3a5c4845cfc1-pool-adapter.js";
|
|
20
|
+
export { confirmedAffinity, earliestPoolEngine, limitPresets, statusVaultOrder, windowRouter, } from "./3dfe71eec6e0487d-presets.js";
|
|
21
|
+
export { acquireLimitsRegistry, clearLimitsAfterProbe, LIMITS_REGISTRY_KEY, } from "./2bb681e99c2721d7-registry.js";
|
|
22
|
+
export { commitRequestExclusion, createRequestHistory, isRequestExcluded, REQUEST_EXCLUSION_EFFECTS, reduceRequestHistory, sameAccount, } from "./f6d728f5e601f98b-request-history.js";
|
|
23
|
+
export { resolveNamedWindowReset, resolveReset } from "./b3c11de5f36e617a-reset.js";
|
|
24
|
+
export { holdWaitMaxS } from "./e26c2bb5722ab047-routing-hold.js";
|
|
25
|
+
export { scopeCovers } from "./8349ed25dc629e97-scope.js";
|
|
26
|
+
export { scanTerminalReset } from "./2ec33b3e2b8ac38a-terminal.js";
|
|
27
|
+
export { UnconfirmedRetainCounter } from "./26b57ac4c3b0c3f6-unconfirmed-retain-counter.js";
|
|
28
|
+
export { hasUnsafeWording, registerLimitMessages, UnsafeWordingError, } from "./3b31b36bf0877602-wording.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RESPONSES_LITE_HEADER } from "./cba8b0aee46b8526-codex-lite.js";
|
|
2
|
+
import { isRecord } from "./775431e21f469203-record.js";
|
|
3
|
+
export function hasWebSocketResponsesLiteMetadata(body) {
|
|
4
|
+
if (typeof body !== "string")
|
|
5
|
+
return !1;
|
|
6
|
+
try {
|
|
7
|
+
const parsed = JSON.parse(body);
|
|
8
|
+
return isRecord(parsed) && isRecord(parsed.client_metadata) && parsed.client_metadata.ws_request_header_x_openai_internal_codex_responses_lite === "true";
|
|
9
|
+
} catch {
|
|
10
|
+
return !1;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function sanitizeHttpFallbackBody(body) {
|
|
14
|
+
if (typeof body !== "string")
|
|
15
|
+
return body;
|
|
16
|
+
try {
|
|
17
|
+
const parsed = JSON.parse(body);
|
|
18
|
+
if (!isRecord(parsed) || !isRecord(parsed.client_metadata))
|
|
19
|
+
return body;
|
|
20
|
+
if (!(("x-codex-turn-metadata" in parsed.client_metadata) || ("x-codex-ws-stream-request-start-ms" in parsed.client_metadata) || ("ws_request_header_x_openai_internal_codex_responses_lite" in parsed.client_metadata)))
|
|
21
|
+
return body;
|
|
22
|
+
const clientMetadata = { ...parsed.client_metadata };
|
|
23
|
+
delete clientMetadata["x-codex-turn-metadata"];
|
|
24
|
+
delete clientMetadata["x-codex-ws-stream-request-start-ms"];
|
|
25
|
+
delete clientMetadata.ws_request_header_x_openai_internal_codex_responses_lite;
|
|
26
|
+
return JSON.stringify({ ...parsed, client_metadata: clientMetadata });
|
|
27
|
+
} catch {
|
|
28
|
+
return body;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function sanitizeHttpFallbackInit(init) {
|
|
32
|
+
if (init?.method?.toUpperCase() !== "POST")
|
|
33
|
+
return init;
|
|
34
|
+
const headers = new Headers(init.headers);
|
|
35
|
+
headers.set("accept", "text/event-stream");
|
|
36
|
+
headers.set("content-type", "application/json");
|
|
37
|
+
if (hasWebSocketResponsesLiteMetadata(init.body))
|
|
38
|
+
headers.set(RESPONSES_LITE_HEADER, "true");
|
|
39
|
+
return {
|
|
40
|
+
...init,
|
|
41
|
+
headers,
|
|
42
|
+
body: sanitizeHttpFallbackBody(init.body)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { AsyncResource } from "node:async_hooks";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { mergeAccessState } from "./f1012265b3a768c7-merge-laws.js";
|
|
5
|
+
import { clearTombstoneId, createLimitsNamespace, pruneLimitsNamespace, timedMarkKeyId, tombstoneCoversCause, } from "./0c9533222cb4380c-namespace.js";
|
|
6
|
+
const detached = new AsyncResource('common-auth-limits-recovery');
|
|
7
|
+
/** Readers never join the write lock; notify them after a detached repair lands. */
|
|
8
|
+
export class EnvelopeRepair {
|
|
9
|
+
logger;
|
|
10
|
+
running;
|
|
11
|
+
listeners = new Set();
|
|
12
|
+
constructor(logger) {
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
}
|
|
15
|
+
subscribe = (listener) => {
|
|
16
|
+
this.listeners.add(listener);
|
|
17
|
+
return () => this.listeners.delete(listener);
|
|
18
|
+
};
|
|
19
|
+
schedule(commit) {
|
|
20
|
+
if (this.running)
|
|
21
|
+
return;
|
|
22
|
+
this.running = detached.runInAsyncScope(async () => {
|
|
23
|
+
// Defer invocation until the single-flight promise is installed, and keep
|
|
24
|
+
// the write outside any caller context that holds the store lock.
|
|
25
|
+
await Promise.resolve();
|
|
26
|
+
let succeeded = false;
|
|
27
|
+
try {
|
|
28
|
+
await commit();
|
|
29
|
+
succeeded = true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
try {
|
|
33
|
+
this.logger?.warn('limits envelope recovery failed; agreement remains degraded', {
|
|
34
|
+
error: error instanceof Error ? error.message : String(error),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// A failed diagnostic must not turn detached bookkeeping into a rejection.
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
this.running = undefined;
|
|
43
|
+
if (succeeded) {
|
|
44
|
+
for (const listener of this.listeners) {
|
|
45
|
+
try {
|
|
46
|
+
listener();
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Observers cannot change the result of a durable repair.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Retain only durable observations; a new, empty namespace is not lost state. */
|
|
58
|
+
export class EnvelopeHistory {
|
|
59
|
+
seen;
|
|
60
|
+
missingGeneration;
|
|
61
|
+
incorporated;
|
|
62
|
+
remember(snapshot, previous) {
|
|
63
|
+
if (this.seen && this.seen.revision > snapshot.revision)
|
|
64
|
+
return;
|
|
65
|
+
this.seen = structuredClone(snapshot);
|
|
66
|
+
this.missingGeneration = undefined;
|
|
67
|
+
if (previous)
|
|
68
|
+
this.incorporated = structuredClone(previous);
|
|
69
|
+
}
|
|
70
|
+
retained(previous) {
|
|
71
|
+
// A notification reload still carries the pre-repair registry snapshot.
|
|
72
|
+
// Do not mistake that already-merged generation for another loss.
|
|
73
|
+
const retainedPrevious = isDeepStrictEqual(previous, this.incorporated)
|
|
74
|
+
? undefined
|
|
75
|
+
: previous;
|
|
76
|
+
return [this.seen, retainedPrevious].filter((snapshot) => snapshot !== undefined &&
|
|
77
|
+
(snapshot === this.seen || snapshot.revision > 0));
|
|
78
|
+
}
|
|
79
|
+
lost(present, previous) {
|
|
80
|
+
return this.retained(previous).some((seen) => !present ||
|
|
81
|
+
seen.generation !== present.generation ||
|
|
82
|
+
present.revision < seen.revision ||
|
|
83
|
+
seen.tombstones.some((clear) => clear.revision > present.lowWatermark &&
|
|
84
|
+
!present.tombstones.some((current) => timedMarkKeyId(current.key) === timedMarkKeyId(clear.key) &&
|
|
85
|
+
tombstoneCoversCause(current, clear.cause) &&
|
|
86
|
+
current.revision >= clear.revision)));
|
|
87
|
+
}
|
|
88
|
+
/** Preview a restrictive merge, or apply it against the envelope under the write lock. */
|
|
89
|
+
recover(present, previous, namespace, now) {
|
|
90
|
+
if (!present)
|
|
91
|
+
this.missingGeneration ??= randomUUID();
|
|
92
|
+
const current = present ??
|
|
93
|
+
createLimitsNamespace(namespace, this.missingGeneration ?? randomUUID());
|
|
94
|
+
const sources = [...this.retained(previous), current];
|
|
95
|
+
const marks = new Map();
|
|
96
|
+
const tombstones = new Map();
|
|
97
|
+
const operations = new Map();
|
|
98
|
+
const access = new Map();
|
|
99
|
+
let highest = 0;
|
|
100
|
+
for (const source of sources) {
|
|
101
|
+
highest = Math.max(highest, source.revision, source.lowWatermark);
|
|
102
|
+
for (const mark of source.marks) {
|
|
103
|
+
const id = timedMarkKeyId(mark.key);
|
|
104
|
+
const old = marks.get(id);
|
|
105
|
+
if (old && old.mergeLaw !== mark.mergeLaw)
|
|
106
|
+
throw new Error('limits-recovery-merge-law-conflict');
|
|
107
|
+
marks.set(id, {
|
|
108
|
+
...mark,
|
|
109
|
+
entries: [...(old?.entries ?? []), ...mark.entries],
|
|
110
|
+
});
|
|
111
|
+
for (const entry of mark.entries)
|
|
112
|
+
highest = Math.max(highest, entry.baseRevision, entry.committedRevision);
|
|
113
|
+
}
|
|
114
|
+
for (const clear of source.tombstones) {
|
|
115
|
+
const id = clearTombstoneId(clear);
|
|
116
|
+
const old = tombstones.get(id);
|
|
117
|
+
if (!old || old.revision < clear.revision)
|
|
118
|
+
tombstones.set(id, clear);
|
|
119
|
+
highest = Math.max(highest, clear.revision);
|
|
120
|
+
}
|
|
121
|
+
for (const op of source.operationIds) {
|
|
122
|
+
const id = JSON.stringify([op.producerId, op.operationId]);
|
|
123
|
+
const old = operations.get(id);
|
|
124
|
+
if (!old || old.revision < op.revision)
|
|
125
|
+
operations.set(id, op);
|
|
126
|
+
highest = Math.max(highest, op.revision);
|
|
127
|
+
}
|
|
128
|
+
for (const state of source.access) {
|
|
129
|
+
const { namespace, accountId, incarnation } = state.account;
|
|
130
|
+
const id = JSON.stringify([namespace, accountId, incarnation]);
|
|
131
|
+
const old = access.get(id);
|
|
132
|
+
access.set(id, old ? mergeAccessState(old, state) : state);
|
|
133
|
+
highest = Math.max(highest, state.committedRevision);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const revision = highest + 1;
|
|
137
|
+
if (!Number.isSafeInteger(revision))
|
|
138
|
+
throw new Error('limits-revision-exhausted');
|
|
139
|
+
// The barrier rejects observations predating even a clear this process never
|
|
140
|
+
// saw. Retain entry base revisions so a later restored clear can remove them.
|
|
141
|
+
return pruneLimitsNamespace({
|
|
142
|
+
...current,
|
|
143
|
+
revision,
|
|
144
|
+
lowWatermark: revision,
|
|
145
|
+
marks: [...marks.values()],
|
|
146
|
+
tombstones: [...tombstones.values()],
|
|
147
|
+
operationIds: [...operations.values()],
|
|
148
|
+
access: [...access.values()],
|
|
149
|
+
}, now);
|
|
150
|
+
}
|
|
151
|
+
}
|