@openclaw/ai 2026.7.2-beta.7 → 2026.8.1-beta.1
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-CE-7SkF6.mjs} +28 -191
- package/dist/{anthropic-usage-DWU-x8MI.mjs → anthropic-usage-Ma4iX6uG.mjs} +262 -4
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-EpJoVwM1.d.mts} +1 -1
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-Cc_kasye.mjs} +4 -4
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-CEV9t6da.mjs} +10 -2
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-DRmDMRHH.d.mts} +2 -1
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CtSg0iTS.mjs → google-CGQu21aw.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-Cq2UKx1l.mjs} +151 -85
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-CusxWzvE.mjs} +10 -7
- package/dist/{host-Dog2WQiR.mjs → host-Bl7Kgddo.mjs} +40 -2
- package/dist/{host-B9GUmcra.d.mts → host-Dn4_SZI2.d.mts} +2 -2
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/internal/anthropic.d.mts +19 -3
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai.d.mts +4 -4
- package/dist/internal/openai.mjs +7 -7
- package/dist/internal/runtime.d.mts +2 -2
- package/dist/internal/runtime.mjs +3 -3
- package/dist/internal/shared.d.mts +1 -1
- package/dist/internal/shared.mjs +3 -4
- package/dist/{mistral-CWmpvWYh.mjs → mistral-Dx6VzNjf.mjs} +25 -9
- package/dist/model-utils-Dau5dlgm.mjs +64 -0
- package/dist/number-coercion-1Miyb5MO.mjs +66 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-SC9m0FSf.mjs} +94 -131
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-BaIpl93j.mjs} +47 -66
- package/dist/{openai-reasoning-compat-YgeLncHw.mjs → openai-reasoning-compat-DKebnIBL.mjs} +147 -6
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-Bdx3V_Yu.mjs} +6 -22
- package/dist/openai-responses-contracts-BBKBfAqR.d.mts +116 -0
- package/dist/openai-responses-prompt-observer-internal-DDZPxRfr.mjs +46 -0
- package/dist/{openai-responses-shared-pXl6Wd8S.mjs → openai-responses-shared-CCyMvg7M.mjs} +21 -10
- package/dist/{openai-responses-stream-internal-Cw5txaGW.mjs → openai-responses-stream-internal-Bl8YyVtF.mjs} +244 -81
- package/dist/{openai-tool-projection-OhX64DoP.mjs → openai-transport-shared-Cipt7egQ.mjs} +129 -29
- package/dist/{provider-error-CAEvRjry.mjs → provider-error-DI0Ts28U.mjs} +1 -1
- package/dist/{provider-options-D8bB3z9b.d.mts → provider-options-C5kYML7i.d.mts} +1 -1
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +9 -9
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-BIBomOGq.mjs} +1 -1
- package/dist/{tool-result-text-CTpIRbYd.mjs → tool-result-text-Dvkp2Dus.mjs} +51 -2
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → tool-schema-json-projection-B1b-XCn5.mjs} +28 -1
- package/dist/transform-messages-DfjpNXNQ.mjs +2 -0
- package/dist/{transport-stream-shared-D81p90xq.mjs → transport-stream-shared-CPNv7A3r.mjs} +4 -4
- package/dist/transports.d.mts +41 -73
- package/dist/transports.mjs +317 -601
- package/dist/{types-bzp5k29J.d.mts → types-CH7ReIcU.d.mts} +4 -0
- package/dist/types.d.mts +3 -3
- package/dist/types.mjs +1 -1
- package/dist/{validation-B-j7cOYp.d.mts → validation-CcPcuEbR.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +1 -1
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-completions-compat-DBWjXoMZ.d.mts +0 -43
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- package/dist/transform-messages-C8mBqZxF.mjs +0 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as normalizeLowercaseStringOrEmpty, b as isRecord, i as transformMessages } from "./host-Bl7Kgddo.mjs";
|
|
2
2
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
3
|
-
import { a as isImageWithMediaPayload,
|
|
4
|
-
import {
|
|
3
|
+
import { a as isImageWithMediaPayload, h as stripSystemPromptCacheBoundary, o as truncateUtf16Safe, r as extractToolResultText, t as describeToolResultMediaPlaceholder } from "./tool-result-text-Dvkp2Dus.mjs";
|
|
4
|
+
import { o as resolveProviderRequestCapabilities } from "./tool-schema-json-projection-B1b-XCn5.mjs";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
5
6
|
//#region packages/ai/src/utils/assistant-text-phase.ts
|
|
6
7
|
function isAssistantTextPhaseBlock(block) {
|
|
7
8
|
if (!block || typeof block !== "object") return false;
|
|
@@ -196,7 +197,7 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
196
197
|
const params = [];
|
|
197
198
|
const normalizeToolCallId = (id) => {
|
|
198
199
|
if (id.includes("|")) return id.slice(0, id.indexOf("|")).replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 40);
|
|
199
|
-
if (model.provider === "openai") return id.length > 40 ? id
|
|
200
|
+
if (model.provider === "openai") return id.length > 40 ? truncateUtf16Safe(id, 40) : id;
|
|
200
201
|
return id;
|
|
201
202
|
};
|
|
202
203
|
const transformedMessages = transformMessages(context.messages, model, (id) => normalizeToolCallId(id));
|
|
@@ -253,7 +254,7 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
253
254
|
type: "text",
|
|
254
255
|
text: sanitizeSurrogates(block.text)
|
|
255
256
|
}));
|
|
256
|
-
const assistantText = assistantTextParts.map((part) => part.text).join("");
|
|
257
|
+
const assistantText = assistantTextParts.map((part) => part.text).join("\n");
|
|
257
258
|
const nonEmptyThinkingBlocks = msg.content.filter(isThinkingContentBlock).filter((block) => block.thinking.trim().length > 0);
|
|
258
259
|
if (nonEmptyThinkingBlocks.length > 0) if (compat.requiresThinkingAsText) assistantMsg.content = [{
|
|
259
260
|
type: "text",
|
|
@@ -338,6 +339,146 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
338
339
|
return params;
|
|
339
340
|
}
|
|
340
341
|
//#endregion
|
|
342
|
+
//#region packages/ai/src/providers/openai-completions-tool-calls.ts
|
|
343
|
+
const MAX_BUFFERED_LEGACY_TOOL_CALL_ARGUMENT_BYTES = 256e3;
|
|
344
|
+
const MAX_BUFFERED_LEGACY_FOLLOWING_DELTA_BYTES = 256e3;
|
|
345
|
+
const MAX_BUFFERED_LEGACY_FOLLOWING_DELTAS = 1024;
|
|
346
|
+
/** Normalize the SDK's legacy single-function lane into its modern tool-call shape. */
|
|
347
|
+
function createOpenAICompletionsToolCallDeltaNormalizer() {
|
|
348
|
+
let sawModernToolCall = false;
|
|
349
|
+
let pendingLegacyArgumentBytes = 0;
|
|
350
|
+
let pendingFollowingDeltaBytes = 0;
|
|
351
|
+
let pendingLegacyToolCall;
|
|
352
|
+
const pendingFollowingDeltas = [];
|
|
353
|
+
const takePendingFollowingDeltas = () => {
|
|
354
|
+
pendingFollowingDeltaBytes = 0;
|
|
355
|
+
return pendingFollowingDeltas.splice(0).map((delta) => ({
|
|
356
|
+
delta,
|
|
357
|
+
toolCalls: []
|
|
358
|
+
}));
|
|
359
|
+
};
|
|
360
|
+
const bufferFollowingDelta = (delta) => {
|
|
361
|
+
const nextDeltaBytes = Buffer.byteLength(JSON.stringify(delta), "utf8");
|
|
362
|
+
if (pendingFollowingDeltaBytes + nextDeltaBytes > MAX_BUFFERED_LEGACY_FOLLOWING_DELTA_BYTES || pendingFollowingDeltas.length >= MAX_BUFFERED_LEGACY_FOLLOWING_DELTAS) throw new Error("Exceeded legacy tool-call content buffer limit");
|
|
363
|
+
pendingFollowingDeltaBytes += nextDeltaBytes;
|
|
364
|
+
pendingFollowingDeltas.push(delta);
|
|
365
|
+
};
|
|
366
|
+
const withoutToolCalls = (delta) => {
|
|
367
|
+
const ordinaryDelta = { ...delta };
|
|
368
|
+
delete ordinaryDelta.function_call;
|
|
369
|
+
delete ordinaryDelta.tool_calls;
|
|
370
|
+
return ordinaryDelta;
|
|
371
|
+
};
|
|
372
|
+
const hasObservableContent = (value) => {
|
|
373
|
+
if (typeof value === "string") return value.length > 0;
|
|
374
|
+
if (Array.isArray(value)) return value.some(hasObservableContent);
|
|
375
|
+
if (isRecord(value)) return Object.entries(value).some(([field, nestedValue]) => field !== "type" && field !== "id" && field !== "index" && hasObservableContent(nestedValue));
|
|
376
|
+
return false;
|
|
377
|
+
};
|
|
378
|
+
const hasOrdinaryContent = (delta) => Object.entries(delta).some(([field, value]) => field !== "role" && hasObservableContent(value));
|
|
379
|
+
return (delta, finishReason) => {
|
|
380
|
+
const ordinaryDelta = withoutToolCalls(delta);
|
|
381
|
+
if (delta.tool_calls && delta.tool_calls.length > 0) {
|
|
382
|
+
const precedingDeltas = takePendingFollowingDeltas();
|
|
383
|
+
sawModernToolCall = true;
|
|
384
|
+
pendingLegacyArgumentBytes = 0;
|
|
385
|
+
pendingLegacyToolCall = void 0;
|
|
386
|
+
return [...precedingDeltas, {
|
|
387
|
+
delta: ordinaryDelta,
|
|
388
|
+
toolCalls: delta.tool_calls
|
|
389
|
+
}];
|
|
390
|
+
}
|
|
391
|
+
const functionCall = delta.function_call;
|
|
392
|
+
if (sawModernToolCall) return [{
|
|
393
|
+
delta: ordinaryDelta,
|
|
394
|
+
toolCalls: []
|
|
395
|
+
}];
|
|
396
|
+
const hadPendingLegacyCall = pendingLegacyToolCall !== void 0;
|
|
397
|
+
const leadingDeltas = [];
|
|
398
|
+
if (hasOrdinaryContent(ordinaryDelta)) if (hadPendingLegacyCall) bufferFollowingDelta(ordinaryDelta);
|
|
399
|
+
else leadingDeltas.push({
|
|
400
|
+
delta: ordinaryDelta,
|
|
401
|
+
toolCalls: []
|
|
402
|
+
});
|
|
403
|
+
if (functionCall && (functionCall.name || functionCall.arguments)) {
|
|
404
|
+
const nextFunctionName = pendingLegacyToolCall?.function?.name ? void 0 : functionCall.name;
|
|
405
|
+
const nextArgumentBytes = Buffer.byteLength(functionCall.arguments ?? "", "utf8") + Buffer.byteLength(nextFunctionName ?? "", "utf8");
|
|
406
|
+
if (pendingLegacyArgumentBytes + nextArgumentBytes > MAX_BUFFERED_LEGACY_TOOL_CALL_ARGUMENT_BYTES) throw new Error("Exceeded tool-call argument buffer limit");
|
|
407
|
+
pendingLegacyArgumentBytes += nextArgumentBytes;
|
|
408
|
+
pendingLegacyToolCall ??= {
|
|
409
|
+
index: 0,
|
|
410
|
+
id: `call_${randomUUID().replaceAll("-", "").slice(0, 24)}`,
|
|
411
|
+
type: "function",
|
|
412
|
+
function: {}
|
|
413
|
+
};
|
|
414
|
+
const pendingFunction = pendingLegacyToolCall.function ??= {};
|
|
415
|
+
if (nextFunctionName) pendingFunction.name = nextFunctionName;
|
|
416
|
+
if (functionCall.arguments) pendingFunction.arguments = (pendingFunction.arguments ?? "") + functionCall.arguments;
|
|
417
|
+
}
|
|
418
|
+
if (!pendingLegacyToolCall) return leadingDeltas.length > 0 ? leadingDeltas : [{
|
|
419
|
+
delta: ordinaryDelta,
|
|
420
|
+
toolCalls: []
|
|
421
|
+
}];
|
|
422
|
+
if (finishReason === "function_call") {
|
|
423
|
+
const confirmedLegacyToolCall = pendingLegacyToolCall;
|
|
424
|
+
pendingLegacyToolCall = void 0;
|
|
425
|
+
pendingLegacyArgumentBytes = 0;
|
|
426
|
+
return [
|
|
427
|
+
...leadingDeltas,
|
|
428
|
+
{
|
|
429
|
+
delta: {},
|
|
430
|
+
toolCalls: [confirmedLegacyToolCall]
|
|
431
|
+
},
|
|
432
|
+
...takePendingFollowingDeltas()
|
|
433
|
+
];
|
|
434
|
+
}
|
|
435
|
+
if (finishReason) {
|
|
436
|
+
pendingLegacyArgumentBytes = 0;
|
|
437
|
+
pendingLegacyToolCall = void 0;
|
|
438
|
+
return [...leadingDeltas, ...takePendingFollowingDeltas()];
|
|
439
|
+
}
|
|
440
|
+
return leadingDeltas;
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
/** Publish only executable calls; streaming scratch state never belongs in replay. */
|
|
444
|
+
function finalizeOpenAICompletionsToolCalls(output, options = {}) {
|
|
445
|
+
const isToolCall = (block) => block.type === "toolCall";
|
|
446
|
+
const hasToolCalls = output.content.some(isToolCall);
|
|
447
|
+
if (output.stopReason === "toolUse" && !hasToolCalls) output.stopReason = "stop";
|
|
448
|
+
if (output.stopReason === "stop" && hasToolCalls && options.allowSilentToolCallPromotion !== false && !output.content.some((block) => {
|
|
449
|
+
const candidate = block;
|
|
450
|
+
return candidate.type === "text" && typeof candidate.text === "string" && candidate.text.trim().length > 0;
|
|
451
|
+
})) output.stopReason = "toolUse";
|
|
452
|
+
if (output.stopReason !== "toolUse") {
|
|
453
|
+
if (hasToolCalls) output.content = output.content.filter((block) => !isToolCall(block));
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
for (const block of output.content) {
|
|
457
|
+
if (!isToolCall(block)) continue;
|
|
458
|
+
const toolCall = block;
|
|
459
|
+
let completeArguments;
|
|
460
|
+
try {
|
|
461
|
+
completeArguments = typeof toolCall.partialArgs === "string" && toolCall.partialArgs.trim().length > 0 ? JSON.parse(toolCall.partialArgs) : void 0;
|
|
462
|
+
} catch {
|
|
463
|
+
completeArguments = void 0;
|
|
464
|
+
}
|
|
465
|
+
if (typeof toolCall.name !== "string" || toolCall.name.trim().length === 0 || !isRecord(completeArguments)) {
|
|
466
|
+
output.stopReason = "error";
|
|
467
|
+
output.errorMessage = "Provider returned an incomplete or malformed tool call";
|
|
468
|
+
output.content = output.content.filter((candidate) => !isToolCall(candidate));
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
toolCall.arguments = completeArguments;
|
|
472
|
+
}
|
|
473
|
+
for (let contentIndex = 0; contentIndex < output.content.length; contentIndex += 1) {
|
|
474
|
+
const block = output.content[contentIndex];
|
|
475
|
+
if (!block || !isToolCall(block)) continue;
|
|
476
|
+
delete block.partialArgs;
|
|
477
|
+
delete block.streamIndex;
|
|
478
|
+
options.onConfirmedToolCall?.(block, contentIndex);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
//#endregion
|
|
341
482
|
//#region packages/ai/src/providers/openai-stop-reason.ts
|
|
342
483
|
function mapOpenAIStopReason(reason, options) {
|
|
343
484
|
if (reason === null) return { stopReason: "stop" };
|
|
@@ -393,4 +534,4 @@ function resolveOpenAIReasoningEffortMap(model, fallbackMap = {}) {
|
|
|
393
534
|
};
|
|
394
535
|
}
|
|
395
536
|
//#endregion
|
|
396
|
-
export {
|
|
537
|
+
export { convertMessages as a, resolveOpenAICompletionsResponseFormat as c, rememberPendingCommentaryTags as d, tagPendingCommentaryText as f, finalizeOpenAICompletionsToolCalls as i, shouldOmitOllamaCompatResponseFormat as l, mapOpenAIStopReason as n, detectOpenAICompletionsCompat as o, createOpenAICompletionsToolCallDeltaNormalizer as r, resolveOpenAICompletionsCompat as s, resolveOpenAIReasoningEffortMap as t, clearPendingCommentaryText as u };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { n as getEnvApiKey, r as __exportAll } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import { n as getAiTransportHost } from "./host-
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-CEV9t6da.mjs";
|
|
3
|
+
import { n as getAiTransportHost } from "./host-Bl7Kgddo.mjs";
|
|
4
4
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
5
5
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { c as buildBaseOptions } from "./tool-result-text-Dvkp2Dus.mjs";
|
|
7
|
+
import { pt as supportsOpenAITemperature } from "./openai-responses-stream-internal-Bl8YyVtF.mjs";
|
|
7
8
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
8
|
-
import { n as
|
|
9
|
-
import { a as runResponsesStreamLifecycle, i as resolveResponsesReasoningEffort, n as convertResponsesMessages, r as createResponsesAssistantOutput, t as applyCommonResponsesParams } from "./openai-responses-shared-pXl6Wd8S.mjs";
|
|
9
|
+
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-CCyMvg7M.mjs";
|
|
10
10
|
import OpenAI from "openai";
|
|
11
11
|
//#region packages/ai/src/providers/openai-responses.ts
|
|
12
12
|
var openai_responses_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -54,7 +54,7 @@ const streamOpenAIResponses = (model, context, options) => {
|
|
|
54
54
|
buildParams: () => buildParams(model, context, options),
|
|
55
55
|
processStreamOptions: {
|
|
56
56
|
serviceTier: options?.serviceTier,
|
|
57
|
-
applyServiceTierPricing: (usage, serviceTier) =>
|
|
57
|
+
applyServiceTierPricing: (usage, serviceTier) => applyResponsesServiceTierPricing(usage, serviceTier, model)
|
|
58
58
|
},
|
|
59
59
|
formatError: formatOpenAIResponsesError
|
|
60
60
|
});
|
|
@@ -118,21 +118,5 @@ function buildParams(model, context, options) {
|
|
|
118
118
|
applyCommonResponsesParams(params, model, context, options, { setDefaultReasoningOff: model.provider !== "github-copilot" });
|
|
119
119
|
return params;
|
|
120
120
|
}
|
|
121
|
-
function getServiceTierCostMultiplier(model, serviceTier) {
|
|
122
|
-
switch (serviceTier) {
|
|
123
|
-
case "flex": return .5;
|
|
124
|
-
case "priority": return model.id === "gpt-5.5" ? 2.5 : 2;
|
|
125
|
-
default: return 1;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function applyServiceTierPricing(usage, serviceTier, model) {
|
|
129
|
-
const multiplier = getServiceTierCostMultiplier(model, serviceTier);
|
|
130
|
-
if (multiplier === 1) return;
|
|
131
|
-
usage.cost.input *= multiplier;
|
|
132
|
-
usage.cost.output *= multiplier;
|
|
133
|
-
usage.cost.cacheRead *= multiplier;
|
|
134
|
-
usage.cost.cacheWrite *= multiplier;
|
|
135
|
-
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
136
|
-
}
|
|
137
121
|
//#endregion
|
|
138
122
|
export { streamOpenAIResponses as n, streamSimpleOpenAIResponses as r, openai_responses_exports as t };
|
|
@@ -0,0 +1,116 @@
|
|
|
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 };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { h as stripSystemPromptCacheBoundary } from "./tool-result-text-Dvkp2Dus.mjs";
|
|
2
|
+
import { B as responsesPromptObserver } from "./openai-responses-stream-internal-Bl8YyVtF.mjs";
|
|
3
|
+
import { u as sanitizeTransportPayloadText } from "./transport-stream-shared-CPNv7A3r.mjs";
|
|
4
|
+
//#region packages/normalization-core/src/error-coercion.ts
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes an unknown thrown value into an Error. Non-Error objects become
|
|
7
|
+
* the `cause` and have their enumerable fields copied so structured details
|
|
8
|
+
* (codes, statuses) survive the coercion.
|
|
9
|
+
*/
|
|
10
|
+
function toErrorObject(value, fallbackMessage) {
|
|
11
|
+
if (value instanceof Error) return value;
|
|
12
|
+
if (typeof value === "string") return new Error(value);
|
|
13
|
+
const error = new Error(fallbackMessage, { cause: value });
|
|
14
|
+
if (typeof value === "object" && value !== null || typeof value === "function") Object.assign(error, value);
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region packages/ai/src/transports/openai-responses-prompt-observer-internal.ts
|
|
19
|
+
function readFinalResponsesPrompt(request) {
|
|
20
|
+
if (typeof request.instructions === "string") return ["instructions", request.instructions];
|
|
21
|
+
const message = (Array.isArray(request.input) ? request.input : []).find((item) => {
|
|
22
|
+
const role = item.role;
|
|
23
|
+
return role === "developer" || role === "system";
|
|
24
|
+
});
|
|
25
|
+
if (!message) return ["missing", ""];
|
|
26
|
+
const content = message.content;
|
|
27
|
+
const observedPrompt = typeof content === "string" ? content : Array.isArray(content) ? content.flatMap((part) => part.type === "input_text" ? [part.text] : []).join("") : "";
|
|
28
|
+
return [message.role === "developer" ? "input.developer" : "input.system", observedPrompt];
|
|
29
|
+
}
|
|
30
|
+
function createResponsesPromptEgressObserver(options, assembledPrompt) {
|
|
31
|
+
const observer = options ? responsesPromptObserver.get(options) : void 0;
|
|
32
|
+
if (!observer) return;
|
|
33
|
+
const expectedPrompt = sanitizeTransportPayloadText(stripSystemPromptCacheBoundary(assembledPrompt ?? ""));
|
|
34
|
+
return (request, metadata) => {
|
|
35
|
+
const [promptSource, observedPrompt] = readFinalResponsesPrompt(request);
|
|
36
|
+
observer({
|
|
37
|
+
...metadata,
|
|
38
|
+
promptSource,
|
|
39
|
+
expectedChars: expectedPrompt.length,
|
|
40
|
+
observedChars: observedPrompt.length,
|
|
41
|
+
matchesAssembledPrompt: promptSource !== "missing" && observedPrompt === expectedPrompt
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { toErrorObject as n, createResponsesPromptEgressObserver as t };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { i as transformMessages, n as getAiTransportHost } from "./host-
|
|
1
|
+
import { i as transformMessages, n as getAiTransportHost } from "./host-Bl7Kgddo.mjs";
|
|
2
|
+
import { r as clampThinkingLevel } from "./model-utils-Dau5dlgm.mjs";
|
|
2
3
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
3
|
-
import { a as isImageWithMediaPayload,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-BBys9hSb.mjs";
|
|
9
|
-
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
4
|
+
import { a as isImageWithMediaPayload, h as stripSystemPromptCacheBoundary, r as extractToolResultText, t as describeToolResultMediaPlaceholder, v as sortPromptCacheToolsByName } from "./tool-result-text-Dvkp2Dus.mjs";
|
|
5
|
+
import { G as normalizeOpenAIStrictToolParameters, U as findOpenAIStrictToolProjectionDiagnostics, ft as supportsOpenAIReasoningEffort, n as processResponsesStream, pt as supportsOpenAITemperature, q as resolveOpenAIProjectedToolsStrictToolFlag, ut as resolveOpenAIReasoningEffortForModel } from "./openai-responses-stream-internal-Bl8YyVtF.mjs";
|
|
6
|
+
import { d as transportAbortError } from "./transport-stream-shared-CPNv7A3r.mjs";
|
|
7
|
+
import { l as projectOpenAITools } from "./openai-transport-shared-Cipt7egQ.mjs";
|
|
8
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-BIBomOGq.mjs";
|
|
10
9
|
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
11
|
-
import "./
|
|
10
|
+
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
11
|
+
import "./transform-messages-DfjpNXNQ.mjs";
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
//#region packages/ai/src/providers/openai-responses-tools.ts
|
|
14
14
|
const LOG_SUBSYSTEM = "llm/openai-responses";
|
|
@@ -294,6 +294,17 @@ function createResponsesAssistantOutput(model, api = model.api) {
|
|
|
294
294
|
timestamp: Date.now()
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
|
+
function applyResponsesServiceTierPricing(usage, serviceTier, model) {
|
|
298
|
+
let multiplier = 1;
|
|
299
|
+
if (serviceTier === "flex") multiplier = .5;
|
|
300
|
+
else if (serviceTier === "priority") multiplier = model.id === "gpt-5.5" ? 2.5 : 2;
|
|
301
|
+
if (multiplier === 1) return;
|
|
302
|
+
usage.cost.input *= multiplier;
|
|
303
|
+
usage.cost.output *= multiplier;
|
|
304
|
+
usage.cost.cacheRead *= multiplier;
|
|
305
|
+
usage.cost.cacheWrite *= multiplier;
|
|
306
|
+
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
307
|
+
}
|
|
297
308
|
function resolveResponsesReasoningEffort(model, reasoning) {
|
|
298
309
|
const clampedReasoning = reasoning ? clampThinkingLevel(model, reasoning) : void 0;
|
|
299
310
|
if (!clampedReasoning || clampedReasoning === "off") return;
|
|
@@ -389,4 +400,4 @@ async function runResponsesStreamLifecycle(params) {
|
|
|
389
400
|
}
|
|
390
401
|
}
|
|
391
402
|
//#endregion
|
|
392
|
-
export {
|
|
403
|
+
export { resolveResponsesReasoningEffort as a, createResponsesAssistantOutput as i, applyResponsesServiceTierPricing as n, runResponsesStreamLifecycle as o, convertResponsesMessages as r, convertResponsesToolPayload as s, applyCommonResponsesParams as t };
|