@shop-os/modelkit 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -213,6 +213,12 @@ var GEMINI_RATIOS = [
213
213
  "adaptive"
214
214
  ];
215
215
  function geminiImage(id, label, aliases, sizes, display, exposure, references) {
216
+ const constraints = {
217
+ aspectRatios: [...GEMINI_RATIOS],
218
+ sizes,
219
+ supports: ["safetySettings", "temperature"]
220
+ };
221
+ if (references !== void 0) constraints.references = references;
216
222
  const model = {
217
223
  id,
218
224
  aliases,
@@ -222,12 +228,7 @@ function geminiImage(id, label, aliases, sizes, display, exposure, references) {
222
228
  providerModelId: id,
223
229
  lifecycle: "active",
224
230
  exposure,
225
- constraints: {
226
- aspectRatios: [...GEMINI_RATIOS],
227
- sizes,
228
- supports: ["safetySettings", "temperature"],
229
- ...references ? { references } : {}
230
- },
231
+ constraints,
231
232
  defaults: { size: "1K", aspectRatio: "1:1" },
232
233
  usage: { ...IMAGE_USAGE, slug: "gemini" },
233
234
  pricingKind: "image_size",
@@ -2128,31 +2129,31 @@ var liveState = store[KEY] ??= {
2128
2129
  var liveCatalog = liveState.catalog;
2129
2130
 
2130
2131
  // src/catalog/load.ts
2132
+ var import_zod2 = require("zod");
2131
2133
  function rowCount() {
2132
2134
  return liveCatalog.list({ lifecycle: ["active", "deprecated", "retired"] }).length;
2133
2135
  }
2134
2136
  function authHeaders(auth) {
2135
2137
  return "bearer" in auth ? { Authorization: `Bearer ${auth.bearer}` } : { "x-api-key": auth.apiKey };
2136
2138
  }
2139
+ var EnvelopeSchema = import_zod2.z.object({
2140
+ rows: CatalogSchema,
2141
+ revision: import_zod2.z.string().optional()
2142
+ });
2143
+ function toEnvelope(data) {
2144
+ if (data.rows.length === 0) throw new Error("invalid catalog response: no rows");
2145
+ const envelope = { rows: data.rows };
2146
+ if (data.revision !== void 0) envelope.revision = data.revision;
2147
+ return envelope;
2148
+ }
2137
2149
  function describeError(err) {
2138
2150
  return err instanceof Error ? err.message : String(err);
2139
2151
  }
2140
- function parseEnvelope(json) {
2141
- if (typeof json !== "object" || json === null || !("rows" in json)) {
2142
- throw new Error("invalid catalog response: missing rows");
2143
- }
2144
- const rows = CatalogSchema.parse(json.rows);
2145
- const rev = json.revision;
2146
- if (typeof rev === "string") return { rows, revision: rev };
2147
- return { rows };
2148
- }
2149
2152
  function logPrimed(logger, result) {
2150
- const { origin: loggedOrigin, rowCount: loggedCount, revision: loggedRevision } = result;
2151
- logger.info("[modelkit] catalog primed", {
2152
- origin: loggedOrigin,
2153
- rowCount: loggedCount,
2154
- revision: loggedRevision
2155
- });
2153
+ const revision = result.revision === void 0 ? "" : ` revision=${result.revision}`;
2154
+ logger.info(
2155
+ `[modelkit] catalog primed origin=${result.origin} rowCount=${result.rowCount}${revision}`
2156
+ );
2156
2157
  }
2157
2158
  async function fetchRemote(source, logger) {
2158
2159
  const fetchImpl = source.fetch ?? globalThis.fetch;
@@ -2165,7 +2166,9 @@ async function fetchRemote(source, logger) {
2165
2166
  if (res.status === 304) return { kept: true };
2166
2167
  if (!res.ok) throw new Error(`catalog fetch failed with status ${res.status}`);
2167
2168
  const json = await res.json();
2168
- const { rows, revision: rev } = parseEnvelope(json);
2169
+ const parsed = EnvelopeSchema.safeParse(json);
2170
+ if (!parsed.success) throw new Error("invalid catalog response: missing rows");
2171
+ const { rows, revision: rev } = toEnvelope(parsed.data);
2169
2172
  if (rev === void 0) return { rows, fromCache: false };
2170
2173
  return { rows, revision: rev, fromCache: false };
2171
2174
  }
@@ -2174,7 +2177,7 @@ async function writeCache(source, logger, rows, rev) {
2174
2177
  try {
2175
2178
  await source.cache.set(JSON.stringify({ rows, revision: rev }));
2176
2179
  } catch (err) {
2177
- logger.warn("[modelkit] catalog cache write failed", err);
2180
+ logger.warn(`[modelkit] catalog cache write failed: ${describeError(err)}`);
2178
2181
  }
2179
2182
  }
2180
2183
  async function prime(source, logger) {
@@ -2195,12 +2198,14 @@ async function prime(source, logger) {
2195
2198
  logPrimed(logger, result);
2196
2199
  return result;
2197
2200
  } catch (err) {
2198
- logger.warn("[modelkit] catalog remote failed, trying cache", err);
2201
+ logger.warn(`[modelkit] catalog remote failed, trying cache: ${describeError(err)}`);
2199
2202
  const error = describeError(err);
2200
2203
  try {
2201
2204
  const cached = await source.cache?.get();
2202
2205
  if (!cached) throw new Error("no cached catalog");
2203
- const { rows, revision: rev } = parseEnvelope(JSON.parse(cached));
2206
+ const cachedParsed = EnvelopeSchema.safeParse(JSON.parse(cached));
2207
+ if (!cachedParsed.success) throw new Error("invalid catalog response: missing rows");
2208
+ const { rows, revision: rev } = toEnvelope(cachedParsed.data);
2204
2209
  liveCatalog.replace(rows);
2205
2210
  liveState.origin = "last-good";
2206
2211
  liveState.revision = rev;
@@ -2213,7 +2218,9 @@ async function prime(source, logger) {
2213
2218
  logPrimed(logger, result);
2214
2219
  return result;
2215
2220
  } catch (cacheErr) {
2216
- logger.warn("[modelkit] catalog cache failed, using snapshot", cacheErr);
2221
+ logger.warn(
2222
+ `[modelkit] catalog cache failed, using snapshot: ${describeError(cacheErr)}`
2223
+ );
2217
2224
  liveCatalog.replace([...MODELS]);
2218
2225
  liveState.origin = "snapshot";
2219
2226
  liveState.revision = void 0;
@@ -2236,23 +2243,24 @@ async function refresh(source, logger) {
2236
2243
  liveState.revision = fetched.revision;
2237
2244
  await writeCache(source, logger, fetched.rows, fetched.revision);
2238
2245
  } catch (err) {
2239
- logger.warn("[modelkit] catalog refresh failed, keeping current rows", err);
2246
+ logger.warn(
2247
+ `[modelkit] catalog refresh failed, keeping current rows: ${describeError(err)}`
2248
+ );
2240
2249
  }
2241
2250
  }
2242
2251
  function primeCatalog(source) {
2243
- const memo = liveState.memo;
2244
- if (memo) return memo;
2252
+ if (liveState.memo) return liveState.memo;
2245
2253
  const logger = source.logger ?? console;
2246
- liveState.memo = prime(source, logger).then((result) => {
2254
+ const pending = prime(source, logger).then((result) => {
2247
2255
  const ttlMs = source.ttlMs ?? 3e5;
2248
2256
  if (ttlMs > 0 && liveState.timer === void 0) {
2249
2257
  liveState.timer = setInterval(() => void refresh(source, logger), ttlMs);
2250
- const maybeUnref = liveState.timer;
2251
- maybeUnref.unref?.();
2258
+ liveState.timer.unref?.();
2252
2259
  }
2253
2260
  return result;
2254
2261
  });
2255
- return liveState.memo;
2262
+ liveState.memo = pending;
2263
+ return pending;
2256
2264
  }
2257
2265
  function resetLiveCatalog() {
2258
2266
  if (liveState.timer !== void 0) {
@@ -2267,13 +2275,16 @@ function resetLiveCatalog() {
2267
2275
 
2268
2276
  // src/catalog/file-cache.ts
2269
2277
  var import_promises = require("fs/promises");
2278
+ function isErrnoException(err) {
2279
+ return err instanceof Error && "code" in err;
2280
+ }
2270
2281
  function fileCatalogCache(path) {
2271
2282
  return {
2272
2283
  async get() {
2273
2284
  try {
2274
2285
  return await (0, import_promises.readFile)(path, "utf8");
2275
2286
  } catch (err) {
2276
- if (err?.code === "ENOENT") return null;
2287
+ if (isErrnoException(err) && err.code === "ENOENT") return null;
2277
2288
  throw err;
2278
2289
  }
2279
2290
  },
@@ -2710,21 +2721,21 @@ function keysFromEnv(env, prefix = "") {
2710
2721
  }
2711
2722
 
2712
2723
  // src/retry.ts
2713
- var import_zod3 = require("zod");
2724
+ var import_zod4 = require("zod");
2714
2725
 
2715
2726
  // src/json.ts
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)
2727
+ var import_zod3 = require("zod");
2728
+ var JsonValueSchema = import_zod3.z.lazy(
2729
+ () => import_zod3.z.union([
2730
+ import_zod3.z.string(),
2731
+ import_zod3.z.number(),
2732
+ import_zod3.z.boolean(),
2733
+ import_zod3.z.null(),
2734
+ import_zod3.z.array(JsonValueSchema),
2735
+ import_zod3.z.record(import_zod3.z.string(), JsonValueSchema)
2725
2736
  ])
2726
2737
  );
2727
- var JsonObjectSchema = import_zod2.z.record(import_zod2.z.string(), JsonValueSchema);
2738
+ var JsonObjectSchema = import_zod3.z.record(import_zod3.z.string(), JsonValueSchema);
2728
2739
  async function readErrorBody(res) {
2729
2740
  const text2 = await res.text().catch(() => "");
2730
2741
  try {
@@ -2733,11 +2744,11 @@ async function readErrorBody(res) {
2733
2744
  return text2;
2734
2745
  }
2735
2746
  }
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()
2747
+ var thrownErrorSchema = import_zod3.z.object({
2748
+ message: import_zod3.z.string().optional(),
2749
+ status: import_zod3.z.number().optional(),
2750
+ statusCode: import_zod3.z.number().optional(),
2751
+ responseBody: import_zod3.z.string().optional()
2741
2752
  });
2742
2753
  function describeThrown(cause) {
2743
2754
  const parsed = thrownErrorSchema.safeParse(cause);
@@ -2748,7 +2759,7 @@ function describeThrown(cause) {
2748
2759
  }
2749
2760
 
2750
2761
  // src/retry.ts
2751
- var textBody = import_zod3.z.string();
2762
+ var textBody = import_zod4.z.string();
2752
2763
  function classifyHttpError(status, body, provider, model) {
2753
2764
  const asText = textBody.safeParse(body);
2754
2765
  const text2 = asText.success ? asText.data : JSON.stringify(body);
@@ -2956,7 +2967,7 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
2956
2967
 
2957
2968
  // src/client.ts
2958
2969
  var import_ai2 = require("ai");
2959
- var import_zod5 = require("zod");
2970
+ var import_zod6 = require("zod");
2960
2971
 
2961
2972
  // src/adapters/media-ref.ts
2962
2973
  function isUrlRef(ref) {
@@ -3041,7 +3052,7 @@ var import_perplexity = require("@ai-sdk/perplexity");
3041
3052
  var import_xai = require("@ai-sdk/xai");
3042
3053
  var import_deepseek = require("@ai-sdk/deepseek");
3043
3054
  var import_moonshotai = require("@ai-sdk/moonshotai");
3044
- var import_zod4 = require("zod");
3055
+ var import_zod5 = require("zod");
3045
3056
  var TEXT_PROVIDERS = [
3046
3057
  "openai",
3047
3058
  "anthropic",
@@ -3052,7 +3063,7 @@ var TEXT_PROVIDERS = [
3052
3063
  "moonshot",
3053
3064
  "minimax"
3054
3065
  ];
3055
- var textProviderSchema = import_zod4.z.enum(TEXT_PROVIDERS);
3066
+ var textProviderSchema = import_zod5.z.enum(TEXT_PROVIDERS);
3056
3067
  function isTextProvider(value) {
3057
3068
  return textProviderSchema.safeParse(value).success;
3058
3069
  }
@@ -3222,10 +3233,10 @@ function textAbortOptions(sdk, context) {
3222
3233
  if (abortSignal) return { abortSignal };
3223
3234
  return {};
3224
3235
  }
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"]);
3236
+ var catalogId = import_zod6.z.string();
3237
+ var exactSize = import_zod6.z.templateLiteral([import_zod6.z.number(), "x", import_zod6.z.number()]);
3238
+ var sdkRatio = import_zod6.z.templateLiteral([import_zod6.z.number(), ":", import_zod6.z.number()]);
3239
+ var sizeTier = import_zod6.z.enum(["512", "1K", "2K", "4K"]);
3229
3240
  function isCatalogId(model) {
3230
3241
  return catalogId.safeParse(model).success;
3231
3242
  }
@@ -3746,7 +3757,7 @@ function createModelKit(config, adapters) {
3746
3757
  }
3747
3758
 
3748
3759
  // src/adapters/ark.ts
3749
- var import_zod6 = require("zod");
3760
+ var import_zod7 = require("zod");
3750
3761
  var ARK_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
3751
3762
  var SUBMIT_PATH = "/contents/generations/tasks";
3752
3763
  var SEEDANCE_POLL_INTERVAL_MS = 15e3;
@@ -3823,7 +3834,7 @@ function arkKey(ctx) {
3823
3834
  return key;
3824
3835
  }
3825
3836
  function throwArkError(status, body, model) {
3826
- const parsed = import_zod6.z.string().safeParse(body);
3837
+ const parsed = import_zod7.z.string().safeParse(body);
3827
3838
  const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
3828
3839
  if (/sensitive.?content|human.?face/i.test(text2)) {
3829
3840
  const init = {
@@ -3861,13 +3872,13 @@ function sniffedImageMime(bytes) {
3861
3872
  return "image/webp";
3862
3873
  return "image/jpeg";
3863
3874
  }
3864
- var SeedreamImageSchema = import_zod6.z.object({
3865
- url: import_zod6.z.string().optional(),
3866
- b64_json: import_zod6.z.string().optional()
3875
+ var SeedreamImageSchema = import_zod7.z.object({
3876
+ url: import_zod7.z.string().optional(),
3877
+ b64_json: import_zod7.z.string().optional()
3867
3878
  });
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()
3879
+ var SeedreamResponseSchema = import_zod7.z.object({
3880
+ data: import_zod7.z.array(SeedreamImageSchema).optional(),
3881
+ error: import_zod7.z.object({ message: import_zod7.z.string().optional(), code: import_zod7.z.string().optional() }).optional()
3871
3882
  });
3872
3883
  function retryOptsFor(ctx, attempts = 3) {
3873
3884
  const opts = { attempts };
@@ -3951,21 +3962,21 @@ async function generateSeedreamImage(req, ctx) {
3951
3962
  if (req.quality !== void 0) usage2.imageQuality = req.quality;
3952
3963
  return { images: [{ bytes, mime: sniffedImageMime(bytes) }], usage: usage2, raw: data };
3953
3964
  }
3954
- var SeedanceUsageSchema = import_zod6.z.object({
3955
- total_tokens: import_zod6.z.number().optional(),
3956
- completion_tokens: import_zod6.z.number().optional()
3965
+ var SeedanceUsageSchema = import_zod7.z.object({
3966
+ total_tokens: import_zod7.z.number().optional(),
3967
+ completion_tokens: import_zod7.z.number().optional()
3957
3968
  });
3958
- var SeedanceResponseSchema = import_zod6.z.object({
3959
- id: import_zod6.z.string().optional(),
3960
- status: import_zod6.z.string().optional(),
3961
- content: import_zod6.z.object({ video_url: import_zod6.z.string().optional() }).optional(),
3969
+ var SeedanceResponseSchema = import_zod7.z.object({
3970
+ id: import_zod7.z.string().optional(),
3971
+ status: import_zod7.z.string().optional(),
3972
+ content: import_zod7.z.object({ video_url: import_zod7.z.string().optional() }).optional(),
3962
3973
  usage: SeedanceUsageSchema.optional(),
3963
- duration: import_zod6.z.number().optional(),
3964
- framespersecond: import_zod6.z.number().optional(),
3965
- resolution: import_zod6.z.string().optional(),
3966
- error: import_zod6.z.union([import_zod6.z.string(), import_zod6.z.object({ message: import_zod6.z.string().optional() })]).optional()
3974
+ duration: import_zod7.z.number().optional(),
3975
+ framespersecond: import_zod7.z.number().optional(),
3976
+ resolution: import_zod7.z.string().optional(),
3977
+ error: import_zod7.z.union([import_zod7.z.string(), import_zod7.z.object({ message: import_zod7.z.string().optional() })]).optional()
3967
3978
  });
3968
- var SeedanceErrorMessageSchema = import_zod6.z.object({ message: import_zod6.z.string().optional() });
3979
+ var SeedanceErrorMessageSchema = import_zod7.z.object({ message: import_zod7.z.string().optional() });
3969
3980
  function seedanceUsage(ctx, req, duration) {
3970
3981
  const usage2 = {
3971
3982
  model: ctx.model.id,
@@ -3979,7 +3990,7 @@ function seedanceUsage(ctx, req, duration) {
3979
3990
  return usage2;
3980
3991
  }
3981
3992
  function seedanceErrorMessage(error, status) {
3982
- const asString = import_zod6.z.string().safeParse(error);
3993
+ const asString = import_zod7.z.string().safeParse(error);
3983
3994
  if (asString.success) return asString.data;
3984
3995
  const asObject = SeedanceErrorMessageSchema.safeParse(error);
3985
3996
  if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
@@ -4128,7 +4139,7 @@ async function generateSeedanceVideo(req, ctx) {
4128
4139
  }
4129
4140
 
4130
4141
  // src/adapters/fal.ts
4131
- var import_zod7 = require("zod");
4142
+ var import_zod8 = require("zod");
4132
4143
  var import_client = require("@fal-ai/client");
4133
4144
  var MUSE_T2I_ENDPOINT = "meta/muse-image/text-to-image";
4134
4145
  var MUSE_EDIT_ENDPOINT = "meta/muse-image/edit";
@@ -4136,7 +4147,7 @@ var KLING_O1_ENDPOINT = "fal-ai/kling-video/o1/video-to-video/reference";
4136
4147
  var FAL_QUEUE_HOST = "https://queue.fal.run";
4137
4148
  var PASSTHROUGH_POLL_MS = 2e3;
4138
4149
  var PASSTHROUGH_MAX_WAIT_MS = 18e4;
4139
- var falSubscribePayloadSchema = import_zod7.z.object({ data: JsonValueSchema });
4150
+ var falSubscribePayloadSchema = import_zod8.z.object({ data: JsonValueSchema });
4140
4151
  function defaultCreateFalClient(opts) {
4141
4152
  const client2 = (0, import_client.createFalClient)(opts);
4142
4153
  return {
@@ -4186,7 +4197,7 @@ function createFalAdapter(deps = defaultDeps) {
4186
4197
  };
4187
4198
  }
4188
4199
  var falAdapter = createFalAdapter();
4189
- var falDetailSchema = import_zod7.z.object({ detail: JsonValueSchema });
4200
+ var falDetailSchema = import_zod8.z.object({ detail: JsonValueSchema });
4190
4201
  function liftDetail(body) {
4191
4202
  const parsed = falDetailSchema.safeParse(body);
4192
4203
  const detail = parsed.success ? parsed.data.detail : void 0;
@@ -4195,11 +4206,11 @@ function liftDetail(body) {
4195
4206
  function falError(status, body, model) {
4196
4207
  return classifyHttpError(status, liftDetail(body), "fal", model);
4197
4208
  }
4198
- var falSdkThrownSchema = import_zod7.z.object({
4199
- status: import_zod7.z.number().optional(),
4200
- statusCode: import_zod7.z.number().optional(),
4209
+ var falSdkThrownSchema = import_zod8.z.object({
4210
+ status: import_zod8.z.number().optional(),
4211
+ statusCode: import_zod8.z.number().optional(),
4201
4212
  body: JsonValueSchema.optional(),
4202
- message: import_zod7.z.string().optional()
4213
+ message: import_zod8.z.string().optional()
4203
4214
  });
4204
4215
  function falSdkError(cause, model) {
4205
4216
  const parsed = falSdkThrownSchema.safeParse(cause);
@@ -4243,12 +4254,12 @@ async function gatewayFetch(cfg, fetchImpl, targetUrl, init) {
4243
4254
  if (init.body !== void 0) request.body = init.body;
4244
4255
  return fetchImpl(cfg.baseUrl, request);
4245
4256
  }
4246
- var falQueueSubmitSchema = import_zod7.z.object({
4247
- request_id: import_zod7.z.string(),
4248
- status_url: import_zod7.z.string(),
4249
- response_url: import_zod7.z.string()
4257
+ var falQueueSubmitSchema = import_zod8.z.object({
4258
+ request_id: import_zod8.z.string(),
4259
+ status_url: import_zod8.z.string(),
4260
+ response_url: import_zod8.z.string()
4250
4261
  });
4251
- var falQueueStatusSchema = import_zod7.z.object({ status: import_zod7.z.string() });
4262
+ var falQueueStatusSchema = import_zod8.z.object({ status: import_zod8.z.string() });
4252
4263
  async function passthroughRequest(ctx, endpoint, input) {
4253
4264
  const cfg = gatewayConfig(ctx);
4254
4265
  const submitRes = await gatewayFetch(cfg, ctx.fetch, `${FAL_QUEUE_HOST}/${endpoint}`, {
@@ -4374,11 +4385,11 @@ async function decodeImage(ctx, url, contentType) {
4374
4385
  const mime = res.headers.get("content-type") ?? contentType ?? "image/png";
4375
4386
  return { bytes: new Uint8Array(await res.arrayBuffer()), mime };
4376
4387
  }
4377
- var museImageResultSchema = import_zod7.z.object({
4378
- images: import_zod7.z.array(
4379
- import_zod7.z.object({
4380
- url: import_zod7.z.string().optional(),
4381
- content_type: import_zod7.z.string().nullable().optional()
4388
+ var museImageResultSchema = import_zod8.z.object({
4389
+ images: import_zod8.z.array(
4390
+ import_zod8.z.object({
4391
+ url: import_zod8.z.string().optional(),
4392
+ content_type: import_zod8.z.string().nullable().optional()
4382
4393
  })
4383
4394
  ).optional()
4384
4395
  });
@@ -4470,8 +4481,8 @@ function klingO1Input(req) {
4470
4481
  if (refs.length > 0) input.image_urls = refs;
4471
4482
  return input;
4472
4483
  }
4473
- var falVideoResultSchema = import_zod7.z.object({
4474
- video: import_zod7.z.object({ url: import_zod7.z.string().optional() }).optional()
4484
+ var falVideoResultSchema = import_zod8.z.object({
4485
+ video: import_zod8.z.object({ url: import_zod8.z.string().optional() }).optional()
4475
4486
  });
4476
4487
  function extractVideoUrl(result, endpoint, model) {
4477
4488
  const parsed = falVideoResultSchema.safeParse(result);
@@ -4661,11 +4672,11 @@ async function passthroughVideoJob(ctx, req, endpoint, input) {
4661
4672
  }
4662
4673
 
4663
4674
  // src/adapters/google-genai.ts
4664
- var import_zod9 = require("zod");
4675
+ var import_zod10 = require("zod");
4665
4676
  var import_genai = require("@google/genai");
4666
4677
 
4667
4678
  // src/adapters/google-files.ts
4668
- var import_zod8 = require("zod");
4679
+ var import_zod9 = require("zod");
4669
4680
  var GOOGLE_FILES_BASE = "https://generativelanguage.googleapis.com";
4670
4681
  var GOOGLE_FILES_POLL_INTERVAL_MS = 2e3;
4671
4682
  var GOOGLE_FILES_POLL_TIMEOUT_MS = 5 * 60 * 1e3;
@@ -4675,17 +4686,17 @@ var GENERIC_MEDIA_TYPES = /* @__PURE__ */ new Set([
4675
4686
  "binary/octet-stream",
4676
4687
  "application/binary"
4677
4688
  ]);
4678
- var uploadedFileSchema = import_zod8.z.object({
4679
- file: import_zod8.z.object({
4680
- uri: import_zod8.z.string().optional(),
4681
- name: import_zod8.z.string().optional(),
4682
- state: import_zod8.z.string().optional(),
4683
- mimeType: import_zod8.z.string().optional()
4689
+ var uploadedFileSchema = import_zod9.z.object({
4690
+ file: import_zod9.z.object({
4691
+ uri: import_zod9.z.string().optional(),
4692
+ name: import_zod9.z.string().optional(),
4693
+ state: import_zod9.z.string().optional(),
4694
+ mimeType: import_zod9.z.string().optional()
4684
4695
  }).optional()
4685
4696
  });
4686
- var fileStateSchema = import_zod8.z.object({
4687
- state: import_zod8.z.string().optional(),
4688
- error: import_zod8.z.object({ message: import_zod8.z.string().optional() }).optional()
4697
+ var fileStateSchema = import_zod9.z.object({
4698
+ state: import_zod9.z.string().optional(),
4699
+ error: import_zod9.z.object({ message: import_zod9.z.string().optional() }).optional()
4689
4700
  });
4690
4701
  function resolveMime(declared, fallback) {
4691
4702
  const clean = declared?.split(";")[0]?.trim().toLowerCase();
@@ -4898,7 +4909,7 @@ var OMNI_POLL_INTERVAL_MS = 1e4;
4898
4909
  var RESULT_TIMEOUT_MS2 = 15 * 60 * 1e3;
4899
4910
  var OMNI_INLINE_LIMIT_BYTES = 4 * 1024 * 1024;
4900
4911
  var MEDIA_PART_INLINE_LIMIT_BYTES = 20 * 1024 * 1024;
4901
- var errorTextSchema = import_zod9.z.string();
4912
+ var errorTextSchema = import_zod10.z.string();
4902
4913
  function createGoogleGenaiAdapter(deps = defaultDeps2) {
4903
4914
  const { createGenAIClient } = deps;
4904
4915
  return {
@@ -5457,15 +5468,15 @@ async function prepareGoogleMediaPart(ref, mediaType, ctx) {
5457
5468
  // src/adapters/google-image.ts
5458
5469
  var import_google2 = require("@ai-sdk/google");
5459
5470
  var import_ai3 = require("ai");
5460
- var import_zod10 = require("zod");
5471
+ var import_zod11 = require("zod");
5461
5472
  var GEMINI_IMAGE_TIMEOUT_MS = 6e5;
5462
5473
  var defaultGoogleImageDeps = {
5463
5474
  createGoogleClient: (opts) => (0, import_google2.createGoogleGenerativeAI)(opts),
5464
5475
  runTextGeneration: (opts) => (0, import_ai3.generateText)(opts)
5465
5476
  };
5466
- var causeChainNodeSchema = import_zod10.z.object({
5467
- message: import_zod10.z.string().optional(),
5468
- cause: import_zod10.z.unknown().optional()
5477
+ var causeChainNodeSchema = import_zod11.z.object({
5478
+ message: import_zod11.z.string().optional(),
5479
+ cause: import_zod11.z.unknown().optional()
5469
5480
  });
5470
5481
  function extractBlockReason(cause) {
5471
5482
  let current = cause;
@@ -5586,7 +5597,7 @@ function createGoogleImageAdapter(deps = defaultGoogleImageDeps) {
5586
5597
  var googleImageAdapter = createGoogleImageAdapter();
5587
5598
 
5588
5599
  // src/adapters/higgsfield.ts
5589
- var import_zod11 = require("zod");
5600
+ var import_zod12 = require("zod");
5590
5601
 
5591
5602
  // src/adapters/higgsfield-motions.ts
5592
5603
  var MOTION_MAP = {
@@ -5774,14 +5785,14 @@ function videoUsage3(ctx, req, duration) {
5774
5785
  if (req.durationSeconds !== void 0) event.durationSeconds = req.durationSeconds;
5775
5786
  return event;
5776
5787
  }
5777
- var klingCreateSchema = import_zod11.z.object({ status_url: import_zod11.z.string() });
5778
- var klingStatusSchema = import_zod11.z.object({
5779
- status: import_zod11.z.string().optional(),
5780
- video: import_zod11.z.object({ url: import_zod11.z.string().optional() }).optional(),
5788
+ var klingCreateSchema = import_zod12.z.object({ status_url: import_zod12.z.string() });
5789
+ var klingStatusSchema = import_zod12.z.object({
5790
+ status: import_zod12.z.string().optional(),
5791
+ video: import_zod12.z.object({ url: import_zod12.z.string().optional() }).optional(),
5781
5792
  error: JsonValueSchema.optional()
5782
5793
  });
5783
- var errorMessageSchema = import_zod11.z.object({ message: import_zod11.z.string().optional() });
5784
- var textValueSchema = import_zod11.z.string();
5794
+ var errorMessageSchema = import_zod12.z.object({ message: import_zod12.z.string().optional() });
5795
+ var textValueSchema = import_zod12.z.string();
5785
5796
  function klingErrorDetail(error) {
5786
5797
  if (error === void 0) return "unknown_error";
5787
5798
  const asText = textValueSchema.safeParse(error);
@@ -5915,8 +5926,8 @@ async function generateKlingVideo(req, ctx) {
5915
5926
  }
5916
5927
  };
5917
5928
  }
5918
- var dopMotionOptionsSchema = import_zod11.z.object({
5919
- modelkit: import_zod11.z.object({ motion: import_zod11.z.string().optional() }).optional()
5929
+ var dopMotionOptionsSchema = import_zod12.z.object({
5930
+ modelkit: import_zod12.z.object({ motion: import_zod12.z.string().optional() }).optional()
5920
5931
  });
5921
5932
  function dopMotionId(ctx) {
5922
5933
  const parsed = dopMotionOptionsSchema.safeParse(ctx.model.providerOptions);
@@ -5932,7 +5943,7 @@ function dopMotionId(ctx) {
5932
5943
  });
5933
5944
  return id;
5934
5945
  }
5935
- var jsonRecordSchema = import_zod11.z.record(import_zod11.z.string(), JsonValueSchema);
5946
+ var jsonRecordSchema = import_zod12.z.record(import_zod12.z.string(), JsonValueSchema);
5936
5947
  var DOP_URL_KEYS = ["url", "video_url", "output_url", "result_url", "download_url"];
5937
5948
  var DOP_NESTED_KEYS = ["video", "result", "results"];
5938
5949
  function dopUrl(body) {
@@ -5960,8 +5971,8 @@ function dopUrl(body) {
5960
5971
  }
5961
5972
  return void 0;
5962
5973
  }
5963
- var dopCreateSchema = import_zod11.z.object({ id: import_zod11.z.string() });
5964
- var dopStatusSchema = import_zod11.z.object({ status: import_zod11.z.string().optional() });
5974
+ var dopCreateSchema = import_zod12.z.object({ id: import_zod12.z.string() });
5975
+ var dopStatusSchema = import_zod12.z.object({ status: import_zod12.z.string().optional() });
5965
5976
  async function generateDopVideo(req, ctx) {
5966
5977
  const firstFrame = req.firstFrame ? refToUrl(req.firstFrame) : void 0;
5967
5978
  if (!firstFrame) {
@@ -6081,7 +6092,7 @@ var higgsfieldAdapter = {
6081
6092
 
6082
6093
  // src/adapters/openai-image.ts
6083
6094
  var import_openai2 = __toESM(require("openai"), 1);
6084
- var import_zod12 = require("zod");
6095
+ var import_zod13 = require("zod");
6085
6096
  var MAX_EDIT_REFERENCES = 16;
6086
6097
  function aspectRatioToSize(ratio, tier) {
6087
6098
  const TIER_LONG_EDGE = {
@@ -6164,9 +6175,9 @@ function toProviderError2(cause, ctx) {
6164
6175
  ctx.model.id
6165
6176
  );
6166
6177
  }
6167
- var openaiUsageSchema = import_zod12.z.object({
6168
- input_tokens: import_zod12.z.number().optional(),
6169
- output_tokens: import_zod12.z.number().optional()
6178
+ var openaiUsageSchema = import_zod13.z.object({
6179
+ input_tokens: import_zod13.z.number().optional(),
6180
+ output_tokens: import_zod13.z.number().optional()
6170
6181
  });
6171
6182
  var openaiImageAdapter = {
6172
6183
  id: "openai-image",
@@ -6573,7 +6584,7 @@ var prodiaAdapter = {
6573
6584
 
6574
6585
  // src/adapters/replicate.ts
6575
6586
  var import_replicate = __toESM(require("replicate"), 1);
6576
- var import_zod13 = require("zod");
6587
+ var import_zod14 = require("zod");
6577
6588
  var POLL_INTERVAL_MS = 1e3;
6578
6589
  var POLL_TIMEOUT_MS = 15 * 6e4;
6579
6590
  var defaultReplicateDeps = {
@@ -6609,8 +6620,8 @@ function route(providerModelId) {
6609
6620
  if (!providerModelId.includes("/")) return { version: providerModelId };
6610
6621
  return { model: providerModelId };
6611
6622
  }
6612
- var replicateResponseStatusSchema = import_zod13.z.object({
6613
- response: import_zod13.z.object({ status: import_zod13.z.number() }).partial()
6623
+ var replicateResponseStatusSchema = import_zod14.z.object({
6624
+ response: import_zod14.z.object({ status: import_zod14.z.number() }).partial()
6614
6625
  });
6615
6626
  function replicateError(cause, ctx) {
6616
6627
  if (isModelKitError(cause)) return cause;
@@ -6637,7 +6648,7 @@ function isUrlFn(value) {
6637
6648
  function extractOutputUrl(output) {
6638
6649
  const root = Array.isArray(output) ? output[0] : output;
6639
6650
  if (root === void 0) throw noOutput();
6640
- const asString = import_zod13.z.string().safeParse(root);
6651
+ const asString = import_zod14.z.string().safeParse(root);
6641
6652
  if (asString.success && asString.data) return asString.data;
6642
6653
  if (root instanceof URL) return root.href;
6643
6654
  if (isObjectOutput(root)) {
@@ -6646,15 +6657,15 @@ function extractOutputUrl(output) {
6646
6657
  if (urlValue !== void 0 && isUrlFn(urlValue)) {
6647
6658
  const called = urlValue();
6648
6659
  if (called instanceof URL) return called.href;
6649
- const calledString = import_zod13.z.string().safeParse(called);
6660
+ const calledString = import_zod14.z.string().safeParse(called);
6650
6661
  if (calledString.success && calledString.data) return calledString.data;
6651
6662
  } else {
6652
- const direct = import_zod13.z.string().safeParse(urlValue);
6663
+ const direct = import_zod14.z.string().safeParse(urlValue);
6653
6664
  if (direct.success && direct.data) return direct.data;
6654
6665
  }
6655
6666
  }
6656
6667
  if ("default" in root) {
6657
- const fallback = import_zod13.z.string().safeParse(root.default);
6668
+ const fallback = import_zod14.z.string().safeParse(root.default);
6658
6669
  if (fallback.success && fallback.data) return fallback.data;
6659
6670
  }
6660
6671
  }
@@ -6715,7 +6726,7 @@ async function runPrediction(ctx, input, deps) {
6715
6726
  }
6716
6727
  return void 0;
6717
6728
  }, pollOpts);
6718
- const predictTime = import_zod13.z.number().safeParse(done.metrics?.predict_time);
6729
+ const predictTime = import_zod14.z.number().safeParse(done.metrics?.predict_time);
6719
6730
  if (done.output === void 0) throw noOutput();
6720
6731
  return {
6721
6732
  url: extractOutputUrl(done.output),
@@ -7058,7 +7069,7 @@ async function generateReplicateVideo(req, ctx, deps) {
7058
7069
  throw replicateError(cause, ctx);
7059
7070
  }
7060
7071
  if (current.status === "succeeded") {
7061
- const predictTime = import_zod13.z.number().safeParse(current.metrics?.predict_time);
7072
+ const predictTime = import_zod14.z.number().safeParse(current.metrics?.predict_time);
7062
7073
  if (current.output === void 0) throw noOutput();
7063
7074
  return {
7064
7075
  url: extractOutputUrl(current.output),
@@ -7190,7 +7201,7 @@ async function generateReplicateAudio(req, ctx, deps) {
7190
7201
  // src/adapters/xai-video.ts
7191
7202
  var import_ai4 = require("ai");
7192
7203
  var import_xai2 = require("@ai-sdk/xai");
7193
- var import_zod14 = require("zod");
7204
+ var import_zod15 = require("zod");
7194
7205
  var POLL_INTERVAL_MS2 = 1e4;
7195
7206
  var POLL_TIMEOUT_MS2 = 15 * 6e4;
7196
7207
  var defaultXaiDeps = {
@@ -7203,8 +7214,8 @@ function createXaiVideoAdapter(deps = defaultXaiDeps) {
7203
7214
  };
7204
7215
  }
7205
7216
  var xaiVideoAdapter = createXaiVideoAdapter();
7206
- var xaiResponseStatusSchema = import_zod14.z.object({
7207
- response: import_zod14.z.object({ status: import_zod14.z.number() }).partial()
7217
+ var xaiResponseStatusSchema = import_zod15.z.object({
7218
+ response: import_zod15.z.object({ status: import_zod15.z.number() }).partial()
7208
7219
  });
7209
7220
  function xaiError(cause, ctx) {
7210
7221
  const info = describeThrown(cause);
@@ -7212,12 +7223,12 @@ function xaiError(cause, ctx) {
7212
7223
  const status = info.status ?? (nested.success ? nested.data.response?.status : void 0);
7213
7224
  return classifyThrown("xai-video", cause, ctx.model.id, { status, body: info.body });
7214
7225
  }
7215
- var xaiMetaSchema = import_zod14.z.object({
7226
+ var xaiMetaSchema = import_zod15.z.object({
7216
7227
  videoUrl: JsonValueSchema.optional(),
7217
7228
  costInUsdTicks: JsonValueSchema.optional(),
7218
7229
  duration: JsonValueSchema.optional()
7219
7230
  });
7220
- var xaiProviderMetadataSchema = import_zod14.z.object({ xai: xaiMetaSchema });
7231
+ var xaiProviderMetadataSchema = import_zod15.z.object({ xai: xaiMetaSchema });
7221
7232
  function metaOf(result) {
7222
7233
  const parsed = xaiProviderMetadataSchema.partial().safeParse(result.providerMetadata);
7223
7234
  if (!parsed.success) return {};
@@ -7324,7 +7335,7 @@ async function mapResult(ctx, req, result) {
7324
7335
  };
7325
7336
  }
7326
7337
  const meta = metaOf(result);
7327
- const videoUrl = import_zod14.z.string().safeParse(meta.videoUrl);
7338
+ const videoUrl = import_zod15.z.string().safeParse(meta.videoUrl);
7328
7339
  if (videoUrl.success && videoUrl.data) {
7329
7340
  const res = await ctx.fetch(videoUrl.data);
7330
7341
  if (!res.ok) {
@@ -7347,7 +7358,7 @@ async function mapResult(ctx, req, result) {
7347
7358
  });
7348
7359
  }
7349
7360
  function usage(ctx, req, meta) {
7350
- const costTicks = import_zod14.z.number().safeParse(meta.costInUsdTicks);
7361
+ const costTicks = import_zod15.z.number().safeParse(meta.costInUsdTicks);
7351
7362
  const cost = costTicks.success ? costTicks.data / 1e10 : void 0;
7352
7363
  const event = {
7353
7364
  model: ctx.model.id,