@openclaw/ai 0.0.0 → 2026.7.1-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -3
- package/dist/anthropic-B5gZQM5X.mjs +1383 -0
- package/dist/api-registry-BXYnCOIR.d.mts +33 -0
- package/dist/azure-openai-responses-DNoSk8Uy.mjs +141 -0
- package/dist/azure-openai-responses-client-compat-a_O_GVQV.mjs +41 -0
- package/dist/diagnostics-BaTA9eVl.d.mts +25 -0
- package/dist/diagnostics-COpOtRwq.mjs +36 -0
- package/dist/diagnostics.d.mts +2 -0
- package/dist/diagnostics.mjs +2 -0
- package/dist/env-api-keys-CtMlqaQ4.mjs +171 -0
- package/dist/event-stream-0nZeBKl2.d.mts +26 -0
- package/dist/event-stream-ReMmOTzX.mjs +65 -0
- package/dist/event-stream.d.mts +2 -0
- package/dist/event-stream.mjs +2 -0
- package/dist/github-copilot-headers-BsH5cqGj.mjs +48 -0
- package/dist/google-D6sIQ1bL.mjs +55 -0
- package/dist/google-shared-ZPSl2qTi.mjs +548 -0
- package/dist/google-vertex-rDGwkoZK.mjs +111 -0
- package/dist/hash-CHgqbJmD.mjs +16 -0
- package/dist/headers-B_e4-1J0.mjs +9 -0
- package/dist/host-4t713IeR.mjs +37 -0
- package/dist/index-BoTnz8cv.d.mts +74 -0
- package/dist/index.d.mts +69 -0
- package/dist/index.mjs +7 -0
- package/dist/internal/anthropic.d.mts +234 -0
- package/dist/internal/anthropic.mjs +4 -0
- package/dist/internal/openai.d.mts +244 -0
- package/dist/internal/openai.mjs +7 -0
- package/dist/internal/runtime.d.mts +245 -0
- package/dist/internal/runtime.mjs +176 -0
- package/dist/internal/shared.d.mts +48 -0
- package/dist/internal/shared.mjs +3 -0
- package/dist/json-parse-DzNSIQBq.mjs +134 -0
- package/dist/llm-request-activity-CehVkZP-.mjs +35 -0
- package/dist/mistral-CePVNdws.mjs +563 -0
- package/dist/model-utils-DgmOla96.mjs +69 -0
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +39 -0
- package/dist/openai-chatgpt-responses-DVC4Bk_A.mjs +1068 -0
- package/dist/openai-completions-B9QLIq2U.mjs +844 -0
- package/dist/openai-responses-B6LylGxM.mjs +136 -0
- package/dist/openai-responses-shared-sj2YUPYc.mjs +1944 -0
- package/dist/openai-tool-projection-BknoV11q.mjs +195 -0
- package/dist/providers.d.mts +11 -0
- package/dist/providers.mjs +109 -0
- package/dist/reasoning-tag-text-partitioner-axhAdUwg.mjs +394 -0
- package/dist/sanitize-unicode-BZiVbGwK.d.mts +24 -0
- package/dist/sanitize-unicode-DT5o51ur.mjs +26 -0
- package/dist/src-CZ503MYJ.mjs +99 -0
- package/dist/stream-CREqxHgU.mjs +74 -0
- package/dist/stream-first-event-timeout-RjWszj8c.mjs +106 -0
- package/dist/streaming-byte-guard-BrbkbwUu.mjs +46 -0
- package/dist/tool-schema-json-projection-BXtBc_mD.mjs +74 -0
- package/dist/transform-messages-BhGF_fF4.mjs +507 -0
- package/dist/types-BVVgDSdq.d.mts +1 -0
- package/dist/types-DRgdPqaZ.d.mts +587 -0
- package/dist/types.d.mts +6 -0
- package/dist/types.mjs +5 -0
- package/dist/validation-BDMWOr8d.d.mts +9 -0
- package/dist/validation-FrchoOlv.mjs +199 -0
- package/dist/validation.d.mts +2 -0
- package/dist/validation.mjs +2 -0
- package/npm-shrinkwrap.json +645 -0
- package/package.json +74 -2
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { c as isRecord } from "./transform-messages-BhGF_fF4.mjs";
|
|
2
|
+
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-BXtBc_mD.mjs";
|
|
3
|
+
//#region packages/ai/src/providers/openai-prompt-cache.ts
|
|
4
|
+
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
5
|
+
const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
6
|
+
/** Truncates a prompt cache key by Unicode code point count. */
|
|
7
|
+
function clampOpenAIPromptCacheKey(key) {
|
|
8
|
+
if (key === void 0) return;
|
|
9
|
+
const chars = Array.from(key);
|
|
10
|
+
if (chars.length <= 64) return key;
|
|
11
|
+
return chars.slice(0, 64).join("");
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region packages/ai/src/providers/openai-tool-projection.ts
|
|
15
|
+
function unreadableToolDiagnostic(toolIndex) {
|
|
16
|
+
return {
|
|
17
|
+
toolIndex,
|
|
18
|
+
violations: [`tool[${toolIndex}] is unreadable`]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Snapshots direct/custom tool descriptors before OpenAI payload construction. */
|
|
22
|
+
function projectOpenAITools(tools) {
|
|
23
|
+
let inputToolCount;
|
|
24
|
+
try {
|
|
25
|
+
inputToolCount = tools.length;
|
|
26
|
+
} catch {
|
|
27
|
+
return {
|
|
28
|
+
inputToolCount: 0,
|
|
29
|
+
tools: [],
|
|
30
|
+
diagnostics: [unreadableToolDiagnostic(0)]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const projectedTools = [];
|
|
34
|
+
const diagnostics = [];
|
|
35
|
+
for (let toolIndex = 0; toolIndex < inputToolCount; toolIndex += 1) {
|
|
36
|
+
let tool;
|
|
37
|
+
try {
|
|
38
|
+
tool = tools[toolIndex];
|
|
39
|
+
} catch {
|
|
40
|
+
diagnostics.push(unreadableToolDiagnostic(toolIndex));
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
let name;
|
|
44
|
+
try {
|
|
45
|
+
name = tool.name;
|
|
46
|
+
} catch {
|
|
47
|
+
diagnostics.push({
|
|
48
|
+
toolIndex,
|
|
49
|
+
violations: [`tool[${toolIndex}].name is unreadable`]
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (typeof name !== "string" || !name) {
|
|
54
|
+
diagnostics.push({
|
|
55
|
+
toolIndex,
|
|
56
|
+
violations: [`tool[${toolIndex}].name is empty`]
|
|
57
|
+
});
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
let parameters;
|
|
61
|
+
try {
|
|
62
|
+
parameters = tool.parameters;
|
|
63
|
+
} catch {
|
|
64
|
+
diagnostics.push({
|
|
65
|
+
toolIndex,
|
|
66
|
+
toolName: name,
|
|
67
|
+
violations: [`${name}.parameters is unreadable`]
|
|
68
|
+
});
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const schemaProjection = projectRuntimeToolInputSchema(parameters ?? {}, `${name}.parameters`);
|
|
72
|
+
if (!isRecord(schemaProjection.schema) || schemaProjection.violations.length > 0) {
|
|
73
|
+
diagnostics.push({
|
|
74
|
+
toolIndex,
|
|
75
|
+
toolName: name,
|
|
76
|
+
violations: schemaProjection.violations.length > 0 ? schemaProjection.violations : [`${name}.parameters must be a JSON object schema`]
|
|
77
|
+
});
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
let descriptionValue;
|
|
81
|
+
try {
|
|
82
|
+
descriptionValue = tool.description;
|
|
83
|
+
} catch {}
|
|
84
|
+
const description = typeof descriptionValue === "string" ? descriptionValue : void 0;
|
|
85
|
+
projectedTools.push({
|
|
86
|
+
toolIndex,
|
|
87
|
+
name,
|
|
88
|
+
...description !== void 0 ? { description } : {},
|
|
89
|
+
parameters: schemaProjection.schema
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
inputToolCount,
|
|
94
|
+
tools: projectedTools,
|
|
95
|
+
diagnostics
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function requireProjectedFunction(name, projection, choiceLabel) {
|
|
99
|
+
if (!projection.tools.some((tool) => tool.name === name)) throw new Error(`${choiceLabel} requested unavailable tool "${name}" after schema conversion`);
|
|
100
|
+
}
|
|
101
|
+
/** Keeps Responses tool choices aligned with surviving function schemas. */
|
|
102
|
+
function reconcileOpenAIResponsesToolChoice(choice, projection) {
|
|
103
|
+
if (choice === "auto") return projection.tools.length > 0 ? choice : void 0;
|
|
104
|
+
if (choice === "required") {
|
|
105
|
+
if (projection.tools.length === 0) throw new Error("OpenAI Responses tool_choice requires a tool, but no tools survived schema conversion");
|
|
106
|
+
return choice;
|
|
107
|
+
}
|
|
108
|
+
if (choice === "none" || !isRecord(choice)) return choice;
|
|
109
|
+
const choiceType = choice.type;
|
|
110
|
+
if (choiceType === "function") {
|
|
111
|
+
const functionName = choice.name;
|
|
112
|
+
if (typeof functionName !== "string") return choice;
|
|
113
|
+
requireProjectedFunction(functionName, projection, "OpenAI Responses tool_choice");
|
|
114
|
+
return {
|
|
115
|
+
type: "function",
|
|
116
|
+
name: functionName
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (choiceType !== "allowed_tools") return choice;
|
|
120
|
+
const mode = choice.mode;
|
|
121
|
+
const tools = choice.tools;
|
|
122
|
+
if (mode !== "auto" && mode !== "required" || !Array.isArray(tools)) return choice;
|
|
123
|
+
const normalizedAllowedTools = [];
|
|
124
|
+
for (const tool of tools) {
|
|
125
|
+
if (!isRecord(tool) || tool.type !== "function") {
|
|
126
|
+
normalizedAllowedTools.push(tool);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const functionName = tool.name;
|
|
130
|
+
if (typeof functionName === "string" && projection.tools.some((projectedTool) => projectedTool.name === functionName)) normalizedAllowedTools.push({
|
|
131
|
+
type: "function",
|
|
132
|
+
name: functionName
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (normalizedAllowedTools.length === 0) {
|
|
136
|
+
if (mode === "auto") return "none";
|
|
137
|
+
throw new Error("OpenAI Responses tool_choice requires a tool, but no allowed tools survived schema conversion");
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
type: "allowed_tools",
|
|
141
|
+
mode,
|
|
142
|
+
tools: normalizedAllowedTools
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** Keeps Chat Completions tool choices aligned with surviving function schemas. */
|
|
146
|
+
function reconcileOpenAICompletionsToolChoice(choice, projection) {
|
|
147
|
+
if (choice === "auto") return projection.tools.length > 0 ? choice : void 0;
|
|
148
|
+
if (choice === "required") {
|
|
149
|
+
if (projection.tools.length === 0) throw new Error("OpenAI Chat Completions tool_choice requires a tool, but no tools survived schema conversion");
|
|
150
|
+
return choice;
|
|
151
|
+
}
|
|
152
|
+
if (choice === "none" || !isRecord(choice)) return choice;
|
|
153
|
+
const choiceType = choice.type;
|
|
154
|
+
if (choiceType === "custom") throw new Error("OpenAI Chat Completions custom tool_choice is unsupported because this adapter emits function tools only");
|
|
155
|
+
if (choiceType === "function") {
|
|
156
|
+
const functionChoice = choice.function;
|
|
157
|
+
if (!isRecord(functionChoice)) return choice;
|
|
158
|
+
const functionName = functionChoice.name;
|
|
159
|
+
if (typeof functionName !== "string") return choice;
|
|
160
|
+
requireProjectedFunction(functionName, projection, "OpenAI Chat Completions tool_choice");
|
|
161
|
+
return {
|
|
162
|
+
type: "function",
|
|
163
|
+
function: { name: functionName }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (choiceType !== "allowed_tools") return choice;
|
|
167
|
+
const allowedConfig = choice.allowed_tools;
|
|
168
|
+
if (!isRecord(allowedConfig)) return choice;
|
|
169
|
+
const mode = allowedConfig.mode;
|
|
170
|
+
const tools = allowedConfig.tools;
|
|
171
|
+
if (mode !== "auto" && mode !== "required" || !Array.isArray(tools)) return choice;
|
|
172
|
+
const normalizedAllowedTools = [];
|
|
173
|
+
for (const tool of tools) {
|
|
174
|
+
if (!isRecord(tool) || tool.type !== "function") continue;
|
|
175
|
+
const functionChoice = tool.function;
|
|
176
|
+
const functionName = isRecord(functionChoice) ? functionChoice.name : void 0;
|
|
177
|
+
if (typeof functionName === "string" && projection.tools.some((projectedTool) => projectedTool.name === functionName)) normalizedAllowedTools.push({
|
|
178
|
+
type: "function",
|
|
179
|
+
function: { name: functionName }
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (normalizedAllowedTools.length === 0) {
|
|
183
|
+
if (mode === "auto") return "none";
|
|
184
|
+
throw new Error("OpenAI Chat Completions tool_choice requires a tool, but no allowed tools survived schema conversion");
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
type: "allowed_tools",
|
|
188
|
+
allowed_tools: {
|
|
189
|
+
mode,
|
|
190
|
+
tools: normalizedAllowedTools
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { clampOpenAIPromptCacheKey as a, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH as i, reconcileOpenAICompletionsToolChoice as n, reconcileOpenAIResponsesToolChoice as r, projectOpenAITools as t };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { n as ApiRegistry } from "./api-registry-BXYnCOIR.mjs";
|
|
2
|
+
|
|
3
|
+
//#region packages/ai/src/providers/register-builtins.d.ts
|
|
4
|
+
/** Source id used for built-in API provider registrations. */
|
|
5
|
+
declare const BUILT_IN_API_PROVIDER_SOURCE_ID = "core:built-in";
|
|
6
|
+
/** Registers every built-in API provider in one runtime registry. */
|
|
7
|
+
declare function registerBuiltInApiProviders(registry: ApiRegistry): void;
|
|
8
|
+
/** Restores the built-in provider registry state for tests. */
|
|
9
|
+
declare function resetApiProviders(registry: ApiRegistry): void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { BUILT_IN_API_PROVIDER_SOURCE_ID, registerBuiltInApiProviders, resetApiProviders };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-ReMmOTzX.mjs";
|
|
2
|
+
//#region packages/ai/src/providers/register-builtins.ts
|
|
3
|
+
/** Source id used for built-in API provider registrations. */
|
|
4
|
+
const BUILT_IN_API_PROVIDER_SOURCE_ID = "core:built-in";
|
|
5
|
+
function forwardStream(target, source) {
|
|
6
|
+
(async () => {
|
|
7
|
+
for await (const event of source) target.push(event);
|
|
8
|
+
target.end();
|
|
9
|
+
})();
|
|
10
|
+
}
|
|
11
|
+
function createLazyLoadErrorMessage(model, error) {
|
|
12
|
+
return {
|
|
13
|
+
role: "assistant",
|
|
14
|
+
content: [],
|
|
15
|
+
api: model.api,
|
|
16
|
+
provider: model.provider,
|
|
17
|
+
model: model.id,
|
|
18
|
+
usage: {
|
|
19
|
+
input: 0,
|
|
20
|
+
output: 0,
|
|
21
|
+
cacheRead: 0,
|
|
22
|
+
cacheWrite: 0,
|
|
23
|
+
totalTokens: 0,
|
|
24
|
+
cost: {
|
|
25
|
+
input: 0,
|
|
26
|
+
output: 0,
|
|
27
|
+
cacheRead: 0,
|
|
28
|
+
cacheWrite: 0,
|
|
29
|
+
total: 0
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
stopReason: "error",
|
|
33
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
34
|
+
timestamp: Date.now()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function createLazyStream(load, select) {
|
|
38
|
+
return (model, context, options) => {
|
|
39
|
+
const outer = new AssistantMessageEventStream();
|
|
40
|
+
load().then((streams) => forwardStream(outer, select(streams)(model, context, options))).catch((error) => {
|
|
41
|
+
const message = createLazyLoadErrorMessage(model, error);
|
|
42
|
+
outer.push({
|
|
43
|
+
type: "error",
|
|
44
|
+
reason: "error",
|
|
45
|
+
error: message
|
|
46
|
+
});
|
|
47
|
+
outer.end(message);
|
|
48
|
+
});
|
|
49
|
+
return outer;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function createLazyRegistration(api, importModule, select) {
|
|
53
|
+
let streamsPromise;
|
|
54
|
+
const load = () => streamsPromise ??= importModule().then(select);
|
|
55
|
+
const stream = createLazyStream(load, (streams) => streams.stream);
|
|
56
|
+
const streamSimple = createLazyStream(load, (streams) => streams.streamSimple);
|
|
57
|
+
return (registry) => {
|
|
58
|
+
registry.registerApiProvider({
|
|
59
|
+
api,
|
|
60
|
+
stream,
|
|
61
|
+
streamSimple
|
|
62
|
+
}, BUILT_IN_API_PROVIDER_SOURCE_ID);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const registerBuiltIns = [
|
|
66
|
+
createLazyRegistration("anthropic-messages", () => import("./anthropic-B5gZQM5X.mjs").then((n) => n.t), (module) => ({
|
|
67
|
+
stream: module.streamAnthropic,
|
|
68
|
+
streamSimple: module.streamSimpleAnthropic
|
|
69
|
+
})),
|
|
70
|
+
createLazyRegistration("openai-completions", () => import("./openai-completions-B9QLIq2U.mjs").then((n) => n.n), (module) => ({
|
|
71
|
+
stream: module.streamOpenAICompletions,
|
|
72
|
+
streamSimple: module.streamSimpleOpenAICompletions
|
|
73
|
+
})),
|
|
74
|
+
createLazyRegistration("mistral-conversations", () => import("./mistral-CePVNdws.mjs"), (module) => ({
|
|
75
|
+
stream: module.streamMistral,
|
|
76
|
+
streamSimple: module.streamSimpleMistral
|
|
77
|
+
})),
|
|
78
|
+
createLazyRegistration("openai-responses", () => import("./openai-responses-B6LylGxM.mjs").then((n) => n.t), (module) => ({
|
|
79
|
+
stream: module.streamOpenAIResponses,
|
|
80
|
+
streamSimple: module.streamSimpleOpenAIResponses
|
|
81
|
+
})),
|
|
82
|
+
createLazyRegistration("azure-openai-responses", () => import("./azure-openai-responses-DNoSk8Uy.mjs"), (module) => ({
|
|
83
|
+
stream: module.streamAzureOpenAIResponses,
|
|
84
|
+
streamSimple: module.streamSimpleAzureOpenAIResponses
|
|
85
|
+
})),
|
|
86
|
+
createLazyRegistration("openai-chatgpt-responses", () => import("./openai-chatgpt-responses-DVC4Bk_A.mjs"), (module) => ({
|
|
87
|
+
stream: module.streamOpenAICodexResponses,
|
|
88
|
+
streamSimple: module.streamSimpleOpenAICodexResponses
|
|
89
|
+
})),
|
|
90
|
+
createLazyRegistration("google-generative-ai", () => import("./google-D6sIQ1bL.mjs"), (module) => ({
|
|
91
|
+
stream: module.streamGoogle,
|
|
92
|
+
streamSimple: module.streamSimpleGoogle
|
|
93
|
+
})),
|
|
94
|
+
createLazyRegistration("google-vertex", () => import("./google-vertex-rDGwkoZK.mjs"), (module) => ({
|
|
95
|
+
stream: module.streamGoogleVertex,
|
|
96
|
+
streamSimple: module.streamSimpleGoogleVertex
|
|
97
|
+
}))
|
|
98
|
+
];
|
|
99
|
+
/** Registers every built-in API provider in one runtime registry. */
|
|
100
|
+
function registerBuiltInApiProviders(registry) {
|
|
101
|
+
for (const register of registerBuiltIns) register(registry);
|
|
102
|
+
}
|
|
103
|
+
/** Restores the built-in provider registry state for tests. */
|
|
104
|
+
function resetApiProviders(registry) {
|
|
105
|
+
registry.unregisterApiProviders(BUILT_IN_API_PROVIDER_SOURCE_ID);
|
|
106
|
+
registerBuiltInApiProviders(registry);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { BUILT_IN_API_PROVIDER_SOURCE_ID, registerBuiltInApiProviders, resetApiProviders };
|