Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 52 lines 1.5 kB view raw
1// Tool: publish_piece 2// Publish a JavaScript piece to aesthetic.computer 3 4export const publishPieceTool = { 5 name: "publish_piece", 6 description: "Publish a JavaScript piece to aesthetic.computer. The piece will be stored and given a short code URL.", 7 inputSchema: { 8 type: "object" as const, 9 properties: { 10 source: { 11 type: "string", 12 description: "JavaScript source code for the piece. Must export lifecycle functions like boot, paint, sim, or act.", 13 }, 14 name: { 15 type: "string", 16 description: "Optional name for the piece (used for code generation)", 17 }, 18 }, 19 required: ["source"], 20 }, 21}; 22 23export async function publishPiece(args: { source: string; name?: string }, token?: string) { 24 const headers: Record<string, string> = { 25 "Content-Type": "application/json", 26 }; 27 28 if (token) { 29 headers["Authorization"] = `Bearer ${token}`; 30 } 31 32 const response = await fetch("https://aesthetic.computer/api/store-piece", { 33 method: "POST", 34 headers, 35 body: JSON.stringify({ 36 source: args.source, 37 name: args.name, 38 }), 39 }); 40 41 if (!response.ok) { 42 const error: any = await response.json().catch(() => ({ error: response.statusText })); 43 throw new Error(`Failed to publish piece: ${error.error || response.statusText}`); 44 } 45 46 const result: any = await response.json(); 47 return { 48 code: result.code, 49 url: result.url, 50 cached: result.cached, 51 }; 52}