@slopmachine/core 0.1.10 → 0.1.14

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.mts CHANGED
@@ -1,13 +1,96 @@
1
+ type ImageAspectRatio = "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9";
1
2
  interface SlopImageOptions {
3
+ /**
4
+ * The unique identifier of your Slop Machine bucket.
5
+ */
2
6
  bucketId: string;
7
+ /**
8
+ * The specific version of the prompt/settings to use.
9
+ * If omitted, the latest version will be used.
10
+ */
3
11
  version?: number;
12
+ /**
13
+ * Result ID to retrieve a specific previously generated image
14
+ * instead of generating a new one.
15
+ */
4
16
  resultId?: string;
5
- aspectRatio?: string;
17
+ /**
18
+ * The aspect ratio of the generated image. Defaults to "1:1".
19
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
20
+ */
21
+ aspectRatio?: ImageAspectRatio;
22
+ /**
23
+ * The AI model to use for generation.
24
+ * Overrides the default model specified in the bucket settings.
25
+ */
6
26
  model?: "gemini" | "gemini-flash" | "gemini-pro" | "imagen";
27
+ /**
28
+ * Dynamic variables to interpolate into the prompt.
29
+ * E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
30
+ */
7
31
  variables?: Record<string, string | number | undefined | null>;
32
+ /**
33
+ * The target quality ("fast" or "high"). Only affects new generations and is ignored for caching.
34
+ * Ignored if `model` is provided.
35
+ * Defaults to "fast".
36
+ */
37
+ quality?: "fast" | "high";
38
+ /**
39
+ * The base URL for the Slop Machine API.
40
+ * Defaults to the production URL. Useful for testing against local deployments.
41
+ */
8
42
  baseUrl?: string;
9
43
  }
10
44
  declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
11
45
  declare function buildImageUrl(options: SlopImageOptions): string;
46
+ type VideoAspectRatio = "9:16" | "16:9";
47
+ interface SlopVideoOptions {
48
+ /**
49
+ * The unique identifier of your Slop Machine bucket.
50
+ */
51
+ bucketId: string;
52
+ /**
53
+ * The specific version of the prompt/settings to use.
54
+ * If omitted, the latest version will be used.
55
+ */
56
+ version?: number;
57
+ /**
58
+ * Result ID to retrieve a specific previously generated video
59
+ * instead of generating a new one.
60
+ */
61
+ resultId?: string;
62
+ /**
63
+ * The aspect ratio of the generated video. Defaults to "16:9".
64
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
65
+ */
66
+ aspectRatio?: VideoAspectRatio;
67
+ /**
68
+ * The AI model to use for generation.
69
+ * Overrides the default model specified in the bucket settings.
70
+ */
71
+ model?: string;
72
+ /**
73
+ * Dynamic variables to interpolate into the prompt.
74
+ * E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
75
+ */
76
+ variables?: Record<string, string | number | undefined | null>;
77
+ /**
78
+ * The duration of the generated video in seconds.
79
+ * Must be between 4 and 8. Defaults to 4.
80
+ */
81
+ duration?: number;
82
+ /**
83
+ * The target quality ("fast" or "high"). Only affects new generations and is ignored for caching.
84
+ * Ignored if `model` is provided.
85
+ * Defaults to "fast".
86
+ */
87
+ quality?: "fast" | "high";
88
+ /**
89
+ * The base URL for the Slop Machine API.
90
+ * Defaults to the production URL. Useful for testing against local deployments.
91
+ */
92
+ baseUrl?: string;
93
+ }
94
+ declare function buildVideoUrl(options: SlopVideoOptions): string;
12
95
 
