MCPcopy Create free account
hub / github.com/cloudflare/computer / generate

Method generate

examples/assets/src/index.ts:61–83  ·  view source on GitHub ↗
(prompt: string)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

#runModelMethod · 0.95
createAssetsFunction · 0.90
shareMethod · 0.80
mkdirMethod · 0.65
writeFileMethod · 0.65

Tested by

no test coverage detected