@protomaze/demo-engine 0.1.9 → 0.1.11
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/AGENTS.md +28 -13
- package/README.md +17 -3
- package/agent/Agent.d.ts +32 -5
- package/agent/Agent.js +1 -1
- package/agent/Assistant.d.ts +83 -0
- package/agent/Assistant.js +1 -0
- package/agent/Guide.d.ts +1 -1
- package/agent/Guide.js +1 -1
- package/engine/DemoEngine.d.ts +29 -2
- package/engine/DemoEngine.js +1 -1
- package/engine/Player.d.ts +1 -1
- package/engine/Player.js +1 -1
- package/engine/Read.d.ts +2 -2
- package/engine/Read.js +1 -1
- package/engine/Settings.d.ts +3 -0
- package/engine/Settings.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +1 -1
- package/model/Demo.d.ts +14 -6
- package/model/Demo.js +1 -1
- package/model/Validate.js +1 -1
- package/package.json +2 -1
- package/page/Still.d.ts +5 -4
- package/page/Still.js +1 -1
- package/page/Targets.js +1 -1
- package/store/Share.d.ts +2 -0
- package/store/Share.js +1 -1
- package/ui/Actions.js +1 -1
- package/ui/Assistant.d.ts +9 -0
- package/ui/Assistant.js +1 -0
- package/ui/EngineUI.js +1 -1
- package/ui/Kit.d.ts +2 -0
- package/ui/Kit.js +1 -1
- package/ui/Library.js +1 -1
- package/ui/Studio.js +1 -1
- package/ui/Styles.d.ts +1 -1
- package/ui/Styles.js +1 -1
package/AGENTS.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<!-- Made from src/agent/Guide.ts by dev/guide.js: edit that. -->
|
|
2
2
|
|
|
3
|
-
An app using @protomaze/demo-engine exposes these tools on `window.demoEngine`
|
|
3
|
+
An app using @protomaze/demo-engine exposes these tools on `window.demoEngine` (unless it keeps them off).
|
|
4
4
|
Drive them through a browser's JavaScript console or an agent's "run JavaScript in the page" tool.
|
|
5
5
|
|
|
6
6
|
# Making a demo with demoEngine
|
|
7
7
|
|
|
8
|
-
You see the app in a browser and run JavaScript in it. `window.demoEngine` has the tools
|
|
9
|
-
result is plain data. A demo is steps; each step's narration is spoken (and subtitled) a sentence at
|
|
8
|
+
You see the app in a browser and run JavaScript in it. `window.demoEngine` has the tools: `await`
|
|
9
|
+
each call (most return a Promise); every result is plain data. A demo is steps; each step's narration is spoken (and subtitled) a sentence at
|
|
10
10
|
a time while its actions play one after the other. Actions point at elements as a person would: by
|
|
11
11
|
what they show, not where they are.
|
|
12
12
|
|
|
@@ -23,11 +23,20 @@ what they show, not where they are.
|
|
|
23
23
|
5. `demoEngine.validate(demo)` - its shape. Then `await demoEngine.check(demo)` - from the demo's
|
|
24
24
|
start, fast and silent, going past what fails, its cleanup after; fix every failure and check
|
|
25
25
|
again until `ok` twice in a row (the second run proves the cleanup). The page's CSS transitions
|
|
26
|
-
and animations are off while it runs, so it works in a background tab too.
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
and animations are off while it runs, so it works in a background tab too. After a failure, what
|
|
27
|
+
follows is waited for 2 s only (it mostly failed with it): fix the first failure first.
|
|
28
|
+
6. `await demoEngine.save(demo)`, then `demoEngine.open(demo.id)` where the person watches your
|
|
29
|
+
browser - they see it in the studio, can play, tune, film and share it (else see below). `demoEngine.play(id)` plays it with sound once the
|
|
29
30
|
person clicks. `demoEngine.estimate(demo)` gives its length.
|
|
30
31
|
|
|
32
|
+
## Your browser and the person's
|
|
33
|
+
|
|
34
|
+
What `save` keeps stays in the browser you work in. Not the person's own (a browser of yours,
|
|
35
|
+
another profile)? Give them `await demoEngine.link(id)`: opened in their browser, the demo is kept
|
|
36
|
+
there and opens in their studio. Where you can write files, `await demoEngine.get(id)` is its
|
|
37
|
+
`.demo.json` as well (the library's New → Import takes it). A demo of theirs comes to you the same
|
|
38
|
+
way: open its link, or `save(link)`, and it is kept in yours. Signing in to the app is theirs: ask.
|
|
39
|
+
|
|
31
40
|
## Length
|
|
32
41
|
|
|
33
42
|
- Short (a teaser, one feature): 4-7 steps, 30-60 s, one or two sentences a step.
|
|
@@ -66,9 +75,9 @@ what they show, not where they are.
|
|
|
66
75
|
"title": "Find an order",
|
|
67
76
|
"say": { "en": "Every order lands here, newest first. Let's find one from Berlin." },
|
|
68
77
|
"actions": [
|
|
69
|
-
{ "do": "spotlight", "target": { "css": "
|
|
78
|
+
{ "do": "spotlight", "target": { "css": "[data-demo=\"orders\"]" }, "text": { "en": "Orders", "de": "Aufträge" }, "for": 2500 },
|
|
70
79
|
{ "do": "type", "target": { "css": "input[type=\"search\"]" }, "text": "Berlin", "cue": 1 },
|
|
71
|
-
{ "do": "click", "target": { "css": "
|
|
80
|
+
{ "do": "click", "target": { "css": "td", "text": "berlin" }, "wait": 1200 }
|
|
72
81
|
]
|
|
73
82
|
}
|
|
74
83
|
]
|
|
@@ -79,10 +88,13 @@ A target: `{ css, text?, key?, index? }` - the `index`th (0-based) element match
|
|
|
79
88
|
is `text` (or the app's locale `key`'s text: works in every language). Labels compare without case,
|
|
80
89
|
spacing, and with every number as "#": a row "Berlin 42" is "berlin #". Use the targets `page()` and
|
|
81
90
|
`describe()` give: they prefer locale keys and named regions. Avoid `index` where a scope does it:
|
|
82
|
-
`{ css: '[data-demo="filters"] button', text: 'apply' }`.
|
|
91
|
+
`{ css: '[data-demo="filters"] button', text: 'apply' }`. A label is the element's whole text, or its
|
|
92
|
+
`data-demo` name, or its `aria-label` - never a part: a table row's is all its cells, which change
|
|
93
|
+
with the data and the language ("open", "offen"). Target what stays: a cell, a `key`, a named region.
|
|
83
94
|
|
|
84
95
|
Every action has `wait` (ms before it, default 800) and `cue` (start with the step's sentence of that
|
|
85
|
-
index, 0-based: syncs a click with the words about it, in every
|
|
96
|
+
index, 0-based: sentences end with . ? or !; syncs a click with the words about it, in every
|
|
97
|
+
language and voice).
|
|
86
98
|
|
|
87
99
|
Interactions:
|
|
88
100
|
- `click` { target, at?: [x, y] fractions of the box, double?, right?, shift?, ctrl?, alt?, meta? }
|
|
@@ -94,12 +106,15 @@ Interactions:
|
|
|
94
106
|
- `scroll` { target?, by?: [x, y] } - into view, or by pixels
|
|
95
107
|
- `waitFor` { target, gone?, timeout? } - until it shows (or goes): after what loads
|
|
96
108
|
|
|
97
|
-
Presentation (shown until the step ends, or `for` ms; `clear` takes all down)
|
|
109
|
+
Presentation (shown until the step ends, or `for` ms; `clear` takes all down). Their text on the
|
|
110
|
+
screen - a card's title and text, a note, a label - is one for every language, or one per language
|
|
111
|
+
as `say` is: `{ "en": "Orders", "de": "Aufträge" }`.
|
|
98
112
|
- `spotlight` { target, text?, padding? } - dims everything else: the one thing to look at
|
|
99
113
|
- `ring` { target, text?, color?, shape?: 'box' | 'circle' } - a pulsing outline
|
|
100
114
|
- `arrow` { target, text?, from?: 'top' | 'right' | 'bottom' | 'left' } - points at it
|
|
101
115
|
- `callout` { text, target?, side?, corner? } - a note by the target, or in a corner
|
|
102
|
-
- `blur` { target } - hides names, addresses, anything private
|
|
116
|
+
- `blur` { target } - hides names, addresses, anything private; for its step only: blur again first
|
|
117
|
+
thing in each step it shows in (`wait: 0`)
|
|
103
118
|
- `card` { title, text? } - full screen: an opening title, a chapter, the end
|
|
104
119
|
- `zoom` { target, scale? } - magnifies the page around it (1.8 by default)
|
|
105
120
|
- `clear`
|
|
@@ -129,6 +144,6 @@ not there within half a second is skipped, so list every reset that might be nee
|
|
|
129
144
|
|
|
130
145
|
help() · languages() · start() · page({ within?, query?, limit? }) · find(target) ·
|
|
131
146
|
describe(css | [x, y]) · try(action) · preview(presentationAction, ms?) · demos() · get(id) ·
|
|
132
|
-
validate(demo) · estimate(demoOrId) · check(demoOrId, { from?, to?, animations? }) · save(demo) · remove(id) ·
|
|
147
|
+
validate(demo) · estimate(demoOrId) · check(demoOrId, { from?, to?, animations? }) · save(demo | link) · remove(id) ·
|
|
133
148
|
open(demoOrId) · play(demoOrId, { from? }) · guide(demoOrId, { from? }) · loop([demoOrId]) ·
|
|
134
149
|
stopLoop() · stop() · state() · link(demoOrId)
|
package/README.md
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Demos of a web app, made and played in the app itself, in the browser: no backend.
|
|
4
4
|
|
|
5
|
-
- **Make**: by
|
|
6
|
-
|
|
5
|
+
- **Make**: by one's own Claude, with only the app's URL ("a one-minute tour of the orders"), or any
|
|
6
|
+
AI that runs JavaScript in the page (`window.demoEngine`); by recording what you do (and say); or
|
|
7
|
+
by hand in the studio, on a `@protomaze/time` timeline.
|
|
7
8
|
- **Narrate**: text to speech in the browser (Kokoro, Piper: free, no key) or ElevenLabs; speech to
|
|
8
9
|
text (Whisper in the browser, or ElevenLabs) turns what you said into narration and subtitles.
|
|
9
10
|
A **narration pack** keeps a demo's finished audio, so every viewer hears it without a key, tokens
|
|
@@ -56,6 +57,17 @@ recording's microphone; a booth's demos; where the presenter's screen goes - and
|
|
|
56
57
|
click sound and filming need. Everything else - the studio, the bars while playing and recording,
|
|
57
58
|
effects - the engine renders over the app, in the top layer.
|
|
58
59
|
|
|
60
|
+
**With your own Claude**: anyone with the app's URL - no source code, no servers of their own - has
|
|
61
|
+
their Claude make, clone and change demos, working in a browser where it runs JavaScript (Claude in
|
|
62
|
+
Chrome, the Claude app's browser). The library's New → "With your own Claude" copies a prompt to
|
|
63
|
+
paste into it: the app's address, where the tools are (`window.demoEngine`, whose `help()` is
|
|
64
|
+
[AGENTS.md](AGENTS.md)), and how to hand the demo back; a demo's ⋯ menu copies one that brings the
|
|
65
|
+
demo along, in its link. Claude walks the app, writes the narration in every language, checks the
|
|
66
|
+
demo twice and saves it; when its browser is not the person's, it gives them the demo's link, which
|
|
67
|
+
opens it in their studio. The tools are on the page wherever the engine mounts: `agent: false` keeps
|
|
68
|
+
them off, `agent: () => …` decides as it mounts (an environment, a role). They can do what the
|
|
69
|
+
library can, in that browser, as the person signed in.
|
|
70
|
+
|
|
59
71
|
From code: `engine.play(demo, { from })`, `engine.guide(demo)`, `engine.film(demo)`,
|
|
60
72
|
`engine.record()`, `engine.loop(demos, { idle, reset: 'reload' })`, `engine.check(demo)`,
|
|
61
73
|
`engine.openStudio(demo)`, `engine.link(demo)`. Sound and filming need a click in the app's window:
|
|
@@ -89,7 +101,9 @@ action (800), `cue` starts it with a sentence of the step: synced in every langu
|
|
|
89
101
|
|
|
90
102
|
Actions: `click`, `hover`, `type`, `key`, `select`, `drag`, `scroll`, `waitFor`; and to present,
|
|
91
103
|
`spotlight`, `ring`, `arrow`, `callout`, `blur`, `card`, `zoom`, `clear` (shown till the step ends,
|
|
92
|
-
or `for` ms)
|
|
104
|
+
or `for` ms); their text on the screen is one for every language, or one per language as narration
|
|
105
|
+
is (`{ "en": "Orders", "de": "Aufträge" }`). [AGENTS.md](AGENTS.md) has every field; it is also what
|
|
106
|
+
an AI reads.
|
|
93
107
|
|
|
94
108
|
A demo leaves the app as it found it, so it plays again and the next starts where it expects:
|
|
95
109
|
its `cleanup` actions run after it - when it ends or is stopped - quickly and unseen (filters
|
package/agent/Agent.d.ts
CHANGED
|
@@ -33,7 +33,10 @@ export declare function agentTools(engine: DemoEngine): {
|
|
|
33
33
|
height: number;
|
|
34
34
|
};
|
|
35
35
|
headings: string[];
|
|
36
|
-
dialogs:
|
|
36
|
+
dialogs: {
|
|
37
|
+
target: DemoTarget;
|
|
38
|
+
text: string;
|
|
39
|
+
}[];
|
|
37
40
|
targets: Listed[];
|
|
38
41
|
};
|
|
39
42
|
/** How many elements a target names, whether the one it means shows, and where. */
|
|
@@ -63,6 +66,10 @@ export declare function agentTools(engine: DemoEngine): {
|
|
|
63
66
|
error?: string;
|
|
64
67
|
appeared: Listed[];
|
|
65
68
|
gone: string[];
|
|
69
|
+
opened: {
|
|
70
|
+
target: DemoTarget;
|
|
71
|
+
text: string;
|
|
72
|
+
}[];
|
|
66
73
|
}>;
|
|
67
74
|
/** Shows a presentation action - spotlight, ring, arrow, callout, blur, card, zoom - for `ms`, to see how it looks. */
|
|
68
75
|
preview: (action: DemoAction, ms?: number) => Promise<{
|
|
@@ -100,10 +107,16 @@ export declare function agentTools(engine: DemoEngine): {
|
|
|
100
107
|
to?: number;
|
|
101
108
|
animations?: boolean;
|
|
102
109
|
}) => Promise<CheckReport>;
|
|
103
|
-
/**
|
|
104
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Kept in this browser; shows in the library. Over an app's demo of the same id, until removed.
|
|
112
|
+
* Or a link `link()` made: the demo in it is kept here.
|
|
113
|
+
*/
|
|
114
|
+
save: (demoOrLink: Demo | string) => Promise<{
|
|
105
115
|
ok: boolean;
|
|
106
|
-
problems:
|
|
116
|
+
problems: {
|
|
117
|
+
path: string;
|
|
118
|
+
message: string;
|
|
119
|
+
}[];
|
|
107
120
|
id?: undefined;
|
|
108
121
|
} | {
|
|
109
122
|
ok: boolean;
|
|
@@ -149,8 +162,22 @@ export declare function agentTools(engine: DemoEngine): {
|
|
|
149
162
|
state: () => {
|
|
150
163
|
message: string | undefined;
|
|
151
164
|
};
|
|
152
|
-
/**
|
|
165
|
+
/**
|
|
166
|
+
* A link that opens the app with the demo in it: in any browser, which keeps it and opens it
|
|
167
|
+
* in the studio. How a demo goes from a browser of the AI's own to the person's.
|
|
168
|
+
*/
|
|
153
169
|
link: (demo: DemoOrId) => Promise<string>;
|
|
154
170
|
};
|
|
155
171
|
export type AgentTools = ReturnType<typeof agentTools>;
|
|
172
|
+
/**
|
|
173
|
+
* What a person tells their own Claude - working in a browser where it runs JavaScript (Claude in
|
|
174
|
+
* Chrome, the Claude app's browser) - to make a demo of the app at `url`, or to change `demo`, which
|
|
175
|
+
* comes with `link`. Ends where the person says what they want.
|
|
176
|
+
*/
|
|
177
|
+
export declare function promptForClaude({ url, agent, demo, link }: {
|
|
178
|
+
url: string;
|
|
179
|
+
agent: string;
|
|
180
|
+
demo?: Demo;
|
|
181
|
+
link?: string;
|
|
182
|
+
}): string;
|
|
156
183
|
export {};
|
package/agent/Agent.js
CHANGED
|
@@ -1 +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{
|
|
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{demoIn as a}from"../store/Share.js";import{GUIDE as r}from"./Guide.js";export function agentTools(n){const s=async e=>{if("string"!=typeof e)return e;const t=(await n.entries()).find(t=>t.demo.id===e);if(!t)throw new Error(`No demo "${e}": demoEngine.demos() lists them`);return t.demo},l=e=>e.getClientRects().length>0&&!e.closest("[data-demo-ignore]"),d=e=>e.innerText?.trim().replace(/\s+/g," ").slice(0,100)??"",g=()=>Array.from(document.querySelectorAll('dialog[open], [role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]')).filter(l).slice(0,10).map(e=>({target:n.targets.describe(e),text:d(e)}));return{help:()=>r,languages:()=>({write:n.languages(),plays:n.language()}),start:()=>n.options.start?.current()??null,page:({within:e,query:t,limit:o}={})=>{return{url:window.location.href,title:document.title,viewport:{width:innerWidth,height:innerHeight},headings:(i='h1, h2, h3, h4, h5, h6, [role="heading"]',Array.from(document.querySelectorAll(i)).filter(l).map(d).filter(Boolean)).slice(0,60),dialogs:g(),targets:n.targets.list({within:e,query:t,limit:o??250})};var i},find:e=>{if(!t(e))throw new Error("A target is { css, text?, key?, index? }");const o=n.targets.matches(e),i=o[e.index??0],a=i?.getBoundingClientRect();return{matches:o.length,shown:Boolean(i&&i.getClientRects().length>0),...i?{label:n.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):n.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=n.targets.targetElement(t)??t;return{target:n.targets.describe(o),label:n.targets.labelOf(o),tag:o.tagName.toLowerCase()}},try:async e=>{const t=n.targets.list({limit:600}),o=new Set(g().map(e=>e.text)),i=await n.check({id:"try",title:"Try",steps:[{say:{},actions:[{...e,wait:0}]}]},{speed:2});await new Promise(e=>setTimeout(e,400));const a=n.targets.list({limit:600}),r=e=>JSON.stringify(e.target),s=new Set(t.map(r)),l=new Set(a.map(r));return{ok:i.ok,...i.ok?{}:{error:i.failures[0]?.error??i.error??i.problems.map(e=>`${e.path} ${e.message}`).join("; ")},appeared:a.filter(e=>!s.has(r(e))).slice(0,60),gone:t.filter(e=>!l.has(r(e))).map(e=>e.label).slice(0,60),opened:g().filter(e=>!o.has(e.text))}},preview:async(e,t=3e3)=>{const o=await n.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 n.entries()).map(({demo:e,origin:t,video:i})=>({id:e.id,title:e.title,description:e.description??"",steps:e.steps.length,origin:t,languages:n.languagesOf(e),duration:o(n.timing(e).duration),video:Boolean(i)})),get:async t=>e(await s(t)),validate:e=>i(e,n.pluginKinds()),estimate:async e=>{const t=n.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={})=>n.check(await s(e),t),save:async e=>{const t="string"==typeof e?await a(e):e;if(!t)return{ok:!1,problems:[{path:"",message:"No demo in that link: link(id) makes one"}]};const o=i(t,n.pluginKinds());return o.length?{ok:!1,problems:o}:(await n.save(t),{ok:!0,id:t.id})},remove:async e=>(await n.remove(e),{ok:!0}),open:async e=>(n.openStudio(await s(e)),{ok:!0}),play:async(e,t={})=>{n.play(await s(e),t);const o=n.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={})=>(n.guide(await s(e),t),{ok:!0,state:n.getState().session.mode}),loop:async e=>(n.loop(await Promise.all(e.map(s))),{ok:!0}),stopLoop:()=>(n.stopLoop(),{ok:!0}),stop:()=>(n.stop(),{ok:!0}),state:()=>{const{session:e,message:t}=n.getState(),{player:o,demo:i,...a}=e;return{...a,message:t?.text}},link:async e=>n.link(await s(e))}}export function promptForClaude({url:e,agent:t,demo:o,link:i}){const a="in a browser where you can run JavaScript in the page (Claude in Chrome, or the browser in the Claude app)",r=["If the app asks for a sign-in, ask me to sign in there.",`The page has tools for demos on window.${t}: run ${t}.help() in the page first and follow it.`],n=`When it is checked and saved, give me the link from \`await ${t}.link(id)\`: it opens the demo in my own browser. If you can write files, also save \`await ${t}.get(id)\` as <id>.demo.json.`;return o&&i?[`Change the demo "${o.title}" (id "${o.id}") of the web app at ${e}`,`Open this link ${a}: it brings the demo into the app.`,i,...r,"A copy of it gets an id of its own.",n,"","What to change: "].join("\n"):[`Make a demo of the web app at ${e}`,`Work ${a}.`,...r,n,"","The demo should show: "].join("\n")}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Demo } from '../model/Demo';
|
|
2
|
+
import type { DemoEngine } from '../engine/DemoEngine';
|
|
3
|
+
/** One line of the conversation, as the panel shows it. */
|
|
4
|
+
export type AssistantEntry = {
|
|
5
|
+
kind: 'you';
|
|
6
|
+
text: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'claude';
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
/** A tool Claude used: what it did, in words. */
|
|
12
|
+
| {
|
|
13
|
+
kind: 'did';
|
|
14
|
+
text: string;
|
|
15
|
+
ok: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'error';
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
export type AssistantState = {
|
|
21
|
+
open: boolean;
|
|
22
|
+
entries: AssistantEntry[];
|
|
23
|
+
working: boolean;
|
|
24
|
+
/** The demo asked about: named with each question. */
|
|
25
|
+
about?: {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
};
|
|
29
|
+
/** Tokens this conversation: input, written to the cache, read from it, output. */
|
|
30
|
+
usage: Usage;
|
|
31
|
+
};
|
|
32
|
+
export type Usage = {
|
|
33
|
+
input: number;
|
|
34
|
+
written: number;
|
|
35
|
+
cached: number;
|
|
36
|
+
output: number;
|
|
37
|
+
};
|
|
38
|
+
/** About what a conversation cost, in US dollars, where the model's prices are known (per million tokens). */
|
|
39
|
+
export declare function costOf(usage: Usage, model: string): number | undefined;
|
|
40
|
+
export type ClaudeSettings = {
|
|
41
|
+
/** The person's own Anthropic API key, kept in this browser. */
|
|
42
|
+
key: string;
|
|
43
|
+
model: string;
|
|
44
|
+
effort: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
45
|
+
};
|
|
46
|
+
export declare const DEFAULT_CLAUDE: ClaudeSettings;
|
|
47
|
+
export declare const EMPTY_ASSISTANT: AssistantState;
|
|
48
|
+
/**
|
|
49
|
+
* Claude, in the app: asked in words, it makes, clones and changes demos with the tools an AI has on
|
|
50
|
+
* `window.demoEngine` - looks at the page, tries the path, writes, checks, saves, opens it in the
|
|
51
|
+
* studio. From the browser, with the person's own Anthropic API key: no backend.
|
|
52
|
+
*/
|
|
53
|
+
export declare class Assistant {
|
|
54
|
+
private engine;
|
|
55
|
+
private settings;
|
|
56
|
+
private changed;
|
|
57
|
+
state: AssistantState;
|
|
58
|
+
private messages;
|
|
59
|
+
private abort;
|
|
60
|
+
private tools;
|
|
61
|
+
constructor(engine: DemoEngine, settings: () => ClaudeSettings, changed: (state: AssistantState) => void);
|
|
62
|
+
private update;
|
|
63
|
+
private add;
|
|
64
|
+
open(about?: Demo): void;
|
|
65
|
+
close(): void;
|
|
66
|
+
/** What the next questions are about; undefined for nothing in particular. */
|
|
67
|
+
setAbout(about: {
|
|
68
|
+
id: string;
|
|
69
|
+
title: string;
|
|
70
|
+
} | undefined): void;
|
|
71
|
+
/** A new conversation. */
|
|
72
|
+
clear(): void;
|
|
73
|
+
stop(): void;
|
|
74
|
+
/** Asks Claude; it works until it is done, stopped, or out of turns. */
|
|
75
|
+
ask(question: string): Promise<void>;
|
|
76
|
+
/** The conversation as the API takes it: a last turn's tool calls answered, or that turn dropped. */
|
|
77
|
+
private repair;
|
|
78
|
+
private count;
|
|
79
|
+
private system;
|
|
80
|
+
/** One tool call: run, its result as data, and a line saying what it did. */
|
|
81
|
+
private use;
|
|
82
|
+
private run;
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{describeTarget as e}from"../engine/Player.js";import{agentTools as t}from"./Agent.js";import{GUIDE as s}from"./Guide.js";const o={input:0,written:0,cached:0,output:0};export function costOf(e,t){const s={"claude-opus-5-5":[4,5,.2,20]}[t];if(s)return(e.input*s[0]+e.written*s[1]+e.cached*s[2]+e.output*s[3])/1e6}export const DEFAULT_CLAUDE={key:"",model:"claude-opus-5-5",effort:"high"};export const EMPTY_ASSISTANT={open:!1,entries:[],working:!1,usage:o};const a=/^claude-(opus-5|fable-5|sonnet-5-5|mythos-5)/,i=4e4,n={type:"object",description:"A whole demo, in the format the guide gives."},r=[["languages","The languages narration is written in (write: write every one), and the one it plays in now (plays).",{}],["start","Where the app is now, as a demo's `start`: a demo made now starts there. null if the app has none.",{}],["page","What is on the page to act on: targets ready for actions, with labels, states and boxes; also headings and open dialogs. `within` a css region, `query` text in the labels, `limit` at most (250).",{within:{type:"string"},query:{type:"string"},limit:{type:"integer"}}],["find","How many elements a target names, whether the one it means shows, its label and box.",{target:{type:"object",description:"A target: { css, text?, key?, index? } - see the guide.",properties:{css:{type:"string"},text:{type:"string"},key:{type:"string"},index:{type:"integer"}},required:["css"]}},["target"]],["describe","The target for an element: the first matching `css`, or the one at viewport point `x`, `y` (px).",{css:{type:"string"},x:{type:"number"},y:{type:"number"}}],["try","Does one action now, quickly, as a demo would (click, hover, type, key, select, drag, scroll, waitFor): to walk the path a demo takes and test its targets. Says what appeared and what went. It really happens in the app.",{action:{type:"object",description:"One action, as in a demo step."}},["action"]],["demos","The demos there are: id, title, steps, languages, duration, origin ('app': the app's own; 'edited': the app's, changed here; 'here': made here).",{}],["get","A demo, whole, by id: to read, clone or change it.",{id:{type:"string"}},["id"]],["validate","What is wrong with a demo's shape, [] if nothing. `check` plays it.",{demo:n},["demo"]],["estimate","How long a demo plays, about, and each step: a `demo`, or the `id` of a saved one.",{demo:n,id:{type:"string"}}],["check","Plays a demo fast and silent from its start, going past what fails, its cleanup after: a `demo`, or the `id` of a saved one. `ok` twice in a row: it plays, and undoes itself. `from`, `to`: steps, 0-based.",{demo:n,id:{type:"string"},from:{type:"integer"},to:{type:"integer"}}],["save","Keeps a demo in this browser: it shows in the library. The id of an app's demo changes that one, here, until removed: give a copy its own id.",{demo:n},["demo"]],["open","Opens a saved demo in the studio, for the person to see, play, tune and film: do it when a demo is done.",{id:{type:"string"}},["id"]]].map(([e,t,s,o])=>({name:e,description:t,input_schema:{type:"object",properties:s,...o?{required:o}:{}},eager_input_streaming:!0}));export class Assistant{constructor(e,s,o){this.engine=e,this.settings=s,this.changed=o,this.state=EMPTY_ASSISTANT,this.messages=[],this.tools=t(e)}update(e){this.state={...this.state,...e},this.changed(this.state)}add(e){this.update({entries:[...this.state.entries,e]})}open(e){this.update({open:!0,...e?{about:{id:e.id,title:e.title}}:{}})}close(){this.update({open:!1})}setAbout(e){this.update({about:e})}clear(){this.state.working||(this.messages=[],this.update({entries:[],usage:o}))}stop(){this.abort?.abort();const e=this.engine.getState().session;"playing"===e.mode&&e.checking&&this.engine.stop()}async ask(e){const t=e.trim();if(!t||this.state.working)return;const{key:s,model:o,effort:i}=this.settings();if(!s)return void this.add({kind:"error",text:"Add your Anthropic API key first."});const n=this.state.about?`\n\n(About the demo "${this.state.about.title}", id "${this.state.about.id}".)`:"";this.add({kind:"you",text:t}),this.messages.push({role:"user",content:t+n});const d=new AbortController;let h;this.abort=d,this.update({working:!0});try{h=await(import("@anthropic-ai/sdk"));const e=new h.Anthropic({apiKey:s,dangerouslyAllowBrowser:!0});let t=0;for(let s=0;s<60&&!d.signal.aborted;s++){const s=e.beta.messages.stream({model:o,max_tokens:64e3,output_config:{effort:i},cache_control:{type:"ephemeral"},system:this.system(),tools:r,messages:this.messages,...a.test(o)?{betas:["server-side-fallback-2026-07-01"],fallbacks:"default"}:{}},{signal:d.signal});let n,l=-1;s.on("text",(e,t)=>{const s=[...this.state.entries];l<0?(l=s.length,s.push({kind:"claude",text:t})):s[l]={kind:"claude",text:t},this.update({entries:s})});try{n=await s.finalMessage(),t=0}catch(e){if(e instanceof h.APIError||d.signal.aborted||t++>=2)throw e;continue}this.count(n.usage);const c=n.content.filter(e=>"text"===e.type).map(e=>e.text.trim()).filter(Boolean);if(l<0&&c.forEach(e=>this.add({kind:"claude",text:e})),"refusal"===n.stop_reason){this.add({kind:"error",text:"Claude declined this request."});break}const p=n.content.filter(e=>"tool_use"===e.type);if("pause_turn"===n.stop_reason){this.messages.push({role:"assistant",content:n.content});continue}if(0===p.length){this.messages.push({role:"assistant",content:n.content});break}if("max_tokens"===n.stop_reason){this.add({kind:"error",text:"The answer was cut off: ask for a smaller piece."});break}this.messages.push({role:"assistant",content:n.content});const u=[];for(const e of p)d.signal.aborted?u.push({type:"tool_result",tool_use_id:e.id,is_error:!0,content:"Stopped by the person."}):u.push(await this.use(e));this.messages.push({role:"user",content:u})}d.signal.aborted&&this.add({kind:"error",text:"Stopped."})}catch(e){d.signal.aborted||h&&e instanceof h.APIUserAbortError?this.add({kind:"error",text:"Stopped."}):h&&e instanceof h.AuthenticationError?this.add({kind:"error",text:"The API key was refused: check it in Key."}):h&&e instanceof h.RateLimitError?this.add({kind:"error",text:"Too many requests for now: try again in a minute."}):h&&e instanceof h.APIError?this.add({kind:"error",text:`Claude: ${e.status??""} ${e.message}`.trim()}):this.add({kind:"error",text:`Claude could not be reached: ${e.message}`})}finally{this.repair(),this.abort=void 0,this.update({working:!1})}}repair(){const e=this.messages[this.messages.length-1];"assistant"===e?.role&&Array.isArray(e.content)&&e.content.some(e=>"tool_use"===e.type)&&this.messages.pop()}count(e){const{input:t,written:s,cached:o,output:a}=this.state.usage;this.update({usage:{input:t+e.input_tokens,written:s+(e.cache_creation_input_tokens??0),cached:o+(e.cache_read_input_tokens??0),output:a+e.output_tokens}})}system(){const e=this.engine.options.app;return`You are Claude, working inside a web app${e?` ("${e}")`:""} for the person using it, through its demo engine. They asked you, in the app's "Ask Claude" panel, to make, clone or change demos of the app. You see the app only through your tools; the person watches the app while you work.\n\nYour tools are the ones the guide below calls on window.demoEngine: page, find, describe, try, demos, get, validate, estimate, check, save, open, languages, start. Call them as tools, not as JavaScript; help() is this guide.\n\n- try really acts in the app, with the person's data and session. Walk only the path a demo takes. Do not delete, send, pay, publish, or change settings or data beyond what the demo shows, unless the person asked for exactly that; when a demo would need it, say so and ask first.\n- A copy of a demo gets an id of its own. Save over a demo's id only to change that demo.\n- Check a demo until it is ok twice in a row (the second run proves its cleanup), save it, then open it in the studio.\n- Reply in the person's language, briefly: what you made or changed, how long it plays, anything that did not work. They see each tool you use, so do not list them.\n\n<guide>\n${s}\n</guide>`}async use(e){const t=e.input??{};try{const{result:s,did:o,ok:a}=await this.run(e.name,t);this.add({kind:"did",text:o,ok:a});let n=JSON.stringify(s??null);return n.length>i&&(n=`${n.slice(0,i)}\n[Cut at 40000 characters: narrow it down (page: query, within or limit).]`),{type:"tool_result",tool_use_id:e.id,content:n,...a?{}:{is_error:!0}}}catch(t){return this.add({kind:"did",text:`${e.name}: ${t.message}`,ok:!1}),{type:"tool_result",tool_use_id:e.id,is_error:!0,content:t.message}}}async run(t,s){const o=this.tools,a=e=>"string"==typeof s[e]?s[e]:void 0,i=e=>"number"==typeof s[e]?s[e]:void 0,n=e=>s[e]&&"object"==typeof s[e]?s[e]:void 0,r=n("demo"),d=()=>{const e=r??a("id");if(!e)throw new Error("Give a demo or an id");return e},h=async e=>`“${"string"==typeof e?(await o.get(e).catch(()=>{}))?.title??e:e.title}”`;switch(t){case"languages":return{result:o.languages(),did:"Read the languages",ok:!0};case"start":return{result:o.start(),did:"Noted where the app is",ok:!0};case"page":{const e=a("query"),t=a("within");return{result:o.page({query:e,within:t,limit:i("limit")}),did:`Looked at the page${e?` for “${e}”`:""}${t?` in ${t}`:""}`,ok:!0}}case"find":{const t=n("target");if(!t)throw new Error("Give a target");const s=o.find(t);return{result:s,did:`Looked for ${e(t)}: ${s.matches?s.shown?"there":"not showing":"none"}`,ok:!0}}case"describe":{const e=a("css"),[t,s]=[i("x"),i("y")],n=e??(void 0!==t&&void 0!==s?[t,s]:void 0);if(!n)throw new Error("Give css, or x and y");const r=o.describe(n);return{result:r,did:"Named "+(r.label?`“${r.label}”`:`a ${r.tag}`),ok:!0}}case"try":{const t=n("action");if(!t||"string"!=typeof t.do)throw new Error("Give an action: { do, ... }");const s=await o.try(t),a="target"in t&&t.target?` ${e(t.target)}`:"";return{result:s,did:`Tried: ${t.do}${a}${s.ok?"":` (${s.error})`}`,ok:s.ok}}case"demos":return{result:await o.demos(),did:"Listed the demos",ok:!0};case"get":{const e=a("id");if(!e)throw new Error("Give an id");const t=await o.get(e);return{result:t,did:`Read “${t.title}”`,ok:!0}}case"validate":{if(!r)throw new Error("Give a demo");const e=o.validate(r);return{result:e,did:e.length?`Its shape: ${e.length} problem${1===e.length?"":"s"}`:"Its shape: fine",ok:0===e.length}}case"estimate":{const e=d(),t=await o.estimate(e);return{result:t,did:`Timed ${await h(e)}: ${t.duration}`,ok:!0}}case"check":{const e=d(),t=await o.check(e,{from:i("from"),to:i("to")}),s=t.failures.length+t.problems.length;return{result:t,did:`Played ${await h(e)} through: ${t.ok?"ok":t.error??`${s} failed`}`,ok:t.ok}}case"save":{if(!r)throw new Error("Give a demo");const e=await o.save(r);return{result:e,did:e.ok?`Saved “${r.title}”`:`Not saved: ${e.problems?.length} problems`,ok:e.ok}}case"open":{const e=a("id");if(!e)throw new Error("Give an id");const t=await o.open(e),s=(await o.get(e)).title;return this.update({about:{id:e,title:s}}),{result:t,did:`Opened “${s}” in the studio`,ok:!0}}default:throw new Error(`No tool "${t}"`)}}}
|
package/agent/Guide.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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
|
|
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: `await`\neach call (most return a Promise); every result 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). The page's CSS transitions\n and animations are off while it runs, so it works in a background tab too. After a failure, what\n follows is waited for 2 s only (it mostly failed with it): fix the first failure first.\n6. `await demoEngine.save(demo)`, then `demoEngine.open(demo.id)` where the person watches your\n browser - they see it in the studio, can play, tune, film and share it (else see below). `demoEngine.play(id)` plays it with sound once the\n person clicks. `demoEngine.estimate(demo)` gives its length.\n\n## Your browser and the person's\n\nWhat `save` keeps stays in the browser you work in. Not the person's own (a browser of yours,\nanother profile)? Give them `await demoEngine.link(id)`: opened in their browser, the demo is kept\nthere and opens in their studio. Where you can write files, `await demoEngine.get(id)` is its\n`.demo.json` as well (the library's New \u2192 Import takes it). A demo of theirs comes to you the same\nway: open its link, or `save(link)`, and it is kept in yours. Signing in to the app is theirs: ask.\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\": \"[data-demo=\\\"orders\\\"]\" }, \"text\": { \"en\": \"Orders\", \"de\": \"Auftr\u00E4ge\" }, \"for\": 2500 },\n { \"do\": \"type\", \"target\": { \"css\": \"input[type=\\\"search\\\"]\" }, \"text\": \"Berlin\", \"cue\": 1 },\n { \"do\": \"click\", \"target\": { \"css\": \"td\", \"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' }`. A label is the element's whole text, or its\n`data-demo` name, or its `aria-label` - never a part: a table row's is all its cells, which change\nwith the data and the language (\"open\", \"offen\"). Target what stays: a cell, a `key`, a named region.\n\nEvery action has `wait` (ms before it, default 800) and `cue` (start with the step's sentence of that\nindex, 0-based: sentences end with . ? or !; syncs a click with the words about it, in every\nlanguage 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). Their text on the\nscreen - a card's title and text, a note, a label - is one for every language, or one per language\nas `say` is: `{ \"en\": \"Orders\", \"de\": \"Auftr\u00E4ge\" }`.\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; for its step only: blur again first\n thing in each step it shows in (`wait: 0`)\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`notes` (on the presenter's screen only: what to add live, figures to mention, questions to expect).\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. A cleanup target\nnot there within half a second is skipped, so list every reset that might be needed.\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?, animations? }) \u00B7 save(demo | link) \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
CHANGED
|
@@ -1 +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
|
|
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: `await`\neach call (most return a Promise); every result 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). The page\'s CSS transitions\n and animations are off while it runs, so it works in a background tab too. After a failure, what\n follows is waited for 2 s only (it mostly failed with it): fix the first failure first.\n6. `await demoEngine.save(demo)`, then `demoEngine.open(demo.id)` where the person watches your\n browser - they see it in the studio, can play, tune, film and share it (else see below). `demoEngine.play(id)` plays it with sound once the\n person clicks. `demoEngine.estimate(demo)` gives its length.\n\n## Your browser and the person\'s\n\nWhat `save` keeps stays in the browser you work in. Not the person\'s own (a browser of yours,\nanother profile)? Give them `await demoEngine.link(id)`: opened in their browser, the demo is kept\nthere and opens in their studio. Where you can write files, `await demoEngine.get(id)` is its\n`.demo.json` as well (the library\'s New → Import takes it). A demo of theirs comes to you the same\nway: open its link, or `save(link)`, and it is kept in yours. Signing in to the app is theirs: ask.\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": "[data-demo=\\"orders\\"]" }, "text": { "en": "Orders", "de": "Aufträge" }, "for": 2500 },\n { "do": "type", "target": { "css": "input[type=\\"search\\"]" }, "text": "Berlin", "cue": 1 },\n { "do": "click", "target": { "css": "td", "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\' }`. A label is the element\'s whole text, or its\n`data-demo` name, or its `aria-label` - never a part: a table row\'s is all its cells, which change\nwith the data and the language ("open", "offen"). Target what stays: a cell, a `key`, a named region.\n\nEvery action has `wait` (ms before it, default 800) and `cue` (start with the step\'s sentence of that\nindex, 0-based: sentences end with . ? or !; syncs a click with the words about it, in every\nlanguage 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). Their text on the\nscreen - a card\'s title and text, a note, a label - is one for every language, or one per language\nas `say` is: `{ "en": "Orders", "de": "Aufträge" }`.\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; for its step only: blur again first\n thing in each step it shows in (`wait: 0`)\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`notes` (on the presenter\'s screen only: what to add live, figures to mention, questions to expect).\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. A cleanup target\nnot there within half a second is skipped, so list every reset that might be needed.\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?, animations? }) · save(demo | link) · remove(id) ·\nopen(demoOrId) · play(demoOrId, { from? }) · guide(demoOrId, { from? }) · loop([demoOrId]) ·\nstopLoop() · stop() · state() · link(demoOrId)\n';
|
package/engine/DemoEngine.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { NarrationPack } from '../speech/Pack';
|
|
|
11
11
|
import { PlayOptions, Player, PlayResult, PlayState } from './Player';
|
|
12
12
|
import type { DemoPlugin } from './Plugin';
|
|
13
13
|
import { RecordState } from './Recorder';
|
|
14
|
+
import { Assistant, AssistantState } from '../agent/Assistant';
|
|
14
15
|
import { DEFAULT_SETTINGS, DemoSettings } from './Settings';
|
|
15
16
|
export type DemoStart = {
|
|
16
17
|
/** Where the app is now, as a demo recorded here starts. */
|
|
@@ -46,8 +47,18 @@ export type DemoEngineOptions = {
|
|
|
46
47
|
overlay?: OverlayOptions;
|
|
47
48
|
/** The engine's UI: 'auto' follows the system. */
|
|
48
49
|
theme?: 'light' | 'dark' | 'auto';
|
|
49
|
-
/**
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Tools for an AI on `window[agent]`: 'demoEngine' by default; false for none. A function
|
|
52
|
+
* decides as the engine mounts, where the app knows more (its environment, who is signed in).
|
|
53
|
+
* With them, anyone with the app's URL and a Claude that runs JavaScript in a browser makes,
|
|
54
|
+
* clones and changes demos; the library copies them a prompt to start with.
|
|
55
|
+
*/
|
|
56
|
+
agent?: string | false | (() => string | false);
|
|
57
|
+
/**
|
|
58
|
+
* Experimental, off: an "Ask Claude" panel in the library, where people make and change demos
|
|
59
|
+
* in words with their own Anthropic API key. True to show it.
|
|
60
|
+
*/
|
|
61
|
+
assistant?: boolean;
|
|
51
62
|
/** A "Demos" button on the page opening the library: for apps without a panel of their own. */
|
|
52
63
|
launcher?: boolean;
|
|
53
64
|
/**
|
|
@@ -166,6 +177,8 @@ export type EngineState = {
|
|
|
166
177
|
dialog?: DialogRequest;
|
|
167
178
|
/** The library: its demos or its settings; the launcher's floating one shows while set. */
|
|
168
179
|
library?: 'demos' | 'settings';
|
|
180
|
+
/** "Ask Claude": its panel, conversation and tokens. */
|
|
181
|
+
assistant: AssistantState;
|
|
169
182
|
};
|
|
170
183
|
export type LoopOptions = {
|
|
171
184
|
/** ms of no input before the loop plays again, after a visitor. Default the setting, 30 s. */
|
|
@@ -204,6 +217,8 @@ export declare class DemoEngine {
|
|
|
204
217
|
readonly speech: Speech;
|
|
205
218
|
readonly store: Store;
|
|
206
219
|
readonly plugins: DemoPlugin[];
|
|
220
|
+
/** "Ask Claude": demos made and changed in words. */
|
|
221
|
+
readonly assistant: Assistant;
|
|
207
222
|
private state;
|
|
208
223
|
private listeners;
|
|
209
224
|
private settingsKey;
|
|
@@ -241,6 +256,16 @@ export declare class DemoEngine {
|
|
|
241
256
|
destroy(): void;
|
|
242
257
|
/** A demo a link brought, one asked for by `?demo=`, or one to play once back from its start's reload. */
|
|
243
258
|
private arrived;
|
|
259
|
+
/** The demo in the address's `#demo=`, kept here and opened in the studio. False without one. */
|
|
260
|
+
private takeLink;
|
|
261
|
+
/** Where an AI finds the engine's tools, `window[name]`; undefined where the app keeps them off. */
|
|
262
|
+
agentName(): string | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* What to tell one's own Claude - in a browser where it runs JavaScript - to make a demo of the
|
|
265
|
+
* app, or change `demo`: the app's address, where the tools are, how to hand the demo back.
|
|
266
|
+
* Undefined where the app keeps the tools off.
|
|
267
|
+
*/
|
|
268
|
+
claudePrompt(demo?: Demo): Promise<string | undefined>;
|
|
244
269
|
/**
|
|
245
270
|
* While a demo plays, the viewer's own input does not reach the app: a click or a key of theirs
|
|
246
271
|
* would take the demo off its path. Not the engine's controls, not a presenter's keys; not while
|
|
@@ -310,6 +335,8 @@ export declare class DemoEngine {
|
|
|
310
335
|
openSettings(): void;
|
|
311
336
|
/** The library's view; undefined closes the launcher's floating one. */
|
|
312
337
|
showLibrary(view: 'demos' | 'settings' | undefined): void;
|
|
338
|
+
/** "Ask Claude"'s panel; `about` a demo, named with each question. Not where the app turned it off. */
|
|
339
|
+
openAssistant(about?: Demo): void;
|
|
313
340
|
/** To a step of what plays (0-based): forward or back. False where it cannot (filmed). */
|
|
314
341
|
goTo(step: number): boolean;
|
|
315
342
|
/**
|