@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/{tool-schema-json-projection-B1sTYwfH.mjs → tool-schema-json-projection-BQpiJlXJ.mjs}
RENAMED
|
@@ -1,13 +1,35 @@
|
|
|
1
|
-
import { a as asRecord, o as isRecord } from "./record-coerce-
|
|
2
|
-
import { r as parseLocalSchemaRefPointer } from "./validation-
|
|
3
|
-
import { o as normalizeOptionalString } from "./string-coerce-
|
|
4
|
-
import { r as getAiTransportHost } from "./host-
|
|
5
|
-
import
|
|
1
|
+
import { a as asRecord, o as isRecord } from "./record-coerce-BQaoiN3r.mjs";
|
|
2
|
+
import { r as parseLocalSchemaRefPointer } from "./validation-DGXqfvkj.mjs";
|
|
3
|
+
import { o as normalizeOptionalString } from "./string-coerce-BCuWMIrk.mjs";
|
|
4
|
+
import { r as getAiTransportHost } from "./host-DX7ORpeH.mjs";
|
|
5
|
+
import "./src-BUsVkrNt.mjs";
|
|
6
|
+
import { n as writeStableStringify, t as stableStringify } from "./stable-stringify-CchQEmeA.mjs";
|
|
7
|
+
import { Buffer } from "node:buffer";
|
|
8
|
+
import { createHash, hash } from "node:crypto";
|
|
6
9
|
import { types } from "node:util";
|
|
7
10
|
//#region packages/normalization-core/src/node-crypto.ts
|
|
8
11
|
function sha256Hex(input) {
|
|
9
12
|
return hash("sha256", input, "hex");
|
|
10
13
|
}
|
|
14
|
+
function sha256StableValue(value, normalizeString) {
|
|
15
|
+
let digest;
|
|
16
|
+
let text = "";
|
|
17
|
+
let byteWeight = 0;
|
|
18
|
+
writeStableStringify(value, (chunk) => {
|
|
19
|
+
text += chunk;
|
|
20
|
+
if (text.length >= 16384) {
|
|
21
|
+
digest ??= createHash("sha256");
|
|
22
|
+
digest.update(text);
|
|
23
|
+
byteWeight += Buffer.byteLength(text);
|
|
24
|
+
text = "";
|
|
25
|
+
}
|
|
26
|
+
}, normalizeString);
|
|
27
|
+
byteWeight += Buffer.byteLength(text);
|
|
28
|
+
return {
|
|
29
|
+
digest: digest ? digest.update(text).digest("hex") : sha256Hex(text),
|
|
30
|
+
byteWeight
|
|
31
|
+
};
|
|
32
|
+
}
|
|
11
33
|
function sha256HexPrefixCore(input, length) {
|
|
12
34
|
return sha256Hex(input).slice(0, length);
|
|
13
35
|
}
|
|
@@ -52,44 +74,10 @@ const SCHEMA_ARRAY_KEYS = /* @__PURE__ */ new Set([
|
|
|
52
74
|
"prefixItems"
|
|
53
75
|
]);
|
|
54
76
|
const SCHEMA_NESTED_KEYS = new Set([...SCHEMA_OBJECT_KEYS, ...SCHEMA_ARRAY_KEYS].toSorted());
|
|
55
|
-
|
|
56
|
-
|
|
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) {
|
|
77
|
+
/** Callers bound schema depth before walking; ordinary recursion stays within that budget. */
|
|
78
|
+
function walkSchemaValue(schema, visitObject) {
|
|
61
79
|
if (!schema || typeof schema !== "object") return schema;
|
|
62
|
-
|
|
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
|
-
}
|
|
80
|
+
return Array.isArray(schema) ? schema.map((entry) => walkSchemaValue(entry, visitObject)) : visitObject(asRecord(schema));
|
|
93
81
|
}
|
|
94
82
|
//#endregion
|
|
95
83
|
//#region packages/ai/src/providers/tool-schema-depth.ts
|
|
@@ -290,49 +278,40 @@ function inlineLocalSchemaRefsWithDefs(schema, defs, refStack, state, rootDocume
|
|
|
290
278
|
}
|
|
291
279
|
return result;
|
|
292
280
|
}
|
|
293
|
-
/** Inline local $ref pointers
|
|
281
|
+
/** Inline local $ref pointers in the normalizer's already-bounded input. */
|
|
294
282
|
function inlineLocalToolSchemaRefs(schema, toolName) {
|
|
295
|
-
if (!schema || typeof schema !== "object") return schema;
|
|
296
|
-
const boundedSchema = truncateToolSchemaDepth(schema, toolName);
|
|
297
283
|
const state = {
|
|
298
284
|
unresolvedLocalRefs: false,
|
|
299
285
|
truncated: false
|
|
300
286
|
};
|
|
301
|
-
const schemaRecord =
|
|
302
|
-
const normalized = inlineLocalSchemaRefsWithDefs(
|
|
287
|
+
const schemaRecord = schema;
|
|
288
|
+
const normalized = inlineLocalSchemaRefsWithDefs(schema, Array.isArray(schema) ? extendSchemaDefs(void 0, schemaRecord) : void 0, void 0, state, schema);
|
|
303
289
|
const bounded = truncateToolSchemaDepth(normalized);
|
|
304
290
|
if (state.truncated || bounded !== normalized) reportToolSchemaTruncation(schema, toolName);
|
|
305
|
-
return inheritToolSchemaTruncation(
|
|
291
|
+
return inheritToolSchemaTruncation(schema, bounded, state.truncated);
|
|
306
292
|
}
|
|
307
293
|
/** Keep compact root definitions. Fall back for scopes or refs we must rewrite. */
|
|
308
|
-
function canPreserveRootSchemaRefs(
|
|
309
|
-
const schema = truncateToolSchemaDepth(inputSchema);
|
|
294
|
+
function canPreserveRootSchemaRefs(schema) {
|
|
310
295
|
if (!isRecord(schema) || schema.type !== "object" || !isRecord(schema.properties) || ["$defs", "definitions"].some((key) => key in schema && !isRecord(schema[key])) || [
|
|
311
296
|
"anyOf",
|
|
312
297
|
"oneOf",
|
|
313
298
|
"allOf"
|
|
314
299
|
].some((key) => Array.isArray(schema[key])) || "$ref" in schema) return false;
|
|
315
300
|
let hasRefs = false;
|
|
316
|
-
const ancestors = /* @__PURE__ */ new Set();
|
|
317
301
|
function visit(node, inDefinitions = false) {
|
|
318
302
|
if (!isRecord(node)) return true;
|
|
319
|
-
if (
|
|
303
|
+
if ("$id" in node || "id" in node || "components" in node || node !== schema && ("$defs" in node || "definitions" in node)) return false;
|
|
320
304
|
if ("$ref" in node) {
|
|
321
305
|
if (typeof node.$ref !== "string" || !/^#\/(\$defs|definitions)\/[^/]+$/.test(node.$ref) || node.nullable === true || tryResolveLocalRef(node.$ref, void 0, schema) === void 0) return false;
|
|
322
306
|
hasRefs ||= !inDefinitions;
|
|
323
307
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
} else if (SCHEMA_OBJECT_KEYS.has(key) && !visit(value, inDefinitions)) return false;
|
|
332
|
-
return true;
|
|
333
|
-
} finally {
|
|
334
|
-
ancestors.delete(node);
|
|
335
|
-
}
|
|
308
|
+
for (const [key, value] of Object.entries(node)) if (SCHEMA_MAP_KEYS.has(key) && isRecord(value)) {
|
|
309
|
+
const childInDefinitions = inDefinitions || key === "$defs" || key === "definitions";
|
|
310
|
+
if (!Object.values(value).every((entry) => visit(entry, childInDefinitions))) return false;
|
|
311
|
+
} else if (SCHEMA_ARRAY_KEYS.has(key) && Array.isArray(value)) {
|
|
312
|
+
if (!value.every((entry) => visit(entry, inDefinitions))) return false;
|
|
313
|
+
} else if (SCHEMA_OBJECT_KEYS.has(key) && !visit(value, inDefinitions)) return false;
|
|
314
|
+
return true;
|
|
336
315
|
}
|
|
337
316
|
return visit(schema) && hasRefs;
|
|
338
317
|
}
|
|
@@ -359,10 +338,14 @@ function publishRuntimeToolInputSchema(schema, path = "parameters", toolName) {
|
|
|
359
338
|
}
|
|
360
339
|
Object.freeze(projection.violations);
|
|
361
340
|
Object.freeze(projection);
|
|
341
|
+
let canonicalFingerprint;
|
|
362
342
|
publishedSchemas.set(projection.schema, Object.freeze({
|
|
363
343
|
projection,
|
|
364
344
|
json,
|
|
365
|
-
fingerprint: sha256Hex(json)
|
|
345
|
+
fingerprint: sha256Hex(json),
|
|
346
|
+
get canonicalFingerprint() {
|
|
347
|
+
return canonicalFingerprint ??= sha256Hex(stableStringify(projection.schema));
|
|
348
|
+
}
|
|
366
349
|
}));
|
|
367
350
|
return projection;
|
|
368
351
|
}
|
|
@@ -448,14 +431,15 @@ function inspectJsonSchema(schema, path, violations, inspectKeywords = true) {
|
|
|
448
431
|
if (inspectKeywords) {
|
|
449
432
|
for (const key of ["$dynamicRef", "$dynamicAnchor"]) if (key in schema) violations.push(`${path.join("")}.${key}`);
|
|
450
433
|
}
|
|
451
|
-
for (const
|
|
434
|
+
for (const key of Object.keys(schema)) {
|
|
435
|
+
const value = schema[key];
|
|
452
436
|
if (typeof value === "number" && !Number.isFinite(value)) return false;
|
|
453
437
|
if (!value || typeof value !== "object") continue;
|
|
454
438
|
path.push(".", key);
|
|
455
439
|
const inspectChildKeywords = inspectKeywords && !SCHEMA_LITERAL_KEYS.has(key);
|
|
456
|
-
if (inspectChildKeywords && SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const
|
|
440
|
+
if (inspectChildKeywords && SCHEMA_MAP_KEYS.has(key) && isRecord(value)) for (const schemaName of Object.keys(value)) {
|
|
457
441
|
path.push(".", schemaName);
|
|
458
|
-
const valid = inspectJsonSchema(
|
|
442
|
+
const valid = inspectJsonSchema(value[schemaName], path, violations);
|
|
459
443
|
path.length -= 2;
|
|
460
444
|
if (!valid) return false;
|
|
461
445
|
}
|
|
@@ -489,4 +473,4 @@ function prepareRuntimeToolInputSchema(schema, path, toolName) {
|
|
|
489
473
|
};
|
|
490
474
|
}
|
|
491
475
|
//#endregion
|
|
492
|
-
export {
|
|
476
|
+
export { sha256Hex as C, redactIdentifier as S, SCHEMA_ARRAY_KEYS as _, SCHEMA_LITERAL_KEYS as a, SCHEMA_OBJECT_KEYS as b, extendSchemaDefs as c, MAX_TOOL_SCHEMA_DEPTH as d, inheritToolSchemaTruncation as f, wasToolSchemaTruncated as g, truncateToolSchemaDepth as h, publishRuntimeToolInputSchema as i, inlineLocalToolSchemaRefs as l, toolSchemaChildPosition as m, prepareRuntimeToolInputSchema as n, canPreserveRootSchemaRefs as o, reportToolSchemaTruncation as p, projectRuntimeToolInputSchema as r, copySchemaMeta as s, getPublishedRuntimeToolInputSchema as t, setOwnSchemaProperty as u, SCHEMA_MAP_KEYS as v, sha256StableValue as w, walkSchemaValue as x, SCHEMA_NESTED_KEYS as y };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-
|
|
1
|
+
import { n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-o1PrVNQb.mjs";
|
|
2
2
|
import { a as createAssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
3
|
-
import { i as asOptionalRecord, n as asNullableRecord, t as asNonArrayRecord } from "./record-coerce-
|
|
4
|
-
import { E as headersToRecord, r as getAiTransportHost } from "./host-
|
|
5
|
-
import { a as projectDiagnosticValue, n as projectProviderError } from "./provider-error-
|
|
6
|
-
import { l as isTransientNetworkError } from "./diagnostics-
|
|
3
|
+
import { i as asOptionalRecord, n as asNullableRecord, t as asNonArrayRecord } from "./record-coerce-BQaoiN3r.mjs";
|
|
4
|
+
import { E as headersToRecord, r as getAiTransportHost } from "./host-DX7ORpeH.mjs";
|
|
5
|
+
import { a as projectDiagnosticValue, n as projectProviderError, r as readTransportDiagnosticLabel } from "./provider-error-DD-fo4Rz.mjs";
|
|
6
|
+
import { l as isTransientNetworkError } from "./diagnostics-CloVGQiK.mjs";
|
|
7
7
|
import { t as createZeroUsage } from "./usage-CJH5D6Ea.mjs";
|
|
8
8
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-CRGuMONI.mjs";
|
|
9
9
|
import { parse } from "partial-json";
|
|
@@ -95,24 +95,20 @@ function clampNumber(value, fallback, min, max) {
|
|
|
95
95
|
if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
|
|
96
96
|
return Math.min(Math.max(value, min ?? Number.NEGATIVE_INFINITY), max ?? Number.POSITIVE_INFINITY);
|
|
97
97
|
}
|
|
98
|
-
function resolveAttemptCount(value, fallback) {
|
|
99
|
-
return Math.max(1, Math.round(clampNumber(value, fallback)));
|
|
100
|
-
}
|
|
101
98
|
function resolveRetryDelayMs(value) {
|
|
102
99
|
return Math.min(Math.max(Math.round(value === Number.POSITIVE_INFINITY ? MAX_TIMER_TIMEOUT_MS : Number.isFinite(value) ? value : 0), 0), MAX_TIMER_TIMEOUT_MS);
|
|
103
100
|
}
|
|
104
|
-
function resolveJitterConfig(value, fallback) {
|
|
105
|
-
if (value === "full") return "full";
|
|
106
|
-
return typeof value === "number" && Number.isFinite(value) ? Math.min(Math.max(value, 0), 1) : fallback;
|
|
107
|
-
}
|
|
108
101
|
function resolveRetryConfig(defaults = DEFAULT_RETRY_CONFIG, overrides) {
|
|
109
|
-
const attempts =
|
|
102
|
+
const attempts = Math.max(1, Math.round(clampNumber(overrides?.attempts, defaults.attempts)));
|
|
110
103
|
const minDelayMs = resolveRetryDelayMs(clampNumber(overrides?.minDelayMs, defaults.minDelayMs, 0));
|
|
104
|
+
const maxDelayMs = Math.max(minDelayMs, resolveRetryDelayMs(clampNumber(overrides?.maxDelayMs, defaults.maxDelayMs, 0)));
|
|
105
|
+
const jitter = overrides?.jitter;
|
|
106
|
+
const fallbackJitter = defaults.jitter;
|
|
111
107
|
return {
|
|
112
108
|
attempts,
|
|
113
109
|
minDelayMs,
|
|
114
|
-
maxDelayMs
|
|
115
|
-
jitter:
|
|
110
|
+
maxDelayMs,
|
|
111
|
+
jitter: jitter === "full" ? jitter : typeof jitter === "number" && Number.isFinite(jitter) ? Math.min(Math.max(jitter, 0), 1) : fallbackJitter
|
|
116
112
|
};
|
|
117
113
|
}
|
|
118
114
|
function applyJitter(delayMs, jitter, mode, random) {
|
|
@@ -152,7 +148,7 @@ function createRetryRunner(runtime = {}) {
|
|
|
152
148
|
return await fn();
|
|
153
149
|
} catch (err) {
|
|
154
150
|
attemptErrors.push(err);
|
|
155
|
-
if (attempt >= maxAttempts || !shouldRetry(err, attempt)) break;
|
|
151
|
+
if (attempt >= maxAttempts || runtime.shouldRetry?.(err) === false || !shouldRetry(err, attempt)) break;
|
|
156
152
|
if (numeric) {
|
|
157
153
|
await runtimeSleep(resolveRetryDelayMs(initialDelayMs * 2 ** (attempt - 1)));
|
|
158
154
|
continue;
|
|
@@ -185,21 +181,6 @@ function createRetryRunner(runtime = {}) {
|
|
|
185
181
|
}
|
|
186
182
|
createRetryRunner();
|
|
187
183
|
//#endregion
|
|
188
|
-
//#region packages/ai/src/utils/hash.ts
|
|
189
|
-
/** Fast deterministic hash to shorten long strings */
|
|
190
|
-
function shortHash(str) {
|
|
191
|
-
let h1 = 3735928559;
|
|
192
|
-
let h2 = 1103547991;
|
|
193
|
-
for (let i = 0; i < str.length; i++) {
|
|
194
|
-
const ch = str.charCodeAt(i);
|
|
195
|
-
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
196
|
-
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
197
|
-
}
|
|
198
|
-
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
199
|
-
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
200
|
-
return (h2 >>> 0).toString(36) + (h1 >>> 0).toString(36);
|
|
201
|
-
}
|
|
202
|
-
//#endregion
|
|
203
184
|
//#region packages/ai/src/utils/json-parse.ts
|
|
204
185
|
const SIMPLE_JSON_ESCAPES = /* @__PURE__ */ new Set([
|
|
205
186
|
"\"",
|
|
@@ -267,7 +248,7 @@ function repairJson(json, options) {
|
|
|
267
248
|
}
|
|
268
249
|
if (!preserveValidControlEscapes && JSON_CONTROL_ESCAPES.has(nextChar)) {
|
|
269
250
|
stringValuePrefix = stringValuePrefix.slice(-160);
|
|
270
|
-
if (
|
|
251
|
+
if (/(?:^|[^A-Za-z0-9])[A-Za-z]:(?:[\\/][^"\\/:*?<>|\r\n]*)*$/.test(stringValuePrefix)) {
|
|
271
252
|
repaired += "\\\\";
|
|
272
253
|
stringValuePrefix += "\\";
|
|
273
254
|
continue;
|
|
@@ -291,9 +272,6 @@ function repairJson(json, options) {
|
|
|
291
272
|
function parseJsonWithRepair(json) {
|
|
292
273
|
return JSON.parse(repairJson(json));
|
|
293
274
|
}
|
|
294
|
-
function looksLikeWindowsPathPrefix(prefix) {
|
|
295
|
-
return /(?:^|[^A-Za-z0-9])[A-Za-z]:(?:[\\/][^"\\/:*?<>|\r\n]*)*$/.test(prefix);
|
|
296
|
-
}
|
|
297
275
|
/**
|
|
298
276
|
* Attempts to parse potentially incomplete JSON during streaming.
|
|
299
277
|
* Always returns a valid object, even if the JSON is incomplete.
|
|
@@ -330,6 +308,21 @@ function createToolArgumentPreviewSchedule() {
|
|
|
330
308
|
};
|
|
331
309
|
}
|
|
332
310
|
//#endregion
|
|
311
|
+
//#region packages/ai/src/utils/hash.ts
|
|
312
|
+
/** Fast deterministic hash to shorten long strings */
|
|
313
|
+
function shortHash(str) {
|
|
314
|
+
let h1 = 3735928559;
|
|
315
|
+
let h2 = 1103547991;
|
|
316
|
+
for (let i = 0; i < str.length; i++) {
|
|
317
|
+
const ch = str.charCodeAt(i);
|
|
318
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
319
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
320
|
+
}
|
|
321
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
322
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
323
|
+
return (h2 >>> 0).toString(36) + (h1 >>> 0).toString(36);
|
|
324
|
+
}
|
|
325
|
+
//#endregion
|
|
333
326
|
//#region packages/ai/src/transports/json-unsafe-integers.ts
|
|
334
327
|
/**
|
|
335
328
|
* JSON parsing helpers that preserve integer literals larger than
|
|
@@ -337,14 +330,14 @@ function createToolArgumentPreviewSchedule() {
|
|
|
337
330
|
*/
|
|
338
331
|
const MAX_SAFE_INTEGER_ABS_STR = String(Number.MAX_SAFE_INTEGER);
|
|
339
332
|
const JSON_STRING_OR_NUMBER_RE = /"(?:\\[\s\S]|[^"\\])*"?|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/g;
|
|
340
|
-
function isUnsafeIntegerLiteral(token) {
|
|
341
|
-
const digits = token[0] === "-" ? token.slice(1) : token;
|
|
342
|
-
return digits.length > MAX_SAFE_INTEGER_ABS_STR.length || digits.length === MAX_SAFE_INTEGER_ABS_STR.length && digits > MAX_SAFE_INTEGER_ABS_STR;
|
|
343
|
-
}
|
|
344
333
|
/** Quotes integer literals above Number.MAX_SAFE_INTEGER before JSON.parse. */
|
|
345
334
|
function quoteUnsafeIntegerLiterals(input) {
|
|
346
335
|
if (!/(?:^|\D)\d{16}/.test(input)) return input;
|
|
347
|
-
return input.replace(JSON_STRING_OR_NUMBER_RE, (token, offset) =>
|
|
336
|
+
return input.replace(JSON_STRING_OR_NUMBER_RE, (token, offset) => {
|
|
337
|
+
if (token[0] === "\"" || /[.eE]/.test(token) || /[.eE]/.test(input.charAt(offset + token.length))) return token;
|
|
338
|
+
const digits = token[0] === "-" ? token.slice(1) : token;
|
|
339
|
+
return digits.length > MAX_SAFE_INTEGER_ABS_STR.length || digits.length === MAX_SAFE_INTEGER_ABS_STR.length && digits > MAX_SAFE_INTEGER_ABS_STR ? `"${token}"` : token;
|
|
340
|
+
});
|
|
348
341
|
}
|
|
349
342
|
/** Parses JSON while preserving unsafe integer literals as strings. */
|
|
350
343
|
function parseJsonPreservingUnsafeIntegers(input) {
|
|
@@ -361,6 +354,83 @@ function parseJsonObjectPreservingUnsafeIntegers(value) {
|
|
|
361
354
|
}
|
|
362
355
|
//#endregion
|
|
363
356
|
//#region packages/ai/src/transports/transport-stream-shared.ts
|
|
357
|
+
/** A single synchronous scanner per stream; undefined requests the next reader result. */
|
|
358
|
+
function* decodeSseFrames(limit) {
|
|
359
|
+
const decoder = new TextDecoder();
|
|
360
|
+
const streaming = { stream: true };
|
|
361
|
+
const parts = [];
|
|
362
|
+
let partsLength = 0;
|
|
363
|
+
let tail = "";
|
|
364
|
+
const lengthOf = limit?.unit === "bytes" ? (text) => Buffer.byteLength(text, "utf8") : (text) => text.length;
|
|
365
|
+
const assertWithinLimit = (length) => {
|
|
366
|
+
if (limit && length > limit.max) throw new Error(limit.message);
|
|
367
|
+
};
|
|
368
|
+
for (;;) {
|
|
369
|
+
const { done, value } = yield void 0;
|
|
370
|
+
const buffer = tail + decoder.decode(value, done ? void 0 : streaming);
|
|
371
|
+
let start = 0;
|
|
372
|
+
let cr = buffer.indexOf("\r");
|
|
373
|
+
let lf = buffer.indexOf("\n");
|
|
374
|
+
for (;;) {
|
|
375
|
+
let frameEnd = buffer.length;
|
|
376
|
+
let boundaryEnd = -1;
|
|
377
|
+
let previousStart = -1;
|
|
378
|
+
let previousEnd = -1;
|
|
379
|
+
while (cr >= 0 || lf >= 0) {
|
|
380
|
+
const next = cr < 0 ? lf : lf < 0 ? cr : Math.min(cr, lf);
|
|
381
|
+
const end = next + (buffer[next] === "\r" && buffer[next + 1] === "\n" ? 2 : 1);
|
|
382
|
+
if (cr >= 0 && cr < end) cr = buffer.indexOf("\r", end);
|
|
383
|
+
if (lf >= 0 && lf < end) lf = buffer.indexOf("\n", end);
|
|
384
|
+
if (previousEnd === next) {
|
|
385
|
+
frameEnd = previousStart;
|
|
386
|
+
boundaryEnd = end;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
previousStart = next;
|
|
390
|
+
previousEnd = end;
|
|
391
|
+
}
|
|
392
|
+
if (boundaryEnd < 0 && (!done || !parts.length && start === buffer.length)) break;
|
|
393
|
+
let frame = buffer.slice(start, frameEnd);
|
|
394
|
+
if (limit) assertWithinLimit(partsLength + lengthOf(frame));
|
|
395
|
+
if (parts.length) {
|
|
396
|
+
parts.push(frame);
|
|
397
|
+
frame = parts.join("");
|
|
398
|
+
parts.length = 0;
|
|
399
|
+
partsLength = 0;
|
|
400
|
+
}
|
|
401
|
+
start = boundaryEnd < 0 ? buffer.length : boundaryEnd;
|
|
402
|
+
yield {
|
|
403
|
+
frame,
|
|
404
|
+
terminated: boundaryEnd >= 0
|
|
405
|
+
};
|
|
406
|
+
if (boundaryEnd < 0) break;
|
|
407
|
+
}
|
|
408
|
+
const pending = buffer.slice(start);
|
|
409
|
+
let split = pending.length;
|
|
410
|
+
while (split > 0 && pending.length - split < 3) {
|
|
411
|
+
const last = pending.charCodeAt(split - 1);
|
|
412
|
+
if (last !== 10 && last !== 13) break;
|
|
413
|
+
split--;
|
|
414
|
+
}
|
|
415
|
+
if (split > 0) {
|
|
416
|
+
const part = pending.slice(0, split);
|
|
417
|
+
parts.push(part);
|
|
418
|
+
if (limit) partsLength += lengthOf(part);
|
|
419
|
+
}
|
|
420
|
+
tail = pending.slice(split);
|
|
421
|
+
if (limit) assertWithinLimit(partsLength + lengthOf(tail));
|
|
422
|
+
if (done) return;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
/** Decodes frame boundaries; callers retain reader lifetime and protocol admission. */
|
|
426
|
+
async function* iterateSseFrames(read, limit) {
|
|
427
|
+
const decoder = decodeSseFrames(limit);
|
|
428
|
+
for (let next = decoder.next(); !next.done;) if (next.value === void 0) next = decoder.next(await read());
|
|
429
|
+
else {
|
|
430
|
+
yield next.value;
|
|
431
|
+
next = decoder.next();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
364
434
|
const EMPTY_TOOL_RESULT_TEXT = "(no output)";
|
|
365
435
|
const MALFORMED_TOOL_CALL_TERMINAL_ERROR_MESSAGE = "Provider completed tool call with malformed JSON arguments";
|
|
366
436
|
function sanitizeTransportPayloadText(text) {
|
|
@@ -387,21 +457,6 @@ var IncompleteToolCallError = class extends Error {
|
|
|
387
457
|
}
|
|
388
458
|
};
|
|
389
459
|
const MALFORMED_TOOL_CALL_TERMINAL_ERROR_CODE = "malformed_tool_call_arguments";
|
|
390
|
-
function createMalformedToolCallArgumentsError(value, errorMessage, repairAttempted) {
|
|
391
|
-
const text = typeof value === "string" ? value : void 0;
|
|
392
|
-
const diagnostics = {
|
|
393
|
-
code: MALFORMED_TOOL_CALL_TERMINAL_ERROR_CODE,
|
|
394
|
-
argumentChars: text?.length ?? 0,
|
|
395
|
-
argumentHash: text === void 0 ? "" : shortHash(text),
|
|
396
|
-
repairAttempted
|
|
397
|
-
};
|
|
398
|
-
const error = new Error(errorMessage, { cause: diagnostics });
|
|
399
|
-
Object.assign(error, {
|
|
400
|
-
errorCode: MALFORMED_TOOL_CALL_TERMINAL_ERROR_CODE,
|
|
401
|
-
errorBody: JSON.stringify(diagnostics)
|
|
402
|
-
});
|
|
403
|
-
return error;
|
|
404
|
-
}
|
|
405
460
|
/**
|
|
406
461
|
* Repair a complete-but-invalid terminal argument buffer. Anthropic fine-grained tool
|
|
407
462
|
* streaming skips server-side JSON validation, so a finished tool_use block can carry raw
|
|
@@ -427,7 +482,24 @@ function parseTerminalToolCallArguments(value, errorMessage = MALFORMED_TOOL_CAL
|
|
|
427
482
|
const repaired = repairTerminalToolCallArguments(value);
|
|
428
483
|
if (repaired) return repaired;
|
|
429
484
|
}
|
|
430
|
-
|
|
485
|
+
const text = typeof value === "string" ? value : void 0;
|
|
486
|
+
/**
|
|
487
|
+
* Bounded, content-free diagnostics for a rejected terminal argument buffer. Carried as the
|
|
488
|
+
* error `cause` and mirrored onto the error's `errorCode` / `errorBody` fields so
|
|
489
|
+
* `projectProviderError` surfaces them on the terminal assistant message.
|
|
490
|
+
*/
|
|
491
|
+
const diagnostics = {
|
|
492
|
+
code: MALFORMED_TOOL_CALL_TERMINAL_ERROR_CODE,
|
|
493
|
+
argumentChars: text?.length ?? 0,
|
|
494
|
+
argumentHash: text === void 0 ? "" : shortHash(text),
|
|
495
|
+
repairAttempted: repairStringLiterals
|
|
496
|
+
};
|
|
497
|
+
const error = new Error(errorMessage, { cause: diagnostics });
|
|
498
|
+
Object.assign(error, {
|
|
499
|
+
errorCode: MALFORMED_TOOL_CALL_TERMINAL_ERROR_CODE,
|
|
500
|
+
errorBody: JSON.stringify(diagnostics)
|
|
501
|
+
});
|
|
502
|
+
throw error;
|
|
431
503
|
}
|
|
432
504
|
/** Validate a complete sibling set before mutating any call into executable state. */
|
|
433
505
|
function finalizeTerminalToolCallArguments(calls, readArguments, errorMessage, options) {
|
|
@@ -470,33 +542,36 @@ function transportAbortError(signal) {
|
|
|
470
542
|
const reason = signal?.reason;
|
|
471
543
|
return reason instanceof Error && typeof reason.code === "string" ? reason : /* @__PURE__ */ new Error("Request was aborted");
|
|
472
544
|
}
|
|
473
|
-
const MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS =
|
|
474
|
-
const
|
|
545
|
+
const MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS = 6;
|
|
546
|
+
const MODEL_STREAM_COOPERATIVE_YIELD_BUDGET = 64;
|
|
547
|
+
const MODEL_STREAM_START_WORK = 8;
|
|
548
|
+
let streamWorkThisTurn = 0;
|
|
549
|
+
let streamTurnStartedAt = 0;
|
|
550
|
+
let nextStreamTurn;
|
|
475
551
|
function throwIfModelStreamAborted(signal) {
|
|
476
552
|
if (signal?.aborted) throw transportAbortError(signal);
|
|
477
553
|
}
|
|
478
|
-
function
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
554
|
+
function waitForModelStreamTurn(signal, work = 1) {
|
|
555
|
+
throwIfModelStreamAborted(signal);
|
|
556
|
+
if (nextStreamTurn && (streamWorkThisTurn + work > MODEL_STREAM_COOPERATIVE_YIELD_BUDGET || Date.now() - streamTurnStartedAt >= MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS)) return nextStreamTurn;
|
|
557
|
+
if (!nextStreamTurn) {
|
|
558
|
+
streamTurnStartedAt = Date.now();
|
|
559
|
+
nextStreamTurn = new Promise((resolve) => {
|
|
560
|
+
setTimeout(() => {
|
|
561
|
+
streamWorkThisTurn = 0;
|
|
562
|
+
nextStreamTurn = void 0;
|
|
563
|
+
resolve();
|
|
564
|
+
}, 0);
|
|
488
565
|
});
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
} };
|
|
566
|
+
}
|
|
567
|
+
streamWorkThisTurn += work;
|
|
492
568
|
}
|
|
493
569
|
/** Keep ready provider events from monopolizing the main loop, including ignored events. */
|
|
494
570
|
async function* iterateModelStream(events, signal) {
|
|
495
|
-
const scheduler = createModelStreamCooperativeScheduler(signal);
|
|
496
571
|
for await (const event of events) {
|
|
497
|
-
|
|
572
|
+
for (let wait; wait = waitForModelStreamTurn(signal);) await wait;
|
|
498
573
|
yield event;
|
|
499
|
-
|
|
574
|
+
throwIfModelStreamAborted(signal);
|
|
500
575
|
}
|
|
501
576
|
}
|
|
502
577
|
const providerAcceptanceObserver = Symbol("openclaw.providerAcceptanceObserver");
|
|
@@ -606,6 +681,7 @@ function withProviderResponseHook(params) {
|
|
|
606
681
|
return { async *[Symbol.asyncIterator]() {
|
|
607
682
|
try {
|
|
608
683
|
await awaitProviderLifecycleCallback(params.hook, params.signal);
|
|
684
|
+
for (let wait; wait = waitForModelStreamTurn(params.signal, MODEL_STREAM_START_WORK);) await wait;
|
|
609
685
|
} catch (error) {
|
|
610
686
|
params.abort(error instanceof Error ? error : new Error(String(error)));
|
|
611
687
|
throw error;
|
|
@@ -627,22 +703,30 @@ function finalizeTransportStream(params) {
|
|
|
627
703
|
stream.end();
|
|
628
704
|
}
|
|
629
705
|
/** Assign terminal fields and record silent transport failures before partial-call cleanup. */
|
|
630
|
-
function assignTransportErrorDetails(output, error, signal) {
|
|
631
|
-
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
706
|
+
function assignTransportErrorDetails(output, error, signal, diagnostic) {
|
|
707
|
+
try {
|
|
708
|
+
const host = getAiTransportHost();
|
|
709
|
+
if (!signal?.aborted && host.isLogEnabled?.("provider-error", "warn") !== false) {
|
|
710
|
+
const record = asOptionalRecord(error);
|
|
711
|
+
const response = asOptionalRecord(record?.response);
|
|
712
|
+
const cause = asOptionalRecord(record?.cause);
|
|
713
|
+
const detail = asOptionalRecord(record?.error) ?? asOptionalRecord(response?.error) ?? asOptionalRecord(asOptionalRecord(record?.payload)?.error);
|
|
714
|
+
const metadata = {
|
|
715
|
+
provider: output.provider,
|
|
716
|
+
model: output.model,
|
|
717
|
+
name: readTransportDiagnosticLabel(record?.name),
|
|
718
|
+
...diagnostic,
|
|
719
|
+
status: readTransportDiagnosticLabel(record?.status ?? record?.statusCode ?? response?.status),
|
|
720
|
+
code: readTransportDiagnosticLabel(record?.errorCode ?? record?.code ?? detail?.code),
|
|
721
|
+
type: readTransportDiagnosticLabel(record?.errorType ?? detail?.type ?? record?.type),
|
|
722
|
+
causeName: readTransportDiagnosticLabel(cause?.name),
|
|
723
|
+
causeCode: readTransportDiagnosticLabel(cause?.code),
|
|
724
|
+
requestId: readTransportDiagnosticLabel(record?.request_id ?? record?.requestId),
|
|
725
|
+
responseId: readTransportDiagnosticLabel(record?.responseId ?? response?.id ?? output.responseId)
|
|
726
|
+
};
|
|
727
|
+
for (const key in metadata) if (metadata[key] === void 0) delete metadata[key];
|
|
728
|
+
host.logWarn("provider-error", "Model request failed", metadata);
|
|
729
|
+
}
|
|
646
730
|
} catch {}
|
|
647
731
|
const projection = projectProviderError(error, signal);
|
|
648
732
|
Object.assign(output, projection);
|
|
@@ -650,7 +734,7 @@ function assignTransportErrorDetails(output, error, signal) {
|
|
|
650
734
|
output.usage.usageReport = { state: "unavailable" };
|
|
651
735
|
output.usage.contextUsage = { state: "unavailable" };
|
|
652
736
|
}
|
|
653
|
-
if (projection.stopReason === "error" && output.content.length === 0 && isTransientNetworkError(projectDiagnosticValue(error)) && !output.diagnostics?.some((
|
|
737
|
+
if (projection.stopReason === "error" && output.content.length === 0 && isTransientNetworkError(projectDiagnosticValue(error)) && !output.diagnostics?.some((entry) => entry.type === "provider_transport_failure")) appendAssistantMessageDiagnostic(output, createAssistantMessageDiagnostic("provider_transport_failure", projection.errorMessage, {
|
|
654
738
|
eventsEmitted: false,
|
|
655
739
|
phase: "before_message_stream_start"
|
|
656
740
|
}));
|
|
@@ -658,7 +742,7 @@ function assignTransportErrorDetails(output, error, signal) {
|
|
|
658
742
|
}
|
|
659
743
|
function failTransportStream(params) {
|
|
660
744
|
const { stream, output, signal, error, cleanup } = params;
|
|
661
|
-
const projection = assignTransportErrorDetails(output, error, signal);
|
|
745
|
+
const projection = assignTransportErrorDetails(output, error, signal, params.diagnostic);
|
|
662
746
|
cleanup?.();
|
|
663
747
|
stream.push({
|
|
664
748
|
type: "error",
|
|
@@ -668,4 +752,4 @@ function failTransportStream(params) {
|
|
|
668
752
|
stream.end();
|
|
669
753
|
}
|
|
670
754
|
//#endregion
|
|
671
|
-
export {
|
|
755
|
+
export { parseStreamingJson as A, withProviderResponseHook as C, shortHash as D, quoteUnsafeIntegerLiterals as E, createAbortError as M, racePromiseWithAbortSignal as N, createToolArgumentPreviewSchedule as O, raceWithTimeout as P, withProviderAcceptanceObserver as S, parseJsonPreservingUnsafeIntegers as T, parseTerminalToolCallArguments as _, createEmptyTransportUsage as a, throwIfModelStreamAborted as b, failTransportStream as c, iterateModelStream as d, iterateSseFrames as f, notifyProviderStreamOpened as g, notifyProviderHttpResponse as h, copyProviderAcceptanceObserver as i, repairJson as j, parseJsonWithRepair as k, finalizeTerminalToolCallArguments as l, notifyProviderHttpMetadata as m, assignTransportErrorDetails as n, createWritableTransportEventStream as o, mergeTransportHeaders as p, coerceTransportToolCallArguments as r, decodeSseFrames as s, IncompleteToolCallError as t, finalizeTransportStream as u, sanitizeNonEmptyTransportPayloadText as v, parseJsonObjectPreservingUnsafeIntegers as w, transportAbortError as x, sanitizeTransportPayloadText as y };
|