@shop-os/modelkit 0.2.25 → 0.2.27

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
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  CatalogSchema: () => CatalogSchema,
41
41
  DEFAULT_ADAPTERS: () => DEFAULT_ADAPTERS,
42
42
  ExposureSchema: () => ExposureSchema,
43
+ IMAGE_INPUT_SPEC_KEYS: () => IMAGE_INPUT_SPEC_KEYS,
43
44
  INPUT_SPEC_SUPPORTS_KEYS: () => INPUT_SPEC_SUPPORTS_KEYS,
44
45
  InputSpecSchema: () => InputSpecSchema,
45
46
  JsonObjectSchema: () => JsonObjectSchema,
@@ -2204,6 +2205,14 @@ var VIDEO_INPUT_SPEC_KEYS = [
2204
2205
  "promptExpansion",
2205
2206
  "referenceImages"
2206
2207
  ];
2208
+ var IMAGE_INPUT_SPEC_KEYS = [
2209
+ "prompt",
2210
+ "references",
2211
+ "aspectRatio",
2212
+ "size",
2213
+ "outputFormat",
2214
+ "seed"
2215
+ ];
2207
2216
  var AUDIO_INPUT_SPEC_KEYS = [
2208
2217
  "prompt",
2209
2218
  "durationSeconds",
@@ -2220,14 +2229,22 @@ var INPUT_SPEC_SUPPORTS_KEYS = [
2220
2229
  "generateAudio",
2221
2230
  "cfgScale",
2222
2231
  "promptExpansion",
2232
+ "outputFormat",
2223
2233
  "instrumental"
2224
2234
  ];
2225
2235
  var VIDEO_KEY_SET = new Set(VIDEO_INPUT_SPEC_KEYS);
2236
+ var IMAGE_KEY_SET = new Set(IMAGE_INPUT_SPEC_KEYS);
2226
2237
  var AUDIO_KEY_SET = new Set(AUDIO_INPUT_SPEC_KEYS);
2227
2238
  var ALL_KEY_SET = /* @__PURE__ */ new Set([
2228
2239
  ...VIDEO_INPUT_SPEC_KEYS,
2240
+ ...IMAGE_INPUT_SPEC_KEYS,
2229
2241
  ...AUDIO_INPUT_SPEC_KEYS
2230
2242
  ]);
2243
+ var ALLOWED_KEYS_BY_TYPE = /* @__PURE__ */ new Map([
2244
+ ["video", VIDEO_KEY_SET],
2245
+ ["image", IMAGE_KEY_SET],
2246
+ ["audio", AUDIO_KEY_SET]
2247
+ ]);
2231
2248
  var ProviderScalarSchema = import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number(), import_zod2.z.boolean()]);
2232
2249
  var FieldsSchema = import_zod2.z.record(import_zod2.z.string(), import_zod2.z.string().min(1)).superRefine((fields, ctx) => {
2233
2250
  const keys = Object.keys(fields);
@@ -2296,13 +2313,13 @@ function validateInputSpec(raw, row) {
2296
2313
  };
2297
2314
  }
2298
2315
  const issues = [];
2299
- if (row.type !== "video" && row.type !== "audio") {
2316
+ const allowed = ALLOWED_KEYS_BY_TYPE.get(row.type);
2317
+ if (allowed === void 0) {
2300
2318
  issues.push({
2301
2319
  path: [],
2302
2320
  message: `inputSpec is not supported for "${row.type}" rows`
2303
2321
  });
2304
2322
  } else {
2305
- const allowed = row.type === "video" ? VIDEO_KEY_SET : AUDIO_KEY_SET;
2306
2323
  for (const key of Object.keys(spec.fields)) {
2307
2324
  if (!allowed.has(key)) {
2308
2325
  issues.push({
@@ -6844,6 +6861,12 @@ async function generateReplicateImage(req, ctx, deps) {
6844
6861
  break;
6845
6862
  }
6846
6863
  default: {
6864
+ const specResult = replicateInputSpec(req, ctx);
6865
+ if (specResult.kind === "invalid") throw replicateInvalidSpec(ctx, specResult.issues);
6866
+ if (specResult.kind === "ok") {
6867
+ input = specResult.input;
6868
+ break;
6869
+ }
6847
6870
  const first = (req.references ?? [])[0];
6848
6871
  const imageInput = { prompt: req.prompt };
6849
6872
  if (first) imageInput.image = refToUrl(first);
@@ -8315,11 +8338,17 @@ function textUsageProvider(model, transport) {
8315
8338
  }
8316
8339
 
8317
8340
  // src/client.ts
8318
- function requiredKeys(model, config, transport) {
8319
- if (model.adapter === "fal" && config.routing?.fal === "cloudflare-passthrough")
8320
- return ["cloudflare"];
8341
+ function routingFor(config, tier) {
8342
+ const routing = config.routing ?? {};
8343
+ if (tier !== "sloosh") return routing;
8344
+ const direct = { ...routing };
8345
+ if (direct.text === "cloudflare") direct.text = "direct";
8346
+ if (direct.fal === "cloudflare-passthrough") direct.fal = "direct";
8347
+ return direct;
8348
+ }
8349
+ function requiredKeys(model, routing, transport) {
8350
+ if (model.adapter === "fal" && routing.fal === "cloudflare-passthrough") return ["cloudflare"];
8321
8351
  if (model.adapter === "ai-sdk-text") {
8322
- const routing = config.routing ?? {};
8323
8352
  const names = [textKeyName(model, transport)];
8324
8353
  if (textUsesCloudflareGateway(model, routing, transport)) names.push("cloudflare");
8325
8354
  return names;
@@ -8423,7 +8452,8 @@ function createModelKit(config, adapters) {
8423
8452
  model: model.id
8424
8453
  });
8425
8454
  const transport = resolveAnthropicTransport(model, config, call.tier, warnOnce);
8426
- const names = requiredKeys(model, config, transport);
8455
+ const routing = routingFor(config, call.tier);
8456
+ const names = requiredKeys(model, routing, transport);
8427
8457
  if (call.tier === "enterprise") {
8428
8458
  const missing = missingEnterpriseKeys(config, names);
8429
8459
  if (missing.length > 0)
@@ -8436,7 +8466,7 @@ function createModelKit(config, adapters) {
8436
8466
  const ctx = {
8437
8467
  model,
8438
8468
  keys,
8439
- routing: config.routing ?? {},
8469
+ routing,
8440
8470
  fetch: fetchImpl,
8441
8471
  logger,
8442
8472
  call,
@@ -8918,6 +8948,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
8918
8948
  CatalogSchema,
8919
8949
  DEFAULT_ADAPTERS,
8920
8950
  ExposureSchema,
8951
+ IMAGE_INPUT_SPEC_KEYS,
8921
8952
  INPUT_SPEC_SUPPORTS_KEYS,
8922
8953
  InputSpecSchema,
8923
8954
  JsonObjectSchema,