@opencode/ai 2.1.2 → 2.1.4
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/dist/cache-policy.js +6 -5
- package/dist/experimental/evaluation.d.ts +7 -6
- package/dist/experimental/evaluation.js +3 -11
- package/dist/experimental/realtime.d.ts +59 -0
- package/dist/experimental/realtime.js +21 -13
- package/dist/experimental.d.ts +1 -1
- package/dist/generation.js +1 -1
- package/dist/image-client.d.ts +11 -9
- package/dist/image.d.ts +158 -150
- package/dist/image.js +2 -2
- package/dist/llm.d.ts +2 -4
- package/dist/llm.js +2 -2
- package/dist/media-model.d.ts +2 -2
- package/dist/media-model.js +1 -1
- package/dist/promise.d.ts +121 -121
- package/dist/promise.js +3 -5
- package/dist/protocols/alibaba-chat.d.ts +18 -18
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-messages.d.ts +12 -12
- package/dist/protocols/alibaba-messages.js +1 -1
- package/dist/protocols/alibaba-responses.d.ts +38 -38
- package/dist/protocols/anthropic-messages.d.ts +40 -44
- package/dist/protocols/anthropic-messages.js +13 -15
- package/dist/protocols/bedrock-converse.d.ts +36 -85
- package/dist/protocols/bedrock-converse.js +6 -6
- package/dist/protocols/bedrock-event-stream.d.ts +6 -1
- package/dist/protocols/bedrock-event-stream.js +9 -8
- package/dist/protocols/cartesia-speech.d.ts +32 -32
- package/dist/protocols/cohere-chat.d.ts +13 -10
- package/dist/protocols/cohere-chat.js +2 -2
- package/dist/protocols/deepgram-speech.d.ts +32 -32
- package/dist/protocols/elevenlabs-speech.d.ts +32 -32
- package/dist/protocols/gemini.d.ts +46 -36
- package/dist/protocols/gemini.js +12 -15
- package/dist/protocols/google-interactions.d.ts +14 -13
- package/dist/protocols/google-interactions.js +16 -11
- package/dist/protocols/google-speech.d.ts +32 -32
- package/dist/protocols/google-transcription.d.ts +32 -32
- package/dist/protocols/meta-messages.d.ts +23 -23
- package/dist/protocols/meta-responses.d.ts +84 -84
- package/dist/protocols/mistral-chat.d.ts +81 -78
- package/dist/protocols/mistral-chat.js +3 -5
- package/dist/protocols/open-responses-channel.js +47 -46
- package/dist/protocols/open-responses-continuation.d.ts +8 -2
- package/dist/protocols/open-responses-continuation.js +3 -1
- package/dist/protocols/open-responses.d.ts +419 -419
- package/dist/protocols/open-responses.js +11 -10
- package/dist/protocols/openai-chat.d.ts +68 -67
- package/dist/protocols/openai-chat.js +7 -8
- package/dist/protocols/openai-compatible-chat.d.ts +13 -14
- package/dist/protocols/openai-compatible-responses.d.ts +39 -40
- package/dist/protocols/openai-images.d.ts +32 -32
- package/dist/protocols/openai-responses.d.ts +253 -253
- package/dist/protocols/openai-responses.js +1 -1
- package/dist/protocols/openai-speech.d.ts +32 -32
- package/dist/protocols/openai-transcription.d.ts +32 -32
- package/dist/protocols/openai-transcription.js +12 -7
- package/dist/protocols/utils/open-responses-options.d.ts +8 -8
- package/dist/protocols/utils/open-responses-options.js +4 -6
- package/dist/protocols/utils/partial-json-options.d.ts +0 -1
- package/dist/protocols/utils/partial-json-options.js +0 -1
- package/dist/protocols/utils/partial-json.js +5 -4
- package/dist/protocols/utils/tool-schema.d.ts +0 -3
- package/dist/protocols/utils/tool-schema.js +0 -4
- package/dist/protocols/utils/tool-stream.d.ts +1 -1
- package/dist/protocols/venice-chat.d.ts +52 -53
- package/dist/protocols/venice-chat.js +6 -5
- package/dist/protocols/xai-images.js +3 -4
- package/dist/protocols/xai-responses.d.ts +81 -81
- package/dist/protocols/zai-chat.d.ts +33 -30
- package/dist/protocols/zai-chat.js +8 -3
- package/dist/protocols/zai-messages.d.ts +21 -19
- package/dist/protocols/zai-messages.js +3 -2
- package/dist/provider-error.js +8 -7
- package/dist/providers/alibaba.d.ts +74 -74
- package/dist/providers/amazon-bedrock-mantle.d.ts +202 -202
- package/dist/providers/amazon-bedrock.d.ts +16 -13
- package/dist/providers/anthropic-compatible.d.ts +13 -13
- package/dist/providers/anthropic.d.ts +13 -13
- package/dist/providers/azure.d.ts +112 -112
- package/dist/providers/baseten.d.ts +24 -24
- package/dist/providers/cerebras.d.ts +24 -24
- package/dist/providers/cloudflare-ai-gateway.d.ts +237 -234
- package/dist/providers/cloudflare-ai-gateway.js +3 -6
- package/dist/providers/cloudflare-workers-ai.d.ts +24 -24
- package/dist/providers/cohere.d.ts +78 -74
- package/dist/providers/deepinfra.d.ts +24 -24
- package/dist/providers/deepseek.d.ts +24 -24
- package/dist/providers/digitalocean.d.ts +36 -36
- package/dist/providers/fireworks.d.ts +24 -24
- package/dist/providers/google-vertex-chat.d.ts +12 -12
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +20 -20
- package/dist/providers/google-vertex-mistral.d.ts +14 -14
- package/dist/providers/google-vertex-responses.d.ts +38 -38
- package/dist/providers/google-vertex.d.ts +17 -17
- package/dist/providers/google-vertex.js +2 -2
- package/dist/providers/google.d.ts +79 -79
- package/dist/providers/groq.d.ts +24 -24
- package/dist/providers/meta.d.ts +189 -189
- package/dist/providers/minimax.d.ts +202 -202
- package/dist/providers/mistral.d.ts +28 -28
- package/dist/providers/moonshot.d.ts +202 -202
- package/dist/providers/open-responses-options.d.ts +0 -1
- package/dist/providers/open-responses-options.js +1 -1
- package/dist/providers/openai-compatible-responses.d.ts +38 -38
- package/dist/providers/openai-compatible.d.ts +12 -12
- package/dist/providers/openai-compatible.js +1 -1
- package/dist/providers/openai-options.d.ts +3 -4
- package/dist/providers/openai-options.js +0 -1
- package/dist/providers/openai.d.ts +103 -103
- package/dist/providers/openrouter.d.ts +171 -112
- package/dist/providers/openrouter.js +40 -33
- package/dist/providers/togetherai.d.ts +24 -24
- package/dist/providers/venice.d.ts +195 -20
- package/dist/providers/xai.d.ts +12 -12
- package/dist/providers/zai-coding-plan.d.ts +152 -72
- package/dist/providers/zai.d.ts +84 -19
- package/dist/route/auth-options.d.ts +0 -3
- package/dist/route/auth.d.ts +0 -2
- package/dist/route/auth.js +0 -2
- package/dist/route/client.d.ts +0 -218
- package/dist/route/client.js +3 -7
- package/dist/route/executor-service.js +1 -1
- package/dist/route/transport/http.js +5 -8
- package/dist/schema/errors.d.ts +1 -1
- package/dist/schema/errors.js +1 -1
- package/dist/schema/messages.js +4 -7
- package/dist/speech-client.d.ts +11 -9
- package/dist/speech.d.ts +158 -150
- package/dist/speech.js +2 -2
- package/dist/transcription-client.d.ts +11 -9
- package/dist/transcription.d.ts +158 -150
- package/dist/transcription.js +2 -2
- package/dist/video-client.d.ts +11 -9
- package/dist/video.d.ts +124 -116
- package/dist/video.js +2 -2
- package/package.json +7 -6
- package/dist/protocols/utils/openai-options.d.ts +0 -16
- package/dist/protocols/utils/openai-options.js +0 -15
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
2
2
|
import { fromUtf8, toUtf8 } from "@smithy/util-utf8";
|
|
3
|
-
import { Effect, Stream } from "effect";
|
|
3
|
+
import { Effect, Schema, Stream } from "effect";
|
|
4
4
|
import { Base64 } from "effect/encoding";
|
|
5
5
|
import { AIError, AIErrorReason, InvalidProviderOutputError } from "../schema/index.js";
|
|
6
6
|
import { Framing } from "../route/framing.js";
|
|
@@ -12,6 +12,7 @@ import { ProviderShared } from "./shared.js";
|
|
|
12
12
|
const eventCodec = new EventStreamCodec(toUtf8, fromUtf8);
|
|
13
13
|
const utf8 = new TextDecoder();
|
|
14
14
|
const initialFrameBuffer = { buffer: new Uint8Array(0), offset: 0 };
|
|
15
|
+
export const Frame = Schema.StructWithRest(Schema.Struct({ rawBody: Schema.String }), [ProviderShared.JsonObject]);
|
|
15
16
|
const endOfStream = { _tag: "End" };
|
|
16
17
|
const appendChunk = (state, chunk) => {
|
|
17
18
|
const remaining = state.buffer.length - state.offset;
|
|
@@ -71,14 +72,14 @@ const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
|
|
|
71
72
|
// before handing the object to the chunk schema. JSON decode goes
|
|
72
73
|
// through the shared Schema-driven codec to satisfy the package rule
|
|
73
74
|
// against ad-hoc `JSON.parse` calls.
|
|
74
|
-
const parsed =
|
|
75
|
+
const parsed = yield* ProviderShared.parseJson(route, payload, "Failed to parse Bedrock Converse event-stream payload").pipe(Effect.mapError((error) => new AIError({
|
|
75
76
|
reason: AIErrorReason.make({ ...error.reason, message: error.message, cause: error.reason.cause, body }),
|
|
76
|
-
})))
|
|
77
|
-
|
|
77
|
+
})));
|
|
78
|
+
if (!ProviderShared.isRecord(parsed))
|
|
79
|
+
return yield* ProviderShared.eventError(route, "Failed to parse Bedrock Converse event-stream payload", body);
|
|
80
|
+
const { p: _, ...event } = parsed;
|
|
78
81
|
out.push({
|
|
79
|
-
...(messageType === "exception"
|
|
80
|
-
? { exception: { type: eventType, details: parsed } }
|
|
81
|
-
: { [eventType]: parsed }),
|
|
82
|
+
...(messageType === "exception" ? { exception: { type: eventType, details: event } } : { [eventType]: event }),
|
|
82
83
|
rawBody: body,
|
|
83
84
|
});
|
|
84
85
|
}
|
|
@@ -92,7 +93,7 @@ const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
|
|
|
92
93
|
*/
|
|
93
94
|
export const framing = (route) => ({
|
|
94
95
|
id: "aws-event-stream",
|
|
95
|
-
body: (frame) =>
|
|
96
|
+
body: (frame) => frame.rawBody,
|
|
96
97
|
frame: (bytes) => bytes.pipe(Stream.map((bytes) => ({ _tag: "Chunk", bytes })), Stream.concat(Stream.succeed(endOfStream)), Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))),
|
|
97
98
|
});
|
|
98
99
|
export * as BedrockEventStream from "./bedrock-event-stream.js";
|
|
@@ -23,14 +23,6 @@ interface State extends SpeechStream.Audio {
|
|
|
23
23
|
readonly done: boolean;
|
|
24
24
|
}
|
|
25
25
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
26
|
-
readonly type: "generation-queued";
|
|
27
|
-
readonly id: string;
|
|
28
|
-
readonly position?: number | undefined;
|
|
29
|
-
} | {
|
|
30
|
-
readonly type: "generation-progress";
|
|
31
|
-
readonly id: string;
|
|
32
|
-
readonly progress?: number | undefined;
|
|
33
|
-
} | {
|
|
34
26
|
readonly type: "audio-delta";
|
|
35
27
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
36
28
|
} | {
|
|
@@ -40,18 +32,18 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
40
32
|
readonly startSeconds: number;
|
|
41
33
|
readonly endSeconds: number;
|
|
42
34
|
}[];
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "generation-queued";
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly position?: number | undefined;
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "generation-progress";
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly progress?: number | undefined;
|
|
43
43
|
} | {
|
|
44
44
|
readonly type: "finish";
|
|
45
45
|
readonly audio: import("../media.js").Asset;
|
|
46
46
|
readonly usage?: {
|
|
47
|
-
readonly type: "tokens";
|
|
48
|
-
readonly input?: number | undefined;
|
|
49
|
-
readonly output?: number | undefined;
|
|
50
|
-
readonly total?: number | undefined;
|
|
51
|
-
readonly details?: {
|
|
52
|
-
readonly [x: string]: unknown;
|
|
53
|
-
} | undefined;
|
|
54
|
-
} | {
|
|
55
47
|
readonly type: "seconds";
|
|
56
48
|
readonly seconds: number;
|
|
57
49
|
} | {
|
|
@@ -63,6 +55,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
63
55
|
} | {
|
|
64
56
|
readonly type: "compute";
|
|
65
57
|
readonly seconds: number;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "tokens";
|
|
60
|
+
readonly input?: number | undefined;
|
|
61
|
+
readonly output?: number | undefined;
|
|
62
|
+
readonly total?: number | undefined;
|
|
63
|
+
readonly details?: {
|
|
64
|
+
readonly [x: string]: unknown;
|
|
65
|
+
} | undefined;
|
|
66
66
|
} | undefined;
|
|
67
67
|
readonly notices?: readonly {
|
|
68
68
|
readonly type: "filtered" | "moderated" | "other";
|
|
@@ -82,14 +82,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
82
82
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<CartesiaSpeechOptions>;
|
|
83
83
|
export declare const CartesiaSpeech: {
|
|
84
84
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
85
|
-
readonly type: "generation-queued";
|
|
86
|
-
readonly id: string;
|
|
87
|
-
readonly position?: number | undefined;
|
|
88
|
-
} | {
|
|
89
|
-
readonly type: "generation-progress";
|
|
90
|
-
readonly id: string;
|
|
91
|
-
readonly progress?: number | undefined;
|
|
92
|
-
} | {
|
|
93
85
|
readonly type: "audio-delta";
|
|
94
86
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
95
87
|
} | {
|
|
@@ -99,18 +91,18 @@ export declare const CartesiaSpeech: {
|
|
|
99
91
|
readonly startSeconds: number;
|
|
100
92
|
readonly endSeconds: number;
|
|
101
93
|
}[];
|
|
94
|
+
} | {
|
|
95
|
+
readonly type: "generation-queued";
|
|
96
|
+
readonly id: string;
|
|
97
|
+
readonly position?: number | undefined;
|
|
98
|
+
} | {
|
|
99
|
+
readonly type: "generation-progress";
|
|
100
|
+
readonly id: string;
|
|
101
|
+
readonly progress?: number | undefined;
|
|
102
102
|
} | {
|
|
103
103
|
readonly type: "finish";
|
|
104
104
|
readonly audio: import("../media.js").Asset;
|
|
105
105
|
readonly usage?: {
|
|
106
|
-
readonly type: "tokens";
|
|
107
|
-
readonly input?: number | undefined;
|
|
108
|
-
readonly output?: number | undefined;
|
|
109
|
-
readonly total?: number | undefined;
|
|
110
|
-
readonly details?: {
|
|
111
|
-
readonly [x: string]: unknown;
|
|
112
|
-
} | undefined;
|
|
113
|
-
} | {
|
|
114
106
|
readonly type: "seconds";
|
|
115
107
|
readonly seconds: number;
|
|
116
108
|
} | {
|
|
@@ -122,6 +114,14 @@ export declare const CartesiaSpeech: {
|
|
|
122
114
|
} | {
|
|
123
115
|
readonly type: "compute";
|
|
124
116
|
readonly seconds: number;
|
|
117
|
+
} | {
|
|
118
|
+
readonly type: "tokens";
|
|
119
|
+
readonly input?: number | undefined;
|
|
120
|
+
readonly output?: number | undefined;
|
|
121
|
+
readonly total?: number | undefined;
|
|
122
|
+
readonly details?: {
|
|
123
|
+
readonly [x: string]: unknown;
|
|
124
|
+
} | undefined;
|
|
125
125
|
} | undefined;
|
|
126
126
|
readonly notices?: readonly {
|
|
127
127
|
readonly type: "filtered" | "moderated" | "other";
|
|
@@ -11,11 +11,6 @@ declare const Options: Schema.Struct<{
|
|
|
11
11
|
}>>;
|
|
12
12
|
}>;
|
|
13
13
|
export type ProviderOptionsInput = Schema.Schema.Type<typeof Options>;
|
|
14
|
-
type State = {
|
|
15
|
-
readonly lifecycle: Lifecycle.State;
|
|
16
|
-
readonly tools: ToolStream.State<number>;
|
|
17
|
-
readonly finished: boolean;
|
|
18
|
-
};
|
|
19
14
|
export declare const protocol: Protocol<{
|
|
20
15
|
readonly model: string;
|
|
21
16
|
readonly messages: readonly {
|
|
@@ -49,7 +44,9 @@ export declare const protocol: Protocol<{
|
|
|
49
44
|
readonly function: {
|
|
50
45
|
readonly name: string;
|
|
51
46
|
readonly description?: string | undefined;
|
|
52
|
-
readonly parameters:
|
|
47
|
+
readonly parameters: {
|
|
48
|
+
readonly [x: string]: unknown;
|
|
49
|
+
};
|
|
53
50
|
};
|
|
54
51
|
}[] | undefined;
|
|
55
52
|
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
@@ -66,6 +63,8 @@ export declare const protocol: Protocol<{
|
|
|
66
63
|
readonly frequency_penalty?: number | undefined;
|
|
67
64
|
readonly presence_penalty?: number | undefined;
|
|
68
65
|
}, string, {
|
|
66
|
+
readonly type: "unknown";
|
|
67
|
+
} | {
|
|
69
68
|
readonly type: "message-start";
|
|
70
69
|
} | {
|
|
71
70
|
readonly type: "content-delta" | "content-start";
|
|
@@ -125,9 +124,11 @@ export declare const protocol: Protocol<{
|
|
|
125
124
|
};
|
|
126
125
|
} | {
|
|
127
126
|
readonly type: "citation-end" | "citation-start";
|
|
128
|
-
}
|
|
129
|
-
readonly
|
|
130
|
-
|
|
127
|
+
}, {
|
|
128
|
+
readonly lifecycle: Lifecycle.State;
|
|
129
|
+
readonly finished: boolean;
|
|
130
|
+
readonly tools: Partial<Record<number, ToolStream.PendingTool>>;
|
|
131
|
+
}>;
|
|
131
132
|
export declare const route: Route<{
|
|
132
133
|
readonly model: string;
|
|
133
134
|
readonly messages: readonly {
|
|
@@ -161,7 +162,9 @@ export declare const route: Route<{
|
|
|
161
162
|
readonly function: {
|
|
162
163
|
readonly name: string;
|
|
163
164
|
readonly description?: string | undefined;
|
|
164
|
-
readonly parameters:
|
|
165
|
+
readonly parameters: {
|
|
166
|
+
readonly [x: string]: unknown;
|
|
167
|
+
};
|
|
165
168
|
};
|
|
166
169
|
}[] | undefined;
|
|
167
170
|
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
@@ -4,7 +4,7 @@ import { Endpoint } from "../route/endpoint.js";
|
|
|
4
4
|
import { Framing } from "../route/framing.js";
|
|
5
5
|
import { Protocol } from "../route/protocol.js";
|
|
6
6
|
import { LLMEvent, Usage } from "../schema/index.js";
|
|
7
|
-
import { ProviderShared } from "./shared.js";
|
|
7
|
+
import { JsonObject, ProviderShared } from "./shared.js";
|
|
8
8
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
9
9
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
10
10
|
const ADAPTER = "cohere-chat";
|
|
@@ -41,7 +41,7 @@ const Body = Schema.Struct({
|
|
|
41
41
|
function: Schema.Struct({
|
|
42
42
|
name: Schema.String,
|
|
43
43
|
description: Schema.optional(Schema.String),
|
|
44
|
-
parameters:
|
|
44
|
+
parameters: JsonObject,
|
|
45
45
|
}),
|
|
46
46
|
}))),
|
|
47
47
|
tool_choice: Schema.optional(Schema.Literals(["NONE", "REQUIRED"])),
|
|
@@ -16,14 +16,6 @@ export type DeepgramSpeechOptions = {
|
|
|
16
16
|
} & Record<string, unknown>;
|
|
17
17
|
export type Request = SpeechRequestFor<DeepgramSpeechOptions>;
|
|
18
18
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
19
|
-
readonly type: "generation-queued";
|
|
20
|
-
readonly id: string;
|
|
21
|
-
readonly position?: number | undefined;
|
|
22
|
-
} | {
|
|
23
|
-
readonly type: "generation-progress";
|
|
24
|
-
readonly id: string;
|
|
25
|
-
readonly progress?: number | undefined;
|
|
26
|
-
} | {
|
|
27
19
|
readonly type: "audio-delta";
|
|
28
20
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
29
21
|
} | {
|
|
@@ -33,18 +25,18 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
33
25
|
readonly startSeconds: number;
|
|
34
26
|
readonly endSeconds: number;
|
|
35
27
|
}[];
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "generation-queued";
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly position?: number | undefined;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "generation-progress";
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly progress?: number | undefined;
|
|
36
36
|
} | {
|
|
37
37
|
readonly type: "finish";
|
|
38
38
|
readonly audio: import("../media.js").Asset;
|
|
39
39
|
readonly usage?: {
|
|
40
|
-
readonly type: "tokens";
|
|
41
|
-
readonly input?: number | undefined;
|
|
42
|
-
readonly output?: number | undefined;
|
|
43
|
-
readonly total?: number | undefined;
|
|
44
|
-
readonly details?: {
|
|
45
|
-
readonly [x: string]: unknown;
|
|
46
|
-
} | undefined;
|
|
47
|
-
} | {
|
|
48
40
|
readonly type: "seconds";
|
|
49
41
|
readonly seconds: number;
|
|
50
42
|
} | {
|
|
@@ -56,6 +48,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
56
48
|
} | {
|
|
57
49
|
readonly type: "compute";
|
|
58
50
|
readonly seconds: number;
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "tokens";
|
|
53
|
+
readonly input?: number | undefined;
|
|
54
|
+
readonly output?: number | undefined;
|
|
55
|
+
readonly total?: number | undefined;
|
|
56
|
+
readonly details?: {
|
|
57
|
+
readonly [x: string]: unknown;
|
|
58
|
+
} | undefined;
|
|
59
59
|
} | undefined;
|
|
60
60
|
readonly notices?: readonly {
|
|
61
61
|
readonly type: "filtered" | "moderated" | "other";
|
|
@@ -75,14 +75,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
75
75
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<DeepgramSpeechOptions>;
|
|
76
76
|
export declare const DeepgramSpeech: {
|
|
77
77
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
78
|
-
readonly type: "generation-queued";
|
|
79
|
-
readonly id: string;
|
|
80
|
-
readonly position?: number | undefined;
|
|
81
|
-
} | {
|
|
82
|
-
readonly type: "generation-progress";
|
|
83
|
-
readonly id: string;
|
|
84
|
-
readonly progress?: number | undefined;
|
|
85
|
-
} | {
|
|
86
78
|
readonly type: "audio-delta";
|
|
87
79
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
88
80
|
} | {
|
|
@@ -92,18 +84,18 @@ export declare const DeepgramSpeech: {
|
|
|
92
84
|
readonly startSeconds: number;
|
|
93
85
|
readonly endSeconds: number;
|
|
94
86
|
}[];
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "generation-queued";
|
|
89
|
+
readonly id: string;
|
|
90
|
+
readonly position?: number | undefined;
|
|
91
|
+
} | {
|
|
92
|
+
readonly type: "generation-progress";
|
|
93
|
+
readonly id: string;
|
|
94
|
+
readonly progress?: number | undefined;
|
|
95
95
|
} | {
|
|
96
96
|
readonly type: "finish";
|
|
97
97
|
readonly audio: import("../media.js").Asset;
|
|
98
98
|
readonly usage?: {
|
|
99
|
-
readonly type: "tokens";
|
|
100
|
-
readonly input?: number | undefined;
|
|
101
|
-
readonly output?: number | undefined;
|
|
102
|
-
readonly total?: number | undefined;
|
|
103
|
-
readonly details?: {
|
|
104
|
-
readonly [x: string]: unknown;
|
|
105
|
-
} | undefined;
|
|
106
|
-
} | {
|
|
107
99
|
readonly type: "seconds";
|
|
108
100
|
readonly seconds: number;
|
|
109
101
|
} | {
|
|
@@ -115,6 +107,14 @@ export declare const DeepgramSpeech: {
|
|
|
115
107
|
} | {
|
|
116
108
|
readonly type: "compute";
|
|
117
109
|
readonly seconds: number;
|
|
110
|
+
} | {
|
|
111
|
+
readonly type: "tokens";
|
|
112
|
+
readonly input?: number | undefined;
|
|
113
|
+
readonly output?: number | undefined;
|
|
114
|
+
readonly total?: number | undefined;
|
|
115
|
+
readonly details?: {
|
|
116
|
+
readonly [x: string]: unknown;
|
|
117
|
+
} | undefined;
|
|
118
118
|
} | undefined;
|
|
119
119
|
readonly notices?: readonly {
|
|
120
120
|
readonly type: "filtered" | "moderated" | "other";
|
|
@@ -19,14 +19,6 @@ export type ElevenLabsSpeechOptions = {
|
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
20
|
export type Request = SpeechRequestFor<ElevenLabsSpeechOptions>;
|
|
21
21
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
22
|
-
readonly type: "generation-queued";
|
|
23
|
-
readonly id: string;
|
|
24
|
-
readonly position?: number | undefined;
|
|
25
|
-
} | {
|
|
26
|
-
readonly type: "generation-progress";
|
|
27
|
-
readonly id: string;
|
|
28
|
-
readonly progress?: number | undefined;
|
|
29
|
-
} | {
|
|
30
22
|
readonly type: "audio-delta";
|
|
31
23
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
32
24
|
} | {
|
|
@@ -36,18 +28,18 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
36
28
|
readonly startSeconds: number;
|
|
37
29
|
readonly endSeconds: number;
|
|
38
30
|
}[];
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "generation-queued";
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly position?: number | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "generation-progress";
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly progress?: number | undefined;
|
|
39
39
|
} | {
|
|
40
40
|
readonly type: "finish";
|
|
41
41
|
readonly audio: import("../media.js").Asset;
|
|
42
42
|
readonly usage?: {
|
|
43
|
-
readonly type: "tokens";
|
|
44
|
-
readonly input?: number | undefined;
|
|
45
|
-
readonly output?: number | undefined;
|
|
46
|
-
readonly total?: number | undefined;
|
|
47
|
-
readonly details?: {
|
|
48
|
-
readonly [x: string]: unknown;
|
|
49
|
-
} | undefined;
|
|
50
|
-
} | {
|
|
51
43
|
readonly type: "seconds";
|
|
52
44
|
readonly seconds: number;
|
|
53
45
|
} | {
|
|
@@ -59,6 +51,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
59
51
|
} | {
|
|
60
52
|
readonly type: "compute";
|
|
61
53
|
readonly seconds: number;
|
|
54
|
+
} | {
|
|
55
|
+
readonly type: "tokens";
|
|
56
|
+
readonly input?: number | undefined;
|
|
57
|
+
readonly output?: number | undefined;
|
|
58
|
+
readonly total?: number | undefined;
|
|
59
|
+
readonly details?: {
|
|
60
|
+
readonly [x: string]: unknown;
|
|
61
|
+
} | undefined;
|
|
62
62
|
} | undefined;
|
|
63
63
|
readonly notices?: readonly {
|
|
64
64
|
readonly type: "filtered" | "moderated" | "other";
|
|
@@ -78,14 +78,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
78
78
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<ElevenLabsSpeechOptions>;
|
|
79
79
|
export declare const ElevenLabsSpeech: {
|
|
80
80
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
81
|
-
readonly type: "generation-queued";
|
|
82
|
-
readonly id: string;
|
|
83
|
-
readonly position?: number | undefined;
|
|
84
|
-
} | {
|
|
85
|
-
readonly type: "generation-progress";
|
|
86
|
-
readonly id: string;
|
|
87
|
-
readonly progress?: number | undefined;
|
|
88
|
-
} | {
|
|
89
81
|
readonly type: "audio-delta";
|
|
90
82
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
91
83
|
} | {
|
|
@@ -95,18 +87,18 @@ export declare const ElevenLabsSpeech: {
|
|
|
95
87
|
readonly startSeconds: number;
|
|
96
88
|
readonly endSeconds: number;
|
|
97
89
|
}[];
|
|
90
|
+
} | {
|
|
91
|
+
readonly type: "generation-queued";
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly position?: number | undefined;
|
|
94
|
+
} | {
|
|
95
|
+
readonly type: "generation-progress";
|
|
96
|
+
readonly id: string;
|
|
97
|
+
readonly progress?: number | undefined;
|
|
98
98
|
} | {
|
|
99
99
|
readonly type: "finish";
|
|
100
100
|
readonly audio: import("../media.js").Asset;
|
|
101
101
|
readonly usage?: {
|
|
102
|
-
readonly type: "tokens";
|
|
103
|
-
readonly input?: number | undefined;
|
|
104
|
-
readonly output?: number | undefined;
|
|
105
|
-
readonly total?: number | undefined;
|
|
106
|
-
readonly details?: {
|
|
107
|
-
readonly [x: string]: unknown;
|
|
108
|
-
} | undefined;
|
|
109
|
-
} | {
|
|
110
102
|
readonly type: "seconds";
|
|
111
103
|
readonly seconds: number;
|
|
112
104
|
} | {
|
|
@@ -118,6 +110,14 @@ export declare const ElevenLabsSpeech: {
|
|
|
118
110
|
} | {
|
|
119
111
|
readonly type: "compute";
|
|
120
112
|
readonly seconds: number;
|
|
113
|
+
} | {
|
|
114
|
+
readonly type: "tokens";
|
|
115
|
+
readonly input?: number | undefined;
|
|
116
|
+
readonly output?: number | undefined;
|
|
117
|
+
readonly total?: number | undefined;
|
|
118
|
+
readonly details?: {
|
|
119
|
+
readonly [x: string]: unknown;
|
|
120
|
+
} | undefined;
|
|
121
121
|
} | undefined;
|
|
122
122
|
readonly notices?: readonly {
|
|
123
123
|
readonly type: "filtered" | "moderated" | "other";
|
|
@@ -158,27 +158,10 @@ export declare const protocol: Protocol<{
|
|
|
158
158
|
readonly contents: readonly {
|
|
159
159
|
readonly role?: "model" | "user" | null | undefined;
|
|
160
160
|
readonly parts?: readonly ({
|
|
161
|
-
readonly inlineData: {
|
|
162
|
-
readonly mimeType: string;
|
|
163
|
-
readonly data: string;
|
|
164
|
-
};
|
|
165
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
166
|
-
} | {
|
|
167
|
-
readonly text: string;
|
|
168
|
-
readonly thought?: boolean | null | undefined;
|
|
169
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
170
|
-
} | {
|
|
171
161
|
readonly fileData: {
|
|
172
162
|
readonly mimeType: string;
|
|
173
163
|
readonly fileUri: string;
|
|
174
164
|
};
|
|
175
|
-
} | {
|
|
176
|
-
readonly functionCall: {
|
|
177
|
-
readonly id?: string | null | undefined;
|
|
178
|
-
readonly name: string;
|
|
179
|
-
readonly args?: unknown;
|
|
180
|
-
};
|
|
181
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
182
165
|
} | {
|
|
183
166
|
readonly functionResponse: {
|
|
184
167
|
readonly id?: string | undefined;
|
|
@@ -192,6 +175,23 @@ export declare const protocol: Protocol<{
|
|
|
192
175
|
readonly thoughtSignature?: string | null | undefined;
|
|
193
176
|
}[] | undefined;
|
|
194
177
|
};
|
|
178
|
+
} | {
|
|
179
|
+
readonly text: string;
|
|
180
|
+
readonly thought?: boolean | null | undefined;
|
|
181
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
182
|
+
} | {
|
|
183
|
+
readonly inlineData: {
|
|
184
|
+
readonly mimeType: string;
|
|
185
|
+
readonly data: string;
|
|
186
|
+
};
|
|
187
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
188
|
+
} | {
|
|
189
|
+
readonly functionCall: {
|
|
190
|
+
readonly id?: string | null | undefined;
|
|
191
|
+
readonly name: string;
|
|
192
|
+
readonly args?: unknown;
|
|
193
|
+
};
|
|
194
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
195
195
|
})[] | null | undefined;
|
|
196
196
|
}[];
|
|
197
197
|
readonly labels?: {
|
|
@@ -239,7 +239,12 @@ export declare const protocol: Protocol<{
|
|
|
239
239
|
} | undefined;
|
|
240
240
|
readonly continuationToken?: string | undefined;
|
|
241
241
|
}, NextRequest | {
|
|
242
|
-
readonly error?:
|
|
242
|
+
readonly error?: {
|
|
243
|
+
readonly [x: string]: unknown;
|
|
244
|
+
readonly code?: number | undefined;
|
|
245
|
+
readonly message?: string | undefined;
|
|
246
|
+
readonly status?: string | undefined;
|
|
247
|
+
} | undefined;
|
|
243
248
|
readonly candidates?: readonly {
|
|
244
249
|
readonly content?: {
|
|
245
250
|
readonly role?: "model" | "user" | null | undefined;
|
|
@@ -261,7 +266,12 @@ export declare const protocol: Protocol<{
|
|
|
261
266
|
readonly totalTokenCount?: number | null | undefined;
|
|
262
267
|
} | null | undefined;
|
|
263
268
|
}, NextRequest | {
|
|
264
|
-
readonly error?:
|
|
269
|
+
readonly error?: {
|
|
270
|
+
readonly [x: string]: unknown;
|
|
271
|
+
readonly code?: number | undefined;
|
|
272
|
+
readonly message?: string | undefined;
|
|
273
|
+
readonly status?: string | undefined;
|
|
274
|
+
} | undefined;
|
|
265
275
|
readonly candidates?: readonly {
|
|
266
276
|
readonly content?: {
|
|
267
277
|
readonly role?: "model" | "user" | null | undefined;
|
|
@@ -288,27 +298,10 @@ export declare const route: Route<{
|
|
|
288
298
|
readonly contents: readonly {
|
|
289
299
|
readonly role?: "model" | "user" | null | undefined;
|
|
290
300
|
readonly parts?: readonly ({
|
|
291
|
-
readonly inlineData: {
|
|
292
|
-
readonly mimeType: string;
|
|
293
|
-
readonly data: string;
|
|
294
|
-
};
|
|
295
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
296
|
-
} | {
|
|
297
|
-
readonly text: string;
|
|
298
|
-
readonly thought?: boolean | null | undefined;
|
|
299
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
300
|
-
} | {
|
|
301
301
|
readonly fileData: {
|
|
302
302
|
readonly mimeType: string;
|
|
303
303
|
readonly fileUri: string;
|
|
304
304
|
};
|
|
305
|
-
} | {
|
|
306
|
-
readonly functionCall: {
|
|
307
|
-
readonly id?: string | null | undefined;
|
|
308
|
-
readonly name: string;
|
|
309
|
-
readonly args?: unknown;
|
|
310
|
-
};
|
|
311
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
312
305
|
} | {
|
|
313
306
|
readonly functionResponse: {
|
|
314
307
|
readonly id?: string | undefined;
|
|
@@ -322,6 +315,23 @@ export declare const route: Route<{
|
|
|
322
315
|
readonly thoughtSignature?: string | null | undefined;
|
|
323
316
|
}[] | undefined;
|
|
324
317
|
};
|
|
318
|
+
} | {
|
|
319
|
+
readonly text: string;
|
|
320
|
+
readonly thought?: boolean | null | undefined;
|
|
321
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
322
|
+
} | {
|
|
323
|
+
readonly inlineData: {
|
|
324
|
+
readonly mimeType: string;
|
|
325
|
+
readonly data: string;
|
|
326
|
+
};
|
|
327
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
328
|
+
} | {
|
|
329
|
+
readonly functionCall: {
|
|
330
|
+
readonly id?: string | null | undefined;
|
|
331
|
+
readonly name: string;
|
|
332
|
+
readonly args?: unknown;
|
|
333
|
+
};
|
|
334
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
325
335
|
})[] | null | undefined;
|
|
326
336
|
}[];
|
|
327
337
|
readonly labels?: {
|
package/dist/protocols/gemini.js
CHANGED
|
@@ -182,8 +182,13 @@ const GeminiPromptFeedback = Schema.StructWithRest(Schema.Struct({
|
|
|
182
182
|
blockReasonMessage: optionalNull(Schema.String),
|
|
183
183
|
safetyRatings: optionalNull(Schema.Unknown),
|
|
184
184
|
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
185
|
+
const GeminiError = Schema.StructWithRest(Schema.Struct({
|
|
186
|
+
code: lenient(Schema.Number),
|
|
187
|
+
message: lenient(Schema.String),
|
|
188
|
+
status: lenient(Schema.String),
|
|
189
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
185
190
|
const GeminiEvent = Schema.Struct({
|
|
186
|
-
error: Schema.optional(
|
|
191
|
+
error: Schema.optional(GeminiError),
|
|
187
192
|
candidates: optionalNull(Schema.Array(GeminiCandidate)),
|
|
188
193
|
promptFeedback: optionalNull(GeminiPromptFeedback),
|
|
189
194
|
usageMetadata: optionalNull(GeminiUsage),
|
|
@@ -211,9 +216,7 @@ const lowerContentPart = Effect.fnUntraced(function* (part) {
|
|
|
211
216
|
const providerMetadata = (key, metadata) => ({ [key]: metadata });
|
|
212
217
|
const thoughtSignature = (metadata, key) => {
|
|
213
218
|
const value = metadata?.[key];
|
|
214
|
-
return
|
|
215
|
-
? value.thoughtSignature
|
|
216
|
-
: undefined;
|
|
219
|
+
return typeof value?.thoughtSignature === "string" ? value.thoughtSignature : undefined;
|
|
217
220
|
};
|
|
218
221
|
const lowerToolCall = (part, omitIds, metadataKey) => ({
|
|
219
222
|
functionCall: { ...(omitIds ? {} : { id: part.id }), name: part.name, args: part.input },
|
|
@@ -221,7 +224,7 @@ const lowerToolCall = (part, omitIds, metadataKey) => ({
|
|
|
221
224
|
});
|
|
222
225
|
const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
223
226
|
const contents = [];
|
|
224
|
-
const metadataKey = request.model.route.providerMetadataKey ??
|
|
227
|
+
const metadataKey = request.model.route.providerMetadataKey ?? request.model.provider;
|
|
225
228
|
const omitCallIds = omitsFunctionCallIds(request.model.id);
|
|
226
229
|
const legacyToolMedia = routesLegacyToolMedia(request.model.id);
|
|
227
230
|
let pendingMedia;
|
|
@@ -511,22 +514,16 @@ const step = (state, event) => {
|
|
|
511
514
|
},
|
|
512
515
|
[],
|
|
513
516
|
]);
|
|
514
|
-
if (
|
|
517
|
+
if (event.error) {
|
|
515
518
|
const body = ProviderShared.encodeJson(event);
|
|
516
519
|
return Effect.fail(new AIError({
|
|
517
520
|
reason: classifyProviderFailure({
|
|
518
|
-
message:
|
|
519
|
-
|
|
520
|
-
: typeof event.error.status === "string" && event.error.status.length > 0
|
|
521
|
-
? event.error.status
|
|
522
|
-
: "Gemini provider error",
|
|
523
|
-
status: typeof event.error.code === "number" ? event.error.code : undefined,
|
|
521
|
+
message: event.error.message || event.error.status || "Gemini provider error",
|
|
522
|
+
status: event.error.code,
|
|
524
523
|
rawBody: body,
|
|
525
524
|
}),
|
|
526
525
|
}));
|
|
527
526
|
}
|
|
528
|
-
if ("error" in event)
|
|
529
|
-
return Effect.fail(ProviderShared.eventError(state.route, `Invalid ${state.route} stream event`, ProviderShared.encodeJson(event)));
|
|
530
527
|
const candidate = event.candidates?.[0];
|
|
531
528
|
const nextState = {
|
|
532
529
|
...state,
|
|
@@ -753,7 +750,7 @@ export const protocol = Protocol.make({
|
|
|
753
750
|
event: Schema.Union([Schema.instanceOf(NextRequest), GeminiEvent]),
|
|
754
751
|
initial: (request) => ({
|
|
755
752
|
route: `${request.model.provider}/${request.model.route.id}`,
|
|
756
|
-
providerMetadataKey: request.model.route.providerMetadataKey ??
|
|
753
|
+
providerMetadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
|
|
757
754
|
hasToolCalls: false,
|
|
758
755
|
lifecycle: Lifecycle.initial(),
|
|
759
756
|
nextReasoningId: 0,
|