@opencode/ai 2.2.0 → 2.2.2
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 +66 -62
- package/dist/effect.d.ts +1 -1
- package/dist/effect.js +1 -1
- package/dist/image-client.d.ts +45 -0
- package/dist/image.d.ts +1 -0
- package/dist/index.d.ts +38 -20
- package/dist/index.js +14 -2
- package/dist/media-client.d.ts +1 -0
- package/dist/media-client.js +1 -0
- package/dist/protocols/alibaba-chat.d.ts +39 -4
- package/dist/protocols/alibaba-responses.d.ts +20 -3
- package/dist/protocols/google-images.js +3 -1
- package/dist/protocols/meta-responses.d.ts +40 -6
- package/dist/protocols/meta-responses.js +1 -1
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/open-responses.d.ts +182 -27
- package/dist/protocols/open-responses.js +108 -36
- package/dist/protocols/openai-chat.d.ts +438 -46
- package/dist/protocols/openai-chat.js +121 -39
- package/dist/protocols/openai-compatible-chat.d.ts +35 -4
- package/dist/protocols/openai-compatible-responses.d.ts +20 -3
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +16 -1
- package/dist/protocols/openai-images.js +49 -17
- package/dist/protocols/openai-responses.d.ts +120 -18
- package/dist/protocols/openai-responses.js +17 -8
- package/dist/protocols/venice-chat.d.ts +39 -4
- package/dist/protocols/venice-chat.js +1 -1
- package/dist/protocols/xai-images.d.ts +6 -0
- package/dist/protocols/xai-images.js +4 -5
- package/dist/protocols/xai-responses.d.ts +20 -3
- package/dist/protocols/xai-responses.js +2 -1
- package/dist/protocols/zai-chat.d.ts +39 -4
- package/dist/provider-error.js +5 -4
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba.d.ts +58 -10
- package/dist/providers/amazon-bedrock-mantle.d.ts +66 -11
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +1 -1
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure.d.ts +79 -15
- package/dist/providers/baseten.d.ts +74 -12
- package/dist/providers/baseten.js +1 -1
- package/dist/providers/cerebras.d.ts +73 -11
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts +113 -17
- package/dist/providers/cloudflare-workers-ai.d.ts +73 -11
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +73 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +73 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +73 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +320 -21
- package/dist/providers/digitalocean.js +18 -7
- package/dist/providers/fireworks.d.ts +73 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex-chat.d.ts +36 -5
- package/dist/providers/google-vertex-chat.js +1 -1
- package/dist/providers/google-vertex-interactions.d.ts +1 -1
- package/dist/providers/google-vertex-interactions.js +1 -1
- package/dist/providers/google-vertex-messages.d.ts +1 -1
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-mistral.d.ts +1 -1
- package/dist/providers/google-vertex-mistral.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +21 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +2 -2
- package/dist/providers/google-vertex.js +1 -1
- package/dist/providers/google.d.ts +2 -2
- package/dist/providers/google.js +1 -1
- package/dist/providers/groq.d.ts +77 -11
- package/dist/providers/groq.js +1 -1
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/index.js +0 -4
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta.d.ts +61 -12
- package/dist/providers/meta.js +2 -1
- package/dist/providers/minimax/chat.d.ts +1 -1
- package/dist/providers/minimax/chat.js +1 -1
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/responses.d.ts +1 -1
- package/dist/providers/minimax/responses.js +1 -1
- package/dist/providers/minimax.d.ts +63 -9
- package/dist/providers/minimax.js +22 -9
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/moonshot/messages.d.ts +1 -1
- package/dist/providers/moonshot/messages.js +1 -1
- package/dist/providers/moonshot/responses.d.ts +1 -1
- package/dist/providers/moonshot/responses.js +1 -1
- package/dist/providers/moonshot.d.ts +56 -8
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai-compatible-responses.d.ts +21 -4
- package/dist/providers/openai-compatible.d.ts +38 -7
- package/dist/providers/openai-compatible.js +9 -2
- package/dist/providers/openai.d.ts +59 -11
- package/dist/providers/openai.js +4 -2
- package/dist/providers/opencode.d.ts +3 -3
- package/dist/providers/opencode.js +1 -1
- package/dist/providers/openrouter/responses.d.ts +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +356 -26
- package/dist/providers/openrouter.js +42 -13
- package/dist/providers/togetherai.d.ts +73 -11
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai.d.ts +3 -3
- package/dist/providers/typesafe-ai.js +1 -1
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +242 -9
- package/dist/providers/venice.js +33 -17
- package/dist/providers/vercel-ai-gateway.d.ts +8 -8
- package/dist/providers/vercel-ai-gateway.js +12 -2
- package/dist/providers/xai.d.ts +39 -8
- package/dist/providers/xai.js +1 -1
- package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
- package/dist/providers/zai-coding-plan/messages.js +1 -1
- package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
- package/dist/providers/zai-coding-plan/responses.js +1 -1
- package/dist/providers/zai-coding-plan.d.ts +56 -8
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +37 -6
- package/dist/providers/zai.js +1 -1
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/media-protocol.d.ts +2 -4
- package/dist/route/media.d.ts +1 -1
- package/dist/route/media.js +2 -4
- package/dist/schema/events.d.ts +2 -0
- package/dist/schema/messages.d.ts +35 -1
- package/dist/schema/messages.js +20 -0
- package/dist/speech-client.d.ts +48 -0
- package/dist/speech.d.ts +1 -0
- package/dist/testing/decision.d.ts +16 -0
- package/dist/testing/decision.js +20 -0
- package/dist/testing/image.d.ts +14 -0
- package/dist/testing/image.js +12 -0
- package/dist/testing/media.d.ts +18 -0
- package/dist/testing/media.js +36 -0
- package/dist/testing/script.d.ts +28 -0
- package/dist/testing/script.js +60 -0
- package/dist/testing/speech.d.ts +14 -0
- package/dist/testing/speech.js +12 -0
- package/dist/testing/transcription.d.ts +14 -0
- package/dist/testing/transcription.js +12 -0
- package/dist/testing/video.d.ts +14 -0
- package/dist/testing/video.js +12 -0
- package/dist/testing.d.ts +10 -21
- package/dist/testing.js +11 -54
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +64 -0
- package/dist/transcription.d.ts +1 -0
- package/dist/video-client.d.ts +41 -0
- package/dist/video.d.ts +1 -0
- package/package.json +24 -40
- package/dist/protocols/bfl-images.d.ts +0 -47
- package/dist/protocols/bfl-images.js +0 -155
- package/dist/protocols/fal-images.d.ts +0 -34
- package/dist/protocols/fal-images.js +0 -95
- package/dist/protocols/fal-video.d.ts +0 -29
- package/dist/protocols/fal-video.js +0 -73
- package/dist/protocols/replicate-images.d.ts +0 -28
- package/dist/protocols/replicate-images.js +0 -127
- package/dist/protocols/stability-images.d.ts +0 -44
- package/dist/protocols/stability-images.js +0 -131
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/providers/black-forest-labs.d.ts +0 -21
- package/dist/providers/black-forest-labs.js +0 -23
- package/dist/providers/fal.d.ts +0 -24
- package/dist/providers/fal.js +0 -26
- package/dist/providers/replicate.d.ts +0 -21
- package/dist/providers/replicate.js +0 -17
- package/dist/providers/stability.d.ts +0 -23
- package/dist/providers/stability.js +0 -18
|
@@ -8,6 +8,70 @@ export declare class TranscriptionClientService extends TranscriptionClientServi
|
|
|
8
8
|
export declare const Service: typeof TranscriptionClientService;
|
|
9
9
|
export type Service = TranscriptionClientService;
|
|
10
10
|
export declare const TranscriptionClient: {
|
|
11
|
+
readonly responseEvents: (response: TranscriptionResponse) => readonly ({
|
|
12
|
+
readonly type: "text-delta";
|
|
13
|
+
readonly delta: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly type: "segment";
|
|
16
|
+
readonly segment: {
|
|
17
|
+
readonly text: string;
|
|
18
|
+
readonly startSeconds: number;
|
|
19
|
+
readonly endSeconds: number;
|
|
20
|
+
readonly speaker?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
readonly type: "generation-queued";
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly position?: number | undefined;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "generation-progress";
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly progress?: number | undefined;
|
|
30
|
+
} | {
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly segments?: readonly {
|
|
33
|
+
readonly text: string;
|
|
34
|
+
readonly startSeconds: number;
|
|
35
|
+
readonly endSeconds: number;
|
|
36
|
+
readonly speaker?: string | undefined;
|
|
37
|
+
}[] | undefined;
|
|
38
|
+
readonly words?: readonly {
|
|
39
|
+
readonly text: string;
|
|
40
|
+
readonly startSeconds: number;
|
|
41
|
+
readonly endSeconds: number;
|
|
42
|
+
readonly speaker?: string | undefined;
|
|
43
|
+
readonly confidence?: number | undefined;
|
|
44
|
+
}[] | undefined;
|
|
45
|
+
readonly language?: string | undefined;
|
|
46
|
+
readonly durationSeconds?: number | undefined;
|
|
47
|
+
readonly usage?: {
|
|
48
|
+
readonly type: "seconds";
|
|
49
|
+
readonly seconds: number;
|
|
50
|
+
} | {
|
|
51
|
+
readonly type: "characters";
|
|
52
|
+
readonly characters: number;
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: "credits";
|
|
55
|
+
readonly credits: number;
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: "compute";
|
|
58
|
+
readonly seconds: number;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: "tokens";
|
|
61
|
+
readonly input?: number | undefined;
|
|
62
|
+
readonly output?: number | undefined;
|
|
63
|
+
readonly total?: number | undefined;
|
|
64
|
+
readonly details?: {
|
|
65
|
+
readonly [x: string]: unknown;
|
|
66
|
+
} | undefined;
|
|
67
|
+
} | undefined;
|
|
68
|
+
readonly providerMetadata?: {
|
|
69
|
+
readonly [x: string]: {
|
|
70
|
+
readonly [x: string]: unknown;
|
|
71
|
+
};
|
|
72
|
+
} | undefined;
|
|
73
|
+
readonly type: "finish";
|
|
74
|
+
})[];
|
|
11
75
|
readonly layer: import("effect/Layer").Layer<TranscriptionClientService, never, import("./route.js").RequestExecutorService>;
|
|
12
76
|
readonly generate: (request: TranscriptionRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<TranscriptionResponse, import("./effect.js").AIError, TranscriptionClientService>;
|
|
13
77
|
readonly stream: (request: TranscriptionRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<{
|
package/dist/transcription.d.ts
CHANGED
|
@@ -305,6 +305,7 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
305
305
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
306
306
|
readonly type: Schema.tag<"finish">;
|
|
307
307
|
}>]> & {
|
|
308
|
+
readonly tag: "type";
|
|
308
309
|
readonly discriminants: readonly ["generation-queued", "generation-progress", "text-delta", "segment", "finish"];
|
|
309
310
|
readonly cases: {
|
|
310
311
|
finish: Schema.Struct<{
|
package/dist/video-client.d.ts
CHANGED
|
@@ -8,6 +8,47 @@ export declare class VideoClientService extends VideoClientService_base {
|
|
|
8
8
|
export declare const Service: typeof VideoClientService;
|
|
9
9
|
export type Service = VideoClientService;
|
|
10
10
|
export declare const VideoClient: {
|
|
11
|
+
readonly responseEvents: (response: VideoResponse) => readonly ({
|
|
12
|
+
readonly type: "video";
|
|
13
|
+
readonly index: number;
|
|
14
|
+
readonly video: import("./media.js").Asset;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: "generation-queued";
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly position?: number | undefined;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "generation-progress";
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly progress?: number | undefined;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "finish";
|
|
25
|
+
readonly usage?: {
|
|
26
|
+
readonly type: "seconds";
|
|
27
|
+
readonly seconds: number;
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "characters";
|
|
30
|
+
readonly characters: number;
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "credits";
|
|
33
|
+
readonly credits: number;
|
|
34
|
+
} | {
|
|
35
|
+
readonly type: "compute";
|
|
36
|
+
readonly seconds: number;
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "tokens";
|
|
39
|
+
readonly input?: number | undefined;
|
|
40
|
+
readonly output?: number | undefined;
|
|
41
|
+
readonly total?: number | undefined;
|
|
42
|
+
readonly details?: {
|
|
43
|
+
readonly [x: string]: unknown;
|
|
44
|
+
} | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
readonly providerMetadata?: {
|
|
47
|
+
readonly [x: string]: {
|
|
48
|
+
readonly [x: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
} | undefined;
|
|
51
|
+
})[];
|
|
11
52
|
readonly layer: import("effect/Layer").Layer<VideoClientService, never, import("./route.js").RequestExecutorService>;
|
|
12
53
|
readonly generate: (request: VideoRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<VideoResponse, import("./effect.js").AIError, VideoClientService>;
|
|
13
54
|
readonly stream: (request: VideoRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<{
|
package/dist/video.d.ts
CHANGED
|
@@ -492,6 +492,7 @@ export declare const VideoEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
492
492
|
}>]>>;
|
|
493
493
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
494
494
|
}>]> & {
|
|
495
|
+
readonly tag: "type";
|
|
495
496
|
readonly discriminants: readonly ["generation-queued", "generation-progress", "video", "finish"];
|
|
496
497
|
readonly cases: {
|
|
497
498
|
finish: Schema.Struct<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,10 +64,6 @@
|
|
|
64
64
|
"import": "./dist/providers/amazon-bedrock.js",
|
|
65
65
|
"types": "./dist/providers/amazon-bedrock.d.ts"
|
|
66
66
|
},
|
|
67
|
-
"./providers/amazon-bedrock-mantle": {
|
|
68
|
-
"import": "./dist/providers/amazon-bedrock-mantle.js",
|
|
69
|
-
"types": "./dist/providers/amazon-bedrock-mantle.d.ts"
|
|
70
|
-
},
|
|
71
67
|
"./providers/amazon-bedrock/mantle": {
|
|
72
68
|
"import": "./dist/providers/amazon-bedrock/mantle.js",
|
|
73
69
|
"types": "./dist/providers/amazon-bedrock/mantle.d.ts"
|
|
@@ -120,10 +116,6 @@
|
|
|
120
116
|
"import": "./dist/providers/baseten/decisions.js",
|
|
121
117
|
"types": "./dist/providers/baseten/decisions.d.ts"
|
|
122
118
|
},
|
|
123
|
-
"./providers/black-forest-labs": {
|
|
124
|
-
"import": "./dist/providers/black-forest-labs.js",
|
|
125
|
-
"types": "./dist/providers/black-forest-labs.d.ts"
|
|
126
|
-
},
|
|
127
119
|
"./providers/cartesia": {
|
|
128
120
|
"import": "./dist/providers/cartesia.js",
|
|
129
121
|
"types": "./dist/providers/cartesia.d.ts"
|
|
@@ -184,14 +176,14 @@
|
|
|
184
176
|
"import": "./dist/providers/digitalocean/images.js",
|
|
185
177
|
"types": "./dist/providers/digitalocean/images.d.ts"
|
|
186
178
|
},
|
|
179
|
+
"./providers/digitalocean/responses": {
|
|
180
|
+
"import": "./dist/providers/digitalocean/responses.js",
|
|
181
|
+
"types": "./dist/providers/digitalocean/responses.d.ts"
|
|
182
|
+
},
|
|
187
183
|
"./providers/elevenlabs": {
|
|
188
184
|
"import": "./dist/providers/elevenlabs.js",
|
|
189
185
|
"types": "./dist/providers/elevenlabs.d.ts"
|
|
190
186
|
},
|
|
191
|
-
"./providers/fal": {
|
|
192
|
-
"import": "./dist/providers/fal.js",
|
|
193
|
-
"types": "./dist/providers/fal.d.ts"
|
|
194
|
-
},
|
|
195
187
|
"./providers/fireworks": {
|
|
196
188
|
"import": "./dist/providers/fireworks.js",
|
|
197
189
|
"types": "./dist/providers/fireworks.d.ts"
|
|
@@ -204,26 +196,10 @@
|
|
|
204
196
|
"import": "./dist/providers/google-vertex.js",
|
|
205
197
|
"types": "./dist/providers/google-vertex.d.ts"
|
|
206
198
|
},
|
|
207
|
-
"./providers/google-vertex-chat": {
|
|
208
|
-
"import": "./dist/providers/google-vertex-chat.js",
|
|
209
|
-
"types": "./dist/providers/google-vertex-chat.d.ts"
|
|
210
|
-
},
|
|
211
|
-
"./providers/google-vertex-interactions": {
|
|
212
|
-
"import": "./dist/providers/google-vertex-interactions.js",
|
|
213
|
-
"types": "./dist/providers/google-vertex-interactions.d.ts"
|
|
214
|
-
},
|
|
215
199
|
"./providers/google-vertex-messages": {
|
|
216
200
|
"import": "./dist/providers/google-vertex-messages.js",
|
|
217
201
|
"types": "./dist/providers/google-vertex-messages.d.ts"
|
|
218
202
|
},
|
|
219
|
-
"./providers/google-vertex-mistral": {
|
|
220
|
-
"import": "./dist/providers/google-vertex-mistral.js",
|
|
221
|
-
"types": "./dist/providers/google-vertex-mistral.d.ts"
|
|
222
|
-
},
|
|
223
|
-
"./providers/google-vertex-responses": {
|
|
224
|
-
"import": "./dist/providers/google-vertex-responses.js",
|
|
225
|
-
"types": "./dist/providers/google-vertex-responses.d.ts"
|
|
226
|
-
},
|
|
227
203
|
"./providers/google-vertex/chat": {
|
|
228
204
|
"import": "./dist/providers/google-vertex/chat.js",
|
|
229
205
|
"types": "./dist/providers/google-vertex/chat.d.ts"
|
|
@@ -272,6 +248,10 @@
|
|
|
272
248
|
"import": "./dist/providers/meta/chat.js",
|
|
273
249
|
"types": "./dist/providers/meta/chat.d.ts"
|
|
274
250
|
},
|
|
251
|
+
"./providers/meta/images": {
|
|
252
|
+
"import": "./dist/providers/meta/images.js",
|
|
253
|
+
"types": "./dist/providers/meta/images.d.ts"
|
|
254
|
+
},
|
|
275
255
|
"./providers/meta/messages": {
|
|
276
256
|
"import": "./dist/providers/meta/messages.js",
|
|
277
257
|
"types": "./dist/providers/meta/messages.d.ts"
|
|
@@ -288,6 +268,10 @@
|
|
|
288
268
|
"import": "./dist/providers/minimax/chat.js",
|
|
289
269
|
"types": "./dist/providers/minimax/chat.d.ts"
|
|
290
270
|
},
|
|
271
|
+
"./providers/minimax/images": {
|
|
272
|
+
"import": "./dist/providers/minimax/images.js",
|
|
273
|
+
"types": "./dist/providers/minimax/images.d.ts"
|
|
274
|
+
},
|
|
291
275
|
"./providers/minimax/messages": {
|
|
292
276
|
"import": "./dist/providers/minimax/messages.js",
|
|
293
277
|
"types": "./dist/providers/minimax/messages.d.ts"
|
|
@@ -368,18 +352,14 @@
|
|
|
368
352
|
"import": "./dist/providers/openrouter/images.js",
|
|
369
353
|
"types": "./dist/providers/openrouter/images.d.ts"
|
|
370
354
|
},
|
|
371
|
-
"./providers/
|
|
372
|
-
"import": "./dist/providers/
|
|
373
|
-
"types": "./dist/providers/
|
|
355
|
+
"./providers/openrouter/responses": {
|
|
356
|
+
"import": "./dist/providers/openrouter/responses.js",
|
|
357
|
+
"types": "./dist/providers/openrouter/responses.d.ts"
|
|
374
358
|
},
|
|
375
359
|
"./providers/runway": {
|
|
376
360
|
"import": "./dist/providers/runway.js",
|
|
377
361
|
"types": "./dist/providers/runway.d.ts"
|
|
378
362
|
},
|
|
379
|
-
"./providers/stability": {
|
|
380
|
-
"import": "./dist/providers/stability.js",
|
|
381
|
-
"types": "./dist/providers/stability.d.ts"
|
|
382
|
-
},
|
|
383
363
|
"./providers/togetherai": {
|
|
384
364
|
"import": "./dist/providers/togetherai.js",
|
|
385
365
|
"types": "./dist/providers/togetherai.d.ts"
|
|
@@ -396,6 +376,10 @@
|
|
|
396
376
|
"import": "./dist/providers/venice.js",
|
|
397
377
|
"types": "./dist/providers/venice.d.ts"
|
|
398
378
|
},
|
|
379
|
+
"./providers/venice/responses": {
|
|
380
|
+
"import": "./dist/providers/venice/responses.js",
|
|
381
|
+
"types": "./dist/providers/venice/responses.d.ts"
|
|
382
|
+
},
|
|
399
383
|
"./providers/vercel-ai-gateway": {
|
|
400
384
|
"import": "./dist/providers/vercel-ai-gateway.js",
|
|
401
385
|
"types": "./dist/providers/vercel-ai-gateway.d.ts"
|
|
@@ -531,8 +515,8 @@
|
|
|
531
515
|
},
|
|
532
516
|
"devDependencies": {
|
|
533
517
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
534
|
-
"@effect/platform-node": "4.0.
|
|
535
|
-
"@opencode/http-recorder": "2.2.
|
|
518
|
+
"@effect/platform-node": "4.0.6",
|
|
519
|
+
"@opencode/http-recorder": "2.2.2",
|
|
536
520
|
"@tsconfig/bun": "1.0.9",
|
|
537
521
|
"@types/bun": "1.4.3",
|
|
538
522
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -542,9 +526,9 @@
|
|
|
542
526
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
543
527
|
"@smithy/eventstream-codec": "4.2.14",
|
|
544
528
|
"@smithy/util-utf8": "4.2.2",
|
|
545
|
-
"@opencode/schema": "2.2.
|
|
529
|
+
"@opencode/schema": "2.2.2",
|
|
546
530
|
"aws4fetch": "1.0.20",
|
|
547
|
-
"effect": "4.0.
|
|
531
|
+
"effect": "4.0.6",
|
|
548
532
|
"google-auth-library": "10.5.0"
|
|
549
533
|
},
|
|
550
534
|
"repository": {
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
|
|
3
|
-
import { Media } from "../media.js";
|
|
4
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
-
import { MediaRoute } from "../route/media.js";
|
|
6
|
-
import { type OpenString } from "../schema/index.js";
|
|
7
|
-
export declare const DEFAULT_BASE_URL = "https://api.bfl.ai";
|
|
8
|
-
/** Native body fields; `aspect` and `resolution` lower to `width`/`height` or `aspect_ratio` depending on the model. */
|
|
9
|
-
export type BlackForestLabsImageOptions = {
|
|
10
|
-
readonly width?: number;
|
|
11
|
-
readonly height?: number;
|
|
12
|
-
readonly seed?: number;
|
|
13
|
-
readonly output_format?: OpenString<"jpeg" | "png" | "webp">;
|
|
14
|
-
/** Inpainting mask for `flux-pro-1.0-fill`. */
|
|
15
|
-
readonly mask?: Media.Asset;
|
|
16
|
-
readonly safety_tolerance?: number;
|
|
17
|
-
readonly prompt_upsampling?: boolean;
|
|
18
|
-
readonly disable_pup?: boolean;
|
|
19
|
-
readonly raw?: boolean;
|
|
20
|
-
readonly guidance?: number;
|
|
21
|
-
readonly steps?: number;
|
|
22
|
-
} & Record<string, unknown>;
|
|
23
|
-
export type Request = ImageRequestFor<BlackForestLabsImageOptions>;
|
|
24
|
-
/**
|
|
25
|
-
* Regional clusters answer on different hosts, so the returned `polling_url` is followed verbatim. BFL reports the
|
|
26
|
-
* credit cost on submit, so it rides on the token; it is optional so tokens persisted before it existed still decode.
|
|
27
|
-
*/
|
|
28
|
-
export declare const Token: Schema.Struct<{
|
|
29
|
-
readonly id: Schema.String;
|
|
30
|
-
readonly pollingURL: Schema.String;
|
|
31
|
-
readonly cost: Schema.optionalKey<Schema.Number>;
|
|
32
|
-
}>;
|
|
33
|
-
export type Token = Schema.Schema.Type<typeof Token>;
|
|
34
|
-
export declare const protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
35
|
-
readonly id: string;
|
|
36
|
-
readonly pollingURL: string;
|
|
37
|
-
readonly cost?: number | undefined;
|
|
38
|
-
}>;
|
|
39
|
-
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<BlackForestLabsImageOptions>;
|
|
40
|
-
export declare const BlackForestLabsImages: {
|
|
41
|
-
readonly protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
42
|
-
readonly id: string;
|
|
43
|
-
readonly pollingURL: string;
|
|
44
|
-
readonly cost?: number | undefined;
|
|
45
|
-
}>;
|
|
46
|
-
readonly model: typeof model;
|
|
47
|
-
};
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
|
-
import { Media } from "../media.js";
|
|
4
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
-
import { MediaRoute } from "../route/media.js";
|
|
6
|
-
import { mergeJsonRecords } from "../schema/index.js";
|
|
7
|
-
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
-
import { ImageSizing } from "./utils/image-sizing.js";
|
|
9
|
-
const route = MediaProtocol.identity({ id: "bfl-images", name: "Black Forest Labs", provider: "black-forest-labs" });
|
|
10
|
-
export const DEFAULT_BASE_URL = "https://api.bfl.ai";
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
// 2. Token and response schemas
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
/**
|
|
15
|
-
* Regional clusters answer on different hosts, so the returned `polling_url` is followed verbatim. BFL reports the
|
|
16
|
-
* credit cost on submit, so it rides on the token; it is optional so tokens persisted before it existed still decode.
|
|
17
|
-
*/
|
|
18
|
-
export const Token = Schema.Struct({
|
|
19
|
-
id: Schema.String,
|
|
20
|
-
pollingURL: Schema.String,
|
|
21
|
-
cost: Schema.optionalKey(Schema.Number),
|
|
22
|
-
});
|
|
23
|
-
const StartResponse = Schema.Struct({
|
|
24
|
-
id: Schema.String,
|
|
25
|
-
polling_url: Schema.String,
|
|
26
|
-
cost: optionalNull(Schema.Number),
|
|
27
|
-
});
|
|
28
|
-
const Result = Schema.Struct({
|
|
29
|
-
id: Schema.String,
|
|
30
|
-
status: Schema.String,
|
|
31
|
-
result: optionalNull(Schema.StructWithRest(Schema.Struct({ sample: Schema.String, seed: optionalNull(Schema.Number), prompt: optionalNull(Schema.String) }), [Schema.Record(Schema.String, Schema.Unknown)])),
|
|
32
|
-
cost: optionalNull(Schema.Number),
|
|
33
|
-
});
|
|
34
|
-
const STATUS = {
|
|
35
|
-
Pending: "running",
|
|
36
|
-
Reasoning: "running",
|
|
37
|
-
Generating: "running",
|
|
38
|
-
Ready: "completed",
|
|
39
|
-
Error: "failed",
|
|
40
|
-
// Moderation is terminal; `decodeResult` reports it as a content-policy failure.
|
|
41
|
-
"Content Moderated": "failed",
|
|
42
|
-
"Request Moderated": "failed",
|
|
43
|
-
"Task not found": "expired",
|
|
44
|
-
};
|
|
45
|
-
const isModerated = (status) => status === "Content Moderated" || status === "Request Moderated";
|
|
46
|
-
const LEGACY_LIMITS = { multiple: 32, minEdge: 256, maxEdge: 1440 };
|
|
47
|
-
const FLUX_2_LIMITS = { multiple: 16, minEdge: 64, maxPixels: 4_194_304 };
|
|
48
|
-
const capabilities = (model) => {
|
|
49
|
-
if (model.startsWith("flux-pro-1.0-fill"))
|
|
50
|
-
return { sizing: "none", imageField: "image", maxImages: 1, mask: true };
|
|
51
|
-
if (model.startsWith("flux-pro-1.0-expand"))
|
|
52
|
-
return { sizing: "none", imageField: "image", maxImages: 1, mask: false };
|
|
53
|
-
if (model.startsWith("flux-kontext"))
|
|
54
|
-
return { sizing: "aspectRatio", imageField: "input_image", maxImages: 4, mask: false };
|
|
55
|
-
if (model.startsWith("flux-pro-1.1-ultra"))
|
|
56
|
-
return { sizing: "aspectRatio", imageField: "image_prompt", maxImages: 1, mask: false };
|
|
57
|
-
if (model.startsWith("flux-pro-1.1") || model.startsWith("flux-dev"))
|
|
58
|
-
return { sizing: LEGACY_LIMITS, imageField: "image_prompt", maxImages: 1, mask: false };
|
|
59
|
-
if (model.startsWith("flux-2-klein"))
|
|
60
|
-
return { sizing: FLUX_2_LIMITS, imageField: "input_image", maxImages: 4, mask: false };
|
|
61
|
-
return { sizing: FLUX_2_LIMITS, imageField: "input_image", maxImages: 8, mask: false };
|
|
62
|
-
};
|
|
63
|
-
const validate = (request, model) => {
|
|
64
|
-
const id = request.model.id;
|
|
65
|
-
const images = request.images?.length ?? 0;
|
|
66
|
-
if (request.n !== undefined && request.n > 1)
|
|
67
|
-
return Effect.fail(route.unsupported("media.n", `${id} generates one image per request; call it once per image`));
|
|
68
|
-
if (request.aspect !== undefined && model.sizing === "none")
|
|
69
|
-
return Effect.fail(route.unsupported("media.aspect", `${id} keeps the source image's size`));
|
|
70
|
-
if (request.resolution !== undefined && typeof model.sizing === "string")
|
|
71
|
-
return Effect.fail(route.unsupported("media.resolution", `${id} does not take resolution`));
|
|
72
|
-
if (images > model.maxImages)
|
|
73
|
-
return Effect.fail(route.unsupported("media.images", `${id} takes at most ${model.maxImages} images`));
|
|
74
|
-
if (request.providerOptions?.mask !== undefined && !model.mask)
|
|
75
|
-
return Effect.fail(route.unsupported("media.mask", `${id} does not inpaint; use flux-pro-1.0-fill`));
|
|
76
|
-
return Effect.void;
|
|
77
|
-
};
|
|
78
|
-
const imageInput = (asset) => {
|
|
79
|
-
const value = asset.inline()?.base64 ?? ProviderShared.mediaUrl(asset);
|
|
80
|
-
if (value === undefined)
|
|
81
|
-
return Effect.fail(ProviderShared.invalidRequest(`${route.name} accepts inline images or https URLs`));
|
|
82
|
-
return Effect.succeed(value);
|
|
83
|
-
};
|
|
84
|
-
const fromRequest = Effect.fn("BlackForestLabsImages.fromRequest")(function* (request) {
|
|
85
|
-
const model = capabilities(request.model.id);
|
|
86
|
-
yield* validate(request, model);
|
|
87
|
-
const images = yield* Effect.forEach(request.images ?? [], imageInput);
|
|
88
|
-
const fields = images.map((image, index) => [
|
|
89
|
-
index === 0 ? model.imageField : `${model.imageField}_${index + 1}`,
|
|
90
|
-
image,
|
|
91
|
-
]);
|
|
92
|
-
const { mask, ...native } = request.providerOptions ?? {};
|
|
93
|
-
const size = typeof model.sizing === "string" ? undefined : yield* ImageSizing.exact(route, request, model.sizing);
|
|
94
|
-
return MediaProtocol.json(mergeJsonRecords({
|
|
95
|
-
prompt: request.prompt,
|
|
96
|
-
...size,
|
|
97
|
-
aspect_ratio: model.sizing === "aspectRatio" ? request.aspect : undefined,
|
|
98
|
-
mask: mask === undefined ? undefined : yield* imageInput(mask),
|
|
99
|
-
...Object.fromEntries(fields),
|
|
100
|
-
}, native, request.http?.body) ?? {});
|
|
101
|
-
});
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
// 6. Response decoding
|
|
104
|
-
// ---------------------------------------------------------------------------
|
|
105
|
-
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
106
|
-
token: {
|
|
107
|
-
id: value.id,
|
|
108
|
-
pollingURL: value.polling_url,
|
|
109
|
-
...(value.cost === undefined || value.cost === null ? {} : { cost: value.cost }),
|
|
110
|
-
},
|
|
111
|
-
snapshot: { id: value.id, status: "queued" },
|
|
112
|
-
}));
|
|
113
|
-
const decodeDocument = route.decodeJson(Result);
|
|
114
|
-
const decodeStatus = Effect.fn("BlackForestLabsImages.decodeStatus")(function* (response, context) {
|
|
115
|
-
const output = yield* decodeDocument(response);
|
|
116
|
-
return { id: context.token.id, status: yield* MediaProtocol.status(STATUS, output.value.status, output) };
|
|
117
|
-
});
|
|
118
|
-
const decodeResult = Effect.fn("BlackForestLabsImages.decodeResult")(function* (response, context) {
|
|
119
|
-
const output = yield* decodeDocument(response);
|
|
120
|
-
const document = output.value;
|
|
121
|
-
const status = yield* MediaProtocol.status(STATUS, document.status, output);
|
|
122
|
-
if (isModerated(document.status))
|
|
123
|
-
return yield* output.contentPolicy(`${route.name} moderated the generation`);
|
|
124
|
-
if (status === "failed" || status === "expired")
|
|
125
|
-
return yield* output.ended(status, `${route.name} generation ${context.token.id} ended with ${document.status}`);
|
|
126
|
-
if (status !== "completed")
|
|
127
|
-
return yield* output.pending(context.token.id);
|
|
128
|
-
if (document.result === undefined || document.result === null)
|
|
129
|
-
return yield* output.invalid(`${route.name} generation ${context.token.id} has no result`);
|
|
130
|
-
const { sample, seed, prompt, ...rest } = document.result;
|
|
131
|
-
// A settled `cost` on the result supersedes the submit-time cost carried on the token.
|
|
132
|
-
const cost = document.cost ?? context.token.cost;
|
|
133
|
-
return new ImageResponse({
|
|
134
|
-
// `sample` is a signed URL that expires 10 minutes after the result is ready, so it is downloaded now.
|
|
135
|
-
images: [yield* context.materialize(Media.url(sample))],
|
|
136
|
-
usage: cost === undefined ? undefined : { type: "credits", credits: cost },
|
|
137
|
-
providerMetadata: {
|
|
138
|
-
bfl: { id: context.token.id, seed: seed ?? undefined, prompt: prompt ?? undefined, ...rest },
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
// ---------------------------------------------------------------------------
|
|
143
|
-
// 7. Protocol and route
|
|
144
|
-
// ---------------------------------------------------------------------------
|
|
145
|
-
export const protocol = MediaProtocol.queued(route, {
|
|
146
|
-
token: Token,
|
|
147
|
-
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
148
|
-
status: { path: (token) => token.pollingURL, decode: decodeStatus },
|
|
149
|
-
result: { path: (token) => token.pollingURL, decode: decodeResult },
|
|
150
|
-
});
|
|
151
|
-
export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: ({ request }) => `/v1/${request.model.id}` }, input);
|
|
152
|
-
export const BlackForestLabsImages = {
|
|
153
|
-
protocol,
|
|
154
|
-
model,
|
|
155
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
|
|
2
|
-
import { Media } from "../media.js";
|
|
3
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
-
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
import { type OpenString } from "../schema/index.js";
|
|
6
|
-
/** Model-defined `input` fields; `aspect` and `resolution` lower to `image_size` or `aspect_ratio` per model. */
|
|
7
|
-
export type FalImageOptions = {
|
|
8
|
-
readonly image_size?: OpenString<"square_hd" | "square" | "portrait_4_3" | "portrait_16_9" | "landscape_4_3" | "landscape_16_9"> | {
|
|
9
|
-
readonly width: number;
|
|
10
|
-
readonly height: number;
|
|
11
|
-
};
|
|
12
|
-
readonly seed?: number;
|
|
13
|
-
readonly output_format?: OpenString<"jpeg" | "png" | "webp">;
|
|
14
|
-
/** Inpainting mask, sent as `mask_url`. */
|
|
15
|
-
readonly mask?: Media.Asset;
|
|
16
|
-
readonly enable_safety_checker?: boolean;
|
|
17
|
-
} & Record<string, unknown>;
|
|
18
|
-
export type Request = ImageRequestFor<FalImageOptions>;
|
|
19
|
-
export declare const protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
20
|
-
readonly requestID: string;
|
|
21
|
-
readonly statusURL: string;
|
|
22
|
-
readonly responseURL: string;
|
|
23
|
-
readonly cancelURL: string;
|
|
24
|
-
}>;
|
|
25
|
-
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<FalImageOptions>;
|
|
26
|
-
export declare const FalImages: {
|
|
27
|
-
readonly protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
28
|
-
readonly requestID: string;
|
|
29
|
-
readonly statusURL: string;
|
|
30
|
-
readonly responseURL: string;
|
|
31
|
-
readonly cancelURL: string;
|
|
32
|
-
}>;
|
|
33
|
-
readonly model: typeof model;
|
|
34
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
|
-
import { Media } from "../media.js";
|
|
4
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
-
import { MediaRoute } from "../route/media.js";
|
|
6
|
-
import { mergeJsonRecords } from "../schema/index.js";
|
|
7
|
-
import { optionalNull } from "./shared.js";
|
|
8
|
-
import { FalQueue } from "./utils/fal-queue.js";
|
|
9
|
-
import { ImageSizing } from "./utils/image-sizing.js";
|
|
10
|
-
const route = MediaProtocol.identity({ id: "fal-images", name: "fal Images", provider: "fal" });
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
// 2. Response schema
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
const QueueResult = Schema.StructWithRest(Schema.Struct({
|
|
15
|
-
images: Schema.Array(Schema.Struct({
|
|
16
|
-
url: Schema.String,
|
|
17
|
-
width: optionalNull(Schema.Number),
|
|
18
|
-
height: optionalNull(Schema.Number),
|
|
19
|
-
content_type: optionalNull(Schema.String),
|
|
20
|
-
})),
|
|
21
|
-
seed: optionalNull(Schema.Number),
|
|
22
|
-
has_nsfw_concepts: optionalNull(Schema.Array(Schema.Boolean)),
|
|
23
|
-
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
// 5. Request body construction
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
/** Nano Banana takes `aspect_ratio` and `resolution` tiers, FLUX Ultra and Kontext only `aspect_ratio`, FLUX `image_size`. */
|
|
28
|
-
const sizing = (model) => {
|
|
29
|
-
if (model.startsWith("fal-ai/nano-banana"))
|
|
30
|
-
return "tiers";
|
|
31
|
-
if (/^fal-ai\/flux-pro\/(v1\.1-ultra|kontext)/.test(model))
|
|
32
|
-
return "aspect_ratio";
|
|
33
|
-
if (model.startsWith("fal-ai/flux"))
|
|
34
|
-
return "image_size";
|
|
35
|
-
return undefined;
|
|
36
|
-
};
|
|
37
|
-
const validate = (request) => {
|
|
38
|
-
const id = request.model.id;
|
|
39
|
-
if (request.resolution !== undefined && sizing(id) === "aspect_ratio")
|
|
40
|
-
return Effect.fail(route.unsupported("media.resolution", `${id} sizes by aspect only`));
|
|
41
|
-
if ((request.images?.length ?? 0) > 1 && !takesImageList(id))
|
|
42
|
-
return Effect.fail(route.unsupported("media.images", `${id} takes one image_url; use an /edit or /multi endpoint for several images`));
|
|
43
|
-
return Effect.void;
|
|
44
|
-
};
|
|
45
|
-
// `/edit` and `/multi` (Kontext) endpoints take an `image_urls` list; image-to-image, fill, and Ultra take one
|
|
46
|
-
// `image_url` (beside `mask_url`).
|
|
47
|
-
const takesImageList = (model) => model.endsWith("/edit") || model.endsWith("/multi");
|
|
48
|
-
const fromRequest = Effect.fn("FalImages.fromRequest")(function* (request) {
|
|
49
|
-
yield* validate(request);
|
|
50
|
-
const images = yield* Effect.forEach(request.images ?? [], (image) => FalQueue.mediaUrl(image, route.name));
|
|
51
|
-
const list = takesImageList(request.model.id);
|
|
52
|
-
const { mask, ...native } = request.providerOptions ?? {};
|
|
53
|
-
const field = sizing(request.model.id);
|
|
54
|
-
return MediaProtocol.json(mergeJsonRecords({
|
|
55
|
-
prompt: request.prompt,
|
|
56
|
-
num_images: request.n,
|
|
57
|
-
...(field === "image_size"
|
|
58
|
-
? { image_size: yield* ImageSizing.exact(route, request, { multiple: 16 }) }
|
|
59
|
-
: { aspect_ratio: request.aspect, resolution: request.resolution }),
|
|
60
|
-
image_urls: list && images.length > 0 ? images : undefined,
|
|
61
|
-
image_url: list ? undefined : images[0],
|
|
62
|
-
mask_url: mask === undefined ? undefined : yield* FalQueue.mediaUrl(mask, route.name),
|
|
63
|
-
}, native, request.http?.body) ?? {});
|
|
64
|
-
});
|
|
65
|
-
// ---------------------------------------------------------------------------
|
|
66
|
-
// 6. Response decoding
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
const decodeQueueResult = route.decodeJson(QueueResult);
|
|
69
|
-
const decodeResult = Effect.fn("FalImages.decodeResult")(function* (response, context) {
|
|
70
|
-
const output = yield* decodeQueueResult(response);
|
|
71
|
-
const { images, seed, ...rest } = output.value;
|
|
72
|
-
if (images.length === 0)
|
|
73
|
-
return yield* output.invalid(`${route.name} returned no images`);
|
|
74
|
-
return new ImageResponse({
|
|
75
|
-
images: images.map((image) => {
|
|
76
|
-
const info = { width: image.width ?? undefined, height: image.height ?? undefined };
|
|
77
|
-
// `sync_mode: true` returns data URIs instead of hosted URLs.
|
|
78
|
-
return (Media.parseDataUrl(image.url, { info }) ??
|
|
79
|
-
Media.url(image.url, { mediaType: image.content_type ?? undefined, info }));
|
|
80
|
-
}),
|
|
81
|
-
providerMetadata: { fal: { requestId: context.token.requestID, seed: seed ?? undefined, ...rest } },
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
// 7. Protocol and route
|
|
86
|
-
// ---------------------------------------------------------------------------
|
|
87
|
-
export const protocol = FalQueue.protocol(route, {
|
|
88
|
-
from: fromRequest,
|
|
89
|
-
decodeResult,
|
|
90
|
-
});
|
|
91
|
-
export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: FalQueue.DEFAULT_BASE_URL, path: ({ request }) => `/${request.model.id}` }, input);
|
|
92
|
-
export const FalImages = {
|
|
93
|
-
protocol,
|
|
94
|
-
model,
|
|
95
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
|
-
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { VideoModel, VideoResponse, type VideoRequestFor } from "../video.js";
|
|
5
|
-
/**
|
|
6
|
-
* Provider-native input. fal video endpoints are model-specific: `duration` is a string enum whose values differ per
|
|
7
|
-
* model (`"8s"` for Veo, `"5"` for Kling), and last-frame fields are named per model (`end_image_url`,
|
|
8
|
-
* `last_frame_url`, `tail_image_url`), so those pass through here instead of lowering from common fields.
|
|
9
|
-
*/
|
|
10
|
-
export type FalVideoOptions = {
|
|
11
|
-
readonly duration?: OpenString<"4s" | "6s" | "8s" | "5" | "10">;
|
|
12
|
-
} & Record<string, unknown>;
|
|
13
|
-
export type Request = VideoRequestFor<FalVideoOptions>;
|
|
14
|
-
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
15
|
-
readonly requestID: string;
|
|
16
|
-
readonly statusURL: string;
|
|
17
|
-
readonly responseURL: string;
|
|
18
|
-
readonly cancelURL: string;
|
|
19
|
-
}>;
|
|
20
|
-
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<FalVideoOptions>;
|
|
21
|
-
export declare const FalVideo: {
|
|
22
|
-
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
23
|
-
readonly requestID: string;
|
|
24
|
-
readonly statusURL: string;
|
|
25
|
-
readonly responseURL: string;
|
|
26
|
-
readonly cancelURL: string;
|
|
27
|
-
}>;
|
|
28
|
-
readonly model: typeof model;
|
|
29
|
-
};
|