@gui-chat-plugin/sequence 0.3.1 → 0.4.1
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/CHANGELOG.md +25 -0
- package/README.md +12 -5
- package/dist/core/index.d.ts +1 -1
- package/dist/core/slideHtml.d.ts +17 -5
- package/dist/core-Bl4BX0HI.cjs +145 -0
- package/dist/{core-BJ7q9fgr.js → core-Dsp7rj6a.js} +128 -130
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/style.css +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +45 -45
- package/package.json +1 -1
- package/dist/core-CPlicVIg.cjs +0 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
- **Slides are explained, not announced.** Asked only to "explain" the slide on the screen, OpenAI's
|
|
6
|
+
voice models often said a line about the slide ("Let's start with the big picture, then we'll
|
|
7
|
+
move on", "This first slide is about quantum theory") and went on to the next. After each slide,
|
|
8
|
+
the model is now told to teach its subject in at least two sentences, beginning with the content
|
|
9
|
+
itself, never with the slide or its plan; a guide step says what to do, directly. In MulmoGlass
|
|
10
|
+
(mock images), OpenAI began 9 of 10 slide explanations with their content, against 3 of 7
|
|
11
|
+
before; Gemini and Grok already did, and still do.
|
|
12
|
+
|
|
13
|
+
## 0.4.0
|
|
14
|
+
|
|
15
|
+
- **HTML slides animate with MulmoCast's `data-animation` attributes**, not CSS: `animate`
|
|
16
|
+
(opacity, translate, scale, rotate, width, height), `counter` and `typewriter`, with `data-start`
|
|
17
|
+
and `data-end` in seconds. A movie made from the slides (MulmoChat's makeMovie: an `html_tailwind`
|
|
18
|
+
beat with `animation: true`) now moves as the View does; MulmoCast pauses CSS animations, so the
|
|
19
|
+
0.3 slides' `animate-fade-up` and the like didn't move there. The page plays them with its own
|
|
20
|
+
player, written for this package (MIT; MulmoCast is AGPL) and checked against MulmoCast's
|
|
21
|
+
renderer: 56 of 56 sampled values equal. CSS animations and transitions don't play; each is
|
|
22
|
+
shown at its end, so an element faded in with the model's own `@keyframes` is seen rather than
|
|
23
|
+
held transparent. `SLIDE_CSS_ANIMATIONS_FINISHED` is those rules, for a host to add to the HTML
|
|
24
|
+
it gives MulmoCast, which would hold such an element at its first frame.
|
|
25
|
+
- Breaking: `SLIDE_ANIMATIONS` (the `animate-*` classes) is gone; `SLIDE_ANIMATION_KINDS`,
|
|
26
|
+
`SLIDE_AUTO_END_SECONDS` and `SLIDE_CSS_ANIMATIONS_FINISHED` are new.
|
|
27
|
+
|
|
3
28
|
## 0.3.1
|
|
4
29
|
|
|
5
30
|
- **"HTML slides" go to presentSlide**: the prompt says that when the user asks for HTML slides,
|
package/README.md
CHANGED
|
@@ -65,13 +65,20 @@ it is drawn.
|
|
|
65
65
|
A slide is a generated picture (`imagePrompt`) or HTML (`html`), the model's choice per slide: a
|
|
66
66
|
picture for a scene or an object, HTML for words, numbers, lists, comparisons and diagrams, which
|
|
67
67
|
picture models draw badly. The model writes the inside of `<body>` for a 1280x720 canvas, with
|
|
68
|
-
Tailwind CSS
|
|
69
|
-
`
|
|
70
|
-
`
|
|
71
|
-
`
|
|
68
|
+
Tailwind CSS classes, and animates it with [MulmoCast](https://github.com/receptron/mulmocast-cli)'s
|
|
69
|
+
declarative `data-animation` attributes: `animate` (`data-opacity`, `data-translate-x/y`,
|
|
70
|
+
`data-scale`, `data-rotate`, `data-width`/`data-height`), `counter` and `typewriter`, each with
|
|
71
|
+
`data-start` and `data-end` in seconds and an optional `data-easing`. A movie made from the slide
|
|
72
|
+
(an `html_tailwind` beat with `animation: true`) moves the same way. The page plays them with its
|
|
73
|
+
own player (MIT; MulmoCast is AGPL), measured against MulmoCast's: the same values at the same
|
|
74
|
+
times. An animation without `data-end` runs to the end of the beat in a movie, and for
|
|
75
|
+
`SLIDE_AUTO_END_SECONDS` (8) here. CSS animations and transitions don't play: each is shown at its
|
|
76
|
+
end. MulmoCast would hold them at their first frame (an element faded in with `@keyframes` stays
|
|
77
|
+
transparent), so a host making a movie adds `SLIDE_CSS_ANIMATIONS_FINISHED` (a `<style>`'s rules)
|
|
78
|
+
to the HTML it passes on. The slide's own scripts don't run.
|
|
72
79
|
|
|
73
80
|
`slideHtmlDocument(html)` (core entry) makes the page: Tailwind's browser build from jsDelivr (one
|
|
74
|
-
version, checked by its hash), the
|
|
81
|
+
version, checked by its hash), the animation player, and a Content Security Policy that lets it send
|
|
75
82
|
nothing out: `connect-src 'none'`; images, media and fonts only from `data:`/`blob:` URLs and
|
|
76
83
|
Google Fonts; and no script but the page's own and Tailwind's, so nothing can navigate the frame to
|
|
77
84
|
a URL carrying the page (a sandbox allows that, and CSP can't forbid it). The slide's `<meta>`,
|
package/dist/core/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare const presentSlidePluginCore: SequencePluginCore;
|
|
|
4
4
|
export declare const defineStoryboardPluginCore: SequencePluginCore;
|
|
5
5
|
export declare const presentPanelPluginCore: SequencePluginCore;
|
|
6
6
|
export * from "./definitions";
|
|
7
|
-
export { MAX_SLIDE_HTML,
|
|
7
|
+
export { MAX_SLIDE_HTML, SLIDE_ANIMATION_KINDS, SLIDE_AUTO_END_SECONDS, SLIDE_CSS_ANIMATIONS_FINISHED, SLIDE_HEIGHT, SLIDE_WIDTH, slideHtmlDocument, } from "./slideHtml";
|
|
8
8
|
export { SLIDESHOWS_DIR, STORYBOARDS_DIR, loadRecord } from "./records";
|
|
9
9
|
export type { SequenceContext } from "./host";
|
package/dist/core/slideHtml.d.ts
CHANGED
|
@@ -2,12 +2,17 @@ export declare const SLIDE_WIDTH = 1280;
|
|
|
2
2
|
export declare const SLIDE_HEIGHT = 720;
|
|
3
3
|
/** The most HTML a slide may have, in characters. */
|
|
4
4
|
export declare const MAX_SLIDE_HTML = 60000;
|
|
5
|
-
/** The
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
5
|
+
/** The data-animation kinds a slide can use: MulmoCast's (its html_tailwind
|
|
6
|
+
* beats with `animation: true`), so a slide animates the same in a movie
|
|
7
|
+
* made from it. MulmoCast also has stagger, codeReveal, blink, coverZoom and
|
|
8
|
+
* coverPan; not these. */
|
|
9
|
+
export declare const SLIDE_ANIMATION_KINDS: readonly ["animate", "counter", "typewriter"];
|
|
10
|
+
/** How long an animation without data-end runs here, in seconds. In a movie
|
|
11
|
+
* it runs to the end of its beat, which the narration decides and the View
|
|
12
|
+
* doesn't know. */
|
|
13
|
+
export declare const SLIDE_AUTO_END_SECONDS = 8;
|
|
9
14
|
/** PAGE_SCRIPT's hash, which the policy allows (checked by a test). */
|
|
10
|
-
export declare const PAGE_SCRIPT_HASH = "sha256-
|
|
15
|
+
export declare const PAGE_SCRIPT_HASH = "sha256-0zsqCvkCfq5Z1iJCn46NiAtSAyIr/JDkyNs/Fae1J+Y=";
|
|
11
16
|
/** The slide's HTML, made safe to show:
|
|
12
17
|
* - the tags that act on the page from outside the body are plain text:
|
|
13
18
|
* <meta> (a refresh navigates the frame, a policy of its own), <base> and
|
|
@@ -19,5 +24,12 @@ export declare const PAGE_SCRIPT_HASH = "sha256-MZyL5rvWmIVxl3WUuDU5BqzPJGR2/fV/
|
|
|
19
24
|
* "shadowroot" is renamed, which leaves no attribute that makes one.
|
|
20
25
|
* Everything stays in the light DOM, where the guard sees it. */
|
|
21
26
|
export declare const neutralizeSlideHtml: (html: string) => string;
|
|
27
|
+
/** CSS rules that stop a slide's CSS animations and transitions, which the
|
|
28
|
+
* slide isn't to use (it animates with data-animation), showing each at its
|
|
29
|
+
* end: an element the model faded in with its own @keyframes is seen, not
|
|
30
|
+
* held at its first, transparent frame. MulmoCast pauses CSS animations at
|
|
31
|
+
* that frame, so a host that makes a movie of the slide adds these to the
|
|
32
|
+
* HTML it passes on (a zero-length animation is at its end even paused). */
|
|
33
|
+
export declare const SLIDE_CSS_ANIMATIONS_FINISHED = "*, *::before, *::after { animation-play-state: paused !important; animation-duration: 0s !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; animation-fill-mode: both !important; transition: none !important; }";
|
|
22
34
|
/** The page an HTML slide is shown as. */
|
|
23
35
|
export declare function slideHtmlDocument(html: string): string;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
let e=require("gui-chat-protocol");var t=1280,n=720,r=6e4,i=`https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.3.3/dist/index.global.js`,a=`sha384-2ql948lIdLcGEE0/qxNiudyTjgauA3RDJERu5xW75kFCvSl5a9odyQYCb6tEjnmB`,o=[`animate`,`counter`,`typewriter`],s=8,c=`
|
|
2
|
+
(() => {
|
|
3
|
+
const EASE = {
|
|
4
|
+
linear: (t) => t,
|
|
5
|
+
easeIn: (t) => t * t,
|
|
6
|
+
easeOut: (t) => 1 - (1 - t) * (1 - t),
|
|
7
|
+
easeInOut: (t) => (t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2),
|
|
8
|
+
};
|
|
9
|
+
const AUTO_END = 8;
|
|
10
|
+
const TRANSFORMS = [
|
|
11
|
+
["data-translate-x", "translateX", "px"],
|
|
12
|
+
["data-translate-y", "translateY", "px"],
|
|
13
|
+
["data-scale", "scale", ""],
|
|
14
|
+
["data-rotate", "rotate", "deg"],
|
|
15
|
+
["data-rotate-x", "rotateX", "deg"],
|
|
16
|
+
["data-rotate-y", "rotateY", "deg"],
|
|
17
|
+
["data-rotate-z", "rotateZ", "deg"],
|
|
18
|
+
];
|
|
19
|
+
const STYLES = [
|
|
20
|
+
["data-opacity", "opacity", ""],
|
|
21
|
+
["data-width", "width", "px"],
|
|
22
|
+
["data-height", "height", "px"],
|
|
23
|
+
];
|
|
24
|
+
const number = (value, fallback) => {
|
|
25
|
+
const n = Number(value);
|
|
26
|
+
return value !== null && value.trim() !== "" && Number.isFinite(n) ? n : fallback;
|
|
27
|
+
};
|
|
28
|
+
const range = (value, unit) => {
|
|
29
|
+
if (value === null) return null;
|
|
30
|
+
const parts = value.split(",").map((part) => part.trim());
|
|
31
|
+
const from = Number(parts[0]);
|
|
32
|
+
const to = Number(parts[1]);
|
|
33
|
+
if (!Number.isFinite(from) || !Number.isFinite(to)) return null;
|
|
34
|
+
return { from, to, unit: parts[2] || unit };
|
|
35
|
+
};
|
|
36
|
+
const ranges = (el, table) =>
|
|
37
|
+
table
|
|
38
|
+
.map(([attr, name, unit]) => [name, range(el.getAttribute(attr), unit)])
|
|
39
|
+
.filter(([, r]) => r);
|
|
40
|
+
let entries = [];
|
|
41
|
+
const collect = () => {
|
|
42
|
+
entries = [...document.querySelectorAll("[data-animation]")].map((el) => {
|
|
43
|
+
const kind = el.getAttribute("data-animation");
|
|
44
|
+
const end = el.getAttribute("data-end");
|
|
45
|
+
const entry = {
|
|
46
|
+
el,
|
|
47
|
+
kind,
|
|
48
|
+
start: number(el.getAttribute("data-start"), 0),
|
|
49
|
+
end: end === null || end.trim() === "auto" ? null : number(end, null),
|
|
50
|
+
ease: EASE[el.getAttribute("data-easing")] || EASE.linear,
|
|
51
|
+
};
|
|
52
|
+
if (kind === "animate") {
|
|
53
|
+
entry.transforms = ranges(el, TRANSFORMS);
|
|
54
|
+
entry.styles = ranges(el, STYLES);
|
|
55
|
+
} else if (kind === "counter") {
|
|
56
|
+
entry.from = number(el.getAttribute("data-from"), 0);
|
|
57
|
+
entry.to = number(el.getAttribute("data-to"), 0);
|
|
58
|
+
entry.decimals = Math.max(0, Math.round(number(el.getAttribute("data-decimals"), 0)));
|
|
59
|
+
entry.prefix = el.getAttribute("data-prefix") || "";
|
|
60
|
+
entry.suffix = el.getAttribute("data-suffix") || "";
|
|
61
|
+
} else if (kind === "typewriter") {
|
|
62
|
+
entry.text = el.getAttribute("data-text") ?? el.textContent;
|
|
63
|
+
} else {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return entry;
|
|
67
|
+
}).filter(Boolean);
|
|
68
|
+
};
|
|
69
|
+
const seek = (t) => {
|
|
70
|
+
for (const e of entries) {
|
|
71
|
+
const end = e.end ?? AUTO_END;
|
|
72
|
+
const span = end - e.start;
|
|
73
|
+
const p = span > 0 ? Math.min(1, Math.max(0, (t - e.start) / span)) : t >= e.start ? 1 : 0;
|
|
74
|
+
const k = e.ease(p);
|
|
75
|
+
const at = (r) => r.from + (r.to - r.from) * k;
|
|
76
|
+
if (e.kind === "animate") {
|
|
77
|
+
if (e.transforms.length) {
|
|
78
|
+
e.el.style.transform = e.transforms.map(([name, r]) => name + "(" + at(r) + r.unit + ")").join(" ");
|
|
79
|
+
}
|
|
80
|
+
for (const [name, r] of e.styles) e.el.style[name] = at(r) + r.unit;
|
|
81
|
+
} else if (e.kind === "counter") {
|
|
82
|
+
e.el.textContent = e.prefix + (e.from + (e.to - e.from) * k).toFixed(e.decimals) + e.suffix;
|
|
83
|
+
} else {
|
|
84
|
+
e.el.textContent = e.text.slice(0, Math.floor(e.text.length * k));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
window.__slideSeek = seek;
|
|
89
|
+
const play = () => {
|
|
90
|
+
const last = Math.max(0, ...entries.map((e) => e.end ?? AUTO_END));
|
|
91
|
+
const begun = performance.now();
|
|
92
|
+
const tick = (now) => {
|
|
93
|
+
const t = (now - begun) / 1000;
|
|
94
|
+
seek(t);
|
|
95
|
+
if (t <= last) requestAnimationFrame(tick);
|
|
96
|
+
};
|
|
97
|
+
requestAnimationFrame(tick);
|
|
98
|
+
};
|
|
99
|
+
// Collected once the body is parsed: at DOMContentLoaded, or earlier when
|
|
100
|
+
// the fallback shows the slide while a slow Tailwind still holds
|
|
101
|
+
// DOMContentLoaded back (the body is parsed by then: readyState is
|
|
102
|
+
// "interactive" before deferred scripts run). Played once both are done.
|
|
103
|
+
let collected = false;
|
|
104
|
+
let shown = false;
|
|
105
|
+
const init = () => {
|
|
106
|
+
if (collected || document.readyState === "loading") return;
|
|
107
|
+
collected = true;
|
|
108
|
+
collect();
|
|
109
|
+
seek(0);
|
|
110
|
+
if (shown) play();
|
|
111
|
+
};
|
|
112
|
+
const show = () => {
|
|
113
|
+
if (shown) return;
|
|
114
|
+
init();
|
|
115
|
+
shown = true;
|
|
116
|
+
document.documentElement.classList.add("ready");
|
|
117
|
+
if (collected) play();
|
|
118
|
+
};
|
|
119
|
+
const ready = () => requestAnimationFrame(() => requestAnimationFrame(show));
|
|
120
|
+
const check = () =>
|
|
121
|
+
document.querySelector("style:not([type]):not(#slide-base)") ? ready() : setTimeout(check, 30);
|
|
122
|
+
addEventListener("DOMContentLoaded", () => {
|
|
123
|
+
init();
|
|
124
|
+
check();
|
|
125
|
+
});
|
|
126
|
+
setTimeout(show, 1000);
|
|
127
|
+
addEventListener("click", (event) => {
|
|
128
|
+
if (event.target instanceof Element && event.target.closest("a, area")) event.preventDefault();
|
|
129
|
+
}, true);
|
|
130
|
+
})();`,l=[`default-src 'none'`,`script-src 'sha256-0zsqCvkCfq5Z1iJCn46NiAtSAyIr/JDkyNs/Fae1J+Y=' ${i}`,`style-src 'unsafe-inline' https://fonts.googleapis.com`,`font-src https://fonts.gstatic.com data:`,`img-src data: blob:`,`media-src data: blob:`,`connect-src 'none'`,`form-action 'none'`,`base-uri 'none'`].join(`; `),u=e=>e.replace(/<(?=(meta|base|link)\b)/gi,`<`).replace(/shadowroot/gi,`data-no-shadow-root`),d=`*, *::before, *::after { animation-play-state: paused !important; animation-duration: 0s !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; animation-fill-mode: both !important; transition: none !important; }`,f=`
|
|
131
|
+
html, body { margin: 0; width: ${t}px; height: 720px; overflow: hidden; }
|
|
132
|
+
html:not(.ready) body { visibility: hidden; }
|
|
133
|
+
${d}`;function p(e){return`<!doctype html>
|
|
134
|
+
<html lang="en">
|
|
135
|
+
<head>
|
|
136
|
+
<meta charset="utf-8">
|
|
137
|
+
<meta http-equiv="Content-Security-Policy" content="${l}">
|
|
138
|
+
<style id="slide-base">${f}</style>
|
|
139
|
+
<script>${c}<\/script>
|
|
140
|
+
<script defer src="${i}" integrity="${a}" crossorigin="anonymous"><\/script>
|
|
141
|
+
</head>
|
|
142
|
+
<body class="bg-white text-slate-900 font-sans antialiased">
|
|
143
|
+
${u(e)}
|
|
144
|
+
</body>
|
|
145
|
+
</html>`}var m=`presentSlide`,h=`defineStoryboard`,g=`presentPanel`,ee=4,te=12,ne=3,_=/^[0-9a-f]{12}$/,v=e=>typeof e==`object`&&!!e&&!Array.isArray(e),y=e=>typeof e==`string`?e.trim():``,b=(e,t)=>e.toLowerCase()===t.toLowerCase(),x=e=>typeof e==`number`&&Number.isInteger(e),S=`presentSlide needs slide and totalSlides (whole numbers, slide from 1 to totalSlides), and either an imagePrompt or html`,re=`presentSlide's html is too long: keep a slide under ${r} characters`;function C(e){let{slide:t,totalSlides:n,title:r,imagePrompt:i}=e,a=y(e.html);return!x(t)||!x(n)||t<1||n<t||!a&&!y(i)?S:a.length>6e4?re:{slide:t,totalSlides:n,title:typeof r==`string`?r:``,imagePrompt:a?``:String(i),...a&&{html:a},mode:e.mode===`steps`?`steps`:`presentation`}}var w=`teach its subject in at least two sentences, as a presenter speaking to the audience. Begin with the content itself, never with the slide or your plan: no "This slide is about…", "The first slide shows…", "Let's unpack this one", "Next, I'll…". A line about the slide is not an explanation.`,T=({slide:e,totalSlides:t,title:n,mode:r})=>{let i=n?` ("${n}")`:``;if(r===`steps`){let n=`Step ${e} of ${t}${i}`;return e<t?`${n} is now on the screen. Say what to do in this step, directly ("Crack two eggs into a bowl…", not "This step is about eggs"), then stop and wait while the user does it. When they say they're ready (next, done, go on), call presentSlide for step ${e+1} with mode "steps". If they ask to go back or to see a step again, call presentSlide for that step.`:`${n}, the last one, is now on the screen. Say what to do, directly, then wrap up the guide once the user is done.`}let a=`Slide ${e} of ${t}${i}`;return e<t?`${a} is now on the screen. Explain it: ${w} Then, in this same reply and without waiting for the user, call presentSlide for slide ${e+1}. If the user has asked you to stop, or asked something else, since the slideshow began, answer them instead of going on.`:`${a}, the last one, is now on the screen. Explain it: ${w} Then wrap up the slideshow.`},ie=[`For an HTML slide, instead of imagePrompt: the slide's content, the inside of <body> only (no <html>, <head> or <body> tags), for a ${t}x720 px canvas, which it should fill (start with a <div class="w-full h-full ...">). Style it with Tailwind CSS v4 classes, which are loaded for you: a clear layout, a large title (text-6xl or so), few words in large type, a color scheme, and inline SVG or emoji for icons and diagrams. There is no network: no <img> from URLs, no links to follow.`,`Animate it so it builds up as you explain it, with MulmoCast's data-animation attributes (the same ones make it move in a movie of the slideshow): data-animation="animate" with data-opacity="0,1", data-translate-x, data-translate-y (px), data-scale, data-rotate (deg), data-width or data-height ("0,80,%"), each "from,to"; data-animation="counter" with data-from, data-to, data-decimals, data-prefix, data-suffix; data-animation="typewriter" (its text, or data-text). Give every one data-start and data-end in seconds, and optionally data-easing (linear, easeIn, easeOut, easeInOut); stagger the parts with later data-start values so they appear one after another over a few seconds (for example 0, 0.6, 1.2). Set the first frame inline too (style="opacity:0" on an element that fades in).`,`CSS animations, transitions and scripts don't play: animate only with data-animation. A <style> for layout is allowed (and Google Fonts by @import).`].join(` `),E=`When the user asks for a slideshow (or to explain something with slides), plan four to six slides, then show them one at a time with presentSlide: slide 1 first, and each next slide only after you have explained the one on the screen. Explain the subject, not the slides: say what the slide teaches, not that a slide is about it. Go on to the last slide without asking whether to continue. A slide is a generated picture (imagePrompt) or a designed slide in HTML (html): use a picture for a scene, an object or a place, and HTML for words, numbers, lists, comparisons, timelines and diagrams, which a picture model draws badly; a slideshow can mix them. When the user asks for HTML slides (slides in HTML, an HTML presentation), this is the tool: make them HTML slides with presentSlide, one call per slide, not one HTML page. When the user wants to be shown how to do something they will do along with you (cooking, folding, fixing, an exercise), make it a step-by-step guide instead: mode "steps", one slide per step, and after each step wait for the user to say they are ready. Use generateImage for a single picture, not for slides.`,D={type:`function`,name:m,prompt:E,description:`Show one slide of a slideshow, full screen: a picture generated from imagePrompt, or a slide written in HTML (html). Call it once per slide, in order, starting with slide 1. With mode "steps" it is a step-by-step guide: one slide per step, and the next step waits for the user.`,parameters:{type:`object`,properties:{slide:{type:`integer`,description:`This slide's number, starting at 1.`},totalSlides:{type:`integer`,description:`How many slides the slideshow has. Keep it the same for every slide.`},title:{type:`string`,description:`The slide's title.`},imagePrompt:{type:`string`,description:`For a picture slide: the picture, a clear illustration of its point, with the title as its only large text. Be concrete. For a step, show the action: hands, tools and the object. Leave it out for an HTML slide.`},html:{type:`string`,description:ie},mode:{type:`string`,enum:[`presentation`,`steps`],description:`"presentation" (the default) goes on by itself; "steps" is a how-to the user does along with you, and waits for them after each step. Keep it the same for every slide.`}},required:[`slide`,`totalSlides`,`title`]}};function O(e){let{totalPanels:t}=e;if(!x(t)||t<1||t>12)return`totalPanels must be a whole number from 1 to 12`;let n=[];for(let t of Array.isArray(e.characters)?e.characters:[]){let e=v(t)?y(t.name):``,r=v(t)?y(t.description):``;if(!e||!r)return`every character needs a name and a description`;if(n.some(t=>b(t.name,e)))return`two characters are named ${e}`;n.push({name:e,description:r})}return n.length<1||n.length>4?`a storyboard has 1 to 4 characters`:{title:y(e.title),style:y(e.style),totalPanels:t,characters:n,interactive:e.interactive===!0}}var k=({title:e,id:t})=>`The cast of "${e}" is now on the screen. Introduce the characters briefly, then, in this same reply and without waiting for the user, call presentPanel for panel 1 with storyboardId "${t}". If the user has asked you to stop, or asked something else, answer them instead of going on.`,A=`presentPanel needs a storyboardId, a panel number (from 1) and an imagePrompt`;function j(e){let{panel:t}=e,n=y(e.storyboardId),r=y(e.imagePrompt);if(!n||!r||!x(t)||t<1)return null;let i=e=>(Array.isArray(e)?e:[]).map(y).filter(Boolean);return{storyboardId:n,panel:t,characters:i(e.characters),imagePrompt:r,caption:y(e.caption),choices:i(e.choices).slice(0,3)}}function M(e,t,n){let{id:r,totalPanels:i}=e;return n.length?`Panel ${t} of ${i} is now on the screen, with the user's choices: ${n.map((e,t)=>`${t+1}. ${e}`).join(` `)} Tell this part of the story, then read the choices out and ask the user which one they pick, and wait for their answer. Then call presentPanel for panel ${t+1} with storyboardId "${r}", going on the way they chose.`:t<i?`Panel ${t} of ${i} is now on the screen. Tell this part of the story, then, in this same reply and without waiting for the user, call presentPanel for panel ${t+1} with storyboardId "${r}". If the user has asked you to stop, or asked something else, since the story began, answer them instead of going on.`:`Panel ${t} of ${i}, the last one, is now on the screen. Tell this part of the story, then bring it to an end.`}var N=`When the user asks for a story, a picture book, a comic or a storyboard, tell it in pictures: first call defineStoryboard with the art style and the characters who appear more than once (it draws a reference sheet for each, so they look the same in every panel), then show the panels one at a time with presentPanel, naming the characters in each, and tell each part of the story when its panel appears. Go on to the last panel without asking whether to continue, unless the story is interactive. When the user wants to decide what happens (an adventure, a story for a child who wants to choose), set interactive, and give two or three choices on two or three of the panels: the story waits there for the user's pick and goes on their way; it still ends at the last panel whichever way it goes. Use presentSlide to explain a topic, not to tell a story.`,P={type:`function`,name:h,prompt:N,description:`Start a story told in pictures: set its art style and draw a reference sheet for each recurring character, shown as the cast. Then call presentPanel for each panel, in order.`,parameters:{type:`object`,properties:{title:{type:`string`,description:`The story's title.`},style:{type:`string`,description:`The art style of every picture, in one sentence (for example: soft watercolor, children's picture book).`},totalPanels:{type:`integer`,description:`How many panels the story has, at most 12; four to eight is usual.`},interactive:{type:`boolean`,description:`The user chooses what happens: panels can offer choices, and the story waits for the pick.`},characters:{type:`array`,description:`The characters who appear in more than one panel, 1 to 4.`,items:{type:`object`,properties:{name:{type:`string`,description:`A short name, used in presentPanel.`},description:{type:`string`,description:`How they look: age, build, face, hair, clothes and colors. Be concrete: it is drawn once and reused in every panel.`}},required:[`name`,`description`]}}},required:[`title`,`style`,`totalPanels`,`characters`]}},F={type:`function`,name:g,description:`Show one panel of a storyboard made with defineStoryboard: a picture of the scene with its characters drawn as in their reference sheets, and a caption. Call it once per panel, in order, starting with panel 1.`,parameters:{type:`object`,properties:{storyboardId:{type:`string`,description:`The storyboardId defineStoryboard returned.`},panel:{type:`integer`,description:`This panel's number, starting at 1.`},characters:{type:`array`,items:{type:`string`},description:`The names (as in defineStoryboard) of the characters in this panel.`},imagePrompt:{type:`string`,description:`What the panel shows: the setting, what happens, expressions and the camera angle. Refer to characters by name; don't describe their looks again.`},caption:{type:`string`,description:`One short line shown under the picture.`},choices:{type:`array`,items:{type:`string`},description:`Only in an interactive story, and not on the last panel: two or three short options for what happens next. The story waits for the user's pick.`}},required:[`storyboardId`,`panel`,`characters`,`imagePrompt`]}},I=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ae=e=>I(e)&&typeof e.message==`string`;function L(e){let t=I(e?.data)?e.data:{};return{...typeof t.imageData==`string`&&{imageData:t.imageData},...typeof t.imagePath==`string`&&{imagePath:t.imagePath}}}function R(e){let t=I(e?.data)?e.data:{};return typeof t.html==`string`?t.html:``}var oe=e=>!!L(e).imageData||!!R(e);function se(e,t){let n=L(e),r=L(t);if(n.imagePath&&r.imagePath)return n.imagePath===r.imagePath;if(n.imageData)return n.imageData===r.imageData;let i=R(e);return!!i&&i===R(t)}var ce=(e,t)=>e.userSpokeAt===void 0||e.userSpokeAt>t,z=()=>crypto.randomUUID().replace(/-/g,``).slice(0,12),le=`artifacts/`;async function B(e,t){let n=e.files?.artifacts;if(!e.app?.editImages||!n)return[];let r=[];for(let e of t)if(e.startsWith(le))try{await n.exists(e.slice(10))&&r.push(e)}catch{}return r}async function V(e,t,n=[]){let r=e.app,i=r?.editImages,a=r?.generateImage;try{let e;if(n.length&&i)e=await i(t,[...n]);else if(a)e=await a(t);else return{message:`image generation isn't available`};return ae(e)?e:{message:`image generation returned an unrecognized result`}}catch(e){return{message:`image generation failed: ${e instanceof Error?e.message:String(e)}`}}}var ue=50;function H(e){let t=new Map;return n=>{let r=n.conversationId??``,i=t.get(r);if(i===void 0?i=e():t.delete(r),t.set(r,i),t.size>ue){let e=t.keys().next().value;e!==void 0&&t.delete(e)}return i}}var U=`slideshows`,W=`storyboards`,G={},K=new WeakMap,q=new WeakMap;function J(e){let t=K.get(e);return t||K.set(e,t=new Map),t}function de(t,n){let r=q.get(t);r||q.set(t,r=new Map);let i=r.get(n);return i||r.set(n,i=(0,e.createSerialLock)()),i}var Y=(e,t)=>`${e}/${t}.json`;async function X(e,t){let n=J(e??G),r=n.get(t);if(r)return r;if(!e)return null;try{let r=JSON.parse(await e.read(t));return n.set(t,r),r}catch{return null}}async function Z(e,t,n){return _.test(n)?X(e,Y(t,n)):null}async function Q(e,t,n,r){let i=Y(t,n),a=e??G;return de(a,i)(async()=>{let t=r(await X(e,i));if(J(a).set(i,t),!e)return!1;try{return await e.write(i,JSON.stringify(t,null,2)),!0}catch(e){return console.warn(`[sequence] could not save`,i,e),!1}})}var $=e=>`the ${e} could not be saved, so it lasts only until the app or server restarts`,fe=6e4;function pe(){let e=new Map;return{claim:t=>{let n=Date.now();for(let[t,r]of e)n-r.at>fe&&e.delete(t);let r=e.get(t);if(r)return{earlier:r.shown};let i=()=>void 0,a=new Promise(e=>i=e);return e.set(t,{at:n,shown:a}),{settle:n=>{!n&&e.get(t)?.shown===a&&e.delete(t),i(n)}}}}}function me({slide:e,totalSlides:t,mode:n}){return n===`steps`?{step:e,total:t,kind:`guide`,label:`Step ${e} of ${t}`,onShown:`explain it`,nextCall:`call presentSlide for step ${e+1} of ${t} with mode "steps"`,waitsForUser:!0}:{step:e,total:t,kind:`slideshow`,label:`Slide ${e} of ${t}`,onShown:`explain it`,nextCall:`call presentSlide for slide ${e+1} of ${t}`}}var he=(e,{slide:t,totalSlides:n,title:r,imagePrompt:i,html:a})=>JSON.stringify([e,t,n,r,i,a]),ge=H(()=>({latest:{presentation:null,steps:null},lastShown:null,repeats:pe()}));function _e(e,t){let n=e.latest[t.mode],r=n?.totalSlides===t.totalSlides&&(t.slide!==1||n.firstTitle===t.title);if(n&&r)return n;let i={id:z(),mode:t.mode,totalSlides:t.totalSlides,firstTitle:t.slide===1?t.title:``,slides:new Map,current:0,shownAt:-1/0};return e.latest[t.mode]=i,i}function ve(e,t,n,r){t.current=n.slide,t.shownAt=Date.now(),e.lastShown=t;let i=n.mode===`steps`?`step`:`slide`,{uuid:a,...o}=r;return{...o,message:`${i} ${n.slide} of ${n.totalSlides} is on the screen again, as it was`,instructions:T(n),instructionsRequired:!0,sequence:me(n)}}function ye(e,t){if(e.mode!==`steps`)return e.title?`A presentation slide titled "${e.title}". ${e.imagePrompt}`:e.imagePrompt;let n=e.title?`, "${e.title}"`:``;return[`An instructional illustration of step ${e.slide} of ${e.totalSlides}${n}. ${e.imagePrompt}`,t?`The reference image is the previous step: keep the same objects, hands, tools and setting, and show what this step changes.`:``,`Show the action clearly, with little or no text.`].filter(Boolean).join(` `)}async function be(e,t,n){if(n.html)return{html:n.html,prompt:``};let r=t.slides.get(n.slide-1),i=n.mode===`steps`?L(r).imagePath:void 0,a=i?await B(e,[i]):[],o=ye(n,a.length>0),s=await V(e,o,a),{imageData:c,imagePath:l}=L(s);return c?{imageData:c,...l&&{imagePath:l},prompt:o}:{failed:{...s,sequence:null}}}async function xe(e,t,n){let r=await be(e,t,n);if(`failed`in r)return r.failed;let{imageData:i,imagePath:a,html:o,prompt:s}=r,c=t.id,l=await Q(e.files?.artifacts,U,c,e=>{let t=e??{id:c,title:``,mode:n.mode,totalSlides:n.totalSlides,slides:{}};return n.slide===1&&(t.title=n.title),t.slides[String(n.slide)]={title:n.title,imagePrompt:n.imagePrompt,...a&&{imagePath:a},...o&&{html:o}},t}),u={...i&&{imageData:i},...a&&{imagePath:a},...o&&{html:o},prompt:s,slideshowId:c,slide:n.slide,totalSlides:n.totalSlides,title:n.title,mode:n.mode},d=n.mode===`steps`?`step`:`slide`;return{data:u,title:n.title||`Slide ${n.slide}`,message:[`${d} ${n.slide} of ${n.totalSlides} of slideshow "${c}" is on the screen`,a?`saved to ${a}`:``,l?``:$(`slideshow`)].filter(Boolean).join(`; `),instructions:T(n),instructionsRequired:!0,sequence:me(n)}}async function Se(e,t){let n=C(t);if(typeof n==`string`)return{message:n,sequence:null};let r=ge(e),i=_e(r,n),a=n.mode===`steps`;if(a&&n.slide>i.current&&i.current>0&&!ce(e,i.shownAt)){console.info(`[sequence] holding step ${n.slide} for the user`);let e=i.shownAt===1/0?`is still being drawn`:`is still on the screen`;return{message:`step ${n.slide} was not shown: the user hasn't said they're ready yet, and step ${i.current} ${e}. Wait for them before calling presentSlide for step ${n.slide}.`,cancelled:!0}}let o=a?i.slides.get(n.slide):void 0;if(o)return se(e.currentResult,o)?{message:`step ${n.slide} of ${n.totalSlides} is already on the screen`,cancelled:!0}:ve(r,i,n,o);let s=r.repeats.claim(he(i.id,n));if(`earlier`in s){if(!await s.earlier)return Se(e,t);let a=i.slides.get(n.slide);return a&&r.lastShown!==i?ve(r,i,n,a):{message:`slide ${n.slide} of ${n.totalSlides} is already on the screen`,cancelled:!0}}let{settle:c}=s,l={current:i.current,shownAt:i.shownAt};i.current=n.slide,i.shownAt=1/0;let u=!1;try{let t=await xe(e,i,n);return u=oe(t),u&&(i.slides.set(n.slide,t),i.current=n.slide,i.shownAt=Date.now(),r.lastShown=i),t}finally{c(u),!u&&i.current===n.slide&&(i.current=l.current,i.shownAt=l.shownAt)}}var Ce=({id:e,title:t,totalPanels:n})=>({step:0,total:n,kind:`story`,label:`The cast of "${t}"`,onShown:`introduce the characters`,nextCall:`call presentPanel for panel 1 of ${n} with storyboardId "${e}"`}),we=({id:e,totalPanels:t},n,r)=>({step:n,total:t,kind:`story`,label:`Panel ${n} of ${t}`,onShown:`tell that part of the story`,nextCall:`call presentPanel for panel ${n+1} of ${t} with storyboardId "${e}"`,...r.length>0&&{waitsForUser:!0}}),Te=(e,t)=>e?`${e}. ${t}`:t,Ee=(e,{name:t,description:n})=>Te(e,`Character reference sheet of ${t}: ${n}. Full body, front, side and back views, on a plain white background. No text or labels.`);async function De(e,t){let n=O(t);if(typeof n==`string`)return{message:n,sequence:null};let r=await Promise.all(n.characters.map(t=>V(e,Ee(n.style,t)))),i=r.map(L),a=r.find((e,t)=>!i[t]?.imageData);if(i.every(({imageData:e})=>!e)&&a)return{...a,message:`the character sheets couldn't be made: ${a.message}`,sequence:null};let o={id:z(),...n,characters:n.characters.map((e,t)=>{let n=i[t]?.imagePath;return{...e,...n&&{imagePath:n}}}),panels:{}},s=await Q(e.files?.artifacts,W,o.id,()=>o),c=o.characters.filter(e=>e.imagePath).map(e=>`${e.name}: ${e.imagePath}`),l=n.characters.map(({name:e},t)=>i[t]?.imageData?null:`${e} (${r[t]?.message??``})`).filter(e=>!!e),u=i.find(e=>e.imageData)?.imageData;return{data:{storyboardId:o.id,title:o.title,totalPanels:o.totalPanels,...u&&{imageData:u},characters:o.characters.map(({name:e,imagePath:t},n)=>{let r=i[n]?.imageData;return{name:e,...r&&{imageData:r},...t&&{imagePath:t}}})},title:o.title,message:[`storyboard "${o.id}" is ready with ${o.totalPanels} panels; the cast is on the screen`,c.length?`character sheets saved to ${c.join(`, `)}`:``,l.length?`no sheet for ${l.join(`; `)}: they will be drawn from their description`:``,s?``:$(`storyboard`)].filter(Boolean).join(`; `),instructions:k(o),instructionsRequired:!0,sequence:Ce(o)}}function Oe(e,t,n){let r=[Te(e.style,`Panel ${t.panel} of ${e.totalPanels} of the illustrated story "${e.title}". ${t.imagePrompt}`)],i=0,a=n.map(({character:e,hasSheet:t})=>t?`${e.name} is the character in reference image ${++i}`:`${e.name}: ${e.description}`);return a.length&&r.push(`${a.join(`. `)}.`),i&&r.push(`Draw each character exactly as in their reference image: the same face, hair, clothes and colors. Use the reference images only for how the characters look, not for their pose or the background.`),r.push(`No captions, speech bubbles or other text in the picture.`),r.join(` `)}async function ke(e,t,n){let r=[],i=[];for(let a of n.characters){let n=t.characters.find(e=>b(e.name,a));if(!n)r.push(a);else if(!i.some(e=>e.character===n)){let[t]=n.imagePath?await B(e,[n.imagePath]):[];i.push({character:n,sheet:t??null})}}let a=i.map(({sheet:e})=>e).filter(e=>!!e),o=Oe(t,n,i.map(({character:e,sheet:t})=>({character:e,hasSheet:!!t}))),s=await V(e,o,a),{imageData:c,imagePath:l}=L(s);if(!c)return{...s,sequence:null};let u=n.panel<t.totalPanels&&n.choices.length>=2?n.choices:[],d=await Q(e.files?.artifacts,W,t.id,e=>{let r=e??t;return u.length&&(r.interactive=!0),r.panels[String(n.panel)]={caption:n.caption,characters:i.map(({character:e})=>e.name),imagePrompt:n.imagePrompt,...l&&{imagePath:l},...u.length&&{choices:u}},r});return{data:{imageData:c,...l&&{imagePath:l},prompt:o,storyboardId:t.id,panel:n.panel,totalPanels:t.totalPanels,caption:n.caption,...u.length&&{choices:u}},title:n.caption||`Panel ${n.panel}`,message:[`panel ${n.panel} of ${t.totalPanels} is on the screen`,l?`saved to ${l}`:``,r.length?`not in the cast, so drawn from the prompt alone: ${r.join(`, `)}`:``,d?``:$(`storyboard`)].filter(Boolean).join(`; `),instructions:M(t,n.panel,u),instructionsRequired:!0,sequence:we(t,n.panel,u)}}var Ae=H(()=>({repeats:pe(),awaitingChoice:new Map}));async function je(e,t){let n=j(t);if(!n)return{message:A,sequence:null};let{storyboardId:r,panel:i}=n,{repeats:a,awaitingChoice:o}=Ae(e),s=o.get(r);if(s&&i>s.panel&&!ce(e,s.shownAt))return console.info(`[sequence] holding panel ${i} for the user`),{message:s.shownAt===1/0?`panel ${i} was not shown: panel ${s.panel} is still being drawn. Wait for it before going on.`:`panel ${i} was not shown: the user hasn't picked a choice yet, and panel ${s.panel} is still on the screen. Wait for their answer.`,cancelled:!0};let c=a.claim(JSON.stringify(n));if(`earlier`in c)return await c.earlier?{message:`panel ${i} is already on the screen`,cancelled:!0}:je(e,t);let{settle:l}=c,u={panel:i,shownAt:1/0},d=o.get(r);o.set(r,u);let f=()=>o.get(r)===u,p=!1;try{let t=await Z(e.files?.artifacts,W,r);if(!t)return{message:`there is no storyboard "${r}"; call defineStoryboard first`,sequence:null};if(i>t.totalPanels)return{message:`storyboard "${t.id}" has ${t.totalPanels} panels`,sequence:null};let a=await ke(e,t,n);p=!!L(a).imageData;let s=a.data;return p&&f()&&(s?.choices?.length?o.set(r,{panel:i,shownAt:Date.now()}):o.delete(r)),a}finally{l(p),!p&&f()&&(d?o.set(r,d):o.delete(r))}}var Me={toolDefinition:D,generatingMessage:`Making the slide...`,isEnabled:()=>!0,execute:(e,t)=>Se(e,t)},Ne={toolDefinition:P,generatingMessage:`Drawing the characters...`,isEnabled:()=>!0,execute:(e,t)=>De(e,t)},Pe={toolDefinition:F,generatingMessage:`Drawing the panel...`,isEnabled:()=>!0,execute:(e,t)=>je(e,t)};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return S}});
|