@slopmachine/core 0.1.9 → 0.1.12

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,84 @@
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 base URL for the Slop Machine API.
34
+ * Defaults to the production URL. Useful for testing against local deployments.
35
+ */
8
36
  baseUrl?: string;
9
37
  }
10
38
  declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
11
39
  declare function buildImageUrl(options: SlopImageOptions): string;
40
+ type VideoAspectRatio = "9:16" | "16:9";
41
+ interface SlopVideoOptions {
42
+ /**
43
+ * The unique identifier of your Slop Machine bucket.
44
+ */
45
+ bucketId: string;
46
+ /**
47
+ * The specific version of the prompt/settings to use.
48
+ * If omitted, the latest version will be used.
49
+ */
50
+ version?: number;
51
+ /**
52
+ * Result ID to retrieve a specific previously generated video
53
+ * instead of generating a new one.
54
+ */
55
+ resultId?: string;
56
+ /**
57
+ * The aspect ratio of the generated video. Defaults to "16:9".
58
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
59
+ */
60
+ aspectRatio?: VideoAspectRatio;
61
+ /**
62
+ * The AI model to use for generation.
63
+ * Overrides the default model specified in the bucket settings.
64
+ */
65
+ model?: string;
66
+ /**
67
+ * Dynamic variables to interpolate into the prompt.
68
+ * E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
69
+ */
70
+ variables?: Record<string, string | number | undefined | null>;
71
+ /**
72
+ * The duration of the generated video in seconds.
73
+ * Must be between 4 and 8. Defaults to 4.
74
+ */
75
+ duration?: number;
76
+ /**
77
+ * The base URL for the Slop Machine API.
78
+ * Defaults to the production URL. Useful for testing against local deployments.
79
+ */
80
+ baseUrl?: string;
81
+ }
82
+ declare function buildVideoUrl(options: SlopVideoOptions): string;
12
83
 
13
- export { type SlopImageOptions, buildImageUrl, interpolatePrompt };
84
+ export { type ImageAspectRatio, type SlopImageOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildVideoUrl, interpolatePrompt };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,84 @@
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 base URL for the Slop Machine API.
34
+ * Defaults to the production URL. Useful for testing against local deployments.
35
+ */
8
36
  baseUrl?: string;
9
37
  }
10
38
  declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
11
39
  declare function buildImageUrl(options: SlopImageOptions): string;
40
+ type VideoAspectRatio = "9:16" | "16:9";
41
+ interface SlopVideoOptions {
42
+ /**
43
+ * The unique identifier of your Slop Machine bucket.
44
+ */
45
+ bucketId: string;
46
+ /**
47
+ * The specific version of the prompt/settings to use.
48
+ * If omitted, the latest version will be used.
49
+ */
50
+ version?: number;
51
+ /**
52
+ * Result ID to retrieve a specific previously generated video
53
+ * instead of generating a new one.
54
+ */
55
+ resultId?: string;
56
+ /**
57
+ * The aspect ratio of the generated video. Defaults to "16:9".
58
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
59
+ */
60
+ aspectRatio?: VideoAspectRatio;
61
+ /**
62
+ * The AI model to use for generation.
63
+ * Overrides the default model specified in the bucket settings.
64
+ */
65
+ model?: string;
66
+ /**
67
+ * Dynamic variables to interpolate into the prompt.
68
+ * E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
69
+ */
70
+ variables?: Record<string, string | number | undefined | null>;
71
+ /**
72
+ * The duration of the generated video in seconds.
73
+ * Must be between 4 and 8. Defaults to 4.
74
+ */
75
+ duration?: number;
76
+ /**
77
+ * The base URL for the Slop Machine API.
78
+ * Defaults to the production URL. Useful for testing against local deployments.
79
+ */
80
+ baseUrl?: string;
81
+ }
82
+ declare function buildVideoUrl(options: SlopVideoOptions): string;
12
83
 
13
- export { type SlopImageOptions, buildImageUrl, interpolatePrompt };
84
+ 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);
@@ -65,8 +66,43 @@ function buildImageUrl(options) {
65
66
  }
66
67
  return `${baseUrl}?${params.toString()}`;
67
68
  }