13
- export { type SlopImageOptions, buildImageUrl, interpolatePrompt };
96
+ export { type ImageAspectRatio, type SlopImageOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildVideoUrl, interpolatePrompt };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,96 @@
1
+ type ImageAspectRatio = "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9";
1
2
  interface SlopImageOptions {
3
+ /**
4
+ * The unique identifier of your Slop Machine bucket.
5
+ */
2
6
  bucketId: string;
7
+ /**
8
+ * The specific version of the prompt/settings to use.
9
+ * If omitted, the latest version will be used.
10
+ */
3
11
  version?: number;
12
+ /**
13
+ * Result ID to retrieve a specific previously generated image
14
+ * instead of generating a new one.
15
+ */
4
16
  resultId?: string;
5
- aspectRatio?: string;
17
+ /**
18
+ * The aspect ratio of the generated image. Defaults to "1:1".
19
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
20
+ */
21
+ aspectRatio?: ImageAspectRatio;
22
+ /**
23
+ * The AI model to use for generation.
24
+ * Overrides the default model specified in the bucket settings.
25
+ */
6
26
  model?: "gemini" | "gemini-flash" | "gemini-pro" | "imagen";
27
+ /**
28
+ * Dynamic variables to interpolate into the prompt.
29
+ * E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
30
+ */
7
31
  variables?: Record<string, string | number | undefined | null>;
32
+ /**
33
+ * The target quality ("fast" or "high"). Only affects new generations and is ignored for caching.
34
+ * Ignored if `model` is provided.
35
+ * Defaults to "fast".
36
+ */
37
+ quality?: "fast" | "high";
38
+ /**
39
+ * The base URL for the Slop Machine API.
40
+ * Defaults to the production URL. Useful for testing against local deployments.
41
+ */
8
42
  baseUrl?: string;
9
43
  }
10
44
  declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
11
45
  declare function buildImageUrl(options: SlopImageOptions): string;
46
+ type VideoAspectRatio = "9:16" | "16:9";
47
+ interface SlopVideoOptions {
48
+ /**
49
+ * The unique identifier of your Slop Machine bucket.
50
+ */
51
+ bucketId: string;
52
+ /**
53
+ * The specific version of the prompt/settings to use.
54
+ * If omitted, the latest version will be used.
55
+ */
56
+ version?: number;
57
+ /**
58
+ * Result ID to retrieve a specific previously generated video
59
+ * instead of generating a new one.
60
+ */
61
+ resultId?: string;
62
+ /**
63
+ * The aspect ratio of the generated video. Defaults to "16:9".
64
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
65
+ */
66
+ aspectRatio?: VideoAspectRatio;
67
+ /**
68
+ * The AI model to use for generation.
69
+ * Overrides the default model specified in the bucket settings.
70
+ */
71
+ model?: string;
72
+ /**
73
+ * Dynamic variables to interpolate into the prompt.
74
+ * E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
75
+ */
76
+ variables?: Record<string, string | number | undefined | null>;
77
+ /**
78
+ * The duration of the generated video in seconds.
79
+ * Must be between 4 and 8. Defaults to 4.
80
+ */
81
+ duration?: number;
82
+ /**
83
+ * The target quality ("fast" or "high"). Only affects new generations and is ignored for caching.
84
+ * Ignored if `model` is provided.
85
+ * Defaults to "fast".
86
+ */
87
+ quality?: "fast" | "high";
88
+ /**
89
+ * The base URL for the Slop Machine API.
90
+ * Defaults to the production URL. Useful for testing against local deployments.
91
+ */
92
+ baseUrl?: string;
93
+ }
94
+ declare function buildVideoUrl(options: SlopVideoOptions): string;
12
95
 
13
- export { type SlopImageOptions, buildImageUrl, interpolatePrompt };
96
+ export { type ImageAspectRatio, type SlopImageOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildVideoUrl, interpolatePrompt };
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  buildImageUrl: () => buildImageUrl,
24
+ buildVideoUrl: () => buildVideoUrl,
24
25
  interpolatePrompt: () => interpolatePrompt
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
@@ -43,6 +44,7 @@ function buildImageUrl(options) {
43
44
  resultId,
44
45
  aspectRatio = "1:1",
45
46
  model,
47
+ quality = "fast",
46
48
  variables = {},
47
49
  baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage"
48
50
  } = options;
