@slopmachine/core 0.1.25 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 * 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 * Array of attachment URLs to include with the request.\n */\n attachments?: 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 original,\n attachments,\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\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\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 * Array of attachment URLs to include with the request.\n */\n attachments?: 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 original,\n attachments,\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\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\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 * Array of attachment URLs to include with the request.\n */\n attachments?: 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 attachments,\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\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\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\n/**\n * Uploads a base64 encoded file as a temporary attachment to be used in generation requests.\n *\n * @param base64 - The base64 encoded file data (without the data:mime/type;base64, prefix).\n * @param mimeType - The MIME type of the file.\n * @returns A promise that resolves to an object containing the URL of the uploaded attachment.\n */\nexport async function uploadTempAttachment(\n base64: string,\n mimeType: string,\n): Promise<{ url: string }> {\n const response = await fetch(\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/uploadTempAttachment\",\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({ data: { base64, mimeType } }),\n },\n );\n if (!response.ok) {\n throw new Error(`Failed to upload attachment: ${response.statusText}`);\n }\n const json = await response.json();\n if (json.error) {\n throw new Error(\n `Failed to upload attachment: ${json.error.message || JSON.stringify(json.error)}`,\n );\n }\n return { url: json.result.url };\n}\n"],"mappings":";AA2DO,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;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M,IAAI,MAAM,gCAAgC,SAAS,UAAU,EAAE;AAAA,EACvE;AACA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,MAAI,KAAK,OAAO;AACd,UAAM,IAAI;AAAA,MACR,gCAAgC,KAAK,MAAM,WAAW,KAAK,UAAU,KAAK,KAAK,CAAC;AAAA,IAClF;AAAA,EACF;AACA,SAAO,EAAE,KAAK,KAAK,OAAO,IAAI;AAChC;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { AspectRatio as ImageAspectRatio, VideoAspectRatio } from \"@pixerate/schemas\";\nexport type { ImageAspectRatio, VideoAspectRatio };\n\nexport interface PipelineStepResult {\n stepId: string;\n stepName?: string;\n type: string;\n outputUrl?: string;\n outputText?: string;\n outputData?: any;\n computeTimeMs?: number;\n fuelCost?: number;\n error?: string;\n}\n\nexport interface PipelineResult {\n id: string;\n pipelineId: string;\n siloId: string;\n url?: string;\n text?: string;\n data?: any;\n resultType: string;\n status: \"completed\" | \"failed\" | \"pending\";\n stepResults: PipelineStepResult[];\n totalComputeTimeMs: number;\n totalFuelCost: number;\n metadata?: Record<string, any>;\n timestamp: any;\n error?: string;\n}\n\nexport interface SlopPipelineOptions {\n /**\n * The unique identifier of the pipeline to execute.\n */\n pipelineId: string;\n /**\n * Optional silo identifier for direct pipeline path resolution.\n */\n siloId?: string;\n /**\n * Dynamic runtime prompt to feed into the pipeline.\n */\n prompt?: string;\n /**\n * Variables to interpolate into prompt or step configs.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * Arbitrary user metadata to attach to the pipeline result document.\n */\n metadata?: Record<string, any>;\n /**\n * Whether to wait for full execution (default true) or return a job ID immediately.\n */\n sync?: boolean;\n /**\n * Whether to redirect to the primary media output URL upon completion.\n */\n redirect?: boolean;\n /**\n * Result ID to retrieve a specific previously generated result.\n */\n resultId?: string;\n /**\n * Base URL for the renderPipeline cloud function endpoint.\n */\n baseUrl?: string;\n}\n\nexport interface ExecutePipelineOptions {\n /**\n * The unique identifier of the pipeline to execute.\n */\n pipelineId: string;\n /**\n * Optional silo identifier for direct pipeline path resolution.\n */\n siloId?: string;\n /**\n * Dynamic runtime prompt to feed into the pipeline.\n */\n prompt?: string;\n /**\n * Variables to interpolate into prompt or step configs.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * Arbitrary user metadata to attach to the pipeline result document.\n */\n metadata?: Record<string, any>;\n /**\n * Base URL for the renderPipeline cloud function endpoint.\n */\n baseUrl?: string;\n}\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n * Required when using a bucket unless pipelineId is provided.\n */\n bucketId?: string;\n /**\n * The unique identifier of your Slop Machine pipeline.\n * Required when targeting a pipeline instead of a bucket.\n */\n pipelineId?: string;\n /**\n * Optional silo identifier.\n */\n siloId?: string;\n /**\n * Dynamic runtime prompt (used when targeting a pipeline).\n */\n prompt?: string;\n /**\n * Arbitrary user metadata to attach to the generation request / result document.\n */\n metadata?: Record<string, any>;\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 * Array of attachment URLs to include with the request.\n */\n attachments?: 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 * Supports both standard Buckets (via `bucketId`) and multi-step Pipelines (via `pipelineId`).\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 pipelineId,\n siloId,\n prompt,\n metadata,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl,\n original,\n attachments,\n } = options;\n\n if (pipelineId) {\n const endpoint =\n baseUrl ||\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline\";\n const params = new URLSearchParams();\n params.set(\"pipelineId\", pipelineId);\n params.set(\"redirect\", \"true\");\n\n if (siloId) params.set(\"siloId\", siloId);\n if (prompt) params.set(\"prompt\", prompt);\n if (resultId) params.set(\"resultId\", resultId);\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n if (metadata && Object.keys(metadata).length > 0) {\n params.set(\"metadata\", JSON.stringify(metadata));\n }\n\n return `${endpoint}?${params.toString()}`;\n }\n\n const endpoint =\n baseUrl ||\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\";\n const params = new URLSearchParams();\n if (bucketId) {\n params.set(\"bucketId\", bucketId);\n }\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\n if (metadata && Object.keys(metadata).length > 0) {\n params.set(\"metadata\", JSON.stringify(metadata));\n }\n\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${endpoint}?${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 interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n * Required when using a bucket unless pipelineId is provided.\n */\n bucketId?: string;\n /**\n * The unique identifier of your Slop Machine pipeline.\n * Required when targeting a pipeline instead of a bucket.\n */\n pipelineId?: string;\n /**\n * Optional silo identifier.\n */\n siloId?: string;\n /**\n * Dynamic runtime prompt (used when targeting a pipeline).\n */\n prompt?: string;\n /**\n * Arbitrary user metadata to attach to the generation request / result document.\n */\n metadata?: Record<string, any>;\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 * Array of attachment URLs to include with the request.\n */\n attachments?: string[];\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * Supports both standard Buckets (via `bucketId`) and multi-step Pipelines (via `pipelineId`).\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 pipelineId,\n siloId,\n prompt,\n metadata,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl,\n original,\n attachments,\n } = options;\n\n if (pipelineId) {\n const endpoint =\n baseUrl ||\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline\";\n const params = new URLSearchParams();\n params.set(\"pipelineId\", pipelineId);\n params.set(\"redirect\", \"true\");\n\n if (siloId) params.set(\"siloId\", siloId);\n if (prompt) params.set(\"prompt\", prompt);\n if (resultId) params.set(\"resultId\", resultId);\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n if (metadata && Object.keys(metadata).length > 0) {\n params.set(\"metadata\", JSON.stringify(metadata));\n }\n\n return `${endpoint}?${params.toString()}`;\n }\n\n const endpoint =\n baseUrl ||\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\";\n const params = new URLSearchParams();\n if (bucketId) {\n params.set(\"bucketId\", bucketId);\n }\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\n if (metadata && Object.keys(metadata).length > 0) {\n params.set(\"metadata\", JSON.stringify(metadata));\n }\n\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${endpoint}?${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 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 * Required when using a bucket unless pipelineId is provided.\n */\n bucketId?: string;\n /**\n * The unique identifier of your Slop Machine pipeline.\n * Required when targeting a pipeline instead of a bucket.\n */\n pipelineId?: string;\n /**\n * Optional silo identifier.\n */\n siloId?: string;\n /**\n * Dynamic runtime prompt (used when targeting a pipeline).\n */\n prompt?: string;\n /**\n * Arbitrary user metadata to attach to the generation request / result document.\n */\n metadata?: Record<string, any>;\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 * Array of attachment URLs to include with the request.\n */\n attachments?: string[];\n}\n\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * Supports both standard Buckets (via `bucketId`) and multi-step Pipelines (via `pipelineId`).\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 pipelineId,\n siloId,\n prompt,\n metadata,\n version,\n resultId,\n variables = {},\n baseUrl,\n attachments,\n } = options;\n\n if (pipelineId) {\n const endpoint =\n baseUrl ||\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline\";\n const params = new URLSearchParams();\n params.set(\"pipelineId\", pipelineId);\n params.set(\"sync\", \"true\");\n\n if (siloId) params.set(\"siloId\", siloId);\n if (prompt) params.set(\"prompt\", prompt);\n if (resultId) params.set(\"resultId\", resultId);\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n if (metadata && Object.keys(metadata).length > 0) {\n params.set(\"metadata\", JSON.stringify(metadata));\n }\n\n return `${endpoint}?${params.toString()}`;\n }\n\n const endpoint =\n baseUrl ||\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\";\n const params = new URLSearchParams();\n if (bucketId) {\n params.set(\"bucketId\", bucketId);\n }\n\n if (!resultId) {\n if (version) {\n params.set(\"version\", String(version));\n }\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n if (metadata && Object.keys(metadata).length > 0) {\n params.set(\"metadata\", JSON.stringify(metadata));\n }\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${endpoint}?${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(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\n/**\n * Builds a URL to execute or inspect a multi-step Pipeline from Slop Machine.\n *\n * @param options - Configuration options for the pipeline execution.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildPipelineUrl(options: SlopPipelineOptions): string {\n const {\n pipelineId,\n siloId,\n prompt,\n variables = {},\n metadata = {},\n sync = true,\n redirect = false,\n resultId,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"pipelineId\", pipelineId);\n\n if (siloId) params.set(\"siloId\", siloId);\n if (prompt) params.set(\"prompt\", prompt);\n if (resultId) params.set(\"resultId\", resultId);\n if (sync !== undefined) params.set(\"sync\", String(sync));\n if (redirect) params.set(\"redirect\", \"true\");\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n if (Object.keys(metadata).length > 0) {\n params.set(\"metadata\", JSON.stringify(metadata));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Executes a Slop Machine multi-step Pipeline programmatically and returns the full typed result payload.\n *\n * @param options - Execution parameters including the pipelineId and runtime prompt/variables/metadata.\n * @returns A promise resolving to the completed PipelineResult document.\n */\nexport async function executePipeline(\n options: ExecutePipelineOptions,\n): Promise<PipelineResult> {\n const {\n pipelineId,\n siloId,\n prompt,\n variables,\n metadata,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline\",\n } = options;\n\n const response = await fetch(baseUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n pipelineId,\n ...(siloId ? { siloId } : {}),\n ...(prompt ? { prompt } : {}),\n variables,\n metadata,\n sync: true,\n }),\n });\n\n if (!response.ok) {\n let errorDetail = response.statusText;\n try {\n const errorJson = await response.json();\n if (errorJson.error) {\n errorDetail = errorJson.error;\n }\n } catch {\n // Use statusText\n }\n throw new Error(\n `Pipeline execution failed (${response.status}): ${errorDetail}`,\n );\n }\n\n return (await response.json()) as PipelineResult;\n}\n\n/**\n * Uploads a base64 encoded file as a temporary attachment to be used in generation requests.\n *\n * @param base64 - The base64 encoded file data (without the data:mime/type;base64, prefix).\n * @param mimeType - The MIME type of the file.\n * @returns A promise that resolves to an object containing the URL of the uploaded attachment.\n */\nexport async function uploadTempAttachment(\n base64: string,\n mimeType: string,\n): Promise<{ url: string }> {\n const response = await fetch(\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/uploadTempAttachment\",\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({ data: { base64, mimeType } }),\n },\n );\n if (!response.ok) {\n throw new Error(`Failed to upload attachment: ${response.statusText}`);\n }\n const json = await response.json();\n if (json.error) {\n throw new Error(\n `Failed to upload attachment: ${json.error.message || JSON.stringify(json.error)}`,\n );\n }\n return { url: json.result.url };\n}\n"],"mappings":";AAmKO,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;AAUO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,UAA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,UAAM,IAAI,MAAM,gCAAgC,SAAS,UAAU,EAAE;AAAA,EACvE;AACA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,MAAI,KAAK,OAAO;AACd,UAAM,IAAI;AAAA,MACR,gCAAgC,KAAK,MAAM,WAAW,KAAK,UAAU,KAAK,KAAK,CAAC;AAAA,IAClF;AAAA,EACF;AACA,SAAO,EAAE,KAAK,KAAK,OAAO,IAAI;AAChC;","names":["endpoint","params"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slopmachine/core",
3
- "version": "0.1.25",
3
+ "version": "0.2.0",
4
4
  "description": "The official Core / VanillaJS SDK for Slop Machine",
5
5
  "llms": "https://docs.slopmachine.dev/llms.txt",
6
6
  "llmsFull": "https://docs.slopmachine.dev/llms-full.txt",
@@ -27,5 +27,8 @@
27
27
  "tsup": "^8.0.0",
28
28
  "typescript": "^5.0.0"
29
29
  },
