@openclaw/ai 0.0.0 → 2026.7.1-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/LICENSE +21 -0
- package/README.md +27 -3
- package/dist/anthropic-B5gZQM5X.mjs +1383 -0
- package/dist/api-registry-BXYnCOIR.d.mts +33 -0
- package/dist/azure-openai-responses-DNoSk8Uy.mjs +141 -0
- package/dist/azure-openai-responses-client-compat-a_O_GVQV.mjs +41 -0
- package/dist/diagnostics-BaTA9eVl.d.mts +25 -0
- package/dist/diagnostics-COpOtRwq.mjs +36 -0
- package/dist/diagnostics.d.mts +2 -0
- package/dist/diagnostics.mjs +2 -0
- package/dist/env-api-keys-CtMlqaQ4.mjs +171 -0
- package/dist/event-stream-0nZeBKl2.d.mts +26 -0
- package/dist/event-stream-ReMmOTzX.mjs +65 -0
- package/dist/event-stream.d.mts +2 -0
- package/dist/event-stream.mjs +2 -0
- package/dist/github-copilot-headers-BsH5cqGj.mjs +48 -0
- package/dist/google-D6sIQ1bL.mjs +55 -0
- package/dist/google-shared-ZPSl2qTi.mjs +548 -0
- package/dist/google-vertex-rDGwkoZK.mjs +111 -0
- package/dist/hash-CHgqbJmD.mjs +16 -0
- package/dist/headers-B_e4-1J0.mjs +9 -0
- package/dist/host-4t713IeR.mjs +37 -0
- package/dist/index-BoTnz8cv.d.mts +74 -0
- package/dist/index.d.mts +69 -0
- package/dist/index.mjs +7 -0
- package/dist/internal/anthropic.d.mts +234 -0
- package/dist/internal/anthropic.mjs +4 -0
- package/dist/internal/openai.d.mts +244 -0
- package/dist/internal/openai.mjs +7 -0
- package/dist/internal/runtime.d.mts +245 -0
- package/dist/internal/runtime.mjs +176 -0
- package/dist/internal/shared.d.mts +48 -0
- package/dist/internal/shared.mjs +3 -0
- package/dist/json-parse-DzNSIQBq.mjs +134 -0
- package/dist/llm-request-activity-CehVkZP-.mjs +35 -0
- package/dist/mistral-CePVNdws.mjs +563 -0
- package/dist/model-utils-DgmOla96.mjs +69 -0
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +39 -0
- package/dist/openai-chatgpt-responses-DVC4Bk_A.mjs +1068 -0
- package/dist/openai-completions-B9QLIq2U.mjs +844 -0
- package/dist/openai-responses-B6LylGxM.mjs +136 -0
- package/dist/openai-responses-shared-sj2YUPYc.mjs +1944 -0
- package/dist/openai-tool-projection-BknoV11q.mjs +195 -0
- package/dist/providers.d.mts +11 -0
- package/dist/providers.mjs +109 -0
- package/dist/reasoning-tag-text-partitioner-axhAdUwg.mjs +394 -0
- package/dist/sanitize-unicode-BZiVbGwK.d.mts +24 -0
- package/dist/sanitize-unicode-DT5o51ur.mjs +26 -0
- package/dist/src-CZ503MYJ.mjs +99 -0
- package/dist/stream-CREqxHgU.mjs +74 -0
- package/dist/stream-first-event-timeout-RjWszj8c.mjs +106 -0
- package/dist/streaming-byte-guard-BrbkbwUu.mjs +46 -0
- package/dist/tool-schema-json-projection-BXtBc_mD.mjs +74 -0
- package/dist/transform-messages-BhGF_fF4.mjs +507 -0
- package/dist/types-BVVgDSdq.d.mts +1 -0
- package/dist/types-DRgdPqaZ.d.mts +587 -0
- package/dist/types.d.mts +6 -0
- package/dist/types.mjs +5 -0
- package/dist/validation-BDMWOr8d.d.mts +9 -0
- package/dist/validation-FrchoOlv.mjs +199 -0
- package/dist/validation.d.mts +2 -0
- package/dist/validation.mjs +2 -0
- package/npm-shrinkwrap.json +645 -0
- package/package.json +74 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region packages/normalization-core/src/number-coercion.ts
|
|
2
|
+
/** Returns a number only when the input is already finite. */
|
|
3
|
+
function asFiniteNumber(value) {
|
|
4
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
5
|
+
}
|
|
6
|
+
/** Conservative upper bound for Node timer delays. */
|
|
7
|
+
const MAX_TIMER_TIMEOUT_MS = 2147e6;
|
|
8
|
+
/** Clamps finite millisecond values into the Node-safe timer range. */
|
|
9
|
+
function clampTimerTimeoutMs(valueMs, minMs = 1) {
|
|
10
|
+
const value = asFiniteNumber(valueMs);
|
|
11
|
+
if (value === void 0) return;
|
|
12
|
+
return Math.min(Math.max(Math.floor(value), Math.max(1, Math.floor(minMs))), MAX_TIMER_TIMEOUT_MS);
|
|
13
|
+
}
|
|
14
|
+
/** Resolves arbitrary timeout input with fallback and minimum timer bounds. */
|
|
15
|
+
function resolveTimerTimeoutMs(valueMs, fallbackMs, minMs = 1) {
|
|
16
|
+
const value = asFiniteNumber(valueMs) ?? asFiniteNumber(fallbackMs);
|
|
17
|
+
const min = Math.max(0, Math.floor(minMs));
|
|
18
|
+
if (value === void 0) return min;
|
|
19
|
+
return Math.min(Math.max(Math.floor(value), min), MAX_TIMER_TIMEOUT_MS);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region packages/ai/src/utils/stream-first-event-timeout.ts
|
|
23
|
+
function getFirstStreamEventTimeoutMs(options) {
|
|
24
|
+
return options?.firstEventTimeoutMs;
|
|
25
|
+
}
|
|
26
|
+
function getFirstStreamEventTimeoutHandler(options) {
|
|
27
|
+
return options?.onFirstEventTimeout;
|
|
28
|
+
}
|
|
29
|
+
function formatOptionalField(name, value) {
|
|
30
|
+
return value ? ` ${name}=${value}` : "";
|
|
31
|
+
}
|
|
32
|
+
function createFirstStreamEventTimeoutError(context) {
|
|
33
|
+
const stage = context.stage ? `${context.stage} ` : "";
|
|
34
|
+
const details = [
|
|
35
|
+
formatOptionalField("provider", context.provider),
|
|
36
|
+
formatOptionalField("api", context.api),
|
|
37
|
+
formatOptionalField("model", context.model)
|
|
38
|
+
].join("");
|
|
39
|
+
return /* @__PURE__ */ new Error(`${stage}HTTP stream opened but did not deliver a first SSE event within ${context.timeoutMs}ms after streaming headers (first-event timeout).${details}` + (context.hint ? ` ${context.hint}` : ""));
|
|
40
|
+
}
|
|
41
|
+
function createFirstStreamEventAbortController(parentSignal) {
|
|
42
|
+
const controller = new AbortController();
|
|
43
|
+
const abortFromParent = () => {
|
|
44
|
+
if (!controller.signal.aborted) controller.abort(parentSignal?.reason);
|
|
45
|
+
};
|
|
46
|
+
if (parentSignal?.aborted) abortFromParent();
|
|
47
|
+
else parentSignal?.addEventListener("abort", abortFromParent, { once: true });
|
|
48
|
+
return {
|
|
49
|
+
signal: controller.signal,
|
|
50
|
+
abort(reason) {
|
|
51
|
+
if (!controller.signal.aborted) controller.abort(reason);
|
|
52
|
+
},
|
|
53
|
+
dispose() {
|
|
54
|
+
parentSignal?.removeEventListener("abort", abortFromParent);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function withFirstStreamEventTimeout(stream, context) {
|
|
59
|
+
const timeoutMs = clampTimerTimeoutMs(context.timeoutMs);
|
|
60
|
+
if (timeoutMs === void 0 || context.timeoutMs <= 0) return stream;
|
|
61
|
+
const timeoutContext = {
|
|
62
|
+
...context,
|
|
63
|
+
timeoutMs
|
|
64
|
+
};
|
|
65
|
+
return { async *[Symbol.asyncIterator]() {
|
|
66
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
67
|
+
let timer;
|
|
68
|
+
let completed = false;
|
|
69
|
+
const clear = () => {
|
|
70
|
+
if (timer) {
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
timer = void 0;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
const first = await new Promise((resolve, reject) => {
|
|
77
|
+
timer = setTimeout(() => {
|
|
78
|
+
const timeoutError = createFirstStreamEventTimeoutError(timeoutContext);
|
|
79
|
+
timeoutContext.onTimeout?.(timeoutError);
|
|
80
|
+
timeoutContext.abort?.(timeoutError);
|
|
81
|
+
reject(timeoutError);
|
|
82
|
+
}, timeoutMs);
|
|
83
|
+
timer.unref?.();
|
|
84
|
+
iterator.next().then(resolve, reject);
|
|
85
|
+
}).finally(clear);
|
|
86
|
+
if (first.done) {
|
|
87
|
+
completed = true;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
yield first.value;
|
|
91
|
+
for (;;) {
|
|
92
|
+
const next = await iterator.next();
|
|
93
|
+
if (next.done) {
|
|
94
|
+
completed = true;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
yield next.value;
|
|
98
|
+
}
|
|
99
|
+
} finally {
|
|
100
|
+
clear();
|
|
101
|
+
if (!completed) iterator.return?.().catch(() => void 0);
|
|
102
|
+
}
|
|
103
|
+
} };
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { withFirstStreamEventTimeout as a, getFirstStreamEventTimeoutMs as i, createFirstStreamEventTimeoutError as n, clampTimerTimeoutMs as o, getFirstStreamEventTimeoutHandler as r, resolveTimerTimeoutMs as s, createFirstStreamEventAbortController as t };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region packages/ai/src/utils/streaming-byte-guard.ts
|
|
2
|
+
function createSseByteGuard(reader, opts) {
|
|
3
|
+
if (!Number.isFinite(opts.maxBytes) || opts.maxBytes < 0) throw new RangeError(`maxBytes must be a non-negative finite number: ${opts.maxBytes}`);
|
|
4
|
+
const onOverflow = opts.onOverflow ?? ((params) => /* @__PURE__ */ new Error(`SSE stream exceeds ${params.maxBytes} bytes (received ${params.size})`));
|
|
5
|
+
let total = 0;
|
|
6
|
+
let overflowedFlag = false;
|
|
7
|
+
let cancelledFlag = false;
|
|
8
|
+
return {
|
|
9
|
+
read: async () => {
|
|
10
|
+
if (overflowedFlag || cancelledFlag) return {
|
|
11
|
+
done: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
};
|
|
14
|
+
const result = await reader.read();
|
|
15
|
+
if (result.done) return result;
|
|
16
|
+
const chunkLen = result.value?.byteLength ?? 0;
|
|
17
|
+
const next = total + chunkLen;
|
|
18
|
+
if (next > opts.maxBytes) {
|
|
19
|
+
overflowedFlag = true;
|
|
20
|
+
cancelledFlag = true;
|
|
21
|
+
const err = onOverflow({
|
|
22
|
+
size: next,
|
|
23
|
+
maxBytes: opts.maxBytes
|
|
24
|
+
});
|
|
25
|
+
try {
|
|
26
|
+
await reader.cancel(err);
|
|
27
|
+
} catch {}
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
total = next;
|
|
31
|
+
return result;
|
|
32
|
+
},
|
|
33
|
+
cancel: async (reason) => {
|
|
34
|
+
if (overflowedFlag) return;
|
|
35
|
+
cancelledFlag = true;
|
|
36
|
+
try {
|
|
37
|
+
await reader.cancel(reason);
|
|
38
|
+
} catch {}
|
|
39
|
+
},
|
|
40
|
+
totalBytes: () => total,
|
|
41
|
+
overflowed: () => overflowedFlag,
|
|
42
|
+
cancelled: () => cancelledFlag
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { createSseByteGuard as t };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//#region packages/ai/src/providers/tool-schema-json-projection.ts
|
|
2
|
+
function isJsonValue(value) {
|
|
3
|
+
if (value === null) return true;
|
|
4
|
+
switch (typeof value) {
|
|
5
|
+
case "boolean":
|
|
6
|
+
case "number":
|
|
7
|
+
case "string": return true;
|
|
8
|
+
case "object":
|
|
9
|
+
if (Array.isArray(value)) return value.every(isJsonValue);
|
|
10
|
+
return Object.values(value).every(isJsonValue);
|
|
11
|
+
default: return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function isJsonObject(value) {
|
|
15
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
function serializeToolInputSchema(value, path) {
|
|
18
|
+
let text;
|
|
19
|
+
try {
|
|
20
|
+
text = JSON.stringify(value);
|
|
21
|
+
} catch {
|
|
22
|
+
return {
|
|
23
|
+
schema: {},
|
|
24
|
+
violations: [`${path} is not JSON-serializable`]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (!text) return {
|
|
28
|
+
schema: {},
|
|
29
|
+
violations: [`${path} is not JSON-serializable`]
|
|
30
|
+
};
|
|
31
|
+
const parsed = JSON.parse(text);
|
|
32
|
+
if (!isJsonValue(parsed)) return {
|
|
33
|
+
schema: {},
|
|
34
|
+
violations: [`${path} is not a JSON value`]
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
schema: parsed,
|
|
38
|
+
violations: []
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const schemaMapKeywords = /* @__PURE__ */ new Set([
|
|
42
|
+
"$defs",
|
|
43
|
+
"definitions",
|
|
44
|
+
"dependencies",
|
|
45
|
+
"dependentSchemas",
|
|
46
|
+
"patternProperties",
|
|
47
|
+
"properties"
|
|
48
|
+
]);
|
|
49
|
+
function findDynamicSchemaKeywordViolations(schema, path) {
|
|
50
|
+
if (Array.isArray(schema)) return schema.flatMap((entry, index) => findDynamicSchemaKeywordViolations(entry, `${path}[${index}]`));
|
|
51
|
+
if (!isJsonObject(schema)) return [];
|
|
52
|
+
const violations = [];
|
|
53
|
+
for (const key of ["$dynamicRef", "$dynamicAnchor"]) if (key in schema) violations.push(`${path}.${key}`);
|
|
54
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
55
|
+
if (!value || typeof value !== "object") continue;
|
|
56
|
+
if (schemaMapKeywords.has(key) && isJsonObject(value)) for (const [schemaName, childSchema] of Object.entries(value)) violations.push(...findDynamicSchemaKeywordViolations(childSchema, `${path}.${key}.${schemaName}`));
|
|
57
|
+
else violations.push(...findDynamicSchemaKeywordViolations(value, `${path}.${key}`));
|
|
58
|
+
}
|
|
59
|
+
return violations;
|
|
60
|
+
}
|
|
61
|
+
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
62
|
+
function projectRuntimeToolInputSchema(schema, path = "parameters") {
|
|
63
|
+
const projection = serializeToolInputSchema(schema, path);
|
|
64
|
+
const violations = [...projection.violations];
|
|
65
|
+
if (!isJsonObject(projection.schema)) violations.push(`${path} must be a JSON object schema`);
|
|
66
|
+
else if (projection.schema.type !== void 0 && projection.schema.type !== "object") violations.push(`${path}.type must be "object"`);
|
|
67
|
+
violations.push(...findDynamicSchemaKeywordViolations(projection.schema, path));
|
|
68
|
+
return {
|
|
69
|
+
schema: projection.schema,
|
|
70
|
+
violations
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { projectRuntimeToolInputSchema as t };
|