@openclaw/ai 2026.9.7 → 2026.10.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/{anthropic-Cw2pgccz.mjs → anthropic-CZv6XFER.mjs} +52 -147
- package/dist/{anthropic-payload-policy-NIPVYXPq.d.mts → anthropic-payload-policy-BhCcgNdm.d.mts} +7 -4
- package/dist/{anthropic-stream-reducer-D9MCkl8Z.mjs → anthropic-stream-reducer-BQ1tjd7x.mjs} +369 -233
- package/dist/{api-registry-D-nbmSqr.d.mts → api-registry-DpU0Rj-I.d.mts} +4 -4
- package/dist/{provider-transcript-transform-JbFbHV8h.mjs → assistant-output-OLm-Oln0.mjs} +17 -17
- package/dist/{assistant-text-phase-C20rxWwP.mjs → assistant-text-phase-Bl1aDCB7.mjs} +2 -8
- package/dist/{azure-openai-responses-BwT3-X8P.mjs → azure-openai-responses-DH7bd3QT.mjs} +12 -17
- package/dist/{azure-openai-responses-client-compat-C7K7QfUE.mjs → azure-openai-responses-client-compat-D0dvJMbZ.mjs} +3 -10
- package/dist/{base64-C1PsYcRQ.mjs → base64-C8CdcsjU.mjs} +3 -45
- package/dist/cloudflare-5qSGvIUH.mjs +39 -0
- package/dist/{diagnostics-CJaB6g8J.mjs → diagnostics-Caj-4RBA.mjs} +19 -37
- package/dist/diagnostics.d.mts +4 -4
- package/dist/diagnostics.mjs +2 -2
- package/dist/{event-stream-vd9UnCAU.mjs → event-stream-C5AbCAaZ.mjs} +29 -1
- package/dist/event-stream-DqDQWqiy.d.mts +1 -0
- package/dist/{event-stream-DOPFYVqs.d.mts → event-stream-DrRM_90c.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-request-facts-BTEBMeOv.mjs → github-copilot-request-facts-DEE6gcB9.mjs} +3 -1
- package/dist/{google-BfapkS_K.mjs → google-1WLOtb8w.mjs} +12 -9
- package/dist/{google-interactions-DW3iXzjc.mjs → google-interactions-wrnE6MLw.mjs} +39 -49
- package/dist/{google-messages-CtjVtVot.mjs → google-messages-BwPPycw6.mjs} +11 -17
- package/dist/{google-shared-Y2YfotEu.mjs → google-shared-Eql1OMPU.mjs} +5 -6
- package/dist/{google-vertex-Dov4kBWu.mjs → google-vertex-0LrlRoO3.mjs} +11 -11
- package/dist/{host-rxlNaBwm.d.mts → host-BinBeGcQ.d.mts} +12 -4
- package/dist/{host-CHi3X87F.mjs → host-DCW52iHe.mjs} +57 -9
- package/dist/{host-policy-BOAwRg_M.mjs → host-policy-B3jc4Rpn.mjs} +9 -2
- package/dist/{index-D6KsSE74.d.mts → index-a8e_oKnu.d.mts} +7 -5
- package/dist/index.d.mts +23 -7
- package/dist/index.mjs +7 -7
- package/dist/internal/anthropic.d.mts +6 -6
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +14 -10
- package/dist/internal/openai.mjs +12 -12
- package/dist/internal/runtime.d.mts +18 -9
- package/dist/internal/runtime.mjs +9 -9
- package/dist/internal/shared.d.mts +6 -4
- package/dist/internal/shared.mjs +6 -6
- package/dist/internal/tool-schema.mjs +1 -1
- package/dist/json-schema-Bp07Qui3.mjs +22 -0
- package/dist/{llm-request-activity-BjtkplhG.mjs → llm-request-activity-D8f_oxHj.mjs} +1 -2
- package/dist/{mistral-RS6mboC-.mjs → mistral-DSt4vQAO.mjs} +18 -29
- package/dist/number-coercion-V8-BhME4.mjs +47 -0
- package/dist/{openai-chatgpt-responses-CYbidtrn.mjs → openai-chatgpt-responses-BC2x0Oqx.mjs} +215 -164
- package/dist/openai-completions-DNyHnXKg.mjs +25 -0
- package/dist/{openai-completions-compat-qJjmqQ71.d.mts → openai-completions-compat-BYdYpXhU.d.mts} +3 -3
- package/dist/{openai-completions-compat-BOVWBZDn.mjs → openai-completions-compat-BdmlhD4u.mjs} +30 -23
- package/dist/{openai-completions-stream-CDCuw3DP.mjs → openai-completions-transport-DWM2mQDB.mjs} +389 -76
- package/dist/{openai-prompt-cache-CouErLh7.d.mts → openai-prompt-cache-45-AH_xv.d.mts} +2 -2
- package/dist/{openai-prompt-cache-D2V7MqR7.mjs → openai-prompt-cache-I8YQTzf8.mjs} +1 -1
- package/dist/{openai-responses-compaction-replay-DiYn-gFM.d.mts → openai-responses-compaction-replay-BClApUIf.d.mts} +4 -4
- package/dist/{openai-responses-compaction-window-UNK1GDpy.mjs → openai-responses-compaction-window-m878aVpU.mjs} +25 -83
- package/dist/{openai-reasoning-effort-ConhwkeX.mjs → openai-responses-contracts-BKu8O7l4.mjs} +106 -7
- package/dist/{openai-responses-contracts-D1iZ0njF.d.mts → openai-responses-contracts-Br5IIw_h.d.mts} +16 -5
- package/dist/openai-responses-prompt-observer-internal-CCg7B6l4.mjs +32 -0
- package/dist/{openai-responses-shared-DL4ulQn7.mjs → openai-responses-shared-C7oVyjED.mjs} +297 -312
- package/dist/{openai-responses-terminal-usage-BE7lf7nW.d.mts → openai-responses-terminal-usage-DgImcyJu.d.mts} +2 -2
- package/dist/{openai-responses-CKCBEc2W.mjs → openai-responses-uZ5oWSp7.mjs} +12 -21
- package/dist/{openai-tool-schema-vsl-cE-n.mjs → openai-tool-schema-DYNePiF8.mjs} +66 -36
- package/dist/{openai-transport-params-BwlpzX-2.mjs → openai-transport-params-JFsnIyto.mjs} +25 -30
- package/dist/openai-web-search-tools-Cfu0uLyN.mjs +14 -0
- package/dist/{positive-integer-CjN5OJbH.mjs → positive-integer-CwLi8LUL.mjs} +1 -1
- package/dist/{provider-error-CwT_j2v0.mjs → provider-error-DQBE1bUQ.mjs} +17 -28
- package/dist/{provider-options-Df7ov0K1.d.mts → provider-options-D5ABCV_l.d.mts} +2 -2
- package/dist/{provider-replay-context-DsyI5jOP.mjs → provider-replay-context-C7Bmi84a.mjs} +6 -2
- package/dist/{provider-transport-turn-state-BheUi_hl.mjs → provider-transport-turn-state-_M2kLdUE.mjs} +25 -3
- package/dist/{provider-types-d4XnoZMd.d.mts → provider-types-F8Mqc9Ma.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +14 -26
- package/dist/{reasoning-tag-text-partitioner-B6FIIBt6.mjs → reasoning-tag-text-partitioner-Ju9VpUGl.mjs} +23 -37
- package/dist/required-api-key-D4kn3252.mjs +9 -0
- package/dist/sanitize-unicode-CjDG6jJx.d.mts +5 -0
- package/dist/{session-affinity-Bcunsn4I.mjs → session-affinity-DA4WHv1h.mjs} +2 -6
- package/dist/session-resources-D1wgDQ8C.mjs +40 -0
- package/dist/{simple-options-CGAkCwtM.mjs → simple-options-BkKTXxhp.mjs} +7 -11
- package/dist/{src-H4aXcFuX.mjs → src-B0NIt2UK.mjs} +7 -4
- package/dist/stream-DSdzKsDK.mjs +275 -0
- package/dist/{stream-first-event-timeout-B9o0S4SZ.mjs → stream-first-event-timeout-D9ZmL_s9.mjs} +3 -3
- package/dist/{string-coerce-fsri9iCu.mjs → string-coerce-CtgOVOSv.mjs} +5 -1
- package/dist/{string-normalization-J9ZiLfGO.mjs → string-normalization-PN10hf6d.mjs} +1 -1
- package/dist/{transport-utils-C-4bf2Ok.mjs → text-signature-MLwfi6fq.mjs} +18 -18
- package/dist/{transport-stream-shared-yYhXa4kX.d.mts → transport-stream-shared-BcAKh2XH.d.mts} +6 -19
- package/dist/{transport-stream-shared-Dh5qKJ8e.mjs → transport-stream-shared-CxXXz_Dd.mjs} +171 -56
- package/dist/transports.d.mts +22 -23
- package/dist/transports.mjs +251 -495
- package/dist/types-BuiEBM3u.d.mts +1 -0
- package/dist/types-CQc6JNG4.mjs +69 -0
- package/dist/{types-CLLR3eB4.d.mts → types-DvzmWW8J.d.mts} +58 -6
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +5 -5
- package/dist/usage-CJH5D6Ea.mjs +19 -0
- package/dist/{validation-Cat2wQsc.d.mts → validation-B3lQt_VE.d.mts} +1 -1
- package/dist/{validation-BFZc40Ig.mjs → validation-DbqlIfDn.mjs} +15 -30
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +4 -4
- package/dist/cache-retention-0x979a5V.mjs +0 -12
- package/dist/event-stream-CMQfX_yr.d.mts +0 -1
- package/dist/github-copilot-headers-B37TB3rB.mjs +0 -30
- package/dist/openai-completions-D14ihPYk.mjs +0 -188
- package/dist/openai-provider-client-CwfsGBbA.mjs +0 -24
- package/dist/openai-responses-contracts-CLxnqS9p.mjs +0 -81
- package/dist/openai-responses-prompt-observer-internal-iAqLb4tk.mjs +0 -198
- package/dist/sanitize-unicode-BZiVbGwK.d.mts +0 -24
- package/dist/session-resources-CkR4WWy1.mjs +0 -21
- package/dist/stream-DDsCBgd-.mjs +0 -68
- package/dist/types-CB-_vNyI.d.mts +0 -1
- package/dist/types-LFWwv0cF.mjs +0 -8
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { n as getAiTransportHost } from "./host-CHi3X87F.mjs";
|
|
2
|
-
import { O as resolveOpenAIClientBaseUrl } from "./openai-transport-params-BwlpzX-2.mjs";
|
|
3
|
-
import { i as resolveCloudflareBaseUrl, r as isCloudflareProvider } from "./github-copilot-headers-B37TB3rB.mjs";
|
|
4
|
-
import OpenAI from "openai";
|
|
5
|
-
//#region packages/ai/src/providers/openai-provider-client.ts
|
|
6
|
-
function createOpenAIProviderClient(model, apiKey, headers, optionsHeaders) {
|
|
7
|
-
if (optionsHeaders) Object.assign(headers, optionsHeaders);
|
|
8
|
-
const defaultHeaders = model.provider === "cloudflare-ai-gateway" ? {
|
|
9
|
-
...headers,
|
|
10
|
-
Authorization: headers.Authorization ?? null,
|
|
11
|
-
"cf-aig-authorization": `Bearer ${apiKey}`
|
|
12
|
-
} : headers;
|
|
13
|
-
const baseUrl = isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl;
|
|
14
|
-
return new OpenAI({
|
|
15
|
-
apiKey,
|
|
16
|
-
baseURL: resolveOpenAIClientBaseUrl(model, baseUrl),
|
|
17
|
-
dangerouslyAllowBrowser: true,
|
|
18
|
-
defaultHeaders,
|
|
19
|
-
maxRetries: 0,
|
|
20
|
-
fetch: getAiTransportHost().buildModelFetch(model)
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
export { createOpenAIProviderClient as t };
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { r as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE } from "./types-LFWwv0cF.mjs";
|
|
2
|
-
import { o as isRecord } from "./record-coerce-CNDovvft.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 };
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
|
|
2
|
-
import { n as getAiTransportHost } from "./host-CHi3X87F.mjs";
|
|
3
|
-
import { d as supportsOpenAITemperature, i as isOpenAIGpt6Model, m as resolveOpenAIThinkingApi } from "./openai-reasoning-effort-ConhwkeX.mjs";
|
|
4
|
-
import { r as resolveOpenAIPromptCacheParams } from "./openai-prompt-cache-D2V7MqR7.mjs";
|
|
5
|
-
import { o as usesNativeOpenAICodexResponsesBackend } from "./openai-completions-compat-BOVWBZDn.mjs";
|
|
6
|
-
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
7
|
-
import { v as sanitizeTransportPayloadText } from "./transport-stream-shared-Dh5qKJ8e.mjs";
|
|
8
|
-
import { C as stripSystemPromptCacheBoundary } from "./simple-options-CGAkCwtM.mjs";
|
|
9
|
-
import { g as resolveOpenAISimpleReasoningEffort, h as resolveOpenAIRequestReasoning, k as resolvePromptCacheKey, m as reconcileOpenAIResponsesToolChoice, s as getCompat } from "./openai-transport-params-BwlpzX-2.mjs";
|
|
10
|
-
import { h as responsesPromptObserver, r as OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS } from "./openai-responses-contracts-CLxnqS9p.mjs";
|
|
11
|
-
import { a as applyOpenAIResponsesPayloadPolicy, s as resolveOpenAIResponsesPayloadPolicy } from "./openai-responses-compaction-window-UNK1GDpy.mjs";
|
|
12
|
-
import { F as convertResponsesMessages, N as buildResponsesInputMessage, a as prepareResponsesTools } from "./openai-responses-shared-DL4ulQn7.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 && (!isOpenAIGpt6Model(model) || resolveOpenAIThinkingApi(model.api) === "azure-openai-responses")) 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 = getAiTransportHost().resolveOpenAIStrictToolSetting(model, {
|
|
138
|
-
transport: "stream",
|
|
139
|
-
supportsStrictMode: compat.supportsStrictMode
|
|
140
|
-
});
|
|
141
|
-
const { projection, tools: converted } = prepareResponsesTools(tools, strict, model);
|
|
142
|
-
if (converted.length > 0 || projection.inputToolCount === 0 && projection.diagnostics.length === 0) params.tools = converted;
|
|
143
|
-
if (options?.toolChoice) {
|
|
144
|
-
const toolChoice = reconcileOpenAIResponsesToolChoice(options.toolChoice, projection);
|
|
145
|
-
if (toolChoice !== void 0) params.tool_choice = toolChoice;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (model.reasoning) {
|
|
149
|
-
const reasoning = options?.reasoning;
|
|
150
|
-
const requestedEffort = options?.reasoningEffort ?? (reasoning === "none" ? "none" : resolveOpenAISimpleReasoningEffort(model, reasoning)) ?? (options?.reasoningSummary ? "high" : payloadPolicy.defaultManagedReasoningEffort);
|
|
151
|
-
const resolvedEffort = requestedEffort === void 0 ? void 0 : resolveOpenAIRequestReasoning(model, requestedEffort).effort;
|
|
152
|
-
if (resolvedEffort !== void 0) {
|
|
153
|
-
const effort = raiseMinimalReasoningForResponsesWebSearch({
|
|
154
|
-
model,
|
|
155
|
-
effort: resolvedEffort,
|
|
156
|
-
tools: params.tools
|
|
157
|
-
});
|
|
158
|
-
const summary = effort !== "none" && (options?.reasoningEffort || options?.reasoning || options?.reasoningSummary) ? options.reasoningSummary || "auto" : void 0;
|
|
159
|
-
params.reasoning = {
|
|
160
|
-
effort,
|
|
161
|
-
...summary ? { summary } : {}
|
|
162
|
-
};
|
|
163
|
-
if (summary) params.include = ["reasoning.encrypted_content"];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
applyOpenAIResponsesPayloadPolicy(params, payloadPolicy);
|
|
167
|
-
return sanitizeOpenAICodexResponsesParams(model, params);
|
|
168
|
-
}
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region packages/ai/src/transports/openai-responses-prompt-observer-internal.ts
|
|
171
|
-
function readFinalResponsesPrompt(request) {
|
|
172
|
-
if (typeof request.instructions === "string") return ["instructions", request.instructions];
|
|
173
|
-
const message = (Array.isArray(request.input) ? request.input : []).find((item) => {
|
|
174
|
-
const role = item.role;
|
|
175
|
-
return role === "developer" || role === "system";
|
|
176
|
-
});
|
|
177
|
-
if (!message) return ["missing", ""];
|
|
178
|
-
const content = message.content;
|
|
179
|
-
const observedPrompt = typeof content === "string" ? content : Array.isArray(content) ? content.flatMap((part) => part.type === "input_text" ? [part.text] : []).join("") : "";
|
|
180
|
-
return [message.role === "developer" ? "input.developer" : "input.system", observedPrompt];
|
|
181
|
-
}
|
|
182
|
-
function createResponsesPromptEgressObserver(options, assembledPrompt) {
|
|
183
|
-
const observer = options ? responsesPromptObserver.get(options) : void 0;
|
|
184
|
-
if (!observer) return;
|
|
185
|
-
const expectedPrompt = sanitizeTransportPayloadText(stripSystemPromptCacheBoundary(assembledPrompt ?? ""));
|
|
186
|
-
return (request, metadata) => {
|
|
187
|
-
const [promptSource, observedPrompt] = readFinalResponsesPrompt(request);
|
|
188
|
-
observer({
|
|
189
|
-
...metadata,
|
|
190
|
-
promptSource,
|
|
191
|
-
expectedChars: expectedPrompt.length,
|
|
192
|
-
observedChars: observedPrompt.length,
|
|
193
|
-
matchesAssembledPrompt: promptSource !== "missing" && observedPrompt === expectedPrompt
|
|
194
|
-
});
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
//#endregion
|
|
198
|
-
export { sanitizeOpenAICodexResponsesParams as a, resolveOpenAIResponsesTextFormat as i, buildOpenAIResponsesCompactSystemMessage as n, buildOpenAIResponsesParams as r, createResponsesPromptEgressObserver as t };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//#region packages/ai/src/utils/sanitize-unicode.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Removes unpaired Unicode surrogate characters from a string.
|
|
4
|
-
*
|
|
5
|
-
* Unpaired surrogates (high surrogates 0xD800-0xDBFF without matching low surrogates 0xDC00-0xDFFF,
|
|
6
|
-
* or vice versa) cause JSON serialization errors in many API providers.
|
|
7
|
-
*
|
|
8
|
-
* Valid emoji and other characters outside the Basic Multilingual Plane use properly paired
|
|
9
|
-
* surrogates and will NOT be affected by this function.
|
|
10
|
-
*
|
|
11
|
-
* @param text - The text to sanitize
|
|
12
|
-
* @returns The sanitized text with unpaired surrogates removed
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* // Valid emoji (properly paired surrogates) are preserved
|
|
16
|
-
* sanitizeSurrogates("Hello 🙈 World") // => "Hello 🙈 World"
|
|
17
|
-
*
|
|
18
|
-
* // Unpaired high surrogate is removed
|
|
19
|
-
* const unpaired = String.fromCharCode(0xD83D); // high surrogate without low
|
|
20
|
-
* sanitizeSurrogates(`Text ${unpaired} here`) // => "Text here"
|
|
21
|
-
*/
|
|
22
|
-
declare function sanitizeSurrogates(text: string): string;
|
|
23
|
-
//#endregion
|
|
24
|
-
export { sanitizeSurrogates as t };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//#region packages/ai/src/session-resources.ts
|
|
2
|
-
const sessionResourceCleanups = /* @__PURE__ */ new Set();
|
|
3
|
-
/** Registers a session-resource cleanup hook and returns an unregister function. */
|
|
4
|
-
function registerSessionResourceCleanup(cleanup) {
|
|
5
|
-
sessionResourceCleanups.add(cleanup);
|
|
6
|
-
return () => {
|
|
7
|
-
sessionResourceCleanups.delete(cleanup);
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
/** Runs all registered cleanup hooks, aggregating failures after every hook has run. */
|
|
11
|
-
function cleanupSessionResources(sessionId) {
|
|
12
|
-
const errors = [];
|
|
13
|
-
for (const cleanup of sessionResourceCleanups) try {
|
|
14
|
-
cleanup(sessionId);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
errors.push(error);
|
|
17
|
-
}
|
|
18
|
-
if (errors.length > 0) throw new AggregateError(errors, "Failed to cleanup session resources");
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { registerSessionResourceCleanup as n, cleanupSessionResources as t };
|
package/dist/stream-DDsCBgd-.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
//#region packages/ai/src/api-registry.ts
|
|
2
|
-
function wrapStream(api, stream) {
|
|
3
|
-
return (model, context, options) => {
|
|
4
|
-
if (model.api !== api) throw new Error(`Mismatched api: ${model.api} expected ${api}`);
|
|
5
|
-
return stream(model, context, options);
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
/** Creates an isolated provider registry for one runtime or tenant. */
|
|
9
|
-
function createApiRegistry() {
|
|
10
|
-
const providers = /* @__PURE__ */ new Map();
|
|
11
|
-
function registerApiProvider(provider, sourceId) {
|
|
12
|
-
providers.set(provider.api, {
|
|
13
|
-
provider: {
|
|
14
|
-
api: provider.api,
|
|
15
|
-
stream: wrapStream(provider.api, provider.stream),
|
|
16
|
-
streamSimple: wrapStream(provider.api, provider.streamSimple)
|
|
17
|
-
},
|
|
18
|
-
sourceId
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function getApiProvider(api) {
|
|
22
|
-
return providers.get(api)?.provider;
|
|
23
|
-
}
|
|
24
|
-
function getApiProviders() {
|
|
25
|
-
return Array.from(providers.values(), (entry) => entry.provider);
|
|
26
|
-
}
|
|
27
|
-
function unregisterApiProviders(sourceId) {
|
|
28
|
-
for (const [api, entry] of providers.entries()) if (entry.sourceId === sourceId) providers.delete(api);
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
registerApiProvider,
|
|
32
|
-
getApiProvider,
|
|
33
|
-
getApiProviders,
|
|
34
|
-
unregisterApiProviders,
|
|
35
|
-
clearApiProviders: () => providers.clear()
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region packages/ai/src/stream.ts
|
|
40
|
-
/** Creates an isolated LLM runtime backed by the supplied provider registry. */
|
|
41
|
-
function createLlmRuntime(registry = createApiRegistry()) {
|
|
42
|
-
function resolveApiProvider(api) {
|
|
43
|
-
const provider = registry.getApiProvider(api);
|
|
44
|
-
if (!provider) throw new Error(`No API provider registered for api: ${api}`);
|
|
45
|
-
return provider;
|
|
46
|
-
}
|
|
47
|
-
function stream(model, context, options) {
|
|
48
|
-
return resolveApiProvider(model.api).stream(model, context, options);
|
|
49
|
-
}
|
|
50
|
-
async function complete(model, context, options) {
|
|
51
|
-
return stream(model, context, options).result();
|
|
52
|
-
}
|
|
53
|
-
function streamSimple(model, context, options) {
|
|
54
|
-
return resolveApiProvider(model.api).streamSimple(model, context, options);
|
|
55
|
-
}
|
|
56
|
-
async function completeSimple(model, context, options) {
|
|
57
|
-
return streamSimple(model, context, options).result();
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
registry,
|
|
61
|
-
stream,
|
|
62
|
-
complete,
|
|
63
|
-
streamSimple,
|
|
64
|
-
completeSimple
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
//#endregion
|
|
68
|
-
export { createApiRegistry as n, createLlmRuntime as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./index-D6KsSE74.mjs";
|
package/dist/types-LFWwv0cF.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region packages/llm-core/src/types.ts
|
|
2
|
-
/** Stable error codes for provider outcomes that cannot be replayed safely. */
|
|
3
|
-
const PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE = "PROVIDER_POST_DISPATCH_AMBIGUITY";
|
|
4
|
-
const PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE = "PROVIDER_FAILURE_WITH_OUTPUT";
|
|
5
|
-
/** Pre-dispatch argument rejection; callers still enforce output and effect guards. */
|
|
6
|
-
const MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE = "malformed_tool_call_arguments";
|
|
7
|
-
//#endregion
|
|
8
|
-
export { PROVIDER_FAILURE_WITH_OUTPUT_ERROR_CODE as n, PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE as r, MALFORMED_TOOL_CALL_ARGUMENTS_ERROR_CODE as t };
|