@opencode/ai 2.2.5 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -72
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +30 -125
- package/dist/decision.js +27 -15
- package/dist/effect.d.ts +10 -15
- package/dist/effect.js +6 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/embedding-client.d.ts +21 -0
- package/dist/embedding-client.js +30 -0
- package/dist/embedding.d.ts +111 -0
- package/dist/embedding.js +75 -0
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -465
- package/dist/image.js +17 -18
- package/dist/index.d.ts +35 -467
- package/dist/index.js +23 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +9 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -176
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +10 -16
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +54 -72
- package/dist/protocols/google-embed-content.d.ts +34 -0
- package/dist/protocols/google-embed-content.js +110 -0
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +44 -30
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
- package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +7 -10
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +2 -22
- package/dist/protocols/open-responses.js +41 -23
- package/dist/protocols/openai-chat.d.ts +27 -23
- package/dist/protocols/openai-chat.js +62 -57
- package/dist/protocols/openai-compatible-chat.d.ts +2 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +15 -2
- package/dist/protocols/openai-embeddings.d.ts +16 -0
- package/dist/protocols/openai-embeddings.js +76 -0
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +14 -7
- package/dist/protocols/shared.js +40 -15
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/system-one.js +8 -1
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +7 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +9 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +7 -80
- package/dist/providers/alibaba/embeddings.d.ts +2 -0
- package/dist/providers/alibaba/embeddings.js +1 -0
- package/dist/providers/alibaba.d.ts +70 -4
- package/dist/providers/alibaba.js +20 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +7 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/embeddings.d.ts +2 -0
- package/dist/providers/azure/embeddings.js +1 -0
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +325 -7
- package/dist/providers/azure.js +40 -9
- package/dist/providers/baseten.d.ts +7 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +7 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +23 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +6 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere/embeddings.d.ts +2 -0
- package/dist/providers/cohere/embeddings.js +1 -0
- package/dist/providers/cohere.d.ts +14 -5
- package/dist/providers/cohere.js +23 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra/embeddings.d.ts +2 -0
- package/dist/providers/deepinfra/embeddings.js +1 -0
- package/dist/providers/deepinfra.d.ts +10 -5
- package/dist/providers/deepinfra.js +20 -14
- package/dist/providers/deepseek.d.ts +7 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean/embeddings.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.js +1 -0
- package/dist/providers/digitalocean.d.ts +18 -5
- package/dist/providers/digitalocean.js +28 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks/embeddings.d.ts +2 -0
- package/dist/providers/fireworks/embeddings.js +1 -0
- package/dist/providers/fireworks.d.ts +10 -5
- package/dist/providers/fireworks.js +17 -14
- package/dist/providers/google/embeddings.d.ts +2 -0
- package/dist/providers/google/embeddings.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex/embeddings.d.ts +2 -0
- package/dist/providers/google-vertex/embeddings.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +4 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +10 -3
- package/dist/providers/google-vertex.js +52 -0
- package/dist/providers/google.d.ts +21 -13
- package/dist/providers/google.js +23 -19
- package/dist/providers/groq.d.ts +10 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +6 -5
- package/dist/providers/meta.js +10 -23
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +6 -5
- package/dist/providers/minimax.js +7 -22
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +6 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai/embeddings.d.ts +2 -0
- package/dist/providers/openai/embeddings.js +1 -0
- package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
- package/dist/providers/openai-compatible/embeddings.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +10 -7
- package/dist/providers/openai-compatible.js +17 -10
- package/dist/providers/openai.d.ts +11 -4
- package/dist/providers/openai.js +17 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter/embeddings.d.ts +2 -0
- package/dist/providers/openrouter/embeddings.js +1 -0
- package/dist/providers/openrouter.d.ts +24 -5
- package/dist/providers/openrouter.js +31 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +7 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +5 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +9 -5
- package/dist/providers/vercel-ai-gateway.js +30 -29
- package/dist/providers/xai.d.ts +5 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +6 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +6 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +14 -0
- package/dist/public.js +6 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/embedding.d.ts +61 -0
- package/dist/route/embedding.js +88 -0
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +309 -257
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
|
@@ -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, CacheTTL,
|
|
11
|
+
import { AIError, CacheTTL, 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";
|
|
@@ -402,11 +402,8 @@ const ANTHROPIC_BREAKPOINT_CAP = 4;
|
|
|
402
402
|
const cacheControl = (breakpoints, cache) => {
|
|
403
403
|
if (cache?.type !== "ephemeral" && cache?.type !== "persistent")
|
|
404
404
|
return undefined;
|
|
405
|
-
if (breakpoints
|
|
406
|
-
breakpoints.dropped += 1;
|
|
405
|
+
if (!Cache.take(breakpoints))
|
|
407
406
|
return undefined;
|
|
408
|
-
}
|
|
409
|
-
breakpoints.remaining -= 1;
|
|
410
407
|
return { type: "ephemeral", ...(cache.ttl === undefined ? {} : { ttl: cache.ttl }) };
|
|
411
408
|
};
|
|
412
409
|
const providerMetadata = (key, metadata) => ({ [key]: metadata });
|
|
@@ -488,68 +485,15 @@ const lowerServerToolResult = Effect.fnUntraced(function* (part, providerMetadat
|
|
|
488
485
|
content: payload,
|
|
489
486
|
};
|
|
490
487
|
});
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
if (typeof metadata.file_id === "string")
|
|
502
|
-
return metadata.file_id;
|
|
503
|
-
if (typeof metadata.fileId === "string")
|
|
504
|
-
return metadata.fileId;
|
|
505
|
-
return undefined;
|
|
506
|
-
};
|
|
507
|
-
const transformationsFromMetadata = (metadata) => {
|
|
508
|
-
if (!metadata)
|
|
509
|
-
return undefined;
|
|
510
|
-
const anthropic = ProviderShared.isRecord(metadata.anthropic) ? metadata.anthropic : undefined;
|
|
511
|
-
const raw = anthropic?.transformations ?? metadata.transformations;
|
|
512
|
-
if (ProviderShared.isRecord(raw)) {
|
|
513
|
-
const value = raw.oversized_image;
|
|
514
|
-
if (value === "downsize" || value === "error")
|
|
515
|
-
return { oversized_image: value };
|
|
516
|
-
}
|
|
517
|
-
if (anthropic && (anthropic.oversized_image === "downsize" || anthropic.oversized_image === "error"))
|
|
518
|
-
return { oversized_image: anthropic.oversized_image };
|
|
519
|
-
return undefined;
|
|
520
|
-
};
|
|
521
|
-
const documentTitleFromPart = (part) => {
|
|
522
|
-
if (part.metadata !== undefined) {
|
|
523
|
-
const anthropic = part.metadata.anthropic;
|
|
524
|
-
if (ProviderShared.isRecord(anthropic) && typeof anthropic.title === "string")
|
|
525
|
-
return anthropic.title;
|
|
526
|
-
if (typeof part.metadata.title === "string")
|
|
527
|
-
return part.metadata.title;
|
|
528
|
-
}
|
|
529
|
-
if (part.filename && part.filename.length > 0)
|
|
530
|
-
return part.filename;
|
|
531
|
-
return undefined;
|
|
532
|
-
};
|
|
533
|
-
const documentContextFromMetadata = (metadata) => {
|
|
534
|
-
if (!metadata)
|
|
535
|
-
return undefined;
|
|
536
|
-
const anthropic = ProviderShared.isRecord(metadata.anthropic) ? metadata.anthropic : undefined;
|
|
537
|
-
if (anthropic && typeof anthropic.context === "string")
|
|
538
|
-
return anthropic.context;
|
|
539
|
-
if (typeof metadata.context === "string")
|
|
540
|
-
return metadata.context;
|
|
541
|
-
return undefined;
|
|
542
|
-
};
|
|
543
|
-
const citationsFromMetadata = (metadata) => {
|
|
544
|
-
if (!metadata)
|
|
545
|
-
return undefined;
|
|
546
|
-
const raw = ProviderShared.isRecord(metadata.anthropic)
|
|
547
|
-
? (metadata.anthropic.citations ?? metadata.citations)
|
|
548
|
-
: metadata.citations;
|
|
549
|
-
if (ProviderShared.isRecord(raw) && typeof raw.enabled === "boolean")
|
|
550
|
-
return { enabled: raw.enabled };
|
|
551
|
-
return undefined;
|
|
552
|
-
};
|
|
488
|
+
// Per-part Anthropic block fields, read from `providerMetadata[providerMetadataKey]` with Anthropic's wire names.
|
|
489
|
+
const MediaOptions = Schema.Struct({
|
|
490
|
+
file_id: Schema.optional(Schema.String),
|
|
491
|
+
title: Schema.optional(Schema.String),
|
|
492
|
+
context: Schema.optional(Schema.String),
|
|
493
|
+
citations: Schema.optional(Schema.Struct({ enabled: Schema.Boolean })),
|
|
494
|
+
transformations: Schema.optional(AnthropicImageTransformations),
|
|
495
|
+
});
|
|
496
|
+
const decodeMediaOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(MediaOptions));
|
|
553
497
|
const isHttpUrl = (value) => /^https?:\/\//i.test(value.trim());
|
|
554
498
|
const lowerMedia = Effect.fnUntraced(function* (part, request, breakpoints) {
|
|
555
499
|
const mime = part.media.mediaType.toLowerCase();
|
|
@@ -567,105 +511,51 @@ const lowerMedia = Effect.fnUntraced(function* (part, request, breakpoints) {
|
|
|
567
511
|
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
568
512
|
};
|
|
569
513
|
}
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
? {}
|
|
580
|
-
: { transformations: transformationsFromMetadata(part.metadata) }),
|
|
581
|
-
};
|
|
514
|
+
const options = yield* decodeMediaOptions(part.providerMetadata?.[request.model.route.providerMetadataKey ?? request.model.provider] ?? {});
|
|
515
|
+
const image = (source) => ({
|
|
516
|
+
type: "image",
|
|
517
|
+
source,
|
|
518
|
+
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
519
|
+
...(options.transformations === undefined ? {} : { transformations: options.transformations }),
|
|
520
|
+
});
|
|
521
|
+
const document = (source) => {
|
|
522
|
+
const title = options.title ?? (part.filename ? part.filename : undefined);
|
|
582
523
|
return {
|
|
583
524
|
type: "document",
|
|
584
|
-
source
|
|
525
|
+
source,
|
|
585
526
|
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
586
|
-
...(
|
|
587
|
-
...(
|
|
588
|
-
|
|
589
|
-
: { context: documentContextFromMetadata(part.metadata) }),
|
|
590
|
-
...(citationsFromMetadata(part.metadata) === undefined
|
|
591
|
-
? {}
|
|
592
|
-
: { citations: citationsFromMetadata(part.metadata) }),
|
|
527
|
+
...(title === undefined ? {} : { title }),
|
|
528
|
+
...(options.context === undefined ? {} : { context: options.context }),
|
|
529
|
+
...(options.citations === undefined ? {} : { citations: options.citations }),
|
|
593
530
|
};
|
|
531
|
+
};
|
|
532
|
+
// SDK file sources: FileImageSource:2350 / FileDocumentSource:2344 {type:"file", file_id}
|
|
533
|
+
if (options.file_id) {
|
|
534
|
+
if (mime.startsWith("image/"))
|
|
535
|
+
return image({ type: "file", file_id: options.file_id });
|
|
536
|
+
return document({ type: "file", file_id: options.file_id });
|
|
594
537
|
}
|
|
595
538
|
const rawString = ProviderShared.mediaUrl(part.media)?.trim();
|
|
596
539
|
// SDK URL sources: URLImageSource:3817 / URLPDFSource:3823 {type:"url", url}
|
|
597
540
|
if (rawString && isHttpUrl(rawString)) {
|
|
598
541
|
if (mime.startsWith("image/"))
|
|
599
|
-
return {
|
|
600
|
-
type: "image",
|
|
601
|
-
source: { type: "url", url: rawString },
|
|
602
|
-
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
603
|
-
...(transformationsFromMetadata(part.metadata) === undefined
|
|
604
|
-
? {}
|
|
605
|
-
: { transformations: transformationsFromMetadata(part.metadata) }),
|
|
606
|
-
};
|
|
542
|
+
return image({ type: "url", url: rawString });
|
|
607
543
|
if (mime === "application/pdf")
|
|
608
|
-
return {
|
|
609
|
-
type: "document",
|
|
610
|
-
source: { type: "url", url: rawString },
|
|
611
|
-
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
612
|
-
...(documentTitleFromPart(part) === undefined ? {} : { title: documentTitleFromPart(part) }),
|
|
613
|
-
...(documentContextFromMetadata(part.metadata) === undefined
|
|
614
|
-
? {}
|
|
615
|
-
: { context: documentContextFromMetadata(part.metadata) }),
|
|
616
|
-
...(citationsFromMetadata(part.metadata) === undefined
|
|
617
|
-
? {}
|
|
618
|
-
: { citations: citationsFromMetadata(part.metadata) }),
|
|
619
|
-
};
|
|
544
|
+
return document({ type: "url", url: rawString });
|
|
620
545
|
}
|
|
621
546
|
const media = yield* ProviderShared.requireInlineMedia("Anthropic Messages", part.media);
|
|
622
547
|
// SDK PlainTextSource:2716 {type:"text", media_type:"text/plain", data}
|
|
623
|
-
if (mime === "text/plain")
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
...(documentTitleFromPart(part) === undefined ? {} : { title: documentTitleFromPart(part) }),
|
|
630
|
-
...(documentContextFromMetadata(part.metadata) === undefined
|
|
631
|
-
? {}
|
|
632
|
-
: { context: documentContextFromMetadata(part.metadata) }),
|
|
633
|
-
...(citationsFromMetadata(part.metadata) === undefined
|
|
634
|
-
? {}
|
|
635
|
-
: { citations: citationsFromMetadata(part.metadata) }),
|
|
636
|
-
};
|
|
637
|
-
}
|
|
548
|
+
if (mime === "text/plain")
|
|
549
|
+
return document({
|
|
550
|
+
type: "text",
|
|
551
|
+
media_type: "text/plain",
|
|
552
|
+
data: Buffer.from(media.base64, "base64").toString("utf8"),
|
|
553
|
+
});
|
|
638
554
|
if (media.mime === "application/pdf")
|
|
639
|
-
return {
|
|
640
|
-
type: "document",
|
|
641
|
-
source: {
|
|
642
|
-
type: "base64",
|
|
643
|
-
media_type: "application/pdf",
|
|
644
|
-
data: media.base64,
|
|
645
|
-
},
|
|
646
|
-
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
647
|
-
...(documentTitleFromPart(part) === undefined ? {} : { title: documentTitleFromPart(part) }),
|
|
648
|
-
...(documentContextFromMetadata(part.metadata) === undefined
|
|
649
|
-
? {}
|
|
650
|
-
: { context: documentContextFromMetadata(part.metadata) }),
|
|
651
|
-
...(citationsFromMetadata(part.metadata) === undefined
|
|
652
|
-
? {}
|
|
653
|
-
: { citations: citationsFromMetadata(part.metadata) }),
|
|
654
|
-
};
|
|
555
|
+
return document({ type: "base64", media_type: "application/pdf", data: media.base64 });
|
|
655
556
|
if (!media.mime.startsWith("image/"))
|
|
656
557
|
return yield* invalid(`Anthropic Messages does not support media type ${part.media.mediaType}`);
|
|
657
|
-
return {
|
|
658
|
-
type: "image",
|
|
659
|
-
source: {
|
|
660
|
-
type: "base64",
|
|
661
|
-
media_type: media.mime,
|
|
662
|
-
data: media.base64,
|
|
663
|
-
},
|
|
664
|
-
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
665
|
-
...(transformationsFromMetadata(part.metadata) === undefined
|
|
666
|
-
? {}
|
|
667
|
-
: { transformations: transformationsFromMetadata(part.metadata) }),
|
|
668
|
-
};
|
|
558
|
+
return image({ type: "base64", media_type: media.mime, data: media.base64 });
|
|
669
559
|
});
|
|
670
560
|
// Tool results may carry structured text, images, and documents. Keep media as provider-native
|
|
671
561
|
// content instead of JSON-stringifying base64 into a prompt string.
|
|
@@ -705,6 +595,9 @@ const requireThinkingSignature = (request) => {
|
|
|
705
595
|
};
|
|
706
596
|
// Opus 4.8 and every Claude 5 model accept mid-conversation system messages; later versions inherit support.
|
|
707
597
|
const supportsNativeSystemUpdates = (request) => {
|
|
598
|
+
const override = request.model.capabilities?.systemUpdates;
|
|
599
|
+
if (override !== undefined)
|
|
600
|
+
return override;
|
|
708
601
|
const version = claudeVersion(request.model.id);
|
|
709
602
|
if (version === undefined)
|
|
710
603
|
return false;
|
|
@@ -793,7 +686,6 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
793
686
|
content.push(yield* lowerMedia(part, request, breakpoints));
|
|
794
687
|
continue;
|
|
795
688
|
}
|
|
796
|
-
return yield* ProviderShared.unsupportedContent("Anthropic Messages", "user", ["text", "media"]);
|
|
797
689
|
}
|
|
798
690
|
if (content.length > 0)
|
|
799
691
|
messages.push({ role: "user", content });
|
|
@@ -850,8 +742,6 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
850
742
|
}
|
|
851
743
|
const content = [];
|
|
852
744
|
for (const part of message.content) {
|
|
853
|
-
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
854
|
-
return yield* ProviderShared.unsupportedContent("Anthropic Messages", "tool", ["tool-result"]);
|
|
855
745
|
content.push({
|
|
856
746
|
type: "tool_result",
|
|
857
747
|
tool_use_id: scrubToolCallID(part.id),
|
|
@@ -869,15 +759,14 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
869
759
|
yield* releaseHeld();
|
|
870
760
|
return messages;
|
|
871
761
|
});
|
|
872
|
-
//
|
|
873
|
-
// `
|
|
874
|
-
// only reads `request.model.compatibility`.
|
|
762
|
+
// The model-ID checks below are fallbacks for models that leave `capabilities.reasoning.updates`,
|
|
763
|
+
// `capabilities.systemUpdates` and `compatibility.supportsThinkingBlockBinding` unset.
|
|
875
764
|
const isThinkingOff = Schema.is(AnthropicThinkingDisabled);
|
|
876
765
|
// Per-turn effort started with Claude Opus 5 and every Claude 5.1 model; later versions of any family inherit it.
|
|
877
766
|
const supportsEffortUpdates = (request) => {
|
|
878
767
|
if (isThinkingOff(request.providerOptions?.thinking))
|
|
879
768
|
return false;
|
|
880
|
-
const override = request.model.
|
|
769
|
+
const override = request.model.capabilities?.reasoning?.updates;
|
|
881
770
|
if (override !== undefined)
|
|
882
771
|
return override;
|
|
883
772
|
const version = claudeVersion(request.model.id);
|
|
@@ -913,7 +802,6 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
913
802
|
const outputConfig = options.output_config ?? options.outputConfig;
|
|
914
803
|
const format = outputConfig?.format ?? undefined;
|
|
915
804
|
const updates = resolveEffortUpdates(request, options.effort ?? outputConfig?.effort ?? undefined);
|
|
916
|
-
const generation = request.generation;
|
|
917
805
|
// Allocate the 4-breakpoint budget in invalidation order: tools → system →
|
|
918
806
|
// messages. Tools live highest in the cache hierarchy, so when callers
|
|
919
807
|
// over-mark we keep their tool hints and shed the message-tail ones first.
|
|
@@ -931,11 +819,9 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
931
819
|
cache_control: cacheControl(breakpoints, part.cache),
|
|
932
820
|
}));
|
|
933
821
|
const messages = yield* lowerMessages(flattened.request, breakpoints);
|
|
934
|
-
|
|
935
|
-
yield* Effect.logWarning(`Anthropic Messages: dropped ${breakpoints.dropped} cache breakpoint(s); the API allows at most ${ANTHROPIC_BREAKPOINT_CAP} per request.`);
|
|
936
|
-
}
|
|
822
|
+
yield* Cache.warnDropped(breakpoints, "Anthropic Messages", ANTHROPIC_BREAKPOINT_CAP);
|
|
937
823
|
const output_config = updates.effort === undefined && format === undefined ? undefined : { effort: updates.effort, format };
|
|
938
|
-
const maxTokens =
|
|
824
|
+
const maxTokens = request.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
939
825
|
const body = {
|
|
940
826
|
model: request.model.id,
|
|
941
827
|
system,
|
|
@@ -944,10 +830,10 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
944
830
|
tool_choice: toolChoice,
|
|
945
831
|
stream: true,
|
|
946
832
|
max_tokens: maxTokens,
|
|
947
|
-
temperature:
|
|
948
|
-
top_p:
|
|
949
|
-
top_k:
|
|
950
|
-
stop_sequences:
|
|
833
|
+
temperature: request.temperature,
|
|
834
|
+
top_p: request.topP,
|
|
835
|
+
top_k: request.topK,
|
|
836
|
+
stop_sequences: request.stop,
|
|
951
837
|
thinking: applyThinkingBindingDefault(request.model, fitThinking(options.thinking, maxTokens)),
|
|
952
838
|
output_config,
|
|
953
839
|
// top-level passthrough per SDK MessageCreateParamsBase:4638,4643,4649,4654,4670
|
|
@@ -992,7 +878,7 @@ const mapFinishReason = (reason) => {
|
|
|
992
878
|
// inclusive `inputTokens` the rest of the contract expects. Extended
|
|
993
879
|
// thinking tokens are included in `output_tokens`; newer responses also
|
|
994
880
|
// expose that subset through `output_tokens_details.thinking_tokens`.
|
|
995
|
-
const mapUsage = (usage, providerMetadataKey) => {
|
|
881
|
+
const mapUsage = (usage, providerMetadataKey, frame) => {
|
|
996
882
|
if (!usage)
|
|
997
883
|
return undefined;
|
|
998
884
|
const iterations = usage.iterations?.length ? usage.iterations : [usage];
|
|
@@ -1013,7 +899,7 @@ const mapUsage = (usage, providerMetadataKey) => {
|
|
|
1013
899
|
cacheWriteInputTokens: cacheWrite,
|
|
1014
900
|
reasoningTokens: ProviderShared.sumTokens(...iterations.map((item) => item.output_tokens_details?.thinking_tokens)),
|
|
1015
901
|
totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
|
|
1016
|
-
...ProviderShared.reportedBilling(usage),
|
|
902
|
+
...ProviderShared.reportedBilling(usage, frame),
|
|
1017
903
|
providerMetadata: { [providerMetadataKey]: usage },
|
|
1018
904
|
});
|
|
1019
905
|
};
|
|
@@ -1242,7 +1128,7 @@ const onContentBlockStop = Effect.fnUntraced(function* (state, event) {
|
|
|
1242
1128
|
return [{ ...state, lifecycle, tools: result.tools, reasoningSignatures }, events];
|
|
1243
1129
|
});
|
|
1244
1130
|
const onMessageDelta = (state, event) => {
|
|
1245
|
-
const usage = mergeUsage(state.usage, mapUsage(event.usage, state.providerMetadataKey), state.providerMetadataKey);
|
|
1131
|
+
const usage = mergeUsage(state.usage, mapUsage(event.usage, state.providerMetadataKey, event), state.providerMetadataKey);
|
|
1246
1132
|
const pendingFinish = (() => {
|
|
1247
1133
|
const stopReason = event.delta?.stop_reason;
|
|
1248
1134
|
if (stopReason === null || stopReason === undefined)
|
|
@@ -1421,7 +1307,7 @@ export const transport = () => {
|
|
|
1421
1307
|
const requiredBetas = requiredBetaHeaders(input.body);
|
|
1422
1308
|
if (requiredBetas.length === 0)
|
|
1423
1309
|
return http.prepare(input);
|
|
1424
|
-
const headers = Headers.fromInput(input.request.
|
|
1310
|
+
const headers = Headers.fromInput(input.request.headers);
|
|
1425
1311
|
const existingBetas = (headers["anthropic-beta"] ?? "")
|
|
1426
1312
|
.split(",")
|
|
1427
1313
|
.map((item) => item.trim())
|
|
@@ -1429,12 +1315,7 @@ export const transport = () => {
|
|
|
1429
1315
|
const betas = new Set([...existingBetas, ...requiredBetas]);
|
|
1430
1316
|
return http.prepare({
|
|
1431
1317
|
...input,
|
|
1432
|
-
request:
|
|
1433
|
-
http: new HttpOptions({
|
|
1434
|
-
...input.request.http,
|
|
1435
|
-
headers: { ...headers, "anthropic-beta": [...betas].join(",") },
|
|
1436
|
-
}),
|
|
1437
|
-
}),
|
|
1318
|
+
request: { ...input.request, headers: { ...headers, "anthropic-beta": [...betas].join(",") } },
|
|
1438
1319
|
});
|
|
1439
1320
|
},
|
|
1440
1321
|
};
|
|
@@ -2,7 +2,7 @@ import { Schema } from "effect";
|
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
5
|
-
import { TranscriptionModel, TranscriptionResponse, type
|
|
5
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequest } from "../transcription.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.assemblyai.com";
|
|
7
7
|
export declare const PATH = "/v2/transcript";
|
|
8
8
|
export declare const UPLOAD_PATH = "/v2/upload";
|
|
@@ -24,7 +24,7 @@ export type AssemblyAITranscriptionOptions = {
|
|
|
24
24
|
};
|
|
25
25
|
readonly speech_models?: ReadonlyArray<OpenString<"universal-3-5-pro" | "universal-2">>;
|
|
26
26
|
} & Record<string, unknown>;
|
|
27
|
-
export type Request =
|
|
27
|
+
export type Request = TranscriptionRequest<TranscriptionModel<AssemblyAITranscriptionOptions>>;
|
|
28
28
|
export declare const Token: Schema.Struct<{
|
|
29
29
|
readonly transcriptID: Schema.String;
|
|
30
30
|
}>;
|
|
@@ -9,6 +9,7 @@ import { classifyProviderFailure } from "../provider-error.js";
|
|
|
9
9
|
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
|
+
import { warnDropped } from "./utils/cache.js";
|
|
12
13
|
import { BedrockMedia } from "./utils/bedrock-media.js";
|
|
13
14
|
import { claudeVersion, supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js";
|
|
14
15
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
@@ -297,8 +298,6 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
297
298
|
if (message.role === "user") {
|
|
298
299
|
const content = [];
|
|
299
300
|
for (const part of message.content) {
|
|
300
|
-
if (!ProviderShared.supportsContent(part, ["text", "media"]))
|
|
301
|
-
return yield* ProviderShared.unsupportedContent("Bedrock Converse", "user", ["text", "media"]);
|
|
302
301
|
if (part.type === "text") {
|
|
303
302
|
content.push(...textWithCache(breakpoints, part.text, part.cache));
|
|
304
303
|
continue;
|
|
@@ -351,8 +350,6 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
351
350
|
}
|
|
352
351
|
const content = [];
|
|
353
352
|
for (const part of message.content) {
|
|
354
|
-
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
355
|
-
return yield* ProviderShared.unsupportedContent("Bedrock Converse", "tool", ["tool-result"]);
|
|
356
353
|
const result = yield* lowerToolResult(part, documentNames, normalizeID);
|
|
357
354
|
const images = hoistImages
|
|
358
355
|
? result.toolResult.content.filter((item) => "image" in item)
|
|
@@ -463,11 +460,10 @@ const applyThinkingBindingDefault = (request, thinking) => {
|
|
|
463
460
|
const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request) {
|
|
464
461
|
const toolChoice = request.toolChoice ? yield* lowerToolChoice(request.toolChoice) : undefined;
|
|
465
462
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
466
|
-
const generation = request.generation;
|
|
467
463
|
const options = yield* decodeOptions(request.providerOptions ?? {});
|
|
468
464
|
const maxTokens = isNova2(request.model) && (options.effort === "high" || isHighReasoningEffort(request.http?.body))
|
|
469
465
|
? undefined
|
|
470
|
-
:
|
|
466
|
+
: request.maxTokens;
|
|
471
467
|
const thinking = applyThinkingBindingDefault(request, (() => {
|
|
472
468
|
if (options.thinking?.type === "enabled")
|
|
473
469
|
return {
|
|
@@ -480,7 +476,7 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
|
|
|
480
476
|
return { type: "adaptive" };
|
|
481
477
|
})());
|
|
482
478
|
const additionalModelRequestFields = {
|
|
483
|
-
...(
|
|
479
|
+
...(request.topK === undefined ? {} : { top_k: request.topK }),
|
|
484
480
|
...(thinking === undefined ? {} : { thinking }),
|
|
485
481
|
...(options.effort === undefined ? {} : effortFields(request.model, options.effort)),
|
|
486
482
|
// Converse takes Anthropic betas in the body, and Bedrock rejects `block_binding` without this one.
|
|
@@ -501,20 +497,18 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
|
|
|
501
497
|
})();
|
|
502
498
|
const system = lowerSystem(breakpoints, request.system);
|
|
503
499
|
const messages = yield* lowerMessages(flattened.request, breakpoints);
|
|
504
|
-
|
|
505
|
-
yield* Effect.logWarning(`Bedrock Converse: dropped ${breakpoints.dropped} cache breakpoint(s); the API allows at most ${BedrockCache.BEDROCK_BREAKPOINT_CAP} per request.`);
|
|
506
|
-
}
|
|
500
|
+
yield* warnDropped(breakpoints, "Bedrock Converse", BedrockCache.BEDROCK_BREAKPOINT_CAP);
|
|
507
501
|
const inferenceConfig = (() => {
|
|
508
502
|
if (maxTokens === undefined &&
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
(
|
|
503
|
+
request.temperature === undefined &&
|
|
504
|
+
request.topP === undefined &&
|
|
505
|
+
(request.stop === undefined || request.stop.length === 0))
|
|
512
506
|
return undefined;
|
|
513
507
|
return {
|
|
514
508
|
maxTokens,
|
|
515
|
-
temperature:
|
|
516
|
-
topP:
|
|
517
|
-
stopSequences:
|
|
509
|
+
temperature: request.temperature,
|
|
510
|
+
topP: request.topP,
|
|
511
|
+
stopSequences: request.stop,
|
|
518
512
|
};
|
|
519
513
|
})();
|
|
520
514
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { SpeechModel, type
|
|
4
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
5
5
|
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.cartesia.ai";
|
|
7
7
|
export declare const API_VERSION = "2026-08-14";
|
|
@@ -18,7 +18,7 @@ export type CartesiaSpeechOptions = {
|
|
|
18
18
|
};
|
|
19
19
|
readonly pronunciation_dict_id?: string;
|
|
20
20
|
} & Record<string, unknown>;
|
|
21
|
-
export type Request =
|
|
21
|
+
export type Request = SpeechRequest<SpeechModel<CartesiaSpeechOptions>>;
|
|
22
22
|
interface State extends SpeechStream.Audio {
|
|
23
23
|
readonly done: boolean;
|
|
24
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import type { MediaRoute } from "../route/media.js";
|
|
4
4
|
/**
|
|
@@ -14,7 +14,7 @@ export type CloudflareWorkersAIImageOptions = {
|
|
|
14
14
|
readonly guidance?: number;
|
|
15
15
|
readonly negative_prompt?: string;
|
|
16
16
|
} & Record<string, unknown>;
|
|
17
|
-
export type Request =
|
|
17
|
+
export type Request = ImageRequest<ImageModel<CloudflareWorkersAIImageOptions>>;
|
|
18
18
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
19
19
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<CloudflareWorkersAIImageOptions>;
|
|
20
20
|
export declare const CloudflareWorkersAIImages: {
|
|
@@ -208,16 +208,16 @@ const fromRequest = Effect.fn("CohereChat.fromRequest")(function* (request) {
|
|
|
208
208
|
// Cohere rejects budgets above max_tokens; fitting also leaves room for the answer.
|
|
209
209
|
token_budget: options.thinking.tokenBudget === undefined
|
|
210
210
|
? undefined
|
|
211
|
-
: ProviderShared.fitThinkingBudget(options.thinking.tokenBudget, request.
|
|
211
|
+
: ProviderShared.fitThinkingBudget(options.thinking.tokenBudget, request.maxTokens),
|
|
212
212
|
},
|
|
213
|
-
max_tokens: request.
|
|
214
|
-
temperature: request.
|
|
215
|
-
p: request.
|
|
216
|
-
k: request.
|
|
217
|
-
seed: request.
|
|
218
|
-
stop_sequences: request.
|
|
219
|
-
frequency_penalty: request.
|
|
220
|
-
presence_penalty: request.
|
|
213
|
+
max_tokens: request.maxTokens,
|
|
214
|
+
temperature: request.temperature,
|
|
215
|
+
p: request.topP,
|
|
216
|
+
k: request.topK,
|
|
217
|
+
seed: request.seed,
|
|
218
|
+
stop_sequences: request.stop,
|
|
219
|
+
frequency_penalty: request.frequencyPenalty,
|
|
220
|
+
presence_penalty: request.presencePenalty,
|
|
221
221
|
};
|
|
222
222
|
});
|
|
223
223
|
const finishReason = (raw) => {
|
|
@@ -304,9 +304,6 @@ export const protocol = Protocol.make({
|
|
|
304
304
|
initial: () => ({ lifecycle: Lifecycle.initial(), tools: ToolStream.empty(), finished: false }),
|
|
305
305
|
step,
|
|
306
306
|
terminal: (event) => event.type === "message-end",
|
|
307
|
-
onHalt: (state) => state.finished
|
|
308
|
-
? Effect.succeed([])
|
|
309
|
-
: Effect.fail(ProviderShared.eventError(ADAPTER, "Cohere stream ended without message-end")),
|
|
310
307
|
},
|
|
311
308
|
});
|
|
312
309
|
export const route = Route.make({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { SpeechModel, type
|
|
4
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
5
5
|
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.deepgram.com";
|
|
7
7
|
export declare const PATH = "/v1/speak";
|
|
@@ -14,7 +14,7 @@ export type DeepgramSpeechOptions = {
|
|
|
14
14
|
readonly mip_opt_out?: boolean;
|
|
15
15
|
readonly tag?: string;
|
|
16
16
|
} & Record<string, unknown>;
|
|
17
|
-
export type Request =
|
|
17
|
+
export type Request = SpeechRequest<SpeechModel<DeepgramSpeechOptions>>;
|
|
18
18
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
19
19
|
readonly type: "audio-delta";
|
|
20
20
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { TranscriptionModel, TranscriptionResponse, type
|
|
4
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequest } from "../transcription.js";
|
|
5
5
|
export declare const DEFAULT_BASE_URL = "https://api.deepgram.com";
|
|
6
6
|
export declare const PATH = "/v1/listen";
|
|
7
7
|
export type DeepgramTranscriptionOptions = {
|
|
@@ -17,7 +17,7 @@ export type DeepgramTranscriptionOptions = {
|
|
|
17
17
|
readonly mip_opt_out?: boolean;
|
|
18
18
|
readonly tag?: string | ReadonlyArray<string>;
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
|
-
export type Request =
|
|
20
|
+
export type Request = TranscriptionRequest<TranscriptionModel<DeepgramTranscriptionOptions>>;
|
|
21
21
|
export declare const protocol: MediaProtocol.Inline<Request, TranscriptionResponse>;
|
|
22
22
|
export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<DeepgramTranscriptionOptions>;
|
|
23
23
|
export declare const DeepgramTranscription: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { SpeechModel, type
|
|
4
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
5
5
|
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.elevenlabs.io";
|
|
7
7
|
export declare const PATH = "/v1/text-to-speech";
|
|
@@ -17,7 +17,7 @@ export type ElevenLabsSpeechOptions = {
|
|
|
17
17
|
readonly seed?: number;
|
|
18
18
|
readonly apply_text_normalization?: OpenString<"auto" | "on" | "off">;
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
|
-
export type Request =
|
|
20
|
+
export type Request = SpeechRequest<SpeechModel<ElevenLabsSpeechOptions>>;
|
|
21
21
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
22
22
|
readonly type: "audio-delta";
|
|
23
23
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { TranscriptionModel, TranscriptionResponse, type
|
|
4
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequest } from "../transcription.js";
|
|
5
5
|
export declare const DEFAULT_BASE_URL = "https://api.elevenlabs.io";
|
|
6
6
|
export declare const PATH = "/v1/speech-to-text";
|
|
7
7
|
export type ElevenLabsTranscriptionOptions = {
|
|
@@ -19,7 +19,7 @@ export type ElevenLabsTranscriptionOptions = {
|
|
|
19
19
|
readonly entity_redaction?: string | ReadonlyArray<string>;
|
|
20
20
|
readonly entity_redaction_mode?: OpenString<"redacted" | "entity_type" | "enumerated_entity_type">;
|
|
21
21
|
} & Record<string, unknown>;
|
|
22
|
-
export type Request =
|
|
22
|
+
export type Request = TranscriptionRequest<TranscriptionModel<ElevenLabsTranscriptionOptions>>;
|
|
23
23
|
export declare const protocol: MediaProtocol.Inline<Request, TranscriptionResponse>;
|
|
24
24
|
export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<ElevenLabsTranscriptionOptions>;
|
|
25
25
|
export declare const ElevenLabsTranscription: {
|
|
@@ -109,6 +109,7 @@ declare const GeminiUsage: Schema.Struct<{
|
|
|
109
109
|
readonly cachedContentTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
110
110
|
readonly thoughtsTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
111
111
|
readonly promptTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
112
|
+
readonly toolUsePromptTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
112
113
|
readonly candidatesTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
113
114
|
readonly totalTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
114
115
|
}>;
|
|
@@ -264,6 +265,7 @@ export declare const protocol: Protocol<{
|
|
|
264
265
|
readonly cachedContentTokenCount?: number | null | undefined;
|
|
265
266
|
readonly thoughtsTokenCount?: number | null | undefined;
|
|
266
267
|
readonly promptTokenCount?: number | null | undefined;
|
|
268
|
+
readonly toolUsePromptTokenCount?: number | null | undefined;
|
|
267
269
|
readonly candidatesTokenCount?: number | null | undefined;
|
|
268
270
|
readonly totalTokenCount?: number | null | undefined;
|
|
269
271
|
} | null | undefined;
|
|
@@ -292,6 +294,7 @@ export declare const protocol: Protocol<{
|
|
|
292
294
|
readonly cachedContentTokenCount?: number | null | undefined;
|
|
293
295
|
readonly thoughtsTokenCount?: number | null | undefined;
|
|
294
296
|
readonly promptTokenCount?: number | null | undefined;
|
|
297
|
+
readonly toolUsePromptTokenCount?: number | null | undefined;
|
|
295
298
|
readonly candidatesTokenCount?: number | null | undefined;
|
|
296
299
|
readonly totalTokenCount?: number | null | undefined;
|
|
297
300
|
} | null | undefined;
|