@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,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getFastModeCostMultiplier2
|
|
3
|
+
} from "./account-limits-cache-f9z00x8c.js";
|
|
4
|
+
|
|
5
|
+
// src/model-variants.ts
|
|
6
|
+
var FAST_MODEL_SUFFIX2 = "-fast";
|
|
7
|
+
function fastModelId2(base) {
|
|
8
|
+
return `${base}${FAST_MODEL_SUFFIX2}`;
|
|
9
|
+
}
|
|
10
|
+
function supportsFastMode2(model) {
|
|
11
|
+
return model.variant === undefined && model.modes?.includes("fast") === true && getFastModeCostMultiplier2(model) !== undefined;
|
|
12
|
+
}
|
|
13
|
+
function withFastVariants2(models) {
|
|
14
|
+
const ids = new Set(models.map((model) => model.id));
|
|
15
|
+
return models.flatMap((model) => supportsFastMode2(model) && !ids.has(fastModelId2(model.id)) ? [
|
|
16
|
+
model,
|
|
17
|
+
{
|
|
18
|
+
...model,
|
|
19
|
+
id: fastModelId2(model.id),
|
|
20
|
+
name: `${model.name} Fast`,
|
|
21
|
+
variant: { mode: "fast", base: model.id }
|
|
22
|
+
}
|
|
23
|
+
] : [model]);
|
|
24
|
+
}
|
|
25
|
+
function baseModel2(model) {
|
|
26
|
+
return model.variant === undefined ? model : { ...model, id: model.variant.base, variant: undefined };
|
|
27
|
+
}
|
|
28
|
+
function providerIdentity2(model) {
|
|
29
|
+
return { provider: model.provider, api: model.api, model: model.variant?.base ?? model.id };
|
|
30
|
+
}
|
|
31
|
+
function providerRequest2(model, options) {
|
|
32
|
+
if (model.variant?.mode !== "fast")
|
|
33
|
+
return { model, options };
|
|
34
|
+
return { model: baseModel2(model), options: { ...options, fast: true } };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { FAST_MODEL_SUFFIX2, fastModelId2, supportsFastMode2, withFastVariants2, baseModel2, providerIdentity2, providerRequest2 };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openAICodexResponsesApi2
|
|
3
|
+
} from "./account-limits-cache-5rx2pfm5.js";
|
|
4
|
+
import {
|
|
5
|
+
fetchOpenAICodexAccountLimits2
|
|
6
|
+
} from "./account-limits-cache-hj3ek3ty.js";
|
|
7
|
+
import {
|
|
8
|
+
lazyOAuth2
|
|
9
|
+
} from "./account-limits-cache-6x05n06z.js";
|
|
10
|
+
import {
|
|
11
|
+
loadOpenAICodexOAuth2
|
|
12
|
+
} from "./account-limits-cache-v4n30az2.js";
|
|
13
|
+
import {
|
|
14
|
+
createProvider2
|
|
15
|
+
} from "./account-limits-cache-ykbqsvv6.js";
|
|
16
|
+
|
|
17
|
+
// src/providers/openai-codex.ts
|
|
18
|
+
function openaiCodexProvider2() {
|
|
19
|
+
return createProvider2({
|
|
20
|
+
id: "openai-codex",
|
|
21
|
+
name: "OpenAI Codex",
|
|
22
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
23
|
+
promptCache: {
|
|
24
|
+
minimumRetentionMs: { short: 5 * 60000, long: 5 * 60000 }
|
|
25
|
+
},
|
|
26
|
+
auth: {
|
|
27
|
+
oauth: lazyOAuth2({
|
|
28
|
+
name: "OpenAI (ChatGPT Plus/Pro)",
|
|
29
|
+
isSubscription: true,
|
|
30
|
+
load: loadOpenAICodexOAuth2
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
fetchAccountLimits: ({ auth, signal }) => fetchOpenAICodexAccountLimits2({
|
|
34
|
+
provider: "openai-codex",
|
|
35
|
+
baseUrl: auth.baseUrl ?? "https://chatgpt.com/backend-api"
|
|
36
|
+
}, { apiKey: auth.apiKey, headers: auth.headers, signal }),
|
|
37
|
+
api: { "openai-codex-responses": openAICodexResponsesApi2() }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { openaiCodexProvider2 };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/utils/hash.ts
|
|
2
|
+
function shortHash2(str) {
|
|
3
|
+
let h1 = 3735928559;
|
|
4
|
+
let h2 = 1103547991;
|
|
5
|
+
for (let i = 0;i < str.length; i++) {
|
|
6
|
+
const ch = str.charCodeAt(i);
|
|
7
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
8
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
9
|
+
}
|
|
10
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
11
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
12
|
+
return (h2 >>> 0).toString(36) + (h1 >>> 0).toString(36);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { shortHash2 };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getProviderEnvValue2
|
|
3
|
+
} from "./account-limits-cache-b23sbrke.js";
|
|
4
|
+
|
|
5
|
+
// src/utils/node-http-proxy.ts
|
|
6
|
+
var DEFAULT_PROXY_PORTS = new Map([
|
|
7
|
+
["ftp", 21],
|
|
8
|
+
["gopher", 70],
|
|
9
|
+
["http", 80],
|
|
10
|
+
["https", 443],
|
|
11
|
+
["ws", 80],
|
|
12
|
+
["wss", 443]
|
|
13
|
+
]);
|
|
14
|
+
function getProxyEnv(key, env) {
|
|
15
|
+
const lowercaseKey = key.toLowerCase();
|
|
16
|
+
const uppercaseKey = key.toUpperCase();
|
|
17
|
+
return env?.[lowercaseKey] || env?.[uppercaseKey] || getProviderEnvValue2(lowercaseKey) || getProviderEnvValue2(uppercaseKey) || "";
|
|
18
|
+
}
|
|
19
|
+
function parseProxyTargetUrl(targetUrl) {
|
|
20
|
+
if (targetUrl instanceof URL) {
|
|
21
|
+
return targetUrl;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
return new URL(targetUrl);
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function stripBrackets(host) {
|
|
30
|
+
return host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
|
|
31
|
+
}
|
|
32
|
+
function parseNoProxyEntry(entry) {
|
|
33
|
+
const trimmed = entry.trim().toLowerCase();
|
|
34
|
+
if (!trimmed)
|
|
35
|
+
return;
|
|
36
|
+
const bracketed = /^\[([^\]]*)\](.*)$/su.exec(trimmed);
|
|
37
|
+
if (bracketed) {
|
|
38
|
+
const [, host, rest] = bracketed;
|
|
39
|
+
const port = rest.startsWith(":") ? Number.parseInt(rest.slice(1), 10) : 0;
|
|
40
|
+
return { host, port: Number.isNaN(port) ? 0 : port };
|
|
41
|
+
}
|
|
42
|
+
const parts = trimmed.split(":");
|
|
43
|
+
if (parts.length !== 2)
|
|
44
|
+
return { host: trimmed, port: 0 };
|
|
45
|
+
const [host, portText] = parts;
|
|
46
|
+
const port = Number.parseInt(portText, 10);
|
|
47
|
+
return Number.isNaN(port) ? { host: trimmed, port: 0 } : { host, port };
|
|
48
|
+
}
|
|
49
|
+
function shouldProxyHostname(hostname, port, env) {
|
|
50
|
+
const noProxy = getProxyEnv("no_proxy", env).toLowerCase();
|
|
51
|
+
if (!noProxy) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (noProxy === "*") {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const targetHost = stripBrackets(hostname.toLowerCase());
|
|
58
|
+
return noProxy.split(/[,\s]/).every((entry) => {
|
|
59
|
+
const parsed = parseNoProxyEntry(entry);
|
|
60
|
+
if (!parsed || parsed.port && parsed.port !== port) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
const host = stripBrackets(parsed.host);
|
|
64
|
+
const domain = host.startsWith("*.") ? host.slice(2) : host.startsWith(".") || host.startsWith("*") ? host.slice(1) : host;
|
|
65
|
+
return !domain || targetHost !== domain && !targetHost.endsWith(`.${domain}`);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function getProxyForUrl(targetUrl, env) {
|
|
69
|
+
const parsedUrl = parseProxyTargetUrl(targetUrl);
|
|
70
|
+
if (!parsedUrl?.protocol || !parsedUrl.host) {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
const protocol = parsedUrl.protocol.split(":", 1)[0];
|
|
74
|
+
const hostname = stripBrackets(parsedUrl.hostname || parsedUrl.host.replace(/:\d*$/, ""));
|
|
75
|
+
const port = Number.parseInt(parsedUrl.port, 10) || DEFAULT_PROXY_PORTS.get(protocol) || 0;
|
|
76
|
+
if (!shouldProxyHostname(hostname, port, env)) {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
let proxy = getProxyEnv(`${protocol}_proxy`, env) || getProxyEnv("all_proxy", env);
|
|
80
|
+
if (proxy && !proxy.includes("://")) {
|
|
81
|
+
proxy = `${protocol}://${proxy}`;
|
|
82
|
+
}
|
|
83
|
+
return proxy;
|
|
84
|
+
}
|
|
85
|
+
var UNSUPPORTED_PROXY_PROTOCOL_MESSAGE2 = "Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.";
|
|
86
|
+
function resolveHttpProxyUrlForTarget2(targetUrl, env) {
|
|
87
|
+
const proxy = getProxyForUrl(targetUrl, env);
|
|
88
|
+
if (!proxy) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let proxyUrl;
|
|
92
|
+
try {
|
|
93
|
+
proxyUrl = new URL(proxy);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
throw new Error(`Invalid proxy URL ${JSON.stringify(proxy)}: ${error instanceof Error ? error.message : String(error)}`);
|
|
96
|
+
}
|
|
97
|
+
if (proxyUrl.protocol !== "http:" && proxyUrl.protocol !== "https:") {
|
|
98
|
+
throw new Error(`${UNSUPPORTED_PROXY_PROTOCOL_MESSAGE2} Got ${proxyUrl.protocol}`);
|
|
99
|
+
}
|
|
100
|
+
return proxyUrl;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { UNSUPPORTED_PROXY_PROTOCOL_MESSAGE2, resolveHttpProxyUrlForTarget2 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/auth/context.ts
|
|
2
|
+
function defaultProviderAuthContext2() {
|
|
3
|
+
return {
|
|
4
|
+
async env(name) {
|
|
5
|
+
if (typeof process === "undefined")
|
|
6
|
+
return;
|
|
7
|
+
const value = process.env[name];
|
|
8
|
+
return value !== undefined && value.trim().length > 0 ? value : undefined;
|
|
9
|
+
},
|
|
10
|
+
async fileExists(path) {
|
|
11
|
+
try {
|
|
12
|
+
const resolved = path.startsWith("~") ? process.getBuiltinModule("node:os").homedir() + path.slice(1) : path;
|
|
13
|
+
await process.getBuiltinModule("node:fs/promises").access(resolved);
|
|
14
|
+
return true;
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { defaultProviderAuthContext2 };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NullableTokenCount2
|
|
3
|
+
} from "./account-limits-cache-736tdyme.js";
|
|
4
|
+
|
|
5
|
+
// src/api/anthropic-events.ts
|
|
6
|
+
import { Type } from "typebox";
|
|
7
|
+
var UsageSchema = Type.Object({
|
|
8
|
+
input_tokens: NullableTokenCount2,
|
|
9
|
+
output_tokens: NullableTokenCount2,
|
|
10
|
+
cache_read_input_tokens: NullableTokenCount2,
|
|
11
|
+
cache_creation_input_tokens: NullableTokenCount2,
|
|
12
|
+
cache_creation: Type.Optional(Type.Union([Type.Object({ ephemeral_1h_input_tokens: NullableTokenCount2 }), Type.Null()])),
|
|
13
|
+
output_tokens_details: Type.Optional(Type.Union([Type.Object({ thinking_tokens: NullableTokenCount2 }), Type.Null()])),
|
|
14
|
+
speed: Type.Optional(Type.Union([Type.String(), Type.Null()]))
|
|
15
|
+
});
|
|
16
|
+
var ContentBlockSchema = Type.Union([
|
|
17
|
+
Type.Object({
|
|
18
|
+
type: Type.Literal("text"),
|
|
19
|
+
text: Type.Optional(Type.Union([Type.String(), Type.Null()]))
|
|
20
|
+
}),
|
|
21
|
+
Type.Object({
|
|
22
|
+
type: Type.Literal("thinking"),
|
|
23
|
+
thinking: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
24
|
+
signature: Type.Optional(Type.Union([Type.String(), Type.Null()]))
|
|
25
|
+
}),
|
|
26
|
+
Type.Object({ type: Type.Literal("redacted_thinking"), data: Type.String() }),
|
|
27
|
+
Type.Object({
|
|
28
|
+
type: Type.Literal("tool_use"),
|
|
29
|
+
id: Type.String(),
|
|
30
|
+
name: Type.String(),
|
|
31
|
+
input: Type.Optional(Type.Union([Type.Record(Type.String(), Type.Unknown()), Type.Null()]))
|
|
32
|
+
})
|
|
33
|
+
]);
|
|
34
|
+
var ContentDeltaSchema = Type.Union([
|
|
35
|
+
Type.Object({ type: Type.Literal("text_delta"), text: Type.String() }),
|
|
36
|
+
Type.Object({ type: Type.Literal("thinking_delta"), thinking: Type.String() }),
|
|
37
|
+
Type.Object({ type: Type.Literal("input_json_delta"), partial_json: Type.String() }),
|
|
38
|
+
Type.Object({ type: Type.Literal("signature_delta"), signature: Type.String() })
|
|
39
|
+
]);
|
|
40
|
+
var ContentIndex = Type.Integer({ minimum: 0 });
|
|
41
|
+
var AnthropicEventSchema2 = Type.Union([
|
|
42
|
+
Type.Object({
|
|
43
|
+
type: Type.Literal("message_start"),
|
|
44
|
+
message: Type.Object({ id: Type.String(), model: Type.String(), usage: UsageSchema })
|
|
45
|
+
}),
|
|
46
|
+
Type.Object({
|
|
47
|
+
type: Type.Literal("message_delta"),
|
|
48
|
+
delta: Type.Object({
|
|
49
|
+
stop_reason: Type.Optional(Type.Union([Type.String(), Type.Null()])),
|
|
50
|
+
stop_details: Type.Optional(Type.Union([
|
|
51
|
+
Type.Object({ explanation: Type.Optional(Type.Union([Type.String(), Type.Null()])) }),
|
|
52
|
+
Type.Null()
|
|
53
|
+
]))
|
|
54
|
+
}),
|
|
55
|
+
usage: Type.Optional(Type.Union([UsageSchema, Type.Null()]))
|
|
56
|
+
}),
|
|
57
|
+
Type.Object({ type: Type.Literal("message_stop") }),
|
|
58
|
+
Type.Object({
|
|
59
|
+
type: Type.Literal("content_block_start"),
|
|
60
|
+
index: ContentIndex,
|
|
61
|
+
content_block: ContentBlockSchema
|
|
62
|
+
}),
|
|
63
|
+
Type.Object({
|
|
64
|
+
type: Type.Literal("content_block_delta"),
|
|
65
|
+
index: ContentIndex,
|
|
66
|
+
delta: ContentDeltaSchema
|
|
67
|
+
}),
|
|
68
|
+
Type.Object({ type: Type.Literal("content_block_stop"), index: ContentIndex })
|
|
69
|
+
]);
|
|
70
|
+
var AnthropicEventTypeSchema2 = Type.Index(AnthropicEventSchema2, ["type"]);
|
|
71
|
+
var IgnoredAnthropicEventSchema2 = Type.Union([
|
|
72
|
+
Type.Object({
|
|
73
|
+
type: Type.Literal("content_block_start"),
|
|
74
|
+
index: ContentIndex,
|
|
75
|
+
content_block: Type.Object({
|
|
76
|
+
type: Type.String({ not: Type.Index(ContentBlockSchema, ["type"]) })
|
|
77
|
+
})
|
|
78
|
+
}),
|
|
79
|
+
Type.Object({
|
|
80
|
+
type: Type.Literal("content_block_delta"),
|
|
81
|
+
index: ContentIndex,
|
|
82
|
+
delta: Type.Object({
|
|
83
|
+
type: Type.String({ not: Type.Index(ContentDeltaSchema, ["type"]) })
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
export { AnthropicEventSchema2, AnthropicEventTypeSchema2, IgnoredAnthropicEventSchema2 };
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sanitizeSurrogates2
|
|
3
|
+
} from "./account-limits-cache-eqwweapz.js";
|
|
4
|
+
import {
|
|
5
|
+
renderSystemMessageUpdate2
|
|
6
|
+
} from "./account-limits-cache-b4edaybk.js";
|
|
7
|
+
import {
|
|
8
|
+
getJsonSchemaToolParameters2,
|
|
9
|
+
resolveJsonSchemaStrictSampling2
|
|
10
|
+
} from "./account-limits-cache-h92bzz1j.js";
|
|
11
|
+
import {
|
|
12
|
+
toClaudeCodeName2
|
|
13
|
+
} from "./account-limits-cache-ks1sjym9.js";
|
|
14
|
+
|
|
15
|
+
// src/api/anthropic-convert.ts
|
|
16
|
+
import { IsProperties, IsRequired } from "typebox/schema";
|
|
17
|
+
var ANTHROPIC_IMAGE_MEDIA_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp"];
|
|
18
|
+
function convertImageBlock(image) {
|
|
19
|
+
const mediaType = ANTHROPIC_IMAGE_MEDIA_TYPES.find((type) => type === image.mimeType);
|
|
20
|
+
if (mediaType === undefined) {
|
|
21
|
+
throw new Error(`Anthropic does not support ${image.mimeType} images`);
|
|
22
|
+
}
|
|
23
|
+
return { type: "image", source: { type: "base64", media_type: mediaType, data: image.data } };
|
|
24
|
+
}
|
|
25
|
+
function convertContentBlocks(content) {
|
|
26
|
+
const hasImages = content.some((c) => c.type === "image");
|
|
27
|
+
if (!hasImages) {
|
|
28
|
+
return sanitizeSurrogates2(content.map((c) => c.type === "text" ? c.text : "").join(`
|
|
29
|
+
`));
|
|
30
|
+
}
|
|
31
|
+
const blocks = content.map((block) => block.type === "text" ? { type: "text", text: sanitizeSurrogates2(block.text) } : convertImageBlock(block));
|
|
32
|
+
const hasText = blocks.some((b) => b.type === "text");
|
|
33
|
+
if (!hasText) {
|
|
34
|
+
blocks.unshift({
|
|
35
|
+
type: "text",
|
|
36
|
+
text: "(see attached image)"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return blocks;
|
|
40
|
+
}
|
|
41
|
+
function normalizeToolCallId2(id) {
|
|
42
|
+
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
43
|
+
}
|
|
44
|
+
function convertToolResult(msg, isOAuthToken, deferredToolNames, loadedToolNames, normalizeToolName) {
|
|
45
|
+
const references = [];
|
|
46
|
+
for (const name of msg.addedToolNames ?? []) {
|
|
47
|
+
const normalizedName = normalizeToolName(name);
|
|
48
|
+
if (!deferredToolNames.has(normalizedName) || loadedToolNames.has(normalizedName))
|
|
49
|
+
continue;
|
|
50
|
+
loadedToolNames.add(normalizedName);
|
|
51
|
+
references.push({
|
|
52
|
+
type: "tool_reference",
|
|
53
|
+
tool_name: isOAuthToken ? toClaudeCodeName2(name) : name
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const convertedContent = convertContentBlocks(msg.content);
|
|
57
|
+
return {
|
|
58
|
+
toolResult: {
|
|
59
|
+
type: "tool_result",
|
|
60
|
+
tool_use_id: msg.toolCallId,
|
|
61
|
+
content: references.length > 0 ? references : convertedContent,
|
|
62
|
+
is_error: msg.isError
|
|
63
|
+
},
|
|
64
|
+
siblingContent: references.length === 0 ? [] : Array.isArray(convertedContent) ? convertedContent : [{ type: "text", text: convertedContent }]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function convertMessages3(transformedMessages, isOAuthToken, cacheControl, allowEmptySignature = false, deferredToolNames = new Set, normalizeToolName = (name) => name, nativeToolChanges = false) {
|
|
68
|
+
const params = [];
|
|
69
|
+
const loadedToolNames = new Set;
|
|
70
|
+
const pendingSystemMessages = [];
|
|
71
|
+
const flushPendingSystemMessages = () => {
|
|
72
|
+
params.push(...pendingSystemMessages);
|
|
73
|
+
pendingSystemMessages.length = 0;
|
|
74
|
+
};
|
|
75
|
+
for (let i = 0;i < transformedMessages.length; i++) {
|
|
76
|
+
const msg = transformedMessages[i];
|
|
77
|
+
if (msg.role === "system") {
|
|
78
|
+
const text = renderSystemMessageUpdate2(msg);
|
|
79
|
+
const blocks = [];
|
|
80
|
+
if (text.length > 0)
|
|
81
|
+
blocks.push({ type: "text", text: sanitizeSurrogates2(text) });
|
|
82
|
+
if (nativeToolChanges) {
|
|
83
|
+
for (const tool of msg.toolsRemoved ?? []) {
|
|
84
|
+
blocks.push({
|
|
85
|
+
type: "tool_removal",
|
|
86
|
+
tool: {
|
|
87
|
+
type: "tool_reference",
|
|
88
|
+
name: isOAuthToken ? toClaudeCodeName2(tool.name) : tool.name
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
for (const tool of msg.toolsAdded ?? []) {
|
|
93
|
+
blocks.push({
|
|
94
|
+
type: "tool_addition",
|
|
95
|
+
tool: {
|
|
96
|
+
type: "tool_reference",
|
|
97
|
+
name: isOAuthToken ? toClaudeCodeName2(tool.name) : tool.name
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (blocks.length > 0)
|
|
103
|
+
pendingSystemMessages.push({ role: "system", content: blocks });
|
|
104
|
+
} else if (msg.role === "user") {
|
|
105
|
+
if (!Array.isArray(msg.content)) {
|
|
106
|
+
if (msg.content.trim().length > 0) {
|
|
107
|
+
params.push({
|
|
108
|
+
role: "user",
|
|
109
|
+
content: sanitizeSurrogates2(msg.content)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
const blocks = msg.content.map((item) => {
|
|
114
|
+
if (item.type === "text") {
|
|
115
|
+
return {
|
|
116
|
+
type: "text",
|
|
117
|
+
text: sanitizeSurrogates2(item.text)
|
|
118
|
+
};
|
|
119
|
+
} else {
|
|
120
|
+
return convertImageBlock(item);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const filteredBlocks = blocks.filter((b) => {
|
|
124
|
+
if (b.type === "text") {
|
|
125
|
+
return b.text.trim().length > 0;
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
});
|
|
129
|
+
if (filteredBlocks.length === 0)
|
|
130
|
+
continue;
|
|
131
|
+
params.push({
|
|
132
|
+
role: "user",
|
|
133
|
+
content: filteredBlocks
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
} else if (msg.role === "assistant") {
|
|
137
|
+
flushPendingSystemMessages();
|
|
138
|
+
const blocks = [];
|
|
139
|
+
for (const block of msg.content) {
|
|
140
|
+
if (block.type === "text") {
|
|
141
|
+
if (block.text.trim().length === 0)
|
|
142
|
+
continue;
|
|
143
|
+
blocks.push({
|
|
144
|
+
type: "text",
|
|
145
|
+
text: sanitizeSurrogates2(block.text)
|
|
146
|
+
});
|
|
147
|
+
} else if (block.type === "thinking") {
|
|
148
|
+
if (block.redacted) {
|
|
149
|
+
blocks.push({
|
|
150
|
+
type: "redacted_thinking",
|
|
151
|
+
data: block.thinkingSignature
|
|
152
|
+
});
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const thinkingSignature = block.thinkingSignature;
|
|
156
|
+
const hasThinkingSignature = !!thinkingSignature && thinkingSignature.trim().length > 0;
|
|
157
|
+
if (block.thinking.trim().length === 0 && !hasThinkingSignature)
|
|
158
|
+
continue;
|
|
159
|
+
if (!hasThinkingSignature) {
|
|
160
|
+
blocks.push(allowEmptySignature ? {
|
|
161
|
+
type: "thinking",
|
|
162
|
+
thinking: sanitizeSurrogates2(block.thinking),
|
|
163
|
+
signature: ""
|
|
164
|
+
} : {
|
|
165
|
+
type: "text",
|
|
166
|
+
text: sanitizeSurrogates2(block.thinking)
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
blocks.push({
|
|
170
|
+
type: "thinking",
|
|
171
|
+
thinking: sanitizeSurrogates2(block.thinking),
|
|
172
|
+
signature: thinkingSignature
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
} else if (block.type === "toolCall") {
|
|
176
|
+
blocks.push({
|
|
177
|
+
type: "tool_use",
|
|
178
|
+
id: block.id,
|
|
179
|
+
name: isOAuthToken ? toClaudeCodeName2(block.name) : block.name,
|
|
180
|
+
input: block.arguments ?? {}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (blocks.length === 0)
|
|
185
|
+
continue;
|
|
186
|
+
params.push({
|
|
187
|
+
role: "assistant",
|
|
188
|
+
content: blocks
|
|
189
|
+
});
|
|
190
|
+
} else if (msg.role === "toolResult") {
|
|
191
|
+
const toolResults = [];
|
|
192
|
+
const siblingContent = [];
|
|
193
|
+
let j = i;
|
|
194
|
+
for (;j < transformedMessages.length; j++) {
|
|
195
|
+
const next = transformedMessages[j];
|
|
196
|
+
if (next.role !== "toolResult")
|
|
197
|
+
break;
|
|
198
|
+
const converted = convertToolResult(next, isOAuthToken, deferredToolNames, loadedToolNames, normalizeToolName);
|
|
199
|
+
toolResults.push(converted.toolResult);
|
|
200
|
+
siblingContent.push(...converted.siblingContent);
|
|
201
|
+
}
|
|
202
|
+
i = j - 1;
|
|
203
|
+
params.push({
|
|
204
|
+
role: "user",
|
|
205
|
+
content: [...toolResults, ...siblingContent]
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
flushPendingSystemMessages();
|
|
210
|
+
if (cacheControl && params.length > 0) {
|
|
211
|
+
const lastMessage = params[params.length - 1];
|
|
212
|
+
if (lastMessage.role === "user" || lastMessage.role === "system") {
|
|
213
|
+
if (Array.isArray(lastMessage.content)) {
|
|
214
|
+
const lastBlock = lastMessage.content[lastMessage.content.length - 1];
|
|
215
|
+
if (lastBlock && (lastBlock.type === "text" || lastBlock.type === "image" || lastBlock.type === "tool_result" || lastBlock.type === "tool_addition" || lastBlock.type === "tool_removal")) {
|
|
216
|
+
lastBlock.cache_control = cacheControl;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
lastMessage.content = [
|
|
220
|
+
{
|
|
221
|
+
type: "text",
|
|
222
|
+
text: lastMessage.content,
|
|
223
|
+
cache_control: cacheControl
|
|
224
|
+
}
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return params;
|
|
230
|
+
}
|
|
231
|
+
var ANTHROPIC_STRICT_UNSUPPORTED_KEYWORDS = new Set([
|
|
232
|
+
"minimum",
|
|
233
|
+
"maximum",
|
|
234
|
+
"exclusiveMinimum",
|
|
235
|
+
"exclusiveMaximum",
|
|
236
|
+
"multipleOf",
|
|
237
|
+
"maxItems",
|
|
238
|
+
"uniqueItems",
|
|
239
|
+
"minContains",
|
|
240
|
+
"maxContains",
|
|
241
|
+
"minProperties",
|
|
242
|
+
"maxProperties"
|
|
243
|
+
]);
|
|
244
|
+
var ANTHROPIC_STRICT_STRING_FORMATS = new Set([
|
|
245
|
+
"date-time",
|
|
246
|
+
"time",
|
|
247
|
+
"date",
|
|
248
|
+
"duration",
|
|
249
|
+
"email",
|
|
250
|
+
"hostname",
|
|
251
|
+
"uri",
|
|
252
|
+
"ipv4",
|
|
253
|
+
"ipv6",
|
|
254
|
+
"uuid"
|
|
255
|
+
]);
|
|
256
|
+
var rejectedByAnthropicStrictTools = (key, value) => {
|
|
257
|
+
if (ANTHROPIC_STRICT_UNSUPPORTED_KEYWORDS.has(key))
|
|
258
|
+
return true;
|
|
259
|
+
if (key === "minItems")
|
|
260
|
+
return value !== 0 && value !== 1;
|
|
261
|
+
if (key === "format")
|
|
262
|
+
return typeof value !== "string" || !ANTHROPIC_STRICT_STRING_FORMATS.has(value);
|
|
263
|
+
return false;
|
|
264
|
+
};
|
|
265
|
+
function convertTools3(tools, isOAuthToken, supportsEagerToolInputStreaming, supportsStrictTools, cacheControl, deferLoading = false) {
|
|
266
|
+
if (!tools)
|
|
267
|
+
return [];
|
|
268
|
+
return tools.map((tool, index) => {
|
|
269
|
+
const strict = resolveJsonSchemaStrictSampling2(tool, supportsStrictTools, rejectedByAnthropicStrictTools);
|
|
270
|
+
const parameters = getJsonSchemaToolParameters2(tool, strict);
|
|
271
|
+
const legacyInputSchema = {
|
|
272
|
+
type: "object",
|
|
273
|
+
properties: IsProperties(parameters) ? parameters.properties : {},
|
|
274
|
+
required: IsRequired(parameters) ? parameters.required : []
|
|
275
|
+
};
|
|
276
|
+
const converted = {
|
|
277
|
+
name: isOAuthToken ? toClaudeCodeName2(tool.name) : tool.name,
|
|
278
|
+
description: tool.description,
|
|
279
|
+
input_schema: strict === true ? { ...parameters, ...legacyInputSchema } : legacyInputSchema
|
|
280
|
+
};
|
|
281
|
+
if (supportsEagerToolInputStreaming)
|
|
282
|
+
converted.eager_input_streaming = true;
|
|
283
|
+
if (strict === true)
|
|
284
|
+
converted.strict = true;
|
|
285
|
+
if (deferLoading)
|
|
286
|
+
converted.defer_loading = true;
|
|
287
|
+
if (cacheControl && index === tools.length - 1)
|
|
288
|
+
converted.cache_control = cacheControl;
|
|
289
|
+
return converted;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export { normalizeToolCallId2, convertMessages3, convertTools3 };
|