@protomaze/demo-engine 0.0.0-stage → 0.1.0

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 (67) hide show
  1. package/AGENTS.md +131 -0
  2. package/README.md +176 -3
  3. package/agent/Agent.d.ts +155 -0
  4. package/agent/Agent.js +1 -0
  5. package/agent/Guide.d.ts +2 -0
  6. package/agent/Guide.js +1 -0
  7. package/engine/DemoEngine.d.ts +316 -0
  8. package/engine/DemoEngine.js +1 -0
  9. package/engine/Guided.d.ts +12 -0
  10. package/engine/Guided.js +1 -0
  11. package/engine/Player.d.ts +127 -0
  12. package/engine/Player.js +1 -0
  13. package/engine/Plugin.d.ts +56 -0
  14. package/engine/Plugin.js +1 -0
  15. package/engine/Read.d.ts +5 -0
  16. package/engine/Read.js +1 -0
  17. package/engine/Recorder.d.ts +50 -0
  18. package/engine/Recorder.js +1 -0
  19. package/engine/Settings.d.ts +49 -0
  20. package/engine/Settings.js +1 -0
  21. package/index.d.ts +24 -0
  22. package/index.js +1 -0
  23. package/model/Demo.d.ts +201 -0
  24. package/model/Demo.js +1 -0
  25. package/model/Subtitles.d.ts +12 -0
  26. package/model/Subtitles.js +1 -0
  27. package/model/Timing.d.ts +45 -0
  28. package/model/Timing.js +1 -0
  29. package/model/Validate.d.ts +16 -0
  30. package/model/Validate.js +1 -0
  31. package/package.json +65 -4
  32. package/page/Input.d.ts +67 -0
  33. package/page/Input.js +1 -0
  34. package/page/Overlay.d.ts +110 -0
  35. package/page/Overlay.js +1 -0
  36. package/page/Targets.d.ts +85 -0
  37. package/page/Targets.js +1 -0
  38. package/speech/Music.d.ts +13 -0
  39. package/speech/Music.js +1 -0
  40. package/speech/Speech.d.ts +112 -0
  41. package/speech/Speech.js +1 -0
  42. package/speech/Transcribe.d.ts +25 -0
  43. package/speech/Transcribe.js +1 -0
  44. package/speech/Workers.d.ts +22 -0
  45. package/speech/Workers.js +1 -0
  46. package/store/Share.d.ts +19 -0
  47. package/store/Share.js +1 -0
  48. package/store/Store.d.ts +55 -0
  49. package/store/Store.js +1 -0
  50. package/ui/Actions.d.ts +33 -0
  51. package/ui/Actions.js +1 -0
  52. package/ui/EngineUI.d.ts +3 -0
  53. package/ui/EngineUI.js +1 -0
  54. package/ui/Hooks.d.ts +5 -0
  55. package/ui/Hooks.js +1 -0
  56. package/ui/Kit.d.ts +108 -0
  57. package/ui/Kit.js +1 -0
  58. package/ui/Library.d.ts +32 -0
  59. package/ui/Library.js +1 -0
  60. package/ui/Studio.d.ts +10 -0
  61. package/ui/Studio.js +1 -0
  62. package/ui/Styles.d.ts +2 -0
  63. package/ui/Styles.js +1 -0
  64. package/ui/Timeline.d.ts +21 -0
  65. package/ui/Timeline.js +1 -0
  66. package/video/Film.d.ts +61 -0
  67. package/video/Film.js +1 -0
