@openclaw/ai 2026.7.2-beta.7 → 2026.8.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-CH4UUnZr.mjs → anthropic-B6dLpq5L.mjs} +55 -203
- package/dist/{src-QkygScBs.mjs → anthropic-JsNA5KCu.mjs} +0 -1
- package/dist/anthropic-compaction-replay-8lJNKXOE.mjs +840 -0
- package/dist/anthropic-payload-policy-CiEuQS72.d.mts +49 -0
- package/dist/{api-registry-DlMgPR39.d.mts → api-registry-k3zTz0cV.d.mts} +1 -1
- package/dist/{azure-openai-responses-CImcwB83.mjs → azure-openai-responses-mxIOtUnn.mjs} +23 -29
- package/dist/diagnostics.d.mts +24 -1
- package/dist/diagnostics.mjs +2 -1
- package/dist/{event-stream-YjaPW20U.d.mts → event-stream-BP6AWT8j.d.mts} +4 -1
- package/dist/{event-stream-D8n2uFee.mjs → event-stream-uSMZJ3FA.mjs} +26 -5
- package/dist/event-stream.d.mts +1 -1
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-CtSg0iTS.mjs → google-C7h2QzDX.mjs} +5 -5
- package/dist/{google-shared-DNBz5rcD.mjs → google-shared-B0Qr9OR7.mjs} +146 -89
- package/dist/google-thinking-level-C-V3tecN.mjs +9 -0
- package/dist/{google-vertex-31f1uS9L.mjs → google-vertex-Bhc3TjDl.mjs} +11 -7
- package/dist/{llm-request-activity-BjtkplhG.mjs → headers-DdOQtGuU.mjs} +9 -1
- package/dist/host-DTqNc7ad.mjs +466 -0
- package/dist/{host-B9GUmcra.d.mts → host-vWgMMhiJ.d.mts} +9 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +7 -5
- package/dist/internal/anthropic.d.mts +29 -5
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -0
- package/dist/internal/openai-responses-payload-policy.mjs +3 -0
- package/dist/internal/openai.d.mts +6 -6
- package/dist/internal/openai.mjs +8 -7
- package/dist/internal/runtime.d.mts +17 -5
- package/dist/internal/runtime.mjs +85 -73
- package/dist/internal/shared.d.mts +1 -6
- package/dist/internal/shared.mjs +3 -5
- package/dist/{json-parse-BvXNt1-7.mjs → json-parse-CDnesDM_.mjs} +4 -6
- package/dist/{mistral-CWmpvWYh.mjs → mistral-CEWoQI_g.mjs} +45 -48
- package/dist/number-coercion-H9qHik3g.mjs +71 -0
- package/dist/openai-chatgpt-jwt-KWcgd0d_.mjs +19 -0
- package/dist/{openai-chatgpt-responses-B84Ibtrd.mjs → openai-chatgpt-responses-CrPmqERt.mjs} +284 -240
- package/dist/{openai-completions-DsOxhOD1.mjs → openai-completions-BPnt4Sml.mjs} +65 -99
- package/dist/{openai-completions-compat-DBWjXoMZ.d.mts → openai-completions-compat-Dt3dcawL.d.mts} +2 -2
- package/dist/{openai-responses-BT7A3sLu.mjs → openai-responses-DhIKtOup.mjs} +18 -41
- package/dist/openai-responses-contracts-CyfIkQi5.mjs +253 -0
- package/dist/openai-responses-contracts-XpZJxrRG.d.mts +68 -0
- package/dist/openai-responses-payload-policy-BDxV-W0c.mjs +206 -0
- package/dist/openai-responses-payload-policy-BSs371VM.d.mts +40 -0
- package/dist/openai-responses-prompt-observer-internal-DgNTYnRY.mjs +46 -0
- package/dist/{openai-responses-stream-internal-Cw5txaGW.mjs → openai-responses-shared-DXIt3iY5.mjs} +1406 -940
- package/dist/{openai-reasoning-compat-YgeLncHw.mjs → openai-stop-reason-BkFkqqK0.mjs} +204 -37
- package/dist/openai-tool-projection-CY04OcvQ.mjs +338 -0
- package/dist/provider-error-BUwEnjXq.mjs +429 -0
- package/dist/provider-error-CzNw4BWX.d.mts +12 -0
- package/dist/{provider-options-D8bB3z9b.d.mts → provider-options-B96RdNpH.d.mts} +9 -3
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +155 -0
- package/dist/provider-types.d.mts +31 -0
- package/dist/provider-types.mjs +8 -0
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +17 -19
- package/dist/{reasoning-tag-text-partitioner-CGDyLWUR.mjs → reasoning-tag-text-partitioner-rnPwX2pg.mjs} +14 -8
- package/dist/record-coerce-DdXsgUd_.mjs +23 -0
- package/dist/sanitize-unicode-BYqrYtC_.mjs +90 -0
- package/dist/session-resources-CkR4WWy1.mjs +21 -0
- package/dist/simple-options-D58D5Kvw.mjs +117 -0
- package/dist/src-D2H6yKkH.mjs +2 -0
- package/dist/{stream-first-event-timeout-BBys9hSb.mjs → stream-first-event-timeout-MK28puvq.mjs} +2 -2
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → tool-schema-json-projection-q5d7QX5c.mjs} +32 -7
- package/dist/transport-utils-DJqkxbhC.mjs +138 -0
- package/dist/transports.d.mts +166 -241
- package/dist/transports.mjs +1979 -1825
- package/dist/types-BDdaOVi2.mjs +6 -0
- package/dist/{types-bzp5k29J.d.mts → types-BHNrPS1l.d.mts} +23 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.mjs +6 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-DAa_yFOM.mjs → validation-B61OhAio.mjs} +6 -6
- package/dist/{validation-B-j7cOYp.d.mts → validation-DT9SrFn3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +15 -1
- package/dist/anthropic-usage-DWU-x8MI.mjs +0 -459
- package/dist/error-coercion-DgxlWC0n.mjs +0 -15
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/host-Dog2WQiR.mjs +0 -369
- package/dist/number-coercion-DvG7SNMg.mjs +0 -129
- package/dist/openai-chatgpt-jwt-DhAAzLkj.mjs +0 -39
- package/dist/openai-responses-shared-pXl6Wd8S.mjs +0 -392
- package/dist/openai-tool-projection-OhX64DoP.mjs +0 -215
- package/dist/provider-error-CAEvRjry.mjs +0 -47
- package/dist/sanitize-unicode-DT5o51ur.mjs +0 -26
- package/dist/simple-options-9lhRrN73.mjs +0 -50
- package/dist/tool-result-text-CTpIRbYd.mjs +0 -225
- package/dist/transform-messages-C8mBqZxF.mjs +0 -2
- package/dist/transport-stream-shared-D81p90xq.mjs +0 -297
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { n as Api } from "./types-BHNrPS1l.mjs";
|
|
2
|
+
import { f as OpenAIApiReasoningEffort, i as BaseOpenAIStreamOptions, p as OpenAIReasoningEffort } from "./provider-options-B96RdNpH.mjs";
|
|
3
|
+
import { FunctionTool, ResponseCompactionItem, ResponseCreateParamsStreaming, ResponseInput } from "openai/resources/responses/responses.js";
|
|
4
|
+
|
|
5
|
+
//#region packages/ai/src/transports/openai-responses-contracts.d.ts
|
|
6
|
+
declare const OPENAI_RESPONSES_APIS: ReadonlySet<Api>;
|
|
7
|
+
type ReplayableResponseCompactionItem = Omit<ResponseCompactionItem, "id"> & {
|
|
8
|
+
id?: string;
|
|
9
|
+
};
|
|
10
|
+
type OpenAIResponsesReasoningReplayMetadata = {
|
|
11
|
+
v: 1;
|
|
12
|
+
source: "openai-responses";
|
|
13
|
+
provider: string;
|
|
14
|
+
api: Api;
|
|
15
|
+
model: string;
|
|
16
|
+
baseUrlHash?: string;
|
|
17
|
+
sessionHash?: string;
|
|
18
|
+
authProfileHash?: string;
|
|
19
|
+
};
|
|
20
|
+
type OpenAIResponsesOptions = BaseOpenAIStreamOptions & {
|
|
21
|
+
reasoning?: OpenAIReasoningEffort;
|
|
22
|
+
reasoningEffort?: OpenAIReasoningEffort;
|
|
23
|
+
reasoningSummary?: "auto" | "detailed" | "concise" | null;
|
|
24
|
+
replayResponsesItemIds?: boolean;
|
|
25
|
+
serviceTier?: ResponseCreateParamsStreaming["service_tier"];
|
|
26
|
+
toolChoice?: ResponseCreateParamsStreaming["tool_choice"];
|
|
27
|
+
};
|
|
28
|
+
type ResponsesPromptObservation = {
|
|
29
|
+
egress: "responses-sdk" | "responses-websocket" | "native-codex-websocket" | "native-codex-sse";
|
|
30
|
+
payloadVariant: "initial" | "reasoning-stripped" | "compaction-stripped" | "continuation-rejected";
|
|
31
|
+
promptSource: "instructions" | "input.developer" | "input.system" | "missing";
|
|
32
|
+
expectedChars: number;
|
|
33
|
+
observedChars: number;
|
|
34
|
+
matchesAssembledPrompt: boolean;
|
|
35
|
+
};
|
|
36
|
+
type ResponsesPromptObserver = (observation: ResponsesPromptObservation) => void;
|
|
37
|
+
declare const responsesPromptObserver: {
|
|
38
|
+
set(options: object, observer: ResponsesPromptObserver): void;
|
|
39
|
+
get(options: object): ResponsesPromptObserver | undefined;
|
|
40
|
+
copy(source: object | undefined, target: object): void;
|
|
41
|
+
};
|
|
42
|
+
type OpenAIResponsesRequestParams = {
|
|
43
|
+
model: string;
|
|
44
|
+
input: ResponseInput;
|
|
45
|
+
stream: true;
|
|
46
|
+
instructions?: string;
|
|
47
|
+
prompt_cache_key?: string;
|
|
48
|
+
prompt_cache_retention?: "24h";
|
|
49
|
+
metadata?: Record<string, string>;
|
|
50
|
+
previous_response_id?: string;
|
|
51
|
+
store?: boolean;
|
|
52
|
+
max_output_tokens?: number;
|
|
53
|
+
temperature?: number;
|
|
54
|
+
top_p?: number;
|
|
55
|
+
text?: ResponseCreateParamsStreaming["text"];
|
|
56
|
+
service_tier?: ResponseCreateParamsStreaming["service_tier"];
|
|
57
|
+
tools?: FunctionTool[];
|
|
58
|
+
tool_choice?: ResponseCreateParamsStreaming["tool_choice"];
|
|
59
|
+
reasoning?: {
|
|
60
|
+
effort: OpenAIApiReasoningEffort;
|
|
61
|
+
} | {
|
|
62
|
+
effort: OpenAIApiReasoningEffort;
|
|
63
|
+
summary: NonNullable<OpenAIResponsesOptions["reasoningSummary"]>;
|
|
64
|
+
};
|
|
65
|
+
include?: string[];
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { ReplayableResponseCompactionItem as a, OpenAIResponsesRequestParams as i, OpenAIResponsesOptions as n, ResponsesPromptObservation as o, OpenAIResponsesReasoningReplayMetadata as r, responsesPromptObserver as s, OPENAI_RESPONSES_APIS as t };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { i as normalizeOptionalLowercaseString, n as normalizeLowercaseStringOrEmpty, s as readStringValue } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
+
import { s as parseStrictPositiveInteger } from "./number-coercion-H9qHik3g.mjs";
|
|
3
|
+
import { i as OPENAI_RESPONSES_APIS, x as supportsOpenAIReasoningEffort } from "./openai-responses-contracts-CyfIkQi5.mjs";
|
|
4
|
+
//#region packages/model-catalog-core/src/provider-id.ts
|
|
5
|
+
function normalizeProviderId(provider) {
|
|
6
|
+
return normalizeLowercaseStringOrEmpty(provider);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region packages/ai/src/transports/openai-responses-payload-policy.ts
|
|
10
|
+
/**
|
|
11
|
+
* OpenAI Responses payload policy.
|
|
12
|
+
* Classifies endpoint capabilities and applies store, prompt-cache,
|
|
13
|
+
* server-compaction, service-tier, and reasoning payload rules.
|
|
14
|
+
*/
|
|
15
|
+
const OPENAI_RESPONSES_PROVIDERS = /* @__PURE__ */ new Set([
|
|
16
|
+
"openai",
|
|
17
|
+
"azure-openai",
|
|
18
|
+
"azure-openai-responses"
|
|
19
|
+
]);
|
|
20
|
+
const LOCAL_ENDPOINT_HOSTS = /* @__PURE__ */ new Set([
|
|
21
|
+
"localhost",
|
|
22
|
+
"127.0.0.1",
|
|
23
|
+
"::1",
|
|
24
|
+
"[::1]"
|
|
25
|
+
]);
|
|
26
|
+
const MODELSTUDIO_NATIVE_BASE_URLS = /* @__PURE__ */ new Set([
|
|
27
|
+
"https://coding-intl.dashscope.aliyuncs.com/v1",
|
|
28
|
+
"https://coding.dashscope.aliyuncs.com/v1",
|
|
29
|
+
"https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
30
|
+
"https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
|
|
31
|
+
]);
|
|
32
|
+
const MOONSHOT_NATIVE_BASE_URLS = /* @__PURE__ */ new Set(["https://api.moonshot.ai/v1", "https://api.moonshot.cn/v1"]);
|
|
33
|
+
function normalizeComparableBaseUrl(value) {
|
|
34
|
+
const trimmed = readStringValue(value)?.trim();
|
|
35
|
+
if (!trimmed) return;
|
|
36
|
+
const parsedValue = /^[a-z0-9.[\]-]+(?::\d+)?(?:[/?#].*)?$/i.test(trimmed) ? `https://${trimmed}` : trimmed;
|
|
37
|
+
try {
|
|
38
|
+
const url = new URL(parsedValue);
|
|
39
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
40
|
+
url.hash = "";
|
|
41
|
+
url.search = "";
|
|
42
|
+
return url.toString().replace(/\/+$/, "").toLowerCase();
|
|
43
|
+
} catch {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function resolveUrlHostname(value) {
|
|
48
|
+
const trimmed = readStringValue(value)?.trim();
|
|
49
|
+
if (!trimmed) return;
|
|
50
|
+
try {
|
|
51
|
+
return new URL(trimmed).hostname.toLowerCase();
|
|
52
|
+
} catch {
|
|
53
|
+
try {
|
|
54
|
+
return new URL(`https://${trimmed}`).hostname.toLowerCase();
|
|
55
|
+
} catch {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function hostMatchesSuffix(host, suffix) {
|
|
61
|
+
return suffix.startsWith(".") || suffix.startsWith("-") ? host.endsWith(suffix) : host === suffix || host.endsWith(`.${suffix}`);
|
|
62
|
+
}
|
|
63
|
+
function isLocalEndpointHost(host) {
|
|
64
|
+
return LOCAL_ENDPOINT_HOSTS.has(host) || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal");
|
|
65
|
+
}
|
|
66
|
+
function resolveBundledOpenAIResponsesEndpointClass(baseUrl) {
|
|
67
|
+
const trimmed = readStringValue(baseUrl)?.trim();
|
|
68
|
+
if (!trimmed) return "default";
|
|
69
|
+
const host = resolveUrlHostname(trimmed);
|
|
70
|
+
if (!host) return "invalid";
|
|
71
|
+
const comparableBaseUrl = normalizeComparableBaseUrl(trimmed);
|
|
72
|
+
switch (host) {
|
|
73
|
+
case "api.anthropic.com": return "anthropic-public";
|
|
74
|
+
case "api.cerebras.ai": return "cerebras-native";
|
|
75
|
+
case "llm.chutes.ai": return "chutes-native";
|
|
76
|
+
case "api.deepseek.com": return "deepseek-native";
|
|
77
|
+
case "api.groq.com": return "groq-native";
|
|
78
|
+
case "api.mistral.ai": return "mistral-public";
|
|
79
|
+
case "api.openai.com": return "openai-public";
|
|
80
|
+
case "chatgpt.com": return "openai";
|
|
81
|
+
case "generativelanguage.googleapis.com": return "google-generative-ai";
|
|
82
|
+
case "aiplatform.googleapis.com": return "google-vertex";
|
|
83
|
+
case "api.x.ai": return "xai-native";
|
|
84
|
+
case "api.z.ai": return "zai-native";
|
|
85
|
+
}
|
|
86
|
+
if (hostMatchesSuffix(host, ".githubcopilot.com")) return "github-copilot-native";
|
|
87
|
+
if ([
|
|
88
|
+
".openai.azure.com",
|
|
89
|
+
".cognitiveservices.azure.com",
|
|
90
|
+
".services.ai.azure.com",
|
|
91
|
+
".api.cognitive.microsoft.com"
|
|
92
|
+
].some((suffix) => hostMatchesSuffix(host, suffix))) return "azure-openai";
|
|
93
|
+
if (hostMatchesSuffix(host, "openrouter.ai")) return "openrouter";
|
|
94
|
+
if (hostMatchesSuffix(host, "opencode.ai")) return "opencode-native";
|
|
95
|
+
if (hostMatchesSuffix(host, "-aiplatform.googleapis.com")) return "google-vertex";
|
|
96
|
+
if (comparableBaseUrl && MOONSHOT_NATIVE_BASE_URLS.has(comparableBaseUrl)) return "moonshot-native";
|
|
97
|
+
if (comparableBaseUrl && MODELSTUDIO_NATIVE_BASE_URLS.has(comparableBaseUrl)) return "modelstudio-native";
|
|
98
|
+
if (isLocalEndpointHost(host)) return "local";
|
|
99
|
+
return "custom";
|
|
100
|
+
}
|
|
101
|
+
function isOpenAIResponsesApi(api) {
|
|
102
|
+
return api !== void 0 && OPENAI_RESPONSES_APIS.has(api);
|
|
103
|
+
}
|
|
104
|
+
function readCompatPayloadBoolean(compat, key) {
|
|
105
|
+
if (!compat || typeof compat !== "object") return;
|
|
106
|
+
const value = compat[key];
|
|
107
|
+
return typeof value === "boolean" ? value : void 0;
|
|
108
|
+
}
|
|
109
|
+
function resolveOpenAIResponsesPayloadCapabilities(model) {
|
|
110
|
+
const provider = normalizeOptionalLowercaseString(model.provider);
|
|
111
|
+
const api = normalizeOptionalLowercaseString(model.api);
|
|
112
|
+
const isOpenAIProvider = provider === "openai";
|
|
113
|
+
const endpointClass = resolveBundledOpenAIResponsesEndpointClass(model.baseUrl);
|
|
114
|
+
const isResponsesApi = isOpenAIResponsesApi(api);
|
|
115
|
+
const usesConfiguredBaseUrl = endpointClass !== "default";
|
|
116
|
+
const usesKnownNativeOpenAIEndpoint = endpointClass === "openai-public" || endpointClass === "openai" || endpointClass === "azure-openai";
|
|
117
|
+
const usesKnownNativeOpenAIRoute = endpointClass === "default" ? provider === "openai" : usesKnownNativeOpenAIEndpoint;
|
|
118
|
+
const usesExplicitProxyLikeEndpoint = usesConfiguredBaseUrl && !usesKnownNativeOpenAIEndpoint;
|
|
119
|
+
const promptCacheKeySupport = readCompatPayloadBoolean(model.compat, "supportsPromptCacheKey");
|
|
120
|
+
const shouldStripResponsesPromptCache = promptCacheKeySupport === true ? false : promptCacheKeySupport === false ? isResponsesApi : isResponsesApi && usesExplicitProxyLikeEndpoint;
|
|
121
|
+
const supportsResponsesStoreField = readCompatPayloadBoolean(model.compat, "supportsStore") !== false && isResponsesApi;
|
|
122
|
+
return {
|
|
123
|
+
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",
|
|
124
|
+
allowsResponsesStore: supportsResponsesStoreField && api !== "openai-chatgpt-responses" && api !== "openclaw-openai-chatgpt-responses-transport" && provider !== void 0 && OPENAI_RESPONSES_PROVIDERS.has(provider) && usesKnownNativeOpenAIEndpoint,
|
|
125
|
+
shouldStripResponsesPromptCache,
|
|
126
|
+
supportsResponsesStoreField,
|
|
127
|
+
usesKnownNativeOpenAIRoute
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function parsePositiveInteger(value) {
|
|
131
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
|
|
132
|
+
if (typeof value === "string") return parseStrictPositiveInteger(value);
|
|
133
|
+
}
|
|
134
|
+
function resolveOpenAIResponsesCompactThreshold(model) {
|
|
135
|
+
const contextWindow = parsePositiveInteger(model.contextWindow);
|
|
136
|
+
if (contextWindow) return Math.max(1e3, Math.floor(contextWindow * .7));
|
|
137
|
+
return 8e4;
|
|
138
|
+
}
|
|
139
|
+
/** Resolve the server-compaction gate and effective threshold for a Responses route. */
|
|
140
|
+
function resolveOpenAIResponsesServerCompactionPlan(model, extraParams) {
|
|
141
|
+
const provider = normalizeOptionalLowercaseString(model.provider);
|
|
142
|
+
const allowsResponsesStore = resolveOpenAIResponsesPayloadCapabilities(model).allowsResponsesStore;
|
|
143
|
+
const configured = extraParams?.responsesServerCompaction;
|
|
144
|
+
const enabled = configured !== false && allowsResponsesStore && (configured === true || provider === "openai");
|
|
145
|
+
return {
|
|
146
|
+
enabled,
|
|
147
|
+
threshold: enabled ? parsePositiveInteger(extraParams?.responsesCompactThreshold) ?? resolveOpenAIResponsesCompactThreshold(model) : void 0
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** Resolve the manual Responses compact-endpoint gate for one route. */
|
|
151
|
+
function resolveOpenAIResponsesCompactEndpointPlan(model, extraParams) {
|
|
152
|
+
const configured = extraParams?.responsesCompactEndpoint;
|
|
153
|
+
const provider = typeof model.provider === "string" ? normalizeProviderId(model.provider) : "";
|
|
154
|
+
return { enabled: isOpenAIResponsesApi(normalizeOptionalLowercaseString(model.api)) && (configured === true || configured !== false && (provider === "xai" || provider === "x-ai") && resolveBundledOpenAIResponsesEndpointClass(model.baseUrl) === "xai-native") };
|
|
155
|
+
}
|
|
156
|
+
function stripDisabledOpenAIReasoningPayload(payloadObj) {
|
|
157
|
+
const reasoning = payloadObj.reasoning;
|
|
158
|
+
if (reasoning === "none") {
|
|
159
|
+
delete payloadObj.reasoning;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!reasoning || typeof reasoning !== "object" || Array.isArray(reasoning)) return;
|
|
163
|
+
if (reasoning.effort === "none") delete payloadObj.reasoning;
|
|
164
|
+
}
|
|
165
|
+
/** Strip returned-item metadata rejected by strict Responses-compatible endpoints. */
|
|
166
|
+
function stripInputItemStatuses(input) {
|
|
167
|
+
if (!Array.isArray(input)) return;
|
|
168
|
+
for (const item of input) if (item && typeof item === "object" && !Array.isArray(item)) delete item.status;
|
|
169
|
+
}
|
|
170
|
+
/** Resolve payload mutation policy for one OpenAI Responses-style model endpoint. */
|
|
171
|
+
function resolveOpenAIResponsesPayloadPolicy(model, options = {}) {
|
|
172
|
+
const capabilities = resolveOpenAIResponsesPayloadCapabilities(model);
|
|
173
|
+
const storeMode = options.storeMode ?? "provider-policy";
|
|
174
|
+
const explicitStore = storeMode === "preserve" ? void 0 : storeMode === "disable" ? capabilities.supportsResponsesStoreField ? false : void 0 : capabilities.allowsResponsesStore ? true : void 0;
|
|
175
|
+
const isResponsesApi = isOpenAIResponsesApi(normalizeOptionalLowercaseString(model.api));
|
|
176
|
+
const shouldStripDisabledReasoningPayload = isResponsesApi && (!capabilities.usesKnownNativeOpenAIRoute || !supportsOpenAIReasoningEffort(model, "none"));
|
|
177
|
+
const shouldStripInputStatus = isResponsesApi && !capabilities.usesKnownNativeOpenAIRoute;
|
|
178
|
+
const serverCompactionPlan = resolveOpenAIResponsesServerCompactionPlan(model, options.extraParams);
|
|
179
|
+
return {
|
|
180
|
+
allowsServiceTier: capabilities.allowsOpenAIServiceTier,
|
|
181
|
+
compactThreshold: serverCompactionPlan.threshold,
|
|
182
|
+
explicitStore,
|
|
183
|
+
shouldStripDisabledReasoningPayload,
|
|
184
|
+
shouldStripInputStatus,
|
|
185
|
+
shouldStripPromptCache: options.enablePromptCacheStripping === true && capabilities.shouldStripResponsesPromptCache,
|
|
186
|
+
shouldStripStore: explicitStore !== true && readCompatPayloadBoolean(model.compat, "supportsStore") === false && isResponsesApi,
|
|
187
|
+
useServerCompaction: options.enableServerCompaction === true && serverCompactionPlan.enabled
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** Mutate a Responses request payload according to the resolved endpoint policy. */
|
|
191
|
+
function applyOpenAIResponsesPayloadPolicy(payloadObj, policy) {
|
|
192
|
+
if (policy.explicitStore !== void 0) payloadObj.store = policy.explicitStore;
|
|
193
|
+
if (policy.shouldStripStore) delete payloadObj.store;
|
|
194
|
+
if (policy.shouldStripPromptCache) {
|
|
195
|
+
delete payloadObj.prompt_cache_key;
|
|
196
|
+
delete payloadObj.prompt_cache_retention;
|
|
197
|
+
}
|
|
198
|
+
if (policy.useServerCompaction && policy.compactThreshold !== void 0 && payloadObj.context_management === void 0) payloadObj.context_management = [{
|
|
199
|
+
type: "compaction",
|
|
200
|
+
compact_threshold: policy.compactThreshold
|
|
201
|
+
}];
|
|
202
|
+
if (policy.shouldStripDisabledReasoningPayload) stripDisabledOpenAIReasoningPayload(payloadObj);
|
|
203
|
+
if (policy.shouldStripInputStatus) stripInputItemStatuses(payloadObj.input);
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
export { resolveOpenAIResponsesServerCompactionPlan as i, resolveOpenAIResponsesCompactEndpointPlan as n, resolveOpenAIResponsesPayloadPolicy as r, applyOpenAIResponsesPayloadPolicy as t };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region packages/ai/src/transports/openai-responses-payload-policy.d.ts
|
|
2
|
+
type OpenAIResponsesPayloadModel = {
|
|
3
|
+
api?: unknown;
|
|
4
|
+
baseUrl?: unknown;
|
|
5
|
+
id?: unknown;
|
|
6
|
+
provider?: unknown;
|
|
7
|
+
contextWindow?: unknown;
|
|
8
|
+
compat?: unknown;
|
|
9
|
+
};
|
|
10
|
+
type OpenAIResponsesPayloadPolicyOptions = {
|
|
11
|
+
extraParams?: Record<string, unknown>;
|
|
12
|
+
storeMode?: "provider-policy" | "disable" | "preserve";
|
|
13
|
+
enablePromptCacheStripping?: boolean;
|
|
14
|
+
enableServerCompaction?: boolean;
|
|
15
|
+
};
|
|
16
|
+
type OpenAIResponsesPayloadPolicy = {
|
|
17
|
+
allowsServiceTier: boolean;
|
|
18
|
+
compactThreshold: number | undefined;
|
|
19
|
+
explicitStore: boolean | undefined;
|
|
20
|
+
shouldStripDisabledReasoningPayload: boolean;
|
|
21
|
+
shouldStripInputStatus: boolean;
|
|
22
|
+
shouldStripPromptCache: boolean;
|
|
23
|
+
shouldStripStore: boolean;
|
|
24
|
+
useServerCompaction: boolean;
|
|
25
|
+
};
|
|
26
|
+
/** Resolve the server-compaction gate and effective threshold for a Responses route. */
|
|
27
|
+
declare function resolveOpenAIResponsesServerCompactionPlan(model: OpenAIResponsesPayloadModel, extraParams?: Record<string, unknown>): {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
threshold: number | undefined;
|
|
30
|
+
};
|
|
31
|
+
/** Resolve the manual Responses compact-endpoint gate for one route. */
|
|
32
|
+
declare function resolveOpenAIResponsesCompactEndpointPlan(model: OpenAIResponsesPayloadModel, extraParams?: Record<string, unknown>): {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
};
|
|
35
|
+
/** Resolve payload mutation policy for one OpenAI Responses-style model endpoint. */
|
|
36
|
+
declare function resolveOpenAIResponsesPayloadPolicy(model: OpenAIResponsesPayloadModel, options?: OpenAIResponsesPayloadPolicyOptions): OpenAIResponsesPayloadPolicy;
|
|
37
|
+
/** Mutate a Responses request payload according to the resolved endpoint policy. */
|
|
38
|
+
declare function applyOpenAIResponsesPayloadPolicy(payloadObj: Record<string, unknown>, policy: OpenAIResponsesPayloadPolicy): void;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { resolveOpenAIResponsesServerCompactionPlan as i, resolveOpenAIResponsesCompactEndpointPlan as n, resolveOpenAIResponsesPayloadPolicy as r, applyOpenAIResponsesPayloadPolicy as t };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { m as responsesPromptObserver } from "./openai-responses-contracts-CyfIkQi5.mjs";
|
|
2
|
+
import { l as stripSystemPromptCacheBoundary } from "./simple-options-D58D5Kvw.mjs";
|
|
3
|
+
import { d as sanitizeTransportPayloadText } from "./provider-transcript-transform-ePx-Bbfr.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 };
|