@openclaw/ai 2026.9.1 → 2026.9.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/README.md +3 -2
- package/dist/anthropic-CZy5U0NY.mjs +376 -0
- package/dist/anthropic-payload-policy-wuRCb6MH.d.mts +85 -0
- package/dist/anthropic-stream-reducer-B_yo_7pf.mjs +1669 -0
- package/dist/{api-registry-Cs6HGNqY.d.mts → api-registry-CB1-1oQ2.d.mts} +2 -2
- package/dist/assistant-output-iqnlJCV2.mjs +16 -0
- package/dist/assistant-text-phase-C20rxWwP.mjs +55 -0
- package/dist/{azure-openai-responses-CN4Fy5zV.mjs → azure-openai-responses-Crpa40QR.mjs} +5 -5
- package/dist/{base64-CEFBpSkN.mjs → base64-D-su8YVo.mjs} +1 -27
- package/dist/{diagnostics-KhXK-QJI.mjs → diagnostics-dV98PqIy.mjs} +96 -21
- package/dist/diagnostics.d.mts +3 -1
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-vK_7r3bj.d.mts → event-stream-C1Z2piyk.d.mts} +11 -3
- package/dist/{event-stream-uSMZJ3FA.mjs → event-stream-D8PARQfL.mjs} +48 -10
- package/dist/event-stream-I_GlBsuZ.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-headers-NCJtz9i0.mjs → github-copilot-headers-B37TB3rB.mjs} +3 -10
- package/dist/github-copilot-request-facts-BTEBMeOv.mjs +16 -0
- package/dist/{google-CC-nrwXg.mjs → google-BDPriaVe.mjs} +10 -10
- package/dist/google-messages-CVn9eFpF.mjs +449 -0
- package/dist/google-shared-BedY23XS.mjs +185 -0
- package/dist/{google-vertex-DCr0pyzQ.mjs → google-vertex-DMz8XQCn.mjs} +7 -6
- package/dist/{host-BIaiBURL.mjs → host-CWuF-sS3.mjs} +84 -34
- package/dist/{host-BztR4tQj.d.mts → host-DK3wmS3e.d.mts} +3 -3
- package/dist/host-policy-CAopLRKA.mjs +37 -0
- package/dist/{index-AfaxKT8w.d.mts → index-CQ6LTHw8.d.mts} +11 -5
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +14 -11
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/google-model-family.d.mts +5 -0
- package/dist/internal/google-model-family.mjs +15 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +1 -1
- package/dist/internal/openai.d.mts +8 -103
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +2 -4
- package/dist/internal/retry-after.mjs +57 -8
- package/dist/internal/runtime.d.mts +7 -6
- package/dist/internal/runtime.mjs +8 -7
- package/dist/internal/shared.d.mts +14 -3
- package/dist/internal/shared.mjs +6 -4
- package/dist/internal/tool-schema.d.mts +63 -0
- package/dist/internal/tool-schema.mjs +3 -0
- package/dist/{json-parse-BuAJEbdW.mjs → json-parse-Dw_hnxsA.mjs} +1 -1
- package/dist/{mistral-B7etBd_H.mjs → mistral--m-Jm6VZ.mjs} +16 -38
- package/dist/model-transport-url-DKocrEsb.d.mts +28 -0
- package/dist/{openai-chatgpt-responses-BAJ4gq3i.mjs → openai-chatgpt-responses-nDZccFW-.mjs} +62 -54
- package/dist/openai-completions-KuoZyx0d.mjs +187 -0
- package/dist/{openai-completions-compat-4IjSBpr6.d.mts → openai-completions-compat-CXn3T1we.d.mts} +26 -4
- package/dist/{openai-completions-stream-DZjwK8vp.mjs → openai-completions-stream-BQk3SkLD.mjs} +621 -451
- package/dist/openai-prompt-cache-BI0rkM-5.mjs +220 -0
- package/dist/openai-prompt-cache-rrutvqxq.d.mts +16 -0
- package/dist/openai-provider-client-ha_WxTyj.mjs +24 -0
- package/dist/openai-reasoning-effort-BK7FbcLT.mjs +167 -0
- package/dist/{openai-responses-BEUlxfDu.mjs → openai-responses-D99dOzKI.mjs} +14 -32
- package/dist/{openai-responses-compaction-window-DO7yV7az.mjs → openai-responses-compaction-window-D5jbzCi3.mjs} +7 -159
- package/dist/{openai-responses-contracts-bPzSN_Ba.d.mts → openai-responses-contracts-B55afwRo.d.mts} +12 -4
- package/dist/{openai-responses-prompt-observer-internal-C7x4IK7r.mjs → openai-responses-prompt-observer-internal-tApyTLVu.mjs} +3 -3
- package/dist/{openai-responses-shared-DiAdpNAM.mjs → openai-responses-shared-ZyQEzS5i.mjs} +217 -212
- package/dist/openai-tool-projection-793cE3QX.d.mts +37 -0
- package/dist/{openai-tool-schema-BMiHFH36.mjs → openai-tool-schema-CzjyYXun.mjs} +53 -583
- package/dist/openai-tool-schema-ynZBgqW-.d.mts +38 -0
- package/dist/openai-transport-params-DNasp2fU.mjs +674 -0
- package/dist/{provider-error-B6EGq6gg.mjs → provider-error-C6TbKiey.mjs} +29 -13
- package/dist/{provider-options-CxFPtvh7.d.mts → provider-options-BXr9Ec83.d.mts} +19 -42
- package/dist/provider-replay-context-BuSUaAk5.mjs +21 -0
- package/dist/{provider-transcript-transform-WvJmFUAf.mjs → provider-transcript-transform-pPmUIwKt.mjs} +1 -1
- package/dist/provider-types-CAV0Og3m.d.mts +29 -0
- package/dist/provider-types.d.mts +6 -31
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-C-4uedDb.mjs → reasoning-tag-text-partitioner-BQBi4B9d.mjs} +90 -35
- package/dist/record-coerce-DwRYMj3t.mjs +32 -0
- package/dist/retry-after-CdCURCVg.d.mts +15 -0
- package/dist/{sanitize-unicode-S6binQG-.mjs → sanitize-unicode-Bb-v9meu.mjs} +1 -1
- package/dist/session-affinity-CCH7eYdB.mjs +20 -0
- package/dist/{simple-options-0PLDyJ-d.mjs → simple-options-tcKOqnpF.mjs} +3 -3
- package/dist/{src-C8U7lkoa.mjs → src-B2Q_6G8V.mjs} +10 -2
- package/dist/{stream-first-event-timeout-DcNjoFQE.mjs → stream-first-event-timeout-2hfrquuz.mjs} +1 -1
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{string-normalization--fwJ4S2q.mjs → string-normalization-CmLIasuf.mjs} +1 -1
- package/dist/{tool-schema-json-projection-BtZiml7r.mjs → tool-schema-json-projection-ClptDdAO.mjs} +2 -38
- package/dist/{transport-stream-shared-CytPVLIg.mjs → transport-stream-shared-Cu3ZPhNW.mjs} +5 -5
- package/dist/{transport-stream-shared-BrvFTkoO.d.mts → transport-stream-shared-DOxpGJ-H.d.mts} +4 -4
- package/dist/transport-utils-CCooe-cr.mjs +121 -0
- package/dist/transports.d.mts +114 -41
- package/dist/transports.mjs +796 -1596
- package/dist/types-BADKjDBI.d.mts +1 -0
- package/dist/{types-DbrhszyQ.d.mts → types-Dy1q0CSu.d.mts} +101 -64
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +4 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-CJZtym2g.mjs → validation-BDzVDnTs.mjs} +9 -1
- package/dist/{validation-BOwtcl9X.d.mts → validation-CaFUZN9B.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +14 -4
- package/dist/anthropic-compaction-replay-OMJZ0uyo.mjs +0 -838
- package/dist/anthropic-hk7F7ptG.mjs +0 -883
- package/dist/anthropic-payload-policy-DBT1itQ-.d.mts +0 -51
- package/dist/event-stream-DeDhbCc5.d.mts +0 -1
- package/dist/google-shared-CjPY0hZM.mjs +0 -634
- package/dist/google-thinking-level-C-V3tecN.mjs +0 -9
- package/dist/openai-completions-D0QZ0AyB.mjs +0 -403
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/transport-utils-CtuS1Upe.mjs +0 -138
- package/dist/types-B5EFUmXs.d.mts +0 -1
- package/dist/utf16-slice-qz3nsy87.mjs +0 -84
|
@@ -1,60 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { r as
|
|
10
|
-
import {
|
|
1
|
+
import { r as appendAssistantThinking } from "./event-stream-D8PARQfL.mjs";
|
|
2
|
+
import { a as normalizeOptionalString } from "./string-coerce-fsri9iCu.mjs";
|
|
3
|
+
import { i as clampThinkingLevel, r as calculateCost } from "./sanitize-unicode-Bb-v9meu.mjs";
|
|
4
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, n as getAiTransportHost } from "./host-CWuF-sS3.mjs";
|
|
5
|
+
import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
6
|
+
import { t as truncateUtf16Safe } from "./utf16-slice-CvGodqok.mjs";
|
|
7
|
+
import { i as stableStringify } from "./provider-error-C6TbKiey.mjs";
|
|
8
|
+
import { a as resolveModelSseDebugMode, i as resolveModelPayloadDebugMode, r as emitModelTransportDebug } from "./diagnostics-dV98PqIy.mjs";
|
|
9
|
+
import { r as asFiniteNumber } from "./base64-D-su8YVo.mjs";
|
|
10
|
+
import { s as redactSensitiveText } from "./transport-utils-CCooe-cr.mjs";
|
|
11
|
+
import { s as transformTransportMessages } from "./host-policy-CAopLRKA.mjs";
|
|
12
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName } from "./simple-options-tcKOqnpF.mjs";
|
|
13
|
+
import { O as redactIdentifier, _ as createOpenAIProviderAcceptanceHook, b as log, f as projectOpenAITools, g as createModelStreamCooperativeScheduler, k as sha256Hex, u as resolveOpenAIStrictToolFlagWithDiagnostics } from "./openai-transport-params-DNasp2fU.mjs";
|
|
14
|
+
import { _ as transportAbortError, c as finalizeTransportStream, g as sanitizeTransportPayloadText, h as sanitizeNonEmptyTransportPayloadText, m as parseTerminalToolCallArguments, o as failTransportStream, y as withProviderResponseHook } from "./transport-stream-shared-Cu3ZPhNW.mjs";
|
|
11
15
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { t as
|
|
15
|
-
import {
|
|
16
|
+
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-BuSUaAk5.mjs";
|
|
17
|
+
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-Dw_hnxsA.mjs";
|
|
18
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
19
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-2hfrquuz.mjs";
|
|
20
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-pPmUIwKt.mjs";
|
|
21
|
+
import { a as resolveOpenAIModelReasoningEfforts, l as supportsOpenAITemperature, o as resolveOpenAIReasoningEffortForModel } from "./openai-reasoning-effort-BK7FbcLT.mjs";
|
|
22
|
+
import { a as resolveOpenAIProjectedToolsStrictToolFlag, r as normalizeOpenAIStrictToolParameters } from "./openai-tool-schema-CzjyYXun.mjs";
|
|
23
|
+
import { b as RESPONSE_FAILED_NO_DETAILS_MESSAGE, g as OPENAI_RESPONSES_RETAINED_COMPACTION_REPLAY_TYPE, h as OPENAI_RESPONSES_REASONING_REPLAY_META_KEY, m as OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY, n as isOpenAIResponsesCompactionOutput, p as OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE, r as readOpenAIResponsesCompactionWindow } from "./openai-responses-compaction-window-D5jbzCi3.mjs";
|
|
16
24
|
import { createHash, randomUUID } from "node:crypto";
|
|
17
|
-
//#region packages/ai/src/transports/model-transport-debug.ts
|
|
18
|
-
/**
|
|
19
|
-
* Environment-driven debug controls for model transport logging.
|
|
20
|
-
*
|
|
21
|
-
* Model adapters share these helpers so payload, SSE, and transport diagnostics
|
|
22
|
-
* interpret OpenClaw debug environment variables consistently.
|
|
23
|
-
*/
|
|
24
|
-
function isTruthyEnv(value) {
|
|
25
|
-
const normalized = normalizeLowercaseStringOrEmpty(value);
|
|
26
|
-
return normalized.length > 0 && normalized !== "0" && normalized !== "false" && normalized !== "off" && normalized !== "no";
|
|
27
|
-
}
|
|
28
|
-
/** Resolves model payload debug verbosity from `OPENCLAW_DEBUG_MODEL_PAYLOAD`. */
|
|
29
|
-
function resolveModelPayloadDebugMode(env = process.env) {
|
|
30
|
-
const normalized = normalizeLowercaseStringOrEmpty(env.OPENCLAW_DEBUG_MODEL_PAYLOAD);
|
|
31
|
-
if (normalized === "tools" || normalized === "full-redacted") return normalized;
|
|
32
|
-
if (normalized === "summary") return "summary";
|
|
33
|
-
return "off";
|
|
34
|
-
}
|
|
35
|
-
/** Resolves SSE stream debug verbosity from `OPENCLAW_DEBUG_SSE`. */
|
|
36
|
-
function resolveModelSseDebugMode(env = process.env) {
|
|
37
|
-
const normalized = normalizeLowercaseStringOrEmpty(env.OPENCLAW_DEBUG_SSE);
|
|
38
|
-
if (normalized === "peek") return "peek";
|
|
39
|
-
if (normalized === "events" || isTruthyEnv(normalized)) return "events";
|
|
40
|
-
return "off";
|
|
41
|
-
}
|
|
42
|
-
/** Returns whether any model transport debug channel is enabled. */
|
|
43
|
-
function isModelTransportDebugEnabled(env = process.env) {
|
|
44
|
-
return isTruthyEnv(env.OPENCLAW_DEBUG_MODEL_TRANSPORT) || resolveModelPayloadDebugMode(env) !== "off" || resolveModelSseDebugMode(env) !== "off" || isTruthyEnv(env.OPENCLAW_DEBUG_CODE_MODE);
|
|
45
|
-
}
|
|
46
|
-
function isModelFetchMetadataMessage(message) {
|
|
47
|
-
return message.startsWith("[model-fetch]");
|
|
48
|
-
}
|
|
49
|
-
/** Emits model-fetch metadata at info level by default; other diagnostics require debug env. */
|
|
50
|
-
function emitModelTransportDebug(log, message) {
|
|
51
|
-
if (isModelFetchMetadataMessage(message) || isModelTransportDebugEnabled()) {
|
|
52
|
-
log.info(message);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
log.debug(message);
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
25
|
//#region packages/ai/src/transports/openai-responses-replay.ts
|
|
59
26
|
/** Resolves the assistant message id that can be replayed to OpenAI Responses. */
|
|
60
27
|
function resolveReplayableResponsesMessageId(params) {
|
|
@@ -66,19 +33,8 @@ function resolveReplayableResponsesMessageId(params) {
|
|
|
66
33
|
//#region packages/ai/src/transports/openai-responses-compaction-replay.ts
|
|
67
34
|
const OPENAI_RESPONSES_COMPACTION_SUPPRESSION_TYPE = "openai-responses-compaction-suppression";
|
|
68
35
|
const OPENAI_RESPONSES_COMPACTION_SUPPRESSION_DATA = "rejected";
|
|
69
|
-
function hashOptionalReplayContextValue(value) {
|
|
70
|
-
const normalized = value?.trim();
|
|
71
|
-
return normalized ? shortHash(normalized) : void 0;
|
|
72
|
-
}
|
|
73
36
|
function buildOpenAIResponsesReplayContext(model, options) {
|
|
74
|
-
return
|
|
75
|
-
provider: model.provider,
|
|
76
|
-
api: model.api,
|
|
77
|
-
model: model.id,
|
|
78
|
-
baseUrlHash: hashOptionalReplayContextValue(model.baseUrl),
|
|
79
|
-
sessionHash: hashOptionalReplayContextValue(options?.sessionId),
|
|
80
|
-
authProfileHash: hashOptionalReplayContextValue(options?.authProfileId)
|
|
81
|
-
};
|
|
37
|
+
return buildProviderReplayContext(model, options);
|
|
82
38
|
}
|
|
83
39
|
function isOpenAIResponsesReplayContext(value) {
|
|
84
40
|
if (!isRecord(value)) return false;
|
|
@@ -93,9 +49,6 @@ function isOpenAIResponsesCompactionState(state) {
|
|
|
93
49
|
function readOpenAIResponsesCompactionReplayState(value) {
|
|
94
50
|
return isRecord(value) && isOpenAIResponsesReplayContext(value) && isOpenAIResponsesCompactionState(value) ? value : void 0;
|
|
95
51
|
}
|
|
96
|
-
function openAIResponsesReplayContextMatches(state, context) {
|
|
97
|
-
return state.provider === context.provider && state.api === context.api && state.model === context.model && state.baseUrlHash === context.baseUrlHash && state.sessionHash === context.sessionHash && state.authProfileHash === context.authProfileHash;
|
|
98
|
-
}
|
|
99
52
|
function captureOpenAIResponsesCompaction(output, item, boundary, model, captureMetadata, compactedOutput) {
|
|
100
53
|
const metadata = captureMetadata ?? buildOpenAIResponsesReasoningReplayMetadata(model);
|
|
101
54
|
if (!item.encrypted_content) return;
|
|
@@ -167,14 +120,14 @@ function resolveNewestOpenAIResponsesCompactionReplay(messages, model, options)
|
|
|
167
120
|
if (message?.role !== "assistant") continue;
|
|
168
121
|
const replay = readOpenAIResponsesCompactionReplayState(message.providerReplay);
|
|
169
122
|
if (replay?.type === OPENAI_RESPONSES_COMPACTION_SUPPRESSION_TYPE) {
|
|
170
|
-
if (
|
|
123
|
+
if (providerReplayContextMatches(replay, context)) return;
|
|
171
124
|
continue;
|
|
172
125
|
}
|
|
173
126
|
if (replay?.type !== "openai-responses-compaction" && replay?.type !== "openai-responses-retained-compaction") {
|
|
174
127
|
if (message.providerReplay?.type === "openai-responses-compaction" || message.providerReplay?.type === "openai-responses-retained-compaction") return;
|
|
175
128
|
continue;
|
|
176
129
|
}
|
|
177
|
-
if (!
|
|
130
|
+
if (!providerReplayContextMatches(replay, context)) return;
|
|
178
131
|
if (replay.compactedWindow !== void 0 || replay.type === "openai-responses-retained-compaction") {
|
|
179
132
|
const output = readOpenAIResponsesCompactionWindow(replay, model);
|
|
180
133
|
const item = output?.at(-1);
|
|
@@ -237,6 +190,63 @@ function buildOpenAIResponsesReasoningReplayMetadata(model, options) {
|
|
|
237
190
|
};
|
|
238
191
|
}
|
|
239
192
|
//#endregion
|
|
193
|
+
//#region packages/ai/src/transports/openai-responses-input-replay.ts
|
|
194
|
+
function recordResponsesInputReplay(message, replay) {
|
|
195
|
+
if (replay) Object.assign(message, { openclawResponsesInputReplay: replay });
|
|
196
|
+
}
|
|
197
|
+
function readResponsesInputReplay(message) {
|
|
198
|
+
const replay = "openclawResponsesInputReplay" in message ? message.openclawResponsesInputReplay : void 0;
|
|
199
|
+
if (isRecord(replay) && typeof replay.afterResponseId === "string" && Array.isArray(replay.before) && replay.before.every((item) => typeof item === "string") && Array.isArray(replay.after) && replay.after.every((item) => typeof item === "string")) return {
|
|
200
|
+
afterResponseId: replay.afterResponseId,
|
|
201
|
+
before: replay.before,
|
|
202
|
+
after: replay.after
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function responsesInputFingerprint(item) {
|
|
206
|
+
if (isRecord(item) && (item.type === "function_call_output" || item.type === "custom_tool_call_output") && typeof item.call_id === "string") return sha256Hex(stableStringify({
|
|
207
|
+
type: item.type,
|
|
208
|
+
call_id: item.call_id
|
|
209
|
+
}));
|
|
210
|
+
return sha256Hex(stableStringify(item));
|
|
211
|
+
}
|
|
212
|
+
/** Reconstruct delivery order without rewriting durable local completion events. */
|
|
213
|
+
function createResponsesInputReplay(model) {
|
|
214
|
+
const starts = /* @__PURE__ */ new Map();
|
|
215
|
+
const ends = /* @__PURE__ */ new Map();
|
|
216
|
+
const fingerprints = /* @__PURE__ */ new Map();
|
|
217
|
+
const fingerprint = (item) => {
|
|
218
|
+
const value = fingerprints.get(item) ?? responsesInputFingerprint(item);
|
|
219
|
+
fingerprints.set(item, value);
|
|
220
|
+
return value;
|
|
221
|
+
};
|
|
222
|
+
return (input, output, message) => {
|
|
223
|
+
const key = message.turnId || message.responseId;
|
|
224
|
+
const start = (key ? starts.get(key) : void 0) ?? output[0];
|
|
225
|
+
if (key && start) starts.set(key, start);
|
|
226
|
+
input.push(...output);
|
|
227
|
+
let end = input.at(-1);
|
|
228
|
+
const replay = readResponsesInputReplay(message);
|
|
229
|
+
const parent = replay ? ends.get(replay.afterResponseId) : void 0;
|
|
230
|
+
if (replay && parent && message.provider === model.provider && message.api === model.api && message.model === model.id) {
|
|
231
|
+
const take = (keys) => {
|
|
232
|
+
const moved = [];
|
|
233
|
+
for (const inputKey of keys.toReversed()) {
|
|
234
|
+
const boundary = input.indexOf(parent);
|
|
235
|
+
const index = input.findLastIndex((item, position) => position > boundary && fingerprint(item) === inputKey);
|
|
236
|
+
if (index > boundary) moved.unshift(...input.splice(index, 1));
|
|
237
|
+
}
|
|
238
|
+
return moved;
|
|
239
|
+
};
|
|
240
|
+
const before = take(replay.before);
|
|
241
|
+
const after = take(replay.after);
|
|
242
|
+
input.splice(start ? input.indexOf(start) : input.length, 0, ...before);
|
|
243
|
+
end = input.at(-1);
|
|
244
|
+
input.push(...after);
|
|
245
|
+
}
|
|
246
|
+
if (message.responseId && end) ends.set(message.responseId, end);
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
240
250
|
//#region packages/ai/src/transports/openai-responses-replay-messages-internal.ts
|
|
241
251
|
function stripEncryptedReasoningContentFields(value) {
|
|
242
252
|
if (!value || typeof value !== "object") return {
|
|
@@ -306,7 +316,7 @@ function prepareOpenAIResponsesReasoningItemForReplay(item, context, blockMetada
|
|
|
306
316
|
const { [OPENAI_RESPONSES_REASONING_REPLAY_META_KEY]: rawMetadata, ...rest } = record;
|
|
307
317
|
if (!("encrypted_content" in rest)) return normalizeOpenAIResponsesReasoningReplayItem(rest);
|
|
308
318
|
const metadata = blockMetadata !== void 0 ? blockMetadata ?? void 0 : isOpenAIResponsesReasoningReplayMetadata(rawMetadata) ? rawMetadata : void 0;
|
|
309
|
-
if (blockMetadata === void 0 && !hasRawMetadata && options?.preserveUnattributedEncryptedContent === true || metadata &&
|
|
319
|
+
if (blockMetadata === void 0 && !hasRawMetadata && options?.preserveUnattributedEncryptedContent === true || metadata && providerReplayContextMatches(metadata, context)) return normalizeOpenAIResponsesReasoningReplayItem(rest);
|
|
310
320
|
return normalizeOpenAIResponsesReasoningReplayItem(stripEncryptedReasoningContentFields(rest).value);
|
|
311
321
|
}
|
|
312
322
|
function normalizeResponsesReplayItemId(id, prefix) {
|
|
@@ -321,6 +331,41 @@ function encodeTextSignatureV1(id, phase) {
|
|
|
321
331
|
...phase ? { phase } : {}
|
|
322
332
|
});
|
|
323
333
|
}
|
|
334
|
+
function orderResponsesAsyncToolResults(source) {
|
|
335
|
+
const turnKey = (message) => {
|
|
336
|
+
const id = message.turnId || message.responseId;
|
|
337
|
+
return id ? `${message.provider}:${message.api}:${message.model}:${id}` : void 0;
|
|
338
|
+
};
|
|
339
|
+
const lastAssistant = /* @__PURE__ */ new Map();
|
|
340
|
+
for (const [index, message] of source.entries()) if (message.role === "assistant") {
|
|
341
|
+
const key = turnKey(message);
|
|
342
|
+
if (key) lastAssistant.set(key, index);
|
|
343
|
+
}
|
|
344
|
+
const owners = /* @__PURE__ */ new Map();
|
|
345
|
+
const pending = /* @__PURE__ */ new Map();
|
|
346
|
+
const ordered = [];
|
|
347
|
+
for (const [index, message] of source.entries()) {
|
|
348
|
+
if (message.role === "assistant") {
|
|
349
|
+
const key = turnKey(message);
|
|
350
|
+
if (key) {
|
|
351
|
+
for (const block of message.content) if (block.type === "toolCall" && block.async) owners.set(block.id, key);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const owner = message.role === "toolResult" ? owners.get(message.toolCallId) : void 0;
|
|
355
|
+
const lastIndex = owner ? lastAssistant.get(owner) : void 0;
|
|
356
|
+
if (lastIndex !== void 0 && lastIndex > index) {
|
|
357
|
+
const results = pending.get(lastIndex) ?? [];
|
|
358
|
+
results.push(message);
|
|
359
|
+
pending.set(lastIndex, results);
|
|
360
|
+
} else ordered.push(message);
|
|
361
|
+
const results = pending.get(index);
|
|
362
|
+
if (results) {
|
|
363
|
+
ordered.push(...results);
|
|
364
|
+
pending.delete(index);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return ordered;
|
|
368
|
+
}
|
|
324
369
|
function parseOpenAIResponsesTextSignature(signature) {
|
|
325
370
|
if (!signature) return;
|
|
326
371
|
if (signature.startsWith("{")) try {
|
|
@@ -416,7 +461,7 @@ function convertResponsesMessagesWithStyle(model, context, allowedToolCallProvid
|
|
|
416
461
|
normalizeSameModelToolCallIds: shouldNormalizeSameModelToolCallIds,
|
|
417
462
|
preserveUnframedToolResults: replayPlan.preserveUnframedToolResults
|
|
418
463
|
});
|
|
419
|
-
const transformedMessages = transformMessages(replayPlan.messages);
|
|
464
|
+
const transformedMessages = orderResponsesAsyncToolResults(transformMessages(replayPlan.messages));
|
|
420
465
|
if ((options?.includeSystemPrompt ?? true) && context.systemPrompt) messages.push(buildResponsesInputMessage(model.reasoning && model.compat?.supportsDeveloperRole !== false ? "developer" : "system", [{
|
|
421
466
|
type: "input_text",
|
|
422
467
|
text: sanitizeTransportPayloadText(stripSystemPromptCacheBoundary(context.systemPrompt))
|
|
@@ -424,17 +469,21 @@ function convertResponsesMessagesWithStyle(model, context, allowedToolCallProvid
|
|
|
424
469
|
if (replayPlan.compactedWindow) messages.push(...replayPlan.compactedWindow);
|
|
425
470
|
let replayMessages = replayPlan.compaction ? [replayPlan.compaction, ...transformedMessages] : transformedMessages;
|
|
426
471
|
const isCarrier = (message) => "role" in message && message.role === "user" && message.runtimeContextCarrier === true;
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
472
|
+
if (replayMessages.some(isCarrier)) {
|
|
473
|
+
const anchored = [];
|
|
474
|
+
let insertionIndex = replayPlan.compactedWindow ? 0 : void 0;
|
|
475
|
+
for (const message of replayMessages) {
|
|
476
|
+
if (isCarrier(message) && insertionIndex !== void 0) {
|
|
477
|
+
anchored.splice(insertionIndex++, 0, message);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
anchored.push(message);
|
|
481
|
+
if (!isCarrier(message) && ("role" in message ? message.role === "user" : message.type === "compaction")) insertionIndex = anchored.length;
|
|
482
|
+
}
|
|
483
|
+
replayMessages = anchored;
|
|
436
484
|
}
|
|
437
485
|
let msgIndex = 0;
|
|
486
|
+
const appendAssistant = createResponsesInputReplay(model);
|
|
438
487
|
for (const msg of replayMessages) {
|
|
439
488
|
if (!("role" in msg)) {
|
|
440
489
|
messages.push(msg);
|
|
@@ -512,12 +561,18 @@ function convertResponsesMessagesWithStyle(model, context, allowedToolCallProvid
|
|
|
512
561
|
...itemId ? { id: itemId } : {},
|
|
513
562
|
call_id: callId,
|
|
514
563
|
name: block.name,
|
|
564
|
+
...block.async ? { async: true } : {},
|
|
515
565
|
arguments: providerStyle ? JSON.stringify(block.arguments) : typeof block.arguments === "string" ? block.arguments : JSON.stringify(block.arguments ?? {})
|
|
516
566
|
});
|
|
517
567
|
previousReplayItemWasReasoning = false;
|
|
518
568
|
}
|
|
519
|
-
|
|
520
|
-
|
|
569
|
+
while (true) {
|
|
570
|
+
const last = output.at(-1);
|
|
571
|
+
if (last?.type !== "reasoning" || !last.id?.startsWith("rs_") || typeof last.encrypted_content === "string" && last.encrypted_content.length > 0) break;
|
|
572
|
+
output.pop();
|
|
573
|
+
}
|
|
574
|
+
appendAssistant(messages, output, msg);
|
|
575
|
+
if (output.length === 0 && providerStyle) continue;
|
|
521
576
|
} else if (msg.role === "toolResult") {
|
|
522
577
|
const textResult = extractToolResultText(msg.content);
|
|
523
578
|
const sanitizedTextResult = sanitizeTransportPayloadText(textResult);
|
|
@@ -1555,6 +1610,7 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1555
1610
|
const outputSlots = createResponsesOutputSlotTracker();
|
|
1556
1611
|
const outputs = createResponsesOutputTracker();
|
|
1557
1612
|
let terminalResponse;
|
|
1613
|
+
let incompleteToolCall;
|
|
1558
1614
|
let lastTextBlock = null;
|
|
1559
1615
|
const blocks = output.content;
|
|
1560
1616
|
const compactionTracker = createCompactionTracker(output, model, options);
|
|
@@ -1644,6 +1700,26 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1644
1700
|
const materializeDeferredTextSlots = (except) => {
|
|
1645
1701
|
for (const slot of outputSlots.values()) if (slot !== except && slot.type === "text") materializeDeferredTextSlot(slot);
|
|
1646
1702
|
};
|
|
1703
|
+
const appendThinkingDelta = (slot, delta) => {
|
|
1704
|
+
appendAssistantThinking(slot.block, delta);
|
|
1705
|
+
stream.push({
|
|
1706
|
+
type: "thinking_delta",
|
|
1707
|
+
contentIndex: slot.contentIndex,
|
|
1708
|
+
delta,
|
|
1709
|
+
partial: output
|
|
1710
|
+
});
|
|
1711
|
+
};
|
|
1712
|
+
const projectTextDelta = (slot, delta) => {
|
|
1713
|
+
if (slot.pendingText !== null) appendResponsesPendingTextDelta(slot, delta, materializeDeferredTextSlot);
|
|
1714
|
+
else if (slot.block && slot.contentIndex !== void 0) {
|
|
1715
|
+
slot.block.text += delta;
|
|
1716
|
+
stream.push({
|
|
1717
|
+
type: "text_delta",
|
|
1718
|
+
contentIndex: slot.contentIndex,
|
|
1719
|
+
delta
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1647
1723
|
const terminal = createResponsesTerminalController({
|
|
1648
1724
|
output,
|
|
1649
1725
|
stream,
|
|
@@ -1670,7 +1746,10 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1670
1746
|
streamingToolCalls.forget(streamingToolCall);
|
|
1671
1747
|
for (const slot of outputSlots.values()) if (slot.type === "toolCall" && slot.toolCall === streamingToolCall) outputSlots.forget(slot);
|
|
1672
1748
|
}
|
|
1673
|
-
terminal.emitToolCallCompletion(identity, finalOutputIndex, streamingToolCall,
|
|
1749
|
+
terminal.emitToolCallCompletion(identity, finalOutputIndex, streamingToolCall, {
|
|
1750
|
+
...validated,
|
|
1751
|
+
...options?.asyncToolExecution && isRecord(item) && item.async === true ? { async: true } : {}
|
|
1752
|
+
});
|
|
1674
1753
|
};
|
|
1675
1754
|
const prepareTerminalToolCalls = (items) => {
|
|
1676
1755
|
const prepared = /* @__PURE__ */ new Map();
|
|
@@ -1709,6 +1788,8 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1709
1788
|
try {
|
|
1710
1789
|
for await (const event of guardedStream) {
|
|
1711
1790
|
notifyLlmRequestActivity(options?.signal);
|
|
1791
|
+
if (event.type === "response.output_item.done" && event.item.type === "function_call" && event.item.status === "incomplete") incompleteToolCall ??= event.item;
|
|
1792
|
+
if (incompleteToolCall && event.type !== "response.completed" && event.type !== "response.incomplete" && event.type !== "response.failed" && event.type !== "error") continue;
|
|
1712
1793
|
if (event.type === "response.created") output.responseId = event.response.id;
|
|
1713
1794
|
else if (event.type === "response.output_item.added") {
|
|
1714
1795
|
materializeDeferredTextSlots();
|
|
@@ -1756,38 +1837,20 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1756
1837
|
slot.item.summary = slot.item.summary || [];
|
|
1757
1838
|
const lastPart = slot.item.summary[slot.item.summary.length - 1];
|
|
1758
1839
|
if (!lastPart) continue;
|
|
1759
|
-
slot.block.thinking += event.delta;
|
|
1760
1840
|
lastPart.text += event.delta;
|
|
1761
|
-
|
|
1762
|
-
type: "thinking_delta",
|
|
1763
|
-
contentIndex: slot.contentIndex,
|
|
1764
|
-
delta: event.delta,
|
|
1765
|
-
partial: output
|
|
1766
|
-
});
|
|
1841
|
+
appendThinkingDelta(slot, event.delta);
|
|
1767
1842
|
} else if (event.type === "response.reasoning_summary_part.done") {
|
|
1768
1843
|
const slot = outputSlots.resolve(event, "thinking");
|
|
1769
1844
|
if (!slot) continue;
|
|
1770
1845
|
slot.item.summary = slot.item.summary || [];
|
|
1771
1846
|
const lastPart = slot.item.summary[slot.item.summary.length - 1];
|
|
1772
1847
|
if (!lastPart) continue;
|
|
1773
|
-
slot.block.thinking += "\n\n";
|
|
1774
1848
|
lastPart.text += "\n\n";
|
|
1775
|
-
|
|
1776
|
-
type: "thinking_delta",
|
|
1777
|
-
contentIndex: slot.contentIndex,
|
|
1778
|
-
delta: "\n\n",
|
|
1779
|
-
partial: output
|
|
1780
|
-
});
|
|
1849
|
+
appendThinkingDelta(slot, "\n\n");
|
|
1781
1850
|
} else if (event.type === "response.reasoning_text.delta") {
|
|
1782
1851
|
const slot = outputSlots.resolve(event, "thinking");
|
|
1783
1852
|
if (!slot) continue;
|
|
1784
|
-
slot
|
|
1785
|
-
stream.push({
|
|
1786
|
-
type: "thinking_delta",
|
|
1787
|
-
contentIndex: slot.contentIndex,
|
|
1788
|
-
delta: event.delta,
|
|
1789
|
-
partial: output
|
|
1790
|
-
});
|
|
1853
|
+
appendThinkingDelta(slot, event.delta);
|
|
1791
1854
|
} else if (event.type === "response.content_part.added") {
|
|
1792
1855
|
const slot = outputSlots.resolve(event, "text");
|
|
1793
1856
|
if (!slot) continue;
|
|
@@ -1807,15 +1870,7 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1807
1870
|
slot.item.content.push(lastPart);
|
|
1808
1871
|
}
|
|
1809
1872
|
lastPart.text += event.delta;
|
|
1810
|
-
|
|
1811
|
-
else if (slot.block && slot.contentIndex !== void 0) {
|
|
1812
|
-
slot.block.text += event.delta;
|
|
1813
|
-
stream.push({
|
|
1814
|
-
type: "text_delta",
|
|
1815
|
-
contentIndex: slot.contentIndex,
|
|
1816
|
-
delta: event.delta
|
|
1817
|
-
});
|
|
1818
|
-
}
|
|
1873
|
+
projectTextDelta(slot, event.delta);
|
|
1819
1874
|
} else if (isAzureResponsesTextDeltaEvent(event)) {
|
|
1820
1875
|
const slot = outputSlots.resolve(event, "text");
|
|
1821
1876
|
if (!slot) continue;
|
|
@@ -1829,15 +1884,7 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1829
1884
|
slot.item.content.push(lastPart);
|
|
1830
1885
|
}
|
|
1831
1886
|
lastPart.text += event.delta;
|
|
1832
|
-
|
|
1833
|
-
else if (slot.block && slot.contentIndex !== void 0) {
|
|
1834
|
-
slot.block.text += event.delta;
|
|
1835
|
-
stream.push({
|
|
1836
|
-
type: "text_delta",
|
|
1837
|
-
contentIndex: slot.contentIndex,
|
|
1838
|
-
delta: event.delta
|
|
1839
|
-
});
|
|
1840
|
-
}
|
|
1887
|
+
projectTextDelta(slot, event.delta);
|
|
1841
1888
|
} else if (event.type === "response.refusal.delta") {
|
|
1842
1889
|
const slot = outputSlots.resolve(event, "text");
|
|
1843
1890
|
if (!slot) continue;
|
|
@@ -1851,15 +1898,7 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1851
1898
|
slot.item.content.push(lastPart);
|
|
1852
1899
|
}
|
|
1853
1900
|
lastPart.refusal += event.delta;
|
|
1854
|
-
|
|
1855
|
-
else if (slot.block && slot.contentIndex !== void 0) {
|
|
1856
|
-
slot.block.text += event.delta;
|
|
1857
|
-
stream.push({
|
|
1858
|
-
type: "text_delta",
|
|
1859
|
-
contentIndex: slot.contentIndex,
|
|
1860
|
-
delta: event.delta
|
|
1861
|
-
});
|
|
1862
|
-
}
|
|
1901
|
+
projectTextDelta(slot, event.delta);
|
|
1863
1902
|
} else if (event.type === "response.function_call_arguments.delta") {
|
|
1864
1903
|
const toolCall = streamingToolCalls.resolve(event);
|
|
1865
1904
|
if (toolCall) {
|
|
@@ -1983,8 +2022,12 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
1983
2022
|
finalizeToolCall(item, readResponsesOutputIndex(event), streamingToolCall, validated);
|
|
1984
2023
|
}
|
|
1985
2024
|
} else if (event.type === "response.completed" || event.type === "response.incomplete") {
|
|
1986
|
-
if (event.type === "response.incomplete" && streamingToolCalls.hasActive()) throw new Error("Responses stream completed with unresolved tool calls");
|
|
1987
2025
|
terminal.finalizeResponse(event.response, event.type);
|
|
2026
|
+
if (incompleteToolCall) {
|
|
2027
|
+
if (output.errorMessage) throw new Error(output.errorMessage);
|
|
2028
|
+
resolveCompletedResponsesToolCall(incompleteToolCall);
|
|
2029
|
+
}
|
|
2030
|
+
if (event.type === "response.incomplete" && streamingToolCalls.hasActive()) throw new Error(output.errorMessage ?? "Responses stream completed with unresolved tool calls");
|
|
1988
2031
|
if (event.type === "response.completed" || output.stopReason === "length") {
|
|
1989
2032
|
const items = event.response.output ?? [];
|
|
1990
2033
|
const completeToolCall = event.type === "response.completed" ? prepareTerminalToolCalls(items) : void 0;
|
|
@@ -2010,26 +2053,26 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
|
|
|
2010
2053
|
}
|
|
2011
2054
|
//#endregion
|
|
2012
2055
|
//#region packages/ai/src/providers/openai-responses-tools.ts
|
|
2013
|
-
|
|
2014
|
-
const MAX_STRICT_TOOL_DOWNGRADE_DIAGNOSTIC_KEYS = 64;
|
|
2015
|
-
const loggedStrictToolDowngradeDiagnosticKeys = /* @__PURE__ */ new Set();
|
|
2016
|
-
/** Converts and returns the projection used to reconcile tool choices. */
|
|
2056
|
+
/** Projects direct provider descriptors before resolving their strict policy. */
|
|
2017
2057
|
function convertResponsesToolPayload(tools, options) {
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2058
|
+
return convertProjectedResponsesTools(projectOpenAITools(tools), resolveResponsesStrictToolSetting(options), options?.model);
|
|
2059
|
+
}
|
|
2060
|
+
/** Uses caller-prepared facts without rereading descriptors or resolving host policy again. */
|
|
2061
|
+
function convertProjectedResponsesTools(projection, strictSetting, model) {
|
|
2062
|
+
const strict = model ? resolveOpenAIStrictToolFlagWithDiagnostics(projection, strictSetting, {
|
|
2063
|
+
transport: "responses",
|
|
2064
|
+
model
|
|
2065
|
+
}) : resolveOpenAIProjectedToolsStrictToolFlag(projection, strictSetting);
|
|
2066
|
+
return sortPromptCacheToolsByName(projection.tools).map((tool) => {
|
|
2067
|
+
const result = {
|
|
2068
|
+
type: "function",
|
|
2069
|
+
name: tool.name,
|
|
2070
|
+
description: tool.description,
|
|
2071
|
+
parameters: normalizeOpenAIStrictToolParameters(tool.parameters, strict === true, model?.compat)
|
|
2072
|
+
};
|
|
2073
|
+
if (strict !== void 0) result.strict = strict;
|
|
2074
|
+
return result;
|
|
2075
|
+
});
|
|
2033
2076
|
}
|
|
2034
2077
|
function resolveResponsesStrictToolSetting(options) {
|
|
2035
2078
|
if (options?.strict !== void 0) return options.strict;
|
|
@@ -2039,47 +2082,8 @@ function resolveResponsesStrictToolSetting(options) {
|
|
|
2039
2082
|
});
|
|
2040
2083
|
return false;
|
|
2041
2084
|
}
|
|
2042
|
-
function resolveResponsesStrictToolFlag(projection, strictSetting, model) {
|
|
2043
|
-
const strict = resolveOpenAIProjectedToolsStrictToolFlag(projection, strictSetting);
|
|
2044
|
-
if (strictSetting === true && strict === false && model) getAiTransportHost().logDebug(LOG_SUBSYSTEM, () => {
|
|
2045
|
-
const diagnostics = findOpenAIStrictToolProjectionDiagnostics(projection);
|
|
2046
|
-
if (!shouldLogStrictToolDowngradeDiagnostic(diagnostics, model)) return null;
|
|
2047
|
-
const sample = diagnostics.slice(0, 5).map((entry) => ({
|
|
2048
|
-
tool: entry.toolName ?? `tool[${entry.toolIndex}]`,
|
|
2049
|
-
violations: entry.violations.slice(0, 8)
|
|
2050
|
-
}));
|
|
2051
|
-
return {
|
|
2052
|
-
message: `OpenAI responses tool schema strict mode downgraded to strict=false for ${model.provider ?? "unknown"}/${model.id ?? "unknown"} because ${diagnostics.length} tool schema(s) are not strict-compatible`,
|
|
2053
|
-
data: {
|
|
2054
|
-
provider: model.provider,
|
|
2055
|
-
model: model.id,
|
|
2056
|
-
incompatibleToolCount: diagnostics.length,
|
|
2057
|
-
sample
|
|
2058
|
-
}
|
|
2059
|
-
};
|
|
2060
|
-
});
|
|
2061
|
-
return strict;
|
|
2062
|
-
}
|
|
2063
|
-
function shouldLogStrictToolDowngradeDiagnostic(diagnostics, model) {
|
|
2064
|
-
const key = createHash("sha256").update(JSON.stringify({
|
|
2065
|
-
provider: model.provider,
|
|
2066
|
-
model: model.id,
|
|
2067
|
-
diagnostics: diagnostics.map((entry) => ({
|
|
2068
|
-
toolIndex: entry.toolIndex,
|
|
2069
|
-
toolName: entry.toolName ?? null,
|
|
2070
|
-
violations: entry.violations
|
|
2071
|
-
}))
|
|
2072
|
-
})).digest("hex");
|
|
2073
|
-
if (loggedStrictToolDowngradeDiagnosticKeys.has(key)) return false;
|
|
2074
|
-
if (loggedStrictToolDowngradeDiagnosticKeys.size >= MAX_STRICT_TOOL_DOWNGRADE_DIAGNOSTIC_KEYS) loggedStrictToolDowngradeDiagnosticKeys.clear();
|
|
2075
|
-
loggedStrictToolDowngradeDiagnosticKeys.add(key);
|
|
2076
|
-
return true;
|
|
2077
|
-
}
|
|
2078
2085
|
//#endregion
|
|
2079
2086
|
//#region packages/ai/src/providers/openai-responses-shared.ts
|
|
2080
|
-
function isResponsesReasoningEffort(effort) {
|
|
2081
|
-
return effort === "minimal" || effort === "low" || effort === "medium" || effort === "high" || effort === "xhigh" || effort === "max";
|
|
2082
|
-
}
|
|
2083
2087
|
function convertResponsesMessages(model, context, allowedToolCallProviders, options) {
|
|
2084
2088
|
return convertProviderResponsesMessages(model, context, allowedToolCallProviders, options);
|
|
2085
2089
|
}
|
|
@@ -2096,33 +2100,34 @@ function applyResponsesServiceTierPricing(usage, serviceTier, model) {
|
|
|
2096
2100
|
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
2097
2101
|
}
|
|
2098
2102
|
function resolveResponsesReasoningEffort(model, reasoning) {
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2103
|
+
if (!reasoning) return;
|
|
2104
|
+
const clampedReasoning = model.reasoning && model.thinkingLevelMap?.[reasoning] === void 0 && resolveOpenAIModelReasoningEfforts(model)?.includes(reasoning) ? reasoning : clampThinkingLevel(model, reasoning);
|
|
2105
|
+
return clampedReasoning === "off" ? void 0 : clampedReasoning;
|
|
2106
|
+
}
|
|
2107
|
+
function resolveResponsesRequestReasoningEffort(model, reasoning) {
|
|
2108
|
+
const mapped = model.thinkingLevelMap?.[reasoning === "none" ? "off" : reasoning];
|
|
2109
|
+
if (mapped !== void 0) return mapped ?? void 0;
|
|
2110
|
+
return resolveOpenAIModelReasoningEfforts(model) === void 0 ? reasoning === "off" ? "none" : reasoning : resolveOpenAIReasoningEffortForModel({
|
|
2111
|
+
model,
|
|
2112
|
+
effort: reasoning
|
|
2113
|
+
});
|
|
2110
2114
|
}
|
|
2111
2115
|
function applyCommonResponsesParams(params, model, context, options, config) {
|
|
2112
2116
|
if (options?.maxTokens) params.max_output_tokens = Math.max(options.maxTokens, 16);
|
|
2113
2117
|
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) params.temperature = options.temperature;
|
|
2114
2118
|
if (context.tools) {
|
|
2115
|
-
const
|
|
2116
|
-
if (
|
|
2119
|
+
const tools = convertResponsesToolPayload(context.tools, { model });
|
|
2120
|
+
if (tools.length > 0) params.tools = tools;
|
|
2117
2121
|
}
|
|
2118
2122
|
if (!model.reasoning) return;
|
|
2123
|
+
const requestedEffort = options?.reasoningEffort ?? (options?.reasoningSummary ? "medium" : config?.setDefaultReasoningOff ?? true ? "off" : void 0);
|
|
2124
|
+
const effort = requestedEffort === void 0 ? void 0 : resolveResponsesRequestReasoningEffort(model, requestedEffort);
|
|
2125
|
+
if (effort === void 0) return;
|
|
2126
|
+
params.reasoning = { effort };
|
|
2119
2127
|
if (options?.reasoningEffort || options?.reasoningSummary) {
|
|
2120
|
-
params.reasoning =
|
|
2121
|
-
effort: options?.reasoningEffort ? model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort : "medium",
|
|
2122
|
-
summary: options?.reasoningSummary || "auto"
|
|
2123
|
-
};
|
|
2128
|
+
params.reasoning.summary = options?.reasoningSummary || "auto";
|
|
2124
2129
|
params.include = ["reasoning.encrypted_content"];
|
|
2125
|
-
}
|
|
2130
|
+
}
|
|
2126
2131
|
}
|
|
2127
2132
|
function buildResponsesRequestOptions(options) {
|
|
2128
2133
|
return {
|
|
@@ -2213,4 +2218,4 @@ async function runResponsesStreamLifecycle(params) {
|
|
|
2213
2218
|
}
|
|
2214
2219
|
}
|
|
2215
2220
|
//#endregion
|
|
2216
|
-
export {
|
|
2221
|
+
export { resolveReplayableResponsesMessageId as $, OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE as A, resolveAzureOpenAIApiVersion as B, summarizeResponsesFailedNoDetailsObservation as C, readResponsesToolCallItemIdentity as D, createResponsesToolCallTracker as E, isResponsesTextDeltaEventType as F, recordResponsesInputReplay as G, buildResponsesInputMessage as H, resolveResponsesMessageSnapshotCollapse as I, buildOpenAIResponsesReasoningReplayMetadata as J, responsesInputFingerprint as K, commitResponsesEncryptedContentAttempt as L, isAzureResponsesTextDeltaEvent as M, isAzureResponsesTextDeltaEventType as N, AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE as O, isResponsesTextContentPartType as P, suppressOpenAIResponsesCompaction as Q, createResponsesStreamWithEncryptedContentRetry as R, summarizeOpenAITransportError as S, summarizeResponsesTools as T, convertResponsesMessages$1 as U, resolveNextResponsesEncryptedContentAttempt as V, createOpenAIResponsesAssistantOutput as W, isOpenAIResponsesReplayContext as X, captureOpenAIResponsesCompaction as Y, resolveNewestOpenAIResponsesCompactionReplay as Z, logResponsesFailedNoDetails as _, resolveResponsesReasoningEffort as a, stringifyRedactedEvent as b, convertProjectedResponsesTools as c, mapResponsesTerminalUsage as d, readResponsesReasoningTokens as f, buildResponsesFailedNoDetailsObservation as g, ResponsesStreamFailure as h, createResponsesAssistantOutput as i, OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE as j, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE as k, convertResponsesToolPayload as l, observeResponsesStream as m, applyResponsesServiceTierPricing as n, resolveResponsesRequestReasoningEffort as o, resolveResponsesTerminalStopReason as p, CompactionReplayRefreshRequiredError as q, convertResponsesMessages as r, runResponsesStreamLifecycle as s, applyCommonResponsesParams as t, processResponsesStream as u, normalizeResponsesFailedEvent as v, summarizeResponsesPayload as w, stringifyRedactedPayload as x, safeDebugValue as y, isInvalidEncryptedContentError as z };
|