@openclaw/ai 2026.8.1 → 2026.8.33
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-Djj7L1rx.mjs → anthropic-BNeFhAh3.mjs} +197 -185
- package/dist/{anthropic-compaction-replay-CY4tkD4V.mjs → anthropic-compaction-replay-B6sEzXhr.mjs} +24 -7
- package/dist/{anthropic-payload-policy-i_5_inWe.d.mts → anthropic-payload-policy-kkq8L7tJ.d.mts} +2 -2
- package/dist/{api-registry-C9-wZd_W.d.mts → api-registry-CAK4bNkq.d.mts} +2 -2
- package/dist/{azure-openai-responses-Bj3czHNa.mjs → azure-openai-responses-CPvqFff1.mjs} +6 -5
- package/dist/diagnostics.mjs +1 -1
- package/dist/event-stream-CDHaMazK.d.mts +1 -0
- package/dist/{event-stream-UhnxHuqt.d.mts → event-stream-DcQzYRWO.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/{google-0Ca6TYbw.mjs → google-B6pXyWB0.mjs} +7 -5
- package/dist/{google-shared-DVfL9COU.mjs → google-shared-C_3CT37v.mjs} +25 -23
- package/dist/{google-vertex-5dAMxprN.mjs → google-vertex-BA2c1toq.mjs} +7 -5
- package/dist/{host-DoPJJ1KD.d.mts → host-DL2Zd9ep.d.mts} +3 -3
- package/dist/{host-D51fmkH6.mjs → host-DhlhmyR6.mjs} +17 -2
- package/dist/index-DcGDVDnC.d.mts +118 -0
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +4 -4
- package/dist/internal/anthropic.d.mts +11 -6
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +1 -1
- package/dist/internal/openai.d.mts +7 -7
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/runtime.d.mts +5 -5
- package/dist/internal/runtime.mjs +3 -3
- package/dist/internal/shared.d.mts +2 -2
- package/dist/internal/shared.mjs +3 -3
- package/dist/{mistral-BCnrI-kV.mjs → mistral-CTcM9TGz.mjs} +18 -13
- package/dist/{openai-chatgpt-responses-CGBGWSqr.mjs → openai-chatgpt-responses-QqHf1o9v.mjs} +17 -16
- package/dist/{openai-completions-BaTuwID7.mjs → openai-completions-BCmKwgsc.mjs} +17 -14
- package/dist/{openai-completions-compat-DB7FFq7k.d.mts → openai-completions-compat-BJE92duO.d.mts} +3 -3
- package/dist/{openai-completions-stream-Bpns6uNc.mjs → openai-completions-stream-0mm4YUag.mjs} +30 -27
- package/dist/openai-prompt-cache-BUJI5cW-.d.mts +16 -0
- package/dist/openai-prompt-cache-CGnVB74a.mjs +21 -0
- package/dist/{openai-responses-compaction-window-DwydGZI8.mjs → openai-responses-compaction-window-vuCaZYLS.mjs} +3 -3
- package/dist/{openai-responses-contracts-DgaR3t5T.d.mts → openai-responses-contracts-DFJOyjd1.d.mts} +6 -3
- package/dist/{openai-responses-1GBcQujk.mjs → openai-responses-pMJVxhHW.mjs} +11 -12
- package/dist/{openai-responses-prompt-observer-internal-_nhGTn2b.mjs → openai-responses-prompt-observer-internal-COaImuDp.mjs} +3 -3
- package/dist/{openai-responses-shared-zPmKnhF5.mjs → openai-responses-shared-CZTRmOFP.mjs} +27 -26
- package/dist/{openai-tool-schema-Dgl4H2MU.mjs → openai-tool-schema-DjS9-DHe.mjs} +14 -12
- package/dist/{provider-error-jZP5NMTZ.mjs → provider-error-BI8kIViN.mjs} +11 -11
- package/dist/{provider-options-HvA_slFa.d.mts → provider-options-CedgbINH.d.mts} +2 -2
- package/dist/{provider-transcript-transform-C01bQ5a3.mjs → provider-transcript-transform-BnsgCK8K.mjs} +1 -1
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +10 -10
- package/dist/{reasoning-tag-text-partitioner-CwzKb0bA.mjs → reasoning-tag-text-partitioner-BsUX44Tq.mjs} +29 -19
- package/dist/{sanitize-unicode-DCkltN94.mjs → sanitize-unicode-Cfcaqa9V.mjs} +2 -8
- package/dist/{simple-options-DKx86yX9.mjs → simple-options-Bwi0x0bX.mjs} +2 -2
- package/dist/{src-Bu3FiFAG.mjs → src-BhgSqnbz.mjs} +88 -2
- package/dist/{tool-schema-json-projection-qvTEs5Am.mjs → tool-schema-json-projection-_gcOC21Y.mjs} +21 -31
- package/dist/{transport-stream-shared-NjwWNaRY.d.mts → transport-stream-shared-B38NWYTa.d.mts} +4 -4
- package/dist/{transport-stream-shared-CT5ycdzn.mjs → transport-stream-shared-y1YR1k5K.mjs} +2 -2
- package/dist/{transport-utils-BHx9z8Cl.mjs → transport-utils-DdLjoPMb.mjs} +2 -2
- package/dist/transports.d.mts +12 -9
- package/dist/transports.mjs +91 -73
- package/dist/types-DmdQ-xcq.d.mts +1 -0
- package/dist/{types-h38Azne1.d.mts → types-DmeScJQe.d.mts} +25 -13
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +3 -3
- package/dist/{validation-B61OhAio.mjs → validation-CJZtym2g.mjs} +7 -5
- package/dist/{validation-C68lP2uy.d.mts → validation-DPDgbaD3.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +2 -2
- package/dist/event-stream-C988TSLe.d.mts +0 -1
- package/dist/index-N3zr6__t.d.mts +0 -105
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/types-DtGu2d3C.d.mts +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
2
|
-
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
3
|
-
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-
|
|
4
|
-
import { n as projectProviderError } from "./provider-error-
|
|
5
|
-
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-
|
|
2
|
+
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-Cfcaqa9V.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-DhlhmyR6.mjs";
|
|
4
|
+
import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
|
|
5
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-Bwi0x0bX.mjs";
|
|
6
6
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
7
|
-
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-
|
|
7
|
+
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-y1YR1k5K.mjs";
|
|
8
8
|
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
9
9
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
10
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BnsgCK8K.mjs";
|
|
11
11
|
import { t as mapOpenAIStopReason } from "./openai-stop-reason-Drnn_6Qj.mjs";
|
|
12
12
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
@@ -15,7 +15,7 @@ import { HTTPClient } from "@mistralai/mistralai/lib/http";
|
|
|
15
15
|
import { Chat } from "@mistralai/mistralai/sdk/chat";
|
|
16
16
|
//#region packages/ai/src/providers/mistral.ts
|
|
17
17
|
const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
|
|
18
|
-
const MISTRAL_STREAM_BODY_MAX_BYTES =
|
|
18
|
+
const MISTRAL_STREAM_BODY_MAX_BYTES = 16777216;
|
|
19
19
|
/**
|
|
20
20
|
* Builds a `Fetcher` that wraps the default `fetch` with a 16 MiB byte cap
|
|
21
21
|
* on streamed response bodies. The wrapped `Response.body` exposes a
|
|
@@ -31,7 +31,8 @@ function createBoundedMistralFetcher(maxBytes = MISTRAL_STREAM_BODY_MAX_BYTES, u
|
|
|
31
31
|
return async (input, init) => {
|
|
32
32
|
const response = init == null ? await upstreamFetch(input) : await upstreamFetch(input, init);
|
|
33
33
|
if (!response.body || typeof response.body.getReader !== "function") return response;
|
|
34
|
-
const
|
|
34
|
+
const reader = response.body.getReader();
|
|
35
|
+
const guard = createSseByteGuard(reader, {
|
|
35
36
|
maxBytes,
|
|
36
37
|
onOverflow: ({ size, maxBytes: cap }) => /* @__PURE__ */ new Error(`mistral: stream body exceeds ${cap} bytes (got ${size})`)
|
|
37
38
|
});
|
|
@@ -198,7 +199,8 @@ function deriveMistralToolCallId(id, attempt) {
|
|
|
198
199
|
const normalized = id.replace(/[^a-zA-Z0-9]/g, "");
|
|
199
200
|
if (attempt === 0 && normalized.length === MISTRAL_TOOL_CALL_ID_LENGTH) return normalized;
|
|
200
201
|
const seedBase = normalized || id;
|
|
201
|
-
|
|
202
|
+
const seed = attempt === 0 ? seedBase : `${seedBase}:${attempt}`;
|
|
203
|
+
return shortHash(seed).replace(/[^a-zA-Z0-9]/g, "").padEnd(MISTRAL_TOOL_CALL_ID_LENGTH, "0").slice(0, MISTRAL_TOOL_CALL_ID_LENGTH);
|
|
202
204
|
}
|
|
203
205
|
function buildChatPayload(model, context, messages, options) {
|
|
204
206
|
const payload = {
|
|
@@ -372,7 +374,8 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
372
374
|
continue;
|
|
373
375
|
}
|
|
374
376
|
if (item.type === "thinking") {
|
|
375
|
-
const
|
|
377
|
+
const deltaText = item.thinking.map((part) => "text" in part ? part.text : "").filter((text) => text.length > 0).join("");
|
|
378
|
+
const thinkingDelta = sanitizeSurrogates(deltaText);
|
|
376
379
|
if (!thinkingDelta) continue;
|
|
377
380
|
if (!currentBlock || currentBlock.type !== "thinking") {
|
|
378
381
|
finishCurrentBlock(currentBlock);
|
|
@@ -514,7 +517,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
514
517
|
}
|
|
515
518
|
}
|
|
516
519
|
function toFunctionTools(tools) {
|
|
517
|
-
|
|
520
|
+
const converted = tools.flatMap((tool) => {
|
|
518
521
|
try {
|
|
519
522
|
const name = tool.name;
|
|
520
523
|
const description = tool.description;
|
|
@@ -534,7 +537,8 @@ function toFunctionTools(tools) {
|
|
|
534
537
|
} catch {
|
|
535
538
|
return [];
|
|
536
539
|
}
|
|
537
|
-
})
|
|
540
|
+
});
|
|
541
|
+
return sortPromptCacheToolsByName(converted).map(({ value }) => value);
|
|
538
542
|
}
|
|
539
543
|
function stripSymbolKeys(value) {
|
|
540
544
|
if (Array.isArray(value)) return value.map((item) => stripSymbolKeys(item));
|
|
@@ -619,10 +623,11 @@ function toChatMessages(messages, supportsImages) {
|
|
|
619
623
|
const toolContent = [];
|
|
620
624
|
const textResult = extractToolResultText(msg.content);
|
|
621
625
|
const mediaPlaceholder = describeToolResultMediaPlaceholder(msg.content);
|
|
626
|
+
const omittedMediaPlaceholder = msg.content.some(isImageWithMediaPayload) && !supportsImages ? textResult.trim() ? "[tool image omitted: model does not support images]" : mediaPlaceholder === "(see attached media)" ? "(media omitted: model does not support images)" : "(image omitted: model does not support images)" : void 0;
|
|
622
627
|
const toolText = formatToolResultText({
|
|
623
628
|
text: textResult,
|
|
624
629
|
mediaPlaceholder,
|
|
625
|
-
omittedMediaPlaceholder
|
|
630
|
+
omittedMediaPlaceholder,
|
|
626
631
|
isError: msg.isError
|
|
627
632
|
});
|
|
628
633
|
toolContent.push({
|
package/dist/{openai-chatgpt-responses-CGBGWSqr.mjs → openai-chatgpt-responses-QqHf1o9v.mjs}
RENAMED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-COpOtRwq.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
4
|
-
import { n as projectProviderError } from "./provider-error-
|
|
5
|
-
import { n as toErrorObject, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-DhlhmyR6.mjs";
|
|
4
|
+
import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
|
|
5
|
+
import { n as toErrorObject, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-COaImuDp.mjs";
|
|
6
6
|
import { o as clampTimerTimeoutMs, u as resolveTimerTimeoutMs } from "./base64-CEFBpSkN.mjs";
|
|
7
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
8
|
-
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-
|
|
7
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
8
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-Bwi0x0bX.mjs";
|
|
9
9
|
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|
|
10
|
-
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-
|
|
10
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-DdLjoPMb.mjs";
|
|
11
11
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
12
|
-
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, y as withProviderResponseHook } from "./transport-stream-shared-
|
|
13
|
-
import { F as commitResponsesEncryptedContentAttempt, L as isInvalidEncryptedContentError, W as buildOpenAIResponsesReasoningReplayMetadata, a as resolveResponsesReasoningEffort, c as processResponsesStream, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, p as ResponsesStreamFailure, q as suppressOpenAIResponsesCompaction, r as convertResponsesMessages, s as convertResponsesToolPayload, z as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-
|
|
14
|
-
import { C as createOpenAIProviderAcceptanceHook, w as createOpenAIResponseHook } from "./openai-tool-schema-
|
|
12
|
+
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, y as withProviderResponseHook } from "./transport-stream-shared-y1YR1k5K.mjs";
|
|
13
|
+
import { F as commitResponsesEncryptedContentAttempt, L as isInvalidEncryptedContentError, W as buildOpenAIResponsesReasoningReplayMetadata, a as resolveResponsesReasoningEffort, c as processResponsesStream, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, p as ResponsesStreamFailure, q as suppressOpenAIResponsesCompaction, r as convertResponsesMessages, s as convertResponsesToolPayload, z as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-CZTRmOFP.mjs";
|
|
14
|
+
import { C as createOpenAIProviderAcceptanceHook, w as createOpenAIResponseHook } from "./openai-tool-schema-DjS9-DHe.mjs";
|
|
15
15
|
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
16
|
-
import { A as supportsOpenAITemperature, S as responsesPromptObserver } from "./openai-responses-compaction-window-
|
|
16
|
+
import { A as supportsOpenAITemperature, S as responsesPromptObserver } from "./openai-responses-compaction-window-vuCaZYLS.mjs";
|
|
17
17
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
18
18
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
19
19
|
import "./diagnostics.mjs";
|
|
@@ -40,7 +40,7 @@ function sleepWithAbort(ms, signal) {
|
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
43
|
-
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES =
|
|
43
|
+
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
|
|
44
44
|
var CodexProtocolError = class extends Error {
|
|
45
45
|
constructor(message, options) {
|
|
46
46
|
super(message);
|
|
@@ -110,7 +110,7 @@ const REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
|
110
110
|
const CODEX_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "opencode"]);
|
|
111
111
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
112
112
|
const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
113
|
-
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES =
|
|
113
|
+
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
|
|
114
114
|
const CODEX_RESPONSE_STATUSES = /* @__PURE__ */ new Set([
|
|
115
115
|
"completed",
|
|
116
116
|
"incomplete",
|
|
@@ -340,7 +340,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
340
340
|
if (!nextSemanticAttempt) throw terminalResponseError ?? /* @__PURE__ */ new Error("Failed after retries");
|
|
341
341
|
semanticAttempt = nextSemanticAttempt;
|
|
342
342
|
}
|
|
343
|
-
|
|
343
|
+
const hookedResponseStream = withProviderResponseHook({
|
|
344
344
|
stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response)),
|
|
345
345
|
signal: firstEventAbort.signal,
|
|
346
346
|
abort: firstEventAbort.abort,
|
|
@@ -349,7 +349,8 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
349
349
|
type: "start",
|
|
350
350
|
partial: output
|
|
351
351
|
})
|
|
352
|
-
})
|
|
352
|
+
});
|
|
353
|
+
await processResponsesStream(hookedResponseStream, output, stream, model, {
|
|
353
354
|
serviceTier: options?.serviceTier,
|
|
354
355
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
355
356
|
abortFirstEventStream: firstEventAbort.abort,
|
|
@@ -515,8 +516,8 @@ function normalizeCodexStatus(status) {
|
|
|
515
516
|
return CODEX_RESPONSE_STATUSES.has(status) ? status : void 0;
|
|
516
517
|
}
|
|
517
518
|
const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
518
|
-
const SESSION_WEBSOCKET_CACHE_TTL_MS =
|
|
519
|
-
const SESSION_WEBSOCKET_MAX_AGE_MS =
|
|
519
|
+
const SESSION_WEBSOCKET_CACHE_TTL_MS = 3e5;
|
|
520
|
+
const SESSION_WEBSOCKET_MAX_AGE_MS = 33e5;
|
|
520
521
|
const websocketSessionCache = /* @__PURE__ */ new Map();
|
|
521
522
|
const websocketSseFallbackSessions = /* @__PURE__ */ new Set();
|
|
522
523
|
let cachedWebsocket = null;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
-
import { i as clampThinkingLevel } from "./sanitize-unicode-
|
|
4
|
-
import { n as getAiTransportHost } from "./host-
|
|
5
|
-
import { n as projectProviderError } from "./provider-error-
|
|
6
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
3
|
+
import { i as clampThinkingLevel } from "./sanitize-unicode-Cfcaqa9V.mjs";
|
|
4
|
+
import { n as getAiTransportHost } from "./host-DhlhmyR6.mjs";
|
|
5
|
+
import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
|
|
6
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
7
7
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
8
|
-
import { m as sortPromptCacheToolsByName, n as buildBaseOptions, o as reasoningTagTextPolicy, u as splitSystemPromptCacheBoundary } from "./simple-options-
|
|
8
|
+
import { m as sortPromptCacheToolsByName, n as buildBaseOptions, o as reasoningTagTextPolicy, u as splitSystemPromptCacheBoundary } from "./simple-options-Bwi0x0bX.mjs";
|
|
9
9
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
10
|
-
import { _ as transportAbortError, y as withProviderResponseHook } from "./transport-stream-shared-
|
|
11
|
-
import { E as tagUnresolvedTextAsCommentary, S as shouldOmitOllamaCompatResponseFormat, _ as hasToolCallHistory, b as resolveOpenAICompletionsCompat, g as convertMessages, h as resolveOpenAIReasoningEffortMap, t as processCompletionsStream, v as finalizeOpenAICompletionsToolCalls, w as clearPendingCommentaryText, x as resolveOpenAICompletionsResponseFormat } from "./openai-completions-stream-
|
|
12
|
-
import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-
|
|
10
|
+
import { _ as transportAbortError, y as withProviderResponseHook } from "./transport-stream-shared-y1YR1k5K.mjs";
|
|
11
|
+
import { E as tagUnresolvedTextAsCommentary, S as shouldOmitOllamaCompatResponseFormat, _ as hasToolCallHistory, b as resolveOpenAICompletionsCompat, g as convertMessages, h as resolveOpenAIReasoningEffortMap, t as processCompletionsStream, v as finalizeOpenAICompletionsToolCalls, w as clearPendingCommentaryText, x as resolveOpenAICompletionsResponseFormat } from "./openai-completions-stream-0mm4YUag.mjs";
|
|
12
|
+
import { C as createOpenAIProviderAcceptanceHook, T as isOpenAICompletionsThinkingEnabled, j as resolveOpenAIClientBaseUrl, v as projectOpenAITools, y as reconcileOpenAICompletionsToolChoice } from "./openai-tool-schema-DjS9-DHe.mjs";
|
|
13
13
|
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
14
14
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
15
15
|
import OpenAI from "openai";
|
|
@@ -191,11 +191,13 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
|
|
|
191
191
|
});
|
|
192
192
|
Object.assign(headers, copilotHeaders);
|
|
193
193
|
}
|
|
194
|
-
if (sessionId && compat.sessionAffinity !== "none")
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
if (sessionId && compat.sessionAffinity !== "none") {
|
|
195
|
+
if (compat.sessionAffinity === "openrouter") headers["x-session-id"] = sessionId;
|
|
196
|
+
else {
|
|
197
|
+
headers.session_id = sessionId;
|
|
198
|
+
headers["x-client-request-id"] = sessionId;
|
|
199
|
+
headers["x-session-affinity"] = sessionId;
|
|
200
|
+
}
|
|
199
201
|
}
|
|
200
202
|
if (optionsHeaders) Object.assign(headers, optionsHeaders);
|
|
201
203
|
const defaultHeaders = model.provider === "cloudflare-ai-gateway" ? {
|
|
@@ -203,9 +205,10 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
|
|
|
203
205
|
Authorization: headers.Authorization ?? null,
|
|
204
206
|
"cf-aig-authorization": `Bearer ${apiKey}`
|
|
205
207
|
} : headers;
|
|
208
|
+
const baseUrl = isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl;
|
|
206
209
|
return new OpenAI({
|
|
207
210
|
apiKey,
|
|
208
|
-
baseURL: resolveOpenAIClientBaseUrl(model,
|
|
211
|
+
baseURL: resolveOpenAIClientBaseUrl(model, baseUrl),
|
|
209
212
|
dangerouslyAllowBrowser: true,
|
|
210
213
|
defaultHeaders,
|
|
211
214
|
fetch: getAiTransportHost().buildModelFetch(model)
|
package/dist/{openai-completions-compat-DB7FFq7k.d.mts → openai-completions-compat-BJE92duO.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { D as Model,
|
|
3
|
-
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-
|
|
1
|
+
import "./index-DcGDVDnC.mjs";
|
|
2
|
+
import { D as Model, j as OpenAICompletionsCompat } from "./types-DmeScJQe.mjs";
|
|
3
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-DL2Zd9ep.mjs";
|
|
4
4
|
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
5
5
|
type ProviderRequestCapabilities = AiProviderRequestCapabilities;
|
|
6
6
|
type OpenAICompletionsSessionAffinity = "none" | "openai" | "openrouter";
|
package/dist/{openai-completions-stream-Bpns6uNc.mjs → openai-completions-stream-0mm4YUag.mjs}
RENAMED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { c as normalizeLowercaseStringOrEmpty, i as asOptionalObjectRecord, o as isRecord, t as truncateUtf16Safe } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
-
import { t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
3
|
-
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, n as getAiTransportHost } from "./host-
|
|
4
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
5
|
-
import { d as stripSystemPromptCacheBoundary } from "./simple-options-
|
|
6
|
-
import { o as resolveProviderRequestCapabilities, r as resolveModelRequestTimeoutMs, s as resolveProviderRequestPolicyConfig } from "./tool-schema-json-projection-
|
|
7
|
-
import { i as isCodeModeModelVisibleToolName, p as sha256Hex } from "./transport-utils-
|
|
8
|
-
import { s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-
|
|
2
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-Cfcaqa9V.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, n as getAiTransportHost } from "./host-DhlhmyR6.mjs";
|
|
4
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
5
|
+
import { d as stripSystemPromptCacheBoundary } from "./simple-options-Bwi0x0bX.mjs";
|
|
6
|
+
import { o as resolveProviderRequestCapabilities, r as resolveModelRequestTimeoutMs, s as resolveProviderRequestPolicyConfig } from "./tool-schema-json-projection-_gcOC21Y.mjs";
|
|
7
|
+
import { i as isCodeModeModelVisibleToolName, p as sha256Hex } from "./transport-utils-DdLjoPMb.mjs";
|
|
8
|
+
import { s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-y1YR1k5K.mjs";
|
|
9
9
|
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
10
10
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
11
|
-
import { A as readOpenAICompletionsReasoningBatch, D as measureUtf8AppendBytes, N as throwIfModelStreamAborted, O as parseOpenAICompletionsUsage, S as createModelStreamCooperativeScheduler, T as isOpenAICompletionsThinkingEnabled, a as resolveOpenAIProjectedToolsStrictToolFlag, k as readOpenAICompletionsContentDeltas, t as findOpenAIStrictToolProjectionDiagnostics } from "./openai-tool-schema-
|
|
11
|
+
import { A as readOpenAICompletionsReasoningBatch, D as measureUtf8AppendBytes, N as throwIfModelStreamAborted, O as parseOpenAICompletionsUsage, S as createModelStreamCooperativeScheduler, T as isOpenAICompletionsThinkingEnabled, a as resolveOpenAIProjectedToolsStrictToolFlag, k as readOpenAICompletionsContentDeltas, t as findOpenAIStrictToolProjectionDiagnostics } from "./openai-tool-schema-DjS9-DHe.mjs";
|
|
12
12
|
import { a as withFirstStreamEventTimeout } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
13
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
13
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BnsgCK8K.mjs";
|
|
14
14
|
import { t as mapOpenAIStopReason } from "./openai-stop-reason-Drnn_6Qj.mjs";
|
|
15
|
-
import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-
|
|
15
|
+
import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-BsUX44Tq.mjs";
|
|
16
16
|
import { randomUUID } from "node:crypto";
|
|
17
17
|
//#region packages/ai/src/utils/assistant-text-phase.ts
|
|
18
18
|
const EMPTY_ASSISTANT_TEXT_BLOCK_SET = /* @__PURE__ */ new Set();
|
|
@@ -396,11 +396,13 @@ function createOpenAICompletionsToolCallDeltaNormalizer() {
|
|
|
396
396
|
}];
|
|
397
397
|
const hadPendingLegacyCall = pendingLegacyToolCall !== void 0;
|
|
398
398
|
const leadingDeltas = [];
|
|
399
|
-
if (hasOrdinaryContent(ordinaryDelta))
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
399
|
+
if (hasOrdinaryContent(ordinaryDelta)) {
|
|
400
|
+
if (hadPendingLegacyCall) bufferFollowingDelta(ordinaryDelta);
|
|
401
|
+
else leadingDeltas.push({
|
|
402
|
+
delta: ordinaryDelta,
|
|
403
|
+
toolCalls: []
|
|
404
|
+
});
|
|
405
|
+
}
|
|
404
406
|
if (functionCall && (functionCall.name || functionCall.arguments)) {
|
|
405
407
|
const nextFunctionName = pendingLegacyToolCall?.function?.name ? void 0 : functionCall.name;
|
|
406
408
|
const nextArgumentBytes = Buffer.byteLength(functionCall.arguments ?? "", "utf8") + Buffer.byteLength(nextFunctionName ?? "", "utf8");
|
|
@@ -566,17 +568,18 @@ function convertMessages(model, context, compat, options = {}) {
|
|
|
566
568
|
}));
|
|
567
569
|
const assistantText = assistantTextParts.map((part) => part.text).join("\n");
|
|
568
570
|
const nonEmptyThinkingBlocks = msg.content.filter(isThinkingContentBlock).filter((block) => block.thinking.trim().length > 0);
|
|
569
|
-
if (nonEmptyThinkingBlocks.length > 0)
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
571
|
+
if (nonEmptyThinkingBlocks.length > 0) {
|
|
572
|
+
if (compat.requiresThinkingAsText) assistantMsg.content = [{
|
|
573
|
+
type: "text",
|
|
574
|
+
text: nonEmptyThinkingBlocks.map((block) => sanitizeSurrogates(block.thinking)).join("\n\n")
|
|
575
|
+
}, ...assistantTextParts];
|
|
576
|
+
else {
|
|
577
|
+
if (assistantText.length > 0) assistantMsg.content = assistantText;
|
|
578
|
+
let signature = nonEmptyThinkingBlocks.at(0)?.thinkingSignature;
|
|
579
|
+
if (model.provider === "opencode-go" && signature === "reasoning") signature = "reasoning_content";
|
|
580
|
+
if (signature && signature.length > 0) assistantMsg[signature] = nonEmptyThinkingBlocks.map((block) => block.thinking).join("\n");
|
|
581
|
+
}
|
|
582
|
+
} else if (assistantText.length > 0) assistantMsg.content = assistantText;
|
|
580
583
|
const toolCalls = msg.content.filter(isToolCallBlock);
|
|
581
584
|
if (toolCalls.length > 0) {
|
|
582
585
|
assistantMsg.tool_calls = toolCalls.map((toolCall) => ({
|
|
@@ -912,7 +915,7 @@ const DEEPSEEK_DSML_INVOKE_OPEN_TAG = new RegExp(`^<${DEEPSEEK_DSML_MARKER_PATTE
|
|
|
912
915
|
const DEEPSEEK_DSML_TOOL_MAX_OPEN_TOKEN_LEN = Math.max(...DEEPSEEK_DSML_TOOL_OPEN_TOKENS.map((token) => token.length));
|
|
913
916
|
const DEEPSEEK_DSML_RECOVERY_MAX_BOUNDARY_LEN = Math.max(...DEEPSEEK_DSML_TOOL_OPEN_TOKENS.map((token) => token.length + 1), ...DEEPSEEK_DSML_INVOKE_OPEN_PREFIXES.map((token) => token.length + 2));
|
|
914
917
|
const MAX_DSML_RECOVERY_BUFFER_BYTES = 256e3;
|
|
915
|
-
const DEEPSEEK_DSML_SCAN_BATCH_CHARS =
|
|
918
|
+
const DEEPSEEK_DSML_SCAN_BATCH_CHARS = 65536;
|
|
916
919
|
function createDsmlRecoverer() {
|
|
917
920
|
let buffer = "";
|
|
918
921
|
let bufferBytes = 0;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { D as Model, l as CacheRetention } from "./types-DmeScJQe.mjs";
|
|
2
|
+
import "./types-DmdQ-xcq.mjs";
|
|
3
|
+
//#region packages/ai/src/providers/openai-prompt-cache.d.ts
|
|
4
|
+
/** Selects the documented cache lifetime fields for a Responses request. */
|
|
5
|
+
declare function resolveOpenAIResponsesCacheParams(model: Pick<Model, "id" | "api" | "baseUrl">, cacheRetention: CacheRetention, supportsLongCacheRetention: boolean): {
|
|
6
|
+
prompt_cache_retention?: "24h";
|
|
7
|
+
prompt_cache_options?: {
|
|
8
|
+
ttl: "30m";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
12
|
+
declare const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
13
|
+
/** Truncates a prompt cache key by Unicode code point count. */
|
|
14
|
+
declare function clampOpenAIPromptCacheKey(key: string | undefined): string | undefined;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { clampOpenAIPromptCacheKey as n, resolveOpenAIResponsesCacheParams as r, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH as t };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region packages/ai/src/providers/openai-prompt-cache.ts
|
|
2
|
+
/** Selects the documented cache lifetime fields for a Responses request. */
|
|
3
|
+
function resolveOpenAIResponsesCacheParams(model, cacheRetention, supportsLongCacheRetention) {
|
|
4
|
+
if (cacheRetention === "none") return {};
|
|
5
|
+
if (model.id === "gpt-6-astra" && model.api === "openai-responses") {
|
|
6
|
+
const endpoint = URL.parse(model.baseUrl ?? "https://api.openai.com/v1");
|
|
7
|
+
if (endpoint?.protocol === "https:" && (endpoint.hostname === "api.openai.com" || endpoint.hostname.endsWith(".api.openai.com"))) return { prompt_cache_options: { ttl: "30m" } };
|
|
8
|
+
}
|
|
9
|
+
return cacheRetention === "long" && supportsLongCacheRetention ? { prompt_cache_retention: "24h" } : {};
|
|
10
|
+
}
|
|
11
|
+
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
12
|
+
const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
13
|
+
/** Truncates a prompt cache key by Unicode code point count. */
|
|
14
|
+
function clampOpenAIPromptCacheKey(key) {
|
|
15
|
+
if (key === void 0) return;
|
|
16
|
+
const chars = Array.from(key);
|
|
17
|
+
if (chars.length <= 64) return key;
|
|
18
|
+
return chars.slice(0, 64).join("");
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { clampOpenAIPromptCacheKey as n, resolveOpenAIResponsesCacheParams as r, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH as t };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "./src-
|
|
1
|
+
import "./src-BhgSqnbz.mjs";
|
|
2
2
|
import { n as PROVIDER_POST_DISPATCH_AMBIGUITY_ERROR_CODE } from "./types-BDdaOVi2.mjs";
|
|
3
3
|
import { c as normalizeLowercaseStringOrEmpty, o as isRecord, p as readStringValue, u as normalizeOptionalLowercaseString } from "./utf16-slice-qz3nsy87.mjs";
|
|
4
4
|
import { t as canonicalizeBase64 } from "./base64-CEFBpSkN.mjs";
|
|
5
5
|
import { n as uniqueStrings, t as normalizeStringEntries } from "./string-normalization--fwJ4S2q.mjs";
|
|
6
|
-
import { s as parsePositiveInteger } from "./transport-utils-
|
|
6
|
+
import { s as parsePositiveInteger } from "./transport-utils-DdLjoPMb.mjs";
|
|
7
7
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
8
8
|
//#region packages/ai/src/providers/openai-reasoning-effort.ts
|
|
9
9
|
/**
|
|
@@ -581,7 +581,7 @@ function sanitizeResponsesImagePayload(params) {
|
|
|
581
581
|
}
|
|
582
582
|
//#endregion
|
|
583
583
|
//#region packages/ai/src/transports/openai-responses-compaction-window.ts
|
|
584
|
-
const COMPACTION_WINDOW_MAX_BYTES =
|
|
584
|
+
const COMPACTION_WINDOW_MAX_BYTES = 16777216;
|
|
585
585
|
function isOptionalCompactionString(value) {
|
|
586
586
|
return value === void 0 || typeof value === "string";
|
|
587
587
|
}
|
package/dist/{openai-responses-contracts-DgaR3t5T.d.mts → openai-responses-contracts-DFJOyjd1.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { D as Model, n as Api } from "./types-
|
|
3
|
-
import { g as OpenAIReasoningEffort, h as OpenAIApiReasoningEffort, i as BaseOpenAIStreamOptions } from "./provider-options-
|
|
1
|
+
import "./index-DcGDVDnC.mjs";
|
|
2
|
+
import { D as Model, n as Api } from "./types-DmeScJQe.mjs";
|
|
3
|
+
import { g as OpenAIReasoningEffort, h as OpenAIApiReasoningEffort, i as BaseOpenAIStreamOptions } from "./provider-options-CedgbINH.mjs";
|
|
4
4
|
import { FunctionTool, ResponseCompactionItem, ResponseCreateParamsStreaming, ResponseInput, ResponseInputItem } from "openai/resources/responses/responses.js";
|
|
5
5
|
//#region packages/ai/src/transports/openai-responses-compaction-window.d.ts
|
|
6
6
|
type OpenAIResponsesCompactionOutput = Array<ResponseInputItem.Message | ReplayableResponseCompactionItem>;
|
|
@@ -55,6 +55,9 @@ type OpenAIResponsesRequestParams = {
|
|
|
55
55
|
instructions?: string;
|
|
56
56
|
prompt_cache_key?: string;
|
|
57
57
|
prompt_cache_retention?: "24h";
|
|
58
|
+
prompt_cache_options?: {
|
|
59
|
+
ttl: "30m";
|
|
60
|
+
};
|
|
58
61
|
metadata?: Record<string, string>;
|
|
59
62
|
previous_response_id?: string;
|
|
60
63
|
store?: boolean;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
-
import { n as getAiTransportHost } from "./host-
|
|
4
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
3
|
+
import { n as getAiTransportHost } from "./host-DhlhmyR6.mjs";
|
|
4
|
+
import { n as clampOpenAIPromptCacheKey, r as resolveOpenAIResponsesCacheParams } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
5
5
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
6
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
6
|
+
import { n as buildBaseOptions } from "./simple-options-Bwi0x0bX.mjs";
|
|
7
7
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
8
|
-
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-
|
|
9
|
-
import { j as resolveOpenAIClientBaseUrl } from "./openai-tool-schema-
|
|
10
|
-
import { A as supportsOpenAITemperature } from "./openai-responses-compaction-window-
|
|
8
|
+
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, o as runResponsesStreamLifecycle, r as convertResponsesMessages, t as applyCommonResponsesParams } from "./openai-responses-shared-CZTRmOFP.mjs";
|
|
9
|
+
import { j as resolveOpenAIClientBaseUrl } from "./openai-tool-schema-DjS9-DHe.mjs";
|
|
10
|
+
import { A as supportsOpenAITemperature } from "./openai-responses-compaction-window-vuCaZYLS.mjs";
|
|
11
11
|
import { i as resolveCloudflareBaseUrl, n as hasCopilotVisionInput, r as isCloudflareProvider, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-NCJtz9i0.mjs";
|
|
12
12
|
import OpenAI from "openai";
|
|
13
13
|
//#region packages/ai/src/providers/openai-responses.ts
|
|
@@ -22,18 +22,16 @@ function getCompat(model) {
|
|
|
22
22
|
supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
function getPromptCacheRetention(compat, cacheRetention) {
|
|
26
|
-
return cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0;
|
|
27
|
-
}
|
|
28
25
|
/**
|
|
29
26
|
* Generate function for OpenAI Responses API
|
|
30
27
|
*/
|
|
31
28
|
const streamOpenAIResponses = (model, context, options) => {
|
|
32
29
|
const stream = new AssistantMessageEventStream();
|
|
30
|
+
const output = createResponsesAssistantOutput(model);
|
|
33
31
|
runResponsesStreamLifecycle({
|
|
34
32
|
stream,
|
|
35
33
|
model,
|
|
36
|
-
output
|
|
34
|
+
output,
|
|
37
35
|
options,
|
|
38
36
|
createClient: () => {
|
|
39
37
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
@@ -82,9 +80,10 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId) {
|
|
|
82
80
|
Authorization: headers.Authorization ?? null,
|
|
83
81
|
"cf-aig-authorization": `Bearer ${apiKey}`
|
|
84
82
|
} : headers;
|
|
83
|
+
const baseUrl = isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl;
|
|
85
84
|
return new OpenAI({
|
|
86
85
|
apiKey,
|
|
87
|
-
baseURL: resolveOpenAIClientBaseUrl(model,
|
|
86
|
+
baseURL: resolveOpenAIClientBaseUrl(model, baseUrl),
|
|
88
87
|
dangerouslyAllowBrowser: true,
|
|
89
88
|
defaultHeaders,
|
|
90
89
|
fetch: getAiTransportHost().buildModelFetch(model)
|
|
@@ -104,7 +103,7 @@ function buildParams(model, context, options, replayMode = "checkpoint") {
|
|
|
104
103
|
input: messages,
|
|
105
104
|
stream: true,
|
|
106
105
|
prompt_cache_key: cacheRetention === "none" ? void 0 : clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId),
|
|
107
|
-
|
|
106
|
+
...resolveOpenAIResponsesCacheParams(model, cacheRetention, compat.supportsLongCacheRetention),
|
|
108
107
|
store: false
|
|
109
108
|
};
|
|
110
109
|
if (options?.maxTokens) params.max_output_tokens = options?.maxTokens;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { d as stripSystemPromptCacheBoundary } from "./simple-options-
|
|
2
|
-
import { g as sanitizeTransportPayloadText } from "./transport-stream-shared-
|
|
3
|
-
import { S as responsesPromptObserver } from "./openai-responses-compaction-window-
|
|
1
|
+
import { d as stripSystemPromptCacheBoundary } from "./simple-options-Bwi0x0bX.mjs";
|
|
2
|
+
import { g as sanitizeTransportPayloadText } from "./transport-stream-shared-y1YR1k5K.mjs";
|
|
3
|
+
import { S as responsesPromptObserver } from "./openai-responses-compaction-window-vuCaZYLS.mjs";
|
|
4
4
|
//#region packages/normalization-core/src/error-coercion.ts
|
|
5
5
|
/**
|
|
6
6
|
* Normalizes an unknown thrown value into an Error. Non-Error objects become
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { c as normalizeLowercaseStringOrEmpty, d as normalizeOptionalString, o as isRecord, t as truncateUtf16Safe } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
-
import { i as clampThinkingLevel, r as calculateCost } from "./sanitize-unicode-
|
|
3
|
-
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, n as getAiTransportHost } from "./host-
|
|
4
|
-
import { n as projectProviderError } from "./provider-error-
|
|
2
|
+
import { i as clampThinkingLevel, r as calculateCost } from "./sanitize-unicode-Cfcaqa9V.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, n as getAiTransportHost } from "./host-DhlhmyR6.mjs";
|
|
4
|
+
import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
|
|
5
5
|
import { r as asFiniteNumber } from "./base64-CEFBpSkN.mjs";
|
|
6
|
-
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName } from "./simple-options-
|
|
7
|
-
import { c as transformTransportMessages } from "./tool-schema-json-projection-
|
|
8
|
-
import { d as redactSensitiveText, u as redactIdentifier } from "./transport-utils-
|
|
9
|
-
import { _ as transportAbortError, g as sanitizeTransportPayloadText, h as sanitizeNonEmptyTransportPayloadText, m as parseTerminalToolCallArguments, y as withProviderResponseHook } from "./transport-stream-shared-
|
|
6
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName } from "./simple-options-Bwi0x0bX.mjs";
|
|
7
|
+
import { c as transformTransportMessages } from "./tool-schema-json-projection-_gcOC21Y.mjs";
|
|
8
|
+
import { d as redactSensitiveText, u as redactIdentifier } from "./transport-utils-DdLjoPMb.mjs";
|
|
9
|
+
import { _ as transportAbortError, g as sanitizeTransportPayloadText, h as sanitizeNonEmptyTransportPayloadText, m as parseTerminalToolCallArguments, y as withProviderResponseHook } from "./transport-stream-shared-y1YR1k5K.mjs";
|
|
10
10
|
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
11
11
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
12
12
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
13
|
-
import { C as createOpenAIProviderAcceptanceHook, E as log, S as createModelStreamCooperativeScheduler, a as resolveOpenAIProjectedToolsStrictToolFlag, r as normalizeOpenAIStrictToolParameters, t as findOpenAIStrictToolProjectionDiagnostics, v as projectOpenAITools } from "./openai-tool-schema-
|
|
13
|
+
import { C as createOpenAIProviderAcceptanceHook, E as log, S as createModelStreamCooperativeScheduler, a as resolveOpenAIProjectedToolsStrictToolFlag, r as normalizeOpenAIStrictToolParameters, t as findOpenAIStrictToolProjectionDiagnostics, v as projectOpenAITools } from "./openai-tool-schema-DjS9-DHe.mjs";
|
|
14
14
|
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
15
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
16
|
-
import { A as supportsOpenAITemperature, D as resolveOpenAIReasoningEffortForModel, b as RESPONSE_FAILED_NO_DETAILS_MESSAGE, g as OPENAI_RESPONSES_RETAINED_COMPACTION_REPLAY_TYPE, h as OPENAI_RESPONSES_REASONING_REPLAY_META_KEY, k as supportsOpenAIReasoningEffort, m as OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY, n as isOpenAIResponsesCompactionOutput, p as OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE, r as readOpenAIResponsesCompactionWindow } from "./openai-responses-compaction-window-
|
|
15
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BnsgCK8K.mjs";
|
|
16
|
+
import { A as supportsOpenAITemperature, D as resolveOpenAIReasoningEffortForModel, b as RESPONSE_FAILED_NO_DETAILS_MESSAGE, g as OPENAI_RESPONSES_RETAINED_COMPACTION_REPLAY_TYPE, h as OPENAI_RESPONSES_REASONING_REPLAY_META_KEY, k as supportsOpenAIReasoningEffort, m as OPENAI_RESPONSES_REASONING_REPLAY_BLOCK_META_KEY, n as isOpenAIResponsesCompactionOutput, p as OPENAI_RESPONSES_COMPACTION_REPLAY_TYPE, r as readOpenAIResponsesCompactionWindow } from "./openai-responses-compaction-window-vuCaZYLS.mjs";
|
|
17
17
|
import { createHash, randomUUID } from "node:crypto";
|
|
18
18
|
//#region packages/ai/src/transports/model-transport-debug.ts
|
|
19
19
|
/**
|
|
@@ -441,23 +441,24 @@ function convertResponsesMessagesWithStyle(model, context, allowedToolCallProvid
|
|
|
441
441
|
messages.push(msg);
|
|
442
442
|
continue;
|
|
443
443
|
}
|
|
444
|
-
if (msg.role === "user")
|
|
445
|
-
|
|
446
|
-
text: sanitizeTransportPayloadText(msg.content)
|
|
447
|
-
}]));
|
|
448
|
-
else {
|
|
449
|
-
const content = msg.content.map((item) => item.type === "text" ? {
|
|
444
|
+
if (msg.role === "user") {
|
|
445
|
+
if (typeof msg.content === "string") messages.push(buildResponsesInputMessage("user", [{
|
|
450
446
|
type: "input_text",
|
|
451
|
-
text: sanitizeTransportPayloadText(
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
447
|
+
text: sanitizeTransportPayloadText(msg.content)
|
|
448
|
+
}]));
|
|
449
|
+
else {
|
|
450
|
+
const content = msg.content.map((item) => item.type === "text" ? {
|
|
451
|
+
type: "input_text",
|
|
452
|
+
text: sanitizeTransportPayloadText(item.text)
|
|
453
|
+
} : {
|
|
454
|
+
type: "input_image",
|
|
455
|
+
detail: "auto",
|
|
456
|
+
image_url: `data:${item.mimeType};base64,${item.data}`
|
|
457
|
+
}).filter((item) => providerStyle || model.input.includes("image") || item.type !== "input_image");
|
|
458
|
+
if (content.length > 0) messages.push(buildResponsesInputMessage("user", content));
|
|
459
|
+
else if (providerStyle) continue;
|
|
460
|
+
}
|
|
461
|
+
} else if (msg.role === "assistant") {
|
|
461
462
|
const output = [];
|
|
462
463
|
let textFallbackOrdinal = 0;
|
|
463
464
|
let previousReplayItemWasReasoning = false;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { c as normalizeLowercaseStringOrEmpty, o as isRecord } from "./utf16-slice-qz3nsy87.mjs";
|
|
2
|
-
import { n as applyProviderReportedUsageCost, r as calculateCost } from "./sanitize-unicode-
|
|
3
|
-
import { n as getAiTransportHost } from "./host-
|
|
2
|
+
import { n as applyProviderReportedUsageCost, r as calculateCost } from "./sanitize-unicode-Cfcaqa9V.mjs";
|
|
3
|
+
import { n as getAiTransportHost } from "./host-DhlhmyR6.mjs";
|
|
4
4
|
import { r as uniqueValues, t as normalizeStringEntries } from "./string-normalization--fwJ4S2q.mjs";
|
|
5
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
6
|
-
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-
|
|
7
|
-
import { C as headersToRecord, _ as transportAbortError, f as notifyProviderHttpResponse } from "./transport-stream-shared-
|
|
5
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-CGnVB74a.mjs";
|
|
6
|
+
import { t as projectRuntimeToolInputSchema } from "./tool-schema-json-projection-_gcOC21Y.mjs";
|
|
7
|
+
import { C as headersToRecord, _ as transportAbortError, f as notifyProviderHttpResponse } from "./transport-stream-shared-y1YR1k5K.mjs";
|
|
8
8
|
//#region packages/ai/src/transports/openai-transport-shared.ts
|
|
9
9
|
/** Shared options, usage shape, cache identity, ordering, and stream scheduling for OpenAI APIs. */
|
|
10
10
|
const MODEL_STREAM_COOPERATIVE_YIELD_INTERVAL_MS = 12;
|
|
@@ -112,7 +112,7 @@ function readOpenAICompletionsReasoningBatch(delta, visibleReasoningDetailTypes)
|
|
|
112
112
|
}
|
|
113
113
|
function parseOpenAICompletionsUsage(rawUsage, model, options) {
|
|
114
114
|
const cacheRead = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? 0;
|
|
115
|
-
const cacheWrite = rawUsage.prompt_tokens_details?.cache_write_tokens
|
|
115
|
+
const cacheWrite = rawUsage.prompt_tokens_details?.cache_write_tokens ?? rawUsage.prompt_tokens_details?.cache_creation_input_tokens ?? 0;
|
|
116
116
|
const input = Math.max(0, (rawUsage.prompt_tokens || 0) - cacheRead - cacheWrite);
|
|
117
117
|
const output = rawUsage.completion_tokens || 0;
|
|
118
118
|
const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens;
|
|
@@ -647,12 +647,14 @@ function cleanSchemaForGeminiWithDefs(schema, defs, refStack) {
|
|
|
647
647
|
cleaned.type = types.length === 1 ? types[0] : types;
|
|
648
648
|
continue;
|
|
649
649
|
}
|
|
650
|
-
if (key === "properties")
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
else if (
|
|
654
|
-
|
|
655
|
-
|
|
650
|
+
if (key === "properties") {
|
|
651
|
+
if (value && typeof value === "object" && !Array.isArray(value)) cleaned[key] = Object.fromEntries(Object.entries(value).map(([k, v]) => [k, cleanSchemaForGeminiWithDefs(v, nextDefs, refStack)]));
|
|
652
|
+
else cleaned[key] = {};
|
|
653
|
+
} else if (key === "items" && value) {
|
|
654
|
+
if (Array.isArray(value)) cleaned[key] = value.map((entry) => cleanSchemaForGeminiWithDefs(entry, nextDefs, refStack));
|
|
655
|
+
else if (typeof value === "object") cleaned[key] = cleanSchemaForGeminiWithDefs(value, nextDefs, refStack);
|
|
656
|
+
else cleaned[key] = value;
|
|
657
|
+
} else if (key === "anyOf" && Array.isArray(value)) cleaned[key] = cleanedAnyOf ?? value.map((variant) => cleanSchemaForGeminiWithDefs(variant, nextDefs, refStack));
|
|
656
658
|
else if (key === "oneOf" && Array.isArray(value)) cleaned[key] = cleanedOneOf ?? value.map((variant) => cleanSchemaForGeminiWithDefs(variant, nextDefs, refStack));
|
|
657
659
|
else if (key === "allOf" && Array.isArray(value)) cleaned[key] = value.map((variant) => cleanSchemaForGeminiWithDefs(variant, nextDefs, refStack));
|
|
658
660
|
else cleaned[key] = value;
|