@howells/motif-sdk 0.5.1 → 0.7.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/dist/index.cjs CHANGED
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
23
  ASPECT_RATIOS: () => ASPECT_RATIOS,
24
24
  CREATIVE_FIELDS: () => CREATIVE_FIELDS,
25
25
  CREATIVE_TAXONOMY: () => CREATIVE_TAXONOMY,
@@ -57,7 +57,7 @@ __export(index_exports, {
57
57
  parseMotifEnv: () => parseMotifEnv,
58
58
  sanitizePrompt: () => sanitizePrompt
59
59
  });
60
- module.exports = __toCommonJS(index_exports);
60
+ module.exports = __toCommonJS(src_exports);
61
61
  var import_neverthrow2 = require("neverthrow");
62
62
 
63
63
  // src/aspects.ts
@@ -2305,6 +2305,18 @@ function toHeaderRecord(headers) {
2305
2305
  }
2306
2306
  return headers;
2307
2307
  }
2308
+ function requestIdFromBody(text) {
2309
+ let parsed;
2310
+ try {
2311
+ parsed = JSON.parse(text);
2312
+ } catch {
2313
+ return void 0;
2314
+ }
2315
+ if (!isRecord(parsed)) {
2316
+ return void 0;
2317
+ }
2318
+ return asString(parsed.request_id) ?? asString(parsed.requestId) ?? asString(parsed.trace_id);
2319
+ }
2308
2320
 
2309
2321
  // src/tools.ts
2310
2322
  var FAL_EXPLORE_CHECKED_AT = "2026-05-12";
@@ -2764,9 +2776,8 @@ var MotifServer = class {
2764
2776
  return await this.getJobResult(job.value.endpoint, job.value.requestId);
2765
2777
  }
2766
2778
  if (status.value.status === "failed") {
2767
- return (0, import_neverthrow.err)(
2768
- new MotifError(status.value.error ?? "Queued generation failed", 0)
2769
- );
2779
+ const message = status.value.error ?? "Queued generation failed";
2780
+ return (0, import_neverthrow.err)(new MotifError(message, 0, void 0, job.value.requestId));
2770
2781
  }
2771
2782
  await new Promise((resolve) => {
2772
2783
  setTimeout(resolve, pollIntervalMs);
@@ -3165,11 +3176,10 @@ var MotifServer = class {
3165
3176
  }
3166
3177
  if (!response.ok) {
3167
3178
  const text = await response.text();
3179
+ const message = `Request failed: ${response.status} ${text}`;
3180
+ const requestId = response.headers.get("x-fal-request-id") ?? requestIdFromBody(text);
3168
3181
  return (0, import_neverthrow.err)(
3169
- new MotifError(
3170
- `Request failed: ${response.status} ${text}`,
3171
- response.status
3172
- )
3182
+ new MotifError(message, response.status, void 0, requestId)
3173
3183
  );
3174
3184
  }
3175
3185
  return (0, import_neverthrow.ok)(response);
@@ -3229,11 +3239,15 @@ var MotifServer = class {
3229
3239
  var MotifError = class extends Error {
3230
3240
  status;
3231
3241
  code;
3232
- constructor(message, status, code) {
3242
+ /** fal's request-correlation id (from the `x-fal-request-id` header or the
3243
+ * error body). Ties a failure back to fal's dashboard/support. */
3244
+ requestId;
3245
+ constructor(message, status, code, requestId) {
3233
3246
  super(message);
3234
3247
  this.name = "MotifError";
3235
3248
  this.status = status;
3236
3249
  this.code = code;
3250
+ this.requestId = requestId;
3237
3251
  }
3238
3252
  };
3239
3253
  function toMotifError(error) {
package/dist/index.d.cts CHANGED
@@ -927,7 +927,10 @@ declare class MotifServer {
927
927
  declare class MotifError extends Error {
928
928
  readonly status: number;
929
929
  readonly code?: string;
930
- constructor(message: string, status: number, code?: string);
930
+ /** fal's request-correlation id (from the `x-fal-request-id` header or the
931
+ * error body). Ties a failure back to fal's dashboard/support. */
932
+ readonly requestId?: string;
933
+ constructor(message: string, status: number, code?: string, requestId?: string);
931
934
  }
932
935
 
933
936
  type FalToolInputKind = "image" | "images" | "video";
package/dist/index.d.ts CHANGED
@@ -927,7 +927,10 @@ declare class MotifServer {
927
927
  declare class MotifError extends Error {
928
928
  readonly status: number;
929
929
  readonly code?: string;
930
- constructor(message: string, status: number, code?: string);
930
+ /** fal's request-correlation id (from the `x-fal-request-id` header or the
931
+ * error body). Ties a failure back to fal's dashboard/support. */
932
+ readonly requestId?: string;
933
+ constructor(message: string, status: number, code?: string, requestId?: string);
931
934
  }
932
935
 
933
936
  type FalToolInputKind = "image" | "images" | "video";
package/dist/index.js CHANGED
@@ -2246,6 +2246,18 @@ function toHeaderRecord(headers) {
2246
2246
  }
2247
2247
  return headers;
2248
2248
  }
2249
+ function requestIdFromBody(text) {
2250
+ let parsed;
2251
+ try {
2252
+ parsed = JSON.parse(text);
2253
+ } catch {
2254
+ return void 0;
2255
+ }
2256
+ if (!isRecord(parsed)) {
2257
+ return void 0;
2258
+ }
2259
+ return asString(parsed.request_id) ?? asString(parsed.requestId) ?? asString(parsed.trace_id);
2260
+ }
2249
2261
 
2250
2262
  // src/tools.ts
2251
2263
  var FAL_EXPLORE_CHECKED_AT = "2026-05-12";
@@ -2705,9 +2717,8 @@ var MotifServer = class {
2705
2717
  return await this.getJobResult(job.value.endpoint, job.value.requestId);
2706
2718
  }
2707
2719
  if (status.value.status === "failed") {
2708
- return err(
2709
- new MotifError(status.value.error ?? "Queued generation failed", 0)
2710
- );
2720
+ const message = status.value.error ?? "Queued generation failed";
2721
+ return err(new MotifError(message, 0, void 0, job.value.requestId));
2711
2722
  }
2712
2723
  await new Promise((resolve) => {
2713
2724
  setTimeout(resolve, pollIntervalMs);
@@ -3106,11 +3117,10 @@ var MotifServer = class {
3106
3117
  }
3107
3118
  if (!response.ok) {
3108
3119
  const text = await response.text();
3120
+ const message = `Request failed: ${response.status} ${text}`;
3121
+ const requestId = response.headers.get("x-fal-request-id") ?? requestIdFromBody(text);
3109
3122
  return err(
3110
- new MotifError(
3111
- `Request failed: ${response.status} ${text}`,
3112
- response.status
3113
- )
3123
+ new MotifError(message, response.status, void 0, requestId)
3114
3124
  );
3115
3125
  }
3116
3126
  return ok(response);
@@ -3170,11 +3180,15 @@ var MotifServer = class {
3170
3180
  var MotifError = class extends Error {
3171
3181
  status;
3172
3182
  code;
3173
- constructor(message, status, code) {
3183
+ /** fal's request-correlation id (from the `x-fal-request-id` header or the
3184
+ * error body). Ties a failure back to fal's dashboard/support. */
3185
+ requestId;
3186
+ constructor(message, status, code, requestId) {
3174
3187
  super(message);
3175
3188
  this.name = "MotifError";
3176
3189
  this.status = status;
3177
3190
  this.code = code;
3191
+ this.requestId = requestId;
3178
3192
  }
3179
3193
  };
3180
3194
  function toMotifError(error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howells/motif-sdk",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "description": "Public Node SDK for Motif fal.ai generation, editing, utility tools, and model metadata.",
5
5
  "keywords": [
6
6
  "fal",
@@ -32,13 +32,19 @@
32
32
  "types": "./dist/index.d.ts",
33
33
  "import": "./dist/index.js",
34
34
  "require": "./dist/index.cjs"
35
+ },
36
+ "./image": {
37
+ "types": "./dist/image.d.ts",
38
+ "import": "./dist/image.js"
35
39
  }
36
40
  },
37
41
  "publishConfig": {
38
42
  "access": "public"
39
43
  },
40
44
  "dependencies": {
45
+ "@ai-sdk/google": "^4.0.12",
41
46
  "@howells/envy": "^0.3.7",
47
+ "ai": "^7.0.22",
42
48
  "neverthrow": "^8.2.0",
43
49
  "zod": "^4.4.3"
44
50
  },
@@ -52,8 +58,8 @@
52
58
  "vitest": "^4.1.10"
53
59
  },
54
60
  "scripts": {
55
- "build": "tsup src/index.ts --format cjs,esm --dts",
56
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
61
+ "build": "tsup",
62
+ "dev": "tsup --watch",
57
63
  "lint": "howells-check .",
58
64
  "lint:fix": "howells-fix .",
59
65
  "typecheck": "tsc --noEmit",