@openclaw/ai 2026.8.1-beta.2 → 2026.8.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-B6dLpq5L.mjs → anthropic-B8KwTtlb.mjs} +37 -27
- package/dist/{anthropic-SrGtwsJu.d.mts → anthropic-BECQCNdF.d.mts} +0 -2
- package/dist/{anthropic-JsNA5KCu.mjs → anthropic-BQXQudmA.mjs} +0 -1
- package/dist/{anthropic-compaction-replay-8lJNKXOE.mjs → anthropic-compaction-replay-4Zx7-aCr.mjs} +14 -15
- package/dist/{anthropic-payload-policy-CiEuQS72.d.mts → anthropic-payload-policy-CSx7MoKH.d.mts} +2 -1
- package/dist/{api-registry-k3zTz0cV.d.mts → api-registry-DFxSnFqG.d.mts} +1 -1
- package/dist/{azure-openai-responses-mxIOtUnn.mjs → azure-openai-responses-Aa4mVcYG.mjs} +3 -3
- package/dist/diagnostics.mjs +1 -1
- package/dist/event-stream-BVVgDSdq.d.mts +1 -0
- package/dist/{event-stream-BP6AWT8j.d.mts → event-stream-D91-ohD_.d.mts} +1 -1
- package/dist/event-stream.d.mts +1 -1
- package/dist/{google-shared-B0Qr9OR7.mjs → google-shared-M1dl64nz.mjs} +12 -5
- package/dist/{google-vertex-Bhc3TjDl.mjs → google-vertex-DCJHM_a5.mjs} +3 -3
- package/dist/{google-C7h2QzDX.mjs → google-yDRnipeq.mjs} +3 -3
- package/dist/headers-B_e4-1J0.mjs +9 -0
- package/dist/{host-DTqNc7ad.mjs → host-DF_yxOsA.mjs} +40 -29
- package/dist/{host-vWgMMhiJ.d.mts → host-DJq_FGcz.d.mts} +6 -6
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +2 -2
- package/dist/internal/anthropic.d.mts +11 -5
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +5 -5
- package/dist/internal/openai.mjs +9 -8
- package/dist/internal/runtime.d.mts +4 -2
- package/dist/internal/runtime.mjs +4 -3
- package/dist/internal/shared.d.mts +17 -3
- package/dist/internal/shared.mjs +4 -4
- package/dist/{headers-DdOQtGuU.mjs → llm-request-activity-BjtkplhG.mjs} +1 -9
- package/dist/{mistral-CEWoQI_g.mjs → mistral-D6hRXI7A.mjs} +47 -33
- package/dist/{openai-chatgpt-responses-CrPmqERt.mjs → openai-chatgpt-responses-C339VIfT.mjs} +23 -15
- package/dist/{openai-completions-BPnt4Sml.mjs → openai-completions-D88orSJ9.mjs} +71 -35
- package/dist/{openai-completions-compat-Dt3dcawL.d.mts → openai-completions-compat-B0KTleXp.d.mts} +2 -2
- package/dist/{openai-responses-DhIKtOup.mjs → openai-responses-BXEcr-Tp.mjs} +4 -4
- package/dist/{openai-responses-contracts-XpZJxrRG.d.mts → openai-responses-contracts-CD75pQ0m.d.mts} +2 -2
- package/dist/{openai-responses-contracts-CyfIkQi5.mjs → openai-responses-contracts-DvILoqBk.mjs} +3 -9
- package/dist/{openai-responses-payload-policy-BDxV-W0c.mjs → openai-responses-payload-policy-BDo8CQsx.mjs} +4 -2
- package/dist/{openai-responses-payload-policy-BSs371VM.d.mts → openai-responses-payload-policy-CNGFT9zr.d.mts} +1 -0
- package/dist/{openai-responses-prompt-observer-internal-DgNTYnRY.mjs → openai-responses-prompt-observer-internal-BG-1AsBI.mjs} +2 -3
- package/dist/{openai-responses-shared-DXIt3iY5.mjs → openai-responses-shared-Cvt5MgEm.mjs} +81 -136
- package/dist/{openai-stop-reason-BkFkqqK0.mjs → openai-stop-reason-9OONKyAm.mjs} +47 -31
- package/dist/{openai-tool-projection-CY04OcvQ.mjs → openai-tool-projection-CHGLt03m.mjs} +94 -6
- package/dist/{provider-error-BUwEnjXq.mjs → provider-error-C8mBRJDl.mjs} +19 -24
- package/dist/provider-options-AvldWZt8.mjs +21 -0
- package/dist/{provider-options-B96RdNpH.d.mts → provider-options-Cc5ZQ6Aa.d.mts} +12 -2
- package/dist/provider-transcript-transform--gtf0ZbR.mjs +32 -0
- package/dist/provider-types.d.mts +5 -5
- package/dist/providers.d.mts +1 -1
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-rnPwX2pg.mjs → reasoning-tag-text-partitioner-5ygO2rZc.mjs} +3 -0
- package/dist/{sanitize-unicode-BYqrYtC_.mjs → sanitize-unicode-BP7HLLZn.mjs} +1 -1
- package/dist/simple-options-oqsXB6U3.mjs +450 -0
- package/dist/{tool-schema-json-projection-q5d7QX5c.mjs → tool-schema-json-projection-FEr-jOoZ.mjs} +16 -7
- package/dist/{transport-utils-DJqkxbhC.mjs → transport-utils-Bv0FHkd0.mjs} +1 -1
- package/dist/transports.d.mts +77 -44
- package/dist/transports.mjs +207 -167
- package/dist/{types-BHNrPS1l.d.mts → types-DTAP49HF.d.mts} +17 -2
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +1 -1
- package/dist/{validation-DT9SrFn3.d.mts → validation-DYNNrU9u.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +1 -1
- package/dist/provider-transcript-transform-ePx-Bbfr.mjs +0 -155
- package/dist/simple-options-D58D5Kvw.mjs +0 -117
package/dist/transports.mjs
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
|
-
import { d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, p as supportsClaudeAdaptiveThinking, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-
|
|
3
|
-
import { r as createAssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
2
|
+
import { d as resolveClaudeSonnet5ModelIdentity, g as supportsClaudeNativeXhighEffort, p as supportsClaudeAdaptiveThinking, u as resolveClaudeOpus5ModelIdentity } from "./anthropic-BQXQudmA.mjs";
|
|
4
3
|
import { n as normalizeLowercaseStringOrEmpty, t as hasNonEmptyString } from "./string-coerce-fsri9iCu.mjs";
|
|
5
|
-
import { r as calculateCost } from "./sanitize-unicode-
|
|
6
|
-
import { _ as
|
|
4
|
+
import { r as calculateCost } from "./sanitize-unicode-BP7HLLZn.mjs";
|
|
5
|
+
import { S as usesClaudeStreamingRefusalContract, _ as prepareClaudeNoPrefillRequestContext, a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, f as ANTHROPIC_CLAUDE_CODE_BILLING_SYSTEM_BLOCK, g as mapAnthropicStopReason, h as defaultsClaudeAdaptiveThinking, m as applyClaudeRequestContract, n as getAiTransportHost, p as ANTHROPIC_CLAUDE_CODE_VERSION, r as resolveAiTransportHeaderSentinels, s as extractToolResultBlockText, v as requiresClaudeAdaptiveThinking, x as usesClaudeFable5MessagesContract, y as resolveAnthropicThinkingEffort } from "./host-DF_yxOsA.mjs";
|
|
7
6
|
import { a as isRecord } from "./record-coerce-DdXsgUd_.mjs";
|
|
8
|
-
import { i as canonicalizeBase64,
|
|
9
|
-
import { n as toErrorObject, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
7
|
+
import { i as canonicalizeBase64, o as stableStringify } from "./provider-error-C8mBRJDl.mjs";
|
|
8
|
+
import { n as toErrorObject, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-BG-1AsBI.mjs";
|
|
10
9
|
import { r as asNonNegativeFiniteNumber } from "./number-coercion-H9qHik3g.mjs";
|
|
11
|
-
import { _ as isOpenAIGpt56Model,
|
|
10
|
+
import { _ as isOpenAIGpt56Model, d as OpenAIResponsesWebSocketSafeRetryError, g as isOpenAIGpt55Model, h as isOpenAIGpt54MiniModel, i as OPENAI_RESPONSES_APIS, l as OpenAIResponsesWebSocketPostDispatchError, p as parseOpenAIResponsesWebSocketServerError, r as OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS, t as AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS, u as OpenAIResponsesWebSocketPreDispatchError, v as normalizeOpenAIReasoningEffort, w as uniqueStrings, y as resolveOpenAIReasoningEffortForModel } from "./openai-responses-contracts-DvILoqBk.mjs";
|
|
12
11
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
13
12
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
14
|
-
import {
|
|
15
|
-
import { a as resolveProviderEndpoint, c as transformTransportMessages, i as resolveOpenAIStrictToolSetting, n as buildGuardedModelFetch, r as resolveModelRequestTimeoutMs, s as resolveProviderRequestPolicyConfig } from "./tool-schema-json-projection-
|
|
16
|
-
import { A as resolveAnthropicImageMediaType, C as readAnthropicFallbackBoundary, D as usesFoundryBearerAuth, E as omitFoundryBearerCredentialHeaders, F as resolveAnthropicPayloadPolicy, I as resolveAnthropicServerCompactionPlan, M as applyAnthropicEphemeralCacheControlMarkers, N as applyAnthropicPayloadPolicyToParams, O as createAnthropicInlineImageBudget, P as resolveAnthropicEphemeralCacheControl, S as applyAnthropicFallbackBoundary, T as applyAnthropicRefusal, _ as ANTHROPIC_OMITTED_REASONING_TEXT, a as applyAnthropicMessageDeltaUsage, b as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, d as normalizeAnthropicToolCallId, f as normalizeAnthropicToolChoice, g as toClaudeCodeToolName, h as resolveOriginalAnthropicToolName, i as suppressAnthropicCompaction, j as applyAnthropicCacheControlToMessages, k as normalizeAnthropicInlineContent, m as reconcileAnthropicToolChoice, n as createCompactionCapture, o as applyAnthropicMessageStartUsage, p as projectAnthropicTools, r as isAnthropicReplayRejection, t as buildAnthropicReplayPlan, v as findActiveAnthropicToolTurnAssistantIndex, w as resolveAnthropicFallbackServingModelCost, y as ANTHROPIC_SERVER_SIDE_FALLBACKS } from "./anthropic-compaction-replay-
|
|
17
|
-
import { a as createOpenAICompletionsToolCallDeltaNormalizer, c as resolveOpenAICompletionsCompat, d as clearPendingCommentaryText, f as rememberPendingCommentaryTags, i as hasToolCallHistory, l as resolveOpenAICompletionsResponseFormat, n as resolveOpenAIReasoningEffortMap, o as finalizeOpenAICompletionsToolCalls, p as
|
|
13
|
+
import { C as withProviderResponseHook, E as quoteUnsafeIntegerLiterals, P as sortPromptCacheToolsByName, S as withProviderAcceptanceObserver, T as parseJsonPreservingUnsafeIntegers, _ as notifyProviderStreamOpened, a as assignTransportErrorDetails, b as sanitizeTransportPayloadText, c as createEmptyTransportUsage, d as finalizeTerminalToolCallArguments, f as finalizeTransportStream, g as notifyProviderHttpResponse, h as notifyProviderHttpMetadata, j as stripSystemPromptCacheBoundary, l as createWritableTransportEventStream, m as mergeTransportMetadata, o as coerceTransportToolCallArguments, p as mergeTransportHeaders, s as copyProviderAcceptanceObserver, t as adjustMaxTokensForThinking, u as failTransportStream, v as parseTerminalToolCallArguments, w as parseJsonObjectPreservingUnsafeIntegers, x as transportAbortError, y as sanitizeNonEmptyTransportPayloadText } from "./simple-options-oqsXB6U3.mjs";
|
|
14
|
+
import { a as resolveProviderEndpoint, c as transformTransportMessages, i as resolveOpenAIStrictToolSetting, n as buildGuardedModelFetch, r as resolveModelRequestTimeoutMs, s as resolveProviderRequestPolicyConfig } from "./tool-schema-json-projection-FEr-jOoZ.mjs";
|
|
15
|
+
import { A as resolveAnthropicImageMediaType, C as readAnthropicFallbackBoundary, D as usesFoundryBearerAuth, E as omitFoundryBearerCredentialHeaders, F as resolveAnthropicPayloadPolicy, I as resolveAnthropicServerCompactionPlan, M as applyAnthropicEphemeralCacheControlMarkers, N as applyAnthropicPayloadPolicyToParams, O as createAnthropicInlineImageBudget, P as resolveAnthropicEphemeralCacheControl, S as applyAnthropicFallbackBoundary, T as applyAnthropicRefusal, _ as ANTHROPIC_OMITTED_REASONING_TEXT, a as applyAnthropicMessageDeltaUsage, b as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, d as normalizeAnthropicToolCallId, f as normalizeAnthropicToolChoice, g as toClaudeCodeToolName, h as resolveOriginalAnthropicToolName, i as suppressAnthropicCompaction, j as applyAnthropicCacheControlToMessages, k as normalizeAnthropicInlineContent, m as reconcileAnthropicToolChoice, n as createCompactionCapture, o as applyAnthropicMessageStartUsage, p as projectAnthropicTools, r as isAnthropicReplayRejection, t as buildAnthropicReplayPlan, v as findActiveAnthropicToolTurnAssistantIndex, w as resolveAnthropicFallbackServingModelCost, y as ANTHROPIC_SERVER_SIDE_FALLBACKS } from "./anthropic-compaction-replay-4Zx7-aCr.mjs";
|
|
16
|
+
import { a as createOpenAICompletionsToolCallDeltaNormalizer, c as resolveOpenAICompletionsCompat, d as clearPendingCommentaryText, f as rememberPendingCommentaryTags, h as tagUnresolvedTextAsCommentary, i as hasToolCallHistory, l as resolveOpenAICompletionsResponseFormat, m as tagPendingCommentaryText, n as resolveOpenAIReasoningEffortMap, o as finalizeOpenAICompletionsToolCalls, p as tagInterruptedTextPhases, r as convertMessages, s as detectOpenAICompletionsCompat, t as mapOpenAIStopReason, u as shouldOmitOllamaCompatResponseFormat } from "./openai-stop-reason-9OONKyAm.mjs";
|
|
18
17
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
19
18
|
import { n as parseStreamingJson } from "./json-parse-CDnesDM_.mjs";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { a as createWritableTransportEventStream, c as mergeTransportHeaders, d as sanitizeTransportPayloadText, f as transportAbortError, i as createEmptyTransportUsage, l as mergeTransportMetadata, n as assignTransportErrorDetails, o as failTransportStream, p as withProviderResponseHook, r as coerceTransportToolCallArguments, s as finalizeTransportStream, u as sanitizeNonEmptyTransportPayloadText } from "./provider-transcript-transform-ePx-Bbfr.mjs";
|
|
23
|
-
import { a as isGoogleGemini3FlashModel, c as readResponseTextSnippet, d as resolveModelHeaderSentinels$1, f as resolveSecretSentinel, i as isCodeModeModelVisibleToolName, l as redactIdentifier, m as supportsModelTools, n as createAbortError$1, o as isGoogleGemini3ProModel, p as sha256Hex, r as estimateStringChars, s as parseRetryAfterSeconds, t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-DJqkxbhC.mjs";
|
|
19
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
20
|
+
import { a as isGoogleGemini3FlashModel, c as readResponseTextSnippet, d as resolveModelHeaderSentinels$1, f as resolveSecretSentinel, i as isCodeModeModelVisibleToolName, l as redactIdentifier, m as supportsModelTools, n as createAbortError$1, o as isGoogleGemini3ProModel, p as sha256Hex, r as estimateStringChars, s as parseRetryAfterSeconds, t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-Bv0FHkd0.mjs";
|
|
24
21
|
import { t as googleFlashSupportsMinimalThinking } from "./google-thinking-level-C-V3tecN.mjs";
|
|
25
|
-
import {
|
|
22
|
+
import { B as buildResponsesInputMessage, C as summarizeResponsesTools, G as suppressOpenAIResponsesCompaction, H as createOpenAIResponsesAssistantOutput, I as createResponsesStreamWithEncryptedContentRetry, K as resolveReplayableResponsesMessageId, L as isInvalidEncryptedContentError, R as resolveAzureOpenAIApiVersion, S as summarizeResponsesPayload, U as buildOpenAIResponsesReasoningReplayMetadata, V as convertResponsesMessages, W as captureOpenAIResponsesCompaction, Y as normalizeOpenAIStrictToolParameters, Z as resolveOpenAIProjectedToolsStrictToolFlag, _ as safeDebugValue, b as summarizeOpenAITransportError, c as processResponsesStream, dt as resolveModelPayloadDebugMode, f as observeResponsesStream, ft as resolveModelSseDebugMode, g as normalizeResponsesFailedEvent, h as logResponsesFailedNoDetails, m as buildResponsesFailedNoDetailsObservation, n as applyResponsesServiceTierPricing, p as ResponsesStreamFailure, q as findOpenAIStrictToolProjectionDiagnostics, ut as emitModelTransportDebug, v as stringifyRedactedEvent, x as summarizeResponsesFailedNoDetailsObservation, y as stringifyRedactedPayload, z as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-Cvt5MgEm.mjs";
|
|
23
|
+
import { t as codeModeToolSurfaceObserver } from "./provider-options-AvldWZt8.mjs";
|
|
24
|
+
import { a as createModelStreamCooperativeScheduler, c as isOpenAICompletionsThinkingEnabled, d as parseOpenAICompletionsUsage, f as readOpenAICompletionsContentDeltas, h as throwIfModelStreamAborted, i as GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, l as log, m as resolvePromptCacheKey, n as reconcileOpenAICompletionsToolChoice, o as createOpenAIProviderAcceptanceHook, p as readOpenAICompletionsReasoningBatch, r as reconcileOpenAIResponsesToolChoice, s as createOpenAIResponseHook, t as projectOpenAITools, u as measureUtf8AppendBytes } from "./openai-tool-projection-CHGLt03m.mjs";
|
|
26
25
|
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-MK28puvq.mjs";
|
|
27
|
-
import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-
|
|
28
|
-
import { i as resolveOpenAIResponsesServerCompactionPlan, n as resolveOpenAIResponsesCompactEndpointPlan, r as resolveOpenAIResponsesPayloadPolicy, t as applyOpenAIResponsesPayloadPolicy } from "./openai-responses-payload-policy-
|
|
26
|
+
import { t as createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner-5ygO2rZc.mjs";
|
|
27
|
+
import { i as resolveOpenAIResponsesServerCompactionPlan, n as resolveOpenAIResponsesCompactEndpointPlan, r as resolveOpenAIResponsesPayloadPolicy, t as applyOpenAIResponsesPayloadPolicy } from "./openai-responses-payload-policy-BDo8CQsx.mjs";
|
|
29
28
|
import { i as resolveAzureDeploymentNameFromMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "./azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
30
29
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
31
30
|
import { randomUUID } from "node:crypto";
|
|
@@ -67,7 +66,7 @@ function isAnthropicOAuthToken(apiKey) {
|
|
|
67
66
|
}
|
|
68
67
|
function isDirectAnthropicModel(model) {
|
|
69
68
|
if (normalizeLowercaseStringOrEmpty(model.provider) !== "anthropic") return false;
|
|
70
|
-
const endpointClass = resolveProviderEndpoint(model
|
|
69
|
+
const endpointClass = resolveProviderEndpoint(model).endpointClass;
|
|
71
70
|
return endpointClass === "default" || endpointClass === "anthropic-public";
|
|
72
71
|
}
|
|
73
72
|
function isKimiAnthropicProvider(provider) {
|
|
@@ -82,7 +81,7 @@ function useAnthropicServerSideFallback(model) {
|
|
|
82
81
|
return (usesClaudeFable5MessagesContract(model) || resolveClaudeOpus5ModelIdentity(model) !== void 0) && isDirectAnthropicModel(model);
|
|
83
82
|
}
|
|
84
83
|
function supportsReasoningContentReplay(model) {
|
|
85
|
-
return resolveProviderEndpoint(model
|
|
84
|
+
return resolveProviderEndpoint(model).endpointClass === "xiaomi-native";
|
|
86
85
|
}
|
|
87
86
|
function buildAnthropicBetaHeader(model, betaFeatures, params) {
|
|
88
87
|
if (!isDirectAnthropicModel(model)) return;
|
|
@@ -304,7 +303,7 @@ function convertAnthropicTools(tools, isOAuthToken) {
|
|
|
304
303
|
};
|
|
305
304
|
}
|
|
306
305
|
function parseAnthropicToolCallArguments(inputJson) {
|
|
307
|
-
return parseJsonObjectPreservingUnsafeIntegers(inputJson) ?? parseStreamingJson(inputJson);
|
|
306
|
+
return coerceTransportToolCallArguments(parseJsonObjectPreservingUnsafeIntegers(inputJson) ?? parseStreamingJson(inputJson));
|
|
308
307
|
}
|
|
309
308
|
const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com";
|
|
310
309
|
/** Resolve the effective Anthropic API base URL from model or environment. */
|
|
@@ -407,7 +406,7 @@ async function* parseAnthropicSseBody(body, signal) {
|
|
|
407
406
|
}
|
|
408
407
|
function createAnthropicMessagesClient(params) {
|
|
409
408
|
const url = resolveAnthropicMessagesUrl(params.baseURL);
|
|
410
|
-
return { messages: { async
|
|
409
|
+
return { messages: { async stream(body, options) {
|
|
411
410
|
const headers = mergeTransportHeaders({
|
|
412
411
|
"content-type": "application/json",
|
|
413
412
|
"anthropic-version": "2023-06-01",
|
|
@@ -420,12 +419,10 @@ function createAnthropicMessagesClient(params) {
|
|
|
420
419
|
body: JSON.stringify(body),
|
|
421
420
|
signal: options?.signal
|
|
422
421
|
});
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
if (!response.body) return;
|
|
428
|
-
yield* parseAnthropicSseBody(response.body, options?.signal);
|
|
422
|
+
return {
|
|
423
|
+
response,
|
|
424
|
+
stream: response.body ? parseAnthropicSseBody(response.body, options?.signal) : []
|
|
425
|
+
};
|
|
429
426
|
} } };
|
|
430
427
|
}
|
|
431
428
|
function formatAnthropicMessagesHttpError(response, detail) {
|
|
@@ -536,7 +533,7 @@ async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
|
536
533
|
baseUrl: model.baseUrl,
|
|
537
534
|
cacheRetention: options?.cacheRetention,
|
|
538
535
|
enableCacheControl: true
|
|
539
|
-
});
|
|
536
|
+
}, model);
|
|
540
537
|
const cacheBreakpointOptOutMessageIndexes = /* @__PURE__ */ new Set();
|
|
541
538
|
const replayPlan = buildAnthropicReplayPlan(context.messages, model, {
|
|
542
539
|
enabled: !isOAuthToken && options?.anthropicServerCompaction === true,
|
|
@@ -620,7 +617,7 @@ function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
|
620
617
|
const reasoningModelMaxTokens = resolvePositiveAnthropicTokenLimit(model.maxTokens) ?? baseMaxTokens;
|
|
621
618
|
const mandatoryAdaptiveThinking = requiresClaudeAdaptiveThinking(model);
|
|
622
619
|
const reasoning = options?.reasoning === "off" && mandatoryAdaptiveThinking ? "low" : options?.reasoning;
|
|
623
|
-
const resolved = {
|
|
620
|
+
const resolved = copyProviderAcceptanceObserver(options, {
|
|
624
621
|
temperature: options?.temperature,
|
|
625
622
|
stop: options?.stop,
|
|
626
623
|
maxTokens: baseMaxTokens,
|
|
@@ -630,6 +627,7 @@ function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
|
630
627
|
sessionId: options?.sessionId,
|
|
631
628
|
headers: options?.headers,
|
|
632
629
|
onPayload: options?.onPayload,
|
|
630
|
+
onResponse: options?.onResponse,
|
|
633
631
|
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
634
632
|
metadata: options?.metadata,
|
|
635
633
|
interleavedThinking: options?.interleavedThinking,
|
|
@@ -638,7 +636,7 @@ function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
|
638
636
|
reasoning,
|
|
639
637
|
...options?.anthropicServerCompaction === true ? { anthropicServerCompaction: true } : {},
|
|
640
638
|
...options?.authProfileId ? { authProfileId: options.authProfileId } : {}
|
|
641
|
-
};
|
|
639
|
+
});
|
|
642
640
|
if (reasoning === "off") {
|
|
643
641
|
resolved.thinkingEnabled = false;
|
|
644
642
|
return resolved;
|
|
@@ -700,12 +698,22 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
700
698
|
const nextParams = await transportOptions.onPayload?.(params, model);
|
|
701
699
|
if (nextParams !== void 0) params = nextParams;
|
|
702
700
|
applyClaudeRequestContract(params, model);
|
|
703
|
-
const anthropicStream = client.messages.stream({
|
|
701
|
+
const { response, stream: anthropicStream } = await client.messages.stream({
|
|
704
702
|
...params,
|
|
705
703
|
stream: true
|
|
706
704
|
}, transportOptions.signal ? { signal: transportOptions.signal } : void 0);
|
|
705
|
+
await notifyProviderHttpResponse({
|
|
706
|
+
options: transportOptions,
|
|
707
|
+
response,
|
|
708
|
+
model
|
|
709
|
+
});
|
|
710
|
+
if (!response.ok) {
|
|
711
|
+
const detail = await readAnthropicMessagesErrorBodySnippet(response);
|
|
712
|
+
throw new Error(formatAnthropicMessagesHttpError(response, detail));
|
|
713
|
+
}
|
|
707
714
|
const blocks = output.content;
|
|
708
715
|
const blockIndexes = /* @__PURE__ */ new Map();
|
|
716
|
+
const sealedToolCalls = [];
|
|
709
717
|
const compactionCapture = createCompactionCapture(output, model, transportOptions);
|
|
710
718
|
const pendingThinkingSignatures = /* @__PURE__ */ new Map();
|
|
711
719
|
const allowReasoningContentReplay = supportsReasoningContentReplay(model);
|
|
@@ -740,6 +748,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
740
748
|
partial: output
|
|
741
749
|
});
|
|
742
750
|
}
|
|
751
|
+
if (contentIndex === void 0) return false;
|
|
743
752
|
block.thinking += text;
|
|
744
753
|
block.thinkingSignature = "reasoning_content";
|
|
745
754
|
eventSink.push({
|
|
@@ -771,6 +780,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
771
780
|
partial: output
|
|
772
781
|
});
|
|
773
782
|
}
|
|
783
|
+
if (contentIndex === void 0) return false;
|
|
774
784
|
block.text += text;
|
|
775
785
|
eventSink.push({
|
|
776
786
|
type: "text_delta",
|
|
@@ -833,6 +843,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
833
843
|
const fallbackBoundary = refusalBuffer ? readAnthropicFallbackBoundary(contentBlock) : null;
|
|
834
844
|
if (fallbackBoundary) {
|
|
835
845
|
refusalBuffer?.discard();
|
|
846
|
+
sealedToolCalls.length = 0;
|
|
836
847
|
pendingTextEnds.length = 0;
|
|
837
848
|
blockIndexes.clear();
|
|
838
849
|
pendingThinkingSignatures.clear();
|
|
@@ -975,7 +986,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
975
986
|
let appendedContent = false;
|
|
976
987
|
if (!hasNativeAnthropicDelta && typeof delta?.content === "string" && delta.content.length > 0) {
|
|
977
988
|
const text = sanitizeTransportPayloadText(delta.content);
|
|
978
|
-
if (text.length > 0) if (block?.type === "text") {
|
|
989
|
+
if (text.length > 0) if (block?.type === "text" && index !== void 0) {
|
|
979
990
|
block.text += text;
|
|
980
991
|
eventSink.push({
|
|
981
992
|
type: "text_delta",
|
|
@@ -1003,6 +1014,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
1003
1014
|
partial: output
|
|
1004
1015
|
});
|
|
1005
1016
|
}
|
|
1017
|
+
if (index === void 0) continue;
|
|
1006
1018
|
if (block?.type === "text" && delta?.type === "text_delta" && typeof delta.text === "string") {
|
|
1007
1019
|
block.text += delta.text;
|
|
1008
1020
|
eventSink.push({
|
|
@@ -1080,12 +1092,9 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
1080
1092
|
continue;
|
|
1081
1093
|
}
|
|
1082
1094
|
if (block.type === "toolCall") {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
contentIndex: index,
|
|
1087
|
-
toolCall: block,
|
|
1088
|
-
partial: output
|
|
1095
|
+
sealedToolCalls.push({
|
|
1096
|
+
block,
|
|
1097
|
+
contentIndex: index
|
|
1089
1098
|
});
|
|
1090
1099
|
finishReasoningContentSidecars(event.index);
|
|
1091
1100
|
}
|
|
@@ -1105,6 +1114,17 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
1105
1114
|
if (isDirectAnthropicModel(model) && !sawMessageStop) throw new Error("Anthropic stream ended before message_stop");
|
|
1106
1115
|
if (transportOptions.signal?.aborted) throw transportAbortError(transportOptions.signal);
|
|
1107
1116
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
1117
|
+
if ([...blockIndexes.values()].some((index) => blocks[index]?.type === "toolCall")) throw new Error("Provider completed stream with an incomplete tool call");
|
|
1118
|
+
finalizeTerminalToolCallArguments(sealedToolCalls.map(({ block }) => block), (block) => block.partialJson && block.partialJson.length > 0 ? block.partialJson : block.arguments);
|
|
1119
|
+
for (const sealed of sealedToolCalls) {
|
|
1120
|
+
delete sealed.block.partialJson;
|
|
1121
|
+
eventSink.push({
|
|
1122
|
+
type: "toolcall_end",
|
|
1123
|
+
contentIndex: sealed.contentIndex,
|
|
1124
|
+
toolCall: sealed.block,
|
|
1125
|
+
partial: output
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1108
1128
|
refusalBuffer?.flush();
|
|
1109
1129
|
if (output.stopReason === "toolUse" || output.content.some((block) => block.type === "toolCall")) tagPendingCommentaryText(output.content);
|
|
1110
1130
|
flushPendingTextEnds();
|
|
@@ -1116,7 +1136,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
1116
1136
|
if (refusalBuffer) {
|
|
1117
1137
|
refusalBuffer.discard();
|
|
1118
1138
|
output.content = [];
|
|
1119
|
-
}
|
|
1139
|
+
} else output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
1120
1140
|
if (usedCompactionReplay && isAnthropicReplayRejection(error)) suppressAnthropicCompaction(output, model, options);
|
|
1121
1141
|
failTransportStream({
|
|
1122
1142
|
stream,
|
|
@@ -1555,10 +1575,33 @@ function readCodeModePayloadToolIdentity(tool, visibleToolNames, allowedHostedTo
|
|
|
1555
1575
|
const name = readCodeModePayloadToolName(tool);
|
|
1556
1576
|
return typeof name === "string" && isCodeModeModelVisibleToolName(name, visibleToolNames) ? `client:${name}` : void 0;
|
|
1557
1577
|
}
|
|
1558
|
-
function
|
|
1578
|
+
function readCodeModePayloadToolIdentities(payload) {
|
|
1579
|
+
if (!isRecord(payload)) return [];
|
|
1580
|
+
const tools = readToolPayloadField(payload, "tools");
|
|
1581
|
+
if (!Array.isArray(tools)) return [];
|
|
1582
|
+
return tools.flatMap((tool) => {
|
|
1583
|
+
if (!isRecord(tool)) return [];
|
|
1584
|
+
const identities = [];
|
|
1585
|
+
const name = readCodeModePayloadToolName(tool);
|
|
1586
|
+
if (name) identities.push(`client:${name}`);
|
|
1587
|
+
for (const key of ["functionDeclarations", "function_declarations"]) {
|
|
1588
|
+
const declarations = readToolPayloadField(tool, key);
|
|
1589
|
+
if (!Array.isArray(declarations)) continue;
|
|
1590
|
+
for (const declaration of declarations) {
|
|
1591
|
+
const declarationName = readCodeModePayloadToolName(declaration);
|
|
1592
|
+
if (declarationName) identities.push(`client:${declarationName}`);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
const type = readToolPayloadField(tool, "type");
|
|
1596
|
+
if (typeof type === "string" && type !== "function") identities.push(`hosted:${type}`);
|
|
1597
|
+
return identities;
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
function filterCodeModePayloadTools(payload, visibleToolNames, allowedHostedToolTypes, observer) {
|
|
1559
1601
|
if (!isRecord(payload)) return;
|
|
1560
1602
|
const tools = readToolPayloadField(payload, "tools");
|
|
1561
1603
|
if (!Array.isArray(tools)) return;
|
|
1604
|
+
const beforeToolIdentities = observer ? readCodeModePayloadToolIdentities(payload) : void 0;
|
|
1562
1605
|
payload.tools = tools.flatMap((tool) => {
|
|
1563
1606
|
const identity = readCodeModePayloadToolIdentity(tool, visibleToolNames, allowedHostedToolTypes);
|
|
1564
1607
|
if (identity) return [tool];
|
|
@@ -1576,15 +1619,24 @@ function filterCodeModePayloadTools(payload, visibleToolNames, allowedHostedTool
|
|
|
1576
1619
|
}
|
|
1577
1620
|
return Object.keys(filteredGroups).length > 0 ? [filteredGroups] : [];
|
|
1578
1621
|
});
|
|
1622
|
+
if (beforeToolIdentities) observer?.({
|
|
1623
|
+
beforeToolIdentities,
|
|
1624
|
+
afterToolIdentities: readCodeModePayloadToolIdentities(payload)
|
|
1625
|
+
});
|
|
1579
1626
|
}
|
|
1580
1627
|
function resolveCodeModeResponsesVisibleToolNames(context) {
|
|
1581
1628
|
return new Set((context.tools ?? []).map(readCodeModePayloadToolName).filter((name) => typeof name === "string"));
|
|
1582
1629
|
}
|
|
1583
|
-
function enforceCodeModeResponsesToolSurface(payload, visibleToolNames, allowedHostedToolTypes) {
|
|
1630
|
+
function enforceCodeModeResponsesToolSurface(payload, visibleToolNames, allowedHostedToolTypes, observer) {
|
|
1584
1631
|
if (!isRecord(payload)) return;
|
|
1585
1632
|
const tools = readToolPayloadField(payload, "tools");
|
|
1586
1633
|
if (!Array.isArray(tools)) return;
|
|
1634
|
+
const beforeToolIdentities = observer ? readCodeModePayloadToolIdentities(payload) : void 0;
|
|
1587
1635
|
payload.tools = tools.filter((tool) => Boolean(readCodeModePayloadToolIdentity(tool, visibleToolNames, allowedHostedToolTypes)));
|
|
1636
|
+
if (beforeToolIdentities) observer?.({
|
|
1637
|
+
beforeToolIdentities,
|
|
1638
|
+
afterToolIdentities: readCodeModePayloadToolIdentities(payload)
|
|
1639
|
+
});
|
|
1588
1640
|
}
|
|
1589
1641
|
function assertCodeModeResponsesToolSurface(payload, visibleToolNames, allowedHostedToolTypes) {
|
|
1590
1642
|
const tools = isRecord(payload) ? readToolPayloadField(payload, "tools") : void 0;
|
|
@@ -1668,7 +1720,7 @@ function buildOpenAIClientHeaders(model, context, optionHeaders, turnHeaders, se
|
|
|
1668
1720
|
...optionHeaders,
|
|
1669
1721
|
...turnHeaders
|
|
1670
1722
|
};
|
|
1671
|
-
const resolvedHeaders = resolveProviderRequestPolicyConfig({
|
|
1723
|
+
const resolvedHeaders = resolveProviderRequestPolicyConfig(model, {
|
|
1672
1724
|
provider: model.provider,
|
|
1673
1725
|
api: model.api,
|
|
1674
1726
|
baseUrl: model.baseUrl,
|
|
@@ -1716,7 +1768,7 @@ function getCompat(model) {
|
|
|
1716
1768
|
//#region packages/ai/src/transports/openai-completions-params.ts
|
|
1717
1769
|
function isKnownOpenAICompletionsEndpoint(model) {
|
|
1718
1770
|
if (!model.baseUrl.trim()) return true;
|
|
1719
|
-
const endpointClass = resolveProviderEndpoint(model
|
|
1771
|
+
const endpointClass = resolveProviderEndpoint(model).endpointClass;
|
|
1720
1772
|
if (endpointClass === "openai-public" || endpointClass === "azure-openai") return true;
|
|
1721
1773
|
try {
|
|
1722
1774
|
return isAzureOpenAICompatibleHost(new URL(model.baseUrl).hostname.toLowerCase());
|
|
@@ -2244,11 +2296,15 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2244
2296
|
const MAX_POST_TOOL_CALL_BUFFER_BYTES = 256e3;
|
|
2245
2297
|
const emitReasoning = options?.emitReasoning ?? true;
|
|
2246
2298
|
const compat = getCompat(model);
|
|
2299
|
+
const visibleReasoningDetailTypes = new Set(compat.visibleReasoningDetailTypes);
|
|
2247
2300
|
const shouldFilterDeepSeekDsmlText = compat.thinkingFormat === "deepseek";
|
|
2248
2301
|
const deepSeekTextFilter = shouldFilterDeepSeekDsmlText ? createDeepSeekTextFilter() : null;
|
|
2249
2302
|
const deepSeekToolCallRecoverer = shouldFilterDeepSeekDsmlText ? createDsmlRecoverer() : null;
|
|
2250
2303
|
const reasoningTagTextPartitioner = createReasoningTagTextPartitioner();
|
|
2251
2304
|
let currentBlock = null;
|
|
2305
|
+
let currentTextSource;
|
|
2306
|
+
let pendingInterruptedTextBlock = null;
|
|
2307
|
+
let confirmedInterruptedTextBlock = null;
|
|
2252
2308
|
let pendingPostToolCallDeltas = [];
|
|
2253
2309
|
let pendingPostToolCallBytes = 0;
|
|
2254
2310
|
let isFlushingPendingPostToolCallDeltas = false;
|
|
@@ -2256,6 +2312,7 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2256
2312
|
const toolCallBlocksById = /* @__PURE__ */ new Map();
|
|
2257
2313
|
const provisionalCommentaryTags = /* @__PURE__ */ new Map();
|
|
2258
2314
|
const toolCallBlockIndices = /* @__PURE__ */ new WeakMap();
|
|
2315
|
+
let explicitVisibleTextBlocks;
|
|
2259
2316
|
const normalizeToolCallDeltas = createOpenAICompletionsToolCallDeltaNormalizer();
|
|
2260
2317
|
let sawStopFinishReason = false;
|
|
2261
2318
|
let sawNativeToolCallDelta = false;
|
|
@@ -2271,7 +2328,7 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2271
2328
|
if (pendingPostToolCallBytes + nextBytes > MAX_POST_TOOL_CALL_BUFFER_BYTES) throw new Error("Exceeded post-tool-call delta buffer limit");
|
|
2272
2329
|
pendingPostToolCallBytes += nextBytes;
|
|
2273
2330
|
const previous = pendingPostToolCallDeltas[pendingPostToolCallDeltas.length - 1];
|
|
2274
|
-
if (!previous || previous.kind !== next.kind) {
|
|
2331
|
+
if (!previous || previous.kind !== next.kind || previous.kind === "text" && next.kind === "text" && previous.source !== next.source) {
|
|
2275
2332
|
pendingPostToolCallDeltas.push(next);
|
|
2276
2333
|
return;
|
|
2277
2334
|
}
|
|
@@ -2307,12 +2364,15 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2307
2364
|
partial: output
|
|
2308
2365
|
});
|
|
2309
2366
|
};
|
|
2310
|
-
const appendTextDeltaInternal = (text) => {
|
|
2367
|
+
const appendTextDeltaInternal = (text, source) => {
|
|
2368
|
+
if (currentBlock?.type === "text" && currentTextSource !== source) currentBlock = null;
|
|
2311
2369
|
if (!currentBlock || currentBlock.type !== "text") {
|
|
2312
2370
|
currentBlock = {
|
|
2313
2371
|
type: "text",
|
|
2314
2372
|
text: ""
|
|
2315
2373
|
};
|
|
2374
|
+
currentTextSource = source;
|
|
2375
|
+
if (source === "reasoning_detail") (explicitVisibleTextBlocks ??= /* @__PURE__ */ new Set()).add(currentBlock);
|
|
2316
2376
|
output.content.push(currentBlock);
|
|
2317
2377
|
pushStreamEvent({
|
|
2318
2378
|
type: "text_start",
|
|
@@ -2321,6 +2381,10 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2321
2381
|
});
|
|
2322
2382
|
}
|
|
2323
2383
|
currentBlock.text += text;
|
|
2384
|
+
if (pendingInterruptedTextBlock && text.trim()) {
|
|
2385
|
+
confirmedInterruptedTextBlock = pendingInterruptedTextBlock;
|
|
2386
|
+
pendingInterruptedTextBlock = null;
|
|
2387
|
+
}
|
|
2324
2388
|
pushStreamEvent({
|
|
2325
2389
|
type: "text_delta",
|
|
2326
2390
|
contentIndex: blockIndex(),
|
|
@@ -2333,7 +2397,7 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2333
2397
|
const bufferedDeltas = pendingPostToolCallDeltas;
|
|
2334
2398
|
pendingPostToolCallDeltas = [];
|
|
2335
2399
|
pendingPostToolCallBytes = 0;
|
|
2336
|
-
for (const delta of bufferedDeltas) if (delta.kind === "text") appendTextDeltaInternal(delta.text);
|
|
2400
|
+
for (const delta of bufferedDeltas) if (delta.kind === "text") appendTextDeltaInternal(delta.text, delta.source);
|
|
2337
2401
|
else if (emitReasoning) appendThinkingDeltaInternal(delta);
|
|
2338
2402
|
isFlushingPendingPostToolCallDeltas = false;
|
|
2339
2403
|
};
|
|
@@ -2341,9 +2405,9 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2341
2405
|
flushPendingPostToolCallDeltas();
|
|
2342
2406
|
appendThinkingDeltaInternal(reasoningDelta);
|
|
2343
2407
|
};
|
|
2344
|
-
const appendTextDelta = (text) => {
|
|
2408
|
+
const appendTextDelta = (text, source) => {
|
|
2345
2409
|
flushPendingPostToolCallDeltas();
|
|
2346
|
-
appendTextDeltaInternal(text);
|
|
2410
|
+
appendTextDeltaInternal(text, source);
|
|
2347
2411
|
};
|
|
2348
2412
|
const appendVisibleTextDelta = (text) => {
|
|
2349
2413
|
if (!text) return;
|
|
@@ -2353,6 +2417,17 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2353
2417
|
});
|
|
2354
2418
|
else appendTextDelta(text);
|
|
2355
2419
|
};
|
|
2420
|
+
const appendReasoningDeltas = (reasoningDeltas) => {
|
|
2421
|
+
for (const reasoningDelta of reasoningDeltas) {
|
|
2422
|
+
if (reasoningDelta.kind === "thinking" && !emitReasoning) continue;
|
|
2423
|
+
if (currentBlock?.type === "toolCall") {
|
|
2424
|
+
queuePostToolCallDelta({ ...reasoningDelta });
|
|
2425
|
+
continue;
|
|
2426
|
+
}
|
|
2427
|
+
if (reasoningDelta.kind === "text") appendTextDelta(reasoningDelta.text, reasoningDelta.source);
|
|
2428
|
+
else if (emitReasoning) appendThinkingDelta(reasoningDelta);
|
|
2429
|
+
}
|
|
2430
|
+
};
|
|
2356
2431
|
const appendRecoveredToolCall = (toolCall) => {
|
|
2357
2432
|
if (currentBlock?.type === "toolCall") {
|
|
2358
2433
|
currentBlock = null;
|
|
@@ -2431,9 +2506,25 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2431
2506
|
if (latestBlock?.type === "text" || latestBlock?.type === "toolCall") return;
|
|
2432
2507
|
appendThinkingDelta({ text: "" });
|
|
2433
2508
|
};
|
|
2434
|
-
const
|
|
2509
|
+
const flushReasoningTagTextPartitioner = () => {
|
|
2435
2510
|
for (const delta of reasoningTagTextPartitioner.flush()) appendPartitionedVisibleDelta(delta);
|
|
2436
2511
|
};
|
|
2512
|
+
const sealTextBeforeReasoning = () => {
|
|
2513
|
+
if (currentBlock?.type !== "text" && !reasoningTagTextPartitioner.hasPending()) return;
|
|
2514
|
+
flushReasoningTagTextPartitioner();
|
|
2515
|
+
if (currentBlock?.type !== "text") return;
|
|
2516
|
+
if (currentTextSource !== "reasoning_detail" && currentBlock.text.trim()) pendingInterruptedTextBlock = currentBlock;
|
|
2517
|
+
currentBlock = null;
|
|
2518
|
+
currentTextSource = void 0;
|
|
2519
|
+
};
|
|
2520
|
+
const beginReasoning = (hasFollowingVisibleText, forceStrict = false) => {
|
|
2521
|
+
if (!output.openclawDelivery?.textPhaseRequiresTerminal) output.openclawDelivery = {
|
|
2522
|
+
...output.openclawDelivery,
|
|
2523
|
+
textPhaseRequiresTerminal: true
|
|
2524
|
+
};
|
|
2525
|
+
if (forceStrict || reasoningTagTextPartitioner.hasPending()) reasoningTagTextPartitioner.markStrict();
|
|
2526
|
+
if (!hasFollowingVisibleText || !reasoningTagTextPartitioner.hasPendingSyntax()) sealTextBeforeReasoning();
|
|
2527
|
+
};
|
|
2437
2528
|
const cooperativeScheduler = createModelStreamCooperativeScheduler(options?.signal);
|
|
2438
2529
|
const guardedStream = withFirstStreamEventTimeout(responseStream, {
|
|
2439
2530
|
provider: model.provider,
|
|
@@ -2485,34 +2576,28 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2485
2576
|
}
|
|
2486
2577
|
for (const normalizedDelta of normalizeToolCallDeltas(rawChoiceDelta, choice.finish_reason)) {
|
|
2487
2578
|
const choiceDelta = normalizedDelta.delta;
|
|
2488
|
-
const
|
|
2489
|
-
const
|
|
2490
|
-
|
|
2491
|
-
const contentDeltas = readOpenAICompletionsContentDeltas(choiceDelta.content, choiceDelta.refusal,
|
|
2492
|
-
const
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
else if (emitReasoning) appendThinkingDelta(reasoningDelta);
|
|
2501
|
-
}
|
|
2502
|
-
};
|
|
2503
|
-
if (hasMirroredReasoning) appendReasoningDeltas();
|
|
2504
|
-
for (const contentDelta of contentDeltas) if (contentDelta.kind === "text") {
|
|
2505
|
-
const routedDeltas = hasMirroredReasoning ? reasoningTagTextPartitioner.push(contentDelta.text) : reasoningTagTextPartitioner.pushVisible(contentDelta.text);
|
|
2579
|
+
const reasoningBatch = readOpenAICompletionsReasoningBatch(choiceDelta, visibleReasoningDetailTypes);
|
|
2580
|
+
const reasoningDeltas = reasoningBatch.deltas;
|
|
2581
|
+
const hasReasoningThinking = reasoningBatch.hasThinking;
|
|
2582
|
+
const contentDeltas = readOpenAICompletionsContentDeltas(choiceDelta.content, choiceDelta.refusal, reasoningBatch.mirroredThinking);
|
|
2583
|
+
const lastVisibleTextIndex = contentDeltas.findLastIndex((delta) => delta.kind === "text");
|
|
2584
|
+
const hasSameChunkVisibleText = reasoningBatch.hasVisibleText || lastVisibleTextIndex !== -1;
|
|
2585
|
+
if (hasReasoningThinking) {
|
|
2586
|
+
beginReasoning(hasSameChunkVisibleText, true);
|
|
2587
|
+
appendReasoningDeltas(reasoningDeltas);
|
|
2588
|
+
}
|
|
2589
|
+
for (const [contentDeltaIndex, contentDelta] of contentDeltas.entries()) if (contentDelta.kind === "text") {
|
|
2590
|
+
const routedDeltas = hasReasoningThinking ? reasoningTagTextPartitioner.push(contentDelta.text) : reasoningTagTextPartitioner.pushVisible(contentDelta.text);
|
|
2506
2591
|
for (const routedDelta of routedDeltas) appendPartitionedVisibleDelta(routedDelta);
|
|
2507
2592
|
} else {
|
|
2508
|
-
|
|
2593
|
+
beginReasoning(contentDeltaIndex < lastVisibleTextIndex);
|
|
2509
2594
|
appendRoutedContentDelta(contentDelta);
|
|
2510
2595
|
}
|
|
2511
|
-
if (!
|
|
2596
|
+
if (!hasReasoningThinking) appendReasoningDeltas(reasoningDeltas);
|
|
2512
2597
|
const toolCallDeltas = normalizedDelta.toolCalls;
|
|
2513
2598
|
if (toolCallDeltas.length > 0) {
|
|
2514
2599
|
sawNativeToolCallDelta = true;
|
|
2515
|
-
|
|
2600
|
+
flushReasoningTagTextPartitioner();
|
|
2516
2601
|
rememberPendingCommentaryTags(provisionalCommentaryTags, tagPendingCommentaryText(output.content));
|
|
2517
2602
|
for (const toolCall of toolCallDeltas) {
|
|
2518
2603
|
const streamIndex = typeof toolCall.index === "number" ? toolCall.index : void 0;
|
|
@@ -2566,7 +2651,7 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2566
2651
|
emitReasoningUsageActivity(hasReasoningUsageActivity);
|
|
2567
2652
|
await cooperativeScheduler.afterEvent();
|
|
2568
2653
|
}
|
|
2569
|
-
|
|
2654
|
+
flushReasoningTagTextPartitioner();
|
|
2570
2655
|
flushDeepSeekToolCallRecovererAtEnd();
|
|
2571
2656
|
flushDeepSeekTextFilterAtEnd();
|
|
2572
2657
|
currentBlock = null;
|
|
@@ -2574,6 +2659,7 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2574
2659
|
finalizeOpenAICompletionsToolCalls(output, {
|
|
2575
2660
|
allowSilentToolCallPromotion: sawStopFinishReason || sawNativeToolCallDelta && (options?.sawStreamDONE?.() ?? false),
|
|
2576
2661
|
onConfirmedToolCall(block, contentIndex) {
|
|
2662
|
+
if (block.type !== "toolCall") return;
|
|
2577
2663
|
pushStreamEvent({
|
|
2578
2664
|
type: "toolcall_end",
|
|
2579
2665
|
contentIndex,
|
|
@@ -2582,66 +2668,11 @@ async function processCompletionsStream(responseStream, output, model, stream, o
|
|
|
2582
2668
|
});
|
|
2583
2669
|
}
|
|
2584
2670
|
});
|
|
2671
|
+
if (confirmedInterruptedTextBlock && output.stopReason !== "toolUse" && output.stopReason !== "error" && output.stopReason !== "aborted") tagInterruptedTextPhases(output.content, confirmedInterruptedTextBlock, explicitVisibleTextBlocks);
|
|
2585
2672
|
if (output.stopReason !== "toolUse") clearPendingCommentaryText(provisionalCommentaryTags);
|
|
2673
|
+
if (output.stopReason === "error" || output.stopReason === "aborted") tagUnresolvedTextAsCommentary(output);
|
|
2586
2674
|
if (output.stopReason === "toolUse") tagPendingCommentaryText(output.content);
|
|
2587
2675
|
}
|
|
2588
|
-
function getCompletionsReasoningDeltas(delta, visibleReasoningDetailTypes) {
|
|
2589
|
-
const output = [];
|
|
2590
|
-
const pushDelta = (next) => {
|
|
2591
|
-
const previous = output[output.length - 1];
|
|
2592
|
-
if (!previous || previous.kind !== next.kind) {
|
|
2593
|
-
output.push(next);
|
|
2594
|
-
return;
|
|
2595
|
-
}
|
|
2596
|
-
if (next.kind === "thinking" && previous.kind === "thinking") {
|
|
2597
|
-
if (previous.signature !== next.signature) {
|
|
2598
|
-
output.push(next);
|
|
2599
|
-
return;
|
|
2600
|
-
}
|
|
2601
|
-
previous.text += next.text;
|
|
2602
|
-
return;
|
|
2603
|
-
}
|
|
2604
|
-
previous.text += next.text;
|
|
2605
|
-
};
|
|
2606
|
-
const reasoningDetails = delta.reasoning_details;
|
|
2607
|
-
let usedReasoningThinkingDetails = false;
|
|
2608
|
-
if (Array.isArray(reasoningDetails)) {
|
|
2609
|
-
const visibleTypes = new Set(visibleReasoningDetailTypes);
|
|
2610
|
-
for (const item of reasoningDetails) {
|
|
2611
|
-
const detail = item;
|
|
2612
|
-
if (typeof detail.text !== "string" || !detail.text) continue;
|
|
2613
|
-
if (detail.type === "reasoning.text") {
|
|
2614
|
-
usedReasoningThinkingDetails = true;
|
|
2615
|
-
pushDelta({
|
|
2616
|
-
kind: "thinking",
|
|
2617
|
-
signature: "reasoning_details",
|
|
2618
|
-
text: detail.text
|
|
2619
|
-
});
|
|
2620
|
-
continue;
|
|
2621
|
-
}
|
|
2622
|
-
if (typeof detail.type === "string" && visibleTypes.has(detail.type)) pushDelta({
|
|
2623
|
-
kind: "text",
|
|
2624
|
-
text: detail.text
|
|
2625
|
-
});
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
if (!usedReasoningThinkingDetails) for (const field of [
|
|
2629
|
-
"reasoning_content",
|
|
2630
|
-
"reasoning",
|
|
2631
|
-
"reasoning_text"
|
|
2632
|
-
]) {
|
|
2633
|
-
const value = delta[field];
|
|
2634
|
-
if (typeof value === "string" && value.length > 0) {
|
|
2635
|
-
pushDelta({
|
|
2636
|
-
kind: "thinking",
|
|
2637
|
-
signature: field,
|
|
2638
|
-
text: value
|
|
2639
|
-
});
|
|
2640
|
-
break;
|
|
2641
|
-
}
|
|
2642
|
-
}
|
|
2643
|
-
return output;
|
|
2644
|
-
}
|
|
2645
2676
|
function resolveOpenAICompletionsReasoningEffort(options) {
|
|
2646
2677
|
return options?.reasoningEffort ?? options?.reasoning ?? "high";
|
|
2647
2678
|
}
|
|
@@ -2738,8 +2769,7 @@ function buildOpenAICompletionsClientConfig(model, context, optionHeaders) {
|
|
|
2738
2769
|
}
|
|
2739
2770
|
function createOpenAICompletionsTransportStreamFn() {
|
|
2740
2771
|
return (model, context, options) => {
|
|
2741
|
-
const eventStream =
|
|
2742
|
-
const stream = eventStream;
|
|
2772
|
+
const { eventStream, stream } = createWritableTransportEventStream();
|
|
2743
2773
|
(async () => {
|
|
2744
2774
|
const output = {
|
|
2745
2775
|
role: "assistant",
|
|
@@ -2794,7 +2824,7 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
2794
2824
|
if (nextParams !== void 0) params = nextParams;
|
|
2795
2825
|
if (options?.openclawCodeModeToolSurface === true) {
|
|
2796
2826
|
const visibleToolNames = resolveCodeModeResponsesVisibleToolNames(context);
|
|
2797
|
-
enforceCodeModeResponsesToolSurface(params, visibleToolNames);
|
|
2827
|
+
enforceCodeModeResponsesToolSurface(params, visibleToolNames, void 0, codeModeToolSurfaceObserver.get(options));
|
|
2798
2828
|
assertCodeModeResponsesToolSurface(params, visibleToolNames);
|
|
2799
2829
|
}
|
|
2800
2830
|
if (getCompat(model).requiresNonEmptyUserOrAssistantMessage) assertOpenAICompletionsPayloadHasConversationTurn(params, model);
|
|
@@ -2808,7 +2838,7 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
2808
2838
|
stream: responseStream,
|
|
2809
2839
|
signal: firstEventAbort.signal,
|
|
2810
2840
|
abort: firstEventAbort.abort,
|
|
2811
|
-
hook:
|
|
2841
|
+
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
2812
2842
|
onReady: () => stream.push({
|
|
2813
2843
|
type: "start",
|
|
2814
2844
|
partial: output
|
|
@@ -2835,6 +2865,7 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
2835
2865
|
cleanup: () => {
|
|
2836
2866
|
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
2837
2867
|
finalizeOpenAICompletionsToolCalls(output, { allowSilentToolCallPromotion: false });
|
|
2868
|
+
tagUnresolvedTextAsCommentary(output);
|
|
2838
2869
|
}
|
|
2839
2870
|
});
|
|
2840
2871
|
} finally {
|
|
@@ -3405,9 +3436,8 @@ function createOpenAIResponsesWebSocketStream(params) {
|
|
|
3405
3436
|
}
|
|
3406
3437
|
const event = readServerEvent(next.value);
|
|
3407
3438
|
if (!event) continue;
|
|
3408
|
-
if (event.type === "response.failed") throw new OpenAIResponsesWebSocketResponseFailedError(event.response.output.length > 0);
|
|
3409
3439
|
if (event.type === "response.completed") terminalResponse = event.response;
|
|
3410
|
-
terminalReceived = event.type === "response.completed" || event.type === "response.incomplete";
|
|
3440
|
+
terminalReceived = event.type === "response.completed" || event.type === "response.incomplete" || event.type === "response.failed";
|
|
3411
3441
|
yield event;
|
|
3412
3442
|
if (terminalReceived) {
|
|
3413
3443
|
degradedWebSocketConnections.delete(degradationKey);
|
|
@@ -3419,7 +3449,7 @@ function createOpenAIResponsesWebSocketStream(params) {
|
|
|
3419
3449
|
const safeRetry = error instanceof OpenAIResponsesWebSocketSafeRetryError;
|
|
3420
3450
|
if (!params.callerSignal?.aborted && !safeRetry) markDegraded();
|
|
3421
3451
|
if (!requestDispatched && !params.signal?.aborted) throw new OpenAIResponsesWebSocketPreDispatchError(error);
|
|
3422
|
-
if (!requestDispatched || params.callerSignal?.aborted ||
|
|
3452
|
+
if (!requestDispatched || params.callerSignal?.aborted || safeRetry) throw error;
|
|
3423
3453
|
throw new OpenAIResponsesWebSocketPostDispatchError(error);
|
|
3424
3454
|
} finally {
|
|
3425
3455
|
await iterator.return?.().catch(() => void 0);
|
|
@@ -3639,11 +3669,17 @@ async function postOpenAIResponsesCompaction(params) {
|
|
|
3639
3669
|
}
|
|
3640
3670
|
});
|
|
3641
3671
|
const output = isRecord(response) && Array.isArray(response.output) ? response.output : [];
|
|
3642
|
-
const item = output
|
|
3672
|
+
const item = output.at(-1);
|
|
3673
|
+
const retainedItems = output.slice(0, -1);
|
|
3674
|
+
const retainedMessagesAreValid = retainedItems.every((candidate) => isRecord(candidate) && candidate.type === "message" && (candidate.role === "user" || candidate.role === "developer" || candidate.role === "system") && Array.isArray(candidate.content));
|
|
3675
|
+
const retainedUserMessageCount = retainedItems.filter((candidate) => isRecord(candidate) && candidate.type === "message" && candidate.role === "user" && Array.isArray(candidate.content)).length;
|
|
3676
|
+
const inputUserMessageCount = Array.isArray(params.request.input) ? params.request.input.filter((candidate) => isRecord(candidate) && candidate.type === "message" && candidate.role === "user").length : 0;
|
|
3677
|
+
const retainedMessagePrefixSupported = supportsNativeOpenAIResponsesEndpoint(params.model);
|
|
3643
3678
|
const usage = isRecord(response) && isRecord(response.usage) ? response.usage : void 0;
|
|
3644
|
-
if (!isRecord(response) || response.object !== "response.compaction" ||
|
|
3679
|
+
if (!isRecord(response) || response.object !== "response.compaction" || !retainedMessagesAreValid || retainedItems.length > 0 && (!retainedMessagePrefixSupported || retainedUserMessageCount !== inputUserMessageCount) || !isRecord(item) || item.type !== "compaction" || typeof item.encrypted_content !== "string" || item.encrypted_content.length === 0 || !usage || typeof usage.input_tokens !== "number" || typeof usage.output_tokens !== "number") throw new Error("Responses compact endpoint did not return one trailing compaction item");
|
|
3645
3680
|
return {
|
|
3646
3681
|
item,
|
|
3682
|
+
historyMode: retainedUserMessageCount > 0 ? "retained-users" : "compacted-prefix",
|
|
3647
3683
|
usage,
|
|
3648
3684
|
model: params.model,
|
|
3649
3685
|
replayMetadata: buildOpenAIResponsesReasoningReplayMetadata(params.model, {
|
|
@@ -3656,8 +3692,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
3656
3692
|
return (model, context, options) => {
|
|
3657
3693
|
const responsesOptions = options;
|
|
3658
3694
|
const compactRequest = claimResponsesCompactRequest(responsesOptions);
|
|
3659
|
-
const eventStream =
|
|
3660
|
-
const stream = eventStream;
|
|
3695
|
+
const { eventStream, stream } = createWritableTransportEventStream();
|
|
3661
3696
|
(async () => {
|
|
3662
3697
|
const output = createOpenAIResponsesAssistantOutput(model, config.outputApi);
|
|
3663
3698
|
let firstEventAbort;
|
|
@@ -3684,7 +3719,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
3684
3719
|
if (options?.openclawCodeModeToolSurface === true) {
|
|
3685
3720
|
const visibleToolNames = resolveCodeModeResponsesVisibleToolNames(context);
|
|
3686
3721
|
const allowedHostedToolTypes = responsesOptions?.openclawCodeModeAllowedHostedToolTypes;
|
|
3687
|
-
enforceCodeModeResponsesToolSurface(params, visibleToolNames, allowedHostedToolTypes);
|
|
3722
|
+
enforceCodeModeResponsesToolSurface(params, visibleToolNames, allowedHostedToolTypes, codeModeToolSurfaceObserver.get(options));
|
|
3688
3723
|
assertCodeModeResponsesToolSurface(params, visibleToolNames, allowedHostedToolTypes);
|
|
3689
3724
|
}
|
|
3690
3725
|
return params;
|
|
@@ -3701,12 +3736,11 @@ function createResponsesTransportExecutor(config) {
|
|
|
3701
3736
|
output.usage.output = compacted.usage.output_tokens;
|
|
3702
3737
|
output.usage.totalTokens = compacted.usage.input_tokens + compacted.usage.output_tokens;
|
|
3703
3738
|
compactRequest.resolve(compacted);
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3739
|
+
finalizeTransportStream({
|
|
3740
|
+
stream,
|
|
3741
|
+
output,
|
|
3742
|
+
signal: options?.signal
|
|
3708
3743
|
});
|
|
3709
|
-
stream.end();
|
|
3710
3744
|
return;
|
|
3711
3745
|
}
|
|
3712
3746
|
const sessionId = options?.sessionId;
|
|
@@ -3760,7 +3794,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
3760
3794
|
stream: observeResponsesStream(rawResponseStream, model, requestStartedAt),
|
|
3761
3795
|
signal: firstEvent.signal,
|
|
3762
3796
|
abort: firstEvent.abort,
|
|
3763
|
-
hook:
|
|
3797
|
+
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
3764
3798
|
onReady: () => {
|
|
3765
3799
|
emitModelTransportDebug(log, `[responses] headers provider=${model.provider} api=${model.api} model=${model.id} transport=sse elapsedMs=${Date.now() - requestStartedAt}`);
|
|
3766
3800
|
startStream();
|
|
@@ -3796,8 +3830,16 @@ function createResponsesTransportExecutor(config) {
|
|
|
3796
3830
|
transport = "websocket";
|
|
3797
3831
|
emitModelTransportDebug(log, `[responses] websocket_selected provider=${model.provider} api=${model.api} model=${model.id} mode=${websocketMode} reused=${websocket.reusedConnection} continuation=${websocket.continuationStatus === "continued"} continuationStatus=${websocket.continuationStatus} sessionIdHash=${redactIdentifier(options?.sessionId)} headersHash=${redactIdentifier(JSON.stringify(Object.entries(websocketHeaders ?? {}).toSorted(([a], [b]) => a.localeCompare(b))))}`);
|
|
3798
3832
|
responseStream = { async *[Symbol.asyncIterator]() {
|
|
3833
|
+
let providerAccepted = false;
|
|
3799
3834
|
try {
|
|
3800
3835
|
for await (const event of websocket.stream) {
|
|
3836
|
+
if (!providerAccepted) {
|
|
3837
|
+
providerAccepted = true;
|
|
3838
|
+
await notifyProviderStreamOpened({
|
|
3839
|
+
options,
|
|
3840
|
+
cancelStream: () => websocket.finish({ keep: false })
|
|
3841
|
+
});
|
|
3842
|
+
}
|
|
3801
3843
|
startStream();
|
|
3802
3844
|
yield event;
|
|
3803
3845
|
}
|
|
@@ -3848,33 +3890,30 @@ function createResponsesTransportExecutor(config) {
|
|
|
3848
3890
|
throw error;
|
|
3849
3891
|
}
|
|
3850
3892
|
emitModelTransportDebug(log, `[responses] completed provider=${model.provider} api=${model.api} model=${model.id} transport=${transport} elapsedMs=${Date.now() - requestStartedAt}`);
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3893
|
+
finalizeTransportStream({
|
|
3894
|
+
stream,
|
|
3895
|
+
output,
|
|
3896
|
+
signal: options?.signal
|
|
3855
3897
|
});
|
|
3856
|
-
stream.end();
|
|
3857
3898
|
} catch (error) {
|
|
3858
3899
|
if (compactRequest) {
|
|
3859
3900
|
compactRequest.reject(error);
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
error
|
|
3901
|
+
failTransportStream({
|
|
3902
|
+
stream,
|
|
3903
|
+
output,
|
|
3904
|
+
signal: options?.signal,
|
|
3905
|
+
error
|
|
3865
3906
|
});
|
|
3866
|
-
stream.end();
|
|
3867
3907
|
return;
|
|
3868
3908
|
}
|
|
3869
3909
|
if (error instanceof ResponsesStreamFailure && error.observation) logResponsesFailedNoDetails(error.observation);
|
|
3870
3910
|
log.warn(`[responses] error provider=${model.provider} api=${model.api} model=${model.id} ` + summarizeOpenAITransportError(error));
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
error
|
|
3911
|
+
failTransportStream({
|
|
3912
|
+
stream,
|
|
3913
|
+
output,
|
|
3914
|
+
signal: options?.signal,
|
|
3915
|
+
error
|
|
3876
3916
|
});
|
|
3877
|
-
stream.end();
|
|
3878
3917
|
} finally {
|
|
3879
3918
|
continuationClaim?.release();
|
|
3880
3919
|
firstEventAbort?.dispose();
|
|
@@ -3970,7 +4009,7 @@ if (process.env.VITEST || false) globalThis.openclawOpenAIResponsesTransportTest
|
|
|
3970
4009
|
/** Whether provider replay state is a prefix-bound server compaction checkpoint. */
|
|
3971
4010
|
function isCompactionReplayCheckpoint(replay) {
|
|
3972
4011
|
const type = replay && typeof replay === "object" ? replay.type : void 0;
|
|
3973
|
-
return type === "anthropic-compaction" || type === "openai-responses-compaction";
|
|
4012
|
+
return type === "anthropic-compaction" || type === "openai-responses-compaction" || type === "openai-responses-retained-compaction";
|
|
3974
4013
|
}
|
|
3975
4014
|
/** Strip prefix-bound checkpoints after local history rewrites. */
|
|
3976
4015
|
function stripCompactionReplayCheckpoint(message) {
|
|
@@ -3991,8 +4030,9 @@ function replaceCompactionReplayOwnerContent(message, content) {
|
|
|
3991
4030
|
};
|
|
3992
4031
|
const replay = message.providerReplay;
|
|
3993
4032
|
if (!isCompactionReplayCheckpoint(replay)) return next;
|
|
4033
|
+
if (replay.type === "openai-responses-retained-compaction") return next;
|
|
3994
4034
|
const replayIndex = replay.replayIndex ?? 0;
|
|
3995
|
-
if (content.length === 0 || replayIndex > message.content.length) return stripCompactionReplayCheckpoint(next);
|
|
4035
|
+
if (content.length === 0 && message.content.length > 0 || replayIndex > message.content.length) return stripCompactionReplayCheckpoint(next);
|
|
3996
4036
|
let sourceIndex = 0;
|
|
3997
4037
|
let nextReplayIndex = 0;
|
|
3998
4038
|
if (!content.every((block) => {
|
|
@@ -4261,4 +4301,4 @@ function prepareModelForSimpleCompletion(params) {
|
|
|
4261
4301
|
return applyProviderSimpleCompletionWrapper(apiRegistry, model, cfg);
|
|
4262
4302
|
}
|
|
4263
4303
|
//#endregion
|
|
4264
|
-
export { GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, applyAnthropicCacheControlToMessages, applyAnthropicEphemeralCacheControlMarkers, applyAnthropicPayloadPolicyToParams, applyOpenAIResponsesPayloadPolicy, assertCodeModeResponsesToolSurface, assignTransportErrorDetails, buildOpenAIClientHeaders, buildOpenAICompletionsParams, buildOpenAISdkClientOptions, buildOpenAISdkRequestOptions, buildTransportAwareSimpleStreamFn, canonicalizeMaxTokensParam, captureOpenAIResponsesCompaction, coerceTransportToolCallArguments, createAnthropicMessagesTransportStreamFn, createAzureOpenAIResponsesTransportStreamFn, createBoundaryAwareStreamFnForModel, createDeepSeekTextFilter, createEmptyTransportUsage, createModelStreamCooperativeScheduler, createOpenAICompletionsTransportStreamFn, createOpenAIResponseHook, createOpenAIResponsesTransportStreamFn, createOpenClawTransportStreamFnForModel, createTransportAwareStreamFnForModel, createWritableTransportEventStream, detectOpenAICompletionsCompat, emitModelTransportDebug, enforceCodeModeResponsesToolSurface, failTransportStream, filterCodeModePayloadTools, finalizeTransportStream, flattenCompletionMessagesToStringContent, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, getCompat, googleFlashSupportsMinimalThinking, hasOpenAICompatibleConversationTurn, isCodeModeModelVisibleToolName, isCompactionReplayCheckpoint, isOpenAICodexResponsesModel, isOpenAICompletionsThinkingEnabled, log, measureUtf8AppendBytes, mergeTransportHeaders, mergeTransportMetadata, normalizeCodexResponsesBaseUrlForOpenAISdk, parseJsonObjectPreservingUnsafeIntegers, parseJsonPreservingUnsafeIntegers, parseOpenAICompletionsUsage, prepareModelForSimpleCompletion, prepareTransportAwareSimpleModel, quoteUnsafeIntegerLiterals, readCodeModePayloadToolName, readOpenAICompletionsContentDeltas, replaceCompactionReplayOwnerContent, requestPreparedOpenAIResponsesCompaction, resolveAnthropicEphemeralCacheControl, resolveAnthropicMessagesUrl, resolveAnthropicPayloadPolicy, resolveAnthropicServerCompactionPlan, resolveCodeModeResponsesVisibleToolNames, resolveMaxTokensParam, resolveModelPayloadDebugMode, resolveModelSseDebugMode, resolveOpenAICompletionsCompat, resolveOpenAIReasoningEffortMap, resolveOpenAIResponsesCompactEndpointPlan, resolveOpenAIResponsesPayloadPolicy, resolveOpenAIResponsesServerCompactionPlan, resolveOpenAIStrictToolFlagWithDiagnostics, resolvePromptCacheKey, resolveReplayableResponsesMessageId, resolveTransportAwareSimpleApi, sanitizeNonEmptyTransportPayloadText, sanitizeResponsesImagePayload, sanitizeTransportPayloadText, sortPromptCacheToolsByName as sortTransportToolsByName, stripCompactionReplayCheckpoint, stripCompactionReplayCheckpointInPlace, stripCompletionMessagesToRoleContent, throwIfModelStreamAborted, transportAbortError, usesNativeOpenAICodexResponsesBackend, withProviderResponseHook };
|
|
4304
|
+
export { GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, applyAnthropicCacheControlToMessages, applyAnthropicEphemeralCacheControlMarkers, applyAnthropicPayloadPolicyToParams, applyOpenAIResponsesPayloadPolicy, assertCodeModeResponsesToolSurface, assignTransportErrorDetails, buildOpenAIClientHeaders, buildOpenAICompletionsParams, buildOpenAISdkClientOptions, buildOpenAISdkRequestOptions, buildTransportAwareSimpleStreamFn, canonicalizeMaxTokensParam, captureOpenAIResponsesCompaction, coerceTransportToolCallArguments, copyProviderAcceptanceObserver, createAnthropicMessagesTransportStreamFn, createAzureOpenAIResponsesTransportStreamFn, createBoundaryAwareStreamFnForModel, createDeepSeekTextFilter, createEmptyTransportUsage, createModelStreamCooperativeScheduler, createOpenAICompletionsTransportStreamFn, createOpenAIProviderAcceptanceHook, createOpenAIResponseHook, createOpenAIResponsesTransportStreamFn, createOpenClawTransportStreamFnForModel, createTransportAwareStreamFnForModel, createWritableTransportEventStream, detectOpenAICompletionsCompat, emitModelTransportDebug, enforceCodeModeResponsesToolSurface, failTransportStream, filterCodeModePayloadTools, finalizeTerminalToolCallArguments, finalizeTransportStream, flattenCompletionMessagesToStringContent, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, getCompat, googleFlashSupportsMinimalThinking, hasOpenAICompatibleConversationTurn, isCodeModeModelVisibleToolName, isCompactionReplayCheckpoint, isOpenAICodexResponsesModel, isOpenAICompletionsThinkingEnabled, log, measureUtf8AppendBytes, mergeTransportHeaders, mergeTransportMetadata, normalizeCodexResponsesBaseUrlForOpenAISdk, notifyProviderHttpMetadata, notifyProviderHttpResponse, notifyProviderStreamOpened, parseJsonObjectPreservingUnsafeIntegers, parseJsonPreservingUnsafeIntegers, parseOpenAICompletionsUsage, parseTerminalToolCallArguments, prepareModelForSimpleCompletion, prepareTransportAwareSimpleModel, quoteUnsafeIntegerLiterals, readCodeModePayloadToolName, readOpenAICompletionsContentDeltas, readOpenAICompletionsReasoningBatch, replaceCompactionReplayOwnerContent, requestPreparedOpenAIResponsesCompaction, resolveAnthropicEphemeralCacheControl, resolveAnthropicMessagesUrl, resolveAnthropicPayloadPolicy, resolveAnthropicServerCompactionPlan, resolveCodeModeResponsesVisibleToolNames, resolveMaxTokensParam, resolveModelPayloadDebugMode, resolveModelSseDebugMode, resolveOpenAICompletionsCompat, resolveOpenAIReasoningEffortMap, resolveOpenAIResponsesCompactEndpointPlan, resolveOpenAIResponsesPayloadPolicy, resolveOpenAIResponsesServerCompactionPlan, resolveOpenAIStrictToolFlagWithDiagnostics, resolvePromptCacheKey, resolveReplayableResponsesMessageId, resolveTransportAwareSimpleApi, sanitizeNonEmptyTransportPayloadText, sanitizeResponsesImagePayload, sanitizeTransportPayloadText, sortPromptCacheToolsByName as sortTransportToolsByName, stripCompactionReplayCheckpoint, stripCompactionReplayCheckpointInPlace, stripCompletionMessagesToRoleContent, throwIfModelStreamAborted, transportAbortError, usesNativeOpenAICodexResponsesBackend, withProviderAcceptanceObserver, withProviderResponseHook };
|