@opencode/ai 2.2.0 → 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 +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/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/messages.d.ts +35 -1
- package/dist/schema/messages.js +20 -0
- package/dist/speech-client.d.ts +48 -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/video-client.d.ts +41 -0
- package/package.json +22 -38
- 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
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { Duration, 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
|
-
const route = MediaProtocol.identity({ id: "replicate-images", name: "Replicate", provider: "replicate" });
|
|
9
|
-
export const DEFAULT_BASE_URL = "https://api.replicate.com";
|
|
10
|
-
const OUTPUT_RETENTION = Duration.hours(1);
|
|
11
|
-
const MAX_DATA_URL_BYTES = 256 * 1024;
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
// 2. Token and response schemas
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
export const Token = Schema.Struct({ id: Schema.String, getURL: Schema.String, cancelURL: Schema.String });
|
|
16
|
-
const Prediction = Schema.Struct({
|
|
17
|
-
id: Schema.String,
|
|
18
|
-
status: Schema.String,
|
|
19
|
-
output: optionalNull(Schema.Unknown),
|
|
20
|
-
error: optionalNull(Schema.Unknown),
|
|
21
|
-
data_removed: optionalNull(Schema.Boolean),
|
|
22
|
-
completed_at: optionalNull(Schema.String),
|
|
23
|
-
metrics: optionalNull(Schema.Struct({ predict_time: optionalNull(Schema.Number) })),
|
|
24
|
-
urls: Schema.Struct({ get: Schema.String, cancel: Schema.String }),
|
|
25
|
-
});
|
|
26
|
-
const Output = Schema.Union([Schema.String, Schema.Array(Schema.String)]);
|
|
27
|
-
const isOutput = Schema.is(Output);
|
|
28
|
-
const STATUS = {
|
|
29
|
-
starting: "queued",
|
|
30
|
-
processing: "running",
|
|
31
|
-
succeeded: "completed",
|
|
32
|
-
failed: "failed",
|
|
33
|
-
canceled: "cancelled",
|
|
34
|
-
// The prediction hit its `Cancel-After` deadline before it started running.
|
|
35
|
-
aborted: "expired",
|
|
36
|
-
};
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
// 5. Request body construction
|
|
39
|
-
// ---------------------------------------------------------------------------
|
|
40
|
-
// Official models run by `owner/name`; anything else (`owner/name:version` or a bare version id) is a pinned version.
|
|
41
|
-
const isOfficial = (model) => /^[^/:]+\/[^/:]+$/.test(model);
|
|
42
|
-
const inlineSize = (source) => {
|
|
43
|
-
if (source.type === "bytes")
|
|
44
|
-
return source.data.byteLength;
|
|
45
|
-
if (source.type === "base64")
|
|
46
|
-
return source.data.length * 0.75;
|
|
47
|
-
return 0;
|
|
48
|
-
};
|
|
49
|
-
const fileInput = (asset) => {
|
|
50
|
-
if (inlineSize(asset.source) > MAX_DATA_URL_BYTES)
|
|
51
|
-
return Effect.fail(ProviderShared.invalidRequest(`${route.name} data URL inputs are limited to 256 KB; pass a larger file by https URL`));
|
|
52
|
-
return ProviderShared.mediaReference(asset, undefined, route.name).pipe(Effect.map((reference) => reference.value));
|
|
53
|
-
};
|
|
54
|
-
const inputValue = (value) => {
|
|
55
|
-
if (value instanceof Media.Asset)
|
|
56
|
-
return fileInput(value);
|
|
57
|
-
if (Array.isArray(value) && value.some((item) => item instanceof Media.Asset))
|
|
58
|
-
return Effect.forEach(value, (item) => (item instanceof Media.Asset ? fileInput(item) : Effect.succeed(item)));
|
|
59
|
-
return Effect.succeed(value);
|
|
60
|
-
};
|
|
61
|
-
const fromRequest = Effect.fn("ReplicateImages.fromRequest")(function* (request) {
|
|
62
|
-
const native = yield* Effect.forEach(Object.entries(request.providerOptions ?? {}), ([key, value]) => inputValue(value).pipe(Effect.map((lowered) => [key, lowered])));
|
|
63
|
-
const input = mergeJsonRecords({ prompt: request.prompt }, Object.fromEntries(native));
|
|
64
|
-
const model = request.model.id;
|
|
65
|
-
return MediaProtocol.json(mergeJsonRecords(isOfficial(model) ? { input } : { version: model, input }, request.http?.body) ?? {});
|
|
66
|
-
});
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
// 6. Response decoding
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
const decodePrediction = route.decodeJson(Prediction);
|
|
71
|
-
const decodeStart = Effect.fn("ReplicateImages.decodeStart")(function* (response) {
|
|
72
|
-
const output = yield* decodePrediction(response);
|
|
73
|
-
const prediction = output.value;
|
|
74
|
-
return {
|
|
75
|
-
token: { id: prediction.id, getURL: prediction.urls.get, cancelURL: prediction.urls.cancel },
|
|
76
|
-
// `Prefer: wait` can return an already-finished prediction, so `await` skips straight to the result.
|
|
77
|
-
snapshot: { id: prediction.id, status: yield* MediaProtocol.status(STATUS, prediction.status, output) },
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
const decodeStatus = Effect.fn("ReplicateImages.decodeStatus")(function* (response, context) {
|
|
81
|
-
const output = yield* decodePrediction(response);
|
|
82
|
-
return { id: context.token.id, status: yield* MediaProtocol.status(STATUS, output.value.status, output) };
|
|
83
|
-
});
|
|
84
|
-
const decodeResult = Effect.fn("ReplicateImages.decodeResult")(function* (response, context) {
|
|
85
|
-
const output = yield* decodePrediction(response);
|
|
86
|
-
const prediction = output.value;
|
|
87
|
-
const status = yield* MediaProtocol.status(STATUS, prediction.status, output);
|
|
88
|
-
if (status === "failed" || status === "cancelled" || status === "expired")
|
|
89
|
-
return yield* output.ended(status, `${route.name} prediction ${context.token.id} ${prediction.status}${typeof prediction.error === "string" ? `: ${prediction.error}` : ""}`);
|
|
90
|
-
if (status !== "completed")
|
|
91
|
-
return yield* output.pending(context.token.id);
|
|
92
|
-
if (prediction.data_removed === true)
|
|
93
|
-
return yield* output.ended("expired", `${route.name} removed the output of prediction ${context.token.id}`);
|
|
94
|
-
if (!isOutput(prediction.output))
|
|
95
|
-
return yield* output.invalid(`${route.name} prediction ${context.token.id} returned output that is not image URLs`);
|
|
96
|
-
const urls = typeof prediction.output === "string" ? [prediction.output] : prediction.output;
|
|
97
|
-
if (urls.length === 0)
|
|
98
|
-
return yield* output.invalid(`${route.name} prediction ${context.token.id} returned no images`);
|
|
99
|
-
const predictTime = prediction.metrics?.predict_time ?? undefined;
|
|
100
|
-
const completedAt = prediction.completed_at ?? undefined;
|
|
101
|
-
const expiresAt = completedAt === undefined ? undefined : Date.parse(completedAt) + Duration.toMillis(OUTPUT_RETENTION);
|
|
102
|
-
return new ImageResponse({
|
|
103
|
-
images: urls.map((url) => Media.url(url, { expiresAt })),
|
|
104
|
-
usage: predictTime === undefined ? undefined : { type: "compute", seconds: predictTime },
|
|
105
|
-
providerMetadata: { replicate: { predictionId: prediction.id } },
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
// ---------------------------------------------------------------------------
|
|
109
|
-
// 7. Protocol and route
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
|
-
export const protocol = MediaProtocol.queued(route, {
|
|
112
|
-
token: Token,
|
|
113
|
-
unsupported: ["images", "n", "aspect", "resolution"],
|
|
114
|
-
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
115
|
-
status: { path: (token) => token.getURL, decode: decodeStatus },
|
|
116
|
-
result: { path: (token) => token.getURL, decode: decodeResult },
|
|
117
|
-
cancel: { method: "POST", path: (token) => token.cancelURL },
|
|
118
|
-
});
|
|
119
|
-
export const model = (input) => ImageModel.fromRoute({
|
|
120
|
-
protocol,
|
|
121
|
-
baseURL: DEFAULT_BASE_URL,
|
|
122
|
-
path: ({ request }) => isOfficial(request.model.id) ? `/v1/models/${request.model.id}/predictions` : "/v1/predictions",
|
|
123
|
-
}, input);
|
|
124
|
-
export const ReplicateImages = {
|
|
125
|
-
protocol,
|
|
126
|
-
model,
|
|
127
|
-
};
|
|
@@ -1,44 +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
|
-
import { type OpenString } from "../schema/index.js";
|
|
6
|
-
export declare const DEFAULT_BASE_URL = "https://api.stability.ai";
|
|
7
|
-
export type StabilityStylePreset = OpenString<"enhance" | "anime" | "photographic" | "digital-art" | "comic-book" | "fantasy-art" | "line-art" | "analog-film" | "neon-punk" | "isometric" | "low-poly" | "origami" | "modeling-compound" | "cinematic" | "3d-model" | "pixel-art" | "tile-texture">;
|
|
8
|
-
/** Native form fields; `aspect` lowers to `aspect_ratio`. */
|
|
9
|
-
export type StabilityImageOptions = {
|
|
10
|
-
readonly seed?: number;
|
|
11
|
-
readonly output_format?: OpenString<"jpeg" | "png" | "webp">;
|
|
12
|
-
readonly negative_prompt?: string;
|
|
13
|
-
readonly style_preset?: StabilityStylePreset;
|
|
14
|
-
readonly strength?: number;
|
|
15
|
-
readonly cfg_scale?: number;
|
|
16
|
-
} & Record<string, unknown>;
|
|
17
|
-
/** Creative upscale options; the one `images` source is the image to upscale. */
|
|
18
|
-
export type StabilityUpscaleOptions = {
|
|
19
|
-
readonly seed?: number;
|
|
20
|
-
readonly output_format?: OpenString<"jpeg" | "png" | "webp">;
|
|
21
|
-
readonly negative_prompt?: string;
|
|
22
|
-
readonly style_preset?: StabilityStylePreset;
|
|
23
|
-
readonly creativity?: number;
|
|
24
|
-
} & Record<string, unknown>;
|
|
25
|
-
export type Request = ImageRequestFor<StabilityImageOptions>;
|
|
26
|
-
export type UpscaleRequest = ImageRequestFor<StabilityUpscaleOptions>;
|
|
27
|
-
export declare const Token: Schema.Struct<{
|
|
28
|
-
readonly id: Schema.String;
|
|
29
|
-
}>;
|
|
30
|
-
export type Token = Schema.Schema.Type<typeof Token>;
|
|
31
|
-
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
32
|
-
export declare const upscaleProtocol: MediaProtocol.Queued<UpscaleRequest, ImageResponse, {
|
|
33
|
-
readonly id: string;
|
|
34
|
-
}>;
|
|
35
|
-
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<StabilityImageOptions>;
|
|
36
|
-
export declare const upscaleModel: (input: Omit<MediaRoute.ModelInput, "id">) => ImageModel<StabilityUpscaleOptions>;
|
|
37
|
-
export declare const StabilityImages: {
|
|
38
|
-
readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
39
|
-
readonly upscaleProtocol: MediaProtocol.Queued<UpscaleRequest, ImageResponse, {
|
|
40
|
-
readonly id: string;
|
|
41
|
-
}>;
|
|
42
|
-
readonly model: typeof model;
|
|
43
|
-
readonly upscaleModel: typeof upscaleModel;
|
|
44
|
-
};
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { ImageModel, ImageResponse } from "../image.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 { ProviderShared } from "./shared.js";
|
|
7
|
-
import { MediaInput } from "./utils/media-input.js";
|
|
8
|
-
const route = MediaProtocol.identity({ id: "stability-images", name: "Stability AI", provider: "stability" });
|
|
9
|
-
const upscaleRoute = MediaProtocol.identity({ id: "stability-upscale", name: "Stability AI", provider: "stability" });
|
|
10
|
-
export const DEFAULT_BASE_URL = "https://api.stability.ai";
|
|
11
|
-
const RESULTS_PATH = "/v2beta/results";
|
|
12
|
-
const UPSCALE_MODEL = "creative";
|
|
13
|
-
/** Base64 JSON instead of raw bytes, so the seed and finish reason arrive with the image. */
|
|
14
|
-
const HEADERS = { accept: "application/json" };
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
// 2. Token and response schemas
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
export const Token = Schema.Struct({ id: Schema.String });
|
|
19
|
-
// Generate names the base64 image `image`; `/v2beta/results/{id}` names it `result`.
|
|
20
|
-
const ImageDocument = Schema.Struct({
|
|
21
|
-
image: Schema.optional(Schema.String),
|
|
22
|
-
result: Schema.optional(Schema.String),
|
|
23
|
-
seed: Schema.optional(Schema.Number),
|
|
24
|
-
finish_reason: Schema.optional(Schema.String),
|
|
25
|
-
});
|
|
26
|
-
const Started = Schema.Struct({ id: Schema.String });
|
|
27
|
-
// ---------------------------------------------------------------------------
|
|
28
|
-
// 5. Request body construction
|
|
29
|
-
// ---------------------------------------------------------------------------
|
|
30
|
-
/** `sd3.5-*` ids share the `sd3` endpoint and select the model with a form field. */
|
|
31
|
-
const endpoint = (model) => (model.startsWith("sd3") ? "sd3" : model);
|
|
32
|
-
const RESERVED_FORM_FIELDS = new Set(["image", "prompt", "mode", "model"]);
|
|
33
|
-
const form = Effect.fnUntraced(function* (identity, fields, native, source) {
|
|
34
|
-
if ((source?.length ?? 0) > 1)
|
|
35
|
-
return yield* identity.unsupported("media.images", `${identity.name} takes one source image`);
|
|
36
|
-
const body = new FormData();
|
|
37
|
-
MediaInput.appendFields(body, fields, { overlay: native, reserved: RESERVED_FORM_FIELDS });
|
|
38
|
-
const image = source?.[0];
|
|
39
|
-
if (image !== undefined)
|
|
40
|
-
body.append("image", MediaInput.blob(yield* MediaInput.inlineBytes(identity.id, image), image.mediaType), "image");
|
|
41
|
-
return MediaProtocol.multipart(body);
|
|
42
|
-
});
|
|
43
|
-
const fromRequest = Effect.fn("StabilityImages.fromRequest")(function* (request) {
|
|
44
|
-
if (request.n !== undefined && request.n > 1)
|
|
45
|
-
return yield* route.unsupported("media.n", `${route.name} generates one image per request; call it once per image`);
|
|
46
|
-
const target = endpoint(request.model.id);
|
|
47
|
-
const edit = (request.images?.length ?? 0) > 0;
|
|
48
|
-
if (edit && target === "core")
|
|
49
|
-
return yield* route.unsupported("media.images", `${route.name} core is text-to-image only; use ultra or sd3.5-*`);
|
|
50
|
-
return yield* form(route, {
|
|
51
|
-
prompt: request.prompt,
|
|
52
|
-
aspect_ratio: request.aspect,
|
|
53
|
-
model: target === "sd3" ? request.model.id : undefined,
|
|
54
|
-
mode: target === "sd3" && edit ? "image-to-image" : undefined,
|
|
55
|
-
}, mergeJsonRecords(request.providerOptions, request.http?.body), request.images);
|
|
56
|
-
});
|
|
57
|
-
const fromUpscaleRequest = Effect.fn("StabilityImages.fromUpscaleRequest")(function* (request) {
|
|
58
|
-
if ((request.images?.length ?? 0) === 0)
|
|
59
|
-
return yield* ProviderShared.invalidRequest(`${upscaleRoute.name} upscale requires the source image in images`);
|
|
60
|
-
return yield* form(upscaleRoute, { prompt: request.prompt }, mergeJsonRecords(request.providerOptions, request.http?.body), request.images);
|
|
61
|
-
});
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
// 6. Response decoding
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
const decodeImageDocument = (identity) => {
|
|
66
|
-
const decode = identity.decodeJson(ImageDocument);
|
|
67
|
-
return Effect.fn("StabilityImages.decodeImage")(function* (response) {
|
|
68
|
-
const output = yield* decode(response);
|
|
69
|
-
const document = output.value;
|
|
70
|
-
const data = document.image ?? document.result;
|
|
71
|
-
if (data === undefined)
|
|
72
|
-
return yield* output.invalid(`${identity.name} returned no image`);
|
|
73
|
-
const image = yield* MediaInput.decodedAsset(output.invalid, `${identity.name} result`, data, undefined);
|
|
74
|
-
return new ImageResponse({
|
|
75
|
-
images: [image],
|
|
76
|
-
providerMetadata: { stability: { seed: document.seed, finishReason: document.finish_reason } },
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
const decodeResponse = decodeImageDocument(route);
|
|
81
|
-
const decodeUpscaleImage = decodeImageDocument(upscaleRoute);
|
|
82
|
-
const decodeStart = upscaleRoute.decodeStarted(Started, (value) => ({
|
|
83
|
-
token: { id: value.id },
|
|
84
|
-
snapshot: { id: value.id, status: "queued" },
|
|
85
|
-
}));
|
|
86
|
-
// `/v2beta/results/{id}` answers 202 while in progress and 200 with the finished image document.
|
|
87
|
-
const decodeStatus = (response, context) => Effect.succeed({
|
|
88
|
-
id: context.token.id,
|
|
89
|
-
status: response.status === 202 ? "running" : "completed",
|
|
90
|
-
});
|
|
91
|
-
const decodeUpscaleResult = Effect.fn("StabilityImages.decodeUpscaleResult")(function* (response, context) {
|
|
92
|
-
if (response.status === 202) {
|
|
93
|
-
const output = yield* upscaleRoute.text(response);
|
|
94
|
-
return yield* output.pending(context.token.id);
|
|
95
|
-
}
|
|
96
|
-
return yield* decodeUpscaleImage(response);
|
|
97
|
-
});
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
// 7. Protocol and route
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
export const protocol = MediaProtocol.inline(route, {
|
|
102
|
-
unsupported: ["resolution"],
|
|
103
|
-
body: { from: fromRequest },
|
|
104
|
-
response: { decode: decodeResponse },
|
|
105
|
-
});
|
|
106
|
-
export const upscaleProtocol = MediaProtocol.queued(upscaleRoute, {
|
|
107
|
-
token: Token,
|
|
108
|
-
unsupported: ["n", "aspect", "resolution"],
|
|
109
|
-
start: { body: { from: fromUpscaleRequest }, decode: decodeStart },
|
|
110
|
-
status: { path: (token) => `${RESULTS_PATH}/${token.id}`, decode: decodeStatus },
|
|
111
|
-
result: { path: (token) => `${RESULTS_PATH}/${token.id}`, decode: decodeUpscaleResult },
|
|
112
|
-
});
|
|
113
|
-
export const model = (input) => ImageModel.fromRoute({
|
|
114
|
-
protocol,
|
|
115
|
-
baseURL: DEFAULT_BASE_URL,
|
|
116
|
-
headers: HEADERS,
|
|
117
|
-
path: ({ request }) => `/v2beta/stable-image/generate/${endpoint(request.model.id)}`,
|
|
118
|
-
}, input);
|
|
119
|
-
export const upscaleModel = (input) => ImageModel.fromRoute({
|
|
120
|
-
protocol: upscaleProtocol,
|
|
121
|
-
baseURL: DEFAULT_BASE_URL,
|
|
122
|
-
headers: HEADERS,
|
|
123
|
-
// Only the creative upscaler is asynchronous; fast and conservative answer inline.
|
|
124
|
-
path: `/v2beta/stable-image/upscale/${UPSCALE_MODEL}`,
|
|
125
|
-
}, { ...input, id: UPSCALE_MODEL });
|
|
126
|
-
export const StabilityImages = {
|
|
127
|
-
protocol,
|
|
128
|
-
upscaleProtocol,
|
|
129
|
-
model,
|
|
130
|
-
upscaleModel,
|
|
131
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import type { HttpClientResponse } from "effect/http";
|
|
3
|
-
import type { Media } from "../../media.js";
|
|
4
|
-
import { MediaProtocol } from "../../route/media-protocol.js";
|
|
5
|
-
import type { AIError } from "../../schema/index.js";
|
|
6
|
-
export declare const DEFAULT_BASE_URL = "https://queue.fal.run";
|
|
7
|
-
/** fal hands back absolute follow-up URLs on submit; they are authoritative for status, result, and cancel. */
|
|
8
|
-
export declare const Token: Schema.Struct<{
|
|
9
|
-
readonly requestID: Schema.String;
|
|
10
|
-
readonly statusURL: Schema.String;
|
|
11
|
-
readonly responseURL: Schema.String;
|
|
12
|
-
readonly cancelURL: Schema.String;
|
|
13
|
-
}>;
|
|
14
|
-
export type Token = Schema.Schema.Type<typeof Token>;
|
|
15
|
-
export declare const mediaUrl: (asset: Media.Asset, name: string) => Effect.Effect<string, AIError, never>;
|
|
16
|
-
export declare const protocol: <Request, Response>(route: MediaProtocol.Identity, input: {
|
|
17
|
-
readonly unsupported?: ReadonlyArray<keyof Request & string>;
|
|
18
|
-
readonly from: (request: Request) => Effect.Effect<MediaProtocol.Body, AIError>;
|
|
19
|
-
readonly decodeResult: (response: HttpClientResponse.HttpClientResponse, context: MediaProtocol.PollContext<Token>) => Effect.Effect<Response, AIError>;
|
|
20
|
-
}) => MediaProtocol.Queued<Request, Response, {
|
|
21
|
-
readonly requestID: string;
|
|
22
|
-
readonly statusURL: string;
|
|
23
|
-
readonly responseURL: string;
|
|
24
|
-
readonly cancelURL: string;
|
|
25
|
-
}>;
|
|
26
|
-
export * as FalQueue from "./fal-queue.js";
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { MediaProtocol } from "../../route/media-protocol.js";
|
|
3
|
-
import { ProviderShared, optionalNull } from "../shared.js";
|
|
4
|
-
export const DEFAULT_BASE_URL = "https://queue.fal.run";
|
|
5
|
-
/** fal hands back absolute follow-up URLs on submit; they are authoritative for status, result, and cancel. */
|
|
6
|
-
export const Token = Schema.Struct({
|
|
7
|
-
requestID: Schema.String,
|
|
8
|
-
statusURL: Schema.String,
|
|
9
|
-
responseURL: Schema.String,
|
|
10
|
-
cancelURL: Schema.String,
|
|
11
|
-
});
|
|
12
|
-
const StartResponse = Schema.Struct({
|
|
13
|
-
request_id: Schema.String,
|
|
14
|
-
status_url: Schema.String,
|
|
15
|
-
response_url: Schema.String,
|
|
16
|
-
cancel_url: Schema.String,
|
|
17
|
-
queue_position: optionalNull(Schema.Number),
|
|
18
|
-
});
|
|
19
|
-
const QueueStatus = Schema.Struct({
|
|
20
|
-
status: Schema.String,
|
|
21
|
-
queue_position: optionalNull(Schema.Number),
|
|
22
|
-
error: optionalNull(Schema.Unknown),
|
|
23
|
-
});
|
|
24
|
-
const STATUS = {
|
|
25
|
-
IN_QUEUE: "queued",
|
|
26
|
-
IN_PROGRESS: "running",
|
|
27
|
-
COMPLETED: "completed",
|
|
28
|
-
};
|
|
29
|
-
// fal accepts public URLs and data URIs; there is no provider file handle to forward.
|
|
30
|
-
export const mediaUrl = (asset, name) => ProviderShared.mediaReference(asset, undefined, name).pipe(Effect.map((reference) => reference.value));
|
|
31
|
-
export const protocol = (route, input) => {
|
|
32
|
-
const decodeQueueStatus = route.decodeJson(QueueStatus);
|
|
33
|
-
return MediaProtocol.queued(route, {
|
|
34
|
-
token: Token,
|
|
35
|
-
unsupported: input.unsupported,
|
|
36
|
-
start: {
|
|
37
|
-
body: { from: input.from },
|
|
38
|
-
decode: route.decodeStarted(StartResponse, (value) => ({
|
|
39
|
-
token: {
|
|
40
|
-
requestID: value.request_id,
|
|
41
|
-
statusURL: value.status_url,
|
|
42
|
-
responseURL: value.response_url,
|
|
43
|
-
cancelURL: value.cancel_url,
|
|
44
|
-
},
|
|
45
|
-
snapshot: { id: value.request_id, status: "queued", position: value.queue_position ?? undefined },
|
|
46
|
-
})),
|
|
47
|
-
},
|
|
48
|
-
status: {
|
|
49
|
-
path: (token) => token.statusURL,
|
|
50
|
-
decode: Effect.fn("FalQueue.decodeStatus")(function* (response, context) {
|
|
51
|
-
const output = yield* decodeQueueStatus(response);
|
|
52
|
-
const decoded = output.value;
|
|
53
|
-
const status = yield* MediaProtocol.status(STATUS, decoded.status, output);
|
|
54
|
-
// fal reports request failures as COMPLETED with an `error`; the response endpoint carries the details.
|
|
55
|
-
const failed = status === "completed" && decoded.error !== undefined && decoded.error !== null;
|
|
56
|
-
return {
|
|
57
|
-
id: context.token.requestID,
|
|
58
|
-
status: failed ? "failed" : status,
|
|
59
|
-
position: status === "queued" ? (decoded.queue_position ?? undefined) : undefined,
|
|
60
|
-
};
|
|
61
|
-
}),
|
|
62
|
-
},
|
|
63
|
-
result: { path: (token) => token.responseURL, decode: input.decodeResult },
|
|
64
|
-
cancel: { method: "PUT", path: (token) => token.cancelURL },
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
export * as FalQueue from "./fal-queue.js";
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { type HttpOptions, type ModelID } from "../schema/index.js";
|
|
3
|
-
export type { BlackForestLabsImageOptions } from "../protocols/bfl-images.js";
|
|
4
|
-
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
|
-
/** `https://api.eu.bfl.ai` or `https://api.us.bfl.ai` pin inference to one region. */
|
|
7
|
-
readonly baseURL?: string;
|
|
8
|
-
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions.Input;
|
|
10
|
-
};
|
|
11
|
-
export declare const configure: (input?: Config) => {
|
|
12
|
-
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
13
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/bfl-images.js").BlackForestLabsImageOptions>;
|
|
14
|
-
configure: typeof configure;
|
|
15
|
-
};
|
|
16
|
-
export declare const provider: {
|
|
17
|
-
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
18
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/bfl-images.js").BlackForestLabsImageOptions>;
|
|
19
|
-
configure: typeof configure;
|
|
20
|
-
};
|
|
21
|
-
export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/bfl-images.js").BlackForestLabsImageOptions>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Auth } from "../route/auth.js";
|
|
2
|
-
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import { ProviderID } from "../schema/index.js";
|
|
4
|
-
import { BlackForestLabsImages } from "../protocols/bfl-images.js";
|
|
5
|
-
export const id = ProviderID.make("black-forest-labs");
|
|
6
|
-
const auth = (options) => {
|
|
7
|
-
if ("auth" in options && options.auth)
|
|
8
|
-
return options.auth;
|
|
9
|
-
return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
|
|
10
|
-
.orElse(Auth.config("BFL_API_KEY"))
|
|
11
|
-
.pipe(Auth.header("x-key"));
|
|
12
|
-
};
|
|
13
|
-
export const configure = (input = {}) => {
|
|
14
|
-
const media = MediaRoute.deployment(input, auth(input));
|
|
15
|
-
const image = (modelID) => BlackForestLabsImages.model({ ...media, id: modelID });
|
|
16
|
-
return {
|
|
17
|
-
id,
|
|
18
|
-
image,
|
|
19
|
-
configure,
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export const provider = configure();
|
|
23
|
-
export const image = provider.image;
|
package/dist/providers/fal.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { type HttpOptions, type ModelID } from "../schema/index.js";
|
|
3
|
-
export type { FalImageOptions } from "../protocols/fal-images.js";
|
|
4
|
-
export type { FalVideoOptions } from "../protocols/fal-video.js";
|
|
5
|
-
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
6
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
7
|
-
readonly baseURL?: string;
|
|
8
|
-
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions.Input;
|
|
10
|
-
};
|
|
11
|
-
export declare const configure: (input?: Config) => {
|
|
12
|
-
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
13
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/fal-images.js").FalImageOptions>;
|
|
14
|
-
video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/fal-video.js").FalVideoOptions>;
|
|
15
|
-
configure: typeof configure;
|
|
16
|
-
};
|
|
17
|
-
export declare const provider: {
|
|
18
|
-
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
19
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/fal-images.js").FalImageOptions>;
|
|
20
|
-
video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/fal-video.js").FalVideoOptions>;
|
|
21
|
-
configure: typeof configure;
|
|
22
|
-
};
|
|
23
|
-
export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/fal-images.js").FalImageOptions>;
|
|
24
|
-
export declare const video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/fal-video.js").FalVideoOptions>;
|
package/dist/providers/fal.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Auth } from "../route/auth.js";
|
|
2
|
-
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import { ProviderID } from "../schema/index.js";
|
|
4
|
-
import { FalImages } from "../protocols/fal-images.js";
|
|
5
|
-
import { FalVideo } from "../protocols/fal-video.js";
|
|
6
|
-
export const id = ProviderID.make("fal");
|
|
7
|
-
// fal authenticates with `Authorization: Key <FAL_KEY>` rather than a bearer token.
|
|
8
|
-
const auth = (options) => {
|
|
9
|
-
if ("auth" in options && options.auth)
|
|
10
|
-
return options.auth;
|
|
11
|
-
return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
|
|
12
|
-
.orElse(Auth.config("FAL_KEY"))
|
|
13
|
-
.pipe(Auth.scheme("Key"));
|
|
14
|
-
};
|
|
15
|
-
export const configure = (input = {}) => {
|
|
16
|
-
const media = MediaRoute.deployment(input, auth(input));
|
|
17
|
-
return {
|
|
18
|
-
id,
|
|
19
|
-
image: (modelID) => FalImages.model({ ...media, id: modelID }),
|
|
20
|
-
video: (modelID) => FalVideo.model({ ...media, id: modelID }),
|
|
21
|
-
configure,
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export const provider = configure();
|
|
25
|
-
export const image = provider.image;
|
|
26
|
-
export const video = provider.video;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { type HttpOptions, type ModelID } from "../schema/index.js";
|
|
3
|
-
export type { ReplicateImageOptions } from "../protocols/replicate-images.js";
|
|
4
|
-
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
|
-
readonly baseURL?: string;
|
|
7
|
-
/** `{ Prefer: "wait=60" }` holds the submission open until the prediction finishes (up to 60 seconds). */
|
|
8
|
-
readonly headers?: Record<string, string>;
|
|
9
|
-
readonly http?: HttpOptions.Input;
|
|
10
|
-
};
|
|
11
|
-
export declare const configure: (input?: Config) => {
|
|
12
|
-
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
13
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/replicate-images.js").ReplicateImageOptions>;
|
|
14
|
-
configure: typeof configure;
|
|
15
|
-
};
|
|
16
|
-
export declare const provider: {
|
|
17
|
-
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
18
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/replicate-images.js").ReplicateImageOptions>;
|
|
19
|
-
configure: typeof configure;
|
|
20
|
-
};
|
|
21
|
-
export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/replicate-images.js").ReplicateImageOptions>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
2
|
-
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import { ProviderID } from "../schema/index.js";
|
|
4
|
-
import { ReplicateImages } from "../protocols/replicate-images.js";
|
|
5
|
-
export const id = ProviderID.make("replicate");
|
|
6
|
-
const auth = (options) => AuthOptions.bearer(options, "REPLICATE_API_TOKEN");
|
|
7
|
-
export const configure = (input = {}) => {
|
|
8
|
-
const media = MediaRoute.deployment(input, auth(input));
|
|
9
|
-
const image = (modelID) => ReplicateImages.model({ ...media, id: modelID });
|
|
10
|
-
return {
|
|
11
|
-
id,
|
|
12
|
-
image,
|
|
13
|
-
configure,
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export const provider = configure();
|
|
17
|
-
export const image = provider.image;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
2
|
-
import { type HttpOptions, type ModelID } from "../schema/index.js";
|
|
3
|
-
export type { StabilityImageOptions, StabilityUpscaleOptions } from "../protocols/stability-images.js";
|
|
4
|
-
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
|
-
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
|
-
readonly baseURL?: string;
|
|
7
|
-
readonly headers?: Record<string, string>;
|
|
8
|
-
readonly http?: HttpOptions.Input;
|
|
9
|
-
};
|
|
10
|
-
export declare const configure: (input?: Config) => {
|
|
11
|
-
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
12
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/stability-images.js").StabilityImageOptions>;
|
|
13
|
-
upscale: () => import("../image.js").ImageModel<import("../protocols/stability-images.js").StabilityUpscaleOptions>;
|
|
14
|
-
configure: typeof configure;
|
|
15
|
-
};
|
|
16
|
-
export declare const provider: {
|
|
17
|
-
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
18
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/stability-images.js").StabilityImageOptions>;
|
|
19
|
-
upscale: () => import("../image.js").ImageModel<import("../protocols/stability-images.js").StabilityUpscaleOptions>;
|
|
20
|
-
configure: typeof configure;
|
|
21
|
-
};
|
|
22
|
-
export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/stability-images.js").StabilityImageOptions>;
|
|
23
|
-
export declare const upscale: () => import("../image.js").ImageModel<import("../protocols/stability-images.js").StabilityUpscaleOptions>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AuthOptions } from "../route/auth-options.js";
|
|
2
|
-
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import { ProviderID } from "../schema/index.js";
|
|
4
|
-
import { StabilityImages } from "../protocols/stability-images.js";
|
|
5
|
-
export const id = ProviderID.make("stability");
|
|
6
|
-
const auth = (options) => AuthOptions.bearer(options, "STABILITY_API_KEY");
|
|
7
|
-
export const configure = (input = {}) => {
|
|
8
|
-
const media = MediaRoute.deployment(input, auth(input));
|
|
9
|
-
return {
|
|
10
|
-
id,
|
|
11
|
-
image: (modelID) => StabilityImages.model({ ...media, id: modelID }),
|
|
12
|
-
upscale: () => StabilityImages.upscaleModel(media),
|
|
13
|
-
configure,
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export const provider = configure();
|
|
17
|
-
export const image = provider.image;
|
|
18
|
-
export const upscale = provider.upscale;
|