@@ -60,6 +62,50 @@ function buildImageUrl(options) {
60
62
  if (resultId) {
61
63
  params.set("resultId", resultId);
62
64
  }
65
+ if (quality && quality !== "fast") {
66
+ params.set("quality", quality);
67
+ } else if (quality === "fast") {
68
+ params.set("quality", "fast");
69
+ }
70
+ if (Object.keys(variables).length > 0) {
71
+ params.set("variables", JSON.stringify(variables));
72
+ }
73
+ return `${baseUrl}?${params.toString()}`;
74
+ }
75
+ function buildVideoUrl(options) {
76
+ const {
77
+ bucketId,
78
+ version,
79
+ resultId,
80
+ aspectRatio = "16:9",
81
+ model,
82
+ quality = "fast",
83
+ variables = {},
84
+ duration = 4,
85
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo"
86
+ } = options;
87
+ const params = new URLSearchParams();
88
+ params.set("bucketId", bucketId);
89
+ if (aspectRatio) {
90
+ params.set("aspectRatio", aspectRatio);
91
+ }
92
+ if (model) {
93
+ params.set("model", model);
94
+ }
95
+ if (version) {
96
+ params.set("version", String(version));
97
+ }
98
+ if (resultId) {
99
+ params.set("resultId", resultId);
100
+ } else {
101
+ const clampedDuration = Math.max(4, Math.min(8, duration));
102
+ params.set("duration", String(clampedDuration));
103
+ }
104
+ if (quality && quality !== "fast") {
105
+ params.set("quality", quality);
106
+ } else if (quality === "fast") {
107
+ params.set("quality", "fast");
108
+ }
63
109
  if (Object.keys(variables).length > 0) {
64
110
  params.set("variables", JSON.stringify(variables));
65
111
  }
@@ -68,5 +114,7 @@ function buildImageUrl(options) {
68
114
  // Annotate the CommonJS export names for ESM import in node:
69
115
  0 && (module.exports = {
70
116
  buildImageUrl,
117
+ buildVideoUrl,
71
118
  interpolatePrompt
72
119
  });
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: \"gemini\" | \"gemini-flash\" | \"gemini-pro\" | \"imagen\";\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n model,\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n model,\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n } else {\n // Only append duration if resultId is NOT provided\n const clampedDuration = Math.max(4, Math.min(8, duration));\n params.set(\"duration\", String(clampedDuration));\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAM,QAAQ,UAAU,GAAG;AAC3B,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC,aAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,GAAG,OAAO,GAAG,GAAG,OAAO,KAAK,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAEO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,aAAa;AACf,WAAO,IAAI,eAAe,WAAW;AAAA,EACvC;AAEA,MAAI,OAAO;AACT,WAAO,IAAI,SAAS,KAAK;AAAA,EAC3B;AACA,MAAI,SAAS;AACX,WAAO,IAAI,WAAW,OAAO,OAAO,CAAC;AAAA,EACvC;AACA,MAAI,UAAU;AACZ,WAAO,IAAI,YAAY,QAAQ;AAAA,EACjC;AACA,MAAI,WAAW,YAAY,QAAQ;AACjC,WAAO,IAAI,WAAW,OAAO;AAAA,EAC/B,WAAW,YAAY,QAAQ;AAC7B,WAAO,IAAI,WAAW,MAAM;AAAA,EAC9B;AAEA,MAAI,OAAO,KAAK,SAAS,EAAE,SAAS,GAAG;AACrC,WAAO,IAAI,aAAa,KAAK,UAAU,SAAS,CAAC;AAAA,EACnD;AAEA,SAAO,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;AAoDO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,WAAW;AAAA,IACX,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,aAAa;AACf,WAAO,IAAI,eAAe,WAAW;AAAA,EACvC;AAEA,MAAI,OAAO;AACT,WAAO,IAAI,SAAS,KAAK;AAAA,EAC3B;AACA,MAAI,SAAS;AACX,WAAO,IAAI,WAAW,OAAO,OAAO,CAAC;AAAA,EACvC;AACA,MAAI,UAAU;AACZ,WAAO,IAAI,YAAY,QAAQ;AAAA,EACjC,OAAO;AAEL,UAAM,kBAAkB,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,CAAC;AACzD,WAAO,IAAI,YAAY,OAAO,eAAe,CAAC;AAAA,EAChD;AACA,MAAI,WAAW,YAAY,QAAQ;AACjC,WAAO,IAAI,WAAW,OAAO;AAAA,EAC/B,WAAW,YAAY,QAAQ;AAC7B,WAAO,IAAI,WAAW,MAAM;AAAA,EAC9B;AAEA,MAAI,OAAO,KAAK,SAAS,EAAE,SAAS,GAAG;AACrC,WAAO,IAAI,aAAa,KAAK,UAAU,SAAS,CAAC;AAAA,EACnD;AAEA,SAAO,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;","names":[]}
package/dist/index.mjs CHANGED
@@ -18,6 +18,7 @@ function buildImageUrl(options) {
18
18
  resultId,
19
19
  aspectRatio = "1:1",
20
20
  model,
21
+ quality = "fast",
21
22
  variables = {},
22
23
  baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage"
23
24
  } = options;
@@ -35,6 +36,50 @@ function buildImageUrl(options) {
35
36
  if (resultId) {
36
37
  params.set("resultId", resultId);
37
38
  }
39
+ if (quality && quality !== "fast") {
40
+ params.set("quality", quality);
41
+ } else if (quality === "fast") {
42
+ params.set("quality", "fast");
43
+ }
44
+ if (Object.keys(variables).length > 0) {
45
+ params.set("variables", JSON.stringify(variables));
46
+ }
47
+ return `${baseUrl}?${params.toString()}`;
48
+ }
49
+ function buildVideoUrl(options) {
50
+ const {
51
+ bucketId,
52
+ version,
53
+ resultId,
54
+ aspectRatio = "16:9",
55
+ model,
56
+ quality = "fast",
57
+ variables = {},
58
+ duration = 4,
59
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo"
60
+ } = options;
61
+ const params = new URLSearchParams();
62
+ params.set("bucketId", bucketId);
63
+ if (aspectRatio) {
64
+ params.set("aspectRatio", aspectRatio);
65
+ }
66
+ if (model) {
67
+ params.set("model", model);
68
+ }
69
+ if (version) {
70
+ params.set("version", String(version));
71
+ }
72
+ if (resultId) {
73
+ params.set("resultId", resultId);
74
+ } else {
75
+ const clampedDuration = Math.max(4, Math.min(8, duration));
76
+ params.set("duration", String(clampedDuration));
77
+ }
78
+ if (quality && quality !== "fast") {
79
+ params.set("quality", quality);
80
+ } else if (quality === "fast") {
81
+ params.set("quality", "fast");
82
+ }
38
83
  if (Object.keys(variables).length > 0) {
39
84
  params.set("variables", JSON.stringify(variables));
40
85
  }
@@ -42,5 +87,7 @@ function buildImageUrl(options) {
42
87
  }
43
88
  export {
44
89
  buildImageUrl,
90
+ buildVideoUrl,
45
91
  interpolatePrompt
46
92
  };
93
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: \"gemini\" | \"gemini-flash\" | \"gemini-pro\" | \"imagen\";\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n model,\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n model,\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n } else {\n // Only append duration if resultId is NOT provided\n const clampedDuration = Math.max(4, Math.min(8, duration));\n params.set(\"duration\", String(clampedDuration));\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n"],"mappings":";AAuDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAM,QAAQ,UAAU,GAAG;AAC3B,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC,aAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,GAAG,OAAO,GAAG,GAAG,OAAO,KAAK,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAEO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,aAAa;AACf,WAAO,IAAI,eAAe,WAAW;AAAA,EACvC;AAEA,MAAI,OAAO;AACT,WAAO,IAAI,SAAS,KAAK;AAAA,EAC3B;AACA,MAAI,SAAS;AACX,WAAO,IAAI,WAAW,OAAO,OAAO,CAAC;AAAA,EACvC;AACA,MAAI,UAAU;AACZ,WAAO,IAAI,YAAY,QAAQ;AAAA,EACjC;AACA,MAAI,WAAW,YAAY,QAAQ;AACjC,WAAO,IAAI,WAAW,OAAO;AAAA,EAC/B,WAAW,YAAY,QAAQ;AAC7B,WAAO,IAAI,WAAW,MAAM;AAAA,EAC9B;AAEA,MAAI,OAAO,KAAK,SAAS,EAAE,SAAS,GAAG;AACrC,WAAO,IAAI,aAAa,KAAK,UAAU,SAAS,CAAC;AAAA,EACnD;AAEA,SAAO,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;AAoDO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,WAAW;AAAA,IACX,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,aAAa;AACf,WAAO,IAAI,eAAe,WAAW;AAAA,EACvC;AAEA,MAAI,OAAO;AACT,WAAO,IAAI,SAAS,KAAK;AAAA,EAC3B;AACA,MAAI,SAAS;AACX,WAAO,IAAI,WAAW,OAAO,OAAO,CAAC;AAAA,EACvC;AACA,MAAI,UAAU;AACZ,WAAO,IAAI,YAAY,QAAQ;AAAA,EACjC,OAAO;AAEL,UAAM,kBAAkB,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,CAAC;AACzD,WAAO,IAAI,YAAY,OAAO,eAAe,CAAC;AAAA,EAChD;AACA,MAAI,WAAW,YAAY,QAAQ;AACjC,WAAO,IAAI,WAAW,OAAO;AAAA,EAC/B,WAAW,YAAY,QAAQ;AAC7B,WAAO,IAAI,WAAW,MAAM;AAAA,EAC9B;AAEA,MAAI,OAAO,KAAK,SAAS,EAAE,SAAS,GAAG;AACrC,WAAO,IAAI,aAAa,KAAK,UAAU,SAAS,CAAC;AAAA,EACnD;AAEA,SAAO,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slopmachine/core",
3
- "version": "0.1.10",
3
+ "version": "0.1.14",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.mjs",
11
- "require": "./dist/index.js"
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
12
13
  }
