@slopmachine/core 0.1.16 → 0.1.20
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 +0 -15
- package/dist/index.d.ts +0 -15
- package/dist/index.js +44 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +45 -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" }.
|
|
@@ -78,11 +73,6 @@ interface SlopVideoOptions {
|
|
|
78
73
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
79
74
|
*/
|
|
80
75
|
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
76
|
/**
|
|
87
77
|
* Dynamic variables to interpolate into the prompt.
|
|
88
78
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -135,11 +125,6 @@ interface SlopTextOptions {
|
|
|
135
125
|
* instead of generating a new one.
|
|
136
126
|
*/
|
|
137
127
|
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
128
|
/**
|
|
144
129
|
* Dynamic variables to interpolate into the prompt.
|
|
145
130
|
* 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" }.
|
|
@@ -78,11 +73,6 @@ interface SlopVideoOptions {
|
|
|
78
73
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
79
74
|
*/
|
|
80
75
|
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
76
|
/**
|
|
87
77
|
* Dynamic variables to interpolate into the prompt.
|
|
88
78
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -135,11 +125,6 @@ interface SlopTextOptions {
|
|
|
135
125
|
* instead of generating a new one.
|
|
136
126
|
*/
|
|
137
127
|
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
128
|
/**
|
|
144
129
|
* Dynamic variables to interpolate into the prompt.
|
|
145
130
|
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
package/dist/index.js
CHANGED
|
@@ -47,33 +47,30 @@ function buildImageUrl(options) {
|
|
|
47
47
|
version,
|
|
48
48
|
resultId,
|
|
49
49
|
aspectRatio = "1:1",
|
|
50
|
-
model,
|
|
51
50
|
quality = "fast",
|
|
52
51
|
variables = {},
|
|
53
52
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage"
|
|
54
53
|
} = options;
|
|
55
54
|
const params = new URLSearchParams();
|
|
56
55
|
params.set("bucketId", bucketId);
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
if (!resultId) {
|
|
57
|
+
if (aspectRatio) {
|
|
58
|
+
params.set("aspectRatio", aspectRatio);
|
|
59
|
+
}
|
|
60
|
+
if (version) {
|
|
61
|
+
params.set("version", String(version));
|
|
62
|
+
}
|
|
63
|
+
if (quality && quality !== "fast") {
|
|
64
|
+
params.set("quality", quality);
|
|
65
|
+
} else if (quality === "fast") {
|
|
66
|
+
params.set("quality", "fast");
|
|
67
|
+
}
|
|
68
|
+
if (Object.keys(variables).length > 0) {
|
|
69
|
+
params.set("variables", JSON.stringify(variables));
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
67
72
|
params.set("resultId", resultId);
|
|
68
73
|
}
|
|
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
74
|
return `${baseUrl}?${params.toString()}`;
|
|
78
75
|
}
|
|
79
76
|
function preloadImage(options) {
|
|
@@ -94,7 +91,6 @@ function buildVideoUrl(options) {
|
|
|
94
91
|
version,
|
|
95
92
|
resultId,
|
|
96
93
|
aspectRatio = "16:9",
|
|
97
|
-
model,
|
|
98
94
|
quality = "fast",
|
|
99
95
|
variables = {},
|
|
100
96
|
duration = 4,
|
|
@@ -102,22 +98,24 @@ function buildVideoUrl(options) {
|
|
|
102
98
|
} = options;
|
|
103
99
|
const params = new URLSearchParams();
|
|
104
100
|
params.set("bucketId", bucketId);
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
if (!resultId) {
|
|
102
|
+
if (aspectRatio) {
|
|
103
|
+
params.set("aspectRatio", aspectRatio);
|
|
104
|
+
}
|
|
105
|
+
if (version) {
|
|
106
|
+
params.set("version", String(version));
|
|
107
|
+
}
|
|
108
|
+
if (duration) {
|
|
109
|
+
params.set("duration", String(duration));
|
|
110
|
+
}
|
|
111
|
+
if (quality) {
|
|
112
|
+
params.set("quality", quality);
|
|
113
|
+
}
|
|
114
|
+
if (Object.keys(variables).length > 0) {
|
|
115
|
+
params.set("variables", JSON.stringify(variables));
|
|
116
|
+
}
|
|
116
117
|
} else {
|
|
117
|
-
params.set("
|
|
118
|
-
}
|
|
119
|
-
if (Object.keys(variables).length > 0) {
|
|
120
|
-
params.set("variables", JSON.stringify(variables));
|
|
118
|
+
params.set("resultId", resultId);
|
|
121
119
|
}
|
|
122
120
|
return `${baseUrl}?${params.toString()}`;
|
|
123
121
|
}
|
|
@@ -135,24 +133,24 @@ function buildTextUrl(options) {
|
|
|
135
133
|
bucketId,
|
|
136
134
|
version,
|
|
137
135
|
resultId,
|
|
138
|
-
model,
|
|
139
136
|
variables = {},
|
|
140
137
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
141
138
|
} = options;
|
|
142
139
|
const params = new URLSearchParams();
|
|
143
140
|
params.set("bucketId", bucketId);
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
if (!resultId) {
|
|
142
|
+
if (version) {
|
|
143
|
+
params.set("version", String(version));
|
|
144
|
+
}
|
|
145
|
+
if (resultId) {
|
|
146
|
+
params.set("resultId", resultId);
|
|
147
|
+
}
|
|
148
|
+
if (Object.keys(variables).length > 0) {
|
|
149
|
+
params.set("variables", JSON.stringify(variables));
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
151
152
|
params.set("resultId", resultId);
|
|
152
153
|
}
|
|
153
|
-
if (Object.keys(variables).length > 0) {
|
|
154
|
-
params.set("variables", JSON.stringify(variables));
|
|
155
|
-
}
|
|
156
154
|
return `${baseUrl}?${params.toString()}`;
|
|
157
155
|
}
|
|
158
156
|
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,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;AAAA,IACA,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,aAAa;AACf,WAAO,IAAI,eAAe,WAAW;AAAA,EACvC;AAEA,MAAI,OAAO;AACT,WAAO,IAAI,SAA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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\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 } = 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 (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\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 } = 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 (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;AAkDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI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ACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,CAAC,UAAU;AACb,QAAI,SAAS;AACX,aAAO,IAAI,WAAW,OAAO,OAAO,CAAC;AAAA,IACvC;AACA,QAAI,UAAU;AACZ,aAAO,IAAI,YAAY,QAAQ;AAAA,IACjC;AAEA,QAAI,OAAO,KAAK,SAAS,EAAE,SAAS,GAAG;AACrC,aAAO,IAAI,aAAa,KAAK,UAAU,SAAS,CAAC;AAAA,IACnD;AAAA,EACF,OAAO;AACL,WAAO,IAAI,YAAY,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/dist/index.mjs
CHANGED
|
@@ -17,33 +17,30 @@ function buildImageUrl(options) {
|
|
|
17
17
|
version,
|
|
18
18
|
resultId,
|
|
19
19
|
aspectRatio = "1:1",
|
|
20
|
-
model,
|
|
21
20
|
quality = "fast",
|
|
22
21
|
variables = {},
|
|
23
22
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage"
|
|
24
23
|
} = options;
|
|
25
24
|
const params = new URLSearchParams();
|
|
26
25
|
params.set("bucketId", bucketId);
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
if (!resultId) {
|
|
27
|
+
if (aspectRatio) {
|
|
28
|
+
params.set("aspectRatio", aspectRatio);
|
|
29
|
+
}
|
|
30
|
+
if (version) {
|
|
31
|
+
params.set("version", String(version));
|
|
32
|
+
}
|
|
33
|
+
if (quality && quality !== "fast") {
|
|
34
|
+
params.set("quality", quality);
|
|
35
|
+
} else if (quality === "fast") {
|
|
36
|
+
params.set("quality", "fast");
|
|
37
|
+
}
|
|
38
|
+
if (Object.keys(variables).length > 0) {
|
|
39
|
+
params.set("variables", JSON.stringify(variables));
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
37
42
|
params.set("resultId", resultId);
|
|
38
43
|
}
|
|
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
44
|
return `${baseUrl}?${params.toString()}`;
|
|
48
45
|
}
|
|
49
46
|
function preloadImage(options) {
|
|
@@ -64,7 +61,6 @@ function buildVideoUrl(options) {
|
|
|
64
61
|
version,
|
|
65
62
|
resultId,
|
|
66
63
|
aspectRatio = "16:9",
|
|
67
|
-
model,
|
|
68
64
|
quality = "fast",
|
|
69
65
|
variables = {},
|
|
70
66
|
duration = 4,
|
|
@@ -72,22 +68,24 @@ function buildVideoUrl(options) {
|
|
|
72
68
|
} = options;
|
|
73
69
|
const params = new URLSearchParams();
|
|
74
70
|
params.set("bucketId", bucketId);
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
if (!resultId) {
|
|
72
|
+
if (aspectRatio) {
|
|
73
|
+
params.set("aspectRatio", aspectRatio);
|
|
74
|
+
}
|
|
75
|
+
if (version) {
|
|
76
|
+
params.set("version", String(version));
|
|
77
|
+
}
|
|
78
|
+
if (duration) {
|
|
79
|
+
params.set("duration", String(duration));
|
|
80
|
+
}
|
|
81
|
+
if (quality) {
|
|
82
|
+
params.set("quality", quality);
|
|
83
|
+
}
|
|
84
|
+
if (Object.keys(variables).length > 0) {
|
|
85
|
+
params.set("variables", JSON.stringify(variables));
|
|
86
|
+
}
|
|
86
87
|
} else {
|
|
87
|
-
params.set("
|
|
88
|
-
}
|
|
89
|
-
if (Object.keys(variables).length > 0) {
|
|
90
|
-
params.set("variables", JSON.stringify(variables));
|
|
88
|
+
params.set("resultId", resultId);
|
|
91
89
|
}
|
|
92
90
|
return `${baseUrl}?${params.toString()}`;
|
|
93
91
|
}
|
|
@@ -105,24 +103,24 @@ function buildTextUrl(options) {
|
|
|
105
103
|
bucketId,
|
|
106
104
|
version,
|
|
107
105
|
resultId,
|
|
108
|
-
model,
|
|
109
106
|
variables = {},
|
|
110
107
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
111
108
|
} = options;
|
|
112
109
|
const params = new URLSearchParams();
|
|
113
110
|
params.set("bucketId", bucketId);
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
if (!resultId) {
|
|
112
|
+
if (version) {
|
|
113
|
+
params.set("version", String(version));
|
|
114
|
+
}
|
|
115
|
+
if (resultId) {
|
|
116
|
+
params.set("resultId", resultId);
|
|
117
|
+
}
|
|
118
|
+
if (Object.keys(variables).length > 0) {
|
|
119
|
+
params.set("variables", JSON.stringify(variables));
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
121
122
|
params.set("resultId", resultId);
|
|
122
123
|
}
|
|
123
|
-
if (Object.keys(variables).length > 0) {
|
|
124
|
-
params.set("variables", JSON.stringify(variables));
|
|
125
|
-
}
|
|
126
124
|
return `${baseUrl}?${params.toString()}`;
|
|
127
125
|
}
|
|
128
126
|
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,kB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;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;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\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 } = 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 (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\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 } = 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 (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":";AAkDO,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,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,CAAC,UAAU;AACb,QAAI,aAAa;AACf,aAAO,IAAI,eAAe,WAAW;AAAA,IACvC;AACA,QAAI,SAAS;AACX,aAAO,IAAI,WAAW,OAA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AAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slopmachine/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "The official Core / VanillaJS SDK for Slop Machine",
|
|
5
5
|
"llms": "https://slopmachine-dev.github.io/slopmachine-sdk/llms.txt",
|
|
6
6
|
"llmsFull": "https://slopmachine-dev.github.io/slopmachine-sdk/llms-full.txt",
|
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" }.
|
|
@@ -82,7 +77,6 @@ export function buildImageUrl(options: SlopImageOptions): string {
|
|
|
82
77
|
version,
|
|
83
78
|
resultId,
|
|
84
79
|
aspectRatio = "1:1",
|
|
85
|
-
model,
|
|
86
80
|
quality = "fast",
|
|
87
81
|
variables = {},
|
|
88
82
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
|
|
@@ -91,28 +85,25 @@ export function buildImageUrl(options: SlopImageOptions): string {
|
|
|
91
85
|
const params = new URLSearchParams();
|
|
92
86
|
params.set("bucketId", bucketId);
|
|
93
87
|
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
if (!resultId) {
|
|
89
|
+
if (aspectRatio) {
|
|
90
|
+
params.set("aspectRatio", aspectRatio);
|
|
91
|
+
}
|
|
92
|
+
if (version) {
|
|
93
|
+
params.set("version", String(version));
|
|
94
|
+
}
|
|
95
|
+
if (quality && quality !== "fast") {
|
|
96
|
+
params.set("quality", quality);
|
|
97
|
+
} else if (quality === "fast") {
|
|
98
|
+
params.set("quality", "fast");
|
|
99
|
+
}
|
|
97
100
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
params.set("version", String(version));
|
|
103
|
-
}
|
|
104
|
-
if (resultId) {
|
|
101
|
+
if (Object.keys(variables).length > 0) {
|
|
102
|
+
params.set("variables", JSON.stringify(variables));
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
105
|
params.set("resultId", resultId);
|
|
106
106
|
}
|
|
107
|
-
if (quality && quality !== "fast") {
|
|
108
|
-
params.set("quality", quality);
|
|
109
|
-
} else if (quality === "fast") {
|
|
110
|
-
params.set("quality", "fast");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (Object.keys(variables).length > 0) {
|
|
114
|
-
params.set("variables", JSON.stringify(variables));
|
|
115
|
-
}
|
|
116
107
|
|
|
117
108
|
return `${baseUrl}?${params.toString()}`;
|
|
118
109
|
}
|
|
@@ -160,11 +151,6 @@ export interface SlopVideoOptions {
|
|
|
160
151
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
161
152
|
*/
|
|
162
153
|
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
154
|
/**
|
|
169
155
|
* Dynamic variables to interpolate into the prompt.
|
|
170
156
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -200,7 +186,6 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
200
186
|
version,
|
|
201
187
|
resultId,
|
|
202
188
|
aspectRatio = "16:9",
|
|
203
|
-
model,
|
|
204
189
|
quality = "fast",
|
|
205
190
|
variables = {},
|
|
206
191
|
duration = 4,
|
|
@@ -210,24 +195,25 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
210
195
|
const params = new URLSearchParams();
|
|
211
196
|
params.set("bucketId", bucketId);
|
|
212
197
|
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
198
|
+
if (!resultId) {
|
|
199
|
+
if (aspectRatio) {
|
|
200
|
+
params.set("aspectRatio", aspectRatio);
|
|
201
|
+
}
|
|
202
|
+
if (version) {
|
|
203
|
+
params.set("version", String(version));
|
|
204
|
+
}
|
|
205
|
+
if (duration) {
|
|
206
|
+
params.set("duration", String(duration));
|
|
207
|
+
}
|
|
208
|
+
if (quality) {
|
|
209
|
+
params.set("quality", quality);
|
|
210
|
+
}
|
|
216
211
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (version) {
|
|
221
|
-
params.set("version", String(version));
|
|
222
|
-
}
|
|
223
|
-
if (resultId) {
|
|
224
|
-
params.set("resultId", resultId);
|
|
212
|
+
if (Object.keys(variables).length > 0) {
|
|
213
|
+
params.set("variables", JSON.stringify(variables));
|
|
214
|
+
}
|
|
225
215
|
} else {
|
|
226
|
-
params.set("
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (Object.keys(variables).length > 0) {
|
|
230
|
-
params.set("variables", JSON.stringify(variables));
|
|
216
|
+
params.set("resultId", resultId);
|
|
231
217
|
}
|
|
232
218
|
|
|
233
219
|
return `${baseUrl}?${params.toString()}`;
|
|
@@ -270,11 +256,6 @@ export interface SlopTextOptions {
|
|
|
270
256
|
* instead of generating a new one.
|
|
271
257
|
*/
|
|
272
258
|
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
259
|
/**
|
|
279
260
|
* Dynamic variables to interpolate into the prompt.
|
|
280
261
|
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
|
@@ -298,7 +279,6 @@ export function buildTextUrl(options: SlopTextOptions): string {
|
|
|
298
279
|
bucketId,
|
|
299
280
|
version,
|
|
300
281
|
resultId,
|
|
301
|
-
model,
|
|
302
282
|
variables = {},
|
|
303
283
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText",
|
|
304
284
|
} = options;
|
|
@@ -306,18 +286,19 @@ export function buildTextUrl(options: SlopTextOptions): string {
|
|
|
306
286
|
const params = new URLSearchParams();
|
|
307
287
|
params.set("bucketId", bucketId);
|
|
308
288
|
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
params.set("resultId", resultId);
|
|
317
|
-
}
|
|
289
|
+
if (!resultId) {
|
|
290
|
+
if (version) {
|
|
291
|
+
params.set("version", String(version));
|
|
292
|
+
}
|
|
293
|
+
if (resultId) {
|
|
294
|
+
params.set("resultId", resultId);
|
|
295
|
+
}
|
|
318
296
|
|
|
319
|
-
|
|
320
|
-
|
|
297
|
+
if (Object.keys(variables).length > 0) {
|
|
298
|
+
params.set("variables", JSON.stringify(variables));
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
params.set("resultId", resultId);
|
|
321
302
|
}
|
|
322
303
|
|
|
323
304
|
return `${baseUrl}?${params.toString()}`;
|