@nyte-ai/ai 0.0.0-stage → 0.0.18
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 +800 -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-c7v93krb.js +235 -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-ghe9ne4j.js +69 -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-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-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,92 @@
|
|
|
1
|
+
// src/api/openai-completions-reasoning.ts
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { Value } from "typebox/value";
|
|
4
|
+
var reasoningDetailFields = {
|
|
5
|
+
id: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
6
|
+
format: Type.Optional(Type.String()),
|
|
7
|
+
index: Type.Optional(Type.Number())
|
|
8
|
+
};
|
|
9
|
+
var OpenAIReasoningDetailSchema2 = Type.Union([
|
|
10
|
+
Type.Object({
|
|
11
|
+
...reasoningDetailFields,
|
|
12
|
+
type: Type.Literal("reasoning.summary"),
|
|
13
|
+
summary: Type.String()
|
|
14
|
+
}),
|
|
15
|
+
Type.Object({
|
|
16
|
+
...reasoningDetailFields,
|
|
17
|
+
type: Type.Literal("reasoning.encrypted"),
|
|
18
|
+
data: Type.String()
|
|
19
|
+
}),
|
|
20
|
+
Type.Object({
|
|
21
|
+
...reasoningDetailFields,
|
|
22
|
+
type: Type.Literal("reasoning.text"),
|
|
23
|
+
text: Type.String(),
|
|
24
|
+
signature: Type.Optional(Type.Union([Type.String(), Type.Null()]))
|
|
25
|
+
})
|
|
26
|
+
]);
|
|
27
|
+
var OpenAIReasoningDetailsSchema = Type.Array(OpenAIReasoningDetailSchema2, { minItems: 1 });
|
|
28
|
+
function parseOpenAIReasoningDetails2(signature) {
|
|
29
|
+
if (!signature)
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(signature);
|
|
33
|
+
return Value.Check(OpenAIReasoningDetailsSchema, parsed) ? parsed : undefined;
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function parseLegacyEncryptedReasoningDetail2(signature) {
|
|
39
|
+
if (!signature)
|
|
40
|
+
return;
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(signature);
|
|
43
|
+
return Value.Check(OpenAIReasoningDetailSchema2, parsed) && parsed.type === "reasoning.encrypted" && parsed.id !== undefined && parsed.id !== null && parsed.id.length > 0 && parsed.data.length > 0 ? parsed : undefined;
|
|
44
|
+
} catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function fillMissingCommonReasoningDetailFields(target, source) {
|
|
49
|
+
target.id ??= source.id;
|
|
50
|
+
target.format ||= source.format;
|
|
51
|
+
target.index ??= source.index;
|
|
52
|
+
}
|
|
53
|
+
function appendOpenAIReasoningDetail2(details, detail) {
|
|
54
|
+
const lastDetail = details.at(-1);
|
|
55
|
+
if (detail.type === "reasoning.text" && lastDetail?.type === "reasoning.text") {
|
|
56
|
+
lastDetail.text += detail.text;
|
|
57
|
+
lastDetail.signature ||= detail.signature;
|
|
58
|
+
fillMissingCommonReasoningDetailFields(lastDetail, detail);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (detail.type === "reasoning.summary" && lastDetail?.type === "reasoning.summary") {
|
|
62
|
+
lastDetail.summary += detail.summary;
|
|
63
|
+
fillMissingCommonReasoningDetailFields(lastDetail, detail);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
details.push({ ...detail });
|
|
67
|
+
}
|
|
68
|
+
var OPENAI_COMPLETIONS_REASONING_FIELDS = [
|
|
69
|
+
"reasoning",
|
|
70
|
+
"reasoning_content",
|
|
71
|
+
"reasoning_text"
|
|
72
|
+
];
|
|
73
|
+
var OpenAICompletionsReasoningFieldSchema2 = Type.Enum(OPENAI_COMPLETIONS_REASONING_FIELDS);
|
|
74
|
+
var CopilotReasoningOpaqueSchema2 = Type.Object({
|
|
75
|
+
reasoning_opaque: Type.String({ minLength: 1 })
|
|
76
|
+
});
|
|
77
|
+
var REASONING_DELTA_SCHEMAS2 = ["reasoning_content", "reasoning", "reasoning_text"].map((field) => ({ field, schema: Type.Object({ [field]: Type.String({ minLength: 1 }) }) }));
|
|
78
|
+
var ReasoningDetailsDeltaSchema2 = Type.Object({
|
|
79
|
+
reasoning_details: Type.Array(Type.Unknown())
|
|
80
|
+
});
|
|
81
|
+
function parseCopilotReasoningOpaque2(signature) {
|
|
82
|
+
if (!signature)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
const parsed = JSON.parse(signature);
|
|
86
|
+
return Value.Check(CopilotReasoningOpaqueSchema2, parsed) ? parsed.reasoning_opaque : undefined;
|
|
87
|
+
} catch {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { OpenAIReasoningDetailSchema2, parseOpenAIReasoningDetails2, parseLegacyEncryptedReasoningDetail2, appendOpenAIReasoningDetail2, OpenAICompletionsReasoningFieldSchema2, CopilotReasoningOpaqueSchema2, REASONING_DELTA_SCHEMAS2, ReasoningDetailsDeltaSchema2, parseCopilotReasoningOpaque2 };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_CODEX_BASE_URL2,
|
|
3
|
+
extractAccountId2,
|
|
4
|
+
buildBaseCodexHeaders2
|
|
5
|
+
} from "./account-limits-cache-fvadc36m.js";
|
|
6
|
+
import {
|
|
7
|
+
limitWindow2,
|
|
8
|
+
fetchAccountUsage2
|
|
9
|
+
} from "./account-limits-cache-ehy0ze2b.js";
|
|
10
|
+
|
|
11
|
+
// src/providers/openai-codex-limits.ts
|
|
12
|
+
import { Type } from "typebox";
|
|
13
|
+
import { Value } from "typebox/value";
|
|
14
|
+
var OptionalJsonNumber = Type.Optional(Type.Union([Type.Number(), Type.Null()]));
|
|
15
|
+
var CodexUsageWindowSchema = Type.Object({
|
|
16
|
+
used_percent: Type.Number(),
|
|
17
|
+
limit_window_seconds: OptionalJsonNumber,
|
|
18
|
+
reset_at: OptionalJsonNumber
|
|
19
|
+
});
|
|
20
|
+
var CodexUsageResponseSchema = Type.Object({
|
|
21
|
+
rate_limit: Type.Optional(Type.Union([
|
|
22
|
+
Type.Object({
|
|
23
|
+
primary_window: Type.Optional(Type.Unknown()),
|
|
24
|
+
secondary_window: Type.Optional(Type.Unknown())
|
|
25
|
+
}),
|
|
26
|
+
Type.Null()
|
|
27
|
+
]))
|
|
28
|
+
});
|
|
29
|
+
var CodexPlanSchema = Type.Object({ plan_type: Type.String() });
|
|
30
|
+
var CodexRateLimitsFrameSchema = Type.Object({
|
|
31
|
+
type: Type.Literal("codex.rate_limits"),
|
|
32
|
+
plan_type: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
33
|
+
rate_limits: Type.Optional(Type.Union([
|
|
34
|
+
Type.Object({
|
|
35
|
+
primary: Type.Optional(Type.Unknown()),
|
|
36
|
+
secondary: Type.Optional(Type.Unknown())
|
|
37
|
+
}),
|
|
38
|
+
Type.Null()
|
|
39
|
+
]))
|
|
40
|
+
});
|
|
41
|
+
var CodexRateLimitWindowSchema = Type.Object({
|
|
42
|
+
used_percent: Type.Number(),
|
|
43
|
+
window_minutes: OptionalJsonNumber,
|
|
44
|
+
reset_at: OptionalJsonNumber
|
|
45
|
+
});
|
|
46
|
+
var FIVE_HOURS_SECONDS = 5 * 60 * 60;
|
|
47
|
+
var WEEK_SECONDS = 7 * 24 * 60 * 60;
|
|
48
|
+
function durationLabel(seconds) {
|
|
49
|
+
if (seconds === WEEK_SECONDS)
|
|
50
|
+
return "Weekly";
|
|
51
|
+
if (seconds % (24 * 60 * 60) === 0)
|
|
52
|
+
return `${String(seconds / (24 * 60 * 60))}-day`;
|
|
53
|
+
if (seconds % (60 * 60) === 0)
|
|
54
|
+
return `${String(seconds / (60 * 60))}-hour`;
|
|
55
|
+
return `${String(Math.round(seconds / 60))}-minute`;
|
|
56
|
+
}
|
|
57
|
+
function codexLimitWindow(fallbackId, usedPercent, windowSeconds, resetAtSeconds) {
|
|
58
|
+
const id = windowSeconds === FIVE_HOURS_SECONDS ? "five_hour" : windowSeconds === WEEK_SECONDS ? "seven_day" : fallbackId;
|
|
59
|
+
const label = windowSeconds === undefined || windowSeconds === null ? fallbackId === "primary" ? "Primary" : "Secondary" : durationLabel(windowSeconds);
|
|
60
|
+
return limitWindow2(id, label, usedPercent, resetAtSeconds === undefined || resetAtSeconds === null ? undefined : resetAtSeconds * 1000, windowSeconds === undefined || windowSeconds === null ? undefined : windowSeconds / 60);
|
|
61
|
+
}
|
|
62
|
+
function minutesWindow(fallbackId, window) {
|
|
63
|
+
if (!window.window_minutes)
|
|
64
|
+
return;
|
|
65
|
+
return codexLimitWindow(fallbackId, window.used_percent, window.window_minutes * 60, window.reset_at);
|
|
66
|
+
}
|
|
67
|
+
function accountLimits(providerId, windows, plan) {
|
|
68
|
+
if (windows.length === 0)
|
|
69
|
+
return;
|
|
70
|
+
const limits = { providerId, windows, observedAt: Date.now() };
|
|
71
|
+
if (plan)
|
|
72
|
+
limits.plan = plan;
|
|
73
|
+
return limits;
|
|
74
|
+
}
|
|
75
|
+
function codexFrameLimits2(frame, providerId) {
|
|
76
|
+
if (!Value.Check(CodexRateLimitsFrameSchema, frame))
|
|
77
|
+
return;
|
|
78
|
+
const windows = [];
|
|
79
|
+
for (const id of ["primary", "secondary"]) {
|
|
80
|
+
const window = frame.rate_limits?.[id];
|
|
81
|
+
const parsed = Value.Check(CodexRateLimitWindowSchema, window) ? minutesWindow(id, window) : undefined;
|
|
82
|
+
if (parsed !== undefined)
|
|
83
|
+
windows.push(parsed);
|
|
84
|
+
}
|
|
85
|
+
return accountLimits(providerId, windows, frame.plan_type);
|
|
86
|
+
}
|
|
87
|
+
function codexHeaderLimits2(headers, providerId) {
|
|
88
|
+
const windows = [];
|
|
89
|
+
for (const id of ["primary", "secondary"]) {
|
|
90
|
+
const usedPercent = Number(headers[`x-codex-${id}-used-percent`]);
|
|
91
|
+
if (!Number.isFinite(usedPercent))
|
|
92
|
+
continue;
|
|
93
|
+
const resetHeader = headers[`x-codex-${id}-reset-at`];
|
|
94
|
+
const resetAt = resetHeader ? Number(resetHeader) : Number.NaN;
|
|
95
|
+
const parsed = minutesWindow(id, {
|
|
96
|
+
used_percent: usedPercent,
|
|
97
|
+
window_minutes: Number(headers[`x-codex-${id}-window-minutes`]),
|
|
98
|
+
reset_at: Number.isFinite(resetAt) ? resetAt : null
|
|
99
|
+
});
|
|
100
|
+
if (parsed !== undefined)
|
|
101
|
+
windows.push(parsed);
|
|
102
|
+
}
|
|
103
|
+
return accountLimits(providerId, windows, headers["x-codex-plan-type"]);
|
|
104
|
+
}
|
|
105
|
+
async function fetchOpenAICodexAccountLimits2(model, options) {
|
|
106
|
+
const apiKey = options?.apiKey;
|
|
107
|
+
if (!apiKey)
|
|
108
|
+
throw new Error(`No API key for provider: ${model.provider}`);
|
|
109
|
+
const headers = buildBaseCodexHeaders2(model.headers, options?.headers, extractAccountId2(apiKey), apiKey);
|
|
110
|
+
headers.set("accept", "application/json");
|
|
111
|
+
const baseUrl = (model.baseUrl?.trim() || DEFAULT_CODEX_BASE_URL2).replace(/\/+$/, "").replace(/\/codex$/, "");
|
|
112
|
+
const decoded = await fetchAccountUsage2(`${baseUrl}/wham/usage`, headers, options, CodexUsageResponseSchema, "Codex");
|
|
113
|
+
const windows = [];
|
|
114
|
+
for (const [id, window] of [
|
|
115
|
+
["primary", decoded.rate_limit?.primary_window],
|
|
116
|
+
["secondary", decoded.rate_limit?.secondary_window]
|
|
117
|
+
]) {
|
|
118
|
+
if (!Value.Check(CodexUsageWindowSchema, window))
|
|
119
|
+
continue;
|
|
120
|
+
windows.push(codexLimitWindow(id, window.used_percent, window.limit_window_seconds, window.reset_at));
|
|
121
|
+
}
|
|
122
|
+
const limits = { providerId: model.provider, windows, observedAt: Date.now() };
|
|
123
|
+
if (Value.Check(CodexPlanSchema, decoded))
|
|
124
|
+
limits.plan = decoded.plan_type;
|
|
125
|
+
return limits;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { codexFrameLimits2, codexHeaderLimits2, fetchOpenAICodexAccountLimits2 };
|