@opencode/ai 2.1.4 → 2.2.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 +339 -166
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +4 -0
- package/dist/cache-policy.js +20 -6
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +472 -0
- package/dist/decision.js +158 -0
- package/dist/effect.d.ts +38 -0
- package/dist/effect.js +27 -0
- package/dist/effort-updates.d.ts +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
- package/dist/experimental/cloudflare-run-extraction.js +83 -0
- package/dist/experimental/extraction.d.ts +183 -0
- package/dist/experimental/extraction.js +102 -0
- package/dist/experimental/realtime.d.ts +7 -2
- package/dist/experimental/realtime.js +5 -5
- package/dist/experimental.d.ts +2 -3
- package/dist/experimental.js +1 -2
- package/dist/image-client.d.ts +50 -14
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +6 -176
- package/dist/image.js +4 -11
- package/dist/index.d.ts +1444 -34
- package/dist/index.js +139 -24
- package/dist/llm.d.ts +16 -1
- package/dist/llm.js +34 -0
- package/dist/media-client.d.ts +3 -1
- package/dist/media-client.js +1 -0
- package/dist/media-model.d.ts +3 -0
- package/dist/media-model.js +4 -1
- package/dist/media.d.ts +0 -7
- package/dist/media.js +0 -6
- package/dist/protocols/alibaba-chat.d.ts +59 -4
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +52 -17
- package/dist/protocols/alibaba-responses.d.ts +26 -6
- package/dist/protocols/anthropic-messages.d.ts +160 -54
- package/dist/protocols/anthropic-messages.js +44 -13
- package/dist/protocols/bedrock-converse.d.ts +110 -15
- package/dist/protocols/bedrock-converse.js +112 -15
- package/dist/protocols/bedrock-event-stream.js +1 -0
- package/dist/protocols/cartesia-speech.d.ts +0 -18
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
- package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
- package/dist/protocols/deepgram-speech.d.ts +0 -18
- package/dist/protocols/elevenlabs-speech.d.ts +0 -18
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +11 -6
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +10 -37
- package/dist/protocols/google-interactions.d.ts +4 -0
- package/dist/protocols/google-interactions.js +12 -5
- package/dist/protocols/google-speech.d.ts +0 -18
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +0 -18
- package/dist/protocols/google-transcription.js +0 -1
- package/dist/protocols/google-video.d.ts +1 -1
- package/dist/protocols/google-video.js +2 -7
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +7 -1
- package/dist/protocols/meta-images.js +10 -8
- package/dist/protocols/meta-messages.d.ts +52 -17
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +46 -6
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/open-responses.d.ts +212 -27
- package/dist/protocols/open-responses.js +116 -54
- package/dist/protocols/openai-chat.d.ts +1135 -31
- package/dist/protocols/openai-chat.js +155 -60
- package/dist/protocols/openai-compatible-chat.d.ts +57 -5
- package/dist/protocols/openai-compatible-responses.d.ts +28 -8
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +36 -24
- package/dist/protocols/openai-images.js +137 -39
- package/dist/protocols/openai-responses.d.ts +202 -42
- package/dist/protocols/openai-responses.js +49 -10
- package/dist/protocols/openai-speech.d.ts +0 -18
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +0 -18
- package/dist/protocols/openai-transcription.js +3 -4
- package/dist/protocols/runway-video.d.ts +1 -1
- package/dist/protocols/runway-video.js +1 -1
- package/dist/protocols/shared.d.ts +9 -1
- package/dist/protocols/shared.js +13 -2
- package/dist/protocols/system-one.d.ts +101 -0
- package/dist/protocols/system-one.js +230 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.js +7 -6
- package/dist/protocols/utils/cache.d.ts +14 -3
- package/dist/protocols/utils/cache.js +11 -4
- package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
- package/dist/protocols/utils/gemini-generate-content.js +10 -16
- package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
- package/dist/protocols/utils/gemini-json-schema.js +3 -3
- package/dist/protocols/utils/image-sizing.d.ts +31 -0
- package/dist/protocols/utils/image-sizing.js +73 -0
- package/dist/protocols/utils/media-input.d.ts +4 -5
- package/dist/protocols/utils/media-input.js +8 -5
- package/dist/protocols/utils/speech-stream.d.ts +0 -1
- package/dist/protocols/utils/speech-stream.js +0 -1
- package/dist/protocols/utils/tool-schema.js +15 -5
- package/dist/protocols/utils/tool-stream.d.ts +9 -0
- package/dist/protocols/venice-chat.d.ts +58 -4
- package/dist/protocols/venice-chat.js +2 -2
- package/dist/protocols/xai-images.d.ts +7 -2
- package/dist/protocols/xai-images.js +11 -5
- package/dist/protocols/xai-responses.d.ts +30 -3
- package/dist/protocols/xai-responses.js +30 -3
- package/dist/protocols/xai-video.d.ts +1 -1
- package/dist/protocols/xai-video.js +11 -8
- package/dist/protocols/zai-chat.d.ts +60 -4
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +52 -17
- package/dist/provider-error.js +23 -7
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +137 -28
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +259 -145
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +34 -14
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +53 -18
- package/dist/providers/anthropic.d.ts +53 -18
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +129 -24
- package/dist/providers/azure.js +19 -1
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +124 -12
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +115 -11
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +290 -60
- package/dist/providers/cloudflare-ai-gateway.js +32 -4
- package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
- package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/images.js +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +128 -12
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +115 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +115 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +115 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.js +1 -0
- package/dist/providers/digitalocean/images.d.ts +2 -0
- package/dist/providers/digitalocean/images.js +1 -0
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +390 -20
- package/dist/providers/digitalocean.js +53 -11
- package/dist/providers/fireworks.d.ts +115 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +57 -5
- package/dist/providers/google-vertex-chat.js +1 -1
- package/dist/providers/google-vertex-interactions.d.ts +1 -1
- package/dist/providers/google-vertex-interactions.js +1 -1
- package/dist/providers/google-vertex-messages.d.ts +53 -18
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-mistral.d.ts +1 -1
- package/dist/providers/google-vertex-mistral.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +24 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +4 -2
- package/dist/providers/google-vertex.js +30 -13
- package/dist/providers/google.d.ts +6 -5
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +119 -15
- package/dist/providers/groq.js +1 -7
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/index.js +0 -4
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta.d.ts +254 -146
- package/dist/providers/meta.js +2 -1
- package/dist/providers/minimax/chat.d.ts +1 -1
- package/dist/providers/minimax/chat.js +1 -1
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/responses.d.ts +1 -1
- package/dist/providers/minimax/responses.js +1 -1
- package/dist/providers/minimax.d.ts +139 -26
- package/dist/providers/minimax.js +22 -9
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/moonshot/messages.d.ts +1 -1
- package/dist/providers/moonshot/messages.js +1 -1
- package/dist/providers/moonshot/responses.d.ts +1 -1
- package/dist/providers/moonshot/responses.js +1 -1
- package/dist/providers/moonshot.d.ts +132 -25
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.js +1 -0
- package/dist/providers/openai-compatible/images.d.ts +2 -0
- package/dist/providers/openai-compatible/images.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +24 -4
- package/dist/providers/openai-compatible.d.ts +62 -8
- package/dist/providers/openai-compatible.js +29 -10
- package/dist/providers/openai-options.d.ts +3 -1
- package/dist/providers/openai.d.ts +103 -18
- package/dist/providers/openai.js +23 -5
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +11 -12
- package/dist/providers/opencode.js +10 -8
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.js +1 -0
- package/dist/providers/openrouter/images.d.ts +2 -0
- package/dist/providers/openrouter/images.js +1 -0
- package/dist/providers/openrouter/responses.d.ts +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +446 -35
- package/dist/providers/openrouter.js +78 -27
- package/dist/providers/togetherai.d.ts +115 -11
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
- package/dist/providers/typesafe-ai/decisions.js +1 -0
- package/dist/providers/typesafe-ai.d.ts +11 -12
- package/dist/providers/typesafe-ai.js +10 -8
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +261 -9
- package/dist/providers/venice.js +33 -17
- package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
- package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +16 -22
- package/dist/providers/vercel-ai-gateway.js +41 -85
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai.d.ts +66 -12
- package/dist/providers/xai.js +15 -8
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
- package/dist/providers/zai-coding-plan/messages.js +1 -1
- package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
- package/dist/providers/zai-coding-plan/responses.js +1 -1
- package/dist/providers/zai-coding-plan.d.ts +132 -25
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +62 -9
- package/dist/providers/zai.js +15 -8
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/client.d.ts +2 -2
- package/dist/route/client.js +26 -4
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor.d.ts +1 -1
- package/dist/route/framing.d.ts +2 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.js +3 -0
- package/dist/route/media-protocol.d.ts +3 -4
- package/dist/route/media-protocol.js +12 -8
- package/dist/route/media.d.ts +6 -2
- package/dist/route/media.js +8 -6
- package/dist/route/transport/http.js +1 -0
- package/dist/route/transport/index.d.ts +1 -0
- package/dist/schema/events.d.ts +148 -6
- package/dist/schema/events.js +20 -0
- package/dist/schema/messages.d.ts +41 -3
- package/dist/schema/messages.js +23 -0
- package/dist/schema/options.d.ts +5 -3
- package/dist/schema/options.js +8 -3
- package/dist/speech-client.d.ts +53 -14
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +0 -135
- package/dist/speech.js +2 -4
- package/dist/testing/decision.d.ts +16 -0
- package/dist/testing/decision.js +20 -0
- package/dist/testing/image.d.ts +14 -0
- package/dist/testing/image.js +12 -0
- package/dist/testing/media.d.ts +18 -0
- package/dist/testing/media.js +36 -0
- package/dist/testing/script.d.ts +28 -0
- package/dist/testing/script.js +60 -0
- package/dist/testing/speech.d.ts +14 -0
- package/dist/testing/speech.js +12 -0
- package/dist/testing/transcription.d.ts +14 -0
- package/dist/testing/transcription.js +12 -0
- package/dist/testing/video.d.ts +14 -0
- package/dist/testing/video.js +12 -0
- package/dist/testing.d.ts +35 -45
- package/dist/testing.js +14 -75
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +69 -14
- package/dist/transcription.d.ts +0 -135
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +46 -14
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +1 -136
- package/dist/video.js +3 -5
- package/package.json +497 -11
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/system-one.d.ts +0 -16
- package/dist/experimental/system-one.js +0 -135
- package/dist/promise.d.ts +0 -1021
- package/dist/promise.js +0 -101
- package/dist/protocols/bfl-images.d.ts +0 -38
- package/dist/protocols/bfl-images.js +0 -153
- package/dist/protocols/fal-images.d.ts +0 -25
- package/dist/protocols/fal-images.js +0 -104
- package/dist/protocols/fal-video.d.ts +0 -29
- package/dist/protocols/fal-video.js +0 -73
- package/dist/protocols/replicate-images.d.ts +0 -28
- package/dist/protocols/replicate-images.js +0 -127
- package/dist/protocols/stability-images.d.ts +0 -39
- package/dist/protocols/stability-images.js +0 -136
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/provider.d.ts +0 -23
- package/dist/provider.js +0 -2
- package/dist/providers/black-forest-labs.d.ts +0 -21
- package/dist/providers/black-forest-labs.js +0 -23
- package/dist/providers/fal.d.ts +0 -24
- package/dist/providers/fal.js +0 -26
- package/dist/providers/replicate.d.ts +0 -21
- package/dist/providers/replicate.js +0 -17
- package/dist/providers/stability.d.ts +0 -23
- package/dist/providers/stability.js +0 -18
|
@@ -8,7 +8,7 @@ import { Framing } from "../route/framing.js";
|
|
|
8
8
|
import { Protocol } from "../route/protocol.js";
|
|
9
9
|
import { Headers } from "effect/http";
|
|
10
10
|
import { HttpTransport } from "../route/transport/index.js";
|
|
11
|
-
import { AIError, HttpOptions, LLMRequest, LLMEvent, mergeJsonRecords, Usage, } from "../schema/index.js";
|
|
11
|
+
import { AIError, CacheTTL, HttpOptions, LLMRequest, LLMEvent, mergeJsonRecords, Usage, } from "../schema/index.js";
|
|
12
12
|
import { JsonObject, knownString, optionalArray, optionalNull, ProviderShared, withUntypedFrames } from "./shared.js";
|
|
13
13
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
14
14
|
import { effortUpdate, resolveEffortUpdates } from "../effort-updates.js";
|
|
@@ -50,9 +50,10 @@ export const ContextManagement = Schema.Struct({
|
|
|
50
50
|
// =============================================================================
|
|
51
51
|
const AnthropicCacheControl = Schema.Struct({
|
|
52
52
|
type: Schema.tag("ephemeral"),
|
|
53
|
-
ttl: Schema.optional(
|
|
53
|
+
ttl: Schema.optional(CacheTTL),
|
|
54
54
|
});
|
|
55
55
|
const AnthropicServiceTier = knownString();
|
|
56
|
+
const AnthropicSpeed = knownString();
|
|
56
57
|
const AnthropicTextBlock = Schema.Struct({
|
|
57
58
|
type: Schema.tag("text"),
|
|
58
59
|
text: Schema.String,
|
|
@@ -81,6 +82,11 @@ const AnthropicImageBlock = Schema.Struct({
|
|
|
81
82
|
cache_control: Schema.optional(AnthropicCacheControl),
|
|
82
83
|
transformations: Schema.optional(AnthropicImageTransformations),
|
|
83
84
|
});
|
|
85
|
+
const AnthropicVideoBlock = Schema.Struct({
|
|
86
|
+
type: Schema.tag("video"),
|
|
87
|
+
source: AnthropicImageSource,
|
|
88
|
+
cache_control: Schema.optional(AnthropicCacheControl),
|
|
89
|
+
});
|
|
84
90
|
// SDK: Base64PDFSource:209 {type:"base64", media_type:"application/pdf", data}, PlainTextSource:2716 {type:"text", media_type:"text/plain", data},
|
|
85
91
|
// SDK: URLPDFSource:3823 {type:"url", url}, FileDocumentSource:2344 {type:"file", file_id}, ContentBlockSource:2266 {type:"content", content}
|
|
86
92
|
// SDK: DocumentBlockParam:2297 {source: 5-way union, cache_control, citations, context, title}
|
|
@@ -157,7 +163,12 @@ const AnthropicServerToolResultBlock = Schema.Struct({
|
|
|
157
163
|
// Anthropic accepts either a plain string or an ordered array of text, image, and
|
|
158
164
|
// document blocks inside `tool_result.content`. The array form keeps media as native
|
|
159
165
|
// model input instead of JSON-stringifying base64 into prompt text.
|
|
160
|
-
const AnthropicToolResultContent = Schema.Union([
|
|
166
|
+
const AnthropicToolResultContent = Schema.Union([
|
|
167
|
+
AnthropicTextBlock,
|
|
168
|
+
AnthropicImageBlock,
|
|
169
|
+
AnthropicDocumentBlock,
|
|
170
|
+
AnthropicVideoBlock,
|
|
171
|
+
]);
|
|
161
172
|
const AnthropicToolResultBlock = Schema.Struct({
|
|
162
173
|
type: Schema.tag("tool_result"),
|
|
163
174
|
tool_use_id: Schema.String,
|
|
@@ -169,6 +180,7 @@ const AnthropicUserBlock = Schema.Union([
|
|
|
169
180
|
AnthropicTextBlock,
|
|
170
181
|
AnthropicImageBlock,
|
|
171
182
|
AnthropicDocumentBlock,
|
|
183
|
+
AnthropicVideoBlock,
|
|
172
184
|
AnthropicToolResultBlock,
|
|
173
185
|
]);
|
|
174
186
|
const AnthropicCompactionBlock = Schema.Struct({
|
|
@@ -276,6 +288,7 @@ const Options = Schema.Struct({
|
|
|
276
288
|
effort: Schema.optional(Schema.String),
|
|
277
289
|
service_tier: Schema.optional(AnthropicServiceTier),
|
|
278
290
|
serviceTier: Schema.optional(AnthropicServiceTier),
|
|
291
|
+
speed: Schema.optional(AnthropicSpeed),
|
|
279
292
|
metadata: Schema.optional(AnthropicMetadata),
|
|
280
293
|
container: Schema.optional(AnthropicContainer),
|
|
281
294
|
inference_geo: optionalNull(Schema.String),
|
|
@@ -314,6 +327,7 @@ const AnthropicBodyFields = {
|
|
|
314
327
|
inference_geo: Schema.optional(Schema.NullOr(Schema.String)),
|
|
315
328
|
metadata: Schema.optional(AnthropicMetadata),
|
|
316
329
|
service_tier: Schema.optional(AnthropicServiceTier),
|
|
330
|
+
speed: Schema.optional(AnthropicSpeed),
|
|
317
331
|
};
|
|
318
332
|
export const AnthropicMessagesBody = Schema.Struct(AnthropicBodyFields);
|
|
319
333
|
const AnthropicIterationUsage = Schema.StructWithRest(Schema.Struct({
|
|
@@ -385,8 +399,6 @@ const invalid = ProviderShared.invalidRequest;
|
|
|
385
399
|
// 400 — so the lowering layer counts emitted markers and silently drops any
|
|
386
400
|
// that exceed it.
|
|
387
401
|
const ANTHROPIC_BREAKPOINT_CAP = 4;
|
|
388
|
-
const EPHEMERAL_5M = { type: "ephemeral" };
|
|
389
|
-
const EPHEMERAL_1H = { type: "ephemeral", ttl: "1h" };
|
|
390
402
|
const cacheControl = (breakpoints, cache) => {
|
|
391
403
|
if (cache?.type !== "ephemeral" && cache?.type !== "persistent")
|
|
392
404
|
return undefined;
|
|
@@ -395,7 +407,7 @@ const cacheControl = (breakpoints, cache) => {
|
|
|
395
407
|
return undefined;
|
|
396
408
|
}
|
|
397
409
|
breakpoints.remaining -= 1;
|
|
398
|
-
return
|
|
410
|
+
return { type: "ephemeral", ...(cache.ttl === undefined ? {} : { ttl: cache.ttl }) };
|
|
399
411
|
};
|
|
400
412
|
const providerMetadata = (key, metadata) => ({ [key]: metadata });
|
|
401
413
|
const signatureFromMetadata = (metadata, key) => {
|
|
@@ -539,9 +551,22 @@ const citationsFromMetadata = (metadata) => {
|
|
|
539
551
|
return undefined;
|
|
540
552
|
};
|
|
541
553
|
const isHttpUrl = (value) => /^https?:\/\//i.test(value.trim());
|
|
542
|
-
const lowerMedia = Effect.fnUntraced(function* (part, breakpoints) {
|
|
554
|
+
const lowerMedia = Effect.fnUntraced(function* (part, request, breakpoints) {
|
|
543
555
|
const mime = part.media.mediaType.toLowerCase();
|
|
544
556
|
const cacheControlValue = breakpoints ? cacheControl(breakpoints, part.cache) : undefined;
|
|
557
|
+
if (mime.startsWith("video/")) {
|
|
558
|
+
const inline = part.media.inline();
|
|
559
|
+
const source = inline
|
|
560
|
+
? { type: "base64", media_type: mime, data: inline.base64 }
|
|
561
|
+
: yield* ProviderShared.mediaReference(part.media, request.model.provider, "Messages video").pipe(Effect.map((reference) => reference.type === "ref" && !reference.value.includes("://")
|
|
562
|
+
? { type: "file", file_id: reference.value }
|
|
563
|
+
: { type: "url", url: reference.value }));
|
|
564
|
+
return {
|
|
565
|
+
type: "video",
|
|
566
|
+
source,
|
|
567
|
+
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
568
|
+
};
|
|
569
|
+
}
|
|
545
570
|
const fileId = fileIdFromMetadata(part.metadata);
|
|
546
571
|
// SDK file sources: FileImageSource:2350 / FileDocumentSource:2344 {type:"file", file_id}
|
|
547
572
|
if (fileId) {
|
|
@@ -644,19 +669,19 @@ const lowerMedia = Effect.fnUntraced(function* (part, breakpoints) {
|
|
|
644
669
|
});
|
|
645
670
|
// Tool results may carry structured text, images, and documents. Keep media as provider-native
|
|
646
671
|
// content instead of JSON-stringifying base64 into a prompt string.
|
|
647
|
-
const lowerToolResultContentItem = Effect.fnUntraced(function* (item) {
|
|
672
|
+
const lowerToolResultContentItem = Effect.fnUntraced(function* (item, request) {
|
|
648
673
|
if (item.type === "text")
|
|
649
674
|
return { type: "text", text: item.text };
|
|
650
|
-
return yield* lowerMedia(ProviderShared.toolFileMedia(item));
|
|
675
|
+
return yield* lowerMedia(ProviderShared.toolFileMedia(item), request);
|
|
651
676
|
});
|
|
652
|
-
const lowerToolResultContent = Effect.fnUntraced(function* (part) {
|
|
677
|
+
const lowerToolResultContent = Effect.fnUntraced(function* (part, request) {
|
|
653
678
|
// Text / json / error results stay as a string for backward compatibility
|
|
654
679
|
// with existing cassettes and provider expectations.
|
|
655
680
|
if (part.result.type !== "content")
|
|
656
681
|
return ProviderShared.toolResultText(part);
|
|
657
682
|
// Preserve the narrowed array element type when compiled through a consumer package.
|
|
658
683
|
const content = part.result.value;
|
|
659
|
-
return yield* Effect.forEach(content, lowerToolResultContentItem);
|
|
684
|
+
return yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request));
|
|
660
685
|
});
|
|
661
686
|
const requireThinkingSignature = (request) => {
|
|
662
687
|
if (request.model.compatibility?.requireSignature !== undefined)
|
|
@@ -763,7 +788,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
763
788
|
continue;
|
|
764
789
|
}
|
|
765
790
|
if (part.type === "media") {
|
|
766
|
-
content.push(yield* lowerMedia(part, breakpoints));
|
|
791
|
+
content.push(yield* lowerMedia(part, request, breakpoints));
|
|
767
792
|
continue;
|
|
768
793
|
}
|
|
769
794
|
return yield* ProviderShared.unsupportedContent("Anthropic Messages", "user", ["text", "media"]);
|
|
@@ -839,7 +864,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
839
864
|
content.push({
|
|
840
865
|
type: "tool_result",
|
|
841
866
|
tool_use_id: scrubToolCallID(part.id),
|
|
842
|
-
content: yield* lowerToolResultContent(part),
|
|
867
|
+
content: yield* lowerToolResultContent(part, request),
|
|
843
868
|
is_error: part.result.type === "error" ? true : undefined,
|
|
844
869
|
cache_control: cacheControl(breakpoints, part.cache),
|
|
845
870
|
});
|
|
@@ -940,6 +965,7 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
940
965
|
inference_geo: options.inference_geo ?? options.inferenceGeo ?? undefined,
|
|
941
966
|
metadata: options.metadata,
|
|
942
967
|
service_tier: options.service_tier ?? options.serviceTier,
|
|
968
|
+
speed: options.speed,
|
|
943
969
|
};
|
|
944
970
|
if (!management)
|
|
945
971
|
return body;
|
|
@@ -996,6 +1022,7 @@ const mapUsage = (usage, providerMetadataKey) => {
|
|
|
996
1022
|
cacheWriteInputTokens: cacheWrite,
|
|
997
1023
|
reasoningTokens: ProviderShared.sumTokens(...iterations.map((item) => item.output_tokens_details?.thinking_tokens)),
|
|
998
1024
|
totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
|
|
1025
|
+
...ProviderShared.reportedBilling(usage),
|
|
999
1026
|
providerMetadata: { [providerMetadataKey]: usage },
|
|
1000
1027
|
});
|
|
1001
1028
|
};
|
|
@@ -1024,6 +1051,7 @@ const mergeUsage = (left, right, providerMetadataKey) => {
|
|
|
1024
1051
|
cacheWriteInputTokens,
|
|
1025
1052
|
reasoningTokens,
|
|
1026
1053
|
totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
|
|
1054
|
+
cost: right.cost ?? left.cost,
|
|
1027
1055
|
providerMetadata: {
|
|
1028
1056
|
[providerMetadataKey]: mergeJsonRecords(left.providerMetadata?.[providerMetadataKey], right.providerMetadata?.[providerMetadataKey]) ??
|
|
1029
1057
|
{},
|
|
@@ -1431,6 +1459,9 @@ function requiredBetaHeaders(body) {
|
|
|
1431
1459
|
betas.push("compact-2026-01-12");
|
|
1432
1460
|
if (body.messages.some((message) => message.role === "system" && message.output_config !== undefined))
|
|
1433
1461
|
betas.push("mid-conversation-output-config-2026-07-01");
|
|
1462
|
+
// Opus 5.5 accepts `speed` without this header; earlier fast-mode models reject `speed` without it.
|
|
1463
|
+
if (body.speed !== undefined)
|
|
1464
|
+
betas.push("fast-mode-2026-02-01");
|
|
1434
1465
|
const thinking = body.thinking;
|
|
1435
1466
|
if (thinking && !isThinkingOff(thinking) && thinking.block_binding)
|
|
1436
1467
|
betas.push(THINKING_BINDING_BETA);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Route } from "../route/client.js";
|
|
3
3
|
import { Protocol } from "../route/protocol.js";
|
|
4
|
-
import { Usage, type FinishReasonDetails } from "../schema/index.js";
|
|
4
|
+
import { Usage, type FinishReasonDetails, type ProviderOptions } from "../schema/index.js";
|
|
5
5
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
6
6
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
7
7
|
export type { Credentials as BedrockCredentials } from "./utils/bedrock-auth.js";
|
|
@@ -54,7 +54,7 @@ declare const BedrockConverseBody: Schema.Struct<{
|
|
|
54
54
|
}>, Schema.Struct<{
|
|
55
55
|
readonly cachePoint: Schema.Struct<{
|
|
56
56
|
readonly type: Schema.tag<"default">;
|
|
57
|
-
readonly ttl: Schema.optional<Schema.Literals<readonly ["
|
|
57
|
+
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
58
58
|
}>;
|
|
59
59
|
}>]>>;
|
|
60
60
|
}>, Schema.Struct<{
|
|
@@ -79,7 +79,7 @@ declare const BedrockConverseBody: Schema.Struct<{
|
|
|
79
79
|
}>, Schema.Struct<{
|
|
80
80
|
readonly cachePoint: Schema.Struct<{
|
|
81
81
|
readonly type: Schema.tag<"default">;
|
|
82
|
-
readonly ttl: Schema.optional<Schema.Literals<readonly ["
|
|
82
|
+
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
83
83
|
}>;
|
|
84
84
|
}>]>>;
|
|
85
85
|
}>]>>;
|
|
@@ -88,7 +88,7 @@ declare const BedrockConverseBody: Schema.Struct<{
|
|
|
88
88
|
}>, Schema.Struct<{
|
|
89
89
|
readonly cachePoint: Schema.Struct<{
|
|
90
90
|
readonly type: Schema.tag<"default">;
|
|
91
|
-
readonly ttl: Schema.optional<Schema.Literals<readonly ["
|
|
91
|
+
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
92
92
|
}>;
|
|
93
93
|
}>]>>>;
|
|
94
94
|
inferenceConfig: Schema.optional<Schema.Struct<{
|
|
@@ -109,7 +109,7 @@ declare const BedrockConverseBody: Schema.Struct<{
|
|
|
109
109
|
}>, Schema.Struct<{
|
|
110
110
|
readonly cachePoint: Schema.Struct<{
|
|
111
111
|
readonly type: Schema.tag<"default">;
|
|
112
|
-
readonly ttl: Schema.optional<Schema.Literals<readonly ["
|
|
112
|
+
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
113
113
|
}>;
|
|
114
114
|
}>]>>;
|
|
115
115
|
readonly toolChoice: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
@@ -123,15 +123,62 @@ declare const BedrockConverseBody: Schema.Struct<{
|
|
|
123
123
|
}>]>>;
|
|
124
124
|
}>>;
|
|
125
125
|
additionalModelRequestFields: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
126
|
+
serviceTier: Schema.optional<Schema.Struct<{
|
|
127
|
+
readonly type: Schema.declare<import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">, import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">>;
|
|
128
|
+
}>>;
|
|
129
|
+
guardrailConfig: Schema.optional<Schema.Struct<{
|
|
130
|
+
readonly guardrailIdentifier: Schema.String;
|
|
131
|
+
readonly guardrailVersion: Schema.String;
|
|
132
|
+
readonly trace: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full">, import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full">>>;
|
|
133
|
+
readonly streamProcessingMode: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"async" | "sync">, import("../schema/options.js").OpenString<"async" | "sync">>>;
|
|
134
|
+
}>>;
|
|
135
|
+
outputConfig: Schema.optional<Schema.Struct<{
|
|
136
|
+
readonly textFormat: Schema.Struct<{
|
|
137
|
+
readonly type: Schema.declare<import("../schema/options.js").OpenString<"json_schema">, import("../schema/options.js").OpenString<"json_schema">>;
|
|
138
|
+
readonly structure: Schema.Struct<{
|
|
139
|
+
readonly jsonSchema: Schema.Struct<{
|
|
140
|
+
readonly schema: Schema.String;
|
|
141
|
+
readonly name: Schema.optional<Schema.String>;
|
|
142
|
+
readonly description: Schema.optional<Schema.String>;
|
|
143
|
+
}>;
|
|
144
|
+
}>;
|
|
145
|
+
}>;
|
|
146
|
+
}>>;
|
|
147
|
+
requestMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
126
148
|
}>;
|
|
127
149
|
export type BedrockConverseBody = Schema.Schema.Type<typeof BedrockConverseBody>;
|
|
128
150
|
declare const Options: Schema.Struct<{
|
|
129
|
-
|
|
151
|
+
/** Claude thinking. `adaptive` and `disabled` apply to Claude models only. */
|
|
152
|
+
readonly thinking: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
130
153
|
readonly type: Schema.Literal<"enabled">;
|
|
131
154
|
readonly budgetTokens: Schema.Number;
|
|
155
|
+
}>, Schema.Struct<{
|
|
156
|
+
readonly type: Schema.Literal<"adaptive">;
|
|
157
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"omitted" | "summarized">, import("../schema/options.js").OpenString<"omitted" | "summarized">>>;
|
|
158
|
+
}>, Schema.Struct<{
|
|
159
|
+
readonly type: Schema.Literal<"disabled">;
|
|
160
|
+
}>]>>;
|
|
161
|
+
/** Reasoning effort, sent in the field each model family reads. */
|
|
162
|
+
readonly effort: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"high" | "low" | "max" | "medium" | "xhigh">, import("../schema/options.js").OpenString<"high" | "low" | "max" | "medium" | "xhigh">>>;
|
|
163
|
+
readonly serviceTier: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">, import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">>>;
|
|
164
|
+
/** Constrains the response text to a JSON schema. */
|
|
165
|
+
readonly outputFormat: Schema.optional<Schema.Struct<{
|
|
166
|
+
readonly type: Schema.declare<import("../schema/options.js").OpenString<"json_schema">, import("../schema/options.js").OpenString<"json_schema">>;
|
|
167
|
+
readonly schema: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
168
|
+
readonly name: Schema.optional<Schema.String>;
|
|
169
|
+
readonly description: Schema.optional<Schema.String>;
|
|
132
170
|
}>>;
|
|
171
|
+
readonly guardrail: Schema.optional<Schema.Struct<{
|
|
172
|
+
readonly identifier: Schema.String;
|
|
173
|
+
readonly version: Schema.String;
|
|
174
|
+
readonly trace: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full">, import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full">>>;
|
|
175
|
+
readonly streamProcessingMode: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"async" | "sync">, import("../schema/options.js").OpenString<"async" | "sync">>>;
|
|
176
|
+
}>>;
|
|
177
|
+
/** Key-value pairs for filtering invocation logs. */
|
|
178
|
+
readonly requestMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
133
179
|
}>;
|
|
134
|
-
|
|
180
|
+
/** Caller-facing provider options; unknown keys are accepted and ignored. */
|
|
181
|
+
export type OptionsInput = ProviderOptions & typeof Options.Encoded;
|
|
135
182
|
/**
|
|
136
183
|
* The Bedrock Converse protocol — request body construction, body schema, and
|
|
137
184
|
* the streaming-event state machine.
|
|
@@ -143,7 +190,7 @@ export declare const protocol: Protocol<{
|
|
|
143
190
|
readonly content: readonly ({
|
|
144
191
|
readonly cachePoint: {
|
|
145
192
|
readonly type: "default";
|
|
146
|
-
readonly ttl?:
|
|
193
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
147
194
|
};
|
|
148
195
|
} | {
|
|
149
196
|
readonly image: {
|
|
@@ -193,7 +240,7 @@ export declare const protocol: Protocol<{
|
|
|
193
240
|
readonly content: readonly ({
|
|
194
241
|
readonly cachePoint: {
|
|
195
242
|
readonly type: "default";
|
|
196
|
-
readonly ttl?:
|
|
243
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
197
244
|
};
|
|
198
245
|
} | {
|
|
199
246
|
readonly text: string;
|
|
@@ -217,7 +264,7 @@ export declare const protocol: Protocol<{
|
|
|
217
264
|
readonly system?: readonly ({
|
|
218
265
|
readonly cachePoint: {
|
|
219
266
|
readonly type: "default";
|
|
220
|
-
readonly ttl?:
|
|
267
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
221
268
|
};
|
|
222
269
|
} | {
|
|
223
270
|
readonly text: string;
|
|
@@ -232,7 +279,7 @@ export declare const protocol: Protocol<{
|
|
|
232
279
|
readonly tools: readonly ({
|
|
233
280
|
readonly cachePoint: {
|
|
234
281
|
readonly type: "default";
|
|
235
|
-
readonly ttl?:
|
|
282
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
236
283
|
};
|
|
237
284
|
} | {
|
|
238
285
|
readonly toolSpec: {
|
|
@@ -258,6 +305,30 @@ export declare const protocol: Protocol<{
|
|
|
258
305
|
readonly additionalModelRequestFields?: {
|
|
259
306
|
readonly [x: string]: unknown;
|
|
260
307
|
} | undefined;
|
|
308
|
+
readonly serviceTier?: {
|
|
309
|
+
readonly type: import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">;
|
|
310
|
+
} | undefined;
|
|
311
|
+
readonly guardrailConfig?: {
|
|
312
|
+
readonly guardrailIdentifier: string;
|
|
313
|
+
readonly guardrailVersion: string;
|
|
314
|
+
readonly trace?: import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full"> | undefined;
|
|
315
|
+
readonly streamProcessingMode?: import("../schema/options.js").OpenString<"async" | "sync"> | undefined;
|
|
316
|
+
} | undefined;
|
|
317
|
+
readonly outputConfig?: {
|
|
318
|
+
readonly textFormat: {
|
|
319
|
+
readonly type: import("../schema/options.js").OpenString<"json_schema">;
|
|
320
|
+
readonly structure: {
|
|
321
|
+
readonly jsonSchema: {
|
|
322
|
+
readonly schema: string;
|
|
323
|
+
readonly name?: string | undefined;
|
|
324
|
+
readonly description?: string | undefined;
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
} | undefined;
|
|
329
|
+
readonly requestMetadata?: {
|
|
330
|
+
readonly [x: string]: string;
|
|
331
|
+
} | undefined;
|
|
261
332
|
}, {
|
|
262
333
|
readonly [x: string]: unknown;
|
|
263
334
|
readonly rawBody: string;
|
|
@@ -331,7 +402,7 @@ export declare const route: Route<{
|
|
|
331
402
|
readonly content: readonly ({
|
|
332
403
|
readonly cachePoint: {
|
|
333
404
|
readonly type: "default";
|
|
334
|
-
readonly ttl?:
|
|
405
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
335
406
|
};
|
|
336
407
|
} | {
|
|
337
408
|
readonly image: {
|
|
@@ -381,7 +452,7 @@ export declare const route: Route<{
|
|
|
381
452
|
readonly content: readonly ({
|
|
382
453
|
readonly cachePoint: {
|
|
383
454
|
readonly type: "default";
|
|
384
|
-
readonly ttl?:
|
|
455
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
385
456
|
};
|
|
386
457
|
} | {
|
|
387
458
|
readonly text: string;
|
|
@@ -405,7 +476,7 @@ export declare const route: Route<{
|
|
|
405
476
|
readonly system?: readonly ({
|
|
406
477
|
readonly cachePoint: {
|
|
407
478
|
readonly type: "default";
|
|
408
|
-
readonly ttl?:
|
|
479
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
409
480
|
};
|
|
410
481
|
} | {
|
|
411
482
|
readonly text: string;
|
|
@@ -420,7 +491,7 @@ export declare const route: Route<{
|
|
|
420
491
|
readonly tools: readonly ({
|
|
421
492
|
readonly cachePoint: {
|
|
422
493
|
readonly type: "default";
|
|
423
|
-
readonly ttl?:
|
|
494
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
424
495
|
};
|
|
425
496
|
} | {
|
|
426
497
|
readonly toolSpec: {
|
|
@@ -446,6 +517,30 @@ export declare const route: Route<{
|
|
|
446
517
|
readonly additionalModelRequestFields?: {
|
|
447
518
|
readonly [x: string]: unknown;
|
|
448
519
|
} | undefined;
|
|
520
|
+
readonly serviceTier?: {
|
|
521
|
+
readonly type: import("../schema/options.js").OpenString<"default" | "flex" | "priority" | "reserved">;
|
|
522
|
+
} | undefined;
|
|
523
|
+
readonly guardrailConfig?: {
|
|
524
|
+
readonly guardrailIdentifier: string;
|
|
525
|
+
readonly guardrailVersion: string;
|
|
526
|
+
readonly trace?: import("../schema/options.js").OpenString<"disabled" | "enabled" | "enabled_full"> | undefined;
|
|
527
|
+
readonly streamProcessingMode?: import("../schema/options.js").OpenString<"async" | "sync"> | undefined;
|
|
528
|
+
} | undefined;
|
|
529
|
+
readonly outputConfig?: {
|
|
530
|
+
readonly textFormat: {
|
|
531
|
+
readonly type: import("../schema/options.js").OpenString<"json_schema">;
|
|
532
|
+
readonly structure: {
|
|
533
|
+
readonly jsonSchema: {
|
|
534
|
+
readonly schema: string;
|
|
535
|
+
readonly name?: string | undefined;
|
|
536
|
+
readonly description?: string | undefined;
|
|
537
|
+
};
|
|
538
|
+
};
|
|
539
|
+
};
|
|
540
|
+
} | undefined;
|
|
541
|
+
readonly requestMetadata?: {
|
|
542
|
+
readonly [x: string]: string;
|
|
543
|
+
} | undefined;
|
|
449
544
|
}, import("../route/transport/http.js").HttpPrepared<{
|
|
450
545
|
readonly [x: string]: unknown;
|
|
451
546
|
readonly rawBody: string;
|
|
@@ -10,7 +10,7 @@ import { JsonObject, optionalArray, ProviderShared } from "./shared.js";
|
|
|
10
10
|
import { BedrockAuth } from "./utils/bedrock-auth.js";
|
|
11
11
|
import { BedrockCache } from "./utils/bedrock-cache.js";
|
|
12
12
|
import { BedrockMedia } from "./utils/bedrock-media.js";
|
|
13
|
-
import { supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js";
|
|
13
|
+
import { claudeVersion, supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js";
|
|
14
14
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
15
15
|
import { MistralToolID } from "./utils/mistral-tool-id.js";
|
|
16
16
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
@@ -86,6 +86,11 @@ const BedrockToolChoice = Schema.Union([
|
|
|
86
86
|
Schema.Struct({ any: Schema.Struct({}) }),
|
|
87
87
|
Schema.Struct({ tool: Schema.Struct({ name: Schema.String }) }),
|
|
88
88
|
]);
|
|
89
|
+
// Value sets from the Converse API reference. Unknown values pass through for forward compatibility.
|
|
90
|
+
const ServiceTierType = ProviderShared.knownString();
|
|
91
|
+
const GuardrailTrace = ProviderShared.knownString();
|
|
92
|
+
const GuardrailStreamProcessingMode = ProviderShared.knownString();
|
|
93
|
+
const TextFormatType = ProviderShared.knownString();
|
|
89
94
|
const BedrockBodyFields = {
|
|
90
95
|
modelId: Schema.String,
|
|
91
96
|
messages: Schema.Array(BedrockMessage),
|
|
@@ -101,6 +106,26 @@ const BedrockBodyFields = {
|
|
|
101
106
|
toolChoice: Schema.optional(BedrockToolChoice),
|
|
102
107
|
})),
|
|
103
108
|
additionalModelRequestFields: Schema.optional(JsonObject),
|
|
109
|
+
serviceTier: Schema.optional(Schema.Struct({ type: ServiceTierType })),
|
|
110
|
+
guardrailConfig: Schema.optional(Schema.Struct({
|
|
111
|
+
guardrailIdentifier: Schema.String,
|
|
112
|
+
guardrailVersion: Schema.String,
|
|
113
|
+
trace: Schema.optional(GuardrailTrace),
|
|
114
|
+
streamProcessingMode: Schema.optional(GuardrailStreamProcessingMode),
|
|
115
|
+
})),
|
|
116
|
+
outputConfig: Schema.optional(Schema.Struct({
|
|
117
|
+
textFormat: Schema.Struct({
|
|
118
|
+
type: TextFormatType,
|
|
119
|
+
structure: Schema.Struct({
|
|
120
|
+
jsonSchema: Schema.Struct({
|
|
121
|
+
schema: Schema.String,
|
|
122
|
+
name: Schema.optional(Schema.String),
|
|
123
|
+
description: Schema.optional(Schema.String),
|
|
124
|
+
}),
|
|
125
|
+
}),
|
|
126
|
+
}),
|
|
127
|
+
})),
|
|
128
|
+
requestMetadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
104
129
|
};
|
|
105
130
|
const BedrockConverseBody = Schema.Struct(BedrockBodyFields);
|
|
106
131
|
const BedrockUsageSchema = Schema.Struct({
|
|
@@ -376,8 +401,49 @@ const isHighReasoningEffort = Schema.is(Schema.Struct({
|
|
|
376
401
|
reasoningConfig: Schema.Struct({ maxReasoningEffort: Schema.Literal("high") }),
|
|
377
402
|
}),
|
|
378
403
|
}));
|
|
404
|
+
// Claude 4.6+ pairs effort with adaptive thinking; earlier Claude models take effort beside a manual budget.
|
|
405
|
+
const supportsAdaptiveThinking = (model) => {
|
|
406
|
+
const version = claudeVersion(model.id);
|
|
407
|
+
return version !== undefined && (version.major > 4 || (version.major === 4 && version.minor >= 6));
|
|
408
|
+
};
|
|
409
|
+
const effortFields = (model, effort) => {
|
|
410
|
+
if (model.id.includes("anthropic"))
|
|
411
|
+
return { output_config: { effort } };
|
|
412
|
+
// gpt-oss takes the flat chat-completions spelling; newer OpenAI and xAI models take the Responses one.
|
|
413
|
+
if (model.id.includes("openai.gpt-oss"))
|
|
414
|
+
return { reasoning_effort: effort };
|
|
415
|
+
if (model.id.includes("openai.") || model.id.includes("xai."))
|
|
416
|
+
return { reasoning: { effort } };
|
|
417
|
+
return { reasoningConfig: { type: "enabled", maxReasoningEffort: effort } };
|
|
418
|
+
};
|
|
379
419
|
const Options = Schema.Struct({
|
|
380
|
-
thinking
|
|
420
|
+
/** Claude thinking. `adaptive` and `disabled` apply to Claude models only. */
|
|
421
|
+
thinking: Schema.optional(Schema.Union([
|
|
422
|
+
Schema.Struct({ type: Schema.Literal("enabled"), budgetTokens: Schema.Number }),
|
|
423
|
+
Schema.Struct({
|
|
424
|
+
type: Schema.Literal("adaptive"),
|
|
425
|
+
display: Schema.optional(ProviderShared.knownString()),
|
|
426
|
+
}),
|
|
427
|
+
Schema.Struct({ type: Schema.Literal("disabled") }),
|
|
428
|
+
])),
|
|
429
|
+
/** Reasoning effort, sent in the field each model family reads. */
|
|
430
|
+
effort: Schema.optional(ProviderShared.knownString()),
|
|
431
|
+
serviceTier: Schema.optional(ServiceTierType),
|
|
432
|
+
/** Constrains the response text to a JSON schema. */
|
|
433
|
+
outputFormat: Schema.optional(Schema.Struct({
|
|
434
|
+
type: TextFormatType,
|
|
435
|
+
schema: JsonObject,
|
|
436
|
+
name: Schema.optional(Schema.String),
|
|
437
|
+
description: Schema.optional(Schema.String),
|
|
438
|
+
})),
|
|
439
|
+
guardrail: Schema.optional(Schema.Struct({
|
|
440
|
+
identifier: Schema.String,
|
|
441
|
+
version: Schema.String,
|
|
442
|
+
trace: Schema.optional(GuardrailTrace),
|
|
443
|
+
streamProcessingMode: Schema.optional(GuardrailStreamProcessingMode),
|
|
444
|
+
})),
|
|
445
|
+
/** Key-value pairs for filtering invocation logs. */
|
|
446
|
+
requestMetadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
381
447
|
});
|
|
382
448
|
const decodeOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(Options));
|
|
383
449
|
// Claude on Bedrock requires the thinking budget below `maxTokens`, with a minimum of 1,024.
|
|
@@ -390,7 +456,7 @@ const isThinkingDisabled = Schema.is(Schema.Struct({
|
|
|
390
456
|
// Claude 5.1+ binds each thinking signature to the prefix above it. Ask Bedrock to drop the affected blocks instead of
|
|
391
457
|
// failing when that prefix changes. `http.body` overlays this field by field, so callers can still override it.
|
|
392
458
|
const applyThinkingBindingDefault = (request, thinking) => {
|
|
393
|
-
if (isThinkingDisabled(request.http?.body))
|
|
459
|
+
if (thinking?.type === "disabled" || isThinkingDisabled(request.http?.body))
|
|
394
460
|
return thinking;
|
|
395
461
|
if (!supportsThinkingBlockBinding(request.model))
|
|
396
462
|
return thinking;
|
|
@@ -404,13 +470,27 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
|
|
|
404
470
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
405
471
|
const generation = request.generation;
|
|
406
472
|
const options = yield* decodeOptions(request.providerOptions ?? {});
|
|
407
|
-
const maxTokens = isNova2(request.model) && isHighReasoningEffort(request.http?.body)
|
|
408
|
-
const thinking = applyThinkingBindingDefault(request, options.thinking === undefined
|
|
473
|
+
const maxTokens = isNova2(request.model) && (options.effort === "high" || isHighReasoningEffort(request.http?.body))
|
|
409
474
|
? undefined
|
|
410
|
-
:
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
475
|
+
: generation?.maxTokens;
|
|
476
|
+
const thinking = applyThinkingBindingDefault(request, (() => {
|
|
477
|
+
if (options.thinking?.type === "enabled")
|
|
478
|
+
return {
|
|
479
|
+
type: "enabled",
|
|
480
|
+
budget_tokens: ProviderShared.fitThinkingBudget(options.thinking.budgetTokens, maxTokens, MIN_THINKING_BUDGET),
|
|
481
|
+
};
|
|
482
|
+
if (options.thinking !== undefined)
|
|
483
|
+
return options.thinking;
|
|
484
|
+
if (options.effort !== undefined && supportsAdaptiveThinking(request.model))
|
|
485
|
+
return { type: "adaptive" };
|
|
486
|
+
})());
|
|
487
|
+
const additionalModelRequestFields = {
|
|
488
|
+
...(generation?.topK === undefined ? {} : { top_k: generation.topK }),
|
|
489
|
+
...(thinking === undefined ? {} : { thinking }),
|
|
490
|
+
...(options.effort === undefined ? {} : effortFields(request.model, options.effort)),
|
|
491
|
+
// Converse takes Anthropic betas in the body, and Bedrock rejects `block_binding` without this one.
|
|
492
|
+
...(thinking?.block_binding === undefined ? {} : { anthropic_beta: [THINKING_BINDING_BETA] }),
|
|
493
|
+
};
|
|
414
494
|
// Bedrock-Claude shares Anthropic's 4-breakpoint cap. Spend the budget in
|
|
415
495
|
// tools → system → messages order to favour the highest-impact prefixes.
|
|
416
496
|
const breakpoints = BedrockCache.breakpoints(request.model);
|
|
@@ -448,16 +528,33 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
|
|
|
448
528
|
system,
|
|
449
529
|
inferenceConfig,
|
|
450
530
|
toolConfig,
|
|
451
|
-
// Converse's base inferenceConfig has no topK or
|
|
531
|
+
// Converse's base inferenceConfig has no topK, thinking or effort; models accept them
|
|
452
532
|
// as model-specific fields, so they go through additionalModelRequestFields.
|
|
453
|
-
additionalModelRequestFields:
|
|
533
|
+
additionalModelRequestFields: Object.keys(additionalModelRequestFields).length === 0 ? undefined : additionalModelRequestFields,
|
|
534
|
+
serviceTier: options.serviceTier === undefined ? undefined : { type: options.serviceTier },
|
|
535
|
+
guardrailConfig: options.guardrail === undefined
|
|
454
536
|
? undefined
|
|
455
537
|
: {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
538
|
+
guardrailIdentifier: options.guardrail.identifier,
|
|
539
|
+
guardrailVersion: options.guardrail.version,
|
|
540
|
+
trace: options.guardrail.trace,
|
|
541
|
+
streamProcessingMode: options.guardrail.streamProcessingMode,
|
|
542
|
+
},
|
|
543
|
+
outputConfig: options.outputFormat === undefined
|
|
544
|
+
? undefined
|
|
545
|
+
: {
|
|
546
|
+
textFormat: {
|
|
547
|
+
type: options.outputFormat.type,
|
|
548
|
+
structure: {
|
|
549
|
+
jsonSchema: {
|
|
550
|
+
schema: ProviderShared.encodeJson(options.outputFormat.schema),
|
|
551
|
+
name: options.outputFormat.name,
|
|
552
|
+
description: options.outputFormat.description,
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
},
|
|
460
556
|
},
|
|
557
|
+
requestMetadata: options.requestMetadata,
|
|
461
558
|
};
|
|
462
559
|
});
|
|
463
560
|
// =============================================================================
|
|
@@ -94,6 +94,7 @@ const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
|
|
|
94
94
|
export const framing = (route) => ({
|
|
95
95
|
id: "aws-event-stream",
|
|
96
96
|
body: (frame) => frame.rawBody,
|
|
97
|
+
raw: ({ rawBody: _, ...event }) => event,
|
|
97
98
|
frame: (bytes) => bytes.pipe(Stream.map((bytes) => ({ _tag: "Chunk", bytes })), Stream.concat(Stream.succeed(endOfStream)), Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))),
|
|
98
99
|
});
|
|
99
100
|
export * as BedrockEventStream from "./bedrock-event-stream.js";
|
|
@@ -64,15 +64,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
64
64
|
readonly [x: string]: unknown;
|
|
65
65
|
} | undefined;
|
|
66
66
|
} | undefined;
|
|
67
|
-
readonly notices?: readonly {
|
|
68
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
69
|
-
readonly message: string;
|
|
70
|
-
readonly providerMetadata?: {
|
|
71
|
-
readonly [x: string]: {
|
|
72
|
-
readonly [x: string]: unknown;
|
|
73
|
-
};
|
|
74
|
-
} | undefined;
|
|
75
|
-
}[] | undefined;
|
|
76
67
|
readonly providerMetadata?: {
|
|
77
68
|
readonly [x: string]: {
|
|
78
69
|
readonly [x: string]: unknown;
|
|
@@ -123,15 +114,6 @@ export declare const CartesiaSpeech: {
|
|
|
123
114
|
readonly [x: string]: unknown;
|
|
124
115
|
} | undefined;
|
|
125
116
|
} | undefined;
|
|
126
|
-
readonly notices?: readonly {
|
|
127
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
128
|
-
readonly message: string;
|
|
129
|
-
readonly providerMetadata?: {
|
|
130
|
-
readonly [x: string]: {
|
|
131
|
-
readonly [x: string]: unknown;
|
|
132
|
-
};
|
|
133
|
-
} | undefined;
|
|
134
|
-
}[] | undefined;
|
|
135
117
|
readonly providerMetadata?: {
|
|
136
118
|
readonly [x: string]: {
|
|
137
119
|
readonly [x: string]: unknown;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
2
|
+
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One body as `input`; media defaults to Clef's top-level lists. */
|
|
3
|
+
export declare const protocol: DecisionRoute.Protocol;
|
|
4
|
+
/** Providers set the Run API base, `.../client/v4/accounts/{account}/ai/run`, with `route.with(...)`. */
|
|
5
|
+
export declare const route: DecisionRoute.Route;
|
|
6
|
+
export declare const CloudflareRunDecisions: {
|
|
7
|
+
readonly protocol: DecisionRoute.Protocol;
|
|
8
|
+
readonly route: DecisionRoute.Route;
|
|
9
|
+
};
|