@openclaw/ai 2026.9.5 → 2026.9.7
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-COtDvgtt.mjs → anthropic-Cw2pgccz.mjs} +59 -88
- package/dist/{anthropic-payload-policy-5Erq1Nzy.d.mts → anthropic-payload-policy-NIPVYXPq.d.mts} +8 -6
- package/dist/{anthropic-stream-reducer-BvdYYWL8.mjs → anthropic-stream-reducer-D9MCkl8Z.mjs} +194 -247
- package/dist/{api-registry-Ba2Cv-ut.d.mts → api-registry-D-nbmSqr.d.mts} +2 -2
- package/dist/{azure-openai-responses-YrgnD583.mjs → azure-openai-responses-BwT3-X8P.mjs} +22 -33
- package/dist/{base64-BQOzsvUH.mjs → base64-C1PsYcRQ.mjs} +22 -16
- package/dist/{diagnostics-Dm4bisWG.mjs → diagnostics-CJaB6g8J.mjs} +55 -10
- package/dist/{diagnostics-CPeq9F7y.mjs → diagnostics-DzrF1h4J.mjs} +18 -1
- package/dist/diagnostics.d.mts +11 -5
- package/dist/diagnostics.mjs +4 -4
- package/dist/{env-api-keys-bktO00EJ.mjs → env-api-keys-CyX4VKGO.mjs} +7 -5
- package/dist/event-stream-CMQfX_yr.d.mts +1 -0
- package/dist/{event-stream-CCoa-qSI.d.mts → event-stream-DOPFYVqs.d.mts} +2 -2
- package/dist/{event-stream-D8PARQfL.mjs → event-stream-vd9UnCAU.mjs} +10 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{google-BuhpRO9r.mjs → google-BfapkS_K.mjs} +8 -11
- package/dist/google-interactions-DW3iXzjc.mjs +574 -0
- package/dist/{google-messages-CyWnYlh0.mjs → google-messages-CtjVtVot.mjs} +35 -71
- package/dist/{google-shared-BT5ZeNer.mjs → google-shared-Y2YfotEu.mjs} +43 -47
- package/dist/{google-vertex-C7EplRvt.mjs → google-vertex-Dov4kBWu.mjs} +16 -30
- package/dist/{host-B4MeUNBc.mjs → host-CHi3X87F.mjs} +64 -189
- package/dist/{host-policy-DUnXSx0I.mjs → host-policy-BOAwRg_M.mjs} +2 -14
- package/dist/{host-FZ1RA_qD.d.mts → host-rxlNaBwm.d.mts} +9 -3
- package/dist/{index-DaF2QbwS.d.mts → index-D6KsSE74.d.mts} +57 -9
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -7
- package/dist/internal/anthropic.d.mts +13 -8
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +46 -9
- package/dist/internal/openai.mjs +13 -12
- package/dist/internal/runtime.d.mts +31 -70
- package/dist/internal/runtime.mjs +11 -66
- package/dist/internal/shared.d.mts +16 -13
- package/dist/internal/shared.mjs +6 -5
- package/dist/internal/tool-schema.d.mts +2 -2
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral-moA-mbwl.mjs → mistral-RS6mboC-.mjs} +46 -93
- package/dist/{model-transport-url-DKocrEsb.d.mts → model-transport-url-C5f59L3Y.d.mts} +1 -1
- package/dist/{openai-chatgpt-responses-DWID3EFO.mjs → openai-chatgpt-responses-CYbidtrn.mjs} +118 -99
- package/dist/{openai-completions-DJ1Vm-CD.mjs → openai-completions-D14ihPYk.mjs} +14 -12
- package/dist/{openai-completions-compat-CkwdxTZx.mjs → openai-completions-compat-BOVWBZDn.mjs} +3 -5
- package/dist/{openai-completions-compat-JE7gqxb9.d.mts → openai-completions-compat-qJjmqQ71.d.mts} +3 -3
- package/dist/{openai-completions-stream-Bu98b0Hv.mjs → openai-completions-stream-CDCuw3DP.mjs} +124 -183
- package/dist/{openai-prompt-cache-CJ_xEevu.d.mts → openai-prompt-cache-CouErLh7.d.mts} +2 -2
- package/dist/{openai-prompt-cache-1wfaIszn.mjs → openai-prompt-cache-D2V7MqR7.mjs} +1 -1
- package/dist/{openai-provider-client-DPo0Hmak.mjs → openai-provider-client-CwfsGBbA.mjs} +2 -2
- package/dist/{openai-reasoning-effort-NlFZmfEu.mjs → openai-reasoning-effort-ConhwkeX.mjs} +14 -5
- package/dist/{openai-responses-BejZzQCP.mjs → openai-responses-CKCBEc2W.mjs} +12 -11
- package/dist/openai-responses-compaction-replay-DiYn-gFM.d.mts +12 -0
- package/dist/{openai-responses-compaction-window-D6P5oZP5.mjs → openai-responses-compaction-window-UNK1GDpy.mjs} +5 -5
- package/dist/{openai-responses-contracts-DWrfMODE.mjs → openai-responses-contracts-CLxnqS9p.mjs} +1 -1
- package/dist/{openai-responses-contracts-Dflvrfa8.d.mts → openai-responses-contracts-D1iZ0njF.d.mts} +4 -4
- package/dist/{openai-responses-prompt-observer-internal-C15_-OwV.mjs → openai-responses-prompt-observer-internal-iAqLb4tk.mjs} +16 -13
- package/dist/openai-responses-request-lifecycle-Fsag-IGZ.mjs +36 -0
- package/dist/{openai-responses-shared-CwsziD_m.mjs → openai-responses-shared-DL4ulQn7.mjs} +838 -577
- package/dist/{openai-responses-terminal-usage-Dl3J6zrf.d.mts → openai-responses-terminal-usage-BE7lf7nW.d.mts} +2 -2
- package/dist/{openai-stop-reason-Drnn_6Qj.mjs → openai-stop-reason-8s70vDXj.mjs} +2 -12
- package/dist/{openai-tool-schema-ynZBgqW-.d.mts → openai-tool-schema-a5ysBBga.d.mts} +0 -6
- package/dist/{openai-tool-schema-BO8rwyAD.mjs → openai-tool-schema-vsl-cE-n.mjs} +365 -429
- package/dist/{openai-transport-params-DQeuAvBl.mjs → openai-transport-params-BwlpzX-2.mjs} +61 -106
- package/dist/{positive-integer-DtjCkbue.mjs → positive-integer-CjN5OJbH.mjs} +1 -1
- package/dist/{provider-error-DDqw9Qda.mjs → provider-error-CwT_j2v0.mjs} +82 -10
- package/dist/{provider-error-CzNw4BWX.d.mts → provider-error-xumb1V3F.d.mts} +3 -1
- package/dist/{provider-options-DprLsWh9.d.mts → provider-options-Df7ov0K1.d.mts} +6 -4
- package/dist/{provider-replay-context-CnUSOwhr.mjs → provider-replay-context-DsyI5jOP.mjs} +1 -1
- package/dist/{provider-transcript-transform-BsRAhuWJ.mjs → provider-transcript-transform-JbFbHV8h.mjs} +17 -2
- package/dist/{provider-transport-turn-state-CkGToCD2.mjs → provider-transport-turn-state-BheUi_hl.mjs} +1 -1
- package/dist/{provider-types-CAKRC7N5.d.mts → provider-types-d4XnoZMd.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +15 -11
- package/dist/{reasoning-tag-text-partitioner-Dy9IO8Dc.mjs → reasoning-tag-text-partitioner-B6FIIBt6.mjs} +193 -98
- package/dist/{record-coerce-DwRYMj3t.mjs → record-coerce-CNDovvft.mjs} +1 -1
- package/dist/simple-options-CGAkCwtM.mjs +349 -0
- package/dist/{src-DeKjbE8I.mjs → src-H4aXcFuX.mjs} +53 -26
- package/dist/{stream-CREqxHgU.mjs → stream-DDsCBgd-.mjs} +1 -7
- package/dist/{stream-first-event-timeout-C9ZadkJW.mjs → stream-first-event-timeout-B9o0S4SZ.mjs} +1 -1
- package/dist/{tool-schema-json-projection-CD9c_fK8.mjs → tool-schema-json-projection-Ct8SeBeJ.mjs} +63 -23
- package/dist/{transport-stream-shared-D-6FQSHm.mjs → transport-stream-shared-Dh5qKJ8e.mjs} +63 -37
- package/dist/{transport-stream-shared-BbUkFaHi.d.mts → transport-stream-shared-yYhXa4kX.d.mts} +13 -7
- package/dist/{transport-utils-1cyq5Y7x.mjs → transport-utils-C-4bf2Ok.mjs} +3 -4
- package/dist/transports.d.mts +37 -33
- package/dist/transports.mjs +208 -239
- package/dist/types-CB-_vNyI.d.mts +1 -0
- package/dist/{types-4_uVs5WH.d.mts → types-CLLR3eB4.d.mts} +5 -1
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +5 -5
- package/dist/{validation-Dw7cb6BV.mjs → validation-BFZc40Ig.mjs} +80 -54
- package/dist/{validation-Ctzu2DhF.d.mts → validation-Cat2wQsc.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +6 -6
- package/dist/assistant-output-BsEkB-vU.mjs +0 -16
- package/dist/event-stream-DmSCpi1T.d.mts +0 -1
- package/dist/simple-options-C6cFWj_f.mjs +0 -175
- package/dist/types-DkJfb4W3.d.mts +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +0 -29
package/dist/transports.mjs
CHANGED
|
@@ -1,54 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as supportsClaudeAdaptiveThinking, b as resolveClaudeSonnet5ModelIdentity, v as resolveClaudeOpus5ModelIdentity, y as resolveClaudeSonnet55ModelIdentity } from "./src-H4aXcFuX.mjs";
|
|
2
|
+
import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
|
|
3
|
+
import { _ as requiresClaudeAdaptiveThinking, b as usesClaudeFable5MessagesContract, f as applyClaudeRequestContract, g as prepareClaudeNoPrefillRequestContext, m as defaultsClaudeAdaptiveThinking, n as getAiTransportHost, p as buildAnthropicClaudeCodeIdentity, r as resolveAiTransportHeaderSentinels, v as resolveAnthropicThinkingEffort, x as usesClaudeStreamingRefusalContract } from "./host-CHi3X87F.mjs";
|
|
2
4
|
import { n as normalizeLowercaseStringOrEmpty, t as hasNonEmptyString } from "./string-coerce-fsri9iCu.mjs";
|
|
3
|
-
import { o as
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import { a as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { a as resolveOpenAIPromptCacheKeySupport, i as resolveOpenAICompletionsCompat, n as isNativeOpenAIEndpoint, o as usesNativeOpenAICodexResponsesBackend, r as isOpenAICodexResponsesModel, t as detectOpenAICompletionsCompat } from "./openai-completions-compat-CkwdxTZx.mjs";
|
|
10
|
-
import { i as resolveProviderEndpoint, s as transformTransportMessages, t as buildGuardedModelFetch } from "./host-policy-DUnXSx0I.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-BvdYYWL8.mjs";
|
|
5
|
+
import { a as redactDiagnosticText, o as truncateUtf16Safe, s as stableStringify } from "./provider-error-CwT_j2v0.mjs";
|
|
6
|
+
import { a as resolveModelSseDebugMode, i as resolveModelPayloadDebugMode, n as formatModelTransportDebugUrl, r as emitModelTransportDebug, t as formatModelTransportDebugBaseUrl, u as hasOnlyResponsesFunctionTools, v as toErrorObject } from "./diagnostics-CJaB6g8J.mjs";
|
|
7
|
+
import { a as readResponseTextSnippet, i as isCodeModeModelVisibleToolName, n as createAbortError$1, s as resolveModelHeaderSentinels, t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-C-4bf2Ok.mjs";
|
|
8
|
+
import { a as resolveOpenAIPromptCacheKeySupport, i as resolveOpenAICompletionsCompat, n as isNativeOpenAIEndpoint, o as usesNativeOpenAICodexResponsesBackend, r as isOpenAICodexResponsesModel, t as detectOpenAICompletionsCompat } from "./openai-completions-compat-BOVWBZDn.mjs";
|
|
9
|
+
import { r as resolveProviderEndpoint, t as buildGuardedModelFetch } from "./host-policy-BOAwRg_M.mjs";
|
|
10
|
+
import { A as applyAnthropicRequestCacheControl, B as ANTHROPIC_SERVER_SIDE_FALLBACKS, C as applyAnthropicThinkingBindingControls, D as applyAnthropicContextManagementToRequest, F as resolveAnthropicCacheOptions, I as resolveAnthropicEphemeralCacheControl, J as usesFoundryBearerAuth, K as isAnthropicOAuthApiKey, L as resolveAnthropicPayloadPolicy, M as isAnthropicServerToolClearingEnabled, N as isDirectAnthropicModel, O as applyAnthropicEphemeralCacheControlMarkers, P as logAnthropicContextEdits, R as resolveAnthropicRequestBetaHeader, d as convertAnthropicTools, f as buildAnthropicReplayPlan, g as normalizeAnthropicToolCallId, h as suppressAnthropicCompaction, j as buildAnthropicSystemBlocks, k as applyAnthropicPayloadPolicyToParams, l as buildAnthropicGenerationParams, m as resolveNewestAnthropicCompaction, p as isAnthropicReplayRejection, q as omitFoundryBearerCredentialHeaders, t as consumeAnthropicStream, u as convertAnthropicMessages, z as resolveAnthropicServerCompactionPlan } from "./anthropic-stream-reducer-D9MCkl8Z.mjs";
|
|
12
11
|
import { t as resolveCacheRetention } from "./cache-retention-0x979a5V.mjs";
|
|
13
|
-
import { a as
|
|
14
|
-
import {
|
|
15
|
-
import { n as
|
|
16
|
-
import {
|
|
12
|
+
import { C as parseJsonObjectPreservingUnsafeIntegers, S as withProviderResponseHook, T as quoteUnsafeIntegerLiterals, _ as sanitizeNonEmptyTransportPayloadText, a as createEmptyTransportUsage, b as transportAbortError, c as failTransportStream, d as iterateModelStream, f as mergeTransportHeaders, g as parseTerminalToolCallArguments, h as notifyProviderStreamOpened, i as copyProviderAcceptanceObserver, l as finalizeTerminalToolCallArguments, m as notifyProviderHttpResponse, n as assignTransportErrorDetails, o as createModelStreamCooperativeScheduler, p as notifyProviderHttpMetadata, r as coerceTransportToolCallArguments, s as createWritableTransportEventStream, t as IncompleteToolCallError, u as finalizeTransportStream, v as sanitizeTransportPayloadText, w as parseJsonPreservingUnsafeIntegers, x as withProviderAcceptanceObserver, y as throwIfModelStreamAborted } from "./transport-stream-shared-Dh5qKJ8e.mjs";
|
|
13
|
+
import { D as sortPromptCacheToolsByName, l as codeModeToolSurfaceObserver, s as prepareModelRequestBody, t as adjustMaxTokensForThinking, u as reasoningTagTextPolicy } from "./simple-options-CGAkCwtM.mjs";
|
|
14
|
+
import { A as redactIdentifier, C as log, D as readOpenAICompletionsReasoningBatch, E as readOpenAICompletionsContentDeltas, O as resolveOpenAIClientBaseUrl, S as isOpenAICompletionsThinkingEnabled, T as parseOpenAICompletionsUsage, _ as resolveOpenAIReasoningEffortMap, a as enforceCodeModeResponsesToolSurface, b as createOpenAIResponseHook, c as readCodeModePayloadToolName, i as buildOpenAISdkRequestOptions, j as sha256Hex, k as resolvePromptCacheKey, 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 measureUtf8AppendBytes, x as createResponseModelTracker, y as createOpenAIProviderAcceptanceHook } from "./openai-transport-params-BwlpzX-2.mjs";
|
|
15
|
+
import { n as getEnvApiKey } from "./env-api-keys-CyX4VKGO.mjs";
|
|
17
16
|
import { t as createDeferredEventBuffer } from "./deferred-event-buffer-DAvyP7qA.mjs";
|
|
18
|
-
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-
|
|
17
|
+
import { n as providerReplayContextMatches, t as buildProviderReplayContext } from "./provider-replay-context-DsyI5jOP.mjs";
|
|
19
18
|
import { a as tagUnresolvedTextAsCommentary } from "./assistant-text-phase-C20rxWwP.mjs";
|
|
20
|
-
import {
|
|
19
|
+
import { n as createAssistantOutput } from "./provider-transcript-transform-JbFbHV8h.mjs";
|
|
21
20
|
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 { 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-
|
|
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 { A as
|
|
21
|
+
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-CDCuw3DP.mjs";
|
|
22
|
+
import { a as googleFlashSupportsMinimalThinking, i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, t as convertGoogleTools } from "./google-messages-CtjVtVot.mjs";
|
|
23
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-B9o0S4SZ.mjs";
|
|
24
|
+
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-CLxnqS9p.mjs";
|
|
25
|
+
import { r as resolveProviderTransportTurnState, t as filterProviderTurnHeadersForExplicitOpencodeSession } from "./provider-transport-turn-state-BheUi_hl.mjs";
|
|
26
|
+
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-UNK1GDpy.mjs";
|
|
27
|
+
import { $ as OPENAI_RESPONSES_FUNCTION_CALL_ITEM_ID_RE, A as recordResponsesContextUsage, B as resolveResponsesContinuationRequest, C as resolveAzureOpenAIApiVersion, D as safeDebugValue, E as logResponsesFailedNoDetails, G as supportsResponsesReasoningUpdate, H as responsesContinuationRequestFingerprint, I as recordResponsesInputReplay, J as captureOpenAIResponsesCompaction, K as CompactionReplayRefreshRequiredError, L as responsesInputFingerprint, O as summarizeOpenAITransportError, Q as OPENAI_RESPONSES_CALL_ID_RE, R as claimOpenAIResponsesHttpContinuation, S as isInvalidEncryptedContentError, T as ResponsesStreamFailure, U as isConfigurationUpdate, V as responsesContinuationPrefixFingerprint, W as replayResponsesReasoningUpdates, X as resolveNewestOpenAIResponsesCompactionReplay, Y as isOpenAIResponsesReplayContext, Z as suppressOpenAIResponsesCompaction, c as observeResponsesStream, et as OPENAI_RESPONSES_ID_MAX_LENGTH, it as resolveReplayableResponsesMessageId, j as resolveResponsesContextUsageBoundary, k as summarizeResponsesPayload, n as applyResponsesServiceTierPricing, nt as shouldNormalizeOpenAIResponsesToolCallId, q as buildOpenAIResponsesReasoningReplayMetadata, rt as splitOpenAIFunctionCallPairing, s as processResponsesStream, tt as normalizeOpenAIResponsesFunctionCallId, w as resolveNextResponsesEncryptedContentAttempt, x as createResponsesStreamWithEncryptedContentRetry, z as recordResponsesContinuationState } from "./openai-responses-shared-DL4ulQn7.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
|
-
import { a as sanitizeOpenAICodexResponsesParams, n as buildOpenAIResponsesCompactSystemMessage, r as buildOpenAIResponsesParams, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
30
|
+
import { a as sanitizeOpenAICodexResponsesParams, n as buildOpenAIResponsesCompactSystemMessage, r as buildOpenAIResponsesParams, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-iAqLb4tk.mjs";
|
|
31
|
+
import { n as withResponsesRequestAcceptance, t as responsesRequestLifecycle } from "./openai-responses-request-lifecycle-Fsag-IGZ.mjs";
|
|
32
32
|
import { randomUUID } from "node:crypto";
|
|
33
33
|
import OpenAI, { AzureOpenAI } from "openai";
|
|
34
34
|
import { ResponsesWS } from "openai/resources/responses/ws.js";
|
|
35
|
-
//#region packages/ai/src/transports/anthropic-transport-
|
|
36
|
-
/**
|
|
37
|
-
* Native Anthropic Messages streaming transport.
|
|
38
|
-
* Converts OpenClaw contexts/tools into Anthropic payloads, streams SSE events
|
|
39
|
-
* back into runtime output blocks, and applies provider request policy.
|
|
40
|
-
*/
|
|
41
|
-
const ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES = 8192;
|
|
42
|
-
const ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS = 400;
|
|
43
|
-
const ANTHROPIC_MESSAGES_ERROR_BODY_READ_IDLE_TIMEOUT_MS = 1e4;
|
|
35
|
+
//#region packages/ai/src/transports/anthropic-transport-options.ts
|
|
44
36
|
const ANTHROPIC_MESSAGES_DEFAULT_MAX_TOKENS = 4096;
|
|
45
37
|
const ANTHROPIC_MESSAGES_FALLBACK_CONTEXT_DIVISOR = 4;
|
|
46
|
-
const ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS = 16777216;
|
|
47
|
-
function resolveAnthropicRequestModelId(model) {
|
|
48
|
-
if (isDirectAnthropicModel(model) && /^anthropic\//i.test(model.id)) return model.id.replace(/^anthropic\//i, "");
|
|
49
|
-
return model.id;
|
|
50
|
-
}
|
|
51
|
-
const EMPTY_ANTHROPIC_MESSAGES_FALLBACK_TEXT = ".";
|
|
52
38
|
function resolvePositiveAnthropicTokenLimit(value) {
|
|
53
39
|
if (typeof value !== "number" || !Number.isFinite(value)) return;
|
|
54
40
|
const floored = Math.floor(value);
|
|
@@ -63,6 +49,72 @@ function resolveAnthropicMessagesMaxTokens(params) {
|
|
|
63
49
|
const contextWindow = resolvePositiveAnthropicTokenLimit(params.modelContextWindow);
|
|
64
50
|
return contextWindow === void 0 ? ANTHROPIC_MESSAGES_DEFAULT_MAX_TOKENS : Math.max(1, Math.min(ANTHROPIC_MESSAGES_DEFAULT_MAX_TOKENS, Math.floor(contextWindow / ANTHROPIC_MESSAGES_FALLBACK_CONTEXT_DIVISOR)));
|
|
65
51
|
}
|
|
52
|
+
function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
53
|
+
const baseMaxTokens = resolveAnthropicMessagesMaxTokens({
|
|
54
|
+
modelContextWindow: model.contextWindow,
|
|
55
|
+
modelMaxTokens: model.maxTokens,
|
|
56
|
+
requestedMaxTokens: options?.maxTokens,
|
|
57
|
+
useModelDefault: resolveClaudeSonnet5ModelIdentity(model) !== void 0 || resolveClaudeOpus5ModelIdentity(model) !== void 0
|
|
58
|
+
});
|
|
59
|
+
if (baseMaxTokens === void 0) throw new Error(`Anthropic Messages transport requires a positive maxTokens value for ${model.provider}/${model.id}`);
|
|
60
|
+
const reasoningModelMaxTokens = resolvePositiveAnthropicTokenLimit(model.maxTokens) ?? baseMaxTokens;
|
|
61
|
+
const mandatoryAdaptiveThinking = requiresClaudeAdaptiveThinking(model);
|
|
62
|
+
const reasoning = options?.reasoning === "off" && mandatoryAdaptiveThinking ? "low" : options?.reasoning;
|
|
63
|
+
const resolved = copyProviderAcceptanceObserver(options, {
|
|
64
|
+
temperature: options?.temperature,
|
|
65
|
+
stop: options?.stop,
|
|
66
|
+
maxTokens: baseMaxTokens,
|
|
67
|
+
signal: options?.signal,
|
|
68
|
+
apiKey,
|
|
69
|
+
cacheRetention: options?.cacheRetention,
|
|
70
|
+
sessionId: options?.sessionId,
|
|
71
|
+
headers: options?.headers,
|
|
72
|
+
onPayload: options?.onPayload,
|
|
73
|
+
onResponse: options?.onResponse,
|
|
74
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
75
|
+
metadata: options?.metadata,
|
|
76
|
+
interleavedThinking: options?.interleavedThinking,
|
|
77
|
+
toolChoice: options?.toolChoice,
|
|
78
|
+
thinkingBudgets: options?.thinkingBudgets,
|
|
79
|
+
thinkingDisplay: options?.thinkingDisplay,
|
|
80
|
+
reasoning,
|
|
81
|
+
anthropicServerCompaction: options?.anthropicServerCompaction,
|
|
82
|
+
anthropicCompactThreshold: options?.anthropicCompactThreshold,
|
|
83
|
+
cacheTtlPruning: options?.cacheTtlPruning,
|
|
84
|
+
...options?.authProfileId ? { authProfileId: options.authProfileId } : {}
|
|
85
|
+
});
|
|
86
|
+
if (reasoning === "off") {
|
|
87
|
+
resolved.thinkingEnabled = false;
|
|
88
|
+
return resolved;
|
|
89
|
+
}
|
|
90
|
+
if (!reasoning) {
|
|
91
|
+
resolved.thinkingEnabled = defaultsClaudeAdaptiveThinking(model);
|
|
92
|
+
if (resolved.thinkingEnabled) resolved.effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
93
|
+
return resolved;
|
|
94
|
+
}
|
|
95
|
+
if (supportsClaudeAdaptiveThinking(model)) {
|
|
96
|
+
resolved.thinkingEnabled = true;
|
|
97
|
+
resolved.effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
98
|
+
return resolved;
|
|
99
|
+
}
|
|
100
|
+
const adjusted = adjustMaxTokensForThinking(baseMaxTokens, reasoningModelMaxTokens, reasoning === "max" ? "high" : reasoning, options?.thinkingBudgets);
|
|
101
|
+
const thinkingEnabled = adjusted.thinkingBudget >= 1024;
|
|
102
|
+
resolved.maxTokens = adjusted.maxTokens;
|
|
103
|
+
resolved.thinkingEnabled = thinkingEnabled;
|
|
104
|
+
resolved.thinkingBudgetTokens = thinkingEnabled ? adjusted.thinkingBudget : void 0;
|
|
105
|
+
return resolved;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region packages/ai/src/transports/anthropic-transport-stream.ts
|
|
109
|
+
const ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES = 8192;
|
|
110
|
+
const ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS = 400;
|
|
111
|
+
const ANTHROPIC_MESSAGES_ERROR_BODY_READ_IDLE_TIMEOUT_MS = 1e4;
|
|
112
|
+
const ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS = 16777216;
|
|
113
|
+
function resolveAnthropicRequestModelId(model) {
|
|
114
|
+
if (isDirectAnthropicModel(model) && /^anthropic\//i.test(model.id)) return model.id.replace(/^anthropic\//i, "");
|
|
115
|
+
return model.id;
|
|
116
|
+
}
|
|
117
|
+
const EMPTY_ANTHROPIC_MESSAGES_FALLBACK_TEXT = ".";
|
|
66
118
|
function isKimiAnthropicProvider(provider) {
|
|
67
119
|
return /^kimi(?:-|$)/.test(normalizeLowercaseStringOrEmpty(provider ?? ""));
|
|
68
120
|
}
|
|
@@ -72,7 +124,7 @@ function isKimiAnthropicProvider(provider) {
|
|
|
72
124
|
* identity) requests are excluded until the beta is verified there.
|
|
73
125
|
*/
|
|
74
126
|
function useAnthropicServerSideFallback(model) {
|
|
75
|
-
return (usesClaudeFable5MessagesContract(model) || resolveClaudeOpus5ModelIdentity(model) !== void 0) && isDirectAnthropicModel(model);
|
|
127
|
+
return (usesClaudeFable5MessagesContract(model) || resolveClaudeOpus5ModelIdentity(model) !== void 0 || resolveClaudeSonnet55ModelIdentity(model) !== void 0) && isDirectAnthropicModel(model);
|
|
76
128
|
}
|
|
77
129
|
function supportsReasoningContentReplay(model) {
|
|
78
130
|
return resolveProviderEndpoint(model).endpointClass === "xiaomi-native";
|
|
@@ -154,31 +206,27 @@ async function* parseAnthropicSseBody(body, signal) {
|
|
|
154
206
|
const decoder = new TextDecoder();
|
|
155
207
|
let buffer = "";
|
|
156
208
|
let completed = false;
|
|
209
|
+
const delimiter = /(?:\r\n|\r(?!\n)|\n)(?:\r\n|\r(?!\n)|\n)/g;
|
|
210
|
+
let scanOffset = 0;
|
|
157
211
|
try {
|
|
158
|
-
while (
|
|
212
|
+
while (!completed) {
|
|
159
213
|
const { done, value } = await readAnthropicSseChunk(reader, signal);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
214
|
+
completed = done;
|
|
215
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
216
|
+
delimiter.lastIndex = scanOffset;
|
|
217
|
+
for (;;) {
|
|
218
|
+
const boundary = delimiter.exec(buffer);
|
|
219
|
+
if (!boundary && (!completed || !buffer)) break;
|
|
220
|
+
const frameEnd = boundary?.index ?? buffer.length;
|
|
167
221
|
assertAnthropicSsePendingBufferWithinLimit(frameEnd);
|
|
168
|
-
const frame = buffer.slice(0, frameEnd);
|
|
169
|
-
buffer = buffer.slice(frameEnd +
|
|
170
|
-
|
|
222
|
+
const frame = boundary ? buffer.slice(0, frameEnd) : buffer.trim();
|
|
223
|
+
buffer = boundary ? buffer.slice(frameEnd + boundary[0].length) : "";
|
|
224
|
+
delimiter.lastIndex = 0;
|
|
225
|
+
const data = frame.split(/\r\n|\n|\r/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart()).join("\n");
|
|
171
226
|
if (data && data !== "[DONE]") yield parseAnthropicSseEventData(data);
|
|
172
|
-
frameEnd = buffer.indexOf("\n\n");
|
|
173
227
|
}
|
|
174
228
|
assertAnthropicSsePendingBufferWithinLimit(buffer.length);
|
|
175
|
-
|
|
176
|
-
const tailBuffer = `${buffer}${decoder.decode()}`.replaceAll("\r\n", "\n");
|
|
177
|
-
assertAnthropicSsePendingBufferWithinLimit(tailBuffer.length);
|
|
178
|
-
const tail = tailBuffer.trim();
|
|
179
|
-
if (tail) {
|
|
180
|
-
const data = tail.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart()).join("\n");
|
|
181
|
-
if (data && data !== "[DONE]") yield parseAnthropicSseEventData(data);
|
|
229
|
+
scanOffset = Math.max(0, buffer.length - 3);
|
|
182
230
|
}
|
|
183
231
|
} finally {
|
|
184
232
|
if (!completed) {
|
|
@@ -189,9 +237,9 @@ async function* parseAnthropicSseBody(body, signal) {
|
|
|
189
237
|
reader.releaseLock();
|
|
190
238
|
}
|
|
191
239
|
}
|
|
192
|
-
function
|
|
240
|
+
function createAnthropicMessageRequest(params) {
|
|
193
241
|
const url = resolveAnthropicMessagesUrl(params.baseURL);
|
|
194
|
-
return
|
|
242
|
+
return async (body, options) => {
|
|
195
243
|
const headers = new Headers(mergeTransportHeaders({
|
|
196
244
|
"content-type": "application/json",
|
|
197
245
|
"anthropic-version": "2023-06-01",
|
|
@@ -209,7 +257,7 @@ function createAnthropicMessagesClient(params) {
|
|
|
209
257
|
response,
|
|
210
258
|
stream: response.body ? parseAnthropicSseBody(response.body, options?.signal) : []
|
|
211
259
|
};
|
|
212
|
-
}
|
|
260
|
+
};
|
|
213
261
|
}
|
|
214
262
|
async function readAnthropicMessagesErrorBody(response) {
|
|
215
263
|
try {
|
|
@@ -235,27 +283,11 @@ function createAnthropicTransportClient(params) {
|
|
|
235
283
|
const optionHeaders = resolveOpencodeSessionHeaders(model, options);
|
|
236
284
|
const needsInterleavedBeta = (options?.interleavedThinking ?? true) && !supportsClaudeAdaptiveThinking(model);
|
|
237
285
|
const fetch = isKimiAnthropicProvider(model.provider) && options?.thinkingEnabled === true ? buildGuardedModelFetch(model, void 0, { sanitizeSse: false }) : buildGuardedModelFetch(model);
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return {
|
|
241
|
-
client: createAnthropicMessagesClient({
|
|
242
|
-
apiKey: null,
|
|
243
|
-
authToken: apiKey,
|
|
244
|
-
baseURL: model.baseUrl,
|
|
245
|
-
defaultHeaders: mergeTransportHeaders({
|
|
246
|
-
accept: "application/json",
|
|
247
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
248
|
-
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
249
|
-
}, model.headers, getAiTransportHost().buildCopilotDynamicHeaders(context.messages), optionHeaders),
|
|
250
|
-
fetch
|
|
251
|
-
}),
|
|
252
|
-
isOAuthToken: false
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
if (usesFoundryBearerAuth(resolveModelHeaderSentinels(model))) {
|
|
286
|
+
const copilot = model.provider === "github-copilot";
|
|
287
|
+
if (copilot || usesFoundryBearerAuth(resolveModelHeaderSentinels(model))) {
|
|
256
288
|
const betaFeatures = needsInterleavedBeta ? ["interleaved-thinking-2025-05-14"] : [];
|
|
257
289
|
return {
|
|
258
|
-
|
|
290
|
+
request: createAnthropicMessageRequest({
|
|
259
291
|
apiKey: null,
|
|
260
292
|
authToken: apiKey,
|
|
261
293
|
baseURL: model.baseUrl,
|
|
@@ -263,7 +295,7 @@ function createAnthropicTransportClient(params) {
|
|
|
263
295
|
accept: "application/json",
|
|
264
296
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
265
297
|
...betaFeatures.length > 0 ? { "anthropic-beta": betaFeatures.join(",") } : {}
|
|
266
|
-
}, omitFoundryBearerCredentialHeaders(model.headers), optionHeaders),
|
|
298
|
+
}, copilot ? model.headers : omitFoundryBearerCredentialHeaders(model.headers), copilot ? getAiTransportHost().buildCopilotDynamicHeaders(context.messages) : void 0, optionHeaders),
|
|
267
299
|
fetch
|
|
268
300
|
}),
|
|
269
301
|
isOAuthToken: false
|
|
@@ -273,32 +305,28 @@ function createAnthropicTransportClient(params) {
|
|
|
273
305
|
if (needsInterleavedBeta) betaFeatures.push("interleaved-thinking-2025-05-14");
|
|
274
306
|
if (isAnthropicOAuthApiKey(apiKey)) {
|
|
275
307
|
const betaHeader = buildAnthropicBetaHeader(model, betaFeatures, { oauth: true });
|
|
308
|
+
const identity = buildAnthropicClaudeCodeIdentity(betaHeader, model.headers, optionHeaders);
|
|
276
309
|
return {
|
|
277
|
-
|
|
310
|
+
request: createAnthropicMessageRequest({
|
|
278
311
|
apiKey: null,
|
|
279
312
|
authToken: apiKey,
|
|
280
313
|
baseURL: model.baseUrl,
|
|
281
|
-
defaultHeaders:
|
|
282
|
-
accept: "application/json",
|
|
283
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
284
|
-
...betaHeader ? { "anthropic-beta": betaHeader } : {},
|
|
285
|
-
"user-agent": `claude-cli/${ANTHROPIC_CLAUDE_CODE_VERSION}`,
|
|
286
|
-
"x-app": "cli"
|
|
287
|
-
}, model.headers, optionHeaders),
|
|
314
|
+
defaultHeaders: identity.headers,
|
|
288
315
|
fetch
|
|
289
316
|
}),
|
|
290
|
-
isOAuthToken: true
|
|
317
|
+
isOAuthToken: true,
|
|
318
|
+
claudeCodeVersion: identity.version
|
|
291
319
|
};
|
|
292
320
|
}
|
|
293
|
-
if (useAnthropicServerSideFallback(model)) betaFeatures.push(ANTHROPIC_SERVER_SIDE_FALLBACK_BETA);
|
|
294
321
|
const betaHeader = buildAnthropicBetaHeader(model, betaFeatures, { oauth: false });
|
|
295
322
|
const defaultHeaders = mergeTransportHeaders({
|
|
296
323
|
accept: "application/json",
|
|
297
324
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
298
|
-
...betaHeader ? { "anthropic-beta": betaHeader } : {}
|
|
325
|
+
...betaHeader ? { "anthropic-beta": betaHeader } : {},
|
|
326
|
+
...options?.sessionId && options.cacheRetention !== "none" && model.compat?.sendSessionAffinityHeaders === true ? { "x-session-affinity": options.sessionId } : {}
|
|
299
327
|
}, model.headers, optionHeaders);
|
|
300
328
|
return {
|
|
301
|
-
|
|
329
|
+
request: createAnthropicMessageRequest({
|
|
302
330
|
apiKey,
|
|
303
331
|
baseURL: model.baseUrl,
|
|
304
332
|
defaultHeaders,
|
|
@@ -308,7 +336,7 @@ function createAnthropicTransportClient(params) {
|
|
|
308
336
|
directApiKeyBetaHeader: isDirectAnthropicModel(model) ? new Headers(defaultHeaders).get("anthropic-beta") ?? "" : void 0
|
|
309
337
|
};
|
|
310
338
|
}
|
|
311
|
-
async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
339
|
+
async function buildAnthropicParams(model, context, isOAuthToken, options, claudeCodeVersion) {
|
|
312
340
|
const replayThinkingEnabled = requiresClaudeAdaptiveThinking(model) || options?.thinkingEnabled === true;
|
|
313
341
|
const maxTokens = resolveAnthropicMessagesMaxTokens({
|
|
314
342
|
modelContextWindow: model.contextWindow,
|
|
@@ -323,7 +351,7 @@ async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
|
323
351
|
sessionId: options?.sessionId
|
|
324
352
|
});
|
|
325
353
|
const cacheBreakpointOptOutMessageIndexes = /* @__PURE__ */ new Set();
|
|
326
|
-
const messages = await convertAnthropicMessages(transformTransportMessages(replayPlan.messages, model, normalizeAnthropicToolCallId), model, isOAuthToken, {
|
|
354
|
+
const messages = await convertAnthropicMessages(getAiTransportHost().transformTransportMessages(replayPlan.messages, model, normalizeAnthropicToolCallId, void 0), model, isOAuthToken, {
|
|
327
355
|
profile: "transport",
|
|
328
356
|
allowReasoningContentReplay: supportsReasoningContentReplay(model),
|
|
329
357
|
allowEmptySignature: model.compat?.allowEmptySignature,
|
|
@@ -338,7 +366,7 @@ async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
|
338
366
|
stream: true
|
|
339
367
|
};
|
|
340
368
|
if (!isOAuthToken && useAnthropicServerSideFallback(model)) params.fallbacks = ANTHROPIC_SERVER_SIDE_FALLBACKS;
|
|
341
|
-
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthToken, cacheControl);
|
|
369
|
+
const system = buildAnthropicSystemBlocks(context.systemPrompt, isOAuthToken, cacheControl, claudeCodeVersion);
|
|
342
370
|
if (system) params.system = system;
|
|
343
371
|
const convertedTools = context.tools ? convertAnthropicTools(context.tools, isOAuthToken) : void 0;
|
|
344
372
|
const toolProjection = convertedTools?.projection;
|
|
@@ -356,60 +384,6 @@ async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
|
356
384
|
usedCompactionReplay: replayPlan.compaction !== void 0
|
|
357
385
|
};
|
|
358
386
|
}
|
|
359
|
-
function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
360
|
-
const baseMaxTokens = resolveAnthropicMessagesMaxTokens({
|
|
361
|
-
modelContextWindow: model.contextWindow,
|
|
362
|
-
modelMaxTokens: model.maxTokens,
|
|
363
|
-
requestedMaxTokens: options?.maxTokens,
|
|
364
|
-
useModelDefault: resolveClaudeSonnet5ModelIdentity(model) !== void 0 || resolveClaudeOpus5ModelIdentity(model) !== void 0
|
|
365
|
-
});
|
|
366
|
-
if (baseMaxTokens === void 0) throw new Error(`Anthropic Messages transport requires a positive maxTokens value for ${model.provider}/${model.id}`);
|
|
367
|
-
const reasoningModelMaxTokens = resolvePositiveAnthropicTokenLimit(model.maxTokens) ?? baseMaxTokens;
|
|
368
|
-
const mandatoryAdaptiveThinking = requiresClaudeAdaptiveThinking(model);
|
|
369
|
-
const reasoning = options?.reasoning === "off" && mandatoryAdaptiveThinking ? "low" : options?.reasoning;
|
|
370
|
-
const resolved = copyProviderAcceptanceObserver(options, {
|
|
371
|
-
temperature: options?.temperature,
|
|
372
|
-
stop: options?.stop,
|
|
373
|
-
maxTokens: baseMaxTokens,
|
|
374
|
-
signal: options?.signal,
|
|
375
|
-
apiKey,
|
|
376
|
-
cacheRetention: options?.cacheRetention,
|
|
377
|
-
sessionId: options?.sessionId,
|
|
378
|
-
headers: options?.headers,
|
|
379
|
-
onPayload: options?.onPayload,
|
|
380
|
-
onResponse: options?.onResponse,
|
|
381
|
-
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
382
|
-
metadata: options?.metadata,
|
|
383
|
-
interleavedThinking: options?.interleavedThinking,
|
|
384
|
-
toolChoice: options?.toolChoice,
|
|
385
|
-
thinkingBudgets: options?.thinkingBudgets,
|
|
386
|
-
reasoning,
|
|
387
|
-
anthropicServerCompaction: options?.anthropicServerCompaction,
|
|
388
|
-
anthropicCompactThreshold: options?.anthropicCompactThreshold,
|
|
389
|
-
cacheTtlPruning: options?.cacheTtlPruning,
|
|
390
|
-
...options?.authProfileId ? { authProfileId: options.authProfileId } : {}
|
|
391
|
-
});
|
|
392
|
-
if (reasoning === "off") {
|
|
393
|
-
resolved.thinkingEnabled = false;
|
|
394
|
-
return resolved;
|
|
395
|
-
}
|
|
396
|
-
if (!reasoning) {
|
|
397
|
-
resolved.thinkingEnabled = defaultsClaudeAdaptiveThinking(model);
|
|
398
|
-
if (resolved.thinkingEnabled) resolved.effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
399
|
-
return resolved;
|
|
400
|
-
}
|
|
401
|
-
if (supportsClaudeAdaptiveThinking(model)) {
|
|
402
|
-
resolved.thinkingEnabled = true;
|
|
403
|
-
resolved.effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
404
|
-
return resolved;
|
|
405
|
-
}
|
|
406
|
-
const adjusted = adjustMaxTokensForThinking(baseMaxTokens, reasoningModelMaxTokens, reasoning === "max" ? "high" : reasoning, options?.thinkingBudgets);
|
|
407
|
-
const thinkingEnabled = adjusted.thinkingBudget >= 1024;
|
|
408
|
-
resolved.maxTokens = adjusted.maxTokens;
|
|
409
|
-
resolved.thinkingEnabled = thinkingEnabled;
|
|
410
|
-
resolved.thinkingBudgetTokens = thinkingEnabled ? adjusted.thinkingBudget : void 0;
|
|
411
|
-
return resolved;
|
|
412
|
-
}
|
|
413
387
|
/** Create the stream function used by Anthropic Messages transport models. */
|
|
414
388
|
function createAnthropicMessagesTransportStreamFn() {
|
|
415
389
|
return (rawModel, context, rawOptions) => {
|
|
@@ -425,22 +399,22 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
425
399
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
426
400
|
const transportOptions = resolveAnthropicTransportOptions(model, options, apiKey);
|
|
427
401
|
const requestContext = prepareClaudeNoPrefillRequestContext(model, context);
|
|
428
|
-
const {
|
|
402
|
+
const { request, isOAuthToken, directApiKeyBetaHeader, claudeCodeVersion } = createAnthropicTransportClient({
|
|
429
403
|
model,
|
|
430
404
|
context: requestContext,
|
|
431
405
|
apiKey,
|
|
432
406
|
options: transportOptions
|
|
433
407
|
});
|
|
434
|
-
const builtParams = await buildAnthropicParams(model, requestContext, isOAuthToken, transportOptions);
|
|
408
|
+
const builtParams = await buildAnthropicParams(model, requestContext, isOAuthToken, transportOptions, claudeCodeVersion);
|
|
435
409
|
usedCompactionReplay = builtParams.usedCompactionReplay;
|
|
436
410
|
let params = builtParams.params;
|
|
437
411
|
applyAnthropicContextManagementToRequest(params, model, transportOptions, directApiKeyBetaHeader);
|
|
438
412
|
const nextParams = await transportOptions.onPayload?.(params, model);
|
|
439
413
|
if (nextParams !== void 0) params = nextParams;
|
|
440
414
|
applyClaudeRequestContract(params, model);
|
|
441
|
-
const betaHeader =
|
|
415
|
+
const betaHeader = resolveAnthropicRequestBetaHeader(params, directApiKeyBetaHeader);
|
|
442
416
|
const bindingHeaders = applyAnthropicThinkingBindingControls(params, betaHeader) ?? (betaHeader ? { "anthropic-beta": betaHeader } : void 0);
|
|
443
|
-
const { response, stream: anthropicStream } = await
|
|
417
|
+
const { response, stream: anthropicStream } = await request({
|
|
444
418
|
...params,
|
|
445
419
|
stream: true
|
|
446
420
|
}, {
|
|
@@ -615,29 +589,7 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
615
589
|
return (model, context, options) => {
|
|
616
590
|
const { eventStream, stream } = createWritableTransportEventStream();
|
|
617
591
|
(async () => {
|
|
618
|
-
const output =
|
|
619
|
-
role: "assistant",
|
|
620
|
-
content: [],
|
|
621
|
-
api: model.api,
|
|
622
|
-
provider: model.provider,
|
|
623
|
-
model: model.id,
|
|
624
|
-
usage: {
|
|
625
|
-
input: 0,
|
|
626
|
-
output: 0,
|
|
627
|
-
cacheRead: 0,
|
|
628
|
-
cacheWrite: 0,
|
|
629
|
-
totalTokens: 0,
|
|
630
|
-
cost: {
|
|
631
|
-
input: 0,
|
|
632
|
-
output: 0,
|
|
633
|
-
cacheRead: 0,
|
|
634
|
-
cacheWrite: 0,
|
|
635
|
-
total: 0
|
|
636
|
-
}
|
|
637
|
-
},
|
|
638
|
-
stopReason: "stop",
|
|
639
|
-
timestamp: Date.now()
|
|
640
|
-
};
|
|
592
|
+
const output = createAssistantOutput(model);
|
|
641
593
|
let firstEventAbort;
|
|
642
594
|
try {
|
|
643
595
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
@@ -676,6 +628,7 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
676
628
|
...optionHeaders
|
|
677
629
|
}, void 0, resolvePromptCacheKey(options, cacheRetention), cacheRetention), { fetch: doneDetectingFetch });
|
|
678
630
|
let params = buildOpenAICompletionsParams(model, context, options);
|
|
631
|
+
const encodeBody = prepareModelRequestBody(options);
|
|
679
632
|
const nextParams = await options?.onPayload?.(params, model);
|
|
680
633
|
if (nextParams !== void 0) params = nextParams;
|
|
681
634
|
if (options?.openclawCodeModeToolSurface === true) {
|
|
@@ -686,7 +639,10 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
686
639
|
if (getCompat(model).requiresNonEmptyUserOrAssistantMessage) assertOpenAICompletionsPayloadHasConversationTurn(params, model);
|
|
687
640
|
const emitReasoning = shouldEmitOpenAICompletionsReasoning(model, options);
|
|
688
641
|
firstEventAbort = createFirstStreamEventAbortController(options?.signal);
|
|
689
|
-
const { data: responseStream, response } = await client.chat.completions.create(params,
|
|
642
|
+
const { data: responseStream, response } = await client.chat.completions.create(params, {
|
|
643
|
+
...buildOpenAISdkRequestOptions(model, firstEventAbort.signal, { timeoutMs: options?.timeoutMs }),
|
|
644
|
+
...await encodeBody(params)
|
|
645
|
+
}).withResponse();
|
|
690
646
|
const hookedResponseStream = withProviderResponseHook({
|
|
691
647
|
stream: responseStream,
|
|
692
648
|
signal: firstEventAbort.signal,
|
|
@@ -1024,10 +980,11 @@ function createOpenAIResponsesWebSocketStream(params) {
|
|
|
1024
980
|
throw new OpenAIResponsesWebSocketPreDispatchError(error);
|
|
1025
981
|
}
|
|
1026
982
|
let prepared;
|
|
983
|
+
let previousContinuation;
|
|
1027
984
|
const resumedSteering = lease.steeringContinuation;
|
|
1028
985
|
const steeringMode = resumedSteering ? resumedSteering.requiresInput ? "required-input" : "automatic" : void 0;
|
|
1029
986
|
try {
|
|
1030
|
-
const continuation = lease.entry?.continuation;
|
|
987
|
+
const continuation = previousContinuation = lease.entry?.continuation;
|
|
1031
988
|
if (continuation && lease.entry) {
|
|
1032
989
|
lease.entry.continuation = void 0;
|
|
1033
990
|
prepared = resolveResponsesContinuationRequest(continuation, fullRequest, steeringMode);
|
|
@@ -1093,11 +1050,7 @@ function createOpenAIResponsesWebSocketStream(params) {
|
|
|
1093
1050
|
const finish = ({ keep = true } = {}) => {
|
|
1094
1051
|
if (released) return;
|
|
1095
1052
|
released = true;
|
|
1096
|
-
if (keep && lease.entry && terminalResponse) lease.entry.continuation =
|
|
1097
|
-
lastRequest: prepared.fullRequest ?? fullRequest,
|
|
1098
|
-
lastResponseId: terminalResponse.id,
|
|
1099
|
-
lastResponseItems: terminalResponse.output
|
|
1100
|
-
};
|
|
1053
|
+
if (keep && lease.entry && terminalResponse) lease.entry.continuation = recordResponsesContinuationState(previousContinuation, prepared.fullRequest ?? fullRequest, terminalResponse, previousContinuation?.lastResponseId === prepared.request.previous_response_id);
|
|
1101
1054
|
lease.release({ keep });
|
|
1102
1055
|
};
|
|
1103
1056
|
return {
|
|
@@ -1337,6 +1290,36 @@ function restoreResponsesReasoningState(context, model, identity, request) {
|
|
|
1337
1290
|
return prepared;
|
|
1338
1291
|
}
|
|
1339
1292
|
//#endregion
|
|
1293
|
+
//#region packages/ai/src/transports/openai-responses-request-fetch.ts
|
|
1294
|
+
function withDefaultResponsesStreamEncoding(fetch) {
|
|
1295
|
+
return (input, init) => {
|
|
1296
|
+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
|
|
1297
|
+
if (headers.has("accept-encoding")) return fetch(input, init);
|
|
1298
|
+
headers.set("accept-encoding", "identity");
|
|
1299
|
+
return fetch(input, {
|
|
1300
|
+
...init,
|
|
1301
|
+
headers
|
|
1302
|
+
});
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
/** Preserve the existing fetch policy while binding explicit continuation dispatch to its signal. */
|
|
1306
|
+
function createResponsesRequestFetch(model, options) {
|
|
1307
|
+
const lifecycle = options.lifecycle;
|
|
1308
|
+
if (lifecycle && options.compact) throw new Error("Provider review continuation cannot replace its reviewed input with compaction");
|
|
1309
|
+
let fetchOverride = options.compact ? createBoundedOpenAIResponsesCompactionFetch(buildGuardedModelFetch(model)) : options.stream ? withDefaultResponsesStreamEncoding(buildGuardedModelFetch(model)) : void 0;
|
|
1310
|
+
if (lifecycle) {
|
|
1311
|
+
const dispatchFetch = fetchOverride ?? buildGuardedModelFetch(model);
|
|
1312
|
+
fetchOverride = async (input, init) => {
|
|
1313
|
+
const signal = init?.signal ?? (input instanceof Request ? input.signal : void 0);
|
|
1314
|
+
await lifecycle.beforeDispatch(signal ?? void 0);
|
|
1315
|
+
signal?.throwIfAborted();
|
|
1316
|
+
lifecycle.assertCurrent();
|
|
1317
|
+
return dispatchFetch(input, init);
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
return fetchOverride;
|
|
1321
|
+
}
|
|
1322
|
+
//#endregion
|
|
1340
1323
|
//#region packages/ai/src/transports/openai-responses-client.ts
|
|
1341
1324
|
function resolveNativeOpenAIResponsesWebSocketMode(model, transport) {
|
|
1342
1325
|
if (transport !== "websocket" && transport !== "websocket-cached" && transport !== "auto") return;
|
|
@@ -1362,29 +1345,20 @@ function createOpenAIResponsesClient(model, apiKey, defaultHeaders, fetchOverrid
|
|
|
1362
1345
|
...buildOpenAISdkClientOptions(model)
|
|
1363
1346
|
});
|
|
1364
1347
|
}
|
|
1365
|
-
function withDefaultResponsesStreamEncoding(fetch) {
|
|
1366
|
-
return (input, init) => {
|
|
1367
|
-
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
|
|
1368
|
-
if (headers.has("accept-encoding")) return fetch(input, init);
|
|
1369
|
-
headers.set("accept-encoding", "identity");
|
|
1370
|
-
return fetch(input, {
|
|
1371
|
-
...init,
|
|
1372
|
-
headers
|
|
1373
|
-
});
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
1348
|
function createResponsesTransportExecutor(config) {
|
|
1377
1349
|
return (model, context, options) => {
|
|
1378
1350
|
const responsesOptions = options;
|
|
1379
1351
|
const compactRequest = claimResponsesCompactRequest(responsesOptions);
|
|
1380
1352
|
const { eventStream, stream } = createWritableTransportEventStream();
|
|
1381
1353
|
(async () => {
|
|
1382
|
-
const output =
|
|
1354
|
+
const output = createAssistantOutput(model, config.outputApi);
|
|
1383
1355
|
let firstEventAbort;
|
|
1384
1356
|
let continuationClaim;
|
|
1357
|
+
const requestLifecycle = responsesRequestLifecycle.get(options);
|
|
1385
1358
|
try {
|
|
1386
1359
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
1387
1360
|
const websocketMode = resolveNativeOpenAIResponsesWebSocketMode(model, responsesOptions?.transport);
|
|
1361
|
+
const encodeBody = prepareModelRequestBody(websocketMode || compactRequest ? void 0 : options);
|
|
1388
1362
|
const turnState = resolveProviderTransportTurnState(model, {
|
|
1389
1363
|
sessionId: options?.sessionId,
|
|
1390
1364
|
turnId: randomUUID(),
|
|
@@ -1396,14 +1370,18 @@ function createResponsesTransportExecutor(config) {
|
|
|
1396
1370
|
const websocketTurnHeaders = filterProviderTurnHeadersForExplicitOpencodeSession(model, options, websocketSessionPolicy?.headers);
|
|
1397
1371
|
const websocketHeaders = websocketMode ? buildOpenAIClientHeaders(model, context, options?.headers, websocketTurnHeaders, options?.sessionId, options?.cacheRetention) : void 0;
|
|
1398
1372
|
const httpHeaders = buildOpenAIClientHeaders(model, context, options?.headers, httpTurnHeaders, options?.sessionId, options?.cacheRetention);
|
|
1399
|
-
const
|
|
1373
|
+
const fetchOverride = createResponsesRequestFetch(model, {
|
|
1374
|
+
compact: Boolean(compactRequest),
|
|
1375
|
+
stream: config.streamRequest,
|
|
1376
|
+
lifecycle: requestLifecycle
|
|
1377
|
+
});
|
|
1378
|
+
const client = config.createClient(model, apiKey, httpHeaders, fetchOverride);
|
|
1400
1379
|
const nativeAstra = model.id === "gpt-6-astra" && supportsNativeOpenAIResponsesEndpoint(model);
|
|
1401
1380
|
const asyncToolExecutionEligible = nativeAstra && options?.asyncToolExecution === true && !responsesOptions?.openclawCodeModeToolSurface;
|
|
1402
1381
|
const prepareRequest = async (request) => {
|
|
1403
1382
|
let params = request;
|
|
1404
1383
|
const nextParams = await options?.onPayload?.(params, model);
|
|
1405
1384
|
if (nextParams !== void 0) params = nextParams;
|
|
1406
|
-
if (!isOpenAICodexResponsesModel(model)) params = mergeTransportMetadata(params, turnState?.metadata);
|
|
1407
1385
|
params = sanitizeOpenAICodexResponsesParams(model, params);
|
|
1408
1386
|
params = sanitizeResponsesImagePayload(params);
|
|
1409
1387
|
if (options?.openclawCodeModeToolSurface === true) {
|
|
@@ -1477,6 +1455,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1477
1455
|
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)}`);
|
|
1478
1456
|
const responseModelTracker = createResponseModelTracker(isOpenAICodexResponsesModel(model));
|
|
1479
1457
|
let continuationBaseline;
|
|
1458
|
+
let dispatchedPreviousResponseId;
|
|
1480
1459
|
let contextUsageEligible = true;
|
|
1481
1460
|
const createSseStream = async (initialRequest = continuationClaim?.request ?? params, initialAttemptKind = "initial", initialRejectedCompaction) => {
|
|
1482
1461
|
const { stream: responseStream } = await createResponsesStreamWithEncryptedContentRetry({
|
|
@@ -1484,6 +1463,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1484
1463
|
request: initialRequest,
|
|
1485
1464
|
requestOptions,
|
|
1486
1465
|
model,
|
|
1466
|
+
encodeBody,
|
|
1487
1467
|
observePrompt,
|
|
1488
1468
|
initialAttemptKind,
|
|
1489
1469
|
initialRejectedCompaction,
|
|
@@ -1492,6 +1472,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1492
1472
|
canRetryStream: () => output.content.length === 0,
|
|
1493
1473
|
wrapStream: ({ stream: rawResponseStream, response, attempt }) => {
|
|
1494
1474
|
contextUsageEligible &&= attempt.kind === "initial";
|
|
1475
|
+
dispatchedPreviousResponseId = attempt.request.previous_response_id;
|
|
1495
1476
|
continuationBaseline = attempt.request.previous_response_id ? params : attempt.request;
|
|
1496
1477
|
const trackedResponseStream = responseModelTracker.track(response, rawResponseStream);
|
|
1497
1478
|
return withProviderResponseHook({
|
|
@@ -1592,7 +1573,9 @@ function createResponsesTransportExecutor(config) {
|
|
|
1592
1573
|
}
|
|
1593
1574
|
else responseStream = await createSseStream();
|
|
1594
1575
|
try {
|
|
1595
|
-
const
|
|
1576
|
+
const acceptedResponseStream = withResponsesRequestAcceptance(responseStream, requestLifecycle, transport === "websocket" ? websocketSignal : firstEvent.signal);
|
|
1577
|
+
const terminal = await processResponsesStream(acceptedResponseStream, output, stream, model, {
|
|
1578
|
+
canRetryIdentityConflict: () => hasOnlyResponsesFunctionTools(transport === "websocket" ? websocketBaseline : continuationBaseline),
|
|
1596
1579
|
...config.pricingOptions?.(responsesOptions, model),
|
|
1597
1580
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options) ?? config.firstEventTimeoutMs,
|
|
1598
1581
|
abortFirstEventStream: firstEvent.abort,
|
|
@@ -1610,7 +1593,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1610
1593
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
1611
1594
|
const admitted = transport === "websocket" ? websocketBaseline : continuationBaseline;
|
|
1612
1595
|
if (terminal && admitted && supportsNativeOpenAIResponsesEndpoint(model)) recordResponsesReasoningState(output, model, responsesOptions, admitted, terminal.output);
|
|
1613
|
-
if (continuationClaim && continuationBaseline && terminal) continuationClaim.commit(continuationBaseline, terminal);
|
|
1596
|
+
if (continuationClaim && continuationBaseline && terminal) continuationClaim.commit(continuationBaseline, terminal, dispatchedPreviousResponseId);
|
|
1614
1597
|
if (terminal && admitted && contextUsageEligible) recordResponsesContextUsage(output, model, responsesOptions, admitted, terminal.output, "transport");
|
|
1615
1598
|
} catch (error) {
|
|
1616
1599
|
finishWebSocket?.({ keep: false });
|
|
@@ -1623,6 +1606,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1623
1606
|
signal: options?.signal
|
|
1624
1607
|
});
|
|
1625
1608
|
} catch (error) {
|
|
1609
|
+
if (requestLifecycle) await requestLifecycle.settle().catch(() => void 0);
|
|
1626
1610
|
if (compactRequest) {
|
|
1627
1611
|
compactRequest.reject(error);
|
|
1628
1612
|
failTransportStream({
|
|
@@ -1884,21 +1868,8 @@ const SIMPLE_TRANSPORT_API_ALIAS = {
|
|
|
1884
1868
|
"google-generative-ai": "openclaw-google-generative-ai-transport"
|
|
1885
1869
|
};
|
|
1886
1870
|
function createProviderOwnedGoogleTransportStreamFn(model, ctx) {
|
|
1887
|
-
const
|
|
1888
|
-
provider
|
|
1889
|
-
config: ctx?.cfg,
|
|
1890
|
-
workspaceDir: ctx?.workspaceDir,
|
|
1891
|
-
env: ctx?.env,
|
|
1892
|
-
context: {
|
|
1893
|
-
config: ctx?.cfg,
|
|
1894
|
-
agentDir: ctx?.agentDir,
|
|
1895
|
-
workspaceDir: ctx?.workspaceDir,
|
|
1896
|
-
provider: model.provider,
|
|
1897
|
-
modelId: model.id,
|
|
1898
|
-
model
|
|
1899
|
-
}
|
|
1900
|
-
}) ?? getAiTransportHost().plugin.resolveProviderStream({
|
|
1901
|
-
provider: "google",
|
|
1871
|
+
const resolveStream = (provider) => getAiTransportHost().plugin.resolveProviderStream({
|
|
1872
|
+
provider,
|
|
1902
1873
|
config: ctx?.cfg,
|
|
1903
1874
|
workspaceDir: ctx?.workspaceDir,
|
|
1904
1875
|
env: ctx?.env,
|
|
@@ -1910,7 +1881,8 @@ function createProviderOwnedGoogleTransportStreamFn(model, ctx) {
|
|
|
1910
1881
|
modelId: model.id,
|
|
1911
1882
|
model
|
|
1912
1883
|
}
|
|
1913
|
-
})
|
|
1884
|
+
});
|
|
1885
|
+
const streamFn = resolveStream(model.provider) ?? resolveStream("google") ?? void 0;
|
|
1914
1886
|
return streamFn ? (requestModel, context, options) => streamFn(requestModel, context, {
|
|
1915
1887
|
...options,
|
|
1916
1888
|
headers: resolveOpencodeSessionHeaders(requestModel, options)
|
|
@@ -1927,13 +1899,6 @@ function createSupportedTransportStreamFn(model, ctx) {
|
|
|
1927
1899
|
default: return;
|
|
1928
1900
|
}
|
|
1929
1901
|
}
|
|
1930
|
-
function hasOpenClawTransportRequirement(model) {
|
|
1931
|
-
return getAiTransportHost().requiresManagedTransport(model);
|
|
1932
|
-
}
|
|
1933
|
-
/** Returns whether OpenClaw has a managed transport implementation for this API. */
|
|
1934
|
-
function isTransportAwareApiSupported(api) {
|
|
1935
|
-
return SUPPORTED_TRANSPORT_APIS.has(api);
|
|
1936
|
-
}
|
|
1937
1902
|
/** Maps public model APIs to the internal transport API id used by simple runtime dispatch. */
|
|
1938
1903
|
function resolveTransportAwareSimpleApi(api) {
|
|
1939
1904
|
if (OPENAI_RESPONSES_APIS.has(api)) {
|
|
@@ -1944,19 +1909,17 @@ function resolveTransportAwareSimpleApi(api) {
|
|
|
1944
1909
|
}
|
|
1945
1910
|
/** Creates a managed transport stream only when request overrides require it. */
|
|
1946
1911
|
function createTransportAwareStreamFnForModel(model, ctx) {
|
|
1947
|
-
if (!
|
|
1948
|
-
if (!
|
|
1912
|
+
if (!getAiTransportHost().requiresManagedTransport(model)) return;
|
|
1913
|
+
if (!SUPPORTED_TRANSPORT_APIS.has(model.api)) throw new Error(`Model-provider request.proxy/request.tls/localService is not yet supported for api "${model.api}"`);
|
|
1949
1914
|
const streamFn = createSupportedTransportStreamFn(model, ctx);
|
|
1950
1915
|
if (!streamFn) throw new Error(`Managed transport stream is unavailable for api "${model.api}"`);
|
|
1951
1916
|
return streamFn;
|
|
1952
1917
|
}
|
|
1953
1918
|
/** Creates a managed OpenClaw transport stream for explicit fallback/runtime callers. */
|
|
1954
1919
|
function createOpenClawTransportStreamFnForModel(model, ctx) {
|
|
1955
|
-
if (!isTransportAwareApiSupported(model.api)) return;
|
|
1956
1920
|
return createSupportedTransportStreamFn(model, ctx);
|
|
1957
1921
|
}
|
|
1958
1922
|
function createBoundaryAwareStreamFnForModel(model, ctx) {
|
|
1959
|
-
if (!isTransportAwareApiSupported(model.api)) return;
|
|
1960
1923
|
return createSupportedTransportStreamFn(model, ctx);
|
|
1961
1924
|
}
|
|
1962
1925
|
function prepareTransportAwareSimpleModel(model, ctx) {
|
|
@@ -2030,13 +1993,15 @@ function normalizeCodexResponsesBaseUrlForOpenAISdk(baseUrl) {
|
|
|
2030
1993
|
if (path.endsWith("/codex/responses")) return path.slice(0, -10);
|
|
2031
1994
|
return path.endsWith("/codex") ? path : `${path}/codex`;
|
|
2032
1995
|
}
|
|
2033
|
-
function resolveProviderSimpleCompletionApi(model) {
|
|
1996
|
+
function resolveProviderSimpleCompletionApi(model, auth, agentId) {
|
|
2034
1997
|
const parts = [
|
|
2035
1998
|
model.provider,
|
|
2036
1999
|
model.id,
|
|
2037
2000
|
model.api,
|
|
2038
2001
|
model.baseUrl || "default"
|
|
2039
2002
|
];
|
|
2003
|
+
if (auth) parts.push(auth.mode, auth.authFlow ?? "");
|
|
2004
|
+
if (agentId) parts.push("agent", agentId);
|
|
2040
2005
|
return `${PROVIDER_SIMPLE_COMPLETION_API_PREFIX}${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
2041
2006
|
}
|
|
2042
2007
|
function resolveProviderStreamApi(model) {
|
|
@@ -2048,7 +2013,7 @@ function resolveProviderStreamApi(model) {
|
|
|
2048
2013
|
];
|
|
2049
2014
|
return `${PROVIDER_STREAM_API_PREFIX}${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
2050
2015
|
}
|
|
2051
|
-
function applyProviderSimpleCompletionWrapper(registry, model, cfg, hookSourceApi = model.api) {
|
|
2016
|
+
function applyProviderSimpleCompletionWrapper(registry, model, cfg, hookSourceApi = model.api, auth, agentId) {
|
|
2052
2017
|
if (model.api.startsWith(PROVIDER_SIMPLE_COMPLETION_API_PREFIX)) return model;
|
|
2053
2018
|
const sourceProvider = registry.getApiProvider(model.api);
|
|
2054
2019
|
if (!sourceProvider) return model;
|
|
@@ -2063,12 +2028,15 @@ function applyProviderSimpleCompletionWrapper(registry, model, cfg, hookSourceAp
|
|
|
2063
2028
|
modelId: model.id,
|
|
2064
2029
|
model,
|
|
2065
2030
|
sourceApi: hookSourceApi,
|
|
2031
|
+
auth,
|
|
2032
|
+
agentId,
|
|
2066
2033
|
streamFn: sourceStreamFn
|
|
2067
2034
|
}
|
|
2068
2035
|
});
|
|
2069
2036
|
if (!streamFn) return model;
|
|
2070
|
-
const
|
|
2071
|
-
|
|
2037
|
+
const registeredStreamFn = (runtimeModel, context, options) => streamFn(projectModel(runtimeModel, { api: hookSourceApi }), context, options);
|
|
2038
|
+
const api = resolveProviderSimpleCompletionApi(model, auth, agentId);
|
|
2039
|
+
return registerCustomApi(registry, api, registeredStreamFn) ? projectModel(model, { api }) : model;
|
|
2072
2040
|
}
|
|
2073
2041
|
function prepareCodexSimpleTransportModel(registry, model, cfg) {
|
|
2074
2042
|
if (model.provider !== "openai" || model.api !== "openai-chatgpt-responses") return;
|
|
@@ -2119,25 +2087,26 @@ function prepareProviderStreamModel(params) {
|
|
|
2119
2087
|
return api === params.model.api ? params.model : projectModel(params.model, { api });
|
|
2120
2088
|
}
|
|
2121
2089
|
function prepareModelForSimpleCompletion(params) {
|
|
2122
|
-
const { apiRegistry, model, cfg } = params;
|
|
2090
|
+
const { apiRegistry, model, cfg, auth, agentId } = params;
|
|
2091
|
+
const wrap = (prepared) => applyProviderSimpleCompletionWrapper(apiRegistry, prepared, cfg, model.api, auth, agentId);
|
|
2123
2092
|
const providerStreamModel = prepareProviderStreamModel({
|
|
2124
2093
|
model,
|
|
2125
2094
|
cfg,
|
|
2126
2095
|
apiRegistry
|
|
2127
2096
|
});
|
|
2128
|
-
if (providerStreamModel) return
|
|
2097
|
+
if (providerStreamModel) return wrap(providerStreamModel);
|
|
2129
2098
|
const codexTransportModel = prepareCodexSimpleTransportModel(apiRegistry, model, cfg);
|
|
2130
|
-
if (codexTransportModel) return
|
|
2099
|
+
if (codexTransportModel) return wrap(codexTransportModel);
|
|
2131
2100
|
const transportAwareModel = prepareTransportAwareSimpleModel(model, { cfg });
|
|
2132
2101
|
if (transportAwareModel !== model) {
|
|
2133
2102
|
const streamFn = buildTransportAwareSimpleStreamFn(model, { cfg });
|
|
2134
|
-
if (streamFn && registerCustomApi(apiRegistry, transportAwareModel.api, streamFn)) return
|
|
2103
|
+
if (streamFn && registerCustomApi(apiRegistry, transportAwareModel.api, streamFn)) return wrap(transportAwareModel);
|
|
2135
2104
|
}
|
|
2136
2105
|
if (model.provider === "anthropic-vertex") {
|
|
2137
2106
|
const api = resolveAnthropicVertexSimpleApi(model.baseUrl);
|
|
2138
|
-
if (registerCustomApi(apiRegistry, api, getAiTransportHost().plugin.createAnthropicVertexStream(model))) return
|
|
2107
|
+
if (registerCustomApi(apiRegistry, api, getAiTransportHost().plugin.createAnthropicVertexStream(model))) return wrap(projectModel(model, { api }));
|
|
2139
2108
|
}
|
|
2140
|
-
return
|
|
2109
|
+
return wrap(model);
|
|
2141
2110
|
}
|
|
2142
2111
|
//#endregion
|
|
2143
|
-
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,
|
|
2112
|
+
export { CompactionReplayRefreshRequiredError, GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, IncompleteToolCallError, MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, OPENAI_RESPONSES_CALL_ID_RE, OPENAI_RESPONSES_FUNCTION_CALL_ITEM_ID_RE, OPENAI_RESPONSES_ID_MAX_LENGTH, 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, iterateModelStream, log, logAnthropicContextEdits, measureUtf8AppendBytes, mergeTransportHeaders, normalizeCodexResponsesBaseUrlForOpenAISdk, normalizeOpenAIResponsesFunctionCallId, notifyProviderHttpMetadata, notifyProviderHttpResponse, notifyProviderStreamOpened, parseJsonObjectPreservingUnsafeIntegers, parseJsonPreservingUnsafeIntegers, parseOpenAICompletionsUsage, parseTerminalToolCallArguments, prepareHeadersForSimpleCompletion, prepareModelForSimpleCompletion, prepareTransportAwareSimpleModel, preserveCompactionReplayWindow, projectGoogleMessages, quoteUnsafeIntegerLiterals, readCodeModePayloadToolName, readOpenAICompletionsContentDeltas, readOpenAICompletionsReasoningBatch, replaceCompactionReplayOwnerContent, requestPreparedOpenAIResponsesCompaction, requiresCompactionReplayRefresh, requiresGoogleToolCallId, resolveAnthropicCacheOptions, resolveAnthropicEphemeralCacheControl, resolveAnthropicMessagesUrl, resolveAnthropicPayloadPolicy, resolveAnthropicRequestBetaHeader, resolveAnthropicServerCompactionPlan, resolveCodeModeResponsesVisibleToolNames, resolveCompactionReplayEligibility, resolveCompactionReplayPressure, resolveMaxTokensParam, resolveModelPayloadDebugMode, resolveModelSseDebugMode, resolveOpenAIClientBaseUrl, resolveOpenAICompletionsCompat, resolveOpenAIPromptCacheKeySupport, resolveOpenAIReasoningEffortMap, resolveOpenAIResponsesCompactEndpointPlan, resolveOpenAIResponsesPayloadPolicy, resolveOpenAIResponsesServerCompactionPlan, resolveOpenAIStrictToolFlagWithDiagnostics, resolvePromptCacheKey, resolveReplayableResponsesMessageId, resolveTransportAwareSimpleApi, sanitizeNonEmptyTransportPayloadText, sanitizeResponsesImagePayload, sanitizeTransportPayloadText, shouldNormalizeOpenAIResponsesToolCallId, sortPromptCacheToolsByName as sortTransportToolsByName, splitOpenAIFunctionCallPairing, stripCompactionReplayCheckpoint, stripCompactionReplayCheckpointInPlace, stripCompletionMessagesToRoleContent, throwIfModelStreamAborted, transportAbortError, usesNativeOpenAICodexResponsesBackend, withProviderAcceptanceObserver, withProviderResponseHook };
|