@openclaw/ai 2026.8.1-beta.1 → 2026.8.1-beta.3
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-CE-7SkF6.mjs → anthropic-B8KwTtlb.mjs} +62 -37
- package/dist/{anthropic-SrGtwsJu.d.mts → anthropic-BECQCNdF.d.mts} +0 -2
- package/dist/{src-QkygScBs.mjs → anthropic-BQXQudmA.mjs} +0 -2
- package/dist/{anthropic-usage-Ma4iX6uG.mjs → anthropic-compaction-replay-4Zx7-aCr.mjs} +225 -103
- package/dist/anthropic-payload-policy-CSx7MoKH.d.mts +50 -0
- package/dist/{api-registry-EpJoVwM1.d.mts → api-registry-DFxSnFqG.d.mts} +1 -1
- package/dist/{azure-openai-responses-Cc_kasye.mjs → azure-openai-responses-Aa4mVcYG.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/event-stream-BVVgDSdq.d.mts +1 -0
- package/dist/{event-stream-DRmDMRHH.d.mts → event-stream-D91-ohD_.d.mts} +3 -1
- package/dist/{event-stream-CEV9t6da.mjs → event-stream-uSMZJ3FA.mjs} +16 -3
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-shared-Cq2UKx1l.mjs → google-shared-M1dl64nz.mjs} +17 -19
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-CusxWzvE.mjs → google-vertex-DCJHM_a5.mjs} +5 -4
- package/dist/{google-CGQu21aw.mjs → google-yDRnipeq.mjs} +4 -4
- package/dist/host-DF_yxOsA.mjs +477 -0
- package/dist/{host-Dn4_SZI2.d.mts → host-DJq_FGcz.d.mts} +13 -8
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +21 -7
- 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 +9 -7
- package/dist/internal/runtime.d.mts +19 -5
- package/dist/internal/runtime.mjs +85 -72
- package/dist/internal/shared.d.mts +17 -8
- package/dist/internal/shared.mjs +4 -5
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-Dx6VzNjf.mjs → mistral-D6hRXI7A.mjs} +67 -72
- package/dist/{number-coercion-1Miyb5MO.mjs → number-coercion-H9qHik3g.mjs} +7 -2
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-SC9m0FSf.mjs → openai-chatgpt-responses-C339VIfT.mjs} +235 -146
- package/dist/{openai-completions-BaIpl93j.mjs → openai-completions-D88orSJ9.mjs} +88 -67
- package/dist/openai-completions-compat-B0KTleXp.d.mts +43 -0
- package/dist/{openai-responses-Bdx3V_Yu.mjs → openai-responses-BXEcr-Tp.mjs} +17 -24
- package/dist/openai-responses-contracts-CD75pQ0m.d.mts +68 -0
- package/dist/openai-responses-contracts-DvILoqBk.mjs +247 -0
- package/dist/openai-responses-payload-policy-BDo8CQsx.mjs +208 -0
- package/dist/openai-responses-payload-policy-CNGFT9zr.d.mts +41 -0
- package/dist/{openai-responses-prompt-observer-internal-DDZPxRfr.mjs → openai-responses-prompt-observer-internal-BG-1AsBI.mjs} +2 -3
- package/dist/{openai-responses-stream-internal-Bl8YyVtF.mjs → openai-responses-shared-Cvt5MgEm.mjs} +1287 -1039
- package/dist/{openai-reasoning-compat-DKebnIBL.mjs → openai-stop-reason-9OONKyAm.mjs} +222 -180
- package/dist/{openai-transport-shared-Cipt7egQ.mjs → openai-tool-projection-CHGLt03m.mjs} +239 -128
- package/dist/provider-error-C8mBRJDl.mjs +424 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/provider-options-AvldWZt8.mjs +21 -0
- package/dist/{provider-options-C5kYML7i.d.mts → provider-options-Cc5ZQ6Aa.d.mts} +19 -3
- package/dist/provider-transcript-transform--gtf0ZbR.mjs +32 -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-5ygO2rZc.mjs} +17 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/{model-utils-Dau5dlgm.mjs → sanitize-unicode-BP7HLLZn.mjs} +28 -2
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-oqsXB6U3.mjs +450 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BIBomOGq.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-B1b-XCn5.mjs → tool-schema-json-projection-FEr-jOoZ.mjs} +20 -13
- package/dist/transport-utils-Bv0FHkd0.mjs +138 -0
- package/dist/transports.d.mts +199 -209
- package/dist/transports.mjs +1842 -1364
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-CH7ReIcU.d.mts → types-DTAP49HF.d.mts} +35 -2
- package/dist/types.d.mts +5 -5
- 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-CcPcuEbR.d.mts → validation-DYNNrU9u.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/host-Bl7Kgddo.mjs +0 -407
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-contracts-BBKBfAqR.d.mts +0 -116
- package/dist/openai-responses-shared-CCyMvg7M.mjs +0 -403
- package/dist/provider-error-DI0Ts28U.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/tool-result-text-Dvkp2Dus.mjs +0 -274
- package/dist/transform-messages-DfjpNXNQ.mjs +0 -2
- package/dist/transport-stream-shared-CPNv7A3r.mjs +0 -297
package/dist/host-Bl7Kgddo.mjs
DELETED
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import { a as requiresClaudeMandatoryAdaptiveThinking, c as resolveClaudeMythos5ModelIdentity, d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, h as supportsClaudeNativeMaxEffort, i as requiresClaudeDefaultSampling, l as resolveClaudeNativeThinkingLevelMap, o as resolveClaudeFable5ModelIdentity, u as resolveClaudeOpus5ModelIdentity } from "./src-QkygScBs.mjs";
|
|
2
|
-
import { r as clampThinkingLevel } from "./model-utils-Dau5dlgm.mjs";
|
|
3
|
-
//#region packages/normalization-core/src/record-coerce.ts
|
|
4
|
-
/** Type guard for non-array object records at browser-safe boundaries. */
|
|
5
|
-
function isRecord(value) {
|
|
6
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region packages/normalization-core/src/string-coerce.ts
|
|
10
|
-
/** Reads a value only when it is already a string, preserving whitespace. */
|
|
11
|
-
function readStringValue(value) {
|
|
12
|
-
return typeof value === "string" ? value : void 0;
|
|
13
|
-
}
|
|
14
|
-
/** Trims string input and returns null for non-strings or empty strings. */
|
|
15
|
-
function normalizeNullableString(value) {
|
|
16
|
-
if (typeof value !== "string") return null;
|
|
17
|
-
const trimmed = value.trim();
|
|
18
|
-
return trimmed ? trimmed : null;
|
|
19
|
-
}
|
|
20
|
-
/** Trims string input and returns undefined for non-strings or empty strings. */
|
|
21
|
-
function normalizeOptionalString(value) {
|
|
22
|
-
return normalizeNullableString(value) ?? void 0;
|
|
23
|
-
}
|
|
24
|
-
/** Lowercases a normalized optional string. */
|
|
25
|
-
function normalizeOptionalLowercaseString(value) {
|
|
26
|
-
return normalizeOptionalString(value)?.toLowerCase();
|
|
27
|
-
}
|
|
28
|
-
/** Lowercases a normalized string or returns an empty string when absent. */
|
|
29
|
-
function normalizeLowercaseStringOrEmpty(value) {
|
|
30
|
-
return normalizeOptionalLowercaseString(value) ?? "";
|
|
31
|
-
}
|
|
32
|
-
/** Type guard for strings that remain non-empty after trimming. */
|
|
33
|
-
function hasNonEmptyString(value) {
|
|
34
|
-
return normalizeOptionalString(value) !== void 0;
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region packages/ai/src/providers/anthropic-model-contract.ts
|
|
38
|
-
const ANTHROPIC_CLAUDE_CODE_VERSION = "2.1.75";
|
|
39
|
-
const ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK = `x-anthropic-billing-header: cc_version=${ANTHROPIC_CLAUDE_CODE_VERSION}; cc_entrypoint=sdk-cli;`;
|
|
40
|
-
function normalizeModelId(modelId) {
|
|
41
|
-
const normalized = normalizeLowercaseStringOrEmpty(modelId);
|
|
42
|
-
return (normalized.startsWith("anthropic/") ? normalized.slice(10) : normalized).replace(/[._\s]+/g, "-");
|
|
43
|
-
}
|
|
44
|
-
function normalizeApi(api) {
|
|
45
|
-
const normalized = normalizeLowercaseStringOrEmpty(api);
|
|
46
|
-
return normalized === "openclaw-anthropic-messages-transport" ? "anthropic-messages" : normalized;
|
|
47
|
-
}
|
|
48
|
-
function hasConcreteResponseModel(ref) {
|
|
49
|
-
const responseModelId = normalizeModelId(ref.responseModelId);
|
|
50
|
-
return responseModelId.length > 0 && responseModelId !== normalizeModelId(ref.modelId);
|
|
51
|
-
}
|
|
52
|
-
function usesClaudeFable5MessagesContract(model) {
|
|
53
|
-
return normalizeApi(model.api) === "anthropic-messages" && resolveClaudeFable5ModelIdentity(model) !== void 0;
|
|
54
|
-
}
|
|
55
|
-
/** Return whether streamed output must wait for the terminal refusal decision. */
|
|
56
|
-
function usesClaudeStreamingRefusalContract(model) {
|
|
57
|
-
if (normalizeApi(model.api) !== "anthropic-messages") return false;
|
|
58
|
-
return resolveClaudeFable5ModelIdentity(model) !== void 0 || resolveClaudeMythos5ModelIdentity(model) !== void 0 || resolveClaudeOpus5ModelIdentity(model) !== void 0 || resolveClaudeSonnet5ModelIdentity(model) !== void 0;
|
|
59
|
-
}
|
|
60
|
-
function requiresClaudeAdaptiveThinking(model) {
|
|
61
|
-
if (normalizeApi(model.api) !== "anthropic-messages") return false;
|
|
62
|
-
return requiresClaudeMandatoryAdaptiveThinking(model);
|
|
63
|
-
}
|
|
64
|
-
/** Return whether omitted thinking should default to adaptive/high. */
|
|
65
|
-
function defaultsClaudeAdaptiveThinking(model) {
|
|
66
|
-
return requiresClaudeAdaptiveThinking(model) || normalizeApi(model.api) === "anthropic-messages" && (resolveClaudeOpus5ModelIdentity(model) !== void 0 || resolveClaudeSonnet5ModelIdentity(model) !== void 0);
|
|
67
|
-
}
|
|
68
|
-
/** Resolve provider-native effort once for direct and managed Claude requests. */
|
|
69
|
-
function resolveAnthropicThinkingEffort(model, level) {
|
|
70
|
-
const requestedLevel = level;
|
|
71
|
-
const thinkingLevelMap = resolveClaudeNativeThinkingLevelMap(model);
|
|
72
|
-
const clampModel = {
|
|
73
|
-
...model,
|
|
74
|
-
...typeof model.params?.canonicalModelId === "string" ? { reasoning: true } : {},
|
|
75
|
-
...thinkingLevelMap ? { thinkingLevelMap } : {}
|
|
76
|
-
};
|
|
77
|
-
const resolvedLevel = requestedLevel ? clampThinkingLevel(clampModel, requestedLevel) : void 0;
|
|
78
|
-
const mapped = resolvedLevel ? thinkingLevelMap?.[resolvedLevel] : void 0;
|
|
79
|
-
if (typeof mapped === "string") return mapped;
|
|
80
|
-
switch (resolvedLevel) {
|
|
81
|
-
case "off":
|
|
82
|
-
case "minimal":
|
|
83
|
-
case "low": return "low";
|
|
84
|
-
case "medium": return "medium";
|
|
85
|
-
case "xhigh": return supportsClaudeNativeXhighEffort(model) ? "xhigh" : "high";
|
|
86
|
-
case "max": return supportsClaudeNativeMaxEffort(model) ? "max" : "high";
|
|
87
|
-
default: return "high";
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/** Normalize Anthropic and Anthropic-compatible terminal reasons identically. */
|
|
91
|
-
function mapAnthropicStopReason(reason) {
|
|
92
|
-
switch (reason) {
|
|
93
|
-
case "end_turn":
|
|
94
|
-
case "pause_turn":
|
|
95
|
-
case "stop_sequence": return "stop";
|
|
96
|
-
case "max_tokens": return "length";
|
|
97
|
-
case "tool_use": return "toolUse";
|
|
98
|
-
case "refusal":
|
|
99
|
-
case "sensitive": return "error";
|
|
100
|
-
default: throw new Error(`Unhandled stop reason: ${String(reason)}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/** Remove unsupported assistant prefills while preserving completed tool-use turns. */
|
|
104
|
-
function prepareClaudeNoPrefillRequestContext(model, context) {
|
|
105
|
-
if (!resolveClaudeOpus5ModelIdentity(model) && !resolveClaudeSonnet5ModelIdentity(model)) return context;
|
|
106
|
-
let end = context.messages.length;
|
|
107
|
-
while (end > 0) {
|
|
108
|
-
const message = context.messages[end - 1];
|
|
109
|
-
if (message?.role !== "assistant" || Array.isArray(message.content) && message.content.some((block) => block.type === "toolCall")) break;
|
|
110
|
-
end -= 1;
|
|
111
|
-
}
|
|
112
|
-
return end === context.messages.length ? context : {
|
|
113
|
-
...context,
|
|
114
|
-
messages: context.messages.slice(0, end)
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function applyClaudeRequestContract(params, model) {
|
|
118
|
-
if (normalizeApi(model.api) !== "anthropic-messages") return;
|
|
119
|
-
const opus5 = resolveClaudeOpus5ModelIdentity(model) !== void 0;
|
|
120
|
-
const sonnet5 = resolveClaudeSonnet5ModelIdentity(model) !== void 0;
|
|
121
|
-
if (!requiresClaudeDefaultSampling(model) && !opus5 && !sonnet5) return;
|
|
122
|
-
delete params.temperature;
|
|
123
|
-
delete params.top_p;
|
|
124
|
-
delete params.top_k;
|
|
125
|
-
if (opus5 || sonnet5) delete params.service_tier;
|
|
126
|
-
}
|
|
127
|
-
function resolveReplayModelBoundIdentity(ref) {
|
|
128
|
-
if (normalizeApi(ref.api) !== "anthropic-messages") return;
|
|
129
|
-
const modelRef = hasConcreteResponseModel(ref) ? { id: ref.responseModelId } : {
|
|
130
|
-
id: ref.modelId,
|
|
131
|
-
params: ref.modelParams
|
|
132
|
-
};
|
|
133
|
-
const fableIdentity = resolveClaudeFable5ModelIdentity(modelRef);
|
|
134
|
-
if (fableIdentity) return `fable:${fableIdentity}`;
|
|
135
|
-
const mythosIdentity = resolveClaudeMythos5ModelIdentity(modelRef);
|
|
136
|
-
if (mythosIdentity) return `mythos:${mythosIdentity}`;
|
|
137
|
-
const opusIdentity = resolveClaudeOpus5ModelIdentity(modelRef);
|
|
138
|
-
if (opusIdentity) return `opus:${opusIdentity}`;
|
|
139
|
-
const sonnetIdentity = resolveClaudeSonnet5ModelIdentity(modelRef);
|
|
140
|
-
return sonnetIdentity ? `sonnet:${sonnetIdentity}` : void 0;
|
|
141
|
-
}
|
|
142
|
-
function resolveModelBoundThinkingReplayMode(params) {
|
|
143
|
-
const sourceApi = normalizeApi(params.source.api);
|
|
144
|
-
const targetApi = normalizeApi(params.target.api);
|
|
145
|
-
const sourceIdentity = resolveReplayModelBoundIdentity(params.source);
|
|
146
|
-
const targetIdentity = resolveReplayModelBoundIdentity(params.target);
|
|
147
|
-
const sameRoute = normalizeLowercaseStringOrEmpty(params.source.provider) === normalizeLowercaseStringOrEmpty(params.target.provider) && sourceApi === targetApi && normalizeModelId(params.source.modelId) === normalizeModelId(params.target.modelId);
|
|
148
|
-
if (!sourceIdentity && !targetIdentity) return "default";
|
|
149
|
-
if (!sourceIdentity && !hasConcreteResponseModel(params.source) && targetIdentity && sameRoute) return "preserve";
|
|
150
|
-
return sourceApi === targetApi && sourceIdentity === targetIdentity ? "preserve" : "drop";
|
|
151
|
-
}
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region packages/ai/src/transcript-transform.ts
|
|
154
|
-
const NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
|
|
155
|
-
const NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
|
|
156
|
-
function isImageWithMediaPayload(block) {
|
|
157
|
-
return isRecord(block) && block.type === "image" && typeof block.data === "string" && block.data.trim().length > 0;
|
|
158
|
-
}
|
|
159
|
-
function replaceImagesWithPlaceholder(content, placeholder) {
|
|
160
|
-
const result = [];
|
|
161
|
-
let previousWasPlaceholder = false;
|
|
162
|
-
for (const block of content) {
|
|
163
|
-
if (block.type === "image") {
|
|
164
|
-
if (!isImageWithMediaPayload(block)) continue;
|
|
165
|
-
if (!previousWasPlaceholder) result.push({
|
|
166
|
-
type: "text",
|
|
167
|
-
text: placeholder
|
|
168
|
-
});
|
|
169
|
-
previousWasPlaceholder = true;
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
result.push(block);
|
|
173
|
-
previousWasPlaceholder = block.text === placeholder;
|
|
174
|
-
}
|
|
175
|
-
return result;
|
|
176
|
-
}
|
|
177
|
-
function downgradeUnsupportedImages(messages, model) {
|
|
178
|
-
if (model.input.includes("image")) return messages;
|
|
179
|
-
return messages.map((msg) => {
|
|
180
|
-
if (msg.role === "user" && Array.isArray(msg.content)) return {
|
|
181
|
-
...msg,
|
|
182
|
-
content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER)
|
|
183
|
-
};
|
|
184
|
-
if (msg.role === "toolResult") return {
|
|
185
|
-
...msg,
|
|
186
|
-
content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER)
|
|
187
|
-
};
|
|
188
|
-
return msg;
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Normalize tool call ID for cross-provider compatibility.
|
|
193
|
-
* OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.
|
|
194
|
-
* Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).
|
|
195
|
-
*/
|
|
196
|
-
function transformMessages(messages, model, normalizeToolCallId) {
|
|
197
|
-
const toolCallIdMap = /* @__PURE__ */ new Map();
|
|
198
|
-
const transformed = downgradeUnsupportedImages(messages.map((msg) => msg.content == null ? {
|
|
199
|
-
...msg,
|
|
200
|
-
content: []
|
|
201
|
-
} : msg), model).map((msg) => {
|
|
202
|
-
if (msg.role === "user") return msg;
|
|
203
|
-
if (msg.role === "toolResult") {
|
|
204
|
-
const normalizedId = toolCallIdMap.get(msg.toolCallId);
|
|
205
|
-
if (normalizedId && normalizedId !== msg.toolCallId) return Object.assign({}, msg, { toolCallId: normalizedId });
|
|
206
|
-
return msg;
|
|
207
|
-
}
|
|
208
|
-
if (msg.role === "assistant") {
|
|
209
|
-
const assistantMsg = msg;
|
|
210
|
-
const modelBoundThinkingReplayMode = resolveModelBoundThinkingReplayMode({
|
|
211
|
-
source: {
|
|
212
|
-
provider: assistantMsg.provider,
|
|
213
|
-
api: assistantMsg.api,
|
|
214
|
-
modelId: assistantMsg.model,
|
|
215
|
-
responseModelId: assistantMsg.responseModel
|
|
216
|
-
},
|
|
217
|
-
target: {
|
|
218
|
-
provider: model.provider,
|
|
219
|
-
api: model.api,
|
|
220
|
-
modelId: model.id,
|
|
221
|
-
modelParams: model.params
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
const isSameModel = modelBoundThinkingReplayMode === "preserve" || assistantMsg.provider === model.provider && assistantMsg.api === model.api && assistantMsg.model === model.id;
|
|
225
|
-
const transformedContent = (typeof assistantMsg.content === "string" ? [{
|
|
226
|
-
type: "text",
|
|
227
|
-
text: assistantMsg.content
|
|
228
|
-
}] : assistantMsg.content).flatMap((block) => {
|
|
229
|
-
if (block.type === "thinking") {
|
|
230
|
-
if (modelBoundThinkingReplayMode === "drop") return [];
|
|
231
|
-
if (block.redacted) return isSameModel ? block : [];
|
|
232
|
-
if (isSameModel && block.thinkingSignature) return block;
|
|
233
|
-
if (!block.thinking || block.thinking.trim() === "") return [];
|
|
234
|
-
if (isSameModel) return block;
|
|
235
|
-
return {
|
|
236
|
-
type: "text",
|
|
237
|
-
text: block.thinking
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
if (block.type === "text") {
|
|
241
|
-
if (isSameModel) return block;
|
|
242
|
-
return {
|
|
243
|
-
type: "text",
|
|
244
|
-
text: block.text
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
if (block.type === "toolCall") {
|
|
248
|
-
const toolCall = block;
|
|
249
|
-
let normalizedToolCall = toolCall;
|
|
250
|
-
if (!isSameModel && toolCall.thoughtSignature) {
|
|
251
|
-
normalizedToolCall = Object.assign({}, toolCall);
|
|
252
|
-
delete normalizedToolCall.thoughtSignature;
|
|
253
|
-
}
|
|
254
|
-
if (!isSameModel && normalizeToolCallId) {
|
|
255
|
-
const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);
|
|
256
|
-
if (normalizedId !== toolCall.id) {
|
|
257
|
-
toolCallIdMap.set(toolCall.id, normalizedId);
|
|
258
|
-
normalizedToolCall = Object.assign({}, normalizedToolCall, { id: normalizedId });
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return normalizedToolCall;
|
|
262
|
-
}
|
|
263
|
-
return block;
|
|
264
|
-
});
|
|
265
|
-
return Object.assign({}, assistantMsg, { content: transformedContent });
|
|
266
|
-
}
|
|
267
|
-
return msg;
|
|
268
|
-
});
|
|
269
|
-
const result = [];
|
|
270
|
-
let pendingToolCalls = [];
|
|
271
|
-
let existingToolResultIds = /* @__PURE__ */ new Set();
|
|
272
|
-
const insertSyntheticToolResults = () => {
|
|
273
|
-
if (pendingToolCalls.length > 0) {
|
|
274
|
-
for (const tc of pendingToolCalls) if (!existingToolResultIds.has(tc.id)) result.push({
|
|
275
|
-
role: "toolResult",
|
|
276
|
-
toolCallId: tc.id,
|
|
277
|
-
toolName: tc.name,
|
|
278
|
-
content: [{
|
|
279
|
-
type: "text",
|
|
280
|
-
text: "No result provided"
|
|
281
|
-
}],
|
|
282
|
-
isError: true,
|
|
283
|
-
timestamp: Date.now()
|
|
284
|
-
});
|
|
285
|
-
pendingToolCalls = [];
|
|
286
|
-
existingToolResultIds = /* @__PURE__ */ new Set();
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
for (const msg of transformed) if (msg.role === "assistant") {
|
|
290
|
-
insertSyntheticToolResults();
|
|
291
|
-
const assistantMsg = msg;
|
|
292
|
-
if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") continue;
|
|
293
|
-
const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall");
|
|
294
|
-
if (toolCalls.length > 0) {
|
|
295
|
-
pendingToolCalls = toolCalls;
|
|
296
|
-
existingToolResultIds = /* @__PURE__ */ new Set();
|
|
297
|
-
}
|
|
298
|
-
result.push(msg);
|
|
299
|
-
} else if (msg.role === "toolResult") {
|
|
300
|
-
existingToolResultIds.add(msg.toolCallId);
|
|
301
|
-
result.push(msg);
|
|
302
|
-
} else if (msg.role === "user") {
|
|
303
|
-
insertSyntheticToolResults();
|
|
304
|
-
result.push(msg);
|
|
305
|
-
} else result.push(msg);
|
|
306
|
-
insertSyntheticToolResults();
|
|
307
|
-
return result;
|
|
308
|
-
}
|
|
309
|
-
//#endregion
|
|
310
|
-
//#region packages/ai/src/host.ts
|
|
311
|
-
const MAX_PENDING_CUSTOM_API_REGISTRATIONS = 32;
|
|
312
|
-
const pendingCustomApiRegistrations = [];
|
|
313
|
-
function queueCustomApiRegistration(registry, api, streamFn) {
|
|
314
|
-
const existing = pendingCustomApiRegistrations.find((registration) => registration.registry === registry && registration.api === api);
|
|
315
|
-
if (existing) {
|
|
316
|
-
existing.streamFn = streamFn;
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
if (pendingCustomApiRegistrations.length >= MAX_PENDING_CUSTOM_API_REGISTRATIONS) throw new Error("Too many custom transport APIs were registered before host configuration");
|
|
320
|
-
pendingCustomApiRegistrations.push({
|
|
321
|
-
registry,
|
|
322
|
-
api,
|
|
323
|
-
streamFn
|
|
324
|
-
});
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
const inertAiTransportHost = {
|
|
328
|
-
buildModelFetch: () => void 0,
|
|
329
|
-
resolveSecretSentinel: (value) => value,
|
|
330
|
-
redactSecrets: (value) => value,
|
|
331
|
-
redactToolPayloadText: (text) => text,
|
|
332
|
-
normalizeAnthropicInlineContentBlocks: async (content) => [...content],
|
|
333
|
-
resolveOpenAIStrictToolSetting: (_model, options) => options?.supportsStrictMode ? false : void 0,
|
|
334
|
-
plugin: {
|
|
335
|
-
resolveProviderStream: () => void 0,
|
|
336
|
-
resolveTransportTurnState: () => void 0,
|
|
337
|
-
wrapSimpleCompletionStream: () => void 0,
|
|
338
|
-
createAnthropicVertexStream: () => {
|
|
339
|
-
throw new Error("Anthropic Vertex transport is not configured by the embedding host");
|
|
340
|
-
}
|
|
341
|
-
},
|
|
342
|
-
buildCopilotDynamicHeaders: () => ({}),
|
|
343
|
-
resolveProviderEndpointClass: () => "default",
|
|
344
|
-
resolveProviderRequestCapabilities: () => ({
|
|
345
|
-
endpointClass: "default",
|
|
346
|
-
knownProviderFamily: "",
|
|
347
|
-
supportsNativeStreamingUsageCompat: false,
|
|
348
|
-
supportsOpenAICompletionsStreamingUsageCompat: false,
|
|
349
|
-
usesExplicitProxyLikeEndpoint: false,
|
|
350
|
-
allowsAnthropicServiceTier: false
|
|
351
|
-
}),
|
|
352
|
-
resolveProviderRequestHeaders: ({ providerHeaders, callerHeaders, precedence }) => ({
|
|
353
|
-
...precedence === "caller-wins" ? providerHeaders : callerHeaders,
|
|
354
|
-
...precedence === "caller-wins" ? callerHeaders : providerHeaders
|
|
355
|
-
}),
|
|
356
|
-
resolveModelRequestTimeoutMs: () => void 0,
|
|
357
|
-
requiresManagedTransport: () => false,
|
|
358
|
-
inheritManagedTransport: (_source, target) => target,
|
|
359
|
-
transformTransportMessages: (messages, model, normalizeToolCallId) => transformMessages(messages, model, normalizeToolCallId),
|
|
360
|
-
registerCustomApi: queueCustomApiRegistration,
|
|
361
|
-
prepareGoogleSimpleCompletionModel: (_registry, model) => model,
|
|
362
|
-
logDebug: () => {},
|
|
363
|
-
logInfo: () => {},
|
|
364
|
-
logWarn: () => {}
|
|
365
|
-
};
|
|
366
|
-
let activeAiTransportHost = inertAiTransportHost;
|
|
367
|
-
/** Installs host implementations for the transport policy ports. */
|
|
368
|
-
function configureAiTransportHost(host) {
|
|
369
|
-
activeAiTransportHost = {
|
|
370
|
-
...inertAiTransportHost,
|
|
371
|
-
...host,
|
|
372
|
-
normalizeAnthropicInlineContentBlocks: host.normalizeAnthropicInlineContentBlocks ?? inertAiTransportHost.normalizeAnthropicInlineContentBlocks,
|
|
373
|
-
plugin: {
|
|
374
|
-
...inertAiTransportHost.plugin,
|
|
375
|
-
...host.plugin
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
const transportHost = activeAiTransportHost;
|
|
379
|
-
if (transportHost.registerCustomApi === inertAiTransportHost.registerCustomApi || pendingCustomApiRegistrations.length === 0) return;
|
|
380
|
-
const pending = pendingCustomApiRegistrations.splice(0);
|
|
381
|
-
for (const [index, registration] of pending.entries()) try {
|
|
382
|
-
transportHost.registerCustomApi(registration.registry, registration.api, registration.streamFn);
|
|
383
|
-
} catch (error) {
|
|
384
|
-
pendingCustomApiRegistrations.unshift(...pending.slice(index));
|
|
385
|
-
throw error;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
/** Returns the active transport host (inert defaults unless configured). */
|
|
389
|
-
function getAiTransportHost() {
|
|
390
|
-
return activeAiTransportHost;
|
|
391
|
-
}
|
|
392
|
-
/** Resolves sentinel substrings in custom headers at a no-fetch adapter boundary. */
|
|
393
|
-
function resolveAiTransportHeaderSentinels(headers) {
|
|
394
|
-
if (!headers) return;
|
|
395
|
-
const host = getAiTransportHost();
|
|
396
|
-
let resolvedHeaders;
|
|
397
|
-
for (const [name, value] of Object.entries(headers)) {
|
|
398
|
-
const resolved = host.resolveSecretSentinel(value);
|
|
399
|
-
if (resolved !== value) {
|
|
400
|
-
resolvedHeaders ??= { ...headers };
|
|
401
|
-
resolvedHeaders[name] = resolved;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return resolvedHeaders ?? headers;
|
|
405
|
-
}
|
|
406
|
-
//#endregion
|
|
407
|
-
export { normalizeLowercaseStringOrEmpty as _, ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK as a, isRecord as b, defaultsClaudeAdaptiveThinking as c, requiresClaudeAdaptiveThinking as d, resolveAnthropicThinkingEffort as f, hasNonEmptyString as g, usesClaudeStreamingRefusalContract as h, transformMessages as i, mapAnthropicStopReason as l, usesClaudeFable5MessagesContract as m, getAiTransportHost as n, ANTHROPIC_CLAUDE_CODE_VERSION as o, resolveModelBoundThinkingReplayMode as p, resolveAiTransportHeaderSentinels as r, applyClaudeRequestContract as s, configureAiTransportHost as t, prepareClaudeNoPrefillRequestContext as u, normalizeOptionalString as v, readStringValue as y };
|
|
@@ -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 };
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { E as Model, O as OpenAICompletionsCompat, n as Api } from "./types-CH7ReIcU.mjs";
|
|
2
|
-
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-Dn4_SZI2.mjs";
|
|
3
|
-
import { d as OpenAIApiReasoningEffort, f as OpenAIReasoningEffort, i as BaseOpenAIStreamOptions } from "./provider-options-C5kYML7i.mjs";
|
|
4
|
-
import { FunctionTool, ResponseCreateParamsStreaming, ResponseInput, ResponseReasoningItem } from "openai/resources/responses/responses.js";
|
|
5
|
-
|
|
6
|
-
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
7
|
-
type ProviderRequestCapabilities = AiProviderRequestCapabilities;
|
|
8
|
-
type OpenAICompletionsSessionAffinity = "none" | "openai" | "openrouter";
|
|
9
|
-
type OpenAICompletionsCompatDefaults = {
|
|
10
|
-
supportsStore: boolean;
|
|
11
|
-
supportsDeveloperRole: boolean;
|
|
12
|
-
supportsReasoningEffort: boolean;
|
|
13
|
-
supportsUsageInStreaming: boolean;
|
|
14
|
-
maxTokensField: "max_completion_tokens" | "max_tokens";
|
|
15
|
-
thinkingFormat: "openai" | "openrouter" | "deepseek" | "together" | "zai";
|
|
16
|
-
visibleReasoningDetailTypes: string[];
|
|
17
|
-
supportsStrictMode: boolean;
|
|
18
|
-
supportsJsonSchemaResponseFormat: boolean;
|
|
19
|
-
requiresReasoningContentOnAssistantMessages: boolean;
|
|
20
|
-
requiresNonEmptyUserOrAssistantMessage: boolean;
|
|
21
|
-
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
22
|
-
sessionAffinityFormat: Exclude<OpenAICompletionsSessionAffinity, "none">;
|
|
23
|
-
supportsLongCacheRetention: boolean;
|
|
24
|
-
};
|
|
25
|
-
type DetectedOpenAICompletionsCompat = {
|
|
26
|
-
capabilities: ProviderRequestCapabilities;
|
|
27
|
-
defaults: OpenAICompletionsCompatDefaults;
|
|
28
|
-
};
|
|
29
|
-
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat" | "openRouterRouting" | "sendSessionAffinityHeaders"> & {
|
|
30
|
-
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
31
|
-
openRouterRouting?: OpenAICompletionsCompat["openRouterRouting"];
|
|
32
|
-
sessionAffinity: OpenAICompletionsSessionAffinity;
|
|
33
|
-
visibleReasoningDetailTypes: string[];
|
|
34
|
-
requiresNonEmptyUserOrAssistantMessage: boolean;
|
|
35
|
-
};
|
|
36
|
-
/** Detects endpoint capabilities and defaults for an OpenAI-completions model. */
|
|
37
|
-
declare function detectOpenAICompletionsCompat(model: Pick<Model<"openai-completions">, "provider" | "baseUrl" | "id"> & {
|
|
38
|
-
compat?: {
|
|
39
|
-
supportsStore?: boolean;
|
|
40
|
-
} | null;
|
|
41
|
-
}, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): DetectedOpenAICompletionsCompat;
|
|
42
|
-
/** Applies explicit model overrides once on top of the canonical transport defaults. */
|
|
43
|
-
declare function resolveOpenAICompletionsCompat(model: Model<"openai-completions">, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): ResolvedOpenAICompletionsCompat;
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region packages/ai/src/transports/openai-responses-contracts.d.ts
|
|
46
|
-
declare const OPENAI_RESPONSES_REASONING_REPLAY_META_KEY = "__openclaw_replay";
|
|
47
|
-
type OpenAIResponsesReasoningReplayMetadata = {
|
|
48
|
-
v: 1;
|
|
49
|
-
source: "openai-responses";
|
|
50
|
-
provider: string;
|
|
51
|
-
api: Api;
|
|
52
|
-
model: string;
|
|
53
|
-
baseUrlHash?: string;
|
|
54
|
-
sessionHash?: string;
|
|
55
|
-
authProfileHash?: string;
|
|
56
|
-
};
|
|
57
|
-
type ReplayableResponseReasoningItem = Omit<ResponseReasoningItem, "id"> & {
|
|
58
|
-
id?: string;
|
|
59
|
-
[OPENAI_RESPONSES_REASONING_REPLAY_META_KEY]?: OpenAIResponsesReasoningReplayMetadata;
|
|
60
|
-
};
|
|
61
|
-
type OpenAIResponsesOptions = BaseOpenAIStreamOptions & {
|
|
62
|
-
reasoning?: OpenAIReasoningEffort;
|
|
63
|
-
reasoningEffort?: OpenAIReasoningEffort;
|
|
64
|
-
reasoningSummary?: "auto" | "detailed" | "concise" | null;
|
|
65
|
-
replayResponsesItemIds?: boolean;
|
|
66
|
-
serviceTier?: ResponseCreateParamsStreaming["service_tier"];
|
|
67
|
-
toolChoice?: ResponseCreateParamsStreaming["tool_choice"];
|
|
68
|
-
};
|
|
69
|
-
type ResponsesPromptObservation = {
|
|
70
|
-
egress: "responses-sdk" | "native-codex-websocket" | "native-codex-sse";
|
|
71
|
-
payloadVariant: "initial" | "encrypted-content-retry";
|
|
72
|
-
promptSource: "instructions" | "input.developer" | "input.system" | "missing";
|
|
73
|
-
expectedChars: number;
|
|
74
|
-
observedChars: number;
|
|
75
|
-
matchesAssembledPrompt: boolean;
|
|
76
|
-
};
|
|
77
|
-
type ResponsesPromptObserver = (observation: ResponsesPromptObservation) => void;
|
|
78
|
-
declare const responsesPromptObserver: {
|
|
79
|
-
set(options: object, observer: ResponsesPromptObserver): void;
|
|
80
|
-
get(options: object): ResponsesPromptObserver | undefined;
|
|
81
|
-
copy(source: object | undefined, target: object): void;
|
|
82
|
-
};
|
|
83
|
-
type OpenAIResponsesReplayContext = {
|
|
84
|
-
provider: string;
|
|
85
|
-
api: Api;
|
|
86
|
-
model: string;
|
|
87
|
-
baseUrlHash?: string;
|
|
88
|
-
sessionHash?: string;
|
|
89
|
-
authProfileHash?: string;
|
|
90
|
-
};
|
|
91
|
-
type OpenAIResponsesRequestParams = {
|
|
92
|
-
model: string;
|
|
93
|
-
input: ResponseInput;
|
|
94
|
-
stream: true;
|
|
95
|
-
instructions?: string;
|
|
96
|
-
prompt_cache_key?: string;
|
|
97
|
-
prompt_cache_retention?: "24h";
|
|
98
|
-
metadata?: Record<string, string>;
|
|
99
|
-
store?: boolean;
|
|
100
|
-
max_output_tokens?: number;
|
|
101
|
-
temperature?: number;
|
|
102
|
-
top_p?: number;
|
|
103
|
-
text?: ResponseCreateParamsStreaming["text"];
|
|
104
|
-
service_tier?: ResponseCreateParamsStreaming["service_tier"];
|
|
105
|
-
tools?: FunctionTool[];
|
|
106
|
-
tool_choice?: ResponseCreateParamsStreaming["tool_choice"];
|
|
107
|
-
reasoning?: {
|
|
108
|
-
effort: OpenAIApiReasoningEffort;
|
|
109
|
-
} | {
|
|
110
|
-
effort: OpenAIApiReasoningEffort;
|
|
111
|
-
summary: NonNullable<OpenAIResponsesOptions["reasoningSummary"]>;
|
|
112
|
-
};
|
|
113
|
-
include?: string[];
|
|
114
|
-
};
|
|
115
|
-
//#endregion
|
|
116
|
-
export { ReplayableResponseReasoningItem as a, ResolvedOpenAICompletionsCompat as c, OpenAIResponsesRequestParams as i, detectOpenAICompletionsCompat as l, OpenAIResponsesReasoningReplayMetadata as n, ResponsesPromptObservation as o, OpenAIResponsesReplayContext as r, responsesPromptObserver as s, OpenAIResponsesOptions as t, resolveOpenAICompletionsCompat as u };
|