@openclaw/ai 2026.9.3 → 2026.9.5
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 +1 -1
- package/dist/{anthropic-CZy5U0NY.mjs → anthropic-COtDvgtt.mjs} +16 -16
- package/dist/{anthropic-payload-policy-wuRCb6MH.d.mts → anthropic-payload-policy-5Erq1Nzy.d.mts} +3 -3
- package/dist/{anthropic-stream-reducer-B_yo_7pf.mjs → anthropic-stream-reducer-BvdYYWL8.mjs} +56 -47
- package/dist/{api-registry-CB1-1oQ2.d.mts → api-registry-Ba2Cv-ut.d.mts} +2 -2
- package/dist/{assistant-output-iqnlJCV2.mjs → assistant-output-BsEkB-vU.mjs} +1 -1
- package/dist/{azure-openai-responses-Crpa40QR.mjs → azure-openai-responses-YrgnD583.mjs} +6 -9
- package/dist/{base64-D-su8YVo.mjs → base64-BQOzsvUH.mjs} +4 -4
- package/dist/credential-redaction-BKv49aiv.d.mts +24 -0
- package/dist/{diagnostics-dV98PqIy.mjs → diagnostics-Dm4bisWG.mjs} +89 -2
- package/dist/diagnostics.d.mts +4 -23
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-C1Z2piyk.d.mts → event-stream-CCoa-qSI.d.mts} +1 -1
- package/dist/event-stream-DmSCpi1T.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{google-BDPriaVe.mjs → google-BuhpRO9r.mjs} +7 -10
- package/dist/{google-messages-CVn9eFpF.mjs → google-messages-CyWnYlh0.mjs} +3 -4
- package/dist/{google-shared-BedY23XS.mjs → google-shared-BT5ZeNer.mjs} +13 -13
- package/dist/{google-vertex-DMz8XQCn.mjs → google-vertex-C7EplRvt.mjs} +5 -8
- package/dist/{host-CWuF-sS3.mjs → host-B4MeUNBc.mjs} +145 -12
- package/dist/{host-DK3wmS3e.d.mts → host-FZ1RA_qD.d.mts} +7 -3
- package/dist/{host-policy-CAopLRKA.mjs → host-policy-DUnXSx0I.mjs} +1 -1
- package/dist/{index-CQ6LTHw8.d.mts → index-DaF2QbwS.d.mts} +5 -10
- package/dist/index.d.mts +7 -8
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +6 -7
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai-completions-compat.d.mts +2 -0
- package/dist/internal/openai-completions-compat.mjs +2 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +3 -2
- package/dist/internal/openai.d.mts +10 -53
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/runtime.d.mts +43 -10
- package/dist/internal/runtime.mjs +5 -11
- package/dist/internal/shared.d.mts +35 -5
- package/dist/internal/shared.mjs +4 -4
- package/dist/internal/tool-schema.d.mts +3 -3
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral--m-Jm6VZ.mjs → mistral-moA-mbwl.mjs} +9 -16
- package/dist/{openai-chatgpt-responses-nDZccFW-.mjs → openai-chatgpt-responses-DWID3EFO.mjs} +76 -33
- package/dist/{openai-completions-KuoZyx0d.mjs → openai-completions-DJ1Vm-CD.mjs} +12 -13
- package/dist/{openai-prompt-cache-BI0rkM-5.mjs → openai-completions-compat-CkwdxTZx.mjs} +5 -50
- package/dist/{openai-completions-compat-CXn3T1we.d.mts → openai-completions-compat-JE7gqxb9.d.mts} +4 -4
- package/dist/{openai-completions-stream-BQk3SkLD.mjs → openai-completions-stream-Bu98b0Hv.mjs} +128 -99
- package/dist/openai-prompt-cache-1wfaIszn.mjs +46 -0
- package/dist/{openai-prompt-cache-rrutvqxq.d.mts → openai-prompt-cache-CJ_xEevu.d.mts} +2 -2
- package/dist/{openai-provider-client-ha_WxTyj.mjs → openai-provider-client-DPo0Hmak.mjs} +2 -2
- package/dist/{openai-reasoning-effort-BK7FbcLT.mjs → openai-reasoning-effort-NlFZmfEu.mjs} +87 -19
- package/dist/{openai-responses-D99dOzKI.mjs → openai-responses-BejZzQCP.mjs} +9 -13
- package/dist/{openai-responses-compaction-window-D5jbzCi3.mjs → openai-responses-compaction-window-D6P5oZP5.mjs} +21 -140
- package/dist/openai-responses-contracts-DWrfMODE.mjs +81 -0
- package/dist/{openai-responses-contracts-B55afwRo.d.mts → openai-responses-contracts-Dflvrfa8.d.mts} +10 -39
- package/dist/{openai-responses-payload-policy-rLRPsSmB.d.mts → openai-responses-payload-policy-C7GsA1y0.d.mts} +5 -3
- package/dist/openai-responses-prompt-observer-internal-C15_-OwV.mjs +195 -0
- package/dist/{openai-responses-shared-ZyQEzS5i.mjs → openai-responses-shared-CwsziD_m.mjs} +390 -183
- package/dist/openai-responses-terminal-usage-Dl3J6zrf.d.mts +47 -0
- package/dist/{openai-tool-schema-CzjyYXun.mjs → openai-tool-schema-BO8rwyAD.mjs} +92 -68
- package/dist/{openai-transport-params-DNasp2fU.mjs → openai-transport-params-DQeuAvBl.mjs} +162 -51
- package/dist/positive-integer-DtjCkbue.mjs +8 -0
- package/dist/{provider-error-C6TbKiey.mjs → provider-error-DDqw9Qda.mjs} +140 -36
- package/dist/{provider-options-BXr9Ec83.d.mts → provider-options-DprLsWh9.d.mts} +9 -6
- package/dist/{provider-replay-context-BuSUaAk5.mjs → provider-replay-context-CnUSOwhr.mjs} +1 -1
- package/dist/{provider-transcript-transform-pPmUIwKt.mjs → provider-transcript-transform-BsRAhuWJ.mjs} +1 -1
- package/dist/provider-transport-turn-state-CkGToCD2.mjs +42 -0
- package/dist/{provider-types-CAV0Og3m.d.mts → provider-types-CAKRC7N5.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -7
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +10 -10
- package/dist/{reasoning-tag-text-partitioner-BQBi4B9d.mjs → reasoning-tag-text-partitioner-Dy9IO8Dc.mjs} +15 -14
- package/dist/{session-affinity-CCH7eYdB.mjs → session-affinity-Bcunsn4I.mjs} +5 -2
- package/dist/{simple-options-tcKOqnpF.mjs → simple-options-C6cFWj_f.mjs} +26 -5
- package/dist/{src-B2Q_6G8V.mjs → src-DeKjbE8I.mjs} +3 -6
- package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-C9ZadkJW.mjs} +1 -1
- package/dist/{string-normalization-CmLIasuf.mjs → string-normalization-J9ZiLfGO.mjs} +13 -1
- package/dist/tool-schema-json-projection-CD9c_fK8.mjs +134 -0
- package/dist/{transport-stream-shared-DOxpGJ-H.d.mts → transport-stream-shared-BbUkFaHi.d.mts} +20 -36
- package/dist/{transport-stream-shared-Cu3ZPhNW.mjs → transport-stream-shared-D-6FQSHm.mjs} +223 -11
- package/dist/{transport-utils-CCooe-cr.mjs → transport-utils-1cyq5Y7x.mjs} +4 -7
- package/dist/transports.d.mts +51 -165
- package/dist/transports.mjs +172 -507
- package/dist/{types-Dy1q0CSu.d.mts → types-4_uVs5WH.d.mts} +49 -3
- package/dist/types-DkJfb4W3.d.mts +1 -0
- package/dist/types-LFWwv0cF.mjs +8 -0
- package/dist/types.d.mts +6 -7
- package/dist/types.mjs +4 -4
- package/dist/{validation-CaFUZN9B.d.mts → validation-Ctzu2DhF.d.mts} +1 -1
- package/dist/{validation-BDzVDnTs.mjs → validation-Dw7cb6BV.mjs} +1 -0
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +10 -5
- package/dist/diagnostics-DnPnOui6.d.mts +0 -29
- package/dist/event-stream-I_GlBsuZ.d.mts +0 -1
- package/dist/hash-CHgqbJmD.mjs +0 -16
- package/dist/json-parse-Dw_hnxsA.mjs +0 -146
- package/dist/openai-responses-prompt-observer-internal-tApyTLVu.mjs +0 -32
- package/dist/sanitize-unicode-Bb-v9meu.mjs +0 -83
- package/dist/tool-schema-json-projection-ClptDdAO.mjs +0 -82
- package/dist/types-BADKjDBI.d.mts +0 -1
- package/dist/types-BDdaOVi2.mjs +0 -6
|
@@ -1,91 +1,15 @@
|
|
|
1
|
-
import "./src-B2Q_6G8V.mjs";
|
|
2
|
-
import { n as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE } from "./types-BDdaOVi2.mjs";
|
|
3
1
|
import { i as normalizeOptionalLowercaseString, n as normalizeLowercaseStringOrEmpty, s as readStringValue } from "./string-coerce-fsri9iCu.mjs";
|
|
4
2
|
import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { l as supportsOpenAIReasoningEffort } from "./openai-reasoning-effort-NlFZmfEu.mjs";
|
|
4
|
+
import { t as canonicalizeBase64 } from "./base64-BQOzsvUH.mjs";
|
|
5
|
+
import { t as parsePositiveInteger } from "./positive-integer-DtjCkbue.mjs";
|
|
6
|
+
import { i as OPENAI_RESPONSES_APIS } from "./openai-responses-contracts-DWrfMODE.mjs";
|
|
8
7
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
9
8
|
//#region packages/model-catalog-core/src/provider-id.ts
|
|
10
9
|
function normalizeProviderId(provider) {
|
|
11
10
|
return normalizeLowercaseStringOrEmpty(provider);
|
|
12
11
|
}
|
|
13
12
|
//#endregion
|
|
14
|
-
//#region packages/ai/src/transports/openai-responses-contracts.ts
|
|
15
|
-
const DEFAULT_AZURE_OPENAI_API_VERSION = "preview";
|
|
16
|
-
const OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS = "Follow the user request.";
|
|
17
|
-
const AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS = 3e4;
|
|
18
|
-
const RESPONSE_FAILED_NO_DETAILS_MESSAGE = "Unknown error (no error details in response)";
|
|
19
|
-
const OPENAI_RESPONSES_REASONING_REPLAY_META_KEY = "__openclaw_replay";
|
|
20
|
-
const OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY = "openclawReasoningReplay";
|
|
21
|
-
const OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE = "openai-responses-compaction";
|
|
22
|
-
const OPENAI_RESPONSES_RETAINED_COMPACTION_REPLAY_TYPE = "openai-responses-retained-compaction";
|
|
23
|
-
const OPENAI_RESPONSES_APIS = /* @__PURE__ */ new Set([
|
|
24
|
-
"openai-responses",
|
|
25
|
-
"azure-openai-responses",
|
|
26
|
-
"openai-chatgpt-responses",
|
|
27
|
-
"openclaw-openai-responses-transport",
|
|
28
|
-
"openclaw-openai-chatgpt-responses-transport",
|
|
29
|
-
"openclaw-azure-openai-responses-transport"
|
|
30
|
-
]);
|
|
31
|
-
var OpenAIResponsesWebSocketPreDispatchError = class extends Error {
|
|
32
|
-
constructor(cause) {
|
|
33
|
-
super("OpenAI Responses WebSocket failed before request dispatch", { cause });
|
|
34
|
-
this.name = "OpenAIResponsesWebSocketPreDispatchError";
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var OpenAIResponsesWebSocketPostDispatchError = class extends Error {
|
|
38
|
-
constructor(cause) {
|
|
39
|
-
super("OpenAI Responses WebSocket failed after request dispatch; outcome is unknown", { cause });
|
|
40
|
-
this.code = PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE;
|
|
41
|
-
this.name = "OpenAIResponsesWebSocketPostDispatchError";
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var OpenAIResponsesWebSocketServerError = class extends Error {
|
|
45
|
-
constructor(code, status, param, message, cause) {
|
|
46
|
-
super(message, { cause });
|
|
47
|
-
this.code = code;
|
|
48
|
-
this.status = status;
|
|
49
|
-
this.param = param;
|
|
50
|
-
this.name = "OpenAIResponsesWebSocketServerError";
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var OpenAIResponsesWebSocketSafeRetryError = class extends OpenAIResponsesWebSocketServerError {};
|
|
54
|
-
function readWebSocketServerError(value) {
|
|
55
|
-
if (!isRecord(value) || value.type !== "error") return;
|
|
56
|
-
const details = isRecord(value.error) ? value.error : value;
|
|
57
|
-
if (typeof details.code !== "string" || typeof details.message !== "string") return;
|
|
58
|
-
const rawStatus = value.status ?? value.status_code;
|
|
59
|
-
return {
|
|
60
|
-
code: details.code,
|
|
61
|
-
message: details.message,
|
|
62
|
-
param: typeof details.param === "string" ? details.param : null,
|
|
63
|
-
status: typeof rawStatus === "number" ? rawStatus : void 0
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function parseOpenAIResponsesWebSocketServerError(cause) {
|
|
67
|
-
if (!isRecord(cause)) return;
|
|
68
|
-
let details = readWebSocketServerError(cause.error) ?? readWebSocketServerError(cause);
|
|
69
|
-
if (!details && typeof cause.message === "string") try {
|
|
70
|
-
details = readWebSocketServerError(JSON.parse(cause.message));
|
|
71
|
-
} catch {}
|
|
72
|
-
if (!details) return;
|
|
73
|
-
return new (details.code === "previous_response_not_found" || details.code === "websocket_connection_limit_reached" || details.code === "invalid_encrypted_content" || details.code === "thinking_signature_invalid" ? OpenAIResponsesWebSocketSafeRetryError : OpenAIResponsesWebSocketServerError)(details.code, details.status, details.param, details.message, cause);
|
|
74
|
-
}
|
|
75
|
-
const PROMPT_OBSERVER = Symbol("openaiResponsesPromptObserver");
|
|
76
|
-
const responsesPromptObserver = {
|
|
77
|
-
set(options, observer) {
|
|
78
|
-
Reflect.set(options, PROMPT_OBSERVER, observer);
|
|
79
|
-
},
|
|
80
|
-
get(options) {
|
|
81
|
-
return Reflect.get(options, PROMPT_OBSERVER);
|
|
82
|
-
},
|
|
83
|
-
copy(source, target) {
|
|
84
|
-
const observer = source && responsesPromptObserver.get(source);
|
|
85
|
-
if (observer) responsesPromptObserver.set(target, observer);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
//#endregion
|
|
89
13
|
//#region packages/ai/src/transports/openai-responses-payload-policy.ts
|
|
90
14
|
/**
|
|
91
15
|
* OpenAI Responses payload policy.
|
|
@@ -97,33 +21,6 @@ const OPENAI_RESPONSES_PROVIDERS = /* @__PURE__ */ new Set([
|
|
|
97
21
|
"azure-openai",
|
|
98
22
|
"azure-openai-responses"
|
|
99
23
|
]);
|
|
100
|
-
const LOCAL_ENDPOINT_HOSTS = /* @__PURE__ */ new Set([
|
|
101
|
-
"localhost",
|
|
102
|
-
"127.0.0.1",
|
|
103
|
-
"::1",
|
|
104
|
-
"[::1]"
|
|
105
|
-
]);
|
|
106
|
-
const MODELSTUDIO_NATIVE_BASE_URLS = /* @__PURE__ */ new Set([
|
|
107
|
-
"https://coding-intl.dashscope.aliyuncs.com/v1",
|
|
108
|
-
"https://coding.dashscope.aliyuncs.com/v1",
|
|
109
|
-
"https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
110
|
-
"https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
|
|
111
|
-
]);
|
|
112
|
-
const MOONSHOT_NATIVE_BASE_URLS = /* @__PURE__ */ new Set(["https://api.moonshot.ai/v1", "https://api.moonshot.cn/v1"]);
|
|
113
|
-
function normalizeComparableBaseUrl(value) {
|
|
114
|
-
const trimmed = readStringValue(value)?.trim();
|
|
115
|
-
if (!trimmed) return;
|
|
116
|
-
const parsedValue = /^[a-z0-9.[\]-]+(?::\d+)?(?:[/?#].*)?$/i.test(trimmed) ? `https://${trimmed}` : trimmed;
|
|
117
|
-
try {
|
|
118
|
-
const url = new URL(parsedValue);
|
|
119
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
120
|
-
url.hash = "";
|
|
121
|
-
url.search = "";
|
|
122
|
-
return url.toString().replace(/\/+$/, "").toLowerCase();
|
|
123
|
-
} catch {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
24
|
function resolveUrlHostname(value) {
|
|
128
25
|
const trimmed = readStringValue(value)?.trim();
|
|
129
26
|
if (!trimmed) return;
|
|
@@ -137,45 +34,22 @@ function resolveUrlHostname(value) {
|
|
|
137
34
|
}
|
|
138
35
|
}
|
|
139
36
|
}
|
|
140
|
-
function
|
|
141
|
-
return suffix.startsWith(".") || suffix.startsWith("-") ? host.endsWith(suffix) : host === suffix || host.endsWith(`.${suffix}`);
|
|
142
|
-
}
|
|
143
|
-
function isLocalEndpointHost(host) {
|
|
144
|
-
return LOCAL_ENDPOINT_HOSTS.has(host) || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal");
|
|
145
|
-
}
|
|
146
|
-
function resolveBundledOpenAIResponsesEndpointClass(baseUrl) {
|
|
37
|
+
function resolveOpenAIResponsesEndpointClass(baseUrl) {
|
|
147
38
|
const trimmed = readStringValue(baseUrl)?.trim();
|
|
148
39
|
if (!trimmed) return "default";
|
|
149
40
|
const host = resolveUrlHostname(trimmed);
|
|
150
|
-
if (!host) return "
|
|
151
|
-
const comparableBaseUrl = normalizeComparableBaseUrl(trimmed);
|
|
41
|
+
if (!host) return "custom";
|
|
152
42
|
switch (host) {
|
|
153
|
-
case "api.anthropic.com": return "anthropic-public";
|
|
154
|
-
case "api.cerebras.ai": return "cerebras-native";
|
|
155
|
-
case "llm.chutes.ai": return "chutes-native";
|
|
156
|
-
case "api.deepseek.com": return "deepseek-native";
|
|
157
|
-
case "api.groq.com": return "groq-native";
|
|
158
|
-
case "api.mistral.ai": return "mistral-public";
|
|
159
43
|
case "api.openai.com": return "openai-public";
|
|
160
44
|
case "chatgpt.com": return "openai";
|
|
161
|
-
case "generativelanguage.googleapis.com": return "google-generative-ai";
|
|
162
|
-
case "aiplatform.googleapis.com": return "google-vertex";
|
|
163
45
|
case "api.x.ai": return "xai-native";
|
|
164
|
-
case "api.z.ai": return "zai-native";
|
|
165
46
|
}
|
|
166
|
-
if (hostMatchesSuffix(host, ".githubcopilot.com")) return "github-copilot-native";
|
|
167
47
|
if ([
|
|
168
48
|
".openai.azure.com",
|
|
169
49
|
".cognitiveservices.azure.com",
|
|
170
50
|
".services.ai.azure.com",
|
|
171
51
|
".api.cognitive.microsoft.com"
|
|
172
|
-
].some((suffix) =>
|
|
173
|
-
if (hostMatchesSuffix(host, "openrouter.ai")) return "openrouter";
|
|
174
|
-
if (hostMatchesSuffix(host, "opencode.ai")) return "opencode-native";
|
|
175
|
-
if (hostMatchesSuffix(host, "-aiplatform.googleapis.com")) return "google-vertex";
|
|
176
|
-
if (comparableBaseUrl && MOONSHOT_NATIVE_BASE_URLS.has(comparableBaseUrl)) return "moonshot-native";
|
|
177
|
-
if (comparableBaseUrl && MODELSTUDIO_NATIVE_BASE_URLS.has(comparableBaseUrl)) return "modelstudio-native";
|
|
178
|
-
if (isLocalEndpointHost(host)) return "local";
|
|
52
|
+
].some((suffix) => host.endsWith(suffix))) return "azure-openai";
|
|
179
53
|
return "custom";
|
|
180
54
|
}
|
|
181
55
|
function isOpenAIResponsesApi(api) {
|
|
@@ -190,7 +64,7 @@ function resolveOpenAIResponsesPayloadCapabilities(model) {
|
|
|
190
64
|
const provider = normalizeOptionalLowercaseString(model.provider);
|
|
191
65
|
const api = normalizeOptionalLowercaseString(model.api);
|
|
192
66
|
const isOpenAIProvider = provider === "openai";
|
|
193
|
-
const endpointClass =
|
|
67
|
+
const endpointClass = resolveOpenAIResponsesEndpointClass(model.baseUrl);
|
|
194
68
|
const isResponsesApi = isOpenAIResponsesApi(api);
|
|
195
69
|
const usesConfiguredBaseUrl = endpointClass !== "default";
|
|
196
70
|
const usesKnownNativeOpenAIEndpoint = endpointClass === "openai-public" || endpointClass === "openai" || endpointClass === "azure-openai";
|
|
@@ -200,9 +74,11 @@ function resolveOpenAIResponsesPayloadCapabilities(model) {
|
|
|
200
74
|
const promptCacheKeySupport = readCompatPayloadBoolean(model.compat, "supportsPromptCacheKey");
|
|
201
75
|
const shouldStripResponsesPromptCache = promptCacheKeySupport === true ? false : promptCacheKeySupport === false ? isResponsesApi : isResponsesApi && usesExplicitProxyLikeEndpoint;
|
|
202
76
|
const supportsResponsesStoreField = readCompatPayloadBoolean(model.compat, "supportsStore") !== false && isResponsesApi;
|
|
77
|
+
const explicitContinuationOptIn = (api === "openai-responses" || api === "openclaw-openai-responses-transport") && supportsResponsesStoreField && provider !== "azure-openai" && provider !== "azure-openai-responses" && readCompatPayloadBoolean(model.compat, "supportsResponsesContinuation") === true;
|
|
203
78
|
return {
|
|
204
79
|
allowsOpenAIServiceTier: provider === "openai" && (api === "openai-responses" || api === "openclaw-openai-responses-transport") && endpointClass === "openai-public" || isOpenAIProvider && (api === "openai-chatgpt-responses" || api === "openclaw-openai-chatgpt-responses-transport" || api === "openai-responses" || api === "openclaw-openai-responses-transport") && endpointClass === "openai",
|
|
205
80
|
allowsResponsesStore: supportsResponsesStoreField && api !== "openai-chatgpt-responses" && api !== "openclaw-openai-chatgpt-responses-transport" && provider !== void 0 && OPENAI_RESPONSES_PROVIDERS.has(provider) && usesKnownNativeOpenAIEndpoint,
|
|
81
|
+
explicitContinuationOptIn,
|
|
206
82
|
shouldStripResponsesPromptCache,
|
|
207
83
|
supportsResponsesStoreField,
|
|
208
84
|
usesKnownNativeOpenAIRoute,
|
|
@@ -227,11 +103,14 @@ function resolveOpenAIResponsesServerCompactionPlan(model, extraParams) {
|
|
|
227
103
|
threshold: enabled ? parsePositiveInteger(extraParams?.responsesCompactThreshold) ?? resolveOpenAIResponsesCompactThreshold(model) : void 0
|
|
228
104
|
};
|
|
229
105
|
}
|
|
230
|
-
/** Resolve the
|
|
231
|
-
function resolveOpenAIResponsesCompactEndpointPlan(model, extraParams) {
|
|
106
|
+
/** Resolve the Responses compact-endpoint gate for one route and compaction purpose. */
|
|
107
|
+
function resolveOpenAIResponsesCompactEndpointPlan(model, extraParams, purpose = "manual") {
|
|
232
108
|
const configured = extraParams?.responsesCompactEndpoint;
|
|
233
109
|
const provider = typeof model.provider === "string" ? normalizeProviderId(model.provider) : "";
|
|
234
|
-
|
|
110
|
+
const api = normalizeOptionalLowercaseString(model.api);
|
|
111
|
+
const endpointClass = resolveOpenAIResponsesEndpointClass(model.baseUrl);
|
|
112
|
+
const enabledByDefault = (provider === "xai" || provider === "x-ai") && endpointClass === "xai-native" || purpose === "budget" && provider === "openai" && api === "openai-responses" && endpointClass === "openai-public";
|
|
113
|
+
return { enabled: isOpenAIResponsesApi(api) && configured !== false && (configured === true || enabledByDefault) };
|
|
235
114
|
}
|
|
236
115
|
function stripDisabledOpenAIReasoningPayload(payloadObj) {
|
|
237
116
|
const reasoning = payloadObj.reasoning;
|
|
@@ -251,15 +130,17 @@ function stripInputItemStatuses(input) {
|
|
|
251
130
|
function resolveOpenAIResponsesPayloadPolicy(model, options = {}) {
|
|
252
131
|
const capabilities = resolveOpenAIResponsesPayloadCapabilities(model);
|
|
253
132
|
const storeMode = options.storeMode ?? "provider-policy";
|
|
254
|
-
const explicitStore = storeMode === "preserve" ? void 0 : storeMode === "disable" ? capabilities.supportsResponsesStoreField ? false : void 0 : capabilities.allowsResponsesStore ? true : void 0;
|
|
133
|
+
const explicitStore = storeMode === "preserve" ? void 0 : storeMode === "disable" || storeMode === "transport-default" && !capabilities.explicitContinuationOptIn ? capabilities.supportsResponsesStoreField ? false : void 0 : capabilities.allowsResponsesStore || capabilities.explicitContinuationOptIn ? true : void 0;
|
|
255
134
|
const isResponsesApi = isOpenAIResponsesApi(normalizeOptionalLowercaseString(model.api));
|
|
256
|
-
const shouldStripDisabledReasoningPayload = isResponsesApi && (
|
|
135
|
+
const shouldStripDisabledReasoningPayload = isResponsesApi && !supportsOpenAIReasoningEffort(capabilities.usesKnownNativeOpenAIRoute ? model : { compat: model.compat }, "none");
|
|
257
136
|
const shouldStripInputStatus = isResponsesApi && !capabilities.usesKnownNativeOpenAIRoute;
|
|
258
137
|
const serverCompactionPlan = resolveOpenAIResponsesServerCompactionPlan(model, options.extraParams);
|
|
259
138
|
const usesInstructionsField = readCompatPayloadBoolean(model.compat, "supportsInstructions") ?? capabilities.usesVerifiedInstructionsEndpoint;
|
|
260
139
|
return {
|
|
261
140
|
allowsServiceTier: capabilities.allowsOpenAIServiceTier,
|
|
262
141
|
compactThreshold: serverCompactionPlan.threshold,
|
|
142
|
+
defaultManagedReasoningEffort: capabilities.usesKnownNativeOpenAIRoute && !shouldStripDisabledReasoningPayload && model.provider !== "github-copilot" ? "none" : void 0,
|
|
143
|
+
explicitContinuationOptIn: capabilities.explicitContinuationOptIn,
|
|
263
144
|
explicitStore,
|
|
264
145
|
shouldStripDisabledReasoningPayload,
|
|
265
146
|
shouldStripInputStatus,
|
|
@@ -531,4 +412,4 @@ function createBoundedOpenAIResponsesCompactionFetch(upstreamFetch) {
|
|
|
531
412
|
};
|
|
532
413
|
}
|
|
533
414
|
//#endregion
|
|
534
|
-
export {
|
|
415
|
+
export { applyOpenAIResponsesPayloadPolicy as a, resolveOpenAIResponsesServerCompactionPlan as c, sanitizeResponsesImagePayload as i, isOpenAIResponsesCompactionOutput as n, resolveOpenAIResponsesCompactEndpointPlan as o, readOpenAIResponsesCompactionWindow as r, resolveOpenAIResponsesPayloadPolicy as s, createBoundedOpenAIResponsesCompactionFetch as t };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { r as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE } from "./types-LFWwv0cF.mjs";
|
|
2
|
+
import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
3
|
+
//#region packages/ai/src/transports/openai-responses-contracts.ts
|
|
4
|
+
const DEFAULT_AZURE_OPENAI_API_VERSION = "preview";
|
|
5
|
+
const OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS = "Follow the user request.";
|
|
6
|
+
const AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS = 3e4;
|
|
7
|
+
const RESPONSE_FAILED_NO_DETAILS_MESSAGE = "Unknown error (no error details in response)";
|
|
8
|
+
const OPENAI_RESPONSES_REASONING_REPLAY_META_KEY = "__openclaw_replay";
|
|
9
|
+
const OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY = "openclawReasoningReplay";
|
|
10
|
+
const OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE = "openai-responses-compaction";
|
|
11
|
+
const OPENAI_RESPONSES_RETAINED_COMPACTION_REPLAY_TYPE = "openai-responses-retained-compaction";
|
|
12
|
+
const OPENAI_RESPONSES_APIS = /* @__PURE__ */ new Set([
|
|
13
|
+
"openai-responses",
|
|
14
|
+
"azure-openai-responses",
|
|
15
|
+
"openai-chatgpt-responses",
|
|
16
|
+
"openclaw-openai-responses-transport",
|
|
17
|
+
"openclaw-openai-chatgpt-responses-transport",
|
|
18
|
+
"openclaw-azure-openai-responses-transport"
|
|
19
|
+
]);
|
|
20
|
+
var OpenAIResponsesWebSocketPreDispatchError = class extends Error {
|
|
21
|
+
constructor(cause) {
|
|
22
|
+
super("OpenAI Responses WebSocket failed before request dispatch", { cause });
|
|
23
|
+
this.name = "OpenAIResponsesWebSocketPreDispatchError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var OpenAIResponsesWebSocketPostDispatchError = class extends Error {
|
|
27
|
+
constructor(cause) {
|
|
28
|
+
super("OpenAI Responses WebSocket failed after request dispatch; outcome is unknown", { cause });
|
|
29
|
+
this.code = PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE;
|
|
30
|
+
this.name = "OpenAIResponsesWebSocketPostDispatchError";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var OpenAIResponsesWebSocketServerError = class extends Error {
|
|
34
|
+
constructor(code, status, param, message, cause) {
|
|
35
|
+
super(message, { cause });
|
|
36
|
+
this.code = code;
|
|
37
|
+
this.status = status;
|
|
38
|
+
this.param = param;
|
|
39
|
+
this.name = "OpenAIResponsesWebSocketServerError";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var OpenAIResponsesWebSocketSafeRetryError = class extends OpenAIResponsesWebSocketServerError {};
|
|
43
|
+
function readWebSocketServerError(value) {
|
|
44
|
+
if (!isRecord(value) || value.type !== "error") return;
|
|
45
|
+
const details = isRecord(value.error) ? value.error : value;
|
|
46
|
+
if (typeof details.code !== "string" || typeof details.message !== "string") return;
|
|
47
|
+
const rawStatus = value.status ?? value.status_code;
|
|
48
|
+
return {
|
|
49
|
+
code: details.code,
|
|
50
|
+
message: details.message,
|
|
51
|
+
param: typeof details.param === "string" ? details.param : null,
|
|
52
|
+
status: typeof rawStatus === "number" ? rawStatus : void 0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function isPreviousResponseRejection(error) {
|
|
56
|
+
return error.code === "previous_response_not_found" || error.code === "unsupported_parameter" && error.param === "previous_response_id";
|
|
57
|
+
}
|
|
58
|
+
function parseOpenAIResponsesWebSocketServerError(cause) {
|
|
59
|
+
if (!isRecord(cause)) return;
|
|
60
|
+
let details = readWebSocketServerError(cause.error) ?? readWebSocketServerError(cause);
|
|
61
|
+
if (!details && typeof cause.message === "string") try {
|
|
62
|
+
details = readWebSocketServerError(JSON.parse(cause.message));
|
|
63
|
+
} catch {}
|
|
64
|
+
if (!details) return;
|
|
65
|
+
return new (isPreviousResponseRejection(details) || details.code === "websocket_connection_limit_reached" || details.code === "invalid_encrypted_content" || details.code === "thinking_signature_invalid" ? OpenAIResponsesWebSocketSafeRetryError : OpenAIResponsesWebSocketServerError)(details.code, details.status, details.param, details.message, cause);
|
|
66
|
+
}
|
|
67
|
+
const PROMPT_OBSERVER = Symbol("openaiResponsesPromptObserver");
|
|
68
|
+
const responsesPromptObserver = {
|
|
69
|
+
set(options, observer) {
|
|
70
|
+
Reflect.set(options, PROMPT_OBSERVER, observer);
|
|
71
|
+
},
|
|
72
|
+
get(options) {
|
|
73
|
+
return Reflect.get(options, PROMPT_OBSERVER);
|
|
74
|
+
},
|
|
75
|
+
copy(source, target) {
|
|
76
|
+
const observer = source && responsesPromptObserver.get(source);
|
|
77
|
+
if (observer) responsesPromptObserver.set(target, observer);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE as a, OPENAI_RESPONSES_RETAINED_COMPACTION_REPLAY_TYPE as c, OpenAIResponsesWebSocketSafeRetryError as d, RESPONSE_FAILED_NO_DETAILS_MESSAGE as f, responsesPromptObserver as h, OPENAI_RESPONSES_APIS as i, OpenAIResponsesWebSocketPostDispatchError as l, parseOpenAIResponsesWebSocketServerError as m, DEFAULT_AZURE_OPENAI_API_VERSION as n, OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY as o, isPreviousResponseRejection as p, OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS as r, OPENAI_RESPONSES_REASONING_REPLAY_META_KEY as s, AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS as t, OpenAIResponsesWebSocketPreDispatchError as u };
|
package/dist/{openai-responses-contracts-B55afwRo.d.mts → openai-responses-contracts-Dflvrfa8.d.mts}
RENAMED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import {
|
|
3
|
-
import { a as BaseOpenAIStreamOptions,
|
|
4
|
-
import
|
|
1
|
+
import "./index-DaF2QbwS.mjs";
|
|
2
|
+
import { O as Model, j as ModelThinkingLevel, n as Api } from "./types-4_uVs5WH.mjs";
|
|
3
|
+
import { a as BaseOpenAIStreamOptions, f as OpenAIReasoningEffort } from "./provider-options-DprLsWh9.mjs";
|
|
4
|
+
import "./types-DkJfb4W3.mjs";
|
|
5
|
+
import { ResponseCompactionItem, ResponseCreateParamsStreaming, ResponseInputItem } from "openai/resources/responses/responses.js";
|
|
6
|
+
//#region packages/ai/src/providers/openai-request-reasoning.d.ts
|
|
7
|
+
type OpenAIRequestReasoningEffort = ModelThinkingLevel | "none";
|
|
8
|
+
//#endregion
|
|
5
9
|
//#region packages/ai/src/transports/openai-responses-compaction-window.d.ts
|
|
6
10
|
type OpenAIResponsesCompactionOutput = Array<ResponseInputItem.Message | ReplayableResponseCompactionItem>;
|
|
7
11
|
/** Read the saved canonical window only when it still matches its opaque checkpoint. */
|
|
@@ -27,7 +31,7 @@ type OpenAIResponsesReasoningReplayMetadata = {
|
|
|
27
31
|
authProfileHash?: string;
|
|
28
32
|
};
|
|
29
33
|
type OpenAIResponsesOptions = BaseOpenAIStreamOptions & {
|
|
30
|
-
reasoning?:
|
|
34
|
+
reasoning?: OpenAIRequestReasoningEffort;
|
|
31
35
|
reasoningEffort?: OpenAIReasoningEffort;
|
|
32
36
|
reasoningSummary?: "auto" | "detailed" | "concise" | null;
|
|
33
37
|
replayResponsesItemIds?: boolean;
|
|
@@ -48,38 +52,5 @@ declare const responsesPromptObserver: {
|
|
|
48
52
|
get(options: object): ResponsesPromptObserver | undefined;
|
|
49
53
|
copy(source: object | undefined, target: object): void;
|
|
50
54
|
};
|
|
51
|
-
type OpenAIResponsesRequestParams = {
|
|
52
|
-
model: string;
|
|
53
|
-
input: ResponseInput;
|
|
54
|
-
stream: true;
|
|
55
|
-
instructions?: string;
|
|
56
|
-
prompt_cache_key?: string;
|
|
57
|
-
prompt_cache_retention?: "24h";
|
|
58
|
-
prompt_cache_options?: {
|
|
59
|
-
ttl: "30m";
|
|
60
|
-
};
|
|
61
|
-
metadata?: Record<string, string>;
|
|
62
|
-
previous_response_id?: string;
|
|
63
|
-
store?: boolean;
|
|
64
|
-
max_output_tokens?: number;
|
|
65
|
-
temperature?: number;
|
|
66
|
-
top_p?: number;
|
|
67
|
-
text?: ResponseCreateParamsStreaming["text"];
|
|
68
|
-
service_tier?: ResponseCreateParamsStreaming["service_tier"];
|
|
69
|
-
tools?: Array<FunctionTool & {
|
|
70
|
-
async?: boolean;
|
|
71
|
-
}>;
|
|
72
|
-
multi_agent?: {
|
|
73
|
-
enabled?: boolean;
|
|
74
|
-
};
|
|
75
|
-
tool_choice?: ResponseCreateParamsStreaming["tool_choice"];
|
|
76
|
-
reasoning?: {
|
|
77
|
-
effort: OpenAIApiReasoningEffort;
|
|
78
|
-
} | {
|
|
79
|
-
effort: OpenAIApiReasoningEffort;
|
|
80
|
-
summary: NonNullable<OpenAIResponsesOptions["reasoningSummary"]>;
|
|
81
|
-
};
|
|
82
|
-
include?: string[];
|
|
83
|
-
};
|
|
84
55
|
//#endregion
|
|
85
|
-
export {
|
|
56
|
+
export { ResponsesPromptObservation as a, readOpenAIResponsesCompactionWindow as c, ReplayableResponseCompactionItem as i, OpenAIRequestReasoningEffort as l, OpenAIResponsesOptions as n, responsesPromptObserver as o, OpenAIResponsesReasoningReplayMetadata as r, OpenAIResponsesCompactionOutput as s, OPENAI_RESPONSES_APIS as t };
|
|
@@ -10,13 +10,15 @@ type OpenAIResponsesPayloadModel = {
|
|
|
10
10
|
};
|
|
11
11
|
type OpenAIResponsesPayloadPolicyOptions = {
|
|
12
12
|
extraParams?: Record<string, unknown>;
|
|
13
|
-
storeMode?: "provider-policy" | "disable" | "preserve";
|
|
13
|
+
storeMode?: "provider-policy" | "transport-default" | "disable" | "preserve";
|
|
14
14
|
enablePromptCacheStripping?: boolean;
|
|
15
15
|
enableServerCompaction?: boolean;
|
|
16
16
|
};
|
|
17
17
|
type OpenAIResponsesPayloadPolicy = {
|
|
18
18
|
allowsServiceTier: boolean;
|
|
19
19
|
compactThreshold: number | undefined;
|
|
20
|
+
defaultManagedReasoningEffort: "none" | undefined;
|
|
21
|
+
explicitContinuationOptIn: boolean;
|
|
20
22
|
explicitStore: boolean | undefined;
|
|
21
23
|
shouldStripDisabledReasoningPayload: boolean;
|
|
22
24
|
shouldStripInputStatus: boolean;
|
|
@@ -30,8 +32,8 @@ declare function resolveOpenAIResponsesServerCompactionPlan(model: OpenAIRespons
|
|
|
30
32
|
enabled: boolean;
|
|
31
33
|
threshold: number | undefined;
|
|
32
34
|
};
|
|
33
|
-
/** Resolve the
|
|
34
|
-
declare function resolveOpenAIResponsesCompactEndpointPlan(model: OpenAIResponsesPayloadModel, extraParams?: Record<string, unknown
|
|
35
|
+
/** Resolve the Responses compact-endpoint gate for one route and compaction purpose. */
|
|
36
|
+
declare function resolveOpenAIResponsesCompactEndpointPlan(model: OpenAIResponsesPayloadModel, extraParams?: Record<string, unknown>, purpose?: "manual" | "budget"): {
|
|
35
37
|
enabled: boolean;
|
|
36
38
|
};
|
|
37
39
|
/** Resolve payload mutation policy for one OpenAI Responses-style model endpoint. */
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
2
|
+
import { u as supportsOpenAITemperature } from "./openai-reasoning-effort-NlFZmfEu.mjs";
|
|
3
|
+
import { r as resolveOpenAIPromptCacheParams } from "./openai-prompt-cache-1wfaIszn.mjs";
|
|
4
|
+
import { o as usesNativeOpenAICodexResponsesBackend } from "./openai-completions-compat-CkwdxTZx.mjs";
|
|
5
|
+
import { r as resolveOpenAIStrictToolSetting } from "./host-policy-DUnXSx0I.mjs";
|
|
6
|
+
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
7
|
+
import { m as stripSystemPromptCacheBoundary } from "./simple-options-C6cFWj_f.mjs";
|
|
8
|
+
import { A as resolvePromptCacheKey, g as resolveOpenAISimpleReasoningEffort, h as resolveOpenAIRequestReasoning, m as reconcileOpenAIResponsesToolChoice, s as getCompat } from "./openai-transport-params-DQeuAvBl.mjs";
|
|
9
|
+
import { _ as sanitizeTransportPayloadText } from "./transport-stream-shared-D-6FQSHm.mjs";
|
|
10
|
+
import { h as responsesPromptObserver, r as OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS } from "./openai-responses-contracts-DWrfMODE.mjs";
|
|
11
|
+
import { a as applyOpenAIResponsesPayloadPolicy, s as resolveOpenAIResponsesPayloadPolicy } from "./openai-responses-compaction-window-D6P5oZP5.mjs";
|
|
12
|
+
import { N as buildResponsesInputMessage, P as convertResponsesMessages, s as prepareResponsesTools } from "./openai-responses-shared-CwsziD_m.mjs";
|
|
13
|
+
//#region packages/ai/src/transports/openai-responses-params-internal.ts
|
|
14
|
+
const OPENAI_RESPONSES_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set([
|
|
15
|
+
"openai",
|
|
16
|
+
"opencode",
|
|
17
|
+
"azure-openai-responses",
|
|
18
|
+
"github-copilot"
|
|
19
|
+
]);
|
|
20
|
+
function hasResponsesWebSearchTool(tools) {
|
|
21
|
+
if (!Array.isArray(tools)) return false;
|
|
22
|
+
return tools.some((tool) => {
|
|
23
|
+
if (!isRecord(tool)) return false;
|
|
24
|
+
if (tool.type === "web_search") return true;
|
|
25
|
+
if (tool.type === "function" && tool.name === "web_search") return true;
|
|
26
|
+
const fn = tool.function;
|
|
27
|
+
return isRecord(fn) && fn.name === "web_search";
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function raiseMinimalReasoningForResponsesWebSearch(params) {
|
|
31
|
+
if (params.effort !== "minimal" || !hasResponsesWebSearchTool(params.tools)) return params.effort;
|
|
32
|
+
for (const effort of [
|
|
33
|
+
"low",
|
|
34
|
+
"medium",
|
|
35
|
+
"high"
|
|
36
|
+
]) {
|
|
37
|
+
const resolved = resolveOpenAIRequestReasoning(params.model, effort).effort;
|
|
38
|
+
if (resolved && resolved !== "none" && resolved !== "minimal") return resolved;
|
|
39
|
+
}
|
|
40
|
+
return params.effort;
|
|
41
|
+
}
|
|
42
|
+
const OPENAI_CODEX_RESPONSES_UNSUPPORTED_PARAMS = [
|
|
43
|
+
"max_output_tokens",
|
|
44
|
+
"metadata",
|
|
45
|
+
"prompt_cache_retention",
|
|
46
|
+
"prompt_cache_options",
|
|
47
|
+
"service_tier",
|
|
48
|
+
"temperature",
|
|
49
|
+
"top_p"
|
|
50
|
+
];
|
|
51
|
+
function stripOpenAICodexResponsesUnsupportedTextFields(params) {
|
|
52
|
+
const text = params.text;
|
|
53
|
+
if (!text || typeof text !== "object" || Array.isArray(text)) return;
|
|
54
|
+
const sanitizedText = { ...text };
|
|
55
|
+
delete sanitizedText.format;
|
|
56
|
+
if (Object.keys(sanitizedText).length > 0) params.text = sanitizedText;
|
|
57
|
+
else delete params.text;
|
|
58
|
+
}
|
|
59
|
+
function sanitizeOpenAICodexResponsesParams(model, params) {
|
|
60
|
+
if (!usesNativeOpenAICodexResponsesBackend(model)) return params;
|
|
61
|
+
for (const key of OPENAI_CODEX_RESPONSES_UNSUPPORTED_PARAMS) delete params[key];
|
|
62
|
+
Object.assign(params, { store: false });
|
|
63
|
+
stripOpenAICodexResponsesUnsupportedTextFields(params);
|
|
64
|
+
return params;
|
|
65
|
+
}
|
|
66
|
+
function buildOpenAIResponsesInstructionsText(context) {
|
|
67
|
+
if (!context.systemPrompt) return;
|
|
68
|
+
return sanitizeTransportPayloadText(stripSystemPromptCacheBoundary(context.systemPrompt));
|
|
69
|
+
}
|
|
70
|
+
function resolveOpenAIResponsesInstructions(model, context, usesInstructionsField) {
|
|
71
|
+
if (!usesInstructionsField) return;
|
|
72
|
+
const instructions = buildOpenAIResponsesInstructionsText(context);
|
|
73
|
+
if (instructions && instructions.trim().length > 0) return instructions;
|
|
74
|
+
return usesNativeOpenAICodexResponsesBackend(model) ? OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS : void 0;
|
|
75
|
+
}
|
|
76
|
+
function buildOpenAIResponsesCompactSystemMessage(model, instructions) {
|
|
77
|
+
const compat = getCompat(model);
|
|
78
|
+
const supportsDeveloperRole = typeof compat.supportsDeveloperRole === "boolean" ? compat.supportsDeveloperRole : void 0;
|
|
79
|
+
const role = model.reasoning && supportsDeveloperRole !== false ? "developer" : "system";
|
|
80
|
+
return buildResponsesInputMessage(role, [{
|
|
81
|
+
type: "input_text",
|
|
82
|
+
text: instructions
|
|
83
|
+
}]);
|
|
84
|
+
}
|
|
85
|
+
function ensureOpenAIResponsesNonEmptyInput(messages, context) {
|
|
86
|
+
if (messages.length > 0 || !context.systemPrompt) return;
|
|
87
|
+
if (!buildOpenAIResponsesInstructionsText(context)) throw new Error("OpenAI Responses requires non-empty input when only systemPrompt is provided.");
|
|
88
|
+
messages.push(buildResponsesInputMessage("user", [{
|
|
89
|
+
type: "input_text",
|
|
90
|
+
text: " "
|
|
91
|
+
}]));
|
|
92
|
+
}
|
|
93
|
+
function resolveOpenAIResponsesTextFormat(responseFormat) {
|
|
94
|
+
if (responseFormat.type === "json_schema" && responseFormat.json_schema && typeof responseFormat.json_schema === "object" && !Array.isArray(responseFormat.json_schema)) return {
|
|
95
|
+
...responseFormat.json_schema,
|
|
96
|
+
type: "json_schema"
|
|
97
|
+
};
|
|
98
|
+
return responseFormat;
|
|
99
|
+
}
|
|
100
|
+
function buildOpenAIResponsesParams(model, context, options, metadata, replayMode = "checkpoint") {
|
|
101
|
+
const payloadPolicy = resolveOpenAIResponsesPayloadPolicy(model, { storeMode: "transport-default" });
|
|
102
|
+
const policyAllowsReplayIds = payloadPolicy.explicitStore !== false && !payloadPolicy.shouldStripStore;
|
|
103
|
+
const replayResponsesItemIds = !usesNativeOpenAICodexResponsesBackend(model) && (options?.replayResponsesItemIds ?? policyAllowsReplayIds);
|
|
104
|
+
const messages = convertResponsesMessages(model, context, OPENAI_RESPONSES_TOOL_CALL_PROVIDERS, {
|
|
105
|
+
includeSystemPrompt: !payloadPolicy.usesInstructionsField,
|
|
106
|
+
replayReasoningItems: true,
|
|
107
|
+
replayResponsesItemIds,
|
|
108
|
+
authProfileId: options?.authProfileId,
|
|
109
|
+
sessionId: options?.sessionId,
|
|
110
|
+
replayMode
|
|
111
|
+
});
|
|
112
|
+
ensureOpenAIResponsesNonEmptyInput(messages, context);
|
|
113
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
114
|
+
const compat = getCompat(model);
|
|
115
|
+
const promptCacheKey = compat.supportsPromptCacheKey ? resolvePromptCacheKey(options, cacheRetention) : void 0;
|
|
116
|
+
const instructions = resolveOpenAIResponsesInstructions(model, context, payloadPolicy.usesInstructionsField);
|
|
117
|
+
const params = {
|
|
118
|
+
model: model.id,
|
|
119
|
+
input: messages,
|
|
120
|
+
stream: true,
|
|
121
|
+
prompt_cache_key: promptCacheKey,
|
|
122
|
+
...resolveOpenAIPromptCacheParams(model, cacheRetention, compat),
|
|
123
|
+
...instructions ? { instructions } : {},
|
|
124
|
+
...metadata ? { metadata } : {}
|
|
125
|
+
};
|
|
126
|
+
const effectiveMaxTokens = options?.maxTokens || model.maxTokens;
|
|
127
|
+
if (effectiveMaxTokens) params.max_output_tokens = Math.max(effectiveMaxTokens, 16);
|
|
128
|
+
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) params.temperature = options.temperature;
|
|
129
|
+
if (options?.topP !== void 0 && model.id !== "gpt-6-astra") params.top_p = options.topP;
|
|
130
|
+
if (options?.responseFormat !== void 0) params.text = {
|
|
131
|
+
...params.text,
|
|
132
|
+
format: resolveOpenAIResponsesTextFormat(options.responseFormat)
|
|
133
|
+
};
|
|
134
|
+
if (options?.serviceTier !== void 0 && payloadPolicy.allowsServiceTier) params.service_tier = options.serviceTier;
|
|
135
|
+
if (context.tools) {
|
|
136
|
+
const tools = context.tools;
|
|
137
|
+
const strict = resolveOpenAIStrictToolSetting(model, { transport: "stream" });
|
|
138
|
+
const { projection, tools: converted } = prepareResponsesTools(tools, strict, model);
|
|
139
|
+
if (converted.length > 0 || projection.inputToolCount === 0 && projection.diagnostics.length === 0) params.tools = converted;
|
|
140
|
+
if (options?.toolChoice) {
|
|
141
|
+
const toolChoice = reconcileOpenAIResponsesToolChoice(options.toolChoice, projection);
|
|
142
|
+
if (toolChoice !== void 0) params.tool_choice = toolChoice;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (model.reasoning) {
|
|
146
|
+
const reasoning = options?.reasoning;
|
|
147
|
+
const requestedEffort = options?.reasoningEffort ?? (reasoning === "none" ? "none" : resolveOpenAISimpleReasoningEffort(model, reasoning)) ?? (options?.reasoningSummary ? "high" : payloadPolicy.defaultManagedReasoningEffort);
|
|
148
|
+
const resolvedEffort = requestedEffort === void 0 ? void 0 : resolveOpenAIRequestReasoning(model, requestedEffort).effort;
|
|
149
|
+
if (resolvedEffort !== void 0) {
|
|
150
|
+
const effort = raiseMinimalReasoningForResponsesWebSearch({
|
|
151
|
+
model,
|
|
152
|
+
effort: resolvedEffort,
|
|
153
|
+
tools: params.tools
|
|
154
|
+
});
|
|
155
|
+
const summary = effort !== "none" && (options?.reasoningEffort || options?.reasoning || options?.reasoningSummary) ? options.reasoningSummary || "auto" : void 0;
|
|
156
|
+
params.reasoning = {
|
|
157
|
+
effort,
|
|
158
|
+
...summary ? { summary } : {}
|
|
159
|
+
};
|
|
160
|
+
if (summary) params.include = ["reasoning.encrypted_content"];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
applyOpenAIResponsesPayloadPolicy(params, payloadPolicy);
|
|
164
|
+
return sanitizeOpenAICodexResponsesParams(model, params);
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region packages/ai/src/transports/openai-responses-prompt-observer-internal.ts
|
|
168
|
+
function readFinalResponsesPrompt(request) {
|
|
169
|
+
if (typeof request.instructions === "string") return ["instructions", request.instructions];
|
|
170
|
+
const message = (Array.isArray(request.input) ? request.input : []).find((item) => {
|
|
171
|
+
const role = item.role;
|
|
172
|
+
return role === "developer" || role === "system";
|
|
173
|
+
});
|
|
174
|
+
if (!message) return ["missing", ""];
|
|
175
|
+
const content = message.content;
|
|
176
|
+
const observedPrompt = typeof content === "string" ? content : Array.isArray(content) ? content.flatMap((part) => part.type === "input_text" ? [part.text] : []).join("") : "";
|
|
177
|
+
return [message.role === "developer" ? "input.developer" : "input.system", observedPrompt];
|
|
178
|
+
}
|
|
179
|
+
function createResponsesPromptEgressObserver(options, assembledPrompt) {
|
|
180
|
+
const observer = options ? responsesPromptObserver.get(options) : void 0;
|
|
181
|
+
if (!observer) return;
|
|
182
|
+
const expectedPrompt = sanitizeTransportPayloadText(stripSystemPromptCacheBoundary(assembledPrompt ?? ""));
|
|
183
|
+
return (request, metadata) => {
|
|
184
|
+
const [promptSource, observedPrompt] = readFinalResponsesPrompt(request);
|
|
185
|
+
observer({
|
|
186
|
+
...metadata,
|
|
187
|
+
promptSource,
|
|
188
|
+
expectedChars: expectedPrompt.length,
|
|
189
|
+
observedChars: observedPrompt.length,
|
|
190
|
+
matchesAssembledPrompt: promptSource !== "missing" && observedPrompt === expectedPrompt
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { sanitizeOpenAICodexResponsesParams as a, resolveOpenAIResponsesTextFormat as i, buildOpenAIResponsesCompactSystemMessage as n, buildOpenAIResponsesParams as r, createResponsesPromptEgressObserver as t };
|