@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,215 @@
|
|
|
1
|
+
import { g as isRecord, n as getAiTransportHost } from "./host-Dog2WQiR.mjs";
|
|
2
|
+
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-BwNu3nDi.mjs";
|
|
3
|
+
//#region packages/ai/src/transports/host-policy.ts
|
|
4
|
+
function buildGuardedModelFetch(model, timeoutMs, options) {
|
|
5
|
+
const host = getAiTransportHost();
|
|
6
|
+
if (options !== void 0) return host.buildModelFetch(model, timeoutMs, options) ?? globalThis.fetch;
|
|
7
|
+
if (timeoutMs !== void 0) return host.buildModelFetch(model, timeoutMs) ?? globalThis.fetch;
|
|
8
|
+
return host.buildModelFetch(model) ?? globalThis.fetch;
|
|
9
|
+
}
|
|
10
|
+
function resolveProviderEndpoint(baseUrl) {
|
|
11
|
+
return { endpointClass: getAiTransportHost().resolveProviderEndpointClass(baseUrl) };
|
|
12
|
+
}
|
|
13
|
+
function resolveProviderRequestCapabilities(input) {
|
|
14
|
+
return getAiTransportHost().resolveProviderRequestCapabilities(input);
|
|
15
|
+
}
|
|
16
|
+
function resolveProviderRequestPolicyConfig(input) {
|
|
17
|
+
return { headers: getAiTransportHost().resolveProviderRequestHeaders(input) };
|
|
18
|
+
}
|
|
19
|
+
function resolveModelRequestTimeoutMs(model, timeoutMs) {
|
|
20
|
+
return timeoutMs ?? getAiTransportHost().resolveModelRequestTimeoutMs(model);
|
|
21
|
+
}
|
|
22
|
+
function resolveOpenAIStrictToolSetting(model, options) {
|
|
23
|
+
return getAiTransportHost().resolveOpenAIStrictToolSetting(model, options);
|
|
24
|
+
}
|
|
25
|
+
function transformTransportMessages(messages, model, normalizeToolCallId, options) {
|
|
26
|
+
return getAiTransportHost().transformTransportMessages(messages, model, normalizeToolCallId, options);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region packages/ai/src/providers/openai-tool-projection.ts
|
|
30
|
+
function unreadableToolDiagnostic(toolIndex) {
|
|
31
|
+
return {
|
|
32
|
+
toolIndex,
|
|
33
|
+
violations: [`tool[${toolIndex}] is unreadable`]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Snapshots direct/custom tool descriptors before OpenAI payload construction. */
|
|
37
|
+
function projectOpenAITools(tools) {
|
|
38
|
+
let inputToolCount;
|
|
39
|
+
try {
|
|
40
|
+
inputToolCount = tools.length;
|
|
41
|
+
} catch {
|
|
42
|
+
return {
|
|
43
|
+
inputToolCount: 0,
|
|
44
|
+
tools: [],
|
|
45
|
+
diagnostics: [unreadableToolDiagnostic(0)]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const projectedTools = [];
|
|
49
|
+
const diagnostics = [];
|
|
50
|
+
for (let toolIndex = 0; toolIndex < inputToolCount; toolIndex += 1) {
|
|
51
|
+
let tool;
|
|
52
|
+
try {
|
|
53
|
+
const candidate = tools[toolIndex];
|
|
54
|
+
if (!candidate) {
|
|
55
|
+
diagnostics.push(unreadableToolDiagnostic(toolIndex));
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
tool = candidate;
|
|
59
|
+
} catch {
|
|
60
|
+
diagnostics.push(unreadableToolDiagnostic(toolIndex));
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
let name;
|
|
64
|
+
try {
|
|
65
|
+
name = tool.name;
|
|
66
|
+
} catch {
|
|
67
|
+
diagnostics.push({
|
|
68
|
+
toolIndex,
|
|
69
|
+
violations: [`tool[${toolIndex}].name is unreadable`]
|
|
70
|
+
});
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (typeof name !== "string" || !name) {
|
|
74
|
+
diagnostics.push({
|
|
75
|
+
toolIndex,
|
|
76
|
+
violations: [`tool[${toolIndex}].name is empty`]
|
|
77
|
+
});
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
let parameters;
|
|
81
|
+
try {
|
|
82
|
+
parameters = tool.parameters;
|
|
83
|
+
} catch {
|
|
84
|
+
diagnostics.push({
|
|
85
|
+
toolIndex,
|
|
86
|
+
toolName: name,
|
|
87
|
+
violations: [`${name}.parameters is unreadable`]
|
|
88
|
+
});
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const schemaProjection = projectRuntimeToolInputSchema(parameters ?? {}, `${name}.parameters`);
|
|
92
|
+
if (!isRecord(schemaProjection.schema) || schemaProjection.violations.length > 0) {
|
|
93
|
+
diagnostics.push({
|
|
94
|
+
toolIndex,
|
|
95
|
+
toolName: name,
|
|
96
|
+
violations: schemaProjection.violations.length > 0 ? schemaProjection.violations : [`${name}.parameters must be a JSON object schema`]
|
|
97
|
+
});
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
let descriptionValue;
|
|
101
|
+
try {
|
|
102
|
+
descriptionValue = tool.description;
|
|
103
|
+
} catch {}
|
|
104
|
+
const description = typeof descriptionValue === "string" ? descriptionValue : void 0;
|
|
105
|
+
projectedTools.push({
|
|
106
|
+
toolIndex,
|
|
107
|
+
name,
|
|
108
|
+
...description !== void 0 ? { description } : {},
|
|
109
|
+
parameters: schemaProjection.schema
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
inputToolCount,
|
|
114
|
+
tools: projectedTools,
|
|
115
|
+
diagnostics
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function requireProjectedFunction(name, projection, choiceLabel) {
|
|
119
|
+
if (!projection.tools.some((tool) => tool.name === name)) throw new Error(`${choiceLabel} requested unavailable tool "${name}" after schema conversion`);
|
|
120
|
+
}
|
|
121
|
+
/** Keeps Responses tool choices aligned with surviving function schemas. */
|
|
122
|
+
function reconcileOpenAIResponsesToolChoice(choice, projection) {
|
|
123
|
+
if (choice === "auto") return projection.tools.length > 0 ? choice : void 0;
|
|
124
|
+
if (choice === "required") {
|
|
125
|
+
if (projection.tools.length === 0) throw new Error("OpenAI Responses tool_choice requires a tool, but no tools survived schema conversion");
|
|
126
|
+
return choice;
|
|
127
|
+
}
|
|
128
|
+
if (choice === "none" || !isRecord(choice)) return choice;
|
|
129
|
+
const choiceType = choice.type;
|
|
130
|
+
if (choiceType === "function") {
|
|
131
|
+
const functionName = choice.name;
|
|
132
|
+
if (typeof functionName !== "string") return choice;
|
|
133
|
+
requireProjectedFunction(functionName, projection, "OpenAI Responses tool_choice");
|
|
134
|
+
return {
|
|
135
|
+
type: "function",
|
|
136
|
+
name: functionName
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (choiceType !== "allowed_tools") return choice;
|
|
140
|
+
const mode = choice.mode;
|
|
141
|
+
const tools = choice.tools;
|
|
142
|
+
if (mode !== "auto" && mode !== "required" || !Array.isArray(tools)) return choice;
|
|
143
|
+
const normalizedAllowedTools = [];
|
|
144
|
+
for (const tool of tools) {
|
|
145
|
+
if (!isRecord(tool) || tool.type !== "function") {
|
|
146
|
+
normalizedAllowedTools.push(tool);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const functionName = tool.name;
|
|
150
|
+
if (typeof functionName === "string" && projection.tools.some((projectedTool) => projectedTool.name === functionName)) normalizedAllowedTools.push({
|
|
151
|
+
type: "function",
|
|
152
|
+
name: functionName
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (normalizedAllowedTools.length === 0) {
|
|
156
|
+
if (mode === "auto") return "none";
|
|
157
|
+
throw new Error("OpenAI Responses tool_choice requires a tool, but no allowed tools survived schema conversion");
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
type: "allowed_tools",
|
|
161
|
+
mode,
|
|
162
|
+
tools: normalizedAllowedTools
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Keeps Chat Completions tool choices aligned with surviving function schemas. */
|
|
166
|
+
function reconcileOpenAICompletionsToolChoice(choice, projection) {
|
|
167
|
+
if (choice === "auto") return projection.tools.length > 0 ? choice : void 0;
|
|
168
|
+
if (choice === "required") {
|
|
169
|
+
if (projection.tools.length === 0) throw new Error("OpenAI Chat Completions tool_choice requires a tool, but no tools survived schema conversion");
|
|
170
|
+
return choice;
|
|
171
|
+
}
|
|
172
|
+
if (choice === "none" || !isRecord(choice)) return choice;
|
|
173
|
+
const choiceType = choice.type;
|
|
174
|
+
if (choiceType === "custom") throw new Error("OpenAI Chat Completions custom tool_choice is unsupported because this adapter emits function tools only");
|
|
175
|
+
if (choiceType === "function") {
|
|
176
|
+
const functionChoice = choice.function;
|
|
177
|
+
if (!isRecord(functionChoice)) return choice;
|
|
178
|
+
const functionName = functionChoice.name;
|
|
179
|
+
if (typeof functionName !== "string") return choice;
|
|
180
|
+
requireProjectedFunction(functionName, projection, "OpenAI Chat Completions tool_choice");
|
|
181
|
+
return {
|
|
182
|
+
type: "function",
|
|
183
|
+
function: { name: functionName }
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
if (choiceType !== "allowed_tools") return choice;
|
|
187
|
+
const allowedConfig = choice.allowed_tools;
|
|
188
|
+
if (!isRecord(allowedConfig)) return choice;
|
|
189
|
+
const mode = allowedConfig.mode;
|
|
190
|
+
const tools = allowedConfig.tools;
|
|
191
|
+
if (mode !== "auto" && mode !== "required" || !Array.isArray(tools)) return choice;
|
|
192
|
+
const normalizedAllowedTools = [];
|
|
193
|
+
for (const tool of tools) {
|
|
194
|
+
if (!isRecord(tool) || tool.type !== "function") continue;
|
|
195
|
+
const functionChoice = tool.function;
|
|
196
|
+
const functionName = isRecord(functionChoice) ? functionChoice.name : void 0;
|
|
197
|
+
if (typeof functionName === "string" && projection.tools.some((projectedTool) => projectedTool.name === functionName)) normalizedAllowedTools.push({
|
|
198
|
+
type: "function",
|
|
199
|
+
function: { name: functionName }
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (normalizedAllowedTools.length === 0) {
|
|
203
|
+
if (mode === "auto") return "none";
|
|
204
|
+
throw new Error("OpenAI Chat Completions tool_choice requires a tool, but no allowed tools survived schema conversion");
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
type: "allowed_tools",
|
|
208
|
+
allowed_tools: {
|
|
209
|
+
mode,
|
|
210
|
+
tools: normalizedAllowedTools
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { resolveModelRequestTimeoutMs as a, resolveProviderRequestCapabilities as c, buildGuardedModelFetch as i, resolveProviderRequestPolicyConfig as l, reconcileOpenAICompletionsToolChoice as n, resolveOpenAIStrictToolSetting as o, reconcileOpenAIResponsesToolChoice as r, resolveProviderEndpoint as s, projectOpenAITools as t, transformTransportMessages as u };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { z as StreamOptions } from "./types-bzp5k29J.mjs";
|
|
2
|
+
import OpenAI from "openai";
|
|
3
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
4
|
+
import { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
|
|
5
|
+
|
|
6
|
+
//#region packages/ai/src/providers/openai-reasoning-effort.d.ts
|
|
7
|
+
type OpenAIReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
8
|
+
type OpenAIApiReasoningEffort = OpenAIReasoningEffort | (string & {});
|
|
9
|
+
type OpenAIReasoningModel = {
|
|
10
|
+
provider?: unknown;
|
|
11
|
+
id?: unknown;
|
|
12
|
+
name?: unknown;
|
|
13
|
+
api?: unknown;
|
|
14
|
+
baseUrl?: unknown;
|
|
15
|
+
compat?: unknown;
|
|
16
|
+
};
|
|
17
|
+
/** Return whether a model is the GPT-5.4 mini family. */
|
|
18
|
+
declare function isOpenAIGpt54MiniModel(model: OpenAIReasoningModel): boolean;
|
|
19
|
+
/** Return whether a model is the GPT-5.5 family. */
|
|
20
|
+
declare function isOpenAIGpt55Model(model: OpenAIReasoningModel): boolean;
|
|
21
|
+
/** Return whether a model is the GPT-5.6 family. */
|
|
22
|
+
declare function isOpenAIGpt56Model(model: OpenAIReasoningModel): boolean;
|
|
23
|
+
/** Normalize user-facing reasoning effort names to API effort names. */
|
|
24
|
+
declare function normalizeOpenAIReasoningEffort(effort: string): string;
|
|
25
|
+
/** Resolve the reasoning efforts accepted by a specific OpenAI-compatible model. */
|
|
26
|
+
declare function resolveOpenAISupportedReasoningEfforts(model: OpenAIReasoningModel): readonly OpenAIApiReasoningEffort[];
|
|
27
|
+
/**
|
|
28
|
+
* Return whether a model accepts the temperature parameter. The GPT-5.6
|
|
29
|
+
* family rejects it with a 400; catalog compat can override per model.
|
|
30
|
+
*/
|
|
31
|
+
declare function supportsOpenAITemperature(model: OpenAIReasoningModel): boolean;
|
|
32
|
+
/** Return whether a model accepts a requested reasoning effort. */
|
|
33
|
+
declare function supportsOpenAIReasoningEffort(model: OpenAIReasoningModel, effort: string): boolean;
|
|
34
|
+
/** Resolve a requested reasoning effort to the closest value supported by the model. */
|
|
35
|
+
declare function resolveOpenAIReasoningEffortForModel(params: {
|
|
36
|
+
model: OpenAIReasoningModel;
|
|
37
|
+
effort: string;
|
|
38
|
+
fallbackMap?: Record<string, string>;
|
|
39
|
+
}): OpenAIApiReasoningEffort | undefined;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region packages/ai/src/providers/openai-tool-projection.d.ts
|
|
42
|
+
type OpenAIToolDescriptor = {
|
|
43
|
+
readonly name?: unknown;
|
|
44
|
+
readonly description?: unknown;
|
|
45
|
+
readonly parameters: unknown;
|
|
46
|
+
};
|
|
47
|
+
type OpenAIProjectedTool = {
|
|
48
|
+
readonly toolIndex: number;
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly description?: string;
|
|
51
|
+
readonly parameters: Record<string, unknown>;
|
|
52
|
+
};
|
|
53
|
+
type OpenAIToolProjectionDiagnostic = {
|
|
54
|
+
readonly toolIndex: number;
|
|
55
|
+
readonly toolName?: string;
|
|
56
|
+
readonly violations: readonly string[];
|
|
57
|
+
};
|
|
58
|
+
type OpenAIToolProjection = {
|
|
59
|
+
readonly inputToolCount: number;
|
|
60
|
+
readonly tools: readonly OpenAIProjectedTool[];
|
|
61
|
+
readonly diagnostics: readonly OpenAIToolProjectionDiagnostic[];
|
|
62
|
+
};
|
|
63
|
+
type OpenAIResponsesToolChoice = ResponseCreateParamsStreaming["tool_choice"];
|
|
64
|
+
type OpenAICompletionsSdkToolChoice = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming["tool_choice"];
|
|
65
|
+
type OpenAICompletionsToolChoice = Exclude<OpenAICompletionsSdkToolChoice, {
|
|
66
|
+
type: "custom";
|
|
67
|
+
}>;
|
|
68
|
+
/** Snapshots direct/custom tool descriptors before OpenAI payload construction. */
|
|
69
|
+
declare function projectOpenAITools(tools: readonly OpenAIToolDescriptor[]): OpenAIToolProjection;
|
|
70
|
+
/** Keeps Responses tool choices aligned with surviving function schemas. */
|
|
71
|
+
declare function reconcileOpenAIResponsesToolChoice(choice: OpenAIResponsesToolChoice, projection: OpenAIToolProjection): OpenAIResponsesToolChoice | undefined;
|
|
72
|
+
/** Keeps Chat Completions tool choices aligned with surviving function schemas. */
|
|
73
|
+
declare function reconcileOpenAICompletionsToolChoice(choice: OpenAICompletionsSdkToolChoice, projection: OpenAIToolProjection): OpenAICompletionsSdkToolChoice | undefined;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region packages/ai/src/provider-options.d.ts
|
|
76
|
+
type AnthropicEffort = "low" | "medium" | "high" | "xhigh" | "max";
|
|
77
|
+
type AnthropicThinkingDisplay = "summarized" | "omitted";
|
|
78
|
+
/** Provider options shared by the Anthropic provider and canonical transport. */
|
|
79
|
+
interface AnthropicOptions extends StreamOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Enable extended thinking.
|
|
82
|
+
* For Opus 4.6+ and Sonnet 4.6: uses adaptive thinking (model decides when/how much to think).
|
|
83
|
+
* For older models: uses budget-based thinking with thinkingBudgetTokens.
|
|
84
|
+
*/
|
|
85
|
+
thinkingEnabled?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Token budget for extended thinking (older models only).
|
|
88
|
+
* Ignored for Opus 4.6+ and Sonnet 4.6, which use adaptive thinking.
|
|
89
|
+
*/
|
|
90
|
+
thinkingBudgetTokens?: number;
|
|
91
|
+
/**
|
|
92
|
+
* Effort level for adaptive thinking (Opus 4.6+ and Sonnet 4.6).
|
|
93
|
+
* Controls how much thinking Claude allocates:
|
|
94
|
+
* - "max": Always thinks with no constraints (Opus 4.6 only)
|
|
95
|
+
* - "xhigh": Highest reasoning level (Opus 4.7+)
|
|
96
|
+
* - "high": Always thinks, deep reasoning (default)
|
|
97
|
+
* - "medium": Moderate thinking, may skip for simple queries
|
|
98
|
+
* - "low": Minimal thinking, skips for simple tasks
|
|
99
|
+
* Ignored for older models.
|
|
100
|
+
*/
|
|
101
|
+
effort?: AnthropicEffort;
|
|
102
|
+
/**
|
|
103
|
+
* Controls how thinking content is returned in API responses.
|
|
104
|
+
* - "summarized": Thinking blocks contain summarized thinking text (default here).
|
|
105
|
+
* - "omitted": Thinking blocks return an empty thinking field; the encrypted
|
|
106
|
+
* signature still travels back for multi-turn continuity. Use for faster
|
|
107
|
+
* time-to-first-text-token when your UI does not surface thinking.
|
|
108
|
+
*
|
|
109
|
+
* Note: Anthropic's API default for Claude Opus 4.7+ and Claude Mythos Preview
|
|
110
|
+
* is "omitted". We default to "summarized" here to keep behavior consistent
|
|
111
|
+
* with older Claude 4 models. Set this explicitly to "omitted" to opt in.
|
|
112
|
+
*/
|
|
113
|
+
thinkingDisplay?: AnthropicThinkingDisplay;
|
|
114
|
+
interleavedThinking?: boolean;
|
|
115
|
+
toolChoice?: "auto" | "any" | "none" | {
|
|
116
|
+
type: "tool";
|
|
117
|
+
name: string;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Pre-built Anthropic client instance. When provided, skips internal client
|
|
121
|
+
* construction entirely. Use this to inject alternative SDK clients such as
|
|
122
|
+
* `AnthropicVertex` that shares the same messaging API.
|
|
123
|
+
*/
|
|
124
|
+
client?: Anthropic;
|
|
125
|
+
}
|
|
126
|
+
/** Options shared by the OpenAI Responses and Completions transports. */
|
|
127
|
+
type BaseOpenAIStreamOptions = StreamOptions & {
|
|
128
|
+
topP?: number;
|
|
129
|
+
authProfileId?: string;
|
|
130
|
+
firstEventTimeoutMs?: number;
|
|
131
|
+
onFirstEventTimeout?: (reason: Error) => void;
|
|
132
|
+
openclawCodeModeToolSurface?: boolean;
|
|
133
|
+
frequencyPenalty?: number;
|
|
134
|
+
presencePenalty?: number;
|
|
135
|
+
seed?: number;
|
|
136
|
+
};
|
|
137
|
+
/** Superset retained under the provider's published compatibility type name. */
|
|
138
|
+
type OpenAICompletionsOptions = BaseOpenAIStreamOptions & {
|
|
139
|
+
toolChoice?: OpenAICompletionsToolChoice;
|
|
140
|
+
reasoning?: OpenAIReasoningEffort;
|
|
141
|
+
reasoningEffort?: OpenAIReasoningEffort;
|
|
142
|
+
};
|
|
143
|
+
//#endregion
|
|
144
|
+
export { resolveOpenAIReasoningEffortForModel as _, OpenAICompletionsOptions as a, supportsOpenAITemperature as b, projectOpenAITools as c, OpenAIApiReasoningEffort as d, OpenAIReasoningEffort as f, normalizeOpenAIReasoningEffort as g, isOpenAIGpt56Model as h, BaseOpenAIStreamOptions as i, reconcileOpenAICompletionsToolChoice as l, isOpenAIGpt55Model as m, AnthropicOptions as n, OpenAICompletionsToolChoice as o, isOpenAIGpt54MiniModel as p, AnthropicThinkingDisplay as r, OpenAIToolProjection as s, AnthropicEffort as t, reconcileOpenAIResponsesToolChoice as u, resolveOpenAISupportedReasoningEfforts as v, supportsOpenAIReasoningEffort as y };
|
package/dist/providers.mjs
CHANGED
|
@@ -64,35 +64,35 @@ function createLazyRegistration(api, importModule, select) {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
const registerBuiltIns = [
|
|
67
|
-
createLazyRegistration("anthropic-messages", () => import("./anthropic-
|
|
67
|
+
createLazyRegistration("anthropic-messages", () => import("./anthropic-CH4UUnZr.mjs").then((n) => n.t), (module) => ({
|
|
68
68
|
stream: module.streamAnthropic,
|
|
69
69
|
streamSimple: module.streamSimpleAnthropic
|
|
70
70
|
})),
|
|
71
|
-
createLazyRegistration("openai-completions", () => import("./openai-completions-
|
|
71
|
+
createLazyRegistration("openai-completions", () => import("./openai-completions-DsOxhOD1.mjs").then((n) => n.t), (module) => ({
|
|
72
72
|
stream: module.streamOpenAICompletions,
|
|
73
73
|
streamSimple: module.streamSimpleOpenAICompletions
|
|
74
74
|
})),
|
|
75
|
-
createLazyRegistration("mistral-conversations", () => import("./mistral-
|
|
75
|
+
createLazyRegistration("mistral-conversations", () => import("./mistral-CWmpvWYh.mjs"), (module) => ({
|
|
76
76
|
stream: module.streamMistral,
|
|
77
77
|
streamSimple: module.streamSimpleMistral
|
|
78
78
|
})),
|
|
79
|
-
createLazyRegistration("openai-responses", () => import("./openai-
|
|
79
|
+
createLazyRegistration("openai-responses", () => import("./openai-responses-BT7A3sLu.mjs").then((n) => n.t), (module) => ({
|
|
80
80
|
stream: module.streamOpenAIResponses,
|
|
81
81
|
streamSimple: module.streamSimpleOpenAIResponses
|
|
82
82
|
})),
|
|
83
|
-
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-
|
|
83
|
+
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-CImcwB83.mjs"), (module) => ({
|
|
84
84
|
stream: module.streamAzureOpenAIResponses,
|
|
85
85
|
streamSimple: module.streamSimpleAzureOpenAIResponses
|
|
86
86
|
})),
|
|
87
|
-
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-
|
|
87
|
+
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-B84Ibtrd.mjs"), (module) => ({
|
|
88
88
|
stream: module.streamOpenAICodexResponses,
|
|
89
89
|
streamSimple: module.streamSimpleOpenAICodexResponses
|
|
90
90
|
})),
|
|
91
|
-
createLazyRegistration("google-generative-ai", () => import("./google-
|
|
91
|
+
createLazyRegistration("google-generative-ai", () => import("./google-CtSg0iTS.mjs"), (module) => ({
|
|
92
92
|
stream: module.streamGoogle,
|
|
93
93
|
streamSimple: module.streamSimpleGoogle
|
|
94
94
|
})),
|
|
95
|
-
createLazyRegistration("google-vertex", () => import("./google-vertex-
|
|
95
|
+
createLazyRegistration("google-vertex", () => import("./google-vertex-31f1uS9L.mjs"), (module) => ({
|
|
96
96
|
stream: module.streamGoogleVertex,
|
|
97
97
|
streamSimple: module.streamSimpleGoogleVertex
|
|
98
98
|
}))
|
package/dist/{stream-first-event-timeout-C3OgBjIk.mjs → reasoning-tag-text-partitioner-CGDyLWUR.mjs}
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { n as clampTimerTimeoutMs } from "./number-coercion-DvG7SNMg.mjs";
|
|
3
2
|
//#region node_modules/mdast-util-to-string/lib/index.js
|
|
4
3
|
/**
|
|
5
4
|
* @typedef {import('mdast').Nodes} Nodes
|
|
@@ -12207,88 +12206,4 @@ function createReasoningTagTextPartitioner() {
|
|
|
12207
12206
|
};
|
|
12208
12207
|
}
|
|
12209
12208
|
//#endregion
|
|
12210
|
-
|
|
12211
|
-
function getFirstStreamEventTimeoutMs(options) {
|
|
12212
|
-
return options?.firstEventTimeoutMs;
|
|
12213
|
-
}
|
|
12214
|
-
function getFirstStreamEventTimeoutHandler(options) {
|
|
12215
|
-
return options?.onFirstEventTimeout;
|
|
12216
|
-
}
|
|
12217
|
-
function formatOptionalField(name, value) {
|
|
12218
|
-
return value ? ` ${name}=${value}` : "";
|
|
12219
|
-
}
|
|
12220
|
-
function createFirstStreamEventTimeoutError(context) {
|
|
12221
|
-
const stage = context.stage ? `${context.stage} ` : "";
|
|
12222
|
-
const details = [
|
|
12223
|
-
formatOptionalField("provider", context.provider),
|
|
12224
|
-
formatOptionalField("api", context.api),
|
|
12225
|
-
formatOptionalField("model", context.model)
|
|
12226
|
-
].join("");
|
|
12227
|
-
return /* @__PURE__ */ new Error(`${stage}HTTP stream opened but did not deliver a first SSE event within ${context.timeoutMs}ms after streaming headers (first-event timeout).${details}` + (context.hint ? ` ${context.hint}` : ""));
|
|
12228
|
-
}
|
|
12229
|
-
function createFirstStreamEventAbortController(parentSignal) {
|
|
12230
|
-
const controller = new AbortController();
|
|
12231
|
-
const abortFromParent = () => {
|
|
12232
|
-
if (!controller.signal.aborted) controller.abort(parentSignal?.reason);
|
|
12233
|
-
};
|
|
12234
|
-
if (parentSignal?.aborted) abortFromParent();
|
|
12235
|
-
else parentSignal?.addEventListener("abort", abortFromParent, { once: true });
|
|
12236
|
-
return {
|
|
12237
|
-
signal: controller.signal,
|
|
12238
|
-
abort(reason) {
|
|
12239
|
-
if (!controller.signal.aborted) controller.abort(reason);
|
|
12240
|
-
},
|
|
12241
|
-
dispose() {
|
|
12242
|
-
parentSignal?.removeEventListener("abort", abortFromParent);
|
|
12243
|
-
}
|
|
12244
|
-
};
|
|
12245
|
-
}
|
|
12246
|
-
function withFirstStreamEventTimeout(stream, context) {
|
|
12247
|
-
const timeoutMs = clampTimerTimeoutMs(context.timeoutMs);
|
|
12248
|
-
if (timeoutMs === void 0 || context.timeoutMs <= 0) return stream;
|
|
12249
|
-
const timeoutContext = {
|
|
12250
|
-
...context,
|
|
12251
|
-
timeoutMs
|
|
12252
|
-
};
|
|
12253
|
-
return { async *[Symbol.asyncIterator]() {
|
|
12254
|
-
const iterator = stream[Symbol.asyncIterator]();
|
|
12255
|
-
let timer;
|
|
12256
|
-
let completed = false;
|
|
12257
|
-
const clear = () => {
|
|
12258
|
-
if (timer) {
|
|
12259
|
-
clearTimeout(timer);
|
|
12260
|
-
timer = void 0;
|
|
12261
|
-
}
|
|
12262
|
-
};
|
|
12263
|
-
try {
|
|
12264
|
-
const first = await new Promise((resolve, reject) => {
|
|
12265
|
-
timer = setTimeout(() => {
|
|
12266
|
-
const timeoutError = createFirstStreamEventTimeoutError(timeoutContext);
|
|
12267
|
-
timeoutContext.onTimeout?.(timeoutError);
|
|
12268
|
-
timeoutContext.abort?.(timeoutError);
|
|
12269
|
-
reject(timeoutError);
|
|
12270
|
-
}, timeoutMs);
|
|
12271
|
-
timer.unref?.();
|
|
12272
|
-
iterator.next().then(resolve, reject);
|
|
12273
|
-
}).finally(clear);
|
|
12274
|
-
if (first.done) {
|
|
12275
|
-
completed = true;
|
|
12276
|
-
return;
|
|
12277
|
-
}
|
|
12278
|
-
yield first.value;
|
|
12279
|
-
for (;;) {
|
|
12280
|
-
const next = await iterator.next();
|
|
12281
|
-
if (next.done) {
|
|
12282
|
-
completed = true;
|
|
12283
|
-
return;
|
|
12284
|
-
}
|
|
12285
|
-
yield next.value;
|
|
12286
|
-
}
|
|
12287
|
-
} finally {
|
|
12288
|
-
clear();
|
|
12289
|
-
if (!completed) iterator.return?.().catch(() => void 0);
|
|
12290
|
-
}
|
|
12291
|
-
} };
|
|
12292
|
-
}
|
|
12293
|
-
//#endregion
|
|
12294
|
-
export { withFirstStreamEventTimeout as a, getFirstStreamEventTimeoutMs as i, createFirstStreamEventTimeoutError as n, createReasoningTagTextPartitioner as o, getFirstStreamEventTimeoutHandler as r, createFirstStreamEventAbortController as t };
|
|
12209
|
+
export { createReasoningTagTextPartitioner as t };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region packages/ai/src/providers/simple-options.ts
|
|
2
|
+
function buildBaseOptions(model, options, apiKey) {
|
|
3
|
+
const firstEventOptions = options;
|
|
4
|
+
return {
|
|
5
|
+
temperature: options?.temperature,
|
|
6
|
+
maxTokens: options?.maxTokens,
|
|
7
|
+
stop: options?.stop,
|
|
8
|
+
signal: options?.signal,
|
|
9
|
+
apiKey: apiKey || options?.apiKey,
|
|
10
|
+
transport: options?.transport,
|
|
11
|
+
cacheRetention: options?.cacheRetention,
|
|
12
|
+
sessionId: options?.sessionId,
|
|
13
|
+
promptCacheKey: options?.promptCacheKey,
|
|
14
|
+
headers: options?.headers,
|
|
15
|
+
onPayload: options?.onPayload,
|
|
16
|
+
onResponse: options?.onResponse,
|
|
17
|
+
timeoutMs: options?.timeoutMs,
|
|
18
|
+
firstEventTimeoutMs: firstEventOptions?.firstEventTimeoutMs,
|
|
19
|
+
onFirstEventTimeout: firstEventOptions?.onFirstEventTimeout,
|
|
20
|
+
maxRetries: options?.maxRetries,
|
|
21
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
22
|
+
metadata: options?.metadata
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function clampMaxTokensToModel(model, requestedMaxTokens) {
|
|
26
|
+
return requestedMaxTokens === void 0 ? void 0 : Math.max(1, Math.min(requestedMaxTokens, model.maxTokens));
|
|
27
|
+
}
|
|
28
|
+
function clampReasoning(effort) {
|
|
29
|
+
return effort === "xhigh" ? "high" : effort;
|
|
30
|
+
}
|
|
31
|
+
function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
|
|
32
|
+
const budgets = {
|
|
33
|
+
minimal: 1024,
|
|
34
|
+
low: 2048,
|
|
35
|
+
medium: 8192,
|
|
36
|
+
high: 16384,
|
|
37
|
+
max: 32768,
|
|
38
|
+
...customBudgets
|
|
39
|
+
};
|
|
40
|
+
const minOutputTokens = 1024;
|
|
41
|
+
let thinkingBudget = budgets[clampReasoning(reasoningLevel)];
|
|
42
|
+
const maxTokens = baseMaxTokens === void 0 ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
|
|
43
|
+
if (maxTokens <= thinkingBudget) thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
|
|
44
|
+
return {
|
|
45
|
+
maxTokens,
|
|
46
|
+
thinkingBudget
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { clampReasoning as i, buildBaseOptions as n, clampMaxTokensToModel as r, adjustMaxTokensForThinking as t };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { n as clampTimerTimeoutMs } from "./number-coercion-DvG7SNMg.mjs";
|
|
2
|
+
//#region packages/ai/src/utils/stream-first-event-timeout.ts
|
|
3
|
+
function getFirstStreamEventTimeoutMs(options) {
|
|
4
|
+
return options?.firstEventTimeoutMs;
|
|
5
|
+
}
|
|
6
|
+
function getFirstStreamEventTimeoutHandler(options) {
|
|
7
|
+
return options?.onFirstEventTimeout;
|
|
8
|
+
}
|
|
9
|
+
function formatOptionalField(name, value) {
|
|
10
|
+
return value ? ` ${name}=${value}` : "";
|
|
11
|
+
}
|
|
12
|
+
function createFirstStreamEventTimeoutError(context) {
|
|
13
|
+
const stage = context.stage ? `${context.stage} ` : "";
|
|
14
|
+
const details = [
|
|
15
|
+
formatOptionalField("provider", context.provider),
|
|
16
|
+
formatOptionalField("api", context.api),
|
|
17
|
+
formatOptionalField("model", context.model)
|
|
18
|
+
].join("");
|
|
19
|
+
return /* @__PURE__ */ new Error(`${stage}HTTP stream opened but did not deliver a first SSE event within ${context.timeoutMs}ms after streaming headers (first-event timeout).${details}` + (context.hint ? ` ${context.hint}` : ""));
|
|
20
|
+
}
|
|
21
|
+
function createFirstStreamEventAbortController(parentSignal) {
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
const abortFromParent = () => {
|
|
24
|
+
if (!controller.signal.aborted) controller.abort(parentSignal?.reason);
|
|
25
|
+
};
|
|
26
|
+
if (parentSignal?.aborted) abortFromParent();
|
|
27
|
+
else parentSignal?.addEventListener("abort", abortFromParent, { once: true });
|
|
28
|
+
return {
|
|
29
|
+
signal: controller.signal,
|
|
30
|
+
abort(reason) {
|
|
31
|
+
if (!controller.signal.aborted) controller.abort(reason);
|
|
32
|
+
},
|
|
33
|
+
dispose() {
|
|
34
|
+
parentSignal?.removeEventListener("abort", abortFromParent);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function withFirstStreamEventTimeout(stream, context) {
|
|
39
|
+
const timeoutMs = clampTimerTimeoutMs(context.timeoutMs);
|
|
40
|
+
if (timeoutMs === void 0 || context.timeoutMs <= 0) return stream;
|
|
41
|
+
const timeoutContext = {
|
|
42
|
+
...context,
|
|
43
|
+
timeoutMs
|
|
44
|
+
};
|
|
45
|
+
return { async *[Symbol.asyncIterator]() {
|
|
46
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
47
|
+
let timer;
|
|
48
|
+
let completed = false;
|
|
49
|
+
const clear = () => {
|
|
50
|
+
if (timer) {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
timer = void 0;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
const first = await new Promise((resolve, reject) => {
|
|
57
|
+
timer = setTimeout(() => {
|
|
58
|
+
const timeoutError = createFirstStreamEventTimeoutError(timeoutContext);
|
|
59
|
+
timeoutContext.onTimeout?.(timeoutError);
|
|
60
|
+
timeoutContext.abort?.(timeoutError);
|
|
61
|
+
reject(timeoutError);
|
|
62
|
+
}, timeoutMs);
|
|
63
|
+
timer.unref?.();
|
|
64
|
+
iterator.next().then(resolve, reject);
|
|
65
|
+
}).finally(clear);
|
|
66
|
+
if (first.done) {
|
|
67
|
+
completed = true;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
yield first.value;
|
|
71
|
+
for (;;) {
|
|
72
|
+
const next = await iterator.next();
|
|
73
|
+
if (next.done) {
|
|
74
|
+
completed = true;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
yield next.value;
|
|
78
|
+
}
|
|
79
|
+
} finally {
|
|
80
|
+
clear();
|
|
81
|
+
if (!completed) iterator.return?.().catch(() => void 0);
|
|
82
|
+
}
|
|
83
|
+
} };
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
export { withFirstStreamEventTimeout as a, getFirstStreamEventTimeoutMs as i, createFirstStreamEventTimeoutError as n, getFirstStreamEventTimeoutHandler as r, createFirstStreamEventAbortController as t };
|