@openclaw/ai 2026.7.2-beta.7 → 2026.8.1-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/dist/{anthropic-CH4UUnZr.mjs → anthropic-B6dLpq5L.mjs} +55 -203
- package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
- package/dist/anthropic-compaction-replay-8lJNKXOE.mjs +840 -0
- package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-BP6AWT8j.d.mts} +4 -1
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-uSMZJ3FA.mjs} +26 -5
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CtSg0iTS.mjs → google-C7h2QzDX.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-B0Qr9OR7.mjs} +146 -89
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-Bhc3TjDl.mjs} +11 -7
- package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
- package/dist/host-DTqNc7ad.mjs +466 -0
- package/dist/{host-B9GUmcra.d.mts → host-vWgMMhiJ.d.mts} +9 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +29 -5
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
- package/dist/internal/openai-responses-payload-policy.mjs +3 -0
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +8 -7
- package/dist/internal/runtime.d.mts +17 -5
- package/dist/internal/runtime.mjs +85 -73
- package/dist/internal/shared.d.mts +1 -6
- package/dist/internal/shared.mjs +3 -5
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-CWmpvWYh.mjs → mistral-CEWoQI_g.mjs} +45 -48
- package/dist/number-coercion-H9qHik3g.mjs +71 -0
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +284 -240
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-BPnt4Sml.mjs} +65 -99
- package/dist/{openai-completions-compat-DBWjXoMZ.d.mts → openai-completions-compat-Dt3dcawL.d.mts} +2 -2
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-DhIKtOup.mjs} +18 -41
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
- package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
- package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
- package/dist/openai-responses-prompt-observer-internal-DgNTYnRY.mjs +46 -0
- package/dist/{openai-responses-stream-internal-Cw5txaGW.mjs → openai-responses-shared-DXIt3iY5.mjs} +1406 -940
- package/dist/{openai-reasoning-compat-YgeLncHw.mjs → openai-stop-reason-BkFkqqK0.mjs} +204 -37
- package/dist/openai-tool-projection-CY04OcvQ.mjs +338 -0
- package/dist/provider-error-BUwEnjXq.mjs +429 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/{provider-options-D8bB3z9b.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -0
- package/dist/provider-types.d.mts +31 -0
- package/dist/provider-types.mjs +8 -0
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +17 -19
- package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-rnPwX2pg.mjs} +14 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/sanitize-unicode-BYqrYtC_.mjs +90 -0
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-D58D5Kvw.mjs +117 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +32 -7
- package/dist/transport-utils-DJqkxbhC.mjs +138 -0
- package/dist/transports.d.mts +166 -241
- package/dist/transports.mjs +1979 -1825
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-bzp5k29J.d.mts → types-BHNrPS1l.d.mts} +23 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.mjs +6 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
- package/dist/{validation-B-j7cOYp.d.mts → validation-DT9SrFn3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/anthropic-usage-DWU-x8MI.mjs +0 -459
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/host-Dog2WQiR.mjs +0 -369
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +0 -392
- package/dist/openai-tool-projection-OhX64DoP.mjs +0 -215
- package/dist/provider-error-CAEvRjry.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- package/dist/tool-result-text-CTpIRbYd.mjs +0 -225
- package/dist/transform-messages-C8mBqZxF.mjs +0 -2
- package/dist/transport-stream-shared-D81p90xq.mjs +0 -297
package/dist/host-Dog2WQiR.mjs
DELETED
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, i as requiresClaudeDefaultSampling, o as resolveClaudeFable5ModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "./src-QkygScBs.mjs";
|
|
2
|
-
//#region packages/normalization-core/src/record-coerce.ts
|
|
3
|
-
/** Type guard for non-array object records at browser-safe boundaries. */
|
|
4
|
-
function isRecord(value) {
|
|
5
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region packages/normalization-core/src/string-coerce.ts
|
|
9
|
-
/** Reads a value only when it is already a string, preserving whitespace. */
|
|
10
|
-
function readStringValue(value) {
|
|
11
|
-
return typeof value === "string" ? value : void 0;
|
|
12
|
-
}
|
|
13
|
-
/** Trims string input and returns null for non-strings or empty strings. */
|
|
14
|
-
function normalizeNullableString(value) {
|
|
15
|
-
if (typeof value !== "string") return null;
|
|
16
|
-
const trimmed = value.trim();
|
|
17
|
-
return trimmed ? trimmed : null;
|
|
18
|
-
}
|
|
19
|
-
/** Trims string input and returns undefined for non-strings or empty strings. */
|
|
20
|
-
function normalizeOptionalString(value) {
|
|
21
|
-
return normalizeNullableString(value) ?? void 0;
|
|
22
|
-
}
|
|
23
|
-
/** Lowercases a normalized optional string. */
|
|
24
|
-
function normalizeOptionalLowercaseString(value) {
|
|
25
|
-
return normalizeOptionalString(value)?.toLowerCase();
|
|
26
|
-
}
|
|
27
|
-
/** Lowercases a normalized string or returns an empty string when absent. */
|
|
28
|
-
function normalizeLowercaseStringOrEmpty(value) {
|
|
29
|
-
return normalizeOptionalLowercaseString(value) ?? "";
|
|
30
|
-
}
|
|
31
|
-
/** Type guard for strings that remain non-empty after trimming. */
|
|
32
|
-
function hasNonEmptyString(value) {
|
|
33
|
-
return normalizeOptionalString(value) !== void 0;
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region packages/ai/src/providers/anthropic-model-contract.ts
|
|
37
|
-
function normalizeModelId(modelId) {
|
|
38
|
-
const normalized = normalizeLowercaseStringOrEmpty(modelId);
|
|
39
|
-
return (normalized.startsWith("anthropic/") ? normalized.slice(10) : normalized).replace(/[._\s]+/g, "-");
|
|
40
|
-
}
|
|
41
|
-
function normalizeApi(api) {
|
|
42
|
-
const normalized = normalizeLowercaseStringOrEmpty(api);
|
|
43
|
-
return normalized === "openclaw-anthropic-messages-transport" ? "anthropic-messages" : normalized;
|
|
44
|
-
}
|
|
45
|
-
function hasConcreteResponseModel(ref) {
|
|
46
|
-
const responseModelId = normalizeModelId(ref.responseModelId);
|
|
47
|
-
return responseModelId.length > 0 && responseModelId !== normalizeModelId(ref.modelId);
|
|
48
|
-
}
|
|
49
|
-
function usesClaudeFable5MessagesContract(model) {
|
|
50
|
-
return normalizeApi(model.api) === "anthropic-messages" && resolveClaudeFable5ModelIdentity(model) !== void 0;
|
|
51
|
-
}
|
|
52
|
-
/** Return whether streamed output must wait for the terminal refusal decision. */
|
|
53
|
-
function usesClaudeStreamingRefusalContract(model) {
|
|
54
|
-
if (normalizeApi(model.api) !== "anthropic-messages") return false;
|
|
55
|
-
return resolveClaudeFable5ModelIdentity(model) !== void 0 || resolveClaudeMythos5ModelIdentity(model) !== void 0 || resolveClaudeOpus5ModelIdentity(model) !== void 0 || resolveClaudeSonnet5ModelIdentity(model) !== void 0;
|
|
56
|
-
}
|
|
57
|
-
function requiresClaudeAdaptiveThinking(model) {
|
|
58
|
-
if (normalizeApi(model.api) !== "anthropic-messages") return false;
|
|
59
|
-
return requiresClaudeMandatoryAdaptiveThinking(model);
|
|
60
|
-
}
|
|
61
|
-
/** Return whether omitted thinking should default to adaptive/high. */
|
|
62
|
-
function defaultsClaudeAdaptiveThinking(model) {
|
|
63
|
-
return requiresClaudeAdaptiveThinking(model) || normalizeApi(model.api) === "anthropic-messages" && (resolveClaudeOpus5ModelIdentity(model) !== void 0 || resolveClaudeSonnet5ModelIdentity(model) !== void 0);
|
|
64
|
-
}
|
|
65
|
-
/** Remove unsupported assistant prefills while preserving completed tool-use turns. */
|
|
66
|
-
function prepareClaudeNoPrefillRequestContext(model, context) {
|
|
67
|
-
if (!resolveClaudeOpus5ModelIdentity(model) && !resolveClaudeSonnet5ModelIdentity(model)) return context;
|
|
68
|
-
let end = context.messages.length;
|
|
69
|
-
while (end > 0) {
|
|
70
|
-
const message = context.messages[end - 1];
|
|
71
|
-
if (message?.role !== "assistant" || Array.isArray(message.content) && message.content.some((block) => block.type === "toolCall")) break;
|
|
72
|
-
end -= 1;
|
|
73
|
-
}
|
|
74
|
-
return end === context.messages.length ? context : {
|
|
75
|
-
...context,
|
|
76
|
-
messages: context.messages.slice(0, end)
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function applyClaudeRequestContract(params, model) {
|
|
80
|
-
if (normalizeApi(model.api) !== "anthropic-messages") return;
|
|
81
|
-
const opus5 = resolveClaudeOpus5ModelIdentity(model) !== void 0;
|
|
82
|
-
const sonnet5 = resolveClaudeSonnet5ModelIdentity(model) !== void 0;
|
|
83
|
-
if (!requiresClaudeDefaultSampling(model) && !opus5 && !sonnet5) return;
|
|
84
|
-
delete params.temperature;
|
|
85
|
-
delete params.top_p;
|
|
86
|
-
delete params.top_k;
|
|
87
|
-
if (opus5 || sonnet5) delete params.service_tier;
|
|
88
|
-
}
|
|
89
|
-
function resolveReplayModelBoundIdentity(ref) {
|
|
90
|
-
if (normalizeApi(ref.api) !== "anthropic-messages") return;
|
|
91
|
-
const modelRef = hasConcreteResponseModel(ref) ? { id: ref.responseModelId } : {
|
|
92
|
-
id: ref.modelId,
|
|
93
|
-
params: ref.modelParams
|
|
94
|
-
};
|
|
95
|
-
const fableIdentity = resolveClaudeFable5ModelIdentity(modelRef);
|
|
96
|
-
if (fableIdentity) return `fable:${fableIdentity}`;
|
|
97
|
-
const mythosIdentity = resolveClaudeMythos5ModelIdentity(modelRef);
|
|
98
|
-
if (mythosIdentity) return `mythos:${mythosIdentity}`;
|
|
99
|
-
const opusIdentity = resolveClaudeOpus5ModelIdentity(modelRef);
|
|
100
|
-
if (opusIdentity) return `opus:${opusIdentity}`;
|
|
101
|
-
const sonnetIdentity = resolveClaudeSonnet5ModelIdentity(modelRef);
|
|
102
|
-
return sonnetIdentity ? `sonnet:${sonnetIdentity}` : void 0;
|
|
103
|
-
}
|
|
104
|
-
function resolveModelBoundThinkingReplayMode(params) {
|
|
105
|
-
const sourceApi = normalizeApi(params.source.api);
|
|
106
|
-
const targetApi = normalizeApi(params.target.api);
|
|
107
|
-
const sourceIdentity = resolveReplayModelBoundIdentity(params.source);
|
|
108
|
-
const targetIdentity = resolveReplayModelBoundIdentity(params.target);
|
|
109
|
-
const sameRoute = normalizeLowercaseStringOrEmpty(params.source.provider) === normalizeLowercaseStringOrEmpty(params.target.provider) && sourceApi === targetApi && normalizeModelId(params.source.modelId) === normalizeModelId(params.target.modelId);
|
|
110
|
-
if (!sourceIdentity && !targetIdentity) return "default";
|
|
111
|
-
if (!sourceIdentity && !hasConcreteResponseModel(params.source) && targetIdentity && sameRoute) return "preserve";
|
|
112
|
-
return sourceApi === targetApi && sourceIdentity === targetIdentity ? "preserve" : "drop";
|
|
113
|
-
}
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region packages/ai/src/transcript-transform.ts
|
|
116
|
-
const NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
|
|
117
|
-
const NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
|
|
118
|
-
function isImageWithMediaPayload(block) {
|
|
119
|
-
return isRecord(block) && block.type === "image" && typeof block.data === "string" && block.data.trim().length > 0;
|
|
120
|
-
}
|
|
121
|
-
function replaceImagesWithPlaceholder(content, placeholder) {
|
|
122
|
-
const result = [];
|
|
123
|
-
let previousWasPlaceholder = false;
|
|
124
|
-
for (const block of content) {
|
|
125
|
-
if (block.type === "image") {
|
|
126
|
-
if (!isImageWithMediaPayload(block)) continue;
|
|
127
|
-
if (!previousWasPlaceholder) result.push({
|
|
128
|
-
type: "text",
|
|
129
|
-
text: placeholder
|
|
130
|
-
});
|
|
131
|
-
previousWasPlaceholder = true;
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
result.push(block);
|
|
135
|
-
previousWasPlaceholder = block.text === placeholder;
|
|
136
|
-
}
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
function downgradeUnsupportedImages(messages, model) {
|
|
140
|
-
if (model.input.includes("image")) return messages;
|
|
141
|
-
return messages.map((msg) => {
|
|
142
|
-
if (msg.role === "user" && Array.isArray(msg.content)) return {
|
|
143
|
-
...msg,
|
|
144
|
-
content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER)
|
|
145
|
-
};
|
|
146
|
-
if (msg.role === "toolResult") return {
|
|
147
|
-
...msg,
|
|
148
|
-
content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER)
|
|
149
|
-
};
|
|
150
|
-
return msg;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Normalize tool call ID for cross-provider compatibility.
|
|
155
|
-
* OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.
|
|
156
|
-
* Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).
|
|
157
|
-
*/
|
|
158
|
-
function transformMessages(messages, model, normalizeToolCallId) {
|
|
159
|
-
const toolCallIdMap = /* @__PURE__ */ new Map();
|
|
160
|
-
const transformed = downgradeUnsupportedImages(messages.map((msg) => msg.content == null ? {
|
|
161
|
-
...msg,
|
|
162
|
-
content: []
|
|
163
|
-
} : msg), model).map((msg) => {
|
|
164
|
-
if (msg.role === "user") return msg;
|
|
165
|
-
if (msg.role === "toolResult") {
|
|
166
|
-
const normalizedId = toolCallIdMap.get(msg.toolCallId);
|
|
167
|
-
if (normalizedId && normalizedId !== msg.toolCallId) return Object.assign({}, msg, { toolCallId: normalizedId });
|
|
168
|
-
return msg;
|
|
169
|
-
}
|
|
170
|
-
if (msg.role === "assistant") {
|
|
171
|
-
const assistantMsg = msg;
|
|
172
|
-
const modelBoundThinkingReplayMode = resolveModelBoundThinkingReplayMode({
|
|
173
|
-
source: {
|
|
174
|
-
provider: assistantMsg.provider,
|
|
175
|
-
api: assistantMsg.api,
|
|
176
|
-
modelId: assistantMsg.model,
|
|
177
|
-
responseModelId: assistantMsg.responseModel
|
|
178
|
-
},
|
|
179
|
-
target: {
|
|
180
|
-
provider: model.provider,
|
|
181
|
-
api: model.api,
|
|
182
|
-
modelId: model.id,
|
|
183
|
-
modelParams: model.params
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
const isSameModel = modelBoundThinkingReplayMode === "preserve" || assistantMsg.provider === model.provider && assistantMsg.api === model.api && assistantMsg.model === model.id;
|
|
187
|
-
const transformedContent = (typeof assistantMsg.content === "string" ? [{
|
|
188
|
-
type: "text",
|
|
189
|
-
text: assistantMsg.content
|
|
190
|
-
}] : assistantMsg.content).flatMap((block) => {
|
|
191
|
-
if (block.type === "thinking") {
|
|
192
|
-
if (modelBoundThinkingReplayMode === "drop") return [];
|
|
193
|
-
if (block.redacted) return isSameModel ? block : [];
|
|
194
|
-
if (isSameModel && block.thinkingSignature) return block;
|
|
195
|
-
if (!block.thinking || block.thinking.trim() === "") return [];
|
|
196
|
-
if (isSameModel) return block;
|
|
197
|
-
return {
|
|
198
|
-
type: "text",
|
|
199
|
-
text: block.thinking
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
if (block.type === "text") {
|
|
203
|
-
if (isSameModel) return block;
|
|
204
|
-
return {
|
|
205
|
-
type: "text",
|
|
206
|
-
text: block.text
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
if (block.type === "toolCall") {
|
|
210
|
-
const toolCall = block;
|
|
211
|
-
let normalizedToolCall = toolCall;
|
|
212
|
-
if (!isSameModel && toolCall.thoughtSignature) {
|
|
213
|
-
normalizedToolCall = Object.assign({}, toolCall);
|
|
214
|
-
delete normalizedToolCall.thoughtSignature;
|
|
215
|
-
}
|
|
216
|
-
if (!isSameModel && normalizeToolCallId) {
|
|
217
|
-
const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);
|
|
218
|
-
if (normalizedId !== toolCall.id) {
|
|
219
|
-
toolCallIdMap.set(toolCall.id, normalizedId);
|
|
220
|
-
normalizedToolCall = Object.assign({}, normalizedToolCall, { id: normalizedId });
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return normalizedToolCall;
|
|
224
|
-
}
|
|
225
|
-
return block;
|
|
226
|
-
});
|
|
227
|
-
return Object.assign({}, assistantMsg, { content: transformedContent });
|
|
228
|
-
}
|
|
229
|
-
return msg;
|
|
230
|
-
});
|
|
231
|
-
const result = [];
|
|
232
|
-
let pendingToolCalls = [];
|
|
233
|
-
let existingToolResultIds = /* @__PURE__ */ new Set();
|
|
234
|
-
const insertSyntheticToolResults = () => {
|
|
235
|
-
if (pendingToolCalls.length > 0) {
|
|
236
|
-
for (const tc of pendingToolCalls) if (!existingToolResultIds.has(tc.id)) result.push({
|
|
237
|
-
role: "toolResult",
|
|
238
|
-
toolCallId: tc.id,
|
|
239
|
-
toolName: tc.name,
|
|
240
|
-
content: [{
|
|
241
|
-
type: "text",
|
|
242
|
-
text: "No result provided"
|
|
243
|
-
}],
|
|
244
|
-
isError: true,
|
|
245
|
-
timestamp: Date.now()
|
|
246
|
-
});
|
|
247
|
-
pendingToolCalls = [];
|
|
248
|
-
existingToolResultIds = /* @__PURE__ */ new Set();
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
for (const msg of transformed) if (msg.role === "assistant") {
|
|
252
|
-
insertSyntheticToolResults();
|
|
253
|
-
const assistantMsg = msg;
|
|
254
|
-
if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") continue;
|
|
255
|
-
const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall");
|
|
256
|
-
if (toolCalls.length > 0) {
|
|
257
|
-
pendingToolCalls = toolCalls;
|
|
258
|
-
existingToolResultIds = /* @__PURE__ */ new Set();
|
|
259
|
-
}
|
|
260
|
-
result.push(msg);
|
|
261
|
-
} else if (msg.role === "toolResult") {
|
|
262
|
-
existingToolResultIds.add(msg.toolCallId);
|
|
263
|
-
result.push(msg);
|
|
264
|
-
} else if (msg.role === "user") {
|
|
265
|
-
insertSyntheticToolResults();
|
|
266
|
-
result.push(msg);
|
|
267
|
-
} else result.push(msg);
|
|
268
|
-
insertSyntheticToolResults();
|
|
269
|
-
return result;
|
|
270
|
-
}
|
|
271
|
-
//#endregion
|
|
272
|
-
//#region packages/ai/src/host.ts
|
|
273
|
-
const MAX_PENDING_CUSTOM_API_REGISTRATIONS = 32;
|
|
274
|
-
const pendingCustomApiRegistrations = [];
|
|
275
|
-
function queueCustomApiRegistration(registry, api, streamFn) {
|
|
276
|
-
const existing = pendingCustomApiRegistrations.find((registration) => registration.registry === registry && registration.api === api);
|
|
277
|
-
if (existing) {
|
|
278
|
-
existing.streamFn = streamFn;
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
if (pendingCustomApiRegistrations.length >= MAX_PENDING_CUSTOM_API_REGISTRATIONS) throw new Error("Too many custom transport APIs were registered before host configuration");
|
|
282
|
-
pendingCustomApiRegistrations.push({
|
|
283
|
-
registry,
|
|
284
|
-
api,
|
|
285
|
-
streamFn
|
|
286
|
-
});
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
289
|
-
const inertAiTransportHost = {
|
|
290
|
-
buildModelFetch: () => void 0,
|
|
291
|
-
resolveSecretSentinel: (value) => value,
|
|
292
|
-
redactSecrets: (value) => value,
|
|
293
|
-
redactToolPayloadText: (text) => text,
|
|
294
|
-
normalizeAnthropicInlineContentBlocks: async (content) => [...content],
|
|
295
|
-
resolveOpenAIStrictToolSetting: (_model, options) => options?.supportsStrictMode ? false : void 0,
|
|
296
|
-
plugin: {
|
|
297
|
-
resolveProviderStream: () => void 0,
|
|
298
|
-
resolveTransportTurnState: () => void 0,
|
|
299
|
-
wrapSimpleCompletionStream: () => void 0,
|
|
300
|
-
createAnthropicVertexStream: () => {
|
|
301
|
-
throw new Error("Anthropic Vertex transport is not configured by the embedding host");
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
buildCopilotDynamicHeaders: () => ({}),
|
|
305
|
-
resolveProviderEndpointClass: () => "default",
|
|
306
|
-
resolveProviderRequestCapabilities: () => ({
|
|
307
|
-
endpointClass: "default",
|
|
308
|
-
knownProviderFamily: "",
|
|
309
|
-
supportsNativeStreamingUsageCompat: false,
|
|
310
|
-
supportsOpenAICompletionsStreamingUsageCompat: false,
|
|
311
|
-
usesExplicitProxyLikeEndpoint: false,
|
|
312
|
-
allowsAnthropicServiceTier: false
|
|
313
|
-
}),
|
|
314
|
-
resolveProviderRequestHeaders: ({ providerHeaders, callerHeaders, precedence }) => ({
|
|
315
|
-
...precedence === "caller-wins" ? providerHeaders : callerHeaders,
|
|
316
|
-
...precedence === "caller-wins" ? callerHeaders : providerHeaders
|
|
317
|
-
}),
|
|
318
|
-
resolveModelRequestTimeoutMs: () => void 0,
|
|
319
|
-
requiresManagedTransport: () => false,
|
|
320
|
-
inheritManagedTransport: (_source, target) => target,
|
|
321
|
-
transformTransportMessages: (messages, model, normalizeToolCallId) => transformMessages(messages, model, normalizeToolCallId),
|
|
322
|
-
registerCustomApi: queueCustomApiRegistration,
|
|
323
|
-
prepareGoogleSimpleCompletionModel: (_registry, model) => model,
|
|
324
|
-
logDebug: () => {},
|
|
325
|
-
logInfo: () => {},
|
|
326
|
-
logWarn: () => {}
|
|
327
|
-
};
|
|
328
|
-
let activeAiTransportHost = inertAiTransportHost;
|
|
329
|
-
/** Installs host implementations for the transport policy ports. */
|
|
330
|
-
function configureAiTransportHost(host) {
|
|
331
|
-
activeAiTransportHost = {
|
|
332
|
-
...inertAiTransportHost,
|
|
333
|
-
...host,
|
|
334
|
-
normalizeAnthropicInlineContentBlocks: host.normalizeAnthropicInlineContentBlocks ?? inertAiTransportHost.normalizeAnthropicInlineContentBlocks,
|
|
335
|
-
plugin: {
|
|
336
|
-
...inertAiTransportHost.plugin,
|
|
337
|
-
...host.plugin
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
const transportHost = activeAiTransportHost;
|
|
341
|
-
if (transportHost.registerCustomApi === inertAiTransportHost.registerCustomApi || pendingCustomApiRegistrations.length === 0) return;
|
|
342
|
-
const pending = pendingCustomApiRegistrations.splice(0);
|
|
343
|
-
for (const [index, registration] of pending.entries()) try {
|
|
344
|
-
transportHost.registerCustomApi(registration.registry, registration.api, registration.streamFn);
|
|
345
|
-
} catch (error) {
|
|
346
|
-
pendingCustomApiRegistrations.unshift(...pending.slice(index));
|
|
347
|
-
throw error;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
/** Returns the active transport host (inert defaults unless configured). */
|
|
351
|
-
function getAiTransportHost() {
|
|
352
|
-
return activeAiTransportHost;
|
|
353
|
-
}
|
|
354
|
-
/** Resolves sentinel substrings in custom headers at a no-fetch adapter boundary. */
|
|
355
|
-
function resolveAiTransportHeaderSentinels(headers) {
|
|
356
|
-
if (!headers) return;
|
|
357
|
-
const host = getAiTransportHost();
|
|
358
|
-
let resolvedHeaders;
|
|
359
|
-
for (const [name, value] of Object.entries(headers)) {
|
|
360
|
-
const resolved = host.resolveSecretSentinel(value);
|
|
361
|
-
if (resolved !== value) {
|
|
362
|
-
resolvedHeaders ??= { ...headers };
|
|
363
|
-
resolvedHeaders[name] = resolved;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return resolvedHeaders ?? headers;
|
|
367
|
-
}
|
|
368
|
-
//#endregion
|
|
369
|
-
export { applyClaudeRequestContract as a, requiresClaudeAdaptiveThinking as c, usesClaudeStreamingRefusalContract as d, hasNonEmptyString as f, isRecord as g, readStringValue as h, transformMessages as i, resolveModelBoundThinkingReplayMode as l, normalizeOptionalString as m, getAiTransportHost as n, defaultsClaudeAdaptiveThinking as o, normalizeLowercaseStringOrEmpty as p, resolveAiTransportHeaderSentinels as r, prepareClaudeNoPrefillRequestContext as s, configureAiTransportHost as t, usesClaudeFable5MessagesContract as u };
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { a as requiresClaudeMandatoryAdaptiveThinking, l as resolveClaudeNativeThinkingLevelMap } from "./src-QkygScBs.mjs";
|
|
2
|
-
//#region packages/ai/src/model-utils.ts
|
|
3
|
-
/** Calculates and stores model cost fields from token usage and per-million pricing. */
|
|
4
|
-
function calculateCost(model, usage) {
|
|
5
|
-
const cacheWrite1h = Math.min(usage.cacheWrite, Math.max(0, usage.cacheWrite1h ?? 0));
|
|
6
|
-
const cacheWrite5m = usage.cacheWrite - cacheWrite1h;
|
|
7
|
-
usage.cost.input = model.cost.input / 1e6 * usage.input;
|
|
8
|
-
usage.cost.output = model.cost.output / 1e6 * usage.output;
|
|
9
|
-
usage.cost.cacheRead = model.cost.cacheRead / 1e6 * usage.cacheRead;
|
|
10
|
-
usage.cost.cacheWrite = (model.cost.cacheWrite * cacheWrite5m + model.cost.input * 2 * cacheWrite1h) / 1e6;
|
|
11
|
-
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
12
|
-
return usage.cost;
|
|
13
|
-
}
|
|
14
|
-
/** Replaces the catalog estimate when the provider reports an authoritative billed total. */
|
|
15
|
-
function applyProviderReportedUsageCost(usage, reportedCost) {
|
|
16
|
-
if (typeof reportedCost !== "number" || !Number.isFinite(reportedCost) || reportedCost < 0) return;
|
|
17
|
-
usage.cost.total = reportedCost;
|
|
18
|
-
usage.cost.totalOrigin = "provider-billed";
|
|
19
|
-
}
|
|
20
|
-
const EXTENDED_THINKING_LEVELS = [
|
|
21
|
-
"off",
|
|
22
|
-
"minimal",
|
|
23
|
-
"low",
|
|
24
|
-
"medium",
|
|
25
|
-
"high",
|
|
26
|
-
"xhigh",
|
|
27
|
-
"max"
|
|
28
|
-
];
|
|
29
|
-
function resolveThinkingLevelMap(model) {
|
|
30
|
-
return model.api === "anthropic-messages" ? resolveClaudeNativeThinkingLevelMap(model) ?? model.thinkingLevelMap : model.thinkingLevelMap;
|
|
31
|
-
}
|
|
32
|
-
/** Returns thinking levels exposed by a reasoning-capable model. */
|
|
33
|
-
function getSupportedThinkingLevels(model) {
|
|
34
|
-
const mandatoryAdaptiveContract = model.api === "anthropic-messages" && requiresClaudeMandatoryAdaptiveThinking(model);
|
|
35
|
-
if (!model.reasoning && !mandatoryAdaptiveContract) return ["off"];
|
|
36
|
-
const thinkingLevelMap = resolveThinkingLevelMap(model);
|
|
37
|
-
return EXTENDED_THINKING_LEVELS.filter((level) => {
|
|
38
|
-
const mapped = thinkingLevelMap?.[level];
|
|
39
|
-
if (mapped === null) return false;
|
|
40
|
-
if (level === "xhigh" || level === "max") return mapped !== void 0;
|
|
41
|
-
return true;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/** Clamps a requested thinking level to the closest supported level for a model. */
|
|
45
|
-
function clampThinkingLevel(model, level) {
|
|
46
|
-
const availableLevels = getSupportedThinkingLevels(model);
|
|
47
|
-
if (availableLevels.includes(level)) return level;
|
|
48
|
-
const requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);
|
|
49
|
-
if (requestedIndex === -1) return availableLevels[0] ?? "off";
|
|
50
|
-
const thinkingLevelMap = resolveThinkingLevelMap(model);
|
|
51
|
-
if ((level === "xhigh" || level === "max") && thinkingLevelMap?.[level] === null) {
|
|
52
|
-
for (const candidate of EXTENDED_THINKING_LEVELS.slice(0, requestedIndex).toReversed()) if (availableLevels.includes(candidate)) return candidate;
|
|
53
|
-
}
|
|
54
|
-
for (const candidate of EXTENDED_THINKING_LEVELS.slice(requestedIndex)) if (availableLevels.includes(candidate)) return candidate;
|
|
55
|
-
for (const candidate of EXTENDED_THINKING_LEVELS.slice(0, requestedIndex).toReversed()) if (availableLevels.includes(candidate)) return candidate;
|
|
56
|
-
return availableLevels[0] ?? "off";
|
|
57
|
-
}
|
|
58
|
-
/** Compares model identity by provider and id. */
|
|
59
|
-
function modelsAreEqual(a, b) {
|
|
60
|
-
if (!a || !b) return false;
|
|
61
|
-
return a.id === b.id && a.provider === b.provider;
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region packages/normalization-core/src/number-coercion.ts
|
|
65
|
-
/** Returns a number only when the input is already finite. */
|
|
66
|
-
function asFiniteNumber(value) {
|
|
67
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
68
|
-
}
|
|
69
|
-
/** Returns a finite number only when it satisfies the supplied inclusive/exclusive bounds. */
|
|
70
|
-
function asFiniteNumberInRange(value, range) {
|
|
71
|
-
const number = asFiniteNumber(value);
|
|
72
|
-
if (number === void 0) return;
|
|
73
|
-
if (range.min !== void 0) {
|
|
74
|
-
if (range.minExclusive ? number <= range.min : number < range.min) return;
|
|
75
|
-
}
|
|
76
|
-
if (range.max !== void 0) {
|
|
77
|
-
if (range.maxExclusive ? number >= range.max : number > range.max) return;
|
|
78
|
-
}
|
|
79
|
-
return number;
|
|
80
|
-
}
|
|
81
|
-
function normalizeNumericString(value) {
|
|
82
|
-
const trimmed = value.trim();
|
|
83
|
-
return trimmed ? trimmed : void 0;
|
|
84
|
-
}
|
|
85
|
-
/** Parses only safe integer numbers or base-10 integer strings. */
|
|
86
|
-
function parseStrictInteger(value) {
|
|
87
|
-
if (typeof value === "number") return Number.isSafeInteger(value) ? value : void 0;
|
|
88
|
-
if (typeof value !== "string") return;
|
|
89
|
-
const normalized = normalizeNumericString(value);
|
|
90
|
-
if (!normalized || !/^[+-]?\d+$/.test(normalized)) return;
|
|
91
|
-
const parsed = Number(normalized);
|
|
92
|
-
return Number.isSafeInteger(parsed) ? parsed : void 0;
|
|
93
|
-
}
|
|
94
|
-
/** Parses only finite decimal/scientific string tokens, rejecting partial numbers. */
|
|
95
|
-
function parseStrictFiniteNumber(value) {
|
|
96
|
-
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
97
|
-
if (typeof value !== "string") return;
|
|
98
|
-
const normalized = normalizeNumericString(value);
|
|
99
|
-
if (!normalized || !/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:e[+-]?\d+)?$/i.test(normalized)) return;
|
|
100
|
-
const parsed = Number(normalized);
|
|
101
|
-
return Number.isFinite(parsed) ? parsed : void 0;
|
|
102
|
-
}
|
|
103
|
-
/** Conservative upper bound for Node timer delays. */
|
|
104
|
-
const MAX_TIMER_TIMEOUT_MS = 2147e6;
|
|
105
|
-
/** Clamps finite millisecond values into the Node-safe timer range. */
|
|
106
|
-
function clampTimerTimeoutMs(valueMs, minMs = 1) {
|
|
107
|
-
const value = asFiniteNumber(valueMs);
|
|
108
|
-
if (value === void 0) return;
|
|
109
|
-
return Math.min(Math.max(Math.floor(value), Math.max(1, Math.floor(minMs))), MAX_TIMER_TIMEOUT_MS);
|
|
110
|
-
}
|
|
111
|
-
/** Resolves arbitrary timeout input with fallback and minimum timer bounds. */
|
|
112
|
-
function resolveTimerTimeoutMs(valueMs, fallbackMs, minMs = 1) {
|
|
113
|
-
const value = asFiniteNumber(valueMs) ?? asFiniteNumber(fallbackMs);
|
|
114
|
-
const min = Math.max(0, Math.floor(minMs));
|
|
115
|
-
if (value === void 0) return min;
|
|
116
|
-
return Math.min(Math.max(Math.floor(value), min), MAX_TIMER_TIMEOUT_MS);
|
|
117
|
-
}
|
|
118
|
-
/** Parses strict positive integer values from numbers or strings. */
|
|
119
|
-
function parseStrictPositiveInteger(value) {
|
|
120
|
-
const parsed = parseStrictInteger(value);
|
|
121
|
-
return parsed !== void 0 && parsed > 0 ? parsed : void 0;
|
|
122
|
-
}
|
|
123
|
-
/** Parses strict non-negative integer values from numbers or strings. */
|
|
124
|
-
function parseStrictNonNegativeInteger(value) {
|
|
125
|
-
const parsed = parseStrictInteger(value);
|
|
126
|
-
return parsed !== void 0 && parsed >= 0 ? parsed : void 0;
|
|
127
|
-
}
|
|
128
|
-
//#endregion
|
|
129
|
-
export { parseStrictPositiveInteger as a, calculateCost as c, modelsAreEqual as d, parseStrictNonNegativeInteger as i, clampThinkingLevel as l, clampTimerTimeoutMs as n, resolveTimerTimeoutMs as o, parseStrictFiniteNumber as r, applyProviderReportedUsageCost as s, asFiniteNumberInRange as t, getSupportedThinkingLevels as u };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
//#region packages/ai/src/session-resources.ts
|
|
2
|
-
const sessionResourceCleanups = /* @__PURE__ */ new Set();
|
|
3
|
-
/** Registers a session-resource cleanup hook and returns an unregister function. */
|
|
4
|
-
function registerSessionResourceCleanup(cleanup) {
|
|
5
|
-
sessionResourceCleanups.add(cleanup);
|
|
6
|
-
return () => {
|
|
7
|
-
sessionResourceCleanups.delete(cleanup);
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
/** Runs all registered cleanup hooks, aggregating failures after every hook has run. */
|
|
11
|
-
function cleanupSessionResources(sessionId) {
|
|
12
|
-
const errors = [];
|
|
13
|
-
for (const cleanup of sessionResourceCleanups) try {
|
|
14
|
-
cleanup(sessionId);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
errors.push(error);
|
|
17
|
-
}
|
|
18
|
-
if (errors.length > 0) throw new AggregateError(errors, "Failed to cleanup session resources");
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region packages/ai/src/utils/oauth/openai-chatgpt-jwt.ts
|
|
22
|
-
const OPENAI_CODEX_AUTH_CLAIM = "https://api.openai.com/auth";
|
|
23
|
-
function decodeOpenAICodexJwtPayload(token) {
|
|
24
|
-
const parts = token.split(".");
|
|
25
|
-
if (parts.length !== 3) return null;
|
|
26
|
-
try {
|
|
27
|
-
const decoded = Buffer.from(parts[1] ?? "", "base64url").toString("utf8");
|
|
28
|
-
const parsed = JSON.parse(decoded);
|
|
29
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
30
|
-
} catch {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function resolveOpenAICodexAccountId(token) {
|
|
35
|
-
const accountId = decodeOpenAICodexJwtPayload(token)?.[OPENAI_CODEX_AUTH_CLAIM]?.chatgpt_account_id;
|
|
36
|
-
return typeof accountId === "string" && accountId.length > 0 ? accountId : null;
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
export { registerSessionResourceCleanup as i, resolveOpenAICodexAccountId as n, cleanupSessionResources as r, decodeOpenAICodexJwtPayload as t };
|