@gui-chat-plugin/sequence 0.6.0 → 0.6.2

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.
@@ -157,11 +157,24 @@ var t = 1280, n = 720, r = 6e4, i = "https://cdn.jsdelivr.net/npm/@tailwindcss/b
157
157
  }, p = (e) => e.replace(/[&<>"]/g, (e) => f[e] ?? e), m = (e) => e.replace(/<(?=(meta|base|link)\b)/gi, "&lt;").replace(/shadowroot/gi, "data-no-shadow-root"), h = "*, *::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; }", ee = `
158
158
  html, body { margin: 0; width: ${t}px; height: 720px; overflow: hidden; }
159
159
  html:not(.ready) body { visibility: hidden; }
160
- ${h}`, g = "{{image}}", _ = /(\bsrc\s*=\s*["']?|\burl\(\s*["']?)(?:\{\{image\}\}|%7B%7Bimage%7D%7D)/gi, te = /^data:image\/[a-z0-9.+-]+;base64,[a-z0-9+/=]+$/i, ne = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", v = /(<pre\b[\s\S]*?<\/pre>|<code\b[\s\S]*?<\/code>)/gi, y = (e) => e.split(v).some((e, t) => t % 2 == 0 && new RegExp(_.source, "i").test(e)), re = (e, t) => {
160
+ ${h}`, g = "{{image}}", _ = /(\bsrc\s*=\s*["']?|\burl\(\s*["']?)(?:\{\{image\}\}|%7B%7Bimage%7D%7D)/gi, te = /^data:image\/[a-z0-9.+-]+;base64,[a-z0-9+/=]+$/i, ne = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", v = /(<pre\b[\s\S]*?<\/pre>|<code\b[\s\S]*?<\/code>)/gi, y = (e) => e.split(v).some((e, t) => t % 2 == 0 && new RegExp(_.source, "i").test(e)), re = {
161
+ "&amp;": "&",
162
+ "&lt;": "<",
163
+ "&gt;": ">",
164
+ "&quot;": "\"",
165
+ "&#39;": "'"
166
+ }, ie = (e) => {
167
+ for (let t of e.split(v).filter((e, t) => t % 2 == 0)) for (let e of t.match(/<img\b[^>]*>/gi) ?? []) {
168
+ if (!new RegExp(_.source, "i").test(e)) continue;
169
+ let t = /\balt\s*=\s*(?:"([^"]*)"|'([^']*)')/i.exec(e);
170
+ return (t?.[1] ?? t?.[2] ?? "").replace(/&(?:amp|lt|gt|quot|#39);/g, (e) => re[e] ?? e).trim();
171
+ }
172
+ return "";
173
+ }, ae = (e, t) => {
161
174
  let n = t && te.test(t) ? t : ne;
162
175
  return e.split(v).map((e, t) => t % 2 == 1 ? e : e.replace(_, (e, t) => t + n)).join("");
163
176
  };
164
- function ie(e) {
177
+ function oe(e) {
165
178
  return `<!doctype html>
166
179
  <html lang="en">
167
180
  <head>
@@ -187,32 +200,32 @@ var b = [
187
200
  "polarArea",
188
201
  "scatter",
189
202
  "bubble"
190
- ], ae = "https://cdn.jsdelivr.net/npm/chart.js@4.5.1/dist/chart.umd.min.js", oe = "sha384-jb8JQMbMoBUzgWatfe6COACi2ljcDdZQ2OxczGA3bGNeWe+6DChMTBJemed7ZnvJ", se = "\n(() => {\n const fail = (why) => {\n document.getElementById(\"chart-error\").textContent = why;\n document.documentElement.classList.add(\"failed\");\n };\n addEventListener(\"DOMContentLoaded\", () => {\n if (!window.Chart) return fail(\"The chart couldn't be drawn: Chart.js didn't load.\");\n let config;\n try {\n config = JSON.parse(document.getElementById(\"chart-config\").textContent);\n } catch {\n return fail(\"The chart couldn't be drawn: its configuration isn't valid.\");\n }\n Chart.defaults.font.size = 22;\n Chart.defaults.color = \"#334155\";\n Chart.defaults.animation.duration = 1200;\n config.options = { ...config.options, responsive: true, maintainAspectRatio: false };\n try {\n new Chart(document.getElementById(\"chart\"), config);\n } catch (error) {\n fail(\"The chart couldn't be drawn: \" + (error && error.message ? error.message : error));\n }\n });\n})();", ce = [
203
+ ], x = "https://cdn.jsdelivr.net/npm/chart.js@4.5.1/dist/chart.umd.min.js", se = "sha384-jb8JQMbMoBUzgWatfe6COACi2ljcDdZQ2OxczGA3bGNeWe+6DChMTBJemed7ZnvJ", ce = "\n(() => {\n const fail = (why) => {\n document.getElementById(\"chart-error\").textContent = why;\n document.documentElement.classList.add(\"failed\");\n };\n addEventListener(\"DOMContentLoaded\", () => {\n if (!window.Chart) return fail(\"The chart couldn't be drawn: Chart.js didn't load.\");\n let config;\n try {\n config = JSON.parse(document.getElementById(\"chart-config\").textContent);\n } catch {\n return fail(\"The chart couldn't be drawn: its configuration isn't valid.\");\n }\n Chart.defaults.font.size = 22;\n Chart.defaults.color = \"#334155\";\n Chart.defaults.animation.duration = 1200;\n config.options = { ...config.options, responsive: true, maintainAspectRatio: false };\n try {\n new Chart(document.getElementById(\"chart\"), config);\n } catch (error) {\n fail(\"The chart couldn't be drawn: \" + (error && error.message ? error.message : error));\n }\n });\n})();", le = [
191
204
  "default-src 'none'",
192
- `script-src 'sha256-TfZZxJX+yWgzYLy7zqsMa85OJEaC+zNLIpKLDZVnUqA=' ${ae}`,
205
+ `script-src 'sha256-TfZZxJX+yWgzYLy7zqsMa85OJEaC+zNLIpKLDZVnUqA=' ${x}`,
193
206
  "style-src 'unsafe-inline'",
194
207
  "img-src data: blob:",
195
208
  "connect-src 'none'",
196
209
  "form-action 'none'",
197
210
  "base-uri 'none'"
198
- ].join("; "), le = `
211
+ ].join("; "), ue = `
199
212
  html, body { margin: 0; width: ${t}px; height: 720px; overflow: hidden; background: #ffffff; color: #0f172a; font-family: ui-sans-serif, system-ui, sans-serif; }
200
213
  body { box-sizing: border-box; padding: 40px 64px 48px; display: flex; flex-direction: column; gap: 24px; }
201
214
  h1 { margin: 0; font-size: 52px; font-weight: 800; color: #1e3a8a; line-height: 1.15; text-align: center; }
202
215
  .chart { position: relative; flex: 1; min-height: 0; }
203
216
  #chart-error { display: none; margin: auto; font-size: 28px; color: #b91c1c; }
204
217
  .failed .chart { display: none; }
205
- .failed #chart-error { display: block; }`, ue = (e) => JSON.stringify(e).replace(/</g, "\\u003c");
206
- function de(e, t) {
218
+ .failed #chart-error { display: block; }`, de = (e) => JSON.stringify(e).replace(/</g, "\\u003c");
219
+ function fe(e, t) {
207
220
  return `<!doctype html>
208
221
  <html lang="en">
209
222
  <head>
210
223
  <meta charset="utf-8">
211
- <meta http-equiv="Content-Security-Policy" content="${ce}">
212
- <style>${le}</style>
213
- <script>${se}<\/script>
214
- <script defer src="${ae}" integrity="${oe}" crossorigin="anonymous"><\/script>
215
- <script type="application/json" id="chart-config">${ue(t)}<\/script>
224
+ <meta http-equiv="Content-Security-Policy" content="${le}">
225
+ <style>${ue}</style>
226
+ <script>${ce}<\/script>
227
+ <script defer src="${x}" integrity="${se}" crossorigin="anonymous"><\/script>
228
+ <script type="application/json" id="chart-config">${de(t)}<\/script>
216
229
  </head>
217
230
  <body>
218
231
  ${e ? `<h1>${p(e)}</h1>` : ""}
@@ -223,52 +236,52 @@ ${e ? `<h1>${p(e)}</h1>` : ""}
223
236
  }
224
237
  //#endregion
225
238
  //#region src/core/definitions.ts
226
- var fe = "presentSlide", pe = "defineStoryboard", me = "presentPanel", he = 4, ge = 12, _e = 3, x = /^[0-9a-f]{12}$/, S = (e) => typeof e == "object" && !!e && !Array.isArray(e), C = (e) => typeof e == "string" ? e.trim() : "", w = (e, t) => e.toLowerCase() === t.toLowerCase(), T = (e) => typeof e == "number" && Number.isInteger(e), E = "presentSlide needs slide and totalSlides (whole numbers, slide from 1 to totalSlides), and one of imagePrompt, html, markdown or chart", D = `presentSlide's slide is too long: keep its html, markdown or chart under ${r} characters`, O = `presentSlide's slide has ${g} but no imagePrompt: give imagePrompt for the picture that goes there, or take ${g} out`, k = `presentSlide's chart must be a Chart.js configuration: an object with type (${b.join(", ")}), data ({ labels, datasets }) and optionally options`;
227
- function ve(e) {
239
+ var S = "presentSlide", pe = "defineStoryboard", C = "presentPanel", me = 4, he = 12, ge = 3, w = /^[0-9a-f]{12}$/, T = (e) => typeof e == "object" && !!e && !Array.isArray(e), E = (e) => typeof e == "string" ? e.trim() : "", D = (e, t) => e.toLowerCase() === t.toLowerCase(), O = (e) => typeof e == "number" && Number.isInteger(e), _e = "presentSlide needs slide and totalSlides (whole numbers, slide from 1 to totalSlides), and one of imagePrompt, html, markdown or chart", ve = `presentSlide's slide is too long: keep its html, markdown or chart under ${r} characters`, ye = `presentSlide's chart must be a Chart.js configuration: an object with type (${b.join(", ")}), data ({ labels, datasets }) and optionally options`;
240
+ function be(e) {
228
241
  let t = e;
229
242
  if (typeof t == "string") try {
230
243
  t = JSON.parse(t);
231
244
  } catch {
232
245
  return null;
233
246
  }
234
- if (!S(t) || !S(t.data)) return null;
247
+ if (!T(t) || !T(t.data)) return null;
235
248
  let n = t.type;
236
- return !b.some((e) => e === n) || t.options !== void 0 && !S(t.options) ? null : t;
249
+ return !b.some((e) => e === n) || t.options !== void 0 && !T(t.options) ? null : t;
237
250
  }
238
- function A(e) {
239
- let { slide: t, totalSlides: n, title: r, imagePrompt: i } = e, a = C(e.html), o = a ? "" : C(e.markdown), s = !a && !o && e.chart !== void 0 && e.chart !== null;
240
- if (!T(t) || !T(n) || t < 1 || n < t || !a && !o && !s && !C(i)) return E;
241
- let c = s ? ve(e.chart) : null;
242
- if (s && !c) return k;
243
- if (Math.max(a.length, o.length, c ? JSON.stringify(c).length : 0) > 6e4) return D;
251
+ function xe(e) {
252
+ let { slide: t, totalSlides: n, title: r, imagePrompt: i } = e, a = E(e.html), o = a ? "" : E(e.markdown), s = !a && !o && e.chart !== void 0 && e.chart !== null;
253
+ if (!O(t) || !O(n) || t < 1 || n < t || !a && !o && !s && !E(i)) return _e;
254
+ let c = s ? be(e.chart) : null;
255
+ if (s && !c) return ye;
256
+ if (Math.max(a.length, o.length, c ? JSON.stringify(c).length : 0) > 6e4) return ve;
244
257
  let l = !a && !o && !c, u = !!a && y(a);
245
- return u && !C(i) ? O : {
258
+ return {
246
259
  slide: t,
247
260
  totalSlides: n,
248
261
  title: typeof r == "string" ? r : "",
249
- imagePrompt: l || u || o && C(i) ? String(i) : "",
262
+ imagePrompt: l ? String(i) : u || o ? E(i) : "",
250
263
  ...a && { html: a },
251
264
  ...o && { markdown: o },
252
265
  ...c && { chart: c },
253
266
  mode: e.mode === "steps" ? "steps" : "presentation"
254
267
  };
255
268
  }
256
- var j = "teach its subject as a presenter speaking to the audience, and cover everything on it: every section, point and number, in order, each in a sentence or more. The slide is replaced by the next one as soon as you stop talking, so a point you leave out is never explained. 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.", M = ({ slide: e, totalSlides: t, title: n, mode: r }) => {
269
+ var Se = "teach its subject as a presenter speaking to the audience, and cover everything on it: every section, point and number, in order, each in a sentence or more. The slide is replaced by the next one as soon as you stop talking, so a point you leave out is never explained. 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.", k = ({ slide: e, totalSlides: t, title: n, mode: r }) => {
257
270
  let i = n ? ` ("${n}")` : "";
258
271
  if (r === "steps") {
259
272
  let n = `Step ${e} of ${t}${i}`;
260
273
  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.`;
261
274
  }
262
275
  let a = `Slide ${e} of ${t}${i}`;
263
- return e < t ? `${a} is now on the screen. Explain it: ${j} This reply is only the explanation: don't call presentSlide in it. When you have finished, you will be asked 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: ${j} Then wrap up the slideshow.`;
264
- }, ye = [
276
+ return e < t ? `${a} is now on the screen. Explain it: ${Se} This reply is only the explanation: don't call presentSlide in it. When you have finished, you will be asked 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: ${Se} Then wrap up the slideshow.`;
277
+ }, Ce = [
265
278
  `For an HTML slide: 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. For one generated picture on the slide (a photo, a scene, an object beside the text), give imagePrompt too and put <img src="${g}" alt="..." class="..."> where it goes, sized by its classes (for example class="w-1/2 h-full object-cover rounded-2xl").`,
266
279
  "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).",
267
280
  "CSS animations, transitions and scripts don't play: animate only with data-animation. A <style> for layout is allowed (and Google Fonts by @import)."
268
- ].join(" "), be = `For a Markdown slide: the slide in Markdown (GitHub's: headings, lists, bold, tables, code), with math in TeX between $...$ inline or $$...$$ for a displayed equation (on lines of its own). Start with a # heading, and keep it to what fits on one slide: a heading and a few lines, a list or an equation or two. Write a dollar sign that isn't math as \\$. For one generated picture on the slide, give imagePrompt too and put ![what it shows](${g}) where it goes.`, xe = `For a chart slide, instead of imagePrompt (for numbers: real figures you have, never a picture of a chart): a Chart.js configuration as JSON text, {"type": ..., "data": ...}: { type, data: { labels, datasets: [{ label, data, backgroundColor }] }, options }. type is one of ${b.join(", ")}. It is drawn under the slide's title, so leave out options.plugins.title; give the datasets colors, and the axes titles (options.scales.x.title) when their units aren't obvious. JSON values only: no functions.`, N = "When the user asks for a slideshow (or to explain something with slides), plan four to six slides (more when the subject or your instructions need them), 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, and explain everything on a slide before showing the next; put on a slide only what you will explain. Go on to the last slide without asking whether to continue. A slide is a generated picture (imagePrompt), a chart (chart), a text slide in Markdown (markdown) or a designed slide in HTML (html): use a picture for a scene, an object or a place; a chart for numbers to compare, a trend or proportions; Markdown for equations and formulas (TeX math), definitions, short lists and small tables; and HTML for designed layouts, comparisons, timelines and diagrams. A picture model draws words, numbers and math badly, so they go on the other kinds; a slideshow can mix them. When a picture helps the text (the thing being explained, beside its key points), make an HTML or Markdown slide with one generated picture on it: imagePrompt for the picture, and {{image}} where it goes. Numbers go on a chart slide: when you have figures (from a search, a document or the user: revenue, market share, growth, prices, counts over time), show them in a chart with those exact values, labelled with their units and the year or period, and say where they come from. Figures over time, shares of a whole or values side by side are a chart, not a list or table on a Markdown or HTML slide. Never make a chart, graph or table a picture (imagePrompt): a picture of a chart has made-up bars and no real numbers. A slideshow about a business, a market or a comparison of companies has its figures on chart slides, not only in text. Never invent figures; with none to show, leave the chart out. A slide holds only its subject, never notes about your work (what you searched for, that a search succeeded). 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.", P = {
281
+ ].join(" "), we = `For a Markdown slide: the slide in Markdown (GitHub's: headings, lists, bold, tables, code), with math in TeX between $...$ inline or $$...$$ for a displayed equation (on lines of its own). Start with a # heading, and keep it to what fits on one slide: a heading and a few lines, a list or an equation or two. Write a dollar sign that isn't math as \\$. For one generated picture on the slide, give imagePrompt too and put ![what it shows](${g}) on a line of its own: the slide is then two columns, the text on the left and the picture on the right. Without imagePrompt, the alt text is what is drawn.`, Te = `For a chart slide, instead of imagePrompt (for numbers: real figures you have, never a picture of a chart): a Chart.js configuration as JSON text, {"type": ..., "data": ...}: { type, data: { labels, datasets: [{ label, data, backgroundColor }] }, options }. type is one of ${b.join(", ")}. It is drawn under the slide's title, so leave out options.plugins.title; give the datasets colors, and the axes titles (options.scales.x.title) when their units aren't obvious. JSON values only: no functions.`, Ee = "When the user asks for a slideshow (or to explain something with slides), plan four to six slides (more when the subject or your instructions need them), 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, and explain everything on a slide before showing the next; put on a slide only what you will explain. Go on to the last slide without asking whether to continue. A slide is a generated picture (imagePrompt), a chart (chart), a text slide in Markdown (markdown) or a designed slide in HTML (html): use a picture for a scene, an object or a place; a chart for numbers to compare, a trend or proportions; Markdown for equations and formulas (TeX math), definitions, short lists and small tables; and HTML for designed layouts, comparisons, timelines and diagrams. A picture model draws words, numbers and math badly, so they go on the other kinds; a slideshow can mix them. When a picture helps the text (the thing being explained, beside its key points), make an HTML or Markdown slide with one generated picture on it: imagePrompt for the picture, and {{image}} where it goes. Numbers go on a chart slide: when you have figures (from a search, a document or the user: revenue, market share, growth, prices, counts over time), show them in a chart with those exact values, labelled with their units and the year or period, and say where they come from. Figures over time, shares of a whole or values side by side are a chart, not a list or table on a Markdown or HTML slide. Never make a chart, graph or table a picture (imagePrompt): a picture of a chart has made-up bars and no real numbers. A slideshow about a business, a market or a comparison of companies has its figures on chart slides, not only in text. Never invent figures; with none to show, leave the chart out. A slide holds only its subject, never notes about your work (what you searched for, that a search succeeded). 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.", A = {
269
282
  type: "function",
270
- name: fe,
271
- prompt: N,
283
+ name: S,
284
+ prompt: Ee,
272
285
  description: "Show one slide of a slideshow, full screen: a picture generated from imagePrompt, a chart (chart), a slide written in Markdown with TeX math (markdown), or a slide written in HTML (html). Give one of the four; an HTML or Markdown slide can also hold one generated picture (imagePrompt, placed at {{image}}). 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.",
273
286
  parameters: {
274
287
  type: "object",
@@ -291,15 +304,15 @@ var j = "teach its subject as a presenter speaking to the audience, and cover ev
291
304
  },
292
305
  html: {
293
306
  type: "string",
294
- description: ye
307
+ description: Ce
295
308
  },
296
309
  markdown: {
297
310
  type: "string",
298
- description: be
311
+ description: we
299
312
  },
300
313
  chart: {
301
314
  type: "string",
302
- description: xe
315
+ description: Te
303
316
  },
304
317
  mode: {
305
318
  type: "string",
@@ -314,49 +327,49 @@ var j = "teach its subject as a presenter speaking to the audience, and cover ev
314
327
  ]
315
328
  }
316
329
  };
317
- function F(e) {
330
+ function j(e) {
318
331
  let { totalPanels: t } = e;
319
- if (!T(t) || t < 1 || t > 12) return "totalPanels must be a whole number from 1 to 12";
332
+ if (!O(t) || t < 1 || t > 12) return "totalPanels must be a whole number from 1 to 12";
320
333
  let n = [];
321
334
  for (let t of Array.isArray(e.characters) ? e.characters : []) {
322
- let e = S(t) ? C(t.name) : "", r = S(t) ? C(t.description) : "";
335
+ let e = T(t) ? E(t.name) : "", r = T(t) ? E(t.description) : "";
323
336
  if (!e || !r) return "every character needs a name and a description";
324
- if (n.some((t) => w(t.name, e))) return `two characters are named ${e}`;
337
+ if (n.some((t) => D(t.name, e))) return `two characters are named ${e}`;
325
338
  n.push({
326
339
  name: e,
327
340
  description: r
328
341
  });
329
342
  }
330
343
  return n.length < 1 || n.length > 4 ? "a storyboard has 1 to 4 characters" : {
331
- title: C(e.title),
332
- style: C(e.style),
344
+ title: E(e.title),
345
+ style: E(e.style),
333
346
  totalPanels: t,
334
347
  characters: n,
335
348
  interactive: e.interactive === !0
336
349
  };
337
350
  }
338
- var I = ({ title: e }) => `The cast of "${e}" is now on the screen. Introduce the characters briefly. This reply is only the introduction: don't call presentPanel in it. When you have finished, you will be asked for panel 1. If the user has asked you to stop, or asked something else, answer them instead of going on.`, L = "presentPanel needs a storyboardId, a panel number (from 1) and an imagePrompt";
339
- function R(e) {
340
- let { panel: t } = e, n = C(e.storyboardId), r = C(e.imagePrompt);
341
- if (!n || !r || !T(t) || t < 1) return null;
342
- let i = (e) => (Array.isArray(e) ? e : []).map(C).filter(Boolean);
351
+ var M = ({ title: e }) => `The cast of "${e}" is now on the screen. Introduce the characters briefly. This reply is only the introduction: don't call presentPanel in it. When you have finished, you will be asked for panel 1. If the user has asked you to stop, or asked something else, answer them instead of going on.`, N = "presentPanel needs a storyboardId, a panel number (from 1) and an imagePrompt";
352
+ function P(e) {
353
+ let { panel: t } = e, n = E(e.storyboardId), r = E(e.imagePrompt);
354
+ if (!n || !r || !O(t) || t < 1) return null;
355
+ let i = (e) => (Array.isArray(e) ? e : []).map(E).filter(Boolean);
343
356
  return {
344
357
  storyboardId: n,
345
358
  panel: t,
346
359
  characters: i(e.characters),
347
360
  imagePrompt: r,
348
- caption: C(e.caption),
361
+ caption: E(e.caption),
349
362
  choices: i(e.choices).slice(0, 3)
350
363
  };
351
364
  }
352
- function z(e, t, n) {
365
+ function F(e, t, n) {
353
366
  let { id: r, totalPanels: i } = e;
354
367
  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, aloud, as a storyteller. This reply is only the telling: don't call presentPanel in it. When you have finished, you will be asked for panel ${t + 1}. 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.`;
355
368
  }
356
- var B = "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.", V = {
369
+ var I = "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.", L = {
357
370
  type: "function",
358
371
  name: pe,
359
- prompt: B,
372
+ prompt: I,
360
373
  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.",
361
374
  parameters: {
362
375
  type: "object",
@@ -403,9 +416,9 @@ var B = "When the user asks for a story, a picture book, a comic or a storyboard
403
416
  "characters"
404
417
  ]
405
418
  }
406
- }, H = {
419
+ }, R = {
407
420
  type: "function",
408
- name: me,
421
+ name: C,
409
422
  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.",
410
423
  parameters: {
411
424
  type: "object",
@@ -444,60 +457,60 @@ var B = "When the user asks for a story, a picture book, a comic or a storyboard
444
457
  "imagePrompt"
445
458
  ]
446
459
  }
447
- }, U = (e) => typeof e == "object" && !!e && !Array.isArray(e), Se = (e) => U(e) && typeof e.message == "string";
448
- function W(e) {
449
- let t = U(e?.data) ? e.data : {};
460
+ }, z = (e) => typeof e == "object" && !!e && !Array.isArray(e), De = (e) => z(e) && typeof e.message == "string";
461
+ function B(e) {
462
+ let t = z(e?.data) ? e.data : {};
450
463
  return {
451
464
  ...typeof t.imageData == "string" && { imageData: t.imageData },
452
465
  ...typeof t.imagePath == "string" && { imagePath: t.imagePath }
453
466
  };
454
467
  }
455
- function G(e) {
456
- let t = U(e?.data) ? e.data : {};
468
+ function V(e) {
469
+ let t = z(e?.data) ? e.data : {};
457
470
  return typeof t.html == "string" ? t.html : "";
458
471
  }
459
- function K(e) {
460
- let t = U(e?.data) ? e.data : {};
461
- return U(t.chart) ? JSON.stringify(t.chart) : "";
472
+ function H(e) {
473
+ let t = z(e?.data) ? e.data : {};
474
+ return z(t.chart) ? JSON.stringify(t.chart) : "";
462
475
  }
463
- var Ce = (e) => !!W(e).imageData || !!G(e) || !!K(e);
464
- function we(e, t) {
465
- let n = W(e), r = W(t);
476
+ var Oe = (e) => !!B(e).imageData || !!V(e) || !!H(e);
477
+ function ke(e, t) {
478
+ let n = B(e), r = B(t);
466
479
  if (n.imagePath && r.imagePath) return n.imagePath === r.imagePath;
467
480
  if (n.imageData) return n.imageData === r.imageData;
468
- let i = G(e);
469
- if (i) return i === G(t);
470
- let a = K(e);
471
- return !!a && a === K(t);
481
+ let i = V(e);
482
+ if (i) return i === V(t);
483
+ let a = H(e);
484
+ return !!a && a === H(t);
472
485
  }
473
- var q = (e, t) => e.userSpokeAt === void 0 || e.userSpokeAt > t, Te = () => crypto.randomUUID().replace(/-/g, "").slice(0, 12), Ee = "artifacts/";
474
- async function De(e, t) {
486
+ var U = (e, t) => e.userSpokeAt === void 0 || e.userSpokeAt > t, W = () => crypto.randomUUID().replace(/-/g, "").slice(0, 12), Ae = "artifacts/";
487
+ async function G(e, t) {
475
488
  let n = e.files?.artifacts;
476
489
  if (!e.app?.editImages || !n) return [];
477
490
  let r = [];
478
- for (let e of t) if (e.startsWith(Ee)) try {
491
+ for (let e of t) if (e.startsWith(Ae)) try {
479
492
  await n.exists(e.slice(10)) && r.push(e);
480
493
  } catch {}
481
494
  return r;
482
495
  }
483
- async function J(e, t, n = []) {
496
+ async function K(e, t, n = []) {
484
497
  let r = e.app, i = r?.editImages, a = r?.generateImage;
485
498
  try {
486
499
  let e;
487
500
  if (n.length && i) e = await i(t, [...n]);
488
501
  else if (a) e = await a(t);
489
502
  else return { message: "image generation isn't available" };
490
- return Se(e) ? e : { message: "image generation returned an unrecognized result" };
503
+ return De(e) ? e : { message: "image generation returned an unrecognized result" };
491
504
  } catch (e) {
492
505
  return { message: `image generation failed: ${e instanceof Error ? e.message : String(e)}` };
493
506
  }
494
507
  }
495
- var Oe = 50;
496
- function ke(e) {
508
+ var je = 50;
509
+ function q(e) {
497
510
  let t = /* @__PURE__ */ new Map();
498
511
  return (n) => {
499
512
  let r = n.conversationId ?? "", i = t.get(r);
500
- if (i === void 0 ? i = e() : t.delete(r), t.set(r, i), t.size > Oe) {
513
+ if (i === void 0 ? i = e() : t.delete(r), t.set(r, i), t.size > je) {
501
514
  let e = t.keys().next().value;
502
515
  e !== void 0 && t.delete(e);
503
516
  }
@@ -506,45 +519,45 @@ function ke(e) {
506
519
  }
507
520
  //#endregion
508
521
  //#region src/core/markdownSlide.ts
509
- var Y = "slide-md", Ae = "slide-md-split", X = "slide-md-text", je = "slide-md-picture", Me = .8, Ne = `
510
- .${Y} { box-sizing: border-box; flex-shrink: 0; width: ${t}px; height: 720px; padding: 56px 80px; overflow: hidden; display: flex; flex-direction: column; justify-content: center; gap: 0.5em; background: #ffffff; color: #0f172a; font-family: ui-sans-serif, system-ui, sans-serif; line-height: 1.35; }
511
- .${Y} > * { margin: 0; }
512
- .${Y} h1 { font-size: 1.9em; font-weight: 800; color: #1e3a8a; line-height: 1.15; }
513
- .${Y} h2 { font-size: 1.5em; font-weight: 700; color: #1e40af; line-height: 1.2; }
514
- .${Y} h3 { font-size: 1.2em; font-weight: 700; color: #334155; }
515
- .${Y} ul, .${Y} ol { padding-left: 1.3em; display: flex; flex-direction: column; gap: 0.3em; }
516
- .${Y} ul { list-style: disc; }
517
- .${Y} ol { list-style: decimal; }
518
- .${Y} li > ul, .${Y} li > ol { margin-top: 0.3em; font-size: 0.9em; }
519
- .${Y} li::marker { color: #2563eb; }
520
- .${Y} strong { font-weight: 700; color: #1e3a8a; }
521
- .${Y} em { font-style: italic; }
522
- .${Y} a { color: #2563eb; text-decoration: underline; }
523
- .${Y} code { font-family: ui-monospace, monospace; font-size: 0.85em; background: #f1f5f9; border-radius: 0.2em; padding: 0.05em 0.3em; }
524
- .${Y} pre { background: #0f172a; color: #e2e8f0; border-radius: 0.4em; padding: 0.6em 0.8em; font-size: 0.75em; overflow: hidden; }
525
- .${Y} pre code { background: none; padding: 0; color: inherit; }
526
- .${Y} blockquote { border-left: 0.2em solid #93c5fd; padding-left: 0.8em; color: #475569; font-style: italic; }
527
- .${Y} table { border-collapse: collapse; font-size: 0.85em; align-self: flex-start; }
528
- .${Y} th, .${Y} td { border: 1px solid #cbd5e1; padding: 0.25em 0.7em; text-align: left; }
529
- .${Y} th { background: #eff6ff; font-weight: 700; }
530
- .${Y} hr { border: 0; border-top: 2px solid #e2e8f0; }
531
- .${Y} img { max-width: 100%; max-height: 60%; }
532
- .${Y}.${Ae} { flex-direction: row; align-items: center; gap: 48px; }
533
- .${Y} .${X} { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 0.5em; }
534
- .${Y} .${X} > * { margin: 0; }
535
- .${Y} .${je} { flex: 0 0 44%; width: 44%; height: 100%; max-width: none; max-height: 100%; object-fit: cover; border-radius: 0.6em; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18); }
536
- .${Y} .math-display { display: block; text-align: center; font-size: 1.15em; }
537
- .${Y} math { font-family: "Latin Modern Math", "STIX Two Math", "Cambria Math", math; }
538
- .${Y} mtd { padding: 0.1em 0.4em; }
539
- .${Y} mtd:first-child { padding-left: 0; }
540
- .${Y} mtd:last-child { padding-right: 0; }
541
- .${Y} .math-error { color: #b91c1c; font-family: ui-monospace, monospace; }`;
542
- function Pe(e) {
522
+ var J = "slide-md", Me = "slide-md-split", Y = "slide-md-text", Ne = "slide-md-picture", Pe = .8, Fe = `
523
+ .${J} { box-sizing: border-box; flex-shrink: 0; width: ${t}px; height: 720px; padding: 56px 80px; overflow: hidden; display: flex; flex-direction: column; justify-content: center; gap: 0.5em; background: #ffffff; color: #0f172a; font-family: ui-sans-serif, system-ui, sans-serif; line-height: 1.35; }
524
+ .${J} > * { margin: 0; }
525
+ .${J} h1 { font-size: 1.9em; font-weight: 800; color: #1e3a8a; line-height: 1.15; }
526
+ .${J} h2 { font-size: 1.5em; font-weight: 700; color: #1e40af; line-height: 1.2; }
527
+ .${J} h3 { font-size: 1.2em; font-weight: 700; color: #334155; }
528
+ .${J} ul, .${J} ol { padding-left: 1.3em; display: flex; flex-direction: column; gap: 0.3em; }
529
+ .${J} ul { list-style: disc; }
530
+ .${J} ol { list-style: decimal; }
531
+ .${J} li > ul, .${J} li > ol { margin-top: 0.3em; font-size: 0.9em; }
532
+ .${J} li::marker { color: #2563eb; }
533
+ .${J} strong { font-weight: 700; color: #1e3a8a; }
534
+ .${J} em { font-style: italic; }
535
+ .${J} a { color: #2563eb; text-decoration: underline; }
536
+ .${J} code { font-family: ui-monospace, monospace; font-size: 0.85em; background: #f1f5f9; border-radius: 0.2em; padding: 0.05em 0.3em; }
537
+ .${J} pre { background: #0f172a; color: #e2e8f0; border-radius: 0.4em; padding: 0.6em 0.8em; font-size: 0.75em; overflow: hidden; }
538
+ .${J} pre code { background: none; padding: 0; color: inherit; }
539
+ .${J} blockquote { border-left: 0.2em solid #93c5fd; padding-left: 0.8em; color: #475569; font-style: italic; }
540
+ .${J} table { border-collapse: collapse; font-size: 0.85em; align-self: flex-start; }
541
+ .${J} th, .${J} td { border: 1px solid #cbd5e1; padding: 0.25em 0.7em; text-align: left; }
542
+ .${J} th { background: #eff6ff; font-weight: 700; }
543
+ .${J} hr { border: 0; border-top: 2px solid #e2e8f0; }
544
+ .${J} img { max-width: 100%; max-height: 60%; }
545
+ .${J}.${Me} { flex-direction: row; align-items: center; gap: 48px; }
546
+ .${J} .${Y} { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 0.5em; }
547
+ .${J} .${Y} > * { margin: 0; }
548
+ .${J} .${Ne} { flex: 0 0 44%; width: 44%; height: 100%; max-width: none; max-height: 100%; object-fit: cover; border-radius: 0.6em; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18); }
549
+ .${J} .math-display { display: block; text-align: center; font-size: 1.15em; }
550
+ .${J} math { font-family: "Latin Modern Math", "STIX Two Math", "Cambria Math", math; }
551
+ .${J} mtd { padding: 0.1em 0.4em; }
552
+ .${J} mtd:first-child { padding-left: 0; }
553
+ .${J} mtd:last-child { padding-right: 0; }
554
+ .${J} .math-error { color: #b91c1c; font-family: ui-monospace, monospace; }`;
555
+ function Ie(e) {
543
556
  let t = e.split("\n").filter((e) => e.trim()).length, n = e.length;
544
557
  return t <= 5 && n <= 250 ? 40 : t <= 8 && n <= 450 ? 34 : t <= 12 && n <= 700 ? 28 : 24;
545
558
  }
546
- var Fe = /^[ \t]*(?:\$\$([\s\S]+?)\$\$|\\\[([\s\S]+?)\\\])[ \t]*(?:\n|$)/, Ie = /^(?:\$\$(.+?)\$\$|\$(?!\s)((?:\\.|[^\\$\n])+?)(?<!\s)\$(?!\d)|\\\((.+?)\\\))/;
547
- function Le(e) {
559
+ var Le = /^[ \t]*(?:\$\$([\s\S]+?)\$\$|\\\[([\s\S]+?)\\\])[ \t]*(?:\n|$)/, Re = /^(?:\$\$(.+?)\$\$|\$(?!\s)((?:\\.|[^\\$\n])+?)(?<!\s)\$(?!\d)|\\\((.+?)\\\))/;
560
+ function ze(e) {
548
561
  return [{
549
562
  name: "blockMath",
550
563
  level: "block",
@@ -553,7 +566,7 @@ function Le(e) {
553
566
  return t ? t.index + (t[1] ?? "").length : void 0;
554
567
  },
555
568
  tokenizer(e) {
556
- let t = Fe.exec(e);
569
+ let t = Le.exec(e);
557
570
  if (t) return {
558
571
  type: "blockMath",
559
572
  raw: t[0],
@@ -566,7 +579,7 @@ function Le(e) {
566
579
  level: "inline",
567
580
  start: (e) => e.match(/(?<!\\)\$|\\\(/)?.index,
568
581
  tokenizer(e) {
569
- let t = Ie.exec(e);
582
+ let t = Re.exec(e);
570
583
  if (t) return {
571
584
  type: "inlineMath",
572
585
  raw: t[0],
@@ -577,11 +590,11 @@ function Le(e) {
577
590
  renderer: (t) => e(String(t.text), t.display === !0)
578
591
  }];
579
592
  }
580
- var Re = /(<\/mi>|<\/mn>|<\/mrow>|<mo[^>]*>[)\]]<\/mo>)?(<mi(?: mathvariant="normal")?>[A-Za-z]{2,}<\/mi>)<mo>\u2061<\/mo>/g, ze = "<mspace width=\"0.1667em\"></mspace>", Be = (e) => e.replace(Re, (e, t, n) => `${t ? t + ze : ""}${n}<mo lspace="0" rspace="0.1667em">\u2061</mo>`);
581
- async function Ve(e) {
593
+ var Be = /(<\/mi>|<\/mn>|<\/mrow>|<mo[^>]*>[)\]]<\/mo>)?(<mi(?: mathvariant="normal")?>[A-Za-z]{2,}<\/mi>)<mo>\u2061<\/mo>/g, Ve = "<mspace width=\"0.1667em\"></mspace>", He = (e) => e.replace(Be, (e, t, n) => `${t ? t + Ve : ""}${n}<mo lspace="0" rspace="0.1667em">\u2061</mo>`);
594
+ async function Ue(e) {
582
595
  let [{ Marked: t }, { default: n }] = await Promise.all([import("marked"), import("katex")]), r = (e, t) => {
583
596
  try {
584
- return Be(n.renderToString(e, {
597
+ return He(n.renderToString(e, {
585
598
  output: "mathml",
586
599
  displayMode: t,
587
600
  throwOnError: !0
@@ -593,38 +606,42 @@ async function Ve(e) {
593
606
  gfm: !0,
594
607
  breaks: !1
595
608
  });
596
- i.use({ extensions: Le(r) });
597
- let a = i.lexer(e), o = a.findIndex((e) => e.type === "paragraph" && e.tokens?.length === 1 && e.tokens[0]?.type === "image" && e.tokens[0].href.trim() === "{{image}}");
609
+ i.use({ extensions: ze(r) });
610
+ let a = i.lexer(e), o = a.findIndex((e) => {
611
+ if (e.type !== "paragraph" || e.tokens?.length !== 1) return !1;
612
+ let t = e.tokens[0];
613
+ return t?.type === "image" ? t.href.trim() === g : t?.type === "text" && t.text.trim() === "{{image}}";
614
+ });
598
615
  if (o >= 0) {
599
616
  let [t] = a.splice(o, 1), n = t?.type === "paragraph" ? t.tokens?.[0] : void 0, r = n?.type === "image" ? n.text : "", s = i.parser(a), c = e.replace(t?.raw ?? "", "");
600
- return `<style>${Ne}</style>
601
- <div class="${Y} ${Ae}" data-fit style="font-size: ${Math.round(Pe(c) * Me)}px">
602
- <div class="${X}">
617
+ return `<style>${Fe}</style>
618
+ <div class="${J} ${Me}" data-fit style="font-size: ${Math.round(Ie(c) * Pe)}px">
619
+ <div class="${Y}">
603
620
  ${s}</div>
604
- <img class="${je}" src="${g}" alt="${p(r)}">
621
+ <img class="${Ne}" src="${g}" alt="${p(r)}">
605
622
  </div>`;
606
623
  }
607
624
  let s = await i.parse(e);
608
- return `<style>${Ne}</style>
609
- <div class="${Y}" data-fit style="font-size: ${Pe(e)}px">
625
+ return `<style>${Fe}</style>
626
+ <div class="${J}" data-fit style="font-size: ${Ie(e)}px">
610
627
  ${s}</div>`;
611
628
  }
612
629
  //#endregion
613
630
  //#region src/core/records.ts
614
- var He = "slideshows", Z = "storyboards", Ue = {}, We = /* @__PURE__ */ new WeakMap(), Ge = /* @__PURE__ */ new WeakMap();
615
- function Ke(e) {
616
- let t = We.get(e);
617
- return t || We.set(e, t = /* @__PURE__ */ new Map()), t;
631
+ var We = "slideshows", X = "storyboards", Ge = {}, Ke = /* @__PURE__ */ new WeakMap(), qe = /* @__PURE__ */ new WeakMap();
632
+ function Je(e) {
633
+ let t = Ke.get(e);
634
+ return t || Ke.set(e, t = /* @__PURE__ */ new Map()), t;
618
635
  }
619
- function qe(t, n) {
620
- let r = Ge.get(t);
621
- r || Ge.set(t, r = /* @__PURE__ */ new Map());
636
+ function Ye(t, n) {
637
+ let r = qe.get(t);
638
+ r || qe.set(t, r = /* @__PURE__ */ new Map());
622
639
  let i = r.get(n);
623
640
  return i || r.set(n, i = e()), i;
624
641
  }
625
- var Je = (e, t) => `${e}/${t}.json`;
626
- async function Ye(e, t) {
627
- let n = Ke(e ?? Ue), r = n.get(t);
642
+ var Xe = (e, t) => `${e}/${t}.json`;
643
+ async function Ze(e, t) {
644
+ let n = Je(e ?? Ge), r = n.get(t);
628
645
  if (r) return r;
629
646
  if (!e) return null;
630
647
  try {
@@ -634,14 +651,14 @@ async function Ye(e, t) {
634
651
  return null;
635
652
  }
636
653
  }
637
- async function Xe(e, t, n) {
638
- return x.test(n) ? Ye(e, Je(t, n)) : null;
654
+ async function Qe(e, t, n) {
655
+ return w.test(n) ? Ze(e, Xe(t, n)) : null;
639
656
  }
640
- async function Q(e, t, n, r) {
641
- let i = Je(t, n), a = e ?? Ue;
642
- return qe(a, i)(async () => {
643
- let t = r(await Ye(e, i));
644
- if (Ke(a).set(i, t), !e) return !1;
657
+ async function Z(e, t, n, r) {
658
+ let i = Xe(t, n), a = e ?? Ge;
659
+ return Ye(a, i)(async () => {
660
+ let t = r(await Ze(e, i));
661
+ if (Je(a).set(i, t), !e) return !1;
645
662
  try {
646
663
  return await e.write(i, JSON.stringify(t, null, 2)), !0;
647
664
  } catch (e) {
@@ -649,12 +666,12 @@ async function Q(e, t, n, r) {
649
666
  }
650
667
  });
651
668
  }
652
- var $ = (e) => `the ${e} could not be saved, so it lasts only until the app or server restarts`, Ze = 6e4;
653
- function Qe() {
669
+ var Q = (e) => `the ${e} could not be saved, so it lasts only until the app or server restarts`, $e = 6e4;
670
+ function et() {
654
671
  let e = /* @__PURE__ */ new Map();
655
672
  return { claim: (t) => {
656
673
  let n = Date.now();
657
- for (let [t, r] of e) n - r.at > Ze && e.delete(t);
674
+ for (let [t, r] of e) n - r.at > $e && e.delete(t);
658
675
  let r = e.get(t);
659
676
  if (r) return { earlier: r.shown };
660
677
  let i = () => void 0, a = new Promise((e) => i = e);
@@ -668,7 +685,7 @@ function Qe() {
668
685
  }
669
686
  //#endregion
670
687
  //#region src/core/presentSlide.ts
671
- function $e({ slide: e, totalSlides: t, mode: n }) {
688
+ function tt({ slide: e, totalSlides: t, mode: n }) {
672
689
  return n === "steps" ? {
673
690
  step: e,
674
691
  total: t,
@@ -686,7 +703,7 @@ function $e({ slide: e, totalSlides: t, mode: n }) {
686
703
  nextCall: `call presentSlide for slide ${e + 1} of ${t}`
687
704
  };
688
705
  }
689
- var et = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, html: a, markdown: o, chart: s }) => JSON.stringify([
706
+ var nt = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, html: a, markdown: o, chart: s }) => JSON.stringify([
690
707
  e,
691
708
  t,
692
709
  n,
@@ -695,19 +712,19 @@ var et = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, html: a, mark
695
712
  a,
696
713
  o,
697
714
  s
698
- ]), tt = ke(() => ({
715
+ ]), rt = q(() => ({
699
716
  latest: {
700
717
  presentation: null,
701
718
  steps: null
702
719
  },
703
720
  lastShown: null,
704
- repeats: Qe()
721
+ repeats: et()
705
722
  }));
706
- function nt(e, t) {
723
+ function it(e, t) {
707
724
  let n = e.latest[t.mode], r = n?.totalSlides === t.totalSlides && (t.slide !== 1 || n.firstTitle === t.title);
708
725
  if (n && r) return n;
709
726
  let i = {
710
- id: Te(),
727
+ id: W(),
711
728
  mode: t.mode,
712
729
  totalSlides: t.totalSlides,
713
730
  firstTitle: t.slide === 1 ? t.title : "",
@@ -717,69 +734,70 @@ function nt(e, t) {
717
734
  };
718
735
  return e.latest[t.mode] = i, i;
719
736
  }
720
- function rt(e, t, n, r) {
737
+ function at(e, t, n, r) {
721
738
  t.current = n.slide, t.shownAt = Date.now(), e.lastShown = t;
722
739
  let i = n.mode === "steps" ? "step" : "slide", { uuid: a, ...o } = r;
723
740
  return {
724
741
  ...o,
725
742
  message: `${i} ${n.slide} of ${n.totalSlides} is on the screen again, as it was`,
726
- instructions: M(n),
743
+ instructions: k(n),
727
744
  instructionsRequired: !0,
728
- sequence: $e(n)
745
+ sequence: tt(n)
729
746
  };
730
747
  }
731
- function it(e, t) {
748
+ function ot(e, t) {
732
749
  if (e.mode !== "steps") return e.title ? `A presentation slide titled "${e.title}". ${e.imagePrompt}` : e.imagePrompt;
733
750
  let n = e.title ? `, "${e.title}"` : "";
734
751
  return [
735
752
  `An instructional illustration of step ${e.slide} of ${e.totalSlides}${n}. ${e.imagePrompt}`,
736
- t ? at : "",
753
+ t ? st : "",
737
754
  "Show the action clearly, with little or no text."
738
755
  ].filter(Boolean).join(" ");
739
756
  }
740
- var at = "The reference image is the previous step: keep the same objects, hands, tools and setting, and show what this step changes.";
741
- async function ot(e, t, n) {
757
+ var st = "The reference image is the previous step: keep the same objects, hands, tools and setting, and show what this step changes.";
758
+ async function ct(e, t, n) {
742
759
  if (n.mode !== "steps") return [];
743
- let r = W(t.slides.get(n.slide - 1)).imagePath;
744
- return r ? await De(e, [r]) : [];
760
+ let r = B(t.slides.get(n.slide - 1)).imagePath;
761
+ return r ? await G(e, [r]) : [];
745
762
  }
746
- var st = (e, t) => [
763
+ var lt = (e, t) => [
747
764
  e.mode === "steps" ? `An instructional illustration for step ${e.slide} of ${e.totalSlides}${e.title ? `, "${e.title}"` : ""}. ${e.imagePrompt}` : `A picture for a presentation slide${e.title ? ` titled "${e.title}"` : ""}. ${e.imagePrompt}`,
748
- t ? at : "",
765
+ t ? st : "",
749
766
  e.markdown ? "Keep the subject in the middle: the picture is cropped to a tall frame." : "",
750
767
  "No text, letters or numbers in the picture."
751
768
  ].filter(Boolean).join(" ");
752
- async function ct(e, t, n) {
769
+ async function ut(e, t, n) {
753
770
  if (n.chart) return {
754
771
  chart: n.chart,
755
772
  prompt: ""
756
773
  };
757
774
  if (n.html || n.markdown) {
758
775
  let r = n.html ? { html: n.html } : {
759
- html: await Ve(n.markdown ?? ""),
776
+ html: await Ue(n.markdown ?? ""),
760
777
  markdown: n.markdown ?? ""
761
- }, i = y(r.html);
762
- if (i && !n.imagePrompt) return { failed: {
763
- message: O,
764
- sequence: null
765
- } };
766
- if (!i) return {
778
+ };
779
+ if (!y(r.html)) return {
767
780
  ...r,
768
781
  prompt: ""
769
782
  };
770
- let a = await ot(e, t, n), o = st(n, a.length > 0), s = await J(e, o, a), { imageData: c, imagePath: l } = W(s);
771
- return c ? {
783
+ let i = n.imagePrompt || ie(r.html) || n.title, a = {
784
+ ...n,
785
+ imagePrompt: i
786
+ }, o = await ct(e, t, a), s = lt(a, o.length > 0), c = await K(e, s, o), { imageData: l, imagePath: u } = B(c);
787
+ return l ? {
772
788
  ...r,
773
- imageData: c,
774
- ...l && { imagePath: l },
775
- prompt: o
789
+ imageData: l,
790
+ ...u && { imagePath: u },
791
+ prompt: s,
792
+ imagePrompt: i
776
793
  } : {
777
794
  ...r,
778
- prompt: o,
779
- pictureFailed: s.message
795
+ prompt: s,
796
+ imagePrompt: i,
797
+ pictureFailed: c.message
780
798
  };
781
799
  }
782
- let r = await ot(e, t, n), i = it(n, r.length > 0), a = await J(e, i, r), { imageData: o, imagePath: s } = W(a);
800
+ let r = await ct(e, t, n), i = ot(n, r.length > 0), a = await K(e, i, r), { imageData: o, imagePath: s } = B(a);
783
801
  return o ? {
784
802
  imageData: o,
785
803
  ...s && { imagePath: s },
@@ -789,10 +807,10 @@ async function ct(e, t, n) {
789
807
  sequence: null
790
808
  } };
791
809
  }
792
- async function lt(e, t, n) {
793
- let r = await ct(e, t, n);
810
+ async function dt(e, t, n) {
811
+ let r = await ut(e, t, n);
794
812
  if ("failed" in r) return r.failed;
795
- let { imageData: i, imagePath: a, html: o, markdown: s, chart: c, prompt: l, pictureFailed: u } = r, d = t.id, f = await Q(e.files?.artifacts, He, d, (e) => {
813
+ let { imageData: i, imagePath: a, html: o, markdown: s, chart: c, prompt: l, pictureFailed: u } = r, d = t.id, f = await Z(e.files?.artifacts, We, d, (e) => {
796
814
  let t = e ?? {
797
815
  id: d,
798
816
  title: "",
@@ -802,7 +820,7 @@ async function lt(e, t, n) {
802
820
  };
803
821
  return n.slide === 1 && (t.title = n.title), t.slides[String(n.slide)] = {
804
822
  title: n.title,
805
- imagePrompt: o && !l ? "" : n.imagePrompt,
823
+ imagePrompt: o ? r.imagePrompt ?? "" : n.imagePrompt,
806
824
  ...a && { imagePath: a },
807
825
  ...o && { html: o },
808
826
  ...s && { markdown: s },
@@ -828,21 +846,21 @@ async function lt(e, t, n) {
828
846
  `${m} ${n.slide} of ${n.totalSlides} of slideshow "${d}" is on the screen`,
829
847
  a ? `saved to ${a}` : "",
830
848
  u ? `its picture couldn't be drawn (${u}), so the slide is shown without it` : "",
831
- f ? "" : $("slideshow")
849
+ f ? "" : Q("slideshow")
832
850
  ].filter(Boolean).join("; "),
833
- instructions: M(n),
851
+ instructions: k(n),
834
852
  instructionsRequired: !0,
835
- sequence: $e(n)
853
+ sequence: tt(n)
836
854
  };
837
855
  }
838
- async function ut(e, t) {
839
- let n = A(t);
856
+ async function $(e, t) {
857
+ let n = xe(t);
840
858
  if (typeof n == "string") return {
841
859
  message: n,
842
860
  sequence: null
843
861
  };
844
- let r = tt(e), i = nt(r, n), a = n.mode === "steps";
845
- if (a && n.slide > i.current && i.current > 0 && !q(e, i.shownAt)) {
862
+ let r = rt(e), i = it(r, n), a = n.mode === "steps";
863
+ if (a && n.slide > i.current && i.current > 0 && !U(e, i.shownAt)) {
846
864
  console.info(`[sequence] holding step ${n.slide} for the user`);
847
865
  let e = i.shownAt === Infinity ? "is still being drawn" : "is still on the screen";
848
866
  return {
@@ -851,15 +869,15 @@ async function ut(e, t) {
851
869
  };
852
870
  }
853
871
  let o = a ? i.slides.get(n.slide) : void 0;
854
- if (o) return we(e.currentResult, o) ? {
872
+ if (o) return ke(e.currentResult, o) ? {
855
873
  message: `step ${n.slide} of ${n.totalSlides} is already on the screen`,
856
874
  cancelled: !0
857
- } : rt(r, i, n, o);
858
- let s = r.repeats.claim(et(i.id, n));
875
+ } : at(r, i, n, o);
876
+ let s = r.repeats.claim(nt(i.id, n));
859
877
  if ("earlier" in s) {
860
- if (!await s.earlier) return ut(e, t);
878
+ if (!await s.earlier) return $(e, t);
861
879
  let a = i.slides.get(n.slide);
862
- return a && r.lastShown !== i ? rt(r, i, n, a) : {
880
+ return a && r.lastShown !== i ? at(r, i, n, a) : {
863
881
  message: `slide ${n.slide} of ${n.totalSlides} is already on the screen`,
864
882
  cancelled: !0
865
883
  };
@@ -871,22 +889,22 @@ async function ut(e, t) {
871
889
  i.current = n.slide, i.shownAt = Infinity;
872
890
  let u = !1;
873
891
  try {
874
- let t = await lt(e, i, n);
875
- return u = Ce(t), u && (i.slides.set(n.slide, t), i.current = n.slide, i.shownAt = Date.now(), r.lastShown = i), t;
892
+ let t = await dt(e, i, n);
893
+ return u = Oe(t), u && (i.slides.set(n.slide, t), i.current = n.slide, i.shownAt = Date.now(), r.lastShown = i), t;
876
894
  } finally {
877
895
  c(u), !u && i.current === n.slide && (i.current = l.current, i.shownAt = l.shownAt);
878
896
  }
879
897
  }
880
898
  //#endregion
881
899
  //#region src/core/storyboard.ts
882
- var dt = ({ id: e, title: t, totalPanels: n }) => ({
900
+ var ft = ({ id: e, title: t, totalPanels: n }) => ({
883
901
  step: 0,
884
902
  total: n,
885
903
  kind: "story",
886
904
  label: `The cast of "${t}"`,
887
905
  onShown: "introduce the characters",
888
906
  nextCall: `call presentPanel for panel 1 of ${n} with storyboardId "${e}"`
889
- }), ft = ({ id: e, totalPanels: t }, n, r) => ({
907
+ }), pt = ({ id: e, totalPanels: t }, n, r) => ({
890
908
  step: n,
891
909
  total: t,
892
910
  kind: "story",
@@ -894,21 +912,21 @@ var dt = ({ id: e, title: t, totalPanels: n }) => ({
894
912
  onShown: "tell that part of the story",
895
913
  nextCall: `call presentPanel for panel ${n + 1} of ${t} with storyboardId "${e}"`,
896
914
  ...r.length > 0 && { waitsForUser: !0 }
897
- }), pt = (e, t) => e ? `${e}. ${t}` : t, mt = (e, { name: t, description: n }) => pt(e, `Character reference sheet of ${t}: ${n}. Full body, front, side and back views, on a plain white background. No text or labels.`);
898
- async function ht(e, t) {
899
- let n = F(t);
915
+ }), mt = (e, t) => e ? `${e}. ${t}` : t, ht = (e, { name: t, description: n }) => mt(e, `Character reference sheet of ${t}: ${n}. Full body, front, side and back views, on a plain white background. No text or labels.`);
916
+ async function gt(e, t) {
917
+ let n = j(t);
900
918
  if (typeof n == "string") return {
901
919
  message: n,
902
920
  sequence: null
903
921
  };
904
- let r = await Promise.all(n.characters.map((t) => J(e, mt(n.style, t)))), i = r.map(W), a = r.find((e, t) => !i[t]?.imageData);
922
+ let r = await Promise.all(n.characters.map((t) => K(e, ht(n.style, t)))), i = r.map(B), a = r.find((e, t) => !i[t]?.imageData);
905
923
  if (i.every(({ imageData: e }) => !e) && a) return {
906
924
  ...a,
907
925
  message: `the character sheets couldn't be made: ${a.message}`,
908
926
  sequence: null
909
927
  };
910
928
  let o = {
911
- id: Te(),
929
+ id: W(),
912
930
  ...n,
913
931
  characters: n.characters.map((e, t) => {
914
932
  let n = i[t]?.imagePath;
@@ -918,7 +936,7 @@ async function ht(e, t) {
918
936
  };
919
937
  }),
920
938
  panels: {}
921
- }, s = await Q(e.files?.artifacts, Z, 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;
939
+ }, s = await Z(e.files?.artifacts, X, 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;
922
940
  return {
923
941
  data: {
924
942
  storyboardId: o.id,
@@ -939,39 +957,39 @@ async function ht(e, t) {
939
957
  `storyboard "${o.id}" is ready with ${o.totalPanels} panels; the cast is on the screen`,
940
958
  c.length ? `character sheets saved to ${c.join(", ")}` : "",
941
959
  l.length ? `no sheet for ${l.join("; ")}: they will be drawn from their description` : "",
942
- s ? "" : $("storyboard")
960
+ s ? "" : Q("storyboard")
943
961
  ].filter(Boolean).join("; "),
944
- instructions: I(o),
962
+ instructions: M(o),
945
963
  instructionsRequired: !0,
946
- sequence: dt(o)
964
+ sequence: ft(o)
947
965
  };
948
966
  }
949
- function gt(e, t, n) {
950
- let r = [pt(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}`);
967
+ function _t(e, t, n) {
968
+ let r = [mt(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}`);
951
969
  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(" ");
952
970
  }
953
- async function _t(e, t, n) {
971
+ async function vt(e, t, n) {
954
972
  let r = [], i = [];
955
973
  for (let a of n.characters) {
956
- let n = t.characters.find((e) => w(e.name, a));
974
+ let n = t.characters.find((e) => D(e.name, a));
957
975
  if (!n) r.push(a);
958
976
  else if (!i.some((e) => e.character === n)) {
959
- let [t] = n.imagePath ? await De(e, [n.imagePath]) : [];
977
+ let [t] = n.imagePath ? await G(e, [n.imagePath]) : [];
960
978
  i.push({
961
979
  character: n,
962
980
  sheet: t ?? null
963
981
  });
964
982
  }
965
983
  }
966
- let a = i.map(({ sheet: e }) => e).filter((e) => !!e), o = gt(t, n, i.map(({ character: e, sheet: t }) => ({
984
+ let a = i.map(({ sheet: e }) => e).filter((e) => !!e), o = _t(t, n, i.map(({ character: e, sheet: t }) => ({
967
985
  character: e,
968
986
  hasSheet: !!t
969
- }))), s = await J(e, o, a), { imageData: c, imagePath: l } = W(s);
987
+ }))), s = await K(e, o, a), { imageData: c, imagePath: l } = B(s);
970
988
  if (!c) return {
971
989
  ...s,
972
990
  sequence: null
973
991
  };
974
- let u = n.panel < t.totalPanels && n.choices.length >= 2 ? n.choices : [], d = await Q(e.files?.artifacts, Z, t.id, (e) => {
992
+ let u = n.panel < t.totalPanels && n.choices.length >= 2 ? n.choices : [], d = await Z(e.files?.artifacts, X, t.id, (e) => {
975
993
  let r = e ?? t;
976
994
  return u.length && (r.interactive = !0), r.panels[String(n.panel)] = {
977
995
  caption: n.caption,
@@ -997,25 +1015,25 @@ async function _t(e, t, n) {
997
1015
  `panel ${n.panel} of ${t.totalPanels} is on the screen`,
998
1016
  l ? `saved to ${l}` : "",
999
1017
  r.length ? `not in the cast, so drawn from the prompt alone: ${r.join(", ")}` : "",
1000
- d ? "" : $("storyboard")
1018
+ d ? "" : Q("storyboard")
1001
1019
  ].filter(Boolean).join("; "),
1002
- instructions: z(t, n.panel, u),
1020
+ instructions: F(t, n.panel, u),
1003
1021
  instructionsRequired: !0,
1004
- sequence: ft(t, n.panel, u)
1022
+ sequence: pt(t, n.panel, u)
1005
1023
  };
1006
1024
  }
1007
- var vt = ke(() => ({
1008
- repeats: Qe(),
1025
+ var yt = q(() => ({
1026
+ repeats: et(),
1009
1027
  awaitingChoice: /* @__PURE__ */ new Map()
1010
1028
  }));
1011
- async function yt(e, t) {
1012
- let n = R(t);
1029
+ async function bt(e, t) {
1030
+ let n = P(t);
1013
1031
  if (!n) return {
1014
- message: L,
1032
+ message: N,
1015
1033
  sequence: null
1016
1034
  };
1017
- let { storyboardId: r, panel: i } = n, { repeats: a, awaitingChoice: o } = vt(e), s = o.get(r);
1018
- if (s && i > s.panel && !q(e, s.shownAt)) return console.info(`[sequence] holding panel ${i} for the user`), {
1035
+ let { storyboardId: r, panel: i } = n, { repeats: a, awaitingChoice: o } = yt(e), s = o.get(r);
1036
+ if (s && i > s.panel && !U(e, s.shownAt)) return console.info(`[sequence] holding panel ${i} for the user`), {
1019
1037
  message: s.shownAt === Infinity ? `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.`,
1020
1038
  cancelled: !0
1021
1039
  };
@@ -1023,7 +1041,7 @@ async function yt(e, t) {
1023
1041
  if ("earlier" in c) return await c.earlier ? {
1024
1042
  message: `panel ${i} is already on the screen`,
1025
1043
  cancelled: !0
1026
- } : yt(e, t);
1044
+ } : bt(e, t);
1027
1045
  let { settle: l } = c, u = {
1028
1046
  panel: i,
1029
1047
  shownAt: Infinity
@@ -1031,7 +1049,7 @@ async function yt(e, t) {
1031
1049
  o.set(r, u);
1032
1050
  let f = () => o.get(r) === u, p = !1;
1033
1051
  try {
1034
- let t = await Xe(e.files?.artifacts, Z, r);
1052
+ let t = await Qe(e.files?.artifacts, X, r);
1035
1053
  if (!t) return {
1036
1054
  message: `there is no storyboard "${r}"; call defineStoryboard first`,
1037
1055
  sequence: null
@@ -1040,8 +1058,8 @@ async function yt(e, t) {
1040
1058
  message: `storyboard "${t.id}" has ${t.totalPanels} panels`,
1041
1059
  sequence: null
1042
1060
  };
1043
- let a = await _t(e, t, n);
1044
- p = !!W(a).imageData;
1061
+ let a = await vt(e, t, n);
1062
+ p = !!B(a).imageData;
1045
1063
  let s = a.data;
1046
1064
  return p && f() && (s?.choices?.length ? o.set(r, {
1047
1065
  panel: i,
@@ -1053,21 +1071,21 @@ async function yt(e, t) {
1053
1071
  }
1054
1072
  //#endregion
1055
1073
  //#region src/core/index.ts
1056
- var bt = {
1057
- toolDefinition: P,
1074
+ var xt = {
1075
+ toolDefinition: A,
1058
1076
  generatingMessage: "Making the slide...",
1059
1077
  isEnabled: () => !0,
1060
- execute: (e, t) => ut(e, t)
1061
- }, xt = {
1062
- toolDefinition: V,
1078
+ execute: (e, t) => $(e, t)
1079
+ }, St = {
1080
+ toolDefinition: L,
1063
1081
  generatingMessage: "Drawing the characters...",
1064
1082
  isEnabled: () => !0,
1065
- execute: (e, t) => ht(e, t)
1066
- }, St = {
1067
- toolDefinition: H,
1083
+ execute: (e, t) => gt(e, t)
1084
+ }, Ct = {
1085
+ toolDefinition: R,
1068
1086
  generatingMessage: "Drawing the panel...",
1069
1087
  isEnabled: () => !0,
1070
- execute: (e, t) => yt(e, t)
1088
+ execute: (e, t) => bt(e, t)
1071
1089
  };
1072
1090
  //#endregion
1073
- export { w as A, g as B, O as C, R as D, z as E, o as F, y as H, s as I, h as L, b as M, de as N, A as O, r as P, l as R, D as S, I as T, ie as U, t as V, re as W, P as _, Z as a, E as b, pe as c, _e as d, ge as f, fe as g, H as h, He as i, M as j, F as k, V as l, me as m, St as n, Xe as o, L as p, bt as r, Ve as s, xt as t, he as u, N as v, B as w, k as x, x as y, n as z };
1091
+ export { k as A, t as B, I as C, xe as D, P as E, s as F, oe as H, h as I, l as L, fe as M, r as N, j as O, o as P, n as R, ve as S, F as T, ae as U, y as V, A as _, X as a, _e as b, pe as c, ge as d, he as f, S as g, R as h, We as i, b as j, D as k, L as l, C as m, Ct as n, Qe as o, N as p, xt as r, Ue as s, St as t, me as u, Ee as v, M as w, ye as x, w as y, g as z };