@shop-os/modelkit 0.2.2 → 0.2.3
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/CHANGELOG.md +8 -0
- package/dist/catalog.cjs +31 -26
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +16 -9
- package/dist/catalog.d.ts +16 -9
- package/dist/catalog.js +31 -26
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +147 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -9
- package/dist/index.d.ts +16 -9
- package/dist/index.js +147 -139
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -213,6 +213,12 @@ var GEMINI_RATIOS = [
|
|
|
213
213
|
"adaptive"
|
|
214
214
|
];
|
|
215
215
|
function geminiImage(id, label, aliases, sizes, display, exposure, references) {
|
|
216
|
+
const constraints = {
|
|
217
|
+
aspectRatios: [...GEMINI_RATIOS],
|
|
218
|
+
sizes,
|
|
219
|
+
supports: ["safetySettings", "temperature"]
|
|
220
|
+
};
|
|
221
|
+
if (references !== void 0) constraints.references = references;
|
|
216
222
|
const model = {
|
|
217
223
|
id,
|
|
218
224
|
aliases,
|
|
@@ -222,12 +228,7 @@ function geminiImage(id, label, aliases, sizes, display, exposure, references) {
|
|
|
222
228
|
providerModelId: id,
|
|
223
229
|
lifecycle: "active",
|
|
224
230
|
exposure,
|
|
225
|
-
constraints
|
|
226
|
-
aspectRatios: [...GEMINI_RATIOS],
|
|
227
|
-
sizes,
|
|
228
|
-
supports: ["safetySettings", "temperature"],
|
|
229
|
-
...references ? { references } : {}
|
|
230
|
-
},
|
|
231
|
+
constraints,
|
|
231
232
|
defaults: { size: "1K", aspectRatio: "1:1" },
|
|
232
233
|
usage: { ...IMAGE_USAGE, slug: "gemini" },
|
|
233
234
|
pricingKind: "image_size",
|
|
@@ -354,6 +355,7 @@ var IMAGE_MODELS = [
|
|
|
354
355
|
pricingKind: "image_size",
|
|
355
356
|
display: {
|
|
356
357
|
provider: "openai",
|
|
358
|
+
sortOrder: 20,
|
|
357
359
|
description: "OpenAI's most capable GPT Image 2.5 tier, built for editing precision; takes text and image input and outputs images in low, medium, high, xhigh, or max quality."
|
|
358
360
|
}
|
|
359
361
|
},
|
|
@@ -388,6 +390,7 @@ var IMAGE_MODELS = [
|
|
|
388
390
|
pricingKind: "image_size",
|
|
389
391
|
display: {
|
|
390
392
|
provider: "openai",
|
|
393
|
+
sortOrder: 10,
|
|
391
394
|
description: "OpenAI's fastest GPT Image 2.5 tier for high-quality everyday image generation and editing; takes text and image input and outputs images."
|
|
392
395
|
}
|
|
393
396
|
},
|
|
@@ -2128,23 +2131,22 @@ var liveState = store[KEY] ??= {
|
|
|
2128
2131
|
var liveCatalog = liveState.catalog;
|
|
2129
2132
|
|
|
2130
2133
|
// src/catalog/load.ts
|
|
2134
|
+
var import_zod2 = require("zod");
|
|
2131
2135
|
function rowCount() {
|
|
2132
2136
|
return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
|
|
2133
2137
|
}
|
|
2134
2138
|
function authHeaders(auth) {
|
|
2135
2139
|
return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
|
|
2136
2140
|
}
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
}
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
if (typeof rev === "string") return { rows, revision: rev };
|
|
2147
|
-
return { rows };
|
|
2141
|
+
var EnvelopeSchema = import_zod2.z.object({
|
|
2142
|
+
rows: CatalogSchema,
|
|
2143
|
+
revision: import_zod2.z.string().optional()
|
|
2144
|
+
});
|
|
2145
|
+
function toEnvelope(data) {
|
|
2146
|
+
if (data.rows.length === 0) throw new Error("invalid catalog response: no rows");
|
|
2147
|
+
const envelope = { rows: data.rows };
|
|
2148
|
+
if (data.revision !== void 0) envelope.revision = data.revision;
|
|
2149
|
+
return envelope;
|
|
2148
2150
|
}
|
|
2149
2151
|
function logPrimed(logger, result) {
|
|
2150
2152
|
const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
|
|
@@ -2165,7 +2167,9 @@ async function fetchRemote(source, logger) {
|
|
|
2165
2167
|
if (res.status === 304) return { kept: true };
|
|
2166
2168
|
if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
|
|
2167
2169
|
const json = await res.json();
|
|
2168
|
-
const
|
|
2170
|
+
const parsed = EnvelopeSchema.safeParse(json);
|
|
2171
|
+
if (!parsed.success) throw new Error("invalid catalog response: missing rows");
|
|
2172
|
+
const { rows, revision: rev } = toEnvelope(parsed.data);
|
|
2169
2173
|
if (rev === void 0) return { rows, fromCache: false };
|
|
2170
2174
|
return { rows, revision: rev, fromCache: false };
|
|
2171
2175
|
}
|
|
@@ -2196,11 +2200,13 @@ async function prime(source, logger) {
|
|
|
2196
2200
|
return result;
|
|
2197
2201
|
} catch (err) {
|
|
2198
2202
|
logger.warn("[modelkit] catalog remote failed, trying cache", err);
|
|
2199
|
-
const error =
|
|
2203
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
2200
2204
|
try {
|
|
2201
2205
|
const cached = await source.cache?.get();
|
|
2202
2206
|
if (!cached) throw new Error("no cached catalog");
|
|
2203
|
-
const
|
|
2207
|
+
const cachedParsed = EnvelopeSchema.safeParse(JSON.parse(cached));
|
|
2208
|
+
if (!cachedParsed.success) throw new Error("invalid catalog response: missing rows");
|
|
2209
|
+
const { rows, revision: rev } = toEnvelope(cachedParsed.data);
|
|
2204
2210
|
liveCatalog.replace(rows);
|
|
2205
2211
|
liveState.origin = "last-good";
|
|
2206
2212
|
liveState.revision = rev;
|
|
@@ -2240,19 +2246,18 @@ async function refresh(source, logger) {
|
|
|
2240
2246
|
}
|
|
2241
2247
|
}
|
|
2242
2248
|
function primeCatalog(source) {
|
|
2243
|
-
|
|
2244
|
-
if (memo) return memo;
|
|
2249
|
+
if (liveState.memo) return liveState.memo;
|
|
2245
2250
|
const logger = source.logger ?? console;
|
|
2246
|
-
|
|
2251
|
+
const pending = prime(source, logger).then((result) => {
|
|
2247
2252
|
const ttlMs = source.ttlMs ?? 3e5;
|
|
2248
2253
|
if (ttlMs > 0 && liveState.timer === void 0) {
|
|
2249
2254
|
liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
|
|
2250
|
-
|
|
2251
|
-
maybeUnref.unref?.();
|
|
2255
|
+
liveState.timer.unref?.();
|
|
2252
2256
|
}
|
|
2253
2257
|
return result;
|
|
2254
2258
|
});
|
|
2255
|
-
|
|
2259
|
+
liveState.memo = pending;
|
|
2260
|
+
return pending;
|
|
2256
2261
|
}
|
|
2257
2262
|
function resetLiveCatalog() {
|
|
2258
2263
|
if (liveState.timer !== void 0) {
|
|
@@ -2267,13 +2272,16 @@ function resetLiveCatalog() {
|
|
|
2267
2272
|
|
|
2268
2273
|
// src/catalog/file-cache.ts
|
|
2269
2274
|
var import_promises = require("fs/promises");
|
|
2275
|
+
function isErrnoException(err) {
|
|
2276
|
+
return err instanceof Error && "code" in err;
|
|
2277
|
+
}
|
|
2270
2278
|
function fileCatalogCache(path) {
|
|
2271
2279
|
return {
|
|
2272
2280
|
async get() {
|
|
2273
2281
|
try {
|
|
2274
2282
|
return await (0, import_promises.readFile)(path, "utf8");
|
|
2275
2283
|
} catch (err) {
|
|
2276
|
-
if (err
|
|
2284
|
+
if (isErrnoException(err) && err.code === "ENOENT") return null;
|
|
2277
2285
|
throw err;
|
|
2278
2286
|
}
|
|
2279
2287
|
},
|
|
@@ -2710,21 +2718,21 @@ function keysFromEnv(env, prefix = "") {
|
|
|
2710
2718
|
}
|
|
2711
2719
|
|
|
2712
2720
|
// src/retry.ts
|
|
2713
|
-
var
|
|
2721
|
+
var import_zod4 = require("zod");
|
|
2714
2722
|
|
|
2715
2723
|
// src/json.ts
|
|
2716
|
-
var
|
|
2717
|
-
var JsonValueSchema =
|
|
2718
|
-
() =>
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2724
|
+
var import_zod3 = require("zod");
|
|
2725
|
+
var JsonValueSchema = import_zod3.z.lazy(
|
|
2726
|
+
() => import_zod3.z.union([
|
|
2727
|
+
import_zod3.z.string(),
|
|
2728
|
+
import_zod3.z.number(),
|
|
2729
|
+
import_zod3.z.boolean(),
|
|
2730
|
+
import_zod3.z.null(),
|
|
2731
|
+
import_zod3.z.array(JsonValueSchema),
|
|
2732
|
+
import_zod3.z.record(import_zod3.z.string(), JsonValueSchema)
|
|
2725
2733
|
])
|
|
2726
2734
|
);
|
|
2727
|
-
var JsonObjectSchema =
|
|
2735
|
+
var JsonObjectSchema = import_zod3.z.record(import_zod3.z.string(), JsonValueSchema);
|
|
2728
2736
|
async function readErrorBody(res) {
|
|
2729
2737
|
const text2 = await res.text().catch(() => "");
|
|
2730
2738
|
try {
|
|
@@ -2733,11 +2741,11 @@ async function readErrorBody(res) {
|
|
|
2733
2741
|
return text2;
|
|
2734
2742
|
}
|
|
2735
2743
|
}
|
|
2736
|
-
var thrownErrorSchema =
|
|
2737
|
-
message:
|
|
2738
|
-
status:
|
|
2739
|
-
statusCode:
|
|
2740
|
-
responseBody:
|
|
2744
|
+
var thrownErrorSchema = import_zod3.z.object({
|
|
2745
|
+
message: import_zod3.z.string().optional(),
|
|
2746
|
+
status: import_zod3.z.number().optional(),
|
|
2747
|
+
statusCode: import_zod3.z.number().optional(),
|
|
2748
|
+
responseBody: import_zod3.z.string().optional()
|
|
2741
2749
|
});
|
|
2742
2750
|
function describeThrown(cause) {
|
|
2743
2751
|
const parsed = thrownErrorSchema.safeParse(cause);
|
|
@@ -2748,7 +2756,7 @@ function describeThrown(cause) {
|
|
|
2748
2756
|
}
|
|
2749
2757
|
|
|
2750
2758
|
// src/retry.ts
|
|
2751
|
-
var textBody =
|
|
2759
|
+
var textBody = import_zod4.z.string();
|
|
2752
2760
|
function classifyHttpError(status, body, provider, model) {
|
|
2753
2761
|
const asText = textBody.safeParse(body);
|
|
2754
2762
|
const text2 = asText.success ? asText.data : JSON.stringify(body);
|
|
@@ -2956,7 +2964,7 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
2956
2964
|
|
|
2957
2965
|
// src/client.ts
|
|
2958
2966
|
var import_ai2 = require("ai");
|
|
2959
|
-
var
|
|
2967
|
+
var import_zod6 = require("zod");
|
|
2960
2968
|
|
|
2961
2969
|
// src/adapters/media-ref.ts
|
|
2962
2970
|
function isUrlRef(ref) {
|
|
@@ -3041,7 +3049,7 @@ var import_perplexity = require("@ai-sdk/perplexity");
|
|
|
3041
3049
|
var import_xai = require("@ai-sdk/xai");
|
|
3042
3050
|
var import_deepseek = require("@ai-sdk/deepseek");
|
|
3043
3051
|
var import_moonshotai = require("@ai-sdk/moonshotai");
|
|
3044
|
-
var
|
|
3052
|
+
var import_zod5 = require("zod");
|
|
3045
3053
|
var TEXT_PROVIDERS = [
|
|
3046
3054
|
"openai",
|
|
3047
3055
|
"anthropic",
|
|
@@ -3052,7 +3060,7 @@ var TEXT_PROVIDERS = [
|
|
|
3052
3060
|
"moonshot",
|
|
3053
3061
|
"minimax"
|
|
3054
3062
|
];
|
|
3055
|
-
var textProviderSchema =
|
|
3063
|
+
var textProviderSchema = import_zod5.z.enum(TEXT_PROVIDERS);
|
|
3056
3064
|
function isTextProvider(value) {
|
|
3057
3065
|
return textProviderSchema.safeParse(value).success;
|
|
3058
3066
|
}
|
|
@@ -3222,10 +3230,10 @@ function textAbortOptions(sdk, context) {
|
|
|
3222
3230
|
if (abortSignal) return { abortSignal };
|
|
3223
3231
|
return {};
|
|
3224
3232
|
}
|
|
3225
|
-
var catalogId =
|
|
3226
|
-
var exactSize =
|
|
3227
|
-
var sdkRatio =
|
|
3228
|
-
var sizeTier =
|
|
3233
|
+
var catalogId = import_zod6.z.string();
|
|
3234
|
+
var exactSize = import_zod6.z.templateLiteral([import_zod6.z.number(), "x", import_zod6.z.number()]);
|
|
3235
|
+
var sdkRatio = import_zod6.z.templateLiteral([import_zod6.z.number(), ":", import_zod6.z.number()]);
|
|
3236
|
+
var sizeTier = import_zod6.z.enum(["512", "1K", "2K", "4K"]);
|
|
3229
3237
|
function isCatalogId(model) {
|
|
3230
3238
|
return catalogId.safeParse(model).success;
|
|
3231
3239
|
}
|
|
@@ -3746,7 +3754,7 @@ function createModelKit(config, adapters) {
|
|
|
3746
3754
|
}
|
|
3747
3755
|
|
|
3748
3756
|
// src/adapters/ark.ts
|
|
3749
|
-
var
|
|
3757
|
+
var import_zod7 = require("zod");
|
|
3750
3758
|
var ARK_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
3751
3759
|
var SUBMIT_PATH = "/contents/generations/tasks";
|
|
3752
3760
|
var SEEDANCE_POLL_INTERVAL_MS = 15e3;
|
|
@@ -3823,7 +3831,7 @@ function arkKey(ctx) {
|
|
|
3823
3831
|
return key;
|
|
3824
3832
|
}
|
|
3825
3833
|
function throwArkError(status, body, model) {
|
|
3826
|
-
const parsed =
|
|
3834
|
+
const parsed = import_zod7.z.string().safeParse(body);
|
|
3827
3835
|
const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
|
|
3828
3836
|
if (/sensitive.?content|human.?face/i.test(text2)) {
|
|
3829
3837
|
const init = {
|
|
@@ -3861,13 +3869,13 @@ function sniffedImageMime(bytes) {
|
|
|
3861
3869
|
return "image/webp";
|
|
3862
3870
|
return "image/jpeg";
|
|
3863
3871
|
}
|
|
3864
|
-
var SeedreamImageSchema =
|
|
3865
|
-
url:
|
|
3866
|
-
b64_json:
|
|
3872
|
+
var SeedreamImageSchema = import_zod7.z.object({
|
|
3873
|
+
url: import_zod7.z.string().optional(),
|
|
3874
|
+
b64_json: import_zod7.z.string().optional()
|
|
3867
3875
|
});
|
|
3868
|
-
var SeedreamResponseSchema =
|
|
3869
|
-
data:
|
|
3870
|
-
error:
|
|
3876
|
+
var SeedreamResponseSchema = import_zod7.z.object({
|
|
3877
|
+
data: import_zod7.z.array(SeedreamImageSchema).optional(),
|
|
3878
|
+
error: import_zod7.z.object({ message: import_zod7.z.string().optional(), code: import_zod7.z.string().optional() }).optional()
|
|
3871
3879
|
});
|
|
3872
3880
|
function retryOptsFor(ctx, attempts = 3) {
|
|
3873
3881
|
const opts = { attempts };
|
|
@@ -3951,21 +3959,21 @@ async function generateSeedreamImage(req, ctx) {
|
|
|
3951
3959
|
if (req.quality !== void 0) usage2.imageQuality = req.quality;
|
|
3952
3960
|
return { images: [{ bytes, mime: sniffedImageMime(bytes) }], usage: usage2, raw: data };
|
|
3953
3961
|
}
|
|
3954
|
-
var SeedanceUsageSchema =
|
|
3955
|
-
total_tokens:
|
|
3956
|
-
completion_tokens:
|
|
3962
|
+
var SeedanceUsageSchema = import_zod7.z.object({
|
|
3963
|
+
total_tokens: import_zod7.z.number().optional(),
|
|
3964
|
+
completion_tokens: import_zod7.z.number().optional()
|
|
3957
3965
|
});
|
|
3958
|
-
var SeedanceResponseSchema =
|
|
3959
|
-
id:
|
|
3960
|
-
status:
|
|
3961
|
-
content:
|
|
3966
|
+
var SeedanceResponseSchema = import_zod7.z.object({
|
|
3967
|
+
id: import_zod7.z.string().optional(),
|
|
3968
|
+
status: import_zod7.z.string().optional(),
|
|
3969
|
+
content: import_zod7.z.object({ video_url: import_zod7.z.string().optional() }).optional(),
|
|
3962
3970
|
usage: SeedanceUsageSchema.optional(),
|
|
3963
|
-
duration:
|
|
3964
|
-
framespersecond:
|
|
3965
|
-
resolution:
|
|
3966
|
-
error:
|
|
3971
|
+
duration: import_zod7.z.number().optional(),
|
|
3972
|
+
framespersecond: import_zod7.z.number().optional(),
|
|
3973
|
+
resolution: import_zod7.z.string().optional(),
|
|
3974
|
+
error: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.object({ message: import_zod7.z.string().optional() })]).optional()
|
|
3967
3975
|
});
|
|
3968
|
-
var SeedanceErrorMessageSchema =
|
|
3976
|
+
var SeedanceErrorMessageSchema = import_zod7.z.object({ message: import_zod7.z.string().optional() });
|
|
3969
3977
|
function seedanceUsage(ctx, req, duration) {
|
|
3970
3978
|
const usage2 = {
|
|
3971
3979
|
model: ctx.model.id,
|
|
@@ -3979,7 +3987,7 @@ function seedanceUsage(ctx, req, duration) {
|
|
|
3979
3987
|
return usage2;
|
|
3980
3988
|
}
|
|
3981
3989
|
function seedanceErrorMessage(error, status) {
|
|
3982
|
-
const asString =
|
|
3990
|
+
const asString = import_zod7.z.string().safeParse(error);
|
|
3983
3991
|
if (asString.success) return asString.data;
|
|
3984
3992
|
const asObject = SeedanceErrorMessageSchema.safeParse(error);
|
|
3985
3993
|
if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
|
|
@@ -4128,7 +4136,7 @@ async function generateSeedanceVideo(req, ctx) {
|
|
|
4128
4136
|
}
|
|
4129
4137
|
|
|
4130
4138
|
// src/adapters/fal.ts
|
|
4131
|
-
var
|
|
4139
|
+
var import_zod8 = require("zod");
|
|
4132
4140
|
var import_client = require("@fal-ai/client");
|
|
4133
4141
|
var MUSE_T2I_ENDPOINT = "meta/muse-image/text-to-image";
|
|
4134
4142
|
var MUSE_EDIT_ENDPOINT = "meta/muse-image/edit";
|
|
@@ -4136,7 +4144,7 @@ var KLING_O1_ENDPOINT = "fal-ai/kling-video/o1/video-to-video/reference";
|
|
|
4136
4144
|
var FAL_QUEUE_HOST = "https://queue.fal.run";
|
|
4137
4145
|
var PASSTHROUGH_POLL_MS = 2e3;
|
|
4138
4146
|
var PASSTHROUGH_MAX_WAIT_MS = 18e4;
|
|
4139
|
-
var falSubscribePayloadSchema =
|
|
4147
|
+
var falSubscribePayloadSchema = import_zod8.z.object({ data: JsonValueSchema });
|
|
4140
4148
|
function defaultCreateFalClient(opts) {
|
|
4141
4149
|
const client2 = (0, import_client.createFalClient)(opts);
|
|
4142
4150
|
return {
|
|
@@ -4186,7 +4194,7 @@ function createFalAdapter(deps = defaultDeps) {
|
|
|
4186
4194
|
};
|
|
4187
4195
|
}
|
|
4188
4196
|
var falAdapter = createFalAdapter();
|
|
4189
|
-
var falDetailSchema =
|
|
4197
|
+
var falDetailSchema = import_zod8.z.object({ detail: JsonValueSchema });
|
|
4190
4198
|
function liftDetail(body) {
|
|
4191
4199
|
const parsed = falDetailSchema.safeParse(body);
|
|
4192
4200
|
const detail = parsed.success ? parsed.data.detail : void 0;
|
|
@@ -4195,11 +4203,11 @@ function liftDetail(body) {
|
|
|
4195
4203
|
function falError(status, body, model) {
|
|
4196
4204
|
return classifyHttpError(status, liftDetail(body), "fal", model);
|
|
4197
4205
|
}
|
|
4198
|
-
var falSdkThrownSchema =
|
|
4199
|
-
status:
|
|
4200
|
-
statusCode:
|
|
4206
|
+
var falSdkThrownSchema = import_zod8.z.object({
|
|
4207
|
+
status: import_zod8.z.number().optional(),
|
|
4208
|
+
statusCode: import_zod8.z.number().optional(),
|
|
4201
4209
|
body: JsonValueSchema.optional(),
|
|
4202
|
-
message:
|
|
4210
|
+
message: import_zod8.z.string().optional()
|
|
4203
4211
|
});
|
|
4204
4212
|
function falSdkError(cause, model) {
|
|
4205
4213
|
const parsed = falSdkThrownSchema.safeParse(cause);
|
|
@@ -4243,12 +4251,12 @@ async function gatewayFetch(cfg, fetchImpl, targetUrl, init) {
|
|
|
4243
4251
|
if (init.body !== void 0) request.body = init.body;
|
|
4244
4252
|
return fetchImpl(cfg.baseUrl, request);
|
|
4245
4253
|
}
|
|
4246
|
-
var falQueueSubmitSchema =
|
|
4247
|
-
request_id:
|
|
4248
|
-
status_url:
|
|
4249
|
-
response_url:
|
|
4254
|
+
var falQueueSubmitSchema = import_zod8.z.object({
|
|
4255
|
+
request_id: import_zod8.z.string(),
|
|
4256
|
+
status_url: import_zod8.z.string(),
|
|
4257
|
+
response_url: import_zod8.z.string()
|
|
4250
4258
|
});
|
|
4251
|
-
var falQueueStatusSchema =
|
|
4259
|
+
var falQueueStatusSchema = import_zod8.z.object({ status: import_zod8.z.string() });
|
|
4252
4260
|
async function passthroughRequest(ctx, endpoint, input) {
|
|
4253
4261
|
const cfg = gatewayConfig(ctx);
|
|
4254
4262
|
const submitRes = await gatewayFetch(cfg, ctx.fetch, `${FAL_QUEUE_HOST}/${endpoint}`, {
|
|
@@ -4374,11 +4382,11 @@ async function decodeImage(ctx, url, contentType) {
|
|
|
4374
4382
|
const mime = res.headers.get("content-type") ?? contentType ?? "image/png";
|
|
4375
4383
|
return { bytes: new Uint8Array(await res.arrayBuffer()), mime };
|
|
4376
4384
|
}
|
|
4377
|
-
var museImageResultSchema =
|
|
4378
|
-
images:
|
|
4379
|
-
|
|
4380
|
-
url:
|
|
4381
|
-
content_type:
|
|
4385
|
+
var museImageResultSchema = import_zod8.z.object({
|
|
4386
|
+
images: import_zod8.z.array(
|
|
4387
|
+
import_zod8.z.object({
|
|
4388
|
+
url: import_zod8.z.string().optional(),
|
|
4389
|
+
content_type: import_zod8.z.string().nullable().optional()
|
|
4382
4390
|
})
|
|
4383
4391
|
).optional()
|
|
4384
4392
|
});
|
|
@@ -4470,8 +4478,8 @@ function klingO1Input(req) {
|
|
|
4470
4478
|
if (refs.length > 0) input.image_urls = refs;
|
|
4471
4479
|
return input;
|
|
4472
4480
|
}
|
|
4473
|
-
var falVideoResultSchema =
|
|
4474
|
-
video:
|
|
4481
|
+
var falVideoResultSchema = import_zod8.z.object({
|
|
4482
|
+
video: import_zod8.z.object({ url: import_zod8.z.string().optional() }).optional()
|
|
4475
4483
|
});
|
|
4476
4484
|
function extractVideoUrl(result, endpoint, model) {
|
|
4477
4485
|
const parsed = falVideoResultSchema.safeParse(result);
|
|
@@ -4661,11 +4669,11 @@ async function passthroughVideoJob(ctx, req, endpoint, input) {
|
|
|
4661
4669
|
}
|
|
4662
4670
|
|
|
4663
4671
|
// src/adapters/google-genai.ts
|
|
4664
|
-
var
|
|
4672
|
+
var import_zod10 = require("zod");
|
|
4665
4673
|
var import_genai = require("@google/genai");
|
|
4666
4674
|
|
|
4667
4675
|
// src/adapters/google-files.ts
|
|
4668
|
-
var
|
|
4676
|
+
var import_zod9 = require("zod");
|
|
4669
4677
|
var GOOGLE_FILES_BASE = "https://generativelanguage.googleapis.com";
|
|
4670
4678
|
var GOOGLE_FILES_POLL_INTERVAL_MS = 2e3;
|
|
4671
4679
|
var GOOGLE_FILES_POLL_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
@@ -4675,17 +4683,17 @@ var GENERIC_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
|
4675
4683
|
"binary/octet-stream",
|
|
4676
4684
|
"application/binary"
|
|
4677
4685
|
]);
|
|
4678
|
-
var uploadedFileSchema =
|
|
4679
|
-
file:
|
|
4680
|
-
uri:
|
|
4681
|
-
name:
|
|
4682
|
-
state:
|
|
4683
|
-
mimeType:
|
|
4686
|
+
var uploadedFileSchema = import_zod9.z.object({
|
|
4687
|
+
file: import_zod9.z.object({
|
|
4688
|
+
uri: import_zod9.z.string().optional(),
|
|
4689
|
+
name: import_zod9.z.string().optional(),
|
|
4690
|
+
state: import_zod9.z.string().optional(),
|
|
4691
|
+
mimeType: import_zod9.z.string().optional()
|
|
4684
4692
|
}).optional()
|
|
4685
4693
|
});
|
|
4686
|
-
var fileStateSchema =
|
|
4687
|
-
state:
|
|
4688
|
-
error:
|
|
4694
|
+
var fileStateSchema = import_zod9.z.object({
|
|
4695
|
+
state: import_zod9.z.string().optional(),
|
|
4696
|
+
error: import_zod9.z.object({ message: import_zod9.z.string().optional() }).optional()
|
|
4689
4697
|
});
|
|
4690
4698
|
function resolveMime(declared, fallback) {
|
|
4691
4699
|
const clean = declared?.split(";")[0]?.trim().toLowerCase();
|
|
@@ -4898,7 +4906,7 @@ var OMNI_POLL_INTERVAL_MS = 1e4;
|
|
|
4898
4906
|
var RESULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
|
|
4899
4907
|
var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
4900
4908
|
var MEDIA_PART_INLINE_LIMIT_BYTES = 20 * 1024 * 1024;
|
|
4901
|
-
var errorTextSchema =
|
|
4909
|
+
var errorTextSchema = import_zod10.z.string();
|
|
4902
4910
|
function createGoogleGenaiAdapter(deps = defaultDeps2) {
|
|
4903
4911
|
const { createGenAIClient } = deps;
|
|
4904
4912
|
return {
|
|
@@ -5457,15 +5465,15 @@ async function prepareGoogleMediaPart(ref, mediaType, ctx) {
|
|
|
5457
5465
|
// src/adapters/google-image.ts
|
|
5458
5466
|
var import_google2 = require("@ai-sdk/google");
|
|
5459
5467
|
var import_ai3 = require("ai");
|
|
5460
|
-
var
|
|
5468
|
+
var import_zod11 = require("zod");
|
|
5461
5469
|
var GEMINI_IMAGE_TIMEOUT_MS = 6e5;
|
|
5462
5470
|
var defaultGoogleImageDeps = {
|
|
5463
5471
|
createGoogleClient: (opts) => (0, import_google2.createGoogleGenerativeAI)(opts),
|
|
5464
5472
|
runTextGeneration: (opts) => (0, import_ai3.generateText)(opts)
|
|
5465
5473
|
};
|
|
5466
|
-
var causeChainNodeSchema =
|
|
5467
|
-
message:
|
|
5468
|
-
cause:
|
|
5474
|
+
var causeChainNodeSchema = import_zod11.z.object({
|
|
5475
|
+
message: import_zod11.z.string().optional(),
|
|
5476
|
+
cause: import_zod11.z.unknown().optional()
|
|
5469
5477
|
});
|
|
5470
5478
|
function extractBlockReason(cause) {
|
|
5471
5479
|
let current = cause;
|
|
@@ -5586,7 +5594,7 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
|
|
|
5586
5594
|
var googleImageAdapter = createGoogleImageAdapter();
|
|
5587
5595
|
|
|
5588
5596
|
// src/adapters/higgsfield.ts
|
|
5589
|
-
var
|
|
5597
|
+
var import_zod12 = require("zod");
|
|
5590
5598
|
|
|
5591
5599
|
// src/adapters/higgsfield-motions.ts
|
|
5592
5600
|
var MOTION_MAP = {
|
|
@@ -5774,14 +5782,14 @@ function videoUsage3(ctx, req, duration) {
|
|
|
5774
5782
|
if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
|
|
5775
5783
|
return event;
|
|
5776
5784
|
}
|
|
5777
|
-
var klingCreateSchema =
|
|
5778
|
-
var klingStatusSchema =
|
|
5779
|
-
status:
|
|
5780
|
-
video:
|
|
5785
|
+
var klingCreateSchema = import_zod12.z.object({ status_url: import_zod12.z.string() });
|
|
5786
|
+
var klingStatusSchema = import_zod12.z.object({
|
|
5787
|
+
status: import_zod12.z.string().optional(),
|
|
5788
|
+
video: import_zod12.z.object({ url: import_zod12.z.string().optional() }).optional(),
|
|
5781
5789
|
error: JsonValueSchema.optional()
|
|
5782
5790
|
});
|
|
5783
|
-
var errorMessageSchema =
|
|
5784
|
-
var textValueSchema =
|
|
5791
|
+
var errorMessageSchema = import_zod12.z.object({ message: import_zod12.z.string().optional() });
|
|
5792
|
+
var textValueSchema = import_zod12.z.string();
|
|
5785
5793
|
function klingErrorDetail(error) {
|
|
5786
5794
|
if (error === void 0) return "unknown_error";
|
|
5787
5795
|
const asText = textValueSchema.safeParse(error);
|
|
@@ -5915,8 +5923,8 @@ async function generateKlingVideo(req, ctx) {
|
|
|
5915
5923
|
}
|
|
5916
5924
|
};
|
|
5917
5925
|
}
|
|
5918
|
-
var dopMotionOptionsSchema =
|
|
5919
|
-
modelkit:
|
|
5926
|
+
var dopMotionOptionsSchema = import_zod12.z.object({
|
|
5927
|
+
modelkit: import_zod12.z.object({ motion: import_zod12.z.string().optional() }).optional()
|
|
5920
5928
|
});
|
|
5921
5929
|
function dopMotionId(ctx) {
|
|
5922
5930
|
const parsed = dopMotionOptionsSchema.safeParse(ctx.model.providerOptions);
|
|
@@ -5932,7 +5940,7 @@ function dopMotionId(ctx) {
|
|
|
5932
5940
|
});
|
|
5933
5941
|
return id;
|
|
5934
5942
|
}
|
|
5935
|
-
var jsonRecordSchema =
|
|
5943
|
+
var jsonRecordSchema = import_zod12.z.record(import_zod12.z.string(), JsonValueSchema);
|
|
5936
5944
|
var DOP_URL_KEYS = ["url", "video_url", "output_url", "result_url", "download_url"];
|
|
5937
5945
|
var DOP_NESTED_KEYS = ["video", "result", "results"];
|
|
5938
5946
|
function dopUrl(body) {
|
|
@@ -5960,8 +5968,8 @@ function dopUrl(body) {
|
|
|
5960
5968
|
}
|
|
5961
5969
|
return void 0;
|
|
5962
5970
|
}
|
|
5963
|
-
var dopCreateSchema =
|
|
5964
|
-
var dopStatusSchema =
|
|
5971
|
+
var dopCreateSchema = import_zod12.z.object({ id: import_zod12.z.string() });
|
|
5972
|
+
var dopStatusSchema = import_zod12.z.object({ status: import_zod12.z.string().optional() });
|
|
5965
5973
|
async function generateDopVideo(req, ctx) {
|
|
5966
5974
|
const firstFrame = req.firstFrame ? refToUrl(req.firstFrame) : void 0;
|
|
5967
5975
|
if (!firstFrame) {
|
|
@@ -6081,7 +6089,7 @@ var higgsfieldAdapter = {
|
|
|
6081
6089
|
|
|
6082
6090
|
// src/adapters/openai-image.ts
|
|
6083
6091
|
var import_openai2 = __toESM(require("openai"), 1);
|
|
6084
|
-
var
|
|
6092
|
+
var import_zod13 = require("zod");
|
|
6085
6093
|
var MAX_EDIT_REFERENCES = 16;
|
|
6086
6094
|
function aspectRatioToSize(ratio, tier) {
|
|
6087
6095
|
const TIER_LONG_EDGE = {
|
|
@@ -6164,9 +6172,9 @@ function toProviderError2(cause, ctx) {
|
|
|
6164
6172
|
ctx.model.id
|
|
6165
6173
|
);
|
|
6166
6174
|
}
|
|
6167
|
-
var openaiUsageSchema =
|
|
6168
|
-
input_tokens:
|
|
6169
|
-
output_tokens:
|
|
6175
|
+
var openaiUsageSchema = import_zod13.z.object({
|
|
6176
|
+
input_tokens: import_zod13.z.number().optional(),
|
|
6177
|
+
output_tokens: import_zod13.z.number().optional()
|
|
6170
6178
|
});
|
|
6171
6179
|
var openaiImageAdapter = {
|
|
6172
6180
|
id: "openai-image",
|
|
@@ -6573,7 +6581,7 @@ var prodiaAdapter = {
|
|
|
6573
6581
|
|
|
6574
6582
|
// src/adapters/replicate.ts
|
|
6575
6583
|
var import_replicate = __toESM(require("replicate"), 1);
|
|
6576
|
-
var
|
|
6584
|
+
var import_zod14 = require("zod");
|
|
6577
6585
|
var POLL_INTERVAL_MS = 1e3;
|
|
6578
6586
|
var POLL_TIMEOUT_MS = 15 * 6e4;
|
|
6579
6587
|
var defaultReplicateDeps = {
|
|
@@ -6609,8 +6617,8 @@ function route(providerModelId) {
|
|
|
6609
6617
|
if (!providerModelId.includes("/")) return { version: providerModelId };
|
|
6610
6618
|
return { model: providerModelId };
|
|
6611
6619
|
}
|
|
6612
|
-
var replicateResponseStatusSchema =
|
|
6613
|
-
response:
|
|
6620
|
+
var replicateResponseStatusSchema = import_zod14.z.object({
|
|
6621
|
+
response: import_zod14.z.object({ status: import_zod14.z.number() }).partial()
|
|
6614
6622
|
});
|
|
6615
6623
|
function replicateError(cause, ctx) {
|
|
6616
6624
|
if (isModelKitError(cause)) return cause;
|
|
@@ -6637,7 +6645,7 @@ function isUrlFn(value) {
|
|
|
6637
6645
|
function extractOutputUrl(output) {
|
|
6638
6646
|
const root = Array.isArray(output) ? output[0] : output;
|
|
6639
6647
|
if (root === void 0) throw noOutput();
|
|
6640
|
-
const asString =
|
|
6648
|
+
const asString = import_zod14.z.string().safeParse(root);
|
|
6641
6649
|
if (asString.success && asString.data) return asString.data;
|
|
6642
6650
|
if (root instanceof URL) return root.href;
|
|
6643
6651
|
if (isObjectOutput(root)) {
|
|
@@ -6646,15 +6654,15 @@ function extractOutputUrl(output) {
|
|
|
6646
6654
|
if (urlValue !== void 0 && isUrlFn(urlValue)) {
|
|
6647
6655
|
const called = urlValue();
|
|
6648
6656
|
if (called instanceof URL) return called.href;
|
|
6649
|
-
const calledString =
|
|
6657
|
+
const calledString = import_zod14.z.string().safeParse(called);
|
|
6650
6658
|
if (calledString.success && calledString.data) return calledString.data;
|
|
6651
6659
|
} else {
|
|
6652
|
-
const direct =
|
|
6660
|
+
const direct = import_zod14.z.string().safeParse(urlValue);
|
|
6653
6661
|
if (direct.success && direct.data) return direct.data;
|
|
6654
6662
|
}
|
|
6655
6663
|
}
|
|
6656
6664
|
if ("default" in root) {
|
|
6657
|
-
const fallback =
|
|
6665
|
+
const fallback = import_zod14.z.string().safeParse(root.default);
|
|
6658
6666
|
if (fallback.success && fallback.data) return fallback.data;
|
|
6659
6667
|
}
|
|
6660
6668
|
}
|
|
@@ -6715,7 +6723,7 @@ async function runPrediction(ctx, input, deps) {
|
|
|
6715
6723
|
}
|
|
6716
6724
|
return void 0;
|
|
6717
6725
|
}, pollOpts);
|
|
6718
|
-
const predictTime =
|
|
6726
|
+
const predictTime = import_zod14.z.number().safeParse(done.metrics?.predict_time);
|
|
6719
6727
|
if (done.output === void 0) throw noOutput();
|
|
6720
6728
|
return {
|
|
6721
6729
|
url: extractOutputUrl(done.output),
|
|
@@ -7058,7 +7066,7 @@ async function generateReplicateVideo(req, ctx, deps) {
|
|
|
7058
7066
|
throw replicateError(cause, ctx);
|
|
7059
7067
|
}
|
|
7060
7068
|
if (current.status === "succeeded") {
|
|
7061
|
-
const predictTime =
|
|
7069
|
+
const predictTime = import_zod14.z.number().safeParse(current.metrics?.predict_time);
|
|
7062
7070
|
if (current.output === void 0) throw noOutput();
|
|
7063
7071
|
return {
|
|
7064
7072
|
url: extractOutputUrl(current.output),
|
|
@@ -7190,7 +7198,7 @@ async function generateReplicateAudio(req, ctx, deps) {
|
|
|
7190
7198
|
// src/adapters/xai-video.ts
|
|
7191
7199
|
var import_ai4 = require("ai");
|
|
7192
7200
|
var import_xai2 = require("@ai-sdk/xai");
|
|
7193
|
-
var
|
|
7201
|
+
var import_zod15 = require("zod");
|
|
7194
7202
|
var POLL_INTERVAL_MS2 = 1e4;
|
|
7195
7203
|
var POLL_TIMEOUT_MS2 = 15 * 6e4;
|
|
7196
7204
|
var defaultXaiDeps = {
|
|
@@ -7203,8 +7211,8 @@ function createXaiVideoAdapter(deps = defaultXaiDeps) {
|
|
|
7203
7211
|
};
|
|
7204
7212
|
}
|
|
7205
7213
|
var xaiVideoAdapter = createXaiVideoAdapter();
|
|
7206
|
-
var xaiResponseStatusSchema =
|
|
7207
|
-
response:
|
|
7214
|
+
var xaiResponseStatusSchema = import_zod15.z.object({
|
|
7215
|
+
response: import_zod15.z.object({ status: import_zod15.z.number() }).partial()
|
|
7208
7216
|
});
|
|
7209
7217
|
function xaiError(cause, ctx) {
|
|
7210
7218
|
const info = describeThrown(cause);
|
|
@@ -7212,12 +7220,12 @@ function xaiError(cause, ctx) {
|
|
|
7212
7220
|
const status = info.status ?? (nested.success ? nested.data.response?.status : void 0);
|
|
7213
7221
|
return classifyThrown("xai-video", cause, ctx.model.id, { status, body: info.body });
|
|
7214
7222
|
}
|
|
7215
|
-
var xaiMetaSchema =
|
|
7223
|
+
var xaiMetaSchema = import_zod15.z.object({
|
|
7216
7224
|
videoUrl: JsonValueSchema.optional(),
|
|
7217
7225
|
costInUsdTicks: JsonValueSchema.optional(),
|
|
7218
7226
|
duration: JsonValueSchema.optional()
|
|
7219
7227
|
});
|
|
7220
|
-
var xaiProviderMetadataSchema =
|
|
7228
|
+
var xaiProviderMetadataSchema = import_zod15.z.object({ xai: xaiMetaSchema });
|
|
7221
7229
|
function metaOf(result) {
|
|
7222
7230
|
const parsed = xaiProviderMetadataSchema.partial().safeParse(result.providerMetadata);
|
|
7223
7231
|
if (!parsed.success) return {};
|
|
@@ -7324,7 +7332,7 @@ async function mapResult(ctx, req, result) {
|
|
|
7324
7332
|
};
|
|
7325
7333
|
}
|
|
7326
7334
|
const meta = metaOf(result);
|
|
7327
|
-
const videoUrl =
|
|
7335
|
+
const videoUrl = import_zod15.z.string().safeParse(meta.videoUrl);
|
|
7328
7336
|
if (videoUrl.success && videoUrl.data) {
|
|
7329
7337
|
const res = await ctx.fetch(videoUrl.data);
|
|
7330
7338
|
if (!res.ok) {
|
|
@@ -7347,7 +7355,7 @@ async function mapResult(ctx, req, result) {
|
|
|
7347
7355
|
});
|
|
7348
7356
|
}
|
|
7349
7357
|
function usage(ctx, req, meta) {
|
|
7350
|
-
const costTicks =
|
|
7358
|
+
const costTicks = import_zod15.z.number().safeParse(meta.costInUsdTicks);
|
|
7351
7359
|
const cost = costTicks.success ? costTicks.data / 1e10 : void 0;
|
|
7352
7360
|
const event = {
|
|
7353
7361
|
model: ctx.model.id,
|