@broberg/ai-sdk 0.10.0 → 0.10.1

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.d.ts CHANGED
@@ -936,6 +936,7 @@ declare const imageInputSchema: z.ZodObject<{
936
936
  path: string;
937
937
  scale?: number | undefined;
938
938
  }[] | undefined;
939
+ lora?: string | undefined;
939
940
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
940
941
  override?: {
941
942
  provider?: string | undefined;
@@ -950,7 +951,6 @@ declare const imageInputSchema: z.ZodObject<{
950
951
  labels?: Record<string, string> | undefined;
951
952
  width?: number | undefined;
952
953
  height?: number | undefined;
953
- lora?: string | undefined;
954
954
  }, {
955
955
  prompt: string;
956
956
  purpose?: string | undefined;
@@ -958,6 +958,7 @@ declare const imageInputSchema: z.ZodObject<{
958
958
  path: string;
959
959
  scale?: number | undefined;
960
960
  }[] | undefined;
961
+ lora?: string | undefined;
961
962
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
962
963
  override?: {
963
964
  provider?: string | undefined;
@@ -972,7 +973,6 @@ declare const imageInputSchema: z.ZodObject<{
972
973
  labels?: Record<string, string> | undefined;
973
974
  width?: number | undefined;
974
975
  height?: number | undefined;
975
- lora?: string | undefined;
976
976
  }>;
977
977
  declare const trainStyleInputSchema: z.ZodObject<{
978
978
  tier: z.ZodOptional<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "video", "embedding"]>>;
@@ -1680,8 +1680,8 @@ declare const falStubAdapter: ProviderAdapter;
1680
1680
  * wires the live adapters. */
1681
1681
  declare const stubProviders: Record<string, ProviderAdapter>;
1682
1682
 
1683
- declare const VERSION: "0.10.0";
1684
- declare const SDK_TAG: "@broberg/ai-sdk@0.10.0";
1683
+ declare const VERSION: "0.10.1";
1684
+ declare const SDK_TAG: "@broberg/ai-sdk@0.10.1";
1685
1685
 
1686
1686
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
1687
1687
  * per-call override. Model IDs are current at scaffold time; callers pin their
package/dist/index.js CHANGED
@@ -1346,8 +1346,14 @@ function falAdapter(config = {}) {
1346
1346
  body,
1347
1347
  config.trainTimeoutMs ?? 6e5
1348
1348
  );
1349
- const loraUrl = result.diffusers_lora_file?.url;
1350
- if (!loraUrl) throw new Error("fal trainStyle: no diffusers_lora_file.url in result");
1349
+ const { loraUrl, configUrl } = extractTrainedFiles(result);
1350
+ if (!loraUrl) {
1351
+ throw new Error(
1352
+ `fal trainStyle: no LoRA file url in result \u2014 fal returned keys [${Object.keys(
1353
+ result ?? {}
1354
+ ).join(", ")}]: ${JSON.stringify(result).slice(0, 800)}`
1355
+ );
1356
+ }
1351
1357
  const usage = freshUsage({
1352
1358
  provider: "fal",
1353
1359
  model: req.spec.model,
@@ -1357,7 +1363,7 @@ function falAdapter(config = {}) {
1357
1363
  outputTokens: 0
1358
1364
  });
1359
1365
  usage.costUsd = config.pricePerTraining ?? FAL_TRAIN_PRICE_ESTIMATE;
1360
- return { loraUrl, configUrl: result.config_file?.url ?? "", usage };
1366
+ return { loraUrl, configUrl: configUrl ?? "", usage };
1361
1367
  }
1362
1368
  async function resolveImagesDataUrl(images) {
1363
1369
  if (typeof images === "string") return images;
@@ -1416,10 +1422,45 @@ function falAdapter(config = {}) {
1416
1422
  await sleep(pollIntervalMs);
1417
1423
  }
1418
1424
  const resultRes = await doFetch(responseUrl, { headers });
1425
+ if (!resultRes.ok) {
1426
+ throw new Error(
1427
+ `fal queue result ${resultRes.status}: ${(await resultRes.text().catch(() => "")).slice(0, 300)}`
1428
+ );
1429
+ }
1419
1430
  return resultRes.json();
1420
1431
  }
1421
1432
  return { name: "fal", image, trainStyle };
1422
1433
  }
1434
+ function urlOf(v) {
1435
+ if (typeof v === "string") return v;
1436
+ if (v && typeof v === "object" && typeof v.url === "string") {
1437
+ return v.url;
1438
+ }
1439
+ return void 0;
1440
+ }
1441
+ function deepFindUrl(obj, match) {
1442
+ const stack = [obj];
1443
+ while (stack.length) {
1444
+ const cur = stack.pop();
1445
+ if (typeof cur === "string") {
1446
+ if (match(cur)) return cur;
1447
+ continue;
1448
+ }
1449
+ if (cur && typeof cur === "object") {
1450
+ const u = cur.url;
1451
+ if (typeof u === "string" && match(u)) return u;
1452
+ for (const v of Object.values(cur)) stack.push(v);
1453
+ }
1454
+ }
1455
+ return void 0;
1456
+ }
1457
+ function extractTrainedFiles(result) {
1458
+ const r = result;
1459
+ const root = r?.data ?? r?.response ?? r?.output ?? r;
1460
+ const loraUrl = urlOf(root?.diffusers_lora_file) ?? urlOf(root?.lora_file) ?? urlOf(root?.safetensors) ?? urlOf(root?.lora) ?? deepFindUrl(root, (u) => /\.safetensors(\?|$)/i.test(u));
1461
+ const configUrl = urlOf(root?.config_file) ?? urlOf(root?.config) ?? deepFindUrl(root, (u) => /config[^/]*\.json(\?|$)/i.test(u));
1462
+ return { loraUrl, configUrl };
1463
+ }
1423
1464
  function fileNameFromUrl(url, i) {
1424
1465
  const base = url.split("?")[0].split("/").pop() || "";
1425
1466
  return /\.[a-z0-9]+$/i.test(base) ? base : `image_${i}.png`;
@@ -2378,8 +2419,8 @@ var stubProviders = {
2378
2419
  };
2379
2420
 
2380
2421
  // src/version.ts
2381
- var VERSION = "0.10.0";
2382
- var SDK_TAG = "@broberg/ai-sdk@0.10.0";
2422
+ var VERSION = "0.10.1";
2423
+ var SDK_TAG = "@broberg/ai-sdk@0.10.1";
2383
2424
 
2384
2425
  // src/cost/budget-store.ts
2385
2426
  function sqliteBudgetStore(config) {