@cortexkit/opencode-openai-auth 1.23.0 → 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 +8 -8
- package/dist/{index-897br01q.js → index-49ncs7dr.js} +1 -1
- package/dist/{index-s7dwe5n8.js → index-by5wfvqm.js} +20 -20
- package/dist/{index-bbrpg1ms.js → index-drm4dk5y.js} +1 -1
- package/dist/index-nd2ks7er.js +2 -0
- package/dist/index-t876xhkr.js +60 -0
- package/dist/{index-fasy4end.js → index-td4g5dc9.js} +1 -1
- package/dist/{index-7hcv94as.js → index-v8w8j1wx.js} +1 -1
- package/dist/{index-r31f36mn.js → index-v8wrmhyp.js} +1 -1
- package/dist/{index-bpx4spyr.js → index-wjp3q15r.js} +1 -1
- package/dist/{index-f340dq90.js → index-x00sxt2w.js} +10 -10
- package/dist/index.d.ts +4 -3
- 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/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.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-preferences.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 +6 -6
- 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-2z4dbnsf.js +0 -60
- package/dist/index-x25m9spd.js +0 -2
- package/dist/map-D5PHhv4z.d.ts +0 -72
- /package/dist/{index-sx9jjkry.js → index-4ktepxn1.js} +0 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
acquireLimitsRegistry,
|
|
4
|
+
createPoolLimitsAdapter,
|
|
5
|
+
isIdentityCompatible,
|
|
6
|
+
LimitsEnvelopeConflictError,
|
|
7
|
+
LimitsEnvelopeUnsupportedError,
|
|
8
|
+
LimitsPersistenceRefusal
|
|
9
|
+
} from "./1547bd74f4214d2d-index.js";
|
|
10
|
+
import { createVaultLimitsAdapter } from "./63c1ee7e70e85e8d-vault.js";
|
|
11
|
+
import {
|
|
12
|
+
limitAccountId,
|
|
13
|
+
limitsBindingProjection,
|
|
14
|
+
poolLimitsNamespace,
|
|
15
|
+
vaultLimitsNamespace
|
|
16
|
+
} from "./595bdf3fff13ba79-limit-identity.js";
|
|
17
|
+
import { LimitProvenanceStore } from "./86da3379973780b9-limit-provenance.js";
|
|
18
|
+
import {
|
|
19
|
+
LimitRecoveryLatch
|
|
20
|
+
} from "./bfc46d34f4c9db33-limit-recovery.js";
|
|
21
|
+
const ACQUIRE_MS = 5000, RETRY_MS = 1000, FAILURE_RUN_MS = 60000, defaultClock = {
|
|
22
|
+
now: () => Date.now(),
|
|
23
|
+
setTimeout: (callback, delay) => setTimeout(callback, delay),
|
|
24
|
+
clearTimeout: (timer) => clearTimeout(timer)
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
class NamespaceLease {
|
|
28
|
+
options;
|
|
29
|
+
clock;
|
|
30
|
+
dropped;
|
|
31
|
+
owners = 0;
|
|
32
|
+
registry;
|
|
33
|
+
recovery;
|
|
34
|
+
provenance;
|
|
35
|
+
provenanceGeneration;
|
|
36
|
+
adapter;
|
|
37
|
+
acquiring;
|
|
38
|
+
releasing;
|
|
39
|
+
deadline;
|
|
40
|
+
fallback = !1;
|
|
41
|
+
fallbackObservers = new Set;
|
|
42
|
+
get fallbackObserverCount() {
|
|
43
|
+
return this.fallbackObservers.size;
|
|
44
|
+
}
|
|
45
|
+
failureAt;
|
|
46
|
+
retryAt = 0;
|
|
47
|
+
retryDelay = RETRY_MS;
|
|
48
|
+
failureTimer;
|
|
49
|
+
latestRead;
|
|
50
|
+
adoptedBindings = [];
|
|
51
|
+
controls = new Map;
|
|
52
|
+
projection;
|
|
53
|
+
producerId = randomUUID();
|
|
54
|
+
constructor(options, clock, dropped) {
|
|
55
|
+
this.options = options;
|
|
56
|
+
this.clock = clock;
|
|
57
|
+
this.dropped = dropped;
|
|
58
|
+
this.recovery = new LimitRecoveryLatch(options.log);
|
|
59
|
+
this.provenance = new LimitProvenanceStore(options.namespace);
|
|
60
|
+
}
|
|
61
|
+
stopTracking() {
|
|
62
|
+
if (this.fallback)
|
|
63
|
+
return;
|
|
64
|
+
this.fallback = !0;
|
|
65
|
+
this.clock.clearTimeout(this.failureTimer);
|
|
66
|
+
for (const notify of this.fallbackObservers)
|
|
67
|
+
notify();
|
|
68
|
+
this.fallbackObservers.clear();
|
|
69
|
+
this.options.log("OpenAI limits tracking is unavailable; serving without timed marks for this process.");
|
|
70
|
+
const registry = this.registry;
|
|
71
|
+
this.registry = void 0;
|
|
72
|
+
this.adapter = void 0;
|
|
73
|
+
this.latestRead = void 0;
|
|
74
|
+
this.provenance.clear();
|
|
75
|
+
if (registry)
|
|
76
|
+
this.releasing = registry.dispose().catch(() => {});
|
|
77
|
+
}
|
|
78
|
+
wait(delay) {
|
|
79
|
+
return new Promise((resolve) => this.clock.setTimeout(resolve, Math.max(0, delay)));
|
|
80
|
+
}
|
|
81
|
+
async bounded(promise, until) {
|
|
82
|
+
const fallback = Promise.withResolvers(), notify = () => fallback.resolve(void 0);
|
|
83
|
+
if (this.fallback)
|
|
84
|
+
notify();
|
|
85
|
+
else
|
|
86
|
+
this.fallbackObservers.add(notify);
|
|
87
|
+
let timer;
|
|
88
|
+
try {
|
|
89
|
+
return await Promise.race([
|
|
90
|
+
promise,
|
|
91
|
+
fallback.promise,
|
|
92
|
+
new Promise((resolve) => {
|
|
93
|
+
timer = this.clock.setTimeout(() => resolve(void 0), Math.max(0, until - this.clock.now()));
|
|
94
|
+
})
|
|
95
|
+
]);
|
|
96
|
+
} finally {
|
|
97
|
+
this.clock.clearTimeout(timer);
|
|
98
|
+
this.fallbackObservers.delete(notify);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
recordFailure() {
|
|
102
|
+
if (!this.registry || this.fallback)
|
|
103
|
+
return;
|
|
104
|
+
const now = this.clock.now();
|
|
105
|
+
if (this.failureAt === void 0) {
|
|
106
|
+
this.failureAt = now;
|
|
107
|
+
this.failureTimer = this.clock.setTimeout(() => this.stopTracking(), FAILURE_RUN_MS);
|
|
108
|
+
}
|
|
109
|
+
this.retryAt = now + this.retryDelay;
|
|
110
|
+
this.retryDelay = Math.min(FAILURE_RUN_MS, this.retryDelay * 2);
|
|
111
|
+
if (now - this.failureAt >= FAILURE_RUN_MS)
|
|
112
|
+
this.stopTracking();
|
|
113
|
+
}
|
|
114
|
+
recordSuccess() {
|
|
115
|
+
this.failureAt = void 0;
|
|
116
|
+
this.retryAt = 0;
|
|
117
|
+
this.retryDelay = RETRY_MS;
|
|
118
|
+
this.clock.clearTimeout(this.failureTimer);
|
|
119
|
+
this.failureTimer = void 0;
|
|
120
|
+
}
|
|
121
|
+
async makeAdapter() {
|
|
122
|
+
const adapter = await this.options.adapter();
|
|
123
|
+
return {
|
|
124
|
+
namespace: adapter.namespace,
|
|
125
|
+
read: async (previous) => {
|
|
126
|
+
this.adoptRead();
|
|
127
|
+
if (this.registry && this.clock.now() < this.retryAt)
|
|
128
|
+
throw this.registry.lastFailure ?? Error("limits-reload-backoff");
|
|
129
|
+
try {
|
|
130
|
+
const view = await adapter.read(previous);
|
|
131
|
+
this.latestRead = this.recovery.capture(view, this.clock.now());
|
|
132
|
+
const adoptable = !previous || view.snapshot.generation !== previous.generation || view.snapshot.revision >= previous.revision;
|
|
133
|
+
if (view.authoritative && !view.degradedAgreement && adoptable)
|
|
134
|
+
this.recordSuccess();
|
|
135
|
+
else if (!view.authoritative || view.degradedAgreement)
|
|
136
|
+
this.recordFailure();
|
|
137
|
+
return view;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
this.recordFailure();
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
commit: async (commands, previous) => {
|
|
144
|
+
this.adoptRead();
|
|
145
|
+
const result = await adapter.commit(commands, previous);
|
|
146
|
+
this.latestRead = this.recovery.capture(result, this.clock.now());
|
|
147
|
+
return result;
|
|
148
|
+
},
|
|
149
|
+
subscribe: adapter.subscribe?.bind(adapter)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async ready(sourceReady) {
|
|
153
|
+
if (!sourceReady || this.fallback || this.registry)
|
|
154
|
+
return;
|
|
155
|
+
if (!this.acquiring)
|
|
156
|
+
this.acquiring = this.acquire().finally(() => {
|
|
157
|
+
this.acquiring = void 0;
|
|
158
|
+
});
|
|
159
|
+
await this.acquiring;
|
|
160
|
+
}
|
|
161
|
+
async acquire() {
|
|
162
|
+
await this.releasing;
|
|
163
|
+
this.deadline ??= this.clock.now() + ACQUIRE_MS;
|
|
164
|
+
while (!this.fallback && !this.registry) {
|
|
165
|
+
if (this.clock.now() >= this.deadline) {
|
|
166
|
+
this.stopTracking();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const attempt = (async () => {
|
|
170
|
+
this.adapter ??= await this.makeAdapter();
|
|
171
|
+
return acquireLimitsRegistry({
|
|
172
|
+
adapter: this.adapter,
|
|
173
|
+
clock: this.clock,
|
|
174
|
+
isAccessRestrictive: this.options.isAccessRestrictive,
|
|
175
|
+
onAbandon: () => this.stopTracking(),
|
|
176
|
+
onRejected: (command) => {
|
|
177
|
+
this.controls.delete(JSON.stringify([command.producerId, command.operationId]));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
})();
|
|
181
|
+
try {
|
|
182
|
+
const registry = await this.bounded(attempt, this.deadline);
|
|
183
|
+
if (!registry || this.fallback) {
|
|
184
|
+
this.stopTracking();
|
|
185
|
+
attempt.then((late) => late.dispose()).catch(() => {});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.registry = registry;
|
|
189
|
+
if (registry.abandoned) {
|
|
190
|
+
this.stopTracking();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
this.adoptRead();
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (error instanceof LimitsEnvelopeConflictError || error instanceof LimitsEnvelopeUnsupportedError) {
|
|
196
|
+
this.stopTracking();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (error instanceof LimitsPersistenceRefusal && error.code === "pool-not-ready") {
|
|
200
|
+
this.deadline = void 0;
|
|
201
|
+
this.adapter = void 0;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
await this.wait(Math.min(RETRY_MS, Math.max(0, this.deadline - this.clock.now())));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
adoptRead() {
|
|
209
|
+
const registry = this.current();
|
|
210
|
+
if (registry && this.latestRead && this.recovery.adopt(this.latestRead, registry.snapshot)) {
|
|
211
|
+
if (this.provenanceGeneration !== void 0 && this.provenanceGeneration !== registry.snapshot.generation)
|
|
212
|
+
this.provenance.clear();
|
|
213
|
+
this.provenanceGeneration = registry.snapshot.generation;
|
|
214
|
+
this.provenance.reconcile(registry.snapshot, this.clock.now());
|
|
215
|
+
this.projection = limitsBindingProjection(this.latestRead.view.bindings);
|
|
216
|
+
this.adoptedBindings = this.latestRead.view.bindings;
|
|
217
|
+
for (const operation of registry.snapshot.operationIds)
|
|
218
|
+
this.controls.delete(JSON.stringify([operation.producerId, operation.operationId]));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
current() {
|
|
222
|
+
if (this.registry?.abandoned)
|
|
223
|
+
this.stopTracking();
|
|
224
|
+
return this.registry;
|
|
225
|
+
}
|
|
226
|
+
snapshot() {
|
|
227
|
+
this.adoptRead();
|
|
228
|
+
return this.current()?.snapshot;
|
|
229
|
+
}
|
|
230
|
+
enqueue(command, provenance) {
|
|
231
|
+
const registry = this.current();
|
|
232
|
+
if (registry) {
|
|
233
|
+
if (command.type !== "mark")
|
|
234
|
+
this.controls.set(JSON.stringify([command.producerId, command.operationId]), command);
|
|
235
|
+
registry.enqueue(command);
|
|
236
|
+
if (command.type !== "mark")
|
|
237
|
+
this.provenance.retire(command.binding.account);
|
|
238
|
+
else if (provenance && provenance.expiry === command.until && provenance.evidenceAt === command.evidenceAt && limitAccountId(provenance.accountKey) === limitAccountId(command.binding.account))
|
|
239
|
+
this.provenance.record(provenance, this.clock.now());
|
|
240
|
+
else
|
|
241
|
+
this.provenance.retire(command.binding.account);
|
|
242
|
+
} else if (command.type === "mark")
|
|
243
|
+
this.dropped();
|
|
244
|
+
}
|
|
245
|
+
dropSignal() {
|
|
246
|
+
this.dropped();
|
|
247
|
+
}
|
|
248
|
+
observe(binding) {
|
|
249
|
+
this.adoptRead();
|
|
250
|
+
const registry = this.current();
|
|
251
|
+
if (!registry || !binding)
|
|
252
|
+
return;
|
|
253
|
+
return {
|
|
254
|
+
...registry.observe(binding),
|
|
255
|
+
registry,
|
|
256
|
+
evidence: this.recovery.candidate(binding, this.clock.now())
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
afterProbe(probe, success, parsedLimit) {
|
|
260
|
+
if (!probe?.evidence || !success || parsedLimit || this.current() !== probe.registry)
|
|
261
|
+
return;
|
|
262
|
+
this.adoptRead();
|
|
263
|
+
if (probe.registry.snapshot.marks.some((mark) => limitAccountId(mark.key.account) === limitAccountId(probe.binding.account) && mark.entries.some((entry) => entry.until > this.clock.now())) || !this.recovery.consume(probe.evidence))
|
|
264
|
+
return;
|
|
265
|
+
this.enqueue({
|
|
266
|
+
type: "clear",
|
|
267
|
+
producerId: this.producerId,
|
|
268
|
+
operationId: randomUUID(),
|
|
269
|
+
binding: probe.binding,
|
|
270
|
+
baseRevision: probe.baseRevision,
|
|
271
|
+
keys: [{ scope: { kind: "pool" }, window: "account" }],
|
|
272
|
+
cause: "rate-limit",
|
|
273
|
+
evidenceAt: probe.evidence.evidenceAt
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
dispatchAtBound(expected) {
|
|
277
|
+
this.adoptRead();
|
|
278
|
+
const snapshot = this.current()?.snapshot;
|
|
279
|
+
if (!snapshot)
|
|
280
|
+
return { status: "ready" };
|
|
281
|
+
const current = this.adoptedBindings.find((binding) => limitAccountId(binding.account) === limitAccountId(expected.account)), controlled = [...this.controls.values()].some((command) => limitAccountId(command.binding.account) === limitAccountId(expected.account)), restricted = snapshot.access.some((access) => limitAccountId(access.account) === limitAccountId(expected.account) && this.options.isAccessRestrictive(access.state));
|
|
282
|
+
return {
|
|
283
|
+
status: !current || !isIdentityCompatible(current, expected) || controlled || restricted ? "blocked" : "ready",
|
|
284
|
+
snapshot
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
async release() {
|
|
288
|
+
if (--this.owners !== 0)
|
|
289
|
+
return;
|
|
290
|
+
await this.acquiring;
|
|
291
|
+
if (this.owners !== 0)
|
|
292
|
+
return;
|
|
293
|
+
const registry = this.current();
|
|
294
|
+
this.registry = void 0;
|
|
295
|
+
this.clock.clearTimeout(this.failureTimer);
|
|
296
|
+
if (registry) {
|
|
297
|
+
this.releasing = registry.dispose();
|
|
298
|
+
await this.releasing;
|
|
299
|
+
}
|
|
300
|
+
this.adapter = void 0;
|
|
301
|
+
this.projection = void 0;
|
|
302
|
+
this.deadline = void 0;
|
|
303
|
+
this.provenance.clear();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export class OpenAiLimitsRequest {
|
|
308
|
+
lease;
|
|
309
|
+
projectionDeadline;
|
|
310
|
+
constructor(lease) {
|
|
311
|
+
this.lease = lease;
|
|
312
|
+
}
|
|
313
|
+
snapshot() {
|
|
314
|
+
return this.lease.snapshot();
|
|
315
|
+
}
|
|
316
|
+
async reloadForBindings(bindings) {
|
|
317
|
+
for (;; ) {
|
|
318
|
+
this.lease.adoptRead();
|
|
319
|
+
const registry = this.lease.current();
|
|
320
|
+
if (!registry)
|
|
321
|
+
return;
|
|
322
|
+
if (limitsBindingProjection(bindings()) === this.lease.projection)
|
|
323
|
+
return;
|
|
324
|
+
this.projectionDeadline ??= this.lease.clock.now() + ACQUIRE_MS;
|
|
325
|
+
if (this.lease.clock.now() >= this.projectionDeadline)
|
|
326
|
+
return;
|
|
327
|
+
await this.lease.bounded(registry.reload(), this.projectionDeadline);
|
|
328
|
+
this.lease.adoptRead();
|
|
329
|
+
if (this.lease.clock.now() >= this.projectionDeadline)
|
|
330
|
+
return;
|
|
331
|
+
if (registry.degradedAgreement)
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async beforeDispatch(expected, bindings, accountId = expected?.account.accountId) {
|
|
336
|
+
await this.reloadForBindings(bindings);
|
|
337
|
+
const checkCurrent = () => {
|
|
338
|
+
if (!accountId)
|
|
339
|
+
return "ready";
|
|
340
|
+
const current = bindings().find((binding) => binding.account.accountId === accountId);
|
|
341
|
+
if (!current)
|
|
342
|
+
return expected ? "absent" : "ready";
|
|
343
|
+
if (expected && (limitAccountId(current.account) !== limitAccountId(expected.account) || !isIdentityCompatible(current, expected)))
|
|
344
|
+
return "changed";
|
|
345
|
+
return "ready";
|
|
346
|
+
};
|
|
347
|
+
let status = checkCurrent();
|
|
348
|
+
if (status !== "ready")
|
|
349
|
+
return { status };
|
|
350
|
+
const registry = this.lease.current();
|
|
351
|
+
if (!registry || !expected)
|
|
352
|
+
return { status: "ready" };
|
|
353
|
+
if (this.projectionDeadline !== void 0 && this.lease.clock.now() >= this.projectionDeadline)
|
|
354
|
+
return this.lease.dispatchAtBound(expected);
|
|
355
|
+
const deadline = this.projectionDeadline ?? this.lease.clock.now() + ACQUIRE_MS;
|
|
356
|
+
let view = await this.lease.bounded(registry.beforeDispatch(expected), deadline);
|
|
357
|
+
if (view?.blocked && this.lease.current()) {
|
|
358
|
+
await this.lease.bounded(registry.reload(), deadline);
|
|
359
|
+
view = await this.lease.bounded(registry.beforeDispatch(expected), deadline);
|
|
360
|
+
}
|
|
361
|
+
status = checkCurrent();
|
|
362
|
+
if (status !== "ready")
|
|
363
|
+
return { status };
|
|
364
|
+
if (!this.lease.current())
|
|
365
|
+
return { status: "ready" };
|
|
366
|
+
this.lease.adoptRead();
|
|
367
|
+
return {
|
|
368
|
+
status: !view || view.blocked ? "blocked" : "ready",
|
|
369
|
+
snapshot: view?.snapshot
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export class OpenAiLimitsOwner {
|
|
375
|
+
lease;
|
|
376
|
+
disposed = !1;
|
|
377
|
+
constructor(lease) {
|
|
378
|
+
this.lease = lease;
|
|
379
|
+
lease.owners++;
|
|
380
|
+
}
|
|
381
|
+
get namespace() {
|
|
382
|
+
return this.lease.options.namespace;
|
|
383
|
+
}
|
|
384
|
+
get registry() {
|
|
385
|
+
return this.lease.current();
|
|
386
|
+
}
|
|
387
|
+
get provenance() {
|
|
388
|
+
this.lease.adoptRead();
|
|
389
|
+
return this.lease.provenance;
|
|
390
|
+
}
|
|
391
|
+
async forRequest(sourceReady) {
|
|
392
|
+
if (this.disposed)
|
|
393
|
+
throw Error("limits-owner-disposed");
|
|
394
|
+
await this.lease.ready(sourceReady);
|
|
395
|
+
return new OpenAiLimitsRequest(this.lease);
|
|
396
|
+
}
|
|
397
|
+
snapshot() {
|
|
398
|
+
return this.lease.snapshot();
|
|
399
|
+
}
|
|
400
|
+
observe(binding) {
|
|
401
|
+
return this.lease.observe(binding);
|
|
402
|
+
}
|
|
403
|
+
enqueue(command, provenance) {
|
|
404
|
+
this.lease.enqueue(command, provenance);
|
|
405
|
+
}
|
|
406
|
+
dropSignal() {
|
|
407
|
+
this.lease.dropSignal();
|
|
408
|
+
}
|
|
409
|
+
afterProbe(probe, success, parsedLimit = !1) {
|
|
410
|
+
this.lease.afterProbe(probe, success, parsedLimit);
|
|
411
|
+
}
|
|
412
|
+
async reload() {
|
|
413
|
+
const registry = this.lease.current();
|
|
414
|
+
if (registry)
|
|
415
|
+
await registry.reload();
|
|
416
|
+
this.lease.adoptRead();
|
|
417
|
+
}
|
|
418
|
+
async flush() {
|
|
419
|
+
await this.lease.current()?.flush();
|
|
420
|
+
}
|
|
421
|
+
async dispose() {
|
|
422
|
+
if (this.disposed)
|
|
423
|
+
return;
|
|
424
|
+
this.disposed = !0;
|
|
425
|
+
await this.lease.release();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
export function createLimitsLeaseManager(clock = defaultClock, options = {}) {
|
|
429
|
+
const leases = new Map, droppedSignalLog = options.droppedSignalLog ?? { logged: !1 };
|
|
430
|
+
return {
|
|
431
|
+
forTest(namespace) {
|
|
432
|
+
const lease = leases.get(namespace);
|
|
433
|
+
if (!lease)
|
|
434
|
+
throw Error("Limits lease not acquired");
|
|
435
|
+
return {
|
|
436
|
+
bounded: lease.bounded.bind(lease),
|
|
437
|
+
fallbackObserverCount: () => lease.fallbackObserverCount
|
|
438
|
+
};
|
|
439
|
+
},
|
|
440
|
+
acquire(options) {
|
|
441
|
+
let lease = leases.get(options.namespace);
|
|
442
|
+
if (!lease) {
|
|
443
|
+
lease = new NamespaceLease(options, clock, () => {
|
|
444
|
+
if (droppedSignalLog.logged)
|
|
445
|
+
return;
|
|
446
|
+
droppedSignalLog.logged = !0;
|
|
447
|
+
options.log("OpenAI limit signal dropped because timed-mark tracking is unavailable.");
|
|
448
|
+
});
|
|
449
|
+
leases.set(options.namespace, lease);
|
|
450
|
+
}
|
|
451
|
+
return new OpenAiLimitsOwner(lease);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
const processKey = Symbol.for("@cortexkit/openai-auth/limits-leases/v1"), processState = globalThis, manager = processState[processKey] ?? createLimitsLeaseManager();
|
|
456
|
+
processState[processKey] = manager;
|
|
457
|
+
export function acquireOpenAiLimits(options) {
|
|
458
|
+
const { source } = options, namespace = source.kind === "pool" ? poolLimitsNamespace(source.configPath, source.statePath) : vaultLimitsNamespace(source.rosterPath), log = options.log ?? (() => {});
|
|
459
|
+
return manager.acquire({
|
|
460
|
+
namespace,
|
|
461
|
+
log,
|
|
462
|
+
isAccessRestrictive: options.isAccessRestrictive ?? (() => !1),
|
|
463
|
+
adapter: () => source.kind === "pool" ? createPoolLimitsAdapter({
|
|
464
|
+
namespace,
|
|
465
|
+
store: source.store,
|
|
466
|
+
logger: { warn: log }
|
|
467
|
+
}) : createVaultLimitsAdapter({
|
|
468
|
+
namespace,
|
|
469
|
+
path: source.rosterPath,
|
|
470
|
+
logger: { warn: log }
|
|
471
|
+
})
|
|
472
|
+
});
|
|
473
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createVaultLimitsAdapter, } from "./1e2f1a89bb34a773-vault-adapter.js";
|