@shop-os/modelkit 0.2.2 → 0.2.3

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