@openclaw/ai 2026.10.10 → 2026.11.5-beta.1
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 +11 -1
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
- package/dist/anthropic-CTND83W3.mjs +182 -0
- package/dist/{anthropic-payload-policy-rqCq9sT_.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
- package/dist/{anthropic-stream-reducer-C__ByTq1.mjs → anthropic-stream-lifecycle-rJe4OH5H.mjs} +845 -649
- package/dist/{anthropic-tool-projection-JTvMo4KG.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
- package/dist/{anthropic-tool-projection-DA_KeluM.mjs → anthropic-tool-projection-dGRfr4iT.mjs} +22 -32
- package/dist/{api-registry-gDt0faai.d.mts → api-registry-DY2MLUyg.d.mts} +2 -2
- package/dist/assistant-output-CD4kY9gu.mjs +16 -0
- package/dist/{azure-openai-responses-DHzTwi-y.mjs → azure-openai-responses-BhoLtP4Z.mjs} +46 -52
- package/dist/{cloudflare-Dttf8jKq.mjs → cloudflare-BJ2_Xabx.mjs} +1 -1
- package/dist/{credential-redaction-XvsPf7Yi.d.mts → credential-redaction-DrgndwTJ.d.mts} +5 -3
- package/dist/{deferred-event-buffer-DAvyP7qA.mjs → deferred-event-buffer-tIGkTkTm.mjs} +1 -2
- package/dist/{diagnostics-Cv7cW3pS.mjs → diagnostics-CloVGQiK.mjs} +42 -19
- package/dist/{diagnostics-DzrF1h4J.mjs → diagnostics-o1PrVNQb.mjs} +11 -4
- package/dist/diagnostics.d.mts +6 -7
- package/dist/diagnostics.mjs +4 -4
- package/dist/{env-api-keys-Xd8dm_aV.mjs → env-api-keys-BuHc86ya.mjs} +1 -26
- package/dist/event-stream-B4ZcSvsu.d.mts +1 -0
- package/dist/{event-stream-CzpE1g_o.d.mts → event-stream-BYmtRe8-.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{github-copilot-request-facts-F-EmvkpW.mjs → github-copilot-request-facts-BZ_EMo7X.mjs} +1 -1
- package/dist/{google-CZ6uGVkV.mjs → google-1uObh-eI.mjs} +7 -8
- package/dist/{google-interactions-qd4flmND.mjs → google-interactions-CY8Xb87S.mjs} +208 -233
- package/dist/{google-messages-B-svbJuN.mjs → google-messages-CwBqSoa4.mjs} +16 -13
- package/dist/{google-provider-stream-DlhaCvCf.mjs → google-provider-stream-D30s9EZp.mjs} +17 -10
- package/dist/{google-shared-Cif7nve-.mjs → google-shared-li0lmEZK.mjs} +70 -42
- package/dist/{google-vertex-BZTcYnWU.mjs → google-vertex-B5CHglca.mjs} +3 -3
- package/dist/{host-rCxf5Tjd.mjs → host-DX7ORpeH.mjs} +57 -46
- package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
- package/dist/{host-policy-Ci1cKluf.mjs → host-policy-jCZebuXx.mjs} +2 -2
- package/dist/index-Bczt0MnO.d.mts +17 -0
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +9 -7
- package/dist/internal/anthropic.d.mts +21 -26
- package/dist/internal/anthropic.mjs +6 -6
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/google.d.mts +15 -0
- package/dist/internal/google.mjs +1 -0
- package/dist/internal/model-request-body.d.mts +37 -0
- package/dist/internal/model-request-body.mjs +106 -0
- package/dist/internal/openai-completions-compat.d.mts +5 -1
- package/dist/internal/openai-completions-compat.mjs +3 -2
- 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 +14 -12
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/reasoning-tag-text-partitioner.d.mts +26 -0
- package/dist/{reasoning-tag-text-partitioner-DzlRubwU.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -122
- package/dist/internal/retry-after.d.mts +2 -2
- package/dist/internal/retry-after.mjs +165 -27
- package/dist/internal/runtime.d.mts +15 -41
- package/dist/internal/runtime.mjs +9 -10
- package/dist/internal/shared.d.mts +21 -25
- package/dist/internal/shared.mjs +9 -98
- package/dist/internal/tool-schema.d.mts +10 -10
- package/dist/internal/tool-schema.mjs +4 -4
- package/dist/{llm-request-activity-CfMuh5cC.mjs → llm-request-activity-DzaHoRAU.mjs} +2 -2
- package/dist/mistral-F5_asrmU.mjs +3741 -0
- package/dist/mistral.LICENSE +201 -0
- package/dist/{model-transport-url-BrsjjdjR.d.mts → model-transport-url-BdksnBqu.d.mts} +6 -8
- package/dist/{number-coercion-37gmNkuA.mjs → number-coercion-C7HsBgUL.mjs} +7 -2
- package/dist/observe-async-iterator-AlARO5wS.d.mts +178 -0
- package/dist/observe-async-iterator-DgmegcZR.mjs +181 -0
- package/dist/{openai-chatgpt-responses-iGYDPbmc.mjs → openai-chatgpt-responses-BIK7HROH.mjs} +61 -80
- package/dist/{openai-completions-CDy5u1mv.mjs → openai-completions-ClJ7QHEB.mjs} +5 -5
- package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
- package/dist/{openai-completions-compat-CJ0OXZgi.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
- package/dist/openai-completions-reasoning-replay-BwT1xwRI.mjs +45 -0
- package/dist/{openai-completions-transport-DLrm5EWi.mjs → openai-completions-transport-C6J4_oGf.mjs} +501 -563
- package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
- package/dist/{openai-prompt-cache-h8vXRiaH.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
- package/dist/openai-responses-Beifmf1s.mjs +89 -0
- package/dist/{openai-responses-compaction-replay-DUBbsfku.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
- package/dist/{openai-responses-contracts-gnl6ZRs1.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
- package/dist/{openai-responses-contracts-DCG51Us0.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
- package/dist/{openai-responses-endpoint-JbBT8IDv.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
- package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
- package/dist/{openai-responses-request-lifecycle-DuMpdA6y.mjs → openai-responses-request-lifecycle-o-ODC_rF.mjs} +12 -26
- package/dist/{openai-responses-shared-CNfHudFg.mjs → openai-responses-shared-CrFDkZ0N.mjs} +637 -389
- package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
- package/dist/{openai-tool-schema-CGhEl7ao.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
- package/dist/otel-D-BkX8bB.mjs +766 -0
- package/dist/{overflow-OF3PgPbw.mjs → overflow-CpApyjG2.mjs} +1 -1
- package/dist/{positive-integer-Bb4Evc7L.mjs → positive-integer-DiqE5vNi.mjs} +2 -3
- package/dist/{prompt-cache-stability-D_MeCQFI.mjs → prompt-cache-stability-w-ICeyOI.mjs} +1 -1
- package/dist/{provider-error-qtZD2inE.mjs → provider-error-DD-fo4Rz.mjs} +71 -234
- package/dist/{provider-options-Bo8GzTGX.d.mts → provider-options-Mo8NM5d1.d.mts} +15 -4
- package/dist/{provider-replay-context-BC23HyZo.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
- package/dist/provider-transcript-transform-BHq3Q4nc.mjs +32 -0
- package/dist/{provider-transport-turn-state-B11rmZpv.mjs → provider-transport-turn-state-DQd9K4Pd.mjs} +3 -3
- package/dist/{provider-types-ODq57rG_.d.mts → provider-types-B1e98js5.d.mts} +6 -4
- package/dist/provider-types.d.mts +7 -6
- package/dist/provider-types.mjs +2 -1
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +26 -29
- package/dist/{record-coerce-CNDovvft.mjs → record-coerce-BQaoiN3r.mjs} +4 -1
- package/dist/request-headers-DO4Mqhw1.mjs +10 -0
- package/dist/{required-api-key-D088S4Cd.mjs → required-api-key-2zZTkmsi.mjs} +1 -1
- package/dist/retry-after-DnHBlFS2.d.mts +45 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/{sanitize-unicode-ZqVLLEKC.d.mts → sanitize-unicode-BISmUlUv.d.mts} +2 -2
- package/dist/{simple-options-BdJJbzZk.mjs → simple-options-tLSeECry.mjs} +108 -82
- package/dist/src-BUsVkrNt.mjs +105 -0
- package/dist/{src-CyA0zJnt.mjs → src-CQ7nH2mL.mjs} +4 -7
- package/dist/stable-stringify-CchQEmeA.mjs +84 -0
- package/dist/{stream-DQqGjhbq.mjs → stream-DrtAWu7c.mjs} +2 -6
- package/dist/{stream-first-event-timeout-D_TfJHRJ.mjs → stream-first-event-timeout-B7RcufAV.mjs} +16 -13
- package/dist/{string-coerce-Cj8sqWHx.mjs → string-coerce-BCuWMIrk.mjs} +1 -1
- package/dist/string-normalization-B8TDDBX_.mjs +32 -0
- package/dist/telemetry-B9f7K_Xe.mjs +582 -0
- package/dist/{tool-schema-json-projection-Cvq69Ajp.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
- package/dist/{transport-stream-shared-DdnJGEj0.mjs → transport-stream-shared-D2uFMhMc.mjs} +177 -93
- package/dist/{transport-stream-shared-8ru8eX4s.d.mts → transport-stream-shared-D3IAU4jn.d.mts} +29 -15
- package/dist/{transport-utils-CcCAuFVS.mjs → transport-utils-Da_39MYi.mjs} +23 -38
- package/dist/transports.d.mts +39 -38
- package/dist/transports.mjs +214 -295
- package/dist/{types-CVYzKrMl.d.mts → types-BVdTf0YV.d.mts} +38 -3
- package/dist/types-Cb3-5WM9.d.mts +1 -0
- package/dist/{types-BXd0kI8-.mjs → types-OVEWUaDh.mjs} +3 -1
- package/dist/types.d.mts +7 -6
- package/dist/types.mjs +7 -5
- package/dist/{validation-9FSkE8T-.mjs → validation-DGXqfvkj.mjs} +45 -27
- package/dist/{validation-BQ5u20Ru.d.mts → validation-QmyD0E5A.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -2
- package/package.json +40 -6
- package/dist/anthropic-B54Ts1tV.mjs +0 -221
- package/dist/assistant-output-DbgdWAhJ.mjs +0 -47
- package/dist/event-stream-CDpFza-M.d.mts +0 -1
- package/dist/index-DSprYWaz.d.mts +0 -185
- package/dist/mistral-C_ImzxlK.mjs +0 -512
- package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
- package/dist/openai-responses-Cp2QPq7K.mjs +0 -87
- package/dist/retry-after-sw-XX8aC.d.mts +0 -15
- package/dist/types-CBJthzJX.d.mts +0 -1
package/dist/transports.mjs
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
import { w as supportsClaudeAdaptiveThinking } from "./src-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { i as
|
|
9
|
-
import { a as
|
|
10
|
-
import { t as
|
|
11
|
-
import {
|
|
12
|
-
import { r as
|
|
13
|
-
import {
|
|
14
|
-
import { n as
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
1
|
+
import { w as supportsClaudeAdaptiveThinking } from "./src-CQ7nH2mL.mjs";
|
|
2
|
+
import { t as omitNullRequestHeaders } from "./request-headers-DO4Mqhw1.mjs";
|
|
3
|
+
import { o as isRecord } from "./record-coerce-BQaoiN3r.mjs";
|
|
4
|
+
import { r as normalizeLowercaseStringOrEmpty } from "./string-coerce-BCuWMIrk.mjs";
|
|
5
|
+
import { _ as buildAnthropicClaudeCodeIdentity, a as resolveAiTransportHeaderSentinels, b as prepareClaudeNoPrefillRequestContext, r as getAiTransportHost } from "./host-DX7ORpeH.mjs";
|
|
6
|
+
import { P as resolveOpenAIReasoningEffortMap, i as OPENAI_RESPONSES_APIS } from "./openai-responses-contracts-xU-n9AJJ.mjs";
|
|
7
|
+
import { c as truncateUtf16Safe, s as redactDiagnosticText } from "./provider-error-DD-fo4Rz.mjs";
|
|
8
|
+
import { S as toErrorObject, a as resolveModelPayloadDebugMode, i as emitModelTransportError, n as formatModelTransportDebugUrl, o as resolveModelSseDebugMode, r as emitModelTransportDebug, t as formatModelTransportDebugBaseUrl } from "./diagnostics-CloVGQiK.mjs";
|
|
9
|
+
import { a as streamFragmentError, i as resolveModelHeaderSentinels, n as isCodeModeModelVisibleToolName, r as readAnthropicMessagesErrorSnippet, t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-Da_39MYi.mjs";
|
|
10
|
+
import { a as resolveOpenAICompletionsCompat, i as isOpenAICodexResponsesModel, n as isKnownOpenAIEndpoint, o as resolveOpenAIPromptCacheKeySupport, r as isNativeOpenAIEndpoint, s as usesNativeOpenAICodexResponsesBackend, t as detectOpenAICompletionsCompat } from "./openai-completions-compat-CstlTQuF.mjs";
|
|
11
|
+
import { t as buildGuardedModelFetch } from "./host-policy-jCZebuXx.mjs";
|
|
12
|
+
import { A as resolveAnthropicServerCompactionPlan, B as usesFoundryBearerAuth, C as isAnthropicServerToolClearingEnabled, D as resolveAnthropicEphemeralCacheControl, E as resolveAnthropicCacheOptions, O as resolveAnthropicPayloadPolicy, R as isAnthropicOAuthApiKey, S as buildAnthropicSystemBlocks, T as logAnthropicContextEdits, a as resolveNewestAnthropicCompaction, b as applyAnthropicPayloadPolicyToParams, i as resolveCompletionTokenReservation, j as supportsAnthropicServerSideFallback, k as resolveAnthropicRequestBetaHeader, r as resolveAnthropicTransportOptions, t as runAnthropicStreamLifecycle, v as applyAnthropicContextManagementToRequest, w as isDirectAnthropicModel, x as applyAnthropicRequestCacheControl, y as applyAnthropicEphemeralCacheControlMarkers, z as omitFoundryBearerCredentialHeaders } from "./anthropic-stream-lifecycle-rJe4OH5H.mjs";
|
|
13
|
+
import { r as sortPromptCacheToolsByName } from "./prompt-cache-stability-w-ICeyOI.mjs";
|
|
14
|
+
import { C as withProviderResponseHook, E as quoteUnsafeIntegerLiterals, M as createAbortError, N as racePromiseWithAbortSignal, S as withProviderAcceptanceObserver, T as parseJsonPreservingUnsafeIntegers, _ as parseTerminalToolCallArguments, a as createEmptyTransportUsage, b as throwIfModelStreamAborted, c as failTransportStream, d as iterateModelStream, f as iterateSseFrames, g as notifyProviderStreamOpened, h as notifyProviderHttpResponse, i as copyProviderAcceptanceObserver, l as finalizeTerminalToolCallArguments, m as notifyProviderHttpMetadata, n as assignTransportErrorDetails, o as createWritableTransportEventStream, p as mergeTransportHeaders, r as coerceTransportToolCallArguments, s as decodeSseFrames, t as IncompleteToolCallError, u as finalizeTransportStream, v as sanitizeNonEmptyTransportPayloadText, w as parseJsonObjectPreservingUnsafeIntegers, x as transportAbortError, y as sanitizeTransportPayloadText } from "./transport-stream-shared-D2uFMhMc.mjs";
|
|
15
|
+
import { n as getEnvApiKey } from "./env-api-keys-BuHc86ya.mjs";
|
|
16
|
+
import { withModelRequestBodyBytes } from "./internal/model-request-body.mjs";
|
|
17
17
|
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-DA4WHv1h.mjs";
|
|
18
|
-
import { c as flattenCompletionMessagesToStringContent, d as hasOpenAICompatibleConversationTurn, f as canonicalizeMaxTokensParam, i as createOpenAIResponsesTransportStreamFn, l as stripCompletionMessagesToRoleContent, m as createDeepSeekTextFilter, o as buildOpenAICompletionsParams, p as resolveMaxTokensParam, r as createAzureOpenAIResponsesTransportStreamFn, t as createOpenAICompletionsTransportStreamFn, u as applyCompletionsAnthropicCacheControl } from "./openai-completions-transport-
|
|
19
|
-
import { a as googleFlashSupportsMinimalThinking, i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, t as convertGoogleTools } from "./google-messages-
|
|
20
|
-
import { At as
|
|
21
|
-
import { c as
|
|
22
|
-
import { c as requestPreparedOpenAIResponsesCompaction } from "./openai-responses-request-lifecycle-
|
|
18
|
+
import { c as flattenCompletionMessagesToStringContent, d as hasOpenAICompatibleConversationTurn, f as canonicalizeMaxTokensParam, i as createOpenAIResponsesTransportStreamFn, l as stripCompletionMessagesToRoleContent, m as createDeepSeekTextFilter, o as buildOpenAICompletionsParams, p as resolveMaxTokensParam, r as createAzureOpenAIResponsesTransportStreamFn, t as createOpenAICompletionsTransportStreamFn, u as applyCompletionsAnthropicCacheControl } from "./openai-completions-transport-C6J4_oGf.mjs";
|
|
19
|
+
import { a as googleFlashSupportsMinimalThinking, i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, t as convertGoogleTools } from "./google-messages-CwBqSoa4.mjs";
|
|
20
|
+
import { At as log, Dt as createResponseModelTracker, Et as createOpenAIResponseHook, Ft as resolveOpenAIClientBaseUrl, It as resolvePromptCacheKey, J as OPENAI_RESPONSES_FUNCTION_CALL_ITEM_ID_RE, L as normalizeOpenAIResponsesReasoningReplayItem, Lt as withOpenAIErrorResponseHook, M as resolveResponsesContextUsageBoundary, Mt as parseOpenAICompletionsUsage, Nt as readOpenAICompletionsContentDeltas, Ot as detachPartialSnapshot, Pt as readOpenAICompletionsReasoningBatch, Q as splitOpenAIFunctionCallPairing, R as resolveReplayableResponsesMessageId, Tt as createOpenAIProviderAcceptanceHook, X as normalizeOpenAIResponsesFunctionCallId, Y as OPENAI_RESPONSES_ID_MAX_LENGTH, Z as shouldNormalizeOpenAIResponsesToolCallId, at as resolveNewestOpenAIResponsesCompactionReplay, ct as buildOpenAIClientHeaders, dt as enforceCodeModeResponsesToolSurface, ft as filterCodeModePayloadTools, gt as resolveOpenAIStrictToolFlagWithDiagnostics, ht as resolveCodeModeResponsesVisibleToolNames, it as captureOpenAIResponsesCompaction, jt as measureUtf8AppendBytes, kt as isOpenAICompletionsThinkingEnabled, lt as buildOpenAISdkClientOptions, mt as readCodeModePayloadToolName, nt as CompactionReplayRefreshRequiredError, pt as getCompat, q as OPENAI_RESPONSES_CALL_ID_RE, st as assertCodeModeResponsesToolSurface, ut as buildOpenAISdkRequestOptions, wt as GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP } from "./openai-responses-shared-CrFDkZ0N.mjs";
|
|
21
|
+
import { c as sanitizeResponsesImagePayload, d as resolveOpenAIResponsesCompactEndpointPlan, f as resolveOpenAIResponsesPayloadPolicy, l as applyOpenAIResponsesPayloadPolicy, m as resolveOpenAIResponsesServerCompactionPlan, p as resolveOpenAIResponsesRequestContextTokens, s as buildResponsesInputImage, u as normalizeOpenAIServiceTier } from "./openai-responses-endpoint-DCkURKS0.mjs";
|
|
22
|
+
import { c as requestPreparedOpenAIResponsesCompaction } from "./openai-responses-request-lifecycle-o-ODC_rF.mjs";
|
|
23
23
|
import { randomUUID } from "node:crypto";
|
|
24
24
|
//#region packages/ai/src/transports/anthropic-transport-stream.ts
|
|
25
|
-
const ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES = 8192;
|
|
26
25
|
const ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS = 400;
|
|
27
|
-
const ANTHROPIC_MESSAGES_ERROR_BODY_READ_IDLE_TIMEOUT_MS = 1e4;
|
|
28
26
|
const ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS = 16777216;
|
|
29
|
-
function isKimiAnthropicProvider(provider) {
|
|
30
|
-
return /^kimi(?:-|$)/.test(normalizeLowercaseStringOrEmpty(provider ?? ""));
|
|
31
|
-
}
|
|
32
|
-
function buildAnthropicBetaHeader(model, betaFeatures, params) {
|
|
33
|
-
if (!isDirectAnthropicModel(model)) return;
|
|
34
|
-
return params.oauth ? `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}` : betaFeatures.join(",");
|
|
35
|
-
}
|
|
36
27
|
const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com";
|
|
37
28
|
/** Resolve the effective Anthropic API base URL from model or environment. */
|
|
38
29
|
function resolveAnthropicBaseUrl(baseUrl) {
|
|
@@ -50,39 +41,6 @@ function withEffectiveAnthropicBaseUrl(model) {
|
|
|
50
41
|
baseUrl
|
|
51
42
|
};
|
|
52
43
|
}
|
|
53
|
-
function createAbortError(signal) {
|
|
54
|
-
const reason = signal.reason;
|
|
55
|
-
if (reason instanceof Error) return reason;
|
|
56
|
-
return createAbortError$1("Request was aborted", reason === void 0 ? void 0 : { cause: reason });
|
|
57
|
-
}
|
|
58
|
-
function readAnthropicSseChunk(reader, signal) {
|
|
59
|
-
if (!signal) return reader.read();
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
let settled = false;
|
|
62
|
-
const onAbort = () => {
|
|
63
|
-
if (settled) return;
|
|
64
|
-
settled = true;
|
|
65
|
-
signal.removeEventListener("abort", onAbort);
|
|
66
|
-
reject(createAbortError(signal));
|
|
67
|
-
};
|
|
68
|
-
if (signal.aborted) {
|
|
69
|
-
onAbort();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
73
|
-
reader.read().then((result) => {
|
|
74
|
-
if (settled) return;
|
|
75
|
-
settled = true;
|
|
76
|
-
signal.removeEventListener("abort", onAbort);
|
|
77
|
-
resolve(result);
|
|
78
|
-
}, (error) => {
|
|
79
|
-
if (settled) return;
|
|
80
|
-
settled = true;
|
|
81
|
-
signal.removeEventListener("abort", onAbort);
|
|
82
|
-
reject(toErrorObject(error, "Non-Error rejection"));
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
44
|
function parseAnthropicSseEventData(data) {
|
|
87
45
|
try {
|
|
88
46
|
return JSON.parse(data);
|
|
@@ -90,36 +48,27 @@ function parseAnthropicSseEventData(data) {
|
|
|
90
48
|
throw streamFragmentError(error);
|
|
91
49
|
}
|
|
92
50
|
}
|
|
93
|
-
function assertAnthropicSsePendingBufferWithinLimit(pendingChars) {
|
|
94
|
-
if (pendingChars <= ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS) return;
|
|
95
|
-
throw new Error(`Anthropic Messages SSE response exceeded max pending buffer size (${ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS} chars) without event boundary`);
|
|
96
|
-
}
|
|
97
51
|
async function* parseAnthropicSseBody(body, signal) {
|
|
98
52
|
const reader = body.getReader();
|
|
99
|
-
const decoder = new TextDecoder();
|
|
100
|
-
let buffer = "";
|
|
101
53
|
let completed = false;
|
|
102
|
-
const delimiter = /(?:\r\n|\r(?!\n)|\n)(?:\r\n|\r(?!\n)|\n)/g;
|
|
103
|
-
let scanOffset = 0;
|
|
104
54
|
try {
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
scanOffset = Math.max(0, buffer.length - 3);
|
|
55
|
+
for await (const { frame, terminated } of iterateSseFrames(async () => {
|
|
56
|
+
const chunk = await (signal ? racePromiseWithAbortSignal(() => reader.read().catch((error) => {
|
|
57
|
+
throw toErrorObject(error, "Non-Error rejection");
|
|
58
|
+
}), signal, (abortedSignal) => {
|
|
59
|
+
const reason = abortedSignal.reason;
|
|
60
|
+
if (reason instanceof Error) return reason;
|
|
61
|
+
return createAbortError("Request was aborted", reason === void 0 ? void 0 : { cause: reason });
|
|
62
|
+
}) : reader.read());
|
|
63
|
+
completed = chunk.done;
|
|
64
|
+
return chunk;
|
|
65
|
+
}, {
|
|
66
|
+
max: ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS,
|
|
67
|
+
unit: "characters",
|
|
68
|
+
message: `Anthropic Messages SSE response exceeded max pending buffer size (${ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS} chars) without event boundary`
|
|
69
|
+
})) {
|
|
70
|
+
const data = (terminated ? frame : frame.trim()).split(/\r\n|\n|\r/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart()).join("\n");
|
|
71
|
+
if (data && data !== "[DONE]") yield parseAnthropicSseEventData(data);
|
|
123
72
|
}
|
|
124
73
|
} finally {
|
|
125
74
|
if (!completed) {
|
|
@@ -132,12 +81,7 @@ async function* parseAnthropicSseBody(body, signal) {
|
|
|
132
81
|
}
|
|
133
82
|
async function readAnthropicMessagesErrorBody(response) {
|
|
134
83
|
try {
|
|
135
|
-
const text = await
|
|
136
|
-
maxBytes: ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES,
|
|
137
|
-
maxChars: ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES,
|
|
138
|
-
chunkTimeoutMs: ANTHROPIC_MESSAGES_ERROR_BODY_READ_IDLE_TIMEOUT_MS,
|
|
139
|
-
onIdleTimeout: ({ chunkTimeoutMs }) => /* @__PURE__ */ new Error(`Anthropic Messages error response stalled: no data received for ${chunkTimeoutMs}ms`)
|
|
140
|
-
}) ?? "";
|
|
84
|
+
const text = await readAnthropicMessagesErrorSnippet(response) ?? "";
|
|
141
85
|
try {
|
|
142
86
|
return JSON.parse(text);
|
|
143
87
|
} catch {
|
|
@@ -149,146 +93,98 @@ async function readAnthropicMessagesErrorBody(response) {
|
|
|
149
93
|
return "";
|
|
150
94
|
}
|
|
151
95
|
}
|
|
152
|
-
function createAnthropicTransportClient(params) {
|
|
153
|
-
const { model, context, apiKey, options } = params;
|
|
154
|
-
const optionHeaders = resolveOpencodeSessionHeaders(model, options);
|
|
155
|
-
const needsInterleavedBeta = (options?.interleavedThinking ?? true) && !supportsClaudeAdaptiveThinking(model);
|
|
156
|
-
const fetch = isKimiAnthropicProvider(model.provider) && options?.thinkingEnabled === true ? buildGuardedModelFetch(model, void 0, { sanitizeSse: false }) : buildGuardedModelFetch(model);
|
|
157
|
-
const copilot = model.provider === "github-copilot";
|
|
158
|
-
const bearerAuth = copilot || usesFoundryBearerAuth(resolveModelHeaderSentinels(model));
|
|
159
|
-
const isOAuthToken = !bearerAuth && isAnthropicOAuthApiKey(apiKey);
|
|
160
|
-
let defaultHeaders;
|
|
161
|
-
let claudeCodeVersion;
|
|
162
|
-
let directApiKeyBetaHeader;
|
|
163
|
-
if (bearerAuth) defaultHeaders = mergeTransportHeaders({
|
|
164
|
-
accept: "application/json",
|
|
165
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
166
|
-
...needsInterleavedBeta ? { "anthropic-beta": "interleaved-thinking-2025-05-14" } : {}
|
|
167
|
-
}, copilot ? model.headers : omitFoundryBearerCredentialHeaders(model.headers), copilot ? getAiTransportHost().buildCopilotDynamicHeaders(context.messages) : void 0, optionHeaders);
|
|
168
|
-
else {
|
|
169
|
-
const betaFeatures = ["fine-grained-tool-streaming-2025-05-14"];
|
|
170
|
-
if (needsInterleavedBeta) betaFeatures.push("interleaved-thinking-2025-05-14");
|
|
171
|
-
const betaHeader = buildAnthropicBetaHeader(model, betaFeatures, { oauth: isOAuthToken });
|
|
172
|
-
if (isOAuthToken) {
|
|
173
|
-
const identity = buildAnthropicClaudeCodeIdentity(betaHeader, model.headers, optionHeaders);
|
|
174
|
-
defaultHeaders = identity.headers;
|
|
175
|
-
claudeCodeVersion = identity.version;
|
|
176
|
-
} else {
|
|
177
|
-
defaultHeaders = mergeTransportHeaders({
|
|
178
|
-
accept: "application/json",
|
|
179
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
180
|
-
...betaHeader ? { "anthropic-beta": betaHeader } : {},
|
|
181
|
-
...options?.sessionId && options.cacheRetention !== "none" && model.compat?.sendSessionAffinityHeaders === true ? { "x-session-affinity": options.sessionId } : {}
|
|
182
|
-
}, model.headers, optionHeaders, getAiTransportHost().resolveProviderRequestHeaders({
|
|
183
|
-
provider: model.provider,
|
|
184
|
-
api: model.api,
|
|
185
|
-
baseUrl: model.baseUrl,
|
|
186
|
-
model
|
|
187
|
-
}));
|
|
188
|
-
directApiKeyBetaHeader = isDirectAnthropicModel(model) ? new Headers(defaultHeaders).get("anthropic-beta") ?? "" : void 0;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
const url = resolveAnthropicMessagesUrl(model.baseUrl);
|
|
192
|
-
return {
|
|
193
|
-
isOAuthToken,
|
|
194
|
-
claudeCodeVersion,
|
|
195
|
-
directApiKeyBetaHeader,
|
|
196
|
-
async request(body, requestOptions) {
|
|
197
|
-
const headers = new Headers(mergeTransportHeaders({
|
|
198
|
-
"content-type": "application/json",
|
|
199
|
-
"anthropic-version": "2023-06-01",
|
|
200
|
-
...bearerAuth || isOAuthToken ? { authorization: `Bearer ${apiKey}` } : { "x-api-key": apiKey }
|
|
201
|
-
}, defaultHeaders));
|
|
202
|
-
for (const [name, value] of Object.entries(requestOptions?.headers ?? {})) headers.set(name, value);
|
|
203
|
-
const response = await fetch(url, {
|
|
204
|
-
method: "POST",
|
|
205
|
-
headers,
|
|
206
|
-
body: JSON.stringify(body),
|
|
207
|
-
signal: requestOptions?.signal
|
|
208
|
-
});
|
|
209
|
-
return {
|
|
210
|
-
response,
|
|
211
|
-
stream: response.body ? parseAnthropicSseBody(response.body, requestOptions?.signal) : []
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
96
|
/** Create the stream function used by Anthropic Messages transport models. */
|
|
217
97
|
function createAnthropicMessagesTransportStreamFn() {
|
|
218
98
|
return (rawModel, context, rawOptions) => {
|
|
219
99
|
const model = withEffectiveAnthropicBaseUrl(rawModel);
|
|
220
100
|
const options = rawOptions;
|
|
221
101
|
const { eventStream, stream } = createWritableTransportEventStream();
|
|
222
|
-
(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
102
|
+
runAnthropicStreamLifecycle({
|
|
103
|
+
model,
|
|
104
|
+
stream,
|
|
105
|
+
options,
|
|
106
|
+
profile: "transport",
|
|
107
|
+
prepare: () => {
|
|
227
108
|
const apiKey = options?.apiKey ?? getEnvApiKey(model.provider) ?? "";
|
|
228
109
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
229
110
|
const transportOptions = resolveAnthropicTransportOptions(model, options, apiKey);
|
|
230
111
|
const requestContext = prepareClaudeNoPrefillRequestContext(model, context);
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
112
|
+
const optionHeaders = resolveOpencodeSessionHeaders(model, transportOptions);
|
|
113
|
+
const needsInterleavedBeta = (transportOptions.interleavedThinking ?? true) && !supportsClaudeAdaptiveThinking(model);
|
|
114
|
+
const fetch = withModelRequestBodyBytes(options, /^kimi(?:-|$)/.test(normalizeLowercaseStringOrEmpty(model.provider ?? "")) && transportOptions.thinkingEnabled === true ? buildGuardedModelFetch(model, void 0, { sanitizeSse: false }) : buildGuardedModelFetch(model));
|
|
115
|
+
const copilot = model.provider === "github-copilot";
|
|
116
|
+
const bearerAuth = copilot || usesFoundryBearerAuth(resolveModelHeaderSentinels(model));
|
|
117
|
+
const isOAuthToken = !bearerAuth && isAnthropicOAuthApiKey(apiKey);
|
|
118
|
+
let defaultHeaders;
|
|
119
|
+
let claudeCodeVersion;
|
|
120
|
+
let directApiKeyBetaHeader;
|
|
121
|
+
if (bearerAuth) defaultHeaders = mergeTransportHeaders({
|
|
122
|
+
accept: "application/json",
|
|
123
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
124
|
+
...needsInterleavedBeta ? { "anthropic-beta": "interleaved-thinking-2025-05-14" } : {}
|
|
125
|
+
}, copilot ? model.headers : omitFoundryBearerCredentialHeaders(model.headers), copilot ? getAiTransportHost().buildCopilotDynamicHeaders(requestContext.messages) : void 0, optionHeaders);
|
|
126
|
+
else {
|
|
127
|
+
const betaFeatures = ["fine-grained-tool-streaming-2025-05-14"];
|
|
128
|
+
if (needsInterleavedBeta) betaFeatures.push("interleaved-thinking-2025-05-14");
|
|
129
|
+
const betaHeader = !isDirectAnthropicModel(model) ? void 0 : isOAuthToken ? `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}` : betaFeatures.join(",");
|
|
130
|
+
if (isOAuthToken) {
|
|
131
|
+
const identity = buildAnthropicClaudeCodeIdentity(betaHeader, model.headers, optionHeaders);
|
|
132
|
+
defaultHeaders = identity.headers;
|
|
133
|
+
claudeCodeVersion = identity.version;
|
|
134
|
+
} else {
|
|
135
|
+
defaultHeaders = mergeTransportHeaders({
|
|
136
|
+
accept: "application/json",
|
|
137
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
138
|
+
...betaHeader ? { "anthropic-beta": betaHeader } : {},
|
|
139
|
+
...transportOptions.sessionId && transportOptions.cacheRetention !== "none" && model.compat?.sendSessionAffinityHeaders === true ? { "x-session-affinity": transportOptions.sessionId } : {}
|
|
140
|
+
}, model.headers, optionHeaders, getAiTransportHost().resolveProviderRequestHeaders({
|
|
141
|
+
provider: model.provider,
|
|
142
|
+
api: model.api,
|
|
143
|
+
baseUrl: model.baseUrl,
|
|
144
|
+
model
|
|
145
|
+
}));
|
|
146
|
+
directApiKeyBetaHeader = isDirectAnthropicModel(model) ? new Headers(omitNullRequestHeaders(defaultHeaders)).get("anthropic-beta") ?? "" : void 0;
|
|
147
|
+
}
|
|
259
148
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
149
|
+
const url = resolveAnthropicMessagesUrl(model.baseUrl);
|
|
150
|
+
return {
|
|
151
|
+
context: requestContext,
|
|
263
152
|
options: transportOptions,
|
|
264
|
-
output,
|
|
265
|
-
stream,
|
|
266
|
-
refusalBuffer,
|
|
267
153
|
isOAuthToken,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
154
|
+
serverSideFallback: !isOAuthToken && supportsAnthropicServerSideFallback(model),
|
|
155
|
+
claudeCodeVersion,
|
|
156
|
+
directApiKeyBetaHeader,
|
|
157
|
+
request: async (_body, requestHeaders, encodeBody) => {
|
|
158
|
+
const headers = new Headers(omitNullRequestHeaders(mergeTransportHeaders({
|
|
159
|
+
"content-type": "application/json",
|
|
160
|
+
"anthropic-version": "2023-06-01",
|
|
161
|
+
...bearerAuth || isOAuthToken ? { authorization: `Bearer ${apiKey}` } : { "x-api-key": apiKey }
|
|
162
|
+
}, defaultHeaders)));
|
|
163
|
+
for (const [name, value] of Object.entries(requestHeaders ?? {})) headers.set(name, value);
|
|
164
|
+
const response = await fetch(url, {
|
|
165
|
+
method: "POST",
|
|
166
|
+
headers,
|
|
167
|
+
body: encodeBody(),
|
|
168
|
+
signal: transportOptions.signal
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
response,
|
|
172
|
+
events: response.body ? parseAnthropicSseBody(response.body, transportOptions.signal) : []
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
checkResponse: async (response) => {
|
|
176
|
+
if (!response.ok) {
|
|
177
|
+
const errorBody = await readAnthropicMessagesErrorBody(response);
|
|
178
|
+
throw Object.assign(/* @__PURE__ */ new Error(`${response.status} status code (no body)`), {
|
|
179
|
+
status: response.status,
|
|
180
|
+
headers: response.headers,
|
|
181
|
+
errorBody
|
|
182
|
+
});
|
|
183
|
+
}
|
|
288
184
|
}
|
|
289
|
-
}
|
|
185
|
+
};
|
|
290
186
|
}
|
|
291
|
-
})
|
|
187
|
+
});
|
|
292
188
|
return eventStream;
|
|
293
189
|
};
|
|
294
190
|
}
|
|
@@ -532,6 +428,45 @@ function prepareTransportAwareSimpleModel(model, ctx) {
|
|
|
532
428
|
});
|
|
533
429
|
}
|
|
534
430
|
//#endregion
|
|
431
|
+
//#region packages/ai/src/transports/provider-wait.ts
|
|
432
|
+
/** A provider-owned wait lasts only until its first response event or settlement. */
|
|
433
|
+
function createProviderWaitObserver(options) {
|
|
434
|
+
let timer;
|
|
435
|
+
let started = false;
|
|
436
|
+
let stopped = false;
|
|
437
|
+
let shown;
|
|
438
|
+
const signal = options?.signal;
|
|
439
|
+
const notify = options?.onProviderWait;
|
|
440
|
+
const report = (reason) => {
|
|
441
|
+
if (!started || stopped || !notify || shown === reason) return;
|
|
442
|
+
shown = reason;
|
|
443
|
+
notify(reason);
|
|
444
|
+
};
|
|
445
|
+
const stop = () => {
|
|
446
|
+
if (stopped) return;
|
|
447
|
+
stopped = true;
|
|
448
|
+
clearTimeout(timer);
|
|
449
|
+
signal?.removeEventListener("abort", stop);
|
|
450
|
+
if (shown) {
|
|
451
|
+
shown = void 0;
|
|
452
|
+
notify?.(null);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
return {
|
|
456
|
+
start() {
|
|
457
|
+
if (started || stopped || !notify || signal?.aborted) return;
|
|
458
|
+
started = true;
|
|
459
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
460
|
+
timer = setTimeout(() => {
|
|
461
|
+
if (!shown) report("response");
|
|
462
|
+
}, 1e3);
|
|
463
|
+
timer.unref?.();
|
|
464
|
+
},
|
|
465
|
+
report,
|
|
466
|
+
stop
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
535
470
|
//#region packages/ai/src/transports/simple-completion-transport.ts
|
|
536
471
|
/** Standalone completions have no durable session, but may require routing identity. */
|
|
537
472
|
function prepareHeadersForSimpleCompletion(model, options) {
|
|
@@ -582,17 +517,6 @@ function normalizeCodexResponsesBaseUrlForOpenAISdk(baseUrl) {
|
|
|
582
517
|
if (customPath.endsWith("/codex/responses")) return customPath.slice(0, -10);
|
|
583
518
|
return customPath.endsWith("/codex") ? customPath : `${customPath}/codex`;
|
|
584
519
|
}
|
|
585
|
-
function resolveProviderSimpleCompletionApi(model, auth, agentId) {
|
|
586
|
-
const parts = [
|
|
587
|
-
model.provider,
|
|
588
|
-
model.id,
|
|
589
|
-
model.api,
|
|
590
|
-
model.baseUrl || "default"
|
|
591
|
-
];
|
|
592
|
-
if (auth) parts.push(auth.mode, auth.authFlow ?? "");
|
|
593
|
-
if (agentId) parts.push("agent", agentId);
|
|
594
|
-
return `${PROVIDER_SIMPLE_COMPLETION_API_PREFIX}${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
595
|
-
}
|
|
596
520
|
function resolveProviderStreamApi(model) {
|
|
597
521
|
const parts = [
|
|
598
522
|
model.provider,
|
|
@@ -602,40 +526,6 @@ function resolveProviderStreamApi(model) {
|
|
|
602
526
|
];
|
|
603
527
|
return `${PROVIDER_STREAM_API_PREFIX}${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
604
528
|
}
|
|
605
|
-
function applyProviderSimpleCompletionWrapper(registry, model, cfg, hookSourceApi, auth, agentId) {
|
|
606
|
-
if (model.api.startsWith(PROVIDER_SIMPLE_COMPLETION_API_PREFIX)) return model;
|
|
607
|
-
const sourceProvider = registry.getApiProvider(model.api);
|
|
608
|
-
if (!sourceProvider) return model;
|
|
609
|
-
const dispatchApi = model.api;
|
|
610
|
-
const sourceStreamFn = (runtimeModel, context, options) => sourceProvider.streamSimple(projectModel(runtimeModel, { api: dispatchApi }), context, options);
|
|
611
|
-
const streamFn = getAiTransportHost().plugin.wrapSimpleCompletionStream({
|
|
612
|
-
provider: model.provider,
|
|
613
|
-
config: cfg,
|
|
614
|
-
context: {
|
|
615
|
-
config: cfg,
|
|
616
|
-
provider: model.provider,
|
|
617
|
-
modelId: model.id,
|
|
618
|
-
model,
|
|
619
|
-
sourceApi: hookSourceApi,
|
|
620
|
-
auth,
|
|
621
|
-
agentId,
|
|
622
|
-
streamFn: sourceStreamFn
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
if (!streamFn) return model;
|
|
626
|
-
const registeredStreamFn = (runtimeModel, context, options) => streamFn(projectModel(runtimeModel, { api: hookSourceApi }), context, options);
|
|
627
|
-
const api = resolveProviderSimpleCompletionApi(model, auth, agentId);
|
|
628
|
-
return registerCustomApi(registry, api, registeredStreamFn) ? projectModel(model, { api }) : model;
|
|
629
|
-
}
|
|
630
|
-
function prepareCodexSimpleTransportModel(registry, model, cfg) {
|
|
631
|
-
if (model.provider !== "openai" || model.api !== "openai-chatgpt-responses") return;
|
|
632
|
-
const transportModel = projectModel(model, { baseUrl: normalizeCodexResponsesBaseUrlForOpenAISdk(model.baseUrl) });
|
|
633
|
-
const api = resolveTransportAwareSimpleApi(model.api);
|
|
634
|
-
const streamFn = createSupportedTransportStreamFn(transportModel, { cfg });
|
|
635
|
-
if (!api || !streamFn) return;
|
|
636
|
-
if (!registerCustomApi(registry, api, streamFn)) return;
|
|
637
|
-
return projectModel(transportModel, { api });
|
|
638
|
-
}
|
|
639
529
|
function resolveModelTransportSentinels(model, boundary) {
|
|
640
530
|
const host = getAiTransportHost();
|
|
641
531
|
if (host.unwrapModelTransportSentinels) return host.unwrapModelTransportSentinels(model, boundary);
|
|
@@ -654,42 +544,71 @@ function wrapPluginProviderStream(streamFn) {
|
|
|
654
544
|
});
|
|
655
545
|
};
|
|
656
546
|
}
|
|
657
|
-
function
|
|
658
|
-
const
|
|
547
|
+
function prepareModelForSimpleCompletion(params) {
|
|
548
|
+
const { apiRegistry, model, cfg, auth, agentId } = params;
|
|
549
|
+
const wrap = (prepared) => {
|
|
550
|
+
const hookSourceApi = model.api;
|
|
551
|
+
if (prepared.api.startsWith(PROVIDER_SIMPLE_COMPLETION_API_PREFIX)) return prepared;
|
|
552
|
+
const sourceProvider = apiRegistry.getApiProvider(prepared.api);
|
|
553
|
+
if (!sourceProvider) return prepared;
|
|
554
|
+
const dispatchApi = prepared.api;
|
|
555
|
+
const sourceStreamFn = (runtimeModel, context, options) => sourceProvider.streamSimple(projectModel(runtimeModel, { api: dispatchApi }), context, options);
|
|
556
|
+
const streamFn = getAiTransportHost().plugin.wrapSimpleCompletionStream({
|
|
557
|
+
provider: prepared.provider,
|
|
558
|
+
config: cfg,
|
|
559
|
+
context: {
|
|
560
|
+
config: cfg,
|
|
561
|
+
provider: prepared.provider,
|
|
562
|
+
modelId: prepared.id,
|
|
563
|
+
model: prepared,
|
|
564
|
+
sourceApi: hookSourceApi,
|
|
565
|
+
auth,
|
|
566
|
+
agentId,
|
|
567
|
+
streamFn: sourceStreamFn
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
if (!streamFn) return prepared;
|
|
571
|
+
const registeredStreamFn = (runtimeModel, context, options) => streamFn(projectModel(runtimeModel, { api: hookSourceApi }), context, options);
|
|
572
|
+
const parts = [
|
|
573
|
+
prepared.provider,
|
|
574
|
+
prepared.id,
|
|
575
|
+
prepared.api,
|
|
576
|
+
prepared.baseUrl || "default"
|
|
577
|
+
];
|
|
578
|
+
if (auth) parts.push(auth.mode, auth.authFlow ?? "");
|
|
579
|
+
if (agentId) parts.push("agent", agentId);
|
|
580
|
+
const api = `${PROVIDER_SIMPLE_COMPLETION_API_PREFIX}${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
581
|
+
return registerCustomApi(apiRegistry, api, registeredStreamFn) ? projectModel(prepared, { api }) : prepared;
|
|
582
|
+
};
|
|
583
|
+
const pluginModel = resolveModelTransportSentinels(model, "plugin simple-completion stream construction");
|
|
659
584
|
const providerStreamFn = getAiTransportHost().plugin.resolveProviderStream({
|
|
660
|
-
provider:
|
|
661
|
-
config:
|
|
585
|
+
provider: model.provider,
|
|
586
|
+
config: cfg,
|
|
662
587
|
context: {
|
|
663
|
-
config:
|
|
664
|
-
provider:
|
|
665
|
-
modelId:
|
|
588
|
+
config: cfg,
|
|
589
|
+
provider: model.provider,
|
|
590
|
+
modelId: model.id,
|
|
666
591
|
model: pluginModel
|
|
667
592
|
}
|
|
668
593
|
});
|
|
669
|
-
const transportFallback = providerStreamFn ? void 0 : createTransportAwareStreamFnForModel(
|
|
670
|
-
const streamFn = providerStreamFn ? wrapPluginProviderStream(providerStreamFn) : transportFallback &&
|
|
671
|
-
if (
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
cfg,
|
|
684
|
-
apiRegistry
|
|
685
|
-
});
|
|
686
|
-
if (providerStreamModel) return wrap(providerStreamModel);
|
|
687
|
-
const codexTransportModel = prepareCodexSimpleTransportModel(apiRegistry, model, cfg);
|
|
688
|
-
if (codexTransportModel) return wrap(codexTransportModel);
|
|
594
|
+
const transportFallback = providerStreamFn ? void 0 : createTransportAwareStreamFnForModel(model.api === "google-generative-ai" ? pluginModel : model, { cfg });
|
|
595
|
+
const streamFn = providerStreamFn ? wrapPluginProviderStream(providerStreamFn) : transportFallback && model.api === "google-generative-ai" ? wrapPluginProviderStream(transportFallback) : transportFallback;
|
|
596
|
+
if (streamFn) {
|
|
597
|
+
const api = apiRegistry.getApiProvider(model.api) ? resolveProviderStreamApi(model) : model.api;
|
|
598
|
+
const sourceApi = model.api;
|
|
599
|
+
const sourceStreamFn = (runtimeModel, context, options) => streamFn(projectModel(runtimeModel, { api: sourceApi }), context, options);
|
|
600
|
+
if (registerCustomApi(apiRegistry, api, sourceStreamFn)) return wrap(api === model.api ? model : projectModel(model, { api }));
|
|
601
|
+
}
|
|
602
|
+
if (model.provider === "openai" && model.api === "openai-chatgpt-responses") {
|
|
603
|
+
const transportModel = projectModel(model, { baseUrl: normalizeCodexResponsesBaseUrlForOpenAISdk(model.baseUrl) });
|
|
604
|
+
const api = resolveTransportAwareSimpleApi(model.api);
|
|
605
|
+
const codexStreamFn = createSupportedTransportStreamFn(transportModel, { cfg });
|
|
606
|
+
if (api && codexStreamFn && registerCustomApi(apiRegistry, api, codexStreamFn)) return wrap(projectModel(transportModel, { api }));
|
|
607
|
+
}
|
|
689
608
|
const transportAwareModel = prepareTransportAwareSimpleModel(model, { cfg });
|
|
690
609
|
if (transportAwareModel !== model) {
|
|
691
|
-
const
|
|
692
|
-
if (
|
|
610
|
+
const transportStreamFn = createTransportAwareStreamFnForModel(model, { cfg });
|
|
611
|
+
if (transportStreamFn && registerCustomApi(apiRegistry, transportAwareModel.api, transportStreamFn)) return wrap(transportAwareModel);
|
|
693
612
|
}
|
|
694
613
|
if (model.provider === "anthropic-vertex") {
|
|
695
614
|
const api = resolveAnthropicVertexSimpleApi(model.baseUrl);
|
|
@@ -698,4 +617,4 @@ function prepareModelForSimpleCompletion(params) {
|
|
|
698
617
|
return wrap(model);
|
|
699
618
|
}
|
|
700
619
|
//#endregion
|
|
701
|
-
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, createTransportAwareStreamFnForModel as buildTransportAwareSimpleStreamFn, createTransportAwareStreamFnForModel, canonicalizeMaxTokensParam, captureOpenAIResponsesCompaction, coerceTransportToolCallArguments, consumeGoogleGenerateContentStream, convertGoogleTools, copyProviderAcceptanceObserver, createAnthropicMessagesTransportStreamFn, createAzureOpenAIResponsesTransportStreamFn, createSupportedTransportStreamFn as createBoundaryAwareStreamFnForModel, createSupportedTransportStreamFn as createOpenClawTransportStreamFnForModel, createDeepSeekTextFilter, createEmptyTransportUsage,
|
|
620
|
+
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, buildResponsesInputImage, createTransportAwareStreamFnForModel as buildTransportAwareSimpleStreamFn, createTransportAwareStreamFnForModel, canonicalizeMaxTokensParam, captureOpenAIResponsesCompaction, coerceTransportToolCallArguments, consumeGoogleGenerateContentStream, convertGoogleTools, copyProviderAcceptanceObserver, createAnthropicMessagesTransportStreamFn, createAzureOpenAIResponsesTransportStreamFn, createSupportedTransportStreamFn as createBoundaryAwareStreamFnForModel, createSupportedTransportStreamFn as createOpenClawTransportStreamFnForModel, createDeepSeekTextFilter, createEmptyTransportUsage, createOpenAICompletionsTransportStreamFn, createOpenAIProviderAcceptanceHook, createOpenAIResponseHook, createOpenAIResponsesTransportStreamFn, createProviderWaitObserver, createResponseModelTracker, createWritableTransportEventStream, decodeSseFrames, detachPartialSnapshot, detectOpenAICompletionsCompat, emitModelTransportDebug, emitModelTransportError, enforceCodeModeResponsesToolSurface, failTransportStream, filterCodeModePayloadTools, finalizeTerminalToolCallArguments, finalizeTransportStream, flattenCompletionMessagesToStringContent, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, getCompat, googleFlashSupportsMinimalThinking, hasOpenAICompatibleConversationTurn, isAnthropicServerToolClearingEnabled, isCodeModeModelVisibleToolName, isCompactionReplayCheckpoint, isDirectAnthropicModel, isKnownOpenAIEndpoint, isNativeOpenAIEndpoint, isOpenAICodexResponsesModel, isOpenAICompletionsThinkingEnabled, iterateModelStream, iterateSseFrames, log, logAnthropicContextEdits, measureUtf8AppendBytes, mergeTransportHeaders, normalizeCodexResponsesBaseUrlForOpenAISdk, normalizeOpenAIResponsesFunctionCallId, normalizeOpenAIResponsesReasoningReplayItem, normalizeOpenAIServiceTier, 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, resolveCompletionTokenReservation, resolveMaxTokensParam, resolveModelPayloadDebugMode, resolveModelSseDebugMode, resolveOpenAIClientBaseUrl, resolveOpenAICompletionsCompat, resolveOpenAIPromptCacheKeySupport, resolveOpenAIReasoningEffortMap, resolveOpenAIResponsesCompactEndpointPlan, resolveOpenAIResponsesPayloadPolicy, resolveOpenAIResponsesRequestContextTokens, resolveOpenAIResponsesServerCompactionPlan, resolveOpenAIStrictToolFlagWithDiagnostics, resolvePromptCacheKey, resolveReplayableResponsesMessageId, resolveTransportAwareSimpleApi, sanitizeNonEmptyTransportPayloadText, sanitizeResponsesImagePayload, sanitizeTransportPayloadText, shouldNormalizeOpenAIResponsesToolCallId, sortPromptCacheToolsByName as sortTransportToolsByName, splitOpenAIFunctionCallPairing, stripCompactionReplayCheckpoint, stripCompactionReplayCheckpointInPlace, stripCompletionMessagesToRoleContent, supportsAnthropicServerSideFallback, throwIfModelStreamAborted, transportAbortError, usesNativeOpenAICodexResponsesBackend, withOpenAIErrorResponseHook, withProviderAcceptanceObserver, withProviderResponseHook };
|