@openclaw/ai 2026.9.3 → 2026.9.5
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 +1 -1
- package/dist/{anthropic-CZy5U0NY.mjs → anthropic-COtDvgtt.mjs} +16 -16
- package/dist/{anthropic-payload-policy-wuRCb6MH.d.mts → anthropic-payload-policy-5Erq1Nzy.d.mts} +3 -3
- package/dist/{anthropic-stream-reducer-B_yo_7pf.mjs → anthropic-stream-reducer-BvdYYWL8.mjs} +56 -47
- package/dist/{api-registry-CB1-1oQ2.d.mts → api-registry-Ba2Cv-ut.d.mts} +2 -2
- package/dist/{assistant-output-iqnlJCV2.mjs → assistant-output-BsEkB-vU.mjs} +1 -1
- package/dist/{azure-openai-responses-Crpa40QR.mjs → azure-openai-responses-YrgnD583.mjs} +6 -9
- package/dist/{base64-D-su8YVo.mjs → base64-BQOzsvUH.mjs} +4 -4
- package/dist/credential-redaction-BKv49aiv.d.mts +24 -0
- package/dist/{diagnostics-dV98PqIy.mjs → diagnostics-Dm4bisWG.mjs} +89 -2
- package/dist/diagnostics.d.mts +4 -23
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-C1Z2piyk.d.mts → event-stream-CCoa-qSI.d.mts} +1 -1
- package/dist/event-stream-DmSCpi1T.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{google-BDPriaVe.mjs → google-BuhpRO9r.mjs} +7 -10
- package/dist/{google-messages-CVn9eFpF.mjs → google-messages-CyWnYlh0.mjs} +3 -4
- package/dist/{google-shared-BedY23XS.mjs → google-shared-BT5ZeNer.mjs} +13 -13
- package/dist/{google-vertex-DMz8XQCn.mjs → google-vertex-C7EplRvt.mjs} +5 -8
- package/dist/{host-CWuF-sS3.mjs → host-B4MeUNBc.mjs} +145 -12
- package/dist/{host-DK3wmS3e.d.mts → host-FZ1RA_qD.d.mts} +7 -3
- package/dist/{host-policy-CAopLRKA.mjs → host-policy-DUnXSx0I.mjs} +1 -1
- package/dist/{index-CQ6LTHw8.d.mts → index-DaF2QbwS.d.mts} +5 -10
- package/dist/index.d.mts +7 -8
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +6 -7
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai-completions-compat.d.mts +2 -0
- package/dist/internal/openai-completions-compat.mjs +2 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +3 -2
- package/dist/internal/openai.d.mts +10 -53
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/runtime.d.mts +43 -10
- package/dist/internal/runtime.mjs +5 -11
- package/dist/internal/shared.d.mts +35 -5
- package/dist/internal/shared.mjs +4 -4
- package/dist/internal/tool-schema.d.mts +3 -3
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral--m-Jm6VZ.mjs → mistral-moA-mbwl.mjs} +9 -16
- package/dist/{openai-chatgpt-responses-nDZccFW-.mjs → openai-chatgpt-responses-DWID3EFO.mjs} +76 -33
- package/dist/{openai-completions-KuoZyx0d.mjs → openai-completions-DJ1Vm-CD.mjs} +12 -13
- package/dist/{openai-prompt-cache-BI0rkM-5.mjs → openai-completions-compat-CkwdxTZx.mjs} +5 -50
- package/dist/{openai-completions-compat-CXn3T1we.d.mts → openai-completions-compat-JE7gqxb9.d.mts} +4 -4
- package/dist/{openai-completions-stream-BQk3SkLD.mjs → openai-completions-stream-Bu98b0Hv.mjs} +128 -99
- package/dist/openai-prompt-cache-1wfaIszn.mjs +46 -0
- package/dist/{openai-prompt-cache-rrutvqxq.d.mts → openai-prompt-cache-CJ_xEevu.d.mts} +2 -2
- package/dist/{openai-provider-client-ha_WxTyj.mjs → openai-provider-client-DPo0Hmak.mjs} +2 -2
- package/dist/{openai-reasoning-effort-BK7FbcLT.mjs → openai-reasoning-effort-NlFZmfEu.mjs} +87 -19
- package/dist/{openai-responses-D99dOzKI.mjs → openai-responses-BejZzQCP.mjs} +9 -13
- package/dist/{openai-responses-compaction-window-D5jbzCi3.mjs → openai-responses-compaction-window-D6P5oZP5.mjs} +21 -140
- package/dist/openai-responses-contracts-DWrfMODE.mjs +81 -0
- package/dist/{openai-responses-contracts-B55afwRo.d.mts → openai-responses-contracts-Dflvrfa8.d.mts} +10 -39
- package/dist/{openai-responses-payload-policy-rLRPsSmB.d.mts → openai-responses-payload-policy-C7GsA1y0.d.mts} +5 -3
- package/dist/openai-responses-prompt-observer-internal-C15_-OwV.mjs +195 -0
- package/dist/{openai-responses-shared-ZyQEzS5i.mjs → openai-responses-shared-CwsziD_m.mjs} +390 -183
- package/dist/openai-responses-terminal-usage-Dl3J6zrf.d.mts +47 -0
- package/dist/{openai-tool-schema-CzjyYXun.mjs → openai-tool-schema-BO8rwyAD.mjs} +92 -68
- package/dist/{openai-transport-params-DNasp2fU.mjs → openai-transport-params-DQeuAvBl.mjs} +162 -51
- package/dist/positive-integer-DtjCkbue.mjs +8 -0
- package/dist/{provider-error-C6TbKiey.mjs → provider-error-DDqw9Qda.mjs} +140 -36
- package/dist/{provider-options-BXr9Ec83.d.mts → provider-options-DprLsWh9.d.mts} +9 -6
- package/dist/{provider-replay-context-BuSUaAk5.mjs → provider-replay-context-CnUSOwhr.mjs} +1 -1
- package/dist/{provider-transcript-transform-pPmUIwKt.mjs → provider-transcript-transform-BsRAhuWJ.mjs} +1 -1
- package/dist/provider-transport-turn-state-CkGToCD2.mjs +42 -0
- package/dist/{provider-types-CAV0Og3m.d.mts → provider-types-CAKRC7N5.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -7
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +10 -10
- package/dist/{reasoning-tag-text-partitioner-BQBi4B9d.mjs → reasoning-tag-text-partitioner-Dy9IO8Dc.mjs} +15 -14
- package/dist/{session-affinity-CCH7eYdB.mjs → session-affinity-Bcunsn4I.mjs} +5 -2
- package/dist/{simple-options-tcKOqnpF.mjs → simple-options-C6cFWj_f.mjs} +26 -5
- package/dist/{src-B2Q_6G8V.mjs → src-DeKjbE8I.mjs} +3 -6
- package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-C9ZadkJW.mjs} +1 -1
- package/dist/{string-normalization-CmLIasuf.mjs → string-normalization-J9ZiLfGO.mjs} +13 -1
- package/dist/tool-schema-json-projection-CD9c_fK8.mjs +134 -0
- package/dist/{transport-stream-shared-DOxpGJ-H.d.mts → transport-stream-shared-BbUkFaHi.d.mts} +20 -36
- package/dist/{transport-stream-shared-Cu3ZPhNW.mjs → transport-stream-shared-D-6FQSHm.mjs} +223 -11
- package/dist/{transport-utils-CCooe-cr.mjs → transport-utils-1cyq5Y7x.mjs} +4 -7
- package/dist/transports.d.mts +51 -165
- package/dist/transports.mjs +172 -507
- package/dist/{types-Dy1q0CSu.d.mts → types-4_uVs5WH.d.mts} +49 -3
- package/dist/types-DkJfb4W3.d.mts +1 -0
- package/dist/types-LFWwv0cF.mjs +8 -0
- package/dist/types.d.mts +6 -7
- package/dist/types.mjs +4 -4
- package/dist/{validation-CaFUZN9B.d.mts → validation-Ctzu2DhF.d.mts} +1 -1
- package/dist/{validation-BDzVDnTs.mjs → validation-Dw7cb6BV.mjs} +1 -0
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +10 -5
- package/dist/diagnostics-DnPnOui6.d.mts +0 -29
- package/dist/event-stream-I_GlBsuZ.d.mts +0 -1
- package/dist/hash-CHgqbJmD.mjs +0 -16
- package/dist/json-parse-Dw_hnxsA.mjs +0 -146
- package/dist/openai-responses-prompt-observer-internal-tApyTLVu.mjs +0 -32
- package/dist/sanitize-unicode-Bb-v9meu.mjs +0 -83
- package/dist/tool-schema-json-projection-ClptDdAO.mjs +0 -82
- package/dist/types-BADKjDBI.d.mts +0 -1
- package/dist/types-BDdaOVi2.mjs +0 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { v as sanitizeSurrogates } from "./host-B4MeUNBc.mjs";
|
|
3
|
+
import { i as copyProviderAcceptanceObserver } from "./transport-stream-shared-D-6FQSHm.mjs";
|
|
4
4
|
//#region packages/ai/src/utils/prompt-cache-stability.ts
|
|
5
5
|
/**
|
|
6
6
|
* Prompt-cache normalization helpers. They keep generated prompt sections
|
|
@@ -40,8 +40,23 @@ function normalizePromptCapabilityIds(capabilities) {
|
|
|
40
40
|
* Keeps stable prompt prefixes separate from dynamic runtime additions for provider prompt caching.
|
|
41
41
|
*/
|
|
42
42
|
const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
43
|
+
/** Producer-delimited Runtime facts; instructions must remain outside this region. */
|
|
44
|
+
const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY = "\n<!-- OPENCLAW-RELOCATABLE-BOUNDARY -->\n";
|
|
45
|
+
const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END = "\n<!-- /OPENCLAW-RELOCATABLE-BOUNDARY -->";
|
|
43
46
|
function stripSystemPromptCacheBoundary(text) {
|
|
44
|
-
return text.replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY, "\n");
|
|
47
|
+
return stripSystemPromptRelocatableBoundary(text.replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY, "\n").replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY.trim(), ""));
|
|
48
|
+
}
|
|
49
|
+
/** Reject ambiguous markers from workspace or hook text instead of moving instructions. */
|
|
50
|
+
function splitSystemPromptRelocatableBoundary(text) {
|
|
51
|
+
const opening = SYSTEM_PROMPT_RELOCATABLE_BOUNDARY.trim();
|
|
52
|
+
const closing = SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END.trim();
|
|
53
|
+
const start = text.indexOf(opening);
|
|
54
|
+
const end = text.indexOf(closing);
|
|
55
|
+
if (start === -1 || end < start || text.includes(opening, start + 38) || text.includes(closing, end + 39)) return;
|
|
56
|
+
return {
|
|
57
|
+
remainingPrompt: [text.slice(0, start).trimEnd(), text.slice(end + 39).trimStart()].filter(Boolean).join("\n"),
|
|
58
|
+
relocatable: text.slice(start + 38, end).trim()
|
|
59
|
+
};
|
|
45
60
|
}
|
|
46
61
|
function ensureSystemPromptCacheBoundary(systemPrompt) {
|
|
47
62
|
if (systemPrompt.trim().length === 0) return systemPrompt;
|
|
@@ -55,6 +70,10 @@ function splitSystemPromptCacheBoundary(text) {
|
|
|
55
70
|
dynamicSuffix: text.slice(boundaryIndex + 34).trimStart()
|
|
56
71
|
};
|
|
57
72
|
}
|
|
73
|
+
/** Keep explicit cache breakpoints while removing relocation metadata. */
|
|
74
|
+
function stripSystemPromptRelocatableBoundary(text) {
|
|
75
|
+
return text.replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY, "\n").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END, "").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY.trim(), "").replaceAll(SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END.trim(), "");
|
|
76
|
+
}
|
|
58
77
|
function prependSystemPromptAdditionAfterCacheBoundary(params) {
|
|
59
78
|
const systemPromptAddition = typeof params.systemPromptAddition === "string" ? normalizeStructuredPromptSection(params.systemPromptAddition) : "";
|
|
60
79
|
if (!systemPromptAddition) return params.systemPrompt;
|
|
@@ -106,7 +125,9 @@ function buildBaseOptions(model, options, apiKey) {
|
|
|
106
125
|
const firstEventOptions = options;
|
|
107
126
|
const baseOptions = {
|
|
108
127
|
temperature: options?.temperature,
|
|
128
|
+
...options?.serviceTier ? { serviceTier: options.serviceTier } : {},
|
|
109
129
|
maxTokens: options?.maxTokens,
|
|
130
|
+
responseFormat: options?.responseFormat,
|
|
110
131
|
stop: options?.stop,
|
|
111
132
|
signal: options?.signal,
|
|
112
133
|
apiKey: apiKey || options?.apiKey,
|
|
@@ -127,7 +148,7 @@ function buildBaseOptions(model, options, apiKey) {
|
|
|
127
148
|
return copyProviderAcceptanceObserver(options, baseOptions);
|
|
128
149
|
}
|
|
129
150
|
function clampMaxTokensToModel(model, requestedMaxTokens) {
|
|
130
|
-
return requestedMaxTokens === void 0 ? void 0 : Math.max(1, Math.min(requestedMaxTokens, model.maxTokens));
|
|
151
|
+
return requestedMaxTokens === void 0 ? void 0 : Math.max(1, Math.min(requestedMaxTokens, model.maxTokens ?? requestedMaxTokens));
|
|
131
152
|
}
|
|
132
153
|
function clampReasoning(effort) {
|
|
133
154
|
return effort === "xhigh" ? "high" : effort;
|
|
@@ -151,4 +172,4 @@ function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLeve
|
|
|
151
172
|
};
|
|
152
173
|
}
|
|
153
174
|
//#endregion
|
|
154
|
-
export { codeModeToolSurfaceObserver as a,
|
|
175
|
+
export { normalizeStructuredPromptSection as _, codeModeToolSurfaceObserver as a, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY as c, prependSystemPromptAdditionAfterCacheBoundary as d, splitSystemPromptCacheBoundary as f, normalizePromptCapabilityIds as g, stripSystemPromptRelocatableBoundary as h, clampReasoning as i, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END as l, stripSystemPromptCacheBoundary as m, buildBaseOptions as n, reasoningTagTextPolicy as o, splitSystemPromptRelocatableBoundary as p, clampMaxTokensToModel as r, SYSTEM_PROMPT_CACHE_BOUNDARY as s, adjustMaxTokensForThinking as t, ensureSystemPromptCacheBoundary as u, sortPromptCacheToolsByName as v };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./validation-
|
|
1
|
+
import "./validation-Dw7cb6BV.mjs";
|
|
2
2
|
//#region packages/llm-core/src/model-contracts/anthropic.ts
|
|
3
3
|
function normalizeClaudeModelId(modelId) {
|
|
4
4
|
const normalized = modelId?.trim().toLowerCase() ?? "";
|
|
@@ -6,15 +6,13 @@ function normalizeClaudeModelId(modelId) {
|
|
|
6
6
|
}
|
|
7
7
|
const CLAUDE_FABLE_5_THINKING_PROFILE = {
|
|
8
8
|
levels: [
|
|
9
|
-
{ id: "minimal" },
|
|
10
9
|
{ id: "low" },
|
|
11
10
|
{ id: "medium" },
|
|
12
11
|
{ id: "high" },
|
|
13
12
|
{ id: "xhigh" },
|
|
14
|
-
{ id: "adaptive" },
|
|
15
13
|
{ id: "max" }
|
|
16
14
|
],
|
|
17
|
-
defaultLevel: "
|
|
15
|
+
defaultLevel: "medium",
|
|
18
16
|
preserveWhenCatalogReasoningFalse: true
|
|
19
17
|
};
|
|
20
18
|
const CLAUDE_SONNET_5_THINKING_PROFILE = {
|
|
@@ -34,8 +32,7 @@ const CLAUDE_OPUS_5_THINKING_PROFILE = CLAUDE_SONNET_5_THINKING_PROFILE;
|
|
|
34
32
|
/** Resolve the canonical normalized Claude model id for one runtime model ref. */
|
|
35
33
|
function resolveClaudeModelIdentity(ref) {
|
|
36
34
|
const normalized = normalizeClaudeModelId((typeof ref.params?.canonicalModelId === "string" ? ref.params.canonicalModelId : void 0) ?? ref.id);
|
|
37
|
-
|
|
38
|
-
return match ? normalized.slice((match.index ?? 0) + (match[0].startsWith("claude-") ? 0 : 1)) : normalized;
|
|
35
|
+
return /(?:^|[-/])(claude-[^/]+)$/.exec(normalized)?.[1] ?? normalized;
|
|
39
36
|
}
|
|
40
37
|
/** Resolve Claude Fable 5 through direct ids, cloud ids, or deployment metadata. */
|
|
41
38
|
function resolveClaudeFable5ModelIdentity(ref) {
|
package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-C9ZadkJW.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as clampTimerTimeoutMs } from "./base64-
|
|
1
|
+
import { a as clampTimerTimeoutMs } from "./base64-BQOzsvUH.mjs";
|
|
2
2
|
//#region packages/ai/src/utils/stream-first-event-timeout.ts
|
|
3
3
|
function getFirstStreamEventTimeoutMs(options) {
|
|
4
4
|
return options?.firstEventTimeoutMs;
|
|
@@ -12,5 +12,17 @@ function uniqueValues(values) {
|
|
|
12
12
|
function uniqueStrings(values) {
|
|
13
13
|
return uniqueValues(values);
|
|
14
14
|
}
|
|
15
|
+
/** Normalizes array-backed string lists and rejects non-array input as empty. */
|
|
16
|
+
function normalizeTrimmedStringList(value) {
|
|
17
|
+
if (!Array.isArray(value)) return [];
|
|
18
|
+
return value.flatMap((entry) => {
|
|
19
|
+
const normalized = normalizeOptionalString(entry);
|
|
20
|
+
return normalized ? [normalized] : [];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Normalizes an array-backed string list and removes duplicates. */
|
|
24
|
+
function normalizeUniqueTrimmedStringList(value) {
|
|
25
|
+
return uniqueStrings(normalizeTrimmedStringList(value));
|
|
26
|
+
}
|
|
15
27
|
//#endregion
|
|
16
|
-
export {
|
|
28
|
+
export { uniqueValues as i, normalizeUniqueTrimmedStringList as n, uniqueStrings as r, normalizeStringEntries as t };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
2
|
+
import { t as expectDefined } from "./expect-lbe3Hgrh.mjs";
|
|
3
|
+
import { types } from "node:util";
|
|
4
|
+
//#region packages/ai/src/providers/tool-schema-json-projection.ts
|
|
5
|
+
function isNonFiniteNumberValue(value) {
|
|
6
|
+
if (typeof value === "number") return !Number.isFinite(value);
|
|
7
|
+
if (value === null || typeof value !== "object" || !types.isNumberObject(value)) return false;
|
|
8
|
+
return !Number.isFinite(Number.prototype.valueOf.call(value));
|
|
9
|
+
}
|
|
10
|
+
function serializeToolInputSchema(value, path, captureJson) {
|
|
11
|
+
const nonFiniteNumber = { path: null };
|
|
12
|
+
const ancestors = [];
|
|
13
|
+
const pathLengths = [];
|
|
14
|
+
const segments = [path];
|
|
15
|
+
let isRoot = true;
|
|
16
|
+
let text;
|
|
17
|
+
try {
|
|
18
|
+
text = JSON.stringify(value, function(key, entry) {
|
|
19
|
+
const invalidNumber = nonFiniteNumber.path === null && isNonFiniteNumberValue(entry);
|
|
20
|
+
if (invalidNumber || entry && typeof entry === "object") {
|
|
21
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {
|
|
22
|
+
ancestors.pop();
|
|
23
|
+
segments.length = expectDefined(pathLengths.pop(), "schema ancestor path length");
|
|
24
|
+
}
|
|
25
|
+
const prefixLength = segments.length;
|
|
26
|
+
if (!isRoot) {
|
|
27
|
+
if (Array.isArray(this)) segments.push("[", key, "]");
|
|
28
|
+
else segments.push(".", key);
|
|
29
|
+
}
|
|
30
|
+
if (invalidNumber) {
|
|
31
|
+
nonFiniteNumber.path = segments.join("");
|
|
32
|
+
segments.length = prefixLength;
|
|
33
|
+
} else {
|
|
34
|
+
ancestors.push(entry);
|
|
35
|
+
pathLengths.push(prefixLength);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
isRoot = false;
|
|
39
|
+
return entry;
|
|
40
|
+
});
|
|
41
|
+
} catch {
|
|
42
|
+
return {
|
|
43
|
+
schema: {},
|
|
44
|
+
violations: [`${path} is not JSON-serializable`]
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (!text) return {
|
|
48
|
+
schema: {},
|
|
49
|
+
violations: [`${path} is not JSON-serializable`]
|
|
50
|
+
};
|
|
51
|
+
if (nonFiniteNumber.path !== null) return {
|
|
52
|
+
schema: {},
|
|
53
|
+
violations: [`${nonFiniteNumber.path} is not JSON-serializable`]
|
|
54
|
+
};
|
|
55
|
+
const schema = JSON.parse(text);
|
|
56
|
+
captureJson?.(text);
|
|
57
|
+
return {
|
|
58
|
+
schema,
|
|
59
|
+
violations: []
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const schemaMapKeywords = /* @__PURE__ */ new Set([
|
|
63
|
+
"$defs",
|
|
64
|
+
"definitions",
|
|
65
|
+
"dependencies",
|
|
66
|
+
"dependentSchemas",
|
|
67
|
+
"patternProperties",
|
|
68
|
+
"properties"
|
|
69
|
+
]);
|
|
70
|
+
function inspectJsonSchema(schema, path, violations) {
|
|
71
|
+
if (Array.isArray(schema)) {
|
|
72
|
+
let index = 0;
|
|
73
|
+
for (const entry of schema) {
|
|
74
|
+
path.push("[", index++, "]");
|
|
75
|
+
const valid = inspectJsonSchema(entry, path, violations);
|
|
76
|
+
path.length -= 3;
|
|
77
|
+
if (!valid) return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (!isRecord(schema)) return typeof schema !== "number" || Number.isFinite(schema);
|
|
82
|
+
for (const key of ["$dynamicRef", "$dynamicAnchor"]) if (key in schema) violations.push(`${path.join("")}.${key}`);
|
|
83
|
+
for (const key of Object.keys(schema)) {
|
|
84
|
+
const value = schema[key];
|
|
85
|
+
if (typeof value === "number" && !Number.isFinite(value)) return false;
|
|
86
|
+
if (!value || typeof value !== "object") continue;
|
|
87
|
+
path.push(".", key);
|
|
88
|
+
if (schemaMapKeywords.has(key) && isRecord(value)) for (const schemaName of Object.keys(value)) {
|
|
89
|
+
const childSchema = value[schemaName];
|
|
90
|
+
if (childSchema === void 0) return false;
|
|
91
|
+
path.push(".", schemaName);
|
|
92
|
+
const valid = inspectJsonSchema(childSchema, path, violations);
|
|
93
|
+
path.length -= 2;
|
|
94
|
+
if (!valid) return false;
|
|
95
|
+
}
|
|
96
|
+
else if (!inspectJsonSchema(value, path, violations)) return false;
|
|
97
|
+
path.length -= 2;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
102
|
+
function projectRuntimeToolInputSchema(schema, path = "parameters") {
|
|
103
|
+
return projectToolInputSchema(schema, path);
|
|
104
|
+
}
|
|
105
|
+
/** Package-private preparation; public projections never carry normalization provenance. */
|
|
106
|
+
function prepareRuntimeToolInputSchema(schema, path) {
|
|
107
|
+
let inputJson;
|
|
108
|
+
const projection = projectToolInputSchema(schema, path, (text) => {
|
|
109
|
+
inputJson = text;
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
projection,
|
|
113
|
+
...schema && typeof schema === "object" && inputJson && projection.violations.length === 0 ? { normalization: {
|
|
114
|
+
source: schema,
|
|
115
|
+
inputJson
|
|
116
|
+
} } : {}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function projectToolInputSchema(schema, path, captureJson) {
|
|
120
|
+
const projection = serializeToolInputSchema(schema, path, captureJson);
|
|
121
|
+
const violations = [...projection.violations];
|
|
122
|
+
if (!isRecord(projection.schema)) violations.push(`${path} must be a JSON object schema`);
|
|
123
|
+
else if (projection.schema.type !== void 0 && projection.schema.type !== "object") violations.push(`${path}.type must be "object"`);
|
|
124
|
+
if (!inspectJsonSchema(projection.schema, [path], violations)) return {
|
|
125
|
+
schema: {},
|
|
126
|
+
violations: [`${path} is not a JSON value`]
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
schema: projection.schema,
|
|
130
|
+
violations
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
export { projectRuntimeToolInputSchema as n, prepareRuntimeToolInputSchema as t };
|
package/dist/{transport-stream-shared-DOxpGJ-H.d.mts → transport-stream-shared-BbUkFaHi.d.mts}
RENAMED
|
@@ -1,36 +1,8 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import {
|
|
3
|
-
import { r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
4
|
-
import "./event-stream-
|
|
1
|
+
import "./index-DaF2QbwS.mjs";
|
|
2
|
+
import { O as Model, V as ProviderResponse, Y as StreamOptions, a as AssistantMessage, ot as Usage } from "./types-4_uVs5WH.mjs";
|
|
3
|
+
import { r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-CCoa-qSI.mjs";
|
|
4
|
+
import "./event-stream-DmSCpi1T.mjs";
|
|
5
5
|
import { t as ProviderErrorProjection } from "./provider-error-CzNw4BWX.mjs";
|
|
6
|
-
//#region packages/ai/src/utils/stream-first-event-timeout.d.ts
|
|
7
|
-
type StreamStage = "responses" | "completions";
|
|
8
|
-
type FirstStreamEventTimeoutContext = {
|
|
9
|
-
provider?: string;
|
|
10
|
-
api?: string;
|
|
11
|
-
model?: string;
|
|
12
|
-
timeoutMs: number;
|
|
13
|
-
stage?: StreamStage;
|
|
14
|
-
hint?: string;
|
|
15
|
-
abort?: (reason: Error) => void;
|
|
16
|
-
onTimeout?: (reason: Error) => void;
|
|
17
|
-
};
|
|
18
|
-
type FirstStreamEventInternalOptions = {
|
|
19
|
-
firstEventTimeoutMs?: number;
|
|
20
|
-
abortFirstEventStream?: (reason: Error) => void;
|
|
21
|
-
onFirstEventTimeout?: (reason: Error) => void;
|
|
22
|
-
};
|
|
23
|
-
type FirstStreamEventAbortController = {
|
|
24
|
-
signal: AbortSignal;
|
|
25
|
-
abort: (reason: Error) => void;
|
|
26
|
-
dispose: () => void;
|
|
27
|
-
};
|
|
28
|
-
declare function getFirstStreamEventTimeoutMs(options: unknown): number | undefined;
|
|
29
|
-
declare function getFirstStreamEventTimeoutHandler(options: unknown): ((reason: Error) => void) | undefined;
|
|
30
|
-
declare function createFirstStreamEventTimeoutError(context: FirstStreamEventTimeoutContext): Error;
|
|
31
|
-
declare function createFirstStreamEventAbortController(parentSignal?: AbortSignal): FirstStreamEventAbortController;
|
|
32
|
-
declare function withFirstStreamEventTimeout<T>(stream: AsyncIterable<T>, context: FirstStreamEventTimeoutContext): AsyncIterable<T>;
|
|
33
|
-
//#endregion
|
|
34
6
|
//#region packages/ai/src/transports/transport-stream-shared.d.ts
|
|
35
7
|
type ContextUsage = NonNullable<Usage["contextUsage"]>;
|
|
36
8
|
type TransportUsage = {
|
|
@@ -52,12 +24,24 @@ type WritableTransportStream = Pick<ReturnType<typeof createAssistantMessageEven
|
|
|
52
24
|
declare function sanitizeTransportPayloadText(text: string): string;
|
|
53
25
|
declare function sanitizeNonEmptyTransportPayloadText(text: string, fallback?: string): string;
|
|
54
26
|
declare function coerceTransportToolCallArguments(argumentsValue: unknown): Record<string, unknown>;
|
|
55
|
-
/**
|
|
56
|
-
declare
|
|
27
|
+
/** Stable terminal fact: presentation must not infer unfinished calls from provider prose. */
|
|
28
|
+
declare class IncompleteToolCallError extends Error {
|
|
29
|
+
readonly code = "incomplete_tool_call";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Admit only complete object-shaped terminal tool arguments; partial parsing is preview-only.
|
|
33
|
+
* `repairStringLiterals` opts a stream whose provider may deliver unvalidated tool input into
|
|
34
|
+
* string-literal repair before rejection.
|
|
35
|
+
*/
|
|
36
|
+
declare function parseTerminalToolCallArguments(value: unknown, errorMessage?: string, options?: {
|
|
37
|
+
repairStringLiterals?: boolean;
|
|
38
|
+
}): Record<string, unknown>;
|
|
57
39
|
/** Validate a complete sibling set before mutating any call into executable state. */
|
|
58
40
|
declare function finalizeTerminalToolCallArguments<T extends {
|
|
59
41
|
arguments: Record<string, unknown>;
|
|
60
|
-
}>(calls: readonly T[], readArguments: (call: T) => unknown, errorMessage?: string
|
|
42
|
+
}>(calls: readonly T[], readArguments: (call: T) => unknown, errorMessage?: string, options?: {
|
|
43
|
+
repairStringLiterals?: boolean;
|
|
44
|
+
}): void;
|
|
61
45
|
declare function mergeTransportHeaders(...headerSources: Array<Record<string, string> | undefined>): Record<string, string> | undefined;
|
|
62
46
|
declare function mergeTransportMetadata<T extends Record<string, unknown>>(payload: T, metadata?: Record<string, string>): T;
|
|
63
47
|
declare function createEmptyTransportUsage(): TransportUsage;
|
|
@@ -135,4 +119,4 @@ declare function failTransportStream(params: {
|
|
|
135
119
|
cleanup?: () => void;
|
|
136
120
|
}): void;
|
|
137
121
|
//#endregion
|
|
138
|
-
export {
|
|
122
|
+
export { withProviderResponseHook as S, parseTerminalToolCallArguments as _, coerceTransportToolCallArguments as a, transportAbortError as b, createWritableTransportEventStream as c, finalizeTransportStream as d, mergeTransportHeaders as f, notifyProviderStreamOpened as g, notifyProviderHttpResponse as h, assignTransportErrorDetails as i, failTransportStream as l, notifyProviderHttpMetadata as m, ProviderAcceptance as n, copyProviderAcceptanceObserver as o, mergeTransportMetadata as p, WritableTransportStream as r, createEmptyTransportUsage as s, IncompleteToolCallError as t, finalizeTerminalToolCallArguments as u, sanitizeNonEmptyTransportPayloadText as v, withProviderAcceptanceObserver as x, sanitizeTransportPayloadText as y };
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import { n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
2
2
|
import { i as createAssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
3
|
-
import { t as sanitizeSurrogates } from "./sanitize-unicode-Bb-v9meu.mjs";
|
|
4
3
|
import { i as asOptionalRecord, n as asNullableRecord, t as asNonArrayRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
4
|
+
import { n as getAiTransportHost, v as sanitizeSurrogates } from "./host-B4MeUNBc.mjs";
|
|
5
|
+
import { i as projectDiagnosticValue, n as projectProviderError } from "./provider-error-DDqw9Qda.mjs";
|
|
6
|
+
import { c as isTransientNetworkError } from "./diagnostics-Dm4bisWG.mjs";
|
|
7
|
+
import { parse } from "partial-json";
|
|
8
|
+
//#region packages/ai/src/utils/hash.ts
|
|
9
|
+
/** Fast deterministic hash to shorten long strings */
|
|
10
|
+
function shortHash(str) {
|
|
11
|
+
let h1 = 3735928559;
|
|
12
|
+
let h2 = 1103547991;
|
|
13
|
+
for (let i = 0; i < str.length; i++) {
|
|
14
|
+
const ch = str.charCodeAt(i);
|
|
15
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
16
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
17
|
+
}
|
|
18
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
19
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
20
|
+
return (h2 >>> 0).toString(36) + (h1 >>> 0).toString(36);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
7
23
|
//#region packages/ai/src/utils/headers.ts
|
|
8
24
|
/** Converts a Headers object to a plain record for provider request handling. */
|
|
9
25
|
function headersToRecord(headers) {
|
|
@@ -12,6 +28,154 @@ function headersToRecord(headers) {
|
|
|
12
28
|
return result;
|
|
13
29
|
}
|
|
14
30
|
//#endregion
|
|
31
|
+
//#region packages/ai/src/utils/json-parse.ts
|
|
32
|
+
const VALID_JSON_ESCAPES = /* @__PURE__ */ new Set([
|
|
33
|
+
"\"",
|
|
34
|
+
"\\",
|
|
35
|
+
"/",
|
|
36
|
+
"b",
|
|
37
|
+
"f",
|
|
38
|
+
"n",
|
|
39
|
+
"r",
|
|
40
|
+
"t",
|
|
41
|
+
"u"
|
|
42
|
+
]);
|
|
43
|
+
const JSON_CONTROL_ESCAPES = /* @__PURE__ */ new Set([
|
|
44
|
+
"b",
|
|
45
|
+
"f",
|
|
46
|
+
"n",
|
|
47
|
+
"r",
|
|
48
|
+
"t"
|
|
49
|
+
]);
|
|
50
|
+
function isControlCharacter(char) {
|
|
51
|
+
const codePoint = char.codePointAt(0);
|
|
52
|
+
return codePoint !== void 0 && codePoint >= 0 && codePoint <= 31;
|
|
53
|
+
}
|
|
54
|
+
function escapeControlCharacter(char) {
|
|
55
|
+
switch (char) {
|
|
56
|
+
case "\b": return "\\b";
|
|
57
|
+
case "\f": return "\\f";
|
|
58
|
+
case "\n": return "\\n";
|
|
59
|
+
case "\r": return "\\r";
|
|
60
|
+
case " ": return "\\t";
|
|
61
|
+
default: return `\\u${char.codePointAt(0)?.toString(16).padStart(4, "0") ?? "0000"}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Repairs malformed JSON string literals by:
|
|
66
|
+
* - escaping raw control characters inside strings
|
|
67
|
+
* - doubling backslashes before invalid escape characters
|
|
68
|
+
*
|
|
69
|
+
* By default a valid control escape (`\n`, `\t`, ...) that follows a Windows-path-looking
|
|
70
|
+
* prefix is treated as an unescaped path separator and doubled. Pass
|
|
71
|
+
* `preserveValidControlEscapes` when the text is authoritative (for example a completed
|
|
72
|
+
* tool-call argument buffer) and every valid escape must survive as written.
|
|
73
|
+
*/
|
|
74
|
+
function repairJson(json, options) {
|
|
75
|
+
if (!/[\\\x00-\x1f]/.test(json)) return json;
|
|
76
|
+
const preserveValidControlEscapes = options?.preserveValidControlEscapes === true;
|
|
77
|
+
let repaired = "";
|
|
78
|
+
let inString = false;
|
|
79
|
+
let stringValuePrefix = "";
|
|
80
|
+
for (let index = 0; index < json.length; index++) {
|
|
81
|
+
const char = json.charAt(index);
|
|
82
|
+
if (!inString) {
|
|
83
|
+
repaired += char;
|
|
84
|
+
if (char === "\"") {
|
|
85
|
+
inString = true;
|
|
86
|
+
stringValuePrefix = "";
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (char === "\"") {
|
|
91
|
+
repaired += char;
|
|
92
|
+
inString = false;
|
|
93
|
+
stringValuePrefix = "";
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (char === "\\") {
|
|
97
|
+
const nextChar = json.charAt(index + 1);
|
|
98
|
+
if (!nextChar) {
|
|
99
|
+
repaired += "\\\\";
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (nextChar === "u") {
|
|
103
|
+
const unicodeDigits = json.slice(index + 2, index + 6);
|
|
104
|
+
if (/^[0-9a-fA-F]{4}$/.test(unicodeDigits)) {
|
|
105
|
+
repaired += `\\u${unicodeDigits}`;
|
|
106
|
+
stringValuePrefix += `\\u${unicodeDigits}`;
|
|
107
|
+
index += 5;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
repaired += "\\\\";
|
|
111
|
+
stringValuePrefix += "\\";
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!preserveValidControlEscapes && JSON_CONTROL_ESCAPES.has(nextChar)) {
|
|
115
|
+
stringValuePrefix = stringValuePrefix.slice(-160);
|
|
116
|
+
if (looksLikeWindowsPathPrefix(stringValuePrefix)) {
|
|
117
|
+
repaired += "\\\\";
|
|
118
|
+
stringValuePrefix += "\\";
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (VALID_JSON_ESCAPES.has(nextChar)) {
|
|
123
|
+
repaired += `\\${nextChar}`;
|
|
124
|
+
stringValuePrefix += nextChar === "\\" ? "\\" : `\\${nextChar}`;
|
|
125
|
+
index += 1;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
repaired += "\\\\";
|
|
129
|
+
stringValuePrefix += "\\";
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
repaired += isControlCharacter(char) ? escapeControlCharacter(char) : char;
|
|
133
|
+
stringValuePrefix += char;
|
|
134
|
+
}
|
|
135
|
+
return repaired;
|
|
136
|
+
}
|
|
137
|
+
function parseJsonWithRepair(json) {
|
|
138
|
+
return JSON.parse(repairJson(json));
|
|
139
|
+
}
|
|
140
|
+
function looksLikeWindowsPathPrefix(prefix) {
|
|
141
|
+
return /(?:^|[^A-Za-z0-9])[A-Za-z]:(?:[\\/][^"\\/:*?<>|\r\n]*)*$/.test(prefix);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Attempts to parse potentially incomplete JSON during streaming.
|
|
145
|
+
* Always returns a valid object, even if the JSON is incomplete.
|
|
146
|
+
*
|
|
147
|
+
* @param partialJson The partial JSON string from streaming
|
|
148
|
+
* @returns Parsed object or empty object if parsing fails
|
|
149
|
+
*/
|
|
150
|
+
function parseStreamingJson(partialJson) {
|
|
151
|
+
if (!partialJson || partialJson.trim() === "") return {};
|
|
152
|
+
try {
|
|
153
|
+
return asNonArrayRecord(parseJsonWithRepair(partialJson));
|
|
154
|
+
} catch {
|
|
155
|
+
try {
|
|
156
|
+
return asNonArrayRecord(parse(partialJson));
|
|
157
|
+
} catch {
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const TOOL_ARGUMENT_PREVIEW_FIRST_CHECKPOINT_CHARS = 512;
|
|
163
|
+
/**
|
|
164
|
+
* Streamed tool-call arguments are preview-only; the terminal parse re-reads
|
|
165
|
+
* the full buffer authoritatively at content_block_stop. Reparsing every delta
|
|
166
|
+
* scans an ever-growing buffer and makes assembly quadratic in the argument
|
|
167
|
+
* size, so refresh previews on a geometric length schedule instead — bounded
|
|
168
|
+
* staleness, linear total parse work.
|
|
169
|
+
*/
|
|
170
|
+
function createToolArgumentPreviewSchedule() {
|
|
171
|
+
let nextCheckpointChars = TOOL_ARGUMENT_PREVIEW_FIRST_CHECKPOINT_CHARS;
|
|
172
|
+
return (accumulatedChars) => {
|
|
173
|
+
if (accumulatedChars < nextCheckpointChars) return false;
|
|
174
|
+
nextCheckpointChars = accumulatedChars * 2;
|
|
175
|
+
return true;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
15
179
|
//#region packages/ai/src/transports/json-unsafe-integers.ts
|
|
16
180
|
/**
|
|
17
181
|
* JSON parsing helpers that preserve integer literals larger than
|
|
@@ -56,6 +220,7 @@ function isUnsafeIntegerLiteral(token) {
|
|
|
56
220
|
}
|
|
57
221
|
/** Quotes integer literals above Number.MAX_SAFE_INTEGER before JSON.parse. */
|
|
58
222
|
function quoteUnsafeIntegerLiterals(input) {
|
|
223
|
+
if (!/(?:^|\D)\d{16}/.test(input)) return input;
|
|
59
224
|
let out = "";
|
|
60
225
|
let inString = false;
|
|
61
226
|
let escaped = false;
|
|
@@ -123,15 +288,59 @@ function coerceTransportToolCallArguments(argumentsValue) {
|
|
|
123
288
|
} catch {}
|
|
124
289
|
return {};
|
|
125
290
|
}
|
|
126
|
-
/**
|
|
127
|
-
|
|
291
|
+
/** Stable terminal fact: presentation must not infer unfinished calls from provider prose. */
|
|
292
|
+
var IncompleteToolCallError = class extends Error {
|
|
293
|
+
constructor(..._args) {
|
|
294
|
+
super(..._args);
|
|
295
|
+
this.code = "incomplete_tool_call";
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const MALFORMED_TOOL_CALL_TERMINAL_ERROR_CODE = "malformed_tool_call_arguments";
|
|
299
|
+
function createMalformedToolCallArgumentsError(value, errorMessage, repairAttempted) {
|
|
300
|
+
const text = typeof value === "string" ? value : void 0;
|
|
301
|
+
const diagnostics = {
|
|
302
|
+
code: MALFORMED_TOOL_CALL_TERMINAL_ERROR_CODE,
|
|
303
|
+
argumentChars: text?.length ?? 0,
|
|
304
|
+
argumentHash: text === void 0 ? "" : shortHash(text),
|
|
305
|
+
repairAttempted
|
|
306
|
+
};
|
|
307
|
+
const error = new Error(errorMessage, { cause: diagnostics });
|
|
308
|
+
Object.assign(error, {
|
|
309
|
+
errorCode: MALFORMED_TOOL_CALL_TERMINAL_ERROR_CODE,
|
|
310
|
+
errorBody: JSON.stringify(diagnostics)
|
|
311
|
+
});
|
|
312
|
+
return error;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Repair a complete-but-invalid terminal argument buffer. Anthropic fine-grained tool
|
|
316
|
+
* streaming skips server-side JSON validation, so a finished tool_use block can carry raw
|
|
317
|
+
* control characters or invalid escapes inside string values. Only string-literal repairs
|
|
318
|
+
* are applied and every valid escape is preserved as written; truncated or non-object
|
|
319
|
+
* buffers stay rejected so a cut-off write never executes with partial arguments.
|
|
320
|
+
*/
|
|
321
|
+
function repairTerminalToolCallArguments(value) {
|
|
322
|
+
const repaired = repairJson(value, { preserveValidControlEscapes: true });
|
|
323
|
+
if (repaired === value) return null;
|
|
324
|
+
return parseJsonObjectPreservingUnsafeIntegers(repaired);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Admit only complete object-shaped terminal tool arguments; partial parsing is preview-only.
|
|
328
|
+
* `repairStringLiterals` opts a stream whose provider may deliver unvalidated tool input into
|
|
329
|
+
* string-literal repair before rejection.
|
|
330
|
+
*/
|
|
331
|
+
function parseTerminalToolCallArguments(value, errorMessage = MALFORMED_TOOL_CALL_TERMINAL_ERROR_MESSAGE, options) {
|
|
128
332
|
const parsed = parseJsonObjectPreservingUnsafeIntegers(value);
|
|
129
|
-
if (
|
|
130
|
-
|
|
333
|
+
if (parsed) return parsed;
|
|
334
|
+
const repairStringLiterals = options?.repairStringLiterals === true && typeof value === "string";
|
|
335
|
+
if (repairStringLiterals) {
|
|
336
|
+
const repaired = repairTerminalToolCallArguments(value);
|
|
337
|
+
if (repaired) return repaired;
|
|
338
|
+
}
|
|
339
|
+
throw createMalformedToolCallArgumentsError(value, errorMessage, repairStringLiterals);
|
|
131
340
|
}
|
|
132
341
|
/** Validate a complete sibling set before mutating any call into executable state. */
|
|
133
|
-
function finalizeTerminalToolCallArguments(calls, readArguments, errorMessage) {
|
|
134
|
-
const validated = calls.map((call) => [call, parseTerminalToolCallArguments(readArguments(call), errorMessage)]);
|
|
342
|
+
function finalizeTerminalToolCallArguments(calls, readArguments, errorMessage, options) {
|
|
343
|
+
const validated = calls.map((call) => [call, parseTerminalToolCallArguments(readArguments(call), errorMessage, options)]);
|
|
135
344
|
for (const [call, argumentsValue] of validated) call.arguments = argumentsValue;
|
|
136
345
|
}
|
|
137
346
|
function mergeTransportHeaders(...headerSources) {
|
|
@@ -229,6 +438,7 @@ async function awaitProviderLifecycleCallback(callback, signal) {
|
|
|
229
438
|
if (signal?.aborted) throw transportAbortError(signal);
|
|
230
439
|
if (!callback) return;
|
|
231
440
|
const callbackPromise = Promise.resolve().then(callback);
|
|
441
|
+
getAiTransportHost().observePendingProviderWork?.(callbackPromise);
|
|
232
442
|
if (!signal) {
|
|
233
443
|
await callbackPromise;
|
|
234
444
|
return;
|
|
@@ -247,7 +457,9 @@ async function awaitProviderLifecycleCallback(callback, signal) {
|
|
|
247
457
|
function startProviderStreamCancellation(cancelStream, error) {
|
|
248
458
|
const reason = error instanceof Error ? error : new Error(String(error));
|
|
249
459
|
try {
|
|
250
|
-
Promise.resolve(cancelStream(reason))
|
|
460
|
+
const pending = Promise.resolve(cancelStream(reason));
|
|
461
|
+
pending.catch(() => void 0);
|
|
462
|
+
getAiTransportHost().observePendingProviderWork?.(pending);
|
|
251
463
|
} catch {}
|
|
252
464
|
}
|
|
253
465
|
async function awaitProviderLifecycleWithCleanup(params) {
|
|
@@ -352,4 +564,4 @@ function failTransportStream(params) {
|
|
|
352
564
|
stream.end();
|
|
353
565
|
}
|
|
354
566
|
//#endregion
|
|
355
|
-
export {
|
|
567
|
+
export { quoteUnsafeIntegerLiterals as C, repairJson as D, parseStreamingJson as E, headersToRecord as O, parseJsonPreservingUnsafeIntegers as S, parseJsonWithRepair as T, sanitizeTransportPayloadText as _, createEmptyTransportUsage as a, withProviderResponseHook as b, finalizeTerminalToolCallArguments as c, mergeTransportMetadata as d, notifyProviderHttpMetadata as f, sanitizeNonEmptyTransportPayloadText as g, parseTerminalToolCallArguments as h, copyProviderAcceptanceObserver as i, shortHash as k, finalizeTransportStream as l, notifyProviderStreamOpened as m, assignTransportErrorDetails as n, createWritableTransportEventStream as o, notifyProviderHttpResponse as p, coerceTransportToolCallArguments as r, failTransportStream as s, IncompleteToolCallError as t, mergeTransportHeaders as u, transportAbortError as v, createToolArgumentPreviewSchedule as w, parseJsonObjectPreservingUnsafeIntegers as x, withProviderAcceptanceObserver as y };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { n as getAiTransportHost } from "./host-
|
|
1
|
+
import { n as getAiTransportHost } from "./host-B4MeUNBc.mjs";
|
|
2
2
|
import { t as truncateUtf16Safe } from "./utf16-slice-CvGodqok.mjs";
|
|
3
|
-
import
|
|
3
|
+
import "./provider-error-DDqw9Qda.mjs";
|
|
4
4
|
import "./internal/retry-after.mjs";
|
|
5
|
+
import "./positive-integer-DtjCkbue.mjs";
|
|
5
6
|
//#region packages/normalization-core/src/response-bytes.ts
|
|
6
7
|
async function consumeResponseBytes(options) {
|
|
7
8
|
let size = 0;
|
|
@@ -30,10 +31,6 @@ async function consumeResponseBytes(options) {
|
|
|
30
31
|
const MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE = "OpenClaw transport error: malformed_streaming_fragment";
|
|
31
32
|
const NON_LATIN_RE = /[\u2E80-\u9FFF\uA000-\uA4FF\uAC00-\uD7AF\uF900-\uFAFF\uFF01-\uFF60\uFFE0-\uFFE6\u{20000}-\u{2FA1F}]/gu;
|
|
32
33
|
const CJK_SURROGATE_HIGH_RE = /[\uD840-\uD87E][\uDC00-\uDFFF]/g;
|
|
33
|
-
function parsePositiveInteger(value) {
|
|
34
|
-
if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
|
|
35
|
-
return typeof value === "string" ? parseStrictPositiveInteger(value) : void 0;
|
|
36
|
-
}
|
|
37
34
|
function redactSensitiveText(text, _options) {
|
|
38
35
|
return getAiTransportHost().redactToolPayloadText(text);
|
|
39
36
|
}
|
|
@@ -118,4 +115,4 @@ async function readResponseTextSnippet(response, options) {
|
|
|
118
115
|
return truncated ? `${collapsed}…` : collapsed;
|
|
119
116
|
}
|
|
120
117
|
//#endregion
|
|
121
|
-
export {
|
|
118
|
+
export { readResponseTextSnippet as a, supportsModelTools as c, isCodeModeModelVisibleToolName as i, createAbortError as n, redactSensitiveText as o, estimateStringChars as r, resolveModelHeaderSentinels as s, MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE as t };
|