@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 { formatDuration, formatReset } from "./bd4aef685681048c-duration.js";
|
|
2
|
+
import { containsEmail, sanitizeRefusalLabel } from "./cec39ccddab4fe9c-labels.js";
|
|
3
|
+
import { hasUnsafeWording, } from "./3b31b36bf0877602-wording.js";
|
|
4
|
+
export class ClaudeIncompleteError extends Error {
|
|
5
|
+
code = 'ECONNRESET';
|
|
6
|
+
syscall = 'sticky-routing';
|
|
7
|
+
isRetryable = true;
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message, { cause: { code: 'ECONNRESET', syscall: 'sticky-routing' } });
|
|
10
|
+
this.name = 'ClaudeIncompleteError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Compute metadata at delivery time, after time spent showing a notice. */
|
|
14
|
+
export function retryAfterSeconds(retryAfterMs, noticeDelayMs = 0) {
|
|
15
|
+
if (retryAfterMs === undefined ||
|
|
16
|
+
!Number.isFinite(retryAfterMs) ||
|
|
17
|
+
retryAfterMs < 0) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const remaining = retryAfterMs - elapsedNotice(noticeDelayMs);
|
|
21
|
+
return remaining >= 0 ? Math.ceil(remaining / 1000) : undefined;
|
|
22
|
+
}
|
|
23
|
+
function elapsedNotice(ms) {
|
|
24
|
+
return Number.isFinite(ms) && ms >= 0 ? ms : 0;
|
|
25
|
+
}
|
|
26
|
+
function keptReset(input) {
|
|
27
|
+
return input.resetAt !== undefined && Number.isFinite(input.resetAt)
|
|
28
|
+
? input.resetAt
|
|
29
|
+
: undefined;
|
|
30
|
+
}
|
|
31
|
+
function resetClause(reset) {
|
|
32
|
+
return reset === undefined ? 'The reset is unknown.' : `Reset at ${reset}.`;
|
|
33
|
+
}
|
|
34
|
+
function defaultText(family, reset, retry, nonRetryable) {
|
|
35
|
+
const retryClause = !nonRetryable && retry !== undefined
|
|
36
|
+
? ` Retry in ${formatDuration(retry * 1000)}.`
|
|
37
|
+
: '';
|
|
38
|
+
const start = family === 'pi-final'
|
|
39
|
+
? 'The request cannot continue.'
|
|
40
|
+
: 'No account is available.';
|
|
41
|
+
return `${start}${retryClause} ${resetClause(reset)}`;
|
|
42
|
+
}
|
|
43
|
+
function fallbackText(input, now, nonRetryable) {
|
|
44
|
+
const resetAt = keptReset(input);
|
|
45
|
+
const reset = resetAt === undefined ? undefined : formatReset({ resetAt, now });
|
|
46
|
+
const retry = retryAfterSeconds(input.retryAfterMs, input.noticeDelayMs);
|
|
47
|
+
return defaultText(input.family, reset, retry, nonRetryable);
|
|
48
|
+
}
|
|
49
|
+
function textFor(input, nonRetryable) {
|
|
50
|
+
const now = input.now + elapsedNotice(input.noticeDelayMs ?? 0);
|
|
51
|
+
const fallback = () => fallbackText(input, now, nonRetryable);
|
|
52
|
+
try {
|
|
53
|
+
const resetAt = keptReset(input);
|
|
54
|
+
const reset = resetAt === undefined
|
|
55
|
+
? undefined
|
|
56
|
+
: (input.messages?.formatReset ?? formatReset)({ resetAt, now });
|
|
57
|
+
const retry = retryAfterSeconds(input.retryAfterMs, input.noticeDelayMs);
|
|
58
|
+
// Whitelist text parameters rather than forwarding decision facts, which may
|
|
59
|
+
// contain account or credential identifiers. Labels are an explicit exception.
|
|
60
|
+
const parameters = Object.freeze({
|
|
61
|
+
labels: Object.freeze(input.labelPolicy === 'relogin'
|
|
62
|
+
? (input.parameters?.labels ?? []).map(sanitizeRefusalLabel)
|
|
63
|
+
: []),
|
|
64
|
+
reset,
|
|
65
|
+
retryIn: !nonRetryable && retry !== undefined
|
|
66
|
+
? formatDuration(retry * 1000)
|
|
67
|
+
: undefined,
|
|
68
|
+
});
|
|
69
|
+
const rendered = input.messages?.render(input.messageKey, parameters, nonRetryable);
|
|
70
|
+
return typeof rendered === 'string'
|
|
71
|
+
? rendered
|
|
72
|
+
: defaultText(input.family, reset, retry, nonRetryable);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// A request must still get its refusal if a plugin's text renderer fails.
|
|
76
|
+
return fallback();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function bodyFor(family, message) {
|
|
80
|
+
switch (family) {
|
|
81
|
+
case 'openai-429':
|
|
82
|
+
return JSON.stringify({
|
|
83
|
+
error: {
|
|
84
|
+
message,
|
|
85
|
+
type: 'rate_limit_exceeded',
|
|
86
|
+
code: 'rate_limit_exceeded',
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
case 'claude-429':
|
|
90
|
+
return JSON.stringify({
|
|
91
|
+
type: 'error',
|
|
92
|
+
error: { type: 'rate_limit_error', message },
|
|
93
|
+
});
|
|
94
|
+
case 'json-412':
|
|
95
|
+
return JSON.stringify({
|
|
96
|
+
error: { code: 412, status: 'FAILED_PRECONDITION', message },
|
|
97
|
+
});
|
|
98
|
+
case 'claustrum-429':
|
|
99
|
+
return JSON.stringify({ error: 'claustrum-auth: accounts-rate-limited' });
|
|
100
|
+
case 'claustrum-402':
|
|
101
|
+
return JSON.stringify({ error: 'claustrum-auth: insufficient balance' });
|
|
102
|
+
default:
|
|
103
|
+
return message;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Pure wire construction: the caller sends the response, emits text, or throws the error. */
|
|
107
|
+
export function buildRefusal(input) {
|
|
108
|
+
const nonRetryable = input.family === 'json-412' || input.family === 'pi-final';
|
|
109
|
+
const attributes = {
|
|
110
|
+
family: input.family,
|
|
111
|
+
disposition: 'refuse',
|
|
112
|
+
retryable: !nonRetryable,
|
|
113
|
+
hostRetry: nonRetryable || input.host === 'opencode2' ? 'veto' : 'leave',
|
|
114
|
+
};
|
|
115
|
+
let body = bodyFor(input.family, textFor(input, nonRetryable));
|
|
116
|
+
if (nonRetryable && (hasUnsafeWording(body) || containsEmail(body))) {
|
|
117
|
+
// Rebuild from retained facts, never from plugin text or fact-supplied labels.
|
|
118
|
+
const now = input.now + elapsedNotice(input.noticeDelayMs ?? 0);
|
|
119
|
+
body = bodyFor(input.family, fallbackText(input, now, true));
|
|
120
|
+
}
|
|
121
|
+
if (input.family === 'claude-econnreset') {
|
|
122
|
+
return {
|
|
123
|
+
...attributes,
|
|
124
|
+
kind: 'throw',
|
|
125
|
+
error: new ClaudeIncompleteError(body),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (input.family === 'pi-final')
|
|
129
|
+
return { ...attributes, kind: 'text', body };
|
|
130
|
+
const headers = new Headers(input.family === 'json-412' ? input.extraHeaders : undefined);
|
|
131
|
+
headers.set('content-type', 'application/json');
|
|
132
|
+
// Only the library's post-notice estimate may control this header, including
|
|
133
|
+
// when a provider supplied an old Retry-After among the extra headers.
|
|
134
|
+
headers.delete('retry-after');
|
|
135
|
+
const retry = retryAfterSeconds(input.retryAfterMs, input.noticeDelayMs);
|
|
136
|
+
if (retry !== undefined)
|
|
137
|
+
headers.set('retry-after', String(retry));
|
|
138
|
+
return {
|
|
139
|
+
...attributes,
|
|
140
|
+
kind: 'http',
|
|
141
|
+
status: input.family === 'json-412'
|
|
142
|
+
? 412
|
|
143
|
+
: input.family === 'claustrum-402'
|
|
144
|
+
? 402
|
|
145
|
+
: 429,
|
|
146
|
+
headers,
|
|
147
|
+
body,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { isRecord } from "./775431e21f469203-record.js";
|
|
3
|
+
const OID_NAMESPACE = Buffer.from("6ba7b8129dad11d180b400c04fd430c8", "hex");
|
|
4
|
+
function uuidV5(namespace, name) {
|
|
5
|
+
const bytes = createHash("sha1").update(namespace).update(name, "utf8").digest().subarray(0, 16);
|
|
6
|
+
bytes[6] = bytes.readUInt8(6) & 15 | 80;
|
|
7
|
+
bytes[8] = bytes.readUInt8(8) & 63 | 128;
|
|
8
|
+
return bytes;
|
|
9
|
+
}
|
|
10
|
+
function baseInstructionsId(threadId, text) {
|
|
11
|
+
const hex = uuidV5(uuidV5(OID_NAMESPACE, threadId), text).toString("hex");
|
|
12
|
+
return `msg_${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
13
|
+
}
|
|
14
|
+
export function moveInstructionsToDeveloperMessage(body, options) {
|
|
15
|
+
const topLevel = body.instructions, hasTopLevel = typeof topLevel === "string" && topLevel.length > 0;
|
|
16
|
+
if (!hasTopLevel && !options?.leadingBareInstructions)
|
|
17
|
+
return;
|
|
18
|
+
const items = Array.isArray(body.input) ? body.input : typeof body.input === "string" ? [
|
|
19
|
+
{
|
|
20
|
+
type: "message",
|
|
21
|
+
role: "user",
|
|
22
|
+
content: [{ type: "input_text", text: body.input }]
|
|
23
|
+
}
|
|
24
|
+
] : [], first = items[0];
|
|
25
|
+
let at = isRecord(first) && first.type === "additional_tools" ? 1 : 0, replace = !1, instructions;
|
|
26
|
+
if (hasTopLevel)
|
|
27
|
+
instructions = topLevel;
|
|
28
|
+
else {
|
|
29
|
+
while (isRecord(items[at]) && items[at].type === "additional_tools")
|
|
30
|
+
at++;
|
|
31
|
+
const leading = items[at];
|
|
32
|
+
if (!isRecord(leading) || leading.role !== "developer" && leading.role !== "system" || typeof leading.content !== "string" || leading.content.length === 0 || Object.keys(leading).length !== 2)
|
|
33
|
+
return;
|
|
34
|
+
instructions = leading.content;
|
|
35
|
+
replace = !0;
|
|
36
|
+
}
|
|
37
|
+
const threadId = body.prompt_cache_key;
|
|
38
|
+
body.input = [
|
|
39
|
+
...items.slice(0, at),
|
|
40
|
+
{
|
|
41
|
+
type: "message",
|
|
42
|
+
...typeof threadId === "string" && {
|
|
43
|
+
id: baseInstructionsId(threadId, instructions)
|
|
44
|
+
},
|
|
45
|
+
role: "developer",
|
|
46
|
+
content: [{ type: "input_text", text: instructions }],
|
|
47
|
+
internal_chat_message_metadata_passthrough: {
|
|
48
|
+
content_item_kinds: ["model.base_instructions"],
|
|
49
|
+
...options?.responsesLite && {
|
|
50
|
+
content_item_metadata: [
|
|
51
|
+
{ provenance: { type: "harness", hook: !1 } }
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
...items.slice(replace ? at + 1 : at)
|
|
57
|
+
];
|
|
58
|
+
delete body.instructions;
|
|
59
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const VAULT_EMPTY_ACCESS_HINT = "No ChatGPT login in the vault has the `openai-native` category, or the grant is missing. Check `ck auth status` for categories and `ck auth grant` for the grant.";
|
|
2
|
+
export function vaultGrantCommand(name) {
|
|
3
|
+
return `ck auth grant --principal enrolled:${name} --selector-kind category --selector openai-native --operation read`;
|
|
4
|
+
}
|
|
5
|
+
export const VAULT_RECLASSIFY_COMMAND = "ck auth reclassify --from-registry";
|
|
6
|
+
export function vaultEmptyAccessHint(name, reach) {
|
|
7
|
+
if (reach === void 0)
|
|
8
|
+
return VAULT_EMPTY_ACCESS_HINT;
|
|
9
|
+
if (reach.grants === 0)
|
|
10
|
+
return `The vault has no grant letting ${name} read OpenAI accounts. Grant it with \`${vaultGrantCommand(name)}\`.`;
|
|
11
|
+
return `The vault's grant for ${name} reaches no ChatGPT login: no login has the \`openai-native\` category. \`${VAULT_RECLASSIFY_COMMAND}\` fills empty category sets from the vault's defaults; then check the CATEGORIES column with \`ck auth status\`.`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function codexBaseURL(endpoint) {
|
|
2
|
+
return endpoint.replace(/\/responses\/?$/, "").replace(/\/$/, "");
|
|
3
|
+
}
|
|
4
|
+
export function codexRequestURL(url, endpoint) {
|
|
5
|
+
const original = new URL(url);
|
|
6
|
+
if (original.origin !== "https://api.openai.com" && original.origin !== "wss://api.openai.com" || !/\/responses\/?$/.test(original.pathname))
|
|
7
|
+
return url;
|
|
8
|
+
const destination = new URL(`${codexBaseURL(endpoint)}/responses`);
|
|
9
|
+
destination.search = original.search;
|
|
10
|
+
if (original.protocol === "ws:" || original.protocol === "wss:")
|
|
11
|
+
destination.protocol = destination.protocol === "https:" ? "wss:" : "ws:";
|
|
12
|
+
return destination.href;
|
|
13
|
+
}
|
|
14
|
+
export const DEFAULT_CODEX_API_ENDPOINT = "https://chatgpt.com/backend-api/codex/responses";
|
|
15
|
+
export function resolveCodexEndpoint(configured, override = process.env.CORTEXKIT_OPENAI_AUTH_CODEX_ENDPOINT) {
|
|
16
|
+
return override?.trim() || typeof configured === "string" && configured.trim() || DEFAULT_CODEX_API_ENDPOINT;
|
|
17
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mutateVaultRoster, readVaultRoster, } from "./30f5bc480f31f51c-roster.js";
|
|
3
|
+
import { EnvelopeGuard } from "./8ca6175bfae53e13-envelope.js";
|
|
4
|
+
import { EnvelopeHistory, EnvelopeRepair, } from "./15f402885cbb2fb3-envelope-loss.js";
|
|
5
|
+
import { applyLimitsCommands, createLimitsNamespace, } from "./0c9533222cb4380c-namespace.js";
|
|
6
|
+
function bindingsOf(namespace, roster) {
|
|
7
|
+
return (roster?.rows ?? []).map((row) => ({
|
|
8
|
+
account: {
|
|
9
|
+
namespace,
|
|
10
|
+
accountId: row.routeId,
|
|
11
|
+
// Credential ids can change within the same provider account; addedAt
|
|
12
|
+
// survives those changes but changes when a removed route returns.
|
|
13
|
+
incarnation: String(row.addedAt),
|
|
14
|
+
},
|
|
15
|
+
credentialEpoch: String(row.addedAt),
|
|
16
|
+
...(row.accountIdentity === undefined
|
|
17
|
+
? {}
|
|
18
|
+
: { identity: row.accountIdentity }),
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads use one atomic roster snapshot. Commits re-read both limits and row
|
|
23
|
+
* bindings under the roster's existing write lock, without accessing local
|
|
24
|
+
* account-pool files.
|
|
25
|
+
*/
|
|
26
|
+
export async function createVaultLimitsAdapter(options) {
|
|
27
|
+
const { namespace, path } = options;
|
|
28
|
+
const generation = randomUUID();
|
|
29
|
+
let history = new EnvelopeHistory();
|
|
30
|
+
const guard = new EnvelopeGuard(namespace, options.logger);
|
|
31
|
+
const repair = new EnvelopeRepair(options.logger);
|
|
32
|
+
const now = options.now ?? Date.now;
|
|
33
|
+
const read = async (previous) => {
|
|
34
|
+
guard.assertWritable();
|
|
35
|
+
const roster = await readVaultRoster(path);
|
|
36
|
+
const { snapshot: present, replacement } = guard.decode(roster?.limits);
|
|
37
|
+
if (!replacement && history.lost(present, previous)) {
|
|
38
|
+
repair.schedule(() => adapter.commit([], previous));
|
|
39
|
+
return {
|
|
40
|
+
snapshot: history.recover(present, previous, namespace, now()),
|
|
41
|
+
bindings: bindingsOf(namespace, roster),
|
|
42
|
+
authoritative: false,
|
|
43
|
+
degradedAgreement: true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (present)
|
|
47
|
+
history.remember(present);
|
|
48
|
+
return {
|
|
49
|
+
snapshot: present ?? createLimitsNamespace(namespace, generation),
|
|
50
|
+
bindings: bindingsOf(namespace, roster),
|
|
51
|
+
authoritative: true,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const adapter = {
|
|
55
|
+
namespace,
|
|
56
|
+
read,
|
|
57
|
+
subscribe: repair.subscribe,
|
|
58
|
+
commit: async (commands, previous) => {
|
|
59
|
+
guard.assertWritable();
|
|
60
|
+
let replacement;
|
|
61
|
+
let publishedSnapshot;
|
|
62
|
+
const onPublished = () => {
|
|
63
|
+
if (guard.didCommit(replacement) && publishedSnapshot) {
|
|
64
|
+
history = new EnvelopeHistory();
|
|
65
|
+
history.remember(publishedSnapshot, previous);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const committed = await mutateVaultRoster(path, (current) => {
|
|
69
|
+
const bindings = bindingsOf(namespace, current);
|
|
70
|
+
const decoded = guard.decode(current?.limits);
|
|
71
|
+
const present = decoded.snapshot;
|
|
72
|
+
replacement = decoded.replacement;
|
|
73
|
+
const degradedAgreement = !replacement && history.lost(present, previous);
|
|
74
|
+
const result = applyLimitsCommands(degradedAgreement
|
|
75
|
+
? history.recover(present, previous, namespace, now())
|
|
76
|
+
: (present ?? createLimitsNamespace(namespace, generation)), commands, {
|
|
77
|
+
now: now(),
|
|
78
|
+
bindings,
|
|
79
|
+
authorizeEpoch: (observed, authoritative) => observed.credentialEpoch === authoritative.credentialEpoch,
|
|
80
|
+
});
|
|
81
|
+
publishedSnapshot = result.snapshot;
|
|
82
|
+
return {
|
|
83
|
+
next: {
|
|
84
|
+
...(current ?? {
|
|
85
|
+
version: 1,
|
|
86
|
+
complete: true,
|
|
87
|
+
rows: [],
|
|
88
|
+
declined: [],
|
|
89
|
+
}),
|
|
90
|
+
limits: result.snapshot,
|
|
91
|
+
},
|
|
92
|
+
result: {
|
|
93
|
+
...result,
|
|
94
|
+
bindings,
|
|
95
|
+
authoritative: true,
|
|
96
|
+
degradedAgreement,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}, {
|
|
100
|
+
beforePublish: async () => guard.assertWritable(),
|
|
101
|
+
onPublished,
|
|
102
|
+
});
|
|
103
|
+
onPublished();
|
|
104
|
+
history.remember(committed.snapshot, previous);
|
|
105
|
+
return committed;
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
await read();
|
|
109
|
+
return adapter;
|
|
110
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isRecord } from "./775431e21f469203-record.js";
|
|
2
|
+
function windowReading(window, checkedAt) {
|
|
3
|
+
if (!window)
|
|
4
|
+
return;
|
|
5
|
+
const usedPercent = window.rawUsedPercent ?? window.usedPercent;
|
|
6
|
+
if (!Number.isFinite(usedPercent) || usedPercent < 0 || usedPercent > 100)
|
|
7
|
+
return;
|
|
8
|
+
return {
|
|
9
|
+
usedPercent,
|
|
10
|
+
remainingPercent: 100 - usedPercent,
|
|
11
|
+
checkedAt,
|
|
12
|
+
...typeof window.resetsAt === "string" && { resetsAt: window.resetsAt },
|
|
13
|
+
...typeof window.windowMinutes === "number" && Number.isFinite(window.windowMinutes) && window.windowMinutes > 0 && { windowMinutes: window.windowMinutes }
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function amount(value) {
|
|
17
|
+
if (!isRecord(value) || typeof value.minor !== "number" || !Number.isSafeInteger(value.minor) || typeof value.exponent !== "number" || !Number.isInteger(value.exponent))
|
|
18
|
+
return;
|
|
19
|
+
const result = value.minor / 10 ** value.exponent;
|
|
20
|
+
return Number.isFinite(result) ? result : void 0;
|
|
21
|
+
}
|
|
22
|
+
function spendReading(pool) {
|
|
23
|
+
const limit = amount(pool.total), remaining = amount(pool.remaining);
|
|
24
|
+
if (limit === void 0 || remaining === void 0 || limit < 0 || remaining < 0)
|
|
25
|
+
return;
|
|
26
|
+
const used = limit - remaining, reached = pool.spendable === !1, usedPercent = limit > 0 ? used / limit * 100 : reached ? 100 : 0;
|
|
27
|
+
return {
|
|
28
|
+
limit,
|
|
29
|
+
used,
|
|
30
|
+
remaining,
|
|
31
|
+
usedPercent,
|
|
32
|
+
remainingPercent: 100 - usedPercent,
|
|
33
|
+
reached,
|
|
34
|
+
...typeof pool.resetsAt === "string" && { resetsAt: pool.resetsAt },
|
|
35
|
+
...isRecord(pool.total) && typeof pool.total.unit === "string" && { unit: pool.total.unit }
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function creditsReading(pool, checkedAt) {
|
|
39
|
+
if (!isRecord(pool))
|
|
40
|
+
return;
|
|
41
|
+
const balance = amount(pool.remaining);
|
|
42
|
+
return {
|
|
43
|
+
hasCredits: !0,
|
|
44
|
+
unlimited: typeof pool.unlimited === "boolean" ? pool.unlimited : !1,
|
|
45
|
+
...balance !== void 0 && balance >= 0 && { balance },
|
|
46
|
+
...pool.spendable === !1 && { overageLimitReached: !0 },
|
|
47
|
+
checkedAt
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function preserveInsulaUnlimited(snapshot, quota) {
|
|
51
|
+
if (snapshot.insulaCreditsUnlimitedUnstated && snapshot.credits && snapshot.credits.balance === void 0 && isRecord(quota) && isRecord(quota.credits) && quota.credits.unlimited === !0)
|
|
52
|
+
return { ...snapshot, credits: { ...snapshot.credits, unlimited: !0 } };
|
|
53
|
+
return snapshot;
|
|
54
|
+
}
|
|
55
|
+
export function normalizeInsulaCodexQuota(entry, context) {
|
|
56
|
+
const primary = windowReading(entry.usage?.primary, context.fetchedAt);
|
|
57
|
+
if (!primary || !Number.isFinite(context.fetchedAt))
|
|
58
|
+
return;
|
|
59
|
+
const secondary = windowReading(entry.usage?.secondary, context.fetchedAt), pool = Array.isArray(entry.spend) ? entry.spend.find((value) => isRecord(value) && value.id === "individual_limit") : void 0, spendControl = isRecord(pool) ? spendReading(pool) : void 0, creditsPool = Array.isArray(entry.spend) ? entry.spend.find((value) => isRecord(value) && value.id === "credits") : void 0, credits = creditsReading(creditsPool, context.fetchedAt), available = isRecord(entry.savedResets) ? entry.savedResets.availableCount : void 0;
|
|
60
|
+
return {
|
|
61
|
+
primary,
|
|
62
|
+
...credits && { credits },
|
|
63
|
+
...credits && isRecord(creditsPool) && typeof creditsPool.unlimited !== "boolean" && {
|
|
64
|
+
insulaCreditsUnlimitedUnstated: !0
|
|
65
|
+
},
|
|
66
|
+
...secondary && { secondary },
|
|
67
|
+
...typeof available === "number" && Number.isFinite(available) && available >= 0 && {
|
|
68
|
+
resetCreditsAvailable: available
|
|
69
|
+
},
|
|
70
|
+
...spendControl && { spendControl },
|
|
71
|
+
...!pool && { spendControlCleared: !0 }
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function routingHandle(sessionId) {
|
|
2
|
+
// The bridge can load after the auth plugin, so never cache the accessor.
|
|
3
|
+
const routing = Reflect.get(globalThis, Symbol.for('cortexkit.routing'));
|
|
4
|
+
if (typeof routing !== 'function')
|
|
5
|
+
return undefined;
|
|
6
|
+
const handle = routing(sessionId);
|
|
7
|
+
return typeof handle === 'object' && handle !== null
|
|
8
|
+
? handle
|
|
9
|
+
: undefined;
|
|
10
|
+
}
|
|
@@ -168,20 +168,19 @@ export function normalizeWham(json) {
|
|
|
168
168
|
const individualLimit = json.spend_control?.individual_limit;
|
|
169
169
|
if (json.spend_control === null || individualLimit === null)
|
|
170
170
|
snapshot.spendControlCleared = !0;
|
|
171
|
-
if (
|
|
172
|
-
const limit = nonNegativeNumberish(individualLimit
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
171
|
+
else if (typeof json.spend_control?.reached === "boolean") {
|
|
172
|
+
const limit = nonNegativeNumberish(individualLimit?.limit), used = nonNegativeNumberish(individualLimit?.used), remaining = nonNegativeNumberish(individualLimit?.remaining), usedPercent = nonNegativeNumberish(individualLimit?.used_percent), remainingPercent = nonNegativeNumberish(individualLimit?.remaining_percent);
|
|
173
|
+
snapshot.spendControl = {
|
|
174
|
+
...limit !== void 0 && { limit },
|
|
175
|
+
...used !== void 0 && { used },
|
|
176
|
+
...remaining !== void 0 && { remaining },
|
|
177
|
+
...usedPercent !== void 0 && { usedPercent },
|
|
178
|
+
...remainingPercent !== void 0 && { remainingPercent },
|
|
179
|
+
resetsAt: toResetIso(individualLimit?.reset_at),
|
|
180
|
+
unit: individualLimit?.unit,
|
|
181
|
+
source: individualLimit?.source,
|
|
182
|
+
reached: json.spend_control.reached
|
|
183
|
+
};
|
|
185
184
|
}
|
|
186
185
|
const credits = json.credits;
|
|
187
186
|
if (credits && typeof credits.has_credits === "boolean" && typeof credits.unlimited === "boolean" && typeof credits.overage_limit_reached === "boolean") {
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { orderCodexBody } from "./f981e6b15fb76cdb-codex-body.js";
|
|
2
|
+
import { restoreReplayedCallStatus } from "./3af9a210aa2ccdf2-codex-call-status.js";
|
|
3
|
+
import { isMessageWithRole } from "./fda579e5a0a54165-codex-effort.js";
|
|
4
|
+
import { moveInstructionsToDeveloperMessage } from "./1a4c289eec261e04-codex-instructions.js";
|
|
5
|
+
import {
|
|
6
|
+
RESPONSES_LITE_HEADER,
|
|
7
|
+
rewriteResponsesLiteBody,
|
|
8
|
+
supportsResponsesLite
|
|
9
|
+
} from "./cba8b0aee46b8526-codex-lite.js";
|
|
10
|
+
import { DUMP_SESSION_HEADER } from "./e2ae081583adfce3-dump.js";
|
|
11
|
+
import {
|
|
12
|
+
canonicalInput,
|
|
13
|
+
canonicalPrefixLength,
|
|
14
|
+
retainedInput
|
|
15
|
+
} from "./f03d7b43a214a4a1-canonical-input.js";
|
|
16
|
+
import { isRecord } from "./775431e21f469203-record.js";
|
|
17
|
+
import { uuidV7 } from "./e8fda84e90176436-uuid-v7.js";
|
|
18
|
+
const CODEX_BETA_FEATURES = "terminal_resize_reflow";
|
|
19
|
+
export const CODEX_VERSION = "0.166.0", CODEX_USER_AGENT = `codex_exec/${CODEX_VERSION} (Debian 12.0.0; aarch64) unknown (codex_exec; ${CODEX_VERSION})`, CODEX_CLIENT_HEADERS = {
|
|
20
|
+
version: CODEX_VERSION,
|
|
21
|
+
"user-agent": CODEX_USER_AGENT,
|
|
22
|
+
originator: "codex_exec"
|
|
23
|
+
};
|
|
24
|
+
const CODEX_SANDBOX = "seccomp";
|
|
25
|
+
export const OPENAI_AGENT_HEADER = "x-openai-auth-agent";
|
|
26
|
+
function parseJsonObject(input) {
|
|
27
|
+
if (typeof input !== "string")
|
|
28
|
+
return;
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(input);
|
|
31
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function startsHttpUserTurn(metadata, input, canonical) {
|
|
37
|
+
if (!metadata.input)
|
|
38
|
+
return input.length > 0;
|
|
39
|
+
const prior = metadata.canonicalInput ?? canonicalInput(metadata.input);
|
|
40
|
+
if (canonicalPrefixLength(prior, canonical) === void 0)
|
|
41
|
+
return !0;
|
|
42
|
+
return input.slice(metadata.input.length).some((item) => isMessageWithRole(item, "user") || isMessageWithRole(item, "developer"));
|
|
43
|
+
}
|
|
44
|
+
export function updateHttpTurnMetadata(metadata, body, runtime) {
|
|
45
|
+
const input = Array.isArray(body?.input) ? body.input : void 0, canonical = input ? canonicalInput(input, metadata.canonicalInput) : void 0;
|
|
46
|
+
if (input && canonical && (startsHttpUserTurn(metadata, input, canonical) || !metadata.turnID)) {
|
|
47
|
+
metadata.turnID = (runtime?.uuid ?? uuidV7)();
|
|
48
|
+
metadata.turnStartedAt = (runtime?.now ?? Date.now)();
|
|
49
|
+
} else if (!metadata.turnStartedAt)
|
|
50
|
+
metadata.turnStartedAt = (runtime?.now ?? Date.now)();
|
|
51
|
+
if (input && canonical) {
|
|
52
|
+
metadata.input = input.slice();
|
|
53
|
+
metadata.canonicalInput = retainedInput(canonical);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function applyCodexClientHeaders(input) {
|
|
57
|
+
for (const [name, value] of Object.entries(CODEX_CLIENT_HEADERS))
|
|
58
|
+
input.headers.set(name, value);
|
|
59
|
+
input.headers.set("x-codex-beta-features", CODEX_BETA_FEATURES);
|
|
60
|
+
if (input.accountId)
|
|
61
|
+
input.headers.set("chatgpt-account-id", input.accountId);
|
|
62
|
+
if (input.websocket) {
|
|
63
|
+
input.headers.delete("accept");
|
|
64
|
+
input.headers.delete("content-type");
|
|
65
|
+
} else
|
|
66
|
+
input.headers.set("accept", "text/event-stream");
|
|
67
|
+
}
|
|
68
|
+
export function shapeCodexRequest(input) {
|
|
69
|
+
applyCodexClientHeaders(input);
|
|
70
|
+
if (!input.body)
|
|
71
|
+
return;
|
|
72
|
+
const chained = input.websocket && "previous_response_id" in input.body;
|
|
73
|
+
shapeCodexBody(input.body, input.headers, {
|
|
74
|
+
useResponsesLite: !input.websocket && Boolean(input.responsesLite) && supportsResponsesLite(input.body.model),
|
|
75
|
+
restoreCallStatus: !chained,
|
|
76
|
+
instructions: chained ? "drop" : "move",
|
|
77
|
+
leadingBareInstructions: input.leadingBareInstructions
|
|
78
|
+
});
|
|
79
|
+
return orderCodexBody(input.body);
|
|
80
|
+
}
|
|
81
|
+
function shapeCodexBody(body, headers, policy) {
|
|
82
|
+
if (policy.restoreCallStatus && "input" in body)
|
|
83
|
+
body.input = restoreReplayedCallStatus(body.input, body.model);
|
|
84
|
+
if (policy.useResponsesLite && !policy.websocket)
|
|
85
|
+
headers.set(RESPONSES_LITE_HEADER, "true");
|
|
86
|
+
body.parallel_tool_calls ??= !0;
|
|
87
|
+
if (Array.isArray(body.tools))
|
|
88
|
+
body.tools = body.tools.map(normalizeCodexTool);
|
|
89
|
+
policy.beforePlacement?.();
|
|
90
|
+
if (policy.useResponsesLite)
|
|
91
|
+
if (policy.rewriteLite)
|
|
92
|
+
policy.rewriteLite(body);
|
|
93
|
+
else
|
|
94
|
+
rewriteResponsesLiteBody(body, policy.leadingBareInstructions);
|
|
95
|
+
else if (policy.instructions === "move")
|
|
96
|
+
moveInstructionsToDeveloperMessage(body, {
|
|
97
|
+
leadingBareInstructions: policy.leadingBareInstructions
|
|
98
|
+
});
|
|
99
|
+
else if (policy.instructions === "drop")
|
|
100
|
+
delete body.instructions;
|
|
101
|
+
headers.delete("content-length");
|
|
102
|
+
}
|
|
103
|
+
export function stampCodexSession(input) {
|
|
104
|
+
const turnMetadata = stampCodexSessionIdentity(input);
|
|
105
|
+
stampCodexBodyMetadata(input, turnMetadata);
|
|
106
|
+
}
|
|
107
|
+
export function stampCodexThreadHeaders(headers, metadata) {
|
|
108
|
+
headers.set("session-id", metadata.threadID);
|
|
109
|
+
headers.delete("x-session-id");
|
|
110
|
+
headers.delete("x-session-affinity");
|
|
111
|
+
headers.set("thread-id", metadata.threadID);
|
|
112
|
+
headers.set("x-codex-window-id", metadata.windowID);
|
|
113
|
+
headers.set("x-client-request-id", metadata.threadID);
|
|
114
|
+
}
|
|
115
|
+
function stampCodexSessionIdentity(input) {
|
|
116
|
+
const { headers, metadata, body } = input, turnMetadata = JSON.stringify({
|
|
117
|
+
session_id: metadata.threadID,
|
|
118
|
+
thread_id: metadata.threadID,
|
|
119
|
+
thread_source: "user",
|
|
120
|
+
turn_id: metadata.turnID,
|
|
121
|
+
sandbox: CODEX_SANDBOX,
|
|
122
|
+
turn_started_at_unix_ms: metadata.turnStartedAt,
|
|
123
|
+
request_kind: "turn",
|
|
124
|
+
window_id: metadata.windowID
|
|
125
|
+
});
|
|
126
|
+
stampCodexThreadHeaders(headers, metadata);
|
|
127
|
+
headers.set("x-codex-turn-metadata", turnMetadata);
|
|
128
|
+
if (body)
|
|
129
|
+
body.prompt_cache_key = metadata.threadID;
|
|
130
|
+
return turnMetadata;
|
|
131
|
+
}
|
|
132
|
+
function stampCodexBodyMetadata(input, turnMetadata, useResponsesLite = !1) {
|
|
133
|
+
if (!input.body)
|
|
134
|
+
return;
|
|
135
|
+
const prior = input.body.client_metadata, clientMetadata = {
|
|
136
|
+
...typeof prior === "object" && prior !== null ? prior : {},
|
|
137
|
+
"x-codex-installation-id": input.installationID,
|
|
138
|
+
"x-codex-window-id": input.metadata.windowID
|
|
139
|
+
};
|
|
140
|
+
if (input.websocket) {
|
|
141
|
+
clientMetadata["x-codex-turn-metadata"] = turnMetadata;
|
|
142
|
+
clientMetadata["x-codex-ws-stream-request-start-ms"] = String((input.now ?? Date.now)());
|
|
143
|
+
if (useResponsesLite)
|
|
144
|
+
clientMetadata.ws_request_header_x_openai_internal_codex_responses_lite = "true";
|
|
145
|
+
}
|
|
146
|
+
input.body.client_metadata = clientMetadata;
|
|
147
|
+
}
|
|
148
|
+
export function prepareCodexRequest(input) {
|
|
149
|
+
const agent = input.headers.get(OPENAI_AGENT_HEADER);
|
|
150
|
+
input.headers.delete(OPENAI_AGENT_HEADER);
|
|
151
|
+
const metadata = input.metadata;
|
|
152
|
+
if (!metadata)
|
|
153
|
+
return { init: input.init };
|
|
154
|
+
const body = parseJsonObject(input.init?.body), now = input.runtime?.now ?? Date.now;
|
|
155
|
+
if (!input.skipTurnUpdate) {
|
|
156
|
+
if (!input.websocket)
|
|
157
|
+
updateHttpTurnMetadata(metadata, body, input.runtime);
|
|
158
|
+
else if (!metadata.turnStartedAt)
|
|
159
|
+
metadata.turnStartedAt = now();
|
|
160
|
+
if (!metadata.turnStartedAt)
|
|
161
|
+
metadata.turnStartedAt = now();
|
|
162
|
+
}
|
|
163
|
+
applyCodexClientHeaders(input);
|
|
164
|
+
const stamp = { ...input, metadata, body, now }, turnMetadata = stampCodexSessionIdentity(stamp);
|
|
165
|
+
if (input.dumpSessionID)
|
|
166
|
+
input.headers.set(DUMP_SESSION_HEADER, input.dumpSessionID);
|
|
167
|
+
if (!body)
|
|
168
|
+
return { init: input.init };
|
|
169
|
+
const useResponsesLite = input.responsesLite && supportsResponsesLite(body.model);
|
|
170
|
+
shapeCodexBody(body, input.headers, {
|
|
171
|
+
useResponsesLite,
|
|
172
|
+
websocket: input.websocket,
|
|
173
|
+
restoreCallStatus: !input.skipCallStatusRestore,
|
|
174
|
+
instructions: input.preserveInstructions ? "preserve" : "move",
|
|
175
|
+
beforePlacement: () => input.applyEffort?.(body, metadata, agent),
|
|
176
|
+
rewriteLite: input.rewriteLite
|
|
177
|
+
});
|
|
178
|
+
stampCodexBodyMetadata(stamp, turnMetadata, useResponsesLite);
|
|
179
|
+
return {
|
|
180
|
+
init: { ...input.init, body: JSON.stringify(orderCodexBody(body)) }
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
export function normalizeCodexTool(tool) {
|
|
184
|
+
if (!isRecord(tool) || tool.type !== "function")
|
|
185
|
+
return tool;
|
|
186
|
+
const parameters = isRecord(tool.parameters) && "$schema" in tool.parameters ? (() => {
|
|
187
|
+
const { $schema: _schema, ...rest } = tool.parameters;
|
|
188
|
+
return rest;
|
|
189
|
+
})() : tool.parameters, { type, name, description, strict, parameters: _p, ...extra } = tool;
|
|
190
|
+
return {
|
|
191
|
+
type,
|
|
192
|
+
name,
|
|
193
|
+
description,
|
|
194
|
+
strict: strict ?? !1,
|
|
195
|
+
parameters,
|
|
196
|
+
...extra
|
|
197
|
+
};
|
|
198
|
+
}
|