@openclaw/ai 2026.10.5 → 2026.10.10-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 -0
- package/dist/{anthropic-DIIiiz99.mjs → anthropic-D6spfBri.mjs} +16 -18
- package/dist/{anthropic-payload-policy-DGblkHL5.d.mts → anthropic-payload-policy-Cr8xjazC.d.mts} +6 -3
- package/dist/{anthropic-stream-reducer-DfMVFm-r.mjs → anthropic-stream-reducer-CzPXOaLM.mjs} +55 -227
- package/dist/anthropic-tool-projection-BdAS3rtJ.mjs +165 -0
- package/dist/anthropic-tool-projection-DKH-aEWU.d.mts +51 -0
- package/dist/{api-registry-BhXXYdRA.d.mts → api-registry-gDt0faai.d.mts} +2 -2
- package/dist/{assistant-output-BuhRpLeD.mjs → assistant-output-6iFA1nbC.mjs} +2 -2
- package/dist/{azure-openai-responses-DGQnXRMs.mjs → azure-openai-responses-0TqHwnlD.mjs} +8 -8
- package/dist/{cloudflare-5qSGvIUH.mjs → cloudflare-Dttf8jKq.mjs} +1 -1
- package/dist/{credential-redaction-BHxruEH6.d.mts → credential-redaction-XvsPf7Yi.d.mts} +1 -0
- package/dist/{diagnostics-tQasYct1.mjs → diagnostics-Cv7cW3pS.mjs} +3 -3
- package/dist/diagnostics.d.mts +6 -6
- package/dist/diagnostics.mjs +2 -2
- package/dist/{env-api-keys-CrxwdylR.mjs → env-api-keys-Xd8dm_aV.mjs} +10 -34
- package/dist/event-stream-CDpFza-M.d.mts +1 -0
- package/dist/{event-stream-BcqWLo_u.d.mts → event-stream-CzpE1g_o.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/{github-copilot-request-facts-DEE6gcB9.mjs → github-copilot-request-facts-F-EmvkpW.mjs} +1 -1
- package/dist/{google-interactions-zIz70M2e.mjs → google-interactions-DVQ7AaSF.mjs} +29 -50
- package/dist/{google-messages-CNbUJK5E.mjs → google-messages-DfpHVTaD.mjs} +15 -5
- package/dist/{google-provider-stream-Cn0XF1MG.mjs → google-provider-stream-DJ8ANfsS.mjs} +6 -6
- package/dist/{google-shared-BPnWP4tT.mjs → google-shared-VTcCJLW3.mjs} +21 -29
- package/dist/{google-vertex-XQ7OQtaM.mjs → google-vertex-Bkfizj7M.mjs} +3 -3
- package/dist/{google-BlbTC1Xp.mjs → google-zWpkDSeN.mjs} +4 -4
- package/dist/{host-Bf3NjYNj.mjs → host-B2gk-d1H.mjs} +5 -11
- package/dist/{host-CTDz7LXD.d.mts → host-jJOffdlW.d.mts} +4 -6
- package/dist/{host-policy-BzZluO6_.mjs → host-policy-mpqGhbeM.mjs} +1 -1
- package/dist/{index-BYDvopUB.d.mts → index-DSprYWaz.d.mts} +7 -5
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +6 -6
- package/dist/internal/anthropic.d.mts +7 -53
- package/dist/internal/anthropic.mjs +6 -5
- package/dist/internal/google-model-family.mjs +1 -1
- 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 +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +3 -3
- package/dist/internal/openai.d.mts +17 -26
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +1 -1
- package/dist/internal/retry-after.mjs +80 -55
- package/dist/internal/runtime.d.mts +9 -31
- package/dist/internal/runtime.mjs +10 -116
- package/dist/internal/shared.d.mts +9 -7
- package/dist/internal/shared.mjs +8 -6
- package/dist/internal/tool-schema.d.mts +83 -5
- package/dist/internal/tool-schema.mjs +4 -3
- package/dist/{mistral-dCDCR5ur.mjs → mistral-CATJrwne.mjs} +32 -35
- package/dist/model-request-body-BD5vy4rP.d.mts +17 -0
- package/dist/{number-coercion-C3hztWoY.mjs → number-coercion-37gmNkuA.mjs} +1 -1
- package/dist/{openai-chatgpt-responses-D8-q7cgy.mjs → openai-chatgpt-responses-CtdnpWwe.mjs} +95 -63
- package/dist/{openai-completions-CMN24pza.mjs → openai-completions-B6sET3oI.mjs} +10 -8
- package/dist/{openai-completions-compat-i-nLZxFy.d.mts → openai-completions-compat-1gsjP-KO.d.mts} +6 -3
- package/dist/{openai-completions-compat-CYX18uDk.mjs → openai-completions-compat-CFhQ3UVU.mjs} +7 -2
- package/dist/{openai-completions-transport-DuXQOxrH.mjs → openai-completions-transport-DviPEqw3.mjs} +369 -237
- package/dist/{openai-prompt-cache-r93BJhjm.mjs → openai-prompt-cache-DJ_P143P.mjs} +1 -1
- package/dist/{openai-prompt-cache-DIPMrMFy.d.mts → openai-prompt-cache-DgjD-UL5.d.mts} +2 -2
- package/dist/{openai-responses-BMxoJdTC.mjs → openai-responses-BXsJK-mD.mjs} +13 -15
- package/dist/{openai-responses-compaction-replay-B2FE4Nw8.d.mts → openai-responses-compaction-replay-Cvnl_nCq.d.mts} +5 -5
- package/dist/{openai-responses-contracts-DlKMMTxK.mjs → openai-responses-contracts-Bx-16mnf.mjs} +45 -6
- package/dist/{openai-responses-contracts-DKqMJ1Ct.d.mts → openai-responses-contracts-CQ4_AWjL.d.mts} +20 -8
- package/dist/{openai-responses-endpoint-CinGh4VZ.mjs → openai-responses-endpoint-D4v-eeYy.mjs} +55 -22
- package/dist/{openai-responses-payload-policy-C7GsA1y0.d.mts → openai-responses-payload-policy-BzM52TTH.d.mts} +9 -3
- package/dist/openai-responses-request-lifecycle-CTdAb2v1.mjs +246 -0
- package/dist/{openai-responses-shared-afo9-s16.mjs → openai-responses-shared-Bv_1NtH9.mjs} +284 -173
- package/dist/{openai-responses-terminal-usage-BygjiAdi.d.mts → openai-responses-terminal-usage-CpVjkqn-.d.mts} +2 -2
- package/dist/{openai-tool-schema-DDPXsvJP.mjs → openai-tool-schema-Buv0GXFb.mjs} +170 -237
- package/dist/overflow-DJHXTNBQ.mjs +117 -0
- package/dist/{positive-integer-CqWjqSi9.mjs → positive-integer-Bb4Evc7L.mjs} +1 -1
- package/dist/prompt-cache-stability-D_MeCQFI.mjs +32 -0
- package/dist/{provider-error-xumb1V3F.d.mts → provider-error-CnaWYTRY.d.mts} +1 -0
- package/dist/{provider-error-CF9GWCs2.mjs → provider-error-qtZD2inE.mjs} +75 -13
- package/dist/{provider-options-CVrXZBtA.d.mts → provider-options-DeYeaflL.d.mts} +52 -6
- package/dist/{transport-utils-34BQoXq3.mjs → provider-replay-context-J6CfU3m1.mjs} +28 -5
- package/dist/{provider-transport-turn-state-BYrELw8H.mjs → provider-transport-turn-state-Jxppzuc2.mjs} +5 -5
- package/dist/{provider-types-CHtRx0dI.d.mts → provider-types-ODq57rG_.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-CpOy9-IQ.mjs → reasoning-tag-text-partitioner-DzlRubwU.mjs} +134 -47
- package/dist/{required-api-key-CFJvcFy_.mjs → required-api-key-D088S4Cd.mjs} +1 -1
- package/dist/{retry-after-CdCURCVg.d.mts → retry-after-sw-XX8aC.d.mts} +1 -1
- package/dist/sanitize-unicode-CRGuMONI.mjs +8 -0
- package/dist/sanitize-unicode-ZqVLLEKC.d.mts +27 -0
- package/dist/{session-resources-D1wgDQ8C.mjs → session-resources-vKvGIE3J.mjs} +1 -10
- package/dist/{simple-options-BAu4B54D.mjs → simple-options-BYgC6kse.mjs} +68 -79
- package/dist/{src-C44MKrW5.mjs → src-CyA0zJnt.mjs} +6 -2
- package/dist/{stream-Dd8DwRFL.mjs → stream-DLBirT0e.mjs} +8 -47
- package/dist/{stream-first-event-timeout-Dc42hKv6.mjs → stream-first-event-timeout-D_TfJHRJ.mjs} +1 -1
- package/dist/{string-coerce-CtgOVOSv.mjs → string-coerce-Cj8sqWHx.mjs} +26 -1
- package/dist/tool-schema-json-projection-B0hHDV7N.mjs +492 -0
- package/dist/{transport-stream-shared-BmpzDtdQ.d.mts → transport-stream-shared-8ru8eX4s.d.mts} +5 -5
- package/dist/{transport-stream-shared-CWGOuLcA.mjs → transport-stream-shared-CzQlAzJH.mjs} +27 -75
- package/dist/transports.d.mts +33 -28
- package/dist/transports.mjs +42 -48
- package/dist/{types-CQc6JNG4.mjs → types-BXd0kI8-.mjs} +1 -1
- package/dist/types-CBJthzJX.d.mts +1 -0
- package/dist/{types-Bd2T86VJ.d.mts → types-CVYzKrMl.d.mts} +20 -3
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +4 -4
- package/dist/{validation-ZX_sPVV0.mjs → validation-9FSkE8T-.mjs} +22 -3
- package/dist/{validation-DdGB1yy3.d.mts → validation-BQ5u20Ru.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +3 -3
- package/dist/assistant-text-phase-mvdMcrY-.mjs +0 -50
- package/dist/event-stream-6UNs-AhN.d.mts +0 -1
- package/dist/expect-lbe3Hgrh.mjs +0 -8
- package/dist/json-schema-Bp07Qui3.mjs +0 -22
- package/dist/openai-responses-request-lifecycle-NSIJo9jY.mjs +0 -67
- package/dist/openai-tool-projection-793cE3QX.d.mts +0 -37
- package/dist/openai-tool-schema-a5ysBBga.d.mts +0 -32
- package/dist/rolldown-runtime-BhDjJH2R.mjs +0 -15
- package/dist/sanitize-unicode-CjDG6jJx.d.mts +0 -5
- package/dist/string-normalization-I3ux50s9.mjs +0 -28
- package/dist/text-signature-CUXnvk_c.mjs +0 -34
- package/dist/tool-schema-json-projection-B8sG1I9v.mjs +0 -180
- package/dist/types-Kdfw_04V.d.mts +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./diagnostics-DzrF1h4J.mjs";
|
|
2
|
-
import "./validation-
|
|
2
|
+
import "./validation-9FSkE8T-.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;
|
|
@@ -137,6 +137,10 @@ function supportsClaudeAdaptiveThinking(ref) {
|
|
|
137
137
|
function supportsClaude1MContext(ref) {
|
|
138
138
|
return supportsClaudeAdaptiveThinkingById(ref);
|
|
139
139
|
}
|
|
140
|
+
/** Return whether Anthropic documents threshold compaction (`compact_20260112`) for a Claude model. */
|
|
141
|
+
function supportsClaudeServerCompaction(ref) {
|
|
142
|
+
return supportsClaudeAdaptiveThinkingById(ref);
|
|
143
|
+
}
|
|
140
144
|
/** Return whether a Claude model supports Anthropic's native fast mode. */
|
|
141
145
|
function supportsClaudeFastMode(ref) {
|
|
142
146
|
const modelId = resolveClaudeModelIdentity(ref);
|
|
@@ -247,4 +251,4 @@ function calculateUsageCost(usage, pricing) {
|
|
|
247
251
|
return cost;
|
|
248
252
|
}
|
|
249
253
|
//#endregion
|
|
250
|
-
export { supportsClaude1MContext as C, supportsClaudeNativeMaxEffort as D, supportsClaudeInHistorySystemMessages as E, supportsClaudeNativeXhighEffort as O, resolveClaudeSonnet5ModelIdentity as S, supportsClaudeFastMode as T, resolveClaudeMythos5ModelIdentity as _, CLAUDE_HAIKU_55_THINKING_PROFILE as a, resolveClaudeOpus5ModelIdentity as b, CLAUDE_SONNET_55_THINKING_PROFILE as c, requiresClaudeBetweenToolsThinking as d, requiresClaudeDefaultSampling as f, resolveClaudeModelIdentity as g, resolveClaudeHaiku55ModelIdentity as h, CLAUDE_FABLE_5_THINKING_PROFILE as i, CLAUDE_SONNET_5_THINKING_PROFILE as l, resolveClaudeFable5ModelIdentity as m, normalizeModelCostConfig as n, CLAUDE_OPUS_55_THINKING_PROFILE as o, requiresClaudeMandatoryAdaptiveThinking as p, normalizeResolvedPricing as r, CLAUDE_OPUS_5_THINKING_PROFILE as s, calculateUsageCost as t, bindsClaudeThinkingPrefix as u, resolveClaudeNativeThinkingLevelMap as v, supportsClaudeAdaptiveThinking as w, resolveClaudeSonnet55ModelIdentity as x, resolveClaudeOpus55ModelIdentity as y };
|
|
254
|
+
export { supportsClaude1MContext as C, supportsClaudeNativeMaxEffort as D, supportsClaudeInHistorySystemMessages as E, supportsClaudeNativeXhighEffort as O, resolveClaudeSonnet5ModelIdentity as S, supportsClaudeFastMode as T, resolveClaudeMythos5ModelIdentity as _, CLAUDE_HAIKU_55_THINKING_PROFILE as a, resolveClaudeOpus5ModelIdentity as b, CLAUDE_SONNET_55_THINKING_PROFILE as c, requiresClaudeBetweenToolsThinking as d, requiresClaudeDefaultSampling as f, resolveClaudeModelIdentity as g, resolveClaudeHaiku55ModelIdentity as h, CLAUDE_FABLE_5_THINKING_PROFILE as i, supportsClaudeServerCompaction as k, CLAUDE_SONNET_5_THINKING_PROFILE as l, resolveClaudeFable5ModelIdentity as m, normalizeModelCostConfig as n, CLAUDE_OPUS_55_THINKING_PROFILE as o, requiresClaudeMandatoryAdaptiveThinking as p, normalizeResolvedPricing as r, CLAUDE_OPUS_5_THINKING_PROFILE as s, calculateUsageCost as t, bindsClaudeThinkingPrefix as u, resolveClaudeNativeThinkingLevelMap as v, supportsClaudeAdaptiveThinking as w, resolveClaudeSonnet55ModelIdentity as x, resolveClaudeOpus55ModelIdentity as y };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as bindAssistantMessageEventStream, o as getEventStreamCompletion } from "./event-stream-X2gmsUWv.mjs";
|
|
2
|
-
import { i as getDefaultAiTransportHost, n as createAiTransportHost, o as runWithAiTransportHost, s as supportsScopedAiTransportHosts } from "./host-
|
|
3
|
-
import {
|
|
2
|
+
import { i as getDefaultAiTransportHost, n as createAiTransportHost, o as runWithAiTransportHost, s as supportsScopedAiTransportHosts } from "./host-B2gk-d1H.mjs";
|
|
3
|
+
import { t as cleanupSessionResources } from "./session-resources-vKvGIE3J.mjs";
|
|
4
4
|
//#region packages/ai/src/api-registry.ts
|
|
5
5
|
function wrapStream(api, stream) {
|
|
6
6
|
return (model, context, options) => {
|
|
@@ -40,31 +40,6 @@ function createApiRegistry() {
|
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region packages/ai/src/stream.ts
|
|
43
|
-
const defaultHostSessionReferences = /* @__PURE__ */ new Set();
|
|
44
|
-
const defaultHostSessionFinalizer = new FinalizationRegistry((reference) => defaultHostSessionReferences.delete(reference));
|
|
45
|
-
function trackDefaultHostSessions(sessions) {
|
|
46
|
-
const reference = new WeakRef(sessions);
|
|
47
|
-
defaultHostSessionReferences.add(reference);
|
|
48
|
-
defaultHostSessionFinalizer.register(sessions, reference, reference);
|
|
49
|
-
}
|
|
50
|
-
function selectDefaultHostSessions(sessions, sessionId) {
|
|
51
|
-
return sessionId ? [[sessionId, sessions.get(sessionId)]] : sessions;
|
|
52
|
-
}
|
|
53
|
-
registerSessionResourceCleanupObserver((sessionId, owner) => {
|
|
54
|
-
for (const reference of defaultHostSessionReferences) {
|
|
55
|
-
const sessions = reference.deref();
|
|
56
|
-
if (!sessions) {
|
|
57
|
-
defaultHostSessionReferences.delete(reference);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const pruneOwners = (owners) => {
|
|
61
|
-
if (owner) owners.delete(owner);
|
|
62
|
-
else owners.clear();
|
|
63
|
-
return owners.size === 0;
|
|
64
|
-
};
|
|
65
|
-
for (const [ownedSessionId, owners] of selectDefaultHostSessions(sessions, sessionId)) if (owners && pruneOwners(owners)) sessions.delete(ownedSessionId);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
43
|
function retainUnscopedStreamLifetime(stream, runWithHost) {
|
|
69
44
|
let releaseLifetime;
|
|
70
45
|
const lifetime = new Promise((resolve) => {
|
|
@@ -180,16 +155,9 @@ function retainUnscopedStreamLifetime(stream, runWithHost) {
|
|
|
180
155
|
}
|
|
181
156
|
function createRuntime(registry, transportHost) {
|
|
182
157
|
const explicitHost = transportHost === void 0 ? void 0 : createAiTransportHost(transportHost);
|
|
183
|
-
const defaultHostsBySession = /* @__PURE__ */ new Map();
|
|
184
|
-
if (!explicitHost) trackDefaultHostSessions(defaultHostsBySession);
|
|
185
158
|
const resolveRuntimeHost = () => explicitHost ?? getDefaultAiTransportHost();
|
|
186
|
-
const startStream = (start
|
|
159
|
+
const startStream = (start) => {
|
|
187
160
|
const host = resolveRuntimeHost();
|
|
188
|
-
if (!explicitHost) {
|
|
189
|
-
const hosts = defaultHostsBySession.get(sessionId) ?? /* @__PURE__ */ new Set();
|
|
190
|
-
hosts.add(host);
|
|
191
|
-
defaultHostsBySession.set(sessionId, hosts);
|
|
192
|
-
}
|
|
193
161
|
const runWithStreamHost = (operation) => runWithAiTransportHost(host, operation);
|
|
194
162
|
const started = runWithStreamHost(start);
|
|
195
163
|
const completion = getEventStreamCompletion(started);
|
|
@@ -214,13 +182,13 @@ function createRuntime(registry, transportHost) {
|
|
|
214
182
|
return provider;
|
|
215
183
|
}
|
|
216
184
|
function stream(model, context, options) {
|
|
217
|
-
return startStream(() => resolveApiProvider(model.api).stream(model, context, options)
|
|
185
|
+
return startStream(() => resolveApiProvider(model.api).stream(model, context, options));
|
|
218
186
|
}
|
|
219
187
|
async function complete(model, context, options) {
|
|
220
188
|
return stream(model, context, options).result();
|
|
221
189
|
}
|
|
222
190
|
function streamSimple(model, context, options) {
|
|
223
|
-
return startStream(() => resolveApiProvider(model.api).streamSimple(model, context, options)
|
|
191
|
+
return startStream(() => resolveApiProvider(model.api).streamSimple(model, context, options));
|
|
224
192
|
}
|
|
225
193
|
async function completeSimple(model, context, options) {
|
|
226
194
|
return streamSimple(model, context, options).result();
|
|
@@ -230,19 +198,12 @@ function createRuntime(registry, transportHost) {
|
|
|
230
198
|
cleanupSessionResources(sessionId);
|
|
231
199
|
return;
|
|
232
200
|
}
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
for (const [, owners] of selectDefaultHostSessions(defaultHostsBySession, sessionId)) for (const host of owners ?? []) usedHosts.add(host);
|
|
236
|
-
usedHosts.add(getDefaultAiTransportHost());
|
|
237
|
-
}
|
|
238
|
-
const hosts = explicitHost ? [explicitHost] : [...usedHosts];
|
|
239
|
-
const errors = [];
|
|
240
|
-
for (const host of hosts) try {
|
|
201
|
+
const host = resolveRuntimeHost();
|
|
202
|
+
try {
|
|
241
203
|
runWithAiTransportHost(host, () => cleanupSessionResources(sessionId, host));
|
|
242
204
|
} catch (error) {
|
|
243
|
-
|
|
205
|
+
throw new AggregateError([error], "Failed to cleanup runtime session resources", { cause: error });
|
|
244
206
|
}
|
|
245
|
-
if (errors.length > 0) throw new AggregateError(errors, "Failed to cleanup runtime session resources");
|
|
246
207
|
}
|
|
247
208
|
return {
|
|
248
209
|
registry,
|
package/dist/{stream-first-event-timeout-Dc42hKv6.mjs → stream-first-event-timeout-D_TfJHRJ.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as clampTimerTimeoutMs } from "./number-coercion-
|
|
1
|
+
import { a as clampTimerTimeoutMs } from "./number-coercion-37gmNkuA.mjs";
|
|
2
2
|
//#region packages/ai/src/utils/stream-first-event-timeout.ts
|
|
3
3
|
function getFirstStreamEventTimeoutMs(options) {
|
|
4
4
|
return options?.firstEventTimeoutMs;
|
|
@@ -30,9 +30,34 @@ function normalizeOptionalLowercaseString(value) {
|
|
|
30
30
|
function normalizeLowercaseStringOrEmpty(value) {
|
|
31
31
|
return normalizeOptionalLowercaseString(value) ?? "";
|
|
32
32
|
}
|
|
33
|
+
/** Parses loose boolean/fast-mode flags from strings or booleans. */
|
|
34
|
+
function normalizeFastMode(raw) {
|
|
35
|
+
if (typeof raw === "boolean") return raw;
|
|
36
|
+
const key = normalizeLowercaseStringOrEmpty(raw);
|
|
37
|
+
if ([
|
|
38
|
+
"off",
|
|
39
|
+
"false",
|
|
40
|
+
"no",
|
|
41
|
+
"0",
|
|
42
|
+
"disable",
|
|
43
|
+
"disabled",
|
|
44
|
+
"normal"
|
|
45
|
+
].includes(key)) return false;
|
|
46
|
+
if ([
|
|
47
|
+
"on",
|
|
48
|
+
"true",
|
|
49
|
+
"yes",
|
|
50
|
+
"1",
|
|
51
|
+
"enable",
|
|
52
|
+
"enabled",
|
|
53
|
+
"fast"
|
|
54
|
+
].includes(key)) return true;
|
|
55
|
+
if (key === "ultrafast") return "ultrafast";
|
|
56
|
+
if (["auto", "automatic"].includes(key)) return "auto";
|
|
57
|
+
}
|
|
33
58
|
/** Type guard for strings that remain non-empty after trimming. */
|
|
34
59
|
function hasNonEmptyString(value) {
|
|
35
60
|
return normalizeOptionalString(value) !== void 0;
|
|
36
61
|
}
|
|
37
62
|
//#endregion
|
|
38
|
-
export {
|
|
63
|
+
export { normalizeOptionalLowercaseString as a, readNonEmptyStringPreservingWhitespace as c, normalizeNullableString as i, readStringValue as l, normalizeFastMode as n, normalizeOptionalString as o, normalizeLowercaseStringOrEmpty as r, normalizeStringifiedOptionalString as s, hasNonEmptyString as t };
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { a as asRecord, o as isRecord } from "./record-coerce-CNDovvft.mjs";
|
|
2
|
+
import { r as parseLocalSchemaRefPointer } from "./validation-9FSkE8T-.mjs";
|
|
3
|
+
import { o as normalizeOptionalString } from "./string-coerce-Cj8sqWHx.mjs";
|
|
4
|
+
import { r as getAiTransportHost } from "./host-B2gk-d1H.mjs";
|
|
5
|
+
import { hash } from "node:crypto";
|
|
6
|
+
import { types } from "node:util";
|
|
7
|
+
//#region packages/normalization-core/src/node-crypto.ts
|
|
8
|
+
function sha256Hex(input) {
|
|
9
|
+
return hash("sha256", input, "hex");
|
|
10
|
+
}
|
|
11
|
+
function sha256HexPrefixCore(input, length) {
|
|
12
|
+
return sha256Hex(input).slice(0, length);
|
|
13
|
+
}
|
|
14
|
+
/** Redacts an identifier to a stable hash label, or "-" for missing values. */
|
|
15
|
+
function redactIdentifier(value, opts) {
|
|
16
|
+
const trimmed = normalizeOptionalString(value);
|
|
17
|
+
if (!trimmed) return "-";
|
|
18
|
+
const len = opts?.len ?? 12;
|
|
19
|
+
return `sha256:${sha256HexPrefixCore(trimmed, Number.isFinite(len) ? Math.max(1, Math.floor(len)) : 12)}`;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region packages/ai/src/providers/schema-walk.ts
|
|
23
|
+
const SCHEMA_MAP_KEYS = /* @__PURE__ */ new Set([
|
|
24
|
+
"$defs",
|
|
25
|
+
"definitions",
|
|
26
|
+
"dependentSchemas",
|
|
27
|
+
"dependencies",
|
|
28
|
+
"patternProperties",
|
|
29
|
+
"properties"
|
|
30
|
+
]);
|
|
31
|
+
/** Containers whose value is a single nested schema. */
|
|
32
|
+
const SCHEMA_OBJECT_KEYS = /* @__PURE__ */ new Set([
|
|
33
|
+
"additionalItems",
|
|
34
|
+
"additionalProperties",
|
|
35
|
+
"contains",
|
|
36
|
+
"contentSchema",
|
|
37
|
+
"else",
|
|
38
|
+
"if",
|
|
39
|
+
"items",
|
|
40
|
+
"not",
|
|
41
|
+
"propertyNames",
|
|
42
|
+
"then",
|
|
43
|
+
"unevaluatedItems",
|
|
44
|
+
"unevaluatedProperties"
|
|
45
|
+
]);
|
|
46
|
+
/** Containers whose value is a list of nested schemas. */
|
|
47
|
+
const SCHEMA_ARRAY_KEYS = /* @__PURE__ */ new Set([
|
|
48
|
+
"allOf",
|
|
49
|
+
"anyOf",
|
|
50
|
+
"items",
|
|
51
|
+
"oneOf",
|
|
52
|
+
"prefixItems"
|
|
53
|
+
]);
|
|
54
|
+
const SCHEMA_NESTED_KEYS = new Set([...SCHEMA_OBJECT_KEYS, ...SCHEMA_ARRAY_KEYS].toSorted());
|
|
55
|
+
function* walkSchemaArray(schemas, visit, result = []) {
|
|
56
|
+
result.length = schemas.length;
|
|
57
|
+
for (let index = 0; index < result.length; index += 1) if (index in schemas) result[index] = yield visit(schemas[index]);
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
function* walkSchemaValue(schema, ancestors, visitObject) {
|
|
61
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
62
|
+
if (ancestors.has(schema)) throw new TypeError("Tool schema contains a circular reference.");
|
|
63
|
+
ancestors.add(schema);
|
|
64
|
+
try {
|
|
65
|
+
return yield Array.isArray(schema) ? walkSchemaArray(schema, (entry) => walkSchemaValue(entry, ancestors, visitObject)) : visitObject(asRecord(schema));
|
|
66
|
+
} finally {
|
|
67
|
+
ancestors.delete(schema);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Resume child schema walks on a heap stack, never through recursive yield delegation. */
|
|
71
|
+
function evaluateSchemaWalk(walk) {
|
|
72
|
+
const parents = [];
|
|
73
|
+
let current = walk;
|
|
74
|
+
let value;
|
|
75
|
+
try {
|
|
76
|
+
while (true) {
|
|
77
|
+
const step = current.next(value);
|
|
78
|
+
if (!step.done) {
|
|
79
|
+
parents.push(current);
|
|
80
|
+
current = step.value;
|
|
81
|
+
value = void 0;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
value = step.value;
|
|
85
|
+
const parent = parents.pop();
|
|
86
|
+
if (!parent) return value;
|
|
87
|
+
current = parent;
|
|
88
|
+
}
|
|
89
|
+
} finally {
|
|
90
|
+
let parent;
|
|
91
|
+
while (parent = parents.pop()) parent.return(void 0);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region packages/ai/src/providers/tool-schema-depth.ts
|
|
96
|
+
/** Schema nodes and expanded references share this budget; containers are transparent. */
|
|
97
|
+
const MAX_TOOL_SCHEMA_DEPTH = 128;
|
|
98
|
+
/** Classify children after toJSON when serializing, or directly when normalizing. */
|
|
99
|
+
function toolSchemaChildPosition(position, parent, key, child) {
|
|
100
|
+
if (!position || typeof child !== "boolean" && (!child || typeof child !== "object")) return;
|
|
101
|
+
if (position.kind === "dependencies" && Array.isArray(child)) return;
|
|
102
|
+
if (position.kind !== "schema" || Array.isArray(parent)) return {
|
|
103
|
+
kind: "schema",
|
|
104
|
+
depth: position.depth + 1
|
|
105
|
+
};
|
|
106
|
+
if (SCHEMA_MAP_KEYS.has(key) && isRecord(child)) return {
|
|
107
|
+
kind: key === "dependencies" ? "dependencies" : "map",
|
|
108
|
+
depth: position.depth
|
|
109
|
+
};
|
|
110
|
+
if (SCHEMA_ARRAY_KEYS.has(key) && Array.isArray(child)) return {
|
|
111
|
+
kind: "array",
|
|
112
|
+
depth: position.depth
|
|
113
|
+
};
|
|
114
|
+
return SCHEMA_OBJECT_KEYS.has(key) ? {
|
|
115
|
+
kind: "schema",
|
|
116
|
+
depth: position.depth + 1
|
|
117
|
+
} : void 0;
|
|
118
|
+
}
|
|
119
|
+
const reportedSchemas = /* @__PURE__ */ new WeakMap();
|
|
120
|
+
const truncatedSchemaResults = /* @__PURE__ */ new WeakSet();
|
|
121
|
+
function wasToolSchemaTruncated(schema) {
|
|
122
|
+
return schema !== null && typeof schema === "object" && truncatedSchemaResults.has(schema);
|
|
123
|
+
}
|
|
124
|
+
/** Preserve reduced-validation provenance across schema copies without repeating diagnostics. */
|
|
125
|
+
function inheritToolSchemaTruncation(source, result, truncated = false) {
|
|
126
|
+
if (result && typeof result === "object") {
|
|
127
|
+
if (truncated || wasToolSchemaTruncated(source)) truncatedSchemaResults.add(result);
|
|
128
|
+
const names = source && typeof source === "object" ? reportedSchemas.get(source) : void 0;
|
|
129
|
+
if (names) reportedSchemas.set(result, names);
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
function reportToolSchemaTruncation(schema, toolName) {
|
|
134
|
+
if (!schema || typeof schema !== "object") return;
|
|
135
|
+
const names = reportedSchemas.get(schema) ?? /* @__PURE__ */ new Set();
|
|
136
|
+
reportedSchemas.set(schema, names);
|
|
137
|
+
if (!toolName || names.has(toolName)) return;
|
|
138
|
+
names.add(toolName);
|
|
139
|
+
getAiTransportHost().logWarn("[tool-schema]", `Tool "${toolName}" schema exceeds 128 nested levels; deep subschemas were replaced with {}. The tool remains available with reduced validation.`);
|
|
140
|
+
}
|
|
141
|
+
/** Bound schema structure without changing literal data or caching mutable provider inputs. */
|
|
142
|
+
function truncateToolSchemaDepth(schema, toolName) {
|
|
143
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
144
|
+
let truncated = false;
|
|
145
|
+
function visit(node, position) {
|
|
146
|
+
if (!position) return node;
|
|
147
|
+
if (position.kind === "schema" && wasToolSchemaTruncated(node)) truncated = true;
|
|
148
|
+
if (position.kind === "schema" && position.depth > 128) {
|
|
149
|
+
truncated = true;
|
|
150
|
+
return {};
|
|
151
|
+
}
|
|
152
|
+
if (!node || typeof node !== "object") return node;
|
|
153
|
+
if (ancestors.has(node)) throw new TypeError("Tool schema contains a circular reference.");
|
|
154
|
+
ancestors.add(node);
|
|
155
|
+
try {
|
|
156
|
+
if (Array.isArray(node)) {
|
|
157
|
+
let changed = false;
|
|
158
|
+
const entries = node.map((entry, index) => {
|
|
159
|
+
const next = visit(entry, toolSchemaChildPosition(position, node, String(index), entry));
|
|
160
|
+
changed ||= next !== entry;
|
|
161
|
+
return next;
|
|
162
|
+
});
|
|
163
|
+
return changed ? entries : node;
|
|
164
|
+
}
|
|
165
|
+
let changed = false;
|
|
166
|
+
const entries = Object.entries(node).map(([key, value]) => {
|
|
167
|
+
const next = visit(value, toolSchemaChildPosition(position, node, key, value));
|
|
168
|
+
changed ||= next !== value;
|
|
169
|
+
return [key, next];
|
|
170
|
+
});
|
|
171
|
+
return changed ? Object.fromEntries(entries) : node;
|
|
172
|
+
} finally {
|
|
173
|
+
ancestors.delete(node);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const normalized = visit(schema, {
|
|
177
|
+
kind: "schema",
|
|
178
|
+
depth: 0
|
|
179
|
+
});
|
|
180
|
+
if (truncated) reportToolSchemaTruncation(schema, toolName);
|
|
181
|
+
return inheritToolSchemaTruncation(schema, normalized, truncated);
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region packages/ai/src/providers/tool-schema-refs.ts
|
|
185
|
+
function setOwnSchemaProperty(target, key, value) {
|
|
186
|
+
Object.defineProperty(target, key, {
|
|
187
|
+
value,
|
|
188
|
+
enumerable: true,
|
|
189
|
+
configurable: true,
|
|
190
|
+
writable: true
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
function copySchemaMeta(from, to) {
|
|
194
|
+
for (const key of [
|
|
195
|
+
"title",
|
|
196
|
+
"description",
|
|
197
|
+
"default"
|
|
198
|
+
]) if (key in from && from[key] !== void 0) to[key] = from[key];
|
|
199
|
+
}
|
|
200
|
+
function extendSchemaDefs(defs, schema) {
|
|
201
|
+
const defsEntry = isRecord(schema.$defs) ? schema.$defs : void 0;
|
|
202
|
+
const legacyDefsEntry = isRecord(schema.definitions) ? schema.definitions : void 0;
|
|
203
|
+
if (!defsEntry && !legacyDefsEntry) return defs;
|
|
204
|
+
const next = {
|
|
205
|
+
$defs: new Map(defs?.$defs),
|
|
206
|
+
definitions: new Map(defs?.definitions)
|
|
207
|
+
};
|
|
208
|
+
if (defsEntry) for (const [key, value] of Object.entries(defsEntry)) next.$defs.set(key, value);
|
|
209
|
+
if (legacyDefsEntry) for (const [key, value] of Object.entries(legacyDefsEntry)) next.definitions.set(key, value);
|
|
210
|
+
return next;
|
|
211
|
+
}
|
|
212
|
+
function resolveJsonPointerPath(value, tokens) {
|
|
213
|
+
let current = value;
|
|
214
|
+
for (const key of tokens) {
|
|
215
|
+
if (!current || typeof current !== "object") return;
|
|
216
|
+
if (Array.isArray(current)) {
|
|
217
|
+
const index = /^(?:0|[1-9]\d*)$/.test(key) ? Number(key) : -1;
|
|
218
|
+
if (index < 0 || index >= current.length) return;
|
|
219
|
+
current = current[index];
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (!isRecord(current) || !Object.hasOwn(current, key)) return;
|
|
223
|
+
current = current[key];
|
|
224
|
+
}
|
|
225
|
+
return current;
|
|
226
|
+
}
|
|
227
|
+
const SCHEMA_LITERAL_KEYS = /* @__PURE__ */ new Set([
|
|
228
|
+
"const",
|
|
229
|
+
"default",
|
|
230
|
+
"enum",
|
|
231
|
+
"examples"
|
|
232
|
+
]);
|
|
233
|
+
function tryResolveLocalRef(ref, defs, rootDocument) {
|
|
234
|
+
const tokens = parseLocalSchemaRefPointer(ref);
|
|
235
|
+
if (!tokens) return;
|
|
236
|
+
const [table, name, ...remainingPath] = tokens;
|
|
237
|
+
if (defs && name && (table === "$defs" || table === "definitions")) {
|
|
238
|
+
const resolved = (table === "$defs" ? defs.$defs : defs.definitions).get(name);
|
|
239
|
+
if (resolved !== void 0) return resolveJsonPointerPath(resolved, remainingPath);
|
|
240
|
+
}
|
|
241
|
+
return resolveJsonPointerPath(rootDocument, tokens);
|
|
242
|
+
}
|
|
243
|
+
function inlineLocalSchemaRefsWithDefs(schema, defs, refStack, state, rootDocument, depth = 0) {
|
|
244
|
+
if (depth > 128) {
|
|
245
|
+
state.truncated = true;
|
|
246
|
+
return {};
|
|
247
|
+
}
|
|
248
|
+
if (Array.isArray(schema)) return schema.map((entry) => inlineLocalSchemaRefsWithDefs(entry, defs, refStack, state, rootDocument, depth + 1));
|
|
249
|
+
if (!isRecord(schema)) return schema;
|
|
250
|
+
const obj = schema;
|
|
251
|
+
const nextDefs = extendSchemaDefs(defs, obj);
|
|
252
|
+
const refValue = typeof obj.$ref === "string" ? obj.$ref : void 0;
|
|
253
|
+
if (refValue) {
|
|
254
|
+
if (refStack?.has(refValue)) return {};
|
|
255
|
+
const resolved = tryResolveLocalRef(refValue, nextDefs, rootDocument);
|
|
256
|
+
if (resolved === void 0) {
|
|
257
|
+
if (refValue.startsWith("#/") || parseLocalSchemaRefPointer(refValue)) state.unresolvedLocalRefs = true;
|
|
258
|
+
return { ...obj };
|
|
259
|
+
}
|
|
260
|
+
const nextRefStack = new Set(refStack);
|
|
261
|
+
nextRefStack.add(refValue);
|
|
262
|
+
const inlined = inlineLocalSchemaRefsWithDefs(resolved, nextDefs, nextRefStack, state, rootDocument, depth + 1);
|
|
263
|
+
if (!isRecord(inlined)) return inlined;
|
|
264
|
+
const result = { ...inlined };
|
|
265
|
+
copySchemaMeta(obj, result);
|
|
266
|
+
if (obj.nullable === true) result.nullable = true;
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
const result = {};
|
|
270
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
271
|
+
if (key === "$defs" || key === "definitions" || key === "components") continue;
|
|
272
|
+
let next = value;
|
|
273
|
+
if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) {
|
|
274
|
+
const entries = Object.entries(value);
|
|
275
|
+
for (const entry of entries) {
|
|
276
|
+
if (key === "dependencies" && Array.isArray(entry[1])) continue;
|
|
277
|
+
entry[1] = inlineLocalSchemaRefsWithDefs(entry[1], nextDefs, refStack, state, rootDocument, depth + 1);
|
|
278
|
+
}
|
|
279
|
+
next = Object.fromEntries(entries);
|
|
280
|
+
} else if (SCHEMA_OBJECT_KEYS.has(key) && isRecord(value)) next = inlineLocalSchemaRefsWithDefs(value, nextDefs, refStack, state, rootDocument, depth + 1);
|
|
281
|
+
else if (SCHEMA_ARRAY_KEYS.has(key) && Array.isArray(value)) next = value.map((entry) => inlineLocalSchemaRefsWithDefs(entry, nextDefs, refStack, state, rootDocument, depth + 1));
|
|
282
|
+
setOwnSchemaProperty(result, key, next);
|
|
283
|
+
}
|
|
284
|
+
if (state.unresolvedLocalRefs) {
|
|
285
|
+
for (const key of [
|
|
286
|
+
"$defs",
|
|
287
|
+
"definitions",
|
|
288
|
+
"components"
|
|
289
|
+
]) if (key in obj) result[key] = obj[key];
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
293
|
+
/** Inline local $ref pointers so providers receive self-contained tool schemas. */
|
|
294
|
+
function inlineLocalToolSchemaRefs(schema, toolName) {
|
|
295
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
296
|
+
const boundedSchema = truncateToolSchemaDepth(schema, toolName);
|
|
297
|
+
const state = {
|
|
298
|
+
unresolvedLocalRefs: false,
|
|
299
|
+
truncated: false
|
|
300
|
+
};
|
|
301
|
+
const schemaRecord = boundedSchema;
|
|
302
|
+
const normalized = inlineLocalSchemaRefsWithDefs(boundedSchema, Array.isArray(boundedSchema) ? extendSchemaDefs(void 0, schemaRecord) : void 0, void 0, state, boundedSchema);
|
|
303
|
+
const bounded = truncateToolSchemaDepth(normalized);
|
|
304
|
+
if (state.truncated || bounded !== normalized) reportToolSchemaTruncation(schema, toolName);
|
|
305
|
+
return inheritToolSchemaTruncation(boundedSchema, bounded, state.truncated);
|
|
306
|
+
}
|
|
307
|
+
/** Keep compact root definitions. Fall back for scopes or refs we must rewrite. */
|
|
308
|
+
function canPreserveRootSchemaRefs(inputSchema) {
|
|
309
|
+
const schema = truncateToolSchemaDepth(inputSchema);
|
|
310
|
+
if (!isRecord(schema) || schema.type !== "object" || !isRecord(schema.properties) || ["$defs", "definitions"].some((key) => key in schema && !isRecord(schema[key])) || [
|
|
311
|
+
"anyOf",
|
|
312
|
+
"oneOf",
|
|
313
|
+
"allOf"
|
|
314
|
+
].some((key) => Array.isArray(schema[key])) || "$ref" in schema) return false;
|
|
315
|
+
let hasRefs = false;
|
|
316
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
317
|
+
function visit(node, inDefinitions = false) {
|
|
318
|
+
if (!isRecord(node)) return true;
|
|
319
|
+
if (ancestors.has(node) || "$id" in node || "id" in node || "components" in node || node !== schema && ("$defs" in node || "definitions" in node)) return false;
|
|
320
|
+
if ("$ref" in node) {
|
|
321
|
+
if (typeof node.$ref !== "string" || !/^#\/(\$defs|definitions)\/[^/]+$/.test(node.$ref) || node.nullable === true || tryResolveLocalRef(node.$ref, void 0, schema) === void 0) return false;
|
|
322
|
+
hasRefs ||= !inDefinitions;
|
|
323
|
+
}
|
|
324
|
+
ancestors.add(node);
|
|
325
|
+
try {
|
|
326
|
+
for (const [key, value] of Object.entries(node)) if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) {
|
|
327
|
+
const childInDefinitions = inDefinitions || key === "$defs" || key === "definitions";
|
|
328
|
+
if (!Object.values(value).every((entry) => visit(entry, childInDefinitions))) return false;
|
|
329
|
+
} else if (SCHEMA_ARRAY_KEYS.has(key) && Array.isArray(value)) {
|
|
330
|
+
if (!value.every((entry) => visit(entry, inDefinitions))) return false;
|
|
331
|
+
} else if (SCHEMA_OBJECT_KEYS.has(key) && !visit(value, inDefinitions)) return false;
|
|
332
|
+
return true;
|
|
333
|
+
} finally {
|
|
334
|
+
ancestors.delete(node);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return visit(schema) && hasRefs;
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region packages/ai/src/providers/tool-schema-json-projection.ts
|
|
341
|
+
const publishedSchemas = /* @__PURE__ */ new WeakMap();
|
|
342
|
+
function getPublishedRuntimeToolInputSchema(schema) {
|
|
343
|
+
return schema !== null && typeof schema === "object" ? publishedSchemas.get(schema) : void 0;
|
|
344
|
+
}
|
|
345
|
+
/** Only an owner's detached JSON publication can bypass later schema traversals. */
|
|
346
|
+
function publishRuntimeToolInputSchema(schema, path = "parameters", toolName) {
|
|
347
|
+
if (getPublishedRuntimeToolInputSchema(schema)) return projectRuntimeToolInputSchema(schema, path, toolName);
|
|
348
|
+
let json = "";
|
|
349
|
+
const projection = projectToolInputSchema(schema, path, (text) => json = text, toolName);
|
|
350
|
+
if (projection.violations.length > 0 || !isRecord(projection.schema)) return projection;
|
|
351
|
+
inheritToolSchemaTruncation(schema, projection.schema);
|
|
352
|
+
const pending = [projection.schema];
|
|
353
|
+
while (pending.length > 0) {
|
|
354
|
+
const value = pending.pop();
|
|
355
|
+
if (value && typeof value === "object") {
|
|
356
|
+
for (const child of Object.values(value)) pending.push(child);
|
|
357
|
+
Object.freeze(value);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
Object.freeze(projection.violations);
|
|
361
|
+
Object.freeze(projection);
|
|
362
|
+
publishedSchemas.set(projection.schema, Object.freeze({
|
|
363
|
+
projection,
|
|
364
|
+
json,
|
|
365
|
+
fingerprint: sha256Hex(json)
|
|
366
|
+
}));
|
|
367
|
+
return projection;
|
|
368
|
+
}
|
|
369
|
+
function isNonFiniteNumberValue(value) {
|
|
370
|
+
if (typeof value === "number") return !Number.isFinite(value);
|
|
371
|
+
if (value === null || typeof value !== "object" || !types.isNumberObject(value)) return false;
|
|
372
|
+
return !Number.isFinite(Number.prototype.valueOf.call(value));
|
|
373
|
+
}
|
|
374
|
+
function projectToolInputSchema(value, path, captureJson, toolName) {
|
|
375
|
+
const nonFiniteNumber = { path: null };
|
|
376
|
+
const ancestors = [];
|
|
377
|
+
const segments = [path];
|
|
378
|
+
let isRoot = true;
|
|
379
|
+
let truncated = false;
|
|
380
|
+
let text;
|
|
381
|
+
try {
|
|
382
|
+
text = JSON.stringify(value, function(key, sourceEntry) {
|
|
383
|
+
let entry = sourceEntry;
|
|
384
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1]?.value !== this) {
|
|
385
|
+
const parent = ancestors.pop();
|
|
386
|
+
if (parent) segments.length = parent.pathLength;
|
|
387
|
+
}
|
|
388
|
+
const position = isRoot ? {
|
|
389
|
+
kind: "schema",
|
|
390
|
+
depth: 0
|
|
391
|
+
} : toolSchemaChildPosition(ancestors[ancestors.length - 1]?.position, this, key, entry);
|
|
392
|
+
if (position?.kind === "schema" && wasToolSchemaTruncated(entry)) truncated = true;
|
|
393
|
+
if (position?.kind === "schema" && position.depth > 128) {
|
|
394
|
+
truncated = true;
|
|
395
|
+
entry = {};
|
|
396
|
+
}
|
|
397
|
+
const invalidNumber = nonFiniteNumber.path === null && isNonFiniteNumberValue(entry);
|
|
398
|
+
if (invalidNumber || entry && typeof entry === "object") {
|
|
399
|
+
const prefixLength = segments.length;
|
|
400
|
+
if (!isRoot) {
|
|
401
|
+
if (Array.isArray(this)) segments.push("[", key, "]");
|
|
402
|
+
else segments.push(".", key);
|
|
403
|
+
}
|
|
404
|
+
if (invalidNumber) {
|
|
405
|
+
nonFiniteNumber.path = segments.join("");
|
|
406
|
+
segments.length = prefixLength;
|
|
407
|
+
} else ancestors.push({
|
|
408
|
+
value: entry,
|
|
409
|
+
pathLength: prefixLength,
|
|
410
|
+
position
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
isRoot = false;
|
|
414
|
+
return entry;
|
|
415
|
+
});
|
|
416
|
+
} catch {}
|
|
417
|
+
if (!text || nonFiniteNumber.path !== null) return {
|
|
418
|
+
schema: {},
|
|
419
|
+
violations: [`${text ? nonFiniteNumber.path : path} is not JSON-serializable`]
|
|
420
|
+
};
|
|
421
|
+
if (truncated) reportToolSchemaTruncation(value, toolName);
|
|
422
|
+
const schema = inheritToolSchemaTruncation(void 0, JSON.parse(text), truncated);
|
|
423
|
+
captureJson?.(text);
|
|
424
|
+
const violations = [];
|
|
425
|
+
if (!isRecord(schema)) violations.push(`${path} must be a JSON object schema`);
|
|
426
|
+
else if (schema.type !== void 0 && schema.type !== "object") violations.push(`${path}.type must be "object"`);
|
|
427
|
+
if (!inspectJsonSchema(schema, [path], violations)) return {
|
|
428
|
+
schema: {},
|
|
429
|
+
violations: [`${path} is not a JSON value`]
|
|
430
|
+
};
|
|
431
|
+
return {
|
|
432
|
+
schema,
|
|
433
|
+
violations
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function inspectJsonSchema(schema, path, violations, inspectKeywords = true) {
|
|
437
|
+
if (Array.isArray(schema)) {
|
|
438
|
+
let index = 0;
|
|
439
|
+
for (const entry of schema) {
|
|
440
|
+
path.push("[", index++, "]");
|
|
441
|
+
const valid = inspectJsonSchema(entry, path, violations, inspectKeywords);
|
|
442
|
+
path.length -= 3;
|
|
443
|
+
if (!valid) return false;
|
|
444
|
+
}
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
if (!isRecord(schema)) return typeof schema !== "number" || Number.isFinite(schema);
|
|
448
|
+
if (inspectKeywords) {
|
|
449
|
+
for (const key of ["$dynamicRef", "$dynamicAnchor"]) if (key in schema) violations.push(`${path.join("")}.${key}`);
|
|
450
|
+
}
|
|
451
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
452
|
+
if (typeof value === "number" && !Number.isFinite(value)) return false;
|
|
453
|
+
if (!value || typeof value !== "object") continue;
|
|
454
|
+
path.push(".", key);
|
|
455
|
+
const inspectChildKeywords = inspectKeywords && !SCHEMA_LITERAL_KEYS.has(key);
|
|
456
|
+
if (inspectChildKeywords && SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const [schemaName, childSchema] of Object.entries(value)) {
|
|
457
|
+
path.push(".", schemaName);
|
|
458
|
+
const valid = inspectJsonSchema(childSchema, path, violations);
|
|
459
|
+
path.length -= 2;
|
|
460
|
+
if (!valid) return false;
|
|
461
|
+
}
|
|
462
|
+
else if (!inspectJsonSchema(value, path, violations, inspectChildKeywords)) return false;
|
|
463
|
+
path.length -= 2;
|
|
464
|
+
}
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
468
|
+
function projectRuntimeToolInputSchema(schema, path = "parameters", toolName) {
|
|
469
|
+
const published = getPublishedRuntimeToolInputSchema(schema);
|
|
470
|
+
if (published) {
|
|
471
|
+
if (wasToolSchemaTruncated(schema)) reportToolSchemaTruncation(schema, toolName);
|
|
472
|
+
return published.projection;
|
|
473
|
+
}
|
|
474
|
+
return projectToolInputSchema(schema, path, void 0, toolName);
|
|
475
|
+
}
|
|
476
|
+
/** Package-private preparation; public projections never carry normalization provenance. */
|
|
477
|
+
function prepareRuntimeToolInputSchema(schema, path, toolName) {
|
|
478
|
+
if (getPublishedRuntimeToolInputSchema(schema)) return { projection: projectRuntimeToolInputSchema(schema, path, toolName) };
|
|
479
|
+
let inputJson;
|
|
480
|
+
const projection = projectToolInputSchema(schema, path, (text) => {
|
|
481
|
+
inputJson = text;
|
|
482
|
+
}, toolName);
|
|
483
|
+
return {
|
|
484
|
+
projection,
|
|
485
|
+
...schema && typeof schema === "object" && inputJson && projection.violations.length === 0 ? { normalization: {
|
|
486
|
+
source: schema,
|
|
487
|
+
inputJson
|
|
488
|
+
} } : {}
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
//#endregion
|
|
492
|
+
export { redactIdentifier as C, walkSchemaValue as S, SCHEMA_MAP_KEYS as _, SCHEMA_LITERAL_KEYS as a, evaluateSchemaWalk as b, inlineLocalToolSchemaRefs as c, inheritToolSchemaTruncation as d, reportToolSchemaTruncation as f, SCHEMA_ARRAY_KEYS as g, wasToolSchemaTruncated as h, publishRuntimeToolInputSchema as i, setOwnSchemaProperty as l, truncateToolSchemaDepth as m, prepareRuntimeToolInputSchema as n, canPreserveRootSchemaRefs as o, toolSchemaChildPosition as p, projectRuntimeToolInputSchema as r, copySchemaMeta as s, getPublishedRuntimeToolInputSchema as t, MAX_TOOL_SCHEMA_DEPTH as u, SCHEMA_NESTED_KEYS as v, sha256Hex as w, walkSchemaArray as x, SCHEMA_OBJECT_KEYS as y };
|
package/dist/{transport-stream-shared-BmpzDtdQ.d.mts → transport-stream-shared-8ru8eX4s.d.mts}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { H as ProviderResponse, a as AssistantMessage, k as Model, nt as StreamOptions, pt as Usage } from "./types-
|
|
3
|
-
import { r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
4
|
-
import "./event-stream-
|
|
5
|
-
import { t as ProviderErrorProjection } from "./provider-error-
|
|
1
|
+
import "./index-DSprYWaz.mjs";
|
|
2
|
+
import { H as ProviderResponse, a as AssistantMessage, k as Model, nt as StreamOptions, pt as Usage } from "./types-CVYzKrMl.mjs";
|
|
3
|
+
import { r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-CzpE1g_o.mjs";
|
|
4
|
+
import "./event-stream-CDpFza-M.mjs";
|
|
5
|
+
import { t as ProviderErrorProjection } from "./provider-error-CnaWYTRY.mjs";
|
|
6
6
|
//#region packages/ai/src/transports/transport-stream-shared.d.ts
|
|
7
7
|
type TransportUsage = Pick<Usage, "input" | "output" | "cacheRead" | "cacheWrite" | "contextUsage" | "totalTokens"> & {
|
|
8
8
|
cost: Pick<Usage["cost"], "input" | "output" | "cacheRead" | "cacheWrite" | "total">;
|