@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,149 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
import { PoolOperationError } from "./04a6357627de5ed0-errors.js";
|
|
4
|
+
import { EnvelopeGuard } from "./8ca6175bfae53e13-envelope.js";
|
|
5
|
+
import { EnvelopeHistory, EnvelopeRepair, } from "./15f402885cbb2fb3-envelope-loss.js";
|
|
6
|
+
import { applyLimitsCommands, createLimitsNamespace, } from "./0c9533222cb4380c-namespace.js";
|
|
7
|
+
import { LimitsPersistenceRefusal, } from "./adc5eeb5a8d28280-persistence.js";
|
|
8
|
+
function bindingsOf(namespace, rows) {
|
|
9
|
+
return rows.flatMap((row) => row.credentialEpoch === undefined
|
|
10
|
+
? []
|
|
11
|
+
: [
|
|
12
|
+
{
|
|
13
|
+
account: {
|
|
14
|
+
namespace,
|
|
15
|
+
accountId: row.id,
|
|
16
|
+
// Pool epochs change on replacement, not on refresh or rotation.
|
|
17
|
+
incarnation: String(row.credentialEpoch),
|
|
18
|
+
},
|
|
19
|
+
credentialEpoch: String(row.credentialEpoch),
|
|
20
|
+
...(row.identity === undefined ? {} : { identity: row.identity }),
|
|
21
|
+
},
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Activate after initialize/load reports ready. Reads never acquire a write
|
|
26
|
+
* lock; recovery is detached and commits merge under the store locks.
|
|
27
|
+
*/
|
|
28
|
+
export async function createPoolLimitsAdapter(options) {
|
|
29
|
+
const { store, namespace } = options;
|
|
30
|
+
if (!store.updateLimitsNamespace)
|
|
31
|
+
throw new LimitsPersistenceRefusal('limits-unsupported');
|
|
32
|
+
const update = store.updateLimitsNamespace.bind(store);
|
|
33
|
+
const generation = randomUUID();
|
|
34
|
+
let history = new EnvelopeHistory();
|
|
35
|
+
const guard = new EnvelopeGuard(namespace, options.logger);
|
|
36
|
+
const repair = new EnvelopeRepair(options.logger);
|
|
37
|
+
const now = options.now ?? Date.now;
|
|
38
|
+
const readBindings = async () => {
|
|
39
|
+
const pool = await store.read();
|
|
40
|
+
if (pool.status !== 'ready') {
|
|
41
|
+
if (pool.status === 'error' && pool.kind === 'snapshot-contended')
|
|
42
|
+
throw new Error(pool.reason);
|
|
43
|
+
throw new LimitsPersistenceRefusal('pool-not-ready');
|
|
44
|
+
}
|
|
45
|
+
return bindingsOf(namespace, pool.rows);
|
|
46
|
+
};
|
|
47
|
+
const readEnvelope = async () => {
|
|
48
|
+
const settings = await store.readSettings();
|
|
49
|
+
if (settings.status !== 'ready')
|
|
50
|
+
throw new LimitsPersistenceRefusal('pool-not-ready');
|
|
51
|
+
return guard.decode(settings.settings.commonAuthLimits);
|
|
52
|
+
};
|
|
53
|
+
const read = async (previous) => {
|
|
54
|
+
guard.assertWritable();
|
|
55
|
+
let bindings = await readBindings();
|
|
56
|
+
let snapshot = await readEnvelope();
|
|
57
|
+
let last;
|
|
58
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
59
|
+
const checked = await readBindings();
|
|
60
|
+
const checkedSnapshot = await readEnvelope();
|
|
61
|
+
// A replacement between the envelope and binding reads must not make an
|
|
62
|
+
// old envelope authoritative for a new incarnation. Recheck the envelope
|
|
63
|
+
// too: its generation or revision can change while the rows stay the same.
|
|
64
|
+
// Bounded retries keep a busy writer from delaying a provider request.
|
|
65
|
+
const stable = isDeepStrictEqual(bindings, checked) &&
|
|
66
|
+
isDeepStrictEqual(snapshot, checkedSnapshot);
|
|
67
|
+
last = {
|
|
68
|
+
snapshot: snapshot.snapshot ?? createLimitsNamespace(namespace, generation),
|
|
69
|
+
bindings,
|
|
70
|
+
authoritative: stable,
|
|
71
|
+
};
|
|
72
|
+
if (stable) {
|
|
73
|
+
if (!snapshot.replacement &&
|
|
74
|
+
history.lost(snapshot.snapshot, previous)) {
|
|
75
|
+
repair.schedule(() => adapter.commit([], previous));
|
|
76
|
+
return {
|
|
77
|
+
snapshot: history.recover(snapshot.snapshot, previous, namespace, now()),
|
|
78
|
+
bindings,
|
|
79
|
+
authoritative: false,
|
|
80
|
+
degradedAgreement: true,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (snapshot.snapshot)
|
|
84
|
+
history.remember(snapshot.snapshot);
|
|
85
|
+
return last;
|
|
86
|
+
}
|
|
87
|
+
bindings = checked;
|
|
88
|
+
snapshot = checkedSnapshot;
|
|
89
|
+
}
|
|
90
|
+
return last;
|
|
91
|
+
};
|
|
92
|
+
const adapter = {
|
|
93
|
+
namespace,
|
|
94
|
+
read,
|
|
95
|
+
subscribe: repair.subscribe,
|
|
96
|
+
async commit(commands, previous) {
|
|
97
|
+
guard.assertWritable();
|
|
98
|
+
let committed;
|
|
99
|
+
let replacement;
|
|
100
|
+
const onPublished = () => {
|
|
101
|
+
if (guard.didCommit(replacement) && committed) {
|
|
102
|
+
history = new EnvelopeHistory();
|
|
103
|
+
history.remember(committed.snapshot, previous);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
await update((envelope, rows) => {
|
|
108
|
+
const bindings = bindingsOf(namespace, rows);
|
|
109
|
+
const decoded = guard.decode(envelope);
|
|
110
|
+
const present = decoded.snapshot;
|
|
111
|
+
replacement = decoded.replacement;
|
|
112
|
+
const degradedAgreement = !replacement && history.lost(present, previous);
|
|
113
|
+
const result = applyLimitsCommands(degradedAgreement
|
|
114
|
+
? history.recover(present, previous, namespace, now())
|
|
115
|
+
: (present ?? createLimitsNamespace(namespace, generation)), commands, {
|
|
116
|
+
now: now(),
|
|
117
|
+
bindings,
|
|
118
|
+
authorizeEpoch: (observed, current) => observed.credentialEpoch === current.credentialEpoch,
|
|
119
|
+
});
|
|
120
|
+
committed = {
|
|
121
|
+
...result,
|
|
122
|
+
bindings,
|
|
123
|
+
authoritative: true,
|
|
124
|
+
degradedAgreement,
|
|
125
|
+
};
|
|
126
|
+
return result.snapshot;
|
|
127
|
+
}, {
|
|
128
|
+
beforePublish: () => guard.assertWritable(),
|
|
129
|
+
onPublished,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
// Store operations wrap mutator failures; preserve the typed terminal refusal.
|
|
134
|
+
guard.assertWritable();
|
|
135
|
+
if (error instanceof PoolOperationError &&
|
|
136
|
+
(error.kind === 'pending-migration' || error.kind === 'load-error'))
|
|
137
|
+
throw new LimitsPersistenceRefusal('pool-not-ready');
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
if (!committed)
|
|
141
|
+
throw new Error('Pool limits mutator was not called');
|
|
142
|
+
onPublished();
|
|
143
|
+
history.remember(committed.snapshot, previous);
|
|
144
|
+
return committed;
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
await read();
|
|
148
|
+
return adapter;
|
|
149
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
reportCacheTouch,
|
|
3
|
+
reportCacheWarmStopped,
|
|
4
|
+
sessionCachePolicy
|
|
5
|
+
} from "./bd5977eca210d2b8-index.js";
|
|
6
|
+
import { hasVaultRoutingAccessor } from "./8c42bbec02f59636-vault-routing.js";
|
|
7
|
+
export function sessionCacheKeepPlan(sessionId) {
|
|
8
|
+
const policy = sessionCachePolicy(sessionId);
|
|
9
|
+
if (!policy?.keep_warm)
|
|
10
|
+
return;
|
|
11
|
+
return { mode: policy.keep_warm, hours: policy.hours };
|
|
12
|
+
}
|
|
13
|
+
export function shouldCaptureSessionCache(sessionId, enabled) {
|
|
14
|
+
const plan = sessionCacheKeepPlan(sessionId);
|
|
15
|
+
return plan ? plan.mode !== "off" : enabled;
|
|
16
|
+
}
|
|
17
|
+
export function reportSessionCacheWarmed(sessionId, input) {
|
|
18
|
+
reportCacheTouch(sessionId, { ...input, ttlMs: "implicit", source: "warm" });
|
|
19
|
+
}
|
|
20
|
+
export function reportSessionCacheWarmStopped(sessionId, input) {
|
|
21
|
+
reportCacheWarmStopped(sessionId, input);
|
|
22
|
+
}
|
|
23
|
+
export function deferSessionCacheResponseTouch(sessionId, at) {
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
reportCacheTouch(sessionId, { at, ttlMs: "implicit", source: "response" });
|
|
26
|
+
}, 0);
|
|
27
|
+
}
|
|
28
|
+
export function reportSessionCacheResponse(response, sessionId, now = Date.now) {
|
|
29
|
+
if (!sessionId || !response.ok || !hasVaultRoutingAccessor())
|
|
30
|
+
return response;
|
|
31
|
+
const completed = () => {
|
|
32
|
+
deferSessionCacheResponseTouch(sessionId, now());
|
|
33
|
+
};
|
|
34
|
+
if (!response.body) {
|
|
35
|
+
completed();
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
const reader = response.body.getReader();
|
|
39
|
+
return new Response(new ReadableStream({
|
|
40
|
+
async pull(controller) {
|
|
41
|
+
try {
|
|
42
|
+
const chunk = await reader.read();
|
|
43
|
+
if (chunk.done) {
|
|
44
|
+
controller.close();
|
|
45
|
+
completed();
|
|
46
|
+
} else
|
|
47
|
+
controller.enqueue(chunk.value);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
controller.error(error);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
cancel(reason) {
|
|
53
|
+
return reader.cancel(reason);
|
|
54
|
+
}
|
|
55
|
+
}, { highWaterMark: 0 }), {
|
|
56
|
+
status: response.status,
|
|
57
|
+
statusText: response.statusText,
|
|
58
|
+
headers: response.headers
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { scopeCovers } from "./8349ed25dc629e97-scope.js";
|
|
2
|
+
/** The caller supplies only this account's marks; other models remain blocked. */
|
|
3
|
+
export function marksAfterSuccess(marks, axes, model, familyOf) {
|
|
4
|
+
return axes.successClearsCoveredScopes === 'off'
|
|
5
|
+
? marks
|
|
6
|
+
: marks.filter((mark) => !scopeCovers(mark.scope, model, familyOf));
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { select } from "./7b5d6afff4ff32b9-select.js";
|
|
2
|
+
import { isInteractive } from "./ea56007991dbf068-terminal.js";
|
|
3
|
+
/**
|
|
4
|
+
* Ask a yes/no question. "No" is listed first unless `defaultYes`, so a
|
|
5
|
+
* stray Enter declines. Escape, and a terminal that cannot take keys, count
|
|
6
|
+
* as "No": nothing destructive runs without an explicit yes.
|
|
7
|
+
*/
|
|
8
|
+
export async function confirm(terminal, message, defaultYes = false) {
|
|
9
|
+
if (!isInteractive(terminal))
|
|
10
|
+
return false;
|
|
11
|
+
const items = defaultYes
|
|
12
|
+
? [
|
|
13
|
+
{ label: 'Yes', value: true },
|
|
14
|
+
{ label: 'No', value: false },
|
|
15
|
+
]
|
|
16
|
+
: [
|
|
17
|
+
{ label: 'No', value: false },
|
|
18
|
+
{ label: 'Yes', value: true },
|
|
19
|
+
];
|
|
20
|
+
return (await select(terminal, items, { message })) ?? false;
|
|
21
|
+
}
|
|
@@ -80,9 +80,10 @@ export function buildAuthorizeUrl(redirectUri, pkce, state) {
|
|
|
80
80
|
});
|
|
81
81
|
return `${ISSUER}/oauth/authorize?${params.toString()}`;
|
|
82
82
|
}
|
|
83
|
-
export async function exchangeCodeForTokens(code, redirectUri, pkce) {
|
|
83
|
+
export async function exchangeCodeForTokens(code, redirectUri, pkce, signal) {
|
|
84
84
|
const response = await fetch(`${ISSUER}/oauth/token`, {
|
|
85
85
|
method: "POST",
|
|
86
|
+
signal,
|
|
86
87
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
87
88
|
body: new URLSearchParams({
|
|
88
89
|
grant_type: "authorization_code",
|
|
@@ -94,7 +95,9 @@ export async function exchangeCodeForTokens(code, redirectUri, pkce) {
|
|
|
94
95
|
});
|
|
95
96
|
if (!response.ok)
|
|
96
97
|
throw Error(`Token exchange failed: ${response.status}`);
|
|
97
|
-
|
|
98
|
+
const tokens = await response.json();
|
|
99
|
+
signal?.throwIfAborted();
|
|
100
|
+
return tokens;
|
|
98
101
|
}
|
|
99
102
|
export function escapeHtml(value) {
|
|
100
103
|
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
@@ -267,7 +270,7 @@ export async function startOAuthServer() {
|
|
|
267
270
|
return;
|
|
268
271
|
}
|
|
269
272
|
flowCleanup(state);
|
|
270
|
-
exchangeCodeForTokens(code, redirectUri, entry.pkce).then((tokens) => entry.resolve(tokens)).catch((err) => entry.reject(err));
|
|
273
|
+
exchangeCodeForTokens(code, redirectUri, entry.pkce, entry.signal).then((tokens) => entry.resolve(tokens)).catch((err) => entry.reject(err));
|
|
271
274
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
272
275
|
res.end(HTML_SUCCESS);
|
|
273
276
|
return;
|
|
@@ -328,36 +331,31 @@ export function waitForOAuthCallback(pkce, state, timeoutMs = 300000, signal) {
|
|
|
328
331
|
reject(Error("Login cancelled"));
|
|
329
332
|
return;
|
|
330
333
|
}
|
|
331
|
-
const
|
|
332
|
-
if (pendingFlows.get(state)) {
|
|
333
|
-
flowCleanup(state);
|
|
334
|
-
reject(Error("OAuth callback timeout \u2014 authorization took too long"));
|
|
335
|
-
}
|
|
336
|
-
}, timeoutMs), onAbort = () => {
|
|
334
|
+
const controller = new AbortController, settle = () => {
|
|
337
335
|
clearTimeout(timeout);
|
|
338
|
-
|
|
336
|
+
signal?.removeEventListener("abort", onAbort);
|
|
337
|
+
}, abort = (error) => {
|
|
338
|
+
if (pendingFlows.get(state) === entry)
|
|
339
339
|
flowCleanup(state);
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
pendingFlows.set(state, {
|
|
340
|
+
controller.abort(error);
|
|
341
|
+
entry.reject(error);
|
|
342
|
+
}, timeout = setTimeout(() => {
|
|
343
|
+
abort(Error("OAuth callback timeout \u2014 authorization took too long"));
|
|
344
|
+
}, timeoutMs), onAbort = () => abort(Error("Login cancelled")), entry = {
|
|
346
345
|
pkce,
|
|
347
346
|
state,
|
|
347
|
+
signal: controller.signal,
|
|
348
348
|
resolve: (tokens) => {
|
|
349
|
-
|
|
350
|
-
if (signal)
|
|
351
|
-
signal.removeEventListener("abort", onAbort);
|
|
349
|
+
settle();
|
|
352
350
|
resolve(tokens);
|
|
353
351
|
},
|
|
354
352
|
reject: (error) => {
|
|
355
|
-
|
|
356
|
-
if (signal)
|
|
357
|
-
signal.removeEventListener("abort", onAbort);
|
|
353
|
+
settle();
|
|
358
354
|
reject(error);
|
|
359
355
|
}
|
|
360
|
-
}
|
|
356
|
+
};
|
|
357
|
+
signal?.addEventListener("abort", onAbort);
|
|
358
|
+
pendingFlows.set(state, entry);
|
|
361
359
|
});
|
|
362
360
|
}
|
|
363
361
|
export async function beginDeviceAuth(version) {
|
|
@@ -379,14 +377,31 @@ export async function beginDeviceAuth(version) {
|
|
|
379
377
|
};
|
|
380
378
|
}
|
|
381
379
|
export async function completeDeviceAuth(deviceData, version, signal) {
|
|
382
|
-
const interval = Math.max(parseInt(deviceData.interval, 10) || 5, 1) * 1000, expires_in = typeof deviceData.expires_in === "number" ? deviceData.expires_in : parseInt(deviceData.expires_in || "", 10), maxDurationMs = !Number.isNaN(expires_in) && expires_in > 0 ? expires_in * 1000 : 900000
|
|
383
|
-
|
|
384
|
-
|
|
380
|
+
const interval = Math.max(parseInt(deviceData.interval, 10) || 5, 1) * 1000, expires_in = typeof deviceData.expires_in === "number" ? deviceData.expires_in : parseInt(deviceData.expires_in || "", 10), maxDurationMs = !Number.isNaN(expires_in) && expires_in > 0 ? expires_in * 1000 : 900000;
|
|
381
|
+
if (signal?.aborted)
|
|
382
|
+
throw Error("Device authorization cancelled");
|
|
383
|
+
const deadline = new AbortController, expired = Error("Device authorization expired"), expiresAt = Date.now() + maxDurationMs, timeout = setTimeout(() => deadline.abort(expired), maxDurationMs), flowSignal = signal ? AbortSignal.any([signal, deadline.signal]) : deadline.signal;
|
|
384
|
+
try {
|
|
385
|
+
return await pollDeviceAuth(deviceData, version, interval, expiresAt, flowSignal);
|
|
386
|
+
} catch (error) {
|
|
387
|
+
if (flowSignal.aborted) {
|
|
388
|
+
if (flowSignal.reason === expired)
|
|
389
|
+
throw expired;
|
|
385
390
|
throw Error("Device authorization cancelled");
|
|
386
|
-
|
|
391
|
+
}
|
|
392
|
+
throw error;
|
|
393
|
+
} finally {
|
|
394
|
+
clearTimeout(timeout);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
async function pollDeviceAuth(deviceData, version, interval, expiresAt, signal) {
|
|
398
|
+
while (!0) {
|
|
399
|
+
signal.throwIfAborted();
|
|
400
|
+
if (Date.now() >= expiresAt)
|
|
387
401
|
throw Error("Device authorization expired");
|
|
388
402
|
const response = await fetch(`${ISSUER}/api/accounts/deviceauth/token`, {
|
|
389
403
|
method: "POST",
|
|
404
|
+
signal,
|
|
390
405
|
headers: {
|
|
391
406
|
"Content-Type": "application/json",
|
|
392
407
|
"User-Agent": buildUserAgent(version)
|
|
@@ -399,6 +414,7 @@ export async function completeDeviceAuth(deviceData, version, signal) {
|
|
|
399
414
|
if (response.ok) {
|
|
400
415
|
const data = await response.json(), tokenResponse = await fetch(`${ISSUER}/oauth/token`, {
|
|
401
416
|
method: "POST",
|
|
417
|
+
signal,
|
|
402
418
|
headers: {
|
|
403
419
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
404
420
|
},
|
|
@@ -412,21 +428,17 @@ export async function completeDeviceAuth(deviceData, version, signal) {
|
|
|
412
428
|
});
|
|
413
429
|
if (!tokenResponse.ok)
|
|
414
430
|
throw Error(`Token exchange failed: ${tokenResponse.status}`);
|
|
415
|
-
|
|
431
|
+
const tokens = await tokenResponse.json();
|
|
432
|
+
signal.throwIfAborted();
|
|
433
|
+
return tokens;
|
|
416
434
|
}
|
|
417
435
|
if (response.status !== 403 && response.status !== 404)
|
|
418
436
|
throw Error(`Device authorization failed: ${response.status}`);
|
|
419
|
-
const remainingMs =
|
|
437
|
+
const remainingMs = expiresAt - Date.now();
|
|
420
438
|
if (remainingMs <= 0)
|
|
421
439
|
throw Error("Device authorization expired");
|
|
422
440
|
const sleepMs = Math.min(interval + OAUTH_POLLING_SAFETY_MARGIN_MS, remainingMs);
|
|
423
|
-
|
|
424
|
-
await sleep(sleepMs, void 0, { signal });
|
|
425
|
-
} catch (err) {
|
|
426
|
-
if (err instanceof Error && err.name === "AbortError")
|
|
427
|
-
throw Error("Device authorization cancelled");
|
|
428
|
-
throw err;
|
|
429
|
-
}
|
|
441
|
+
await sleep(sleepMs, void 0, { signal });
|
|
430
442
|
}
|
|
431
443
|
}
|
|
432
444
|
export function upsertAccount(accounts, account) {
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decideAfterLimit,
|
|
3
|
+
sameAccount,
|
|
4
|
+
sameAccountHoldFacts,
|
|
5
|
+
windowRouter
|
|
6
|
+
} from "./1547bd74f4214d2d-index.js";
|
|
7
|
+
import { getFallbackStatuses } from "./dbc61cd405941828-accounts.js";
|
|
8
|
+
import { isRecord } from "./775431e21f469203-record.js";
|
|
9
|
+
export const QUOTA_STALENESS_MS = 900000;
|
|
10
|
+
export function openAiLimitAxes(fallbackOn) {
|
|
11
|
+
return {
|
|
12
|
+
...windowRouter,
|
|
13
|
+
shortLimit: {
|
|
14
|
+
...windowRouter.shortLimit,
|
|
15
|
+
holdBound: "cache-ttl",
|
|
16
|
+
preference: "same-account-first",
|
|
17
|
+
jitter: "none"
|
|
18
|
+
},
|
|
19
|
+
advance: {
|
|
20
|
+
...windowRouter.advance,
|
|
21
|
+
opencode1: {
|
|
22
|
+
...windowRouter.advance.opencode1,
|
|
23
|
+
statuses: fallbackOn?.length ? [...fallbackOn] : [401, 403, 429]
|
|
24
|
+
},
|
|
25
|
+
pi: {
|
|
26
|
+
...windowRouter.advance.pi,
|
|
27
|
+
statuses: fallbackOn?.length ? [...fallbackOn] : [401, 403, 429]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
terminalMetadata: "setting-capped-fresh"
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function freshQuotaEvidence(checkedAt, now) {
|
|
34
|
+
return Number.isFinite(checkedAt) && checkedAt <= now && now - checkedAt <= QUOTA_STALENESS_MS;
|
|
35
|
+
}
|
|
36
|
+
export function quotaResetAt(value) {
|
|
37
|
+
if (!value)
|
|
38
|
+
return;
|
|
39
|
+
const reset = Date.parse(value);
|
|
40
|
+
return Number.isFinite(reset) ? reset : void 0;
|
|
41
|
+
}
|
|
42
|
+
export function confirmedQuotaWindows(reading, now) {
|
|
43
|
+
return ["primary", "secondary"].flatMap((name) => {
|
|
44
|
+
const window = reading?.[name];
|
|
45
|
+
if (!window || !freshQuotaEvidence(window.checkedAt, now) || !Number.isFinite(window.usedPercent) || !(window.usedPercent >= 100))
|
|
46
|
+
return [];
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
window: name,
|
|
50
|
+
confirmed: !0,
|
|
51
|
+
confirmedByReading: !0,
|
|
52
|
+
resetAt: quotaResetAt(window.resetsAt),
|
|
53
|
+
observedAt: window.checkedAt,
|
|
54
|
+
provenance: "reading"
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export function openAiSignalWindows(parsed, observedAt, reading, now) {
|
|
60
|
+
const named = parsed.window === "primary" || parsed.window === "secondary", window = named ? reading?.[parsed.window] : void 0, fresh = window && freshQuotaEvidence(window.checkedAt, now), usage = parsed.window === "usage_limit_reached", providerReset = usage && parsed.resetAt !== void 0 && Number.isFinite(parsed.resetAt) && parsed.resetAt > 0;
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
window: named ? parsed.window : usage ? "usage" : parsed.window,
|
|
64
|
+
confirmed: named || usage,
|
|
65
|
+
confirmedByReading: !1,
|
|
66
|
+
resetAt: named ? fresh ? quotaResetAt(window.resetsAt) : void 0 : providerReset ? parsed.resetAt : void 0,
|
|
67
|
+
observedAt: named && fresh ? window.checkedAt : observedAt,
|
|
68
|
+
provenance: named && fresh ? "reading" : providerReset ? "provider" : "unproven"
|
|
69
|
+
}
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
export function classifyOpenAiLimitBody(input) {
|
|
73
|
+
let body = input.body;
|
|
74
|
+
if (typeof body === "string")
|
|
75
|
+
try {
|
|
76
|
+
body = JSON.parse(body);
|
|
77
|
+
} catch {
|
|
78
|
+
body = void 0;
|
|
79
|
+
}
|
|
80
|
+
const root = isRecord(body) ? body : {}, failed = root.type === "response.failed" && isRecord(root.response) ? root.response : void 0, detail = isRecord(failed?.error) ? failed.error : isRecord(root.error) ? root.error : root, label = isRecord(failed?.failed) ? failed.failed.rate_limit_reached_type : void 0, type = typeof detail.type === "string" ? detail.type : void 0, code = typeof detail.code === "string" ? detail.code : void 0, reason = typeof label === "string" ? label : failed ? code ?? type : type ?? code, status = input.status ?? (typeof root.status === "number" ? root.status : typeof root.status_code === "number" ? root.status_code : void 0);
|
|
81
|
+
if (reason !== "usage_limit_reached" && !failed && status !== 429)
|
|
82
|
+
return;
|
|
83
|
+
if (failed && !reason)
|
|
84
|
+
return;
|
|
85
|
+
if (failed && reason !== "primary" && reason !== "secondary" && reason !== "usage_limit_reached" && reason !== "rate_limit_exceeded")
|
|
86
|
+
return;
|
|
87
|
+
const { resets_at: absolute, resets_in_seconds: relative } = detail, resetAt = typeof absolute === "number" && Number.isFinite(absolute) && absolute > 0 ? absolute * 1000 : typeof relative === "number" && Number.isFinite(relative) && relative > 0 ? input.now + relative * 1000 : void 0, windows = failed || type === "usage_limit_reached" ? openAiSignalWindows({
|
|
88
|
+
window: reason ?? "rate_limit",
|
|
89
|
+
resetAt
|
|
90
|
+
}, input.now, input.reading, input.now) : [
|
|
91
|
+
{
|
|
92
|
+
window: reason ?? "rate_limit",
|
|
93
|
+
confirmed: !1,
|
|
94
|
+
confirmedByReading: !1,
|
|
95
|
+
observedAt: input.now,
|
|
96
|
+
provenance: "unproven"
|
|
97
|
+
}
|
|
98
|
+
], hint = input.headers?.get("retry-after"), seconds = hint?.trim() ? Number(hint) : NaN;
|
|
99
|
+
return {
|
|
100
|
+
account: input.account,
|
|
101
|
+
kind: windows.some((window) => window.confirmed) ? "quota-exhausted" : "rate-limit",
|
|
102
|
+
reason: reason ?? "rate_limit",
|
|
103
|
+
status,
|
|
104
|
+
scope: { kind: "pool" },
|
|
105
|
+
windows,
|
|
106
|
+
observedAt: input.now,
|
|
107
|
+
...Number.isFinite(seconds) && seconds >= 0 ? { retryAfterMs: seconds * 1000, retryAfterSource: "retry-after" } : {}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export function openAiConfirmedBlockers(signal, reading, now) {
|
|
111
|
+
const windows = new Map(confirmedQuotaWindows(reading, now).map((window) => [
|
|
112
|
+
window.window,
|
|
113
|
+
window
|
|
114
|
+
]));
|
|
115
|
+
for (const window of signal?.windows ?? []) {
|
|
116
|
+
if (!window.confirmed)
|
|
117
|
+
continue;
|
|
118
|
+
const previous = windows.get(window.window);
|
|
119
|
+
if (!previous || (window.resetAt ?? 1 / 0) >= (previous.resetAt ?? 1 / 0))
|
|
120
|
+
windows.set(window.window, window);
|
|
121
|
+
}
|
|
122
|
+
return [...windows.values()];
|
|
123
|
+
}
|
|
124
|
+
function holdSuppressed(candidate, status, now) {
|
|
125
|
+
if (status === 401 || status === 403 || !candidate.admitted)
|
|
126
|
+
return !0;
|
|
127
|
+
const confirmed = candidate.confirmedBlockers?.filter((window) => window.confirmed) ?? [], target = Math.max(...confirmed.map((window) => window.resetAt ?? NaN));
|
|
128
|
+
return !Number.isFinite(target) || candidate.blockers.some((blocker) => blocker.kind === "hard" && (blocker.until ?? 0) > now && (blocker.until ?? 0) > target);
|
|
129
|
+
}
|
|
130
|
+
export function openAiHoldFacts(input) {
|
|
131
|
+
if (holdSuppressed(input.candidate, input.status, input.now))
|
|
132
|
+
return;
|
|
133
|
+
const hold = sameAccountHoldFacts({
|
|
134
|
+
activity: input.activity,
|
|
135
|
+
accountKey: input.candidate.account,
|
|
136
|
+
maxSameAccountWait: input.maxSameAccountWait
|
|
137
|
+
});
|
|
138
|
+
return hold ? {
|
|
139
|
+
...hold,
|
|
140
|
+
...input.maxDelayMs === void 0 ? {} : { maxDelayMs: input.maxDelayMs }
|
|
141
|
+
} : void 0;
|
|
142
|
+
}
|
|
143
|
+
export function shouldDecideOpenAiLimit(input) {
|
|
144
|
+
return !(input.host !== "opencode2" && input.mode === "ordered" && input.status !== void 0 && !getFallbackStatuses({
|
|
145
|
+
version: 1,
|
|
146
|
+
accounts: [],
|
|
147
|
+
fallbackOn: input.fallbackOn
|
|
148
|
+
}).includes(input.status));
|
|
149
|
+
}
|
|
150
|
+
export function decideOpenAiLimit(facts, options) {
|
|
151
|
+
if (facts.phase === "after-limit" && !shouldDecideOpenAiLimit({
|
|
152
|
+
...options,
|
|
153
|
+
host: facts.host,
|
|
154
|
+
status: facts.status
|
|
155
|
+
}))
|
|
156
|
+
return;
|
|
157
|
+
const attempted = facts.candidates.find((candidate) => facts.attempted && sameAccount(candidate.account, facts.attempted)), suppressed = !attempted || holdSuppressed(attempted, facts.status, facts.now);
|
|
158
|
+
return (options.decide ?? decideAfterLimit)({ ...facts, hold: suppressed ? void 0 : facts.hold }, openAiLimitAxes(options.fallbackOn));
|
|
159
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalLimitsPath
|
|
3
|
+
} from "./1547bd74f4214d2d-index.js";
|
|
4
|
+
export function poolLimitsNamespace(configPath, statePath) {
|
|
5
|
+
return JSON.stringify([
|
|
6
|
+
"openai",
|
|
7
|
+
"pool",
|
|
8
|
+
canonicalLimitsPath(configPath),
|
|
9
|
+
canonicalLimitsPath(statePath)
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
export function vaultLimitsNamespace(rosterPath) {
|
|
13
|
+
return JSON.stringify(["openai", "vault", canonicalLimitsPath(rosterPath)]);
|
|
14
|
+
}
|
|
15
|
+
export function limitAccountKey(namespace, account) {
|
|
16
|
+
const accountId = account.kind === "vault" ? account.routeId : account.id, incarnation = account.kind === "pool" ? account.credentialEpoch : account.kind === "vault" ? account.addedAt : account.verifiedIdentity;
|
|
17
|
+
if (incarnation === void 0 || incarnation === "")
|
|
18
|
+
return;
|
|
19
|
+
return { namespace, accountId, incarnation: String(incarnation) };
|
|
20
|
+
}
|
|
21
|
+
export function poolLimitsBinding(namespace, row) {
|
|
22
|
+
const account = limitAccountKey(namespace, { kind: "pool", ...row });
|
|
23
|
+
return account ? { account, credentialEpoch: account.incarnation, identity: row.identity } : void 0;
|
|
24
|
+
}
|
|
25
|
+
export function vaultLimitsBinding(namespace, row) {
|
|
26
|
+
return {
|
|
27
|
+
account: {
|
|
28
|
+
namespace,
|
|
29
|
+
accountId: row.routeId,
|
|
30
|
+
incarnation: String(row.addedAt)
|
|
31
|
+
},
|
|
32
|
+
credentialEpoch: String(row.addedAt),
|
|
33
|
+
identity: row.accountIdentity
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function limitAccountId(account) {
|
|
37
|
+
return JSON.stringify([
|
|
38
|
+
account.namespace,
|
|
39
|
+
account.accountId,
|
|
40
|
+
account.incarnation
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
export function limitsBindingProjection(bindings) {
|
|
44
|
+
return JSON.stringify(bindings.map((binding) => [
|
|
45
|
+
limitAccountId(binding.account),
|
|
46
|
+
binding.credentialEpoch,
|
|
47
|
+
binding.identity ?? null
|
|
48
|
+
]).sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b))));
|
|
49
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSessionActivityStore
|
|
3
|
+
} from "./1547bd74f4214d2d-index.js";
|
|
4
|
+
|
|
5
|
+
export { createSessionActivityStore };
|
|
6
|
+
export function is30MinCacheSupportedModel(bodyText) {
|
|
7
|
+
try {
|
|
8
|
+
const model = JSON.parse(bodyText)?.model;
|
|
9
|
+
if (typeof model !== "string")
|
|
10
|
+
return !1;
|
|
11
|
+
const match = /^gpt-(\d+)(?:\.(\d+))?(?:-|$)/.exec(model);
|
|
12
|
+
if (!match)
|
|
13
|
+
return !1;
|
|
14
|
+
const major = Number(match[1]), minor = Number(match[2] ?? 0);
|
|
15
|
+
return major > 5 || major === 5 && minor >= 6;
|
|
16
|
+
} catch {
|
|
17
|
+
return !1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function ttlForModel(bodyText, defaultTtlMs = 300000) {
|
|
21
|
+
return is30MinCacheSupportedModel(bodyText) ? 1800000 : defaultTtlMs;
|
|
22
|
+
}
|
|
23
|
+
export function recordSessionCompletion(activity, dispatch, currentAccountKey, completion) {
|
|
24
|
+
if (!currentAccountKey || completion.kind === "synthetic")
|
|
25
|
+
return !1;
|
|
26
|
+
if (completion.aborted)
|
|
27
|
+
return !1;
|
|
28
|
+
return (completion.kind === "http" ? completion.completed && !completion.failed : completion.kind === "ws" ? completion.event === "response.completed" : completion.kind === "pi" ? completion.stop === "stop" : completion.status >= 200 && completion.status < 300) && activity.recordAccepted({
|
|
29
|
+
sessionId: dispatch.sessionId,
|
|
30
|
+
accountKey: dispatch.accountKey,
|
|
31
|
+
currentAccountKey,
|
|
32
|
+
lastAcceptedAt: dispatch.dispatchedAt,
|
|
33
|
+
ttlMs: dispatch.ttlMs
|
|
34
|
+
});
|
|
35
|
+
}
|