69
+ function buildVideoUrl(options) {
70
+ const {
71
+ bucketId,
72
+ version,
73
+ resultId,
74
+ aspectRatio = "16:9",
75
+ model,
76
+ variables = {},
77
+ duration = 4,
78
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo"
79
+ } = options;
80
+ const params = new URLSearchParams();
81
+ params.set("bucketId", bucketId);
82
+ if (aspectRatio) {
83
+ params.set("aspectRatio", aspectRatio);
84
+ }
85
+ if (model) {
86
+ params.set("model", model);
87
+ }
88
+ if (version) {
89
+ params.set("version", String(version));
90
+ }
91
+ if (resultId) {
92
+ params.set("resultId", resultId);
93
+ } else {
94
+ const clampedDuration = Math.max(4, Math.min(8, duration));
95
+ params.set("duration", String(clampedDuration));
96
+ }
97
+ if (Object.keys(variables).length > 0) {
98
+ params.set("variables", JSON.stringify(variables));
99
+ }
100
+ return `${baseUrl}?${params.toString()}`;
101
+ }
68
102
  // Annotate the CommonJS export names for ESM import in node:
69
103
  0 && (module.exports = {
70
104
  buildImageUrl,
105
+ buildVideoUrl,
71
106
  interpolatePrompt
72
107
  });
108
+ //# 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 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 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\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 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 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\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;AAiDO,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,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;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;AA8CO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,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;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
@@ -40,7 +40,42 @@ function buildImageUrl(options) {
40
40
  }
41
41
  return `${baseUrl}?${params.toString()}`;
42
42
  }
43
+ function buildVideoUrl(options) {
44
+ const {
45
+ bucketId,
46
+ version,
47
+ resultId,
48
+ aspectRatio = "16:9",
49
+ model,
50
+ variables = {},
51
+ duration = 4,
52
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo"
53
+ } = options;
54
+ const params = new URLSearchParams();
55
+ params.set("bucketId", bucketId);
56
+ if (aspectRatio) {
57
+ params.set("aspectRatio", aspectRatio);
58
+ }
59
+ if (model) {
60
+ params.set("model", model);
61
+ }
62
+ if (version) {
63
+ params.set("version", String(version));
64
+ }
65
+ if (resultId) {
66
+ params.set("resultId", resultId);
67
+ } else {
68
+ const clampedDuration = Math.max(4, Math.min(8, duration));
69
+ params.set("duration", String(clampedDuration));
70
+ }
71
+ if (Object.keys(variables).length > 0) {
72
+ params.set("variables", JSON.stringify(variables));
73
+ }
74
+ return `${baseUrl}?${params.toString()}`;
75
+ }
43
76
  export {
44
77
  buildImageUrl,
78
+ buildVideoUrl,
45
79
  interpolatePrompt
46
80
  };
81
+ //# 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 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 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\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 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 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\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n"],"mappings":";AAiDO,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,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;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;AA8CO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,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;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,28 +1,20 @@
1
1
  {
2
2
  "name": "@slopmachine/core",
3
- "version": "0.1.9",
4
- "main": "./dist/index.js",
5
- "module": "./dist/index.mjs",
6
- "types": "./dist/index.d.ts",
3
+ "version": "0.1.12",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.mjs",
6
+ "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "import": {
10
- "types": "./dist/index.d.mts",
11
- "default": "./dist/index.mjs"
12
- },
13
- "require": {
14
- "types": "./dist/index.d.ts",
15
- "default": "./dist/index.js"
16
- }
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
17
13
  }
18
14
  },
19
- "files": [
20
- "dist"
21
- ],
22
15
  "scripts": {
23
16
  "build": "tsup",
24
- "dev": "tsup --watch",
25
- "prepublishOnly": "npm run build"
17
+ "dev": "tsup --watch"
26
18
  },