package/AGENTS.md ADDED
@@ -0,0 +1,131 @@
1
+ <!-- Made from src/agent/Guide.ts by dev/guide.js: edit that. -->
2
+
3
+ An app using @protomaze/demo-engine exposes these tools on `window.demoEngine` in development.
4
+ Drive them through a browser's JavaScript console or an agent's "run JavaScript in the page" tool.
5
+
6
+ # Making a demo with demoEngine
7
+
8
+ You see the app in a browser and run JavaScript in it. `window.demoEngine` has the tools; every
9
+ result is plain data. A demo is steps; each step's narration is spoken (and subtitled) a sentence at
10
+ a time while its actions play one after the other. Actions point at elements as a person would: by
11
+ what they show, not where they are.
12
+
13
+ ## Workflow
14
+
15
+ 1. `demoEngine.languages()` - which languages to write narration in.
16
+ `demoEngine.start()` - where the app is; a demo starts there. `demoEngine.demos()` - what exists.
17
+ 2. Explore. `demoEngine.page()` lists what can be acted on, each with a ready `target`, its label,
18
+ state and box; `page({ query: 'save' })` or `page({ within: '[data-demo="filters"]' })` narrows it.
19
+ Look with screenshots too. `demoEngine.try({ do: 'click', target })` does one action now and says
20
+ what appeared and went: walk the app this way to learn the path the demo will take.
21
+ 3. Plan the story before the actions: what should the viewer understand at the end? One idea per step.
22
+ 4. Write the demo (format below). Narration first, then the actions that show it.
23
+ 5. `demoEngine.validate(demo)` - its shape. Then `await demoEngine.check(demo)` - from the demo's
24
+ start, fast and silent, going past what fails, its cleanup after; fix every failure and check
25
+ again until `ok` twice in a row (the second run proves the cleanup).
26
+ 6. `await demoEngine.save(demo)`, then `demoEngine.open(demo.id)` - the person sees it in the
27
+ studio, can play, tune, film and share it. `demoEngine.play(id)` plays it with sound once the
28
+ person clicks. `demoEngine.estimate(demo)` gives its length.
29
+
30
+ ## Length
31
+
32
+ - Short (a teaser, one feature): 4-7 steps, 30-60 s, one or two sentences a step.
33
+ - Normal (a tour): 8-12 steps, 1-3 min.
34
+ - Detailed (a deep dive): 12-25 steps, 3-6 min; still one idea per step.
35
+
36
+ ## What it is for
37
+
38
+ - Marketing video: short, benefit first, a `card` to open and close, zooms on what impresses; no
39
+ setup steps on screen. The person films it (film button); music can play under it.
40
+ - Sales pitch: one step per point the presenter makes; `pause: true` on steps where they talk
41
+ freely. They advance with a clicker (PageDown) and repeat with PageUp.
42
+ - Expo booth: 30-90 s, readable without sound (subtitles carry it), ends where it started so it can
43
+ loop. `demoEngine.loop([ids])` plays them unattended; a visitor's touch hands the app over.
44
+ - Tutorial or training: `demoEngine.guide(id)` lets the viewer do each click and entry themselves,
45
+ ringed with what to do. Narrate why, not only what; small steps; one new thing each.
46
+
47
+ ## Narration
48
+
49
+ - For the viewer, about what matters to them: "Which pipes need work first?" before "Click Risk".
50
+ - Present tense, plain words, at most ~20 words a sentence; a step ~1-3 sentences.
51
+ - Say what to look at as it happens; name things as the app names them.
52
+ - Every language of `languages().write`: `say: { en: '…', de: '…' }`. Same meaning, natural in each.
53
+ - No "In this demo…" filler; open with the question or the benefit, close with what was shown.
54
+
55
+ ## Format
56
+
57
+ ```json
58
+ {
59
+ "id": "orders-tour",
60
+ "title": "Orders, from list to invoice",
61
+ "description": "One sentence: who it is for and what it shows.",
62
+ "start": { "…": "as demoEngine.start() gives it, or leave out" },
63
+ "steps": [
64
+ {
65
+ "title": "Find an order",
66
+ "say": { "en": "Every order lands here, newest first. Let's find one from Berlin." },
67
+ "actions": [
68
+ { "do": "spotlight", "target": { "css": "table", "text": "orders" }, "for": 2500 },
69
+ { "do": "type", "target": { "css": "input[type=\"search\"]" }, "text": "Berlin", "cue": 1 },
70
+ { "do": "click", "target": { "css": "tr", "text": "berlin #" }, "wait": 1200 }
71
+ ]
72
+ }
73
+ ]
74
+ }
75
+ ```
76
+
77
+ A target: `{ css, text?, key?, index? }` - the `index`th (0-based) element matching `css` whose label
78
+ is `text` (or the app's locale `key`'s text: works in every language). Labels compare without case,
79
+ spacing, and with every number as "#": a row "Berlin 42" is "berlin #". Use the targets `page()` and
80
+ `describe()` give: they prefer locale keys and named regions. Avoid `index` where a scope does it:
81
+ `{ css: '[data-demo="filters"] button', text: 'apply' }`.
82
+
83
+ Every action has `wait` (ms before it, default 800) and `cue` (start with the step's sentence of that
84
+ index, 0-based: syncs a click with the words about it, in every language and voice).
85
+
86
+ Interactions:
87
+ - `click` { target, at?: [x, y] fractions of the box, double?, right?, shift?, ctrl?, alt?, meta? }
88
+ - `hover` { target, at? } - shows tooltips and hover cards (not CSS :hover looks)
89
+ - `type` { target, text } - replaces the field's text, a letter at a time
90
+ - `key` { key, target? } - 'Escape', 'Enter', 'ArrowDown', 'Control+K'; shown as keycaps
91
+ - `select` { target, option } - a native <select>'s option by text or value
92
+ - `drag` { target, at?, to: { target?, at? } } - sliders, drag and drop, panning
93
+ - `scroll` { target?, by?: [x, y] } - into view, or by pixels
94
+ - `waitFor` { target, gone?, timeout? } - until it shows (or goes): after what loads
95
+
96
+ Presentation (shown until the step ends, or `for` ms; `clear` takes all down):
97
+ - `spotlight` { target, text?, padding? } - dims everything else: the one thing to look at
98
+ - `ring` { target, text?, color?, shape?: 'box' | 'circle' } - a pulsing outline
99
+ - `arrow` { target, text?, from?: 'top' | 'right' | 'bottom' | 'left' } - points at it
100
+ - `callout` { text, target?, side?, corner? } - a note by the target, or in a corner
101
+ - `blur` { target } - hides names, addresses, anything private
102
+ - `card` { title, text? } - full screen: an opening title, a chapter, the end
103
+ - `zoom` { target, scale? } - magnifies the page around it (1.8 by default)
104
+ - `clear`
105
+
106
+ The app may add its own actions (a map's `view`, `mapClick`): `validate` lists every kind it knows
107
+ when one is wrong; read the app's demos (`demoEngine.get(id)`) for examples.
108
+
109
+ Step options: `title` (for the editor), `hold` (ms after), `pause: true` (waits for the presenter).
110
+
111
+ `cleanup`: actions done after the demo - when it ends or is stopped - quickly and unseen, so the app
112
+ is as it found it and the demo plays again: clear filters and searches, close what was opened, go
113
+ back to the first tab. What the app cannot undo through its UI, its start resets.
114
+
115
+ ## Good demos
116
+
117
+ - Open with a `card` (title, one line of promise), close with one (what was shown, what next).
118
+ - Direct the eye: a spotlight or ring on what the sentence is about, an arrow for small things.
119
+ - Let the viewer see results: a `wait` of 1500-3000 ms after what changes a lot; `waitFor` what loads.
120
+ - Keep the pointer purposeful: no clicks that do not move the story.
121
+ - Blur personal data.
122
+ - Leave the app as it started: a `cleanup` list undoes what the steps changed, so demos run one
123
+ after another and again. Check that too: `check` runs the cleanup, then `check` again.
124
+
125
+ ## Tools
126
+
127
+ help() · languages() · start() · page({ within?, query?, limit? }) · find(target) ·
128
+ describe(css | [x, y]) · try(action) · preview(presentationAction, ms?) · demos() · get(id) ·
129
+ validate(demo) · estimate(demoOrId) · check(demoOrId, { from?, to? }) · save(demo) · remove(id) ·
130
+ open(demoOrId) · play(demoOrId, { from? }) · guide(demoOrId, { from? }) · loop([demoOrId]) ·
131
+ stopLoop() · stop() · state() · link(demoOrId)
package/README.md CHANGED
@@ -1,3 +1,176 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Protomaze Demo Engine
2
+
3
+ Demos of a web app, made and played in the app itself, in the browser: no backend.
4
+
5
+ - **Make**: by an AI through the browser (`window.demoEngine`), by recording what you do (and say),
6
+ or by hand in the studio, on a `@protomaze/time` timeline.
7
+ - **Narrate**: text to speech in the browser (Kokoro, Piper: free, no key) or ElevenLabs; speech to
8
+ text (Whisper in the browser, or ElevenLabs) turns what you said into narration and subtitles.
9
+ - **Show**: a stand-in pointer, spotlights, rings, arrows, notes, blur, title cards, zoom, keycaps.
10
+ - **Play**: as a video would; **present** step by step with a clicker; **guide** a viewer who does
11
+ each step themselves (tutorials, trainings); **loop** unattended at an expo booth.
12
+ - **Film**: an MP4 or WebM of the tab with narration, music and subtitles, made in the browser, at
13
+ exactly 720p, 1080p, 1440p or 4K, landscape, portrait or square.
14
+ - **Music**: four tracks the engine composes itself (calm, lo-fi, bright, piano) - free to use
15
+ anywhere, nothing downloaded - or a file of one's own; quieter under the narration.
16
+ - **Share**: `.demo.json`, a scenario `.md`, a link with the demo in it, the video, `.vtt` / `.srt`.
17
+
18
+ ```bash
19
+ npm run dev # the sample app, on http://localhost:8095: "Demos" bottom left
20
+ npm test # the model: validation, timing, subtitles
21
+ npm run check # type-check everything, sample included
22
+ ```
23
+
24
+ ## In an app
25
+
26
+ ```ts
27
+ import { DemoEngine, dictionaryLabels } from '@protomaze/demo-engine';
28
+
29
+ const engine = new DemoEngine({
30
+ app: 'orders', // where demos, videos and settings are kept
31
+ demos: [{ demo: tour, scenario: tourMarkdown }], // the app's own, checked in as <id>.demo.json
32
+ languages: ['en', 'de'], // narration is written in these
33
+ language: () => i18n.language, // the page's
34
+ labels: dictionaryLabels(() => LOCALES[i18n.language], key => t(key)), // targets in every language
35
+ start: { // where a demo starts, in the app's terms
36
+ current: () => ({ tenant, mode }),
37
+ go: start => (start.tenant !== tenant ? reloadWith(start) : setMode(start.mode)), // 'reload' if it navigates
38
+ },
39
+ plugins: [mapPlugin(map)], // actions only the app knows
40
+ ready: () => map.whenReady(), // before a demo plays
41
+ filmElement: () => document.getElementById('app'), // videos crop to it, where the browser can
42
+ launcher: true, // a "Demos" button, for apps without a panel
43
+ });
44
+ await engine.mount();
45
+ ```
46
+
47
+ Or put the library in the app's own panel: `<DemoLibrary engine={engine} />` (in its own shadow
48
+ root: the app's styles stay out). Everything else - the studio, the bars while playing and
49
+ recording, effects - the engine renders over the app, in the top layer.
50
+
51
+ From code: `engine.play(demo, { from })`, `engine.guide(demo)`, `engine.film(demo)`,
52
+ `engine.record()`, `engine.loop(demos, { idle, reset: 'reload' })`, `engine.check(demo)`,
53
+ `engine.openStudio(demo)`, `engine.link(demo)`. Sound and filming need a click in the app's window:
54
+ started from elsewhere (a dev panel in its own window, a link, code) the engine asks for one.
55
+ React: `useEngine(engine)`, `useDemos(engine)`.
56
+
57
+ ## Demos
58
+
59
+ ```json
60
+ {
61
+ "id": "risk-tour",
62
+ "title": "Risk, explained",
63
+ "start": { "tenant": "Gelsenkirchen" },
64
+ "steps": [
65
+ {
66
+ "say": { "en": "Which pipes matter most?", "de": "Welche Haltungen sind am wichtigsten?" },
67
+ "actions": [
68
+ { "do": "spotlight", "target": { "css": "[data-demo=\"risk matrix\"]" } },
69
+ { "do": "click", "target": { "css": "button", "key": "risk_reset_weights" }, "cue": 0, "wait": 1200 }
70
+ ]
71
+ }
72
+ ]
73
+ }
74
+ ```
75
+
76
+ Each step's narration is spoken a sentence at a time, each a subtitle, while its actions play one
77
+ after the other. A target is `{ css, text?, key?, index? }`: the elements matching `css` whose label -
78
+ `data-demo`, their text, `aria-label`, a field's label - is `text`, or the locale `key`'s text in the
79
+ page's language. Labels compare without case or spacing, every number as `#`. `wait` is ms before an
80
+ action (800), `cue` starts it with a sentence of the step: synced in every language and voice.
81
+
82
+ Actions: `click`, `hover`, `type`, `key`, `select`, `drag`, `scroll`, `waitFor`; and to present,
83
+ `spotlight`, `ring`, `arrow`, `callout`, `blur`, `card`, `zoom`, `clear` (shown till the step ends,
84
+ or `for` ms). [AGENTS.md](AGENTS.md) has every field; it is also what an AI reads.
85
+
86
+ A demo leaves the app as it found it, so it plays again and the next starts where it expects:
87
+ its `cleanup` actions run after it - when it ends or is stopped - quickly and unseen (filters
88
+ cleared, what it opened closed); what the app cannot undo through its UI, `start.go` resets before
89
+ every play and check (a sandbox tenant, demo data reloaded, the page reloaded).
90
+
91
+ `data-demo="name"` on an element names it for demos in every language and gives targets a scope.
92
+ `data-demo-ignore` keeps a part of the page out of recording and targets (a dev panel).
93
+
94
+ ## Plugins
95
+
96
+ What only the app knows: a map's views and points, a canvas chart's bars.
97
+
98
+ ```ts
99
+ const mapPlugin = (map: WebGLMap): DemoPlugin => ({
100
+ name: 'map',
101
+ actions: {
102
+ view: { play: action => showBounds(map, action.bounds), read: () => 'Move the map', duration: () => 1200 },
103
+ mapClick: {
104
+ async play(action, { hand }) {
105
+ const at = toView(map, action.at); // lon, lat → px in the map
106
+ const box = map.domNode.getBoundingClientRect();
107
+ await hand.click(map.domNode, { x: box.left + at.x, y: box.top + at.y }, { shift: action.shift });
108
+ },
109
+ read: () => 'Click on the map',
110
+ },
111
+ },
112
+ record: ({ push }) => {
113
+ const moved = map.on('MapChange', () => /* once at rest */ push({ do: 'view', bounds: viewBounds(map) }));
114
+ return {
115
+ claims: element => map.domNode.contains(element), // the engine records nothing there itself
116
+ click: (element, x, y) => ({ do: 'mapClick', at: toWorld(map, x, y) }),
117
+ stop: () => moved.remove(),
118
+ };
119
+ },
120
+ });
121
+ ```
122
+
123
+ ## Playing
124
+
125
+ | | |
126
+ |---|---|
127
+ | Space | pause, resume |
128
+ | → Enter PageDown | waiting: go on; else on to the next step (the rest of this one done quickly) |
129
+ | ← PageUp | waiting: say the step again |
130
+ | Esc | stop |
131
+ | Ctrl+Shift+L | stop a loop |
132
+ | Recording: Alt+N, Alt+H, Esc | next step, a hover where the pointer is, stop |
133
+
134
+ While a demo plays, the viewer's own clicks, keys and scrolling do not reach the app - they would
135
+ take the demo off its path - and the bar says why. Paused, the app is theirs. Guided, the ringed
136
+ part is. At a booth, a visitor's touch hands the app over.
137
+
138
+ A presenter's clicker sends PageDown and PageUp: "Wait for the presenter after each step" makes
139
+ a pitch. Guided, the viewer does each click, entry and choice; "Do it for me" lets the demo. Looped,
140
+ a visitor's touch hands the app over; after `idle` it plays on, from the app's start (or a reload).
141
+ A booth with sound: start the browser allowing it, e.g. Chrome's
142
+ `--autoplay-policy=no-user-gesture-required --kiosk`.
143
+
144
+ ## In the browser
145
+
146
+ Free voices and Whisper download once from public CDNs (jsDelivr, Hugging Face) and are kept by the
147
+ browser: about 80-330 MB for Kokoro, 60 MB per Piper voice, 40-250 MB for Whisper. An ElevenLabs
148
+ key is kept in the browser's local storage, every sentence paid for once and kept. Demos, videos
149
+ and the music are kept in IndexedDB, per app. Filming uses the tab's own capture (Chrome, Edge:
150
+ MP4; Firefox: WebM).
151
+
152
+ ## From Ing+ `src/demos`
153
+
154
+ The format is the same: `.demo.json` files play as they are, once the map's actions
155
+ (`view`, `mapClick`, `mapHover`) come in as a plugin. `DemoPlayer`, `DemoRecorder`, `DemoTargets`,
156
+ `DemoSpeech`, `DemoVideo`, `DemoStore`, `DemoLink`, `DemoSession`, `DemoOverlay` and `DemoEditor` are
157
+ the engine; `DemosGroup` becomes `<DemoLibrary>`; `start` and its reloads go to `start`; the locale
158
+ keys to `labels`; the highlight manager's readiness to `ready`.
159
+
160
+ ## Publishing
161
+
162
+ Straight to npm, by [`.github/workflows/publish.yml`](.github/workflows/publish.yml) with npm's
163
+ **Trusted Publishing**: no npm token anywhere. A `v*.*.*` tag push runs it: it tests, compiles and
164
+ publishes `build/`, which is the package.
165
+
166
+ ```bash
167
+ npm version patch # or minor / major - bumps package.json and tags it
168
+ git push --follow-tags
169
+ ```
170
+
171
+ One-time setup, by the npm account owner: publish the first version by hand (`npm login
172
+ --auth-type=web`, then `npm run deploy`; `npm-first-publish.cmd` in the protomaze folder does both),
173
+ then in the package's settings on npmjs.com add a Trusted Publisher: GitHub Actions, repository
174
+ `protomaze/demo-engine`, workflow `publish.yml`. npm checks `repository.url` in `package.json`
175
+ against the repository, so it stays `git+https://github.com/protomaze/demo-engine.git`. The
176
+ protomaze folder's `NPM_README.md` has the whole procedure, for every package.
@@ -0,0 +1,155 @@
1
+ import { Demo, DemoAction, DemoTarget } from '../model/Demo';
2
+ import type { CheckReport, DemoEngine } from '../engine/DemoEngine';
3
+ import type { Listed } from '../page/Targets';
4
+ type DemoOrId = Demo | string;
5
+ /**
6
+ * Tools for an AI that sees the app through a browser and runs JavaScript in it: look at what can
7
+ * be acted on, try actions, write a demo, check it plays, save it, open it for the person. Every
8
+ * result is plain data. `demoEngine.help()` says how.
9
+ */
10
+ export declare function agentTools(engine: DemoEngine): {
11
+ /** How to make a demo with these tools: read it first. */
12
+ help: () => string;
13
+ /** The languages narration is written in, and the one it plays in now. */
14
+ languages: () => {
15
+ write: string[];
16
+ plays: string;
17
+ };
18
+ /** Where the app is: a demo made now starts there. */
19
+ start: () => Record<string, string> | null;
20
+ /**
21
+ * What is on the page to act on, as targets ready for actions: `within` a region (css), `query`
22
+ * a text in their labels. Also the headings and open dialogs, to know where one is.
23
+ */
24
+ page: ({ within, query, limit }?: {
25
+ within?: string;
26
+ query?: string;
27
+ limit?: number;
28
+ }) => {
29
+ url: string;
30
+ title: string;
31
+ viewport: {
32
+ width: number;
33
+ height: number;
34
+ };
35
+ headings: string[];
36
+ dialogs: string[];
37
+ targets: Listed[];
38
+ };
39
+ /** How many elements a target names, whether the one it means shows, and where. */
40
+ find: (target: DemoTarget) => {
41
+ label?: string | undefined;
42
+ box?: {
43
+ x: number;
44
+ y: number;
45
+ width: number;
46
+ height: number;
47
+ } | undefined;
48
+ matches: number;
49
+ shown: boolean;
50
+ };
51
+ /** A target for the element at a point of the viewport, or the first matching `css`. */
52
+ describe: (where: string | [number, number]) => {
53
+ target: DemoTarget;
54
+ label: string;
55
+ tag: string;
56
+ };
57
+ /**
58
+ * Does one action now, quickly, as a demo would: to explore the app and to test a target.
59
+ * Says what came on the page with it, and what went.
60
+ */
61
+ try: (action: DemoAction) => Promise<{
62
+ ok: boolean;
63
+ error?: string;
64
+ appeared: Listed[];
65
+ gone: string[];
66
+ }>;
67
+ /** Shows a presentation action - spotlight, ring, arrow, callout, blur, card, zoom - for `ms`, to see how it looks. */
68
+ preview: (action: DemoAction, ms?: number) => Promise<{
69
+ error?: string | undefined;
70
+ ok: boolean;
71
+ }>;
72
+ /** The demos there are. */
73
+ demos: () => Promise<{
74
+ id: string;
75
+ title: string;
76
+ description: string;
77
+ steps: number;
78
+ origin: "app" | "edited" | "here";
79
+ languages: string[];
80
+ duration: string;
81
+ video: boolean;
82
+ }[]>;
83
+ get: (id: string) => Promise<Demo>;
84
+ /** What is wrong with it as a demo, [] if nothing: its shape only; `check` plays it. */
85
+ validate: (demo: Demo) => import("..").Problem[];
86
+ /** How long it plays, about, and each step: for pacing. */
87
+ estimate: (demo: DemoOrId) => Promise<{
88
+ duration: string;
89
+ steps: {
90
+ step: number;
91
+ seconds: number;
92
+ }[];
93
+ }>;
94
+ /**
95
+ * Plays it fast and silent from its start, going past what fails, its cleanup after: every
96
+ * target found, every action played? `from`, `to`: steps, 0-based.
97
+ */
98
+ check: (demo: DemoOrId, options?: {
99
+ from?: number;
100
+ to?: number;
101
+ }) => Promise<CheckReport>;
102
+ /** Kept in this browser; shows in the library. Over an app's demo of the same id, until removed. */
103
+ save: (demo: Demo) => Promise<{
104
+ ok: boolean;
105
+ problems: import("..").Problem[];
106
+ id?: undefined;
107
+ } | {
108
+ ok: boolean;
109
+ id: string;
110
+ problems?: undefined;
111
+ }>;
112
+ remove: (id: string) => Promise<{
113
+ ok: boolean;
114
+ }>;
115
+ /** Opens it in the studio, for the person to see, tune and play. */
116
+ open: (demo: DemoOrId) => Promise<{
117
+ ok: boolean;
118
+ }>;
119
+ /**
120
+ * Plays it for the person, with narration. Sound needs a click in the page: without one,
121
+ * the page asks the person to click to start. Resolves at once.
122
+ */
123
+ play: (demo: DemoOrId, options?: {
124
+ from?: number;
125
+ }) => Promise<{
126
+ note?: string | undefined;
127
+ ok: boolean;
128
+ state: "playing" | "recording" | "idle" | "ready" | "preparing";
129
+ }>;
130
+ /** Plays it guided, for a tutorial: the person does each click and entry, the page shows what. Needs their click too. */
131
+ guide: (demo: DemoOrId, options?: {
132
+ from?: number;
133
+ }) => Promise<{
134
+ ok: boolean;
135
+ state: "playing" | "recording" | "idle" | "ready" | "preparing";
136
+ }>;
137
+ /** Plays these on a loop, unattended: an expo booth. A visitor's touch hands the app over; idle, it plays on. */
138
+ loop: (demos: DemoOrId[]) => Promise<{
139
+ ok: boolean;
140
+ }>;
141
+ stopLoop: () => {
142
+ ok: boolean;
143
+ };
144
+ stop: () => {
145
+ ok: boolean;
146
+ };
147
+ /** What the engine is doing now. */
148
+ state: () => {
149
+ message: string | undefined;
150
+ };
151
+ /** A link that opens the app with the demo in it. */
152
+ link: (demo: DemoOrId) => Promise<string>;
153
+ };
154
+ export type AgentTools = ReturnType<typeof agentTools>;
155
+ export {};
package/agent/Agent.js ADDED
@@ -0,0 +1 @@
1
+ import{copyOf as e,isTarget as t}from"../model/Demo.js";import{clock as o}from"../model/Timing.js";import{validate as i}from"../model/Validate.js";import{GUIDE as a}from"./Guide.js";export function agentTools(r){const s=async e=>{if("string"!=typeof e)return e;const t=(await r.entries()).find(t=>t.demo.id===e);if(!t)throw new Error(`No demo "${e}": demoEngine.demos() lists them`);return t.demo};return{help:()=>a,languages:()=>({write:r.languages(),plays:r.language()}),start:()=>r.options.start?.current()??null,page:({within:e,query:t,limit:o}={})=>{const i=e=>e.getClientRects().length>0&&!e.closest("[data-demo-ignore]"),a=e=>Array.from(document.querySelectorAll(e)).filter(i).map(e=>e.innerText?.trim().replace(/\s+/g," ").slice(0,100)).filter(Boolean);return{url:window.location.href,title:document.title,viewport:{width:innerWidth,height:innerHeight},headings:a('h1, h2, h3, h4, h5, h6, [role="heading"]').slice(0,60),dialogs:a('dialog[open], [role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]').slice(0,10),targets:r.targets.list({within:e,query:t,limit:o??250})}},find:e=>{if(!t(e))throw new Error("A target is { css, text?, key?, index? }");const o=r.targets.matches(e),i=o[e.index??0],a=i?.getBoundingClientRect();return{matches:o.length,shown:Boolean(i&&i.getClientRects().length>0),...i?{label:r.targets.labelOf(i),box:{x:Math.round(a.x),y:Math.round(a.y),width:Math.round(a.width),height:Math.round(a.height)}}:{}}},describe:e=>{const t="string"==typeof e?document.querySelector(e):r.targets.targetElement(document.elementsFromPoint(e[0],e[1]).find(e=>!e.closest("[data-demo-ignore]"))??null);if(!t)throw new Error(`Nothing at ${JSON.stringify(e)}`);const o=r.targets.targetElement(t)??t;return{target:r.targets.describe(o),label:r.targets.labelOf(o),tag:o.tagName.toLowerCase()}},try:async e=>{const t=r.targets.list({limit:600}),o=await r.check({id:"try",title:"Try",steps:[{say:{},actions:[{...e,wait:0}]}]},{speed:2});await new Promise(e=>setTimeout(e,400));const i=r.targets.list({limit:600}),a=e=>JSON.stringify(e.target),s=new Set(t.map(a)),n=new Set(i.map(a));return{ok:o.ok,...o.ok?{}:{error:o.failures[0]?.error??o.error??o.problems.map(e=>`${e.path} ${e.message}`).join("; ")},appeared:i.filter(e=>!s.has(a(e))).slice(0,60),gone:t.filter(e=>!n.has(a(e))).map(e=>e.label).slice(0,60)}},preview:async(e,t=3e3)=>{const o=await r.check({id:"preview",title:"Preview",steps:[{say:{},actions:[{...e,wait:0}],hold:t}]},{speed:1});return{ok:o.ok,...o.ok?{}:{error:o.failures[0]?.error??o.error}}},demos:async()=>(await r.entries()).map(({demo:e,origin:t,video:i})=>({id:e.id,title:e.title,description:e.description??"",steps:e.steps.length,origin:t,languages:r.languagesOf(e),duration:o(r.timing(e).duration),video:Boolean(i)})),get:async t=>e(await s(t)),validate:e=>i(e,r.pluginKinds()),estimate:async e=>{const t=r.timing(await s(e));return{duration:o(t.duration),steps:t.steps.map(e=>({step:e.step,seconds:Math.round((e.end-e.start)/100)/10}))}},check:async(e,t={})=>r.check(await s(e),t),save:async e=>{const t=i(e,r.pluginKinds());return t.length?{ok:!1,problems:t}:(await r.save(e),{ok:!0,id:e.id})},remove:async e=>(await r.remove(e),{ok:!0}),open:async e=>(r.openStudio(await s(e)),{ok:!0}),play:async(e,t={})=>{r.play(await s(e),t);const o=r.getState().session;return{ok:!0,state:o.mode,..."ready"===o.mode?{note:'Waiting for the person to click "Play" on the page.'}:{}}},guide:async(e,t={})=>(r.guide(await s(e),t),{ok:!0,state:r.getState().session.mode}),loop:async e=>(r.loop(await Promise.all(e.map(s))),{ok:!0}),stopLoop:()=>(r.stopLoop(),{ok:!0}),stop:()=>(r.stop(),{ok:!0}),state:()=>{const{session:e,message:t}=r.getState(),{player:o,demo:i,...a}=e;return{...a,message:t?.text}},link:async e=>r.link(await s(e))}}
@@ -0,0 +1,2 @@
1
+ /** How an AI makes a demo with `window.demoEngine`: `demoEngine.help()` returns it; AGENTS.md is made from it. */
2
+ export declare const GUIDE = "# Making a demo with demoEngine\n\nYou see the app in a browser and run JavaScript in it. `window.demoEngine` has the tools; every\nresult is plain data. A demo is steps; each step's narration is spoken (and subtitled) a sentence at\na time while its actions play one after the other. Actions point at elements as a person would: by\nwhat they show, not where they are.\n\n## Workflow\n\n1. `demoEngine.languages()` - which languages to write narration in.\n `demoEngine.start()` - where the app is; a demo starts there. `demoEngine.demos()` - what exists.\n2. Explore. `demoEngine.page()` lists what can be acted on, each with a ready `target`, its label,\n state and box; `page({ query: 'save' })` or `page({ within: '[data-demo=\"filters\"]' })` narrows it.\n Look with screenshots too. `demoEngine.try({ do: 'click', target })` does one action now and says\n what appeared and went: walk the app this way to learn the path the demo will take.\n3. Plan the story before the actions: what should the viewer understand at the end? One idea per step.\n4. Write the demo (format below). Narration first, then the actions that show it.\n5. `demoEngine.validate(demo)` - its shape. Then `await demoEngine.check(demo)` - from the demo's\n start, fast and silent, going past what fails, its cleanup after; fix every failure and check\n again until `ok` twice in a row (the second run proves the cleanup).\n6. `await demoEngine.save(demo)`, then `demoEngine.open(demo.id)` - the person sees it in the\n studio, can play, tune, film and share it. `demoEngine.play(id)` plays it with sound once the\n person clicks. `demoEngine.estimate(demo)` gives its length.\n\n## Length\n\n- Short (a teaser, one feature): 4-7 steps, 30-60 s, one or two sentences a step.\n- Normal (a tour): 8-12 steps, 1-3 min.\n- Detailed (a deep dive): 12-25 steps, 3-6 min; still one idea per step.\n\n## What it is for\n\n- Marketing video: short, benefit first, a `card` to open and close, zooms on what impresses; no\n setup steps on screen. The person films it (film button); music can play under it.\n- Sales pitch: one step per point the presenter makes; `pause: true` on steps where they talk\n freely. They advance with a clicker (PageDown) and repeat with PageUp.\n- Expo booth: 30-90 s, readable without sound (subtitles carry it), ends where it started so it can\n loop. `demoEngine.loop([ids])` plays them unattended; a visitor's touch hands the app over.\n- Tutorial or training: `demoEngine.guide(id)` lets the viewer do each click and entry themselves,\n ringed with what to do. Narrate why, not only what; small steps; one new thing each.\n\n## Narration\n\n- For the viewer, about what matters to them: \"Which pipes need work first?\" before \"Click Risk\".\n- Present tense, plain words, at most ~20 words a sentence; a step ~1-3 sentences.\n- Say what to look at as it happens; name things as the app names them.\n- Every language of `languages().write`: `say: { en: '\u2026', de: '\u2026' }`. Same meaning, natural in each.\n- No \"In this demo\u2026\" filler; open with the question or the benefit, close with what was shown.\n\n## Format\n\n```json\n{\n \"id\": \"orders-tour\",\n \"title\": \"Orders, from list to invoice\",\n \"description\": \"One sentence: who it is for and what it shows.\",\n \"start\": { \"\u2026\": \"as demoEngine.start() gives it, or leave out\" },\n \"steps\": [\n {\n \"title\": \"Find an order\",\n \"say\": { \"en\": \"Every order lands here, newest first. Let's find one from Berlin.\" },\n \"actions\": [\n { \"do\": \"spotlight\", \"target\": { \"css\": \"table\", \"text\": \"orders\" }, \"for\": 2500 },\n { \"do\": \"type\", \"target\": { \"css\": \"input[type=\\\"search\\\"]\" }, \"text\": \"Berlin\", \"cue\": 1 },\n { \"do\": \"click\", \"target\": { \"css\": \"tr\", \"text\": \"berlin #\" }, \"wait\": 1200 }\n ]\n }\n ]\n}\n```\n\nA target: `{ css, text?, key?, index? }` - the `index`th (0-based) element matching `css` whose label\nis `text` (or the app's locale `key`'s text: works in every language). Labels compare without case,\nspacing, and with every number as \"#\": a row \"Berlin 42\" is \"berlin #\". Use the targets `page()` and\n`describe()` give: they prefer locale keys and named regions. Avoid `index` where a scope does it:\n`{ css: '[data-demo=\"filters\"] button', text: 'apply' }`.\n\nEvery action has `wait` (ms before it, default 800) and `cue` (start with the step's sentence of that\nindex, 0-based: syncs a click with the words about it, in every language and voice).\n\nInteractions:\n- `click` { target, at?: [x, y] fractions of the box, double?, right?, shift?, ctrl?, alt?, meta? }\n- `hover` { target, at? } - shows tooltips and hover cards (not CSS :hover looks)\n- `type` { target, text } - replaces the field's text, a letter at a time\n- `key` { key, target? } - 'Escape', 'Enter', 'ArrowDown', 'Control+K'; shown as keycaps\n- `select` { target, option } - a native <select>'s option by text or value\n- `drag` { target, at?, to: { target?, at? } } - sliders, drag and drop, panning\n- `scroll` { target?, by?: [x, y] } - into view, or by pixels\n- `waitFor` { target, gone?, timeout? } - until it shows (or goes): after what loads\n\nPresentation (shown until the step ends, or `for` ms; `clear` takes all down):\n- `spotlight` { target, text?, padding? } - dims everything else: the one thing to look at\n- `ring` { target, text?, color?, shape?: 'box' | 'circle' } - a pulsing outline\n- `arrow` { target, text?, from?: 'top' | 'right' | 'bottom' | 'left' } - points at it\n- `callout` { text, target?, side?, corner? } - a note by the target, or in a corner\n- `blur` { target } - hides names, addresses, anything private\n- `card` { title, text? } - full screen: an opening title, a chapter, the end\n- `zoom` { target, scale? } - magnifies the page around it (1.8 by default)\n- `clear`\n\nThe app may add its own actions (a map's `view`, `mapClick`): `validate` lists every kind it knows\nwhen one is wrong; read the app's demos (`demoEngine.get(id)`) for examples.\n\nStep options: `title` (for the editor), `hold` (ms after), `pause: true` (waits for the presenter).\n\n`cleanup`: actions done after the demo - when it ends or is stopped - quickly and unseen, so the app\nis as it found it and the demo plays again: clear filters and searches, close what was opened, go\nback to the first tab. What the app cannot undo through its UI, its start resets.\n\n## Good demos\n\n- Open with a `card` (title, one line of promise), close with one (what was shown, what next).\n- Direct the eye: a spotlight or ring on what the sentence is about, an arrow for small things.\n- Let the viewer see results: a `wait` of 1500-3000 ms after what changes a lot; `waitFor` what loads.\n- Keep the pointer purposeful: no clicks that do not move the story.\n- Blur personal data.\n- Leave the app as it started: a `cleanup` list undoes what the steps changed, so demos run one\n after another and again. Check that too: `check` runs the cleanup, then `check` again.\n\n## Tools\n\nhelp() \u00B7 languages() \u00B7 start() \u00B7 page({ within?, query?, limit? }) \u00B7 find(target) \u00B7\ndescribe(css | [x, y]) \u00B7 try(action) \u00B7 preview(presentationAction, ms?) \u00B7 demos() \u00B7 get(id) \u00B7\nvalidate(demo) \u00B7 estimate(demoOrId) \u00B7 check(demoOrId, { from?, to? }) \u00B7 save(demo) \u00B7 remove(id) \u00B7\nopen(demoOrId) \u00B7 play(demoOrId, { from? }) \u00B7 guide(demoOrId, { from? }) \u00B7 loop([demoOrId]) \u00B7\nstopLoop() \u00B7 stop() \u00B7 state() \u00B7 link(demoOrId)\n";
package/agent/Guide.js ADDED
@@ -0,0 +1 @@
1
+ export const GUIDE='# Making a demo with demoEngine\n\nYou see the app in a browser and run JavaScript in it. `window.demoEngine` has the tools; every\nresult is plain data. A demo is steps; each step\'s narration is spoken (and subtitled) a sentence at\na time while its actions play one after the other. Actions point at elements as a person would: by\nwhat they show, not where they are.\n\n## Workflow\n\n1. `demoEngine.languages()` - which languages to write narration in.\n `demoEngine.start()` - where the app is; a demo starts there. `demoEngine.demos()` - what exists.\n2. Explore. `demoEngine.page()` lists what can be acted on, each with a ready `target`, its label,\n state and box; `page({ query: \'save\' })` or `page({ within: \'[data-demo="filters"]\' })` narrows it.\n Look with screenshots too. `demoEngine.try({ do: \'click\', target })` does one action now and says\n what appeared and went: walk the app this way to learn the path the demo will take.\n3. Plan the story before the actions: what should the viewer understand at the end? One idea per step.\n4. Write the demo (format below). Narration first, then the actions that show it.\n5. `demoEngine.validate(demo)` - its shape. Then `await demoEngine.check(demo)` - from the demo\'s\n start, fast and silent, going past what fails, its cleanup after; fix every failure and check\n again until `ok` twice in a row (the second run proves the cleanup).\n6. `await demoEngine.save(demo)`, then `demoEngine.open(demo.id)` - the person sees it in the\n studio, can play, tune, film and share it. `demoEngine.play(id)` plays it with sound once the\n person clicks. `demoEngine.estimate(demo)` gives its length.\n\n## Length\n\n- Short (a teaser, one feature): 4-7 steps, 30-60 s, one or two sentences a step.\n- Normal (a tour): 8-12 steps, 1-3 min.\n- Detailed (a deep dive): 12-25 steps, 3-6 min; still one idea per step.\n\n## What it is for\n\n- Marketing video: short, benefit first, a `card` to open and close, zooms on what impresses; no\n setup steps on screen. The person films it (film button); music can play under it.\n- Sales pitch: one step per point the presenter makes; `pause: true` on steps where they talk\n freely. They advance with a clicker (PageDown) and repeat with PageUp.\n- Expo booth: 30-90 s, readable without sound (subtitles carry it), ends where it started so it can\n loop. `demoEngine.loop([ids])` plays them unattended; a visitor\'s touch hands the app over.\n- Tutorial or training: `demoEngine.guide(id)` lets the viewer do each click and entry themselves,\n ringed with what to do. Narrate why, not only what; small steps; one new thing each.\n\n## Narration\n\n- For the viewer, about what matters to them: "Which pipes need work first?" before "Click Risk".\n- Present tense, plain words, at most ~20 words a sentence; a step ~1-3 sentences.\n- Say what to look at as it happens; name things as the app names them.\n- Every language of `languages().write`: `say: { en: \'…\', de: \'…\' }`. Same meaning, natural in each.\n- No "In this demo…" filler; open with the question or the benefit, close with what was shown.\n\n## Format\n\n```json\n{\n "id": "orders-tour",\n "title": "Orders, from list to invoice",\n "description": "One sentence: who it is for and what it shows.",\n "start": { "…": "as demoEngine.start() gives it, or leave out" },\n "steps": [\n {\n "title": "Find an order",\n "say": { "en": "Every order lands here, newest first. Let\'s find one from Berlin." },\n "actions": [\n { "do": "spotlight", "target": { "css": "table", "text": "orders" }, "for": 2500 },\n { "do": "type", "target": { "css": "input[type=\\"search\\"]" }, "text": "Berlin", "cue": 1 },\n { "do": "click", "target": { "css": "tr", "text": "berlin #" }, "wait": 1200 }\n ]\n }\n ]\n}\n```\n\nA target: `{ css, text?, key?, index? }` - the `index`th (0-based) element matching `css` whose label\nis `text` (or the app\'s locale `key`\'s text: works in every language). Labels compare without case,\nspacing, and with every number as "#": a row "Berlin 42" is "berlin #". Use the targets `page()` and\n`describe()` give: they prefer locale keys and named regions. Avoid `index` where a scope does it:\n`{ css: \'[data-demo="filters"] button\', text: \'apply\' }`.\n\nEvery action has `wait` (ms before it, default 800) and `cue` (start with the step\'s sentence of that\nindex, 0-based: syncs a click with the words about it, in every language and voice).\n\nInteractions:\n- `click` { target, at?: [x, y] fractions of the box, double?, right?, shift?, ctrl?, alt?, meta? }\n- `hover` { target, at? } - shows tooltips and hover cards (not CSS :hover looks)\n- `type` { target, text } - replaces the field\'s text, a letter at a time\n- `key` { key, target? } - \'Escape\', \'Enter\', \'ArrowDown\', \'Control+K\'; shown as keycaps\n- `select` { target, option } - a native <select>\'s option by text or value\n- `drag` { target, at?, to: { target?, at? } } - sliders, drag and drop, panning\n- `scroll` { target?, by?: [x, y] } - into view, or by pixels\n- `waitFor` { target, gone?, timeout? } - until it shows (or goes): after what loads\n\nPresentation (shown until the step ends, or `for` ms; `clear` takes all down):\n- `spotlight` { target, text?, padding? } - dims everything else: the one thing to look at\n- `ring` { target, text?, color?, shape?: \'box\' | \'circle\' } - a pulsing outline\n- `arrow` { target, text?, from?: \'top\' | \'right\' | \'bottom\' | \'left\' } - points at it\n- `callout` { text, target?, side?, corner? } - a note by the target, or in a corner\n- `blur` { target } - hides names, addresses, anything private\n- `card` { title, text? } - full screen: an opening title, a chapter, the end\n- `zoom` { target, scale? } - magnifies the page around it (1.8 by default)\n- `clear`\n\nThe app may add its own actions (a map\'s `view`, `mapClick`): `validate` lists every kind it knows\nwhen one is wrong; read the app\'s demos (`demoEngine.get(id)`) for examples.\n\nStep options: `title` (for the editor), `hold` (ms after), `pause: true` (waits for the presenter).\n\n`cleanup`: actions done after the demo - when it ends or is stopped - quickly and unseen, so the app\nis as it found it and the demo plays again: clear filters and searches, close what was opened, go\nback to the first tab. What the app cannot undo through its UI, its start resets.\n\n## Good demos\n\n- Open with a `card` (title, one line of promise), close with one (what was shown, what next).\n- Direct the eye: a spotlight or ring on what the sentence is about, an arrow for small things.\n- Let the viewer see results: a `wait` of 1500-3000 ms after what changes a lot; `waitFor` what loads.\n- Keep the pointer purposeful: no clicks that do not move the story.\n- Blur personal data.\n- Leave the app as it started: a `cleanup` list undoes what the steps changed, so demos run one\n after another and again. Check that too: `check` runs the cleanup, then `check` again.\n\n## Tools\n\nhelp() · languages() · start() · page({ within?, query?, limit? }) · find(target) ·\ndescribe(css | [x, y]) · try(action) · preview(presentationAction, ms?) · demos() · get(id) ·\nvalidate(demo) · estimate(demoOrId) · check(demoOrId, { from?, to? }) · save(demo) · remove(id) ·\nopen(demoOrId) · play(demoOrId, { from? }) · guide(demoOrId, { from? }) · loop([demoOrId]) ·\nstopLoop() · stop() · state() · link(demoOrId)\n';