@opencode/ai 2.0.15 → 2.0.17
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 +441 -99
- package/dist/ai-client.d.ts +8 -0
- package/dist/ai-client.js +12 -0
- package/dist/experimental/evaluation-client.d.ts +3 -3
- package/dist/experimental/evaluation-client.js +1 -1
- package/dist/experimental/evaluation.js +1 -1
- package/dist/generation.d.ts +39 -29
- package/dist/generation.js +62 -36
- package/dist/image-client.d.ts +59 -17
- package/dist/image-client.js +16 -24
- package/dist/image.d.ts +394 -55
- package/dist/image.js +48 -57
- package/dist/index.d.ts +15 -2
- package/dist/index.js +10 -0
- package/dist/llm.d.ts +7 -5
- package/dist/llm.js +10 -4
- package/dist/media-client.d.ts +30 -0
- package/dist/media-client.js +51 -0
- package/dist/media-model.d.ts +43 -0
- package/dist/media-model.js +47 -0
- package/dist/media.d.ts +10 -9
- package/dist/media.js +11 -12
- package/dist/promise.d.ts +473 -15
- package/dist/promise.js +71 -13
- package/dist/protocols/alibaba-chat.d.ts +12 -0
- package/dist/protocols/alibaba-chat.js +4 -1
- package/dist/protocols/alibaba-messages.d.ts +1 -1
- package/dist/protocols/alibaba-messages.js +6 -4
- package/dist/protocols/alibaba-responses.d.ts +2 -2
- package/dist/protocols/anthropic-messages.d.ts +34 -34
- package/dist/protocols/anthropic-messages.js +14 -9
- package/dist/protocols/assemblyai-transcription.d.ts +41 -0
- package/dist/protocols/assemblyai-transcription.js +136 -0
- package/dist/protocols/bedrock-converse.d.ts +7 -0
- package/dist/protocols/bedrock-converse.js +39 -19
- package/dist/protocols/bfl-images.d.ts +38 -0
- package/dist/protocols/bfl-images.js +153 -0
- package/dist/protocols/cartesia-speech.d.ts +143 -0
- package/dist/protocols/cartesia-speech.js +120 -0
- package/dist/protocols/deepgram-speech.d.ts +135 -0
- package/dist/protocols/deepgram-speech.js +91 -0
- package/dist/protocols/deepgram-transcription.d.ts +26 -0
- package/dist/protocols/deepgram-transcription.js +125 -0
- package/dist/protocols/elevenlabs-speech.d.ts +138 -0
- package/dist/protocols/elevenlabs-speech.js +111 -0
- package/dist/protocols/fal-images.d.ts +25 -0
- package/dist/protocols/fal-images.js +104 -0
- package/dist/protocols/fal-video.d.ts +29 -0
- package/dist/protocols/fal-video.js +73 -0
- package/dist/protocols/gemini.d.ts +22 -22
- package/dist/protocols/gemini.js +19 -36
- package/dist/protocols/google-images.d.ts +3 -3
- package/dist/protocols/google-images.js +12 -34
- package/dist/protocols/google-speech.d.ts +146 -0
- package/dist/protocols/google-speech.js +88 -0
- package/dist/protocols/google-transcription.d.ts +174 -0
- package/dist/protocols/google-transcription.js +126 -0
- package/dist/protocols/google-video.d.ts +26 -0
- package/dist/protocols/google-video.js +142 -0
- package/dist/protocols/meta-images.d.ts +3 -4
- package/dist/protocols/meta-images.js +13 -29
- package/dist/protocols/meta-messages.d.ts +5 -5
- package/dist/protocols/meta-responses.d.ts +4 -4
- package/dist/protocols/meta-responses.js +6 -4
- package/dist/protocols/open-responses.d.ts +10 -9
- package/dist/protocols/open-responses.js +4 -9
- package/dist/protocols/openai-chat.d.ts +84 -0
- package/dist/protocols/openai-chat.js +28 -17
- package/dist/protocols/openai-compatible-chat.d.ts +12 -0
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-images.d.ts +130 -7
- package/dist/protocols/openai-images.js +143 -91
- package/dist/protocols/openai-responses.d.ts +20 -20
- package/dist/protocols/openai-responses.js +31 -31
- package/dist/protocols/openai-speech.d.ts +136 -0
- package/dist/protocols/openai-speech.js +97 -0
- package/dist/protocols/openai-transcription.d.ts +211 -0
- package/dist/protocols/openai-transcription.js +202 -0
- package/dist/protocols/replicate-images.d.ts +28 -0
- package/dist/protocols/replicate-images.js +127 -0
- package/dist/protocols/runway-video.d.ts +38 -0
- package/dist/protocols/runway-video.js +140 -0
- package/dist/protocols/shared.d.ts +21 -17
- package/dist/protocols/shared.js +27 -36
- package/dist/protocols/stability-images.d.ts +39 -0
- package/dist/protocols/stability-images.js +136 -0
- package/dist/protocols/utils/fal-queue.d.ts +26 -0
- package/dist/protocols/utils/fal-queue.js +67 -0
- package/dist/protocols/utils/gemini-generate-content.d.ts +65 -0
- package/dist/protocols/utils/gemini-generate-content.js +65 -0
- package/dist/protocols/utils/gemini-json-schema.d.ts +3 -0
- package/dist/protocols/utils/gemini-json-schema.js +76 -0
- package/dist/protocols/utils/media-input.d.ts +23 -1
- package/dist/protocols/utils/media-input.js +40 -0
- package/dist/protocols/utils/responses-checkpoint.js +3 -7
- package/dist/protocols/utils/responses-compaction.d.ts +3 -1
- package/dist/protocols/utils/responses-compaction.js +16 -3
- package/dist/protocols/utils/speech-stream.d.ts +49 -0
- package/dist/protocols/utils/speech-stream.js +64 -0
- package/dist/protocols/utils/tool-schema.d.ts +2 -2
- package/dist/protocols/utils/tool-schema.js +62 -19
- package/dist/protocols/xai-images.d.ts +4 -4
- package/dist/protocols/xai-images.js +14 -40
- package/dist/protocols/xai-responses.d.ts +2 -2
- package/dist/protocols/xai-responses.js +1 -1
- package/dist/protocols/xai-video.d.ts +34 -0
- package/dist/protocols/xai-video.js +141 -0
- package/dist/protocols/zai-chat.d.ts +13 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-images.js +11 -14
- package/dist/protocols/zai-messages.d.ts +1 -1
- package/dist/provider-error.js +10 -1
- package/dist/providers/alibaba.d.ts +15 -3
- package/dist/providers/amazon-bedrock-mantle.d.ts +14 -2
- package/dist/providers/amazon-bedrock.d.ts +2 -0
- package/dist/providers/amazon-bedrock.js +1 -0
- package/dist/providers/anthropic-compatible.d.ts +5 -5
- package/dist/providers/anthropic.d.ts +5 -5
- package/dist/providers/assemblyai.d.ts +25 -0
- package/dist/providers/assemblyai.js +24 -0
- package/dist/providers/azure.d.ts +20 -8
- package/dist/providers/azure.js +2 -2
- package/dist/providers/baseten.d.ts +24 -0
- package/dist/providers/black-forest-labs.d.ts +25 -0
- package/dist/providers/black-forest-labs.js +23 -0
- package/dist/providers/cartesia.d.ts +24 -0
- package/dist/providers/cartesia.js +17 -0
- package/dist/providers/cerebras.d.ts +24 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +42 -18
- package/dist/providers/cloudflare-workers-ai.d.ts +24 -0
- package/dist/providers/deepgram.d.ts +29 -0
- package/dist/providers/deepgram.js +25 -0
- package/dist/providers/deepinfra.d.ts +24 -0
- package/dist/providers/deepseek.d.ts +24 -0
- package/dist/providers/elevenlabs.d.ts +24 -0
- package/dist/providers/elevenlabs.js +23 -0
- package/dist/providers/fal.d.ts +29 -0
- package/dist/providers/fal.js +26 -0
- package/dist/providers/fireworks.d.ts +24 -0
- package/dist/providers/google-vertex-chat.d.ts +12 -0
- package/dist/providers/google-vertex-messages.d.ts +5 -5
- package/dist/providers/google-vertex-responses.d.ts +2 -2
- package/dist/providers/google-vertex.d.ts +6 -6
- package/dist/providers/google.d.ts +21 -6
- package/dist/providers/google.js +13 -9
- package/dist/providers/groq.d.ts +24 -0
- package/dist/providers/index.d.ts +9 -0
- package/dist/providers/index.js +9 -0
- package/dist/providers/meta.d.ts +22 -10
- package/dist/providers/meta.js +4 -8
- package/dist/providers/minimax.d.ts +19 -7
- package/dist/providers/moonshot.d.ts +19 -7
- package/dist/providers/moonshot.js +3 -3
- package/dist/providers/openai-compatible-responses.d.ts +2 -2
- package/dist/providers/openai-compatible.d.ts +12 -0
- package/dist/providers/openai-options.d.ts +3 -9
- package/dist/providers/openai-options.js +4 -7
- package/dist/providers/openai.d.ts +33 -12
- package/dist/providers/openai.js +17 -9
- package/dist/providers/opencode-zen.js +1 -1
- package/dist/providers/openrouter.d.ts +54 -7
- package/dist/providers/openrouter.js +10 -5
- package/dist/providers/replicate.d.ts +25 -0
- package/dist/providers/replicate.js +17 -0
- package/dist/providers/runway.d.ts +24 -0
- package/dist/providers/runway.js +17 -0
- package/dist/providers/stability.d.ts +28 -0
- package/dist/providers/stability.js +18 -0
- package/dist/providers/togetherai.d.ts +24 -0
- package/dist/providers/typesafe-ai.js +1 -1
- package/dist/providers/vercel-ai-gateway.js +1 -1
- package/dist/providers/xai.d.ts +17 -0
- package/dist/providers/xai.js +7 -9
- package/dist/providers/zai-coding-plan.d.ts +16 -4
- package/dist/providers/zai.d.ts +13 -1
- package/dist/providers/zai.js +4 -8
- package/dist/route/auth.d.ts +5 -2
- package/dist/route/auth.js +20 -13
- package/dist/route/client.d.ts +9 -7
- package/dist/route/client.js +6 -8
- package/dist/route/endpoint.d.ts +1 -0
- package/dist/route/endpoint.js +2 -2
- package/dist/route/executor-service.d.ts +4 -2
- package/dist/route/executor-service.js +2 -1
- package/dist/route/executor.d.ts +3 -1
- package/dist/route/executor.js +7 -0
- package/dist/route/framing.d.ts +15 -2
- package/dist/route/framing.js +53 -4
- package/dist/route/index.d.ts +1 -1
- package/dist/route/media-protocol.d.ts +145 -18
- package/dist/route/media-protocol.js +96 -28
- package/dist/route/media.d.ts +54 -9
- package/dist/route/media.js +194 -38
- package/dist/route/protocol.d.ts +3 -1
- package/dist/schema/events.d.ts +0 -6
- package/dist/schema/messages.d.ts +0 -3
- package/dist/schema/options.d.ts +10 -6
- package/dist/schema/options.js +10 -5
- package/dist/speech-client.d.ts +66 -0
- package/dist/speech-client.js +21 -0
- package/dist/speech.d.ts +1307 -0
- package/dist/speech.js +124 -0
- package/dist/testing.d.ts +2 -2
- package/dist/transcription-client.d.ts +82 -0
- package/dist/transcription-client.js +13 -0
- package/dist/transcription.d.ts +1492 -0
- package/dist/transcription.js +127 -0
- package/dist/utils/bytes.d.ts +1 -0
- package/dist/utils/bytes.js +10 -0
- package/dist/utils/json.d.ts +4 -0
- package/dist/utils/json.js +4 -0
- package/dist/utils/media-type.d.ts +3 -1
- package/dist/utils/media-type.js +25 -2
- package/dist/video-client.d.ts +59 -0
- package/dist/video-client.js +20 -0
- package/dist/video.d.ts +1351 -0
- package/dist/video.js +118 -0
- package/package.json +3 -3
- package/dist/protocols/utils/gemini-tool-schema.d.ts +0 -2
- package/dist/protocols/utils/gemini-tool-schema.js +0 -103
- package/dist/protocols/utils/meta-image.d.ts +0 -2
- package/dist/protocols/utils/meta-image.js +0 -13
- package/dist/protocols/utils/openai-image.d.ts +0 -5
- package/dist/protocols/utils/openai-image.js +0 -18
|
@@ -50,6 +50,12 @@ export declare const protocol: Protocol<{
|
|
|
50
50
|
readonly image_url: {
|
|
51
51
|
readonly url: string;
|
|
52
52
|
};
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: "file";
|
|
55
|
+
readonly file: {
|
|
56
|
+
readonly filename: string;
|
|
57
|
+
readonly file_data: string;
|
|
58
|
+
};
|
|
53
59
|
})[];
|
|
54
60
|
} | {
|
|
55
61
|
readonly role: "user";
|
|
@@ -65,6 +71,12 @@ export declare const protocol: Protocol<{
|
|
|
65
71
|
readonly image_url: {
|
|
66
72
|
readonly url: string;
|
|
67
73
|
};
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: "file";
|
|
76
|
+
readonly file: {
|
|
77
|
+
readonly filename: string;
|
|
78
|
+
readonly file_data: string;
|
|
79
|
+
};
|
|
68
80
|
})[];
|
|
69
81
|
} | {
|
|
70
82
|
readonly [x: string]: unknown;
|
|
@@ -55,7 +55,10 @@ export const protocol = Protocol.make({
|
|
|
55
55
|
return {
|
|
56
56
|
...(yield* OpenAIChat.protocol.body.from(req)),
|
|
57
57
|
enable_thinking: opts.enableThinking,
|
|
58
|
-
|
|
58
|
+
// Alibaba also rejects an explicit budget that is not below `max_completion_tokens`.
|
|
59
|
+
thinking_budget: opts.thinkingBudget === undefined
|
|
60
|
+
? undefined
|
|
61
|
+
: ProviderShared.fitThinkingBudget(opts.thinkingBudget, req.generation?.maxTokens),
|
|
59
62
|
preserve_thinking: opts.preserveThinking,
|
|
60
63
|
clear_thinking: opts.clearThinking,
|
|
61
64
|
thinking: opts.thinking,
|
|
@@ -228,7 +228,7 @@ export declare const protocol: Protocol<{
|
|
|
228
228
|
readonly type: string;
|
|
229
229
|
readonly budget_tokens?: number | undefined;
|
|
230
230
|
} | undefined;
|
|
231
|
-
readonly service_tier?: "auto" |
|
|
231
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
|
|
232
232
|
readonly container?: string | {
|
|
233
233
|
readonly id?: string | null | undefined;
|
|
234
234
|
readonly skills?: readonly {
|
|
@@ -22,15 +22,17 @@ export const protocol = Protocol.make({
|
|
|
22
22
|
from: Effect.fn("AlibabaMessages.fromRequest")(function* (req) {
|
|
23
23
|
const opts = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(req.providerOptions ?? {});
|
|
24
24
|
// Model Studio accepts enabled thinking without Anthropic's mandatory token budget.
|
|
25
|
+
const body = yield* AnthropicMessages.protocol.body.from(LLMRequest.update(req, {
|
|
26
|
+
providerOptions: { ...req.providerOptions, thinking: undefined },
|
|
27
|
+
}));
|
|
28
|
+
const budget = opts.thinking?.budgetTokens ?? opts.thinking?.budget_tokens;
|
|
25
29
|
return {
|
|
26
|
-
...
|
|
27
|
-
providerOptions: { ...req.providerOptions, thinking: undefined },
|
|
28
|
-
}))),
|
|
30
|
+
...body,
|
|
29
31
|
thinking: opts.thinking === undefined
|
|
30
32
|
? undefined
|
|
31
33
|
: {
|
|
32
34
|
type: opts.thinking.type,
|
|
33
|
-
budget_tokens:
|
|
35
|
+
budget_tokens: budget === undefined ? undefined : ProviderShared.fitThinkingBudget(budget, body.max_tokens),
|
|
34
36
|
},
|
|
35
37
|
};
|
|
36
38
|
}),
|
|
@@ -77,8 +77,8 @@ export declare const protocol: Protocol<{
|
|
|
77
77
|
} | {
|
|
78
78
|
readonly type: "input_file";
|
|
79
79
|
readonly filename: string;
|
|
80
|
-
readonly detail?: string | undefined;
|
|
81
80
|
readonly file_data?: string | undefined;
|
|
81
|
+
readonly detail?: string | undefined;
|
|
82
82
|
readonly file_url?: string | undefined;
|
|
83
83
|
} | {
|
|
84
84
|
readonly type: "input_text";
|
|
@@ -114,8 +114,8 @@ export declare const protocol: Protocol<{
|
|
|
114
114
|
} | {
|
|
115
115
|
readonly type: "input_file";
|
|
116
116
|
readonly filename: string;
|
|
117
|
-
readonly detail?: string | undefined;
|
|
118
117
|
readonly file_data?: string | undefined;
|
|
118
|
+
readonly detail?: string | undefined;
|
|
119
119
|
readonly file_url?: string | undefined;
|
|
120
120
|
} | {
|
|
121
121
|
readonly type: "input_text";
|
|
@@ -28,33 +28,33 @@ export declare const ContextManagement: Schema.Struct<{
|
|
|
28
28
|
}>;
|
|
29
29
|
export type ContextManagement = typeof ContextManagement.Type;
|
|
30
30
|
declare const AnthropicThinkingBlockBinding: Schema.Struct<{
|
|
31
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
31
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
32
32
|
}>;
|
|
33
33
|
declare const Thinking: Schema.Union<readonly [Schema.decodeTo<Schema.Struct<{
|
|
34
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
34
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
35
35
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
36
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
36
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
37
37
|
}>>;
|
|
38
38
|
readonly type: Schema.tag<"enabled">;
|
|
39
39
|
readonly budget_tokens: Schema.Number;
|
|
40
40
|
}>, Schema.Union<readonly [Schema.Struct<{
|
|
41
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
41
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
42
42
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
43
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
43
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
44
44
|
}>>;
|
|
45
45
|
readonly type: Schema.tag<"enabled">;
|
|
46
46
|
readonly budgetTokens: Schema.Number;
|
|
47
47
|
}>, Schema.Struct<{
|
|
48
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
48
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
49
49
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
50
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
50
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
51
51
|
}>>;
|
|
52
52
|
readonly type: Schema.tag<"enabled">;
|
|
53
53
|
readonly budget_tokens: Schema.Number;
|
|
54
54
|
}>]>, never, never>, Schema.Struct<{
|
|
55
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
55
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
56
56
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
57
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
57
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
58
58
|
}>>;
|
|
59
59
|
readonly type: Schema.tag<"adaptive">;
|
|
60
60
|
}>, Schema.Struct<{
|
|
@@ -74,38 +74,38 @@ declare const Options: Schema.Struct<{
|
|
|
74
74
|
}>>;
|
|
75
75
|
}>>;
|
|
76
76
|
readonly thinking: Schema.optional<Schema.Union<readonly [Schema.decodeTo<Schema.Struct<{
|
|
77
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
77
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
78
78
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
79
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
79
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
80
80
|
}>>;
|
|
81
81
|
readonly type: Schema.tag<"enabled">;
|
|
82
82
|
readonly budget_tokens: Schema.Number;
|
|
83
83
|
}>, Schema.Union<readonly [Schema.Struct<{
|
|
84
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
84
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
85
85
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
86
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
86
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
87
87
|
}>>;
|
|
88
88
|
readonly type: Schema.tag<"enabled">;
|
|
89
89
|
readonly budgetTokens: Schema.Number;
|
|
90
90
|
}>, Schema.Struct<{
|
|
91
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
91
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
92
92
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
93
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
93
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
94
94
|
}>>;
|
|
95
95
|
readonly type: Schema.tag<"enabled">;
|
|
96
96
|
readonly budget_tokens: Schema.Number;
|
|
97
97
|
}>]>, never, never>, Schema.Struct<{
|
|
98
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
98
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
99
99
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
100
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
100
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
101
101
|
}>>;
|
|
102
102
|
readonly type: Schema.tag<"adaptive">;
|
|
103
103
|
}>, Schema.Struct<{
|
|
104
104
|
readonly type: Schema.tag<"disabled">;
|
|
105
105
|
}>]>>;
|
|
106
106
|
readonly effort: Schema.optional<Schema.String>;
|
|
107
|
-
readonly service_tier: Schema.optional<Schema.declare<"auto" |
|
|
108
|
-
readonly serviceTier: Schema.optional<Schema.declare<"auto" |
|
|
107
|
+
readonly service_tier: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"auto" | "standard_only">, import("../schema/options.js").OpenString<"auto" | "standard_only">>>;
|
|
108
|
+
readonly serviceTier: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"auto" | "standard_only">, import("../schema/options.js").OpenString<"auto" | "standard_only">>>;
|
|
109
109
|
readonly metadata: Schema.optional<Schema.Struct<{
|
|
110
110
|
readonly user_id: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
111
111
|
}>>;
|
|
@@ -369,16 +369,16 @@ export declare const AnthropicMessagesBody: Schema.Struct<{
|
|
|
369
369
|
top_k: Schema.optional<Schema.Number>;
|
|
370
370
|
stop_sequences: Schema.optional<Schema.$Array<Schema.String>>;
|
|
371
371
|
thinking: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
372
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
372
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
373
373
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
374
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
374
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
375
375
|
}>>;
|
|
376
376
|
readonly type: Schema.tag<"enabled">;
|
|
377
377
|
readonly budget_tokens: Schema.Number;
|
|
378
378
|
}>, Schema.Struct<{
|
|
379
|
-
readonly display: Schema.optional<Schema.declare<(
|
|
379
|
+
readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"summarized" | "omitted">, import("../schema/options.js").OpenString<"summarized" | "omitted">>>;
|
|
380
380
|
readonly block_binding: Schema.optional<Schema.Struct<{
|
|
381
|
-
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<(
|
|
381
|
+
readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"error" | "drop_block">, import("../schema/options.js").OpenString<"error" | "drop_block">>>;
|
|
382
382
|
}>>;
|
|
383
383
|
readonly type: Schema.tag<"adaptive">;
|
|
384
384
|
}>, Schema.Struct<{
|
|
@@ -403,7 +403,7 @@ export declare const AnthropicMessagesBody: Schema.Struct<{
|
|
|
403
403
|
metadata: Schema.optional<Schema.Struct<{
|
|
404
404
|
readonly user_id: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
405
405
|
}>>;
|
|
406
|
-
service_tier: Schema.optional<Schema.declare<"auto" |
|
|
406
|
+
service_tier: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"auto" | "standard_only">, import("../schema/options.js").OpenString<"auto" | "standard_only">>>;
|
|
407
407
|
}>;
|
|
408
408
|
export type AnthropicMessagesBody = Schema.Schema.Type<typeof AnthropicMessagesBody>;
|
|
409
409
|
/**
|
|
@@ -627,20 +627,20 @@ export declare const protocol: Protocol<{
|
|
|
627
627
|
readonly thinking?: {
|
|
628
628
|
readonly type: "enabled";
|
|
629
629
|
readonly budget_tokens: number;
|
|
630
|
-
readonly display?: (
|
|
630
|
+
readonly display?: import("../schema/options.js").OpenString<"summarized" | "omitted"> | undefined;
|
|
631
631
|
readonly block_binding?: {
|
|
632
|
-
readonly prefix_mismatch_behavior?: (
|
|
632
|
+
readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"error" | "drop_block"> | undefined;
|
|
633
633
|
} | undefined;
|
|
634
634
|
} | {
|
|
635
635
|
readonly type: "adaptive";
|
|
636
|
-
readonly display?: (
|
|
636
|
+
readonly display?: import("../schema/options.js").OpenString<"summarized" | "omitted"> | undefined;
|
|
637
637
|
readonly block_binding?: {
|
|
638
|
-
readonly prefix_mismatch_behavior?: (
|
|
638
|
+
readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"error" | "drop_block"> | undefined;
|
|
639
639
|
} | undefined;
|
|
640
640
|
} | {
|
|
641
641
|
readonly type: "disabled";
|
|
642
642
|
} | undefined;
|
|
643
|
-
readonly service_tier?: "auto" |
|
|
643
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
|
|
644
644
|
readonly container?: string | {
|
|
645
645
|
readonly id?: string | null | undefined;
|
|
646
646
|
readonly skills?: readonly {
|
|
@@ -984,20 +984,20 @@ export declare const route: Route<{
|
|
|
984
984
|
readonly thinking?: {
|
|
985
985
|
readonly type: "enabled";
|
|
986
986
|
readonly budget_tokens: number;
|
|
987
|
-
readonly display?: (
|
|
987
|
+
readonly display?: import("../schema/options.js").OpenString<"summarized" | "omitted"> | undefined;
|
|
988
988
|
readonly block_binding?: {
|
|
989
|
-
readonly prefix_mismatch_behavior?: (
|
|
989
|
+
readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"error" | "drop_block"> | undefined;
|
|
990
990
|
} | undefined;
|
|
991
991
|
} | {
|
|
992
992
|
readonly type: "adaptive";
|
|
993
|
-
readonly display?: (
|
|
993
|
+
readonly display?: import("../schema/options.js").OpenString<"summarized" | "omitted"> | undefined;
|
|
994
994
|
readonly block_binding?: {
|
|
995
|
-
readonly prefix_mismatch_behavior?: (
|
|
995
|
+
readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"error" | "drop_block"> | undefined;
|
|
996
996
|
} | undefined;
|
|
997
997
|
} | {
|
|
998
998
|
readonly type: "disabled";
|
|
999
999
|
} | undefined;
|
|
1000
|
-
readonly service_tier?: "auto" |
|
|
1000
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
|
|
1001
1001
|
readonly container?: string | {
|
|
1002
1002
|
readonly id?: string | null | undefined;
|
|
1003
1003
|
readonly skills?: readonly {
|
|
@@ -14,12 +14,12 @@ import { classifyProviderFailure } from "../provider-error.js";
|
|
|
14
14
|
import { effortUpdate, resolveEffortUpdates } from "../effort-updates.js";
|
|
15
15
|
import * as Cache from "./utils/cache.js";
|
|
16
16
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
17
|
-
import { ToolSchemaProjection } from "./utils/tool-schema.js";
|
|
18
17
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
19
18
|
const ADAPTER = "anthropic-messages";
|
|
20
19
|
export const DEFAULT_BASE_URL = "https://api.anthropic.com/v1";
|
|
21
20
|
export const PATH = "/messages";
|
|
22
21
|
export const DEFAULT_MAX_TOKENS = 32_000;
|
|
22
|
+
const MIN_THINKING_BUDGET = 1_024;
|
|
23
23
|
const DEFAULT_EFFORT = "high";
|
|
24
24
|
const SSE_EVENTS = new Set([
|
|
25
25
|
"message",
|
|
@@ -407,10 +407,10 @@ const redactedDataFromMetadata = (metadata, key) => {
|
|
|
407
407
|
return undefined;
|
|
408
408
|
return typeof provider.redactedData === "string" ? provider.redactedData : undefined;
|
|
409
409
|
};
|
|
410
|
-
const lowerTool = (breakpoints, tool
|
|
410
|
+
const lowerTool = (breakpoints, tool) => ({
|
|
411
411
|
name: tool.name,
|
|
412
412
|
description: tool.description,
|
|
413
|
-
input_schema: inputSchema,
|
|
413
|
+
input_schema: tool.inputSchema,
|
|
414
414
|
cache_control: cacheControl(breakpoints, tool.cache),
|
|
415
415
|
});
|
|
416
416
|
const lowerToolChoice = (toolChoice) => ProviderShared.matchToolChoice("Anthropic Messages", toolChoice, {
|
|
@@ -890,6 +890,13 @@ const applyThinkingBindingDefault = (model, thinking) => {
|
|
|
890
890
|
},
|
|
891
891
|
};
|
|
892
892
|
};
|
|
893
|
+
// Anthropic also requires an explicit thinking budget below `max_tokens` and at or above its minimum.
|
|
894
|
+
const fitThinking = (thinking, maxTokens) => thinking?.type === "enabled"
|
|
895
|
+
? {
|
|
896
|
+
...thinking,
|
|
897
|
+
budget_tokens: ProviderShared.fitThinkingBudget(thinking.budget_tokens, maxTokens, MIN_THINKING_BUDGET),
|
|
898
|
+
}
|
|
899
|
+
: thinking;
|
|
893
900
|
const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (request) {
|
|
894
901
|
const options = yield* decodeOptions(request.providerOptions ?? {});
|
|
895
902
|
const management = options.contextManagement;
|
|
@@ -897,15 +904,12 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
897
904
|
const format = outputConfig?.format ?? undefined;
|
|
898
905
|
const updates = resolveEffortUpdates(request, options.effort ?? outputConfig?.effort ?? undefined);
|
|
899
906
|
const generation = request.generation;
|
|
900
|
-
const toolSchemaCompatibility = request.model.compatibility?.toolSchema;
|
|
901
907
|
// Allocate the 4-breakpoint budget in invalidation order: tools → system →
|
|
902
908
|
// messages. Tools live highest in the cache hierarchy, so when callers
|
|
903
909
|
// over-mark we keep their tool hints and shed the message-tail ones first.
|
|
904
910
|
const breakpoints = Cache.newBreakpoints(ANTHROPIC_BREAKPOINT_CAP);
|
|
905
911
|
const flattened = ProviderShared.flattenToolRequest(updates.request);
|
|
906
|
-
const tools = flattened.tools.length === 0
|
|
907
|
-
? undefined
|
|
908
|
-
: flattened.tools.map((tool) => lowerTool(breakpoints, tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, toolSchemaCompatibility)));
|
|
912
|
+
const tools = flattened.tools.length === 0 ? undefined : flattened.tools.map((tool) => lowerTool(breakpoints, tool));
|
|
909
913
|
// Anthropic rejects tool_choice when tools are absent; "none" is only meaningful with tools present.
|
|
910
914
|
const toolChoice = tools === undefined || !request.toolChoice ? undefined : yield* lowerToolChoice(request.toolChoice);
|
|
911
915
|
const systemParts = request.system.filter((part) => part.text.length > 0);
|
|
@@ -921,6 +925,7 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
921
925
|
yield* Effect.logWarning(`Anthropic Messages: dropped ${breakpoints.dropped} cache breakpoint(s); the API allows at most ${ANTHROPIC_BREAKPOINT_CAP} per request.`);
|
|
922
926
|
}
|
|
923
927
|
const output_config = updates.effort === undefined && format === undefined ? undefined : { effort: updates.effort, format };
|
|
928
|
+
const maxTokens = generation?.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
924
929
|
const body = {
|
|
925
930
|
model: request.model.id,
|
|
926
931
|
system,
|
|
@@ -928,12 +933,12 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
928
933
|
tools,
|
|
929
934
|
tool_choice: toolChoice,
|
|
930
935
|
stream: true,
|
|
931
|
-
max_tokens:
|
|
936
|
+
max_tokens: maxTokens,
|
|
932
937
|
temperature: generation?.temperature,
|
|
933
938
|
top_p: generation?.topP,
|
|
934
939
|
top_k: generation?.topK,
|
|
935
940
|
stop_sequences: generation?.stop,
|
|
936
|
-
thinking: applyThinkingBindingDefault(request.model, options.thinking),
|
|
941
|
+
thinking: applyThinkingBindingDefault(request.model, fitThinking(options.thinking, maxTokens)),
|
|
937
942
|
output_config,
|
|
938
943
|
// top-level passthrough per SDK MessageCreateParamsBase:4638,4643,4649,4654,4670
|
|
939
944
|
cache_control: options.cache_control ?? options.cacheControl,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { type OpenString } from "../schema/index.js";
|
|
5
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequestFor } from "../transcription.js";
|
|
6
|
+
export declare const DEFAULT_BASE_URL = "https://api.assemblyai.com";
|
|
7
|
+
export declare const PATH = "/v2/transcript";
|
|
8
|
+
export declare const UPLOAD_PATH = "/v2/upload";
|
|
9
|
+
export type AssemblyAITranscriptionOptions = {
|
|
10
|
+
readonly keyterms_prompt?: ReadonlyArray<string>;
|
|
11
|
+
readonly punctuate?: boolean;
|
|
12
|
+
readonly format_text?: boolean;
|
|
13
|
+
readonly disfluencies?: boolean;
|
|
14
|
+
readonly filter_profanity?: boolean;
|
|
15
|
+
readonly temperature?: number;
|
|
16
|
+
readonly speaker_options?: {
|
|
17
|
+
readonly min_speakers_expected?: number;
|
|
18
|
+
readonly max_speakers_expected?: number;
|
|
19
|
+
};
|
|
20
|
+
readonly language_detection_options?: {
|
|
21
|
+
readonly expected_languages?: ReadonlyArray<string>;
|
|
22
|
+
readonly fallback_language?: string;
|
|
23
|
+
readonly code_switching?: boolean;
|
|
24
|
+
};
|
|
25
|
+
readonly speech_models?: ReadonlyArray<OpenString<"universal-3-5-pro" | "universal-2">>;
|
|
26
|
+
} & Record<string, unknown>;
|
|
27
|
+
export type Request = TranscriptionRequestFor<AssemblyAITranscriptionOptions>;
|
|
28
|
+
export declare const Token: Schema.Struct<{
|
|
29
|
+
readonly transcriptID: Schema.String;
|
|
30
|
+
}>;
|
|
31
|
+
export type Token = Schema.Schema.Type<typeof Token>;
|
|
32
|
+
export declare const protocol: MediaProtocol.Queued<Request, TranscriptionResponse, {
|
|
33
|
+
readonly transcriptID: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<AssemblyAITranscriptionOptions>;
|
|
36
|
+
export declare const AssemblyAITranscription: {
|
|
37
|
+
readonly protocol: MediaProtocol.Queued<Request, TranscriptionResponse, {
|
|
38
|
+
readonly transcriptID: string;
|
|
39
|
+
}>;
|
|
40
|
+
readonly model: (input: MediaRoute.ModelInput) => TranscriptionModel<AssemblyAITranscriptionOptions>;
|
|
41
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Media } from "../media.js";
|
|
3
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
+
import { MediaRoute } from "../route/media.js";
|
|
5
|
+
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { TranscriptionModel, TranscriptionResponse } from "../transcription.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
9
|
+
const route = MediaProtocol.identity({ id: "assemblyai-transcription", name: "AssemblyAI", provider: "assemblyai" });
|
|
10
|
+
export const DEFAULT_BASE_URL = "https://api.assemblyai.com";
|
|
11
|
+
export const PATH = "/v2/transcript";
|
|
12
|
+
export const UPLOAD_PATH = "/v2/upload";
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// 2. Token and response schemas
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
export const Token = Schema.Struct({ transcriptID: Schema.String });
|
|
17
|
+
const Upload = Schema.Struct({ upload_url: Schema.String });
|
|
18
|
+
/** Word and utterance times are milliseconds. */
|
|
19
|
+
const Transcript = Schema.Struct({
|
|
20
|
+
id: Schema.String,
|
|
21
|
+
status: Schema.String,
|
|
22
|
+
text: optionalNull(Schema.String),
|
|
23
|
+
words: optionalNull(Schema.Array(Schema.Struct({
|
|
24
|
+
text: Schema.String,
|
|
25
|
+
start: Schema.Number,
|
|
26
|
+
end: Schema.Number,
|
|
27
|
+
confidence: optionalNull(Schema.Number),
|
|
28
|
+
speaker: optionalNull(Schema.String),
|
|
29
|
+
}))),
|
|
30
|
+
utterances: optionalNull(Schema.Array(Schema.Struct({
|
|
31
|
+
text: Schema.String,
|
|
32
|
+
start: Schema.Number,
|
|
33
|
+
end: Schema.Number,
|
|
34
|
+
speaker: optionalNull(Schema.String),
|
|
35
|
+
}))),
|
|
36
|
+
language_code: optionalNull(Schema.String),
|
|
37
|
+
audio_duration: optionalNull(Schema.Number),
|
|
38
|
+
speech_model_used: optionalNull(Schema.String),
|
|
39
|
+
error: optionalNull(Schema.String),
|
|
40
|
+
});
|
|
41
|
+
const STATUS = {
|
|
42
|
+
queued: "queued",
|
|
43
|
+
processing: "running",
|
|
44
|
+
completed: "completed",
|
|
45
|
+
error: "failed",
|
|
46
|
+
};
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// 5. Request body construction
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
const decodeUpload = route.decodeJson(Upload);
|
|
51
|
+
/** `/v2/transcript` only takes a URL, so inline audio is uploaded to `/v2/upload` first. */
|
|
52
|
+
const prepare = Effect.fn("AssemblyAITranscription.prepare")(function* (request, send) {
|
|
53
|
+
if (request.audio.source.type !== "bytes" && request.audio.source.type !== "base64")
|
|
54
|
+
return request;
|
|
55
|
+
const audio = yield* MediaInput.inlineBytes(route.id, request.audio);
|
|
56
|
+
const uploaded = yield* send(UPLOAD_PATH, MediaProtocol.binary(audio, "application/octet-stream")).pipe(Effect.flatMap(decodeUpload));
|
|
57
|
+
return { ...request, audio: Media.url(uploaded.value.upload_url, { mediaType: request.audio.mediaType }) };
|
|
58
|
+
});
|
|
59
|
+
const fromRequest = Effect.fn("AssemblyAITranscription.fromRequest")(function* (request) {
|
|
60
|
+
const audio = yield* ProviderShared.mediaReference(request.audio, route.provider, route.name);
|
|
61
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
62
|
+
audio_url: audio.value,
|
|
63
|
+
speech_models: [request.model.id],
|
|
64
|
+
language_code: request.language,
|
|
65
|
+
language_detection: request.language === undefined ? true : undefined,
|
|
66
|
+
prompt: request.prompt,
|
|
67
|
+
// Turn-level `utterances`, the only segments AssemblyAI returns, and `speakers_expected` require speaker labels.
|
|
68
|
+
speaker_labels: request.diarize === true || request.timestamps === "segment" || request.speakers !== undefined
|
|
69
|
+
? true
|
|
70
|
+
: undefined,
|
|
71
|
+
speakers_expected: request.speakers,
|
|
72
|
+
}, request.providerOptions, request.http?.body) ?? {});
|
|
73
|
+
});
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// 6. Response decoding
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
const decodeTranscript = route.decodeJson(Transcript);
|
|
78
|
+
const decodeStart = Effect.fn("AssemblyAITranscription.decodeStart")(function* (response) {
|
|
79
|
+
const output = yield* decodeTranscript(response);
|
|
80
|
+
const status = yield* MediaProtocol.status(STATUS, output.value.status, output);
|
|
81
|
+
return { token: { transcriptID: output.value.id }, snapshot: { id: output.value.id, status } };
|
|
82
|
+
});
|
|
83
|
+
const decodeStatus = Effect.fn("AssemblyAITranscription.decodeStatus")(function* (response, context) {
|
|
84
|
+
const output = yield* decodeTranscript(response);
|
|
85
|
+
const status = yield* MediaProtocol.status(STATUS, output.value.status, output);
|
|
86
|
+
return { id: context.token.transcriptID, status };
|
|
87
|
+
});
|
|
88
|
+
const seconds = (milliseconds) => milliseconds / 1000;
|
|
89
|
+
const decodeResult = Effect.fn("AssemblyAITranscription.decodeResult")(function* (response, context) {
|
|
90
|
+
const output = yield* decodeTranscript(response);
|
|
91
|
+
const transcript = output.value;
|
|
92
|
+
const status = yield* MediaProtocol.status(STATUS, transcript.status, output);
|
|
93
|
+
const error = transcript.error ?? undefined;
|
|
94
|
+
if (status === "failed")
|
|
95
|
+
return yield* output.ended("failed", `${route.name} transcription failed${error === undefined ? "" : `: ${error}`}`);
|
|
96
|
+
if (status !== "completed")
|
|
97
|
+
return yield* output.pending(context.token.transcriptID);
|
|
98
|
+
const duration = transcript.audio_duration ?? undefined;
|
|
99
|
+
return new TranscriptionResponse({
|
|
100
|
+
text: transcript.text ?? "",
|
|
101
|
+
segments: transcript.utterances?.map((utterance) => ({
|
|
102
|
+
text: utterance.text,
|
|
103
|
+
startSeconds: seconds(utterance.start),
|
|
104
|
+
endSeconds: seconds(utterance.end),
|
|
105
|
+
speaker: utterance.speaker ?? undefined,
|
|
106
|
+
})),
|
|
107
|
+
words: transcript.words?.map((word) => ({
|
|
108
|
+
text: word.text,
|
|
109
|
+
startSeconds: seconds(word.start),
|
|
110
|
+
endSeconds: seconds(word.end),
|
|
111
|
+
speaker: word.speaker ?? undefined,
|
|
112
|
+
confidence: word.confidence ?? undefined,
|
|
113
|
+
})),
|
|
114
|
+
language: transcript.language_code?.toLowerCase(),
|
|
115
|
+
durationSeconds: duration,
|
|
116
|
+
usage: duration === undefined ? undefined : { type: "seconds", seconds: duration },
|
|
117
|
+
providerMetadata: {
|
|
118
|
+
assemblyai: { transcriptId: transcript.id, speechModel: transcript.speech_model_used ?? undefined },
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
// 7. Protocol and route
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
const transcriptPath = (token) => `${PATH}/${token.transcriptID}`;
|
|
126
|
+
export const protocol = MediaProtocol.queued(route, {
|
|
127
|
+
token: Token,
|
|
128
|
+
start: { prepare, body: { from: fromRequest }, decode: decodeStart },
|
|
129
|
+
status: { path: transcriptPath, decode: decodeStatus },
|
|
130
|
+
result: { path: transcriptPath, decode: decodeResult },
|
|
131
|
+
});
|
|
132
|
+
export const model = (input) => TranscriptionModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
133
|
+
export const AssemblyAITranscription = {
|
|
134
|
+
protocol,
|
|
135
|
+
model,
|
|
136
|
+
};
|
|
@@ -126,6 +126,13 @@ declare const BedrockConverseBody: Schema.Struct<{
|
|
|
126
126
|
additionalModelRequestFields: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
127
127
|
}>;
|
|
128
128
|
export type BedrockConverseBody = Schema.Schema.Type<typeof BedrockConverseBody>;
|
|
129
|
+
declare const Options: Schema.Struct<{
|
|
130
|
+
readonly thinking: Schema.optional<Schema.Struct<{
|
|
131
|
+
readonly type: Schema.Literal<"enabled">;
|
|
132
|
+
readonly budgetTokens: Schema.Number;
|
|
133
|
+
}>>;
|
|
134
|
+
}>;
|
|
135
|
+
export type OptionsInput = typeof Options.Type;
|
|
129
136
|
interface ParserState {
|
|
130
137
|
readonly providerMetadataKey: string;
|
|
131
138
|
readonly tools: ToolStream.State<number>;
|