27
19
  "repository": {
28
20
  "type": "git",
package/src/index.ts ADDED
@@ -0,0 +1,184 @@
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
+
13
+ export interface SlopImageOptions {
14
+ /**
15
+ * The unique identifier of your Slop Machine bucket.
16
+ */
17
+ bucketId: string;
18
+ /**
19
+ * The specific version of the prompt/settings to use.
20
+ * If omitted, the latest version will be used.
21
+ */
22
+ version?: number;
23
+ /**
24
+ * Result ID to retrieve a specific previously generated image
25
+ * instead of generating a new one.
26
+ */
27
+ resultId?: 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
+ */
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
+ */
42
+ variables?: Record<string, string | number | undefined | null>;
43
+ /**
44
+ * The base URL for the Slop Machine API.
45
+ * Defaults to the production URL. Useful for testing against local deployments.
46
+ */
47
+ baseUrl?: string;
48
+ }
49
+
50
+ export function interpolatePrompt(
51
+ prompt?: string,
52
+ variables?: Record<string, string | number | undefined | null>,
53
+ ): string {
54
+ if (!prompt) return "";
55
+ let text = prompt;
56
+ if (!variables) return text;
57
+
58
+ Object.keys(variables).forEach((key) => {
59
+ const value = variables[key];
60
+ if (value !== undefined && value !== null) {
61
+ text = text.replace(new RegExp(`\\{${key}\\}`, "g"), String(value));
62
+ }
63
+ });
64
+ return text;
65
+ }
66
+
67
+ export function buildImageUrl(options: SlopImageOptions): string {
68
+ const {
69
+ bucketId,
70
+ version,
71
+ resultId,
72
+ aspectRatio = "1:1",
73
+ model,
74
+ variables = {},
75
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
76
+ } = options;
77
+
78
+ const params = new URLSearchParams();
79
+ params.set("bucketId", bucketId);
80
+
81
+ if (aspectRatio) {
82
+ params.set("aspectRatio", aspectRatio);
83
+ }
84
+
85
+ if (model) {
86
+ params.set("model", model);
87
+ }
88
+ if (version) {
89
+ params.set("version", String(version));
90
+ }
91
+ if (resultId) {
92
+ params.set("resultId", resultId);
93
+ }
94
+
95
+ if (Object.keys(variables).length > 0) {
96
+ params.set("variables", JSON.stringify(variables));
97
+ }
98
+
99
+ return `${baseUrl}?${params.toString()}`;
100
+ }
101
+
102
+ export type VideoAspectRatio = "9:16" | "16:9";
103
+
104
+ export interface SlopVideoOptions {
105
+ /**
106
+ * The unique identifier of your Slop Machine bucket.
107
+ */
108
+ bucketId: string;
109
+ /**
110
+ * The specific version of the prompt/settings to use.
111
+ * If omitted, the latest version will be used.
112
+ */
113
+ version?: number;
114
+ /**
115
+ * Result ID to retrieve a specific previously generated video
116
+ * instead of generating a new one.
117
+ */
118
+ resultId?: string;
119
+ /**
120
+ * The aspect ratio of the generated video. Defaults to "16:9".
121
+ * Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
122
+ */
123
+ aspectRatio?: VideoAspectRatio;
124
+ /**
125
+ * The AI model to use for generation.
126
+ * Overrides the default model specified in the bucket settings.
127
+ */
128
+ model?: string;
129
+ /**
130
+ * Dynamic variables to interpolate into the prompt.
131
+ * E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
132
+ */
133
+ variables?: Record<string, string | number | undefined | null>;
134
+ /**
135
+ * The duration of the generated video in seconds.
136
+ * Must be between 4 and 8. Defaults to 4.
137
+ */
138
+ duration?: number;
139
+ /**
140
+ * The base URL for the Slop Machine API.
141
+ * Defaults to the production URL. Useful for testing against local deployments.
142
+ */
143
+ baseUrl?: string;
144
+ }
145
+
146
+ export function buildVideoUrl(options: SlopVideoOptions): string {
147
+ const {
148
+ bucketId,
149
+ version,
150
+ resultId,
151
+ aspectRatio = "16:9",
152
+ model,
153
+ variables = {},
154
+ duration = 4,
155
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
156
+ } = options;
157
+
158
+ const params = new URLSearchParams();
159
+ params.set("bucketId", bucketId);
160
+
161
+ if (aspectRatio) {
162
+ params.set("aspectRatio", aspectRatio);
163
+ }
164
+
165
+ if (model) {
166
+ params.set("model", model);
167
+ }
168
+ if (version) {
169
+ params.set("version", String(version));
170
+ }
171
+ if (resultId) {
172
+ params.set("resultId", resultId);
173
+ } else {
174
+ // Only append duration if resultId is NOT provided
175
+ const clampedDuration = Math.max(4, Math.min(8, duration));
176
+ params.set("duration", String(clampedDuration));
177
+ }
178
+
179
+ if (Object.keys(variables).length > 0) {
180
+ params.set("variables", JSON.stringify(variables));
181
+ }
182
+
183
+ return `${baseUrl}?${params.toString()}`;
184
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "declaration": true,
8
+ "declarationMap": true,
9
+ "skipLibCheck": true
10
+ },
11
+ "include": ["src"]
12
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/index.ts"],
5
+ format: ["cjs", "esm"],
6
+ dts: true,
7
+ sourcemap: true,
8
+ clean: true,
9
+ });