@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.cjs
CHANGED
|
@@ -31,8 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
+
ADAPTER_IDS: () => ADAPTER_IDS,
|
|
34
35
|
ADAPTER_KEYS: () => ADAPTER_KEYS,
|
|
35
36
|
Catalog: () => Catalog,
|
|
37
|
+
CatalogModelSchema: () => CatalogModelSchema,
|
|
38
|
+
CatalogSchema: () => CatalogSchema,
|
|
36
39
|
DEFAULT_ADAPTERS: () => DEFAULT_ADAPTERS,
|
|
37
40
|
JsonObjectSchema: () => JsonObjectSchema,
|
|
38
41
|
JsonValueSchema: () => JsonValueSchema,
|
|
@@ -48,6 +51,7 @@ __export(index_exports, {
|
|
|
48
51
|
describeThrown: () => describeThrown,
|
|
49
52
|
experimental_generateImage: () => generateImage,
|
|
50
53
|
falAdapter: () => falAdapter,
|
|
54
|
+
fileCatalogCache: () => fileCatalogCache,
|
|
51
55
|
generateAudio: () => generateAudio,
|
|
52
56
|
generateImage: () => generateImage,
|
|
53
57
|
generateObject: () => generateObject,
|
|
@@ -59,15 +63,18 @@ __export(index_exports, {
|
|
|
59
63
|
isModelKitError: () => isModelKitError,
|
|
60
64
|
keysFromEnv: () => keysFromEnv,
|
|
61
65
|
languageModel: () => languageModel,
|
|
66
|
+
liveCatalog: () => liveCatalog,
|
|
62
67
|
mergeTextProviderOptions: () => mergeTextProviderOptions,
|
|
63
68
|
nearestAspectRatio: () => nearestAspectRatio,
|
|
64
69
|
openaiImageAdapter: () => openaiImageAdapter,
|
|
65
70
|
passthroughTextModel: () => passthroughTextModel,
|
|
66
71
|
pollUntil: () => pollUntil,
|
|
67
72
|
prepareMediaPart: () => prepareMediaPart,
|
|
73
|
+
primeCatalog: () => primeCatalog,
|
|
68
74
|
prodiaAdapter: () => prodiaAdapter,
|
|
69
75
|
readErrorBody: () => readErrorBody,
|
|
70
76
|
replicateAdapter: () => replicateAdapter,
|
|
77
|
+
resetLiveCatalog: () => resetLiveCatalog,
|
|
71
78
|
resolveAudioOptions: () => resolveAudioOptions,
|
|
72
79
|
resolveImageOptions: () => resolveImageOptions,
|
|
73
80
|
resolveKeys: () => resolveKeys,
|
|
@@ -179,6 +186,14 @@ var Catalog = class _Catalog {
|
|
|
179
186
|
...rows
|
|
180
187
|
]);
|
|
181
188
|
}
|
|
189
|
+
/** Atomically swap every row. Builds the maps first so a bad batch throws before anything changes. */
|
|
190
|
+
replace(rows) {
|
|
191
|
+
const next = new _Catalog(rows);
|
|
192
|
+
this.byId.clear();
|
|
193
|
+
this.byAlias.clear();
|
|
194
|
+
for (const [id, model] of next.byId) this.byId.set(id, model);
|
|
195
|
+
for (const [alias, id] of next.byAlias) this.byAlias.set(alias, id);
|
|
196
|
+
}
|
|
182
197
|
};
|
|
183
198
|
|
|
184
199
|
// src/catalog/image.ts
|
|
@@ -1869,6 +1884,407 @@ var MODELS = [
|
|
|
1869
1884
|
...OTHER_MODELS
|
|
1870
1885
|
];
|
|
1871
1886
|
|
|
1887
|
+
// src/catalog/schema.ts
|
|
1888
|
+
var import_zod = require("zod");
|
|
1889
|
+
var ADAPTER_IDS = [
|
|
1890
|
+
"ai-sdk-text",
|
|
1891
|
+
"google-image",
|
|
1892
|
+
"openai-image",
|
|
1893
|
+
"google-genai",
|
|
1894
|
+
"ark",
|
|
1895
|
+
"fal",
|
|
1896
|
+
"replicate",
|
|
1897
|
+
"prodia",
|
|
1898
|
+
"higgsfield",
|
|
1899
|
+
"xai-video"
|
|
1900
|
+
];
|
|
1901
|
+
var ModelTypeSchema = import_zod.z.enum(["text", "image", "video", "audio", "upscale", "bg-remove"]);
|
|
1902
|
+
var LifecycleSchema = import_zod.z.enum(["active", "deprecated", "retired"]);
|
|
1903
|
+
var AdapterSchema = import_zod.z.enum(ADAPTER_IDS);
|
|
1904
|
+
var AspectRatioSchema = import_zod.z.enum([
|
|
1905
|
+
"1:1",
|
|
1906
|
+
"16:9",
|
|
1907
|
+
"9:16",
|
|
1908
|
+
"4:3",
|
|
1909
|
+
"3:4",
|
|
1910
|
+
"3:2",
|
|
1911
|
+
"2:3",
|
|
1912
|
+
"4:5",
|
|
1913
|
+
"5:4",
|
|
1914
|
+
"21:9",
|
|
1915
|
+
"9:21",
|
|
1916
|
+
"97:30",
|
|
1917
|
+
"adaptive"
|
|
1918
|
+
]);
|
|
1919
|
+
var ImageSizeSchema = import_zod.z.enum(["512", "1K", "2K", "4K"]);
|
|
1920
|
+
var VideoResolutionSchema = import_zod.z.enum(["360p", "480p", "720p", "768p", "1080p", "2k", "4k"]);
|
|
1921
|
+
var ImageQualitySchema = import_zod.z.enum(["auto", "low", "medium", "high", "xhigh", "max"]);
|
|
1922
|
+
var OutputFormatSchema = import_zod.z.enum(["png", "jpeg", "webp"]);
|
|
1923
|
+
var RequiredInputSchema = import_zod.z.enum(["firstFrame", "sourceVideo", "references"]);
|
|
1924
|
+
var SupportedOptionSchema = import_zod.z.enum([
|
|
1925
|
+
"seed",
|
|
1926
|
+
"quality",
|
|
1927
|
+
"negativePrompt",
|
|
1928
|
+
"cfgScale",
|
|
1929
|
+
"generateAudio",
|
|
1930
|
+
"promptExpansion",
|
|
1931
|
+
"lastFrame",
|
|
1932
|
+
"count",
|
|
1933
|
+
"outputFormat",
|
|
1934
|
+
"scaleFactor",
|
|
1935
|
+
"safetySettings",
|
|
1936
|
+
"temperature",
|
|
1937
|
+
"upscale",
|
|
1938
|
+
"watermark",
|
|
1939
|
+
"safetyChecker",
|
|
1940
|
+
"instrumental"
|
|
1941
|
+
]);
|
|
1942
|
+
var UsageUnitSchema = import_zod.z.enum([
|
|
1943
|
+
"tokens",
|
|
1944
|
+
"images",
|
|
1945
|
+
"seconds",
|
|
1946
|
+
"reported_cost_usd",
|
|
1947
|
+
"compute_seconds"
|
|
1948
|
+
]);
|
|
1949
|
+
var PricingKindSchema = import_zod.z.enum(["token", "image_size", "video_per_second", "flat"]);
|
|
1950
|
+
var ProviderOptionValueSchema = import_zod.z.lazy(
|
|
1951
|
+
() => import_zod.z.union([
|
|
1952
|
+
import_zod.z.string(),
|
|
1953
|
+
import_zod.z.number(),
|
|
1954
|
+
import_zod.z.boolean(),
|
|
1955
|
+
import_zod.z.array(ProviderOptionValueSchema),
|
|
1956
|
+
import_zod.z.record(import_zod.z.string(), ProviderOptionValueSchema)
|
|
1957
|
+
])
|
|
1958
|
+
);
|
|
1959
|
+
var ProviderOptionsSchema = import_zod.z.record(import_zod.z.string(), import_zod.z.record(import_zod.z.string(), ProviderOptionValueSchema));
|
|
1960
|
+
var ReferenceLimitsSchema = import_zod.z.looseObject({
|
|
1961
|
+
images: import_zod.z.number().optional(),
|
|
1962
|
+
videos: import_zod.z.number().optional(),
|
|
1963
|
+
audios: import_zod.z.number().optional(),
|
|
1964
|
+
total: import_zod.z.number().optional(),
|
|
1965
|
+
audioOnly: import_zod.z.boolean().optional()
|
|
1966
|
+
});
|
|
1967
|
+
var ModelConstraintsSchema = import_zod.z.looseObject({
|
|
1968
|
+
aspectRatios: import_zod.z.array(AspectRatioSchema).optional(),
|
|
1969
|
+
sizes: import_zod.z.array(ImageSizeSchema).optional(),
|
|
1970
|
+
resolutions: import_zod.z.array(VideoResolutionSchema).optional(),
|
|
1971
|
+
durations: import_zod.z.union([import_zod.z.looseObject({ min: import_zod.z.number(), max: import_zod.z.number() }), import_zod.z.array(import_zod.z.number())]).optional(),
|
|
1972
|
+
durationPresets: import_zod.z.array(import_zod.z.number()).optional(),
|
|
1973
|
+
qualityOptions: import_zod.z.array(import_zod.z.string()).optional(),
|
|
1974
|
+
exactSizes: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).optional(),
|
|
1975
|
+
references: ReferenceLimitsSchema.optional(),
|
|
1976
|
+
requires: import_zod.z.array(RequiredInputSchema).optional(),
|
|
1977
|
+
supports: import_zod.z.array(SupportedOptionSchema).optional(),
|
|
1978
|
+
ratioIgnoredWith: import_zod.z.array(import_zod.z.enum(["firstFrame", "sourceVideo"])).optional()
|
|
1979
|
+
});
|
|
1980
|
+
var MediaRefSchema = import_zod.z.union([
|
|
1981
|
+
import_zod.z.looseObject({ url: import_zod.z.string(), label: import_zod.z.string().optional() }),
|
|
1982
|
+
import_zod.z.looseObject({
|
|
1983
|
+
bytes: import_zod.z.instanceof(Uint8Array),
|
|
1984
|
+
mime: import_zod.z.string(),
|
|
1985
|
+
label: import_zod.z.string().optional()
|
|
1986
|
+
})
|
|
1987
|
+
]);
|
|
1988
|
+
var ImageSafetySettingSchema = import_zod.z.looseObject({ category: import_zod.z.string(), threshold: import_zod.z.string() });
|
|
1989
|
+
var UpscaleOptionsSchema = import_zod.z.looseObject({
|
|
1990
|
+
enhanceModel: import_zod.z.string().optional(),
|
|
1991
|
+
subjectDetection: import_zod.z.string().optional(),
|
|
1992
|
+
faceEnhancement: import_zod.z.boolean().optional(),
|
|
1993
|
+
faceEnhancementCreativity: import_zod.z.number().optional(),
|
|
1994
|
+
faceEnhancementStrength: import_zod.z.number().optional()
|
|
1995
|
+
});
|
|
1996
|
+
var DefaultsSchema = import_zod.z.looseObject({
|
|
1997
|
+
references: import_zod.z.array(MediaRefSchema).optional(),
|
|
1998
|
+
aspectRatio: AspectRatioSchema.optional(),
|
|
1999
|
+
size: ImageSizeSchema.optional(),
|
|
2000
|
+
exactSize: import_zod.z.string().optional(),
|
|
2001
|
+
quality: ImageQualitySchema.optional(),
|
|
2002
|
+
seed: import_zod.z.number().optional(),
|
|
2003
|
+
count: import_zod.z.number().optional(),
|
|
2004
|
+
outputFormat: OutputFormatSchema.optional(),
|
|
2005
|
+
scaleFactor: import_zod.z.number().optional(),
|
|
2006
|
+
safetySettings: import_zod.z.array(ImageSafetySettingSchema).optional(),
|
|
2007
|
+
temperature: import_zod.z.number().optional(),
|
|
2008
|
+
upscale: UpscaleOptionsSchema.optional(),
|
|
2009
|
+
firstFrame: MediaRefSchema.optional(),
|
|
2010
|
+
lastFrame: MediaRefSchema.optional(),
|
|
2011
|
+
sourceVideo: MediaRefSchema.optional(),
|
|
2012
|
+
referenceImages: import_zod.z.array(MediaRefSchema).optional(),
|
|
2013
|
+
referenceVideos: import_zod.z.array(MediaRefSchema).optional(),
|
|
2014
|
+
referenceAudios: import_zod.z.array(MediaRefSchema).optional(),
|
|
2015
|
+
resolution: VideoResolutionSchema.optional(),
|
|
2016
|
+
durationSeconds: import_zod.z.number().optional(),
|
|
2017
|
+
generateAudio: import_zod.z.boolean().optional(),
|
|
2018
|
+
negativePrompt: import_zod.z.string().optional(),
|
|
2019
|
+
cfgScale: import_zod.z.number().optional(),
|
|
2020
|
+
promptExpansion: import_zod.z.enum(["fast", "balanced", "quality"]).optional(),
|
|
2021
|
+
watermark: import_zod.z.boolean().optional(),
|
|
2022
|
+
safetyChecker: import_zod.z.boolean().optional(),
|
|
2023
|
+
mode: import_zod.z.enum(["standard", "pro"]).optional(),
|
|
2024
|
+
instrumental: import_zod.z.boolean().optional()
|
|
2025
|
+
});
|
|
2026
|
+
var CatalogDisplaySchema = import_zod.z.looseObject({
|
|
2027
|
+
provider: import_zod.z.string(),
|
|
2028
|
+
description: import_zod.z.string(),
|
|
2029
|
+
logo: import_zod.z.string().optional(),
|
|
2030
|
+
costTier: import_zod.z.union([import_zod.z.literal(1), import_zod.z.literal(2), import_zod.z.literal(3)]).optional(),
|
|
2031
|
+
recommended: import_zod.z.boolean().optional(),
|
|
2032
|
+
sortOrder: import_zod.z.number().optional(),
|
|
2033
|
+
chat: import_zod.z.looseObject({
|
|
2034
|
+
providerOptions: ProviderOptionsSchema.optional(),
|
|
2035
|
+
temperature: import_zod.z.number().optional()
|
|
2036
|
+
}).optional()
|
|
2037
|
+
});
|
|
2038
|
+
var CatalogCapabilitiesSchema = import_zod.z.looseObject({
|
|
2039
|
+
acceptsSourceVideo: import_zod.z.boolean().optional(),
|
|
2040
|
+
framesExcludeReferences: import_zod.z.boolean().optional(),
|
|
2041
|
+
reasoning: import_zod.z.boolean().optional(),
|
|
2042
|
+
vision: import_zod.z.boolean().optional(),
|
|
2043
|
+
contextWindow: import_zod.z.number().optional()
|
|
2044
|
+
});
|
|
2045
|
+
var CatalogModelSchemaBase = import_zod.z.looseObject({
|
|
2046
|
+
id: import_zod.z.string().min(1),
|
|
2047
|
+
aliases: import_zod.z.array(import_zod.z.string()).default([]),
|
|
2048
|
+
label: import_zod.z.string().min(1),
|
|
2049
|
+
type: ModelTypeSchema,
|
|
2050
|
+
adapter: AdapterSchema,
|
|
2051
|
+
providerModelId: import_zod.z.string().min(1),
|
|
2052
|
+
lifecycle: LifecycleSchema,
|
|
2053
|
+
replacedBy: import_zod.z.string().optional(),
|
|
2054
|
+
exposure: import_zod.z.enum(["catalog", "internal"]),
|
|
2055
|
+
constraints: ModelConstraintsSchema,
|
|
2056
|
+
defaults: DefaultsSchema,
|
|
2057
|
+
providerOptions: ProviderOptionsSchema.optional(),
|
|
2058
|
+
usage: import_zod.z.looseObject({
|
|
2059
|
+
unit: UsageUnitSchema,
|
|
2060
|
+
slug: import_zod.z.string().optional(),
|
|
2061
|
+
providerLabel: import_zod.z.string().optional()
|
|
2062
|
+
}),
|
|
2063
|
+
pricingKind: PricingKindSchema,
|
|
2064
|
+
display: CatalogDisplaySchema.optional(),
|
|
2065
|
+
capabilities: CatalogCapabilitiesSchema.optional()
|
|
2066
|
+
}).superRefine((row, ctx) => {
|
|
2067
|
+
if (row.lifecycle === "active" && !row.display) {
|
|
2068
|
+
ctx.addIssue({
|
|
2069
|
+
code: "custom",
|
|
2070
|
+
path: ["display"],
|
|
2071
|
+
message: "active rows need display"
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
if (row.lifecycle === "active" && row.type === "text" && !row.capabilities?.contextWindow) {
|
|
2075
|
+
ctx.addIssue({
|
|
2076
|
+
code: "custom",
|
|
2077
|
+
path: ["capabilities", "contextWindow"],
|
|
2078
|
+
message: "active text rows need contextWindow"
|
|
2079
|
+
});
|
|
2080
|
+
}
|
|
2081
|
+
if (row.replacedBy !== void 0 && row.replacedBy === row.id) {
|
|
2082
|
+
ctx.addIssue({
|
|
2083
|
+
code: "custom",
|
|
2084
|
+
path: ["replacedBy"],
|
|
2085
|
+
message: "replacedBy must not equal id"
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
var CatalogModelSchema = CatalogModelSchemaBase;
|
|
2090
|
+
var CatalogSchema = import_zod.z.array(CatalogModelSchemaBase).superRefine((rows, ctx) => {
|
|
2091
|
+
const seenIds = /* @__PURE__ */ new Map();
|
|
2092
|
+
rows.forEach((row, index) => {
|
|
2093
|
+
if (seenIds.has(row.id)) {
|
|
2094
|
+
ctx.addIssue({
|
|
2095
|
+
code: "custom",
|
|
2096
|
+
path: [index, "id"],
|
|
2097
|
+
message: `Duplicate model id "${row.id}"`
|
|
2098
|
+
});
|
|
2099
|
+
} else {
|
|
2100
|
+
seenIds.set(row.id, index);
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
const seenAliases = /* @__PURE__ */ new Map();
|
|
2104
|
+
rows.forEach((row, index) => {
|
|
2105
|
+
row.aliases.forEach((alias, aliasIndex) => {
|
|
2106
|
+
const path = [index, "aliases", aliasIndex];
|
|
2107
|
+
if (alias === row.id || seenIds.has(alias)) {
|
|
2108
|
+
ctx.addIssue({
|
|
2109
|
+
code: "custom",
|
|
2110
|
+
path,
|
|
2111
|
+
message: `Alias "${alias}" collides with a model id`
|
|
2112
|
+
});
|
|
2113
|
+
return;
|
|
2114
|
+
}
|
|
2115
|
+
if (seenAliases.has(alias)) {
|
|
2116
|
+
ctx.addIssue({
|
|
2117
|
+
code: "custom",
|
|
2118
|
+
path,
|
|
2119
|
+
message: `Duplicate alias "${alias}"`
|
|
2120
|
+
});
|
|
2121
|
+
} else {
|
|
2122
|
+
seenAliases.set(alias, index);
|
|
2123
|
+
}
|
|
2124
|
+
});
|
|
2125
|
+
});
|
|
2126
|
+
});
|
|
2127
|
+
|
|
2128
|
+
// src/catalog/live.ts
|
|
2129
|
+
var liveCatalog = new Catalog(MODELS);
|
|
2130
|
+
|
|
2131
|
+
// src/catalog/load.ts
|
|
2132
|
+
var memo;
|
|
2133
|
+
var timer;
|
|
2134
|
+
var revision;
|
|
2135
|
+
var origin = "snapshot";
|
|
2136
|
+
function rowCount() {
|
|
2137
|
+
return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
|
|
2138
|
+
}
|
|
2139
|
+
function authHeaders(auth) {
|
|
2140
|
+
return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
|
|
2141
|
+
}
|
|
2142
|
+
function describeError(err) {
|
|
2143
|
+
return err instanceof Error ? err.message : String(err);
|
|
2144
|
+
}
|
|
2145
|
+
function parseEnvelope(json) {
|
|
2146
|
+
if (typeof json !== "object" || json === null || !("rows" in json)) {
|
|
2147
|
+
throw new Error("invalid catalog response: missing rows");
|
|
2148
|
+
}
|
|
2149
|
+
const rows = CatalogSchema.parse(json.rows);
|
|
2150
|
+
const rev = json.revision;
|
|
2151
|
+
if (typeof rev === "string") return { rows, revision: rev };
|
|
2152
|
+
return { rows };
|
|
2153
|
+
}
|
|
2154
|
+
function logPrimed(logger, result) {
|
|
2155
|
+
const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
|
|
2156
|
+
logger.info("[modelkit] catalog primed", {
|
|
2157
|
+
origin: loggedOrigin,
|
|
2158
|
+
rowCount: loggedCount,
|
|
2159
|
+
revision: loggedRevision
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
async function fetchRemote(source, logger) {
|
|
2163
|
+
const fetchImpl = source.fetch ?? globalThis.fetch;
|
|
2164
|
+
const headers2 = authHeaders(source.auth);
|
|
2165
|
+
if (revision !== void 0) headers2["If-None-Match"] = `"${revision}"`;
|
|
2166
|
+
const res = await fetchImpl(`${source.baseUrl}/models/catalog`, {
|
|
2167
|
+
headers: headers2,
|
|
2168
|
+
signal: AbortSignal.timeout(source.timeoutMs ?? 1e4)
|
|
2169
|
+
});
|
|
2170
|
+
if (res.status === 304) return { kept: true };
|
|
2171
|
+
if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
|
|
2172
|
+
const json = await res.json();
|
|
2173
|
+
const { rows, revision: rev } = parseEnvelope(json);
|
|
2174
|
+
if (rev === void 0) return { rows, fromCache: false };
|
|
2175
|
+
return { rows, revision: rev, fromCache: false };
|
|
2176
|
+
}
|
|
2177
|
+
async function writeCache(source, logger, rows, rev) {
|
|
2178
|
+
if (!source.cache) return;
|
|
2179
|
+
try {
|
|
2180
|
+
await source.cache.set(JSON.stringify({ rows, revision: rev }));
|
|
2181
|
+
} catch (err) {
|
|
2182
|
+
logger.warn("[modelkit] catalog cache write failed", err);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
async function prime(source, logger) {
|
|
2186
|
+
try {
|
|
2187
|
+
const fetched = await fetchRemote(source, logger);
|
|
2188
|
+
if ("kept" in fetched) {
|
|
2189
|
+
const result2 = { origin, rowCount: rowCount() };
|
|
2190
|
+
if (revision !== void 0) result2.revision = revision;
|
|
2191
|
+
logPrimed(logger, result2);
|
|
2192
|
+
return result2;
|
|
2193
|
+
}
|
|
2194
|
+
liveCatalog.replace(fetched.rows);
|
|
2195
|
+
origin = "remote";
|
|
2196
|
+
revision = fetched.revision;
|
|
2197
|
+
await writeCache(source, logger, fetched.rows, fetched.revision);
|
|
2198
|
+
const result = { origin, rowCount: rowCount() };
|
|
2199
|
+
if (fetched.revision !== void 0) result.revision = fetched.revision;
|
|
2200
|
+
logPrimed(logger, result);
|
|
2201
|
+
return result;
|
|
2202
|
+
} catch (err) {
|
|
2203
|
+
logger.warn("[modelkit] catalog remote failed, trying cache", err);
|
|
2204
|
+
const error = describeError(err);
|
|
2205
|
+
try {
|
|
2206
|
+
const cached = await source.cache?.get();
|
|
2207
|
+
if (!cached) throw new Error("no cached catalog");
|
|
2208
|
+
const { rows, revision: rev } = parseEnvelope(JSON.parse(cached));
|
|
2209
|
+
liveCatalog.replace(rows);
|
|
2210
|
+
origin = "last-good";
|
|
2211
|
+
revision = rev;
|
|
2212
|
+
const result = { origin, rowCount: rowCount(), error };
|
|
2213
|
+
if (rev !== void 0) result.revision = rev;
|
|
2214
|
+
logPrimed(logger, result);
|
|
2215
|
+
return result;
|
|
2216
|
+
} catch (cacheErr) {
|
|
2217
|
+
logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
|
|
2218
|
+
liveCatalog.replace([...MODELS]);
|
|
2219
|
+
origin = "snapshot";
|
|
2220
|
+
revision = void 0;
|
|
2221
|
+
const result = {
|
|
2222
|
+
origin,
|
|
2223
|
+
rowCount: rowCount(),
|
|
2224
|
+
error
|
|
2225
|
+
};
|
|
2226
|
+
logPrimed(logger, result);
|
|
2227
|
+
return result;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
async function refresh(source, logger) {
|
|
2232
|
+
try {
|
|
2233
|
+
const fetched = await fetchRemote(source, logger);
|
|
2234
|
+
if ("kept" in fetched) return;
|
|
2235
|
+
liveCatalog.replace(fetched.rows);
|
|
2236
|
+
origin = "remote";
|
|
2237
|
+
revision = fetched.revision;
|
|
2238
|
+
await writeCache(source, logger, fetched.rows, fetched.revision);
|
|
2239
|
+
} catch (err) {
|
|
2240
|
+
logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
function primeCatalog(source) {
|
|
2244
|
+
if (memo) return memo;
|
|
2245
|
+
const logger = source.logger ?? console;
|
|
2246
|
+
memo = prime(source, logger).then((result) => {
|
|
2247
|
+
const ttlMs = source.ttlMs ?? 3e5;
|
|
2248
|
+
if (ttlMs > 0 && timer === void 0) {
|
|
2249
|
+
timer = setInterval(() => void refresh(source, logger), ttlMs);
|
|
2250
|
+
const maybeUnref = timer;
|
|
2251
|
+
maybeUnref.unref?.();
|
|
2252
|
+
}
|
|
2253
|
+
return result;
|
|
2254
|
+
});
|
|
2255
|
+
return memo;
|
|
2256
|
+
}
|
|
2257
|
+
function resetLiveCatalog() {
|
|
2258
|
+
if (timer !== void 0) {
|
|
2259
|
+
clearInterval(timer);
|
|
2260
|
+
timer = void 0;
|
|
2261
|
+
}
|
|
2262
|
+
memo = void 0;
|
|
2263
|
+
revision = void 0;
|
|
2264
|
+
origin = "snapshot";
|
|
2265
|
+
liveCatalog.replace([...MODELS]);
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2268
|
+
// src/catalog/file-cache.ts
|
|
2269
|
+
var import_promises = require("fs/promises");
|
|
2270
|
+
function fileCatalogCache(path) {
|
|
2271
|
+
return {
|
|
2272
|
+
async get() {
|
|
2273
|
+
try {
|
|
2274
|
+
return await (0, import_promises.readFile)(path, "utf8");
|
|
2275
|
+
} catch (err) {
|
|
2276
|
+
if (err?.code === "ENOENT") return null;
|
|
2277
|
+
throw err;
|
|
2278
|
+
}
|
|
2279
|
+
},
|
|
2280
|
+
async set(json) {
|
|
2281
|
+
const tmp = `${path}.tmp`;
|
|
2282
|
+
await (0, import_promises.writeFile)(tmp, json, "utf8");
|
|
2283
|
+
await (0, import_promises.rename)(tmp, path);
|
|
2284
|
+
}
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
|
|
1872
2288
|
// src/resolve-options.ts
|
|
1873
2289
|
var SIZE_ORDER = ["512", "1K", "2K", "4K"];
|
|
1874
2290
|
var RESOLUTION_ORDER = ["360p", "480p", "720p", "768p", "1080p", "2k", "4k"];
|
|
@@ -2294,21 +2710,21 @@ function keysFromEnv(env, prefix = "") {
|
|
|
2294
2710
|
}
|
|
2295
2711
|
|
|
2296
2712
|
// src/retry.ts
|
|
2297
|
-
var
|
|
2713
|
+
var import_zod3 = require("zod");
|
|
2298
2714
|
|
|
2299
2715
|
// src/json.ts
|
|
2300
|
-
var
|
|
2301
|
-
var JsonValueSchema =
|
|
2302
|
-
() =>
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2716
|
+
var import_zod2 = require("zod");
|
|
2717
|
+
var JsonValueSchema = import_zod2.z.lazy(
|
|
2718
|
+
() => import_zod2.z.union([
|
|
2719
|
+
import_zod2.z.string(),
|
|
2720
|
+
import_zod2.z.number(),
|
|
2721
|
+
import_zod2.z.boolean(),
|
|
2722
|
+
import_zod2.z.null(),
|
|
2723
|
+
import_zod2.z.array(JsonValueSchema),
|
|
2724
|
+
import_zod2.z.record(import_zod2.z.string(), JsonValueSchema)
|
|
2309
2725
|
])
|
|
2310
2726
|
);
|
|
2311
|
-
var JsonObjectSchema =
|
|
2727
|
+
var JsonObjectSchema = import_zod2.z.record(import_zod2.z.string(), JsonValueSchema);
|
|
2312
2728
|
async function readErrorBody(res) {
|
|
2313
2729
|
const text2 = await res.text().catch(() => "");
|
|
2314
2730
|
try {
|
|
@@ -2317,11 +2733,11 @@ async function readErrorBody(res) {
|
|
|
2317
2733
|
return text2;
|
|
2318
2734
|
}
|
|
2319
2735
|
}
|
|
2320
|
-
var thrownErrorSchema =
|
|
2321
|
-
message:
|
|
2322
|
-
status:
|
|
2323
|
-
statusCode:
|
|
2324
|
-
responseBody:
|
|
2736
|
+
var thrownErrorSchema = import_zod2.z.object({
|
|
2737
|
+
message: import_zod2.z.string().optional(),
|
|
2738
|
+
status: import_zod2.z.number().optional(),
|
|
2739
|
+
statusCode: import_zod2.z.number().optional(),
|
|
2740
|
+
responseBody: import_zod2.z.string().optional()
|
|
2325
2741
|
});
|
|
2326
2742
|
function describeThrown(cause) {
|
|
2327
2743
|
const parsed = thrownErrorSchema.safeParse(cause);
|
|
@@ -2332,7 +2748,7 @@ function describeThrown(cause) {
|
|
|
2332
2748
|
}
|
|
2333
2749
|
|
|
2334
2750
|
// src/retry.ts
|
|
2335
|
-
var textBody =
|
|
2751
|
+
var textBody = import_zod3.z.string();
|
|
2336
2752
|
function classifyHttpError(status, body, provider, model) {
|
|
2337
2753
|
const asText = textBody.safeParse(body);
|
|
2338
2754
|
const text2 = asText.success ? asText.data : JSON.stringify(body);
|
|
@@ -2389,12 +2805,12 @@ function sleep(ms, signal) {
|
|
|
2389
2805
|
rejectAborted();
|
|
2390
2806
|
return;
|
|
2391
2807
|
}
|
|
2392
|
-
let
|
|
2808
|
+
let timer2;
|
|
2393
2809
|
const onAbort = () => {
|
|
2394
|
-
if (
|
|
2810
|
+
if (timer2 !== void 0) clearTimeout(timer2);
|
|
2395
2811
|
rejectAborted();
|
|
2396
2812
|
};
|
|
2397
|
-
|
|
2813
|
+
timer2 = setTimeout(() => {
|
|
2398
2814
|
signal?.removeEventListener("abort", onAbort);
|
|
2399
2815
|
resolve();
|
|
2400
2816
|
}, ms);
|
|
@@ -2540,7 +2956,7 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
2540
2956
|
|
|
2541
2957
|
// src/client.ts
|
|
2542
2958
|
var import_ai2 = require("ai");
|
|
2543
|
-
var
|
|
2959
|
+
var import_zod5 = require("zod");
|
|
2544
2960
|
|
|
2545
2961
|
// src/adapters/media-ref.ts
|
|
2546
2962
|
function isUrlRef(ref) {
|
|
@@ -2625,7 +3041,7 @@ var import_perplexity = require("@ai-sdk/perplexity");
|
|
|
2625
3041
|
var import_xai = require("@ai-sdk/xai");
|
|
2626
3042
|
var import_deepseek = require("@ai-sdk/deepseek");
|
|
2627
3043
|
var import_moonshotai = require("@ai-sdk/moonshotai");
|
|
2628
|
-
var
|
|
3044
|
+
var import_zod4 = require("zod");
|
|
2629
3045
|
var TEXT_PROVIDERS = [
|
|
2630
3046
|
"openai",
|
|
2631
3047
|
"anthropic",
|
|
@@ -2636,7 +3052,7 @@ var TEXT_PROVIDERS = [
|
|
|
2636
3052
|
"moonshot",
|
|
2637
3053
|
"minimax"
|
|
2638
3054
|
];
|
|
2639
|
-
var textProviderSchema =
|
|
3055
|
+
var textProviderSchema = import_zod4.z.enum(TEXT_PROVIDERS);
|
|
2640
3056
|
function isTextProvider(value) {
|
|
2641
3057
|
return textProviderSchema.safeParse(value).success;
|
|
2642
3058
|
}
|
|
@@ -2806,10 +3222,10 @@ function textAbortOptions(sdk, context) {
|
|
|
2806
3222
|
if (abortSignal) return { abortSignal };
|
|
2807
3223
|
return {};
|
|
2808
3224
|
}
|
|
2809
|
-
var catalogId =
|
|
2810
|
-
var exactSize =
|
|
2811
|
-
var sdkRatio =
|
|
2812
|
-
var sizeTier =
|
|
3225
|
+
var catalogId = import_zod5.z.string();
|
|
3226
|
+
var exactSize = import_zod5.z.templateLiteral([import_zod5.z.number(), "x", import_zod5.z.number()]);
|
|
3227
|
+
var sdkRatio = import_zod5.z.templateLiteral([import_zod5.z.number(), ":", import_zod5.z.number()]);
|
|
3228
|
+
var sizeTier = import_zod5.z.enum(["512", "1K", "2K", "4K"]);
|
|
2813
3229
|
function isCatalogId(model) {
|
|
2814
3230
|
return catalogId.safeParse(model).success;
|
|
2815
3231
|
}
|
|
@@ -2876,7 +3292,7 @@ function logCoercions(logger, modelId, warnings) {
|
|
|
2876
3292
|
logger.warn(`[modelkit] ${modelId} request coerced`, { model: modelId, warnings });
|
|
2877
3293
|
}
|
|
2878
3294
|
function createModelKit(config, adapters) {
|
|
2879
|
-
const catalog =
|
|
3295
|
+
const catalog = config.catalogOverride ? liveCatalog.withOverrides(config.catalogOverride) : liveCatalog;
|
|
2880
3296
|
const logger = config.logger ?? console;
|
|
2881
3297
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
2882
3298
|
function context(model, call, warnings) {
|
|
@@ -3330,7 +3746,7 @@ function createModelKit(config, adapters) {
|
|
|
3330
3746
|
}
|
|
3331
3747
|
|
|
3332
3748
|
// src/adapters/ark.ts
|
|
3333
|
-
var
|
|
3749
|
+
var import_zod6 = require("zod");
|
|
3334
3750
|
var ARK_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
3335
3751
|
var SUBMIT_PATH = "/contents/generations/tasks";
|
|
3336
3752
|
var SEEDANCE_POLL_INTERVAL_MS = 15e3;
|
|
@@ -3407,7 +3823,7 @@ function arkKey(ctx) {
|
|
|
3407
3823
|
return key;
|
|
3408
3824
|
}
|
|
3409
3825
|
function throwArkError(status, body, model) {
|
|
3410
|
-
const parsed =
|
|
3826
|
+
const parsed = import_zod6.z.string().safeParse(body);
|
|
3411
3827
|
const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
|
|
3412
3828
|
if (/sensitive.?content|human.?face/i.test(text2)) {
|
|
3413
3829
|
const init = {
|
|
@@ -3445,13 +3861,13 @@ function sniffedImageMime(bytes) {
|
|
|
3445
3861
|
return "image/webp";
|
|
3446
3862
|
return "image/jpeg";
|
|
3447
3863
|
}
|
|
3448
|
-
var SeedreamImageSchema =
|
|
3449
|
-
url:
|
|
3450
|
-
b64_json:
|
|
3864
|
+
var SeedreamImageSchema = import_zod6.z.object({
|
|
3865
|
+
url: import_zod6.z.string().optional(),
|
|
3866
|
+
b64_json: import_zod6.z.string().optional()
|
|
3451
3867
|
});
|
|
3452
|
-
var SeedreamResponseSchema =
|
|
3453
|
-
data:
|
|
3454
|
-
error:
|
|
3868
|
+
var SeedreamResponseSchema = import_zod6.z.object({
|
|
3869
|
+
data: import_zod6.z.array(SeedreamImageSchema).optional(),
|
|
3870
|
+
error: import_zod6.z.object({ message: import_zod6.z.string().optional(), code: import_zod6.z.string().optional() }).optional()
|
|
3455
3871
|
});
|
|
3456
3872
|
function retryOptsFor(ctx, attempts = 3) {
|
|
3457
3873
|
const opts = { attempts };
|
|
@@ -3523,21 +3939,21 @@ async function generateSeedreamImage(req, ctx) {
|
|
|
3523
3939
|
if (req.quality !== void 0) usage2.imageQuality = req.quality;
|
|
3524
3940
|
return { images: [{ bytes, mime: sniffedImageMime(bytes) }], usage: usage2, raw: data };
|
|
3525
3941
|
}
|
|
3526
|
-
var SeedanceUsageSchema =
|
|
3527
|
-
total_tokens:
|
|
3528
|
-
completion_tokens:
|
|
3942
|
+
var SeedanceUsageSchema = import_zod6.z.object({
|
|
3943
|
+
total_tokens: import_zod6.z.number().optional(),
|
|
3944
|
+
completion_tokens: import_zod6.z.number().optional()
|
|
3529
3945
|
});
|
|
3530
|
-
var SeedanceResponseSchema =
|
|
3531
|
-
id:
|
|
3532
|
-
status:
|
|
3533
|
-
content:
|
|
3946
|
+
var SeedanceResponseSchema = import_zod6.z.object({
|
|
3947
|
+
id: import_zod6.z.string().optional(),
|
|
3948
|
+
status: import_zod6.z.string().optional(),
|
|
3949
|
+
content: import_zod6.z.object({ video_url: import_zod6.z.string().optional() }).optional(),
|
|
3534
3950
|
usage: SeedanceUsageSchema.optional(),
|
|
3535
|
-
duration:
|
|
3536
|
-
framespersecond:
|
|
3537
|
-
resolution:
|
|
3538
|
-
error:
|
|
3951
|
+
duration: import_zod6.z.number().optional(),
|
|
3952
|
+
framespersecond: import_zod6.z.number().optional(),
|
|
3953
|
+
resolution: import_zod6.z.string().optional(),
|
|
3954
|
+
error: import_zod6.z.union([import_zod6.z.string(), import_zod6.z.object({ message: import_zod6.z.string().optional() })]).optional()
|
|
3539
3955
|
});
|
|
3540
|
-
var SeedanceErrorMessageSchema =
|
|
3956
|
+
var SeedanceErrorMessageSchema = import_zod6.z.object({ message: import_zod6.z.string().optional() });
|
|
3541
3957
|
function seedanceUsage(ctx, req, duration) {
|
|
3542
3958
|
const usage2 = {
|
|
3543
3959
|
model: ctx.model.id,
|
|
@@ -3551,7 +3967,7 @@ function seedanceUsage(ctx, req, duration) {
|
|
|
3551
3967
|
return usage2;
|
|
3552
3968
|
}
|
|
3553
3969
|
function seedanceErrorMessage(error, status) {
|
|
3554
|
-
const asString =
|
|
3970
|
+
const asString = import_zod6.z.string().safeParse(error);
|
|
3555
3971
|
if (asString.success) return asString.data;
|
|
3556
3972
|
const asObject = SeedanceErrorMessageSchema.safeParse(error);
|
|
3557
3973
|
if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
|
|
@@ -3700,7 +4116,7 @@ async function generateSeedanceVideo(req, ctx) {
|
|
|
3700
4116
|
}
|
|
3701
4117
|
|
|
3702
4118
|
// src/adapters/fal.ts
|
|
3703
|
-
var
|
|
4119
|
+
var import_zod7 = require("zod");
|
|
3704
4120
|
var import_client = require("@fal-ai/client");
|
|
3705
4121
|
var MUSE_T2I_ENDPOINT = "meta/muse-image/text-to-image";
|
|
3706
4122
|
var MUSE_EDIT_ENDPOINT = "meta/muse-image/edit";
|
|
@@ -3708,7 +4124,7 @@ var KLING_O1_ENDPOINT = "fal-ai/kling-video/o1/video-to-video/reference";
|
|
|
3708
4124
|
var FAL_QUEUE_HOST = "https://queue.fal.run";
|
|
3709
4125
|
var PASSTHROUGH_POLL_MS = 2e3;
|
|
3710
4126
|
var PASSTHROUGH_MAX_WAIT_MS = 18e4;
|
|
3711
|
-
var falSubscribePayloadSchema =
|
|
4127
|
+
var falSubscribePayloadSchema = import_zod7.z.object({ data: JsonValueSchema });
|
|
3712
4128
|
function defaultCreateFalClient(opts) {
|
|
3713
4129
|
const client2 = (0, import_client.createFalClient)(opts);
|
|
3714
4130
|
return {
|
|
@@ -3758,7 +4174,7 @@ function createFalAdapter(deps = defaultDeps) {
|
|
|
3758
4174
|
};
|
|
3759
4175
|
}
|
|
3760
4176
|
var falAdapter = createFalAdapter();
|
|
3761
|
-
var falDetailSchema =
|
|
4177
|
+
var falDetailSchema = import_zod7.z.object({ detail: JsonValueSchema });
|
|
3762
4178
|
function liftDetail(body) {
|
|
3763
4179
|
const parsed = falDetailSchema.safeParse(body);
|
|
3764
4180
|
const detail = parsed.success ? parsed.data.detail : void 0;
|
|
@@ -3767,11 +4183,11 @@ function liftDetail(body) {
|
|
|
3767
4183
|
function falError(status, body, model) {
|
|
3768
4184
|
return classifyHttpError(status, liftDetail(body), "fal", model);
|
|
3769
4185
|
}
|
|
3770
|
-
var falSdkThrownSchema =
|
|
3771
|
-
status:
|
|
3772
|
-
statusCode:
|
|
4186
|
+
var falSdkThrownSchema = import_zod7.z.object({
|
|
4187
|
+
status: import_zod7.z.number().optional(),
|
|
4188
|
+
statusCode: import_zod7.z.number().optional(),
|
|
3773
4189
|
body: JsonValueSchema.optional(),
|
|
3774
|
-
message:
|
|
4190
|
+
message: import_zod7.z.string().optional()
|
|
3775
4191
|
});
|
|
3776
4192
|
function falSdkError(cause, model) {
|
|
3777
4193
|
const parsed = falSdkThrownSchema.safeParse(cause);
|
|
@@ -3815,12 +4231,12 @@ async function gatewayFetch(cfg, fetchImpl, targetUrl, init) {
|
|
|
3815
4231
|
if (init.body !== void 0) request.body = init.body;
|
|
3816
4232
|
return fetchImpl(cfg.baseUrl, request);
|
|
3817
4233
|
}
|
|
3818
|
-
var falQueueSubmitSchema =
|
|
3819
|
-
request_id:
|
|
3820
|
-
status_url:
|
|
3821
|
-
response_url:
|
|
4234
|
+
var falQueueSubmitSchema = import_zod7.z.object({
|
|
4235
|
+
request_id: import_zod7.z.string(),
|
|
4236
|
+
status_url: import_zod7.z.string(),
|
|
4237
|
+
response_url: import_zod7.z.string()
|
|
3822
4238
|
});
|
|
3823
|
-
var falQueueStatusSchema =
|
|
4239
|
+
var falQueueStatusSchema = import_zod7.z.object({ status: import_zod7.z.string() });
|
|
3824
4240
|
async function passthroughRequest(ctx, endpoint, input) {
|
|
3825
4241
|
const cfg = gatewayConfig(ctx);
|
|
3826
4242
|
const submitRes = await gatewayFetch(cfg, ctx.fetch, `${FAL_QUEUE_HOST}/${endpoint}`, {
|
|
@@ -3946,11 +4362,11 @@ async function decodeImage(ctx, url, contentType) {
|
|
|
3946
4362
|
const mime = res.headers.get("content-type") ?? contentType ?? "image/png";
|
|
3947
4363
|
return { bytes: new Uint8Array(await res.arrayBuffer()), mime };
|
|
3948
4364
|
}
|
|
3949
|
-
var museImageResultSchema =
|
|
3950
|
-
images:
|
|
3951
|
-
|
|
3952
|
-
url:
|
|
3953
|
-
content_type:
|
|
4365
|
+
var museImageResultSchema = import_zod7.z.object({
|
|
4366
|
+
images: import_zod7.z.array(
|
|
4367
|
+
import_zod7.z.object({
|
|
4368
|
+
url: import_zod7.z.string().optional(),
|
|
4369
|
+
content_type: import_zod7.z.string().nullable().optional()
|
|
3954
4370
|
})
|
|
3955
4371
|
).optional()
|
|
3956
4372
|
});
|
|
@@ -4042,8 +4458,8 @@ function klingO1Input(req) {
|
|
|
4042
4458
|
if (refs.length > 0) input.image_urls = refs;
|
|
4043
4459
|
return input;
|
|
4044
4460
|
}
|
|
4045
|
-
var falVideoResultSchema =
|
|
4046
|
-
video:
|
|
4461
|
+
var falVideoResultSchema = import_zod7.z.object({
|
|
4462
|
+
video: import_zod7.z.object({ url: import_zod7.z.string().optional() }).optional()
|
|
4047
4463
|
});
|
|
4048
4464
|
function extractVideoUrl(result, endpoint, model) {
|
|
4049
4465
|
const parsed = falVideoResultSchema.safeParse(result);
|
|
@@ -4233,11 +4649,11 @@ async function passthroughVideoJob(ctx, req, endpoint, input) {
|
|
|
4233
4649
|
}
|
|
4234
4650
|
|
|
4235
4651
|
// src/adapters/google-genai.ts
|
|
4236
|
-
var
|
|
4652
|
+
var import_zod9 = require("zod");
|
|
4237
4653
|
var import_genai = require("@google/genai");
|
|
4238
4654
|
|
|
4239
4655
|
// src/adapters/google-files.ts
|
|
4240
|
-
var
|
|
4656
|
+
var import_zod8 = require("zod");
|
|
4241
4657
|
var GOOGLE_FILES_BASE = "https://generativelanguage.googleapis.com";
|
|
4242
4658
|
var GOOGLE_FILES_POLL_INTERVAL_MS = 2e3;
|
|
4243
4659
|
var GOOGLE_FILES_POLL_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
@@ -4247,17 +4663,17 @@ var GENERIC_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
|
4247
4663
|
"binary/octet-stream",
|
|
4248
4664
|
"application/binary"
|
|
4249
4665
|
]);
|
|
4250
|
-
var uploadedFileSchema =
|
|
4251
|
-
file:
|
|
4252
|
-
uri:
|
|
4253
|
-
name:
|
|
4254
|
-
state:
|
|
4255
|
-
mimeType:
|
|
4666
|
+
var uploadedFileSchema = import_zod8.z.object({
|
|
4667
|
+
file: import_zod8.z.object({
|
|
4668
|
+
uri: import_zod8.z.string().optional(),
|
|
4669
|
+
name: import_zod8.z.string().optional(),
|
|
4670
|
+
state: import_zod8.z.string().optional(),
|
|
4671
|
+
mimeType: import_zod8.z.string().optional()
|
|
4256
4672
|
}).optional()
|
|
4257
4673
|
});
|
|
4258
|
-
var fileStateSchema =
|
|
4259
|
-
state:
|
|
4260
|
-
error:
|
|
4674
|
+
var fileStateSchema = import_zod8.z.object({
|
|
4675
|
+
state: import_zod8.z.string().optional(),
|
|
4676
|
+
error: import_zod8.z.object({ message: import_zod8.z.string().optional() }).optional()
|
|
4261
4677
|
});
|
|
4262
4678
|
function resolveMime(declared, fallback) {
|
|
4263
4679
|
const clean = declared?.split(";")[0]?.trim().toLowerCase();
|
|
@@ -4470,7 +4886,7 @@ var OMNI_POLL_INTERVAL_MS = 1e4;
|
|
|
4470
4886
|
var RESULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
|
|
4471
4887
|
var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
4472
4888
|
var MEDIA_PART_INLINE_LIMIT_BYTES = 20 * 1024 * 1024;
|
|
4473
|
-
var errorTextSchema =
|
|
4889
|
+
var errorTextSchema = import_zod9.z.string();
|
|
4474
4890
|
function createGoogleGenaiAdapter(deps = defaultDeps2) {
|
|
4475
4891
|
const { createGenAIClient } = deps;
|
|
4476
4892
|
return {
|
|
@@ -5028,15 +5444,15 @@ async function prepareGoogleMediaPart(ref, mediaType, ctx) {
|
|
|
5028
5444
|
// src/adapters/google-image.ts
|
|
5029
5445
|
var import_google2 = require("@ai-sdk/google");
|
|
5030
5446
|
var import_ai3 = require("ai");
|
|
5031
|
-
var
|
|
5447
|
+
var import_zod10 = require("zod");
|
|
5032
5448
|
var GEMINI_IMAGE_TIMEOUT_MS = 6e5;
|
|
5033
5449
|
var defaultGoogleImageDeps = {
|
|
5034
5450
|
createGoogleClient: (opts) => (0, import_google2.createGoogleGenerativeAI)(opts),
|
|
5035
5451
|
runTextGeneration: (opts) => (0, import_ai3.generateText)(opts)
|
|
5036
5452
|
};
|
|
5037
|
-
var causeChainNodeSchema =
|
|
5038
|
-
message:
|
|
5039
|
-
cause:
|
|
5453
|
+
var causeChainNodeSchema = import_zod10.z.object({
|
|
5454
|
+
message: import_zod10.z.string().optional(),
|
|
5455
|
+
cause: import_zod10.z.unknown().optional()
|
|
5040
5456
|
});
|
|
5041
5457
|
function extractBlockReason(cause) {
|
|
5042
5458
|
let current = cause;
|
|
@@ -5157,7 +5573,7 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
|
|
|
5157
5573
|
var googleImageAdapter = createGoogleImageAdapter();
|
|
5158
5574
|
|
|
5159
5575
|
// src/adapters/higgsfield.ts
|
|
5160
|
-
var
|
|
5576
|
+
var import_zod11 = require("zod");
|
|
5161
5577
|
|
|
5162
5578
|
// src/adapters/higgsfield-motions.ts
|
|
5163
5579
|
var MOTION_MAP = {
|
|
@@ -5345,14 +5761,14 @@ function videoUsage3(ctx, req, duration) {
|
|
|
5345
5761
|
if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
|
|
5346
5762
|
return event;
|
|
5347
5763
|
}
|
|
5348
|
-
var klingCreateSchema =
|
|
5349
|
-
var klingStatusSchema =
|
|
5350
|
-
status:
|
|
5351
|
-
video:
|
|
5764
|
+
var klingCreateSchema = import_zod11.z.object({ status_url: import_zod11.z.string() });
|
|
5765
|
+
var klingStatusSchema = import_zod11.z.object({
|
|
5766
|
+
status: import_zod11.z.string().optional(),
|
|
5767
|
+
video: import_zod11.z.object({ url: import_zod11.z.string().optional() }).optional(),
|
|
5352
5768
|
error: JsonValueSchema.optional()
|
|
5353
5769
|
});
|
|
5354
|
-
var errorMessageSchema =
|
|
5355
|
-
var textValueSchema =
|
|
5770
|
+
var errorMessageSchema = import_zod11.z.object({ message: import_zod11.z.string().optional() });
|
|
5771
|
+
var textValueSchema = import_zod11.z.string();
|
|
5356
5772
|
function klingErrorDetail(error) {
|
|
5357
5773
|
if (error === void 0) return "unknown_error";
|
|
5358
5774
|
const asText = textValueSchema.safeParse(error);
|
|
@@ -5486,8 +5902,8 @@ async function generateKlingVideo(req, ctx) {
|
|
|
5486
5902
|
}
|
|
5487
5903
|
};
|
|
5488
5904
|
}
|
|
5489
|
-
var dopMotionOptionsSchema =
|
|
5490
|
-
modelkit:
|
|
5905
|
+
var dopMotionOptionsSchema = import_zod11.z.object({
|
|
5906
|
+
modelkit: import_zod11.z.object({ motion: import_zod11.z.string().optional() }).optional()
|
|
5491
5907
|
});
|
|
5492
5908
|
function dopMotionId(ctx) {
|
|
5493
5909
|
const parsed = dopMotionOptionsSchema.safeParse(ctx.model.providerOptions);
|
|
@@ -5503,7 +5919,7 @@ function dopMotionId(ctx) {
|
|
|
5503
5919
|
});
|
|
5504
5920
|
return id;
|
|
5505
5921
|
}
|
|
5506
|
-
var jsonRecordSchema =
|
|
5922
|
+
var jsonRecordSchema = import_zod11.z.record(import_zod11.z.string(), JsonValueSchema);
|
|
5507
5923
|
var DOP_URL_KEYS = ["url", "video_url", "output_url", "result_url", "download_url"];
|
|
5508
5924
|
var DOP_NESTED_KEYS = ["video", "result", "results"];
|
|
5509
5925
|
function dopUrl(body) {
|
|
@@ -5531,8 +5947,8 @@ function dopUrl(body) {
|
|
|
5531
5947
|
}
|
|
5532
5948
|
return void 0;
|
|
5533
5949
|
}
|
|
5534
|
-
var dopCreateSchema =
|
|
5535
|
-
var dopStatusSchema =
|
|
5950
|
+
var dopCreateSchema = import_zod11.z.object({ id: import_zod11.z.string() });
|
|
5951
|
+
var dopStatusSchema = import_zod11.z.object({ status: import_zod11.z.string().optional() });
|
|
5536
5952
|
async function generateDopVideo(req, ctx) {
|
|
5537
5953
|
const firstFrame = req.firstFrame ? refToUrl(req.firstFrame) : void 0;
|
|
5538
5954
|
if (!firstFrame) {
|
|
@@ -5652,7 +6068,7 @@ var higgsfieldAdapter = {
|
|
|
5652
6068
|
|
|
5653
6069
|
// src/adapters/openai-image.ts
|
|
5654
6070
|
var import_openai2 = __toESM(require("openai"), 1);
|
|
5655
|
-
var
|
|
6071
|
+
var import_zod12 = require("zod");
|
|
5656
6072
|
var MAX_EDIT_REFERENCES = 16;
|
|
5657
6073
|
function aspectRatioToSize(ratio, tier) {
|
|
5658
6074
|
const TIER_LONG_EDGE = {
|
|
@@ -5735,9 +6151,9 @@ function toProviderError2(cause, ctx) {
|
|
|
5735
6151
|
ctx.model.id
|
|
5736
6152
|
);
|
|
5737
6153
|
}
|
|
5738
|
-
var openaiUsageSchema =
|
|
5739
|
-
input_tokens:
|
|
5740
|
-
output_tokens:
|
|
6154
|
+
var openaiUsageSchema = import_zod12.z.object({
|
|
6155
|
+
input_tokens: import_zod12.z.number().optional(),
|
|
6156
|
+
output_tokens: import_zod12.z.number().optional()
|
|
5741
6157
|
});
|
|
5742
6158
|
var openaiImageAdapter = {
|
|
5743
6159
|
id: "openai-image",
|
|
@@ -6127,7 +6543,7 @@ var prodiaAdapter = {
|
|
|
6127
6543
|
|
|
6128
6544
|
// src/adapters/replicate.ts
|
|
6129
6545
|
var import_replicate = __toESM(require("replicate"), 1);
|
|
6130
|
-
var
|
|
6546
|
+
var import_zod13 = require("zod");
|
|
6131
6547
|
var POLL_INTERVAL_MS = 1e3;
|
|
6132
6548
|
var POLL_TIMEOUT_MS = 15 * 6e4;
|
|
6133
6549
|
var defaultReplicateDeps = {
|
|
@@ -6163,8 +6579,8 @@ function route(providerModelId) {
|
|
|
6163
6579
|
if (!providerModelId.includes("/")) return { version: providerModelId };
|
|
6164
6580
|
return { model: providerModelId };
|
|
6165
6581
|
}
|
|
6166
|
-
var replicateResponseStatusSchema =
|
|
6167
|
-
response:
|
|
6582
|
+
var replicateResponseStatusSchema = import_zod13.z.object({
|
|
6583
|
+
response: import_zod13.z.object({ status: import_zod13.z.number() }).partial()
|
|
6168
6584
|
});
|
|
6169
6585
|
function replicateError(cause, ctx) {
|
|
6170
6586
|
if (isModelKitError(cause)) return cause;
|
|
@@ -6191,7 +6607,7 @@ function isUrlFn(value) {
|
|
|
6191
6607
|
function extractOutputUrl(output) {
|
|
6192
6608
|
const root = Array.isArray(output) ? output[0] : output;
|
|
6193
6609
|
if (root === void 0) throw noOutput();
|
|
6194
|
-
const asString =
|
|
6610
|
+
const asString = import_zod13.z.string().safeParse(root);
|
|
6195
6611
|
if (asString.success && asString.data) return asString.data;
|
|
6196
6612
|
if (root instanceof URL) return root.href;
|
|
6197
6613
|
if (isObjectOutput(root)) {
|
|
@@ -6200,15 +6616,15 @@ function extractOutputUrl(output) {
|
|
|
6200
6616
|
if (urlValue !== void 0 && isUrlFn(urlValue)) {
|
|
6201
6617
|
const called = urlValue();
|
|
6202
6618
|
if (called instanceof URL) return called.href;
|
|
6203
|
-
const calledString =
|
|
6619
|
+
const calledString = import_zod13.z.string().safeParse(called);
|
|
6204
6620
|
if (calledString.success && calledString.data) return calledString.data;
|
|
6205
6621
|
} else {
|
|
6206
|
-
const direct =
|
|
6622
|
+
const direct = import_zod13.z.string().safeParse(urlValue);
|
|
6207
6623
|
if (direct.success && direct.data) return direct.data;
|
|
6208
6624
|
}
|
|
6209
6625
|
}
|
|
6210
6626
|
if ("default" in root) {
|
|
6211
|
-
const fallback =
|
|
6627
|
+
const fallback = import_zod13.z.string().safeParse(root.default);
|
|
6212
6628
|
if (fallback.success && fallback.data) return fallback.data;
|
|
6213
6629
|
}
|
|
6214
6630
|
}
|
|
@@ -6269,7 +6685,7 @@ async function runPrediction(ctx, input, deps) {
|
|
|
6269
6685
|
}
|
|
6270
6686
|
return void 0;
|
|
6271
6687
|
}, pollOpts);
|
|
6272
|
-
const predictTime =
|
|
6688
|
+
const predictTime = import_zod13.z.number().safeParse(done.metrics?.predict_time);
|
|
6273
6689
|
if (done.output === void 0) throw noOutput();
|
|
6274
6690
|
return {
|
|
6275
6691
|
url: extractOutputUrl(done.output),
|
|
@@ -6612,7 +7028,7 @@ async function generateReplicateVideo(req, ctx, deps) {
|
|
|
6612
7028
|
throw replicateError(cause, ctx);
|
|
6613
7029
|
}
|
|
6614
7030
|
if (current.status === "succeeded") {
|
|
6615
|
-
const predictTime =
|
|
7031
|
+
const predictTime = import_zod13.z.number().safeParse(current.metrics?.predict_time);
|
|
6616
7032
|
if (current.output === void 0) throw noOutput();
|
|
6617
7033
|
return {
|
|
6618
7034
|
url: extractOutputUrl(current.output),
|
|
@@ -6744,7 +7160,7 @@ async function generateReplicateAudio(req, ctx, deps) {
|
|
|
6744
7160
|
// src/adapters/xai-video.ts
|
|
6745
7161
|
var import_ai4 = require("ai");
|
|
6746
7162
|
var import_xai2 = require("@ai-sdk/xai");
|
|
6747
|
-
var
|
|
7163
|
+
var import_zod14 = require("zod");
|
|
6748
7164
|
var POLL_INTERVAL_MS2 = 1e4;
|
|
6749
7165
|
var POLL_TIMEOUT_MS2 = 15 * 6e4;
|
|
6750
7166
|
var defaultXaiDeps = {
|
|
@@ -6757,8 +7173,8 @@ function createXaiVideoAdapter(deps = defaultXaiDeps) {
|
|
|
6757
7173
|
};
|
|
6758
7174
|
}
|
|
6759
7175
|
var xaiVideoAdapter = createXaiVideoAdapter();
|
|
6760
|
-
var xaiResponseStatusSchema =
|
|
6761
|
-
response:
|
|
7176
|
+
var xaiResponseStatusSchema = import_zod14.z.object({
|
|
7177
|
+
response: import_zod14.z.object({ status: import_zod14.z.number() }).partial()
|
|
6762
7178
|
});
|
|
6763
7179
|
function xaiError(cause, ctx) {
|
|
6764
7180
|
const info = describeThrown(cause);
|
|
@@ -6766,12 +7182,12 @@ function xaiError(cause, ctx) {
|
|
|
6766
7182
|
const status = info.status ?? (nested.success ? nested.data.response?.status : void 0);
|
|
6767
7183
|
return classifyThrown("xai-video", cause, ctx.model.id, { status, body: info.body });
|
|
6768
7184
|
}
|
|
6769
|
-
var xaiMetaSchema =
|
|
7185
|
+
var xaiMetaSchema = import_zod14.z.object({
|
|
6770
7186
|
videoUrl: JsonValueSchema.optional(),
|
|
6771
7187
|
costInUsdTicks: JsonValueSchema.optional(),
|
|
6772
7188
|
duration: JsonValueSchema.optional()
|
|
6773
7189
|
});
|
|
6774
|
-
var xaiProviderMetadataSchema =
|
|
7190
|
+
var xaiProviderMetadataSchema = import_zod14.z.object({ xai: xaiMetaSchema });
|
|
6775
7191
|
function metaOf(result) {
|
|
6776
7192
|
const parsed = xaiProviderMetadataSchema.partial().safeParse(result.providerMetadata);
|
|
6777
7193
|
if (!parsed.success) return {};
|
|
@@ -6878,7 +7294,7 @@ async function mapResult(ctx, req, result) {
|
|
|
6878
7294
|
};
|
|
6879
7295
|
}
|
|
6880
7296
|
const meta = metaOf(result);
|
|
6881
|
-
const videoUrl =
|
|
7297
|
+
const videoUrl = import_zod14.z.string().safeParse(meta.videoUrl);
|
|
6882
7298
|
if (videoUrl.success && videoUrl.data) {
|
|
6883
7299
|
const res = await ctx.fetch(videoUrl.data);
|
|
6884
7300
|
if (!res.ok) {
|
|
@@ -6901,7 +7317,7 @@ async function mapResult(ctx, req, result) {
|
|
|
6901
7317
|
});
|
|
6902
7318
|
}
|
|
6903
7319
|
function usage(ctx, req, meta) {
|
|
6904
|
-
const costTicks =
|
|
7320
|
+
const costTicks = import_zod14.z.number().safeParse(meta.costInUsdTicks);
|
|
6905
7321
|
const cost = costTicks.success ? costTicks.data / 1e10 : void 0;
|
|
6906
7322
|
const event = {
|
|
6907
7323
|
model: ctx.model.id,
|
|
@@ -6950,8 +7366,11 @@ var languageModel = (modelId, call) => createDefaultModelKit().languageModel(mod
|
|
|
6950
7366
|
var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
6951
7367
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6952
7368
|
0 && (module.exports = {
|
|
7369
|
+
ADAPTER_IDS,
|
|
6953
7370
|
ADAPTER_KEYS,
|
|
6954
7371
|
Catalog,
|
|
7372
|
+
CatalogModelSchema,
|
|
7373
|
+
CatalogSchema,
|
|
6955
7374
|
DEFAULT_ADAPTERS,
|
|
6956
7375
|
JsonObjectSchema,
|
|
6957
7376
|
JsonValueSchema,
|
|
@@ -6967,6 +7386,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
6967
7386
|
describeThrown,
|
|
6968
7387
|
experimental_generateImage,
|
|
6969
7388
|
falAdapter,
|
|
7389
|
+
fileCatalogCache,
|
|
6970
7390
|
generateAudio,
|
|
6971
7391
|
generateImage,
|
|
6972
7392
|
generateObject,
|
|
@@ -6978,15 +7398,18 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
6978
7398
|
isModelKitError,
|
|
6979
7399
|
keysFromEnv,
|
|
6980
7400
|
languageModel,
|
|
7401
|
+
liveCatalog,
|
|
6981
7402
|
mergeTextProviderOptions,
|
|
6982
7403
|
nearestAspectRatio,
|
|
6983
7404
|
openaiImageAdapter,
|
|
6984
7405
|
passthroughTextModel,
|
|
6985
7406
|
pollUntil,
|
|
6986
7407
|
prepareMediaPart,
|
|
7408
|
+
primeCatalog,
|
|
6987
7409
|
prodiaAdapter,
|
|
6988
7410
|
readErrorBody,
|
|
6989
7411
|
replicateAdapter,
|
|
7412
|
+
resetLiveCatalog,
|
|
6990
7413
|
resolveAudioOptions,
|
|
6991
7414
|
resolveImageOptions,
|
|
6992
7415
|
resolveKeys,
|