@gui-chat-plugin/sequence 0.6.1 → 0.6.3

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", me = "presentPanel", he = 4, ge = 12, _e = 3, ve = /^[0-9a-f]{12}$/, C = (e) => typeof e == "object" && !!e && !Array.isArray(e), w = (e) => typeof e == "string" ? e.trim() : "", T = (e, t) => e.toLowerCase() === t.toLowerCase(), E = (e) => typeof e == "number" && Number.isInteger(e), ye = "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 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 (!C(t) || !C(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 && !C(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;
251
+ function k(e) {
252
+ let { slide: t, totalSlides: n, title: r, imagePrompt: i } = e, a = w(e.html), o = a ? "" : w(e.markdown), s = !a && !o && e.chart !== void 0 && e.chart !== null;
253
+ if (!E(t) || !E(n) || t < 1 || n < t || !a && !o && !s && !w(i)) return ye;
254
+ let c = s ? be(e.chart) : null;
255
+ if (s && !c) return O;
243
256
  if (Math.max(a.length, o.length, c ? JSON.stringify(c).length : 0) > 6e4) return D;
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 ? w(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 xe = "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.", A = ({ 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: ${xe} 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: ${xe} Then wrap up the slideshow.`;
277
+ }, Se = [
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}) on a line of its own: the slide is then two columns, the text on the left and the picture on the right.`, 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(" "), Ce = `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 \\$, and & % # inside \\text{} 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.`, we = `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.`, Te = "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.", j = {
269
282
  type: "function",
270
- name: fe,
271
- prompt: N,
283
+ name: S,
284
+ prompt: Te,
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: Se
295
308
  },
296
309
  markdown: {
297
310
  type: "string",
298
- description: be
311
+ description: Ce
299
312
  },
300
313
  chart: {
301
314
  type: "string",
302
- description: xe
315
+ description: we
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 M(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 (!E(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 = C(t) ? w(t.name) : "", r = C(t) ? w(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) => T(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: w(e.title),
345
+ style: w(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 N = ({ 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.`, P = "presentPanel needs a storyboardId, a panel number (from 1) and an imagePrompt";
352
+ function F(e) {
353
+ let { panel: t } = e, n = w(e.storyboardId), r = w(e.imagePrompt);
354
+ if (!n || !r || !E(t) || t < 1) return null;
355
+ let i = (e) => (Array.isArray(e) ? e : []).map(w).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: w(e.caption),
349
362
  choices: i(e.choices).slice(0, 3)
350
363
  };
351
364
  }
352
- function z(e, t, n) {
365
+ function I(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 L = "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.", R = {
357
370
  type: "function",
358
371
  name: pe,
359
- prompt: B,
372
+ prompt: L,
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,7 +416,7 @@ 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
+ }, z = {
407
420
  type: "function",
408
421
  name: me,
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.",
@@ -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
+ }, B = (e) => typeof e == "object" && !!e && !Array.isArray(e), Ee = (e) => B(e) && typeof e.message == "string";
461
+ function V(e) {
462
+ let t = B(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 H(e) {
469
+ let t = B(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 U(e) {
473
+ let t = B(e?.data) ? e.data : {};
474
+ return B(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 De = (e) => !!V(e).imageData || !!H(e) || !!U(e);
477
+ function Oe(e, t) {
478
+ let n = V(e), r = V(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 = H(e);
482
+ if (i) return i === H(t);
483
+ let a = U(e);
484
+ return !!a && a === U(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 W = (e, t) => e.userSpokeAt === void 0 || e.userSpokeAt > t, G = () => crypto.randomUUID().replace(/-/g, "").slice(0, 12), ke = "artifacts/";
487
+ async function K(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(ke)) 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 q(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 Ee(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 Ae = 50;
509
+ function J(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 > Ae) {
501
514
  let e = t.keys().next().value;
502
515
  e !== void 0 && t.delete(e);
503
516
  }
@@ -506,7 +519,7 @@ 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 = `
522
+ var Y = "slide-md", je = "slide-md-split", X = "slide-md-text", Me = "slide-md-picture", Ne = .8, Pe = `
510
523
  .${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
524
  .${Y} > * { margin: 0; }
512
525
  .${Y} h1 { font-size: 1.9em; font-weight: 800; color: #1e3a8a; line-height: 1.15; }
@@ -529,22 +542,22 @@ var Y = "slide-md", Ae = "slide-md-split", X = "slide-md-text", je = "slide-md-p
529
542
  .${Y} th { background: #eff6ff; font-weight: 700; }
530
543
  .${Y} hr { border: 0; border-top: 2px solid #e2e8f0; }
531
544
  .${Y} img { max-width: 100%; max-height: 60%; }
532
- .${Y}.${Ae} { flex-direction: row; align-items: center; gap: 48px; }
545
+ .${Y}.${je} { flex-direction: row; align-items: center; gap: 48px; }
533
546
  .${Y} .${X} { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 0.5em; }
534
547
  .${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); }
548
+ .${Y} .${Me} { 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
549
  .${Y} .math-display { display: block; text-align: center; font-size: 1.15em; }
537
550
  .${Y} math { font-family: "Latin Modern Math", "STIX Two Math", "Cambria Math", math; }
538
551
  .${Y} mtd { padding: 0.1em 0.4em; }
539
552
  .${Y} mtd:first-child { padding-left: 0; }
540
553
  .${Y} mtd:last-child { padding-right: 0; }
541
554
  .${Y} .math-error { color: #b91c1c; font-family: ui-monospace, monospace; }`;
542
- function Pe(e) {
555
+ function Fe(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 Ie = /^[ \t]*(?:\$\$([\s\S]+?)\$\$|\\\[([\s\S]+?)\\\])[ \t]*(?:\n|$)/, Le = /^(?:\$\$(.+?)\$\$|\$(?!\s)((?:\\.|[^\\$\n])+?)(?<!\s)\$(?!\d)|\\\((.+?)\\\))/;
560
+ function Re(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 = Ie.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 = Le.exec(e);
570
583
  if (t) return {
571
584
  type: "inlineMath",
572
585
  raw: t[0],
@@ -577,11 +590,21 @@ 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 ze = /(<\/mi>|<\/mn>|<\/mrow>|<mo[^>]*>[)\]]<\/mo>)?(<mi(?: mathvariant="normal")?>[A-Za-z]{2,}<\/mi>)<mo>\u2061<\/mo>/g, Be = "<mspace width=\"0.1667em\"></mspace>", Ve = (e) => e.replace(ze, (e, t, n) => `${t ? t + Be : ""}${n}<mo lspace="0" rspace="0.1667em">\u2061</mo>`), He = /\\(?:text(?:bf|it|rm|sf|tt|normal)?|mbox)\s*\{/g, Ue = (e) => {
594
+ let t = "", n = 0;
595
+ for (let r of e.matchAll(He)) {
596
+ let i = r.index + r[0].length;
597
+ if (i <= n) continue;
598
+ let a = 1, o = i;
599
+ for (; o < e.length && a > 0; o++) e[o] === "\\" ? o++ : e[o] === "{" ? a++ : e[o] === "}" && a--;
600
+ t += e.slice(n, i) + e.slice(i, o).replace(/(?<!\\)((?:\\\\)*)([&%#])/g, "$1\\$2"), n = o;
601
+ }
602
+ return t + e.slice(n);
603
+ };
604
+ async function We(e) {
582
605
  let [{ Marked: t }, { default: n }] = await Promise.all([import("marked"), import("katex")]), r = (e, t) => {
583
606
  try {
584
- return Be(n.renderToString(e, {
607
+ return Ve(n.renderToString(Ue(e), {
585
608
  output: "mathml",
586
609
  displayMode: t,
587
610
  throwOnError: !0
@@ -593,7 +616,7 @@ async function Ve(e) {
593
616
  gfm: !0,
594
617
  breaks: !1
595
618
  });
596
- i.use({ extensions: Le(r) });
619
+ i.use({ extensions: Re(r) });
597
620
  let a = i.lexer(e), o = a.findIndex((e) => {
598
621
  if (e.type !== "paragraph" || e.tokens?.length !== 1) return !1;
599
622
  let t = e.tokens[0];
@@ -601,34 +624,34 @@ async function Ve(e) {
601
624
  });
602
625
  if (o >= 0) {
603
626
  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 ?? "", "");
604
- return `<style>${Ne}</style>
605
- <div class="${Y} ${Ae}" data-fit style="font-size: ${Math.round(Pe(c) * Me)}px">
627
+ return `<style>${Pe}</style>
628
+ <div class="${Y} ${je}" data-fit style="font-size: ${Math.round(Fe(c) * Ne)}px">
606
629
  <div class="${X}">
607
630
  ${s}</div>
608
- <img class="${je}" src="${g}" alt="${p(r)}">
631
+ <img class="${Me}" src="${g}" alt="${p(r)}">
609
632
  </div>`;
610
633
  }
611
634
  let s = await i.parse(e);
612
- return `<style>${Ne}</style>
613
- <div class="${Y}" data-fit style="font-size: ${Pe(e)}px">
635
+ return `<style>${Pe}</style>
636
+ <div class="${Y}" data-fit style="font-size: ${Fe(e)}px">
614
637
  ${s}</div>`;
615
638
  }
616
639
  //#endregion
617
640
  //#region src/core/records.ts
618
- var He = "slideshows", Z = "storyboards", Ue = {}, We = /* @__PURE__ */ new WeakMap(), Ge = /* @__PURE__ */ new WeakMap();
619
- function Ke(e) {
620
- let t = We.get(e);
621
- return t || We.set(e, t = /* @__PURE__ */ new Map()), t;
641
+ var Ge = "slideshows", Z = "storyboards", Ke = {}, qe = /* @__PURE__ */ new WeakMap(), Je = /* @__PURE__ */ new WeakMap();
642
+ function Ye(e) {
643
+ let t = qe.get(e);
644
+ return t || qe.set(e, t = /* @__PURE__ */ new Map()), t;
622
645
  }
623
- function qe(t, n) {
624
- let r = Ge.get(t);
625
- r || Ge.set(t, r = /* @__PURE__ */ new Map());
646
+ function Xe(t, n) {
647
+ let r = Je.get(t);
648
+ r || Je.set(t, r = /* @__PURE__ */ new Map());
626
649
  let i = r.get(n);
627
650
  return i || r.set(n, i = e()), i;
628
651
  }
629
- var Je = (e, t) => `${e}/${t}.json`;
630
- async function Ye(e, t) {
631
- let n = Ke(e ?? Ue), r = n.get(t);
652
+ var Ze = (e, t) => `${e}/${t}.json`;
653
+ async function Qe(e, t) {
654
+ let n = Ye(e ?? Ke), r = n.get(t);
632
655
  if (r) return r;
633
656
  if (!e) return null;
634
657
  try {
@@ -638,14 +661,14 @@ async function Ye(e, t) {
638
661
  return null;
639
662
  }
640
663
  }
641
- async function Xe(e, t, n) {
642
- return x.test(n) ? Ye(e, Je(t, n)) : null;
664
+ async function $e(e, t, n) {
665
+ return ve.test(n) ? Qe(e, Ze(t, n)) : null;
643
666
  }
644
667
  async function Q(e, t, n, r) {
645
- let i = Je(t, n), a = e ?? Ue;
646
- return qe(a, i)(async () => {
647
- let t = r(await Ye(e, i));
648
- if (Ke(a).set(i, t), !e) return !1;
668
+ let i = Ze(t, n), a = e ?? Ke;
669
+ return Xe(a, i)(async () => {
670
+ let t = r(await Qe(e, i));
671
+ if (Ye(a).set(i, t), !e) return !1;
649
672
  try {
650
673
  return await e.write(i, JSON.stringify(t, null, 2)), !0;
651
674
  } catch (e) {
@@ -653,12 +676,12 @@ async function Q(e, t, n, r) {
653
676
  }
654
677
  });
655
678
  }
656
- var $ = (e) => `the ${e} could not be saved, so it lasts only until the app or server restarts`, Ze = 6e4;
657
- function Qe() {
679
+ var $ = (e) => `the ${e} could not be saved, so it lasts only until the app or server restarts`, et = 6e4;
680
+ function tt() {
658
681
  let e = /* @__PURE__ */ new Map();
659
682
  return { claim: (t) => {
660
683
  let n = Date.now();
661
- for (let [t, r] of e) n - r.at > Ze && e.delete(t);
684
+ for (let [t, r] of e) n - r.at > et && e.delete(t);
662
685
  let r = e.get(t);
663
686
  if (r) return { earlier: r.shown };
664
687
  let i = () => void 0, a = new Promise((e) => i = e);
@@ -672,7 +695,7 @@ function Qe() {
672
695
  }
673
696
  //#endregion
674
697
  //#region src/core/presentSlide.ts
675
- function $e({ slide: e, totalSlides: t, mode: n }) {
698
+ function nt({ slide: e, totalSlides: t, mode: n }) {
676
699
  return n === "steps" ? {
677
700
  step: e,
678
701
  total: t,
@@ -690,7 +713,7 @@ function $e({ slide: e, totalSlides: t, mode: n }) {
690
713
  nextCall: `call presentSlide for slide ${e + 1} of ${t}`
691
714
  };
692
715
  }
693
- var et = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, html: a, markdown: o, chart: s }) => JSON.stringify([
716
+ var rt = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, html: a, markdown: o, chart: s }) => JSON.stringify([
694
717
  e,
695
718
  t,
696
719
  n,
@@ -699,19 +722,19 @@ var et = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, html: a, mark
699
722
  a,
700
723
  o,
701
724
  s
702
- ]), tt = ke(() => ({
725
+ ]), it = J(() => ({
703
726
  latest: {
704
727
  presentation: null,
705
728
  steps: null
706
729
  },
707
730
  lastShown: null,
708
- repeats: Qe()
731
+ repeats: tt()
709
732
  }));
710
- function nt(e, t) {
733
+ function at(e, t) {
711
734
  let n = e.latest[t.mode], r = n?.totalSlides === t.totalSlides && (t.slide !== 1 || n.firstTitle === t.title);
712
735
  if (n && r) return n;
713
736
  let i = {
714
- id: Te(),
737
+ id: G(),
715
738
  mode: t.mode,
716
739
  totalSlides: t.totalSlides,
717
740
  firstTitle: t.slide === 1 ? t.title : "",
@@ -721,69 +744,70 @@ function nt(e, t) {
721
744
  };
722
745
  return e.latest[t.mode] = i, i;
723
746
  }
724
- function rt(e, t, n, r) {
747
+ function ot(e, t, n, r) {
725
748
  t.current = n.slide, t.shownAt = Date.now(), e.lastShown = t;
726
749
  let i = n.mode === "steps" ? "step" : "slide", { uuid: a, ...o } = r;
727
750
  return {
728
751
  ...o,
729
752
  message: `${i} ${n.slide} of ${n.totalSlides} is on the screen again, as it was`,
730
- instructions: M(n),
753
+ instructions: A(n),
731
754
  instructionsRequired: !0,
732
- sequence: $e(n)
755
+ sequence: nt(n)
733
756
  };
734
757
  }
735
- function it(e, t) {
758
+ function st(e, t) {
736
759
  if (e.mode !== "steps") return e.title ? `A presentation slide titled "${e.title}". ${e.imagePrompt}` : e.imagePrompt;
737
760
  let n = e.title ? `, "${e.title}"` : "";
738
761
  return [
739
762
  `An instructional illustration of step ${e.slide} of ${e.totalSlides}${n}. ${e.imagePrompt}`,
740
- t ? at : "",
763
+ t ? ct : "",
741
764
  "Show the action clearly, with little or no text."
742
765
  ].filter(Boolean).join(" ");
743
766
  }
744
- var at = "The reference image is the previous step: keep the same objects, hands, tools and setting, and show what this step changes.";
745
- async function ot(e, t, n) {
767
+ var ct = "The reference image is the previous step: keep the same objects, hands, tools and setting, and show what this step changes.";
768
+ async function lt(e, t, n) {
746
769
  if (n.mode !== "steps") return [];
747
- let r = W(t.slides.get(n.slide - 1)).imagePath;
748
- return r ? await De(e, [r]) : [];
770
+ let r = V(t.slides.get(n.slide - 1)).imagePath;
771
+ return r ? await K(e, [r]) : [];
749
772
  }
750
- var st = (e, t) => [
773
+ var ut = (e, t) => [
751
774
  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}`,
752
- t ? at : "",
775
+ t ? ct : "",
753
776
  e.markdown ? "Keep the subject in the middle: the picture is cropped to a tall frame." : "",
754
777
  "No text, letters or numbers in the picture."
755
778
  ].filter(Boolean).join(" ");
756
- async function ct(e, t, n) {
779
+ async function dt(e, t, n) {
757
780
  if (n.chart) return {
758
781
  chart: n.chart,
759
782
  prompt: ""
760
783
  };
761
784
  if (n.html || n.markdown) {
762
785
  let r = n.html ? { html: n.html } : {
763
- html: await Ve(n.markdown ?? ""),
786
+ html: await We(n.markdown ?? ""),
764
787
  markdown: n.markdown ?? ""
765
- }, i = y(r.html);
766
- if (i && !n.imagePrompt) return { failed: {
767
- message: O,
768
- sequence: null
769
- } };
770
- if (!i) return {
788
+ };
789
+ if (!y(r.html)) return {
771
790
  ...r,
772
791
  prompt: ""
773
792
  };
774
- 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);
775
- return c ? {
793
+ let i = n.imagePrompt || ie(r.html) || n.title, a = {
794
+ ...n,
795
+ imagePrompt: i
796
+ }, o = await lt(e, t, a), s = ut(a, o.length > 0), c = await q(e, s, o), { imageData: l, imagePath: u } = V(c);
797
+ return l ? {
776
798
  ...r,
777
- imageData: c,
778
- ...l && { imagePath: l },
779
- prompt: o
799
+ imageData: l,
800
+ ...u && { imagePath: u },
801
+ prompt: s,
802
+ imagePrompt: i
780
803
  } : {
781
804
  ...r,
782
- prompt: o,
783
- pictureFailed: s.message
805
+ prompt: s,
806
+ imagePrompt: i,
807
+ pictureFailed: c.message
784
808
  };
785
809
  }
786
- 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);
810
+ let r = await lt(e, t, n), i = st(n, r.length > 0), a = await q(e, i, r), { imageData: o, imagePath: s } = V(a);
787
811
  return o ? {
788
812
  imageData: o,
789
813
  ...s && { imagePath: s },
@@ -793,10 +817,10 @@ async function ct(e, t, n) {
793
817
  sequence: null
794
818
  } };
795
819
  }
796
- async function lt(e, t, n) {
797
- let r = await ct(e, t, n);
820
+ async function ft(e, t, n) {
821
+ let r = await dt(e, t, n);
798
822
  if ("failed" in r) return r.failed;
799
- 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) => {
823
+ 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, Ge, d, (e) => {
800
824
  let t = e ?? {
801
825
  id: d,
802
826
  title: "",
@@ -806,7 +830,7 @@ async function lt(e, t, n) {
806
830
  };
807
831
  return n.slide === 1 && (t.title = n.title), t.slides[String(n.slide)] = {
808
832
  title: n.title,
809
- imagePrompt: o && !l ? "" : n.imagePrompt,
833
+ imagePrompt: o ? r.imagePrompt ?? "" : n.imagePrompt,
810
834
  ...a && { imagePath: a },
811
835
  ...o && { html: o },
812
836
  ...s && { markdown: s },
@@ -834,19 +858,19 @@ async function lt(e, t, n) {
834
858
  u ? `its picture couldn't be drawn (${u}), so the slide is shown without it` : "",
835
859
  f ? "" : $("slideshow")
836
860
  ].filter(Boolean).join("; "),
837
- instructions: M(n),
861
+ instructions: A(n),
838
862
  instructionsRequired: !0,
839
- sequence: $e(n)
863
+ sequence: nt(n)
840
864
  };
841
865
  }
842
- async function ut(e, t) {
843
- let n = A(t);
866
+ async function pt(e, t) {
867
+ let n = k(t);
844
868
  if (typeof n == "string") return {
845
869
  message: n,
846
870
  sequence: null
847
871
  };
848
- let r = tt(e), i = nt(r, n), a = n.mode === "steps";
849
- if (a && n.slide > i.current && i.current > 0 && !q(e, i.shownAt)) {
872
+ let r = it(e), i = at(r, n), a = n.mode === "steps";
873
+ if (a && n.slide > i.current && i.current > 0 && !W(e, i.shownAt)) {
850
874
  console.info(`[sequence] holding step ${n.slide} for the user`);
851
875
  let e = i.shownAt === Infinity ? "is still being drawn" : "is still on the screen";
852
876
  return {
@@ -855,15 +879,15 @@ async function ut(e, t) {
855
879
  };
856
880
  }
857
881
  let o = a ? i.slides.get(n.slide) : void 0;
858
- if (o) return we(e.currentResult, o) ? {
882
+ if (o) return Oe(e.currentResult, o) ? {
859
883
  message: `step ${n.slide} of ${n.totalSlides} is already on the screen`,
860
884
  cancelled: !0
861
- } : rt(r, i, n, o);
862
- let s = r.repeats.claim(et(i.id, n));
885
+ } : ot(r, i, n, o);
886
+ let s = r.repeats.claim(rt(i.id, n));
863
887
  if ("earlier" in s) {
864
- if (!await s.earlier) return ut(e, t);
888
+ if (!await s.earlier) return pt(e, t);
865
889
  let a = i.slides.get(n.slide);
866
- return a && r.lastShown !== i ? rt(r, i, n, a) : {
890
+ return a && r.lastShown !== i ? ot(r, i, n, a) : {
867
891
  message: `slide ${n.slide} of ${n.totalSlides} is already on the screen`,
868
892
  cancelled: !0
869
893
  };
@@ -875,22 +899,22 @@ async function ut(e, t) {
875
899
  i.current = n.slide, i.shownAt = Infinity;
876
900
  let u = !1;
877
901
  try {
878
- let t = await lt(e, i, n);
879
- return u = Ce(t), u && (i.slides.set(n.slide, t), i.current = n.slide, i.shownAt = Date.now(), r.lastShown = i), t;
902
+ let t = await ft(e, i, n);
903
+ return u = De(t), u && (i.slides.set(n.slide, t), i.current = n.slide, i.shownAt = Date.now(), r.lastShown = i), t;
880
904
  } finally {
881
905
  c(u), !u && i.current === n.slide && (i.current = l.current, i.shownAt = l.shownAt);
882
906
  }
883
907
  }
884
908
  //#endregion
885
909
  //#region src/core/storyboard.ts
886
- var dt = ({ id: e, title: t, totalPanels: n }) => ({
910
+ var mt = ({ id: e, title: t, totalPanels: n }) => ({
887
911
  step: 0,
888
912
  total: n,
889
913
  kind: "story",
890
914
  label: `The cast of "${t}"`,
891
915
  onShown: "introduce the characters",
892
916
  nextCall: `call presentPanel for panel 1 of ${n} with storyboardId "${e}"`
893
- }), ft = ({ id: e, totalPanels: t }, n, r) => ({
917
+ }), ht = ({ id: e, totalPanels: t }, n, r) => ({
894
918
  step: n,
895
919
  total: t,
896
920
  kind: "story",
@@ -898,21 +922,21 @@ var dt = ({ id: e, title: t, totalPanels: n }) => ({
898
922
  onShown: "tell that part of the story",
899
923
  nextCall: `call presentPanel for panel ${n + 1} of ${t} with storyboardId "${e}"`,
900
924
  ...r.length > 0 && { waitsForUser: !0 }
901
- }), 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.`);
902
- async function ht(e, t) {
903
- let n = F(t);
925
+ }), gt = (e, t) => e ? `${e}. ${t}` : t, _t = (e, { name: t, description: n }) => gt(e, `Character reference sheet of ${t}: ${n}. Full body, front, side and back views, on a plain white background. No text or labels.`);
926
+ async function vt(e, t) {
927
+ let n = M(t);
904
928
  if (typeof n == "string") return {
905
929
  message: n,
906
930
  sequence: null
907
931
  };
908
- 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);
932
+ let r = await Promise.all(n.characters.map((t) => q(e, _t(n.style, t)))), i = r.map(V), a = r.find((e, t) => !i[t]?.imageData);
909
933
  if (i.every(({ imageData: e }) => !e) && a) return {
910
934
  ...a,
911
935
  message: `the character sheets couldn't be made: ${a.message}`,
912
936
  sequence: null
913
937
  };
914
938
  let o = {
915
- id: Te(),
939
+ id: G(),
916
940
  ...n,
917
941
  characters: n.characters.map((e, t) => {
918
942
  let n = i[t]?.imagePath;
@@ -945,32 +969,32 @@ async function ht(e, t) {
945
969
  l.length ? `no sheet for ${l.join("; ")}: they will be drawn from their description` : "",
946
970
  s ? "" : $("storyboard")
947
971
  ].filter(Boolean).join("; "),
948
- instructions: I(o),
972
+ instructions: N(o),
949
973
  instructionsRequired: !0,
950
- sequence: dt(o)
974
+ sequence: mt(o)
951
975
  };
952
976
  }
953
- function gt(e, t, n) {
954
- 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}`);
977
+ function yt(e, t, n) {
978
+ let r = [gt(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}`);
955
979
  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(" ");
956
980
  }
957
- async function _t(e, t, n) {
981
+ async function bt(e, t, n) {
958
982
  let r = [], i = [];
959
983
  for (let a of n.characters) {
960
- let n = t.characters.find((e) => w(e.name, a));
984
+ let n = t.characters.find((e) => T(e.name, a));
961
985
  if (!n) r.push(a);
962
986
  else if (!i.some((e) => e.character === n)) {
963
- let [t] = n.imagePath ? await De(e, [n.imagePath]) : [];
987
+ let [t] = n.imagePath ? await K(e, [n.imagePath]) : [];
964
988
  i.push({
965
989
  character: n,
966
990
  sheet: t ?? null
967
991
  });
968
992
  }
969
993
  }
970
- let a = i.map(({ sheet: e }) => e).filter((e) => !!e), o = gt(t, n, i.map(({ character: e, sheet: t }) => ({
994
+ let a = i.map(({ sheet: e }) => e).filter((e) => !!e), o = yt(t, n, i.map(({ character: e, sheet: t }) => ({
971
995
  character: e,
972
996
  hasSheet: !!t
973
- }))), s = await J(e, o, a), { imageData: c, imagePath: l } = W(s);
997
+ }))), s = await q(e, o, a), { imageData: c, imagePath: l } = V(s);
974
998
  if (!c) return {
975
999
  ...s,
976
1000
  sequence: null
@@ -1003,23 +1027,23 @@ async function _t(e, t, n) {
1003
1027
  r.length ? `not in the cast, so drawn from the prompt alone: ${r.join(", ")}` : "",
1004
1028
  d ? "" : $("storyboard")
1005
1029
  ].filter(Boolean).join("; "),
1006
- instructions: z(t, n.panel, u),
1030
+ instructions: I(t, n.panel, u),
1007
1031
  instructionsRequired: !0,
1008
- sequence: ft(t, n.panel, u)
1032
+ sequence: ht(t, n.panel, u)
1009
1033
  };
1010
1034
  }
1011
- var vt = ke(() => ({
1012
- repeats: Qe(),
1035
+ var xt = J(() => ({
1036
+ repeats: tt(),
1013
1037
  awaitingChoice: /* @__PURE__ */ new Map()
1014
1038
  }));
1015
- async function yt(e, t) {
1016
- let n = R(t);
1039
+ async function St(e, t) {
1040
+ let n = F(t);
1017
1041
  if (!n) return {
1018
- message: L,
1042
+ message: P,
1019
1043
  sequence: null
1020
1044
  };
1021
- let { storyboardId: r, panel: i } = n, { repeats: a, awaitingChoice: o } = vt(e), s = o.get(r);
1022
- if (s && i > s.panel && !q(e, s.shownAt)) return console.info(`[sequence] holding panel ${i} for the user`), {
1045
+ let { storyboardId: r, panel: i } = n, { repeats: a, awaitingChoice: o } = xt(e), s = o.get(r);
1046
+ if (s && i > s.panel && !W(e, s.shownAt)) return console.info(`[sequence] holding panel ${i} for the user`), {
1023
1047
  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.`,
1024
1048
  cancelled: !0
1025
1049
  };
@@ -1027,7 +1051,7 @@ async function yt(e, t) {
1027
1051
  if ("earlier" in c) return await c.earlier ? {
1028
1052
  message: `panel ${i} is already on the screen`,
1029
1053
  cancelled: !0
1030
- } : yt(e, t);
1054
+ } : St(e, t);
1031
1055
  let { settle: l } = c, u = {
1032
1056
  panel: i,
1033
1057
  shownAt: Infinity
@@ -1035,7 +1059,7 @@ async function yt(e, t) {
1035
1059
  o.set(r, u);
1036
1060
  let f = () => o.get(r) === u, p = !1;
1037
1061
  try {
1038
- let t = await Xe(e.files?.artifacts, Z, r);
1062
+ let t = await $e(e.files?.artifacts, Z, r);
1039
1063
  if (!t) return {
1040
1064
  message: `there is no storyboard "${r}"; call defineStoryboard first`,
1041
1065
  sequence: null
@@ -1044,8 +1068,8 @@ async function yt(e, t) {
1044
1068
  message: `storyboard "${t.id}" has ${t.totalPanels} panels`,
1045
1069
  sequence: null
1046
1070
  };
1047
- let a = await _t(e, t, n);
1048
- p = !!W(a).imageData;
1071
+ let a = await bt(e, t, n);
1072
+ p = !!V(a).imageData;
1049
1073
  let s = a.data;
1050
1074
  return p && f() && (s?.choices?.length ? o.set(r, {
1051
1075
  panel: i,
@@ -1057,21 +1081,21 @@ async function yt(e, t) {
1057
1081
  }
1058
1082
  //#endregion
1059
1083
  //#region src/core/index.ts
1060
- var bt = {
1061
- toolDefinition: P,
1084
+ var Ct = {
1085
+ toolDefinition: j,
1062
1086
  generatingMessage: "Making the slide...",
1063
1087
  isEnabled: () => !0,
1064
- execute: (e, t) => ut(e, t)
1065
- }, xt = {
1066
- toolDefinition: V,
1088
+ execute: (e, t) => pt(e, t)
1089
+ }, wt = {
1090
+ toolDefinition: R,
1067
1091
  generatingMessage: "Drawing the characters...",
1068
1092
  isEnabled: () => !0,
1069
- execute: (e, t) => ht(e, t)
1070
- }, St = {
1071
- toolDefinition: H,
1093
+ execute: (e, t) => vt(e, t)
1094
+ }, Tt = {
1095
+ toolDefinition: z,
1072
1096
  generatingMessage: "Drawing the panel...",
1073
1097
  isEnabled: () => !0,
1074
- execute: (e, t) => yt(e, t)
1098
+ execute: (e, t) => St(e, t)
1075
1099
  };
1076
1100
  //#endregion
1077
- 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 };
1101
+ export { A, t as B, L as C, k as D, F as E, s as F, oe as H, h as I, l as L, fe as M, r as N, M as O, o as P, n as R, D as S, I as T, ae as U, y as V, j as _, Z as a, ye as b, pe as c, _e as d, ge as f, S as g, z as h, Ge as i, b as j, T as k, R as l, me as m, Tt as n, $e as o, P as p, Ct as r, We as s, wt as t, he as u, Te as v, N as w, O as x, ve as y, g as z };