(prompt: string)
| 59 | // Generate an image from `prompt`, store it, and return a |
| 60 | // shareable link. |
| 61 | async generate(prompt: string): Promise<GenerateResult> { |
| 62 | const image = await this.#runModel(prompt); |
| 63 | |
| 64 | // One file per request, named by a random id so repeated |
| 65 | // prompts never collide on the VFS. |
| 66 | const path = `/workspace/${crypto.randomUUID()}.png`; |
| 67 | await this.#workspace.fs.mkdir("/workspace", { recursive: true }); |
| 68 | await this.#workspace.fs.writeFile(path, image); |
| 69 | |
| 70 | const assets = createAssets({ |
| 71 | ws: this.#workspace, |
| 72 | bucket: this.env.ASSETS, |
| 73 | s3: { bucket: this.env.ASSETS_BUCKET_NAME }, |
| 74 | env: this.env as unknown as Record<string, string | undefined>, |
| 75 | }); |
| 76 | |
| 77 | const url = await assets.share(path, { |
| 78 | expiresAfter: LINK_TTL_MS, |
| 79 | prefix: "generated", |
| 80 | }); |
| 81 | |
| 82 | return { path, url }; |
| 83 | } |
| 84 | |
| 85 | // Run the text-to-image model and return the decoded PNG bytes. |
| 86 | // The model takes multipart form fields and returns the image as |
nothing calls this directly
no test coverage detected