13
14
  },
14
15
  "scripts": {
@@ -22,5 +23,6 @@
22
23
  "devDependencies": {
23
24
  "tsup": "^8.0.0",
24
25
  "typescript": "^5.0.0"
25
- }
26
+ },
27
+ "license": "MIT"
26
28
  }
package/src/index.ts CHANGED
@@ -1,10 +1,55 @@
1
+ export type ImageAspectRatio =
2
+ | "1:1"
3
+ | "2:3"
4
+ | "3:2"
5
+ | "3:4"
6
+ | "4:3"
7
+ | "4:5"
8
+ | "5:4"
9
+ | "9:16"
10
+ | "16:9"
11
+ | "21:9";
12
+
1
13
  export interface SlopImageOptions {
14
+ /**
15
+ * The unique identifier of your Slop Machine bucket.
16
+ */
2
17
  bucketId: string;
18
+ /**
19
+ * The specific version of the prompt/settings to use.
20
+ * If omitted, the latest version will be used.
21
+ */
3
22
  version?: number;
23
+ /**
24
+ * Result ID to retrieve a specific previously generated image
25
+ * instead of generating a new one.
26
+ */
4
27
  resultId?: string;
5
- aspectRatio?: string;
28
+ /**
29
+ * The aspect ratio of the generated image. Defaults to "1:1".
30
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
31
+ */
32
+ aspectRatio?: ImageAspectRatio;
33
+ /**
34
+ * The AI model to use for generation.
35
+ * Overrides the default model specified in the bucket settings.
36
+ */
6
37
  model?: "gemini" | "gemini-flash" | "gemini-pro" | "imagen";
38
+ /**
39
+ * Dynamic variables to interpolate into the prompt.
40
+ * E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
41
+ */
7
42
  variables?: Record<string, string | number | undefined | null>;
43
+ /**
44
+ * The target quality ("fast" or "high"). Only affects new generations and is ignored for caching.
45
+ * Ignored if `model` is provided.
46
+ * Defaults to "fast".
47
+ */
48
+ quality?: "fast" | "high";
49
+ /**
50
+ * The base URL for the Slop Machine API.
51
+ * Defaults to the production URL. Useful for testing against local deployments.
52
+ */
8
53
  baseUrl?: string;
9
54
  }
