@openclaw/ai 2026.9.4 → 2026.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{anthropic-C4Qu4H0Z.mjs → anthropic-DZQ_7gD1.mjs} +37 -38
- package/dist/{anthropic-payload-policy-BZ8umAbk.d.mts → anthropic-payload-policy-DyfwikYJ.d.mts} +4 -4
- package/dist/{anthropic-stream-reducer-CILWF7JD.mjs → anthropic-stream-reducer-D6ZI1wwj.mjs} +70 -50
- package/dist/{api-registry-ByUwIR0e.d.mts → api-registry-C2T3lTV7.d.mts} +2 -2
- package/dist/{assistant-output-tLt4H-iQ.mjs → assistant-output-DM1JBNs1.mjs} +1 -1
- package/dist/{azure-openai-responses-BAlqlKKc.mjs → azure-openai-responses-DS86GYzq.mjs} +6 -9
- package/dist/{base64-D-su8YVo.mjs → base64-CPmadnUf.mjs} +12 -12
- package/dist/credential-redaction-BKv49aiv.d.mts +24 -0
- package/dist/{diagnostics-QuErwCIl.mjs → diagnostics-CH8j2wIG.mjs} +139 -7
- package/dist/{diagnostics-CPeq9F7y.mjs → diagnostics-DzrF1h4J.mjs} +18 -1
- package/dist/diagnostics.d.mts +11 -24
- package/dist/diagnostics.mjs +4 -4
- package/dist/event-stream-C0nsgbj2.d.mts +1 -0
- package/dist/{event-stream-Bt5Y4Pav.d.mts → event-stream-CjnIZZst.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{google-DPBAOaOW.mjs → google-BZJFjhuC.mjs} +6 -9
- package/dist/{google-messages-6JkpHrhJ.mjs → google-messages-DB7GKkDk.mjs} +3 -3
- package/dist/{google-shared-BvBeW9aq.mjs → google-shared-Bok4I6zB.mjs} +13 -13
- package/dist/{google-vertex-k-TMCAYD.mjs → google-vertex-3eVNR2qW.mjs} +5 -8
- package/dist/{host-4atIX-2V.d.mts → host-DH-Z-LDb.d.mts} +5 -3
- package/dist/{host-policy-Zcg_cNz8.mjs → host-policy-DZO3oPPk.mjs} +1 -1
- package/dist/{host-B8YfDGd4.mjs → host-yTvBrYM2.mjs} +63 -31
- package/dist/{index-DdD3qerf.d.mts → index-C25RT6bP.d.mts} +37 -14
- package/dist/index.d.mts +7 -8
- package/dist/index.mjs +5 -6
- package/dist/internal/anthropic.d.mts +13 -10
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-completions-compat.d.mts +2 -0
- package/dist/internal/openai-completions-compat.mjs +2 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +24 -53
- package/dist/internal/openai.mjs +12 -9
- package/dist/internal/runtime.d.mts +6 -8
- package/dist/internal/runtime.mjs +6 -10
- package/dist/internal/shared.d.mts +7 -5
- package/dist/internal/shared.mjs +4 -3
- package/dist/internal/tool-schema.d.mts +4 -4
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral-CxUZ1jUb.mjs → mistral-C_13dVBn.mjs} +9 -13
- package/dist/{model-transport-url-DKocrEsb.d.mts → model-transport-url-C5f59L3Y.d.mts} +1 -1
- package/dist/{openai-chatgpt-responses-CgO6kZfo.mjs → openai-chatgpt-responses-sTxPl4zM.mjs} +150 -83
- package/dist/{openai-completions-yJuk7eis.mjs → openai-completions-BO6D_hrB.mjs} +11 -12
- package/dist/{openai-prompt-cache-Bds-n_9Q.mjs → openai-completions-compat-CUollwl6.mjs} +5 -50
- package/dist/{openai-completions-compat-eHgh5UPE.d.mts → openai-completions-compat-DfJG1wSO.d.mts} +4 -4
- package/dist/{openai-completions-stream-Da2vvl-S.mjs → openai-completions-stream-BpuJ0ZOA.mjs} +117 -106
- package/dist/{openai-prompt-cache-B4eYo2-I.d.mts → openai-prompt-cache-C4RHdN4n.d.mts} +2 -2
- package/dist/openai-prompt-cache-CjV_2IRI.mjs +46 -0
- package/dist/{openai-provider-client-S2gCrM2Z.mjs → openai-provider-client-BP8J1aeg.mjs} +2 -2
- package/dist/openai-reasoning-effort-ash8dPrd.mjs +243 -0
- package/dist/{openai-responses-DaYwH05E.mjs → openai-responses-BJ_IEoMU.mjs} +8 -12
- package/dist/{openai-responses-compaction-window-CIhBAkkq.mjs → openai-responses-compaction-window-BiNCT0bS.mjs} +20 -62
- package/dist/{openai-responses-contracts-BjBAqAg_.d.mts → openai-responses-contracts-B1ENJFpI.d.mts} +9 -5
- package/dist/openai-responses-contracts-DWrfMODE.mjs +81 -0
- package/dist/{openai-responses-payload-policy-rLRPsSmB.d.mts → openai-responses-payload-policy-C7GsA1y0.d.mts} +5 -3
- package/dist/openai-responses-prompt-observer-internal-DPHWgbBH.mjs +198 -0
- package/dist/openai-responses-request-lifecycle-DFuyO1pQ.mjs +36 -0
- package/dist/{openai-responses-shared-B8RdBPCv.mjs → openai-responses-shared-DvSqtJ6_.mjs} +859 -581
- package/dist/openai-responses-terminal-usage-BNFbvY9f.d.mts +47 -0
- package/dist/{openai-tool-schema-CzjyYXun.mjs → openai-tool-schema-D4BMcj2D.mjs} +262 -162
- package/dist/{openai-transport-params-9aPuV5YY.mjs → openai-transport-params-DZKOTSfH.mjs} +157 -47
- package/dist/{positive-integer-41zhOdcV.mjs → positive-integer-BiUxrd71.mjs} +1 -1
- package/dist/{provider-error-BA-v_tKd.mjs → provider-error-CRhW7lkJ.mjs} +139 -44
- package/dist/{provider-error-CzNw4BWX.d.mts → provider-error-xumb1V3F.d.mts} +3 -1
- package/dist/{provider-options-Ceqv1OKk.d.mts → provider-options-DZYq53lj.d.mts} +12 -7
- package/dist/{provider-replay-context-CJ_YvcEW.mjs → provider-replay-context-DPr3w20a.mjs} +1 -1
- package/dist/{provider-transcript-transform-V5YzU9zh.mjs → provider-transcript-transform-BTocjCRs.mjs} +1 -1
- package/dist/{provider-transport-turn-state-D5EXOFL2.mjs → provider-transport-turn-state-lrXEFkYr.mjs} +1 -1
- package/dist/{provider-types-CVjKjsuq.d.mts → provider-types-w1rEqrGP.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -7
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +10 -10
- package/dist/{reasoning-tag-text-partitioner-BcR5pztD.mjs → reasoning-tag-text-partitioner-Di38crhI.mjs} +167 -40
- package/dist/{simple-options-BQbb4yQL.mjs → simple-options-np1XPuhm.mjs} +5 -3
- package/dist/{usage-cost-BNWbbXav.mjs → src-DwGYYyZp.mjs} +18 -11
- package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-BeptfRL6.mjs} +1 -1
- package/dist/{string-normalization-CmLIasuf.mjs → string-normalization-J9ZiLfGO.mjs} +13 -1
- package/dist/tool-schema-json-projection-CD9c_fK8.mjs +134 -0
- package/dist/{transport-stream-shared-zHll9BxO.mjs → transport-stream-shared-B5RioB_Q.mjs} +16 -24
- package/dist/{transport-stream-shared-DNvmoWnv.d.mts → transport-stream-shared-B7Z9oCYg.d.mts} +5 -5
- package/dist/{transport-utils-zrYjICLZ.mjs → transport-utils-03Qi0CN2.mjs} +3 -3
- package/dist/transports.d.mts +27 -13
- package/dist/transports.mjs +168 -462
- package/dist/types-DTvddOfm.d.mts +1 -0
- package/dist/{types-Ntv5z2g2.d.mts → types-qZFbaDbK.d.mts} +49 -3
- package/dist/types.d.mts +6 -7
- package/dist/types.mjs +4 -5
- package/dist/{validation-B0t_G2H6.d.mts → validation-DhQhmt6t.d.mts} +1 -1
- package/dist/{validation-BDzVDnTs.mjs → validation-Dw7cb6BV.mjs} +1 -0
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +11 -6
- package/dist/diagnostics-DnPnOui6.d.mts +0 -29
- package/dist/event-stream-C3WGFsum.d.mts +0 -1
- package/dist/openai-responses-contracts-DDOHA62Y.mjs +0 -245
- package/dist/openai-responses-prompt-observer-internal-f8J7wpsk.mjs +0 -32
- package/dist/src-DDmEryvj.mjs +0 -2
- package/dist/tool-schema-json-projection-ClptDdAO.mjs +0 -82
- package/dist/types-DlfwzH3T.d.mts +0 -1
package/dist/transports.mjs
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as resolveClaudeSonnet5ModelIdentity, g as resolveClaudeOpus5ModelIdentity, y as supportsClaudeAdaptiveThinking } from "./src-DwGYYyZp.mjs";
|
|
2
2
|
import { n as normalizeLowercaseStringOrEmpty, t as hasNonEmptyString } from "./string-coerce-fsri9iCu.mjs";
|
|
3
|
-
import { E as resolveAnthropicThinkingEffort, O as usesClaudeFable5MessagesContract, S as defaultsClaudeAdaptiveThinking, T as requiresClaudeAdaptiveThinking, b as ANTHROPIC_CLAUDE_CODE_VERSION, k as usesClaudeStreamingRefusalContract, n as getAiTransportHost, r as resolveAiTransportHeaderSentinels, w as prepareClaudeNoPrefillRequestContext, x as applyClaudeRequestContract } from "./host-B8YfDGd4.mjs";
|
|
4
3
|
import { o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { a as
|
|
8
|
-
import { a as
|
|
9
|
-
import {
|
|
10
|
-
import { i as
|
|
11
|
-
import {
|
|
4
|
+
import { E as resolveAnthropicThinkingEffort, O as usesClaudeFable5MessagesContract, S as defaultsClaudeAdaptiveThinking, T as requiresClaudeAdaptiveThinking, b as applyClaudeRequestContract, k as usesClaudeStreamingRefusalContract, n as getAiTransportHost, r as resolveAiTransportHeaderSentinels, w as prepareClaudeNoPrefillRequestContext, x as buildAnthropicClaudeCodeIdentity } from "./host-yTvBrYM2.mjs";
|
|
5
|
+
import { t as truncateUtf16Safe } from "./utf16-slice-CvGodqok.mjs";
|
|
6
|
+
import { a as redactDiagnosticText, o as stableStringify } from "./provider-error-CRhW7lkJ.mjs";
|
|
7
|
+
import { a as resolveModelSseDebugMode, i as resolveModelPayloadDebugMode, n as formatModelTransportDebugUrl, r as emitModelTransportDebug, t as formatModelTransportDebugBaseUrl, u as hasOnlyResponsesFunctionTools, v as toErrorObject } from "./diagnostics-CH8j2wIG.mjs";
|
|
8
|
+
import { a as readResponseTextSnippet, i as isCodeModeModelVisibleToolName, n as createAbortError$1, s as resolveModelHeaderSentinels, t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-03Qi0CN2.mjs";
|
|
9
|
+
import { a as resolveOpenAIPromptCacheKeySupport, i as resolveOpenAICompletionsCompat, n as isNativeOpenAIEndpoint, o as usesNativeOpenAICodexResponsesBackend, r as isOpenAICodexResponsesModel, t as detectOpenAICompletionsCompat } from "./openai-completions-compat-CUollwl6.mjs";
|
|
10
|
+
import { i as resolveProviderEndpoint, s as transformTransportMessages, t as buildGuardedModelFetch } from "./host-policy-DZO3oPPk.mjs";
|
|
11
|
+
import { B as logAnthropicContextEdits, C as applyAnthropicThinkingBindingControls, D as ANTHROPIC_SERVER_SIDE_FALLBACKS, F as applyAnthropicPayloadPolicyToParams, G as resolveAnthropicServerCompactionPlan, H as resolveAnthropicContextManagementBetaHeader, I as applyAnthropicRequestCacheControl, J as usesFoundryBearerAuth, K as isAnthropicOAuthApiKey, L as buildAnthropicSystemBlocks, N as applyAnthropicContextManagementToRequest, O as ANTHROPIC_SERVER_SIDE_FALLBACK_BETA, P as applyAnthropicEphemeralCacheControlMarkers, R as isAnthropicServerToolClearingEnabled, U as resolveAnthropicEphemeralCacheControl, V as resolveAnthropicCacheOptions, W as resolveAnthropicPayloadPolicy, d as convertAnthropicTools, f as buildAnthropicReplayPlan, g as normalizeAnthropicToolCallId, h as suppressAnthropicCompaction, l as buildAnthropicGenerationParams, m as resolveNewestAnthropicCompaction, p as isAnthropicReplayRejection, q as omitFoundryBearerCredentialHeaders, t as consumeAnthropicStream, u as convertAnthropicMessages, z as isDirectAnthropicModel } from "./anthropic-stream-reducer-D6ZI1wwj.mjs";
|
|
12
12
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
13
|
-
import { a as codeModeToolSurfaceObserver,
|
|
14
|
-
import {
|
|
13
|
+
import { a as codeModeToolSurfaceObserver, o as reasoningTagTextPolicy, t as adjustMaxTokensForThinking, v as sortPromptCacheToolsByName } from "./simple-options-np1XPuhm.mjs";
|
|
14
|
+
import { A as resolvePromptCacheKey, C as isOpenAICompletionsThinkingEnabled, D as readOpenAICompletionsContentDeltas, E as parseOpenAICompletionsUsage, M as redactIdentifier, N as sha256Hex, O as readOpenAICompletionsReasoningBatch, S as createResponseModelTracker, T as measureUtf8AppendBytes, _ as resolveOpenAIReasoningEffortMap, a as enforceCodeModeResponsesToolSurface, b as createOpenAIProviderAcceptanceHook, c as readCodeModePayloadToolName, i as buildOpenAISdkRequestOptions, j as throwIfModelStreamAborted, k as resolveOpenAIClientBaseUrl, l as resolveCodeModeResponsesVisibleToolNames, n as buildOpenAIClientHeaders, o as filterCodeModePayloadTools, r as buildOpenAISdkClientOptions, s as getCompat, t as assertCodeModeResponsesToolSurface, u as resolveOpenAIStrictToolFlagWithDiagnostics, v as GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, w as log, x as createOpenAIResponseHook, y as createModelStreamCooperativeScheduler } from "./openai-transport-params-DZKOTSfH.mjs";
|
|
15
15
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
16
|
-
import { C as quoteUnsafeIntegerLiterals, S as parseJsonPreservingUnsafeIntegers, _ as sanitizeTransportPayloadText, a as createEmptyTransportUsage, b as withProviderResponseHook, c as finalizeTerminalToolCallArguments, d as mergeTransportMetadata, f as notifyProviderHttpMetadata, g as sanitizeNonEmptyTransportPayloadText, h as parseTerminalToolCallArguments, i as copyProviderAcceptanceObserver, l as finalizeTransportStream, m as notifyProviderStreamOpened, n as assignTransportErrorDetails, o as createWritableTransportEventStream, p as notifyProviderHttpResponse, r as coerceTransportToolCallArguments, s as failTransportStream, t as IncompleteToolCallError, u as mergeTransportHeaders, v as transportAbortError, x as parseJsonObjectPreservingUnsafeIntegers, y as withProviderAcceptanceObserver } from "./transport-stream-shared-
|
|
16
|
+
import { C as quoteUnsafeIntegerLiterals, S as parseJsonPreservingUnsafeIntegers, _ as sanitizeTransportPayloadText, a as createEmptyTransportUsage, b as withProviderResponseHook, c as finalizeTerminalToolCallArguments, d as mergeTransportMetadata, f as notifyProviderHttpMetadata, g as sanitizeNonEmptyTransportPayloadText, h as parseTerminalToolCallArguments, i as copyProviderAcceptanceObserver, l as finalizeTransportStream, m as notifyProviderStreamOpened, n as assignTransportErrorDetails, o as createWritableTransportEventStream, p as notifyProviderHttpResponse, r as coerceTransportToolCallArguments, s as failTransportStream, t as IncompleteToolCallError, u as mergeTransportHeaders, v as transportAbortError, x as parseJsonObjectPreservingUnsafeIntegers, y as withProviderAcceptanceObserver } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
17
17
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
18
|
-
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-
|
|
18
|
+
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-DPr3w20a.mjs";
|
|
19
19
|
import { a as tagUnresolvedTextAsCommentary } from "./assistant-text-phase-C20rxWwP.mjs";
|
|
20
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
20
|
+
import { t as createAssistantOutput } from "./assistant-output-DM1JBNs1.mjs";
|
|
21
21
|
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-Bcunsn4I.mjs";
|
|
22
|
-
import { c as flattenCompletionMessagesToStringContent, d as canonicalizeMaxTokensParam, f as resolveMaxTokensParam, l as stripCompletionMessagesToRoleContent, n as shouldEmitOpenAICompletionsReasoning, o as isAzureOpenAICompatibleHost, p as createDeepSeekTextFilter, r as buildOpenAICompletionsParams, s as finalizeOpenAICompletionsToolCalls, t as processCompletionsStream, u as applyCompletionsAnthropicCacheControl } from "./openai-completions-stream-
|
|
23
|
-
import { a as googleFlashSupportsMinimalThinking, i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, t as convertGoogleTools } from "./google-messages-
|
|
24
|
-
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-
|
|
25
|
-
import {
|
|
26
|
-
import { r as resolveProviderTransportTurnState, t as filterProviderTurnHeadersForExplicitOpencodeSession } from "./provider-transport-turn-state-
|
|
27
|
-
import { a as applyOpenAIResponsesPayloadPolicy, c as resolveOpenAIResponsesServerCompactionPlan, i as sanitizeResponsesImagePayload, n as isOpenAIResponsesCompactionOutput, o as resolveOpenAIResponsesCompactEndpointPlan, s as resolveOpenAIResponsesPayloadPolicy, t as createBoundedOpenAIResponsesCompactionFetch } from "./openai-responses-compaction-window-
|
|
28
|
-
import { B as
|
|
22
|
+
import { c as flattenCompletionMessagesToStringContent, d as canonicalizeMaxTokensParam, f as resolveMaxTokensParam, l as stripCompletionMessagesToRoleContent, n as shouldEmitOpenAICompletionsReasoning, o as isAzureOpenAICompatibleHost, p as createDeepSeekTextFilter, r as buildOpenAICompletionsParams, s as finalizeOpenAICompletionsToolCalls, t as processCompletionsStream, u as applyCompletionsAnthropicCacheControl } from "./openai-completions-stream-BpuJ0ZOA.mjs";
|
|
23
|
+
import { a as googleFlashSupportsMinimalThinking, i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, t as convertGoogleTools } from "./google-messages-DB7GKkDk.mjs";
|
|
24
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-BeptfRL6.mjs";
|
|
25
|
+
import { d as OpenAIResponsesWebSocketSafeRetryError, i as OPENAI_RESPONSES_APIS, l as OpenAIResponsesWebSocketPostDispatchError, m as parseOpenAIResponsesWebSocketServerError, t as AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS, u as OpenAIResponsesWebSocketPreDispatchError } from "./openai-responses-contracts-DWrfMODE.mjs";
|
|
26
|
+
import { r as resolveProviderTransportTurnState, t as filterProviderTurnHeadersForExplicitOpencodeSession } from "./provider-transport-turn-state-lrXEFkYr.mjs";
|
|
27
|
+
import { a as applyOpenAIResponsesPayloadPolicy, c as resolveOpenAIResponsesServerCompactionPlan, i as sanitizeResponsesImagePayload, n as isOpenAIResponsesCompactionOutput, o as resolveOpenAIResponsesCompactEndpointPlan, s as resolveOpenAIResponsesPayloadPolicy, t as createBoundedOpenAIResponsesCompactionFetch } from "./openai-responses-compaction-window-BiNCT0bS.mjs";
|
|
28
|
+
import { A as summarizeOpenAITransportError, B as resolveResponsesContinuationRequest, C as createResponsesStreamWithEncryptedContentRetry, D as ResponsesStreamFailure, E as resolveNextResponsesEncryptedContentAttempt, G as supportsResponsesReasoningUpdate, H as responsesContinuationRequestFingerprint, I as createOpenAIResponsesAssistantOutput, J as captureOpenAIResponsesCompaction, K as CompactionReplayRefreshRequiredError, L as recordResponsesInputReplay, M as recordResponsesContextUsage, N as resolveResponsesContextUsageBoundary, O as logResponsesFailedNoDetails, Q as resolveReplayableResponsesMessageId, R as responsesInputFingerprint, T as resolveAzureOpenAIApiVersion, U as isConfigurationUpdate, V as responsesContinuationPrefixFingerprint, W as replayResponsesReasoningUpdates, X as resolveNewestOpenAIResponsesCompactionReplay, Y as isOpenAIResponsesReplayContext, Z as suppressOpenAIResponsesCompaction, j as summarizeResponsesPayload, k as safeDebugValue, l as processResponsesStream, n as applyResponsesServiceTierPricing, q as buildOpenAIResponsesReasoningReplayMetadata, u as observeResponsesStream, w as isInvalidEncryptedContentError, z as claimOpenAIResponsesHttpContinuation } from "./openai-responses-shared-DvSqtJ6_.mjs";
|
|
29
29
|
import { i as resolveAzureDeploymentNameFromMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "./azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
30
30
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
31
|
-
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
31
|
+
import { a as sanitizeOpenAICodexResponsesParams, n as buildOpenAIResponsesCompactSystemMessage, r as buildOpenAIResponsesParams, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-DPHWgbBH.mjs";
|
|
32
|
+
import { n as withResponsesRequestAcceptance, t as responsesRequestLifecycle } from "./openai-responses-request-lifecycle-DFuyO1pQ.mjs";
|
|
32
33
|
import { randomUUID } from "node:crypto";
|
|
33
34
|
import OpenAI, { AzureOpenAI } from "openai";
|
|
34
35
|
import { ResponsesWS } from "openai/resources/responses/ws.js";
|
|
@@ -211,19 +212,20 @@ function createAnthropicMessagesClient(params) {
|
|
|
211
212
|
};
|
|
212
213
|
} } };
|
|
213
214
|
}
|
|
214
|
-
function
|
|
215
|
-
const retryAfterSeconds = parseRetryAfterHeadersSeconds(response.headers);
|
|
216
|
-
const retryAfterSuffix = Number.isFinite(retryAfterSeconds) ? `; Retry-After: ${Math.ceil(retryAfterSeconds ?? 0)} seconds` : "";
|
|
217
|
-
return `HTTP ${response.status}: ${detail || "Anthropic Messages request failed"}${retryAfterSuffix}`;
|
|
218
|
-
}
|
|
219
|
-
async function readAnthropicMessagesErrorBodySnippet(response) {
|
|
215
|
+
async function readAnthropicMessagesErrorBody(response) {
|
|
220
216
|
try {
|
|
221
|
-
|
|
217
|
+
const text = await readResponseTextSnippet(response, {
|
|
222
218
|
maxBytes: ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES,
|
|
223
|
-
maxChars:
|
|
219
|
+
maxChars: ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES,
|
|
224
220
|
chunkTimeoutMs: ANTHROPIC_MESSAGES_ERROR_BODY_READ_IDLE_TIMEOUT_MS,
|
|
225
221
|
onIdleTimeout: ({ chunkTimeoutMs }) => /* @__PURE__ */ new Error(`Anthropic Messages error response stalled: no data received for ${chunkTimeoutMs}ms`)
|
|
226
222
|
}) ?? "";
|
|
223
|
+
try {
|
|
224
|
+
return JSON.parse(text);
|
|
225
|
+
} catch {
|
|
226
|
+
const redacted = redactDiagnosticText(text);
|
|
227
|
+
return redacted.length > ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS ? `${truncateUtf16Safe(redacted, ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS)}…` : redacted;
|
|
228
|
+
}
|
|
227
229
|
} catch (error) {
|
|
228
230
|
if (error instanceof Error && error.message.startsWith("Anthropic Messages error response stalled:")) return error.message;
|
|
229
231
|
return "";
|
|
@@ -251,7 +253,7 @@ function createAnthropicTransportClient(params) {
|
|
|
251
253
|
isOAuthToken: false
|
|
252
254
|
};
|
|
253
255
|
}
|
|
254
|
-
if (usesFoundryBearerAuth(resolveModelHeaderSentinels
|
|
256
|
+
if (usesFoundryBearerAuth(resolveModelHeaderSentinels(model))) {
|
|
255
257
|
const betaFeatures = needsInterleavedBeta ? ["interleaved-thinking-2025-05-14"] : [];
|
|
256
258
|
return {
|
|
257
259
|
client: createAnthropicMessagesClient({
|
|
@@ -272,21 +274,17 @@ function createAnthropicTransportClient(params) {
|
|
|
272
274
|
if (needsInterleavedBeta) betaFeatures.push("interleaved-thinking-2025-05-14");
|
|
273
275
|
if (isAnthropicOAuthApiKey(apiKey)) {
|
|
274
276
|
const betaHeader = buildAnthropicBetaHeader(model, betaFeatures, { oauth: true });
|
|
277
|
+
const identity = buildAnthropicClaudeCodeIdentity(betaHeader, model.headers, optionHeaders);
|
|
275
278
|
return {
|
|
276
279
|
client: createAnthropicMessagesClient({
|
|
277
280
|
apiKey: null,
|
|
278
281
|
authToken: apiKey,
|
|
279
282
|
baseURL: model.baseUrl,
|
|
280
|
-
defaultHeaders:
|
|
281
|
-
accept: "application/json",
|
|
282
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
283
|
-
...betaHeader ? { "anthropic-beta": betaHeader } : {},
|
|
284
|
-
"user-agent": `claude-cli/${ANTHROPIC_CLAUDE_CODE_VERSION}`,
|
|
285
|
-
"x-app": "cli"
|
|
286
|
-
}, model.headers, optionHeaders),
|
|
283
|
+
defaultHeaders: identity.headers,
|
|
287
284
|
fetch
|
|
288
285
|
}),
|
|
289
|
-
isOAuthToken: true
|
|
286
|
+
isOAuthToken: true,
|
|
287
|
+
claudeCodeVersion: identity.version
|
|
290
288
|
};
|
|
291
289
|
}
|
|
292
290
|
if (useAnthropicServerSideFallback(model)) betaFeatures.push(ANTHROPIC_SERVER_SIDE_FALLBACK_BETA);
|
|
@@ -307,7 +305,7 @@ function createAnthropicTransportClient(params) {
|
|
|
307
305
|
directApiKeyBetaHeader: isDirectAnthropicModel(model) ? new Headers(defaultHeaders).get("anthropic-beta") ?? "" : void 0
|
|
308
306
|
};
|
|
309
307
|
}
|
|
310
|
-
async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
308
|
+
async function buildAnthropicParams(model, context, isOAuthToken, options, claudeCodeVersion) {
|
|
311
309
|
const replayThinkingEnabled = requiresClaudeAdaptiveThinking(model) || options?.thinkingEnabled === true;
|
|
312
310
|
const maxTokens = resolveAnthropicMessagesMaxTokens({
|
|
313
311
|
modelContextWindow: model.contextWindow,
|
|
@@ -325,6 +323,7 @@ async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
|
325
323
|
const messages = await convertAnthropicMessages(transformTransportMessages(replayPlan.messages, model, normalizeAnthropicToolCallId), model, isOAuthToken, {
|
|
326
324
|
profile: "transport",
|
|
327
325
|
allowReasoningContentReplay: supportsReasoningContentReplay(model),
|
|
326
|
+
allowEmptySignature: model.compat?.allowEmptySignature,
|
|
328
327
|
compaction: replayPlan.compaction,
|
|
329
328
|
replayThinkingEnabled,
|
|
330
329
|
cacheBreakpointOptOutMessageIndexes
|
|
@@ -336,7 +335,7 @@ async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
|
336
335
|
stream: true
|
|
337
336
|
};
|
|
338
337
|
if (!isOAuthToken && useAnthropicServerSideFallback(model)) params.fallbacks = ANTHROPIC_SERVER_SIDE_FALLBACKS;
|
|
339
|
-
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthToken, cacheControl);
|
|
338
|
+
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthToken, cacheControl, claudeCodeVersion);
|
|
340
339
|
if (system) params.system = system;
|
|
341
340
|
const convertedTools = context.tools ? convertAnthropicTools(context.tools, isOAuthToken) : void 0;
|
|
342
341
|
const toolProjection = convertedTools?.projection;
|
|
@@ -393,7 +392,7 @@ function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
|
393
392
|
}
|
|
394
393
|
if (!reasoning) {
|
|
395
394
|
resolved.thinkingEnabled = defaultsClaudeAdaptiveThinking(model);
|
|
396
|
-
if (resolved.thinkingEnabled) resolved.effort =
|
|
395
|
+
if (resolved.thinkingEnabled) resolved.effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
397
396
|
return resolved;
|
|
398
397
|
}
|
|
399
398
|
if (supportsClaudeAdaptiveThinking(model)) {
|
|
@@ -423,16 +422,15 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
423
422
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
424
423
|
const transportOptions = resolveAnthropicTransportOptions(model, options, apiKey);
|
|
425
424
|
const requestContext = prepareClaudeNoPrefillRequestContext(model, context);
|
|
426
|
-
const { client, isOAuthToken, directApiKeyBetaHeader } = createAnthropicTransportClient({
|
|
425
|
+
const { client, isOAuthToken, directApiKeyBetaHeader, claudeCodeVersion } = createAnthropicTransportClient({
|
|
427
426
|
model,
|
|
428
427
|
context: requestContext,
|
|
429
428
|
apiKey,
|
|
430
429
|
options: transportOptions
|
|
431
430
|
});
|
|
432
|
-
const builtParams = await buildAnthropicParams(model, requestContext, isOAuthToken, transportOptions);
|
|
431
|
+
const builtParams = await buildAnthropicParams(model, requestContext, isOAuthToken, transportOptions, claudeCodeVersion);
|
|
433
432
|
usedCompactionReplay = builtParams.usedCompactionReplay;
|
|
434
433
|
let params = builtParams.params;
|
|
435
|
-
const toolProjection = builtParams.toolProjection;
|
|
436
434
|
applyAnthropicContextManagementToRequest(params, model, transportOptions, directApiKeyBetaHeader);
|
|
437
435
|
const nextParams = await transportOptions.onPayload?.(params, model);
|
|
438
436
|
if (nextParams !== void 0) params = nextParams;
|
|
@@ -452,8 +450,12 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
452
450
|
model
|
|
453
451
|
});
|
|
454
452
|
if (!response.ok) {
|
|
455
|
-
const
|
|
456
|
-
throw new Error(
|
|
453
|
+
const errorBody = await readAnthropicMessagesErrorBody(response);
|
|
454
|
+
throw Object.assign(/* @__PURE__ */ new Error(`${response.status} status code (no body)`), {
|
|
455
|
+
status: response.status,
|
|
456
|
+
headers: response.headers,
|
|
457
|
+
errorBody
|
|
458
|
+
});
|
|
457
459
|
}
|
|
458
460
|
await consumeAnthropicStream({
|
|
459
461
|
events: anthropicStream,
|
|
@@ -463,7 +465,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
463
465
|
stream,
|
|
464
466
|
refusalBuffer,
|
|
465
467
|
isOAuthToken,
|
|
466
|
-
toolProjection,
|
|
468
|
+
toolProjection: builtParams.toolProjection,
|
|
467
469
|
profile: "transport"
|
|
468
470
|
});
|
|
469
471
|
finalizeTransportStream({
|
|
@@ -481,7 +483,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
481
483
|
refusalBuffer.discard();
|
|
482
484
|
output.content = [];
|
|
483
485
|
} else output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
484
|
-
if (usedCompactionReplay && isAnthropicReplayRejection(
|
|
486
|
+
if (usedCompactionReplay && isAnthropicReplayRejection(output)) suppressAnthropicCompaction(output, model, options);
|
|
485
487
|
for (const block of output.content) delete block.index;
|
|
486
488
|
}
|
|
487
489
|
});
|
|
@@ -567,8 +569,8 @@ function createSseDoneDetector() {
|
|
|
567
569
|
sawDone: () => sawDone
|
|
568
570
|
};
|
|
569
571
|
}
|
|
570
|
-
function createOpenAICompletionsClient(model,
|
|
571
|
-
const clientConfig = buildOpenAICompletionsClientConfig(model,
|
|
572
|
+
function createOpenAICompletionsClient(model, apiKey, headers, opts) {
|
|
573
|
+
const clientConfig = buildOpenAICompletionsClientConfig(model, headers);
|
|
572
574
|
return new OpenAI({
|
|
573
575
|
apiKey,
|
|
574
576
|
baseURL: clientConfig.baseURL,
|
|
@@ -579,8 +581,7 @@ function createOpenAICompletionsClient(model, context, apiKey, optionHeaders, op
|
|
|
579
581
|
...buildOpenAISdkClientOptions(model)
|
|
580
582
|
});
|
|
581
583
|
}
|
|
582
|
-
function buildOpenAICompletionsClientConfig(model,
|
|
583
|
-
const headers = buildOpenAIClientHeaders(model, context, optionHeaders);
|
|
584
|
+
function buildOpenAICompletionsClientConfig(model, headers) {
|
|
584
585
|
const defaultQuery = {};
|
|
585
586
|
let baseURL = model.baseUrl;
|
|
586
587
|
let isAzureHost = false;
|
|
@@ -666,10 +667,11 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
666
667
|
statusText: response.statusText
|
|
667
668
|
});
|
|
668
669
|
};
|
|
669
|
-
const
|
|
670
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
671
|
+
const client = createOpenAICompletionsClient(model, apiKey, buildOpenAIClientHeaders(model, context, {
|
|
670
672
|
...turnHeaders,
|
|
671
673
|
...optionHeaders
|
|
672
|
-
}, { fetch: doneDetectingFetch });
|
|
674
|
+
}, void 0, resolvePromptCacheKey(options, cacheRetention), cacheRetention), { fetch: doneDetectingFetch });
|
|
673
675
|
let params = buildOpenAICompletionsParams(model, context, options);
|
|
674
676
|
const nextParams = await options?.onPayload?.(params, model);
|
|
675
677
|
if (nextParams !== void 0) params = nextParams;
|
|
@@ -726,374 +728,6 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
726
728
|
};
|
|
727
729
|
}
|
|
728
730
|
//#endregion
|
|
729
|
-
//#region packages/ai/src/transports/openai-responses-params-internal.ts
|
|
730
|
-
const OPENAI_RESPONSES_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set([
|
|
731
|
-
"openai",
|
|
732
|
-
"opencode",
|
|
733
|
-
"azure-openai-responses",
|
|
734
|
-
"github-copilot"
|
|
735
|
-
]);
|
|
736
|
-
function resolveOpenAIReasoningEffort(options) {
|
|
737
|
-
return normalizeOpenAIReasoningEffort(options?.reasoningEffort ?? options?.reasoning ?? "high");
|
|
738
|
-
}
|
|
739
|
-
function hasResponsesWebSearchTool(tools) {
|
|
740
|
-
if (!Array.isArray(tools)) return false;
|
|
741
|
-
return tools.some((tool) => {
|
|
742
|
-
if (!isRecord(tool)) return false;
|
|
743
|
-
if (tool.type === "web_search") return true;
|
|
744
|
-
if (tool.type === "function" && tool.name === "web_search") return true;
|
|
745
|
-
const fn = tool.function;
|
|
746
|
-
return isRecord(fn) && fn.name === "web_search";
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
function raiseMinimalReasoningForResponsesWebSearch(params) {
|
|
750
|
-
if (params.effort !== "minimal" || !hasResponsesWebSearchTool(params.tools)) return params.effort;
|
|
751
|
-
for (const effort of [
|
|
752
|
-
"low",
|
|
753
|
-
"medium",
|
|
754
|
-
"high"
|
|
755
|
-
]) {
|
|
756
|
-
const resolved = resolveOpenAIReasoningEffortForModel({
|
|
757
|
-
model: params.model,
|
|
758
|
-
effort
|
|
759
|
-
});
|
|
760
|
-
if (resolved && resolved !== "none" && resolved !== "minimal") return resolved;
|
|
761
|
-
}
|
|
762
|
-
return params.effort;
|
|
763
|
-
}
|
|
764
|
-
const OPENAI_CODEX_RESPONSES_UNSUPPORTED_PARAMS = [
|
|
765
|
-
"max_output_tokens",
|
|
766
|
-
"metadata",
|
|
767
|
-
"prompt_cache_retention",
|
|
768
|
-
"prompt_cache_options",
|
|
769
|
-
"service_tier",
|
|
770
|
-
"temperature",
|
|
771
|
-
"top_p"
|
|
772
|
-
];
|
|
773
|
-
function stripOpenAICodexResponsesUnsupportedTextFields(params) {
|
|
774
|
-
const text = params.text;
|
|
775
|
-
if (!text || typeof text !== "object" || Array.isArray(text)) return;
|
|
776
|
-
const sanitizedText = { ...text };
|
|
777
|
-
delete sanitizedText.format;
|
|
778
|
-
if (Object.keys(sanitizedText).length > 0) params.text = sanitizedText;
|
|
779
|
-
else delete params.text;
|
|
780
|
-
}
|
|
781
|
-
function sanitizeOpenAICodexResponsesParams(model, params) {
|
|
782
|
-
if (!usesNativeOpenAICodexResponsesBackend(model)) return params;
|
|
783
|
-
for (const key of OPENAI_CODEX_RESPONSES_UNSUPPORTED_PARAMS) delete params[key];
|
|
784
|
-
Object.assign(params, { store: false });
|
|
785
|
-
stripOpenAICodexResponsesUnsupportedTextFields(params);
|
|
786
|
-
return params;
|
|
787
|
-
}
|
|
788
|
-
function buildOpenAIResponsesInstructionsText(context) {
|
|
789
|
-
if (!context.systemPrompt) return;
|
|
790
|
-
return sanitizeTransportPayloadText(stripSystemPromptCacheBoundary(context.systemPrompt));
|
|
791
|
-
}
|
|
792
|
-
function resolveOpenAIResponsesInstructions(model, context, usesInstructionsField) {
|
|
793
|
-
if (!usesInstructionsField) return;
|
|
794
|
-
const instructions = buildOpenAIResponsesInstructionsText(context);
|
|
795
|
-
if (instructions && instructions.trim().length > 0) return instructions;
|
|
796
|
-
return usesNativeOpenAICodexResponsesBackend(model) ? OPENAI_CODEX_RESPONSES_DEFAULT_INSTRUCTIONS : void 0;
|
|
797
|
-
}
|
|
798
|
-
function buildOpenAIResponsesCompactSystemMessage(model, instructions) {
|
|
799
|
-
const compat = getCompat(model);
|
|
800
|
-
const supportsDeveloperRole = typeof compat.supportsDeveloperRole === "boolean" ? compat.supportsDeveloperRole : void 0;
|
|
801
|
-
const role = model.reasoning && supportsDeveloperRole !== false ? "developer" : "system";
|
|
802
|
-
return buildResponsesInputMessage(role, [{
|
|
803
|
-
type: "input_text",
|
|
804
|
-
text: instructions
|
|
805
|
-
}]);
|
|
806
|
-
}
|
|
807
|
-
function ensureOpenAIResponsesNonEmptyInput(messages, context) {
|
|
808
|
-
if (messages.length > 0 || !context.systemPrompt) return;
|
|
809
|
-
if (!buildOpenAIResponsesInstructionsText(context)) throw new Error("OpenAI Responses requires non-empty input when only systemPrompt is provided.");
|
|
810
|
-
messages.push(buildResponsesInputMessage("user", [{
|
|
811
|
-
type: "input_text",
|
|
812
|
-
text: " "
|
|
813
|
-
}]));
|
|
814
|
-
}
|
|
815
|
-
function resolveOpenAIResponsesTextFormat(responseFormat) {
|
|
816
|
-
if (responseFormat.type === "json_schema" && responseFormat.json_schema && typeof responseFormat.json_schema === "object" && !Array.isArray(responseFormat.json_schema)) return {
|
|
817
|
-
...responseFormat.json_schema,
|
|
818
|
-
type: "json_schema"
|
|
819
|
-
};
|
|
820
|
-
return responseFormat;
|
|
821
|
-
}
|
|
822
|
-
function convertOpenAIResponsesMessagesForRequest(model, context, options, replayMode) {
|
|
823
|
-
const isNativeCodexResponses = usesNativeOpenAICodexResponsesBackend(model);
|
|
824
|
-
const payloadPolicy = resolveOpenAIResponsesPayloadPolicy(model, { storeMode: "disable" });
|
|
825
|
-
const policyAllowsReplayIds = payloadPolicy.explicitStore !== false && !payloadPolicy.shouldStripStore;
|
|
826
|
-
const replayResponsesItemIds = !isNativeCodexResponses && (options?.replayResponsesItemIds ?? policyAllowsReplayIds);
|
|
827
|
-
return convertResponsesMessages(model, context, OPENAI_RESPONSES_TOOL_CALL_PROVIDERS, {
|
|
828
|
-
includeSystemPrompt: !payloadPolicy.usesInstructionsField,
|
|
829
|
-
replayReasoningItems: true,
|
|
830
|
-
replayResponsesItemIds,
|
|
831
|
-
authProfileId: options?.authProfileId,
|
|
832
|
-
sessionId: options?.sessionId,
|
|
833
|
-
replayMode
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
function buildOpenAIResponsesParams(model, context, options, metadata, replayMode = "checkpoint") {
|
|
837
|
-
const payloadPolicy = resolveOpenAIResponsesPayloadPolicy(model, { storeMode: "disable" });
|
|
838
|
-
const messages = convertOpenAIResponsesMessagesForRequest(model, context, options, replayMode);
|
|
839
|
-
ensureOpenAIResponsesNonEmptyInput(messages, context);
|
|
840
|
-
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
841
|
-
const compat = getCompat(model);
|
|
842
|
-
const promptCacheKey = compat.supportsPromptCacheKey ? resolvePromptCacheKey(options, cacheRetention) : void 0;
|
|
843
|
-
const instructions = resolveOpenAIResponsesInstructions(model, context, payloadPolicy.usesInstructionsField);
|
|
844
|
-
const params = {
|
|
845
|
-
model: model.id,
|
|
846
|
-
input: messages,
|
|
847
|
-
stream: true,
|
|
848
|
-
prompt_cache_key: promptCacheKey,
|
|
849
|
-
...resolveOpenAIPromptCacheParams(model, cacheRetention, compat),
|
|
850
|
-
...instructions ? { instructions } : {},
|
|
851
|
-
...metadata ? { metadata } : {}
|
|
852
|
-
};
|
|
853
|
-
const effectiveMaxTokens = options?.maxTokens || model.maxTokens;
|
|
854
|
-
if (effectiveMaxTokens) params.max_output_tokens = Math.max(effectiveMaxTokens, 16);
|
|
855
|
-
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) params.temperature = options.temperature;
|
|
856
|
-
if (options?.topP !== void 0 && model.id !== "gpt-6-astra") params.top_p = options.topP;
|
|
857
|
-
if (options?.responseFormat !== void 0) params.text = {
|
|
858
|
-
...params.text,
|
|
859
|
-
format: resolveOpenAIResponsesTextFormat(options.responseFormat)
|
|
860
|
-
};
|
|
861
|
-
if (options?.serviceTier !== void 0 && payloadPolicy.allowsServiceTier) params.service_tier = options.serviceTier;
|
|
862
|
-
if (context.tools) {
|
|
863
|
-
const tools = context.tools;
|
|
864
|
-
const strict = resolveOpenAIStrictToolSetting(model, { transport: "stream" });
|
|
865
|
-
const projection = projectOpenAITools(tools);
|
|
866
|
-
const converted = convertProjectedResponsesTools(projection, strict, model);
|
|
867
|
-
if (converted.length > 0 || projection.inputToolCount === 0 && projection.diagnostics.length === 0) params.tools = converted;
|
|
868
|
-
if (options?.toolChoice) {
|
|
869
|
-
const toolChoice = reconcileOpenAIResponsesToolChoice(options.toolChoice, projection);
|
|
870
|
-
if (toolChoice !== void 0) params.tool_choice = toolChoice;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
if (model.reasoning) {
|
|
874
|
-
if (options?.reasoningEffort || options?.reasoning || options?.reasoningSummary) {
|
|
875
|
-
const requestedReasoningEffort = resolveOpenAIReasoningEffort(options);
|
|
876
|
-
const resolvedReasoningEffort = resolveOpenAIReasoningEffortForModel({
|
|
877
|
-
model,
|
|
878
|
-
effort: requestedReasoningEffort
|
|
879
|
-
});
|
|
880
|
-
const reasoningEffort = resolvedReasoningEffort ? raiseMinimalReasoningForResponsesWebSearch({
|
|
881
|
-
model,
|
|
882
|
-
effort: resolvedReasoningEffort,
|
|
883
|
-
tools: params.tools
|
|
884
|
-
}) : void 0;
|
|
885
|
-
if (reasoningEffort) {
|
|
886
|
-
params.reasoning = {
|
|
887
|
-
effort: reasoningEffort,
|
|
888
|
-
...reasoningEffort === "none" ? {} : { summary: options?.reasoningSummary || "auto" }
|
|
889
|
-
};
|
|
890
|
-
if (reasoningEffort !== "none") params.include = ["reasoning.encrypted_content"];
|
|
891
|
-
}
|
|
892
|
-
} else if (model.provider !== "github-copilot") {
|
|
893
|
-
const reasoningEffort = resolveOpenAIReasoningEffortForModel({
|
|
894
|
-
model,
|
|
895
|
-
effort: "none"
|
|
896
|
-
});
|
|
897
|
-
if (reasoningEffort) params.reasoning = { effort: reasoningEffort };
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
applyOpenAIResponsesPayloadPolicy(params, payloadPolicy);
|
|
901
|
-
return sanitizeOpenAICodexResponsesParams(model, params);
|
|
902
|
-
}
|
|
903
|
-
//#endregion
|
|
904
|
-
//#region packages/ai/src/transports/openai-responses-reasoning-update.ts
|
|
905
|
-
function isConfigurationUpdate(value) {
|
|
906
|
-
return isRecord(value) && value.type === "configuration_update" && isRecord(value.reasoning) && typeof value.reasoning.effort === "string";
|
|
907
|
-
}
|
|
908
|
-
function isResponsesReasoningUpdateCompatible(request) {
|
|
909
|
-
const mode = isRecord(request.reasoning) ? request.reasoning.mode : void 0;
|
|
910
|
-
return request.model === "gpt-6-astra" && (mode === void 0 || mode === "standard") && (!isRecord(request.multi_agent) || request.multi_agent.enabled !== true) && request.truncation !== "auto" && (!Array.isArray(request.context_management) || !request.context_management.some((item) => isRecord(item) && item.type === "compaction"));
|
|
911
|
-
}
|
|
912
|
-
function supportsResponsesReasoningUpdate(request) {
|
|
913
|
-
return isResponsesReasoningUpdateCompatible(request) && isRecord(request.reasoning) && typeof request.reasoning.effort === "string";
|
|
914
|
-
}
|
|
915
|
-
function canReferenceResponsesReasoningHistory(previous, request) {
|
|
916
|
-
return !previous.input?.some(isConfigurationUpdate) || isResponsesReasoningUpdateCompatible(request);
|
|
917
|
-
}
|
|
918
|
-
/** Rehydrate input controls only provisionally; continuation must validate the full prefix. */
|
|
919
|
-
function replayResponsesReasoningUpdates(previous, request, previousOutputLength, steering) {
|
|
920
|
-
if (steering !== "required-input" && (!supportsResponsesReasoningUpdate(previous) || !supportsResponsesReasoningUpdate(request)) || !Array.isArray(previous.input) || !Array.isArray(request.input) || request.input.some(isConfigurationUpdate)) return request;
|
|
921
|
-
const input = [...request.input];
|
|
922
|
-
let activeEffort = isRecord(previous.reasoning) ? previous.reasoning.effort : void 0;
|
|
923
|
-
for (const [index, item] of previous.input.entries()) if (isConfigurationUpdate(item)) {
|
|
924
|
-
input.splice(index, 0, item);
|
|
925
|
-
activeEffort = item.reasoning.effort;
|
|
926
|
-
}
|
|
927
|
-
if (steering === "required-input") return input.length === request.input.length ? request : {
|
|
928
|
-
...request,
|
|
929
|
-
input
|
|
930
|
-
};
|
|
931
|
-
if (!isRecord(previous.reasoning) || !isRecord(request.reasoning) || typeof request.reasoning.effort !== "string") return request;
|
|
932
|
-
if (activeEffort !== request.reasoning.effort && steering !== "automatic") {
|
|
933
|
-
const baselineLength = previous.input.length + previousOutputLength;
|
|
934
|
-
const nextUser = input.findIndex((item, index) => index >= baselineLength && "role" in item && item.role === "user");
|
|
935
|
-
if (nextUser === -1) return request;
|
|
936
|
-
input.splice(nextUser, 0, {
|
|
937
|
-
type: "configuration_update",
|
|
938
|
-
reasoning: { effort: request.reasoning.effort }
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
if (input.length === request.input.length && activeEffort === request.reasoning.effort) return request;
|
|
942
|
-
return {
|
|
943
|
-
...request,
|
|
944
|
-
reasoning: {
|
|
945
|
-
...request.reasoning,
|
|
946
|
-
effort: previous.reasoning.effort
|
|
947
|
-
},
|
|
948
|
-
input
|
|
949
|
-
};
|
|
950
|
-
}
|
|
951
|
-
//#endregion
|
|
952
|
-
//#region packages/ai/src/transports/openai-responses-continuation.ts
|
|
953
|
-
const HTTP_CONTINUATION_IDLE_TTL_MS = 3e5;
|
|
954
|
-
const TURN_HEADERS = /* @__PURE__ */ new Set([
|
|
955
|
-
"traceparent",
|
|
956
|
-
"x-openclaw-turn-id",
|
|
957
|
-
"x-openclaw-turn-attempt"
|
|
958
|
-
]);
|
|
959
|
-
function jsonValuesEqual(left, right) {
|
|
960
|
-
const leftJson = JSON.stringify(left);
|
|
961
|
-
const normalizedLeft = stableStringify(JSON.parse(leftJson));
|
|
962
|
-
const rightJson = JSON.stringify(right);
|
|
963
|
-
return leftJson === rightJson || normalizedLeft === stableStringify(JSON.parse(rightJson));
|
|
964
|
-
}
|
|
965
|
-
function requestWithoutInput(request) {
|
|
966
|
-
const { input: _input, previous_response_id: _previousResponseId, instructions: _instructions, tools: _tools, ...rest } = request;
|
|
967
|
-
if (!isRecord(rest.metadata)) return rest;
|
|
968
|
-
const metadata = Object.fromEntries(Object.entries(rest.metadata).filter(([key]) => key !== "openclaw_turn_id" && key !== "openclaw_turn_attempt"));
|
|
969
|
-
return {
|
|
970
|
-
...rest,
|
|
971
|
-
metadata
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
function normalizeAssistantReplayInput(input, fromResponse = false) {
|
|
975
|
-
return input.map((item) => {
|
|
976
|
-
if (!isRecord(item)) return item;
|
|
977
|
-
if (item.type === "reasoning") return { type: "reasoning" };
|
|
978
|
-
if (item.type !== "function_call" && !(item.type === "message" && item.role === "assistant")) return item;
|
|
979
|
-
const { id: _id, status: _status, ...stableItem } = item;
|
|
980
|
-
if (fromResponse && item.type === "function_call") {
|
|
981
|
-
const args = parseJsonObjectPreservingUnsafeIntegers(stableItem.arguments);
|
|
982
|
-
stableItem.arguments = args ? JSON.stringify(args) : stableItem.arguments;
|
|
983
|
-
}
|
|
984
|
-
if (item.type === "message" && Array.isArray(stableItem.content)) stableItem.content = stableItem.content.map((part) => {
|
|
985
|
-
if (!isRecord(part) || part.type !== "output_text") return part;
|
|
986
|
-
const { annotations: _annotations, logprobs: _logprobs, ...stablePart } = part;
|
|
987
|
-
return stablePart;
|
|
988
|
-
});
|
|
989
|
-
return stableItem;
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
function responsesContinuationRequestFingerprint(request) {
|
|
993
|
-
const serialized = JSON.stringify(requestWithoutInput(request));
|
|
994
|
-
return sha256Hex(stableStringify(JSON.parse(serialized)));
|
|
995
|
-
}
|
|
996
|
-
function responsesContinuationPrefixFingerprint(input, output = []) {
|
|
997
|
-
const serialized = JSON.stringify([...normalizeAssistantReplayInput(input), ...normalizeAssistantReplayInput(output, true)]);
|
|
998
|
-
return sha256Hex(stableStringify(JSON.parse(serialized)));
|
|
999
|
-
}
|
|
1000
|
-
function resolveResponsesContinuationRequest(continuation, request, steering) {
|
|
1001
|
-
if (!continuation) return {
|
|
1002
|
-
request,
|
|
1003
|
-
continuationStatus: "no_previous_response"
|
|
1004
|
-
};
|
|
1005
|
-
if (request.previous_response_id) return {
|
|
1006
|
-
request,
|
|
1007
|
-
continuationStatus: "explicit_previous_response_id"
|
|
1008
|
-
};
|
|
1009
|
-
if (!canReferenceResponsesReasoningHistory(continuation.lastRequest, request)) return {
|
|
1010
|
-
request,
|
|
1011
|
-
continuationStatus: "request_changed"
|
|
1012
|
-
};
|
|
1013
|
-
const prepared = replayResponsesReasoningUpdates(continuation.lastRequest, request, continuation.lastResponseItems.length, steering);
|
|
1014
|
-
if (steering !== "required-input" && !jsonValuesEqual(requestWithoutInput(prepared), requestWithoutInput(continuation.lastRequest))) return {
|
|
1015
|
-
request,
|
|
1016
|
-
continuationStatus: "request_changed"
|
|
1017
|
-
};
|
|
1018
|
-
const currentInput = prepared.input ?? [];
|
|
1019
|
-
const previousInput = continuation.lastRequest.input ?? [];
|
|
1020
|
-
const baselineLength = previousInput.length + continuation.lastResponseItems.length;
|
|
1021
|
-
if (currentInput.length < baselineLength) return {
|
|
1022
|
-
request,
|
|
1023
|
-
continuationStatus: "history_shorter"
|
|
1024
|
-
};
|
|
1025
|
-
if (!jsonValuesEqual(normalizeAssistantReplayInput(currentInput.slice(0, previousInput.length)), normalizeAssistantReplayInput(previousInput)) || !jsonValuesEqual(normalizeAssistantReplayInput(currentInput.slice(previousInput.length, baselineLength)), normalizeAssistantReplayInput(continuation.lastResponseItems, true))) return {
|
|
1026
|
-
request,
|
|
1027
|
-
continuationStatus: "history_changed"
|
|
1028
|
-
};
|
|
1029
|
-
return {
|
|
1030
|
-
request: {
|
|
1031
|
-
...prepared,
|
|
1032
|
-
previous_response_id: continuation.lastResponseId,
|
|
1033
|
-
input: currentInput.slice(baselineLength)
|
|
1034
|
-
},
|
|
1035
|
-
...prepared !== request ? { fullRequest: prepared } : {},
|
|
1036
|
-
continuationStatus: "continued"
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
const httpContinuationEntries = /* @__PURE__ */ new Map();
|
|
1040
|
-
function deleteHttpContinuationIfOwned(key, entry) {
|
|
1041
|
-
if (httpContinuationEntries.get(key) === entry) httpContinuationEntries.delete(key);
|
|
1042
|
-
}
|
|
1043
|
-
function connectionIdentity(params) {
|
|
1044
|
-
const headers = Object.entries(resolveAiTransportHeaderSentinels(params.headers) ?? {}).map(([name, value]) => [name.toLowerCase(), value]).filter(([name]) => !TURN_HEADERS.has(name)).toSorted(([a], [b]) => a.localeCompare(b));
|
|
1045
|
-
return sha256Hex(JSON.stringify([
|
|
1046
|
-
getAiTransportHost().resolveSecretSentinel(params.apiKey),
|
|
1047
|
-
params.baseUrl,
|
|
1048
|
-
headers
|
|
1049
|
-
]));
|
|
1050
|
-
}
|
|
1051
|
-
function claimOpenAIResponsesHttpContinuation(params) {
|
|
1052
|
-
const key = `${params.sessionId}\0${connectionIdentity(params)}`;
|
|
1053
|
-
const previous = httpContinuationEntries.get(key);
|
|
1054
|
-
if (previous?.kind === "claimed") return;
|
|
1055
|
-
if (previous?.kind === "ready") clearTimeout(previous.idleTimer);
|
|
1056
|
-
const claimed = {
|
|
1057
|
-
kind: "claimed",
|
|
1058
|
-
sessionId: params.sessionId
|
|
1059
|
-
};
|
|
1060
|
-
httpContinuationEntries.set(key, claimed);
|
|
1061
|
-
try {
|
|
1062
|
-
const request = previous?.kind === "ready" ? params.request : params.restoreRequest?.() ?? params.request;
|
|
1063
|
-
const resolved = resolveResponsesContinuationRequest(previous?.kind === "ready" ? previous.state : void 0, request);
|
|
1064
|
-
const fullRequest = resolved.fullRequest ?? request;
|
|
1065
|
-
return {
|
|
1066
|
-
request: params.request.store === false ? fullRequest : resolved.request,
|
|
1067
|
-
fullRequest,
|
|
1068
|
-
commit: (effectiveRequest, response) => {
|
|
1069
|
-
if (httpContinuationEntries.get(key) !== claimed) return;
|
|
1070
|
-
const ready = {
|
|
1071
|
-
...claimed,
|
|
1072
|
-
kind: "ready",
|
|
1073
|
-
state: {
|
|
1074
|
-
lastRequest: effectiveRequest,
|
|
1075
|
-
lastResponseId: response.id,
|
|
1076
|
-
lastResponseItems: response.output
|
|
1077
|
-
},
|
|
1078
|
-
idleTimer: setTimeout(() => deleteHttpContinuationIfOwned(key, ready), HTTP_CONTINUATION_IDLE_TTL_MS)
|
|
1079
|
-
};
|
|
1080
|
-
ready.idleTimer.unref?.();
|
|
1081
|
-
httpContinuationEntries.set(key, ready);
|
|
1082
|
-
},
|
|
1083
|
-
release: () => deleteHttpContinuationIfOwned(key, claimed)
|
|
1084
|
-
};
|
|
1085
|
-
} catch (error) {
|
|
1086
|
-
deleteHttpContinuationIfOwned(key, claimed);
|
|
1087
|
-
throw error;
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
registerSessionResourceCleanup((sessionId) => {
|
|
1091
|
-
for (const [key, entry] of httpContinuationEntries) if (!sessionId || entry.sessionId === sessionId) {
|
|
1092
|
-
if (entry.kind === "ready") clearTimeout(entry.idleTimer);
|
|
1093
|
-
httpContinuationEntries.delete(key);
|
|
1094
|
-
}
|
|
1095
|
-
});
|
|
1096
|
-
//#endregion
|
|
1097
731
|
//#region packages/ai/src/transports/openai-responses-steering.ts
|
|
1098
732
|
function cloneWireRequest(request) {
|
|
1099
733
|
const serialized = JSON.stringify(request);
|
|
@@ -1700,6 +1334,36 @@ function restoreResponsesReasoningState(context, model, identity, request) {
|
|
|
1700
1334
|
return prepared;
|
|
1701
1335
|
}
|
|
1702
1336
|
//#endregion
|
|
1337
|
+
//#region packages/ai/src/transports/openai-responses-request-fetch.ts
|
|
1338
|
+
function withDefaultResponsesStreamEncoding(fetch) {
|
|
1339
|
+
return (input, init) => {
|
|
1340
|
+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
|
|
1341
|
+
if (headers.has("accept-encoding")) return fetch(input, init);
|
|
1342
|
+
headers.set("accept-encoding", "identity");
|
|
1343
|
+
return fetch(input, {
|
|
1344
|
+
...init,
|
|
1345
|
+
headers
|
|
1346
|
+
});
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
/** Preserve the existing fetch policy while binding explicit continuation dispatch to its signal. */
|
|
1350
|
+
function createResponsesRequestFetch(model, options) {
|
|
1351
|
+
const lifecycle = options.lifecycle;
|
|
1352
|
+
if (lifecycle && options.compact) throw new Error("Provider review continuation cannot replace its reviewed input with compaction");
|
|
1353
|
+
let fetchOverride = options.compact ? createBoundedOpenAIResponsesCompactionFetch(buildGuardedModelFetch(model)) : options.stream ? withDefaultResponsesStreamEncoding(buildGuardedModelFetch(model)) : void 0;
|
|
1354
|
+
if (lifecycle) {
|
|
1355
|
+
const dispatchFetch = fetchOverride ?? buildGuardedModelFetch(model);
|
|
1356
|
+
fetchOverride = async (input, init) => {
|
|
1357
|
+
const signal = init?.signal ?? (input instanceof Request ? input.signal : void 0);
|
|
1358
|
+
await lifecycle.beforeDispatch(signal ?? void 0);
|
|
1359
|
+
signal?.throwIfAborted();
|
|
1360
|
+
lifecycle.assertCurrent();
|
|
1361
|
+
return dispatchFetch(input, init);
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
return fetchOverride;
|
|
1365
|
+
}
|
|
1366
|
+
//#endregion
|
|
1703
1367
|
//#region packages/ai/src/transports/openai-responses-client.ts
|
|
1704
1368
|
function resolveNativeOpenAIResponsesWebSocketMode(model, transport) {
|
|
1705
1369
|
if (transport !== "websocket" && transport !== "websocket-cached" && transport !== "auto") return;
|
|
@@ -1734,6 +1398,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1734
1398
|
const output = createOpenAIResponsesAssistantOutput(model, config.outputApi);
|
|
1735
1399
|
let firstEventAbort;
|
|
1736
1400
|
let continuationClaim;
|
|
1401
|
+
const requestLifecycle = responsesRequestLifecycle.get(options);
|
|
1737
1402
|
try {
|
|
1738
1403
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
1739
1404
|
const websocketMode = resolveNativeOpenAIResponsesWebSocketMode(model, responsesOptions?.transport);
|
|
@@ -1748,7 +1413,12 @@ function createResponsesTransportExecutor(config) {
|
|
|
1748
1413
|
const websocketTurnHeaders = filterProviderTurnHeadersForExplicitOpencodeSession(model, options, websocketSessionPolicy?.headers);
|
|
1749
1414
|
const websocketHeaders = websocketMode ? buildOpenAIClientHeaders(model, context, options?.headers, websocketTurnHeaders, options?.sessionId, options?.cacheRetention) : void 0;
|
|
1750
1415
|
const httpHeaders = buildOpenAIClientHeaders(model, context, options?.headers, httpTurnHeaders, options?.sessionId, options?.cacheRetention);
|
|
1751
|
-
const
|
|
1416
|
+
const fetchOverride = createResponsesRequestFetch(model, {
|
|
1417
|
+
compact: Boolean(compactRequest),
|
|
1418
|
+
stream: config.streamRequest,
|
|
1419
|
+
lifecycle: requestLifecycle
|
|
1420
|
+
});
|
|
1421
|
+
const client = config.createClient(model, apiKey, httpHeaders, fetchOverride);
|
|
1752
1422
|
const nativeAstra = model.id === "gpt-6-astra" && supportsNativeOpenAIResponsesEndpoint(model);
|
|
1753
1423
|
const asyncToolExecutionEligible = nativeAstra && options?.asyncToolExecution === true && !responsesOptions?.openclawCodeModeToolSurface;
|
|
1754
1424
|
const prepareRequest = async (request) => {
|
|
@@ -1792,11 +1462,11 @@ function createResponsesTransportExecutor(config) {
|
|
|
1792
1462
|
return;
|
|
1793
1463
|
}
|
|
1794
1464
|
const sessionId = options?.sessionId;
|
|
1795
|
-
if (config.httpContinuation && !websocketMode && !getAiTransportHost().requiresManagedTransport(model) && supportsNativeOpenAIResponsesEndpoint({
|
|
1465
|
+
if (config.httpContinuation && !websocketMode && !getAiTransportHost().requiresManagedTransport(model) && (supportsNativeOpenAIResponsesEndpoint({
|
|
1796
1466
|
provider: model.provider,
|
|
1797
1467
|
api: model.api,
|
|
1798
1468
|
baseUrl: model.baseUrl
|
|
1799
|
-
}) && sessionId && (params.store === true || supportsResponsesReasoningUpdate(params)) && !params.previous_response_id) {
|
|
1469
|
+
}) || resolveOpenAIResponsesPayloadPolicy(model).explicitContinuationOptIn) && sessionId && (params.store === true || supportsResponsesReasoningUpdate(params)) && !params.previous_response_id) {
|
|
1800
1470
|
continuationClaim = claimOpenAIResponsesHttpContinuation({
|
|
1801
1471
|
sessionId,
|
|
1802
1472
|
apiKey,
|
|
@@ -1827,7 +1497,9 @@ function createResponsesTransportExecutor(config) {
|
|
|
1827
1497
|
});
|
|
1828
1498
|
const websocketSignal = combineWebSocketTimeoutSignal(firstEvent.signal, model, requestOptions?.timeout);
|
|
1829
1499
|
emitModelTransportDebug(log, `[responses] start provider=${model.provider} api=${model.api} model=${model.id} requestIdHash=${redactIdentifier(options?.requestId, { len: 64 })} baseUrl=${formatModelTransportDebugBaseUrl(model.baseUrl)} timeoutMs=${safeDebugValue(requestOptions?.timeout)} apiKey=${apiKey ? "present" : "missing"} ${summarizeResponsesPayload(params)}`);
|
|
1500
|
+
const responseModelTracker = createResponseModelTracker(isOpenAICodexResponsesModel(model));
|
|
1830
1501
|
let continuationBaseline;
|
|
1502
|
+
let contextUsageEligible = true;
|
|
1831
1503
|
const createSseStream = async (initialRequest = continuationClaim?.request ?? params, initialAttemptKind = "initial", initialRejectedCompaction) => {
|
|
1832
1504
|
const { stream: responseStream } = await createResponsesStreamWithEncryptedContentRetry({
|
|
1833
1505
|
client,
|
|
@@ -1841,9 +1513,11 @@ function createResponsesTransportExecutor(config) {
|
|
|
1841
1513
|
onCompactionRejected: (checkpoint) => suppressOpenAIResponsesCompaction(output, model, responsesOptions, checkpoint),
|
|
1842
1514
|
canRetryStream: () => output.content.length === 0,
|
|
1843
1515
|
wrapStream: ({ stream: rawResponseStream, response, attempt }) => {
|
|
1516
|
+
contextUsageEligible &&= attempt.kind === "initial";
|
|
1844
1517
|
continuationBaseline = attempt.request.previous_response_id ? params : attempt.request;
|
|
1518
|
+
const trackedResponseStream = responseModelTracker.track(response, rawResponseStream);
|
|
1845
1519
|
return withProviderResponseHook({
|
|
1846
|
-
stream: observeResponsesStream(
|
|
1520
|
+
stream: observeResponsesStream(trackedResponseStream, model, requestStartedAt),
|
|
1847
1521
|
signal: firstEvent.signal,
|
|
1848
1522
|
abort: firstEvent.abort,
|
|
1849
1523
|
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
@@ -1879,24 +1553,29 @@ function createResponsesTransportExecutor(config) {
|
|
|
1879
1553
|
callerSignal: options?.signal,
|
|
1880
1554
|
degradeCooldownMs: websocketSessionPolicy?.degradeCooldownMs,
|
|
1881
1555
|
onActiveResponse: nativeAstra && params.model === "gpt-6-astra" ? options?.onActiveResponse : void 0,
|
|
1882
|
-
steeringInput: (messages) =>
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1556
|
+
steeringInput: (messages) => {
|
|
1557
|
+
contextUsageEligible = false;
|
|
1558
|
+
return projectResponsesSteeringInput(params, () => buildRequest("checkpoint", {
|
|
1559
|
+
...context,
|
|
1560
|
+
messages: [...context.messages, ...messages]
|
|
1561
|
+
}));
|
|
1562
|
+
}
|
|
1886
1563
|
});
|
|
1887
1564
|
finishWebSocket = websocket.finish;
|
|
1888
1565
|
websocketBaseline = websocket.fullRequest;
|
|
1889
1566
|
recordResponsesInputReplay(output, websocket.inputReplay);
|
|
1567
|
+
contextUsageEligible &&= websocket.inputReplay === void 0;
|
|
1890
1568
|
observePrompt?.(websocket.request, {
|
|
1891
1569
|
egress: "responses-websocket",
|
|
1892
1570
|
payloadVariant: "initial"
|
|
1893
1571
|
});
|
|
1894
1572
|
transport = "websocket";
|
|
1895
1573
|
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))))}`);
|
|
1574
|
+
const trackedWebSocketStream = responseModelTracker.track(void 0, websocket.stream);
|
|
1896
1575
|
responseStream = { async *[Symbol.asyncIterator]() {
|
|
1897
1576
|
let providerAccepted = false;
|
|
1898
1577
|
try {
|
|
1899
|
-
for await (const event of
|
|
1578
|
+
for await (const event of trackedWebSocketStream) {
|
|
1900
1579
|
if (!providerAccepted) {
|
|
1901
1580
|
providerAccepted = true;
|
|
1902
1581
|
await notifyProviderStreamOpened({
|
|
@@ -1935,7 +1614,9 @@ function createResponsesTransportExecutor(config) {
|
|
|
1935
1614
|
}
|
|
1936
1615
|
else responseStream = await createSseStream();
|
|
1937
1616
|
try {
|
|
1938
|
-
const
|
|
1617
|
+
const acceptedResponseStream = withResponsesRequestAcceptance(responseStream, requestLifecycle, transport === "websocket" ? websocketSignal : firstEvent.signal);
|
|
1618
|
+
const terminal = await processResponsesStream(acceptedResponseStream, output, stream, model, {
|
|
1619
|
+
canRetryIdentityConflict: () => hasOnlyResponsesFunctionTools(transport === "websocket" ? websocketBaseline : continuationBaseline),
|
|
1939
1620
|
...config.pricingOptions?.(responsesOptions, model),
|
|
1940
1621
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options) ?? config.firstEventTimeoutMs,
|
|
1941
1622
|
abortFirstEventStream: firstEvent.abort,
|
|
@@ -1945,7 +1626,8 @@ function createResponsesTransportExecutor(config) {
|
|
|
1945
1626
|
authProfileId: responsesOptions?.authProfileId,
|
|
1946
1627
|
sessionId: options?.sessionId
|
|
1947
1628
|
}),
|
|
1948
|
-
asyncToolExecution: asyncTools
|
|
1629
|
+
asyncToolExecution: asyncTools,
|
|
1630
|
+
...responseModelTracker.terminalOptions
|
|
1949
1631
|
});
|
|
1950
1632
|
finishWebSocket?.();
|
|
1951
1633
|
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
@@ -1953,6 +1635,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1953
1635
|
const admitted = transport === "websocket" ? websocketBaseline : continuationBaseline;
|
|
1954
1636
|
if (terminal && admitted && supportsNativeOpenAIResponsesEndpoint(model)) recordResponsesReasoningState(output, model, responsesOptions, admitted, terminal.output);
|
|
1955
1637
|
if (continuationClaim && continuationBaseline && terminal) continuationClaim.commit(continuationBaseline, terminal);
|
|
1638
|
+
if (terminal && admitted && contextUsageEligible) recordResponsesContextUsage(output, model, responsesOptions, admitted, terminal.output, "transport");
|
|
1956
1639
|
} catch (error) {
|
|
1957
1640
|
finishWebSocket?.({ keep: false });
|
|
1958
1641
|
throw error;
|
|
@@ -1964,6 +1647,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1964
1647
|
signal: options?.signal
|
|
1965
1648
|
});
|
|
1966
1649
|
} catch (error) {
|
|
1650
|
+
if (requestLifecycle) await requestLifecycle.settle().catch(() => void 0);
|
|
1967
1651
|
if (compactRequest) {
|
|
1968
1652
|
compactRequest.reject(error);
|
|
1969
1653
|
failTransportStream({
|
|
@@ -2007,7 +1691,13 @@ function createAzureOpenAIResponsesTransportStreamFn() {
|
|
|
2007
1691
|
outputApi: "azure-openai-responses",
|
|
2008
1692
|
firstEventTimeoutMs: AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS,
|
|
2009
1693
|
createClient: createAzureOpenAIClient,
|
|
2010
|
-
buildRequest: (model, context, options, metadata, replayMode) =>
|
|
1694
|
+
buildRequest: (model, context, options, metadata, replayMode) => {
|
|
1695
|
+
const deploymentName = resolveAzureDeploymentName(model);
|
|
1696
|
+
const params = buildOpenAIResponsesParams(model, context, options, metadata, replayMode);
|
|
1697
|
+
params.model = deploymentName;
|
|
1698
|
+
delete params.store;
|
|
1699
|
+
return params;
|
|
1700
|
+
}
|
|
2011
1701
|
});
|
|
2012
1702
|
}
|
|
2013
1703
|
function resolveAzureDeploymentName(model) {
|
|
@@ -2032,12 +1722,6 @@ function createAzureOpenAIClient(model, apiKey, defaultHeaders, fetchOverride) {
|
|
|
2032
1722
|
apiVersion: resolveAzureOpenAIApiVersion()
|
|
2033
1723
|
});
|
|
2034
1724
|
}
|
|
2035
|
-
function buildAzureOpenAIResponsesParams(model, context, options, deploymentName, metadata, replayMode = "checkpoint") {
|
|
2036
|
-
const params = buildOpenAIResponsesParams(model, context, options, metadata, replayMode);
|
|
2037
|
-
params.model = deploymentName;
|
|
2038
|
-
delete params.store;
|
|
2039
|
-
return params;
|
|
2040
|
-
}
|
|
2041
1725
|
//#endregion
|
|
2042
1726
|
//#region packages/ai/src/transports/provider-compaction-replay.ts
|
|
2043
1727
|
function isAssistantReplayMessage(message) {
|
|
@@ -2095,35 +1779,55 @@ function preserveCompactionReplayWindow(source, windowed, model, identity) {
|
|
|
2095
1779
|
providerReplay
|
|
2096
1780
|
}, ...windowed.filter((message) => suffix.has(message))];
|
|
2097
1781
|
}
|
|
2098
|
-
function
|
|
2099
|
-
|
|
2100
|
-
|
|
1782
|
+
function estimateResponsesContent(content, estimate, text) {
|
|
1783
|
+
if (typeof content === "string") return text(content);
|
|
1784
|
+
if (!Array.isArray(content)) return estimate.json(content);
|
|
1785
|
+
return content.reduce((tokens, block) => {
|
|
1786
|
+
if (!isRecord(block)) return tokens + estimate.json(block);
|
|
1787
|
+
if ((block.type === "input_text" || block.type === "output_text") && typeof block.text === "string") {
|
|
1788
|
+
const { text: value, ...metadata } = block;
|
|
1789
|
+
return tokens + text(value) + estimate.json(metadata);
|
|
1790
|
+
}
|
|
1791
|
+
if (block.type === "input_image") {
|
|
1792
|
+
const { image_url: url, ...metadata } = block;
|
|
1793
|
+
return tokens + estimate.image() + estimate.json(typeof url === "string" && url.startsWith("data:") ? metadata : block);
|
|
1794
|
+
}
|
|
1795
|
+
return tokens + estimate.json(block);
|
|
1796
|
+
}, 0);
|
|
1797
|
+
}
|
|
1798
|
+
function estimateResponsesInput(input, estimate) {
|
|
1799
|
+
return input.reduce((tokens, entry) => {
|
|
1800
|
+
if (!isRecord(entry)) return tokens + estimate.json(entry);
|
|
1801
|
+
if (entry.type === "compaction" && typeof entry.encrypted_content === "string") {
|
|
2101
1802
|
const { encrypted_content, ...metadata } = entry;
|
|
2102
1803
|
return tokens + estimate.text(encrypted_content) + estimate.json(metadata);
|
|
2103
1804
|
}
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
}
|
|
2114
|
-
return sum + estimate.json(block);
|
|
2115
|
-
}, 0);
|
|
1805
|
+
if (entry.type === "message") {
|
|
1806
|
+
const { content, ...metadata } = entry;
|
|
1807
|
+
return tokens + estimate.json(metadata) + estimateResponsesContent(content, estimate, (value) => estimate.text(value));
|
|
1808
|
+
}
|
|
1809
|
+
if (entry.type === "function_call_output" || entry.type === "custom_tool_call_output") {
|
|
1810
|
+
const { output, ...metadata } = entry;
|
|
1811
|
+
return tokens + estimate.json(metadata) + estimateResponsesContent(output, estimate, (value) => estimate.toolResult ? estimate.toolResult(value) : estimate.text(value));
|
|
1812
|
+
}
|
|
1813
|
+
return tokens + estimate.json(entry);
|
|
2116
1814
|
}, 0);
|
|
2117
1815
|
}
|
|
2118
1816
|
/** Estimate the canonical prefix and its tail once, independent of unbound usage snapshots. */
|
|
2119
|
-
function resolveCompactionReplayPressure(messages, model, identity, estimate) {
|
|
1817
|
+
function resolveCompactionReplayPressure(messages, model, identity, estimate, systemPrompt) {
|
|
2120
1818
|
const checkpoint = resolveCompactionSource(messages, model, identity);
|
|
2121
1819
|
if (!checkpoint) return;
|
|
2122
1820
|
if (checkpoint.family === "responses" && checkpoint.mode === "refresh-required") throw new CompactionReplayRefreshRequiredError();
|
|
2123
1821
|
const ownerIndex = messages.findIndex((message) => message === checkpoint.owner);
|
|
2124
1822
|
const owner = messages[ownerIndex];
|
|
2125
1823
|
if (!owner) return;
|
|
2126
|
-
const prefixTokens = checkpoint.family === "anthropic" ? estimate.text(checkpoint.summary) : checkpoint.mode === "complete-window" ?
|
|
1824
|
+
const prefixTokens = checkpoint.family === "anthropic" ? estimate.text(checkpoint.summary) : checkpoint.mode === "complete-window" ? estimateResponsesInput(checkpoint.output, estimate) : estimate.text(checkpoint.item.encrypted_content);
|
|
1825
|
+
const measuredBoundary = checkpoint.family === "responses" ? resolveResponsesContextUsageBoundary(messages, model, identity, systemPrompt) : void 0;
|
|
1826
|
+
if (measuredBoundary) return {
|
|
1827
|
+
messages: [],
|
|
1828
|
+
prefixTokens: measuredBoundary.totalTokens + estimateResponsesInput(measuredBoundary.suffix, estimate),
|
|
1829
|
+
measuredTokens: measuredBoundary.totalTokens
|
|
1830
|
+
};
|
|
2127
1831
|
const { contextUsage: _staleContextUsage, ...usage } = checkpoint.owner.usage;
|
|
2128
1832
|
const tail = [];
|
|
2129
1833
|
for (const message of messages.slice(ownerIndex + 1)) {
|
|
@@ -2400,7 +2104,9 @@ function prepareCodexSimpleTransportModel(registry, model, cfg) {
|
|
|
2400
2104
|
if (!registerCustomApi(registry, api, streamFn)) return;
|
|
2401
2105
|
return projectModel(transportModel, { api });
|
|
2402
2106
|
}
|
|
2403
|
-
function
|
|
2107
|
+
function resolveModelTransportSentinels(model, boundary) {
|
|
2108
|
+
const host = getAiTransportHost();
|
|
2109
|
+
if (host.unwrapModelTransportSentinels) return host.unwrapModelTransportSentinels(model, boundary);
|
|
2404
2110
|
const headers = resolveAiTransportHeaderSentinels(model.headers);
|
|
2405
2111
|
return headers === model.headers ? model : projectModel(model, { headers });
|
|
2406
2112
|
}
|
|
@@ -2409,7 +2115,7 @@ function wrapPluginProviderStream(streamFn) {
|
|
|
2409
2115
|
const host = getAiTransportHost();
|
|
2410
2116
|
const apiKey = options?.apiKey ? host.resolveSecretSentinel(options.apiKey) : options?.apiKey;
|
|
2411
2117
|
const headers = resolveAiTransportHeaderSentinels(options?.headers);
|
|
2412
|
-
return streamFn(
|
|
2118
|
+
return streamFn(resolveModelTransportSentinels(model, "plugin simple-completion stream egress"), context, apiKey === options?.apiKey && headers === options?.headers ? options : {
|
|
2413
2119
|
...options,
|
|
2414
2120
|
apiKey,
|
|
2415
2121
|
headers
|
|
@@ -2417,7 +2123,7 @@ function wrapPluginProviderStream(streamFn) {
|
|
|
2417
2123
|
};
|
|
2418
2124
|
}
|
|
2419
2125
|
function prepareProviderStreamModel(params) {
|
|
2420
|
-
const pluginModel =
|
|
2126
|
+
const pluginModel = resolveModelTransportSentinels(params.model, "plugin simple-completion stream construction");
|
|
2421
2127
|
const providerStreamFn = getAiTransportHost().plugin.resolveProviderStream({
|
|
2422
2128
|
provider: params.model.provider,
|
|
2423
2129
|
config: params.cfg,
|
|
@@ -2459,4 +2165,4 @@ function prepareModelForSimpleCompletion(params) {
|
|
|
2459
2165
|
return applyProviderSimpleCompletionWrapper(apiRegistry, model, cfg);
|
|
2460
2166
|
}
|
|
2461
2167
|
//#endregion
|
|
2462
|
-
export { CompactionReplayRefreshRequiredError, GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, IncompleteToolCallError, MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, applyAnthropicContextManagementToRequest, applyAnthropicEphemeralCacheControlMarkers, applyAnthropicPayloadPolicyToParams, applyAnthropicRequestCacheControl, applyCompletionsAnthropicCacheControl, applyOpenAIResponsesPayloadPolicy, assertCodeModeResponsesToolSurface, assignTransportErrorDetails, buildAnthropicSystemBlocks, buildOpenAIClientHeaders, buildOpenAICompletionsParams, buildOpenAISdkClientOptions, buildOpenAISdkRequestOptions, buildTransportAwareSimpleStreamFn, canonicalizeMaxTokensParam, captureOpenAIResponsesCompaction, coerceTransportToolCallArguments, consumeGoogleGenerateContentStream, convertGoogleTools, 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, isAnthropicServerToolClearingEnabled, isCodeModeModelVisibleToolName, isCompactionReplayCheckpoint, isDirectAnthropicModel, isNativeOpenAIEndpoint, isOpenAICodexResponsesModel, isOpenAICompletionsThinkingEnabled, log, logAnthropicContextEdits, measureUtf8AppendBytes, mergeTransportHeaders, mergeTransportMetadata, normalizeCodexResponsesBaseUrlForOpenAISdk, notifyProviderHttpMetadata, notifyProviderHttpResponse, notifyProviderStreamOpened, parseJsonObjectPreservingUnsafeIntegers, parseJsonPreservingUnsafeIntegers, parseOpenAICompletionsUsage, parseTerminalToolCallArguments, prepareHeadersForSimpleCompletion, prepareModelForSimpleCompletion, prepareTransportAwareSimpleModel, preserveCompactionReplayWindow, projectGoogleMessages, quoteUnsafeIntegerLiterals, readCodeModePayloadToolName, readOpenAICompletionsContentDeltas, readOpenAICompletionsReasoningBatch, replaceCompactionReplayOwnerContent, requestPreparedOpenAIResponsesCompaction, requiresCompactionReplayRefresh, requiresGoogleToolCallId, resolveAnthropicCacheOptions, resolveAnthropicContextManagementBetaHeader, resolveAnthropicEphemeralCacheControl, resolveAnthropicMessagesUrl, resolveAnthropicPayloadPolicy, resolveAnthropicServerCompactionPlan, resolveCodeModeResponsesVisibleToolNames, resolveCompactionReplayEligibility, resolveCompactionReplayPressure, resolveMaxTokensParam, resolveModelPayloadDebugMode, resolveModelSseDebugMode, resolveOpenAIClientBaseUrl, resolveOpenAICompletionsCompat, resolveOpenAIPromptCacheKeySupport, resolveOpenAIReasoningEffortMap, resolveOpenAIResponsesCompactEndpointPlan, resolveOpenAIResponsesPayloadPolicy, resolveOpenAIResponsesServerCompactionPlan, resolveOpenAIStrictToolFlagWithDiagnostics, resolvePromptCacheKey, resolveReplayableResponsesMessageId, resolveTransportAwareSimpleApi, sanitizeNonEmptyTransportPayloadText, sanitizeResponsesImagePayload, sanitizeTransportPayloadText, sortPromptCacheToolsByName as sortTransportToolsByName, stripCompactionReplayCheckpoint, stripCompactionReplayCheckpointInPlace, stripCompletionMessagesToRoleContent, throwIfModelStreamAborted, transportAbortError, usesNativeOpenAICodexResponsesBackend, withProviderAcceptanceObserver, withProviderResponseHook };
|
|
2168
|
+
export { CompactionReplayRefreshRequiredError, GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, IncompleteToolCallError, MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, applyAnthropicContextManagementToRequest, applyAnthropicEphemeralCacheControlMarkers, applyAnthropicPayloadPolicyToParams, applyAnthropicRequestCacheControl, applyCompletionsAnthropicCacheControl, applyOpenAIResponsesPayloadPolicy, assertCodeModeResponsesToolSurface, assignTransportErrorDetails, buildAnthropicSystemBlocks, buildOpenAIClientHeaders, buildOpenAICompletionsParams, buildOpenAISdkClientOptions, buildOpenAISdkRequestOptions, buildTransportAwareSimpleStreamFn, canonicalizeMaxTokensParam, captureOpenAIResponsesCompaction, coerceTransportToolCallArguments, consumeGoogleGenerateContentStream, convertGoogleTools, copyProviderAcceptanceObserver, createAnthropicMessagesTransportStreamFn, createAzureOpenAIResponsesTransportStreamFn, createBoundaryAwareStreamFnForModel, createDeepSeekTextFilter, createEmptyTransportUsage, createModelStreamCooperativeScheduler, createOpenAICompletionsTransportStreamFn, createOpenAIProviderAcceptanceHook, createOpenAIResponseHook, createOpenAIResponsesTransportStreamFn, createOpenClawTransportStreamFnForModel, createResponseModelTracker, createTransportAwareStreamFnForModel, createWritableTransportEventStream, detectOpenAICompletionsCompat, emitModelTransportDebug, enforceCodeModeResponsesToolSurface, failTransportStream, filterCodeModePayloadTools, finalizeTerminalToolCallArguments, finalizeTransportStream, flattenCompletionMessagesToStringContent, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, getCompat, googleFlashSupportsMinimalThinking, hasOpenAICompatibleConversationTurn, isAnthropicServerToolClearingEnabled, isCodeModeModelVisibleToolName, isCompactionReplayCheckpoint, isDirectAnthropicModel, isNativeOpenAIEndpoint, isOpenAICodexResponsesModel, isOpenAICompletionsThinkingEnabled, log, logAnthropicContextEdits, measureUtf8AppendBytes, mergeTransportHeaders, mergeTransportMetadata, normalizeCodexResponsesBaseUrlForOpenAISdk, notifyProviderHttpMetadata, notifyProviderHttpResponse, notifyProviderStreamOpened, parseJsonObjectPreservingUnsafeIntegers, parseJsonPreservingUnsafeIntegers, parseOpenAICompletionsUsage, parseTerminalToolCallArguments, prepareHeadersForSimpleCompletion, prepareModelForSimpleCompletion, prepareTransportAwareSimpleModel, preserveCompactionReplayWindow, projectGoogleMessages, quoteUnsafeIntegerLiterals, readCodeModePayloadToolName, readOpenAICompletionsContentDeltas, readOpenAICompletionsReasoningBatch, replaceCompactionReplayOwnerContent, requestPreparedOpenAIResponsesCompaction, requiresCompactionReplayRefresh, requiresGoogleToolCallId, resolveAnthropicCacheOptions, resolveAnthropicContextManagementBetaHeader, resolveAnthropicEphemeralCacheControl, resolveAnthropicMessagesUrl, resolveAnthropicPayloadPolicy, resolveAnthropicServerCompactionPlan, resolveCodeModeResponsesVisibleToolNames, resolveCompactionReplayEligibility, resolveCompactionReplayPressure, resolveMaxTokensParam, resolveModelPayloadDebugMode, resolveModelSseDebugMode, resolveOpenAIClientBaseUrl, resolveOpenAICompletionsCompat, resolveOpenAIPromptCacheKeySupport, resolveOpenAIReasoningEffortMap, resolveOpenAIResponsesCompactEndpointPlan, resolveOpenAIResponsesPayloadPolicy, resolveOpenAIResponsesServerCompactionPlan, resolveOpenAIStrictToolFlagWithDiagnostics, resolvePromptCacheKey, resolveReplayableResponsesMessageId, resolveTransportAwareSimpleApi, sanitizeNonEmptyTransportPayloadText, sanitizeResponsesImagePayload, sanitizeTransportPayloadText, sortPromptCacheToolsByName as sortTransportToolsByName, stripCompactionReplayCheckpoint, stripCompactionReplayCheckpointInPlace, stripCompletionMessagesToRoleContent, throwIfModelStreamAborted, transportAbortError, usesNativeOpenAICodexResponsesBackend, withProviderAcceptanceObserver, withProviderResponseHook };
|