@nyte-ai/ai 0.0.0-stage → 0.0.19
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/LICENSE +21 -0
- package/README.md +170 -2
- package/THIRD-PARTY-NOTICES.md +866 -0
- package/dist/chunks/account-limits-cache-031vfpt3.js +37 -0
- package/dist/chunks/account-limits-cache-09vs98g6.js +41 -0
- package/dist/chunks/account-limits-cache-0af5gqeg.js +15 -0
- package/dist/chunks/account-limits-cache-0yd6bde8.js +103 -0
- package/dist/chunks/account-limits-cache-1jv43fhh.js +22 -0
- package/dist/chunks/account-limits-cache-3ykqmnj5.js +88 -0
- package/dist/chunks/account-limits-cache-4b8ckwqw.js +293 -0
- package/dist/chunks/account-limits-cache-4fn5w63p.js +295 -0
- package/dist/chunks/account-limits-cache-4hptgd2h.js +49 -0
- package/dist/chunks/account-limits-cache-53e64mhx.js +417 -0
- package/dist/chunks/account-limits-cache-5jdhn0e1.js +562 -0
- package/dist/chunks/account-limits-cache-5rx2pfm5.js +8 -0
- package/dist/chunks/account-limits-cache-5ygxyyss.js +19 -0
- package/dist/chunks/account-limits-cache-6250ykn6.js +21 -0
- package/dist/chunks/account-limits-cache-6x05n06z.js +49 -0
- package/dist/chunks/account-limits-cache-736tdyme.js +6 -0
- package/dist/chunks/account-limits-cache-75smws02.js +213 -0
- package/dist/chunks/account-limits-cache-7z9s8j16.js +139 -0
- package/dist/chunks/account-limits-cache-8137j3zp.js +37 -0
- package/dist/chunks/account-limits-cache-8qzk56vj.js +160 -0
- package/dist/chunks/account-limits-cache-8s8bz4dr.js +36 -0
- package/dist/chunks/account-limits-cache-8vzx8k6r.js +166 -0
- package/dist/chunks/account-limits-cache-8wfqg73s.js +135 -0
- package/dist/chunks/account-limits-cache-90c9c2eb.js +50 -0
- package/dist/chunks/account-limits-cache-9wqk28n5.js +25 -0
- package/dist/chunks/account-limits-cache-a1jyaq00.js +56 -0
- package/dist/chunks/account-limits-cache-a558rjbg.js +138 -0
- package/dist/chunks/account-limits-cache-a55e14fr.js +70 -0
- package/dist/chunks/account-limits-cache-a6cgeagz.js +77 -0
- package/dist/chunks/account-limits-cache-ag5b8dja.js +38 -0
- package/dist/chunks/account-limits-cache-b0x2sfya.js +45 -0
- package/dist/chunks/account-limits-cache-b23sbrke.js +26 -0
- package/dist/chunks/account-limits-cache-b4edaybk.js +8 -0
- package/dist/chunks/account-limits-cache-bsknrh6t.js +74 -0
- package/dist/chunks/account-limits-cache-csbxvam7.js +12 -0
- package/dist/chunks/account-limits-cache-cw7q7vfy.js +293 -0
- package/dist/chunks/account-limits-cache-d1ypzqzp.js +27 -0
- package/dist/chunks/account-limits-cache-d2a51dka.js +17 -0
- package/dist/chunks/account-limits-cache-dejeygdt.js +114 -0
- package/dist/chunks/account-limits-cache-eejm0vth.js +11 -0
- package/dist/chunks/account-limits-cache-ehy0ze2b.js +33 -0
- package/dist/chunks/account-limits-cache-emg5b4hj.js +53 -0
- package/dist/chunks/account-limits-cache-eqwweapz.js +6 -0
- package/dist/chunks/account-limits-cache-eyx1jcxc.js +8 -0
- package/dist/chunks/account-limits-cache-f9z00x8c.js +36 -0
- package/dist/chunks/account-limits-cache-fbkaq46e.js +113 -0
- package/dist/chunks/account-limits-cache-fdwad56n.js +399 -0
- package/dist/chunks/account-limits-cache-fht68jp2.js +22 -0
- package/dist/chunks/account-limits-cache-fp03ztsw.js +17 -0
- package/dist/chunks/account-limits-cache-fsktnetm.js +69 -0
- package/dist/chunks/account-limits-cache-fvadc36m.js +110 -0
- package/dist/chunks/account-limits-cache-gknnm1kv.js +13 -0
- package/dist/chunks/account-limits-cache-gqsrbky9.js +40 -0
- package/dist/chunks/account-limits-cache-gr671dr2.js +0 -0
- package/dist/chunks/account-limits-cache-gs8a3fhw.js +32 -0
- package/dist/chunks/account-limits-cache-gsa5tzck.js +37 -0
- package/dist/chunks/account-limits-cache-h92bzz1j.js +235 -0
- package/dist/chunks/account-limits-cache-hemxtapd.js +142 -0
- package/dist/chunks/account-limits-cache-hj1h48sc.js +92 -0
- package/dist/chunks/account-limits-cache-hj3ek3ty.js +128 -0
- package/dist/chunks/account-limits-cache-hwehc67r.js +509 -0
- package/dist/chunks/account-limits-cache-hyzn1jmk.js +46 -0
- package/dist/chunks/account-limits-cache-j2bt392s.js +63 -0
- package/dist/chunks/account-limits-cache-k0pkzhbx.js +74 -0
- package/dist/chunks/account-limits-cache-kjx405q0.js +277 -0
- package/dist/chunks/account-limits-cache-ks1sjym9.js +37 -0
- package/dist/chunks/account-limits-cache-me1x57bs.js +89 -0
- package/dist/chunks/account-limits-cache-n3yk6g5c.js +314 -0
- package/dist/chunks/account-limits-cache-nbhht7xz.js +72 -0
- package/dist/chunks/account-limits-cache-nbkyhs6v.js +42 -0
- package/dist/chunks/account-limits-cache-nn9jebsj.js +26 -0
- package/dist/chunks/account-limits-cache-nxkprk3g.js +13 -0
- package/dist/chunks/account-limits-cache-nyy770yd.js +38 -0
- package/dist/chunks/account-limits-cache-pfa86y8e.js +45 -0
- package/dist/chunks/account-limits-cache-pfr14mcn.js +59 -0
- package/dist/chunks/account-limits-cache-q1ebtvet.js +8 -0
- package/dist/chunks/account-limits-cache-q63mc41j.js +51 -0
- package/dist/chunks/account-limits-cache-re8hpzwn.js +104 -0
- package/dist/chunks/account-limits-cache-rz8p1g5y.js +9 -0
- package/dist/chunks/account-limits-cache-skbfmzqe.js +7 -0
- package/dist/chunks/account-limits-cache-tc38g0ca.js +20 -0
- package/dist/chunks/account-limits-cache-v4n30az2.js +24 -0
- package/dist/chunks/account-limits-cache-vwgfz727.js +281 -0
- package/dist/chunks/account-limits-cache-wtg64ez7.js +69 -0
- package/dist/chunks/account-limits-cache-x9fvb3s5.js +8 -0
- package/dist/chunks/account-limits-cache-xds88kxd.js +209 -0
- package/dist/chunks/account-limits-cache-xz65wyd1.js +428 -0
- package/dist/chunks/account-limits-cache-ydq8p8qp.js +39 -0
- package/dist/chunks/account-limits-cache-ykbqsvv6.js +134 -0
- package/dist/chunks/account-limits-cache-yzyp0c2h.js +251 -0
- package/dist/chunks/account-limits-cache-za42x8a3.js +25 -0
- package/dist/chunks/account-limits-cache-zcbkmrvy.js +79 -0
- package/dist/chunks/account-limits-cache-zgzptd0z.js +62 -0
- package/dist/chunks/account-limits-cache-zn01kscn.js +252 -0
- package/dist/chunks/account-limits-cache-zpjmeyt0.js +113 -0
- package/dist/chunks/account-limits-cache-zqdb4yh4.js +8 -0
- package/dist/src/account-limits-cache.d.ts +16 -0
- package/dist/src/account-limits-cache.js +7 -0
- package/dist/src/api/anthropic-client.d.ts +25 -0
- package/dist/src/api/anthropic-client.js +30 -0
- package/dist/src/api/anthropic-convert.d.ts +17 -0
- package/dist/src/api/anthropic-convert.js +14 -0
- package/dist/src/api/anthropic-events.d.ts +101 -0
- package/dist/src/api/anthropic-events.js +11 -0
- package/dist/src/api/anthropic-messages.d.ts +88 -0
- package/dist/src/api/anthropic-messages.js +578 -0
- package/dist/src/api/anthropic-messages.lazy.d.ts +2 -0
- package/dist/src/api/anthropic-messages.lazy.js +11 -0
- package/dist/src/api/assistant-stream.d.ts +23 -0
- package/dist/src/api/assistant-stream.js +15 -0
- package/dist/src/api/claude-code.d.ts +12 -0
- package/dist/src/api/claude-code.js +12 -0
- package/dist/src/api/cloudflare.d.ts +8 -0
- package/dist/src/api/cloudflare.js +11 -0
- package/dist/src/api/constrained-sampling.d.ts +24 -0
- package/dist/src/api/constrained-sampling.js +16 -0
- package/dist/src/api/deferred.d.ts +7 -0
- package/dist/src/api/deferred.js +10 -0
- package/dist/src/api/github-copilot-headers.d.ts +15 -0
- package/dist/src/api/github-copilot-headers.js +12 -0
- package/dist/src/api/google-generative-ai.d.ts +22 -0
- package/dist/src/api/google-generative-ai.js +583 -0
- package/dist/src/api/google-generative-ai.lazy.d.ts +2 -0
- package/dist/src/api/google-generative-ai.lazy.js +11 -0
- package/dist/src/api/lazy.d.ts +18 -0
- package/dist/src/api/lazy.js +12 -0
- package/dist/src/api/openai-codex-compact.d.ts +14 -0
- package/dist/src/api/openai-codex-compact.js +389 -0
- package/dist/src/api/openai-codex-compaction-error.d.ts +7 -0
- package/dist/src/api/openai-codex-compaction-error.js +6 -0
- package/dist/src/api/openai-codex-protocol.d.ts +125 -0
- package/dist/src/api/openai-codex-protocol.js +48 -0
- package/dist/src/api/openai-codex-responses.d.ts +4 -0
- package/dist/src/api/openai-codex-responses.js +175 -0
- package/dist/src/api/openai-codex-responses.lazy.d.ts +2 -0
- package/dist/src/api/openai-codex-responses.lazy.js +11 -0
- package/dist/src/api/openai-codex-websocket.d.ts +13 -0
- package/dist/src/api/openai-codex-websocket.js +37 -0
- package/dist/src/api/openai-codex-wire.d.ts +44 -0
- package/dist/src/api/openai-codex-wire.js +34 -0
- package/dist/src/api/openai-compact.d.ts +9 -0
- package/dist/src/api/openai-compact.js +12 -0
- package/dist/src/api/openai-completions-convert.d.ts +58 -0
- package/dist/src/api/openai-completions-convert.js +21 -0
- package/dist/src/api/openai-completions-params.d.ts +29 -0
- package/dist/src/api/openai-completions-params.js +20 -0
- package/dist/src/api/openai-completions-reasoning.d.ts +54 -0
- package/dist/src/api/openai-completions-reasoning.js +22 -0
- package/dist/src/api/openai-completions.d.ts +22 -0
- package/dist/src/api/openai-completions.js +484 -0
- package/dist/src/api/openai-completions.lazy.d.ts +5 -0
- package/dist/src/api/openai-completions.lazy.js +11 -0
- package/dist/src/api/openai-prompt-cache.d.ts +1 -0
- package/dist/src/api/openai-prompt-cache.js +6 -0
- package/dist/src/api/openai-responses-convert.d.ts +58 -0
- package/dist/src/api/openai-responses-convert.js +16 -0
- package/dist/src/api/openai-responses-events.d.ts +379 -0
- package/dist/src/api/openai-responses-events.js +12 -0
- package/dist/src/api/openai-responses-stream.d.ts +36 -0
- package/dist/src/api/openai-responses-stream.js +25 -0
- package/dist/src/api/openai-responses.d.ts +18 -0
- package/dist/src/api/openai-responses.js +276 -0
- package/dist/src/api/openai-responses.lazy.d.ts +2 -0
- package/dist/src/api/openai-responses.lazy.js +11 -0
- package/dist/src/api/simple-options.d.ts +17 -0
- package/dist/src/api/simple-options.js +18 -0
- package/dist/src/api/token-count.d.ts +5 -0
- package/dist/src/api/token-count.js +8 -0
- package/dist/src/api/transform-messages.d.ts +9 -0
- package/dist/src/api/transform-messages.js +6 -0
- package/dist/src/api-options.d.ts +27 -0
- package/dist/src/api-options.js +0 -0
- package/dist/src/auth/context.d.ts +11 -0
- package/dist/src/auth/context.js +6 -0
- package/dist/src/auth/credential-store.d.ts +17 -0
- package/dist/src/auth/credential-store.js +7 -0
- package/dist/src/auth/helpers.d.ts +24 -0
- package/dist/src/auth/helpers.js +8 -0
- package/dist/src/auth/oauth/anthropic.d.ts +7 -0
- package/dist/src/auth/oauth/anthropic.js +12 -0
- package/dist/src/auth/oauth/authorization-input.d.ts +14 -0
- package/dist/src/auth/oauth/authorization-input.js +6 -0
- package/dist/src/auth/oauth/device-code.d.ts +29 -0
- package/dist/src/auth/oauth/device-code.js +9 -0
- package/dist/src/auth/oauth/github-copilot.d.ts +23 -0
- package/dist/src/auth/oauth/github-copilot.js +12 -0
- package/dist/src/auth/oauth/load.d.ts +14 -0
- package/dist/src/auth/oauth/load.js +10 -0
- package/dist/src/auth/oauth/oauth-page.d.ts +13 -0
- package/dist/src/auth/oauth/oauth-page.js +8 -0
- package/dist/src/auth/oauth/openai-codex.d.ts +10 -0
- package/dist/src/auth/oauth/openai-codex.js +18 -0
- package/dist/src/auth/oauth/pkce.d.ts +12 -0
- package/dist/src/auth/oauth/pkce.js +6 -0
- package/dist/src/auth/resolve.d.ts +38 -0
- package/dist/src/auth/resolve.js +12 -0
- package/dist/src/auth/store.d.ts +29 -0
- package/dist/src/auth/store.js +10 -0
- package/dist/src/auth/types.d.ts +291 -0
- package/dist/src/auth/types.js +8 -0
- package/dist/src/auth/verify.d.ts +13 -0
- package/dist/src/auth/verify.js +7 -0
- package/dist/src/bun-oauth.d.ts +2 -0
- package/dist/src/bun-oauth.js +25 -0
- package/dist/src/env-api-keys.d.ts +32 -0
- package/dist/src/env-api-keys.js +27 -0
- package/dist/src/file-models-store.d.ts +18 -0
- package/dist/src/file-models-store.js +9 -0
- package/dist/src/index.d.ts +62 -0
- package/dist/src/index.js +372 -0
- package/dist/src/model-capabilities.d.ts +21 -0
- package/dist/src/model-capabilities.js +14 -0
- package/dist/src/model-pricing.d.ts +6 -0
- package/dist/src/model-pricing.js +10 -0
- package/dist/src/model-variants.d.ts +21 -0
- package/dist/src/model-variants.js +19 -0
- package/dist/src/models-refresh.d.ts +27 -0
- package/dist/src/models-refresh.js +9 -0
- package/dist/src/models-store.d.ts +31 -0
- package/dist/src/models-store.js +6 -0
- package/dist/src/models-types.d.ts +206 -0
- package/dist/src/models-types.js +0 -0
- package/dist/src/models.d.ts +7 -0
- package/dist/src/models.js +44 -0
- package/dist/src/prompt-cache.d.ts +5 -0
- package/dist/src/prompt-cache.js +9 -0
- package/dist/src/provider.d.ts +23 -0
- package/dist/src/provider.js +14 -0
- package/dist/src/providers/account-limits.d.ts +13 -0
- package/dist/src/providers/account-limits.js +8 -0
- package/dist/src/providers/anthropic-limits.d.ts +9 -0
- package/dist/src/providers/anthropic-limits.js +10 -0
- package/dist/src/providers/anthropic.d.ts +2 -0
- package/dist/src/providers/anthropic.js +25 -0
- package/dist/src/providers/github-copilot-catalog.d.ts +5 -0
- package/dist/src/providers/github-copilot-catalog.js +7 -0
- package/dist/src/providers/github-copilot.d.ts +2 -0
- package/dist/src/providers/github-copilot.js +23 -0
- package/dist/src/providers/nyte-catalog.d.ts +15 -0
- package/dist/src/providers/nyte-catalog.js +63 -0
- package/dist/src/providers/openai-codex-limits.d.ts +8 -0
- package/dist/src/providers/openai-codex-limits.js +14 -0
- package/dist/src/providers/openai-codex.d.ts +2 -0
- package/dist/src/providers/openai-codex.js +23 -0
- package/dist/src/providers/openai.d.ts +2 -0
- package/dist/src/providers/openai.js +19 -0
- package/dist/src/providers/opencode-go.d.ts +5 -0
- package/dist/src/providers/opencode-go.js +22 -0
- package/dist/src/providers/opencode-headers.d.ts +5 -0
- package/dist/src/providers/opencode-headers.js +6 -0
- package/dist/src/providers/opencode.d.ts +14 -0
- package/dist/src/providers/opencode.js +23 -0
- package/dist/src/providers/openrouter.d.ts +2 -0
- package/dist/src/providers/openrouter.js +19 -0
- package/dist/src/providers/vercel-ai-gateway.d.ts +3 -0
- package/dist/src/providers/vercel-ai-gateway.js +19 -0
- package/dist/src/session-resources.d.ts +9 -0
- package/dist/src/session-resources.js +10 -0
- package/dist/src/types.d.ts +210 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils/abort.d.ts +12 -0
- package/dist/src/utils/abort.js +10 -0
- package/dist/src/utils/deferred-tools.d.ts +11 -0
- package/dist/src/utils/deferred-tools.js +6 -0
- package/dist/src/utils/diagnostics.d.ts +11 -0
- package/dist/src/utils/diagnostics.js +12 -0
- package/dist/src/utils/error-body.d.ts +26 -0
- package/dist/src/utils/error-body.js +10 -0
- package/dist/src/utils/estimate.d.ts +20 -0
- package/dist/src/utils/estimate.js +14 -0
- package/dist/src/utils/event-stream.d.ts +22 -0
- package/dist/src/utils/event-stream.js +11 -0
- package/dist/src/utils/failure.d.ts +49 -0
- package/dist/src/utils/failure.js +10 -0
- package/dist/src/utils/fifo-queue.d.ts +11 -0
- package/dist/src/utils/fifo-queue.js +6 -0
- package/dist/src/utils/hash.d.ts +5 -0
- package/dist/src/utils/hash.js +6 -0
- package/dist/src/utils/headers.d.ts +12 -0
- package/dist/src/utils/headers.js +14 -0
- package/dist/src/utils/json-parse.d.ts +33 -0
- package/dist/src/utils/json-parse.js +12 -0
- package/dist/src/utils/node-http-proxy.d.ts +6 -0
- package/dist/src/utils/node-http-proxy.js +9 -0
- package/dist/src/utils/nyte-home.d.ts +2 -0
- package/dist/src/utils/nyte-home.js +6 -0
- package/dist/src/utils/nyte-user-agent.d.ts +1 -0
- package/dist/src/utils/nyte-user-agent.js +6 -0
- package/dist/src/utils/overflow.d.ts +18 -0
- package/dist/src/utils/overflow.js +9 -0
- package/dist/src/utils/provider-env.d.ts +9 -0
- package/dist/src/utils/provider-env.js +6 -0
- package/dist/src/utils/provider-retry.d.ts +22 -0
- package/dist/src/utils/provider-retry.js +9 -0
- package/dist/src/utils/retry.d.ts +66 -0
- package/dist/src/utils/retry.js +18 -0
- package/dist/src/utils/sanitize-unicode.d.ts +24 -0
- package/dist/src/utils/sanitize-unicode.js +6 -0
- package/dist/src/utils/sse.d.ts +21 -0
- package/dist/src/utils/sse.js +6 -0
- package/dist/src/utils/text.d.ts +5 -0
- package/dist/src/utils/text.js +10 -0
- package/dist/src/utils/transcript.d.ts +5 -0
- package/dist/src/utils/transcript.js +36 -0
- package/dist/src/utils/typebox-helpers.d.ts +19 -0
- package/dist/src/utils/typebox-helpers.js +6 -0
- package/dist/src/utils/uuid.d.ts +2 -0
- package/dist/src/utils/uuid.js +6 -0
- package/dist/src/utils/validation.d.ts +13 -0
- package/dist/src/utils/validation.js +8 -0
- package/package.json +152 -3
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyServiceTierPricing2
|
|
3
|
+
} from "../../chunks/account-limits-cache-f9z00x8c.js";
|
|
4
|
+
import {
|
|
5
|
+
calculateCost2
|
|
6
|
+
} from "../../chunks/account-limits-cache-zgzptd0z.js";
|
|
7
|
+
import {
|
|
8
|
+
reportsQuotaExhaustion2
|
|
9
|
+
} from "../../chunks/account-limits-cache-xds88kxd.js";
|
|
10
|
+
import {
|
|
11
|
+
headersToRecord2
|
|
12
|
+
} from "../../chunks/account-limits-cache-ag5b8dja.js";
|
|
13
|
+
import"../../chunks/account-limits-cache-j2bt392s.js";
|
|
14
|
+
import {
|
|
15
|
+
RetryDelayExceededError2,
|
|
16
|
+
retryProviderRequest2
|
|
17
|
+
} from "../../chunks/account-limits-cache-nbhht7xz.js";
|
|
18
|
+
import {
|
|
19
|
+
normalizeContext2,
|
|
20
|
+
resolveTranscript2
|
|
21
|
+
} from "../../chunks/account-limits-cache-6250ykn6.js";
|
|
22
|
+
import"../../chunks/account-limits-cache-zcbkmrvy.js";
|
|
23
|
+
import"../../chunks/account-limits-cache-nn9jebsj.js";
|
|
24
|
+
import"../../chunks/account-limits-cache-a6cgeagz.js";
|
|
25
|
+
import {
|
|
26
|
+
emptyCost2
|
|
27
|
+
} from "../../chunks/account-limits-cache-fsktnetm.js";
|
|
28
|
+
import {
|
|
29
|
+
OpenAICodexCompactionError2
|
|
30
|
+
} from "../../chunks/account-limits-cache-eejm0vth.js";
|
|
31
|
+
import"../../chunks/account-limits-cache-gknnm1kv.js";
|
|
32
|
+
import {
|
|
33
|
+
CodexFrameJson2,
|
|
34
|
+
readRecord2,
|
|
35
|
+
TERMINAL_RESPONSE_TYPES2,
|
|
36
|
+
normalizeTimeoutMs2,
|
|
37
|
+
resolveCodexUrl2,
|
|
38
|
+
extractAccountId2,
|
|
39
|
+
buildSSEHeaders2
|
|
40
|
+
} from "../../chunks/account-limits-cache-fvadc36m.js";
|
|
41
|
+
import"../../chunks/account-limits-cache-ehy0ze2b.js";
|
|
42
|
+
import"../../chunks/account-limits-cache-hj3ek3ty.js";
|
|
43
|
+
import"../../chunks/account-limits-cache-8s8bz4dr.js";
|
|
44
|
+
import"../../chunks/account-limits-cache-9wqk28n5.js";
|
|
45
|
+
import"../../chunks/account-limits-cache-me1x57bs.js";
|
|
46
|
+
import"../../chunks/account-limits-cache-b4edaybk.js";
|
|
47
|
+
import"../../chunks/account-limits-cache-h92bzz1j.js";
|
|
48
|
+
import"../../chunks/account-limits-cache-0af5gqeg.js";
|
|
49
|
+
import"../../chunks/account-limits-cache-eqwweapz.js";
|
|
50
|
+
import"../../chunks/account-limits-cache-8qzk56vj.js";
|
|
51
|
+
import"../../chunks/account-limits-cache-n3yk6g5c.js";
|
|
52
|
+
import {
|
|
53
|
+
DEFAULT_MAX_RETRIES2,
|
|
54
|
+
compressRequestBodyZstd2,
|
|
55
|
+
buildRequestBody2,
|
|
56
|
+
resolveCodexServiceTier2,
|
|
57
|
+
CodexRequestError2,
|
|
58
|
+
retryableCodexRequest2,
|
|
59
|
+
CodexProtocolError2,
|
|
60
|
+
extractCodexEventError2,
|
|
61
|
+
parseSSE2
|
|
62
|
+
} from "../../chunks/account-limits-cache-vwgfz727.js";
|
|
63
|
+
import {
|
|
64
|
+
clampOpenAIPromptCacheKey2
|
|
65
|
+
} from "../../chunks/account-limits-cache-csbxvam7.js";
|
|
66
|
+
import"../../chunks/account-limits-cache-fbkaq46e.js";
|
|
67
|
+
import"../../chunks/account-limits-cache-736tdyme.js";
|
|
68
|
+
import"../../chunks/account-limits-cache-a558rjbg.js";
|
|
69
|
+
import {
|
|
70
|
+
withPriorityTier2
|
|
71
|
+
} from "../../chunks/account-limits-cache-53e64mhx.js";
|
|
72
|
+
|
|
73
|
+
// src/api/openai-codex-compact.ts
|
|
74
|
+
import { Type } from "typebox";
|
|
75
|
+
import { Value } from "typebox/value";
|
|
76
|
+
var DEFAULT_COMPACT_IDLE_TIMEOUT_MS = 300000;
|
|
77
|
+
var RETRYABLE_COMPACTION_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
|
|
78
|
+
var RETRYABLE_COMPACTION_CODES = new Set([
|
|
79
|
+
"server_error",
|
|
80
|
+
"rate_limit_exceeded",
|
|
81
|
+
"overloaded"
|
|
82
|
+
]);
|
|
83
|
+
var compactTokenCount = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });
|
|
84
|
+
var codexCompactionItem = Type.Object({
|
|
85
|
+
type: Type.Literal("compaction"),
|
|
86
|
+
id: Type.Optional(Type.Union([Type.String({ minLength: 1 }), Type.Null()])),
|
|
87
|
+
encrypted_content: Type.String({ minLength: 1 })
|
|
88
|
+
});
|
|
89
|
+
var compactUsage = Type.Union([
|
|
90
|
+
Type.Null(),
|
|
91
|
+
Type.Object({
|
|
92
|
+
input_tokens: compactTokenCount,
|
|
93
|
+
output_tokens: compactTokenCount,
|
|
94
|
+
total_tokens: compactTokenCount,
|
|
95
|
+
input_tokens_details: Type.Optional(Type.Union([
|
|
96
|
+
Type.Null(),
|
|
97
|
+
Type.Object({
|
|
98
|
+
cached_tokens: Type.Optional(compactTokenCount),
|
|
99
|
+
cache_write_tokens: Type.Optional(compactTokenCount)
|
|
100
|
+
})
|
|
101
|
+
])),
|
|
102
|
+
output_tokens_details: Type.Optional(Type.Union([
|
|
103
|
+
Type.Null(),
|
|
104
|
+
Type.Object({
|
|
105
|
+
reasoning_tokens: Type.Optional(compactTokenCount)
|
|
106
|
+
})
|
|
107
|
+
]))
|
|
108
|
+
})
|
|
109
|
+
]);
|
|
110
|
+
var compactServiceTier = Type.Union([
|
|
111
|
+
Type.Null(),
|
|
112
|
+
Type.Literal("auto"),
|
|
113
|
+
Type.Literal("default"),
|
|
114
|
+
Type.Literal("flex"),
|
|
115
|
+
Type.Literal("scale"),
|
|
116
|
+
Type.Literal("priority")
|
|
117
|
+
]);
|
|
118
|
+
var codexCompactCompleted = Type.Object({
|
|
119
|
+
id: Type.String({ minLength: 1 }),
|
|
120
|
+
status: Type.Optional(Type.Literal("completed")),
|
|
121
|
+
error: Type.Optional(Type.Null()),
|
|
122
|
+
incomplete_details: Type.Optional(Type.Null()),
|
|
123
|
+
usage: Type.Optional(compactUsage),
|
|
124
|
+
service_tier: Type.Optional(compactServiceTier)
|
|
125
|
+
});
|
|
126
|
+
var codexRetainedMessages = Type.Array(Type.Object({
|
|
127
|
+
role: Type.Literal("user"),
|
|
128
|
+
content: Type.Union([
|
|
129
|
+
Type.String(),
|
|
130
|
+
Type.Array(Type.Union([
|
|
131
|
+
Type.Object({ type: Type.Literal("input_text"), text: Type.String() }),
|
|
132
|
+
Type.Object({
|
|
133
|
+
type: Type.Literal("input_image"),
|
|
134
|
+
image_url: Type.String(),
|
|
135
|
+
detail: Type.Literal("auto")
|
|
136
|
+
})
|
|
137
|
+
]))
|
|
138
|
+
])
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
class CompactionStepError extends Error {
|
|
142
|
+
retryable;
|
|
143
|
+
constructor(reason, retryable) {
|
|
144
|
+
super(reason);
|
|
145
|
+
this.retryable = retryable;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function addUsage(total, next) {
|
|
149
|
+
if (total === undefined)
|
|
150
|
+
return next;
|
|
151
|
+
return {
|
|
152
|
+
input: total.input + next.input,
|
|
153
|
+
output: total.output + next.output,
|
|
154
|
+
cacheRead: total.cacheRead + next.cacheRead,
|
|
155
|
+
cacheWrite: total.cacheWrite + next.cacheWrite,
|
|
156
|
+
reasoning: (total.reasoning ?? 0) + (next.reasoning ?? 0),
|
|
157
|
+
totalTokens: total.totalTokens + next.totalTokens,
|
|
158
|
+
cost: {
|
|
159
|
+
input: total.cost.input + next.cost.input,
|
|
160
|
+
output: total.cost.output + next.cost.output,
|
|
161
|
+
cacheRead: total.cost.cacheRead + next.cost.cacheRead,
|
|
162
|
+
cacheWrite: total.cost.cacheWrite + next.cost.cacheWrite,
|
|
163
|
+
total: total.cost.total + next.cost.total
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function terminalUsage(terminal, model, options) {
|
|
168
|
+
const tokens = terminal?.usage;
|
|
169
|
+
if (tokens !== undefined && !Value.Check(compactUsage, tokens)) {
|
|
170
|
+
throw new CompactionStepError("Invalid terminal usage", false);
|
|
171
|
+
}
|
|
172
|
+
if (!tokens)
|
|
173
|
+
return;
|
|
174
|
+
const cached = tokens.input_tokens_details?.cached_tokens ?? 0;
|
|
175
|
+
const written = tokens.input_tokens_details?.cache_write_tokens ?? 0;
|
|
176
|
+
const usage = {
|
|
177
|
+
input: Math.max(0, tokens.input_tokens - cached - written),
|
|
178
|
+
output: tokens.output_tokens,
|
|
179
|
+
cacheRead: cached,
|
|
180
|
+
cacheWrite: written,
|
|
181
|
+
reasoning: tokens.output_tokens_details?.reasoning_tokens ?? 0,
|
|
182
|
+
totalTokens: tokens.total_tokens,
|
|
183
|
+
cost: emptyCost2()
|
|
184
|
+
};
|
|
185
|
+
const serviceTier = terminal?.service_tier;
|
|
186
|
+
calculateCost2(model, usage);
|
|
187
|
+
applyServiceTierPricing2(usage, resolveCodexServiceTier2(Value.Check(compactServiceTier, serviceTier) ? serviceTier : undefined, options?.serviceTier), model);
|
|
188
|
+
return usage;
|
|
189
|
+
}
|
|
190
|
+
function readOutputItem(item, output) {
|
|
191
|
+
if (!Value.Check(CodexFrameJson2, item))
|
|
192
|
+
return { kind: "invalid", reason: "Invalid output item" };
|
|
193
|
+
if (item.type !== "compaction" || output.kind === "invalid")
|
|
194
|
+
return output;
|
|
195
|
+
if (!Value.Check(codexCompactionItem, item)) {
|
|
196
|
+
return { kind: "invalid", reason: "Invalid compaction item" };
|
|
197
|
+
}
|
|
198
|
+
if (output.kind === "checkpoint") {
|
|
199
|
+
return { kind: "invalid", reason: "Expected exactly one compaction item" };
|
|
200
|
+
}
|
|
201
|
+
const checkpoint = {
|
|
202
|
+
type: item.type,
|
|
203
|
+
encrypted_content: item.encrypted_content
|
|
204
|
+
};
|
|
205
|
+
if (item.id !== undefined)
|
|
206
|
+
checkpoint.id = item.id;
|
|
207
|
+
return { kind: "checkpoint", item: checkpoint };
|
|
208
|
+
}
|
|
209
|
+
async function compactOpenAICodexContext(model, context, requested) {
|
|
210
|
+
const options = withPriorityTier2(requested);
|
|
211
|
+
const apiKey = options?.apiKey;
|
|
212
|
+
if (!apiKey)
|
|
213
|
+
throw new Error(`No API key for provider: ${model.provider}`);
|
|
214
|
+
const accountId = extractAccountId2(apiKey);
|
|
215
|
+
const cacheSessionId = options?.cacheRetention === "none" ? undefined : clampOpenAIPromptCacheKey2(options?.sessionId);
|
|
216
|
+
const request = buildRequestBody2(model, resolveTranscript2(normalizeContext2(context), model.compat?.supportsMidConvoSystemMessages), options, cacheSessionId);
|
|
217
|
+
const input = [
|
|
218
|
+
...request.input ?? [],
|
|
219
|
+
{ type: "compaction_trigger" }
|
|
220
|
+
];
|
|
221
|
+
request.input = input;
|
|
222
|
+
await options?.onPayload?.(request, model);
|
|
223
|
+
const userInputs = input.filter((item) => ("role" in item) && item.role === "user");
|
|
224
|
+
if (!Value.Check(codexRetainedMessages, userInputs)) {
|
|
225
|
+
throw new Error("Invalid Codex compaction user input");
|
|
226
|
+
}
|
|
227
|
+
const headers = buildSSEHeaders2(model.headers, options?.headers, accountId, apiKey, cacheSessionId);
|
|
228
|
+
const betaFeatures = new Set((headers.get("x-codex-beta-features") ?? "").split(",").filter(Boolean));
|
|
229
|
+
betaFeatures.add("remote_compaction_v2");
|
|
230
|
+
headers.set("x-codex-beta-features", [...betaFeatures].join(","));
|
|
231
|
+
const encodedBody = JSON.stringify(request);
|
|
232
|
+
const compressedBody = compressRequestBodyZstd2(encodedBody);
|
|
233
|
+
if (compressedBody)
|
|
234
|
+
headers.set("content-encoding", "zstd");
|
|
235
|
+
const url = new URL(resolveCodexUrl2(model.baseUrl));
|
|
236
|
+
const timeoutMs = normalizeTimeoutMs2(options?.timeoutMs) ?? DEFAULT_COMPACT_IDLE_TIMEOUT_MS;
|
|
237
|
+
const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES2;
|
|
238
|
+
if (!Number.isSafeInteger(maxRetries) || maxRetries < 0) {
|
|
239
|
+
throw new Error("Invalid Codex compaction maxRetries");
|
|
240
|
+
}
|
|
241
|
+
let response;
|
|
242
|
+
let usage;
|
|
243
|
+
const attempt = async () => {
|
|
244
|
+
response = undefined;
|
|
245
|
+
const headerTimeout = new AbortController;
|
|
246
|
+
const signal = options?.signal ? AbortSignal.any([options.signal, headerTimeout.signal]) : headerTimeout.signal;
|
|
247
|
+
const timer = timeoutMs > 0 ? setTimeout(() => headerTimeout.abort(), timeoutMs) : undefined;
|
|
248
|
+
let retryable = true;
|
|
249
|
+
let output = { kind: "missing" };
|
|
250
|
+
try {
|
|
251
|
+
response = await (options?.fetch ?? globalThis.fetch)(url, {
|
|
252
|
+
method: "POST",
|
|
253
|
+
headers,
|
|
254
|
+
body: compressedBody ?? encodedBody,
|
|
255
|
+
signal
|
|
256
|
+
});
|
|
257
|
+
clearTimeout(timer);
|
|
258
|
+
retryable = false;
|
|
259
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord2(response.headers) }, model);
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
retryable = RETRYABLE_COMPACTION_STATUSES.has(response.status);
|
|
262
|
+
if (response.status === 429) {
|
|
263
|
+
const bodyTimer = timeoutMs > 0 ? setTimeout(() => headerTimeout.abort(), timeoutMs) : undefined;
|
|
264
|
+
try {
|
|
265
|
+
retryable = !reportsQuotaExhaustion2(await response.text());
|
|
266
|
+
} finally {
|
|
267
|
+
clearTimeout(bodyTimer);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
throw new CompactionStepError("HTTP request failed", retryable);
|
|
271
|
+
}
|
|
272
|
+
retryable = true;
|
|
273
|
+
for await (const event of parseSSE2(response, signal, timeoutMs)) {
|
|
274
|
+
if (event.type === "response.output_item.done") {
|
|
275
|
+
output = readOutputItem(event.item, output);
|
|
276
|
+
} else if (TERMINAL_RESPONSE_TYPES2.has(event.type) || event.type === "response.cancelled") {
|
|
277
|
+
retryable = false;
|
|
278
|
+
const terminal = readRecord2(event.response);
|
|
279
|
+
const reported = terminalUsage(terminal, model, options);
|
|
280
|
+
if (reported)
|
|
281
|
+
usage = addUsage(usage, reported);
|
|
282
|
+
if (event.type !== "response.completed") {
|
|
283
|
+
throw new CompactionStepError(output.kind === "invalid" ? output.reason : "Compaction did not complete", event.type === "response.failed" && RETRYABLE_COMPACTION_CODES.has(readRecord2(terminal?.error)?.code));
|
|
284
|
+
}
|
|
285
|
+
if (!Value.Check(codexCompactCompleted, event.response)) {
|
|
286
|
+
throw new CompactionStepError("Invalid completed response or usage", false);
|
|
287
|
+
}
|
|
288
|
+
if (output.kind !== "checkpoint") {
|
|
289
|
+
throw new CompactionStepError(output.kind === "invalid" ? output.reason : "Expected exactly one compaction item", false);
|
|
290
|
+
}
|
|
291
|
+
const data = [...retainCodexUserInputs(userInputs), output.item];
|
|
292
|
+
return usage === undefined ? { data } : { data, usage };
|
|
293
|
+
} else if (event.type === "error") {
|
|
294
|
+
throw new CompactionStepError("Compaction did not complete", RETRYABLE_COMPACTION_CODES.has(extractCodexEventError2(event).code));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
throw new CompactionStepError(output.kind === "invalid" ? output.reason : "Stream ended before response.completed", retryable);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (options?.signal?.aborted)
|
|
300
|
+
throw error;
|
|
301
|
+
const failure = headerTimeout.signal.aborted ? response ? "HTTP error body timed out" : "Response headers timed out" : error instanceof DOMException && error.name === "TimeoutError" ? "Stream idle timeout" : error instanceof CodexProtocolError2 ? "Invalid SSE stream" : error instanceof CompactionStepError ? error.message : "Request failed";
|
|
302
|
+
const stepRetryable = error instanceof CompactionStepError ? error.retryable : retryable && !(error instanceof CodexProtocolError2);
|
|
303
|
+
throw new CodexRequestError2(failure, response?.ok === false ? response.status : undefined, response?.headers, stepRetryable && output.kind !== "invalid");
|
|
304
|
+
} finally {
|
|
305
|
+
clearTimeout(timer);
|
|
306
|
+
await response?.body?.cancel().catch(() => {
|
|
307
|
+
return;
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
try {
|
|
312
|
+
return await retryProviderRequest2(attempt, {
|
|
313
|
+
maxRetries,
|
|
314
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
315
|
+
signal: options?.signal,
|
|
316
|
+
retryable: retryableCodexRequest2
|
|
317
|
+
});
|
|
318
|
+
} catch (error) {
|
|
319
|
+
const failure = options?.signal?.aborted ? "Request was aborted" : error instanceof RetryDelayExceededError2 || error instanceof CodexRequestError2 ? error.message : "Request failed";
|
|
320
|
+
const requestId = response?.headers.get("x-request-id") ?? response?.headers.get("x-openai-request-id");
|
|
321
|
+
const safeRequestId = requestId && /^[a-zA-Z0-9_-]{1,200}$/.test(requestId) ? requestId : undefined;
|
|
322
|
+
throw new OpenAICodexCompactionError2(`Codex compaction: ${failure}; ${url.origin}${url.pathname}${response ? `; HTTP ${response.status}` : ""}${safeRequestId ? `; request ID ${safeRequestId}` : ""}`, usage);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
var IMAGE_TOKENS = 1844;
|
|
326
|
+
function truncateMiddle(text, remaining, encoder) {
|
|
327
|
+
const bytes = encoder.encode(text);
|
|
328
|
+
const budget = remaining * 4;
|
|
329
|
+
let left = budget / 2;
|
|
330
|
+
let right = bytes.length - budget / 2;
|
|
331
|
+
while (left > 0 && (bytes[left] & 192) === 128)
|
|
332
|
+
left--;
|
|
333
|
+
while (right < bytes.length && (bytes[right] & 192) === 128)
|
|
334
|
+
right++;
|
|
335
|
+
const decoder = new TextDecoder;
|
|
336
|
+
return {
|
|
337
|
+
type: "input_text",
|
|
338
|
+
text: `${decoder.decode(bytes.subarray(0, left))}…${Math.ceil((bytes.length - budget) / 4)} tokens truncated…${decoder.decode(bytes.subarray(right))}`
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function retainCodexUserInputs(messages) {
|
|
342
|
+
let remaining = 64000;
|
|
343
|
+
const retained = [];
|
|
344
|
+
const encoder = new TextEncoder;
|
|
345
|
+
for (const message of messages.toReversed()) {
|
|
346
|
+
if (remaining === 0)
|
|
347
|
+
break;
|
|
348
|
+
const content = Array.isArray(message.content) ? message.content : [{ type: "input_text", text: message.content }];
|
|
349
|
+
const budgeted = content.map((part) => ({
|
|
350
|
+
part,
|
|
351
|
+
tokens: part.type === "input_image" ? IMAGE_TOKENS : Math.ceil(encoder.encode(part.text).length / 4)
|
|
352
|
+
}));
|
|
353
|
+
const cost = Math.max(1, budgeted.reduce((sum, item) => sum + item.tokens, 0));
|
|
354
|
+
if (cost <= remaining) {
|
|
355
|
+
retained.push({ type: "message", role: "user", content });
|
|
356
|
+
remaining -= cost;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
const hasImages = content.some((part) => part.type === "input_image");
|
|
360
|
+
const parts = [];
|
|
361
|
+
for (const { part, tokens } of hasImages ? budgeted.toReversed() : budgeted) {
|
|
362
|
+
if (part.type === "input_image") {
|
|
363
|
+
if (tokens <= remaining) {
|
|
364
|
+
parts.push(part);
|
|
365
|
+
remaining -= tokens;
|
|
366
|
+
} else
|
|
367
|
+
remaining = 0;
|
|
368
|
+
} else if (remaining > 0) {
|
|
369
|
+
if (tokens <= remaining) {
|
|
370
|
+
if (part.text)
|
|
371
|
+
parts.push(part);
|
|
372
|
+
remaining -= tokens;
|
|
373
|
+
} else {
|
|
374
|
+
parts.push(truncateMiddle(part.text, remaining, encoder));
|
|
375
|
+
remaining = 0;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (hasImages)
|
|
380
|
+
parts.reverse();
|
|
381
|
+
if (parts.length > 0)
|
|
382
|
+
retained.push({ type: "message", role: "user", content: parts });
|
|
383
|
+
remaining = 0;
|
|
384
|
+
}
|
|
385
|
+
return retained.reverse();
|
|
386
|
+
}
|
|
387
|
+
export {
|
|
388
|
+
compactOpenAICodexContext
|
|
389
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Usage } from "../types.ts";
|
|
2
|
+
/** Sanitized failure, kept out of the client module so `instanceof` checks stay cheap to import. */
|
|
3
|
+
export declare class OpenAICodexCompactionError extends Error {
|
|
4
|
+
/** Sum of valid terminal usage across attempts; undefined means none was reported. */
|
|
5
|
+
readonly usage: Usage | undefined;
|
|
6
|
+
constructor(message: string, usage?: Usage);
|
|
7
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Codex Responses protocol both transports and compaction share: request options and body,
|
|
3
|
+
* error types, frame decoding and the mapping of Codex frames onto Responses stream events.
|
|
4
|
+
*/
|
|
5
|
+
import type { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
|
|
6
|
+
import type { AccountLimits, AssistantMessage, Model, StreamOptions, TranscriptContext } from "../types.ts";
|
|
7
|
+
import { type CodexFrame } from "./openai-codex-wire.ts";
|
|
8
|
+
import { type ResponsesInput, type ResponsesTool } from "./openai-responses-convert.ts";
|
|
9
|
+
import type { ResponsesServiceTier } from "./openai-responses-events.ts";
|
|
10
|
+
import type { OpenAIResponsesStreamOptions } from "./openai-responses-stream.ts";
|
|
11
|
+
export interface OpenAICodexResponsesOptions extends StreamOptions {
|
|
12
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
13
|
+
reasoningSummary?: "auto" | "concise" | "detailed" | "off" | "on" | null;
|
|
14
|
+
serviceTier?: ResponseCreateParamsStreaming["service_tier"];
|
|
15
|
+
textVerbosity?: "low" | "medium" | "high";
|
|
16
|
+
toolChoice?: "auto" | "none" | "required";
|
|
17
|
+
}
|
|
18
|
+
export interface RequestBody {
|
|
19
|
+
model: string;
|
|
20
|
+
store?: boolean;
|
|
21
|
+
stream?: boolean;
|
|
22
|
+
instructions?: string;
|
|
23
|
+
previous_response_id?: string;
|
|
24
|
+
input?: ResponsesInput;
|
|
25
|
+
tools?: ResponsesTool[];
|
|
26
|
+
tool_choice?: OpenAICodexResponsesOptions["toolChoice"];
|
|
27
|
+
parallel_tool_calls?: boolean;
|
|
28
|
+
temperature?: number;
|
|
29
|
+
reasoning?: {
|
|
30
|
+
effort?: string;
|
|
31
|
+
summary?: string;
|
|
32
|
+
};
|
|
33
|
+
service_tier?: ResponseCreateParamsStreaming["service_tier"];
|
|
34
|
+
text?: {
|
|
35
|
+
verbosity?: string;
|
|
36
|
+
};
|
|
37
|
+
include?: string[];
|
|
38
|
+
prompt_cache_key?: string;
|
|
39
|
+
}
|
|
40
|
+
/** One Codex request as both transports send it. */
|
|
41
|
+
export interface CodexRequest {
|
|
42
|
+
readonly model: Model<"openai-codex-responses">;
|
|
43
|
+
readonly body: RequestBody;
|
|
44
|
+
readonly accountId: string;
|
|
45
|
+
/** The caller's session id, unless prompt caching is off; it keys the WebSocket cache. */
|
|
46
|
+
readonly cacheSessionId: string | undefined;
|
|
47
|
+
readonly grammarToolInputProperties: ReadonlyMap<string, string>;
|
|
48
|
+
/** Bounds the SSE header wait and WebSocket idleness, from `options.timeoutMs`. */
|
|
49
|
+
readonly timeoutMs: number | undefined;
|
|
50
|
+
/** Bounds the WebSocket open handshake, from `options.websocketConnectTimeoutMs`. */
|
|
51
|
+
readonly connectTimeoutMs: number | undefined;
|
|
52
|
+
readonly options: OpenAICodexResponsesOptions | undefined;
|
|
53
|
+
}
|
|
54
|
+
interface CodexEventError {
|
|
55
|
+
code?: string;
|
|
56
|
+
message?: string;
|
|
57
|
+
}
|
|
58
|
+
export declare const DEFAULT_MAX_RETRIES = 0;
|
|
59
|
+
export declare const CODEX_TOOL_CALL_PROVIDERS: ReadonlySet<string>;
|
|
60
|
+
/** `bodyJson` as zstd, or null outside Node and Bun, where `node:zlib` is unavailable. */
|
|
61
|
+
export declare function compressRequestBodyZstd(bodyJson: string): Uint8Array<ArrayBuffer> | null;
|
|
62
|
+
/**
|
|
63
|
+
* The Codex request body. Later system messages anchor their own tool additions, and
|
|
64
|
+
* `addedToolNames` on a tool result only loads request-list tools the transcript did not anchor,
|
|
65
|
+
* so nothing is declared twice.
|
|
66
|
+
*/
|
|
67
|
+
export declare function buildRequestBody(model: Model<"openai-codex-responses">, context: TranscriptContext, options: OpenAICodexResponsesOptions | undefined, cacheSessionId: string | undefined, grammarToolInputProperties?: ReadonlyMap<string, string>): RequestBody;
|
|
68
|
+
/** Codex answers `default` for a flex or priority request it served at that tier. */
|
|
69
|
+
export declare function resolveCodexServiceTier(responseServiceTier: ResponsesServiceTier | undefined, requestServiceTier: ResponseCreateParamsStreaming["service_tier"] | undefined): ResponsesServiceTier | undefined;
|
|
70
|
+
/** How the shared Responses stream processor reads a Codex response. */
|
|
71
|
+
export declare function codexStreamOptions(request: CodexRequest): OpenAIResponsesStreamOptions;
|
|
72
|
+
/**
|
|
73
|
+
* A failed Codex request attempt, carrying `status` and `headers` so the shared provider retry
|
|
74
|
+
* policy applies; `retryable` vetoes a retry the policy would allow, such as a 429 that is quota
|
|
75
|
+
* exhaustion, which waiting does not lift.
|
|
76
|
+
*/
|
|
77
|
+
export declare class CodexRequestError extends Error {
|
|
78
|
+
readonly status: number | undefined;
|
|
79
|
+
readonly headers: Headers | undefined;
|
|
80
|
+
readonly retryable: boolean;
|
|
81
|
+
constructor(message: string, status: number | undefined, headers: Headers | undefined, retryable: boolean, options?: {
|
|
82
|
+
cause?: unknown;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** The retry veto for Codex attempts: only a {@link CodexRequestError} marked retryable runs again. */
|
|
86
|
+
export declare function retryableCodexRequest(error: unknown): boolean;
|
|
87
|
+
/** An error the Codex API reported in a frame, with its machine-readable code. */
|
|
88
|
+
export declare class CodexApiError extends Error {
|
|
89
|
+
readonly code?: string;
|
|
90
|
+
readonly payload?: unknown;
|
|
91
|
+
constructor(message: string, options?: {
|
|
92
|
+
code?: string;
|
|
93
|
+
payload?: unknown;
|
|
94
|
+
cause?: unknown;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** A frame that is not valid Codex protocol JSON. */
|
|
98
|
+
export declare class CodexProtocolError extends Error {
|
|
99
|
+
readonly payload?: unknown;
|
|
100
|
+
constructor(message: string, options?: {
|
|
101
|
+
payload?: unknown;
|
|
102
|
+
cause?: unknown;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** The code and message of an `error` frame, flat or nested under `error`. */
|
|
106
|
+
export declare function extractCodexEventError(event: CodexFrame): CodexEventError;
|
|
107
|
+
/**
|
|
108
|
+
* Maps Codex frames onto Responses stream events. `codex.rate_limits` frames go to
|
|
109
|
+
* `onAccountLimits`, whose failures never fail the assistant stream. Every terminal frame
|
|
110
|
+
* becomes `response.completed` carrying its status, so the shared finalizer accounts for usage
|
|
111
|
+
* before a `response.failed` frame throws a {@link CodexApiError} that keeps the Codex error
|
|
112
|
+
* code, which tells API failures from retryable transport failures.
|
|
113
|
+
*/
|
|
114
|
+
export declare function mapCodexEvents(events: AsyncIterable<CodexFrame>, output: AssistantMessage, onAccountLimits?: (limits: AccountLimits) => void | Promise<void>): AsyncGenerator<unknown>;
|
|
115
|
+
/** Codex frames from an SSE response body; `[DONE]` and empty data are skipped. */
|
|
116
|
+
export declare function parseSSE(response: Response, signal?: AbortSignal, idleTimeoutMs?: number): AsyncGenerator<CodexFrame>;
|
|
117
|
+
/**
|
|
118
|
+
* The message of a failed Codex HTTP response, and a usage-limit explanation for a 429 or a
|
|
119
|
+
* usage-limit error code, with the plan and reset time when the body gives them.
|
|
120
|
+
*/
|
|
121
|
+
export declare function parseErrorResponse(raw: string, response: Response): {
|
|
122
|
+
message: string;
|
|
123
|
+
friendlyMessage?: string;
|
|
124
|
+
};
|
|
125
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_MAX_RETRIES2,
|
|
3
|
+
CODEX_TOOL_CALL_PROVIDERS2,
|
|
4
|
+
compressRequestBodyZstd2,
|
|
5
|
+
buildRequestBody2,
|
|
6
|
+
resolveCodexServiceTier2,
|
|
7
|
+
codexStreamOptions2,
|
|
8
|
+
CodexRequestError2,
|
|
9
|
+
retryableCodexRequest2,
|
|
10
|
+
CodexApiError2,
|
|
11
|
+
CodexProtocolError2,
|
|
12
|
+
extractCodexEventError2,
|
|
13
|
+
mapCodexEvents2,
|
|
14
|
+
parseSSE2,
|
|
15
|
+
parseErrorResponse2
|
|
16
|
+
} from "../../chunks/account-limits-cache-vwgfz727.js";
|
|
17
|
+
import"../../chunks/account-limits-cache-n3yk6g5c.js";
|
|
18
|
+
import"../../chunks/account-limits-cache-8qzk56vj.js";
|
|
19
|
+
import"../../chunks/account-limits-cache-h92bzz1j.js";
|
|
20
|
+
import"../../chunks/account-limits-cache-eqwweapz.js";
|
|
21
|
+
import"../../chunks/account-limits-cache-me1x57bs.js";
|
|
22
|
+
import"../../chunks/account-limits-cache-0af5gqeg.js";
|
|
23
|
+
import"../../chunks/account-limits-cache-8s8bz4dr.js";
|
|
24
|
+
import"../../chunks/account-limits-cache-hj3ek3ty.js";
|
|
25
|
+
import"../../chunks/account-limits-cache-fvadc36m.js";
|
|
26
|
+
import"../../chunks/account-limits-cache-ehy0ze2b.js";
|
|
27
|
+
import"../../chunks/account-limits-cache-b4edaybk.js";
|
|
28
|
+
import"../../chunks/account-limits-cache-6250ykn6.js";
|
|
29
|
+
import"../../chunks/account-limits-cache-gknnm1kv.js";
|
|
30
|
+
import"../../chunks/account-limits-cache-ag5b8dja.js";
|
|
31
|
+
import"../../chunks/account-limits-cache-9wqk28n5.js";
|
|
32
|
+
import"../../chunks/account-limits-cache-f9z00x8c.js";
|
|
33
|
+
export {
|
|
34
|
+
CODEX_TOOL_CALL_PROVIDERS2 as CODEX_TOOL_CALL_PROVIDERS,
|
|
35
|
+
CodexApiError2 as CodexApiError,
|
|
36
|
+
CodexProtocolError2 as CodexProtocolError,
|
|
37
|
+
CodexRequestError2 as CodexRequestError,
|
|
38
|
+
DEFAULT_MAX_RETRIES2 as DEFAULT_MAX_RETRIES,
|
|
39
|
+
buildRequestBody2 as buildRequestBody,
|
|
40
|
+
codexStreamOptions2 as codexStreamOptions,
|
|
41
|
+
compressRequestBodyZstd2 as compressRequestBodyZstd,
|
|
42
|
+
extractCodexEventError2 as extractCodexEventError,
|
|
43
|
+
mapCodexEvents2 as mapCodexEvents,
|
|
44
|
+
parseErrorResponse2 as parseErrorResponse,
|
|
45
|
+
parseSSE2 as parseSSE,
|
|
46
|
+
resolveCodexServiceTier2 as resolveCodexServiceTier,
|
|
47
|
+
retryableCodexRequest2 as retryableCodexRequest
|
|
48
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SimpleStreamOptions, StreamFunction } from "../types.ts";
|
|
2
|
+
import { type OpenAICodexResponsesOptions } from "./openai-codex-protocol.ts";
|
|
3
|
+
export declare const stream: StreamFunction<"openai-codex-responses", OpenAICodexResponsesOptions>;
|
|
4
|
+
export declare const streamSimple: StreamFunction<"openai-codex-responses", SimpleStreamOptions>;
|