@openclaw/ai 2026.11.3 → 2026.11.5-beta.2
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/README.md +11 -8
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
- package/dist/anthropic-DEKgalVg.mjs +182 -0
- package/dist/{anthropic-payload-policy-C0ki72BT.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
- package/dist/{anthropic-stream-reducer-yWDb5Cct.mjs → anthropic-stream-lifecycle-DF2qVvg1.mjs} +845 -649
- package/dist/{anthropic-tool-projection-C2-d1eZ3.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
- package/dist/{anthropic-tool-projection-DZOKfAmL.mjs → anthropic-tool-projection-dGRfr4iT.mjs} +22 -32
- package/dist/{api-registry-gDt0faai.d.mts → api-registry-DY2MLUyg.d.mts} +2 -2
- package/dist/assistant-output-CD4kY9gu.mjs +16 -0
- package/dist/{azure-openai-responses-BvvXzZbi.mjs → azure-openai-responses-DbQV5RTx.mjs} +47 -53
- package/dist/{cloudflare-Dttf8jKq.mjs → cloudflare-BJ2_Xabx.mjs} +1 -1
- package/dist/{credential-redaction-XvsPf7Yi.d.mts → credential-redaction-DrgndwTJ.d.mts} +5 -3
- package/dist/{deferred-event-buffer-DAvyP7qA.mjs → deferred-event-buffer-tIGkTkTm.mjs} +1 -2
- package/dist/{diagnostics-v7oVEW59.mjs → diagnostics-CloVGQiK.mjs} +27 -20
- package/dist/{diagnostics-DzrF1h4J.mjs → diagnostics-o1PrVNQb.mjs} +11 -4
- package/dist/diagnostics.d.mts +6 -7
- package/dist/diagnostics.mjs +4 -4
- package/dist/{env-api-keys-Xd8dm_aV.mjs → env-api-keys-BuHc86ya.mjs} +1 -26
- package/dist/event-stream-B4ZcSvsu.d.mts +1 -0
- package/dist/{event-stream-CzpE1g_o.d.mts → event-stream-BYmtRe8-.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{github-copilot-request-facts-F-EmvkpW.mjs → github-copilot-request-facts-BZ_EMo7X.mjs} +1 -1
- package/dist/{google-Cpi_cLKZ.mjs → google-B1g82bn4.mjs} +7 -8
- package/dist/{google-interactions-CGINbsjO.mjs → google-interactions-Ckr0Z99Z.mjs} +243 -269
- package/dist/{google-messages-DQMgG5yG.mjs → google-messages-A-9d3y5V.mjs} +52 -18
- package/dist/{google-provider-stream-BHd0cST9.mjs → google-provider-stream-CNVh4gpm.mjs} +19 -11
- package/dist/{google-shared-vtag8bj5.mjs → google-shared-WNM86ZcW.mjs} +72 -42
- package/dist/{google-vertex-eKoUnW7N.mjs → google-vertex-CXjleC6g.mjs} +3 -3
- package/dist/{google-video-slots-D8tPH8wX.mjs → google-video-slots-Bxt-OXO8.mjs} +1 -1
- package/dist/{host-CWt55nnF.mjs → host-DX7ORpeH.mjs} +46 -39
- package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
- package/dist/{host-policy-Dm7PM6AD.mjs → host-policy-jCZebuXx.mjs} +2 -2
- package/dist/index-Bczt0MnO.d.mts +17 -0
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +9 -7
- package/dist/internal/anthropic.d.mts +21 -26
- package/dist/internal/anthropic.mjs +6 -6
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/google.d.mts +15 -0
- package/dist/internal/google.mjs +1 -0
- package/dist/internal/model-request-body.d.mts +37 -0
- package/dist/internal/model-request-body.mjs +106 -0
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +14 -12
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/reasoning-tag-text-partitioner.d.mts +26 -0
- package/dist/{reasoning-tag-text-partitioner-CU9A4Lg8.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -111
- package/dist/internal/retry-after.d.mts +2 -2
- package/dist/internal/retry-after.mjs +96 -32
- package/dist/internal/runtime.d.mts +15 -41
- package/dist/internal/runtime.mjs +9 -10
- package/dist/internal/shared.d.mts +21 -25
- package/dist/internal/shared.mjs +9 -98
- package/dist/internal/tool-schema.d.mts +10 -10
- package/dist/internal/tool-schema.mjs +4 -4
- package/dist/{llm-request-activity-CfMuh5cC.mjs → llm-request-activity-DzaHoRAU.mjs} +2 -2
- package/dist/mistral-CjHkvsqR.mjs +3741 -0
- package/dist/{openai.LICENSE → mistral.LICENSE} +1 -1
- package/dist/{model-transport-url-BrsjjdjR.d.mts → model-transport-url-BdksnBqu.d.mts} +6 -8
- package/dist/{number-coercion-37gmNkuA.mjs → number-coercion-C7HsBgUL.mjs} +7 -2
- package/dist/observe-async-iterator-AlARO5wS.d.mts +178 -0
- package/dist/observe-async-iterator-DgmegcZR.mjs +181 -0
- package/dist/{openai-chatgpt-responses-BZa3SySh.mjs → openai-chatgpt-responses-CwS5JP7A.mjs} +61 -80
- package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
- package/dist/{openai-completions-compat-bNQXF1y9.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
- package/dist/{openai-completions-CCZ_UHCk.mjs → openai-completions-sj4S-RXQ.mjs} +5 -5
- package/dist/openai-completions-transport-BDAIA0_P.mjs +3406 -0
- package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
- package/dist/{openai-prompt-cache-B9AvdoEo.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
- package/dist/{openai-responses-compaction-replay-_sUXtcwU.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
- package/dist/{openai-responses-contracts-B1nkeLL6.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
- package/dist/{openai-responses-contracts-B5mGAbR6.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
- package/dist/{openai-responses-endpoint-CfKR6N5f.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
- package/dist/openai-responses-ev_c6oTy.mjs +89 -0
- package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
- package/dist/{openai-responses-request-lifecycle-CTqHc02t.mjs → openai-responses-request-lifecycle-BuOs0mwI.mjs} +12 -26
- package/dist/{openai-responses-shared-wx9v1MCn.mjs → openai-responses-shared-BmRQnUPP.mjs} +633 -1493
- package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
- package/dist/{openai-tool-schema-BTEU2xmN.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
- package/dist/otel-Buswj0Mf.mjs +766 -0
- package/dist/{overflow-OF3PgPbw.mjs → overflow-CpApyjG2.mjs} +1 -1
- package/dist/{positive-integer-Bb4Evc7L.mjs → positive-integer-DiqE5vNi.mjs} +2 -3
- package/dist/{prompt-cache-stability-D_MeCQFI.mjs → prompt-cache-stability-w-ICeyOI.mjs} +1 -1
- package/dist/{provider-error-qtZD2inE.mjs → provider-error-DD-fo4Rz.mjs} +71 -234
- package/dist/{provider-options-DAzsyi49.d.mts → provider-options-Mo8NM5d1.d.mts} +16 -5
- package/dist/{provider-replay-context-4vxI7p4V.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
- package/dist/provider-transcript-transform-DtaxNcC1.mjs +32 -0
- package/dist/{provider-transport-turn-state-D_GjPJHe.mjs → provider-transport-turn-state-BIS8maBK.mjs} +4 -4
- package/dist/{provider-types-CWl4VXvE.d.mts → provider-types-B1e98js5.d.mts} +3 -3
- package/dist/provider-types.d.mts +7 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +26 -29
- package/dist/{record-coerce-CNDovvft.mjs → record-coerce-BQaoiN3r.mjs} +4 -1
- package/dist/request-headers-DO4Mqhw1.mjs +10 -0
- package/dist/{required-api-key-D088S4Cd.mjs → required-api-key-2zZTkmsi.mjs} +1 -1
- package/dist/{retry-after-BrmTv0jL.d.mts → retry-after-DnHBlFS2.d.mts} +21 -1
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/{sanitize-unicode-ZqVLLEKC.d.mts → sanitize-unicode-BISmUlUv.d.mts} +2 -2
- package/dist/{simple-options-xJkqrG_E.mjs → simple-options-tLSeECry.mjs} +108 -82
- package/dist/src-BUsVkrNt.mjs +105 -0
- package/dist/{src-CyA0zJnt.mjs → src-CQ7nH2mL.mjs} +4 -7
- package/dist/stable-stringify-CchQEmeA.mjs +84 -0
- package/dist/{stream-C4YDqhFj.mjs → stream-DrtAWu7c.mjs} +2 -6
- package/dist/{stream-first-event-timeout-D_TfJHRJ.mjs → stream-first-event-timeout-B7RcufAV.mjs} +16 -13
- package/dist/{string-coerce-Cj8sqWHx.mjs → string-coerce-BCuWMIrk.mjs} +1 -1
- package/dist/string-normalization-B8TDDBX_.mjs +32 -0
- package/dist/telemetry-CvK1yQg7.mjs +582 -0
- package/dist/{tool-schema-json-projection-B1sTYwfH.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
- package/dist/{transport-stream-shared-lhgkTOz3.mjs → transport-stream-shared-D2uFMhMc.mjs} +177 -93
- package/dist/{transport-stream-shared-8ru8eX4s.d.mts → transport-stream-shared-D3IAU4jn.d.mts} +29 -15
- package/dist/{transport-utils-DwOpuTjL.mjs → transport-utils-Da_39MYi.mjs} +23 -38
- package/dist/transports.d.mts +42 -39
- package/dist/transports.mjs +215 -296
- package/dist/{types-CVYzKrMl.d.mts → types-BVdTf0YV.d.mts} +38 -3
- package/dist/types-Cb3-5WM9.d.mts +1 -0
- package/dist/{types-BXd0kI8-.mjs → types-OVEWUaDh.mjs} +3 -1
- package/dist/types.d.mts +7 -6
- package/dist/types.mjs +7 -5
- package/dist/{validation-9FSkE8T-.mjs → validation-DGXqfvkj.mjs} +45 -27
- package/dist/{validation-BQ5u20Ru.d.mts → validation-QmyD0E5A.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -2
- package/package.json +40 -6
- package/dist/anthropic-lueA8LUg.mjs +0 -221
- package/dist/assistant-output-BnQm3fov.mjs +0 -47
- package/dist/event-stream-CDpFza-M.d.mts +0 -1
- package/dist/index-DSprYWaz.d.mts +0 -185
- package/dist/mistral-CQ7aoWg2.mjs +0 -512
- package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
- package/dist/openai-CiRi-nVE.mjs +0 -20077
- package/dist/openai-completions-transport-DFvSBbUT.mjs +0 -10881
- package/dist/openai-responses-DQsZKUoI.mjs +0 -87
- package/dist/rolldown-runtime-B4iAMlE-.mjs +0 -35
- package/dist/types-CBJthzJX.d.mts +0 -1
- package/dist/ws.LICENSE +0 -20
package/dist/providers.mjs
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import { t as AssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
2
|
-
import { n as projectProviderError } from "./provider-error-
|
|
3
|
-
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-
|
|
2
|
+
import { n as projectProviderError } from "./provider-error-DD-fo4Rz.mjs";
|
|
3
|
+
import { n as clampOpenAIPromptCacheKey, t as OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH } from "./openai-prompt-cache-CgDoFhO0.mjs";
|
|
4
4
|
import { t as createZeroUsage } from "./usage-CJH5D6Ea.mjs";
|
|
5
5
|
//#region packages/ai/src/providers/register-builtins.ts
|
|
6
6
|
/** Source id used for built-in API provider registrations. */
|
|
7
7
|
const BUILT_IN_API_PROVIDER_SOURCE_ID = "core:built-in";
|
|
8
|
-
async function forwardStream(target, source) {
|
|
9
|
-
for await (const event of source) target.push(event);
|
|
10
|
-
target.end();
|
|
11
|
-
}
|
|
12
|
-
function createLazyLoadErrorMessage(model, error, signal) {
|
|
13
|
-
return {
|
|
14
|
-
role: "assistant",
|
|
15
|
-
content: [],
|
|
16
|
-
api: model.api,
|
|
17
|
-
provider: model.provider,
|
|
18
|
-
model: model.id,
|
|
19
|
-
usage: createZeroUsage(),
|
|
20
|
-
...projectProviderError(error, signal),
|
|
21
|
-
timestamp: Date.now()
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
8
|
function createLazyStream(load, select) {
|
|
25
9
|
return (model, context, options) => {
|
|
26
10
|
const outer = new AssistantMessageEventStream();
|
|
27
|
-
load().then(
|
|
28
|
-
const
|
|
11
|
+
load().then(async (streams) => {
|
|
12
|
+
for await (const event of select(streams)(model, context, options)) outer.push(event);
|
|
13
|
+
outer.end();
|
|
14
|
+
}).catch((error) => {
|
|
15
|
+
const lazyLoadSignal = options?.signal;
|
|
16
|
+
const message = {
|
|
17
|
+
role: "assistant",
|
|
18
|
+
content: [],
|
|
19
|
+
api: model.api,
|
|
20
|
+
provider: model.provider,
|
|
21
|
+
model: model.id,
|
|
22
|
+
usage: createZeroUsage(),
|
|
23
|
+
...projectProviderError(error, lazyLoadSignal),
|
|
24
|
+
timestamp: Date.now()
|
|
25
|
+
};
|
|
29
26
|
outer.push({
|
|
30
27
|
type: "error",
|
|
31
28
|
reason: message.stopReason,
|
|
@@ -50,39 +47,39 @@ function createLazyRegistration(api, importModule, select) {
|
|
|
50
47
|
};
|
|
51
48
|
}
|
|
52
49
|
const registerBuiltIns = [
|
|
53
|
-
createLazyRegistration("anthropic-messages", () => import("./anthropic-
|
|
50
|
+
createLazyRegistration("anthropic-messages", () => import("./anthropic-DEKgalVg.mjs").then((n) => n.t), (module) => ({
|
|
54
51
|
stream: module.streamAnthropic,
|
|
55
52
|
streamSimple: module.streamSimpleAnthropic
|
|
56
53
|
})),
|
|
57
|
-
createLazyRegistration("openai-completions", () => import("./openai-completions-
|
|
54
|
+
createLazyRegistration("openai-completions", () => import("./openai-completions-sj4S-RXQ.mjs").then((n) => n.t), (module) => ({
|
|
58
55
|
stream: module.streamOpenAICompletions,
|
|
59
56
|
streamSimple: module.streamSimpleOpenAICompletions
|
|
60
57
|
})),
|
|
61
|
-
createLazyRegistration("mistral-conversations", () => import("./mistral-
|
|
58
|
+
createLazyRegistration("mistral-conversations", () => import("./mistral-CjHkvsqR.mjs").then((n) => n.t), (module) => ({
|
|
62
59
|
stream: module.streamMistral,
|
|
63
60
|
streamSimple: module.streamSimpleMistral
|
|
64
61
|
})),
|
|
65
|
-
createLazyRegistration("openai-responses", () => import("./openai-responses-
|
|
62
|
+
createLazyRegistration("openai-responses", () => import("./openai-responses-ev_c6oTy.mjs").then((n) => n.t), (module) => ({
|
|
66
63
|
stream: module.streamOpenAIResponses,
|
|
67
64
|
streamSimple: module.streamSimpleOpenAIResponses
|
|
68
65
|
})),
|
|
69
|
-
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-
|
|
66
|
+
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-DbQV5RTx.mjs"), (module) => ({
|
|
70
67
|
stream: module.streamAzureOpenAIResponses,
|
|
71
68
|
streamSimple: module.streamSimpleAzureOpenAIResponses
|
|
72
69
|
})),
|
|
73
|
-
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-
|
|
70
|
+
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-CwS5JP7A.mjs"), (module) => ({
|
|
74
71
|
stream: module.streamOpenAICodexResponses,
|
|
75
72
|
streamSimple: module.streamSimpleOpenAICodexResponses
|
|
76
73
|
})),
|
|
77
|
-
createLazyRegistration("google-generative-ai", () => import("./google-
|
|
74
|
+
createLazyRegistration("google-generative-ai", () => import("./google-B1g82bn4.mjs"), (module) => ({
|
|
78
75
|
stream: module.streamGoogle,
|
|
79
76
|
streamSimple: module.streamSimpleGoogle
|
|
80
77
|
})),
|
|
81
|
-
createLazyRegistration("google-interactions", () => import("./google-interactions-
|
|
78
|
+
createLazyRegistration("google-interactions", () => import("./google-interactions-Ckr0Z99Z.mjs"), (module) => ({
|
|
82
79
|
stream: module.streamGoogleInteractions,
|
|
83
80
|
streamSimple: module.streamSimpleGoogleInteractions
|
|
84
81
|
})),
|
|
85
|
-
createLazyRegistration("google-vertex", () => import("./google-vertex-
|
|
82
|
+
createLazyRegistration("google-vertex", () => import("./google-vertex-CXjleC6g.mjs"), (module) => ({
|
|
86
83
|
stream: module.streamGoogleVertex,
|
|
87
84
|
streamSimple: module.streamSimpleGoogleVertex
|
|
88
85
|
}))
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
function isRecord(value) {
|
|
4
4
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
5
|
}
|
|
6
|
+
function isStringArray(value) {
|
|
7
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
8
|
+
}
|
|
6
9
|
/** Coerces object-like values to records, falling back to an empty record. */
|
|
7
10
|
function asRecord(value) {
|
|
8
11
|
return asOptionalObjectRecord(value) ?? {};
|
|
@@ -29,4 +32,4 @@ function asOptionalObjectRecord(value) {
|
|
|
29
32
|
return value && typeof value === "object" ? value : void 0;
|
|
30
33
|
}
|
|
31
34
|
//#endregion
|
|
32
|
-
export { asRecord as a, asOptionalRecord as i, asNullableRecord as n, isRecord as o, asOptionalObjectRecord as r,
|
|
35
|
+
export { asRecord as a, readStringField as c, asOptionalRecord as i, asNullableRecord as n, isRecord as o, asOptionalObjectRecord as r, isStringArray as s, asNonArrayRecord as t };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region packages/llm-core/src/utils/request-headers.ts
|
|
2
|
+
/** Materialize merged overrides for HTTP clients that cannot consume SDK deletion sentinels. */
|
|
3
|
+
function omitNullRequestHeaders(headers) {
|
|
4
|
+
if (!headers) return;
|
|
5
|
+
const result = {};
|
|
6
|
+
for (const [name, value] of Object.entries(headers)) if (value !== null) result[name] = value;
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { omitNullRequestHeaders as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getEnvApiKey } from "./env-api-keys-
|
|
1
|
+
import { n as getEnvApiKey } from "./env-api-keys-BuHc86ya.mjs";
|
|
2
2
|
//#region packages/ai/src/utils/required-api-key.ts
|
|
3
3
|
function requireApiKey(provider, apiKey) {
|
|
4
4
|
const resolved = apiKey || getEnvApiKey(provider);
|
|
@@ -3,23 +3,43 @@ type HttpDateInstant = {
|
|
|
3
3
|
timestampMs: number;
|
|
4
4
|
leapSecond: boolean;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Provider retry timing split by authority: an explicit instruction for this request
|
|
8
|
+
* (Retry-After, retry-after-ms) versus an exhausted bucket's full-refill time.
|
|
9
|
+
*/
|
|
10
|
+
type RetryAfterTiming = {
|
|
11
|
+
explicitSeconds?: number;
|
|
12
|
+
resetSeconds?: number;
|
|
13
|
+
};
|
|
6
14
|
/** Reads only retry timing metadata, without invoking provider getters or serialization hooks. */
|
|
7
15
|
declare function parseRetryAfterHeadersSeconds(headers: unknown, nowMs?: number, status?: number): number | undefined;
|
|
16
|
+
/** Header timing with explicit retry instructions kept apart from bucket refills. */
|
|
17
|
+
declare function parseRetryAfterHeadersTiming(headers: unknown, nowMs?: number, status?: number): RetryAfterTiming | undefined;
|
|
8
18
|
/** SDK errors carry native response headers separately from their error body. */
|
|
9
19
|
declare function parseRetryAfterErrorSeconds(error: unknown, nowMs?: number): number | undefined;
|
|
20
|
+
/** Header timing from an SDK error and its response, merged per authority. */
|
|
21
|
+
declare function parseRetryAfterErrorTiming(error: unknown, nowMs?: number): RetryAfterTiming | undefined;
|
|
10
22
|
/** Provider prose such as "Please try again in 6s", "retry in 32s" or "Retry-After: 7". */
|
|
11
23
|
declare const RETRY_AFTER_TEXT_RE: RegExp;
|
|
12
24
|
/** Seconds named by a captured retry-text value: a number with an optional time unit, or an HTTP-date. */
|
|
13
25
|
declare function parseRetryAfterTextSeconds(valueText: string, nowMs?: number): number | undefined;
|
|
26
|
+
/** Whether text carries an explicit retry instruction that parseRetryAfterTextSeconds accepts. */
|
|
27
|
+
declare function hasExplicitRetryText(text: unknown, nowMs?: number): boolean;
|
|
14
28
|
/**
|
|
15
29
|
* Reads google.rpc.RetryInfo delays from raw error text or a google.rpc.Status-shaped body
|
|
16
30
|
* in any key order, with a fixed number of descriptor reads and no getters. Pass the
|
|
17
31
|
* untruncated body: Gemini puts RetryInfo after its QuotaFailure details.
|
|
18
32
|
*/
|
|
19
33
|
declare function parseGoogleRetryDelaySeconds(value: unknown): number | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Retry time for one thrown provider error, before any lossy projection.
|
|
36
|
+
* Explicit instructions (Retry-After headers, Google RetryInfo) win; prose timing is left
|
|
37
|
+
* for text consumers; an exhausted-bucket refill applies only when neither is present.
|
|
38
|
+
*/
|
|
39
|
+
declare function resolveProviderErrorRetrySeconds(error: unknown, nowMs?: number): number | undefined;
|
|
20
40
|
/** Round leap seconds forward for Retry-After so an unrepresentable instant cannot retry early. */
|
|
21
41
|
declare function parseRetryAfterHttpDateMs(value: string, nowMs?: number): number | undefined;
|
|
22
42
|
/** Parse all three HTTP-date forms while retaining leap-second ordering. */
|
|
23
43
|
declare function parseHttpDateInstant(value: string, nowMs?: number): HttpDateInstant | undefined;
|
|
24
44
|
//#endregion
|
|
25
|
-
export {
|
|
45
|
+
export { parseHttpDateInstant as a, parseRetryAfterHeadersSeconds as c, parseRetryAfterTextSeconds as d, resolveProviderErrorRetrySeconds as f, parseGoogleRetryDelaySeconds as i, parseRetryAfterHeadersTiming as l, RetryAfterTiming as n, parseRetryAfterErrorSeconds as o, hasExplicitRetryText as r, parseRetryAfterErrorTiming as s, RETRY_AFTER_TEXT_RE as t, parseRetryAfterHttpDateMs as u };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as AssistantMessage } from "./types-
|
|
2
|
-
import "./types-
|
|
1
|
+
import { a as AssistantMessage } from "./types-BVdTf0YV.mjs";
|
|
2
|
+
import "./types-Cb3-5WM9.mjs";
|
|
3
3
|
//#region packages/ai/src/utils/overflow.d.ts
|
|
4
4
|
declare const CONTEXT_OVERFLOW_PATTERN_SCOPES: {
|
|
5
5
|
readonly "assistant-error": RegExp[];
|
|
@@ -1,17 +1,59 @@
|
|
|
1
|
-
import { o as isRecord } from "./record-coerce-
|
|
2
|
-
import { M as hasMediaPayload } from "./host-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { o as isRecord } from "./record-coerce-BQaoiN3r.mjs";
|
|
2
|
+
import { M as hasMediaPayload } from "./host-DX7ORpeH.mjs";
|
|
3
|
+
import { y as responsesServiceTierObserver } from "./openai-responses-contracts-xU-n9AJJ.mjs";
|
|
4
|
+
import { c as truncateUtf16Safe } from "./provider-error-DD-fo4Rz.mjs";
|
|
5
5
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-CRGuMONI.mjs";
|
|
6
|
-
import { n as normalizeStructuredPromptSection } from "./prompt-cache-stability-
|
|
7
|
-
import { i as copyProviderAcceptanceObserver } from "./transport-stream-shared-
|
|
6
|
+
import { n as normalizeStructuredPromptSection } from "./prompt-cache-stability-w-ICeyOI.mjs";
|
|
7
|
+
import { i as copyProviderAcceptanceObserver } from "./transport-stream-shared-D2uFMhMc.mjs";
|
|
8
|
+
import { modelRequestBodyState } from "./internal/model-request-body.mjs";
|
|
9
|
+
import { PROVIDER_CONTEXT_HANDOFF, PROVIDER_MODEL_INPUT } from "./provider-types.mjs";
|
|
8
10
|
//#region packages/ai/src/utils/system-prompt-cache-boundary.ts
|
|
9
11
|
const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
10
12
|
/** Producer-delimited Runtime facts; instructions must remain outside this region. */
|
|
11
13
|
const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY = "\n<!-- OPENCLAW-RELOCATABLE-BOUNDARY -->\n";
|
|
12
14
|
const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END = "\n<!-- /OPENCLAW-RELOCATABLE-BOUNDARY -->";
|
|
15
|
+
const strippedSystemPrompts = /* @__PURE__ */ new Map();
|
|
16
|
+
const MAX_STRIPPED_SYSTEM_PROMPTS = 32;
|
|
17
|
+
/** Carry this fact with its session; interleaved sessions cannot evict a live revision. */
|
|
18
|
+
function prepareSystemPrompt(text, previous) {
|
|
19
|
+
if (previous?.text === text) return previous;
|
|
20
|
+
let stripped;
|
|
21
|
+
let instructions;
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
text,
|
|
24
|
+
get stripped() {
|
|
25
|
+
return stripped ??= stripSystemPromptCacheBoundary(text);
|
|
26
|
+
},
|
|
27
|
+
get instructions() {
|
|
28
|
+
return instructions ??= sanitizeSurrogates(this.stripped);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** A stream's boundary transform carries the revision it actually passes downstream. */
|
|
33
|
+
function createSystemPromptCacheBoundaryStripper() {
|
|
34
|
+
let prepared;
|
|
35
|
+
return (context) => {
|
|
36
|
+
if (!context.systemPrompt) return context;
|
|
37
|
+
const stripped = prepareSystemPrompt(context.systemPrompt, context.preparedSystemPrompt).stripped;
|
|
38
|
+
prepared = prepareSystemPrompt(stripped, prepared);
|
|
39
|
+
return {
|
|
40
|
+
...context,
|
|
41
|
+
systemPrompt: stripped,
|
|
42
|
+
preparedSystemPrompt: prepared
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}
|
|
13
46
|
function stripSystemPromptCacheBoundary(text) {
|
|
14
|
-
|
|
47
|
+
let stripped = strippedSystemPrompts.get(text);
|
|
48
|
+
if (stripped === void 0) {
|
|
49
|
+
stripped = stripSystemPromptRelocatableBoundary(text.replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY, "\n").replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY.trim(), ""));
|
|
50
|
+
for (const oldest of strippedSystemPrompts.keys()) {
|
|
51
|
+
if (strippedSystemPrompts.size < MAX_STRIPPED_SYSTEM_PROMPTS) break;
|
|
52
|
+
strippedSystemPrompts.delete(oldest);
|
|
53
|
+
}
|
|
54
|
+
strippedSystemPrompts.set(text, stripped);
|
|
55
|
+
}
|
|
56
|
+
return stripped;
|
|
15
57
|
}
|
|
16
58
|
/** Reject ambiguous markers from workspace or hook text instead of moving instructions. */
|
|
17
59
|
function splitSystemPromptRelocatableBoundary(text) {
|
|
@@ -52,6 +94,32 @@ function prependSystemPromptAdditionAfterCacheBoundary(params) {
|
|
|
52
94
|
}
|
|
53
95
|
//#endregion
|
|
54
96
|
//#region packages/ai/src/provider-options.ts
|
|
97
|
+
const measuredRequestPressures = /* @__PURE__ */ new WeakMap();
|
|
98
|
+
/** Request-local pressure admitted by the host's matched provider-usage owner. */
|
|
99
|
+
const measuredRequestPressure = {
|
|
100
|
+
set(model, context, tokens) {
|
|
101
|
+
if (tokens === void 0) {
|
|
102
|
+
measuredRequestPressures.delete(context);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
measuredRequestPressures.set(context, {
|
|
106
|
+
model: {
|
|
107
|
+
provider: model.provider,
|
|
108
|
+
id: model.id,
|
|
109
|
+
api: model.api,
|
|
110
|
+
baseUrl: model.baseUrl
|
|
111
|
+
},
|
|
112
|
+
messages: context.messages,
|
|
113
|
+
tools: context.tools,
|
|
114
|
+
systemPrompt: context.systemPrompt,
|
|
115
|
+
tokens
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
get(model, context) {
|
|
119
|
+
const pressure = measuredRequestPressures.get(context);
|
|
120
|
+
return pressure && pressure.model.provider === model.provider && pressure.model.id === model.id && pressure.model.api === model.api && pressure.model.baseUrl === model.baseUrl && pressure.messages === context.messages && pressure.tools === context.tools && pressure.systemPrompt === context.systemPrompt ? pressure.tokens : void 0;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
55
123
|
const CODE_MODE_TOOL_SURFACE_OBSERVER = Symbol("openaiCodeModeToolSurfaceObserver");
|
|
56
124
|
const CODE_MODE_TOOL_SURFACE_COLLECTOR = Symbol("openaiCodeModeToolSurfaceCollector");
|
|
57
125
|
const STRICT_REASONING_TAG_TEXT = Symbol("openaiStrictReasoningTagText");
|
|
@@ -94,6 +162,9 @@ const preparedRequestSuffix = {
|
|
|
94
162
|
has(context) {
|
|
95
163
|
return Reflect.has(context, PREPARED_REQUEST_SUFFIX);
|
|
96
164
|
},
|
|
165
|
+
hasToolCall(context, id) {
|
|
166
|
+
return Reflect.get(context, PREPARED_REQUEST_SUFFIX)?.has(id) ?? false;
|
|
167
|
+
},
|
|
97
168
|
toolCallId(context, id, normalized) {
|
|
98
169
|
const ids = Reflect.get(context, PREPARED_REQUEST_SUFFIX);
|
|
99
170
|
return ids && !ids.has(id) && ids.has(normalized) ? normalized : id;
|
|
@@ -131,39 +202,6 @@ function readMimeType(value) {
|
|
|
131
202
|
if (typeof mimeType === "string" && mimeType.trim().length > 0) return mimeType;
|
|
132
203
|
}
|
|
133
204
|
}
|
|
134
|
-
function isBinaryMimeType(mimeType) {
|
|
135
|
-
const normalized = mimeType.split(";", 1)[0]?.trim().toLowerCase();
|
|
136
|
-
return normalized ? !TEXTUAL_MIME_PATTERN.test(normalized) : false;
|
|
137
|
-
}
|
|
138
|
-
function redactInlineDataUris(value) {
|
|
139
|
-
return value.replace(INLINE_DATA_URI_PATTERN, (_match, prefix, uri) => `${prefix}[inline data URI: ${uri.length} chars]`);
|
|
140
|
-
}
|
|
141
|
-
function stringifyStructuredBlock(block) {
|
|
142
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
143
|
-
try {
|
|
144
|
-
const serialized = JSON.stringify(block, function structuredToolResultReplacer(key, value) {
|
|
145
|
-
if (OPAQUE_OR_BINARY_FIELD_RE.test(key)) return `[omitted ${key}]`;
|
|
146
|
-
if (key === "data") {
|
|
147
|
-
const mimeType = readMimeType(this);
|
|
148
|
-
if (mimeType && isBinaryMimeType(mimeType)) {
|
|
149
|
-
const length = typeof value === "string" ? value.length : JSON.stringify(value)?.length;
|
|
150
|
-
return length ? `[binary data omitted: ${length} chars]` : "[binary data omitted]";
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (typeof value === "bigint") return value.toString();
|
|
154
|
-
if (typeof value === "string") return redactInlineDataUris(value);
|
|
155
|
-
if (typeof value === "function" || typeof value === "symbol" || value === void 0) return;
|
|
156
|
-
if (!value || typeof value !== "object") return value;
|
|
157
|
-
if (seen.has(value)) return "[Circular]";
|
|
158
|
-
seen.add(value);
|
|
159
|
-
return value;
|
|
160
|
-
});
|
|
161
|
-
if (!serialized || serialized === "{}") return;
|
|
162
|
-
return serialized;
|
|
163
|
-
} catch {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
205
|
function truncateStructuredToolText(text) {
|
|
168
206
|
if (text.length <= STRUCTURED_TOOL_RESULT_MAX_CHARS) return text;
|
|
169
207
|
return `${truncateUtf16Safe(text, STRUCTURED_TOOL_RESULT_MAX_CHARS)}\n…(truncated)…`;
|
|
@@ -197,8 +235,31 @@ function extractToolResultBlockText(block) {
|
|
|
197
235
|
const text = typeof record.text === "string" ? record.text : "";
|
|
198
236
|
return text ? sanitizeSurrogates(text) : void 0;
|
|
199
237
|
}
|
|
200
|
-
|
|
201
|
-
|
|
238
|
+
let structured;
|
|
239
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
240
|
+
try {
|
|
241
|
+
structured = JSON.stringify(record, function structuredToolResultReplacer(key, value) {
|
|
242
|
+
if (OPAQUE_OR_BINARY_FIELD_RE.test(key)) return `[omitted ${key}]`;
|
|
243
|
+
if (key === "data") {
|
|
244
|
+
const normalizedMimeType = readMimeType(this)?.split(";", 1)[0]?.trim().toLowerCase();
|
|
245
|
+
if (normalizedMimeType && !TEXTUAL_MIME_PATTERN.test(normalizedMimeType)) {
|
|
246
|
+
const length = typeof value === "string" ? value.length : JSON.stringify(value)?.length;
|
|
247
|
+
return length ? `[binary data omitted: ${length} chars]` : "[binary data omitted]";
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (typeof value === "bigint") return value.toString();
|
|
251
|
+
if (typeof value === "string") return value.replace(INLINE_DATA_URI_PATTERN, (_match, prefix, uri) => `${prefix}[inline data URI: ${uri.length} chars]`);
|
|
252
|
+
if (typeof value === "function" || typeof value === "symbol" || value === void 0) return;
|
|
253
|
+
if (!value || typeof value !== "object") return value;
|
|
254
|
+
if (seen.has(value)) return "[Circular]";
|
|
255
|
+
seen.add(value);
|
|
256
|
+
return value;
|
|
257
|
+
});
|
|
258
|
+
if (!structured || structured === "{}") return;
|
|
259
|
+
} catch {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
return sanitizeSurrogates(truncateStructuredToolText(structured));
|
|
202
263
|
}
|
|
203
264
|
function extractToolResultText(blocks, options) {
|
|
204
265
|
const explicitTexts = [];
|
|
@@ -236,49 +297,12 @@ function formatToolResultText(params) {
|
|
|
236
297
|
return `${params.isError ? "[tool error] " : ""}${body}`;
|
|
237
298
|
}
|
|
238
299
|
//#endregion
|
|
239
|
-
//#region packages/ai/src/transports/model-request-body.ts
|
|
240
|
-
const REQUEST_BODY = Symbol("modelRequestBody");
|
|
241
|
-
/** Call-local state survives option spreads; no payload is cached across requests. */
|
|
242
|
-
function modelRequestBodyState(options, inheritFrom) {
|
|
243
|
-
const state = Reflect.get(options, REQUEST_BODY) ?? (inheritFrom && Reflect.get(inheritFrom, REQUEST_BODY)) ?? {};
|
|
244
|
-
Reflect.set(options, REQUEST_BODY, state);
|
|
245
|
-
return state;
|
|
246
|
-
}
|
|
247
|
-
function serializeModelRequestBody(payload, onSerializedPayload) {
|
|
248
|
-
const json = JSON.stringify(payload);
|
|
249
|
-
const serialized = json === void 0 ? void 0 : JSON.parse(json);
|
|
250
|
-
const stream = typeof serialized === "object" && serialized !== null && "stream" in serialized && serialized.stream === true;
|
|
251
|
-
onSerializedPayload?.(serialized);
|
|
252
|
-
return {
|
|
253
|
-
body: new TextEncoder().encode(json),
|
|
254
|
-
stream
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
const encodedBodyStreams = /* @__PURE__ */ new WeakMap();
|
|
258
|
-
function encodedModelRequestBodyStream(body) {
|
|
259
|
-
return typeof body === "object" && body !== null ? encodedBodyStreams.get(body) : void 0;
|
|
260
|
-
}
|
|
261
|
-
/** SDK RequestOptions.body overrides encoding while the original params retain stream metadata. */
|
|
262
|
-
function prepareModelRequestBody(options) {
|
|
263
|
-
const state = options ? modelRequestBodyState(options) : {};
|
|
264
|
-
state.enabled = true;
|
|
265
|
-
return async (payload) => {
|
|
266
|
-
const encoded = state.encode ? await state.encode(payload) : serializeModelRequestBody(payload);
|
|
267
|
-
const body = new Blob([encoded.body]);
|
|
268
|
-
state.onEncoded?.(body, payload);
|
|
269
|
-
state.onBytes?.(body.size);
|
|
270
|
-
encodedBodyStreams.set(body, encoded.stream);
|
|
271
|
-
return {
|
|
272
|
-
body,
|
|
273
|
-
headers: { "content-type": "application/json" }
|
|
274
|
-
};
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
//#endregion
|
|
278
300
|
//#region packages/ai/src/providers/simple-options.ts
|
|
279
301
|
function buildBaseOptions(model, options, apiKey) {
|
|
280
302
|
const firstEventOptions = options;
|
|
281
303
|
const baseOptions = {
|
|
304
|
+
[PROVIDER_CONTEXT_HANDOFF]: options?.[PROVIDER_CONTEXT_HANDOFF],
|
|
305
|
+
[PROVIDER_MODEL_INPUT]: options?.[PROVIDER_MODEL_INPUT],
|
|
282
306
|
temperature: options?.temperature,
|
|
283
307
|
...options?.serviceTier ? { serviceTier: options.serviceTier } : {},
|
|
284
308
|
maxTokens: options?.maxTokens,
|
|
@@ -288,11 +312,13 @@ function buildBaseOptions(model, options, apiKey) {
|
|
|
288
312
|
apiKey: apiKey || options?.apiKey,
|
|
289
313
|
transport: options?.transport,
|
|
290
314
|
cacheRetention: options?.cacheRetention,
|
|
315
|
+
promptCacheTtl: options?.promptCacheTtl,
|
|
291
316
|
sessionId: options?.sessionId,
|
|
292
317
|
promptCacheKey: options?.promptCacheKey,
|
|
293
318
|
headers: options?.headers,
|
|
294
319
|
onPayload: options?.onPayload,
|
|
295
320
|
onResponse: options?.onResponse,
|
|
321
|
+
onProviderWait: options?.onProviderWait,
|
|
296
322
|
timeoutMs: options?.timeoutMs,
|
|
297
323
|
firstEventTimeoutMs: firstEventOptions?.firstEventTimeoutMs,
|
|
298
324
|
onFirstEventTimeout: firstEventOptions?.onFirstEventTimeout,
|
|
@@ -329,4 +355,4 @@ function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLeve
|
|
|
329
355
|
};
|
|
330
356
|
}
|
|
331
357
|
//#endregion
|
|
332
|
-
export {
|
|
358
|
+
export { stripSystemPromptCacheBoundary as C, splitSystemPromptRelocatableBoundary as S, createSystemPromptCacheBoundaryStripper as _, describeToolResultMediaPlaceholder as a, prependSystemPromptAdditionAfterCacheBoundary as b, extractToolResultText as c, measuredRequestPressure as d, preparedRequestSuffix as f, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END as g, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY as h, clampReasoning as i, formatToolResultText as l, SYSTEM_PROMPT_CACHE_BOUNDARY as m, buildBaseOptions as n, describeUnsupportedToolResultMedia as o, reasoningTagTextPolicy as p, clampMaxTokensToModel as r, extractToolResultBlockText as s, adjustMaxTokensForThinking as t, codeModeToolSurfaceObserver as u, ensureSystemPromptCacheBoundary as v, stripSystemPromptRelocatableBoundary as w, splitSystemPromptCacheBoundary as x, prepareSystemPrompt as y };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import "./number-coercion-C7HsBgUL.mjs";
|
|
2
|
+
const DEFAULT_BUDGET_OPTIONS = {};
|
|
3
|
+
const ASCII_RUN_OR_NON_ASCII_CODE_POINT_RE = /[\p{ASCII}]+|[^\p{ASCII}]/gu;
|
|
4
|
+
const WEIGHTED_CJK_RANGES = [
|
|
5
|
+
[
|
|
6
|
+
[183, 183],
|
|
7
|
+
[12288, 12703],
|
|
8
|
+
[19968, 40869],
|
|
9
|
+
[44032, 55215],
|
|
10
|
+
[65281, 65376]
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
[4352, 4607],
|
|
14
|
+
[11904, 12287],
|
|
15
|
+
[12704, 19967],
|
|
16
|
+
[40870, 40959],
|
|
17
|
+
[40960, 42239],
|
|
18
|
+
[42752, 42759],
|
|
19
|
+
[43360, 43391],
|
|
20
|
+
[55216, 55295],
|
|
21
|
+
[63744, 64255]
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
[711, 711],
|
|
25
|
+
[713, 715],
|
|
26
|
+
[729, 729],
|
|
27
|
+
[746, 747],
|
|
28
|
+
[773, 773],
|
|
29
|
+
[803, 803],
|
|
30
|
+
[65040, 65103],
|
|
31
|
+
[65377, 65500],
|
|
32
|
+
[65504, 65510]
|
|
33
|
+
],
|
|
34
|
+
[[119648, 119665]],
|
|
35
|
+
[
|
|
36
|
+
[94176, 94207],
|
|
37
|
+
[110576, 110591],
|
|
38
|
+
[110592, 110959],
|
|
39
|
+
[127488, 127743],
|
|
40
|
+
[131072, 195103],
|
|
41
|
+
[196608, 210047]
|
|
42
|
+
]
|
|
43
|
+
];
|
|
44
|
+
const WEIGHTED_CJK_RE = new RegExp(`[${WEIGHTED_CJK_RANGES.flatMap((ranges) => ranges.map(([start, end]) => `\\u{${start.toString(16)}}-\\u{${end.toString(16)}}`)).join("")}]`, "u");
|
|
45
|
+
const CJK_CATEGORY = (() => {
|
|
46
|
+
const maxCodePoint = Math.max(...WEIGHTED_CJK_RANGES.flatMap((ranges) => ranges.map(([, end]) => end)));
|
|
47
|
+
const categories = new Uint8Array(maxCodePoint + 1);
|
|
48
|
+
for (const [bucket, ranges] of WEIGHTED_CJK_RANGES.entries()) for (const [start, end] of ranges) categories.fill(bucket + 1, start, end + 1);
|
|
49
|
+
return categories;
|
|
50
|
+
})();
|
|
51
|
+
function estimateStringChars(text) {
|
|
52
|
+
return estimateStringCharsWithMinimumRawWeight(text);
|
|
53
|
+
}
|
|
54
|
+
/** Apply a raw-text safety floor without multiplying CJK adjustments twice. */
|
|
55
|
+
function estimateStringCharsWithMinimumRawWeight(text, options = DEFAULT_BUDGET_OPTIONS) {
|
|
56
|
+
const minimumRawWeight = Math.max(1, options.minimumRawWeight ?? 1);
|
|
57
|
+
if (minimumRawWeight !== 1 && minimumRawWeight !== 2) {
|
|
58
|
+
let chars = 0;
|
|
59
|
+
for (const match of text.matchAll(ASCII_RUN_OR_NON_ASCII_CODE_POINT_RE)) {
|
|
60
|
+
const segment = match[0];
|
|
61
|
+
const minimumChars = Math.ceil(segment.length * minimumRawWeight);
|
|
62
|
+
chars += segment.charCodeAt(0) <= 127 ? minimumChars : Math.max(estimateStringChars(segment), minimumChars);
|
|
63
|
+
}
|
|
64
|
+
return chars;
|
|
65
|
+
}
|
|
66
|
+
const firstWeighted = text.search(WEIGHTED_CJK_RE);
|
|
67
|
+
if (firstWeighted < 0) return text.length * minimumRawWeight;
|
|
68
|
+
let common = 0;
|
|
69
|
+
let rareBmp = 0;
|
|
70
|
+
let twoToken = 0;
|
|
71
|
+
let threeTokenSupplementary = 0;
|
|
72
|
+
let supplementary = 0;
|
|
73
|
+
for (let index = firstWeighted; index < text.length; index += 1) {
|
|
74
|
+
let codePoint = text.charCodeAt(index);
|
|
75
|
+
if (codePoint < 128) continue;
|
|
76
|
+
if (codePoint >= 55296 && codePoint <= 56319) {
|
|
77
|
+
const low = text.charCodeAt(index + 1);
|
|
78
|
+
if (low >= 56320 && low <= 57343) {
|
|
79
|
+
codePoint = 65536 + (codePoint - 55296) * 1024 + low - 56320;
|
|
80
|
+
index += 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
switch (CJK_CATEGORY[codePoint]) {
|
|
84
|
+
case 1:
|
|
85
|
+
common += 1;
|
|
86
|
+
break;
|
|
87
|
+
case 2:
|
|
88
|
+
rareBmp += 1;
|
|
89
|
+
break;
|
|
90
|
+
case 3:
|
|
91
|
+
twoToken += 1;
|
|
92
|
+
break;
|
|
93
|
+
case 4:
|
|
94
|
+
threeTokenSupplementary += 1;
|
|
95
|
+
break;
|
|
96
|
+
case 5: supplementary += 1;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return text.length * minimumRawWeight + common * (4 - minimumRawWeight) + rareBmp * (12 - minimumRawWeight) + twoToken * (8 - minimumRawWeight) + threeTokenSupplementary * (12 - 2 * minimumRawWeight) + supplementary * (16 - 2 * minimumRawWeight);
|
|
100
|
+
}
|
|
101
|
+
function estimateTokensFromChars(chars) {
|
|
102
|
+
return Math.ceil(Math.max(0, chars) / 4);
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { estimateTokensFromChars as n, estimateStringChars as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./diagnostics-
|
|
2
|
-
import "./validation-
|
|
1
|
+
import "./diagnostics-o1PrVNQb.mjs";
|
|
2
|
+
import "./validation-DGXqfvkj.mjs";
|
|
3
3
|
//#region packages/llm-core/src/model-contracts/anthropic.ts
|
|
4
4
|
function readListedClaudeCapability(ref, capability) {
|
|
5
5
|
const listed = ref.params?.claudeCapabilities;
|
|
@@ -7,10 +7,6 @@ function readListedClaudeCapability(ref, capability) {
|
|
|
7
7
|
const value = Reflect.get(listed, capability);
|
|
8
8
|
return typeof value === "boolean" ? value : void 0;
|
|
9
9
|
}
|
|
10
|
-
function normalizeClaudeModelId(modelId) {
|
|
11
|
-
const normalized = modelId?.trim().toLowerCase() ?? "";
|
|
12
|
-
return (normalized.startsWith("anthropic/") ? normalized.slice(10) : normalized).replace(/[._\s]+/g, "-");
|
|
13
|
-
}
|
|
14
10
|
const CLAUDE_FABLE_5_THINKING_PROFILE = {
|
|
15
11
|
levels: [
|
|
16
12
|
{ id: "low" },
|
|
@@ -60,7 +56,8 @@ function resolveClaudeHaiku55ModelIdentity(ref) {
|
|
|
60
56
|
}
|
|
61
57
|
/** Resolve the canonical normalized Claude model id for one runtime model ref. */
|
|
62
58
|
function resolveClaudeModelIdentity(ref) {
|
|
63
|
-
const
|
|
59
|
+
const modelId = ((typeof ref.params?.canonicalModelId === "string" ? ref.params.canonicalModelId : void 0) ?? ref.id)?.trim().toLowerCase() ?? "";
|
|
60
|
+
const normalized = (modelId.startsWith("anthropic/") ? modelId.slice(10) : modelId).replace(/[._\s]+/g, "-");
|
|
64
61
|
return /(?:^|[-/])(claude-[^/]+)$/.exec(normalized)?.[1] ?? normalized;
|
|
65
62
|
}
|
|
66
63
|
function matchClaudeModelIdentity(normalized, pattern) {
|