30
+ "dependencies": {
31
+ "@pixerate/schemas": "^1.1.0"
32
+ },
30
33
  "license": "MIT"
31
34
  }
package/src/index.ts CHANGED
@@ -1,20 +1,124 @@
1
- export type ImageAspectRatio =
2
- | "1:1"
3
- | "2:3"
4
- | "3:2"
5
- | "3:4"
6
- | "4:3"
7
- | "4:5"
8
- | "5:4"
9
- | "9:16"
10
- | "16:9"
11
- | "21:9";
1
+ import { AspectRatio as ImageAspectRatio, VideoAspectRatio } from "@pixerate/schemas";
2
+ export type { ImageAspectRatio, VideoAspectRatio };
3
+
4
+ export interface PipelineStepResult {
5
+ stepId: string;
6
+ stepName?: string;
7
+ type: string;
8
+ outputUrl?: string;
9
+ outputText?: string;
10
+ outputData?: any;
11
+ computeTimeMs?: number;
12
+ fuelCost?: number;
13
+ error?: string;
14
+ }
15
+
16
+ export interface PipelineResult {
17
+ id: string;
18
+ pipelineId: string;
19
+ siloId: string;
20
+ url?: string;
21
+ text?: string;
22
+ data?: any;
23
+ resultType: string;
24
+ status: "completed" | "failed" | "pending";
25
+ stepResults: PipelineStepResult[];
26
+ totalComputeTimeMs: number;
27
+ totalFuelCost: number;
28
+ metadata?: Record<string, any>;
29
+ timestamp: any;
30
+ error?: string;
31
+ }
32
+
33
+ export interface SlopPipelineOptions {
34
+ /**
35
+ * The unique identifier of the pipeline to execute.
36
+ */
37
+ pipelineId: string;
38
+ /**
39
+ * Optional silo identifier for direct pipeline path resolution.
40
+ */
41
+ siloId?: string;
42
+ /**
43
+ * Dynamic runtime prompt to feed into the pipeline.
44
+ */
45
+ prompt?: string;
46
+ /**
47
+ * Variables to interpolate into prompt or step configs.
48
+ */
49
+ variables?: Record<string, string | number | undefined | null>;
50
+ /**
51
+ * Arbitrary user metadata to attach to the pipeline result document.
52
+ */
53
+ metadata?: Record<string, any>;
54
+ /**
55
+ * Whether to wait for full execution (default true) or return a job ID immediately.
56
+ */
57
+ sync?: boolean;
58
+ /**
59
+ * Whether to redirect to the primary media output URL upon completion.
60
+ */
61
+ redirect?: boolean;
62
+ /**
63
+ * Result ID to retrieve a specific previously generated result.
64
+ */
65
+ resultId?: string;
66
+ /**
67
+ * Base URL for the renderPipeline cloud function endpoint.
68
+ */
69
+ baseUrl?: string;
70
+ }
71
+
72
+ export interface ExecutePipelineOptions {
73
+ /**
74
+ * The unique identifier of the pipeline to execute.
75
+ */
76
+ pipelineId: string;
77
+ /**
78
+ * Optional silo identifier for direct pipeline path resolution.
79
+ */
80
+ siloId?: string;
81
+ /**
82
+ * Dynamic runtime prompt to feed into the pipeline.
83
+ */
84
+ prompt?: string;
85
+ /**
86
+ * Variables to interpolate into prompt or step configs.
87
+ */
88
+ variables?: Record<string, string | number | undefined | null>;
89
+ /**
90
+ * Arbitrary user metadata to attach to the pipeline result document.
91
+ */
92
+ metadata?: Record<string, any>;
93
+ /**
94
+ * Base URL for the renderPipeline cloud function endpoint.
95
+ */
96
+ baseUrl?: string;
97
+ }
12
98
 
