@openclaw/ai 2026.9.4 → 2026.9.5
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-COtDvgtt.mjs} +10 -11
- package/dist/{anthropic-payload-policy-BZ8umAbk.d.mts → anthropic-payload-policy-5Erq1Nzy.d.mts} +3 -3
- package/dist/{anthropic-stream-reducer-CILWF7JD.mjs → anthropic-stream-reducer-BvdYYWL8.mjs} +47 -43
- package/dist/{api-registry-ByUwIR0e.d.mts → api-registry-Ba2Cv-ut.d.mts} +2 -2
- package/dist/{assistant-output-tLt4H-iQ.mjs → assistant-output-BsEkB-vU.mjs} +1 -1
- package/dist/{azure-openai-responses-BAlqlKKc.mjs → azure-openai-responses-YrgnD583.mjs} +6 -9
- package/dist/{base64-D-su8YVo.mjs → base64-BQOzsvUH.mjs} +4 -4
- package/dist/credential-redaction-BKv49aiv.d.mts +24 -0
- package/dist/{diagnostics-QuErwCIl.mjs → diagnostics-Dm4bisWG.mjs} +89 -2
- package/dist/diagnostics.d.mts +4 -23
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-Bt5Y4Pav.d.mts → event-stream-CCoa-qSI.d.mts} +1 -1
- package/dist/event-stream-DmSCpi1T.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{google-DPBAOaOW.mjs → google-BuhpRO9r.mjs} +6 -9
- package/dist/{google-messages-6JkpHrhJ.mjs → google-messages-CyWnYlh0.mjs} +3 -3
- package/dist/{google-shared-BvBeW9aq.mjs → google-shared-BT5ZeNer.mjs} +13 -13
- package/dist/{google-vertex-k-TMCAYD.mjs → google-vertex-C7EplRvt.mjs} +5 -8
- package/dist/{host-B8YfDGd4.mjs → host-B4MeUNBc.mjs} +25 -27
- package/dist/{host-4atIX-2V.d.mts → host-FZ1RA_qD.d.mts} +5 -3
- package/dist/{host-policy-Zcg_cNz8.mjs → host-policy-DUnXSx0I.mjs} +1 -1
- package/dist/{index-DdD3qerf.d.mts → index-DaF2QbwS.d.mts} +4 -9
- package/dist/index.d.mts +6 -7
- package/dist/index.mjs +3 -4
- package/dist/internal/anthropic.d.mts +6 -7
- package/dist/internal/anthropic.mjs +4 -4
- 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 +10 -53
- package/dist/internal/openai.mjs +11 -9
- package/dist/internal/runtime.d.mts +6 -8
- package/dist/internal/runtime.mjs +5 -9
- package/dist/internal/shared.d.mts +6 -5
- package/dist/internal/shared.mjs +4 -3
- package/dist/internal/tool-schema.d.mts +3 -3
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral-CxUZ1jUb.mjs → mistral-moA-mbwl.mjs} +9 -13
- package/dist/{openai-chatgpt-responses-CgO6kZfo.mjs → openai-chatgpt-responses-DWID3EFO.mjs} +73 -29
- package/dist/{openai-completions-yJuk7eis.mjs → openai-completions-DJ1Vm-CD.mjs} +11 -12
- package/dist/{openai-prompt-cache-Bds-n_9Q.mjs → openai-completions-compat-CkwdxTZx.mjs} +5 -50
- package/dist/{openai-completions-compat-eHgh5UPE.d.mts → openai-completions-compat-JE7gqxb9.d.mts} +4 -4
- package/dist/{openai-completions-stream-Da2vvl-S.mjs → openai-completions-stream-Bu98b0Hv.mjs} +94 -96
- package/dist/openai-prompt-cache-1wfaIszn.mjs +46 -0
- package/dist/{openai-prompt-cache-B4eYo2-I.d.mts → openai-prompt-cache-CJ_xEevu.d.mts} +2 -2
- package/dist/{openai-provider-client-S2gCrM2Z.mjs → openai-provider-client-DPo0Hmak.mjs} +2 -2
- package/dist/openai-reasoning-effort-NlFZmfEu.mjs +235 -0
- package/dist/{openai-responses-DaYwH05E.mjs → openai-responses-BejZzQCP.mjs} +8 -12
- package/dist/{openai-responses-compaction-window-CIhBAkkq.mjs → openai-responses-compaction-window-D6P5oZP5.mjs} +20 -62
- package/dist/openai-responses-contracts-DWrfMODE.mjs +81 -0
- package/dist/{openai-responses-contracts-BjBAqAg_.d.mts → openai-responses-contracts-Dflvrfa8.d.mts} +9 -5
- 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-C15_-OwV.mjs +195 -0
- package/dist/{openai-responses-shared-B8RdBPCv.mjs → openai-responses-shared-CwsziD_m.mjs} +385 -178
- package/dist/openai-responses-terminal-usage-Dl3J6zrf.d.mts +47 -0
- package/dist/{openai-tool-schema-CzjyYXun.mjs → openai-tool-schema-BO8rwyAD.mjs} +92 -68
- package/dist/{openai-transport-params-9aPuV5YY.mjs → openai-transport-params-DQeuAvBl.mjs} +157 -47
- package/dist/{positive-integer-41zhOdcV.mjs → positive-integer-DtjCkbue.mjs} +1 -1
- package/dist/{provider-error-BA-v_tKd.mjs → provider-error-DDqw9Qda.mjs} +100 -38
- package/dist/{provider-options-Ceqv1OKk.d.mts → provider-options-DprLsWh9.d.mts} +9 -6
- package/dist/{provider-replay-context-CJ_YvcEW.mjs → provider-replay-context-CnUSOwhr.mjs} +1 -1
- package/dist/{provider-transcript-transform-V5YzU9zh.mjs → provider-transcript-transform-BsRAhuWJ.mjs} +1 -1
- package/dist/{provider-transport-turn-state-D5EXOFL2.mjs → provider-transport-turn-state-CkGToCD2.mjs} +1 -1
- package/dist/{provider-types-CVjKjsuq.d.mts → provider-types-CAKRC7N5.d.mts} +3 -3
- package/dist/provider-types.d.mts +5 -6
- 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-Dy9IO8Dc.mjs} +15 -7
- package/dist/{simple-options-BQbb4yQL.mjs → simple-options-C6cFWj_f.mjs} +5 -3
- package/dist/{usage-cost-BNWbbXav.mjs → src-DeKjbE8I.mjs} +3 -5
- package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-C9ZadkJW.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-DNvmoWnv.d.mts → transport-stream-shared-BbUkFaHi.d.mts} +4 -4
- package/dist/{transport-stream-shared-zHll9BxO.mjs → transport-stream-shared-D-6FQSHm.mjs} +14 -14
- package/dist/{transport-utils-zrYjICLZ.mjs → transport-utils-1cyq5Y7x.mjs} +3 -3
- package/dist/transports.d.mts +26 -12
- package/dist/transports.mjs +130 -449
- package/dist/{types-Ntv5z2g2.d.mts → types-4_uVs5WH.d.mts} +47 -3
- package/dist/types-DkJfb4W3.d.mts +1 -0
- package/dist/types.d.mts +5 -6
- package/dist/types.mjs +2 -3
- package/dist/{validation-B0t_G2H6.d.mts → validation-Ctzu2DhF.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 +10 -5
- 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,34 @@
|
|
|
1
|
-
import { _ as supportsClaudeAdaptiveThinking, h as resolveClaudeSonnet5ModelIdentity, m as resolveClaudeOpus5ModelIdentity } from "./
|
|
1
|
+
import { _ as supportsClaudeAdaptiveThinking, h as resolveClaudeSonnet5ModelIdentity, m as resolveClaudeOpus5ModelIdentity } from "./src-DeKjbE8I.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 ANTHROPIC_CLAUDE_CODE_VERSION, k as usesClaudeStreamingRefusalContract, n as getAiTransportHost, r as resolveAiTransportHeaderSentinels, w as prepareClaudeNoPrefillRequestContext, x as applyClaudeRequestContract } from "./host-B4MeUNBc.mjs";
|
|
5
|
+
import { t as truncateUtf16Safe } from "./utf16-slice-CvGodqok.mjs";
|
|
6
|
+
import { a as redactDiagnosticText, o as stableStringify } from "./provider-error-DDqw9Qda.mjs";
|
|
7
|
+
import { a as resolveModelSseDebugMode, i as resolveModelPayloadDebugMode, m as toErrorObject, n as formatModelTransportDebugUrl, r as emitModelTransportDebug, t as formatModelTransportDebugBaseUrl } from "./diagnostics-Dm4bisWG.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-1cyq5Y7x.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-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";
|
|
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-C6cFWj_f.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-DQeuAvBl.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-D-6FQSHm.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-CnUSOwhr.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-BsEkB-vU.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-Bu98b0Hv.mjs";
|
|
23
|
+
import { a as googleFlashSupportsMinimalThinking, i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, t as convertGoogleTools } from "./google-messages-CyWnYlh0.mjs";
|
|
24
|
+
import { i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-C9ZadkJW.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-CkGToCD2.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-D6P5oZP5.mjs";
|
|
28
|
+
import { A as resolveNextResponsesEncryptedContentAttempt, B as responsesContinuationPrefixFingerprint, D as createResponsesStreamWithEncryptedContentRetry, F as createOpenAIResponsesAssistantOutput, G as CompactionReplayRefreshRequiredError, H as isConfigurationUpdate, I as recordResponsesInputReplay, J as isOpenAIResponsesReplayContext, K as buildOpenAIResponsesReasoningReplayMetadata, L as responsesInputFingerprint, M as resolveResponsesContextUsageBoundary, O as isInvalidEncryptedContentError, R as claimOpenAIResponsesHttpContinuation, U as replayResponsesReasoningUpdates, V as responsesContinuationRequestFingerprint, W as supportsResponsesReasoningUpdate, X as suppressOpenAIResponsesCompaction, Y as resolveNewestOpenAIResponsesCompactionReplay, Z as resolveReplayableResponsesMessageId, c as processResponsesStream, d as logResponsesFailedNoDetails, f as safeDebugValue, j as recordResponsesContextUsage, k as resolveAzureOpenAIApiVersion, l as observeResponsesStream, m as summarizeResponsesPayload, n as applyResponsesServiceTierPricing, p as summarizeOpenAITransportError, q as captureOpenAIResponsesCompaction, u as ResponsesStreamFailure, z as resolveResponsesContinuationRequest } from "./openai-responses-shared-CwsziD_m.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-C15_-OwV.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";
|
|
@@ -211,19 +211,20 @@ function createAnthropicMessagesClient(params) {
|
|
|
211
211
|
};
|
|
212
212
|
} } };
|
|
213
213
|
}
|
|
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) {
|
|
214
|
+
async function readAnthropicMessagesErrorBody(response) {
|
|
220
215
|
try {
|
|
221
|
-
|
|
216
|
+
const text = await readResponseTextSnippet(response, {
|
|
222
217
|
maxBytes: ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES,
|
|
223
|
-
maxChars:
|
|
218
|
+
maxChars: ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES,
|
|
224
219
|
chunkTimeoutMs: ANTHROPIC_MESSAGES_ERROR_BODY_READ_IDLE_TIMEOUT_MS,
|
|
225
220
|
onIdleTimeout: ({ chunkTimeoutMs }) => /* @__PURE__ */ new Error(`Anthropic Messages error response stalled: no data received for ${chunkTimeoutMs}ms`)
|
|
226
221
|
}) ?? "";
|
|
222
|
+
try {
|
|
223
|
+
return JSON.parse(text);
|
|
224
|
+
} catch {
|
|
225
|
+
const redacted = redactDiagnosticText(text);
|
|
226
|
+
return redacted.length > ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS ? `${truncateUtf16Safe(redacted, ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS)}…` : redacted;
|
|
227
|
+
}
|
|
227
228
|
} catch (error) {
|
|
228
229
|
if (error instanceof Error && error.message.startsWith("Anthropic Messages error response stalled:")) return error.message;
|
|
229
230
|
return "";
|
|
@@ -251,7 +252,7 @@ function createAnthropicTransportClient(params) {
|
|
|
251
252
|
isOAuthToken: false
|
|
252
253
|
};
|
|
253
254
|
}
|
|
254
|
-
if (usesFoundryBearerAuth(resolveModelHeaderSentinels
|
|
255
|
+
if (usesFoundryBearerAuth(resolveModelHeaderSentinels(model))) {
|
|
255
256
|
const betaFeatures = needsInterleavedBeta ? ["interleaved-thinking-2025-05-14"] : [];
|
|
256
257
|
return {
|
|
257
258
|
client: createAnthropicMessagesClient({
|
|
@@ -325,6 +326,7 @@ async function buildAnthropicParams(model, context, isOAuthToken, options) {
|
|
|
325
326
|
const messages = await convertAnthropicMessages(transformTransportMessages(replayPlan.messages, model, normalizeAnthropicToolCallId), model, isOAuthToken, {
|
|
326
327
|
profile: "transport",
|
|
327
328
|
allowReasoningContentReplay: supportsReasoningContentReplay(model),
|
|
329
|
+
allowEmptySignature: model.compat?.allowEmptySignature,
|
|
328
330
|
compaction: replayPlan.compaction,
|
|
329
331
|
replayThinkingEnabled,
|
|
330
332
|
cacheBreakpointOptOutMessageIndexes
|
|
@@ -393,7 +395,7 @@ function resolveAnthropicTransportOptions(model, options, apiKey) {
|
|
|
393
395
|
}
|
|
394
396
|
if (!reasoning) {
|
|
395
397
|
resolved.thinkingEnabled = defaultsClaudeAdaptiveThinking(model);
|
|
396
|
-
if (resolved.thinkingEnabled) resolved.effort =
|
|
398
|
+
if (resolved.thinkingEnabled) resolved.effort = resolveAnthropicThinkingEffort(model, reasoning);
|
|
397
399
|
return resolved;
|
|
398
400
|
}
|
|
399
401
|
if (supportsClaudeAdaptiveThinking(model)) {
|
|
@@ -432,7 +434,6 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
432
434
|
const builtParams = await buildAnthropicParams(model, requestContext, isOAuthToken, transportOptions);
|
|
433
435
|
usedCompactionReplay = builtParams.usedCompactionReplay;
|
|
434
436
|
let params = builtParams.params;
|
|
435
|
-
const toolProjection = builtParams.toolProjection;
|
|
436
437
|
applyAnthropicContextManagementToRequest(params, model, transportOptions, directApiKeyBetaHeader);
|
|
437
438
|
const nextParams = await transportOptions.onPayload?.(params, model);
|
|
438
439
|
if (nextParams !== void 0) params = nextParams;
|
|
@@ -452,8 +453,12 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
452
453
|
model
|
|
453
454
|
});
|
|
454
455
|
if (!response.ok) {
|
|
455
|
-
const
|
|
456
|
-
throw new Error(
|
|
456
|
+
const errorBody = await readAnthropicMessagesErrorBody(response);
|
|
457
|
+
throw Object.assign(/* @__PURE__ */ new Error(`${response.status} status code (no body)`), {
|
|
458
|
+
status: response.status,
|
|
459
|
+
headers: response.headers,
|
|
460
|
+
errorBody
|
|
461
|
+
});
|
|
457
462
|
}
|
|
458
463
|
await consumeAnthropicStream({
|
|
459
464
|
events: anthropicStream,
|
|
@@ -463,7 +468,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
463
468
|
stream,
|
|
464
469
|
refusalBuffer,
|
|
465
470
|
isOAuthToken,
|
|
466
|
-
toolProjection,
|
|
471
|
+
toolProjection: builtParams.toolProjection,
|
|
467
472
|
profile: "transport"
|
|
468
473
|
});
|
|
469
474
|
finalizeTransportStream({
|
|
@@ -481,7 +486,7 @@ function createAnthropicMessagesTransportStreamFn() {
|
|
|
481
486
|
refusalBuffer.discard();
|
|
482
487
|
output.content = [];
|
|
483
488
|
} else output.content = output.content.filter((block) => block.type !== "toolCall");
|
|
484
|
-
if (usedCompactionReplay && isAnthropicReplayRejection(
|
|
489
|
+
if (usedCompactionReplay && isAnthropicReplayRejection(output)) suppressAnthropicCompaction(output, model, options);
|
|
485
490
|
for (const block of output.content) delete block.index;
|
|
486
491
|
}
|
|
487
492
|
});
|
|
@@ -567,8 +572,8 @@ function createSseDoneDetector() {
|
|
|
567
572
|
sawDone: () => sawDone
|
|
568
573
|
};
|
|
569
574
|
}
|
|
570
|
-
function createOpenAICompletionsClient(model,
|
|
571
|
-
const clientConfig = buildOpenAICompletionsClientConfig(model,
|
|
575
|
+
function createOpenAICompletionsClient(model, apiKey, headers, opts) {
|
|
576
|
+
const clientConfig = buildOpenAICompletionsClientConfig(model, headers);
|
|
572
577
|
return new OpenAI({
|
|
573
578
|
apiKey,
|
|
574
579
|
baseURL: clientConfig.baseURL,
|
|
@@ -579,8 +584,7 @@ function createOpenAICompletionsClient(model, context, apiKey, optionHeaders, op
|
|
|
579
584
|
...buildOpenAISdkClientOptions(model)
|
|
580
585
|
});
|
|
581
586
|
}
|
|
582
|
-
function buildOpenAICompletionsClientConfig(model,
|
|
583
|
-
const headers = buildOpenAIClientHeaders(model, context, optionHeaders);
|
|
587
|
+
function buildOpenAICompletionsClientConfig(model, headers) {
|
|
584
588
|
const defaultQuery = {};
|
|
585
589
|
let baseURL = model.baseUrl;
|
|
586
590
|
let isAzureHost = false;
|
|
@@ -666,10 +670,11 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
666
670
|
statusText: response.statusText
|
|
667
671
|
});
|
|
668
672
|
};
|
|
669
|
-
const
|
|
673
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
674
|
+
const client = createOpenAICompletionsClient(model, apiKey, buildOpenAIClientHeaders(model, context, {
|
|
670
675
|
...turnHeaders,
|
|
671
676
|
...optionHeaders
|
|
672
|
-
}, { fetch: doneDetectingFetch });
|
|
677
|
+
}, void 0, resolvePromptCacheKey(options, cacheRetention), cacheRetention), { fetch: doneDetectingFetch });
|
|
673
678
|
let params = buildOpenAICompletionsParams(model, context, options);
|
|
674
679
|
const nextParams = await options?.onPayload?.(params, model);
|
|
675
680
|
if (nextParams !== void 0) params = nextParams;
|
|
@@ -726,374 +731,6 @@ function createOpenAICompletionsTransportStreamFn() {
|
|
|
726
731
|
};
|
|
727
732
|
}
|
|
728
733
|
//#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
734
|
//#region packages/ai/src/transports/openai-responses-steering.ts
|
|
1098
735
|
function cloneWireRequest(request) {
|
|
1099
736
|
const serialized = JSON.stringify(request);
|
|
@@ -1725,6 +1362,17 @@ function createOpenAIResponsesClient(model, apiKey, defaultHeaders, fetchOverrid
|
|
|
1725
1362
|
...buildOpenAISdkClientOptions(model)
|
|
1726
1363
|
});
|
|
1727
1364
|
}
|
|
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
|
+
}
|
|
1728
1376
|
function createResponsesTransportExecutor(config) {
|
|
1729
1377
|
return (model, context, options) => {
|
|
1730
1378
|
const responsesOptions = options;
|
|
@@ -1748,7 +1396,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1748
1396
|
const websocketTurnHeaders = filterProviderTurnHeadersForExplicitOpencodeSession(model, options, websocketSessionPolicy?.headers);
|
|
1749
1397
|
const websocketHeaders = websocketMode ? buildOpenAIClientHeaders(model, context, options?.headers, websocketTurnHeaders, options?.sessionId, options?.cacheRetention) : void 0;
|
|
1750
1398
|
const httpHeaders = buildOpenAIClientHeaders(model, context, options?.headers, httpTurnHeaders, options?.sessionId, options?.cacheRetention);
|
|
1751
|
-
const client = config.createClient(model, apiKey, httpHeaders, compactRequest ? createBoundedOpenAIResponsesCompactionFetch(buildGuardedModelFetch(model)) : void 0);
|
|
1399
|
+
const client = config.createClient(model, apiKey, httpHeaders, compactRequest ? createBoundedOpenAIResponsesCompactionFetch(buildGuardedModelFetch(model)) : config.streamRequest ? withDefaultResponsesStreamEncoding(buildGuardedModelFetch(model)) : void 0);
|
|
1752
1400
|
const nativeAstra = model.id === "gpt-6-astra" && supportsNativeOpenAIResponsesEndpoint(model);
|
|
1753
1401
|
const asyncToolExecutionEligible = nativeAstra && options?.asyncToolExecution === true && !responsesOptions?.openclawCodeModeToolSurface;
|
|
1754
1402
|
const prepareRequest = async (request) => {
|
|
@@ -1792,11 +1440,11 @@ function createResponsesTransportExecutor(config) {
|
|
|
1792
1440
|
return;
|
|
1793
1441
|
}
|
|
1794
1442
|
const sessionId = options?.sessionId;
|
|
1795
|
-
if (config.httpContinuation && !websocketMode && !getAiTransportHost().requiresManagedTransport(model) && supportsNativeOpenAIResponsesEndpoint({
|
|
1443
|
+
if (config.httpContinuation && !websocketMode && !getAiTransportHost().requiresManagedTransport(model) && (supportsNativeOpenAIResponsesEndpoint({
|
|
1796
1444
|
provider: model.provider,
|
|
1797
1445
|
api: model.api,
|
|
1798
1446
|
baseUrl: model.baseUrl
|
|
1799
|
-
}) && sessionId && (params.store === true || supportsResponsesReasoningUpdate(params)) && !params.previous_response_id) {
|
|
1447
|
+
}) || resolveOpenAIResponsesPayloadPolicy(model).explicitContinuationOptIn) && sessionId && (params.store === true || supportsResponsesReasoningUpdate(params)) && !params.previous_response_id) {
|
|
1800
1448
|
continuationClaim = claimOpenAIResponsesHttpContinuation({
|
|
1801
1449
|
sessionId,
|
|
1802
1450
|
apiKey,
|
|
@@ -1827,7 +1475,9 @@ function createResponsesTransportExecutor(config) {
|
|
|
1827
1475
|
});
|
|
1828
1476
|
const websocketSignal = combineWebSocketTimeoutSignal(firstEvent.signal, model, requestOptions?.timeout);
|
|
1829
1477
|
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
|
+
const responseModelTracker = createResponseModelTracker(isOpenAICodexResponsesModel(model));
|
|
1830
1479
|
let continuationBaseline;
|
|
1480
|
+
let contextUsageEligible = true;
|
|
1831
1481
|
const createSseStream = async (initialRequest = continuationClaim?.request ?? params, initialAttemptKind = "initial", initialRejectedCompaction) => {
|
|
1832
1482
|
const { stream: responseStream } = await createResponsesStreamWithEncryptedContentRetry({
|
|
1833
1483
|
client,
|
|
@@ -1841,9 +1491,11 @@ function createResponsesTransportExecutor(config) {
|
|
|
1841
1491
|
onCompactionRejected: (checkpoint) => suppressOpenAIResponsesCompaction(output, model, responsesOptions, checkpoint),
|
|
1842
1492
|
canRetryStream: () => output.content.length === 0,
|
|
1843
1493
|
wrapStream: ({ stream: rawResponseStream, response, attempt }) => {
|
|
1494
|
+
contextUsageEligible &&= attempt.kind === "initial";
|
|
1844
1495
|
continuationBaseline = attempt.request.previous_response_id ? params : attempt.request;
|
|
1496
|
+
const trackedResponseStream = responseModelTracker.track(response, rawResponseStream);
|
|
1845
1497
|
return withProviderResponseHook({
|
|
1846
|
-
stream: observeResponsesStream(
|
|
1498
|
+
stream: observeResponsesStream(trackedResponseStream, model, requestStartedAt),
|
|
1847
1499
|
signal: firstEvent.signal,
|
|
1848
1500
|
abort: firstEvent.abort,
|
|
1849
1501
|
hook: createOpenAIProviderAcceptanceHook(options, response, model),
|
|
@@ -1879,24 +1531,29 @@ function createResponsesTransportExecutor(config) {
|
|
|
1879
1531
|
callerSignal: options?.signal,
|
|
1880
1532
|
degradeCooldownMs: websocketSessionPolicy?.degradeCooldownMs,
|
|
1881
1533
|
onActiveResponse: nativeAstra && params.model === "gpt-6-astra" ? options?.onActiveResponse : void 0,
|
|
1882
|
-
steeringInput: (messages) =>
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1534
|
+
steeringInput: (messages) => {
|
|
1535
|
+
contextUsageEligible = false;
|
|
1536
|
+
return projectResponsesSteeringInput(params, () => buildRequest("checkpoint", {
|
|
1537
|
+
...context,
|
|
1538
|
+
messages: [...context.messages, ...messages]
|
|
1539
|
+
}));
|
|
1540
|
+
}
|
|
1886
1541
|
});
|
|
1887
1542
|
finishWebSocket = websocket.finish;
|
|
1888
1543
|
websocketBaseline = websocket.fullRequest;
|
|
1889
1544
|
recordResponsesInputReplay(output, websocket.inputReplay);
|
|
1545
|
+
contextUsageEligible &&= websocket.inputReplay === void 0;
|
|
1890
1546
|
observePrompt?.(websocket.request, {
|
|
1891
1547
|
egress: "responses-websocket",
|
|
1892
1548
|
payloadVariant: "initial"
|
|
1893
1549
|
});
|
|
1894
1550
|
transport = "websocket";
|
|
1895
1551
|
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))))}`);
|
|
1552
|
+
const trackedWebSocketStream = responseModelTracker.track(void 0, websocket.stream);
|
|
1896
1553
|
responseStream = { async *[Symbol.asyncIterator]() {
|
|
1897
1554
|
let providerAccepted = false;
|
|
1898
1555
|
try {
|
|
1899
|
-
for await (const event of
|
|
1556
|
+
for await (const event of trackedWebSocketStream) {
|
|
1900
1557
|
if (!providerAccepted) {
|
|
1901
1558
|
providerAccepted = true;
|
|
1902
1559
|
await notifyProviderStreamOpened({
|
|
@@ -1945,7 +1602,8 @@ function createResponsesTransportExecutor(config) {
|
|
|
1945
1602
|
authProfileId: responsesOptions?.authProfileId,
|
|
1946
1603
|
sessionId: options?.sessionId
|
|
1947
1604
|
}),
|
|
1948
|
-
asyncToolExecution: asyncTools
|
|
1605
|
+
asyncToolExecution: asyncTools,
|
|
1606
|
+
...responseModelTracker.terminalOptions
|
|
1949
1607
|
});
|
|
1950
1608
|
finishWebSocket?.();
|
|
1951
1609
|
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
@@ -1953,6 +1611,7 @@ function createResponsesTransportExecutor(config) {
|
|
|
1953
1611
|
const admitted = transport === "websocket" ? websocketBaseline : continuationBaseline;
|
|
1954
1612
|
if (terminal && admitted && supportsNativeOpenAIResponsesEndpoint(model)) recordResponsesReasoningState(output, model, responsesOptions, admitted, terminal.output);
|
|
1955
1613
|
if (continuationClaim && continuationBaseline && terminal) continuationClaim.commit(continuationBaseline, terminal);
|
|
1614
|
+
if (terminal && admitted && contextUsageEligible) recordResponsesContextUsage(output, model, responsesOptions, admitted, terminal.output, "transport");
|
|
1956
1615
|
} catch (error) {
|
|
1957
1616
|
finishWebSocket?.({ keep: false });
|
|
1958
1617
|
throw error;
|
|
@@ -2007,7 +1666,13 @@ function createAzureOpenAIResponsesTransportStreamFn() {
|
|
|
2007
1666
|
outputApi: "azure-openai-responses",
|
|
2008
1667
|
firstEventTimeoutMs: AZURE_RESPONSES_FIRST_EVENT_TIMEOUT_MS,
|
|
2009
1668
|
createClient: createAzureOpenAIClient,
|
|
2010
|
-
buildRequest: (model, context, options, metadata, replayMode) =>
|
|
1669
|
+
buildRequest: (model, context, options, metadata, replayMode) => {
|
|
1670
|
+
const deploymentName = resolveAzureDeploymentName(model);
|
|
1671
|
+
const params = buildOpenAIResponsesParams(model, context, options, metadata, replayMode);
|
|
1672
|
+
params.model = deploymentName;
|
|
1673
|
+
delete params.store;
|
|
1674
|
+
return params;
|
|
1675
|
+
}
|
|
2011
1676
|
});
|
|
2012
1677
|
}
|
|
2013
1678
|
function resolveAzureDeploymentName(model) {
|
|
@@ -2032,12 +1697,6 @@ function createAzureOpenAIClient(model, apiKey, defaultHeaders, fetchOverride) {
|
|
|
2032
1697
|
apiVersion: resolveAzureOpenAIApiVersion()
|
|
2033
1698
|
});
|
|
2034
1699
|
}
|
|
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
1700
|
//#endregion
|
|
2042
1701
|
//#region packages/ai/src/transports/provider-compaction-replay.ts
|
|
2043
1702
|
function isAssistantReplayMessage(message) {
|
|
@@ -2095,35 +1754,55 @@ function preserveCompactionReplayWindow(source, windowed, model, identity) {
|
|
|
2095
1754
|
providerReplay
|
|
2096
1755
|
}, ...windowed.filter((message) => suffix.has(message))];
|
|
2097
1756
|
}
|
|
2098
|
-
function
|
|
2099
|
-
|
|
2100
|
-
|
|
1757
|
+
function estimateResponsesContent(content, estimate, text) {
|
|
1758
|
+
if (typeof content === "string") return text(content);
|
|
1759
|
+
if (!Array.isArray(content)) return estimate.json(content);
|
|
1760
|
+
return content.reduce((tokens, block) => {
|
|
1761
|
+
if (!isRecord(block)) return tokens + estimate.json(block);
|
|
1762
|
+
if ((block.type === "input_text" || block.type === "output_text") && typeof block.text === "string") {
|
|
1763
|
+
const { text: value, ...metadata } = block;
|
|
1764
|
+
return tokens + text(value) + estimate.json(metadata);
|
|
1765
|
+
}
|
|
1766
|
+
if (block.type === "input_image") {
|
|
1767
|
+
const { image_url: url, ...metadata } = block;
|
|
1768
|
+
return tokens + estimate.image() + estimate.json(typeof url === "string" && url.startsWith("data:") ? metadata : block);
|
|
1769
|
+
}
|
|
1770
|
+
return tokens + estimate.json(block);
|
|
1771
|
+
}, 0);
|
|
1772
|
+
}
|
|
1773
|
+
function estimateResponsesInput(input, estimate) {
|
|
1774
|
+
return input.reduce((tokens, entry) => {
|
|
1775
|
+
if (!isRecord(entry)) return tokens + estimate.json(entry);
|
|
1776
|
+
if (entry.type === "compaction" && typeof entry.encrypted_content === "string") {
|
|
2101
1777
|
const { encrypted_content, ...metadata } = entry;
|
|
2102
1778
|
return tokens + estimate.text(encrypted_content) + estimate.json(metadata);
|
|
2103
1779
|
}
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
}
|
|
2114
|
-
return sum + estimate.json(block);
|
|
2115
|
-
}, 0);
|
|
1780
|
+
if (entry.type === "message") {
|
|
1781
|
+
const { content, ...metadata } = entry;
|
|
1782
|
+
return tokens + estimate.json(metadata) + estimateResponsesContent(content, estimate, (value) => estimate.text(value));
|
|
1783
|
+
}
|
|
1784
|
+
if (entry.type === "function_call_output" || entry.type === "custom_tool_call_output") {
|
|
1785
|
+
const { output, ...metadata } = entry;
|
|
1786
|
+
return tokens + estimate.json(metadata) + estimateResponsesContent(output, estimate, (value) => estimate.toolResult ? estimate.toolResult(value) : estimate.text(value));
|
|
1787
|
+
}
|
|
1788
|
+
return tokens + estimate.json(entry);
|
|
2116
1789
|
}, 0);
|
|
2117
1790
|
}
|
|
2118
1791
|
/** Estimate the canonical prefix and its tail once, independent of unbound usage snapshots. */
|
|
2119
|
-
function resolveCompactionReplayPressure(messages, model, identity, estimate) {
|
|
1792
|
+
function resolveCompactionReplayPressure(messages, model, identity, estimate, systemPrompt) {
|
|
2120
1793
|
const checkpoint = resolveCompactionSource(messages, model, identity);
|
|
2121
1794
|
if (!checkpoint) return;
|
|
2122
1795
|
if (checkpoint.family === "responses" && checkpoint.mode === "refresh-required") throw new CompactionReplayRefreshRequiredError();
|
|
2123
1796
|
const ownerIndex = messages.findIndex((message) => message === checkpoint.owner);
|
|
2124
1797
|
const owner = messages[ownerIndex];
|
|
2125
1798
|
if (!owner) return;
|
|
2126
|
-
const prefixTokens = checkpoint.family === "anthropic" ? estimate.text(checkpoint.summary) : checkpoint.mode === "complete-window" ?
|
|
1799
|
+
const prefixTokens = checkpoint.family === "anthropic" ? estimate.text(checkpoint.summary) : checkpoint.mode === "complete-window" ? estimateResponsesInput(checkpoint.output, estimate) : estimate.text(checkpoint.item.encrypted_content);
|
|
1800
|
+
const measuredBoundary = checkpoint.family === "responses" ? resolveResponsesContextUsageBoundary(messages, model, identity, systemPrompt) : void 0;
|
|
1801
|
+
if (measuredBoundary) return {
|
|
1802
|
+
messages: [],
|
|
1803
|
+
prefixTokens: measuredBoundary.totalTokens + estimateResponsesInput(measuredBoundary.suffix, estimate),
|
|
1804
|
+
measuredTokens: measuredBoundary.totalTokens
|
|
1805
|
+
};
|
|
2127
1806
|
const { contextUsage: _staleContextUsage, ...usage } = checkpoint.owner.usage;
|
|
2128
1807
|
const tail = [];
|
|
2129
1808
|
for (const message of messages.slice(ownerIndex + 1)) {
|
|
@@ -2400,7 +2079,9 @@ function prepareCodexSimpleTransportModel(registry, model, cfg) {
|
|
|
2400
2079
|
if (!registerCustomApi(registry, api, streamFn)) return;
|
|
2401
2080
|
return projectModel(transportModel, { api });
|
|
2402
2081
|
}
|
|
2403
|
-
function
|
|
2082
|
+
function resolveModelTransportSentinels(model, boundary) {
|
|
2083
|
+
const host = getAiTransportHost();
|
|
2084
|
+
if (host.unwrapModelTransportSentinels) return host.unwrapModelTransportSentinels(model, boundary);
|
|
2404
2085
|
const headers = resolveAiTransportHeaderSentinels(model.headers);
|
|
2405
2086
|
return headers === model.headers ? model : projectModel(model, { headers });
|
|
2406
2087
|
}
|
|
@@ -2409,7 +2090,7 @@ function wrapPluginProviderStream(streamFn) {
|
|
|
2409
2090
|
const host = getAiTransportHost();
|
|
2410
2091
|
const apiKey = options?.apiKey ? host.resolveSecretSentinel(options.apiKey) : options?.apiKey;
|
|
2411
2092
|
const headers = resolveAiTransportHeaderSentinels(options?.headers);
|
|
2412
|
-
return streamFn(
|
|
2093
|
+
return streamFn(resolveModelTransportSentinels(model, "plugin simple-completion stream egress"), context, apiKey === options?.apiKey && headers === options?.headers ? options : {
|
|
2413
2094
|
...options,
|
|
2414
2095
|
apiKey,
|
|
2415
2096
|
headers
|
|
@@ -2417,7 +2098,7 @@ function wrapPluginProviderStream(streamFn) {
|
|
|
2417
2098
|
};
|
|
2418
2099
|
}
|
|
2419
2100
|
function prepareProviderStreamModel(params) {
|
|
2420
|
-
const pluginModel =
|
|
2101
|
+
const pluginModel = resolveModelTransportSentinels(params.model, "plugin simple-completion stream construction");
|
|
2421
2102
|
const providerStreamFn = getAiTransportHost().plugin.resolveProviderStream({
|
|
2422
2103
|
provider: params.model.provider,
|
|
2423
2104
|
config: params.cfg,
|
|
@@ -2459,4 +2140,4 @@ function prepareModelForSimpleCompletion(params) {
|
|
|
2459
2140
|
return applyProviderSimpleCompletionWrapper(apiRegistry, model, cfg);
|
|
2460
2141
|
}
|
|
2461
2142
|
//#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 };
|
|
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, 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 };
|