@opencode/ai 2.0.15 → 2.0.16
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 +286 -2
- package/dist/generation.d.ts +36 -22
- package/dist/generation.js +53 -24
- package/dist/image-client.d.ts +14 -7
- package/dist/image-client.js +24 -8
- package/dist/image.d.ts +398 -47
- package/dist/image.js +47 -45
- package/dist/index.d.ts +13 -1
- package/dist/index.js +9 -0
- package/dist/media-model.d.ts +44 -0
- package/dist/media-model.js +49 -0
- package/dist/media.d.ts +10 -9
- package/dist/media.js +9 -10
- package/dist/promise.d.ts +428 -8
- package/dist/promise.js +40 -3
- package/dist/protocols/alibaba-chat.d.ts +12 -0
- package/dist/protocols/alibaba-responses.d.ts +2 -2
- package/dist/protocols/anthropic-messages.js +1 -2
- package/dist/protocols/assemblyai-transcription.d.ts +40 -0
- package/dist/protocols/assemblyai-transcription.js +138 -0
- package/dist/protocols/bedrock-converse.js +5 -11
- package/dist/protocols/bfl-images.d.ts +32 -0
- package/dist/protocols/bfl-images.js +153 -0
- package/dist/protocols/cartesia-speech.d.ts +127 -0
- package/dist/protocols/cartesia-speech.js +126 -0
- package/dist/protocols/deepgram-speech.d.ts +119 -0
- package/dist/protocols/deepgram-speech.js +92 -0
- package/dist/protocols/deepgram-transcription.d.ts +25 -0
- package/dist/protocols/deepgram-transcription.js +129 -0
- package/dist/protocols/elevenlabs-speech.d.ts +122 -0
- package/dist/protocols/elevenlabs-speech.js +115 -0
- package/dist/protocols/fal-images.d.ts +24 -0
- package/dist/protocols/fal-images.js +114 -0
- package/dist/protocols/fal-video.d.ts +29 -0
- package/dist/protocols/fal-video.js +88 -0
- package/dist/protocols/gemini.d.ts +9 -9
- package/dist/protocols/gemini.js +8 -34
- package/dist/protocols/google-images.js +2 -14
- package/dist/protocols/google-speech.d.ts +130 -0
- package/dist/protocols/google-speech.js +84 -0
- package/dist/protocols/google-transcription.d.ts +173 -0
- package/dist/protocols/google-transcription.js +138 -0
- package/dist/protocols/google-video.d.ts +26 -0
- package/dist/protocols/google-video.js +158 -0
- package/dist/protocols/meta-images.js +2 -9
- package/dist/protocols/meta-responses.d.ts +4 -4
- package/dist/protocols/meta-responses.js +1 -1
- package/dist/protocols/open-responses.d.ts +6 -6
- package/dist/protocols/open-responses.js +1 -2
- package/dist/protocols/openai-chat.d.ts +84 -0
- package/dist/protocols/openai-chat.js +26 -14
- 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 +124 -3
- package/dist/protocols/openai-images.js +107 -54
- package/dist/protocols/openai-responses.d.ts +15 -15
- package/dist/protocols/openai-responses.js +5 -6
- package/dist/protocols/openai-speech.d.ts +116 -0
- package/dist/protocols/openai-speech.js +98 -0
- package/dist/protocols/openai-transcription.d.ts +207 -0
- package/dist/protocols/openai-transcription.js +190 -0
- package/dist/protocols/replicate-images.d.ts +28 -0
- package/dist/protocols/replicate-images.js +133 -0
- package/dist/protocols/runway-video.d.ts +38 -0
- package/dist/protocols/runway-video.js +146 -0
- package/dist/protocols/shared.d.ts +13 -3
- package/dist/protocols/shared.js +23 -3
- package/dist/protocols/stability-images.d.ts +38 -0
- package/dist/protocols/stability-images.js +148 -0
- package/dist/protocols/utils/fal-queue.d.ts +28 -0
- package/dist/protocols/utils/fal-queue.js +69 -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 +8 -0
- package/dist/protocols/utils/media-input.js +18 -0
- package/dist/protocols/utils/speech-stream.d.ts +49 -0
- package/dist/protocols/utils/speech-stream.js +67 -0
- package/dist/protocols/utils/tool-schema.d.ts +2 -2
- package/dist/protocols/utils/tool-schema.js +40 -17
- package/dist/protocols/xai-images.js +1 -12
- package/dist/protocols/xai-responses.d.ts +2 -2
- package/dist/protocols/xai-video.d.ts +34 -0
- package/dist/protocols/xai-video.js +147 -0
- package/dist/protocols/zai-chat.d.ts +13 -1
- package/dist/provider-error.js +3 -0
- package/dist/providers/alibaba.d.ts +14 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +14 -2
- package/dist/providers/assemblyai.d.ts +25 -0
- package/dist/providers/assemblyai.js +29 -0
- package/dist/providers/azure.d.ts +18 -6
- 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 +28 -0
- package/dist/providers/cartesia.d.ts +24 -0
- package/dist/providers/cartesia.js +22 -0
- package/dist/providers/cerebras.d.ts +24 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +30 -6
- package/dist/providers/cloudflare-workers-ai.d.ts +24 -0
- package/dist/providers/deepgram.d.ts +29 -0
- package/dist/providers/deepgram.js +31 -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 +28 -0
- package/dist/providers/fal.d.ts +29 -0
- package/dist/providers/fal.js +33 -0
- package/dist/providers/fireworks.d.ts +24 -0
- package/dist/providers/google-vertex-chat.d.ts +12 -0
- package/dist/providers/google-vertex-responses.d.ts +2 -2
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +18 -3
- package/dist/providers/google.js +11 -2
- 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 +14 -2
- package/dist/providers/minimax.d.ts +14 -2
- package/dist/providers/moonshot.d.ts +14 -2
- 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.d.ts +25 -3
- package/dist/providers/openai.js +10 -1
- package/dist/providers/openrouter.d.ts +48 -0
- package/dist/providers/replicate.d.ts +25 -0
- package/dist/providers/replicate.js +22 -0
- package/dist/providers/runway.d.ts +24 -0
- package/dist/providers/runway.js +22 -0
- package/dist/providers/stability.d.ts +28 -0
- package/dist/providers/stability.js +23 -0
- package/dist/providers/togetherai.d.ts +24 -0
- package/dist/providers/xai.d.ts +17 -0
- package/dist/providers/xai.js +5 -2
- package/dist/providers/zai-coding-plan.d.ts +15 -3
- package/dist/providers/zai.d.ts +13 -1
- package/dist/route/auth.d.ts +4 -1
- package/dist/route/auth.js +6 -0
- package/dist/route/framing.d.ts +5 -1
- package/dist/route/framing.js +9 -0
- package/dist/route/media-protocol.d.ts +116 -3
- package/dist/route/media-protocol.js +60 -4
- package/dist/route/media.d.ts +58 -7
- package/dist/route/media.js +201 -29
- package/dist/schema/events.d.ts +0 -6
- package/dist/schema/messages.d.ts +0 -3
- package/dist/schema/options.d.ts +4 -3
- package/dist/schema/options.js +3 -2
- package/dist/speech-client.d.ts +21 -0
- package/dist/speech-client.js +25 -0
- package/dist/speech.d.ts +1150 -0
- package/dist/speech.js +119 -0
- package/dist/transcription-client.d.ts +28 -0
- package/dist/transcription-client.js +44 -0
- package/dist/transcription.d.ts +1504 -0
- package/dist/transcription.js +133 -0
- package/dist/utils/bytes.d.ts +1 -0
- package/dist/utils/bytes.js +10 -0
- package/dist/utils/media-type.d.ts +1 -0
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +28 -0
- package/dist/video-client.js +40 -0
- package/dist/video.d.ts +1359 -0
- package/dist/video.js +119 -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
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Effect, Schema, Stream } from "effect";
|
|
2
|
+
import { Generation, ProgressEvent, QueuedEvent } from "./generation.js";
|
|
3
|
+
import { Media } from "./media.js";
|
|
4
|
+
import { MediaModel, composeAnyRoute, tryRequest } from "./media-model.js";
|
|
5
|
+
import { MediaRoute } from "./route/media.js";
|
|
6
|
+
import { AIError, HttpOptions, MediaUsage, ProviderMetadata } from "./schema/index.js";
|
|
7
|
+
import { TranscriptionClient, Service } from "./transcription-client.js";
|
|
8
|
+
export class TranscriptionModel extends MediaModel {
|
|
9
|
+
static make(input) {
|
|
10
|
+
return new TranscriptionModel(input);
|
|
11
|
+
}
|
|
12
|
+
static fromRoute(route, input) {
|
|
13
|
+
return new TranscriptionModel({
|
|
14
|
+
id: input.id,
|
|
15
|
+
provider: route.provider,
|
|
16
|
+
http: input.http,
|
|
17
|
+
route: composeAnyRoute(route, input, collectResponse),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export const TranscriptionModelSchema = Schema.declare((value) => value instanceof TranscriptionModel, { expected: "Transcription.Model" });
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Request
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
export const TranscriptionTimestamps = Schema.Literals(["none", "segment", "word"]);
|
|
26
|
+
export class TranscriptionRequest extends Schema.Class("Transcription.Request")({
|
|
27
|
+
model: TranscriptionModelSchema,
|
|
28
|
+
audio: Media.AssetSchema,
|
|
29
|
+
language: Schema.optional(Schema.String),
|
|
30
|
+
prompt: Schema.optional(Schema.String),
|
|
31
|
+
/** Routes that cannot produce the requested granularity fail typed; routes may return more than asked. */
|
|
32
|
+
timestamps: Schema.optional(TranscriptionTimestamps),
|
|
33
|
+
diarize: Schema.optional(Schema.Boolean),
|
|
34
|
+
speakers: Schema.optional(Schema.Int),
|
|
35
|
+
providerOptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
36
|
+
http: Schema.optional(HttpOptions),
|
|
37
|
+
}) {
|
|
38
|
+
}
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Response and events
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/** Speaker labels are provider-native (`A`, `0`, `spk:0`, or a known speaker name). */
|
|
43
|
+
export const TranscriptionSegment = Schema.Struct({
|
|
44
|
+
text: Schema.String,
|
|
45
|
+
startSeconds: Schema.Number,
|
|
46
|
+
endSeconds: Schema.Number,
|
|
47
|
+
speaker: Schema.optional(Schema.String),
|
|
48
|
+
}).annotate({ identifier: "Transcription.Segment" });
|
|
49
|
+
export const TranscriptionWord = Schema.Struct({
|
|
50
|
+
text: Schema.String,
|
|
51
|
+
startSeconds: Schema.Number,
|
|
52
|
+
endSeconds: Schema.Number,
|
|
53
|
+
speaker: Schema.optional(Schema.String),
|
|
54
|
+
confidence: Schema.optional(Schema.Number),
|
|
55
|
+
}).annotate({ identifier: "Transcription.Word" });
|
|
56
|
+
const transcriptFields = {
|
|
57
|
+
text: Schema.String,
|
|
58
|
+
segments: Schema.optional(Schema.Array(TranscriptionSegment)),
|
|
59
|
+
words: Schema.optional(Schema.Array(TranscriptionWord)),
|
|
60
|
+
/** Provider-native language as detected or echoed (`en`, `english`, `en_us`), lowercased but not normalized. */
|
|
61
|
+
language: Schema.optional(Schema.String),
|
|
62
|
+
durationSeconds: Schema.optional(Schema.Number),
|
|
63
|
+
usage: Schema.optional(MediaUsage),
|
|
64
|
+
notices: Schema.optional(Schema.Array(Media.Notice)),
|
|
65
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
66
|
+
};
|
|
67
|
+
export class TranscriptionResponse extends Schema.Class("Transcription.Response")(transcriptFields) {
|
|
68
|
+
}
|
|
69
|
+
export const TranscriptionTextDeltaEvent = Schema.Struct({
|
|
70
|
+
type: Schema.tag("text-delta"),
|
|
71
|
+
delta: Schema.String,
|
|
72
|
+
}).annotate({ identifier: "Transcription.Event.TextDelta" });
|
|
73
|
+
export const TranscriptionSegmentEvent = Schema.Struct({
|
|
74
|
+
type: Schema.tag("segment"),
|
|
75
|
+
segment: TranscriptionSegment,
|
|
76
|
+
}).annotate({ identifier: "Transcription.Event.Segment" });
|
|
77
|
+
export const TranscriptionFinishEvent = Schema.Struct({
|
|
78
|
+
type: Schema.tag("finish"),
|
|
79
|
+
...transcriptFields,
|
|
80
|
+
}).annotate({ identifier: "Transcription.Event.Finish" });
|
|
81
|
+
const transcriptionEventTagged = Schema.Union([
|
|
82
|
+
QueuedEvent,
|
|
83
|
+
ProgressEvent,
|
|
84
|
+
TranscriptionTextDeltaEvent,
|
|
85
|
+
TranscriptionSegmentEvent,
|
|
86
|
+
TranscriptionFinishEvent,
|
|
87
|
+
]).pipe(Schema.toTaggedUnion("type"));
|
|
88
|
+
export const TranscriptionEvent = Object.assign(transcriptionEventTagged, {
|
|
89
|
+
is: {
|
|
90
|
+
generationQueued: transcriptionEventTagged.guards["generation-queued"],
|
|
91
|
+
generationProgress: transcriptionEventTagged.guards["generation-progress"],
|
|
92
|
+
textDelta: transcriptionEventTagged.guards["text-delta"],
|
|
93
|
+
segment: transcriptionEventTagged.guards.segment,
|
|
94
|
+
finish: transcriptionEventTagged.guards.finish,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
export const responseEvents = (response) => [
|
|
98
|
+
TranscriptionFinishEvent.make({ ...response }),
|
|
99
|
+
];
|
|
100
|
+
const collectResponse = (events) => {
|
|
101
|
+
const finish = events.find(TranscriptionEvent.is.finish);
|
|
102
|
+
// Every transcription protocol's `finish` emits the terminal event or fails, so a completed stream always has one.
|
|
103
|
+
if (finish === undefined)
|
|
104
|
+
return Effect.die(new Error("The transcription stream completed without a finish event"));
|
|
105
|
+
const { type: _type, ...transcript } = finish;
|
|
106
|
+
return Effect.succeed(new TranscriptionResponse(transcript));
|
|
107
|
+
};
|
|
108
|
+
export function request(input) {
|
|
109
|
+
if (input instanceof TranscriptionRequest)
|
|
110
|
+
return input;
|
|
111
|
+
return new TranscriptionRequest({
|
|
112
|
+
...input,
|
|
113
|
+
http: input.http === undefined ? undefined : HttpOptions.make(input.http),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const requestEffect = (input) => tryRequest(() => request(input));
|
|
117
|
+
export function generate(input, options) {
|
|
118
|
+
return requestEffect(input).pipe(Effect.flatMap((request) => TranscriptionClient.generate(request, options)));
|
|
119
|
+
}
|
|
120
|
+
export function stream(input, options) {
|
|
121
|
+
return Stream.unwrap(requestEffect(input).pipe(Effect.map((request) => TranscriptionClient.stream(request, options))));
|
|
122
|
+
}
|
|
123
|
+
export function start(input) {
|
|
124
|
+
return requestEffect(input).pipe(Effect.flatMap((request) => TranscriptionClient.start(request)));
|
|
125
|
+
}
|
|
126
|
+
export const resume = (model, token) => TranscriptionClient.resume(model, token);
|
|
127
|
+
export const Transcription = {
|
|
128
|
+
request,
|
|
129
|
+
generate,
|
|
130
|
+
stream,
|
|
131
|
+
start,
|
|
132
|
+
resume,
|
|
133
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const concatBytes: (chunks: ReadonlyArray<Uint8Array>) => Uint8Array<ArrayBufferLike>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const concatBytes = (chunks) => {
|
|
2
|
+
if (chunks.length === 1)
|
|
3
|
+
return chunks[0];
|
|
4
|
+
const bytes = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));
|
|
5
|
+
chunks.reduce((offset, chunk) => {
|
|
6
|
+
bytes.set(chunk, offset);
|
|
7
|
+
return offset + chunk.length;
|
|
8
|
+
}, 0);
|
|
9
|
+
return bytes;
|
|
10
|
+
};
|
package/dist/utils/media-type.js
CHANGED
|
@@ -24,10 +24,15 @@ export const detectMediaType = (bytes) => {
|
|
|
24
24
|
return "video/mp4";
|
|
25
25
|
if (startsWith(bytes, [0x1a, 0x45, 0xdf, 0xa3]))
|
|
26
26
|
return "video/webm";
|
|
27
|
-
if (startsWith(bytes, [0x49, 0x44, 0x33])
|
|
27
|
+
if (startsWith(bytes, [0x49, 0x44, 0x33]))
|
|
28
28
|
return "audio/mpeg";
|
|
29
|
+
// An 11-bit frame sync; layer bits `00` mark AAC ADTS, any other layer is MPEG audio.
|
|
30
|
+
if (bytes.length >= 2 && bytes[0] === 0xff && (bytes[1] & 0xe0) === 0xe0)
|
|
31
|
+
return (bytes[1] & 0x06) === 0 ? "audio/aac" : "audio/mpeg";
|
|
29
32
|
if (startsWith(bytes, [0x4f, 0x67, 0x67, 0x53]))
|
|
30
33
|
return "audio/ogg";
|
|
34
|
+
if (startsWith(bytes, [0x66, 0x4c, 0x61, 0x43]))
|
|
35
|
+
return "audio/flac";
|
|
31
36
|
return undefined;
|
|
32
37
|
};
|
|
33
38
|
const EXTENSIONS = {
|
|
@@ -40,10 +45,26 @@ const EXTENSIONS = {
|
|
|
40
45
|
mp4: "video/mp4",
|
|
41
46
|
webm: "video/webm",
|
|
42
47
|
mp3: "audio/mpeg",
|
|
48
|
+
m4a: "audio/mp4",
|
|
43
49
|
wav: "audio/wav",
|
|
44
50
|
ogg: "audio/ogg",
|
|
51
|
+
flac: "audio/flac",
|
|
52
|
+
aac: "audio/aac",
|
|
45
53
|
txt: "text/plain",
|
|
46
54
|
md: "text/markdown",
|
|
47
55
|
csv: "text/csv",
|
|
48
56
|
};
|
|
49
57
|
export const extensionMediaType = (path) => EXTENSIONS[path.slice(path.lastIndexOf(".") + 1).toLowerCase()];
|
|
58
|
+
const EXTENSION_ALIASES = {
|
|
59
|
+
"audio/mp3": "mp3",
|
|
60
|
+
"audio/m4a": "m4a",
|
|
61
|
+
"audio/x-m4a": "m4a",
|
|
62
|
+
"audio/webm": "webm",
|
|
63
|
+
"audio/wave": "wav",
|
|
64
|
+
"audio/x-wav": "wav",
|
|
65
|
+
"audio/x-flac": "flac",
|
|
66
|
+
};
|
|
67
|
+
export const mediaTypeExtension = (mediaType) => {
|
|
68
|
+
const type = mediaType.split(";", 1)[0].trim().toLowerCase();
|
|
69
|
+
return EXTENSION_ALIASES[type] ?? Object.entries(EXTENSIONS).find(([, known]) => known === type)?.[0];
|
|
70
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Stream } from "effect";
|
|
2
|
+
import { type AwaitOptions, type Generation } from "./generation.js";
|
|
3
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
4
|
+
import type { AIError } from "./schema/index.js";
|
|
5
|
+
import { type VideoEvent, type VideoModel, type VideoOptions, type VideoRequestFor, type VideoResponse } from "./video.js";
|
|
6
|
+
export interface Interface {
|
|
7
|
+
readonly start: <Options extends VideoOptions>(request: VideoRequestFor<Options>) => Effect.Effect<Generation<VideoResponse>, AIError>;
|
|
8
|
+
readonly resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError>;
|
|
9
|
+
readonly generate: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Effect.Effect<VideoResponse, AIError>;
|
|
10
|
+
readonly stream: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Stream.Stream<VideoEvent, AIError>;
|
|
11
|
+
}
|
|
12
|
+
declare const Service_base: Context.ServiceClass<Service, "@opencode/VideoClient", Interface>;
|
|
13
|
+
export declare class Service extends Service_base {
|
|
14
|
+
}
|
|
15
|
+
export declare const start: <Options extends VideoOptions>(request: VideoRequestFor<Options>) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
|
|
16
|
+
export declare const resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
|
|
17
|
+
export declare const generate: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Effect.Effect<VideoResponse, AIError, Service>;
|
|
18
|
+
export declare const stream: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Stream.Stream<VideoEvent, AIError, Service>;
|
|
19
|
+
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
20
|
+
export declare const VideoClient: {
|
|
21
|
+
readonly Service: typeof Service;
|
|
22
|
+
readonly layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
23
|
+
readonly start: <Options extends VideoOptions>(request: VideoRequestFor<Options>) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
|
|
24
|
+
readonly resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
|
|
25
|
+
readonly generate: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Effect.Effect<VideoResponse, AIError, Service>;
|
|
26
|
+
readonly stream: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Stream.Stream<VideoEvent, AIError, Service>;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Stream } from "effect";
|
|
2
|
+
import { resultEvents } from "./generation.js";
|
|
3
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
4
|
+
import { responseEvents, } from "./video.js";
|
|
5
|
+
export class Service extends Context.Service()("@opencode/VideoClient") {
|
|
6
|
+
}
|
|
7
|
+
export const start = (request) => Effect.gen(function* () {
|
|
8
|
+
const client = yield* Service;
|
|
9
|
+
return yield* client.start(request);
|
|
10
|
+
});
|
|
11
|
+
export const resume = (model, token) => Effect.gen(function* () {
|
|
12
|
+
const client = yield* Service;
|
|
13
|
+
return yield* client.resume(model, token);
|
|
14
|
+
});
|
|
15
|
+
export const generate = (request, options) => Effect.gen(function* () {
|
|
16
|
+
const client = yield* Service;
|
|
17
|
+
return yield* client.generate(request, options);
|
|
18
|
+
});
|
|
19
|
+
export const stream = (request, options) => Stream.unwrap(Effect.gen(function* () {
|
|
20
|
+
const client = yield* Service;
|
|
21
|
+
return client.stream(request, options);
|
|
22
|
+
}));
|
|
23
|
+
export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
24
|
+
const executor = yield* RequestExecutor.Service;
|
|
25
|
+
const start = (request) => request.model.route.start(request, executor.execute);
|
|
26
|
+
return Service.of({
|
|
27
|
+
start,
|
|
28
|
+
resume: (model, token) => model.route.resume(model, token, executor.execute),
|
|
29
|
+
generate: (request, options) => start(request).pipe(Effect.flatMap((generation) => generation.await(options))),
|
|
30
|
+
stream: (request, options) => Stream.unwrap(start(request).pipe(Effect.map((generation) => resultEvents(generation, responseEvents, options)))),
|
|
31
|
+
});
|
|
32
|
+
}));
|
|
33
|
+
export const VideoClient = {
|
|
34
|
+
Service,
|
|
35
|
+
layer,
|
|
36
|
+
start,
|
|
37
|
+
resume,
|
|
38
|
+
generate,
|
|
39
|
+
stream,
|
|
40
|
+
};
|