13
99
  export interface SlopImageOptions {
14
100
  /**
15
101
  * The unique identifier of your Slop Machine bucket.
102
+ * Required when using a bucket unless pipelineId is provided.
103
+ */
104
+ bucketId?: string;
105
+ /**
106
+ * The unique identifier of your Slop Machine pipeline.
107
+ * Required when targeting a pipeline instead of a bucket.
108
+ */
109
+ pipelineId?: string;
110
+ /**
111
+ * Optional silo identifier.
16
112
  */
17
- bucketId: string;
113
+ siloId?: string;
114
+ /**
115
+ * Dynamic runtime prompt (used when targeting a pipeline).
116
+ */
117
+ prompt?: string;
118
+ /**
119
+ * Arbitrary user metadata to attach to the generation request / result document.
120
+ */
121
+ metadata?: Record<string, any>;
18
122
  /**
19
123
  * The specific version of the prompt/settings to use.
20
124
  * If omitted, the latest version will be used.
@@ -77,24 +181,57 @@ export function interpolatePrompt(
77
181
  /**
78
182
  * Builds a URL to render or retrieve an image from Slop Machine.
79
183
  *
184
+ * Supports both standard Buckets (via `bucketId`) and multi-step Pipelines (via `pipelineId`).
185
+ *
80
186
  * @param options - Configuration options for the image generation.
81
187
  * @returns A string containing the fully constructed URL.
82
188
  */
83
189
  export function buildImageUrl(options: SlopImageOptions): string {
84
190
  const {
85
191
  bucketId,
192
+ pipelineId,
193
+ siloId,
194
+ prompt,
195
+ metadata,
86
196
  version,
87
197
  resultId,
88
198
  aspectRatio = "1:1",
89
199
  quality = "fast",
90
200
  variables = {},
91
- baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
201
+ baseUrl,
92
202
  original,
93
203
  attachments,
94
204
  } = options;
95
205
 
206
+ if (pipelineId) {
207
+ const endpoint =
208
+ baseUrl ||
209
+ "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline";
210
+ const params = new URLSearchParams();
211
+ params.set("pipelineId", pipelineId);
212
+ params.set("redirect", "true");
213
+
214
+ if (siloId) params.set("siloId", siloId);
215
+ if (prompt) params.set("prompt", prompt);
216
+ if (resultId) params.set("resultId", resultId);
217
+
218
+ if (Object.keys(variables).length > 0) {
219
+ params.set("variables", JSON.stringify(variables));
220
+ }
221
+ if (metadata && Object.keys(metadata).length > 0) {
222
+ params.set("metadata", JSON.stringify(metadata));
223
+ }
224
+
225
+ return `${endpoint}?${params.toString()}`;
226
+ }
227
+
228
+ const endpoint =
229
+ baseUrl ||
230
+ "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage";
96
231
  const params = new URLSearchParams();
97
- params.set("bucketId", bucketId);
232
+ if (bucketId) {
233
+ params.set("bucketId", bucketId);
234
+ }
98
235
 
99
236
  if (!resultId) {
100
237
  if (aspectRatio) {
@@ -117,6 +254,10 @@ export function buildImageUrl(options: SlopImageOptions): string {
117
254
  params.set("variables", JSON.stringify(variables));
118
255
  }
119
256
 
257
+ if (metadata && Object.keys(metadata).length > 0) {
258
+ params.set("metadata", JSON.stringify(metadata));
259
+ }
260
+
120
261
  if (attachments && attachments.length > 0) {
121
262
  params.set("attachments", JSON.stringify(attachments));
122
263
  }
@@ -124,7 +265,7 @@ export function buildImageUrl(options: SlopImageOptions): string {
124
265
  params.set("resultId", resultId);
125
266
  }
126
267
 
127
- return `${baseUrl}?${params.toString()}`;
268
+ return `${endpoint}?${params.toString()}`;
128
269
  }
129
270
 
130
271
  /**
@@ -148,13 +289,29 @@ export function preloadImage(options: SlopImageOptions): Promise<void> {
148
289
  });
149
290
  }
150
291
 
151
- export type VideoAspectRatio = "9:16" | "16:9";
152
-
153
292
  export interface SlopVideoOptions {
154
293
  /**
155
294
  * The unique identifier of your Slop Machine bucket.
295
+ * Required when using a bucket unless pipelineId is provided.
296
+ */
297
+ bucketId?: string;
298
+ /**
299
+ * The unique identifier of your Slop Machine pipeline.
300
+ * Required when targeting a pipeline instead of a bucket.
301
+ */
302
+ pipelineId?: string;
303
+ /**
304
+ * Optional silo identifier.
305
+ */
306
+ siloId?: string;
307
+ /**
308
+ * Dynamic runtime prompt (used when targeting a pipeline).
309
+ */
310
+ prompt?: string;
311
+ /**
312
+ * Arbitrary user metadata to attach to the generation request / result document.
156
313
  */
157
- bucketId: string;
314
+ metadata?: Record<string, any>;
158
315
  /**
159
316
  * The specific version of the prompt/settings to use.
160
317
  * If omitted, the latest version will be used.
@@ -205,25 +362,58 @@ export interface SlopVideoOptions {
205
362
  /**
206
363
  * Builds a URL to render or retrieve a video from Slop Machine.
207
364
  *
365
+ * Supports both standard Buckets (via `bucketId`) and multi-step Pipelines (via `pipelineId`).
366
+ *
208
367
  * @param options - Configuration options for the video generation.
209
368
  * @returns A string containing the fully constructed URL.
210
369
  */
211
370
  export function buildVideoUrl(options: SlopVideoOptions): string {
212
371
  const {
213
372
  bucketId,
373
+ pipelineId,
374
+ siloId,
375
+ prompt,
376
+ metadata,
214
377
  version,
215
378
  resultId,
216
379
  aspectRatio = "16:9",
217
380
  quality = "fast",
218
381
  variables = {},
219
382
  duration = 4,
220
- baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
383
+ baseUrl,
221
384
  original,
222
385
  attachments,
223
386
  } = options;
224
387
 
388
+ if (pipelineId) {
389
+ const endpoint =
390
+ baseUrl ||
391
+ "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline";
392
+ const params = new URLSearchParams();
393
+ params.set("pipelineId", pipelineId);
394
+ params.set("redirect", "true");
395
+
396
+ if (siloId) params.set("siloId", siloId);
397
+ if (prompt) params.set("prompt", prompt);
398
+ if (resultId) params.set("resultId", resultId);
399
+
400
+ if (Object.keys(variables).length > 0) {
401
+ params.set("variables", JSON.stringify(variables));
402
+ }
403
+ if (metadata && Object.keys(metadata).length > 0) {
404
+ params.set("metadata", JSON.stringify(metadata));
405
+ }
406
+
407
+ return `${endpoint}?${params.toString()}`;
408
+ }
409
+
410
+ const endpoint =
411
+ baseUrl ||
412
+ "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo";
225
413
  const params = new URLSearchParams();
226
- params.set("bucketId", bucketId);
414
+ if (bucketId) {
415
+ params.set("bucketId", bucketId);
416
+ }
227
417
 
228
418
  if (!resultId) {
229
419
  if (aspectRatio) {
@@ -247,6 +437,10 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
247
437
  params.set("variables", JSON.stringify(variables));
248
438
  }
249
439
 
440
+ if (metadata && Object.keys(metadata).length > 0) {
441
+ params.set("metadata", JSON.stringify(metadata));
442
+ }
443
+
250
444
  if (attachments && attachments.length > 0) {
251
445
  params.set("attachments", JSON.stringify(attachments));
252
446
  }
@@ -254,7 +448,7 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
254
448
  params.set("resultId", resultId);
255
449
  }
256
450
 
257
- return `${baseUrl}?${params.toString()}`;
451
+ return `${endpoint}?${params.toString()}`;
258
452
  }
259
453
 
260
454
  /**
@@ -271,8 +465,6 @@ export function preloadVideo(options: SlopVideoOptions): Promise<void> {
271
465
  return;
272
466
  }
273
467
 
274
- // We can just fetch the URL to preload it into the browser's cache.
275
- // We use no-cors to avoid CORS errors for simple preloads
276
468
  fetch(buildVideoUrl(options), { mode: "no-cors" })
277
469
  .then(() => resolve())
278
470
  .catch((err) => reject(err));
@@ -282,8 +474,26 @@ export function preloadVideo(options: SlopVideoOptions): Promise<void> {
282
474
  export interface SlopTextOptions {
283
475
  /**
284
476
  * The unique identifier of your Slop Machine bucket.
477
+ * Required when using a bucket unless pipelineId is provided.
285
478
  */
286
- bucketId: string;
479
+ bucketId?: string;
480
+ /**
481
+ * The unique identifier of your Slop Machine pipeline.
482
+ * Required when targeting a pipeline instead of a bucket.
483
+ */
484
+ pipelineId?: string;
485
+ /**
486
+ * Optional silo identifier.
487
+ */
488
+ siloId?: string;
489
+ /**
490
+ * Dynamic runtime prompt (used when targeting a pipeline).
491
+ */
492
+ prompt?: string;
493
+ /**
494
+ * Arbitrary user metadata to attach to the generation request / result document.
495
+ */
496
+ metadata?: Record<string, any>;
287
497
  /**
288
498
  * The specific version of the prompt/settings to use.
289
499
  * If omitted, the latest version will be used.
@@ -313,34 +523,65 @@ export interface SlopTextOptions {
313
523
  /**
314
524
  * Builds a URL to render or retrieve text from Slop Machine.
315
525
  *
526
+ * Supports both standard Buckets (via `bucketId`) and multi-step Pipelines (via `pipelineId`).
527
+ *
316
528
  * @param options - Configuration options for the text generation.
317
529
  * @returns A string containing the fully constructed URL.
318
530
  */
319
531
  export function buildTextUrl(options: SlopTextOptions): string {
320
532
  const {
321
533
  bucketId,
534
+ pipelineId,
535
+ siloId,
536
+ prompt,
537
+ metadata,
322
538
  version,
323
539
  resultId,
324
540
  variables = {},
325
- baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText",
541
+ baseUrl,
326
542
  attachments,
327
543
  } = options;
328
544
 
545
+ if (pipelineId) {
546
+ const endpoint =
547
+ baseUrl ||
548
+ "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline";
549
+ const params = new URLSearchParams();
550
+ params.set("pipelineId", pipelineId);
551
+ params.set("sync", "true");
552
+
553
+ if (siloId) params.set("siloId", siloId);
554
+ if (prompt) params.set("prompt", prompt);
555
+ if (resultId) params.set("resultId", resultId);
556
+
557
+ if (Object.keys(variables).length > 0) {
558
+ params.set("variables", JSON.stringify(variables));
559
+ }
560
+ if (metadata && Object.keys(metadata).length > 0) {
561
+ params.set("metadata", JSON.stringify(metadata));
562
+ }
563
+
564
+ return `${endpoint}?${params.toString()}`;
565
+ }
566
+
567
+ const endpoint =
568
+ baseUrl ||
569
+ "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText";
329
570
  const params = new URLSearchParams();
330
- params.set("bucketId", bucketId);
571
+ if (bucketId) {
572
+ params.set("bucketId", bucketId);
573
+ }
331
574
 
332
575
  if (!resultId) {
333
576
  if (version) {
334
577
  params.set("version", String(version));
335
578
  }
336
- if (resultId) {
337
- params.set("resultId", resultId);
338
- }
339
-
340
579
  if (Object.keys(variables).length > 0) {
341
580
  params.set("variables", JSON.stringify(variables));
342
581
  }
343
-
582
+ if (metadata && Object.keys(metadata).length > 0) {
583
+ params.set("metadata", JSON.stringify(metadata));
584
+ }
344
585
  if (attachments && attachments.length > 0) {
345
586
  params.set("attachments", JSON.stringify(attachments));
346
587
  }
@@ -348,7 +589,7 @@ export function buildTextUrl(options: SlopTextOptions): string {
348
589
  params.set("resultId", resultId);
349
590
  }
350
591
 
351
- return `${baseUrl}?${params.toString()}`;
592
+ return `${endpoint}?${params.toString()}`;
352
593
  }
353
594
 
354
595
  /**
@@ -365,14 +606,101 @@ export function preloadText(options: SlopTextOptions): Promise<void> {
365
606
  return;
366
607
  }
367
608
 
368
- // Fetch the URL to preload it into the browser's cache.
369
- // We use no-cors to avoid CORS errors for simple preloads
370
609
  fetch(buildTextUrl(options), { mode: "no-cors" })
371
610
  .then(() => resolve())
372
611
  .catch((err) => reject(err));
373
612
  });
374
613
  }
375
614
 
615
+ /**
616
+ * Builds a URL to execute or inspect a multi-step Pipeline from Slop Machine.
617
+ *
618
+ * @param options - Configuration options for the pipeline execution.
619
+ * @returns A string containing the fully constructed URL.
620
+ */
621
+ export function buildPipelineUrl(options: SlopPipelineOptions): string {
622
+ const {
623
+ pipelineId,
624
+ siloId,
625
+ prompt,
626
+ variables = {},
627
+ metadata = {},
628
+ sync = true,
629
+ redirect = false,
630
+ resultId,
631
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline",
632
+ } = options;
633
+
634
+ const params = new URLSearchParams();
635
+ params.set("pipelineId", pipelineId);
636
+
637
+ if (siloId) params.set("siloId", siloId);
638
+ if (prompt) params.set("prompt", prompt);
639
+ if (resultId) params.set("resultId", resultId);
640
+ if (sync !== undefined) params.set("sync", String(sync));
641
+ if (redirect) params.set("redirect", "true");
642
+
643
+ if (Object.keys(variables).length > 0) {
644
+ params.set("variables", JSON.stringify(variables));
645
+ }
646
+ if (Object.keys(metadata).length > 0) {
647
+ params.set("metadata", JSON.stringify(metadata));
648
+ }
649
+
650
+ return `${baseUrl}?${params.toString()}`;
651
+ }
652
+
653
+ /**
654
+ * Executes a Slop Machine multi-step Pipeline programmatically and returns the full typed result payload.
655
+ *
656
+ * @param options - Execution parameters including the pipelineId and runtime prompt/variables/metadata.
657
+ * @returns A promise resolving to the completed PipelineResult document.
658
+ */
659
+ export async function executePipeline(
660
+ options: ExecutePipelineOptions,
661
+ ): Promise<PipelineResult> {
662
+ const {
663
+ pipelineId,
664
+ siloId,
665
+ prompt,
666
+ variables,
667
+ metadata,
668
+ baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderPipeline",
669
+ } = options;
670
+
671
+ const response = await fetch(baseUrl, {
672
+ method: "POST",
673
+ headers: {
674
+ "Content-Type": "application/json",
675
+ },
676
+ body: JSON.stringify({
677
+ pipelineId,
678
+ ...(siloId ? { siloId } : {}),
679
+ ...(prompt ? { prompt } : {}),
680
+ variables,
681
+ metadata,
682
+ sync: true,
683
+ }),
684
+ });
685
+
686
+ if (!response.ok) {
687
+ let errorDetail = response.statusText;
688
+ try {
689
+ const errorJson = await response.json();
690
+ if (errorJson.error) {
691
+ errorDetail = errorJson.error;
692
+ }
693
+ } catch {
694
+ // Use statusText
695
+ }
696
+ throw new Error(
697
+ `Pipeline execution failed (${response.status}): ${errorDetail}`,
698
+ );
699
+ }
700
+
701
+ return (await response.json()) as PipelineResult;
702
+ }
703
+
376
704
  /**
377
705
  * Uploads a base64 encoded file as a temporary attachment to be used in generation requests.
378
706
  *