@openclaw/ai 2026.11.3 → 2026.11.5-beta.2
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 -8
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
- package/dist/anthropic-DEKgalVg.mjs +182 -0
- package/dist/{anthropic-payload-policy-C0ki72BT.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
- package/dist/{anthropic-stream-reducer-yWDb5Cct.mjs → anthropic-stream-lifecycle-DF2qVvg1.mjs} +845 -649
- package/dist/{anthropic-tool-projection-C2-d1eZ3.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
- package/dist/{anthropic-tool-projection-DZOKfAmL.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-BvvXzZbi.mjs → azure-openai-responses-DbQV5RTx.mjs} +47 -53
- 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-v7oVEW59.mjs → diagnostics-CloVGQiK.mjs} +27 -20
- 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-Cpi_cLKZ.mjs → google-B1g82bn4.mjs} +7 -8
- package/dist/{google-interactions-CGINbsjO.mjs → google-interactions-Ckr0Z99Z.mjs} +243 -269
- package/dist/{google-messages-DQMgG5yG.mjs → google-messages-A-9d3y5V.mjs} +52 -18
- package/dist/{google-provider-stream-BHd0cST9.mjs → google-provider-stream-CNVh4gpm.mjs} +19 -11
- package/dist/{google-shared-vtag8bj5.mjs → google-shared-WNM86ZcW.mjs} +72 -42
- package/dist/{google-vertex-eKoUnW7N.mjs → google-vertex-CXjleC6g.mjs} +3 -3
- package/dist/{google-video-slots-D8tPH8wX.mjs → google-video-slots-Bxt-OXO8.mjs} +1 -1
- package/dist/{host-CWt55nnF.mjs → host-DX7ORpeH.mjs} +46 -39
- package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
- package/dist/{host-policy-Dm7PM6AD.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 +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- 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-CU9A4Lg8.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -111
- package/dist/internal/retry-after.d.mts +2 -2
- package/dist/internal/retry-after.mjs +96 -32
- 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-CjHkvsqR.mjs +3741 -0
- package/dist/{openai.LICENSE → mistral.LICENSE} +1 -1
- 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-BZa3SySh.mjs → openai-chatgpt-responses-CwS5JP7A.mjs} +61 -80
- package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
- package/dist/{openai-completions-compat-bNQXF1y9.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
- package/dist/{openai-completions-CCZ_UHCk.mjs → openai-completions-sj4S-RXQ.mjs} +5 -5
- package/dist/openai-completions-transport-BDAIA0_P.mjs +3406 -0
- package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
- package/dist/{openai-prompt-cache-B9AvdoEo.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
- package/dist/{openai-responses-compaction-replay-_sUXtcwU.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
- package/dist/{openai-responses-contracts-B1nkeLL6.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
- package/dist/{openai-responses-contracts-B5mGAbR6.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
- package/dist/{openai-responses-endpoint-CfKR6N5f.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
- package/dist/openai-responses-ev_c6oTy.mjs +89 -0
- package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
- package/dist/{openai-responses-request-lifecycle-CTqHc02t.mjs → openai-responses-request-lifecycle-BuOs0mwI.mjs} +12 -26
- package/dist/{openai-responses-shared-wx9v1MCn.mjs → openai-responses-shared-BmRQnUPP.mjs} +633 -1493
- package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
- package/dist/{openai-tool-schema-BTEU2xmN.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
- package/dist/otel-Buswj0Mf.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-DAzsyi49.d.mts → provider-options-Mo8NM5d1.d.mts} +16 -5
- package/dist/{provider-replay-context-4vxI7p4V.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
- package/dist/provider-transcript-transform-DtaxNcC1.mjs +32 -0
- package/dist/{provider-transport-turn-state-D_GjPJHe.mjs → provider-transport-turn-state-BIS8maBK.mjs} +4 -4
- package/dist/{provider-types-CWl4VXvE.d.mts → provider-types-B1e98js5.d.mts} +3 -3
- package/dist/provider-types.d.mts +7 -6
- 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-BrmTv0jL.d.mts → retry-after-DnHBlFS2.d.mts} +21 -1
- 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-xJkqrG_E.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-C4YDqhFj.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-CvK1yQg7.mjs +582 -0
- package/dist/{tool-schema-json-projection-B1sTYwfH.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
- package/dist/{transport-stream-shared-lhgkTOz3.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-DwOpuTjL.mjs → transport-utils-Da_39MYi.mjs} +23 -38
- package/dist/transports.d.mts +42 -39
- package/dist/transports.mjs +215 -296
- 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-lueA8LUg.mjs +0 -221
- package/dist/assistant-output-BnQm3fov.mjs +0 -47
- package/dist/event-stream-CDpFza-M.d.mts +0 -1
- package/dist/index-DSprYWaz.d.mts +0 -185
- package/dist/mistral-CQ7aoWg2.mjs +0 -512
- package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
- package/dist/openai-CiRi-nVE.mjs +0 -20077
- package/dist/openai-completions-transport-DFvSBbUT.mjs +0 -10881
- package/dist/openai-responses-DQsZKUoI.mjs +0 -87
- package/dist/rolldown-runtime-B4iAMlE-.mjs +0 -35
- package/dist/types-CBJthzJX.d.mts +0 -1
- package/dist/ws.LICENSE +0 -20
package/dist/transports.mjs
CHANGED
|
@@ -1,39 +1,30 @@
|
|
|
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-DF2qVvg1.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 {
|
|
20
|
-
import { At as
|
|
21
|
-
import { c as
|
|
22
|
-
import { c as requestPreparedOpenAIResponsesCompaction } from "./openai-responses-request-lifecycle-
|
|
23
|
-
import { n as createGoogleVideoPlaceholder, r as materializeGoogleVideoSlots, t as GOOGLE_VIDEO_SLOT_OMISSION } from "./google-video-slots-
|
|
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-BDAIA0_P.mjs";
|
|
19
|
+
import { i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, s as googleFlashSupportsMinimalThinking, t as convertGoogleTools } from "./google-messages-A-9d3y5V.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-BmRQnUPP.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-BuOs0mwI.mjs";
|
|
23
|
+
import { n as createGoogleVideoPlaceholder, r as materializeGoogleVideoSlots, t as GOOGLE_VIDEO_SLOT_OMISSION } from "./google-video-slots-Bxt-OXO8.mjs";
|
|
24
24
|
import { randomUUID } from "node:crypto";
|
|
25
25
|
//#region packages/ai/src/transports/anthropic-transport-stream.ts
|
|
26
|
-
const ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES = 8192;
|
|
27
26
|
const ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS = 400;
|
|
28
|
-
const ANTHROPIC_MESSAGES_ERROR_BODY_READ_IDLE_TIMEOUT_MS = 1e4;
|
|
29
27
|
const ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS = 16777216;
|
|
30
|
-
function isKimiAnthropicProvider(provider) {
|
|
31
|
-
return /^kimi(?:-|$)/.test(normalizeLowercaseStringOrEmpty(provider ?? ""));
|
|
32
|
-
}
|
|
33
|
-
function buildAnthropicBetaHeader(model, betaFeatures, params) {
|
|
34
|
-
if (!isDirectAnthropicModel(model)) return;
|
|
35
|
-
return params.oauth ? `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}` : betaFeatures.join(",");
|
|
36
|
-
}
|
|
37
28
|
const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com";
|
|
38
29
|
/** Resolve the effective Anthropic API base URL from model or environment. */
|
|
39
30
|
function resolveAnthropicBaseUrl(baseUrl) {
|
|
@@ -51,39 +42,6 @@ function withEffectiveAnthropicBaseUrl(model) {
|
|
|
51
42
|
baseUrl
|
|
52
43
|
};
|
|
53
44
|
}
|
|
54
|
-
function createAbortError(signal) {
|
|
55
|
-
const reason = signal.reason;
|
|
56
|
-
if (reason instanceof Error) return reason;
|
|
57
|
-
return createAbortError$1("Request was aborted", reason === void 0 ? void 0 : { cause: reason });
|
|
58
|
-
}
|
|
59
|
-
function readAnthropicSseChunk(reader, signal) {
|
|
60
|
-
if (!signal) return reader.read();
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
let settled = false;
|
|
63
|
-
const onAbort = () => {
|
|
64
|
-
if (settled) return;
|
|
65
|
-
settled = true;
|
|
66
|
-
signal.removeEventListener("abort", onAbort);
|
|
67
|
-
reject(createAbortError(signal));
|
|
68
|
-
};
|
|
69
|
-
if (signal.aborted) {
|
|
70
|
-
onAbort();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
74
|
-
reader.read().then((result) => {
|
|
75
|
-
if (settled) return;
|
|
76
|
-
settled = true;
|
|
77
|
-
signal.removeEventListener("abort", onAbort);
|
|
78
|
-
resolve(result);
|
|
79
|
-
}, (error) => {
|
|
80
|
-
if (settled) return;
|
|
81
|
-
settled = true;
|
|
82
|
-
signal.removeEventListener("abort", onAbort);
|
|
83
|
-
reject(toErrorObject(error, "Non-Error rejection"));
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
45
|
function parseAnthropicSseEventData(data) {
|
|
88
46
|
try {
|
|
89
47
|
return JSON.parse(data);
|
|
@@ -91,36 +49,27 @@ function parseAnthropicSseEventData(data) {
|
|
|
91
49
|
throw streamFragmentError(error);
|
|
92
50
|
}
|
|
93
51
|
}
|
|
94
|
-
function assertAnthropicSsePendingBufferWithinLimit(pendingChars) {
|
|
95
|
-
if (pendingChars <= ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS) return;
|
|
96
|
-
throw new Error(`Anthropic Messages SSE response exceeded max pending buffer size (${ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS} chars) without event boundary`);
|
|
97
|
-
}
|
|
98
52
|
async function* parseAnthropicSseBody(body, signal) {
|
|
99
53
|
const reader = body.getReader();
|
|
100
|
-
const decoder = new TextDecoder();
|
|
101
|
-
let buffer = "";
|
|
102
54
|
let completed = false;
|
|
103
|
-
const delimiter = /(?:\r\n|\r(?!\n)|\n)(?:\r\n|\r(?!\n)|\n)/g;
|
|
104
|
-
let scanOffset = 0;
|
|
105
55
|
try {
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
scanOffset = Math.max(0, buffer.length - 3);
|
|
56
|
+
for await (const { frame, terminated } of iterateSseFrames(async () => {
|
|
57
|
+
const chunk = await (signal ? racePromiseWithAbortSignal(() => reader.read().catch((error) => {
|
|
58
|
+
throw toErrorObject(error, "Non-Error rejection");
|
|
59
|
+
}), signal, (abortedSignal) => {
|
|
60
|
+
const reason = abortedSignal.reason;
|
|
61
|
+
if (reason instanceof Error) return reason;
|
|
62
|
+
return createAbortError("Request was aborted", reason === void 0 ? void 0 : { cause: reason });
|
|
63
|
+
}) : reader.read());
|
|
64
|
+
completed = chunk.done;
|
|
65
|
+
return chunk;
|
|
66
|
+
}, {
|
|
67
|
+
max: ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS,
|
|
68
|
+
unit: "characters",
|
|
69
|
+
message: `Anthropic Messages SSE response exceeded max pending buffer size (${ANTHROPIC_MESSAGES_SSE_PENDING_BUFFER_MAX_CHARS} chars) without event boundary`
|
|
70
|
+
})) {
|
|
71
|
+
const data = (terminated ? frame : frame.trim()).split(/\r\n|\n|\r/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart()).join("\n");
|
|
72
|
+
if (data && data !== "[DONE]") yield parseAnthropicSseEventData(data);
|
|
124
73
|
}
|
|
125
74
|
} finally {
|
|
126
75
|
if (!completed) {
|
|
@@ -133,12 +82,7 @@ async function* parseAnthropicSseBody(body, signal) {
|
|
|
133
82
|
}
|
|
134
83
|
async function readAnthropicMessagesErrorBody(response) {
|
|
135
84
|
try {
|
|
136
|
-
const text = await
|
|
137
|
-
maxBytes: ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES,
|
|
138
|
-
maxChars: ANTHROPIC_MESSAGES_ERROR_BODY_MAX_BYTES,
|
|
139
|
-
chunkTimeoutMs: ANTHROPIC_MESSAGES_ERROR_BODY_READ_IDLE_TIMEOUT_MS,
|
|
140
|
-
onIdleTimeout: ({ chunkTimeoutMs }) => /* @__PURE__ */ new Error(`Anthropic Messages error response stalled: no data received for ${chunkTimeoutMs}ms`)
|
|
141
|
-
}) ?? "";
|
|
85
|
+
const text = await readAnthropicMessagesErrorSnippet(response) ?? "";
|
|
142
86
|
try {
|
|
143
87
|
return JSON.parse(text);
|
|
144
88
|
} catch {
|
|
@@ -150,146 +94,98 @@ async function readAnthropicMessagesErrorBody(response) {
|
|
|
150
94
|
return "";
|
|
151
95
|
}
|
|
152
96
|
}
|
|
153
|
-
function createAnthropicTransportClient(params) {
|
|
154
|
-
const { model, context, apiKey, options } = params;
|
|
155
|
-
const optionHeaders = resolveOpencodeSessionHeaders(model, options);
|
|
156
|
-
const needsInterleavedBeta = (options?.interleavedThinking ?? true) && !supportsClaudeAdaptiveThinking(model);
|
|
157
|
-
const fetch = isKimiAnthropicProvider(model.provider) && options?.thinkingEnabled === true ? buildGuardedModelFetch(model, void 0, { sanitizeSse: false }) : buildGuardedModelFetch(model);
|
|
158
|
-
const copilot = model.provider === "github-copilot";
|
|
159
|
-
const bearerAuth = copilot || usesFoundryBearerAuth(resolveModelHeaderSentinels(model));
|
|
160
|
-
const isOAuthToken = !bearerAuth && isAnthropicOAuthApiKey(apiKey);
|
|
161
|
-
let defaultHeaders;
|
|
162
|
-
let claudeCodeVersion;
|
|
163
|
-
let directApiKeyBetaHeader;
|
|
164
|
-
if (bearerAuth) defaultHeaders = mergeTransportHeaders({
|
|
165
|
-
accept: "application/json",
|
|
166
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
167
|
-
...needsInterleavedBeta ? { "anthropic-beta": "interleaved-thinking-2025-05-14" } : {}
|
|
168
|
-
}, copilot ? model.headers : omitFoundryBearerCredentialHeaders(model.headers), copilot ? getAiTransportHost().buildCopilotDynamicHeaders(context.messages) : void 0, optionHeaders);
|
|
169
|
-
else {
|
|
170
|
-
const betaFeatures = ["fine-grained-tool-streaming-2025-05-14"];
|
|
171
|
-
if (needsInterleavedBeta) betaFeatures.push("interleaved-thinking-2025-05-14");
|
|
172
|
-
const betaHeader = buildAnthropicBetaHeader(model, betaFeatures, { oauth: isOAuthToken });
|
|
173
|
-
if (isOAuthToken) {
|
|
174
|
-
const identity = buildAnthropicClaudeCodeIdentity(betaHeader, model.headers, optionHeaders);
|
|
175
|
-
defaultHeaders = identity.headers;
|
|
176
|
-
claudeCodeVersion = identity.version;
|
|
177
|
-
} else {
|
|
178
|
-
defaultHeaders = mergeTransportHeaders({
|
|
179
|
-
accept: "application/json",
|
|
180
|
-
"anthropic-dangerous-direct-browser-access": "true",
|
|
181
|
-
...betaHeader ? { "anthropic-beta": betaHeader } : {},
|
|
182
|
-
...options?.sessionId && options.cacheRetention !== "none" && model.compat?.sendSessionAffinityHeaders === true ? { "x-session-affinity": options.sessionId } : {}
|
|
183
|
-
}, model.headers, optionHeaders, getAiTransportHost().resolveProviderRequestHeaders({
|
|
184
|
-
provider: model.provider,
|
|
185
|
-
api: model.api,
|
|
186
|
-
baseUrl: model.baseUrl,
|
|
187
|
-
model
|
|
188
|
-
}));
|
|
189
|
-
directApiKeyBetaHeader = isDirectAnthropicModel(model) ? new Headers(defaultHeaders).get("anthropic-beta") ?? "" : void 0;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const url = resolveAnthropicMessagesUrl(model.baseUrl);
|
|
193
|
-
return {
|
|
194
|
-
isOAuthToken,
|
|
195
|
-
claudeCodeVersion,
|
|
196
|
-
directApiKeyBetaHeader,
|
|
197
|
-
async request(body, requestOptions) {
|
|
198
|
-
const headers = new Headers(mergeTransportHeaders({
|
|
199
|
-
"content-type": "application/json",
|
|
200
|
-
"anthropic-version": "2023-06-01",
|
|
201
|
-
...bearerAuth || isOAuthToken ? { authorization: `Bearer ${apiKey}` } : { "x-api-key": apiKey }
|
|
202
|
-
}, defaultHeaders));
|
|
203
|
-
for (const [name, value] of Object.entries(requestOptions?.headers ?? {})) headers.set(name, value);
|
|
204
|
-
const response = await fetch(url, {
|
|
205
|
-
method: "POST",
|
|
206
|
-
headers,
|
|
207
|
-
body: JSON.stringify(body),
|
|
208
|
-
signal: requestOptions?.signal
|
|
209
|
-
});
|
|
210
|
-
return {
|
|
211
|
-
response,
|
|
212
|
-
stream: response.body ? parseAnthropicSseBody(response.body, requestOptions?.signal) : []
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
97
|
/** Create the stream function used by Anthropic Messages transport models. */
|
|
218
98
|
function createAnthropicMessagesTransportStreamFn() {
|
|
219
99
|
return (rawModel, context, rawOptions) => {
|
|
220
100
|
const model = withEffectiveAnthropicBaseUrl(rawModel);
|
|
221
101
|
const options = rawOptions;
|
|
222
102
|
const { eventStream, stream } = createWritableTransportEventStream();
|
|
223
|
-
(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
103
|
+
runAnthropicStreamLifecycle({
|
|
104
|
+
model,
|
|
105
|
+
stream,
|
|
106
|
+
options,
|
|
107
|
+
profile: "transport",
|
|
108
|
+
prepare: () => {
|
|
228
109
|
const apiKey = options?.apiKey ?? getEnvApiKey(model.provider) ?? "";
|
|
229
110
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
230
111
|
const transportOptions = resolveAnthropicTransportOptions(model, options, apiKey);
|
|
231
112
|
const requestContext = prepareClaudeNoPrefillRequestContext(model, context);
|
|
232
|
-
const
|
|
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
|
-
|
|
259
|
-
|
|
113
|
+
const optionHeaders = resolveOpencodeSessionHeaders(model, transportOptions);
|
|
114
|
+
const needsInterleavedBeta = (transportOptions.interleavedThinking ?? true) && !supportsClaudeAdaptiveThinking(model);
|
|
115
|
+
const fetch = withModelRequestBodyBytes(options, /^kimi(?:-|$)/.test(normalizeLowercaseStringOrEmpty(model.provider ?? "")) && transportOptions.thinkingEnabled === true ? buildGuardedModelFetch(model, void 0, { sanitizeSse: false }) : buildGuardedModelFetch(model));
|
|
116
|
+
const copilot = model.provider === "github-copilot";
|
|
117
|
+
const bearerAuth = copilot || usesFoundryBearerAuth(resolveModelHeaderSentinels(model));
|
|
118
|
+
const isOAuthToken = !bearerAuth && isAnthropicOAuthApiKey(apiKey);
|
|
119
|
+
let defaultHeaders;
|
|
120
|
+
let claudeCodeVersion;
|
|
121
|
+
let directApiKeyBetaHeader;
|
|
122
|
+
if (bearerAuth) defaultHeaders = mergeTransportHeaders({
|
|
123
|
+
accept: "application/json",
|
|
124
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
125
|
+
...needsInterleavedBeta ? { "anthropic-beta": "interleaved-thinking-2025-05-14" } : {}
|
|
126
|
+
}, copilot ? model.headers : omitFoundryBearerCredentialHeaders(model.headers), copilot ? getAiTransportHost().buildCopilotDynamicHeaders(requestContext.messages) : void 0, optionHeaders);
|
|
127
|
+
else {
|
|
128
|
+
const betaFeatures = ["fine-grained-tool-streaming-2025-05-14"];
|
|
129
|
+
if (needsInterleavedBeta) betaFeatures.push("interleaved-thinking-2025-05-14");
|
|
130
|
+
const betaHeader = !isDirectAnthropicModel(model) ? void 0 : isOAuthToken ? `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}` : betaFeatures.join(",");
|
|
131
|
+
if (isOAuthToken) {
|
|
132
|
+
const identity = buildAnthropicClaudeCodeIdentity(betaHeader, model.headers, optionHeaders);
|
|
133
|
+
defaultHeaders = identity.headers;
|
|
134
|
+
claudeCodeVersion = identity.version;
|
|
135
|
+
} else {
|
|
136
|
+
defaultHeaders = mergeTransportHeaders({
|
|
137
|
+
accept: "application/json",
|
|
138
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
139
|
+
...betaHeader ? { "anthropic-beta": betaHeader } : {},
|
|
140
|
+
...transportOptions.sessionId && transportOptions.cacheRetention !== "none" && model.compat?.sendSessionAffinityHeaders === true ? { "x-session-affinity": transportOptions.sessionId } : {}
|
|
141
|
+
}, model.headers, optionHeaders, getAiTransportHost().resolveProviderRequestHeaders({
|
|
142
|
+
provider: model.provider,
|
|
143
|
+
api: model.api,
|
|
144
|
+
baseUrl: model.baseUrl,
|
|
145
|
+
model
|
|
146
|
+
}));
|
|
147
|
+
directApiKeyBetaHeader = isDirectAnthropicModel(model) ? new Headers(omitNullRequestHeaders(defaultHeaders)).get("anthropic-beta") ?? "" : void 0;
|
|
148
|
+
}
|
|
260
149
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
150
|
+
const url = resolveAnthropicMessagesUrl(model.baseUrl);
|
|
151
|
+
return {
|
|
152
|
+
context: requestContext,
|
|
264
153
|
options: transportOptions,
|
|
265
|
-
output,
|
|
266
|
-
stream,
|
|
267
|
-
refusalBuffer,
|
|
268
154
|
isOAuthToken,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
155
|
+
serverSideFallback: !isOAuthToken && supportsAnthropicServerSideFallback(model),
|
|
156
|
+
claudeCodeVersion,
|
|
157
|
+
directApiKeyBetaHeader,
|
|
158
|
+
request: async (_body, requestHeaders, encodeBody) => {
|
|
159
|
+
const headers = new Headers(omitNullRequestHeaders(mergeTransportHeaders({
|
|
160
|
+
"content-type": "application/json",
|
|
161
|
+
"anthropic-version": "2023-06-01",
|
|
162
|
+
...bearerAuth || isOAuthToken ? { authorization: `Bearer ${apiKey}` } : { "x-api-key": apiKey }
|
|
163
|
+
}, defaultHeaders)));
|
|
164
|
+
for (const [name, value] of Object.entries(requestHeaders ?? {})) headers.set(name, value);
|
|
165
|
+
const response = await fetch(url, {
|
|
166
|
+
method: "POST",
|
|
167
|
+
headers,
|
|
168
|
+
body: encodeBody(),
|
|
169
|
+
signal: transportOptions.signal
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
response,
|
|
173
|
+
events: response.body ? parseAnthropicSseBody(response.body, transportOptions.signal) : []
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
checkResponse: async (response) => {
|
|
177
|
+
if (!response.ok) {
|
|
178
|
+
const errorBody = await readAnthropicMessagesErrorBody(response);
|
|
179
|
+
throw Object.assign(/* @__PURE__ */ new Error(`${response.status} status code (no body)`), {
|
|
180
|
+
status: response.status,
|
|
181
|
+
headers: response.headers,
|
|
182
|
+
errorBody
|
|
183
|
+
});
|
|
184
|
+
}
|
|
289
185
|
}
|
|
290
|
-
}
|
|
186
|
+
};
|
|
291
187
|
}
|
|
292
|
-
})
|
|
188
|
+
});
|
|
293
189
|
return eventStream;
|
|
294
190
|
};
|
|
295
191
|
}
|
|
@@ -533,6 +429,45 @@ function prepareTransportAwareSimpleModel(model, ctx) {
|
|
|
533
429
|
});
|
|
534
430
|
}
|
|
535
431
|
//#endregion
|
|
432
|
+
//#region packages/ai/src/transports/provider-wait.ts
|
|
433
|
+
/** A provider-owned wait lasts only until its first response event or settlement. */
|
|
434
|
+
function createProviderWaitObserver(options) {
|
|
435
|
+
let timer;
|
|
436
|
+
let started = false;
|
|
437
|
+
let stopped = false;
|
|
438
|
+
let shown;
|
|
439
|
+
const signal = options?.signal;
|
|
440
|
+
const notify = options?.onProviderWait;
|
|
441
|
+
const report = (reason) => {
|
|
442
|
+
if (!started || stopped || !notify || shown === reason) return;
|
|
443
|
+
shown = reason;
|
|
444
|
+
notify(reason);
|
|
445
|
+
};
|
|
446
|
+
const stop = () => {
|
|
447
|
+
if (stopped) return;
|
|
448
|
+
stopped = true;
|
|
449
|
+
clearTimeout(timer);
|
|
450
|
+
signal?.removeEventListener("abort", stop);
|
|
451
|
+
if (shown) {
|
|
452
|
+
shown = void 0;
|
|
453
|
+
notify?.(null);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
return {
|
|
457
|
+
start() {
|
|
458
|
+
if (started || stopped || !notify || signal?.aborted) return;
|
|
459
|
+
started = true;
|
|
460
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
461
|
+
timer = setTimeout(() => {
|
|
462
|
+
if (!shown) report("response");
|
|
463
|
+
}, 1e3);
|
|
464
|
+
timer.unref?.();
|
|
465
|
+
},
|
|
466
|
+
report,
|
|
467
|
+
stop
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
//#endregion
|
|
536
471
|
//#region packages/ai/src/transports/simple-completion-transport.ts
|
|
537
472
|
/** Standalone completions have no durable session, but may require routing identity. */
|
|
538
473
|
function prepareHeadersForSimpleCompletion(model, options) {
|
|
@@ -583,17 +518,6 @@ function normalizeCodexResponsesBaseUrlForOpenAISdk(baseUrl) {
|
|
|
583
518
|
if (customPath.endsWith("/codex/responses")) return customPath.slice(0, -10);
|
|
584
519
|
return customPath.endsWith("/codex") ? customPath : `${customPath}/codex`;
|
|
585
520
|
}
|
|
586
|
-
function resolveProviderSimpleCompletionApi(model, auth, agentId) {
|
|
587
|
-
const parts = [
|
|
588
|
-
model.provider,
|
|
589
|
-
model.id,
|
|
590
|
-
model.api,
|
|
591
|
-
model.baseUrl || "default"
|
|
592
|
-
];
|
|
593
|
-
if (auth) parts.push(auth.mode, auth.authFlow ?? "");
|
|
594
|
-
if (agentId) parts.push("agent", agentId);
|
|
595
|
-
return `${PROVIDER_SIMPLE_COMPLETION_API_PREFIX}${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
596
|
-
}
|
|
597
521
|
function resolveProviderStreamApi(model) {
|
|
598
522
|
const parts = [
|
|
599
523
|
model.provider,
|
|
@@ -603,40 +527,6 @@ function resolveProviderStreamApi(model) {
|
|
|
603
527
|
];
|
|
604
528
|
return `${PROVIDER_STREAM_API_PREFIX}${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
605
529
|
}
|
|
606
|
-
function applyProviderSimpleCompletionWrapper(registry, model, cfg, hookSourceApi, auth, agentId) {
|
|
607
|
-
if (model.api.startsWith(PROVIDER_SIMPLE_COMPLETION_API_PREFIX)) return model;
|
|
608
|
-
const sourceProvider = registry.getApiProvider(model.api);
|
|
609
|
-
if (!sourceProvider) return model;
|
|
610
|
-
const dispatchApi = model.api;
|
|
611
|
-
const sourceStreamFn = (runtimeModel, context, options) => sourceProvider.streamSimple(projectModel(runtimeModel, { api: dispatchApi }), context, options);
|
|
612
|
-
const streamFn = getAiTransportHost().plugin.wrapSimpleCompletionStream({
|
|
613
|
-
provider: model.provider,
|
|
614
|
-
config: cfg,
|
|
615
|
-
context: {
|
|
616
|
-
config: cfg,
|
|
617
|
-
provider: model.provider,
|
|
618
|
-
modelId: model.id,
|
|
619
|
-
model,
|
|
620
|
-
sourceApi: hookSourceApi,
|
|
621
|
-
auth,
|
|
622
|
-
agentId,
|
|
623
|
-
streamFn: sourceStreamFn
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
if (!streamFn) return model;
|
|
627
|
-
const registeredStreamFn = (runtimeModel, context, options) => streamFn(projectModel(runtimeModel, { api: hookSourceApi }), context, options);
|
|
628
|
-
const api = resolveProviderSimpleCompletionApi(model, auth, agentId);
|
|
629
|
-
return registerCustomApi(registry, api, registeredStreamFn) ? projectModel(model, { api }) : model;
|
|
630
|
-
}
|
|
631
|
-
function prepareCodexSimpleTransportModel(registry, model, cfg) {
|
|
632
|
-
if (model.provider !== "openai" || model.api !== "openai-chatgpt-responses") return;
|
|
633
|
-
const transportModel = projectModel(model, { baseUrl: normalizeCodexResponsesBaseUrlForOpenAISdk(model.baseUrl) });
|
|
634
|
-
const api = resolveTransportAwareSimpleApi(model.api);
|
|
635
|
-
const streamFn = createSupportedTransportStreamFn(transportModel, { cfg });
|
|
636
|
-
if (!api || !streamFn) return;
|
|
637
|
-
if (!registerCustomApi(registry, api, streamFn)) return;
|
|
638
|
-
return projectModel(transportModel, { api });
|
|
639
|
-
}
|
|
640
530
|
function resolveModelTransportSentinels(model, boundary) {
|
|
641
531
|
const host = getAiTransportHost();
|
|
642
532
|
if (host.unwrapModelTransportSentinels) return host.unwrapModelTransportSentinels(model, boundary);
|
|
@@ -655,42 +545,71 @@ function wrapPluginProviderStream(streamFn) {
|
|
|
655
545
|
});
|
|
656
546
|
};
|
|
657
547
|
}
|
|
658
|
-
function
|
|
659
|
-
const
|
|
548
|
+
function prepareModelForSimpleCompletion(params) {
|
|
549
|
+
const { apiRegistry, model, cfg, auth, agentId } = params;
|
|
550
|
+
const wrap = (prepared) => {
|
|
551
|
+
const hookSourceApi = model.api;
|
|
552
|
+
if (prepared.api.startsWith(PROVIDER_SIMPLE_COMPLETION_API_PREFIX)) return prepared;
|
|
553
|
+
const sourceProvider = apiRegistry.getApiProvider(prepared.api);
|
|
554
|
+
if (!sourceProvider) return prepared;
|
|
555
|
+
const dispatchApi = prepared.api;
|
|
556
|
+
const sourceStreamFn = (runtimeModel, context, options) => sourceProvider.streamSimple(projectModel(runtimeModel, { api: dispatchApi }), context, options);
|
|
557
|
+
const streamFn = getAiTransportHost().plugin.wrapSimpleCompletionStream({
|
|
558
|
+
provider: prepared.provider,
|
|
559
|
+
config: cfg,
|
|
560
|
+
context: {
|
|
561
|
+
config: cfg,
|
|
562
|
+
provider: prepared.provider,
|
|
563
|
+
modelId: prepared.id,
|
|
564
|
+
model: prepared,
|
|
565
|
+
sourceApi: hookSourceApi,
|
|
566
|
+
auth,
|
|
567
|
+
agentId,
|
|
568
|
+
streamFn: sourceStreamFn
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
if (!streamFn) return prepared;
|
|
572
|
+
const registeredStreamFn = (runtimeModel, context, options) => streamFn(projectModel(runtimeModel, { api: hookSourceApi }), context, options);
|
|
573
|
+
const parts = [
|
|
574
|
+
prepared.provider,
|
|
575
|
+
prepared.id,
|
|
576
|
+
prepared.api,
|
|
577
|
+
prepared.baseUrl || "default"
|
|
578
|
+
];
|
|
579
|
+
if (auth) parts.push(auth.mode, auth.authFlow ?? "");
|
|
580
|
+
if (agentId) parts.push("agent", agentId);
|
|
581
|
+
const api = `${PROVIDER_SIMPLE_COMPLETION_API_PREFIX}${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
582
|
+
return registerCustomApi(apiRegistry, api, registeredStreamFn) ? projectModel(prepared, { api }) : prepared;
|
|
583
|
+
};
|
|
584
|
+
const pluginModel = resolveModelTransportSentinels(model, "plugin simple-completion stream construction");
|
|
660
585
|
const providerStreamFn = getAiTransportHost().plugin.resolveProviderStream({
|
|
661
|
-
provider:
|
|
662
|
-
config:
|
|
586
|
+
provider: model.provider,
|
|
587
|
+
config: cfg,
|
|
663
588
|
context: {
|
|
664
|
-
config:
|
|
665
|
-
provider:
|
|
666
|
-
modelId:
|
|
589
|
+
config: cfg,
|
|
590
|
+
provider: model.provider,
|
|
591
|
+
modelId: model.id,
|
|
667
592
|
model: pluginModel
|
|
668
593
|
}
|
|
669
594
|
});
|
|
670
|
-
const transportFallback = providerStreamFn ? void 0 : createTransportAwareStreamFnForModel(
|
|
671
|
-
const streamFn = providerStreamFn ? wrapPluginProviderStream(providerStreamFn) : transportFallback &&
|
|
672
|
-
if (
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
cfg,
|
|
685
|
-
apiRegistry
|
|
686
|
-
});
|
|
687
|
-
if (providerStreamModel) return wrap(providerStreamModel);
|
|
688
|
-
const codexTransportModel = prepareCodexSimpleTransportModel(apiRegistry, model, cfg);
|
|
689
|
-
if (codexTransportModel) return wrap(codexTransportModel);
|
|
595
|
+
const transportFallback = providerStreamFn ? void 0 : createTransportAwareStreamFnForModel(model.api === "google-generative-ai" ? pluginModel : model, { cfg });
|
|
596
|
+
const streamFn = providerStreamFn ? wrapPluginProviderStream(providerStreamFn) : transportFallback && model.api === "google-generative-ai" ? wrapPluginProviderStream(transportFallback) : transportFallback;
|
|
597
|
+
if (streamFn) {
|
|
598
|
+
const api = apiRegistry.getApiProvider(model.api) ? resolveProviderStreamApi(model) : model.api;
|
|
599
|
+
const sourceApi = model.api;
|
|
600
|
+
const sourceStreamFn = (runtimeModel, context, options) => streamFn(projectModel(runtimeModel, { api: sourceApi }), context, options);
|
|
601
|
+
if (registerCustomApi(apiRegistry, api, sourceStreamFn)) return wrap(api === model.api ? model : projectModel(model, { api }));
|
|
602
|
+
}
|
|
603
|
+
if (model.provider === "openai" && model.api === "openai-chatgpt-responses") {
|
|
604
|
+
const transportModel = projectModel(model, { baseUrl: normalizeCodexResponsesBaseUrlForOpenAISdk(model.baseUrl) });
|
|
605
|
+
const api = resolveTransportAwareSimpleApi(model.api);
|
|
606
|
+
const codexStreamFn = createSupportedTransportStreamFn(transportModel, { cfg });
|
|
607
|
+
if (api && codexStreamFn && registerCustomApi(apiRegistry, api, codexStreamFn)) return wrap(projectModel(transportModel, { api }));
|
|
608
|
+
}
|
|
690
609
|
const transportAwareModel = prepareTransportAwareSimpleModel(model, { cfg });
|
|
691
610
|
if (transportAwareModel !== model) {
|
|
692
|
-
const
|
|
693
|
-
if (
|
|
611
|
+
const transportStreamFn = createTransportAwareStreamFnForModel(model, { cfg });
|
|
612
|
+
if (transportStreamFn && registerCustomApi(apiRegistry, transportAwareModel.api, transportStreamFn)) return wrap(transportAwareModel);
|
|
694
613
|
}
|
|
695
614
|
if (model.provider === "anthropic-vertex") {
|
|
696
615
|
const api = resolveAnthropicVertexSimpleApi(model.baseUrl);
|
|
@@ -699,4 +618,4 @@ function prepareModelForSimpleCompletion(params) {
|
|
|
699
618
|
return wrap(model);
|
|
700
619
|
}
|
|
701
620
|
//#endregion
|
|
702
|
-
export { CompactionReplayRefreshRequiredError, GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, GOOGLE_VIDEO_SLOT_OMISSION, 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, createGoogleVideoPlaceholder,
|
|
621
|
+
export { CompactionReplayRefreshRequiredError, GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP, GOOGLE_VIDEO_SLOT_OMISSION, 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, createGoogleVideoPlaceholder, 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, materializeGoogleVideoSlots, 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 };
|