@opencode/ai 2.1.4 → 2.2.1
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 +339 -166
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +4 -0
- package/dist/cache-policy.js +20 -6
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +472 -0
- package/dist/decision.js +158 -0
- package/dist/effect.d.ts +38 -0
- package/dist/effect.js +27 -0
- package/dist/effort-updates.d.ts +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
- package/dist/experimental/cloudflare-run-extraction.js +83 -0
- package/dist/experimental/extraction.d.ts +183 -0
- package/dist/experimental/extraction.js +102 -0
- package/dist/experimental/realtime.d.ts +7 -2
- package/dist/experimental/realtime.js +5 -5
- package/dist/experimental.d.ts +2 -3
- package/dist/experimental.js +1 -2
- package/dist/image-client.d.ts +50 -14
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +6 -176
- package/dist/image.js +4 -11
- package/dist/index.d.ts +1444 -34
- package/dist/index.js +139 -24
- package/dist/llm.d.ts +16 -1
- package/dist/llm.js +34 -0
- package/dist/media-client.d.ts +3 -1
- package/dist/media-client.js +1 -0
- package/dist/media-model.d.ts +3 -0
- package/dist/media-model.js +4 -1
- package/dist/media.d.ts +0 -7
- package/dist/media.js +0 -6
- package/dist/protocols/alibaba-chat.d.ts +59 -4
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +52 -17
- package/dist/protocols/alibaba-responses.d.ts +26 -6
- package/dist/protocols/anthropic-messages.d.ts +160 -54
- package/dist/protocols/anthropic-messages.js +44 -13
- package/dist/protocols/bedrock-converse.d.ts +110 -15
- package/dist/protocols/bedrock-converse.js +112 -15
- package/dist/protocols/bedrock-event-stream.js +1 -0
- package/dist/protocols/cartesia-speech.d.ts +0 -18
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
- package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
- package/dist/protocols/deepgram-speech.d.ts +0 -18
- package/dist/protocols/elevenlabs-speech.d.ts +0 -18
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +11 -6
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +10 -37
- package/dist/protocols/google-interactions.d.ts +4 -0
- package/dist/protocols/google-interactions.js +12 -5
- package/dist/protocols/google-speech.d.ts +0 -18
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +0 -18
- package/dist/protocols/google-transcription.js +0 -1
- package/dist/protocols/google-video.d.ts +1 -1
- package/dist/protocols/google-video.js +2 -7
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +7 -1
- package/dist/protocols/meta-images.js +10 -8
- package/dist/protocols/meta-messages.d.ts +52 -17
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +46 -6
- package/dist/protocols/meta-responses.js +29 -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 +212 -27
- package/dist/protocols/open-responses.js +116 -54
- package/dist/protocols/openai-chat.d.ts +1135 -31
- package/dist/protocols/openai-chat.js +155 -60
- package/dist/protocols/openai-compatible-chat.d.ts +57 -5
- package/dist/protocols/openai-compatible-responses.d.ts +28 -8
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +36 -24
- package/dist/protocols/openai-images.js +137 -39
- package/dist/protocols/openai-responses.d.ts +202 -42
- package/dist/protocols/openai-responses.js +49 -10
- package/dist/protocols/openai-speech.d.ts +0 -18
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +0 -18
- package/dist/protocols/openai-transcription.js +3 -4
- package/dist/protocols/runway-video.d.ts +1 -1
- package/dist/protocols/runway-video.js +1 -1
- package/dist/protocols/shared.d.ts +9 -1
- package/dist/protocols/shared.js +13 -2
- package/dist/protocols/system-one.d.ts +101 -0
- package/dist/protocols/system-one.js +230 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.js +7 -6
- package/dist/protocols/utils/cache.d.ts +14 -3
- package/dist/protocols/utils/cache.js +11 -4
- package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
- package/dist/protocols/utils/gemini-generate-content.js +10 -16
- package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
- package/dist/protocols/utils/gemini-json-schema.js +3 -3
- package/dist/protocols/utils/image-sizing.d.ts +31 -0
- package/dist/protocols/utils/image-sizing.js +73 -0
- package/dist/protocols/utils/media-input.d.ts +4 -5
- package/dist/protocols/utils/media-input.js +8 -5
- package/dist/protocols/utils/speech-stream.d.ts +0 -1
- package/dist/protocols/utils/speech-stream.js +0 -1
- package/dist/protocols/utils/tool-schema.js +15 -5
- package/dist/protocols/utils/tool-stream.d.ts +9 -0
- package/dist/protocols/venice-chat.d.ts +58 -4
- package/dist/protocols/venice-chat.js +2 -2
- package/dist/protocols/xai-images.d.ts +7 -2
- package/dist/protocols/xai-images.js +11 -5
- package/dist/protocols/xai-responses.d.ts +30 -3
- package/dist/protocols/xai-responses.js +30 -3
- package/dist/protocols/xai-video.d.ts +1 -1
- package/dist/protocols/xai-video.js +11 -8
- package/dist/protocols/zai-chat.d.ts +60 -4
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +52 -17
- package/dist/provider-error.js +23 -7
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +137 -28
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +259 -145
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +34 -14
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +53 -18
- package/dist/providers/anthropic.d.ts +53 -18
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +129 -24
- package/dist/providers/azure.js +19 -1
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +124 -12
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +115 -11
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +290 -60
- package/dist/providers/cloudflare-ai-gateway.js +32 -4
- package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
- package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/images.js +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +128 -12
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +115 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +115 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +115 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.js +1 -0
- package/dist/providers/digitalocean/images.d.ts +2 -0
- package/dist/providers/digitalocean/images.js +1 -0
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +390 -20
- package/dist/providers/digitalocean.js +53 -11
- package/dist/providers/fireworks.d.ts +115 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +57 -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 +53 -18
- 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 +24 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +4 -2
- package/dist/providers/google-vertex.js +30 -13
- package/dist/providers/google.d.ts +6 -5
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +119 -15
- package/dist/providers/groq.js +1 -7
- 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 +254 -146
- 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 +139 -26
- 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 +132 -25
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.js +1 -0
- package/dist/providers/openai-compatible/images.d.ts +2 -0
- package/dist/providers/openai-compatible/images.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +24 -4
- package/dist/providers/openai-compatible.d.ts +62 -8
- package/dist/providers/openai-compatible.js +29 -10
- package/dist/providers/openai-options.d.ts +3 -1
- package/dist/providers/openai.d.ts +103 -18
- package/dist/providers/openai.js +23 -5
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +11 -12
- package/dist/providers/opencode.js +10 -8
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.js +1 -0
- package/dist/providers/openrouter/images.d.ts +2 -0
- package/dist/providers/openrouter/images.js +1 -0
- package/dist/providers/openrouter/responses.d.ts +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +446 -35
- package/dist/providers/openrouter.js +78 -27
- package/dist/providers/togetherai.d.ts +115 -11
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
- package/dist/providers/typesafe-ai/decisions.js +1 -0
- package/dist/providers/typesafe-ai.d.ts +11 -12
- package/dist/providers/typesafe-ai.js +10 -8
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +261 -9
- package/dist/providers/venice.js +33 -17
- package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
- package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +16 -22
- package/dist/providers/vercel-ai-gateway.js +41 -85
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai.d.ts +66 -12
- package/dist/providers/xai.js +15 -8
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- 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 +132 -25
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +62 -9
- package/dist/providers/zai.js +15 -8
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/client.d.ts +2 -2
- package/dist/route/client.js +26 -4
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor.d.ts +1 -1
- package/dist/route/framing.d.ts +2 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.js +3 -0
- package/dist/route/media-protocol.d.ts +3 -4
- package/dist/route/media-protocol.js +12 -8
- package/dist/route/media.d.ts +6 -2
- package/dist/route/media.js +8 -6
- package/dist/route/transport/http.js +1 -0
- package/dist/route/transport/index.d.ts +1 -0
- package/dist/schema/events.d.ts +148 -6
- package/dist/schema/events.js +20 -0
- package/dist/schema/messages.d.ts +41 -3
- package/dist/schema/messages.js +23 -0
- package/dist/schema/options.d.ts +5 -3
- package/dist/schema/options.js +8 -3
- package/dist/speech-client.d.ts +53 -14
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +0 -135
- package/dist/speech.js +2 -4
- 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 +35 -45
- package/dist/testing.js +14 -75
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +69 -14
- package/dist/transcription.d.ts +0 -135
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +46 -14
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +1 -136
- package/dist/video.js +3 -5
- package/package.json +497 -11
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/system-one.d.ts +0 -16
- package/dist/experimental/system-one.js +0 -135
- package/dist/promise.d.ts +0 -1021
- package/dist/promise.js +0 -101
- package/dist/protocols/bfl-images.d.ts +0 -38
- package/dist/protocols/bfl-images.js +0 -153
- package/dist/protocols/fal-images.d.ts +0 -25
- package/dist/protocols/fal-images.js +0 -104
- 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 -39
- package/dist/protocols/stability-images.js +0 -136
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/provider.d.ts +0 -23
- package/dist/provider.js +0 -2
- 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
package/dist/promise.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Effect, Layer, ManagedRuntime, Stream } from "effect";
|
|
2
|
-
import { AIClient } from "./ai-client.js";
|
|
3
|
-
import { Image } from "./image.js";
|
|
4
|
-
import { LLM } from "./index.js";
|
|
5
|
-
import { Media } from "./media.js";
|
|
6
|
-
import { RequestExecutor } from "./route/executor.js";
|
|
7
|
-
import { AIError, InvalidRequestError, LanguageModel } from "./schema/index.js";
|
|
8
|
-
import { Speech } from "./speech.js";
|
|
9
|
-
import { Transcription, } from "./transcription.js";
|
|
10
|
-
import { fileMediaType } from "./utils/media-type.js";
|
|
11
|
-
import { Video } from "./video.js";
|
|
12
|
-
// Fails with `signal.reason` so aborted calls reject and aborted streams throw like `fetch`: an `AbortError` by default.
|
|
13
|
-
const abortEffect = (signal) => signal === undefined
|
|
14
|
-
? Effect.never
|
|
15
|
-
: Effect.callback((resume) => {
|
|
16
|
-
if (signal.aborted) {
|
|
17
|
-
resume(Effect.fail(signal.reason));
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const onAbort = () => resume(Effect.fail(signal.reason));
|
|
21
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
22
|
-
return Effect.sync(() => signal.removeEventListener("abort", onAbort));
|
|
23
|
-
});
|
|
24
|
-
export const make = (options = {}) => {
|
|
25
|
-
const runtime = ManagedRuntime.make(AIClient.layerWith(options.layer ?? RequestExecutor.fetchLayer));
|
|
26
|
-
/** Run any package Effect (for example `LLMClient.compact(...)`) inside this runtime. */
|
|
27
|
-
const run = (effect, options) => runtime.runPromise(Effect.raceFirst(effect, abortEffect(options?.signal)));
|
|
28
|
-
const iterate = (stream, options) => Stream.toAsyncIterable(Stream.unwrap(runtime.contextEffect.pipe(Effect.map((context) => stream.pipe(Stream.interruptWhen(abortEffect(options?.signal)), Stream.provideContext(context))))));
|
|
29
|
-
const handle = (generation) => ({
|
|
30
|
-
...generation.snapshot,
|
|
31
|
-
token: generation.token,
|
|
32
|
-
await: (options) => run(generation.await({ poll: options?.poll }), options),
|
|
33
|
-
events: (options) => iterate(generation.events({ poll: options?.poll }), options),
|
|
34
|
-
result: (options) => run(generation.result(), options),
|
|
35
|
-
refresh: (options) => run(generation.refresh(), options).then(handle),
|
|
36
|
-
cancel: (options) => run(generation.cancel(), options),
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
run,
|
|
40
|
-
/** Decoded asset bytes, downloading `url` sources through the executor. */
|
|
41
|
-
bytes: (asset, options) => run(asset.bytes(), options),
|
|
42
|
-
base64: (asset, options) => run(asset.base64(), options),
|
|
43
|
-
/** Pull a `url` asset into owned bytes before the provider URL expires. */
|
|
44
|
-
materialize: (asset, options) => run(asset.materialize(), options),
|
|
45
|
-
/** Read a file into an asset like `Media.file`: sniffed media type, then the extension's. */
|
|
46
|
-
file: async (path, options) => {
|
|
47
|
-
const { readFile } = await import("node:fs/promises");
|
|
48
|
-
return run(Effect.tryPromise({
|
|
49
|
-
try: (signal) => readFile(path, { signal }),
|
|
50
|
-
catch: (cause) => fileError(`Failed to read media file ${path}`, cause),
|
|
51
|
-
}).pipe(Effect.map((buffer) => {
|
|
52
|
-
const data = new Uint8Array(buffer);
|
|
53
|
-
return Media.bytes(data, fileMediaType(data, path), options);
|
|
54
|
-
})), options);
|
|
55
|
-
},
|
|
56
|
-
/** Write an asset's bytes like `Media.write`, downloading `url` sources through the executor. */
|
|
57
|
-
write: async (asset, path, options) => {
|
|
58
|
-
const { writeFile } = await import("node:fs/promises");
|
|
59
|
-
return run(asset.bytes().pipe(Effect.flatMap((data) => Effect.tryPromise({
|
|
60
|
-
try: (signal) => writeFile(path, data, { signal }),
|
|
61
|
-
catch: (cause) => fileError(`Failed to write media file ${path}`, cause),
|
|
62
|
-
}))), options);
|
|
63
|
-
},
|
|
64
|
-
llm: {
|
|
65
|
-
request: LLM.request,
|
|
66
|
-
generate: (input, options) => run(LLM.generate(input), options),
|
|
67
|
-
stream: (input, options) => iterate(LLM.stream(input), options),
|
|
68
|
-
},
|
|
69
|
-
image: {
|
|
70
|
-
request: Image.request,
|
|
71
|
-
generate: (input, options) => run(Image.generate(input, { poll: options?.poll }), options),
|
|
72
|
-
stream: (input, options) => iterate(Image.stream(input, { poll: options?.poll }), options),
|
|
73
|
-
start: (input, options) => run(Image.start(input), options).then(handle),
|
|
74
|
-
resume: (model, token, options) => run(Image.resume(model, token), options).then(handle),
|
|
75
|
-
},
|
|
76
|
-
video: {
|
|
77
|
-
request: Video.request,
|
|
78
|
-
start: (input, options) => run(Video.start(input), options).then(handle),
|
|
79
|
-
generate: (input, options) => run(Video.generate(input, { poll: options?.poll }), options),
|
|
80
|
-
resume: (model, token, options) => run(Video.resume(model, token), options).then(handle),
|
|
81
|
-
stream: (input, options) => iterate(Video.stream(input, { poll: options?.poll }), options),
|
|
82
|
-
},
|
|
83
|
-
speech: {
|
|
84
|
-
request: Speech.request,
|
|
85
|
-
generate: (input, options) => run(Speech.generate(input), options),
|
|
86
|
-
stream: (input, options) => iterate(Speech.stream(input), options),
|
|
87
|
-
},
|
|
88
|
-
transcription: {
|
|
89
|
-
request: Transcription.request,
|
|
90
|
-
generate: (input, options) => run(Transcription.generate(input, { poll: options?.poll }), options),
|
|
91
|
-
stream: (input, options) => iterate(Transcription.stream(input, { poll: options?.poll }), options),
|
|
92
|
-
start: (input, options) => run(Transcription.start(input), options).then(handle),
|
|
93
|
-
resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle),
|
|
94
|
-
},
|
|
95
|
-
dispose: () => runtime.dispose(),
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
const fileError = (message, cause) => new AIError({ reason: new InvalidRequestError({ message, cause }) });
|
|
99
|
-
/** Default client over `RequestExecutor.fetchLayer` for scripts; the runtime builds its layer on first use. */
|
|
100
|
-
export const ai = make();
|
|
101
|
-
export * as AI from "./promise.js";
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
|
|
3
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
-
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
export declare const DEFAULT_BASE_URL = "https://api.bfl.ai";
|
|
6
|
-
export type BlackForestLabsImageOptions = {
|
|
7
|
-
readonly safety_tolerance?: number;
|
|
8
|
-
readonly prompt_upsampling?: boolean;
|
|
9
|
-
readonly disable_pup?: boolean;
|
|
10
|
-
readonly raw?: boolean;
|
|
11
|
-
readonly guidance?: number;
|
|
12
|
-
readonly steps?: number;
|
|
13
|
-
} & Record<string, unknown>;
|
|
14
|
-
export type Request = ImageRequestFor<BlackForestLabsImageOptions>;
|
|
15
|
-
/**
|
|
16
|
-
* Regional clusters answer on different hosts, so the returned `polling_url` is followed verbatim. BFL reports the
|
|
17
|
-
* credit cost on submit, so it rides on the token; it is optional so tokens persisted before it existed still decode.
|
|
18
|
-
*/
|
|
19
|
-
export declare const Token: Schema.Struct<{
|
|
20
|
-
readonly id: Schema.String;
|
|
21
|
-
readonly pollingURL: Schema.String;
|
|
22
|
-
readonly cost: Schema.optionalKey<Schema.Number>;
|
|
23
|
-
}>;
|
|
24
|
-
export type Token = Schema.Schema.Type<typeof Token>;
|
|
25
|
-
export declare const protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
26
|
-
readonly id: string;
|
|
27
|
-
readonly pollingURL: string;
|
|
28
|
-
readonly cost?: number | undefined;
|
|
29
|
-
}>;
|
|
30
|
-
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<BlackForestLabsImageOptions>;
|
|
31
|
-
export declare const BlackForestLabsImages: {
|
|
32
|
-
readonly protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
33
|
-
readonly id: string;
|
|
34
|
-
readonly pollingURL: string;
|
|
35
|
-
readonly cost?: number | undefined;
|
|
36
|
-
}>;
|
|
37
|
-
readonly model: typeof model;
|
|
38
|
-
};
|
|
@@ -1,153 +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 { MediaInput } from "./utils/media-input.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 capabilities = (model) => {
|
|
47
|
-
if (model.startsWith("flux-pro-1.0-fill"))
|
|
48
|
-
return { sizing: "none", imageField: "image", maxImages: 1, mask: true };
|
|
49
|
-
if (model.startsWith("flux-pro-1.0-expand"))
|
|
50
|
-
return { sizing: "none", imageField: "image", maxImages: 1, mask: false };
|
|
51
|
-
if (model.startsWith("flux-kontext"))
|
|
52
|
-
return { sizing: "aspectRatio", imageField: "input_image", maxImages: 4, mask: false };
|
|
53
|
-
if (model.startsWith("flux-pro-1.1-ultra"))
|
|
54
|
-
return { sizing: "aspectRatio", imageField: "image_prompt", maxImages: 1, mask: false };
|
|
55
|
-
if (model.startsWith("flux-pro-1.1") || model.startsWith("flux-dev"))
|
|
56
|
-
return { sizing: "dimensions", imageField: "image_prompt", maxImages: 1, mask: false };
|
|
57
|
-
if (model.startsWith("flux-2-klein"))
|
|
58
|
-
return { sizing: "dimensions", imageField: "input_image", maxImages: 4, mask: false };
|
|
59
|
-
return { sizing: "dimensions", imageField: "input_image", maxImages: 8, mask: false };
|
|
60
|
-
};
|
|
61
|
-
const validate = (request, model) => {
|
|
62
|
-
const id = request.model.id;
|
|
63
|
-
const images = request.images?.length ?? 0;
|
|
64
|
-
if (request.n !== undefined && request.n > 1)
|
|
65
|
-
return Effect.fail(route.unsupported("media.n", `${id} generates one image per request; call it once per image`));
|
|
66
|
-
if (request.size !== undefined && model.sizing !== "dimensions")
|
|
67
|
-
return Effect.fail(route.unsupported("media.size", `${id} does not take size (width and height)`));
|
|
68
|
-
if (request.aspectRatio !== undefined && model.sizing !== "aspectRatio")
|
|
69
|
-
return Effect.fail(route.unsupported("media.aspectRatio", `${id} does not take aspectRatio`));
|
|
70
|
-
if (images > model.maxImages)
|
|
71
|
-
return Effect.fail(route.unsupported("media.images", `${id} takes at most ${model.maxImages} images`));
|
|
72
|
-
if (request.mask !== undefined && !model.mask)
|
|
73
|
-
return Effect.fail(route.unsupported("media.mask", `${id} does not inpaint; use flux-pro-1.0-fill`));
|
|
74
|
-
return Effect.void;
|
|
75
|
-
};
|
|
76
|
-
const imageInput = (asset) => {
|
|
77
|
-
const value = asset.inline()?.base64 ?? ProviderShared.mediaUrl(asset);
|
|
78
|
-
if (value === undefined)
|
|
79
|
-
return Effect.fail(ProviderShared.invalidRequest(`${route.name} accepts inline images or https URLs`));
|
|
80
|
-
return Effect.succeed(value);
|
|
81
|
-
};
|
|
82
|
-
const fromRequest = Effect.fn("BlackForestLabsImages.fromRequest")(function* (request) {
|
|
83
|
-
const model = capabilities(request.model.id);
|
|
84
|
-
yield* validate(request, model);
|
|
85
|
-
const images = yield* Effect.forEach(request.images ?? [], imageInput);
|
|
86
|
-
const fields = images.map((image, index) => [
|
|
87
|
-
index === 0 ? model.imageField : `${model.imageField}_${index + 1}`,
|
|
88
|
-
image,
|
|
89
|
-
]);
|
|
90
|
-
return MediaProtocol.json(mergeJsonRecords({
|
|
91
|
-
prompt: request.prompt,
|
|
92
|
-
...(request.size === undefined ? {} : MediaInput.dimensions(request.size)),
|
|
93
|
-
aspect_ratio: request.aspectRatio,
|
|
94
|
-
seed: request.seed,
|
|
95
|
-
output_format: request.format,
|
|
96
|
-
mask: request.mask === undefined ? undefined : yield* imageInput(request.mask),
|
|
97
|
-
...Object.fromEntries(fields),
|
|
98
|
-
}, request.providerOptions, request.http?.body) ?? {});
|
|
99
|
-
});
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
// 6. Response decoding
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
104
|
-
token: {
|
|
105
|
-
id: value.id,
|
|
106
|
-
pollingURL: value.polling_url,
|
|
107
|
-
...(value.cost === undefined || value.cost === null ? {} : { cost: value.cost }),
|
|
108
|
-
},
|
|
109
|
-
snapshot: { id: value.id, status: "queued" },
|
|
110
|
-
}));
|
|
111
|
-
const decodeDocument = route.decodeJson(Result);
|
|
112
|
-
const decodeStatus = Effect.fn("BlackForestLabsImages.decodeStatus")(function* (response, context) {
|
|
113
|
-
const output = yield* decodeDocument(response);
|
|
114
|
-
return { id: context.token.id, status: yield* MediaProtocol.status(STATUS, output.value.status, output) };
|
|
115
|
-
});
|
|
116
|
-
const decodeResult = Effect.fn("BlackForestLabsImages.decodeResult")(function* (response, context) {
|
|
117
|
-
const output = yield* decodeDocument(response);
|
|
118
|
-
const document = output.value;
|
|
119
|
-
const status = yield* MediaProtocol.status(STATUS, document.status, output);
|
|
120
|
-
if (isModerated(document.status))
|
|
121
|
-
return yield* output.contentPolicy(`${route.name} moderated the generation`);
|
|
122
|
-
if (status === "failed" || status === "expired")
|
|
123
|
-
return yield* output.ended(status, `${route.name} generation ${context.token.id} ended with ${document.status}`);
|
|
124
|
-
if (status !== "completed")
|
|
125
|
-
return yield* output.pending(context.token.id);
|
|
126
|
-
if (document.result === undefined || document.result === null)
|
|
127
|
-
return yield* output.invalid(`${route.name} generation ${context.token.id} has no result`);
|
|
128
|
-
const { sample, seed, prompt, ...rest } = document.result;
|
|
129
|
-
// A settled `cost` on the result supersedes the submit-time cost carried on the token.
|
|
130
|
-
const cost = document.cost ?? context.token.cost;
|
|
131
|
-
return new ImageResponse({
|
|
132
|
-
// `sample` is a signed URL that expires 10 minutes after the result is ready, so it is downloaded now.
|
|
133
|
-
images: [yield* context.materialize(Media.url(sample))],
|
|
134
|
-
usage: cost === undefined ? undefined : { type: "credits", credits: cost },
|
|
135
|
-
providerMetadata: {
|
|
136
|
-
bfl: { id: context.token.id, seed: seed ?? undefined, prompt: prompt ?? undefined, ...rest },
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
// ---------------------------------------------------------------------------
|
|
141
|
-
// 7. Protocol and route
|
|
142
|
-
// ---------------------------------------------------------------------------
|
|
143
|
-
export const protocol = MediaProtocol.queued(route, {
|
|
144
|
-
token: Token,
|
|
145
|
-
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
146
|
-
status: { path: (token) => token.pollingURL, decode: decodeStatus },
|
|
147
|
-
result: { path: (token) => token.pollingURL, decode: decodeResult },
|
|
148
|
-
});
|
|
149
|
-
export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: ({ request }) => `/v1/${request.model.id}` }, input);
|
|
150
|
-
export const BlackForestLabsImages = {
|
|
151
|
-
protocol,
|
|
152
|
-
model,
|
|
153
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
|
|
2
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
-
import { MediaRoute } from "../route/media.js";
|
|
4
|
-
import { type OpenString } from "../schema/index.js";
|
|
5
|
-
export type FalImageOptions = {
|
|
6
|
-
readonly image_size?: OpenString<"square_hd" | "square" | "portrait_4_3" | "portrait_16_9" | "landscape_4_3" | "landscape_16_9">;
|
|
7
|
-
readonly enable_safety_checker?: boolean;
|
|
8
|
-
} & Record<string, unknown>;
|
|
9
|
-
export type Request = ImageRequestFor<FalImageOptions>;
|
|
10
|
-
export declare const protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
11
|
-
readonly requestID: string;
|
|
12
|
-
readonly statusURL: string;
|
|
13
|
-
readonly responseURL: string;
|
|
14
|
-
readonly cancelURL: string;
|
|
15
|
-
}>;
|
|
16
|
-
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<FalImageOptions>;
|
|
17
|
-
export declare const FalImages: {
|
|
18
|
-
readonly protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
19
|
-
readonly requestID: string;
|
|
20
|
-
readonly statusURL: string;
|
|
21
|
-
readonly responseURL: string;
|
|
22
|
-
readonly cancelURL: string;
|
|
23
|
-
}>;
|
|
24
|
-
readonly model: typeof model;
|
|
25
|
-
};
|
|
@@ -1,104 +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 { FalQueue } from "./utils/fal-queue.js";
|
|
9
|
-
import { MediaInput } from "./utils/media-input.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
|
-
const sizing = (model) => {
|
|
28
|
-
if (/^fal-ai\/(nano-banana|flux-pro\/(v1\.1-ultra|kontext))/.test(model))
|
|
29
|
-
return "aspect_ratio";
|
|
30
|
-
if (model.startsWith("fal-ai/flux"))
|
|
31
|
-
return "image_size";
|
|
32
|
-
return undefined;
|
|
33
|
-
};
|
|
34
|
-
const validate = (request) => {
|
|
35
|
-
const id = request.model.id;
|
|
36
|
-
const field = sizing(id);
|
|
37
|
-
if (request.size !== undefined && request.aspectRatio !== undefined)
|
|
38
|
-
return Effect.fail(ProviderShared.invalidRequest(`${route.name} accepts either size or aspectRatio, not both`));
|
|
39
|
-
if (request.size !== undefined && field === "aspect_ratio")
|
|
40
|
-
return Effect.fail(route.unsupported("media.size", `${id} sizes by aspectRatio`));
|
|
41
|
-
if (request.aspectRatio !== undefined && field === "image_size")
|
|
42
|
-
return Effect.fail(route.unsupported("media.aspectRatio", `${id} sizes by size (image_size)`));
|
|
43
|
-
if ((request.images?.length ?? 0) > 1 && !takesImageList(id))
|
|
44
|
-
return Effect.fail(route.unsupported("media.images", `${id} takes one image_url; use an /edit or /multi endpoint for several images`));
|
|
45
|
-
return Effect.void;
|
|
46
|
-
};
|
|
47
|
-
// `/edit` and `/multi` (Kontext) endpoints take an `image_urls` list; image-to-image, fill, and Ultra take one
|
|
48
|
-
// `image_url` (beside `mask_url`).
|
|
49
|
-
const takesImageList = (model) => model.endsWith("/edit") || model.endsWith("/multi");
|
|
50
|
-
const fromRequest = Effect.fn("FalImages.fromRequest")(function* (request) {
|
|
51
|
-
yield* validate(request);
|
|
52
|
-
const images = yield* Effect.forEach(request.images ?? [], (image) => FalQueue.mediaUrl(image, route.name));
|
|
53
|
-
const list = takesImageList(request.model.id);
|
|
54
|
-
return MediaProtocol.json(mergeJsonRecords({
|
|
55
|
-
prompt: request.prompt,
|
|
56
|
-
num_images: request.n,
|
|
57
|
-
seed: request.seed,
|
|
58
|
-
image_size: request.size === undefined ? undefined : MediaInput.dimensions(request.size),
|
|
59
|
-
aspect_ratio: request.aspectRatio,
|
|
60
|
-
output_format: request.format,
|
|
61
|
-
image_urls: list && images.length > 0 ? images : undefined,
|
|
62
|
-
image_url: list ? undefined : images[0],
|
|
63
|
-
mask_url: request.mask === undefined ? undefined : yield* FalQueue.mediaUrl(request.mask, route.name),
|
|
64
|
-
}, request.providerOptions, request.http?.body) ?? {});
|
|
65
|
-
});
|
|
66
|
-
// ---------------------------------------------------------------------------
|
|
67
|
-
// 6. Response decoding
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
const decodeQueueResult = route.decodeJson(QueueResult);
|
|
70
|
-
const decodeResult = Effect.fn("FalImages.decodeResult")(function* (response, context) {
|
|
71
|
-
const output = yield* decodeQueueResult(response);
|
|
72
|
-
const { images, seed, has_nsfw_concepts, ...rest } = output.value;
|
|
73
|
-
if (images.length === 0)
|
|
74
|
-
return yield* output.invalid(`${route.name} returned no images`);
|
|
75
|
-
// With the safety checker on, flagged images come back blacked out rather than omitted.
|
|
76
|
-
const flagged = (has_nsfw_concepts ?? []).flatMap((value, index) => (value ? [index] : []));
|
|
77
|
-
return new ImageResponse({
|
|
78
|
-
images: images.map((image) => {
|
|
79
|
-
const info = { width: image.width ?? undefined, height: image.height ?? undefined };
|
|
80
|
-
// `sync_mode: true` returns data URIs instead of hosted URLs.
|
|
81
|
-
return (Media.parseDataUrl(image.url, { info }) ??
|
|
82
|
-
Media.url(image.url, { mediaType: image.content_type ?? undefined, info }));
|
|
83
|
-
}),
|
|
84
|
-
notices: flagged.length === 0
|
|
85
|
-
? undefined
|
|
86
|
-
: flagged.map((index) => ({
|
|
87
|
-
type: "moderated",
|
|
88
|
-
message: `${route.name} flagged image ${index} as NSFW`,
|
|
89
|
-
})),
|
|
90
|
-
providerMetadata: { fal: { requestId: context.token.requestID, seed: seed ?? undefined, ...rest } },
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
// ---------------------------------------------------------------------------
|
|
94
|
-
// 7. Protocol and route
|
|
95
|
-
// ---------------------------------------------------------------------------
|
|
96
|
-
export const protocol = FalQueue.protocol(route, {
|
|
97
|
-
from: fromRequest,
|
|
98
|
-
decodeResult,
|
|
99
|
-
});
|
|
100
|
-
export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: FalQueue.DEFAULT_BASE_URL, path: ({ request }) => `/${request.model.id}` }, input);
|
|
101
|
-
export const FalImages = {
|
|
102
|
-
protocol,
|
|
103
|
-
model,
|
|
104
|
-
};
|
|
@@ -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
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { Media } from "../media.js";
|
|
3
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
-
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
-
import { VideoModel, VideoResponse } from "../video.js";
|
|
7
|
-
import { optionalNull } from "./shared.js";
|
|
8
|
-
import { FalQueue } from "./utils/fal-queue.js";
|
|
9
|
-
const route = MediaProtocol.identity({ id: "fal-video", name: "fal Video", provider: "fal" });
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
// 2. Response schema
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
const QueueResult = Schema.StructWithRest(Schema.Struct({
|
|
14
|
-
video: Schema.Struct({
|
|
15
|
-
url: Schema.String,
|
|
16
|
-
content_type: optionalNull(Schema.String),
|
|
17
|
-
file_name: optionalNull(Schema.String),
|
|
18
|
-
file_size: optionalNull(Schema.Number),
|
|
19
|
-
}),
|
|
20
|
-
seed: optionalNull(Schema.Number),
|
|
21
|
-
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// 5. Request body construction
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
const fromRequest = Effect.fn("FalVideo.fromRequest")(function* (request) {
|
|
26
|
-
if (request.frames?.last !== undefined)
|
|
27
|
-
return yield* route.unsupported("video.frames.last", `${route.name} names the last frame per model; pass it through providerOptions (e.g. end_image_url) instead of frames.last`);
|
|
28
|
-
const imageUrl = request.frames?.first === undefined ? undefined : yield* FalQueue.mediaUrl(request.frames.first, route.name);
|
|
29
|
-
const videoUrl = request.video === undefined ? undefined : yield* FalQueue.mediaUrl(request.video, route.name);
|
|
30
|
-
return MediaProtocol.json(mergeJsonRecords({
|
|
31
|
-
prompt: request.prompt,
|
|
32
|
-
negative_prompt: request.negativePrompt,
|
|
33
|
-
seed: request.seed,
|
|
34
|
-
aspect_ratio: request.aspectRatio,
|
|
35
|
-
resolution: request.resolution,
|
|
36
|
-
generate_audio: request.audio,
|
|
37
|
-
image_url: imageUrl,
|
|
38
|
-
video_url: videoUrl,
|
|
39
|
-
}, request.providerOptions, request.http?.body) ?? {});
|
|
40
|
-
});
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
// 6. Response decoding
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
const decodeQueueResult = route.decodeJson(QueueResult);
|
|
45
|
-
const decodeResult = Effect.fn("FalVideo.decodeResult")(function* (response, context) {
|
|
46
|
-
const output = yield* decodeQueueResult(response);
|
|
47
|
-
const { video, seed, ...rest } = output.value;
|
|
48
|
-
return new VideoResponse({
|
|
49
|
-
videos: [Media.url(video.url, { mediaType: video.content_type ?? "video/mp4" })],
|
|
50
|
-
providerMetadata: {
|
|
51
|
-
fal: {
|
|
52
|
-
requestId: context.token.requestID,
|
|
53
|
-
seed: seed ?? undefined,
|
|
54
|
-
fileName: video.file_name ?? undefined,
|
|
55
|
-
fileSize: video.file_size ?? undefined,
|
|
56
|
-
...rest,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
// ---------------------------------------------------------------------------
|
|
62
|
-
// 7. Protocol and route
|
|
63
|
-
// ---------------------------------------------------------------------------
|
|
64
|
-
export const protocol = FalQueue.protocol(route, {
|
|
65
|
-
unsupported: ["n", "durationSeconds", "references"],
|
|
66
|
-
from: fromRequest,
|
|
67
|
-
decodeResult,
|
|
68
|
-
});
|
|
69
|
-
export const model = (input) => VideoModel.fromRoute({ protocol, baseURL: FalQueue.DEFAULT_BASE_URL, path: ({ request }) => `/${request.model.id}` }, input);
|
|
70
|
-
export const FalVideo = {
|
|
71
|
-
protocol,
|
|
72
|
-
model,
|
|
73
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
|
|
3
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
-
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
export declare const DEFAULT_BASE_URL = "https://api.replicate.com";
|
|
6
|
-
/** Model-defined `input` fields under the model's own names; `Media.Asset` values lower to URLs or data URLs. */
|
|
7
|
-
export type ReplicateImageOptions = Record<string, unknown>;
|
|
8
|
-
export type Request = ImageRequestFor<ReplicateImageOptions>;
|
|
9
|
-
export declare const Token: Schema.Struct<{
|
|
10
|
-
readonly id: Schema.String;
|
|
11
|
-
readonly getURL: Schema.String;
|
|
12
|
-
readonly cancelURL: Schema.String;
|
|
13
|
-
}>;
|
|
14
|
-
export type Token = Schema.Schema.Type<typeof Token>;
|
|
15
|
-
export declare const protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
16
|
-
readonly id: string;
|
|
17
|
-
readonly getURL: string;
|
|
18
|
-
readonly cancelURL: string;
|
|
19
|
-
}>;
|
|
20
|
-
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<ReplicateImageOptions>;
|
|
21
|
-
export declare const ReplicateImages: {
|
|
22
|
-
readonly protocol: MediaProtocol.Queued<Request, ImageResponse, {
|
|
23
|
-
readonly id: string;
|
|
24
|
-
readonly getURL: string;
|
|
25
|
-
readonly cancelURL: string;
|
|
26
|
-
}>;
|
|
27
|
-
readonly model: typeof model;
|
|
28
|
-
};
|