10
55
 
@@ -32,6 +77,7 @@ export function buildImageUrl(options: SlopImageOptions): string {
32
77
  resultId,
33
78
  aspectRatio = "1:1",
34
79
  model,
80
+ quality = "fast",
35
81
  variables = {},
36
82
  baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
37
83
  } = options;
@@ -52,6 +98,107 @@ export function buildImageUrl(options: SlopImageOptions): string {
52
98
  if (resultId) {
53
99
  params.set("resultId", resultId);
54
100
  }
101
+ if (quality && quality !== "fast") {
102
+ params.set("quality", quality);
103
+ } else if (quality === "fast") {
104
+ params.set("quality", "fast");
105
+ }
106
+
107
+ if (Object.keys(variables).length > 0) {
108
+ params.set("variables", JSON.stringify(variables));
109
+ }
110
+
111
+ return `${baseUrl}?${params.toString()}`;
112
+ }
113
+
114
+ export type VideoAspectRatio = "9:16" | "16:9";
115
+
116
+ export interface SlopVideoOptions {
117
+ /**
118
+ * The unique identifier of your Slop Machine bucket.
119
+ */
120
+ bucketId: string;
121
+ /**
122
+ * The specific version of the prompt/settings to use.
123
+ * If omitted, the latest version will be used.
124
+ */
125
+ version?: number;
126
+ /**
127
+ * Result ID to retrieve a specific previously generated video
128
+ * instead of generating a new one.
129
+ */
130
+ resultId?: string;
131
+ /**
132
+ * The aspect ratio of the generated video. Defaults to "16:9".
133
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
134
+ */
135
+ aspectRatio?: VideoAspectRatio;
136
+ /**
137
+ * The AI model to use for generation.
138
+ * Overrides the default model specified in the bucket settings.
139
+ */
140
+ model?: string;
141
+ /**
142
+ * Dynamic variables to interpolate into the prompt.
143
+ * E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
144
+ */
145
+ variables?: Record<string, string | number | undefined | null>;
146
+ /**
147
+ * The duration of the generated video in seconds.
148
+ * Must be between 4 and 8. Defaults to 4.
149
+ */
150
+ duration?: number;
151
+ /**
152
+ * The target quality ("fast" or "high"). Only affects new generations and is ignored for caching.
153
+ * Ignored if `model` is provided.
154
+ * Defaults to "fast".
155
+ */
156
+ quality?: "fast" | "high";
157
+ /**
158
+ * The base URL for the Slop Machine API.
159
+ * Defaults to the production URL. Useful for testing against local deployments.
160
+ */
161
+ baseUrl?: string;
162
+ }
163
+
164
+ export function buildVideoUrl(options: SlopVideoOptions): string {
165
+ const {
166
+ bucketId,
167
+ version,
168
+ resultId,
169
+ aspectRatio = "16:9",
170
+ model,
171
+ quality = "fast",
172
+ variables = {},
173
+ duration = 4,
174
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
175
+ } = options;
176
+
177
+ const params = new URLSearchParams();
178
+ params.set("bucketId", bucketId);
179
+
180
+ if (aspectRatio) {
181
+ params.set("aspectRatio", aspectRatio);
182
+ }
183
+
184
+ if (model) {
185
+ params.set("model", model);
186
+ }
187
+ if (version) {
188
+ params.set("version", String(version));
189
+ }
190
+ if (resultId) {
191
+ params.set("resultId", resultId);
192
+ } else {
193
+ // Only append duration if resultId is NOT provided
194
+ const clampedDuration = Math.max(4, Math.min(8, duration));
195
+ params.set("duration", String(clampedDuration));
196
+ }
197
+ if (quality && quality !== "fast") {
198
+ params.set("quality", quality);
199
+ } else if (quality === "fast") {
200
+ params.set("quality", "fast");
201
+ }
55
202
 
56
203
  if (Object.keys(variables).length > 0) {
57
204
  params.set("variables", JSON.stringify(variables));
package/tsconfig.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "moduleResolution": "bundler",
6
6
  "strict": true,
7
7
  "declaration": true,
8
+ "declarationMap": true,
8
9
  "skipLibCheck": true
9
10
  },
10
11
  "include": ["src"]
package/tsup.config.ts CHANGED
@@ -4,5 +4,6 @@ export default defineConfig({
4
4
  entry: ["src/index.ts"],
5
5
  format: ["cjs", "esm"],
6
6
  dts: true,
7
+ sourcemap: true,
7
8
  clean: true,
8
9
  });