Open History to see the last commit
1import { config } from 'dotenv';
2import { createHash } from 'node:crypto';
3import { setTimeout as wait } from 'node:timers/promises';
4config({ path: '.env.local', quiet: true });
5const { database } = await import('../services/api/src/database.ts');
6const { createApp } = await import('../services/api/src/store.ts');
7
8// Seeds the feed with apps built by the real agent for a few demo creators. The creators cannot
9// sign in (their email addresses are unroutable). Safe to re-run: every ID is derived from its
10// handle or prompt, so creators and apps are only created once, and finished apps are posted.
11// Usage: pnpm exec tsx scripts/seed.ts
12const uuid = (value: string) => { const h = createHash('sha256').update(`glow-seed:${value}`).digest('hex'); return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-a${h.slice(17, 20)}-${h.slice(20, 32)}`; };
13const creators = [
14 { handle: 'mikamakes', name: 'Mika Tanaka', bio: 'Tiny toys for big feelings. Pastel everything.', apps: [
15 'A virtual pet blob you feed by dragging snacks onto it. It bounces, changes colour with its mood, giggles when tickled, and sulks if you ignore it for a minute. Cute pastel style, made for touch.',
16 'A calming breathing app: a glowing orb expands and contracts with box-breathing timing (4-4-4-4), a soft drifting gradient background, a gentle text cue for each phase, and a count of completed rounds.',
17 'A wholesome compliment machine: tap a big glossy button to get an over-the-top, heartfelt compliment on a card that flips in with confetti. Keep a little stack of favourites you can scroll back through.',
18 ] },
19 { handle: 'devbuilds', name: 'Dev Okafor', bio: 'Games I wish existed. Mostly physics, occasionally chaos.', apps: [
20 'A one-thumb arcade game: steer a paper plane through drifting clouds and wind gusts by holding the left or right side of the screen. Collect stars, the speed slowly ramps up, and the best score is saved.',
21 'A tower stacking game: a block slides back and forth above the tower, tap to drop it, and any overhang gets sliced off and tumbles away. Blocks get smaller as you miss. Bright gradient colours, camera rises with the tower, best height saved.',
22 'A top-down mini golf game with 6 hand-designed holes: drag back from the ball to aim and set power, walls bounce, sand slows the ball, water puts it back. Show strokes per hole and a scorecard at the end.',
23 ] },
24 { handle: 'lenalabs', name: 'Lena Brooks', bio: 'Useful little tools. Occasionally silly ones.', apps: [
25 'A split-the-bill helper: enter the total and tip, add people by name, mark anyone who had extra, and see what each person owes in big friendly numbers. Round up to a nice number with one tap.',
26 'A habit tracker: add habits with an emoji, tick off each day on a 7-day strip, build streaks shown with a growing flame, and get a satisfying check animation. Progress is saved.',
27 'A focus timer where a tomato slowly ripens from green to red while you focus for 25 minutes, then a short break with a stretch suggestion. Show today\'s total focus time and a row of tomatoes earned.',
28 ] },
29 { handle: 'rafapixels', name: 'Rafa Moreno', bio: 'Pixel art, chiptune bleeps, arcade vibes.', apps: [
30 'A retro pixel drum machine: a 16-step sequencer with kick, snare, hi-hat and clap rows, synthesized sounds, a tempo slider, and chunky neon pads that light up as the playhead moves. Include a few preset beats.',
31 'A pixel art painter: a 24x24 canvas, a 16-colour retro palette, pencil, eraser, fill bucket, and a mirror mode for symmetric sprites. Save your drawing and download it as a PNG.',
32 'An endless runner: a pixel cat dashes across a neon city skyline at night, tap to jump over traffic cones, swipe down to duck under drones. Parallax background, speed increases, high score saved.',
33 ] },
34 { handle: 'priyaplays', name: 'Priya Shah', bio: 'Puzzles, word games and brain snacks.', apps: [
35 'A word ladder puzzle: turn the start word into the target word by changing one letter at a time, every step must be a real four-letter word. Built-in word list, a few puzzles of rising difficulty, hints, and a step counter.',
36 'A colour sorting puzzle: tubes hold stacks of coloured balls, tap a tube then another to move the top ball if it matches or the tube is empty. Sort every tube to a single colour. 10 levels that get harder, with undo.',
37 'A 60-second mental maths sprint: quick additions, subtractions and times tables, answered on a big number pad. Streaks build a combo multiplier, wrong answers shake, and the personal best is saved.',
38 ] },
39];
40
41const db = database();
42const apiUrl = process.env.GLOW_API_URL!, secret = process.env.GLOW_SWEEP_SECRET!;
43const appIds: Array<{ id: string; creator: string }> = [];
44for (const creator of creators) {
45 const userId = uuid(`user:${creator.handle}`);
46 await db.query(`INSERT INTO "user"(id,name,email,"emailVerified") VALUES($1,$2,$3,false) ON CONFLICT(id) DO NOTHING`, [userId, creator.name, `${creator.handle}@seed.glow.invalid`]);
47 await db.query(`INSERT INTO glow_profiles(user_id,handle,display_name,bio) VALUES($1,$2,$3,$4) ON CONFLICT(user_id) DO UPDATE SET handle=$2,display_name=$3,bio=$4`, [userId, creator.handle, creator.name, creator.bio]);
48 for (const prompt of creator.apps) {
49 const app = await createApp(userId, prompt, uuid(`app:${prompt}`));
50 appIds.push({ id: app.data.id, creator: creator.handle });
51 }
52}
53console.log(`${creators.length} creators, ${appIds.length} apps queued.`);
54
55const sweep = () => fetch(new URL('/internal/sweep', apiUrl), { method: 'POST', headers: { Authorization: `Bearer ${secret}` } }).catch(() => {});
56const retried = new Set<string>(), gaveUp = new Set<string>();
57for (let minute = 0; minute < 120; minute += 0.25) {
58 await sweep();
59 const { rows } = await db.query(`SELECT a.data AS app, (SELECT r.data FROM glow_runs r WHERE r.app_id=a.id ORDER BY r.data->>'createdAt' DESC LIMIT 1) AS run FROM glow_apps a WHERE a.id = ANY($1::uuid[])`, [appIds.map(item => item.id)]);
60 let open = 0;
61 for (const { app, run } of rows) {
62 if (app.visibility === 'public') continue;
63 if (app.status === 'ready' && app.draftVersionId && run?.status === 'ready') {
64 // Post it to the feed, as the Post button does.
65 const postedAt = new Date().toISOString();
66 await db.query(`UPDATE glow_apps SET data=data || jsonb_build_object('visibility','public','postedAt',$2::text,'headVersionId',data->>'draftVersionId','publicCover',data->'cover','caption',data->>'tagline','updatedAt',$2::text) WHERE id=$1`, [app.id, postedAt]);
67 await db.query(`UPDATE glow_versions SET data=data || '{"published":true}'::jsonb WHERE id=$1`, [app.draftVersionId]);
68 console.log(`Posted ${app.emoji ?? ''} ${app.title}`);
69 } else if (run?.status === 'failed' && !retried.has(app.id)) {
70 retried.add(app.id); open++;
71 await db.query(`UPDATE glow_runs SET data=data || jsonb_build_object('status','queued','phase','Queued','error',null,'attempt',0,'continuation',false,'slices',0,'fence',(data->>'fence')::int+1),model_calls=0,owner_id=NULL,activation_hash=NULL,lease_until=NULL,dispatch_id=NULL WHERE id=$1`, [run.id]);
72 console.log(`Retrying ${app.title}: ${run.error}`);
73 } else if (app.status === 'failed' || run?.status === 'failed') { if (!gaveUp.has(app.id)) console.log(`Gave up on ${app.title}: ${run?.error ?? 'setup failed'}`); gaveUp.add(app.id); }
74 else open++;
75 }
76 if (!open) break;
77 await wait(15_000);
78}
79const { rows } = await db.query(`SELECT count(*) FILTER (WHERE data->>'visibility'='public')::int AS posted FROM glow_apps WHERE id = ANY($1::uuid[])`, [appIds.map(item => item.id)]);
80console.log(`Done: ${rows[0].posted}/${appIds.length} posted.`);
81await db.end();