@shop-os/modelkit 0.2.2 → 0.2.4
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 +13 -0
- package/dist/catalog.cjs +41 -33
- 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 +41 -33
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +157 -146
- 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 +157 -146
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -122,6 +122,12 @@ var GEMINI_RATIOS = [
|
|
|
122
122
|
"adaptive"
|
|
123
123
|
];
|
|
124
124
|
function geminiImage(id, label, aliases, sizes, display, exposure, references) {
|
|
125
|
+
const constraints = {
|
|
126
|
+
aspectRatios: [...GEMINI_RATIOS],
|
|
127
|
+
sizes,
|
|
128
|
+
supports: ["safetySettings", "temperature"]
|
|
129
|
+
};
|
|
130
|
+
if (references !== void 0) constraints.references = references;
|
|
125
131
|
const model = {
|
|
126
132
|
id,
|
|
127
133
|
aliases,
|
|
@@ -131,12 +137,7 @@ function geminiImage(id, label, aliases, sizes, display, exposure, references) {
|
|
|
131
137
|
providerModelId: id,
|
|
132
138
|
lifecycle: "active",
|
|
133
139
|
exposure,
|
|
134
|
-
constraints
|
|
135
|
-
aspectRatios: [...GEMINI_RATIOS],
|
|
136
|
-
sizes,
|
|
137
|
-
supports: ["safetySettings", "temperature"],
|
|
138
|
-
...references ? { references } : {}
|
|
139
|
-
},
|
|
140
|
+
constraints,
|
|
140
141
|
defaults: { size: "1K", aspectRatio: "1:1" },
|
|
141
142
|
usage: { ...IMAGE_USAGE, slug: "gemini" },
|
|
142
143
|
pricingKind: "image_size",
|
|
@@ -2037,31 +2038,31 @@ var liveState = store[KEY] ??= {
|
|
|
2037
2038
|
var liveCatalog = liveState.catalog;
|
|
2038
2039
|
|
|
2039
2040
|
// src/catalog/load.ts
|
|
2041
|
+
import { z as z2 } from "zod";
|
|
2040
2042
|
function rowCount() {
|
|
2041
2043
|
return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
|
|
2042
2044
|
}
|
|
2043
2045
|
function authHeaders(auth) {
|
|
2044
2046
|
return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
|
|
2045
2047
|
}
|
|
2048
|
+
var EnvelopeSchema = z2.object({
|
|
2049
|
+
rows: CatalogSchema,
|
|
2050
|
+
revision: z2.string().optional()
|
|
2051
|
+
});
|
|
2052
|
+
function toEnvelope(data) {
|
|
2053
|
+
if (data.rows.length === 0) throw new Error("invalid catalog response: no rows");
|
|
2054
|
+
const envelope = { rows: data.rows };
|
|
2055
|
+
if (data.revision !== void 0) envelope.revision = data.revision;
|
|
2056
|
+
return envelope;
|
|
2057
|
+
}
|
|
2046
2058
|
function describeError(err) {
|
|
2047
2059
|
return err instanceof Error ? err.message : String(err);
|
|
2048
2060
|
}
|
|
2049
|
-
function parseEnvelope(json) {
|
|
2050
|
-
if (typeof json !== "object" || json === null || !("rows" in json)) {
|
|
2051
|
-
throw new Error("invalid catalog response: missing rows");
|
|
2052
|
-
}
|
|
2053
|
-
const rows = CatalogSchema.parse(json.rows);
|
|
2054
|
-
const rev = json.revision;
|
|
2055
|
-
if (typeof rev === "string") return { rows, revision: rev };
|
|
2056
|
-
return { rows };
|
|
2057
|
-
}
|
|
2058
2061
|
function logPrimed(logger, result) {
|
|
2059
|
-
const
|
|
2060
|
-
logger.info(
|
|
2061
|
-
origin
|
|
2062
|
-
|
|
2063
|
-
revision: loggedRevision
|
|
2064
|
-
});
|
|
2062
|
+
const revision = result.revision === void 0 ? "" : ` revision=${result.revision}`;
|
|
2063
|
+
logger.info(
|
|
2064
|
+
`[modelkit] catalog primed origin=${result.origin} rowCount=${result.rowCount}${revision}`
|
|
2065
|
+
);
|
|
2065
2066
|
}
|
|
2066
2067
|
async function fetchRemote(source, logger) {
|
|
2067
2068
|
const fetchImpl = source.fetch ?? globalThis.fetch;
|
|
@@ -2074,7 +2075,9 @@ async function fetchRemote(source, logger) {
|
|
|
2074
2075
|
if (res.status === 304) return { kept: true };
|
|
2075
2076
|
if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
|
|
2076
2077
|
const json = await res.json();
|
|
2077
|
-
const
|
|
2078
|
+
const parsed = EnvelopeSchema.safeParse(json);
|
|
2079
|
+
if (!parsed.success) throw new Error("invalid catalog response: missing rows");
|
|
2080
|
+
const { rows, revision: rev } = toEnvelope(parsed.data);
|
|
2078
2081
|
if (rev === void 0) return { rows, fromCache: false };
|
|
2079
2082
|
return { rows, revision: rev, fromCache: false };
|
|
2080
2083
|
}
|
|
@@ -2083,7 +2086,7 @@ async function writeCache(source, logger, rows, rev) {
|
|
|
2083
2086
|
try {
|
|
2084
2087
|
await source.cache.set(JSON.stringify({ rows, revision: rev }));
|
|
2085
2088
|
} catch (err) {
|
|
2086
|
-
logger.warn(
|
|
2089
|
+
logger.warn(`[modelkit] catalog cache write failed: ${describeError(err)}`);
|
|
2087
2090
|
}
|
|
2088
2091
|
}
|
|
2089
2092
|
async function prime(source, logger) {
|
|
@@ -2104,12 +2107,14 @@ async function prime(source, logger) {
|
|
|
2104
2107
|
logPrimed(logger, result);
|
|
2105
2108
|
return result;
|
|
2106
2109
|
} catch (err) {
|
|
2107
|
-
logger.warn(
|
|
2110
|
+
logger.warn(`[modelkit] catalog remote failed, trying cache: ${describeError(err)}`);
|
|
2108
2111
|
const error = describeError(err);
|
|
2109
2112
|
try {
|
|
2110
2113
|
const cached = await source.cache?.get();
|
|
2111
2114
|
if (!cached) throw new Error("no cached catalog");
|
|
2112
|
-
const
|
|
2115
|
+
const cachedParsed = EnvelopeSchema.safeParse(JSON.parse(cached));
|
|
2116
|
+
if (!cachedParsed.success) throw new Error("invalid catalog response: missing rows");
|
|
2117
|
+
const { rows, revision: rev } = toEnvelope(cachedParsed.data);
|
|
2113
2118
|
liveCatalog.replace(rows);
|
|
2114
2119
|
liveState.origin = "last-good";
|
|
2115
2120
|
liveState.revision = rev;
|
|
@@ -2122,7 +2127,9 @@ async function prime(source, logger) {
|
|
|
2122
2127
|
logPrimed(logger, result);
|
|
2123
2128
|
return result;
|
|
2124
2129
|
} catch (cacheErr) {
|
|
2125
|
-
logger.warn(
|
|
2130
|
+
logger.warn(
|
|
2131
|
+
`[modelkit] catalog cache failed, using snapshot: ${describeError(cacheErr)}`
|
|
2132
|
+
);
|
|
2126
2133
|
liveCatalog.replace([...MODELS]);
|
|
2127
2134
|
liveState.origin = "snapshot";
|
|
2128
2135
|
liveState.revision = void 0;
|
|
@@ -2145,23 +2152,24 @@ async function refresh(source, logger) {
|
|
|
2145
2152
|
liveState.revision = fetched.revision;
|
|
2146
2153
|
await writeCache(source, logger, fetched.rows, fetched.revision);
|
|
2147
2154
|
} catch (err) {
|
|
2148
|
-
logger.warn(
|
|
2155
|
+
logger.warn(
|
|
2156
|
+
`[modelkit] catalog refresh failed, keeping current rows: ${describeError(err)}`
|
|
2157
|
+
);
|
|
2149
2158
|
}
|
|
2150
2159
|
}
|
|
2151
2160
|
function primeCatalog(source) {
|
|
2152
|
-
|
|
2153
|
-
if (memo) return memo;
|
|
2161
|
+
if (liveState.memo) return liveState.memo;
|
|
2154
2162
|
const logger = source.logger ?? console;
|
|
2155
|
-
|
|
2163
|
+
const pending = prime(source, logger).then((result) => {
|
|
2156
2164
|
const ttlMs = source.ttlMs ?? 3e5;
|
|
2157
2165
|
if (ttlMs > 0 && liveState.timer === void 0) {
|
|
2158
2166
|
liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
|
|
2159
|
-
|
|
2160
|
-
maybeUnref.unref?.();
|
|
2167
|
+
liveState.timer.unref?.();
|
|
2161
2168
|
}
|
|
2162
2169
|
return result;
|
|
2163
2170
|
});
|
|
2164
|
-
|
|
2171
|
+
liveState.memo = pending;
|
|
2172
|
+
return pending;
|
|
2165
2173
|
}
|
|
2166
2174
|
function resetLiveCatalog() {
|
|
2167
2175
|
if (liveState.timer !== void 0) {
|
|
@@ -2176,13 +2184,16 @@ function resetLiveCatalog() {
|
|
|
2176
2184
|
|
|
2177
2185
|
// src/catalog/file-cache.ts
|
|
2178
2186
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
2187
|
+
function isErrnoException(err) {
|
|
2188
|
+
return err instanceof Error && "code" in err;
|
|
2189
|
+
}
|
|
2179
2190
|
function fileCatalogCache(path) {
|
|
2180
2191
|
return {
|
|
2181
2192
|
async get() {
|
|
2182
2193
|
try {
|
|
2183
2194
|
return await readFile(path, "utf8");
|
|
2184
2195
|
} catch (err) {
|
|
2185
|
-
if (err
|
|
2196
|
+
if (isErrnoException(err) && err.code === "ENOENT") return null;
|
|
2186
2197
|
throw err;
|
|
2187
2198
|
}
|
|
2188
2199
|
},
|
|
@@ -2619,21 +2630,21 @@ function keysFromEnv(env, prefix = "") {
|
|
|
2619
2630
|
}
|
|
2620
2631
|
|
|
2621
2632
|
// src/retry.ts
|
|
2622
|
-
import { z as
|
|
2633
|
+
import { z as z4 } from "zod";
|
|
2623
2634
|
|
|
2624
2635
|
// src/json.ts
|
|
2625
|
-
import { z as
|
|
2626
|
-
var JsonValueSchema =
|
|
2627
|
-
() =>
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2636
|
+
import { z as z3 } from "zod";
|
|
2637
|
+
var JsonValueSchema = z3.lazy(
|
|
2638
|
+
() => z3.union([
|
|
2639
|
+
z3.string(),
|
|
2640
|
+
z3.number(),
|
|
2641
|
+
z3.boolean(),
|
|
2642
|
+
z3.null(),
|
|
2643
|
+
z3.array(JsonValueSchema),
|
|
2644
|
+
z3.record(z3.string(), JsonValueSchema)
|
|
2634
2645
|
])
|
|
2635
2646
|
);
|
|
2636
|
-
var JsonObjectSchema =
|
|
2647
|
+
var JsonObjectSchema = z3.record(z3.string(), JsonValueSchema);
|
|
2637
2648
|
async function readErrorBody(res) {
|
|
2638
2649
|
const text2 = await res.text().catch(() => "");
|
|
2639
2650
|
try {
|
|
@@ -2642,11 +2653,11 @@ async function readErrorBody(res) {
|
|
|
2642
2653
|
return text2;
|
|
2643
2654
|
}
|
|
2644
2655
|
}
|
|
2645
|
-
var thrownErrorSchema =
|
|
2646
|
-
message:
|
|
2647
|
-
status:
|
|
2648
|
-
statusCode:
|
|
2649
|
-
responseBody:
|
|
2656
|
+
var thrownErrorSchema = z3.object({
|
|
2657
|
+
message: z3.string().optional(),
|
|
2658
|
+
status: z3.number().optional(),
|
|
2659
|
+
statusCode: z3.number().optional(),
|
|
2660
|
+
responseBody: z3.string().optional()
|
|
2650
2661
|
});
|
|
2651
2662
|
function describeThrown(cause) {
|
|
2652
2663
|
const parsed = thrownErrorSchema.safeParse(cause);
|
|
@@ -2657,7 +2668,7 @@ function describeThrown(cause) {
|
|
|
2657
2668
|
}
|
|
2658
2669
|
|
|
2659
2670
|
// src/retry.ts
|
|
2660
|
-
var textBody =
|
|
2671
|
+
var textBody = z4.string();
|
|
2661
2672
|
function classifyHttpError(status, body, provider, model) {
|
|
2662
2673
|
const asText = textBody.safeParse(body);
|
|
2663
2674
|
const text2 = asText.success ? asText.data : JSON.stringify(body);
|
|
@@ -2872,7 +2883,7 @@ import {
|
|
|
2872
2883
|
streamObject as aiStreamObject2,
|
|
2873
2884
|
streamText as aiStreamText2
|
|
2874
2885
|
} from "ai";
|
|
2875
|
-
import { z as
|
|
2886
|
+
import { z as z6 } from "zod";
|
|
2876
2887
|
|
|
2877
2888
|
// src/adapters/media-ref.ts
|
|
2878
2889
|
function isUrlRef(ref) {
|
|
@@ -2957,7 +2968,7 @@ import { createPerplexity } from "@ai-sdk/perplexity";
|
|
|
2957
2968
|
import { createXai } from "@ai-sdk/xai";
|
|
2958
2969
|
import { createDeepSeek } from "@ai-sdk/deepseek";
|
|
2959
2970
|
import { createMoonshotAI } from "@ai-sdk/moonshotai";
|
|
2960
|
-
import { z as
|
|
2971
|
+
import { z as z5 } from "zod";
|
|
2961
2972
|
var TEXT_PROVIDERS = [
|
|
2962
2973
|
"openai",
|
|
2963
2974
|
"anthropic",
|
|
@@ -2968,7 +2979,7 @@ var TEXT_PROVIDERS = [
|
|
|
2968
2979
|
"moonshot",
|
|
2969
2980
|
"minimax"
|
|
2970
2981
|
];
|
|
2971
|
-
var textProviderSchema =
|
|
2982
|
+
var textProviderSchema = z5.enum(TEXT_PROVIDERS);
|
|
2972
2983
|
function isTextProvider(value) {
|
|
2973
2984
|
return textProviderSchema.safeParse(value).success;
|
|
2974
2985
|
}
|
|
@@ -3138,10 +3149,10 @@ function textAbortOptions(sdk, context) {
|
|
|
3138
3149
|
if (abortSignal) return { abortSignal };
|
|
3139
3150
|
return {};
|
|
3140
3151
|
}
|
|
3141
|
-
var catalogId =
|
|
3142
|
-
var exactSize =
|
|
3143
|
-
var sdkRatio =
|
|
3144
|
-
var sizeTier =
|
|
3152
|
+
var catalogId = z6.string();
|
|
3153
|
+
var exactSize = z6.templateLiteral([z6.number(), "x", z6.number()]);
|
|
3154
|
+
var sdkRatio = z6.templateLiteral([z6.number(), ":", z6.number()]);
|
|
3155
|
+
var sizeTier = z6.enum(["512", "1K", "2K", "4K"]);
|
|
3145
3156
|
function isCatalogId(model) {
|
|
3146
3157
|
return catalogId.safeParse(model).success;
|
|
3147
3158
|
}
|
|
@@ -3662,7 +3673,7 @@ function createModelKit(config, adapters) {
|
|
|
3662
3673
|
}
|
|
3663
3674
|
|
|
3664
3675
|
// src/adapters/ark.ts
|
|
3665
|
-
import { z as
|
|
3676
|
+
import { z as z7 } from "zod";
|
|
3666
3677
|
var ARK_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
3667
3678
|
var SUBMIT_PATH = "/contents/generations/tasks";
|
|
3668
3679
|
var SEEDANCE_POLL_INTERVAL_MS = 15e3;
|
|
@@ -3739,7 +3750,7 @@ function arkKey(ctx) {
|
|
|
3739
3750
|
return key;
|
|
3740
3751
|
}
|
|
3741
3752
|
function throwArkError(status, body, model) {
|
|
3742
|
-
const parsed =
|
|
3753
|
+
const parsed = z7.string().safeParse(body);
|
|
3743
3754
|
const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
|
|
3744
3755
|
if (/sensitive.?content|human.?face/i.test(text2)) {
|
|
3745
3756
|
const init = {
|
|
@@ -3777,13 +3788,13 @@ function sniffedImageMime(bytes) {
|
|
|
3777
3788
|
return "image/webp";
|
|
3778
3789
|
return "image/jpeg";
|
|
3779
3790
|
}
|
|
3780
|
-
var SeedreamImageSchema =
|
|
3781
|
-
url:
|
|
3782
|
-
b64_json:
|
|
3791
|
+
var SeedreamImageSchema = z7.object({
|
|
3792
|
+
url: z7.string().optional(),
|
|
3793
|
+
b64_json: z7.string().optional()
|
|
3783
3794
|
});
|
|
3784
|
-
var SeedreamResponseSchema =
|
|
3785
|
-
data:
|
|
3786
|
-
error:
|
|
3795
|
+
var SeedreamResponseSchema = z7.object({
|
|
3796
|
+
data: z7.array(SeedreamImageSchema).optional(),
|
|
3797
|
+
error: z7.object({ message: z7.string().optional(), code: z7.string().optional() }).optional()
|
|
3787
3798
|
});
|
|
3788
3799
|
function retryOptsFor(ctx, attempts = 3) {
|
|
3789
3800
|
const opts = { attempts };
|
|
@@ -3867,21 +3878,21 @@ async function generateSeedreamImage(req, ctx) {
|
|
|
3867
3878
|
if (req.quality !== void 0) usage2.imageQuality = req.quality;
|
|
3868
3879
|
return { images: [{ bytes, mime: sniffedImageMime(bytes) }], usage: usage2, raw: data };
|
|
3869
3880
|
}
|
|
3870
|
-
var SeedanceUsageSchema =
|
|
3871
|
-
total_tokens:
|
|
3872
|
-
completion_tokens:
|
|
3881
|
+
var SeedanceUsageSchema = z7.object({
|
|
3882
|
+
total_tokens: z7.number().optional(),
|
|
3883
|
+
completion_tokens: z7.number().optional()
|
|
3873
3884
|
});
|
|
3874
|
-
var SeedanceResponseSchema =
|
|
3875
|
-
id:
|
|
3876
|
-
status:
|
|
3877
|
-
content:
|
|
3885
|
+
var SeedanceResponseSchema = z7.object({
|
|
3886
|
+
id: z7.string().optional(),
|
|
3887
|
+
status: z7.string().optional(),
|
|
3888
|
+
content: z7.object({ video_url: z7.string().optional() }).optional(),
|
|
3878
3889
|
usage: SeedanceUsageSchema.optional(),
|
|
3879
|
-
duration:
|
|
3880
|
-
framespersecond:
|
|
3881
|
-
resolution:
|
|
3882
|
-
error:
|
|
3890
|
+
duration: z7.number().optional(),
|
|
3891
|
+
framespersecond: z7.number().optional(),
|
|
3892
|
+
resolution: z7.string().optional(),
|
|
3893
|
+
error: z7.union([z7.string(), z7.object({ message: z7.string().optional() })]).optional()
|
|
3883
3894
|
});
|
|
3884
|
-
var SeedanceErrorMessageSchema =
|
|
3895
|
+
var SeedanceErrorMessageSchema = z7.object({ message: z7.string().optional() });
|
|
3885
3896
|
function seedanceUsage(ctx, req, duration) {
|
|
3886
3897
|
const usage2 = {
|
|
3887
3898
|
model: ctx.model.id,
|
|
@@ -3895,7 +3906,7 @@ function seedanceUsage(ctx, req, duration) {
|
|
|
3895
3906
|
return usage2;
|
|
3896
3907
|
}
|
|
3897
3908
|
function seedanceErrorMessage(error, status) {
|
|
3898
|
-
const asString =
|
|
3909
|
+
const asString = z7.string().safeParse(error);
|
|
3899
3910
|
if (asString.success) return asString.data;
|
|
3900
3911
|
const asObject = SeedanceErrorMessageSchema.safeParse(error);
|
|
3901
3912
|
if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
|
|
@@ -4044,7 +4055,7 @@ async function generateSeedanceVideo(req, ctx) {
|
|
|
4044
4055
|
}
|
|
4045
4056
|
|
|
4046
4057
|
// src/adapters/fal.ts
|
|
4047
|
-
import { z as
|
|
4058
|
+
import { z as z8 } from "zod";
|
|
4048
4059
|
import { createFalClient } from "@fal-ai/client";
|
|
4049
4060
|
var MUSE_T2I_ENDPOINT = "meta/muse-image/text-to-image";
|
|
4050
4061
|
var MUSE_EDIT_ENDPOINT = "meta/muse-image/edit";
|
|
@@ -4052,7 +4063,7 @@ var KLING_O1_ENDPOINT = "fal-ai/kling-video/o1/video-to-video/reference";
|
|
|
4052
4063
|
var FAL_QUEUE_HOST = "https://queue.fal.run";
|
|
4053
4064
|
var PASSTHROUGH_POLL_MS = 2e3;
|
|
4054
4065
|
var PASSTHROUGH_MAX_WAIT_MS = 18e4;
|
|
4055
|
-
var falSubscribePayloadSchema =
|
|
4066
|
+
var falSubscribePayloadSchema = z8.object({ data: JsonValueSchema });
|
|
4056
4067
|
function defaultCreateFalClient(opts) {
|
|
4057
4068
|
const client2 = createFalClient(opts);
|
|
4058
4069
|
return {
|
|
@@ -4102,7 +4113,7 @@ function createFalAdapter(deps = defaultDeps) {
|
|
|
4102
4113
|
};
|
|
4103
4114
|
}
|
|
4104
4115
|
var falAdapter = createFalAdapter();
|
|
4105
|
-
var falDetailSchema =
|
|
4116
|
+
var falDetailSchema = z8.object({ detail: JsonValueSchema });
|
|
4106
4117
|
function liftDetail(body) {
|
|
4107
4118
|
const parsed = falDetailSchema.safeParse(body);
|
|
4108
4119
|
const detail = parsed.success ? parsed.data.detail : void 0;
|
|
@@ -4111,11 +4122,11 @@ function liftDetail(body) {
|
|
|
4111
4122
|
function falError(status, body, model) {
|
|
4112
4123
|
return classifyHttpError(status, liftDetail(body), "fal", model);
|
|
4113
4124
|
}
|
|
4114
|
-
var falSdkThrownSchema =
|
|
4115
|
-
status:
|
|
4116
|
-
statusCode:
|
|
4125
|
+
var falSdkThrownSchema = z8.object({
|
|
4126
|
+
status: z8.number().optional(),
|
|
4127
|
+
statusCode: z8.number().optional(),
|
|
4117
4128
|
body: JsonValueSchema.optional(),
|
|
4118
|
-
message:
|
|
4129
|
+
message: z8.string().optional()
|
|
4119
4130
|
});
|
|
4120
4131
|
function falSdkError(cause, model) {
|
|
4121
4132
|
const parsed = falSdkThrownSchema.safeParse(cause);
|
|
@@ -4159,12 +4170,12 @@ async function gatewayFetch(cfg, fetchImpl, targetUrl, init) {
|
|
|
4159
4170
|
if (init.body !== void 0) request.body = init.body;
|
|
4160
4171
|
return fetchImpl(cfg.baseUrl, request);
|
|
4161
4172
|
}
|
|
4162
|
-
var falQueueSubmitSchema =
|
|
4163
|
-
request_id:
|
|
4164
|
-
status_url:
|
|
4165
|
-
response_url:
|
|
4173
|
+
var falQueueSubmitSchema = z8.object({
|
|
4174
|
+
request_id: z8.string(),
|
|
4175
|
+
status_url: z8.string(),
|
|
4176
|
+
response_url: z8.string()
|
|
4166
4177
|
});
|
|
4167
|
-
var falQueueStatusSchema =
|
|
4178
|
+
var falQueueStatusSchema = z8.object({ status: z8.string() });
|
|
4168
4179
|
async function passthroughRequest(ctx, endpoint, input) {
|
|
4169
4180
|
const cfg = gatewayConfig(ctx);
|
|
4170
4181
|
const submitRes = await gatewayFetch(cfg, ctx.fetch, `${FAL_QUEUE_HOST}/${endpoint}`, {
|
|
@@ -4290,11 +4301,11 @@ async function decodeImage(ctx, url, contentType) {
|
|
|
4290
4301
|
const mime = res.headers.get("content-type") ?? contentType ?? "image/png";
|
|
4291
4302
|
return { bytes: new Uint8Array(await res.arrayBuffer()), mime };
|
|
4292
4303
|
}
|
|
4293
|
-
var museImageResultSchema =
|
|
4294
|
-
images:
|
|
4295
|
-
|
|
4296
|
-
url:
|
|
4297
|
-
content_type:
|
|
4304
|
+
var museImageResultSchema = z8.object({
|
|
4305
|
+
images: z8.array(
|
|
4306
|
+
z8.object({
|
|
4307
|
+
url: z8.string().optional(),
|
|
4308
|
+
content_type: z8.string().nullable().optional()
|
|
4298
4309
|
})
|
|
4299
4310
|
).optional()
|
|
4300
4311
|
});
|
|
@@ -4386,8 +4397,8 @@ function klingO1Input(req) {
|
|
|
4386
4397
|
if (refs.length > 0) input.image_urls = refs;
|
|
4387
4398
|
return input;
|
|
4388
4399
|
}
|
|
4389
|
-
var falVideoResultSchema =
|
|
4390
|
-
video:
|
|
4400
|
+
var falVideoResultSchema = z8.object({
|
|
4401
|
+
video: z8.object({ url: z8.string().optional() }).optional()
|
|
4391
4402
|
});
|
|
4392
4403
|
function extractVideoUrl(result, endpoint, model) {
|
|
4393
4404
|
const parsed = falVideoResultSchema.safeParse(result);
|
|
@@ -4577,13 +4588,13 @@ async function passthroughVideoJob(ctx, req, endpoint, input) {
|
|
|
4577
4588
|
}
|
|
4578
4589
|
|
|
4579
4590
|
// src/adapters/google-genai.ts
|
|
4580
|
-
import { z as
|
|
4591
|
+
import { z as z10 } from "zod";
|
|
4581
4592
|
import {
|
|
4582
4593
|
GoogleGenAI
|
|
4583
4594
|
} from "@google/genai";
|
|
4584
4595
|
|
|
4585
4596
|
// src/adapters/google-files.ts
|
|
4586
|
-
import { z as
|
|
4597
|
+
import { z as z9 } from "zod";
|
|
4587
4598
|
var GOOGLE_FILES_BASE = "https://generativelanguage.googleapis.com";
|
|
4588
4599
|
var GOOGLE_FILES_POLL_INTERVAL_MS = 2e3;
|
|
4589
4600
|
var GOOGLE_FILES_POLL_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
@@ -4593,17 +4604,17 @@ var GENERIC_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
|
4593
4604
|
"binary/octet-stream",
|
|
4594
4605
|
"application/binary"
|
|
4595
4606
|
]);
|
|
4596
|
-
var uploadedFileSchema =
|
|
4597
|
-
file:
|
|
4598
|
-
uri:
|
|
4599
|
-
name:
|
|
4600
|
-
state:
|
|
4601
|
-
mimeType:
|
|
4607
|
+
var uploadedFileSchema = z9.object({
|
|
4608
|
+
file: z9.object({
|
|
4609
|
+
uri: z9.string().optional(),
|
|
4610
|
+
name: z9.string().optional(),
|
|
4611
|
+
state: z9.string().optional(),
|
|
4612
|
+
mimeType: z9.string().optional()
|
|
4602
4613
|
}).optional()
|
|
4603
4614
|
});
|
|
4604
|
-
var fileStateSchema =
|
|
4605
|
-
state:
|
|
4606
|
-
error:
|
|
4615
|
+
var fileStateSchema = z9.object({
|
|
4616
|
+
state: z9.string().optional(),
|
|
4617
|
+
error: z9.object({ message: z9.string().optional() }).optional()
|
|
4607
4618
|
});
|
|
4608
4619
|
function resolveMime(declared, fallback) {
|
|
4609
4620
|
const clean = declared?.split(";")[0]?.trim().toLowerCase();
|
|
@@ -4816,7 +4827,7 @@ var OMNI_POLL_INTERVAL_MS = 1e4;
|
|
|
4816
4827
|
var RESULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
|
|
4817
4828
|
var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
4818
4829
|
var MEDIA_PART_INLINE_LIMIT_BYTES = 20 * 1024 * 1024;
|
|
4819
|
-
var errorTextSchema =
|
|
4830
|
+
var errorTextSchema = z10.string();
|
|
4820
4831
|
function createGoogleGenaiAdapter(deps = defaultDeps2) {
|
|
4821
4832
|
const { createGenAIClient } = deps;
|
|
4822
4833
|
return {
|
|
@@ -5375,15 +5386,15 @@ async function prepareGoogleMediaPart(ref, mediaType, ctx) {
|
|
|
5375
5386
|
// src/adapters/google-image.ts
|
|
5376
5387
|
import { createGoogleGenerativeAI as createGoogleGenerativeAI2 } from "@ai-sdk/google";
|
|
5377
5388
|
import { generateText } from "ai";
|
|
5378
|
-
import { z as
|
|
5389
|
+
import { z as z11 } from "zod";
|
|
5379
5390
|
var GEMINI_IMAGE_TIMEOUT_MS = 6e5;
|
|
5380
5391
|
var defaultGoogleImageDeps = {
|
|
5381
5392
|
createGoogleClient: (opts) => createGoogleGenerativeAI2(opts),
|
|
5382
5393
|
runTextGeneration: (opts) => generateText(opts)
|
|
5383
5394
|
};
|
|
5384
|
-
var causeChainNodeSchema =
|
|
5385
|
-
message:
|
|
5386
|
-
cause:
|
|
5395
|
+
var causeChainNodeSchema = z11.object({
|
|
5396
|
+
message: z11.string().optional(),
|
|
5397
|
+
cause: z11.unknown().optional()
|
|
5387
5398
|
});
|
|
5388
5399
|
function extractBlockReason(cause) {
|
|
5389
5400
|
let current = cause;
|
|
@@ -5504,7 +5515,7 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
|
|
|
5504
5515
|
var googleImageAdapter = createGoogleImageAdapter();
|
|
5505
5516
|
|
|
5506
5517
|
// src/adapters/higgsfield.ts
|
|
5507
|
-
import { z as
|
|
5518
|
+
import { z as z12 } from "zod";
|
|
5508
5519
|
|
|
5509
5520
|
// src/adapters/higgsfield-motions.ts
|
|
5510
5521
|
var MOTION_MAP = {
|
|
@@ -5692,14 +5703,14 @@ function videoUsage3(ctx, req, duration) {
|
|
|
5692
5703
|
if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
|
|
5693
5704
|
return event;
|
|
5694
5705
|
}
|
|
5695
|
-
var klingCreateSchema =
|
|
5696
|
-
var klingStatusSchema =
|
|
5697
|
-
status:
|
|
5698
|
-
video:
|
|
5706
|
+
var klingCreateSchema = z12.object({ status_url: z12.string() });
|
|
5707
|
+
var klingStatusSchema = z12.object({
|
|
5708
|
+
status: z12.string().optional(),
|
|
5709
|
+
video: z12.object({ url: z12.string().optional() }).optional(),
|
|
5699
5710
|
error: JsonValueSchema.optional()
|
|
5700
5711
|
});
|
|
5701
|
-
var errorMessageSchema =
|
|
5702
|
-
var textValueSchema =
|
|
5712
|
+
var errorMessageSchema = z12.object({ message: z12.string().optional() });
|
|
5713
|
+
var textValueSchema = z12.string();
|
|
5703
5714
|
function klingErrorDetail(error) {
|
|
5704
5715
|
if (error === void 0) return "unknown_error";
|
|
5705
5716
|
const asText = textValueSchema.safeParse(error);
|
|
@@ -5833,8 +5844,8 @@ async function generateKlingVideo(req, ctx) {
|
|
|
5833
5844
|
}
|
|
5834
5845
|
};
|
|
5835
5846
|
}
|
|
5836
|
-
var dopMotionOptionsSchema =
|
|
5837
|
-
modelkit:
|
|
5847
|
+
var dopMotionOptionsSchema = z12.object({
|
|
5848
|
+
modelkit: z12.object({ motion: z12.string().optional() }).optional()
|
|
5838
5849
|
});
|
|
5839
5850
|
function dopMotionId(ctx) {
|
|
5840
5851
|
const parsed = dopMotionOptionsSchema.safeParse(ctx.model.providerOptions);
|
|
@@ -5850,7 +5861,7 @@ function dopMotionId(ctx) {
|
|
|
5850
5861
|
});
|
|
5851
5862
|
return id;
|
|
5852
5863
|
}
|
|
5853
|
-
var jsonRecordSchema =
|
|
5864
|
+
var jsonRecordSchema = z12.record(z12.string(), JsonValueSchema);
|
|
5854
5865
|
var DOP_URL_KEYS = ["url", "video_url", "output_url", "result_url", "download_url"];
|
|
5855
5866
|
var DOP_NESTED_KEYS = ["video", "result", "results"];
|
|
5856
5867
|
function dopUrl(body) {
|
|
@@ -5878,8 +5889,8 @@ function dopUrl(body) {
|
|
|
5878
5889
|
}
|
|
5879
5890
|
return void 0;
|
|
5880
5891
|
}
|
|
5881
|
-
var dopCreateSchema =
|
|
5882
|
-
var dopStatusSchema =
|
|
5892
|
+
var dopCreateSchema = z12.object({ id: z12.string() });
|
|
5893
|
+
var dopStatusSchema = z12.object({ status: z12.string().optional() });
|
|
5883
5894
|
async function generateDopVideo(req, ctx) {
|
|
5884
5895
|
const firstFrame = req.firstFrame ? refToUrl(req.firstFrame) : void 0;
|
|
5885
5896
|
if (!firstFrame) {
|
|
@@ -5999,7 +6010,7 @@ var higgsfieldAdapter = {
|
|
|
5999
6010
|
|
|
6000
6011
|
// src/adapters/openai-image.ts
|
|
6001
6012
|
import OpenAI from "openai";
|
|
6002
|
-
import { z as
|
|
6013
|
+
import { z as z13 } from "zod";
|
|
6003
6014
|
var MAX_EDIT_REFERENCES = 16;
|
|
6004
6015
|
function aspectRatioToSize(ratio, tier) {
|
|
6005
6016
|
const TIER_LONG_EDGE = {
|
|
@@ -6082,9 +6093,9 @@ function toProviderError2(cause, ctx) {
|
|
|
6082
6093
|
ctx.model.id
|
|
6083
6094
|
);
|
|
6084
6095
|
}
|
|
6085
|
-
var openaiUsageSchema =
|
|
6086
|
-
input_tokens:
|
|
6087
|
-
output_tokens:
|
|
6096
|
+
var openaiUsageSchema = z13.object({
|
|
6097
|
+
input_tokens: z13.number().optional(),
|
|
6098
|
+
output_tokens: z13.number().optional()
|
|
6088
6099
|
});
|
|
6089
6100
|
var openaiImageAdapter = {
|
|
6090
6101
|
id: "openai-image",
|
|
@@ -6491,7 +6502,7 @@ var prodiaAdapter = {
|
|
|
6491
6502
|
|
|
6492
6503
|
// src/adapters/replicate.ts
|
|
6493
6504
|
import Replicate from "replicate";
|
|
6494
|
-
import { z as
|
|
6505
|
+
import { z as z14 } from "zod";
|
|
6495
6506
|
var POLL_INTERVAL_MS = 1e3;
|
|
6496
6507
|
var POLL_TIMEOUT_MS = 15 * 6e4;
|
|
6497
6508
|
var defaultReplicateDeps = {
|
|
@@ -6527,8 +6538,8 @@ function route(providerModelId) {
|
|
|
6527
6538
|
if (!providerModelId.includes("/")) return { version: providerModelId };
|
|
6528
6539
|
return { model: providerModelId };
|
|
6529
6540
|
}
|
|
6530
|
-
var replicateResponseStatusSchema =
|
|
6531
|
-
response:
|
|
6541
|
+
var replicateResponseStatusSchema = z14.object({
|
|
6542
|
+
response: z14.object({ status: z14.number() }).partial()
|
|
6532
6543
|
});
|
|
6533
6544
|
function replicateError(cause, ctx) {
|
|
6534
6545
|
if (isModelKitError(cause)) return cause;
|
|
@@ -6555,7 +6566,7 @@ function isUrlFn(value) {
|
|
|
6555
6566
|
function extractOutputUrl(output) {
|
|
6556
6567
|
const root = Array.isArray(output) ? output[0] : output;
|
|
6557
6568
|
if (root === void 0) throw noOutput();
|
|
6558
|
-
const asString =
|
|
6569
|
+
const asString = z14.string().safeParse(root);
|
|
6559
6570
|
if (asString.success && asString.data) return asString.data;
|
|
6560
6571
|
if (root instanceof URL) return root.href;
|
|
6561
6572
|
if (isObjectOutput(root)) {
|
|
@@ -6564,15 +6575,15 @@ function extractOutputUrl(output) {
|
|
|
6564
6575
|
if (urlValue !== void 0 && isUrlFn(urlValue)) {
|
|
6565
6576
|
const called = urlValue();
|
|
6566
6577
|
if (called instanceof URL) return called.href;
|
|
6567
|
-
const calledString =
|
|
6578
|
+
const calledString = z14.string().safeParse(called);
|
|
6568
6579
|
if (calledString.success && calledString.data) return calledString.data;
|
|
6569
6580
|
} else {
|
|
6570
|
-
const direct =
|
|
6581
|
+
const direct = z14.string().safeParse(urlValue);
|
|
6571
6582
|
if (direct.success && direct.data) return direct.data;
|
|
6572
6583
|
}
|
|
6573
6584
|
}
|
|
6574
6585
|
if ("default" in root) {
|
|
6575
|
-
const fallback =
|
|
6586
|
+
const fallback = z14.string().safeParse(root.default);
|
|
6576
6587
|
if (fallback.success && fallback.data) return fallback.data;
|
|
6577
6588
|
}
|
|
6578
6589
|
}
|
|
@@ -6633,7 +6644,7 @@ async function runPrediction(ctx, input, deps) {
|
|
|
6633
6644
|
}
|
|
6634
6645
|
return void 0;
|
|
6635
6646
|
}, pollOpts);
|
|
6636
|
-
const predictTime =
|
|
6647
|
+
const predictTime = z14.number().safeParse(done.metrics?.predict_time);
|
|
6637
6648
|
if (done.output === void 0) throw noOutput();
|
|
6638
6649
|
return {
|
|
6639
6650
|
url: extractOutputUrl(done.output),
|
|
@@ -6976,7 +6987,7 @@ async function generateReplicateVideo(req, ctx, deps) {
|
|
|
6976
6987
|
throw replicateError(cause, ctx);
|
|
6977
6988
|
}
|
|
6978
6989
|
if (current.status === "succeeded") {
|
|
6979
|
-
const predictTime =
|
|
6990
|
+
const predictTime = z14.number().safeParse(current.metrics?.predict_time);
|
|
6980
6991
|
if (current.output === void 0) throw noOutput();
|
|
6981
6992
|
return {
|
|
6982
6993
|
url: extractOutputUrl(current.output),
|
|
@@ -7108,7 +7119,7 @@ async function generateReplicateAudio(req, ctx, deps) {
|
|
|
7108
7119
|
// src/adapters/xai-video.ts
|
|
7109
7120
|
import { experimental_generateVideo } from "ai";
|
|
7110
7121
|
import { createXai as createXai2 } from "@ai-sdk/xai";
|
|
7111
|
-
import { z as
|
|
7122
|
+
import { z as z15 } from "zod";
|
|
7112
7123
|
var POLL_INTERVAL_MS2 = 1e4;
|
|
7113
7124
|
var POLL_TIMEOUT_MS2 = 15 * 6e4;
|
|
7114
7125
|
var defaultXaiDeps = {
|
|
@@ -7121,8 +7132,8 @@ function createXaiVideoAdapter(deps = defaultXaiDeps) {
|
|
|
7121
7132
|
};
|
|
7122
7133
|
}
|
|
7123
7134
|
var xaiVideoAdapter = createXaiVideoAdapter();
|
|
7124
|
-
var xaiResponseStatusSchema =
|
|
7125
|
-
response:
|
|
7135
|
+
var xaiResponseStatusSchema = z15.object({
|
|
7136
|
+
response: z15.object({ status: z15.number() }).partial()
|
|
7126
7137
|
});
|
|
7127
7138
|
function xaiError(cause, ctx) {
|
|
7128
7139
|
const info = describeThrown(cause);
|
|
@@ -7130,12 +7141,12 @@ function xaiError(cause, ctx) {
|
|
|
7130
7141
|
const status = info.status ?? (nested.success ? nested.data.response?.status : void 0);
|
|
7131
7142
|
return classifyThrown("xai-video", cause, ctx.model.id, { status, body: info.body });
|
|
7132
7143
|
}
|
|
7133
|
-
var xaiMetaSchema =
|
|
7144
|
+
var xaiMetaSchema = z15.object({
|
|
7134
7145
|
videoUrl: JsonValueSchema.optional(),
|
|
7135
7146
|
costInUsdTicks: JsonValueSchema.optional(),
|
|
7136
7147
|
duration: JsonValueSchema.optional()
|
|
7137
7148
|
});
|
|
7138
|
-
var xaiProviderMetadataSchema =
|
|
7149
|
+
var xaiProviderMetadataSchema = z15.object({ xai: xaiMetaSchema });
|
|
7139
7150
|
function metaOf(result) {
|
|
7140
7151
|
const parsed = xaiProviderMetadataSchema.partial().safeParse(result.providerMetadata);
|
|
7141
7152
|
if (!parsed.success) return {};
|
|
@@ -7242,7 +7253,7 @@ async function mapResult(ctx, req, result) {
|
|
|
7242
7253
|
};
|
|
7243
7254
|
}
|
|
7244
7255
|
const meta = metaOf(result);
|
|
7245
|
-
const videoUrl =
|
|
7256
|
+
const videoUrl = z15.string().safeParse(meta.videoUrl);
|
|
7246
7257
|
if (videoUrl.success && videoUrl.data) {
|
|
7247
7258
|
const res = await ctx.fetch(videoUrl.data);
|
|
7248
7259
|
if (!res.ok) {
|
|
@@ -7265,7 +7276,7 @@ async function mapResult(ctx, req, result) {
|
|
|
7265
7276
|
});
|
|
7266
7277
|
}
|
|
7267
7278
|
function usage(ctx, req, meta) {
|
|
7268
|
-
const costTicks =
|
|
7279
|
+
const costTicks = z15.number().safeParse(meta.costInUsdTicks);
|
|
7269
7280
|
const cost = costTicks.success ? costTicks.data / 1e10 : void 0;
|
|
7270
7281
|
const event = {
|
|
7271
7282
|
model: ctx.model.id,
|