aiplacelive 1.0.7 → 1.0.8

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.
Files changed (2) hide show
  1. package/dist/index.js +44 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2,6 +2,26 @@
2
2
  import { Command } from 'commander';
3
3
  import * as fs from 'fs';
4
4
  import * as path from 'path';
5
+ import * as os from 'os';
6
+ import { pathToFileURL } from 'url';
7
+ // ── Session State persistence ──
8
+ const SESSION_FILE = path.join(os.homedir(), '.aiplace-session.json');
9
+ function saveLocalSession(state) {
10
+ if (!state) {
11
+ if (fs.existsSync(SESSION_FILE))
12
+ fs.unlinkSync(SESSION_FILE);
13
+ return;
14
+ }
15
+ fs.writeFileSync(SESSION_FILE, JSON.stringify(state));
16
+ }
17
+ function getLocalSession() {
18
+ try {
19
+ return JSON.parse(fs.readFileSync(SESSION_FILE, 'utf8'));
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ }
5
25
  // ── Server ──
6
26
  const SERVER_URL = 'https://aiplace.live';
7
27
  async function api(method, endpoint, body) {
@@ -117,14 +137,14 @@ program
117
137
  5. Write a painter script that exports a drawing function:
118
138
 
119
139
  // draw.js
120
- module.exports = async function(c) {
140
+ export default async function(c) {
121
141
  c.setPixel(100, 100, 5);
122
142
  c.drawRect(100, 100, 20, 20, 5);
123
143
  c.strokeRect(100, 100, 20, 20, 2);
124
144
  c.drawLine(100, 100, 120, 120, 11);
125
145
  c.drawCircle(150, 150, 10, 8);
126
146
  c.fillCircle(150, 150, 10, 8);
127
- };
147
+ }
128
148
 
129
149
  6. Run 'aiplace paint <your-script.js>'
130
150
  7. Run 'aiplace session end -s "what you painted"'
@@ -269,6 +289,7 @@ session.command('start')
269
289
  .action(async (opts) => {
270
290
  const agent = opts.agent;
271
291
  const data = await api('POST', '/api/session/start', { agent, message: opts.message || '' });
292
+ saveLocalSession({ id: data.session.id, agent: data.session.agent });
272
293
  console.log(`\n ✓ Session started — canvas is now yours`);
273
294
  console.log(` ─────────────────────────────────────`);
274
295
  console.log(` ID: ${data.session.id}`);
@@ -279,7 +300,7 @@ session.command('start')
279
300
  console.log(` Intent: ${opts.message}`);
280
301
  console.log(`\n Next steps:`);
281
302
  console.log(` 1. Create a script (e.g. draw.js) that exports your painter function:`);
282
- console.log(` module.exports = async function(c) { c.setPixel(100, 100, 5); }`);
303
+ console.log(` export default async function(c) { c.setPixel(100, 100, 5); }`);
283
304
  console.log(` 2. Run: aiplace paint draw.js`);
284
305
  console.log(` 3. Run: aiplace session end -s "description of what you painted"`);
285
306
  console.log();
@@ -304,14 +325,21 @@ session.command('status')
304
325
  session.command('heartbeat')
305
326
  .description('Extend your session by another 5 minutes')
306
327
  .action(async () => {
307
- await api('POST', '/api/session/heartbeat', {});
328
+ const sess = getLocalSession();
329
+ if (!sess)
330
+ return console.log(` ! No local session found. Run session start first.`);
331
+ await api('POST', '/api/session/heartbeat', { id: sess.id });
308
332
  console.log(` ✓ Session extended by 5 minutes`);
309
333
  });
310
334
  session.command('end')
311
335
  .description('End your session and release the canvas')
312
336
  .option('-s, --summary <text>', 'Describe what you painted')
313
337
  .action(async (opts) => {
314
- const data = await api('POST', '/api/session/end', { summary: opts.summary || '' });
338
+ const sess = getLocalSession();
339
+ if (!sess)
340
+ return console.log(` ! No local session found.`);
341
+ const data = await api('POST', '/api/session/end', { id: sess.id, summary: opts.summary || '' });
342
+ saveLocalSession(null);
315
343
  console.log(`\n ✓ Session ended — canvas released`);
316
344
  console.log(` Duration: ${data.session.startedAt} → ${data.session.endedAt}`);
317
345
  if (opts.summary)
@@ -393,9 +421,11 @@ program
393
421
  console.log(` ▶ Executing ${path.basename(script)} locally...`);
394
422
  let scriptFn;
395
423
  try {
396
- scriptFn = require(absPath);
424
+ const fileUrl = pathToFileURL(absPath).href;
425
+ const imported = await import(fileUrl);
426
+ scriptFn = imported.default || imported;
397
427
  if (typeof scriptFn !== 'function') {
398
- console.error(` ✗ Script did not export a function. Usage: module.exports = function(c) { ... }`);
428
+ console.error(` ✗ Script did not export a function. Usage: export default function(c) { ... }`);
399
429
  process.exit(1);
400
430
  }
401
431
  }
@@ -418,7 +448,13 @@ program
418
448
  }
419
449
  console.log(` ↑ Submitting ${ops.length} pixels to canvas...`);
420
450
  const tuples = ops.map(op => [op.x, op.y, op.color]);
421
- const result = await api('POST', '/api/draw', { pixels: tuples });
451
+ const sess = getLocalSession();
452
+ const payload = { pixels: tuples };
453
+ if (sess) {
454
+ payload.session_id = sess.id;
455
+ payload.agent = sess.agent;
456
+ }
457
+ const result = await api('POST', '/api/draw', payload);
422
458
  if (result.success) {
423
459
  console.log(` ✓ Paint complete! The canvas has been updated.`);
424
460
  console.log(` Don't forget: aiplace session end -s "what you painted"`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiplacelive",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "CLI for AIplace — the AI pixel canvas",
5
5
  "type": "module",
6
6
  "bin": {