@openclaw/ai 2026.7.2-beta.5 → 2026.7.2-beta.7
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/dist/{anthropic-CQVj3le6.mjs → anthropic-CH4UUnZr.mjs} +14 -463
- package/dist/anthropic-usage-DWU-x8MI.mjs +459 -0
- package/dist/{azure-openai-responses-DIYgsqFM.mjs → azure-openai-responses-CImcwB83.mjs} +4 -3
- package/dist/azure-openai-responses-client-compat-C7K7QfUE.mjs +62 -0
- package/dist/cache-retention-0x979a5V.mjs +12 -0
- package/dist/deferred-event-buffer-DAvyP7qA.mjs +19 -0
- package/dist/github-copilot-headers-NCJtz9i0.mjs +37 -0
- package/dist/{google-f-A8xrae.mjs → google-CtSg0iTS.mjs} +3 -3
- package/dist/{google-shared-J6qvYINH.mjs → google-shared-DNBz5rcD.mjs} +5 -3
- package/dist/{google-vertex-D3yMVXIY.mjs → google-vertex-31f1uS9L.mjs} +3 -3
- package/dist/host-Dog2WQiR.mjs +369 -0
- package/dist/index.mjs +1 -1
- package/dist/internal/anthropic.d.mts +3 -53
- package/dist/internal/anthropic.mjs +3 -2
- package/dist/internal/openai.d.mts +259 -2
- package/dist/internal/openai.mjs +8 -4
- package/dist/internal/runtime.mjs +6 -4
- package/dist/internal/shared.d.mts +1 -1
- package/dist/internal/shared.mjs +5 -1
- package/dist/{llm-request-activity-CehVkZP-.mjs → llm-request-activity-BjtkplhG.mjs} +1 -19
- package/dist/{mistral-CKV-TOQj.mjs → mistral-CWmpvWYh.mjs} +5 -3
- package/dist/{openai-chatgpt-responses-CedIj0hk.mjs → openai-chatgpt-responses-B84Ibtrd.mjs} +18 -13
- package/dist/openai-completions-DsOxhOD1.mjs +630 -0
- package/dist/openai-completions-compat-DBWjXoMZ.d.mts +43 -0
- package/dist/openai-reasoning-compat-YgeLncHw.mjs +396 -0
- package/dist/openai-responses-BT7A3sLu.mjs +138 -0
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +392 -0
- package/dist/{openai-D3PD6PE-.mjs → openai-responses-stream-internal-Cw5txaGW.mjs} +1409 -1863
- package/dist/openai-tool-projection-OhX64DoP.mjs +215 -0
- package/dist/{provider-error-apVOZI6G.mjs → provider-error-CAEvRjry.mjs} +1 -1
- package/dist/provider-options-D8bB3z9b.d.mts +144 -0
- package/dist/providers.mjs +8 -8
- package/dist/{stream-first-event-timeout-C3OgBjIk.mjs → reasoning-tag-text-partitioner-CGDyLWUR.mjs} +1 -86
- package/dist/simple-options-9lhRrN73.mjs +50 -0
- package/dist/stream-first-event-timeout-BBys9hSb.mjs +86 -0
- package/dist/tls-certificate-errors-DXSpluKI.mjs +93 -0
- package/dist/tool-result-text-CTpIRbYd.mjs +225 -0
- package/dist/{github-copilot-headers-BCoBNmL7.mjs → tool-schema-json-projection-BwNu3nDi.mjs} +1 -48
- package/dist/transform-messages-C8mBqZxF.mjs +2 -0
- package/dist/{transport-stream-shared-BbMELSI4.mjs → transport-stream-shared-D81p90xq.mjs} +4 -4
- package/dist/transports.d.mts +13 -33
- package/dist/transports.mjs +75 -34
- package/package.json +4 -4
- package/dist/host-XYGZcgO8.mjs +0 -98
- package/dist/openai-BPor_3WI.d.mts +0 -358
- package/dist/openai-completions-CiSutyu0.mjs +0 -1223
- package/dist/shared-CdjNZd35.mjs +0 -634
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//#region packages/ai/src/utils/tls-certificate-errors.ts
|
|
2
|
+
const HOSTNAME_MISMATCH_CODES = /* @__PURE__ */ new Set(["ERR_TLS_CERT_ALTNAME_INVALID", "HOSTNAME_MISMATCH"]);
|
|
3
|
+
const CERTIFICATE_INVALID_CODES = /* @__PURE__ */ new Set([
|
|
4
|
+
"CERT_CHAIN_TOO_LONG",
|
|
5
|
+
"CERT_HAS_EXPIRED",
|
|
6
|
+
"CERT_NOT_YET_VALID",
|
|
7
|
+
"CERT_REJECTED",
|
|
8
|
+
"CERT_REVOKED",
|
|
9
|
+
"CERT_SIGNATURE_FAILURE",
|
|
10
|
+
"CERT_UNTRUSTED",
|
|
11
|
+
"CRL_HAS_EXPIRED",
|
|
12
|
+
"CRL_NOT_YET_VALID",
|
|
13
|
+
"CRL_SIGNATURE_FAILURE",
|
|
14
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
15
|
+
"ERROR_IN_CERT_NOT_AFTER_FIELD",
|
|
16
|
+
"ERROR_IN_CERT_NOT_BEFORE_FIELD",
|
|
17
|
+
"ERROR_IN_CRL_LAST_UPDATE_FIELD",
|
|
18
|
+
"ERROR_IN_CRL_NEXT_UPDATE_FIELD",
|
|
19
|
+
"INVALID_CA",
|
|
20
|
+
"INVALID_PURPOSE",
|
|
21
|
+
"PATH_LENGTH_EXCEEDED",
|
|
22
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
23
|
+
"UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY",
|
|
24
|
+
"UNABLE_TO_DECRYPT_CERT_SIGNATURE",
|
|
25
|
+
"UNABLE_TO_DECRYPT_CRL_SIGNATURE",
|
|
26
|
+
"UNABLE_TO_GET_CRL",
|
|
27
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
28
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
29
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE"
|
|
30
|
+
]);
|
|
31
|
+
const HOSTNAME_MISMATCH_PATTERNS = [
|
|
32
|
+
/hostname\/ip does not match certificate(?:'s)? altnames/i,
|
|
33
|
+
/hostname mismatch/i,
|
|
34
|
+
/host: .+ is not in the cert(?:ificate)?(?:'s)? altnames/i
|
|
35
|
+
];
|
|
36
|
+
const CERTIFICATE_INVALID_PATTERNS = [
|
|
37
|
+
/certificate has expired/i,
|
|
38
|
+
/certificate is not yet valid/i,
|
|
39
|
+
/self[- ]signed certificate/i,
|
|
40
|
+
/unable to get local issuer certificate/i,
|
|
41
|
+
/unable to verify the first certificate/i
|
|
42
|
+
];
|
|
43
|
+
const MAX_TLS_ERROR_DEPTH = 8;
|
|
44
|
+
function classifyCode(code) {
|
|
45
|
+
if (HOSTNAME_MISMATCH_CODES.has(code)) return "hostname_mismatch";
|
|
46
|
+
return CERTIFICATE_INVALID_CODES.has(code) ? "certificate_invalid" : null;
|
|
47
|
+
}
|
|
48
|
+
function classifyMessage(message) {
|
|
49
|
+
if (HOSTNAME_MISMATCH_PATTERNS.some((pattern) => pattern.test(message))) return "hostname_mismatch";
|
|
50
|
+
return CERTIFICATE_INVALID_PATTERNS.some((pattern) => pattern.test(message)) ? "certificate_invalid" : null;
|
|
51
|
+
}
|
|
52
|
+
function inspectTlsCertificateErrorInternal(error, seen, depth) {
|
|
53
|
+
if (depth > MAX_TLS_ERROR_DEPTH) return null;
|
|
54
|
+
if (typeof error === "string") {
|
|
55
|
+
const kind = classifyMessage(error);
|
|
56
|
+
return kind ? {
|
|
57
|
+
kind,
|
|
58
|
+
message: error
|
|
59
|
+
} : null;
|
|
60
|
+
}
|
|
61
|
+
if (!error || typeof error !== "object" || seen.has(error)) return null;
|
|
62
|
+
seen.add(error);
|
|
63
|
+
const candidate = error;
|
|
64
|
+
const code = typeof candidate.code === "string" ? candidate.code.trim().toUpperCase() : void 0;
|
|
65
|
+
const message = typeof candidate.message === "string" && candidate.message.trim() ? candidate.message : void 0;
|
|
66
|
+
const codeKind = code ? classifyCode(code) : null;
|
|
67
|
+
if (code && codeKind) return {
|
|
68
|
+
kind: codeKind,
|
|
69
|
+
code,
|
|
70
|
+
message: message ?? code
|
|
71
|
+
};
|
|
72
|
+
const nestedErrors = Array.isArray(candidate.errors) ? candidate.errors : [];
|
|
73
|
+
for (const nested of [
|
|
74
|
+
candidate.cause,
|
|
75
|
+
candidate.error,
|
|
76
|
+
...nestedErrors
|
|
77
|
+
]) {
|
|
78
|
+
if (nested === void 0 || nested === error) continue;
|
|
79
|
+
const details = inspectTlsCertificateErrorInternal(nested, seen, depth + 1);
|
|
80
|
+
if (details) return details;
|
|
81
|
+
}
|
|
82
|
+
const messageKind = message ? classifyMessage(message) : null;
|
|
83
|
+
return messageKind && message ? {
|
|
84
|
+
kind: messageKind,
|
|
85
|
+
message
|
|
86
|
+
} : null;
|
|
87
|
+
}
|
|
88
|
+
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
89
|
+
function inspectTlsCertificateError(error) {
|
|
90
|
+
return inspectTlsCertificateErrorInternal(error, /* @__PURE__ */ new Set(), 0);
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { inspectTlsCertificateError as t };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { g as isRecord, n as getAiTransportHost, p as normalizeLowercaseStringOrEmpty } from "./host-Dog2WQiR.mjs";
|
|
2
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
3
|
+
//#region packages/ai/src/utils/prompt-cache-stability.ts
|
|
4
|
+
/**
|
|
5
|
+
* Prompt-cache normalization helpers. They keep generated prompt sections
|
|
6
|
+
* deterministic across platform newlines, trailing whitespace, and input
|
|
7
|
+
* ordering.
|
|
8
|
+
*/
|
|
9
|
+
/** Canonicalizes provider tool order without relying on host locale settings. */
|
|
10
|
+
function sortPromptCacheToolsByName(tools) {
|
|
11
|
+
const compareText = (left, right) => {
|
|
12
|
+
const leftText = left ?? "";
|
|
13
|
+
const rightText = right ?? "";
|
|
14
|
+
return leftText < rightText ? -1 : leftText > rightText ? 1 : 0;
|
|
15
|
+
};
|
|
16
|
+
return tools.toSorted((left, right) => compareText(left.wireName ?? left.name, right.wireName ?? right.name) || compareText(left.description, right.description));
|
|
17
|
+
}
|
|
18
|
+
/** Normalize structured prompt text before hashing or snapshot comparison. */
|
|
19
|
+
function normalizeStructuredPromptSection(text) {
|
|
20
|
+
return sanitizeSurrogates(text).replace(/\r\n?/g, "\n").replace(/[ \t]+$/gm, "").trim();
|
|
21
|
+
}
|
|
22
|
+
/** Normalize, de-dupe, and sort capability ids for stable prompt payloads. */
|
|
23
|
+
function normalizePromptCapabilityIds(capabilities) {
|
|
24
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25
|
+
const normalized = [];
|
|
26
|
+
for (const capability of capabilities) {
|
|
27
|
+
const value = normalizeLowercaseStringOrEmpty(normalizeStructuredPromptSection(capability));
|
|
28
|
+
if (!value || seen.has(value)) continue;
|
|
29
|
+
seen.add(value);
|
|
30
|
+
normalized.push(value);
|
|
31
|
+
}
|
|
32
|
+
return normalized.toSorted((left, right) => left.localeCompare(right));
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region packages/ai/src/utils/system-prompt-cache-boundary.ts
|
|
36
|
+
/**
|
|
37
|
+
* System prompt cache-boundary helpers.
|
|
38
|
+
*
|
|
39
|
+
* Keeps stable prompt prefixes separate from dynamic runtime additions for provider prompt caching.
|
|
40
|
+
*/
|
|
41
|
+
const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
42
|
+
function stripSystemPromptCacheBoundary(text) {
|
|
43
|
+
return text.replaceAll(SYSTEM_PROMPT_CACHE_BOUNDARY, "\n");
|
|
44
|
+
}
|
|
45
|
+
function ensureSystemPromptCacheBoundary(systemPrompt) {
|
|
46
|
+
if (systemPrompt.trim().length === 0) return systemPrompt;
|
|
47
|
+
return systemPrompt.includes("\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n") ? systemPrompt : `${systemPrompt}${SYSTEM_PROMPT_CACHE_BOUNDARY}`;
|
|
48
|
+
}
|
|
49
|
+
function splitSystemPromptCacheBoundary(text) {
|
|
50
|
+
const boundaryIndex = text.indexOf(SYSTEM_PROMPT_CACHE_BOUNDARY);
|
|
51
|
+
if (boundaryIndex === -1) return;
|
|
52
|
+
return {
|
|
53
|
+
stablePrefix: text.slice(0, boundaryIndex).trimEnd(),
|
|
54
|
+
dynamicSuffix: text.slice(boundaryIndex + 34).trimStart()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function prependSystemPromptAdditionAfterCacheBoundary(params) {
|
|
58
|
+
const systemPromptAddition = typeof params.systemPromptAddition === "string" ? normalizeStructuredPromptSection(params.systemPromptAddition) : "";
|
|
59
|
+
if (!systemPromptAddition) return params.systemPrompt;
|
|
60
|
+
if (params.systemPrompt.trim().length === 0) return systemPromptAddition;
|
|
61
|
+
const split = splitSystemPromptCacheBoundary(params.systemPrompt);
|
|
62
|
+
if (!split) return `${systemPromptAddition}\n\n${params.systemPrompt}`;
|
|
63
|
+
const dynamicSuffix = split.dynamicSuffix ? normalizeStructuredPromptSection(split.dynamicSuffix) : "";
|
|
64
|
+
if (!dynamicSuffix) return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}`;
|
|
65
|
+
return `${split.stablePrefix}${SYSTEM_PROMPT_CACHE_BOUNDARY}${systemPromptAddition}\n\n${dynamicSuffix}`;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region packages/normalization-core/src/utf16-slice.ts
|
|
69
|
+
function isHighSurrogate(codeUnit) {
|
|
70
|
+
return codeUnit >= 55296 && codeUnit <= 56319;
|
|
71
|
+
}
|
|
72
|
+
function isLowSurrogate(codeUnit) {
|
|
73
|
+
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
74
|
+
}
|
|
75
|
+
/** Slices a UTF-16 string without returning dangling surrogate halves at either edge. */
|
|
76
|
+
function sliceUtf16Safe(input, start, end) {
|
|
77
|
+
const len = input.length;
|
|
78
|
+
let from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
79
|
+
let to = end === void 0 ? len : end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
|
|
80
|
+
if (to <= from) return "";
|
|
81
|
+
if (from > 0 && from < len) {
|
|
82
|
+
if (isLowSurrogate(input.charCodeAt(from)) && isHighSurrogate(input.charCodeAt(from - 1))) from += 1;
|
|
83
|
+
}
|
|
84
|
+
if (to > 0 && to < len) {
|
|
85
|
+
if (isHighSurrogate(input.charCodeAt(to - 1)) && isLowSurrogate(input.charCodeAt(to))) to -= 1;
|
|
86
|
+
}
|
|
87
|
+
return input.slice(from, to);
|
|
88
|
+
}
|
|
89
|
+
/** Truncates a UTF-16 string without cutting a surrogate pair in half. */
|
|
90
|
+
function truncateUtf16Safe(input, maxLen) {
|
|
91
|
+
const limit = Math.max(0, Math.floor(maxLen));
|
|
92
|
+
if (input.length <= limit) return input;
|
|
93
|
+
return sliceUtf16Safe(input, 0, limit);
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region packages/ai/src/providers/tool-result-text.ts
|
|
97
|
+
const PROVIDER_TOOL_RESULT_MAX_CHARS = 8e3;
|
|
98
|
+
const IMAGE_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([
|
|
99
|
+
"image",
|
|
100
|
+
"image_url",
|
|
101
|
+
"input_image"
|
|
102
|
+
]);
|
|
103
|
+
const AUDIO_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([
|
|
104
|
+
"audio",
|
|
105
|
+
"input_audio",
|
|
106
|
+
"output_audio"
|
|
107
|
+
]);
|
|
108
|
+
const MEDIA_ONLY_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set([...IMAGE_TOOL_RESULT_TYPES, ...AUDIO_TOOL_RESULT_TYPES]);
|
|
109
|
+
const INLINE_DATA_URI_PATTERN = /(^|[^A-Za-z0-9_])data:([a-z][a-z0-9.+-]*\/[a-z0-9.+-]+(?:;[a-z0-9.+-]+=[^,;"'\s]+|;base64)*,[^\s"'<>)]+)/gi;
|
|
110
|
+
const MIME_KEY_CANDIDATES = [
|
|
111
|
+
"mimeType",
|
|
112
|
+
"mime_type",
|
|
113
|
+
"mediaType",
|
|
114
|
+
"media_type",
|
|
115
|
+
"contentType",
|
|
116
|
+
"content_type"
|
|
117
|
+
];
|
|
118
|
+
const TEXTUAL_MIME_PATTERN = /^(?:text\/|application\/(?:json|ld\+json|x-ndjson|xml|javascript|x-www-form-urlencoded)|[^/]+\/[^+]+\+(?:json|xml)$)/i;
|
|
119
|
+
const OPAQUE_OR_BINARY_FIELD_RE = /^(?:blob|buffer|bytes|encrypted_content|encrypted_stdout)$/i;
|
|
120
|
+
function readMimeType(value) {
|
|
121
|
+
if (!isRecord(value)) return;
|
|
122
|
+
for (const key of MIME_KEY_CANDIDATES) {
|
|
123
|
+
const mimeType = value[key];
|
|
124
|
+
if (typeof mimeType === "string" && mimeType.trim().length > 0) return mimeType;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function isBinaryMimeType(mimeType) {
|
|
128
|
+
const normalized = mimeType.split(";", 1)[0]?.trim().toLowerCase();
|
|
129
|
+
return normalized ? !TEXTUAL_MIME_PATTERN.test(normalized) : false;
|
|
130
|
+
}
|
|
131
|
+
function describeOmittedValue(value, label) {
|
|
132
|
+
const length = typeof value === "string" ? value.length : JSON.stringify(value)?.length;
|
|
133
|
+
return length ? `[${label} omitted: ${length} chars]` : `[${label} omitted]`;
|
|
134
|
+
}
|
|
135
|
+
function redactInlineDataUris(value) {
|
|
136
|
+
return value.replace(INLINE_DATA_URI_PATTERN, (_match, prefix, uri) => `${prefix}[inline data URI: ${uri.length} chars]`);
|
|
137
|
+
}
|
|
138
|
+
function redactStructuredTextValue(value) {
|
|
139
|
+
const host = getAiTransportHost();
|
|
140
|
+
const redacted = host.redactToolPayloadText(value);
|
|
141
|
+
const trimmed = redacted.trim();
|
|
142
|
+
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return redacted;
|
|
143
|
+
try {
|
|
144
|
+
const redactedWrapper = host.redactSecrets({ structuredTextValue: JSON.parse(redacted) });
|
|
145
|
+
return JSON.stringify(redactedWrapper.structuredTextValue);
|
|
146
|
+
} catch {
|
|
147
|
+
return redacted;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function stringifyStructuredBlock(block) {
|
|
151
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
152
|
+
try {
|
|
153
|
+
const redactedBlock = getAiTransportHost().redactSecrets({ structuredToolResult: block }).structuredToolResult;
|
|
154
|
+
const serialized = JSON.stringify(redactedBlock, function structuredToolResultReplacer(key, value) {
|
|
155
|
+
if (OPAQUE_OR_BINARY_FIELD_RE.test(key)) return `[omitted ${key}]`;
|
|
156
|
+
if (key === "data") {
|
|
157
|
+
const mimeType = readMimeType(this);
|
|
158
|
+
if (mimeType && isBinaryMimeType(mimeType)) return describeOmittedValue(value, "binary data");
|
|
159
|
+
}
|
|
160
|
+
if (typeof value === "bigint") return value.toString();
|
|
161
|
+
if (typeof value === "string") return redactInlineDataUris(redactStructuredTextValue(value));
|
|
162
|
+
if (typeof value === "function" || typeof value === "symbol" || value === void 0) return;
|
|
163
|
+
if (!value || typeof value !== "object") return value;
|
|
164
|
+
if (seen.has(value)) return "[Circular]";
|
|
165
|
+
seen.add(value);
|
|
166
|
+
return value;
|
|
167
|
+
});
|
|
168
|
+
if (!serialized || serialized === "{}") return;
|
|
169
|
+
return serialized;
|
|
170
|
+
} catch {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function truncateProviderToolText(text) {
|
|
175
|
+
if (text.length <= PROVIDER_TOOL_RESULT_MAX_CHARS) return text;
|
|
176
|
+
return `${truncateUtf16Safe(text, PROVIDER_TOOL_RESULT_MAX_CHARS)}\n…(truncated)…`;
|
|
177
|
+
}
|
|
178
|
+
/** Media metadata alone is not an attachment; provider emitters need inline bytes. */
|
|
179
|
+
function hasMediaPayload(block) {
|
|
180
|
+
return isRecord(block) && typeof block.data === "string" && block.data.trim().length > 0;
|
|
181
|
+
}
|
|
182
|
+
/** Image metadata alone is not an attachment; provider emitters need inline bytes. */
|
|
183
|
+
function isImageWithMediaPayload(block) {
|
|
184
|
+
return isRecord(block) && block.type === "image" && hasMediaPayload(block);
|
|
185
|
+
}
|
|
186
|
+
function describeToolResultMediaPlaceholder(blocks) {
|
|
187
|
+
let hasImage = false;
|
|
188
|
+
let hasAudio = false;
|
|
189
|
+
for (const block of blocks) {
|
|
190
|
+
if (!hasMediaPayload(block)) continue;
|
|
191
|
+
const record = block;
|
|
192
|
+
const type = typeof record.type === "string" ? record.type : void 0;
|
|
193
|
+
const mimeType = readMimeType(record);
|
|
194
|
+
if (type && IMAGE_TOOL_RESULT_TYPES.has(type) || mimeType?.toLowerCase().startsWith("image/")) hasImage = true;
|
|
195
|
+
if (type && AUDIO_TOOL_RESULT_TYPES.has(type) || mimeType?.toLowerCase().startsWith("audio/")) hasAudio = true;
|
|
196
|
+
}
|
|
197
|
+
if (hasImage && hasAudio) return "(see attached media)";
|
|
198
|
+
if (hasAudio) return "(see attached audio)";
|
|
199
|
+
if (hasImage) return "(see attached image)";
|
|
200
|
+
}
|
|
201
|
+
function extractToolResultBlockText(block) {
|
|
202
|
+
if (!block || typeof block !== "object") return;
|
|
203
|
+
const record = block;
|
|
204
|
+
if (typeof record.type === "string" && MEDIA_ONLY_TOOL_RESULT_TYPES.has(record.type)) return;
|
|
205
|
+
if (record.type === "text") {
|
|
206
|
+
const text = typeof record.text === "string" ? record.text : "";
|
|
207
|
+
return text ? sanitizeSurrogates(text) : void 0;
|
|
208
|
+
}
|
|
209
|
+
const structured = stringifyStructuredBlock(record);
|
|
210
|
+
return structured ? sanitizeSurrogates(truncateProviderToolText(structured)) : void 0;
|
|
211
|
+
}
|
|
212
|
+
function extractToolResultText(blocks) {
|
|
213
|
+
const explicitTexts = [];
|
|
214
|
+
const structuredTexts = [];
|
|
215
|
+
for (const block of blocks) {
|
|
216
|
+
const text = extractToolResultBlockText(block);
|
|
217
|
+
if (!text) continue;
|
|
218
|
+
if (block.type === "text") explicitTexts.push(text);
|
|
219
|
+
else structuredTexts.push(text);
|
|
220
|
+
}
|
|
221
|
+
if (explicitTexts.length > 0) return sanitizeSurrogates(explicitTexts.join("\n"));
|
|
222
|
+
return sanitizeSurrogates(truncateProviderToolText(structuredTexts.join("\n")));
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
export { isImageWithMediaPayload as a, ensureSystemPromptCacheBoundary as c, stripSystemPromptCacheBoundary as d, normalizePromptCapabilityIds as f, hasMediaPayload as i, prependSystemPromptAdditionAfterCacheBoundary as l, sortPromptCacheToolsByName as m, extractToolResultBlockText as n, truncateUtf16Safe as o, normalizeStructuredPromptSection as p, extractToolResultText as r, SYSTEM_PROMPT_CACHE_BOUNDARY as s, describeToolResultMediaPlaceholder as t, splitSystemPromptCacheBoundary as u };
|
package/dist/{github-copilot-headers-BCoBNmL7.mjs → tool-schema-json-projection-BwNu3nDi.mjs}
RENAMED
|
@@ -91,51 +91,4 @@ function projectRuntimeToolInputSchema(schema, path = "parameters") {
|
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
//#endregion
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Resolve cache retention preference.
|
|
97
|
-
* Defaults to "short" and uses OPENCLAW_CACHE_RETENTION for backward compatibility.
|
|
98
|
-
*/
|
|
99
|
-
function resolveCacheRetention(cacheRetention) {
|
|
100
|
-
if (cacheRetention) return cacheRetention;
|
|
101
|
-
if (typeof process !== "undefined" && process.env.OPENCLAW_CACHE_RETENTION === "long") return "long";
|
|
102
|
-
return "short";
|
|
103
|
-
}
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region packages/ai/src/providers/cloudflare.ts
|
|
106
|
-
function isCloudflareProvider(provider) {
|
|
107
|
-
return provider === "cloudflare-workers-ai" || provider === "cloudflare-ai-gateway";
|
|
108
|
-
}
|
|
109
|
-
/** Substitute `{VAR}` placeholders in a Cloudflare baseUrl from process.env. */
|
|
110
|
-
function resolveCloudflareBaseUrl(model) {
|
|
111
|
-
const url = model.baseUrl;
|
|
112
|
-
if (!url.includes("{")) return url;
|
|
113
|
-
return url.replace(/\{([A-Z_][A-Z0-9_]*)\}/g, (_match, name) => {
|
|
114
|
-
const value = process.env[name];
|
|
115
|
-
if (!value) throw new Error(`${name} is required for provider ${model.provider} but is not set.`);
|
|
116
|
-
return value;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region packages/ai/src/providers/github-copilot-headers.ts
|
|
121
|
-
function inferCopilotInitiator(messages) {
|
|
122
|
-
const last = messages[messages.length - 1];
|
|
123
|
-
return last && last.role !== "user" ? "agent" : "user";
|
|
124
|
-
}
|
|
125
|
-
function hasCopilotVisionInput(messages) {
|
|
126
|
-
return messages.some((msg) => {
|
|
127
|
-
if (msg.role === "user" && Array.isArray(msg.content)) return msg.content.some((c) => c.type === "image");
|
|
128
|
-
if (msg.role === "toolResult" && Array.isArray(msg.content)) return msg.content.some((c) => c.type === "image");
|
|
129
|
-
return false;
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function buildCopilotDynamicHeaders(params) {
|
|
133
|
-
const headers = {
|
|
134
|
-
"X-Initiator": inferCopilotInitiator(params.messages),
|
|
135
|
-
"Openai-Intent": "conversation-edits"
|
|
136
|
-
};
|
|
137
|
-
if (params.hasImages) headers["Copilot-Vision-Request"] = "true";
|
|
138
|
-
return headers;
|
|
139
|
-
}
|
|
140
|
-
//#endregion
|
|
141
|
-
export { resolveCacheRetention as a, resolveCloudflareBaseUrl as i, hasCopilotVisionInput as n, projectRuntimeToolInputSchema as o, isCloudflareProvider as r, buildCopilotDynamicHeaders as t };
|
|
94
|
+
export { projectRuntimeToolInputSchema as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as createAssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
2
|
-
import { n as getAiTransportHost } from "./host-
|
|
3
|
-
import { D as truncateUtf16Safe, b as normalizeOptionalString } from "./shared-CdjNZd35.mjs";
|
|
2
|
+
import { m as normalizeOptionalString, n as getAiTransportHost } from "./host-Dog2WQiR.mjs";
|
|
4
3
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
4
|
+
import { o as truncateUtf16Safe } from "./tool-result-text-CTpIRbYd.mjs";
|
|
5
5
|
import { i as parseStrictNonNegativeInteger, r as parseStrictFiniteNumber, t as asFiniteNumberInRange } from "./number-coercion-DvG7SNMg.mjs";
|
|
6
6
|
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
@@ -54,8 +54,8 @@ function estimateStringChars(text) {
|
|
|
54
54
|
function supportsModelTools(model) {
|
|
55
55
|
return (model.compat && typeof model.compat === "object" ? model.compat : void 0)?.supportsTools !== false;
|
|
56
56
|
}
|
|
57
|
-
function isCodeModeModelVisibleToolName(name) {
|
|
58
|
-
return name
|
|
57
|
+
function isCodeModeModelVisibleToolName(name, visibleToolNames) {
|
|
58
|
+
return visibleToolNames.has(name);
|
|
59
59
|
}
|
|
60
60
|
function isGoogleGemini3Model(modelId, family) {
|
|
61
61
|
const normalized = modelId.trim().toLowerCase();
|
package/dist/transports.d.mts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { E as Model, L as StreamFn, O as OpenAICompletionsCompat, X as Usage, a as AssistantMessageEvent, i as AssistantMessage, n as Api, u as Context } from "./types-bzp5k29J.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-YjaPW20U.mjs";
|
|
3
3
|
import { n as ApiRegistry } from "./api-registry-DlMgPR39.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { a as OpenAICompletionsOptions, d as OpenAIApiReasoningEffort, f as OpenAIReasoningEffort, i as BaseOpenAIStreamOptions, s as OpenAIToolProjection } from "./provider-options-D8bB3z9b.mjs";
|
|
5
|
+
import { n as detectOpenAICompletionsCompat, r as resolveOpenAICompletionsCompat, t as ResolvedOpenAICompletionsCompat } from "./openai-completions-compat-DBWjXoMZ.mjs";
|
|
5
6
|
import { n as FirstStreamEventInternalOptions } from "./stream-first-event-timeout-DvDeSucC.mjs";
|
|
6
7
|
import { r as sortPromptCacheToolsByName } from "./prompt-cache-stability-Cwcjv_fx.mjs";
|
|
7
8
|
import OpenAI from "openai";
|
|
8
|
-
import { ChatCompletionChunk } from "openai/resources/chat/completions.js";
|
|
9
9
|
import { FunctionTool, ResponseCreateParamsStreaming, ResponseInput, ResponseReasoningItem } from "openai/resources/responses/responses.js";
|
|
10
|
+
import { ChatCompletionChunk } from "openai/resources/chat/completions.js";
|
|
10
11
|
|
|
11
12
|
//#region packages/ai/src/transports/anthropic-payload-policy.d.ts
|
|
12
13
|
/** @deprecated Anthropic-family provider payload helper; do not use from third-party plugins. */
|
|
@@ -125,32 +126,6 @@ declare const log: {
|
|
|
125
126
|
info(message: string, data?: Record<string, unknown>): void;
|
|
126
127
|
warn(message: string, data?: Record<string, unknown>): void;
|
|
127
128
|
};
|
|
128
|
-
type BaseOpenAIStreamOptions = {
|
|
129
|
-
temperature?: number;
|
|
130
|
-
topP?: number;
|
|
131
|
-
maxTokens?: number;
|
|
132
|
-
stop?: string[];
|
|
133
|
-
signal?: AbortSignal;
|
|
134
|
-
apiKey?: string;
|
|
135
|
-
cacheRetention?: "none" | "short" | "long";
|
|
136
|
-
sessionId?: string;
|
|
137
|
-
promptCacheKey?: string;
|
|
138
|
-
authProfileId?: string;
|
|
139
|
-
onPayload?: (payload: unknown, model: Model) => unknown;
|
|
140
|
-
headers?: Record<string, string>;
|
|
141
|
-
firstEventTimeoutMs?: number;
|
|
142
|
-
onFirstEventTimeout?: (reason: Error) => void;
|
|
143
|
-
openclawCodeModeToolSurface?: boolean;
|
|
144
|
-
responseFormat?: Record<string, unknown>;
|
|
145
|
-
frequencyPenalty?: number;
|
|
146
|
-
presencePenalty?: number;
|
|
147
|
-
seed?: number;
|
|
148
|
-
};
|
|
149
|
-
type OpenAICompletionsOptions = BaseOpenAIStreamOptions & {
|
|
150
|
-
toolChoice?: OpenAICompletionsToolChoice;
|
|
151
|
-
reasoning?: OpenAIReasoningEffort;
|
|
152
|
-
reasoningEffort?: OpenAIReasoningEffort;
|
|
153
|
-
};
|
|
154
129
|
type OpenAIModeCompatInput = Omit<OpenAICompletionsCompat, "thinkingFormat"> & {
|
|
155
130
|
thinkingFormat?: string;
|
|
156
131
|
requiresStringContent?: boolean;
|
|
@@ -190,12 +165,14 @@ type ModelStreamCooperativeScheduler = {
|
|
|
190
165
|
};
|
|
191
166
|
declare function throwIfModelStreamAborted(signal?: AbortSignal): void;
|
|
192
167
|
declare function createModelStreamCooperativeScheduler(signal?: AbortSignal): ModelStreamCooperativeScheduler;
|
|
193
|
-
declare function resolveCacheRetention(cacheRetention: string | undefined): "short" | "long" | "none";
|
|
194
168
|
declare function resolvePromptCacheKey(options: Pick<BaseOpenAIStreamOptions, "promptCacheKey" | "sessionId"> | undefined, cacheRetention: "short" | "long" | "none"): string | undefined;
|
|
195
169
|
//#endregion
|
|
196
170
|
//#region packages/ai/src/transports/openai-transport-params.d.ts
|
|
197
|
-
declare function
|
|
198
|
-
declare function
|
|
171
|
+
declare function readCodeModePayloadToolName(tool: unknown): string | undefined;
|
|
172
|
+
declare function filterCodeModePayloadTools(payload: unknown, visibleToolNames: ReadonlySet<string>): void;
|
|
173
|
+
declare function resolveCodeModeResponsesVisibleToolNames(context: Pick<Context, "tools">): ReadonlySet<string>;
|
|
174
|
+
declare function enforceCodeModeResponsesToolSurface(payload: unknown, visibleToolNames: ReadonlySet<string>): void;
|
|
175
|
+
declare function assertCodeModeResponsesToolSurface(payload: unknown, visibleToolNames: ReadonlySet<string>): void;
|
|
199
176
|
declare function resolveOpenAIStrictToolFlagWithDiagnostics(projection: OpenAIToolProjection, strictSetting: boolean | null | undefined, context: {
|
|
200
177
|
transport: "responses" | "completions";
|
|
201
178
|
model: OpenAIModeModel;
|
|
@@ -208,9 +185,12 @@ declare function buildOpenAISdkClientOptions(model: Model): {
|
|
|
208
185
|
};
|
|
209
186
|
declare function buildOpenAISdkRequestOptions(model: Model, signal?: AbortSignal, options?: {
|
|
210
187
|
stream?: boolean;
|
|
188
|
+
timeoutMs?: number;
|
|
189
|
+
maxRetries?: number;
|
|
211
190
|
}): {
|
|
212
191
|
signal?: AbortSignal;
|
|
213
192
|
timeout?: number;
|
|
193
|
+
maxRetries?: number;
|
|
214
194
|
headers?: Record<string, string>;
|
|
215
195
|
} | undefined;
|
|
216
196
|
declare function getCompat(model: OpenAIModeModel): {
|
|
@@ -588,6 +568,6 @@ declare function failTransportStream(params: {
|
|
|
588
568
|
}): void;
|
|
589
569
|
//#endregion
|
|
590
570
|
//#region packages/ai/src/transports/transport-utils.d.ts
|
|
591
|
-
declare function isCodeModeModelVisibleToolName(name: string): boolean;
|
|
571
|
+
declare function isCodeModeModelVisibleToolName(name: string, visibleToolNames: ReadonlySet<string>): boolean;
|
|
592
572
|
//#endregion
|
|
593
|
-
export {
|
|
573
|
+
export { GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, MutableAssistantOutput, type OpenAICompletionsOptions, OpenAIModeModel, ResolvedOpenAICompletionsCompat, WritableTransportStream, applyAnthropicEphemeralCacheControlMarkers, applyAnthropicPayloadPolicyToParams, applyOpenAIResponsesPayloadPolicy, assertCodeModeResponsesToolSurface, assignTransportErrorDetails, buildOpenAIClientHeaders, buildOpenAICompletionsParams, buildOpenAISdkClientOptions, buildOpenAISdkRequestOptions, buildTransportAwareSimpleStreamFn, canonicalizeMaxTokensParam, coerceTransportToolCallArguments, createAnthropicMessagesTransportStreamFn, createAzureOpenAIResponsesTransportStreamFn, createBoundaryAwareStreamFnForModel, createDeepSeekTextFilter, createEmptyTransportUsage, createModelStreamCooperativeScheduler, createOpenAICompletionsTransportStreamFn, createOpenAIResponsesTransportStreamFn, createOpenClawTransportStreamFnForModel, createTransportAwareStreamFnForModel, createWritableTransportEventStream, detectOpenAICompletionsCompat, emitModelTransportDebug, enforceCodeModeResponsesToolSurface, failTransportStream, filterCodeModePayloadTools, finalizeTransportStream, flattenCompletionMessagesToStringContent, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, getCompat, hasOpenAICompatibleConversationTurn, isCodeModeModelVisibleToolName, isOpenAICodexResponsesModel, log, mergeTransportHeaders, mergeTransportMetadata, normalizeCodexResponsesBaseUrlForOpenAISdk, parseJsonObjectPreservingUnsafeIntegers, parseJsonPreservingUnsafeIntegers, prepareModelForSimpleCompletion, prepareTransportAwareSimpleModel, quoteUnsafeIntegerLiterals, readCodeModePayloadToolName, resolveAnthropicEphemeralCacheControl, resolveAnthropicMessagesUrl, resolveAnthropicPayloadPolicy, resolveCodeModeResponsesVisibleToolNames, resolveMaxTokensParam, resolveModelPayloadDebugMode, resolveModelSseDebugMode, resolveOpenAICompletionsCompat, resolveOpenAIReasoningEffortMap, resolveOpenAIResponsesPayloadPolicy, resolveOpenAIStrictToolFlagWithDiagnostics, resolvePromptCacheKey, resolveReplayableResponsesMessageId, resolveTransportAwareSimpleApi, sanitizeNonEmptyTransportPayloadText, sanitizeResponsesImagePayload, sanitizeTransportPayloadText, sortPromptCacheToolsByName as sortTransportToolsByName, stripCompletionMessagesToRoleContent, throwIfModelStreamAborted, transportAbortError, usesNativeOpenAICodexResponsesBackend };
|