@slopmachine/core 0.1.16 → 0.1.24
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 +10 -15
- package/dist/index.d.ts +10 -15
- package/dist/index.js +54 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +65 -64
package/dist/index.d.mts
CHANGED
|
@@ -19,11 +19,6 @@ interface SlopImageOptions {
|
|
|
19
19
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
20
20
|
*/
|
|
21
21
|
aspectRatio?: ImageAspectRatio;
|
|
22
|
-
/**
|
|
23
|
-
* The AI model to use for generation.
|
|
24
|
-
* Overrides the default model specified in the bucket settings.
|
|
25
|
-
*/
|
|
26
|
-
model?: "gemini" | "gemini-flash" | "gemini-pro" | "imagen";
|
|
27
22
|
/**
|
|
28
23
|
* Dynamic variables to interpolate into the prompt.
|
|
29
24
|
* E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
|
|
@@ -40,6 +35,11 @@ interface SlopImageOptions {
|
|
|
40
35
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
41
36
|
*/
|
|
42
37
|
baseUrl?: string;
|
|
38
|
+
/**
|
|
39
|
+
* If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).
|
|
40
|
+
* Defaults to false.
|
|
41
|
+
*/
|
|
42
|
+
original?: boolean;
|
|
43
43
|
}
|
|
44
44
|
declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
|
|
45
45
|
/**
|
|
@@ -78,11 +78,6 @@ interface SlopVideoOptions {
|
|
|
78
78
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
79
79
|
*/
|
|
80
80
|
aspectRatio?: VideoAspectRatio;
|
|
81
|
-
/**
|
|
82
|
-
* The AI model to use for generation.
|
|
83
|
-
* Overrides the default model specified in the bucket settings.
|
|
84
|
-
*/
|
|
85
|
-
model?: string;
|
|
86
81
|
/**
|
|
87
82
|
* Dynamic variables to interpolate into the prompt.
|
|
88
83
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -104,6 +99,11 @@ interface SlopVideoOptions {
|
|
|
104
99
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
105
100
|
*/
|
|
106
101
|
baseUrl?: string;
|
|
102
|
+
/**
|
|
103
|
+
* If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.
|
|
104
|
+
* Defaults to false.
|
|
105
|
+
*/
|
|
106
|
+
original?: boolean;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
@@ -135,11 +135,6 @@ interface SlopTextOptions {
|
|
|
135
135
|
* instead of generating a new one.
|
|
136
136
|
*/
|
|
137
137
|
resultId?: string;
|
|
138
|
-
/**
|
|
139
|
-
* The AI model to use for generation.
|
|
140
|
-
* Overrides the default model specified in the bucket settings.
|
|
141
|
-
*/
|
|
142
|
-
model?: string;
|
|
143
138
|
/**
|
|
144
139
|
* Dynamic variables to interpolate into the prompt.
|
|
145
140
|
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
package/dist/index.d.ts
CHANGED
|
@@ -19,11 +19,6 @@ interface SlopImageOptions {
|
|
|
19
19
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
20
20
|
*/
|
|
21
21
|
aspectRatio?: ImageAspectRatio;
|
|
22
|
-
/**
|
|
23
|
-
* The AI model to use for generation.
|
|
24
|
-
* Overrides the default model specified in the bucket settings.
|
|
25
|
-
*/
|
|
26
|
-
model?: "gemini" | "gemini-flash" | "gemini-pro" | "imagen";
|
|
27
22
|
/**
|
|
28
23
|
* Dynamic variables to interpolate into the prompt.
|
|
29
24
|
* E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
|
|
@@ -40,6 +35,11 @@ interface SlopImageOptions {
|
|
|
40
35
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
41
36
|
*/
|
|
42
37
|
baseUrl?: string;
|
|
38
|
+
/**
|
|
39
|
+
* If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).
|
|
40
|
+
* Defaults to false.
|
|
41
|
+
*/
|
|
42
|
+
original?: boolean;
|
|
43
43
|
}
|
|
44
44
|
declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
|
|
45
45
|
/**
|
|
@@ -78,11 +78,6 @@ interface SlopVideoOptions {
|
|
|
78
78
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
79
79
|
*/
|
|
80
80
|
aspectRatio?: VideoAspectRatio;
|
|
81
|
-
/**
|
|
82
|
-
* The AI model to use for generation.
|
|
83
|
-
* Overrides the default model specified in the bucket settings.
|
|
84
|
-
*/
|
|
85
|
-
model?: string;
|
|
86
81
|
/**
|
|
87
82
|
* Dynamic variables to interpolate into the prompt.
|
|
88
83
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -104,6 +99,11 @@ interface SlopVideoOptions {
|
|
|
104
99
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
105
100
|
*/
|
|
106
101
|
baseUrl?: string;
|
|
102
|
+
/**
|
|
103
|
+
* If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.
|
|
104
|
+
* Defaults to false.
|
|
105
|
+
*/
|
|
106
|
+
original?: boolean;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
@@ -135,11 +135,6 @@ interface SlopTextOptions {
|
|
|
135
135
|
* instead of generating a new one.
|
|
136
136
|
*/
|
|
137
137
|
resultId?: string;
|
|
138
|
-
/**
|
|
139
|
-
* The AI model to use for generation.
|
|
140
|
-
* Overrides the default model specified in the bucket settings.
|
|
141
|
-
*/
|
|
142
|
-
model?: string;
|
|
143
138
|
/**
|
|
144
139
|
* Dynamic variables to interpolate into the prompt.
|
|
145
140
|
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
package/dist/index.js
CHANGED
|
@@ -47,33 +47,34 @@ function buildImageUrl(options) {
|
|
|
47
47
|
version,
|
|
48
48
|
resultId,
|
|
49
49
|
aspectRatio = "1:1",
|
|
50
|
-
model,
|
|
51
50
|
quality = "fast",
|
|
52
51
|
variables = {},
|
|
53
|
-
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage"
|
|
52
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
|
|
53
|
+
original
|
|
54
54
|
} = options;
|
|
55
55
|
const params = new URLSearchParams();
|
|
56
56
|
params.set("bucketId", bucketId);
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
if (!resultId) {
|
|
58
|
+
if (aspectRatio) {
|
|
59
|
+
params.set("aspectRatio", aspectRatio);
|
|
60
|
+
}
|
|
61
|
+
if (version) {
|
|
62
|
+
params.set("version", String(version));
|
|
63
|
+
}
|
|
64
|
+
if (quality && quality !== "fast") {
|
|
65
|
+
params.set("quality", quality);
|
|
66
|
+
} else if (quality === "fast") {
|
|
67
|
+
params.set("quality", "fast");
|
|
68
|
+
}
|
|
69
|
+
if (original) {
|
|
70
|
+
params.set("original", "true");
|
|
71
|
+
}
|
|
72
|
+
if (Object.keys(variables).length > 0) {
|
|
73
|
+
params.set("variables", JSON.stringify(variables));
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
67
76
|
params.set("resultId", resultId);
|
|
68
77
|
}
|
|
69
|
-
if (quality && quality !== "fast") {
|
|
70
|
-
params.set("quality", quality);
|
|
71
|
-
} else if (quality === "fast") {
|
|
72
|
-
params.set("quality", "fast");
|
|
73
|
-
}
|
|
74
|
-
if (Object.keys(variables).length > 0) {
|
|
75
|
-
params.set("variables", JSON.stringify(variables));
|
|
76
|
-
}
|
|
77
78
|
return `${baseUrl}?${params.toString()}`;
|
|
78
79
|
}
|
|
79
80
|
function preloadImage(options) {
|
|
@@ -94,30 +95,35 @@ function buildVideoUrl(options) {
|
|
|
94
95
|
version,
|
|
95
96
|
resultId,
|
|
96
97
|
aspectRatio = "16:9",
|
|
97
|
-
model,
|
|
98
98
|
quality = "fast",
|
|
99
99
|
variables = {},
|
|
100
100
|
duration = 4,
|
|
101
|
-
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo"
|
|
101
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
|
|
102
|
+
original
|
|
102
103
|
} = options;
|
|
103
104
|
const params = new URLSearchParams();
|
|
104
105
|
params.set("bucketId", bucketId);
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
if (!resultId) {
|
|
107
|
+
if (aspectRatio) {
|
|
108
|
+
params.set("aspectRatio", aspectRatio);
|
|
109
|
+
}
|
|
110
|
+
if (version) {
|
|
111
|
+
params.set("version", String(version));
|
|
112
|
+
}
|
|
113
|
+
if (duration) {
|
|
114
|
+
params.set("duration", String(duration));
|
|
115
|
+
}
|
|
116
|
+
if (quality) {
|
|
117
|
+
params.set("quality", quality);
|
|
118
|
+
}
|
|
119
|
+
if (original) {
|
|
120
|
+
params.set("original", "true");
|
|
121
|
+
}
|
|
122
|
+
if (Object.keys(variables).length > 0) {
|
|
123
|
+
params.set("variables", JSON.stringify(variables));
|
|
124
|
+
}
|
|
116
125
|
} else {
|
|
117
|
-
params.set("
|
|
118
|
-
}
|
|
119
|
-
if (Object.keys(variables).length > 0) {
|
|
120
|
-
params.set("variables", JSON.stringify(variables));
|
|
126
|
+
params.set("resultId", resultId);
|
|
121
127
|
}
|
|
122
128
|
return `${baseUrl}?${params.toString()}`;
|
|
123
129
|
}
|
|
@@ -135,24 +141,24 @@ function buildTextUrl(options) {
|
|
|
135
141
|
bucketId,
|
|
136
142
|
version,
|
|
137
143
|
resultId,
|
|
138
|
-
model,
|
|
139
144
|
variables = {},
|
|
140
145
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
141
146
|
} = options;
|
|
142
147
|
const params = new URLSearchParams();
|
|
143
148
|
params.set("bucketId", bucketId);
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
if (!resultId) {
|
|
150
|
+
if (version) {
|
|
151
|
+
params.set("version", String(version));
|
|
152
|
+
}
|
|
153
|
+
if (resultId) {
|
|
154
|
+
params.set("resultId", resultId);
|
|
155
|
+
}
|
|
156
|
+
if (Object.keys(variables).length > 0) {
|
|
157
|
+
params.set("variables", JSON.stringify(variables));
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
151
160
|
params.set("resultId", resultId);
|
|
152
161
|
}
|
|
153
|
-
if (Object.keys(variables).length > 0) {
|
|
154
|
-
params.set("variables", JSON.stringify(variables));
|
|
155
|
-
}
|
|
156
162
|
return `${baseUrl}?${params.toString()}`;
|
|
157
163
|
}
|
|
158
164
|
function preloadText(options) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\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\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\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\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\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 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\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\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 text\n * instead of generating a new one.\n */\n resultId?: string;\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 story about 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\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n model,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\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\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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,OA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,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;AASO,SAAS,YAAY,SAAyC;AACnE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,OAAO,WAAW,aAAa;AACjC,cAAQ;AACR;AAAA,IACF;AAIA,UAAM,aAAa,OAAO,GAAG,EAAE,MAAM,UAAU,CAAC,EAC7C,KAAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
|
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 * 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 * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).\n * Defaults to false.\n */\n original?: boolean;\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\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n original,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\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 (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\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 * 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 * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.\n * Defaults to false.\n */\n original?: boolean;\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n original,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (duration) {\n params.set(\"duration\", String(duration));\n }\n if (quality) {\n params.set(\"quality\", quality);\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\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 text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about 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\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\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 } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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;AAQO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,IACV;AAAA,EACF,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,CAAC,UAAU;A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,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;AASO,SAAS,YAAY,SAAyC;AACnE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,OAAO,WAAW,aAAa;AACjC,cAAQ;AACR;AAAA,IACF;AAIA,UAAM,aAAa,OAAO,GAAG,EAAE,MAAM,UAAU,CAAC,EAC7C,KAAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -17,33 +17,34 @@ function buildImageUrl(options) {
|
|
|
17
17
|
version,
|
|
18
18
|
resultId,
|
|
19
19
|
aspectRatio = "1:1",
|
|
20
|
-
model,
|
|
21
20
|
quality = "fast",
|
|
22
21
|
variables = {},
|
|
23
|
-
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage"
|
|
22
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
|
|
23
|
+
original
|
|
24
24
|
} = options;
|
|
25
25
|
const params = new URLSearchParams();
|
|
26
26
|
params.set("bucketId", bucketId);
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
if (!resultId) {
|
|
28
|
+
if (aspectRatio) {
|
|
29
|
+
params.set("aspectRatio", aspectRatio);
|
|
30
|
+
}
|
|
31
|
+
if (version) {
|
|
32
|
+
params.set("version", String(version));
|
|
33
|
+
}
|
|
34
|
+
if (quality && quality !== "fast") {
|
|
35
|
+
params.set("quality", quality);
|
|
36
|
+
} else if (quality === "fast") {
|
|
37
|
+
params.set("quality", "fast");
|
|
38
|
+
}
|
|
39
|
+
if (original) {
|
|
40
|
+
params.set("original", "true");
|
|
41
|
+
}
|
|
42
|
+
if (Object.keys(variables).length > 0) {
|
|
43
|
+
params.set("variables", JSON.stringify(variables));
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
37
46
|
params.set("resultId", resultId);
|
|
38
47
|
}
|
|
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
48
|
return `${baseUrl}?${params.toString()}`;
|
|
48
49
|
}
|
|
49
50
|
function preloadImage(options) {
|
|
@@ -64,30 +65,35 @@ function buildVideoUrl(options) {
|
|
|
64
65
|
version,
|
|
65
66
|
resultId,
|
|
66
67
|
aspectRatio = "16:9",
|
|
67
|
-
model,
|
|
68
68
|
quality = "fast",
|
|
69
69
|
variables = {},
|
|
70
70
|
duration = 4,
|
|
71
|
-
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo"
|
|
71
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
|
|
72
|
+
original
|
|
72
73
|
} = options;
|
|
73
74
|
const params = new URLSearchParams();
|
|
74
75
|
params.set("bucketId", bucketId);
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
if (!resultId) {
|
|
77
|
+
if (aspectRatio) {
|
|
78
|
+
params.set("aspectRatio", aspectRatio);
|
|
79
|
+
}
|
|
80
|
+
if (version) {
|
|
81
|
+
params.set("version", String(version));
|
|
82
|
+
}
|
|
83
|
+
if (duration) {
|
|
84
|
+
params.set("duration", String(duration));
|
|
85
|
+
}
|
|
86
|
+
if (quality) {
|
|
87
|
+
params.set("quality", quality);
|
|
88
|
+
}
|
|
89
|
+
if (original) {
|
|
90
|
+
params.set("original", "true");
|
|
91
|
+
}
|
|
92
|
+
if (Object.keys(variables).length > 0) {
|
|
93
|
+
params.set("variables", JSON.stringify(variables));
|
|
94
|
+
}
|
|
86
95
|
} else {
|
|
87
|
-
params.set("
|
|
88
|
-
}
|
|
89
|
-
if (Object.keys(variables).length > 0) {
|
|
90
|
-
params.set("variables", JSON.stringify(variables));
|
|
96
|
+
params.set("resultId", resultId);
|
|
91
97
|
}
|
|
92
98
|
return `${baseUrl}?${params.toString()}`;
|
|
93
99
|
}
|
|
@@ -105,24 +111,24 @@ function buildTextUrl(options) {
|
|
|
105
111
|
bucketId,
|
|
106
112
|
version,
|
|
107
113
|
resultId,
|
|
108
|
-
model,
|
|
109
114
|
variables = {},
|
|
110
115
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
111
116
|
} = options;
|
|
112
117
|
const params = new URLSearchParams();
|
|
113
118
|
params.set("bucketId", bucketId);
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
if (!resultId) {
|
|
120
|
+
if (version) {
|
|
121
|
+
params.set("version", String(version));
|
|
122
|
+
}
|
|
123
|
+
if (resultId) {
|
|
124
|
+
params.set("resultId", resultId);
|
|
125
|
+
}
|
|
126
|
+
if (Object.keys(variables).length > 0) {
|
|
127
|
+
params.set("variables", JSON.stringify(variables));
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
121
130
|
params.set("resultId", resultId);
|
|
122
131
|
}
|
|
123
|
-
if (Object.keys(variables).length > 0) {
|
|
124
|
-
params.set("variables", JSON.stringify(variables));
|
|
125
|
-
}
|
|
126
132
|
return `${baseUrl}?${params.toString()}`;
|
|
127
133
|
}
|
|
128
134
|
function preloadText(options) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +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\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\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\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\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\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\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 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\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\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 text\n * instead of generating a new one.\n */\n resultId?: string;\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 story about 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\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n model,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\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\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\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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AgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,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;AASO,SAAS,YAAY,SAAyC;AACnE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,OAAO,WAAW,aAAa;AACjC,cAAQ;AACR;AAAA,IACF;AAIA,UAAM,aAAa,OAAO,GAAG,EAAE,MAAM,UAAU,CAAC,EAC7C,KAAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
|
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 * 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 * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).\n * Defaults to false.\n */\n original?: boolean;\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\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n original,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\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 (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\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 * 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 * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.\n * Defaults to false.\n */\n original?: boolean;\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n original,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (duration) {\n params.set(\"duration\", String(duration));\n }\n if (quality) {\n params.set(\"quality\", quality);\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\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 text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about 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\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\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 } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\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;AAQO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,IACV;AAAA,EACF,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY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AAY,QAAQ;AAAA,EACjC;AAEA,SAAO,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;AASO,SAAS,YAAY,SAAyC;AACnE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,OAAO,WAAW,aAAa;AACjC,cAAQ;AACR;AAAA,IACF;AAIA,UAAM,aAAa,OAAO,GAAG,EAAE,MAAM,UAAU,CAAC,EAC7C,KAAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slopmachine/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "The official Core / VanillaJS SDK for Slop Machine",
|
|
5
|
-
"llms": "https://slopmachine
|
|
6
|
-
"llmsFull": "https://slopmachine
|
|
5
|
+
"llms": "https://docs.slopmachine.dev/llms.txt",
|
|
6
|
+
"llmsFull": "https://docs.slopmachine.dev/llms-full.txt",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist/index.mjs",
|
|
9
9
|
"types": "dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -30,11 +30,6 @@ export interface SlopImageOptions {
|
|
|
30
30
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
31
31
|
*/
|
|
32
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
33
|
/**
|
|
39
34
|
* Dynamic variables to interpolate into the prompt.
|
|
40
35
|
* E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
|
|
@@ -51,6 +46,11 @@ export interface SlopImageOptions {
|
|
|
51
46
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
52
47
|
*/
|
|
53
48
|
baseUrl?: string;
|
|
49
|
+
/**
|
|
50
|
+
* If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).
|
|
51
|
+
* Defaults to false.
|
|
52
|
+
*/
|
|
53
|
+
original?: boolean;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export function interpolatePrompt(
|
|
@@ -82,36 +82,37 @@ export function buildImageUrl(options: SlopImageOptions): string {
|
|
|
82
82
|
version,
|
|
83
83
|
resultId,
|
|
84
84
|
aspectRatio = "1:1",
|
|
85
|
-
model,
|
|
86
85
|
quality = "fast",
|
|
87
86
|
variables = {},
|
|
88
87
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
|
|
88
|
+
original,
|
|
89
89
|
} = options;
|
|
90
90
|
|
|
91
91
|
const params = new URLSearchParams();
|
|
92
92
|
params.set("bucketId", bucketId);
|
|
93
93
|
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
if (!resultId) {
|
|
95
|
+
if (aspectRatio) {
|
|
96
|
+
params.set("aspectRatio", aspectRatio);
|
|
97
|
+
}
|
|
98
|
+
if (version) {
|
|
99
|
+
params.set("version", String(version));
|
|
100
|
+
}
|
|
101
|
+
if (quality && quality !== "fast") {
|
|
102
|
+
params.set("quality", quality);
|
|
103
|
+
} else if (quality === "fast") {
|
|
104
|
+
params.set("quality", "fast");
|
|
105
|
+
}
|
|
97
106
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (version) {
|
|
102
|
-
params.set("version", String(version));
|
|
103
|
-
}
|
|
104
|
-
if (resultId) {
|
|
105
|
-
params.set("resultId", resultId);
|
|
106
|
-
}
|
|
107
|
-
if (quality && quality !== "fast") {
|
|
108
|
-
params.set("quality", quality);
|
|
109
|
-
} else if (quality === "fast") {
|
|
110
|
-
params.set("quality", "fast");
|
|
111
|
-
}
|
|
107
|
+
if (original) {
|
|
108
|
+
params.set("original", "true");
|
|
109
|
+
}
|
|
112
110
|
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
if (Object.keys(variables).length > 0) {
|
|
112
|
+
params.set("variables", JSON.stringify(variables));
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
params.set("resultId", resultId);
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
return `${baseUrl}?${params.toString()}`;
|
|
@@ -160,11 +161,6 @@ export interface SlopVideoOptions {
|
|
|
160
161
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
161
162
|
*/
|
|
162
163
|
aspectRatio?: VideoAspectRatio;
|
|
163
|
-
/**
|
|
164
|
-
* The AI model to use for generation.
|
|
165
|
-
* Overrides the default model specified in the bucket settings.
|
|
166
|
-
*/
|
|
167
|
-
model?: string;
|
|
168
164
|
/**
|
|
169
165
|
* Dynamic variables to interpolate into the prompt.
|
|
170
166
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -186,6 +182,11 @@ export interface SlopVideoOptions {
|
|
|
186
182
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
187
183
|
*/
|
|
188
184
|
baseUrl?: string;
|
|
185
|
+
/**
|
|
186
|
+
* If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.
|
|
187
|
+
* Defaults to false.
|
|
188
|
+
*/
|
|
189
|
+
original?: boolean;
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
/**
|
|
@@ -200,34 +201,39 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
200
201
|
version,
|
|
201
202
|
resultId,
|
|
202
203
|
aspectRatio = "16:9",
|
|
203
|
-
model,
|
|
204
204
|
quality = "fast",
|
|
205
205
|
variables = {},
|
|
206
206
|
duration = 4,
|
|
207
207
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
|
|
208
|
+
original,
|
|
208
209
|
} = options;
|
|
209
210
|
|
|
210
211
|
const params = new URLSearchParams();
|
|
211
212
|
params.set("bucketId", bucketId);
|
|
212
213
|
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
if (!resultId) {
|
|
215
|
+
if (aspectRatio) {
|
|
216
|
+
params.set("aspectRatio", aspectRatio);
|
|
217
|
+
}
|
|
218
|
+
if (version) {
|
|
219
|
+
params.set("version", String(version));
|
|
220
|
+
}
|
|
221
|
+
if (duration) {
|
|
222
|
+
params.set("duration", String(duration));
|
|
223
|
+
}
|
|
224
|
+
if (quality) {
|
|
225
|
+
params.set("quality", quality);
|
|
226
|
+
}
|
|
216
227
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (version) {
|
|
221
|
-
params.set("version", String(version));
|
|
222
|
-
}
|
|
223
|
-
if (resultId) {
|
|
224
|
-
params.set("resultId", resultId);
|
|
225
|
-
} else {
|
|
226
|
-
params.set("quality", "fast");
|
|
227
|
-
}
|
|
228
|
+
if (original) {
|
|
229
|
+
params.set("original", "true");
|
|
230
|
+
}
|
|
228
231
|
|
|
229
|
-
|
|
230
|
-
|
|
232
|
+
if (Object.keys(variables).length > 0) {
|
|
233
|
+
params.set("variables", JSON.stringify(variables));
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
params.set("resultId", resultId);
|
|
231
237
|
}
|
|
232
238
|
|
|
233
239
|
return `${baseUrl}?${params.toString()}`;
|
|
@@ -270,11 +276,6 @@ export interface SlopTextOptions {
|
|
|
270
276
|
* instead of generating a new one.
|
|
271
277
|
*/
|
|
272
278
|
resultId?: string;
|
|
273
|
-
/**
|
|
274
|
-
* The AI model to use for generation.
|
|
275
|
-
* Overrides the default model specified in the bucket settings.
|
|
276
|
-
*/
|
|
277
|
-
model?: string;
|
|
278
279
|
/**
|
|
279
280
|
* Dynamic variables to interpolate into the prompt.
|
|
280
281
|
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
|
@@ -298,7 +299,6 @@ export function buildTextUrl(options: SlopTextOptions): string {
|
|
|
298
299
|
bucketId,
|
|
299
300
|
version,
|
|
300
301
|
resultId,
|
|
301
|
-
model,
|
|
302
302
|
variables = {},
|
|
303
303
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText",
|
|
304
304
|
} = options;
|
|
@@ -306,18 +306,19 @@ export function buildTextUrl(options: SlopTextOptions): string {
|
|
|
306
306
|
const params = new URLSearchParams();
|
|
307
307
|
params.set("bucketId", bucketId);
|
|
308
308
|
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
params.set("resultId", resultId);
|
|
317
|
-
}
|
|
309
|
+
if (!resultId) {
|
|
310
|
+
if (version) {
|
|
311
|
+
params.set("version", String(version));
|
|
312
|
+
}
|
|
313
|
+
if (resultId) {
|
|
314
|
+
params.set("resultId", resultId);
|
|
315
|
+
}
|
|
318
316
|
|
|
319
|
-
|
|
320
|
-
|
|
317
|
+
if (Object.keys(variables).length > 0) {
|
|
318
|
+
params.set("variables", JSON.stringify(variables));
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
params.set("resultId", resultId);
|
|
321
322
|
}
|
|
322
323
|
|
|
323
324
|
return `${baseUrl}?${params.toString()}`;
|