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

Method card

examples/tutorial/src/index.ts:88–117  ·  view source on GitHub ↗

Run the agent.

(prompt: string)

Source from the content-addressed store, hash-verified

86
87 /** Run the agent. */
88 async card(prompt: string): Promise<{ url: string; summary: string }> {
89 try {
90 await this.workspace.fs.mkdir("/workspace", { recursive: true });
91 const turn = await this.saveMessages([
92 { id: crypto.randomUUID(), role: "user", parts: [{ type: "text", text: prompt }] },
93 ]);
94 if (turn.status !== "completed") {
95 throw new Error(`Agent turn ${turn.status}: ${turn.error ?? "no detail"}`);
96 }
97 const written = await this.workspace.fs.stat("/workspace/card.pdf").catch(() => null);
98 if (!written?.isFile) throw new Error("The agent produced no PDF at /workspace/card.pdf");
99 const assets = createAssets({
100 ws: this.workspace,
101 bucket: this.env.CARDS,
102 s3: {
103 bucket: this.env.CARDS_BUCKET_NAME,
104 accountId: this.env.CLOUDFLARE_ACCOUNT_ID,
105 accessKeyId: this.env.R2_ACCESS_KEY_ID,
106 secretAccessKey: this.env.R2_SECRET_ACCESS_KEY,
107 },
108 });
109 const url = await assets.share("/workspace/card.pdf", {
110 expiresAfter: 24 * 60 * 60 * 1000,
111 prefix: "cards",
112 });
113 return { url, summary: lastAssistantText(this.messages) };
114 } finally {
115 await this.workspace.close();
116 }
117 }
118}
119
120export default {

Callers 1

fetchFunction · 0.80

Calls 6

createAssetsFunction · 0.90
lastAssistantTextFunction · 0.85
shareMethod · 0.80
mkdirMethod · 0.65
statMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected