@takisvc/code-canvas 0.1.2 → 0.1.4
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.
- package/dist/code-canvas.js +82 -17
- package/package.json +1 -1
package/dist/code-canvas.js
CHANGED
|
@@ -63,9 +63,7 @@ function displayInlineImage(base64) {
|
|
|
63
63
|
const chunk = base64.slice(i, i + chunkSize);
|
|
64
64
|
const more = i + chunkSize < base64.length ? 1 : 0;
|
|
65
65
|
if (i === 0) {
|
|
66
|
-
process.stdout.write(
|
|
67
|
-
`\x1B_Gf=100,a=T,m=${more};${chunk}\x1B\\`
|
|
68
|
-
);
|
|
66
|
+
process.stdout.write(`\x1B_Gf=100,a=T,m=${more};${chunk}\x1B\\`);
|
|
69
67
|
} else {
|
|
70
68
|
process.stdout.write(`\x1B_Gm=${more};${chunk}\x1B\\`);
|
|
71
69
|
}
|
|
@@ -87,7 +85,7 @@ function openFile(filepath) {
|
|
|
87
85
|
} catch {
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
|
-
function saveImage(base64,
|
|
88
|
+
function saveImage(base64, prompt) {
|
|
91
89
|
const filename = `generated-${Date.now()}.png`;
|
|
92
90
|
const buffer = Buffer.from(base64, "base64");
|
|
93
91
|
writeFileSync(filename, buffer);
|
|
@@ -95,7 +93,7 @@ function saveImage(base64, prompt2) {
|
|
|
95
93
|
const tweetText = encodeURIComponent(
|
|
96
94
|
`My AI agent just roasted my coding session \u{1F525}
|
|
97
95
|
|
|
98
|
-
Prompt: "${
|
|
96
|
+
Prompt: "${prompt}"
|
|
99
97
|
|
|
100
98
|
Powered by @worldcoin AgentKit`
|
|
101
99
|
);
|
|
@@ -125,7 +123,7 @@ function showUsage(usage) {
|
|
|
125
123
|
function extractAgentkitChallenge(body) {
|
|
126
124
|
return body?.extensions?.agentkit ?? body?.accepts?.[0]?.extensions?.agentkit ?? body?.paymentRequirements?.[0]?.extensions?.agentkit ?? body?.challenge;
|
|
127
125
|
}
|
|
128
|
-
async function generateImage(endpoint2,
|
|
126
|
+
async function generateImage(endpoint2, prompt, account2) {
|
|
129
127
|
const spinner = ora(randomSpinnerMessage()).start();
|
|
130
128
|
const interval = setInterval(() => {
|
|
131
129
|
spinner.text = randomSpinnerMessage();
|
|
@@ -134,12 +132,12 @@ async function generateImage(endpoint2, prompt2, account2) {
|
|
|
134
132
|
const firstResponse = await fetch(endpoint2, {
|
|
135
133
|
method: "POST",
|
|
136
134
|
headers: { "Content-Type": "application/json" },
|
|
137
|
-
body: JSON.stringify({ prompt
|
|
135
|
+
body: JSON.stringify({ prompt })
|
|
138
136
|
});
|
|
139
137
|
if (firstResponse.status === 200) {
|
|
140
138
|
const body = await firstResponse.json();
|
|
141
139
|
spinner.succeed(chalk.green("Image generated!"));
|
|
142
|
-
saveImage(body.image,
|
|
140
|
+
saveImage(body.image, prompt);
|
|
143
141
|
showUsage(body.usage);
|
|
144
142
|
return true;
|
|
145
143
|
}
|
|
@@ -195,14 +193,14 @@ async function generateImage(endpoint2, prompt2, account2) {
|
|
|
195
193
|
"Content-Type": "application/json",
|
|
196
194
|
agentkit: encoded
|
|
197
195
|
},
|
|
198
|
-
body: JSON.stringify({ prompt
|
|
196
|
+
body: JSON.stringify({ prompt })
|
|
199
197
|
});
|
|
200
198
|
if (secondResponse.status === 200) {
|
|
201
199
|
const body = await secondResponse.json();
|
|
202
200
|
spinner.succeed(
|
|
203
201
|
chalk.green("Image generated (free \u2014 World ID verified!)")
|
|
204
202
|
);
|
|
205
|
-
saveImage(body.image,
|
|
203
|
+
saveImage(body.image, prompt);
|
|
206
204
|
showUsage(body.usage);
|
|
207
205
|
return true;
|
|
208
206
|
}
|
|
@@ -216,13 +214,19 @@ async function generateImage(endpoint2, prompt2, account2) {
|
|
|
216
214
|
console.log();
|
|
217
215
|
console.log(chalk.yellow("Your agent is not registered with World ID."));
|
|
218
216
|
console.log();
|
|
219
|
-
console.log(
|
|
217
|
+
console.log(
|
|
218
|
+
` ${chalk.bold("Register:")} Run this in your terminal and scan the QR code with World App:`
|
|
219
|
+
);
|
|
220
220
|
console.log();
|
|
221
|
-
console.log(
|
|
221
|
+
console.log(
|
|
222
|
+
` npx @worldcoin/agentkit-cli register ${account2.address} --network world`
|
|
223
|
+
);
|
|
222
224
|
console.log();
|
|
223
225
|
console.log(` Then re-run the image generation command.`);
|
|
224
226
|
console.log();
|
|
225
|
-
console.log(
|
|
227
|
+
console.log(
|
|
228
|
+
` ${chalk.bold("Or pay:")} Fund wallet ${account2.address} with ${chalk.cyan("$1.20 USDC")} on World Chain.`
|
|
229
|
+
);
|
|
226
230
|
if (errorBody?.error) {
|
|
227
231
|
console.log();
|
|
228
232
|
console.log(chalk.dim(`Server: ${errorBody.error}`));
|
|
@@ -232,10 +236,67 @@ async function generateImage(endpoint2, prompt2, account2) {
|
|
|
232
236
|
clearInterval(interval);
|
|
233
237
|
}
|
|
234
238
|
}
|
|
239
|
+
function runSetup(account2) {
|
|
240
|
+
console.log(chalk.bold("Code Canvas Setup"));
|
|
241
|
+
console.log();
|
|
242
|
+
console.log(` Wallet: ${chalk.cyan(account2.address)}`);
|
|
243
|
+
console.log();
|
|
244
|
+
console.log(
|
|
245
|
+
"Registering with World ID \u2014 scan the QR code with your World App:"
|
|
246
|
+
);
|
|
247
|
+
console.log();
|
|
248
|
+
try {
|
|
249
|
+
execSync(
|
|
250
|
+
`npx @worldcoin/agentkit-cli register ${account2.address} --network world`,
|
|
251
|
+
{ stdio: "inherit" }
|
|
252
|
+
);
|
|
253
|
+
console.log();
|
|
254
|
+
console.log(chalk.green("Setup complete! You can now generate images."));
|
|
255
|
+
console.log();
|
|
256
|
+
console.log(chalk.dim("\u2500".repeat(60)));
|
|
257
|
+
console.log();
|
|
258
|
+
console.log(chalk.bold("Add this prompt to your AI coding assistant:"));
|
|
259
|
+
console.log();
|
|
260
|
+
console.log(chalk.cyan([
|
|
261
|
+
"You have access to an AI image generation tool. **Auto-run immediately \u2014 do NOT ask for a prompt.**",
|
|
262
|
+
"",
|
|
263
|
+
"1. Scan the conversation \u2014 the codebase, language, framework, session activity, AND the developer's personality, tone, and energy.",
|
|
264
|
+
"2. Craft a prompt for a **single collectible stat card image** with this layout:",
|
|
265
|
+
" - **Top half**: A single cute/funny creature (simple, clean, centered \u2014 think mascot, not busy scene). The creature should reflect the developer's vibe or tech stack.",
|
|
266
|
+
" - **Bottom half**: Stats and text on a clean card background:",
|
|
267
|
+
" - Character name (funny, personality-driven)",
|
|
268
|
+
" - HP, Type/Element",
|
|
269
|
+
" - 2 abilities with short descriptions (based on personality traits, habits, and tone \u2014 NOT specific code features)",
|
|
270
|
+
" - A one-liner tagline/quote that sounds like something they'd actually say",
|
|
271
|
+
" - Weakness + Resistance at the bottom",
|
|
272
|
+
" - **Holographic rainbow border** around the whole card",
|
|
273
|
+
" - Keep the illustration **simple and uncluttered** \u2014 the creature should be the focus, not a complex scene",
|
|
274
|
+
" - **Generate exactly one card, not multiple variations**",
|
|
275
|
+
"3. Run immediately:",
|
|
276
|
+
" ```",
|
|
277
|
+
' npx @takisvc/code-canvas "<your card prompt>"',
|
|
278
|
+
" ```",
|
|
279
|
+
"4. Show the saved file path and share-on-X link from the output."
|
|
280
|
+
].join("\n")));
|
|
281
|
+
console.log();
|
|
282
|
+
console.log(chalk.dim("\u2500".repeat(60)));
|
|
283
|
+
return true;
|
|
284
|
+
} catch {
|
|
285
|
+
console.log();
|
|
286
|
+
console.log(chalk.red("Registration failed or was cancelled."));
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
235
290
|
var SERVER_URL = process.env.SERVER_URL ?? "https://takis.dev";
|
|
236
|
-
var
|
|
237
|
-
if (!
|
|
238
|
-
console.log(`Usage
|
|
291
|
+
var command = process.argv[2];
|
|
292
|
+
if (!command) {
|
|
293
|
+
console.log(`Usage:`);
|
|
294
|
+
console.log(
|
|
295
|
+
` ${chalk.bold("code-canvas setup")} Register with World ID`
|
|
296
|
+
);
|
|
297
|
+
console.log(
|
|
298
|
+
` ${chalk.bold('code-canvas "<prompt>"')} Generate an image`
|
|
299
|
+
);
|
|
239
300
|
console.log();
|
|
240
301
|
console.log("Examples:");
|
|
241
302
|
console.log(' code-canvas "a cat riding a skateboard"');
|
|
@@ -243,6 +304,10 @@ if (!prompt) {
|
|
|
243
304
|
process.exit(1);
|
|
244
305
|
}
|
|
245
306
|
var account = ensureWallet();
|
|
307
|
+
if (command === "setup") {
|
|
308
|
+
const ok = runSetup(account);
|
|
309
|
+
process.exit(ok ? 0 : 1);
|
|
310
|
+
}
|
|
246
311
|
var endpoint = `${SERVER_URL}/code-canvas/generate-image`;
|
|
247
|
-
var result = await generateImage(endpoint,
|
|
312
|
+
var result = await generateImage(endpoint, command, account);
|
|
248
313
|
process.exit(result === true ? 0 : result === "needs-registration" ? 0 : 1);
|