@shop-os/modelkit 0.1.11 → 0.2.0
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 +24 -3
- package/dist/catalog.cjs +395 -0
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +41 -1
- package/dist/catalog.d.ts +41 -1
- package/dist/catalog.js +395 -0
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +539 -116
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -2
- package/dist/index.d.ts +43 -2
- package/dist/index.js +532 -116
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96,6 +96,14 @@ var Catalog = class _Catalog {
|
|
|
96
96
|
...rows
|
|
97
97
|
]);
|
|
98
98
|
}
|
|
99
|
+
/** Atomically swap every row. Builds the maps first so a bad batch throws before anything changes. */
|
|
100
|
+
replace(rows) {
|
|
101
|
+
const next = new _Catalog(rows);
|
|
102
|
+
this.byId.clear();
|
|
103
|
+
this.byAlias.clear();
|
|
104
|
+
for (const [id, model] of next.byId) this.byId.set(id, model);
|
|
105
|
+
for (const [alias, id] of next.byAlias) this.byAlias.set(alias, id);
|
|
106
|
+
}
|
|
99
107
|
};
|
|
100
108
|
|
|
101
109
|
// src/catalog/image.ts
|
|
@@ -1786,6 +1794,407 @@ var MODELS = [
|
|
|
1786
1794
|
...OTHER_MODELS
|
|
1787
1795
|
];
|
|
1788
1796
|
|
|
1797
|
+
// src/catalog/schema.ts
|
|
1798
|
+
import { z } from "zod";
|
|
1799
|
+
var ADAPTER_IDS = [
|
|
1800
|
+
"ai-sdk-text",
|
|
1801
|
+
"google-image",
|
|
1802
|
+
"openai-image",
|
|
1803
|
+
"google-genai",
|
|
1804
|
+
"ark",
|
|
1805
|
+
"fal",
|
|
1806
|
+
"replicate",
|
|
1807
|
+
"prodia",
|
|
1808
|
+
"higgsfield",
|
|
1809
|
+
"xai-video"
|
|
1810
|
+
];
|
|
1811
|
+
var ModelTypeSchema = z.enum(["text", "image", "video", "audio", "upscale", "bg-remove"]);
|
|
1812
|
+
var LifecycleSchema = z.enum(["active", "deprecated", "retired"]);
|
|
1813
|
+
var AdapterSchema = z.enum(ADAPTER_IDS);
|
|
1814
|
+
var AspectRatioSchema = z.enum([
|
|
1815
|
+
"1:1",
|
|
1816
|
+
"16:9",
|
|
1817
|
+
"9:16",
|
|
1818
|
+
"4:3",
|
|
1819
|
+
"3:4",
|
|
1820
|
+
"3:2",
|
|
1821
|
+
"2:3",
|
|
1822
|
+
"4:5",
|
|
1823
|
+
"5:4",
|
|
1824
|
+
"21:9",
|
|
1825
|
+
"9:21",
|
|
1826
|
+
"97:30",
|
|
1827
|
+
"adaptive"
|
|
1828
|
+
]);
|
|
1829
|
+
var ImageSizeSchema = z.enum(["512", "1K", "2K", "4K"]);
|
|
1830
|
+
var VideoResolutionSchema = z.enum(["360p", "480p", "720p", "768p", "1080p", "2k", "4k"]);
|
|
1831
|
+
var ImageQualitySchema = z.enum(["auto", "low", "medium", "high", "xhigh", "max"]);
|
|
1832
|
+
var OutputFormatSchema = z.enum(["png", "jpeg", "webp"]);
|
|
1833
|
+
var RequiredInputSchema = z.enum(["firstFrame", "sourceVideo", "references"]);
|
|
1834
|
+
var SupportedOptionSchema = z.enum([
|
|
1835
|
+
"seed",
|
|
1836
|
+
"quality",
|
|
1837
|
+
"negativePrompt",
|
|
1838
|
+
"cfgScale",
|
|
1839
|
+
"generateAudio",
|
|
1840
|
+
"promptExpansion",
|
|
1841
|
+
"lastFrame",
|
|
1842
|
+
"count",
|
|
1843
|
+
"outputFormat",
|
|
1844
|
+
"scaleFactor",
|
|
1845
|
+
"safetySettings",
|
|
1846
|
+
"temperature",
|
|
1847
|
+
"upscale",
|
|
1848
|
+
"watermark",
|
|
1849
|
+
"safetyChecker",
|
|
1850
|
+
"instrumental"
|
|
1851
|
+
]);
|
|
1852
|
+
var UsageUnitSchema = z.enum([
|
|
1853
|
+
"tokens",
|
|
1854
|
+
"images",
|
|
1855
|
+
"seconds",
|
|
1856
|
+
"reported_cost_usd",
|
|
1857
|
+
"compute_seconds"
|
|
1858
|
+
]);
|
|
1859
|
+
var PricingKindSchema = z.enum(["token", "image_size", "video_per_second", "flat"]);
|
|
1860
|
+
var ProviderOptionValueSchema = z.lazy(
|
|
1861
|
+
() => z.union([
|
|
1862
|
+
z.string(),
|
|
1863
|
+
z.number(),
|
|
1864
|
+
z.boolean(),
|
|
1865
|
+
z.array(ProviderOptionValueSchema),
|
|
1866
|
+
z.record(z.string(), ProviderOptionValueSchema)
|
|
1867
|
+
])
|
|
1868
|
+
);
|
|
1869
|
+
var ProviderOptionsSchema = z.record(z.string(), z.record(z.string(), ProviderOptionValueSchema));
|
|
1870
|
+
var ReferenceLimitsSchema = z.looseObject({
|
|
1871
|
+
images: z.number().optional(),
|
|
1872
|
+
videos: z.number().optional(),
|
|
1873
|
+
audios: z.number().optional(),
|
|
1874
|
+
total: z.number().optional(),
|
|
1875
|
+
audioOnly: z.boolean().optional()
|
|
1876
|
+
});
|
|
1877
|
+
var ModelConstraintsSchema = z.looseObject({
|
|
1878
|
+
aspectRatios: z.array(AspectRatioSchema).optional(),
|
|
1879
|
+
sizes: z.array(ImageSizeSchema).optional(),
|
|
1880
|
+
resolutions: z.array(VideoResolutionSchema).optional(),
|
|
1881
|
+
durations: z.union([z.looseObject({ min: z.number(), max: z.number() }), z.array(z.number())]).optional(),
|
|
1882
|
+
durationPresets: z.array(z.number()).optional(),
|
|
1883
|
+
qualityOptions: z.array(z.string()).optional(),
|
|
1884
|
+
exactSizes: z.record(z.string(), z.string()).optional(),
|
|
1885
|
+
references: ReferenceLimitsSchema.optional(),
|
|
1886
|
+
requires: z.array(RequiredInputSchema).optional(),
|
|
1887
|
+
supports: z.array(SupportedOptionSchema).optional(),
|
|
1888
|
+
ratioIgnoredWith: z.array(z.enum(["firstFrame", "sourceVideo"])).optional()
|
|
1889
|
+
});
|
|
1890
|
+
var MediaRefSchema = z.union([
|
|
1891
|
+
z.looseObject({ url: z.string(), label: z.string().optional() }),
|
|
1892
|
+
z.looseObject({
|
|
1893
|
+
bytes: z.instanceof(Uint8Array),
|
|
1894
|
+
mime: z.string(),
|
|
1895
|
+
label: z.string().optional()
|
|
1896
|
+
})
|
|
1897
|
+
]);
|
|
1898
|
+
var ImageSafetySettingSchema = z.looseObject({ category: z.string(), threshold: z.string() });
|
|
1899
|
+
var UpscaleOptionsSchema = z.looseObject({
|
|
1900
|
+
enhanceModel: z.string().optional(),
|
|
1901
|
+
subjectDetection: z.string().optional(),
|
|
1902
|
+
faceEnhancement: z.boolean().optional(),
|
|
1903
|
+
faceEnhancementCreativity: z.number().optional(),
|
|
1904
|
+
faceEnhancementStrength: z.number().optional()
|
|
1905
|
+
});
|
|
1906
|
+
var DefaultsSchema = z.looseObject({
|
|
1907
|
+
references: z.array(MediaRefSchema).optional(),
|
|
1908
|
+
aspectRatio: AspectRatioSchema.optional(),
|
|
1909
|
+
size: ImageSizeSchema.optional(),
|
|
1910
|
+
exactSize: z.string().optional(),
|
|
1911
|
+
quality: ImageQualitySchema.optional(),
|
|
1912
|
+
seed: z.number().optional(),
|
|
1913
|
+
count: z.number().optional(),
|
|
1914
|
+
outputFormat: OutputFormatSchema.optional(),
|
|
1915
|
+
scaleFactor: z.number().optional(),
|
|
1916
|
+
safetySettings: z.array(ImageSafetySettingSchema).optional(),
|
|
1917
|
+
temperature: z.number().optional(),
|
|
1918
|
+
upscale: UpscaleOptionsSchema.optional(),
|
|
1919
|
+
firstFrame: MediaRefSchema.optional(),
|
|
1920
|
+
lastFrame: MediaRefSchema.optional(),
|
|
1921
|
+
sourceVideo: MediaRefSchema.optional(),
|
|
1922
|
+
referenceImages: z.array(MediaRefSchema).optional(),
|
|
1923
|
+
referenceVideos: z.array(MediaRefSchema).optional(),
|
|
1924
|
+
referenceAudios: z.array(MediaRefSchema).optional(),
|
|
1925
|
+
resolution: VideoResolutionSchema.optional(),
|
|
1926
|
+
durationSeconds: z.number().optional(),
|
|
1927
|
+
generateAudio: z.boolean().optional(),
|
|
1928
|
+
negativePrompt: z.string().optional(),
|
|
1929
|
+
cfgScale: z.number().optional(),
|
|
1930
|
+
promptExpansion: z.enum(["fast", "balanced", "quality"]).optional(),
|
|
1931
|
+
watermark: z.boolean().optional(),
|
|
1932
|
+
safetyChecker: z.boolean().optional(),
|
|
1933
|
+
mode: z.enum(["standard", "pro"]).optional(),
|
|
1934
|
+
instrumental: z.boolean().optional()
|
|
1935
|
+
});
|
|
1936
|
+
var CatalogDisplaySchema = z.looseObject({
|
|
1937
|
+
provider: z.string(),
|
|
1938
|
+
description: z.string(),
|
|
1939
|
+
logo: z.string().optional(),
|
|
1940
|
+
costTier: z.union([z.literal(1), z.literal(2), z.literal(3)]).optional(),
|
|
1941
|
+
recommended: z.boolean().optional(),
|
|
1942
|
+
sortOrder: z.number().optional(),
|
|
1943
|
+
chat: z.looseObject({
|
|
1944
|
+
providerOptions: ProviderOptionsSchema.optional(),
|
|
1945
|
+
temperature: z.number().optional()
|
|
1946
|
+
}).optional()
|
|
1947
|
+
});
|
|
1948
|
+
var CatalogCapabilitiesSchema = z.looseObject({
|
|
1949
|
+
acceptsSourceVideo: z.boolean().optional(),
|
|
1950
|
+
framesExcludeReferences: z.boolean().optional(),
|
|
1951
|
+
reasoning: z.boolean().optional(),
|
|
1952
|
+
vision: z.boolean().optional(),
|
|
1953
|
+
contextWindow: z.number().optional()
|
|
1954
|
+
});
|
|
1955
|
+
var CatalogModelSchemaBase = z.looseObject({
|
|
1956
|
+
id: z.string().min(1),
|
|
1957
|
+
aliases: z.array(z.string()).default([]),
|
|
1958
|
+
label: z.string().min(1),
|
|
1959
|
+
type: ModelTypeSchema,
|
|
1960
|
+
adapter: AdapterSchema,
|
|
1961
|
+
providerModelId: z.string().min(1),
|
|
1962
|
+
lifecycle: LifecycleSchema,
|
|
1963
|
+
replacedBy: z.string().optional(),
|
|
1964
|
+
exposure: z.enum(["catalog", "internal"]),
|
|
1965
|
+
constraints: ModelConstraintsSchema,
|
|
1966
|
+
defaults: DefaultsSchema,
|
|
1967
|
+
providerOptions: ProviderOptionsSchema.optional(),
|
|
1968
|
+
usage: z.looseObject({
|
|
1969
|
+
unit: UsageUnitSchema,
|
|
1970
|
+
slug: z.string().optional(),
|
|
1971
|
+
providerLabel: z.string().optional()
|
|
1972
|
+
}),
|
|
1973
|
+
pricingKind: PricingKindSchema,
|
|
1974
|
+
display: CatalogDisplaySchema.optional(),
|
|
1975
|
+
capabilities: CatalogCapabilitiesSchema.optional()
|
|
1976
|
+
}).superRefine((row, ctx) => {
|
|
1977
|
+
if (row.lifecycle === "active" && !row.display) {
|
|
1978
|
+
ctx.addIssue({
|
|
1979
|
+
code: "custom",
|
|
1980
|
+
path: ["display"],
|
|
1981
|
+
message: "active rows need display"
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
if (row.lifecycle === "active" && row.type === "text" && !row.capabilities?.contextWindow) {
|
|
1985
|
+
ctx.addIssue({
|
|
1986
|
+
code: "custom",
|
|
1987
|
+
path: ["capabilities", "contextWindow"],
|
|
1988
|
+
message: "active text rows need contextWindow"
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
if (row.replacedBy !== void 0 && row.replacedBy === row.id) {
|
|
1992
|
+
ctx.addIssue({
|
|
1993
|
+
code: "custom",
|
|
1994
|
+
path: ["replacedBy"],
|
|
1995
|
+
message: "replacedBy must not equal id"
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1999
|
+
var CatalogModelSchema = CatalogModelSchemaBase;
|
|
2000
|
+
var CatalogSchema = z.array(CatalogModelSchemaBase).superRefine((rows, ctx) => {
|
|
2001
|
+
const seenIds = /* @__PURE__ */ new Map();
|
|
2002
|
+
rows.forEach((row, index) => {
|
|
2003
|
+
if (seenIds.has(row.id)) {
|
|
2004
|
+
ctx.addIssue({
|
|
2005
|
+
code: "custom",
|
|
2006
|
+
path: [index, "id"],
|
|
2007
|
+
message: `Duplicate model id "${row.id}"`
|
|
2008
|
+
});
|
|
2009
|
+
} else {
|
|
2010
|
+
seenIds.set(row.id, index);
|
|
2011
|
+
}
|
|
2012
|
+
});
|
|
2013
|
+
const seenAliases = /* @__PURE__ */ new Map();
|
|
2014
|
+
rows.forEach((row, index) => {
|
|
2015
|
+
row.aliases.forEach((alias, aliasIndex) => {
|
|
2016
|
+
const path = [index, "aliases", aliasIndex];
|
|
2017
|
+
if (alias === row.id || seenIds.has(alias)) {
|
|
2018
|
+
ctx.addIssue({
|
|
2019
|
+
code: "custom",
|
|
2020
|
+
path,
|
|
2021
|
+
message: `Alias "${alias}" collides with a model id`
|
|
2022
|
+
});
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
if (seenAliases.has(alias)) {
|
|
2026
|
+
ctx.addIssue({
|
|
2027
|
+
code: "custom",
|
|
2028
|
+
path,
|
|
2029
|
+
message: `Duplicate alias "${alias}"`
|
|
2030
|
+
});
|
|
2031
|
+
} else {
|
|
2032
|
+
seenAliases.set(alias, index);
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2035
|
+
});
|
|
2036
|
+
});
|
|
2037
|
+
|
|
2038
|
+
// src/catalog/live.ts
|
|
2039
|
+
var liveCatalog = new Catalog(MODELS);
|
|
2040
|
+
|
|
2041
|
+
// src/catalog/load.ts
|
|
2042
|
+
var memo;
|
|
2043
|
+
var timer;
|
|
2044
|
+
var revision;
|
|
2045
|
+
var origin = "snapshot";
|
|
2046
|
+
function rowCount() {
|
|
2047
|
+
return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
|
|
2048
|
+
}
|
|
2049
|
+
function authHeaders(auth) {
|
|
2050
|
+
return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
|
|
2051
|
+
}
|
|
2052
|
+
function describeError(err) {
|
|
2053
|
+
return err instanceof Error ? err.message : String(err);
|
|
2054
|
+
}
|
|
2055
|
+
function parseEnvelope(json) {
|
|
2056
|
+
if (typeof json !== "object" || json === null || !("rows" in json)) {
|
|
2057
|
+
throw new Error("invalid catalog response: missing rows");
|
|
2058
|
+
}
|
|
2059
|
+
const rows = CatalogSchema.parse(json.rows);
|
|
2060
|
+
const rev = json.revision;
|
|
2061
|
+
if (typeof rev === "string") return { rows, revision: rev };
|
|
2062
|
+
return { rows };
|
|
2063
|
+
}
|
|
2064
|
+
function logPrimed(logger, result) {
|
|
2065
|
+
const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
|
|
2066
|
+
logger.info("[modelkit] catalog primed", {
|
|
2067
|
+
origin: loggedOrigin,
|
|
2068
|
+
rowCount: loggedCount,
|
|
2069
|
+
revision: loggedRevision
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
async function fetchRemote(source, logger) {
|
|
2073
|
+
const fetchImpl = source.fetch ?? globalThis.fetch;
|
|
2074
|
+
const headers2 = authHeaders(source.auth);
|
|
2075
|
+
if (revision !== void 0) headers2["If-None-Match"] = `"${revision}"`;
|
|
2076
|
+
const res = await fetchImpl(`${source.baseUrl}/models/catalog`, {
|
|
2077
|
+
headers: headers2,
|
|
2078
|
+
signal: AbortSignal.timeout(source.timeoutMs ?? 1e4)
|
|
2079
|
+
});
|
|
2080
|
+
if (res.status === 304) return { kept: true };
|
|
2081
|
+
if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
|
|
2082
|
+
const json = await res.json();
|
|
2083
|
+
const { rows, revision: rev } = parseEnvelope(json);
|
|
2084
|
+
if (rev === void 0) return { rows, fromCache: false };
|
|
2085
|
+
return { rows, revision: rev, fromCache: false };
|
|
2086
|
+
}
|
|
2087
|
+
async function writeCache(source, logger, rows, rev) {
|
|
2088
|
+
if (!source.cache) return;
|
|
2089
|
+
try {
|
|
2090
|
+
await source.cache.set(JSON.stringify({ rows, revision: rev }));
|
|
2091
|
+
} catch (err) {
|
|
2092
|
+
logger.warn("[modelkit] catalog cache write failed", err);
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
async function prime(source, logger) {
|
|
2096
|
+
try {
|
|
2097
|
+
const fetched = await fetchRemote(source, logger);
|
|
2098
|
+
if ("kept" in fetched) {
|
|
2099
|
+
const result2 = { origin, rowCount: rowCount() };
|
|
2100
|
+
if (revision !== void 0) result2.revision = revision;
|
|
2101
|
+
logPrimed(logger, result2);
|
|
2102
|
+
return result2;
|
|
2103
|
+
}
|
|
2104
|
+
liveCatalog.replace(fetched.rows);
|
|
2105
|
+
origin = "remote";
|
|
2106
|
+
revision = fetched.revision;
|
|
2107
|
+
await writeCache(source, logger, fetched.rows, fetched.revision);
|
|
2108
|
+
const result = { origin, rowCount: rowCount() };
|
|
2109
|
+
if (fetched.revision !== void 0) result.revision = fetched.revision;
|
|
2110
|
+
logPrimed(logger, result);
|
|
2111
|
+
return result;
|
|
2112
|
+
} catch (err) {
|
|
2113
|
+
logger.warn("[modelkit] catalog remote failed, trying cache", err);
|
|
2114
|
+
const error = describeError(err);
|
|
2115
|
+
try {
|
|
2116
|
+
const cached = await source.cache?.get();
|
|
2117
|
+
if (!cached) throw new Error("no cached catalog");
|
|
2118
|
+
const { rows, revision: rev } = parseEnvelope(JSON.parse(cached));
|
|
2119
|
+
liveCatalog.replace(rows);
|
|
2120
|
+
origin = "last-good";
|
|
2121
|
+
revision = rev;
|
|
2122
|
+
const result = { origin, rowCount: rowCount(), error };
|
|
2123
|
+
if (rev !== void 0) result.revision = rev;
|
|
2124
|
+
logPrimed(logger, result);
|
|
2125
|
+
return result;
|
|
2126
|
+
} catch (cacheErr) {
|
|
2127
|
+
logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
|
|
2128
|
+
liveCatalog.replace([...MODELS]);
|
|
2129
|
+
origin = "snapshot";
|
|
2130
|
+
revision = void 0;
|
|
2131
|
+
const result = {
|
|
2132
|
+
origin,
|
|
2133
|
+
rowCount: rowCount(),
|
|
2134
|
+
error
|
|
2135
|
+
};
|
|
2136
|
+
logPrimed(logger, result);
|
|
2137
|
+
return result;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
async function refresh(source, logger) {
|
|
2142
|
+
try {
|
|
2143
|
+
const fetched = await fetchRemote(source, logger);
|
|
2144
|
+
if ("kept" in fetched) return;
|
|
2145
|
+
liveCatalog.replace(fetched.rows);
|
|
2146
|
+
origin = "remote";
|
|
2147
|
+
revision = fetched.revision;
|
|
2148
|
+
await writeCache(source, logger, fetched.rows, fetched.revision);
|
|
2149
|
+
} catch (err) {
|
|
2150
|
+
logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
function primeCatalog(source) {
|
|
2154
|
+
if (memo) return memo;
|
|
2155
|
+
const logger = source.logger ?? console;
|
|
2156
|
+
memo = prime(source, logger).then((result) => {
|
|
2157
|
+
const ttlMs = source.ttlMs ?? 3e5;
|
|
2158
|
+
if (ttlMs > 0 && timer === void 0) {
|
|
2159
|
+
timer = setInterval(() => void refresh(source, logger), ttlMs);
|
|
2160
|
+
const maybeUnref = timer;
|
|
2161
|
+
maybeUnref.unref?.();
|
|
2162
|
+
}
|
|
2163
|
+
return result;
|
|
2164
|
+
});
|
|
2165
|
+
return memo;
|
|
2166
|
+
}
|
|
2167
|
+
function resetLiveCatalog() {
|
|
2168
|
+
if (timer !== void 0) {
|
|
2169
|
+
clearInterval(timer);
|
|
2170
|
+
timer = void 0;
|
|
2171
|
+
}
|
|
2172
|
+
memo = void 0;
|
|
2173
|
+
revision = void 0;
|
|
2174
|
+
origin = "snapshot";
|
|
2175
|
+
liveCatalog.replace([...MODELS]);
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
// src/catalog/file-cache.ts
|
|
2179
|
+
import { readFile, rename, writeFile } from "fs/promises";
|
|
2180
|
+
function fileCatalogCache(path) {
|
|
2181
|
+
return {
|
|
2182
|
+
async get() {
|
|
2183
|
+
try {
|
|
2184
|
+
return await readFile(path, "utf8");
|
|
2185
|
+
} catch (err) {
|
|
2186
|
+
if (err?.code === "ENOENT") return null;
|
|
2187
|
+
throw err;
|
|
2188
|
+
}
|
|
2189
|
+
},
|
|
2190
|
+
async set(json) {
|
|
2191
|
+
const tmp = `${path}.tmp`;
|
|
2192
|
+
await writeFile(tmp, json, "utf8");
|
|
2193
|
+
await rename(tmp, path);
|
|
2194
|
+
}
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
|
|
1789
2198
|
// src/resolve-options.ts
|
|
1790
2199
|
var SIZE_ORDER = ["512", "1K", "2K", "4K"];
|
|
1791
2200
|
var RESOLUTION_ORDER = ["360p", "480p", "720p", "768p", "1080p", "2k", "4k"];
|
|
@@ -2211,21 +2620,21 @@ function keysFromEnv(env, prefix = "") {
|
|
|
2211
2620
|
}
|
|
2212
2621
|
|
|
2213
2622
|
// src/retry.ts
|
|
2214
|
-
import { z as
|
|
2623
|
+
import { z as z3 } from "zod";
|
|
2215
2624
|
|
|
2216
2625
|
// src/json.ts
|
|
2217
|
-
import { z } from "zod";
|
|
2218
|
-
var JsonValueSchema =
|
|
2219
|
-
() =>
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2626
|
+
import { z as z2 } from "zod";
|
|
2627
|
+
var JsonValueSchema = z2.lazy(
|
|
2628
|
+
() => z2.union([
|
|
2629
|
+
z2.string(),
|
|
2630
|
+
z2.number(),
|
|
2631
|
+
z2.boolean(),
|
|
2632
|
+
z2.null(),
|
|
2633
|
+
z2.array(JsonValueSchema),
|
|
2634
|
+
z2.record(z2.string(), JsonValueSchema)
|
|
2226
2635
|
])
|
|
2227
2636
|
);
|
|
2228
|
-
var JsonObjectSchema =
|
|
2637
|
+
var JsonObjectSchema = z2.record(z2.string(), JsonValueSchema);
|
|
2229
2638
|
async function readErrorBody(res) {
|
|
2230
2639
|
const text2 = await res.text().catch(() => "");
|
|
2231
2640
|
try {
|
|
@@ -2234,11 +2643,11 @@ async function readErrorBody(res) {
|
|
|
2234
2643
|
return text2;
|
|
2235
2644
|
}
|
|
2236
2645
|
}
|
|
2237
|
-
var thrownErrorSchema =
|
|
2238
|
-
message:
|
|
2239
|
-
status:
|
|
2240
|
-
statusCode:
|
|
2241
|
-
responseBody:
|
|
2646
|
+
var thrownErrorSchema = z2.object({
|
|
2647
|
+
message: z2.string().optional(),
|
|
2648
|
+
status: z2.number().optional(),
|
|
2649
|
+
statusCode: z2.number().optional(),
|
|
2650
|
+
responseBody: z2.string().optional()
|
|
2242
2651
|
});
|
|
2243
2652
|
function describeThrown(cause) {
|
|
2244
2653
|
const parsed = thrownErrorSchema.safeParse(cause);
|
|
@@ -2249,7 +2658,7 @@ function describeThrown(cause) {
|
|
|
2249
2658
|
}
|
|
2250
2659
|
|
|
2251
2660
|
// src/retry.ts
|
|
2252
|
-
var textBody =
|
|
2661
|
+
var textBody = z3.string();
|
|
2253
2662
|
function classifyHttpError(status, body, provider, model) {
|
|
2254
2663
|
const asText = textBody.safeParse(body);
|
|
2255
2664
|
const text2 = asText.success ? asText.data : JSON.stringify(body);
|
|
@@ -2306,12 +2715,12 @@ function sleep(ms, signal) {
|
|
|
2306
2715
|
rejectAborted();
|
|
2307
2716
|
return;
|
|
2308
2717
|
}
|
|
2309
|
-
let
|
|
2718
|
+
let timer2;
|
|
2310
2719
|
const onAbort = () => {
|
|
2311
|
-
if (
|
|
2720
|
+
if (timer2 !== void 0) clearTimeout(timer2);
|
|
2312
2721
|
rejectAborted();
|
|
2313
2722
|
};
|
|
2314
|
-
|
|
2723
|
+
timer2 = setTimeout(() => {
|
|
2315
2724
|
signal?.removeEventListener("abort", onAbort);
|
|
2316
2725
|
resolve();
|
|
2317
2726
|
}, ms);
|
|
@@ -2464,7 +2873,7 @@ import {
|
|
|
2464
2873
|
streamObject as aiStreamObject2,
|
|
2465
2874
|
streamText as aiStreamText2
|
|
2466
2875
|
} from "ai";
|
|
2467
|
-
import { z as
|
|
2876
|
+
import { z as z5 } from "zod";
|
|
2468
2877
|
|
|
2469
2878
|
// src/adapters/media-ref.ts
|
|
2470
2879
|
function isUrlRef(ref) {
|
|
@@ -2549,7 +2958,7 @@ import { createPerplexity } from "@ai-sdk/perplexity";
|
|
|
2549
2958
|
import { createXai } from "@ai-sdk/xai";
|
|
2550
2959
|
import { createDeepSeek } from "@ai-sdk/deepseek";
|
|
2551
2960
|
import { createMoonshotAI } from "@ai-sdk/moonshotai";
|
|
2552
|
-
import { z as
|
|
2961
|
+
import { z as z4 } from "zod";
|
|
2553
2962
|
var TEXT_PROVIDERS = [
|
|
2554
2963
|
"openai",
|
|
2555
2964
|
"anthropic",
|
|
@@ -2560,7 +2969,7 @@ var TEXT_PROVIDERS = [
|
|
|
2560
2969
|
"moonshot",
|
|
2561
2970
|
"minimax"
|
|
2562
2971
|
];
|
|
2563
|
-
var textProviderSchema =
|
|
2972
|
+
var textProviderSchema = z4.enum(TEXT_PROVIDERS);
|
|
2564
2973
|
function isTextProvider(value) {
|
|
2565
2974
|
return textProviderSchema.safeParse(value).success;
|
|
2566
2975
|
}
|
|
@@ -2730,10 +3139,10 @@ function textAbortOptions(sdk, context) {
|
|
|
2730
3139
|
if (abortSignal) return { abortSignal };
|
|
2731
3140
|
return {};
|
|
2732
3141
|
}
|
|
2733
|
-
var catalogId =
|
|
2734
|
-
var exactSize =
|
|
2735
|
-
var sdkRatio =
|
|
2736
|
-
var sizeTier =
|
|
3142
|
+
var catalogId = z5.string();
|
|
3143
|
+
var exactSize = z5.templateLiteral([z5.number(), "x", z5.number()]);
|
|
3144
|
+
var sdkRatio = z5.templateLiteral([z5.number(), ":", z5.number()]);
|
|
3145
|
+
var sizeTier = z5.enum(["512", "1K", "2K", "4K"]);
|
|
2737
3146
|
function isCatalogId(model) {
|
|
2738
3147
|
return catalogId.safeParse(model).success;
|
|
2739
3148
|
}
|
|
@@ -2800,7 +3209,7 @@ function logCoercions(logger, modelId, warnings) {
|
|
|
2800
3209
|
logger.warn(`[modelkit] ${modelId} request coerced`, { model: modelId, warnings });
|
|
2801
3210
|
}
|
|
2802
3211
|
function createModelKit(config, adapters) {
|
|
2803
|
-
const catalog =
|
|
3212
|
+
const catalog = config.catalogOverride ? liveCatalog.withOverrides(config.catalogOverride) : liveCatalog;
|
|
2804
3213
|
const logger = config.logger ?? console;
|
|
2805
3214
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
2806
3215
|
function context(model, call, warnings) {
|
|
@@ -3254,7 +3663,7 @@ function createModelKit(config, adapters) {
|
|
|
3254
3663
|
}
|
|
3255
3664
|
|
|
3256
3665
|
// src/adapters/ark.ts
|
|
3257
|
-
import { z as
|
|
3666
|
+
import { z as z6 } from "zod";
|
|
3258
3667
|
var ARK_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
3259
3668
|
var SUBMIT_PATH = "/contents/generations/tasks";
|
|
3260
3669
|
var SEEDANCE_POLL_INTERVAL_MS = 15e3;
|
|
@@ -3331,7 +3740,7 @@ function arkKey(ctx) {
|
|
|
3331
3740
|
return key;
|
|
3332
3741
|
}
|
|
3333
3742
|
function throwArkError(status, body, model) {
|
|
3334
|
-
const parsed =
|
|
3743
|
+
const parsed = z6.string().safeParse(body);
|
|
3335
3744
|
const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
|
|
3336
3745
|
if (/sensitive.?content|human.?face/i.test(text2)) {
|
|
3337
3746
|
const init = {
|
|
@@ -3369,13 +3778,13 @@ function sniffedImageMime(bytes) {
|
|
|
3369
3778
|
return "image/webp";
|
|
3370
3779
|
return "image/jpeg";
|
|
3371
3780
|
}
|
|
3372
|
-
var SeedreamImageSchema =
|
|
3373
|
-
url:
|
|
3374
|
-
b64_json:
|
|
3781
|
+
var SeedreamImageSchema = z6.object({
|
|
3782
|
+
url: z6.string().optional(),
|
|
3783
|
+
b64_json: z6.string().optional()
|
|
3375
3784
|
});
|
|
3376
|
-
var SeedreamResponseSchema =
|
|
3377
|
-
data:
|
|
3378
|
-
error:
|
|
3785
|
+
var SeedreamResponseSchema = z6.object({
|
|
3786
|
+
data: z6.array(SeedreamImageSchema).optional(),
|
|
3787
|
+
error: z6.object({ message: z6.string().optional(), code: z6.string().optional() }).optional()
|
|
3379
3788
|
});
|
|
3380
3789
|
function retryOptsFor(ctx, attempts = 3) {
|
|
3381
3790
|
const opts = { attempts };
|
|
@@ -3447,21 +3856,21 @@ async function generateSeedreamImage(req, ctx) {
|
|
|
3447
3856
|
if (req.quality !== void 0) usage2.imageQuality = req.quality;
|
|
3448
3857
|
return { images: [{ bytes, mime: sniffedImageMime(bytes) }], usage: usage2, raw: data };
|
|
3449
3858
|
}
|
|
3450
|
-
var SeedanceUsageSchema =
|
|
3451
|
-
total_tokens:
|
|
3452
|
-
completion_tokens:
|
|
3859
|
+
var SeedanceUsageSchema = z6.object({
|
|
3860
|
+
total_tokens: z6.number().optional(),
|
|
3861
|
+
completion_tokens: z6.number().optional()
|
|
3453
3862
|
});
|
|
3454
|
-
var SeedanceResponseSchema =
|
|
3455
|
-
id:
|
|
3456
|
-
status:
|
|
3457
|
-
content:
|
|
3863
|
+
var SeedanceResponseSchema = z6.object({
|
|
3864
|
+
id: z6.string().optional(),
|
|
3865
|
+
status: z6.string().optional(),
|
|
3866
|
+
content: z6.object({ video_url: z6.string().optional() }).optional(),
|
|
3458
3867
|
usage: SeedanceUsageSchema.optional(),
|
|
3459
|
-
duration:
|
|
3460
|
-
framespersecond:
|
|
3461
|
-
resolution:
|
|
3462
|
-
error:
|
|
3868
|
+
duration: z6.number().optional(),
|
|
3869
|
+
framespersecond: z6.number().optional(),
|
|
3870
|
+
resolution: z6.string().optional(),
|
|
3871
|
+
error: z6.union([z6.string(), z6.object({ message: z6.string().optional() })]).optional()
|
|
3463
3872
|
});
|
|
3464
|
-
var SeedanceErrorMessageSchema =
|
|
3873
|
+
var SeedanceErrorMessageSchema = z6.object({ message: z6.string().optional() });
|
|
3465
3874
|
function seedanceUsage(ctx, req, duration) {
|
|
3466
3875
|
const usage2 = {
|
|
3467
3876
|
model: ctx.model.id,
|
|
@@ -3475,7 +3884,7 @@ function seedanceUsage(ctx, req, duration) {
|
|
|
3475
3884
|
return usage2;
|
|
3476
3885
|
}
|
|
3477
3886
|
function seedanceErrorMessage(error, status) {
|
|
3478
|
-
const asString =
|
|
3887
|
+
const asString = z6.string().safeParse(error);
|
|
3479
3888
|
if (asString.success) return asString.data;
|
|
3480
3889
|
const asObject = SeedanceErrorMessageSchema.safeParse(error);
|
|
3481
3890
|
if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
|
|
@@ -3624,7 +4033,7 @@ async function generateSeedanceVideo(req, ctx) {
|
|
|
3624
4033
|
}
|
|
3625
4034
|
|
|
3626
4035
|
// src/adapters/fal.ts
|
|
3627
|
-
import { z as
|
|
4036
|
+
import { z as z7 } from "zod";
|
|
3628
4037
|
import { createFalClient } from "@fal-ai/client";
|
|
3629
4038
|
var MUSE_T2I_ENDPOINT = "meta/muse-image/text-to-image";
|
|
3630
4039
|
var MUSE_EDIT_ENDPOINT = "meta/muse-image/edit";
|
|
@@ -3632,7 +4041,7 @@ var KLING_O1_ENDPOINT = "fal-ai/kling-video/o1/video-to-video/reference";
|
|
|
3632
4041
|
var FAL_QUEUE_HOST = "https://queue.fal.run";
|
|
3633
4042
|
var PASSTHROUGH_POLL_MS = 2e3;
|
|
3634
4043
|
var PASSTHROUGH_MAX_WAIT_MS = 18e4;
|
|
3635
|
-
var falSubscribePayloadSchema =
|
|
4044
|
+
var falSubscribePayloadSchema = z7.object({ data: JsonValueSchema });
|
|
3636
4045
|
function defaultCreateFalClient(opts) {
|
|
3637
4046
|
const client2 = createFalClient(opts);
|
|
3638
4047
|
return {
|
|
@@ -3682,7 +4091,7 @@ function createFalAdapter(deps = defaultDeps) {
|
|
|
3682
4091
|
};
|
|
3683
4092
|
}
|
|
3684
4093
|
var falAdapter = createFalAdapter();
|
|
3685
|
-
var falDetailSchema =
|
|
4094
|
+
var falDetailSchema = z7.object({ detail: JsonValueSchema });
|
|
3686
4095
|
function liftDetail(body) {
|
|
3687
4096
|
const parsed = falDetailSchema.safeParse(body);
|
|
3688
4097
|
const detail = parsed.success ? parsed.data.detail : void 0;
|
|
@@ -3691,11 +4100,11 @@ function liftDetail(body) {
|
|
|
3691
4100
|
function falError(status, body, model) {
|
|
3692
4101
|
return classifyHttpError(status, liftDetail(body), "fal", model);
|
|
3693
4102
|
}
|
|
3694
|
-
var falSdkThrownSchema =
|
|
3695
|
-
status:
|
|
3696
|
-
statusCode:
|
|
4103
|
+
var falSdkThrownSchema = z7.object({
|
|
4104
|
+
status: z7.number().optional(),
|
|
4105
|
+
statusCode: z7.number().optional(),
|
|
3697
4106
|
body: JsonValueSchema.optional(),
|
|
3698
|
-
message:
|
|
4107
|
+
message: z7.string().optional()
|
|
3699
4108
|
});
|
|
3700
4109
|
function falSdkError(cause, model) {
|
|
3701
4110
|
const parsed = falSdkThrownSchema.safeParse(cause);
|
|
@@ -3739,12 +4148,12 @@ async function gatewayFetch(cfg, fetchImpl, targetUrl, init) {
|
|
|
3739
4148
|
if (init.body !== void 0) request.body = init.body;
|
|
3740
4149
|
return fetchImpl(cfg.baseUrl, request);
|
|
3741
4150
|
}
|
|
3742
|
-
var falQueueSubmitSchema =
|
|
3743
|
-
request_id:
|
|
3744
|
-
status_url:
|
|
3745
|
-
response_url:
|
|
4151
|
+
var falQueueSubmitSchema = z7.object({
|
|
4152
|
+
request_id: z7.string(),
|
|
4153
|
+
status_url: z7.string(),
|
|
4154
|
+
response_url: z7.string()
|
|
3746
4155
|
});
|
|
3747
|
-
var falQueueStatusSchema =
|
|
4156
|
+
var falQueueStatusSchema = z7.object({ status: z7.string() });
|
|
3748
4157
|
async function passthroughRequest(ctx, endpoint, input) {
|
|
3749
4158
|
const cfg = gatewayConfig(ctx);
|
|
3750
4159
|
const submitRes = await gatewayFetch(cfg, ctx.fetch, `${FAL_QUEUE_HOST}/${endpoint}`, {
|
|
@@ -3870,11 +4279,11 @@ async function decodeImage(ctx, url, contentType) {
|
|
|
3870
4279
|
const mime = res.headers.get("content-type") ?? contentType ?? "image/png";
|
|
3871
4280
|
return { bytes: new Uint8Array(await res.arrayBuffer()), mime };
|
|
3872
4281
|
}
|
|
3873
|
-
var museImageResultSchema =
|
|
3874
|
-
images:
|
|
3875
|
-
|
|
3876
|
-
url:
|
|
3877
|
-
content_type:
|
|
4282
|
+
var museImageResultSchema = z7.object({
|
|
4283
|
+
images: z7.array(
|
|
4284
|
+
z7.object({
|
|
4285
|
+
url: z7.string().optional(),
|
|
4286
|
+
content_type: z7.string().nullable().optional()
|
|
3878
4287
|
})
|
|
3879
4288
|
).optional()
|
|
3880
4289
|
});
|
|
@@ -3966,8 +4375,8 @@ function klingO1Input(req) {
|
|
|
3966
4375
|
if (refs.length > 0) input.image_urls = refs;
|
|
3967
4376
|
return input;
|
|
3968
4377
|
}
|
|
3969
|
-
var falVideoResultSchema =
|
|
3970
|
-
video:
|
|
4378
|
+
var falVideoResultSchema = z7.object({
|
|
4379
|
+
video: z7.object({ url: z7.string().optional() }).optional()
|
|
3971
4380
|
});
|
|
3972
4381
|
function extractVideoUrl(result, endpoint, model) {
|
|
3973
4382
|
const parsed = falVideoResultSchema.safeParse(result);
|
|
@@ -4157,13 +4566,13 @@ async function passthroughVideoJob(ctx, req, endpoint, input) {
|
|
|
4157
4566
|
}
|
|
4158
4567
|
|
|
4159
4568
|
// src/adapters/google-genai.ts
|
|
4160
|
-
import { z as
|
|
4569
|
+
import { z as z9 } from "zod";
|
|
4161
4570
|
import {
|
|
4162
4571
|
GoogleGenAI
|
|
4163
4572
|
} from "@google/genai";
|
|
4164
4573
|
|
|
4165
4574
|
// src/adapters/google-files.ts
|
|
4166
|
-
import { z as
|
|
4575
|
+
import { z as z8 } from "zod";
|
|
4167
4576
|
var GOOGLE_FILES_BASE = "https://generativelanguage.googleapis.com";
|
|
4168
4577
|
var GOOGLE_FILES_POLL_INTERVAL_MS = 2e3;
|
|
4169
4578
|
var GOOGLE_FILES_POLL_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
@@ -4173,17 +4582,17 @@ var GENERIC_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
|
4173
4582
|
"binary/octet-stream",
|
|
4174
4583
|
"application/binary"
|
|
4175
4584
|
]);
|
|
4176
|
-
var uploadedFileSchema =
|
|
4177
|
-
file:
|
|
4178
|
-
uri:
|
|
4179
|
-
name:
|
|
4180
|
-
state:
|
|
4181
|
-
mimeType:
|
|
4585
|
+
var uploadedFileSchema = z8.object({
|
|
4586
|
+
file: z8.object({
|
|
4587
|
+
uri: z8.string().optional(),
|
|
4588
|
+
name: z8.string().optional(),
|
|
4589
|
+
state: z8.string().optional(),
|
|
4590
|
+
mimeType: z8.string().optional()
|
|
4182
4591
|
}).optional()
|
|
4183
4592
|
});
|
|
4184
|
-
var fileStateSchema =
|
|
4185
|
-
state:
|
|
4186
|
-
error:
|
|
4593
|
+
var fileStateSchema = z8.object({
|
|
4594
|
+
state: z8.string().optional(),
|
|
4595
|
+
error: z8.object({ message: z8.string().optional() }).optional()
|
|
4187
4596
|
});
|
|
4188
4597
|
function resolveMime(declared, fallback) {
|
|
4189
4598
|
const clean = declared?.split(";")[0]?.trim().toLowerCase();
|
|
@@ -4396,7 +4805,7 @@ var OMNI_POLL_INTERVAL_MS = 1e4;
|
|
|
4396
4805
|
var RESULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
|
|
4397
4806
|
var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
4398
4807
|
var MEDIA_PART_INLINE_LIMIT_BYTES = 20 * 1024 * 1024;
|
|
4399
|
-
var errorTextSchema =
|
|
4808
|
+
var errorTextSchema = z9.string();
|
|
4400
4809
|
function createGoogleGenaiAdapter(deps = defaultDeps2) {
|
|
4401
4810
|
const { createGenAIClient } = deps;
|
|
4402
4811
|
return {
|
|
@@ -4954,15 +5363,15 @@ async function prepareGoogleMediaPart(ref, mediaType, ctx) {
|
|
|
4954
5363
|
// src/adapters/google-image.ts
|
|
4955
5364
|
import { createGoogleGenerativeAI as createGoogleGenerativeAI2 } from "@ai-sdk/google";
|
|
4956
5365
|
import { generateText } from "ai";
|
|
4957
|
-
import { z as
|
|
5366
|
+
import { z as z10 } from "zod";
|
|
4958
5367
|
var GEMINI_IMAGE_TIMEOUT_MS = 6e5;
|
|
4959
5368
|
var defaultGoogleImageDeps = {
|
|
4960
5369
|
createGoogleClient: (opts) => createGoogleGenerativeAI2(opts),
|
|
4961
5370
|
runTextGeneration: (opts) => generateText(opts)
|
|
4962
5371
|
};
|
|
4963
|
-
var causeChainNodeSchema =
|
|
4964
|
-
message:
|
|
4965
|
-
cause:
|
|
5372
|
+
var causeChainNodeSchema = z10.object({
|
|
5373
|
+
message: z10.string().optional(),
|
|
5374
|
+
cause: z10.unknown().optional()
|
|
4966
5375
|
});
|
|
4967
5376
|
function extractBlockReason(cause) {
|
|
4968
5377
|
let current = cause;
|
|
@@ -5083,7 +5492,7 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
|
|
|
5083
5492
|
var googleImageAdapter = createGoogleImageAdapter();
|
|
5084
5493
|
|
|
5085
5494
|
// src/adapters/higgsfield.ts
|
|
5086
|
-
import { z as
|
|
5495
|
+
import { z as z11 } from "zod";
|
|
5087
5496
|
|
|
5088
5497
|
// src/adapters/higgsfield-motions.ts
|
|
5089
5498
|
var MOTION_MAP = {
|
|
@@ -5271,14 +5680,14 @@ function videoUsage3(ctx, req, duration) {
|
|
|
5271
5680
|
if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
|
|
5272
5681
|
return event;
|
|
5273
5682
|
}
|
|
5274
|
-
var klingCreateSchema =
|
|
5275
|
-
var klingStatusSchema =
|
|
5276
|
-
status:
|
|
5277
|
-
video:
|
|
5683
|
+
var klingCreateSchema = z11.object({ status_url: z11.string() });
|
|
5684
|
+
var klingStatusSchema = z11.object({
|
|
5685
|
+
status: z11.string().optional(),
|
|
5686
|
+
video: z11.object({ url: z11.string().optional() }).optional(),
|
|
5278
5687
|
error: JsonValueSchema.optional()
|
|
5279
5688
|
});
|
|
5280
|
-
var errorMessageSchema =
|
|
5281
|
-
var textValueSchema =
|
|
5689
|
+
var errorMessageSchema = z11.object({ message: z11.string().optional() });
|
|
5690
|
+
var textValueSchema = z11.string();
|
|
5282
5691
|
function klingErrorDetail(error) {
|
|
5283
5692
|
if (error === void 0) return "unknown_error";
|
|
5284
5693
|
const asText = textValueSchema.safeParse(error);
|
|
@@ -5412,8 +5821,8 @@ async function generateKlingVideo(req, ctx) {
|
|
|
5412
5821
|
}
|
|
5413
5822
|
};
|
|
5414
5823
|
}
|
|
5415
|
-
var dopMotionOptionsSchema =
|
|
5416
|
-
modelkit:
|
|
5824
|
+
var dopMotionOptionsSchema = z11.object({
|
|
5825
|
+
modelkit: z11.object({ motion: z11.string().optional() }).optional()
|
|
5417
5826
|
});
|
|
5418
5827
|
function dopMotionId(ctx) {
|
|
5419
5828
|
const parsed = dopMotionOptionsSchema.safeParse(ctx.model.providerOptions);
|
|
@@ -5429,7 +5838,7 @@ function dopMotionId(ctx) {
|
|
|
5429
5838
|
});
|
|
5430
5839
|
return id;
|
|
5431
5840
|
}
|
|
5432
|
-
var jsonRecordSchema =
|
|
5841
|
+
var jsonRecordSchema = z11.record(z11.string(), JsonValueSchema);
|
|
5433
5842
|
var DOP_URL_KEYS = ["url", "video_url", "output_url", "result_url", "download_url"];
|
|
5434
5843
|
var DOP_NESTED_KEYS = ["video", "result", "results"];
|
|
5435
5844
|
function dopUrl(body) {
|
|
@@ -5457,8 +5866,8 @@ function dopUrl(body) {
|
|
|
5457
5866
|
}
|
|
5458
5867
|
return void 0;
|
|
5459
5868
|
}
|
|
5460
|
-
var dopCreateSchema =
|
|
5461
|
-
var dopStatusSchema =
|
|
5869
|
+
var dopCreateSchema = z11.object({ id: z11.string() });
|
|
5870
|
+
var dopStatusSchema = z11.object({ status: z11.string().optional() });
|
|
5462
5871
|
async function generateDopVideo(req, ctx) {
|
|
5463
5872
|
const firstFrame = req.firstFrame ? refToUrl(req.firstFrame) : void 0;
|
|
5464
5873
|
if (!firstFrame) {
|
|
@@ -5578,7 +5987,7 @@ var higgsfieldAdapter = {
|
|
|
5578
5987
|
|
|
5579
5988
|
// src/adapters/openai-image.ts
|
|
5580
5989
|
import OpenAI from "openai";
|
|
5581
|
-
import { z as
|
|
5990
|
+
import { z as z12 } from "zod";
|
|
5582
5991
|
var MAX_EDIT_REFERENCES = 16;
|
|
5583
5992
|
function aspectRatioToSize(ratio, tier) {
|
|
5584
5993
|
const TIER_LONG_EDGE = {
|
|
@@ -5661,9 +6070,9 @@ function toProviderError2(cause, ctx) {
|
|
|
5661
6070
|
ctx.model.id
|
|
5662
6071
|
);
|
|
5663
6072
|
}
|
|
5664
|
-
var openaiUsageSchema =
|
|
5665
|
-
input_tokens:
|
|
5666
|
-
output_tokens:
|
|
6073
|
+
var openaiUsageSchema = z12.object({
|
|
6074
|
+
input_tokens: z12.number().optional(),
|
|
6075
|
+
output_tokens: z12.number().optional()
|
|
5667
6076
|
});
|
|
5668
6077
|
var openaiImageAdapter = {
|
|
5669
6078
|
id: "openai-image",
|
|
@@ -6053,7 +6462,7 @@ var prodiaAdapter = {
|
|
|
6053
6462
|
|
|
6054
6463
|
// src/adapters/replicate.ts
|
|
6055
6464
|
import Replicate from "replicate";
|
|
6056
|
-
import { z as
|
|
6465
|
+
import { z as z13 } from "zod";
|
|
6057
6466
|
var POLL_INTERVAL_MS = 1e3;
|
|
6058
6467
|
var POLL_TIMEOUT_MS = 15 * 6e4;
|
|
6059
6468
|
var defaultReplicateDeps = {
|
|
@@ -6089,8 +6498,8 @@ function route(providerModelId) {
|
|
|
6089
6498
|
if (!providerModelId.includes("/")) return { version: providerModelId };
|
|
6090
6499
|
return { model: providerModelId };
|
|
6091
6500
|
}
|
|
6092
|
-
var replicateResponseStatusSchema =
|
|
6093
|
-
response:
|
|
6501
|
+
var replicateResponseStatusSchema = z13.object({
|
|
6502
|
+
response: z13.object({ status: z13.number() }).partial()
|
|
6094
6503
|
});
|
|
6095
6504
|
function replicateError(cause, ctx) {
|
|
6096
6505
|
if (isModelKitError(cause)) return cause;
|
|
@@ -6117,7 +6526,7 @@ function isUrlFn(value) {
|
|
|
6117
6526
|
function extractOutputUrl(output) {
|
|
6118
6527
|
const root = Array.isArray(output) ? output[0] : output;
|
|
6119
6528
|
if (root === void 0) throw noOutput();
|
|
6120
|
-
const asString =
|
|
6529
|
+
const asString = z13.string().safeParse(root);
|
|
6121
6530
|
if (asString.success && asString.data) return asString.data;
|
|
6122
6531
|
if (root instanceof URL) return root.href;
|
|
6123
6532
|
if (isObjectOutput(root)) {
|
|
@@ -6126,15 +6535,15 @@ function extractOutputUrl(output) {
|
|
|
6126
6535
|
if (urlValue !== void 0 && isUrlFn(urlValue)) {
|
|
6127
6536
|
const called = urlValue();
|
|
6128
6537
|
if (called instanceof URL) return called.href;
|
|
6129
|
-
const calledString =
|
|
6538
|
+
const calledString = z13.string().safeParse(called);
|
|
6130
6539
|
if (calledString.success && calledString.data) return calledString.data;
|
|
6131
6540
|
} else {
|
|
6132
|
-
const direct =
|
|
6541
|
+
const direct = z13.string().safeParse(urlValue);
|
|
6133
6542
|
if (direct.success && direct.data) return direct.data;
|
|
6134
6543
|
}
|
|
6135
6544
|
}
|
|
6136
6545
|
if ("default" in root) {
|
|
6137
|
-
const fallback =
|
|
6546
|
+
const fallback = z13.string().safeParse(root.default);
|
|
6138
6547
|
if (fallback.success && fallback.data) return fallback.data;
|
|
6139
6548
|
}
|
|
6140
6549
|
}
|
|
@@ -6195,7 +6604,7 @@ async function runPrediction(ctx, input, deps) {
|
|
|
6195
6604
|
}
|
|
6196
6605
|
return void 0;
|
|
6197
6606
|
}, pollOpts);
|
|
6198
|
-
const predictTime =
|
|
6607
|
+
const predictTime = z13.number().safeParse(done.metrics?.predict_time);
|
|
6199
6608
|
if (done.output === void 0) throw noOutput();
|
|
6200
6609
|
return {
|
|
6201
6610
|
url: extractOutputUrl(done.output),
|
|
@@ -6538,7 +6947,7 @@ async function generateReplicateVideo(req, ctx, deps) {
|
|
|
6538
6947
|
throw replicateError(cause, ctx);
|
|
6539
6948
|
}
|
|
6540
6949
|
if (current.status === "succeeded") {
|
|
6541
|
-
const predictTime =
|
|
6950
|
+
const predictTime = z13.number().safeParse(current.metrics?.predict_time);
|
|
6542
6951
|
if (current.output === void 0) throw noOutput();
|
|
6543
6952
|
return {
|
|
6544
6953
|
url: extractOutputUrl(current.output),
|
|
@@ -6670,7 +7079,7 @@ async function generateReplicateAudio(req, ctx, deps) {
|
|
|
6670
7079
|
// src/adapters/xai-video.ts
|
|
6671
7080
|
import { experimental_generateVideo } from "ai";
|
|
6672
7081
|
import { createXai as createXai2 } from "@ai-sdk/xai";
|
|
6673
|
-
import { z as
|
|
7082
|
+
import { z as z14 } from "zod";
|
|
6674
7083
|
var POLL_INTERVAL_MS2 = 1e4;
|
|
6675
7084
|
var POLL_TIMEOUT_MS2 = 15 * 6e4;
|
|
6676
7085
|
var defaultXaiDeps = {
|
|
@@ -6683,8 +7092,8 @@ function createXaiVideoAdapter(deps = defaultXaiDeps) {
|
|
|
6683
7092
|
};
|
|
6684
7093
|
}
|
|
6685
7094
|
var xaiVideoAdapter = createXaiVideoAdapter();
|
|
6686
|
-
var xaiResponseStatusSchema =
|
|
6687
|
-
response:
|
|
7095
|
+
var xaiResponseStatusSchema = z14.object({
|
|
7096
|
+
response: z14.object({ status: z14.number() }).partial()
|
|
6688
7097
|
});
|
|
6689
7098
|
function xaiError(cause, ctx) {
|
|
6690
7099
|
const info = describeThrown(cause);
|
|
@@ -6692,12 +7101,12 @@ function xaiError(cause, ctx) {
|
|
|
6692
7101
|
const status = info.status ?? (nested.success ? nested.data.response?.status : void 0);
|
|
6693
7102
|
return classifyThrown("xai-video", cause, ctx.model.id, { status, body: info.body });
|
|
6694
7103
|
}
|
|
6695
|
-
var xaiMetaSchema =
|
|
7104
|
+
var xaiMetaSchema = z14.object({
|
|
6696
7105
|
videoUrl: JsonValueSchema.optional(),
|
|
6697
7106
|
costInUsdTicks: JsonValueSchema.optional(),
|
|
6698
7107
|
duration: JsonValueSchema.optional()
|
|
6699
7108
|
});
|
|
6700
|
-
var xaiProviderMetadataSchema =
|
|
7109
|
+
var xaiProviderMetadataSchema = z14.object({ xai: xaiMetaSchema });
|
|
6701
7110
|
function metaOf(result) {
|
|
6702
7111
|
const parsed = xaiProviderMetadataSchema.partial().safeParse(result.providerMetadata);
|
|
6703
7112
|
if (!parsed.success) return {};
|
|
@@ -6804,7 +7213,7 @@ async function mapResult(ctx, req, result) {
|
|
|
6804
7213
|
};
|
|
6805
7214
|
}
|
|
6806
7215
|
const meta = metaOf(result);
|
|
6807
|
-
const videoUrl =
|
|
7216
|
+
const videoUrl = z14.string().safeParse(meta.videoUrl);
|
|
6808
7217
|
if (videoUrl.success && videoUrl.data) {
|
|
6809
7218
|
const res = await ctx.fetch(videoUrl.data);
|
|
6810
7219
|
if (!res.ok) {
|
|
@@ -6827,7 +7236,7 @@ async function mapResult(ctx, req, result) {
|
|
|
6827
7236
|
});
|
|
6828
7237
|
}
|
|
6829
7238
|
function usage(ctx, req, meta) {
|
|
6830
|
-
const costTicks =
|
|
7239
|
+
const costTicks = z14.number().safeParse(meta.costInUsdTicks);
|
|
6831
7240
|
const cost = costTicks.success ? costTicks.data / 1e10 : void 0;
|
|
6832
7241
|
const event = {
|
|
6833
7242
|
model: ctx.model.id,
|
|
@@ -6875,8 +7284,11 @@ var prepareMediaPart = (modelId, ref, mediaType, call) => createDefaultModelKit(
|
|
|
6875
7284
|
var languageModel = (modelId, call) => createDefaultModelKit().languageModel(modelId, call);
|
|
6876
7285
|
var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
6877
7286
|
export {
|
|
7287
|
+
ADAPTER_IDS,
|
|
6878
7288
|
ADAPTER_KEYS,
|
|
6879
7289
|
Catalog,
|
|
7290
|
+
CatalogModelSchema,
|
|
7291
|
+
CatalogSchema,
|
|
6880
7292
|
DEFAULT_ADAPTERS,
|
|
6881
7293
|
JsonObjectSchema,
|
|
6882
7294
|
JsonValueSchema,
|
|
@@ -6892,6 +7304,7 @@ export {
|
|
|
6892
7304
|
describeThrown,
|
|
6893
7305
|
generateImage as experimental_generateImage,
|
|
6894
7306
|
falAdapter,
|
|
7307
|
+
fileCatalogCache,
|
|
6895
7308
|
generateAudio,
|
|
6896
7309
|
generateImage,
|
|
6897
7310
|
generateObject,
|
|
@@ -6903,15 +7316,18 @@ export {
|
|
|
6903
7316
|
isModelKitError,
|
|
6904
7317
|
keysFromEnv,
|
|
6905
7318
|
languageModel,
|
|
7319
|
+
liveCatalog,
|
|
6906
7320
|
mergeTextProviderOptions,
|
|
6907
7321
|
nearestAspectRatio,
|
|
6908
7322
|
openaiImageAdapter,
|
|
6909
7323
|
passthroughTextModel,
|
|
6910
7324
|
pollUntil,
|
|
6911
7325
|
prepareMediaPart,
|
|
7326
|
+
primeCatalog,
|
|
6912
7327
|
prodiaAdapter,
|
|
6913
7328
|
readErrorBody,
|
|
6914
7329
|
replicateAdapter,
|
|
7330
|
+
resetLiveCatalog,
|
|
6915
7331
|
resolveAudioOptions,
|
|
6916
7332
|
resolveImageOptions,
|
|
6917
7333
|
resolveKeys,
|