@gui-chat-plugin/sequence 0.6.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -154,33 +154,33 @@ var t = 1280, n = 720, r = 6e4, i = "https://cdn.jsdelivr.net/npm/@tailwindcss/b
154
154
  "<": "&lt;",
155
155
  ">": "&gt;",
156
156
  "\"": "&quot;"
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 = `
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; }", g = `
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 = {
160
+ ${h}`, _ = "{{image}}", v = /(\bsrc\s*=\s*["']?|\burl\(\s*["']?)(?:\{\{image\}\}|%7B%7Bimage%7D%7D)/gi, ee = /^data:image\/[a-z0-9.+-]+;base64,[a-z0-9+/=]+$/i, te = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", y = /(<pre\b[\s\S]*?<\/pre>|<code\b[\s\S]*?<\/code>)/gi, b = (e) => e.split(y).some((e, t) => t % 2 == 0 && new RegExp(v.source, "i").test(e)), ne = {
161
161
  "&amp;": "&",
162
162
  "&lt;": "<",
163
163
  "&gt;": ">",
164
164
  "&quot;": "\"",
165
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;
166
+ }, re = (e) => {
167
+ for (let t of e.split(y).filter((e, t) => t % 2 == 0)) for (let e of t.match(/<img\b[^>]*>/gi) ?? []) {
168
+ if (!new RegExp(v.source, "i").test(e)) continue;
169
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();
170
+ return (t?.[1] ?? t?.[2] ?? "").replace(/&(?:amp|lt|gt|quot|#39);/g, (e) => ne[e] ?? e).trim();
171
171
  }
172
172
  return "";
173
- }, ae = (e, t) => {
174
- let n = t && te.test(t) ? t : ne;
175
- return e.split(v).map((e, t) => t % 2 == 1 ? e : e.replace(_, (e, t) => t + n)).join("");
173
+ }, ie = (e, t) => {
174
+ let n = t && ee.test(t) ? t : te;
175
+ return e.split(y).map((e, t) => t % 2 == 1 ? e : e.replace(v, (e, t) => t + n)).join("");
176
176
  };
177
- function oe(e) {
177
+ function ae(e) {
178
178
  return `<!doctype html>
179
179
  <html lang="en">
180
180
  <head>
181
181
  <meta charset="utf-8">
182
182
  <meta http-equiv="Content-Security-Policy" content="${d}">
183
- <style id="slide-base">${ee}</style>
183
+ <style id="slide-base">${g}</style>
184
184
  <script>${u}<\/script>
185
185
  <script defer src="${i}" integrity="${a}" crossorigin="anonymous"><\/script>
186
186
  </head>
@@ -191,7 +191,7 @@ ${m(e)}
191
191
  }
192
192
  //#endregion
193
193
  //#region src/core/chartSlide.ts
194
- var b = [
194
+ var x = [
195
195
  "bar",
196
196
  "line",
197
197
  "pie",
@@ -200,9 +200,9 @@ var b = [
200
200
  "polarArea",
201
201
  "scatter",
202
202
  "bubble"
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 = [
203
+ ], oe = "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 = [
204
204
  "default-src 'none'",
205
- `script-src 'sha256-TfZZxJX+yWgzYLy7zqsMa85OJEaC+zNLIpKLDZVnUqA=' ${x}`,
205
+ `script-src 'sha256-TfZZxJX+yWgzYLy7zqsMa85OJEaC+zNLIpKLDZVnUqA=' ${oe}`,
206
206
  "style-src 'unsafe-inline'",
207
207
  "img-src data: blob:",
208
208
  "connect-src 'none'",
@@ -224,7 +224,7 @@ function fe(e, t) {
224
224
  <meta http-equiv="Content-Security-Policy" content="${le}">
225
225
  <style>${ue}</style>
226
226
  <script>${ce}<\/script>
227
- <script defer src="${x}" integrity="${se}" crossorigin="anonymous"><\/script>
227
+ <script defer src="${oe}" integrity="${se}" crossorigin="anonymous"><\/script>
228
228
  <script type="application/json" id="chart-config">${de(t)}<\/script>
229
229
  </head>
230
230
  <body>
@@ -236,8 +236,8 @@ ${e ? `<h1>${p(e)}</h1>` : ""}
236
236
  }
237
237
  //#endregion
238
238
  //#region src/core/definitions.ts
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) {
239
+ var pe = "presentSlide", me = "defineStoryboard", he = "presentPanel", ge = 4, _e = 12, ve = 3, S = /^[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), D = "presentSlide needs slide and totalSlides (whole numbers, slide from 1 to totalSlides), and one of imagePrompt, imageUrl, html, markdown or chart", O = `presentSlide's slide is too long: keep its html, markdown or chart under ${r} characters`, k = `presentSlide's chart must be a Chart.js configuration: an object with type (${x.join(", ")}), data ({ labels, datasets }) and optionally options`;
240
+ function ye(e) {
241
241
  let t = e;
242
242
  if (typeof t == "string") try {
243
243
  t = JSON.parse(t);
@@ -246,43 +246,44 @@ function be(e) {
246
246
  }
247
247
  if (!C(t) || !C(t.data)) return null;
248
248
  let n = t.type;
249
- return !b.some((e) => e === n) || t.options !== void 0 && !C(t.options) ? null : t;
249
+ return !x.some((e) => e === n) || t.options !== void 0 && !C(t.options) ? null : t;
250
250
  }
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;
256
- if (Math.max(a.length, o.length, c ? JSON.stringify(c).length : 0) > 6e4) return D;
257
- let l = !a && !o && !c, u = !!a && y(a);
251
+ function A(e) {
252
+ let { slide: t, totalSlides: n, title: r, imagePrompt: i } = e, a = w(e.imageUrl), o = w(e.html), s = o ? "" : w(e.markdown), c = !o && !s && e.chart !== void 0 && e.chart !== null;
253
+ if (!E(t) || !E(n) || t < 1 || n < t || !o && !s && !c && !w(i) && !a) return D;
254
+ let l = c ? ye(e.chart) : null;
255
+ if (c && !l) return k;
256
+ if (Math.max(o.length, s.length, l ? JSON.stringify(l).length : 0) > 6e4) return O;
257
+ let u = !o && !s && !l, d = !!o && b(o), f = u || d || !!s;
258
258
  return {
259
259
  slide: t,
260
260
  totalSlides: n,
261
261
  title: typeof r == "string" ? r : "",
262
- imagePrompt: l ? String(i) : u || o ? w(i) : "",
263
- ...a && { html: a },
264
- ...o && { markdown: o },
265
- ...c && { chart: c },
262
+ imagePrompt: u ? typeof i == "string" ? i : "" : f ? w(i) : "",
263
+ ...f && a && { imageUrl: a },
264
+ ...o && { html: o },
265
+ ...s && { markdown: s },
266
+ ...l && { chart: l },
266
267
  mode: e.mode === "steps" ? "steps" : "presentation"
267
268
  };
268
269
  }
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 }) => {
270
+ 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 }) => {
270
271
  let i = n ? ` ("${n}")` : "";
271
272
  if (r === "steps") {
272
273
  let n = `Step ${e} of ${t}${i}`;
273
274
  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.`;
274
275
  }
275
276
  let a = `Slide ${e} of ${t}${i}`;
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 = [
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").`,
277
+ 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.`;
278
+ }, be = [
279
+ `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 picture on the slide (a photo, a scene, an object beside the text), give imagePrompt (a generated picture) or imageUrl (a picture from the web) too and put <img src="${_}" alt="..." class="..."> where it goes, sized by its classes (for example class="w-1/2 h-full object-cover rounded-2xl").`,
279
280
  "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).",
280
281
  "CSS animations, transitions and scripts don't play: animate only with data-animation. A <style> for layout is allowed (and Google Fonts by @import)."
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 = {
282
+ ].join(" "), xe = `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 picture on the slide, give imagePrompt (a generated picture) or imageUrl (a picture from the web) too and put ![what it shows](${_}) 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.`, Se = `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 ${x.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 picture on it: imagePrompt for the picture, and {{image}} where it goes. When the slide is about a real, particular thing (a person, a building, a product, an artwork) and you have the address of a picture of it (an image file, from a search or the user), give that as imageUrl instead of imagePrompt: it is shown as it is. 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 = {
282
283
  type: "function",
283
- name: S,
284
- prompt: Te,
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.",
284
+ name: pe,
285
+ prompt: N,
286
+ description: "Show one slide of a slideshow, full screen: a picture generated from imagePrompt or from the web (imageUrl), a chart (chart), a slide written in Markdown with TeX math (markdown), or a slide written in HTML (html). Give one of them; an HTML or Markdown slide can also hold one picture (imagePrompt or imageUrl, 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.",
286
287
  parameters: {
287
288
  type: "object",
288
289
  properties: {
@@ -302,17 +303,21 @@ var xe = "teach its subject as a presenter speaking to the audience, and cover e
302
303
  type: "string",
303
304
  description: "For a picture slide: the picture, a clear illustration of its point, with the title as its only large text. Be concrete. Never a chart, graph, table, dashboard, infographic, key figures or anything with numbers: those are chart, Markdown or HTML slides. For a step, show the action: hands, tools and the object. With html or markdown, it is the one picture placed where the slide has {{image}}; leave it out for a chart, and for an HTML or Markdown slide without {{image}}."
304
305
  },
306
+ imageUrl: {
307
+ type: "string",
308
+ description: "A picture from the web, shown instead of a generated one: the https address of an image file (PNG, JPEG, GIF or WebP) of a real, particular thing, from a search or the user. Never an address you made up, or a web page's. With imagePrompt too, the picture is drawn from imagePrompt if the address can't be fetched. With html or markdown, it is the one picture placed where the slide has {{image}}."
309
+ },
305
310
  html: {
306
311
  type: "string",
307
- description: Se
312
+ description: be
308
313
  },
309
314
  markdown: {
310
315
  type: "string",
311
- description: Ce
316
+ description: xe
312
317
  },
313
318
  chart: {
314
319
  type: "string",
315
- description: we
320
+ description: Se
316
321
  },
317
322
  mode: {
318
323
  type: "string",
@@ -327,7 +332,7 @@ var xe = "teach its subject as a presenter speaking to the audience, and cover e
327
332
  ]
328
333
  }
329
334
  };
330
- function M(e) {
335
+ function F(e) {
331
336
  let { totalPanels: t } = e;
332
337
  if (!E(t) || t < 1 || t > 12) return "totalPanels must be a whole number from 1 to 12";
333
338
  let n = [];
@@ -348,8 +353,8 @@ function M(e) {
348
353
  interactive: e.interactive === !0
349
354
  };
350
355
  }
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) {
356
+ 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";
357
+ function R(e) {
353
358
  let { panel: t } = e, n = w(e.storyboardId), r = w(e.imagePrompt);
354
359
  if (!n || !r || !E(t) || t < 1) return null;
355
360
  let i = (e) => (Array.isArray(e) ? e : []).map(w).filter(Boolean);
@@ -362,14 +367,14 @@ function F(e) {
362
367
  choices: i(e.choices).slice(0, 3)
363
368
  };
364
369
  }
365
- function I(e, t, n) {
370
+ function z(e, t, n) {
366
371
  let { id: r, totalPanels: i } = e;
367
372
  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.`;
368
373
  }
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 = {
374
+ 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.", Ce = {
370
375
  type: "function",
371
- name: pe,
372
- prompt: L,
376
+ name: me,
377
+ prompt: B,
373
378
  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.",
374
379
  parameters: {
375
380
  type: "object",
@@ -416,9 +421,9 @@ var L = "When the user asks for a story, a picture book, a comic or a storyboard
416
421
  "characters"
417
422
  ]
418
423
  }
419
- }, z = {
424
+ }, we = {
420
425
  type: "function",
421
- name: me,
426
+ name: he,
422
427
  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.",
423
428
  parameters: {
424
429
  type: "object",
@@ -457,60 +462,60 @@ var L = "When the user asks for a story, a picture book, a comic or a storyboard
457
462
  "imagePrompt"
458
463
  ]
459
464
  }
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 : {};
465
+ }, V = (e) => typeof e == "object" && !!e && !Array.isArray(e), Te = (e) => V(e) && typeof e.message == "string";
466
+ function H(e) {
467
+ let t = V(e?.data) ? e.data : {};
463
468
  return {
464
469
  ...typeof t.imageData == "string" && { imageData: t.imageData },
465
470
  ...typeof t.imagePath == "string" && { imagePath: t.imagePath }
466
471
  };
467
472
  }
468
- function H(e) {
469
- let t = B(e?.data) ? e.data : {};
473
+ function U(e) {
474
+ let t = V(e?.data) ? e.data : {};
470
475
  return typeof t.html == "string" ? t.html : "";
471
476
  }
472
- function U(e) {
473
- let t = B(e?.data) ? e.data : {};
474
- return B(t.chart) ? JSON.stringify(t.chart) : "";
477
+ function W(e) {
478
+ let t = V(e?.data) ? e.data : {};
479
+ return V(t.chart) ? JSON.stringify(t.chart) : "";
475
480
  }
476
- var De = (e) => !!V(e).imageData || !!H(e) || !!U(e);
477
- function Oe(e, t) {
478
- let n = V(e), r = V(t);
481
+ var Ee = (e) => !!H(e).imageData || !!U(e) || !!W(e);
482
+ function De(e, t) {
483
+ let n = H(e), r = H(t);
479
484
  if (n.imagePath && r.imagePath) return n.imagePath === r.imagePath;
480
485
  if (n.imageData) return n.imageData === r.imageData;
481
- let i = H(e);
482
- if (i) return i === H(t);
483
- let a = U(e);
484
- return !!a && a === U(t);
486
+ let i = U(e);
487
+ if (i) return i === U(t);
488
+ let a = W(e);
489
+ return !!a && a === W(t);
485
490
  }
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) {
491
+ var Oe = (e, t) => e.userSpokeAt === void 0 || e.userSpokeAt > t, ke = () => crypto.randomUUID().replace(/-/g, "").slice(0, 12), Ae = "artifacts/";
492
+ async function je(e, t) {
488
493
  let n = e.files?.artifacts;
489
494
  if (!e.app?.editImages || !n) return [];
490
495
  let r = [];
491
- for (let e of t) if (e.startsWith(ke)) try {
496
+ for (let e of t) if (e.startsWith(Ae)) try {
492
497
  await n.exists(e.slice(10)) && r.push(e);
493
498
  } catch {}
494
499
  return r;
495
500
  }
496
- async function q(e, t, n = []) {
501
+ async function G(e, t, n = []) {
497
502
  let r = e.app, i = r?.editImages, a = r?.generateImage;
498
503
  try {
499
504
  let e;
500
505
  if (n.length && i) e = await i(t, [...n]);
501
506
  else if (a) e = await a(t);
502
507
  else return { message: "image generation isn't available" };
503
- return Ee(e) ? e : { message: "image generation returned an unrecognized result" };
508
+ return Te(e) ? e : { message: "image generation returned an unrecognized result" };
504
509
  } catch (e) {
505
510
  return { message: `image generation failed: ${e instanceof Error ? e.message : String(e)}` };
506
511
  }
507
512
  }
508
- var Ae = 50;
509
- function J(e) {
513
+ var Me = 50;
514
+ function Ne(e) {
510
515
  let t = /* @__PURE__ */ new Map();
511
516
  return (n) => {
512
517
  let r = n.conversationId ?? "", i = t.get(r);
513
- if (i === void 0 ? i = e() : t.delete(r), t.set(r, i), t.size > Ae) {
518
+ if (i === void 0 ? i = e() : t.delete(r), t.set(r, i), t.size > Me) {
514
519
  let e = t.keys().next().value;
515
520
  e !== void 0 && t.delete(e);
516
521
  }
@@ -519,45 +524,45 @@ function J(e) {
519
524
  }
520
525
  //#endregion
521
526
  //#region src/core/markdownSlide.ts
522
- var Y = "slide-md", je = "slide-md-split", X = "slide-md-text", Me = "slide-md-picture", Ne = .8, Pe = `
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; }
524
- .${Y} > * { margin: 0; }
525
- .${Y} h1 { font-size: 1.9em; font-weight: 800; color: #1e3a8a; line-height: 1.15; }
526
- .${Y} h2 { font-size: 1.5em; font-weight: 700; color: #1e40af; line-height: 1.2; }
527
- .${Y} h3 { font-size: 1.2em; font-weight: 700; color: #334155; }
528
- .${Y} ul, .${Y} ol { padding-left: 1.3em; display: flex; flex-direction: column; gap: 0.3em; }
529
- .${Y} ul { list-style: disc; }
530
- .${Y} ol { list-style: decimal; }
531
- .${Y} li > ul, .${Y} li > ol { margin-top: 0.3em; font-size: 0.9em; }
532
- .${Y} li::marker { color: #2563eb; }
533
- .${Y} strong { font-weight: 700; color: #1e3a8a; }
534
- .${Y} em { font-style: italic; }
535
- .${Y} a { color: #2563eb; text-decoration: underline; }
536
- .${Y} code { font-family: ui-monospace, monospace; font-size: 0.85em; background: #f1f5f9; border-radius: 0.2em; padding: 0.05em 0.3em; }
537
- .${Y} pre { background: #0f172a; color: #e2e8f0; border-radius: 0.4em; padding: 0.6em 0.8em; font-size: 0.75em; overflow: hidden; }
538
- .${Y} pre code { background: none; padding: 0; color: inherit; }
539
- .${Y} blockquote { border-left: 0.2em solid #93c5fd; padding-left: 0.8em; color: #475569; font-style: italic; }
540
- .${Y} table { border-collapse: collapse; font-size: 0.85em; align-self: flex-start; }
541
- .${Y} th, .${Y} td { border: 1px solid #cbd5e1; padding: 0.25em 0.7em; text-align: left; }
542
- .${Y} th { background: #eff6ff; font-weight: 700; }
543
- .${Y} hr { border: 0; border-top: 2px solid #e2e8f0; }
544
- .${Y} img { max-width: 100%; max-height: 60%; }
545
- .${Y}.${je} { flex-direction: row; align-items: center; gap: 48px; }
546
- .${Y} .${X} { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 0.5em; }
547
- .${Y} .${X} > * { margin: 0; }
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); }
549
- .${Y} .math-display { display: block; text-align: center; font-size: 1.15em; }
550
- .${Y} math { font-family: "Latin Modern Math", "STIX Two Math", "Cambria Math", math; }
551
- .${Y} mtd { padding: 0.1em 0.4em; }
552
- .${Y} mtd:first-child { padding-left: 0; }
553
- .${Y} mtd:last-child { padding-right: 0; }
554
- .${Y} .math-error { color: #b91c1c; font-family: ui-monospace, monospace; }`;
555
- function Fe(e) {
527
+ var K = "slide-md", Pe = "slide-md-split", q = "slide-md-text", Fe = "slide-md-picture", Ie = .8, Le = `
528
+ .${K} { 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; }
529
+ .${K} > * { margin: 0; }
530
+ .${K} h1 { font-size: 1.9em; font-weight: 800; color: #1e3a8a; line-height: 1.15; }
531
+ .${K} h2 { font-size: 1.5em; font-weight: 700; color: #1e40af; line-height: 1.2; }
532
+ .${K} h3 { font-size: 1.2em; font-weight: 700; color: #334155; }
533
+ .${K} ul, .${K} ol { padding-left: 1.3em; display: flex; flex-direction: column; gap: 0.3em; }
534
+ .${K} ul { list-style: disc; }
535
+ .${K} ol { list-style: decimal; }
536
+ .${K} li > ul, .${K} li > ol { margin-top: 0.3em; font-size: 0.9em; }
537
+ .${K} li::marker { color: #2563eb; }
538
+ .${K} strong { font-weight: 700; color: #1e3a8a; }
539
+ .${K} em { font-style: italic; }
540
+ .${K} a { color: #2563eb; text-decoration: underline; }
541
+ .${K} code { font-family: ui-monospace, monospace; font-size: 0.85em; background: #f1f5f9; border-radius: 0.2em; padding: 0.05em 0.3em; }
542
+ .${K} pre { background: #0f172a; color: #e2e8f0; border-radius: 0.4em; padding: 0.6em 0.8em; font-size: 0.75em; overflow: hidden; }
543
+ .${K} pre code { background: none; padding: 0; color: inherit; }
544
+ .${K} blockquote { border-left: 0.2em solid #93c5fd; padding-left: 0.8em; color: #475569; font-style: italic; }
545
+ .${K} table { border-collapse: collapse; font-size: 0.85em; align-self: flex-start; }
546
+ .${K} th, .${K} td { border: 1px solid #cbd5e1; padding: 0.25em 0.7em; text-align: left; }
547
+ .${K} th { background: #eff6ff; font-weight: 700; }
548
+ .${K} hr { border: 0; border-top: 2px solid #e2e8f0; }
549
+ .${K} img { max-width: 100%; max-height: 60%; }
550
+ .${K}.${Pe} { flex-direction: row; align-items: center; gap: 48px; }
551
+ .${K} .${q} { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 0.5em; }
552
+ .${K} .${q} > * { margin: 0; }
553
+ .${K} .${Fe} { 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); }
554
+ .${K} .math-display { display: block; text-align: center; font-size: 1.15em; }
555
+ .${K} math { font-family: "Latin Modern Math", "STIX Two Math", "Cambria Math", math; }
556
+ .${K} mtd { padding: 0.1em 0.4em; }
557
+ .${K} mtd:first-child { padding-left: 0; }
558
+ .${K} mtd:last-child { padding-right: 0; }
559
+ .${K} .math-error { color: #b91c1c; font-family: ui-monospace, monospace; }`;
560
+ function J(e) {
556
561
  let t = e.split("\n").filter((e) => e.trim()).length, n = e.length;
557
562
  return t <= 5 && n <= 250 ? 40 : t <= 8 && n <= 450 ? 34 : t <= 12 && n <= 700 ? 28 : 24;
558
563
  }
559
- var Ie = /^[ \t]*(?:\$\$([\s\S]+?)\$\$|\\\[([\s\S]+?)\\\])[ \t]*(?:\n|$)/, Le = /^(?:\$\$(.+?)\$\$|\$(?!\s)((?:\\.|[^\\$\n])+?)(?<!\s)\$(?!\d)|\\\((.+?)\\\))/;
560
- function Re(e) {
564
+ var Re = /^[ \t]*(?:\$\$([\s\S]+?)\$\$|\\\[([\s\S]+?)\\\])[ \t]*(?:\n|$)/, ze = /^(?:\$\$(.+?)\$\$|\$(?!\s)((?:\\.|[^\\$\n])+?)(?<!\s)\$(?!\d)|\\\((.+?)\\\))/;
565
+ function Be(e) {
561
566
  return [{
562
567
  name: "blockMath",
563
568
  level: "block",
@@ -566,7 +571,7 @@ function Re(e) {
566
571
  return t ? t.index + (t[1] ?? "").length : void 0;
567
572
  },
568
573
  tokenizer(e) {
569
- let t = Ie.exec(e);
574
+ let t = Re.exec(e);
570
575
  if (t) return {
571
576
  type: "blockMath",
572
577
  raw: t[0],
@@ -579,7 +584,7 @@ function Re(e) {
579
584
  level: "inline",
580
585
  start: (e) => e.match(/(?<!\\)\$|\\\(/)?.index,
581
586
  tokenizer(e) {
582
- let t = Le.exec(e);
587
+ let t = ze.exec(e);
583
588
  if (t) return {
584
589
  type: "inlineMath",
585
590
  raw: t[0],
@@ -590,9 +595,9 @@ function Re(e) {
590
595
  renderer: (t) => e(String(t.text), t.display === !0)
591
596
  }];
592
597
  }
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) => {
598
+ var Ve = /(<\/mi>|<\/mn>|<\/mrow>|<mo[^>]*>[)\]]<\/mo>)?(<mi(?: mathvariant="normal")?>[A-Za-z]{2,}<\/mi>)<mo>\u2061<\/mo>/g, He = "<mspace width=\"0.1667em\"></mspace>", Ue = (e) => e.replace(Ve, (e, t, n) => `${t ? t + He : ""}${n}<mo lspace="0" rspace="0.1667em">\u2061</mo>`), We = /\\(?:text(?:bf|it|rm|sf|tt|normal)?|mbox)\s*\{/g, Ge = (e) => {
594
599
  let t = "", n = 0;
595
- for (let r of e.matchAll(He)) {
600
+ for (let r of e.matchAll(We)) {
596
601
  let i = r.index + r[0].length;
597
602
  if (i <= n) continue;
598
603
  let a = 1, o = i;
@@ -601,10 +606,10 @@ var ze = /(<\/mi>|<\/mn>|<\/mrow>|<mo[^>]*>[)\]]<\/mo>)?(<mi(?: mathvariant="nor
601
606
  }
602
607
  return t + e.slice(n);
603
608
  };
604
- async function We(e) {
609
+ async function Ke(e) {
605
610
  let [{ Marked: t }, { default: n }] = await Promise.all([import("marked"), import("katex")]), r = (e, t) => {
606
611
  try {
607
- return Ve(n.renderToString(Ue(e), {
612
+ return Ue(n.renderToString(Ge(e), {
608
613
  output: "mathml",
609
614
  displayMode: t,
610
615
  throwOnError: !0
@@ -616,42 +621,42 @@ async function We(e) {
616
621
  gfm: !0,
617
622
  breaks: !1
618
623
  });
619
- i.use({ extensions: Re(r) });
624
+ i.use({ extensions: Be(r) });
620
625
  let a = i.lexer(e), o = a.findIndex((e) => {
621
626
  if (e.type !== "paragraph" || e.tokens?.length !== 1) return !1;
622
627
  let t = e.tokens[0];
623
- return t?.type === "image" ? t.href.trim() === g : t?.type === "text" && t.text.trim() === "{{image}}";
628
+ return t?.type === "image" ? t.href.trim() === _ : t?.type === "text" && t.text.trim() === "{{image}}";
624
629
  });
625
630
  if (o >= 0) {
626
631
  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 ?? "", "");
627
- return `<style>${Pe}</style>
628
- <div class="${Y} ${je}" data-fit style="font-size: ${Math.round(Fe(c) * Ne)}px">
629
- <div class="${X}">
632
+ return `<style>${Le}</style>
633
+ <div class="${K} ${Pe}" data-fit style="font-size: ${Math.round(J(c) * Ie)}px">
634
+ <div class="${q}">
630
635
  ${s}</div>
631
- <img class="${Me}" src="${g}" alt="${p(r)}">
636
+ <img class="${Fe}" src="${_}" alt="${p(r)}">
632
637
  </div>`;
633
638
  }
634
639
  let s = await i.parse(e);
635
- return `<style>${Pe}</style>
636
- <div class="${Y}" data-fit style="font-size: ${Fe(e)}px">
640
+ return `<style>${Le}</style>
641
+ <div class="${K}" data-fit style="font-size: ${J(e)}px">
637
642
  ${s}</div>`;
638
643
  }
639
644
  //#endregion
640
645
  //#region src/core/records.ts
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;
646
+ var qe = "slideshows", Y = "storyboards", Je = {}, Ye = /* @__PURE__ */ new WeakMap(), Xe = /* @__PURE__ */ new WeakMap();
647
+ function Ze(e) {
648
+ let t = Ye.get(e);
649
+ return t || Ye.set(e, t = /* @__PURE__ */ new Map()), t;
645
650
  }
646
- function Xe(t, n) {
647
- let r = Je.get(t);
648
- r || Je.set(t, r = /* @__PURE__ */ new Map());
651
+ function Qe(t, n) {
652
+ let r = Xe.get(t);
653
+ r || Xe.set(t, r = /* @__PURE__ */ new Map());
649
654
  let i = r.get(n);
650
655
  return i || r.set(n, i = e()), i;
651
656
  }
652
- var Ze = (e, t) => `${e}/${t}.json`;
653
- async function Qe(e, t) {
654
- let n = Ye(e ?? Ke), r = n.get(t);
657
+ var $e = (e, t) => `${e}/${t}.json`;
658
+ async function et(e, t) {
659
+ let n = Ze(e ?? Je), r = n.get(t);
655
660
  if (r) return r;
656
661
  if (!e) return null;
657
662
  try {
@@ -661,14 +666,14 @@ async function Qe(e, t) {
661
666
  return null;
662
667
  }
663
668
  }
664
- async function $e(e, t, n) {
665
- return ve.test(n) ? Qe(e, Ze(t, n)) : null;
669
+ async function tt(e, t, n) {
670
+ return S.test(n) ? et(e, $e(t, n)) : null;
666
671
  }
667
- async function Q(e, t, n, r) {
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;
672
+ async function X(e, t, n, r) {
673
+ let i = $e(t, n), a = e ?? Je;
674
+ return Qe(a, i)(async () => {
675
+ let t = r(await et(e, i));
676
+ if (Ze(a).set(i, t), !e) return !1;
672
677
  try {
673
678
  return await e.write(i, JSON.stringify(t, null, 2)), !0;
674
679
  } catch (e) {
@@ -676,12 +681,12 @@ async function Q(e, t, n, r) {
676
681
  }
677
682
  });
678
683
  }
679
- var $ = (e) => `the ${e} could not be saved, so it lasts only until the app or server restarts`, et = 6e4;
680
- function tt() {
684
+ var Z = (e) => `the ${e} could not be saved, so it lasts only until the app or server restarts`, nt = 6e4;
685
+ function rt() {
681
686
  let e = /* @__PURE__ */ new Map();
682
687
  return { claim: (t) => {
683
688
  let n = Date.now();
684
- for (let [t, r] of e) n - r.at > et && e.delete(t);
689
+ for (let [t, r] of e) n - r.at > nt && e.delete(t);
685
690
  let r = e.get(t);
686
691
  if (r) return { earlier: r.shown };
687
692
  let i = () => void 0, a = new Promise((e) => i = e);
@@ -694,8 +699,136 @@ function tt() {
694
699
  } };
695
700
  }
696
701
  //#endregion
702
+ //#region src/core/webImage.ts
703
+ var it = 1e4, at = 5242880, ot = 3, st = "images", ct = "artifacts/";
704
+ function lt(e) {
705
+ if (e.protocol !== "https:") return "only https URLs are fetched";
706
+ if (e.username || e.password) return "a URL with a password isn't fetched";
707
+ let t = e.hostname.toLowerCase().replace(/\.$/, "");
708
+ return t.startsWith("[") || /^\d+\.\d+\.\d+\.\d+$/.test(t) ? "a URL with an IP address isn't fetched" : !t.includes(".") || /\.(localhost|local|internal|lan|home\.arpa)$/.test(t) ? "a URL on a local network isn't fetched" : null;
709
+ }
710
+ var Q = (e, t, n = 0) => t.every((t, r) => e[n + r] === t);
711
+ function ut(e) {
712
+ return Q(e, [
713
+ 137,
714
+ 80,
715
+ 78,
716
+ 71,
717
+ 13,
718
+ 10,
719
+ 26,
720
+ 10
721
+ ]) ? {
722
+ mime: "image/png",
723
+ extension: "png"
724
+ } : Q(e, [
725
+ 255,
726
+ 216,
727
+ 255
728
+ ]) ? {
729
+ mime: "image/jpeg",
730
+ extension: "jpg"
731
+ } : Q(e, [
732
+ 71,
733
+ 73,
734
+ 70,
735
+ 56
736
+ ]) ? {
737
+ mime: "image/gif",
738
+ extension: "gif"
739
+ } : Q(e, [
740
+ 82,
741
+ 73,
742
+ 70,
743
+ 70
744
+ ]) && Q(e, [
745
+ 87,
746
+ 69,
747
+ 66,
748
+ 80
749
+ ], 8) ? {
750
+ mime: "image/webp",
751
+ extension: "webp"
752
+ } : null;
753
+ }
754
+ function dt(e) {
755
+ let t = "", n = 32768;
756
+ for (let r = 0; r < e.length; r += n) t += String.fromCharCode(...e.subarray(r, r + n));
757
+ return btoa(t);
758
+ }
759
+ var $ = (e) => e.body?.cancel().catch(() => void 0) ?? Promise.resolve();
760
+ async function ft(e) {
761
+ if (Number(e.headers.get("content-length")) > 5242880) return await $(e), null;
762
+ if (!e.body) {
763
+ let t = new Uint8Array(await e.arrayBuffer());
764
+ return t.length > 5242880 ? null : t;
765
+ }
766
+ let t = e.body.getReader(), n = [], r = 0;
767
+ for (;;) {
768
+ let { done: e, value: i } = await t.read();
769
+ if (e) break;
770
+ if (r += i.length, r > 5242880) return await t.cancel(), null;
771
+ n.push(i);
772
+ }
773
+ let i = new Uint8Array(r), a = 0;
774
+ for (let e of n) i.set(e, a), a += e.length;
775
+ return i;
776
+ }
777
+ async function pt(e, t) {
778
+ let n;
779
+ try {
780
+ n = new URL(e);
781
+ } catch {
782
+ return "it isn't a URL";
783
+ }
784
+ for (let e = 0;; e++) {
785
+ let r = lt(n);
786
+ if (r) return r;
787
+ let i = await fetch(n, {
788
+ redirect: "manual",
789
+ signal: t,
790
+ credentials: "omit",
791
+ referrerPolicy: "no-referrer"
792
+ });
793
+ if (i.type === "opaqueredirect") return fetch(n, {
794
+ signal: t,
795
+ credentials: "omit",
796
+ referrerPolicy: "no-referrer"
797
+ });
798
+ let a = i.headers.get("location");
799
+ if (i.status < 300 || i.status >= 400 || !a) return i;
800
+ if (await $(i), e >= ot) return "it redirects too many times";
801
+ n = new URL(a, n);
802
+ }
803
+ }
804
+ async function mt(e, t) {
805
+ let n;
806
+ try {
807
+ let t = await pt(e, AbortSignal.timeout(it));
808
+ if (typeof t == "string") return { error: t };
809
+ if (!t.ok) return await $(t), { error: `the site answered ${t.status}` };
810
+ n = await ft(t);
811
+ } catch (e) {
812
+ return { error: `it couldn't be fetched (${e instanceof Error ? e.message : String(e)})` };
813
+ }
814
+ if (!n) return { error: `it is larger than ${at / 1024 / 1024} MB` };
815
+ let r = ut(n);
816
+ if (!r) return { error: "it isn't a PNG, JPEG, GIF or WebP picture" };
817
+ let i = `data:${r.mime};base64,${dt(n)}`;
818
+ if (!t) return { imageData: i };
819
+ let a = /* @__PURE__ */ new Date(), o = String(a.getUTCMonth() + 1).padStart(2, "0"), s = crypto.randomUUID().replace(/-/g, "").slice(0, 16), c = `${st}/${a.getUTCFullYear()}/${o}/${s}.${r.extension}`;
820
+ try {
821
+ return await t.write(c, n), {
822
+ imageData: i,
823
+ imagePath: `${ct}${c}`
824
+ };
825
+ } catch {
826
+ return { imageData: i };
827
+ }
828
+ }
829
+ //#endregion
697
830
  //#region src/core/presentSlide.ts
698
- function nt({ slide: e, totalSlides: t, mode: n }) {
831
+ function ht({ slide: e, totalSlides: t, mode: n }) {
699
832
  return n === "steps" ? {
700
833
  step: e,
701
834
  total: t,
@@ -713,7 +846,7 @@ function nt({ slide: e, totalSlides: t, mode: n }) {
713
846
  nextCall: `call presentSlide for slide ${e + 1} of ${t}`
714
847
  };
715
848
  }
716
- var rt = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, html: a, markdown: o, chart: s }) => JSON.stringify([
849
+ var gt = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, imageUrl: a, html: o, markdown: s, chart: c }) => JSON.stringify([
717
850
  e,
718
851
  t,
719
852
  n,
@@ -721,20 +854,21 @@ var rt = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i, html: a, mark
721
854
  i,
722
855
  a,
723
856
  o,
724
- s
725
- ]), it = J(() => ({
857
+ s,
858
+ c
859
+ ]), _t = Ne(() => ({
726
860
  latest: {
727
861
  presentation: null,
728
862
  steps: null
729
863
  },
730
864
  lastShown: null,
731
- repeats: tt()
865
+ repeats: rt()
732
866
  }));
733
- function at(e, t) {
867
+ function vt(e, t) {
734
868
  let n = e.latest[t.mode], r = n?.totalSlides === t.totalSlides && (t.slide !== 1 || n.firstTitle === t.title);
735
869
  if (n && r) return n;
736
870
  let i = {
737
- id: G(),
871
+ id: ke(),
738
872
  mode: t.mode,
739
873
  totalSlides: t.totalSlides,
740
874
  firstTitle: t.slide === 1 ? t.title : "",
@@ -744,85 +878,118 @@ function at(e, t) {
744
878
  };
745
879
  return e.latest[t.mode] = i, i;
746
880
  }
747
- function ot(e, t, n, r) {
881
+ function yt(e, t, n, r) {
748
882
  t.current = n.slide, t.shownAt = Date.now(), e.lastShown = t;
749
883
  let i = n.mode === "steps" ? "step" : "slide", { uuid: a, ...o } = r;
750
884
  return {
751
885
  ...o,
752
886
  message: `${i} ${n.slide} of ${n.totalSlides} is on the screen again, as it was`,
753
- instructions: A(n),
887
+ instructions: M(n),
754
888
  instructionsRequired: !0,
755
- sequence: nt(n)
889
+ sequence: ht(n)
756
890
  };
757
891
  }
758
- function st(e, t) {
892
+ function bt(e, t) {
759
893
  if (e.mode !== "steps") return e.title ? `A presentation slide titled "${e.title}". ${e.imagePrompt}` : e.imagePrompt;
760
894
  let n = e.title ? `, "${e.title}"` : "";
761
895
  return [
762
896
  `An instructional illustration of step ${e.slide} of ${e.totalSlides}${n}. ${e.imagePrompt}`,
763
- t ? ct : "",
897
+ t ? xt : "",
764
898
  "Show the action clearly, with little or no text."
765
899
  ].filter(Boolean).join(" ");
766
900
  }
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) {
901
+ var xt = "The reference image is the previous step: keep the same objects, hands, tools and setting, and show what this step changes.";
902
+ async function St(e, t, n) {
769
903
  if (n.mode !== "steps") return [];
770
- let r = V(t.slides.get(n.slide - 1)).imagePath;
771
- return r ? await K(e, [r]) : [];
904
+ let r = H(t.slides.get(n.slide - 1)).imagePath;
905
+ return r ? await je(e, [r]) : [];
772
906
  }
773
- var ut = (e, t) => [
907
+ var Ct = (e, t) => [
774
908
  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}`,
775
- t ? ct : "",
909
+ t ? xt : "",
776
910
  e.markdown ? "Keep the subject in the middle: the picture is cropped to a tall frame." : "",
777
911
  "No text, letters or numbers in the picture."
778
912
  ].filter(Boolean).join(" ");
779
- async function dt(e, t, n) {
913
+ async function wt(e, t) {
914
+ let n = await mt(t, e.files?.artifacts);
915
+ return "error" in n && console.info(`[sequence] picture at ${t} not shown: ${n.error}`), n;
916
+ }
917
+ async function Tt(e, t, n) {
780
918
  if (n.chart) return {
781
919
  chart: n.chart,
782
920
  prompt: ""
783
921
  };
784
922
  if (n.html || n.markdown) {
785
923
  let r = n.html ? { html: n.html } : {
786
- html: await We(n.markdown ?? ""),
924
+ html: await Ke(n.markdown ?? ""),
787
925
  markdown: n.markdown ?? ""
788
926
  };
789
- if (!y(r.html)) return {
927
+ if (!b(r.html)) return {
790
928
  ...r,
791
929
  prompt: ""
792
930
  };
793
- let i = n.imagePrompt || ie(r.html) || n.title, a = {
931
+ let i = n.imagePrompt || re(r.html) || n.title, a;
932
+ if (n.imageUrl) {
933
+ let t = await wt(e, n.imageUrl);
934
+ if (!("error" in t)) return {
935
+ ...r,
936
+ ...t,
937
+ imageUrl: n.imageUrl,
938
+ prompt: i,
939
+ imagePrompt: i
940
+ };
941
+ a = t.error;
942
+ }
943
+ let o = {
794
944
  ...n,
795
945
  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 ? {
946
+ }, s = await St(e, t, o), c = Ct(o, s.length > 0), l = await G(e, c, s), { imageData: u, imagePath: d } = H(l), f = a !== void 0 && { urlFailed: a };
947
+ return u ? {
798
948
  ...r,
799
- imageData: l,
800
- ...u && { imagePath: u },
801
- prompt: s,
802
- imagePrompt: i
949
+ imageData: u,
950
+ ...d && { imagePath: d },
951
+ prompt: c,
952
+ imagePrompt: i,
953
+ ...f
803
954
  } : {
804
955
  ...r,
805
- prompt: s,
956
+ prompt: c,
806
957
  imagePrompt: i,
807
- pictureFailed: c.message
958
+ pictureFailed: l.message,
959
+ ...f
808
960
  };
809
961
  }
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);
811
- return o ? {
812
- imageData: o,
813
- ...s && { imagePath: s },
814
- prompt: i
962
+ let r;
963
+ if (n.imageUrl) {
964
+ let t = await wt(e, n.imageUrl);
965
+ if (!("error" in t)) return {
966
+ ...t,
967
+ imageUrl: n.imageUrl,
968
+ prompt: n.imagePrompt || n.title
969
+ };
970
+ if (!n.imagePrompt) return { failed: {
971
+ message: `the picture at ${n.imageUrl} couldn't be shown: ${t.error}. Call presentSlide again with another imageUrl (an image file's address), or with imagePrompt to draw it.`,
972
+ sequence: null
973
+ } };
974
+ r = t.error;
975
+ }
976
+ let i = await St(e, t, n), a = bt(n, i.length > 0), o = await G(e, a, i), { imageData: s, imagePath: c } = H(o);
977
+ return s ? {
978
+ imageData: s,
979
+ ...c && { imagePath: c },
980
+ prompt: a,
981
+ ...r !== void 0 && { urlFailed: r }
815
982
  } : { failed: {
816
- ...a,
983
+ ...o,
817
984
  sequence: null
818
985
  } };
819
986
  }
820
- async function ft(e, t, n) {
821
- let r = await dt(e, t, n);
987
+ async function Et(e, t, n) {
988
+ let r = await Tt(e, t, n);
822
989
  if ("failed" in r) return r.failed;
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) => {
990
+ let { imageData: i, imagePath: a, imageUrl: o, html: s, markdown: c, chart: l, prompt: u, pictureFailed: d, urlFailed: f } = r, p = t.id, m = await X(e.files?.artifacts, qe, p, (e) => {
824
991
  let t = e ?? {
825
- id: d,
992
+ id: p,
826
993
  title: "",
827
994
  mode: n.mode,
828
995
  totalSlides: n.totalSlides,
@@ -830,47 +997,51 @@ async function ft(e, t, n) {
830
997
  };
831
998
  return n.slide === 1 && (t.title = n.title), t.slides[String(n.slide)] = {
832
999
  title: n.title,
833
- imagePrompt: o ? r.imagePrompt ?? "" : n.imagePrompt,
1000
+ imagePrompt: s ? r.imagePrompt ?? "" : n.imagePrompt,
834
1001
  ...a && { imagePath: a },
835
- ...o && { html: o },
836
- ...s && { markdown: s },
837
- ...c && { chart: c }
1002
+ ...o && { imageUrl: o },
1003
+ ...s && { html: s },
1004
+ ...c && { markdown: c },
1005
+ ...l && { chart: l }
838
1006
  }, t;
839
- }), p = {
1007
+ }), h = {
840
1008
  ...i && { imageData: i },
841
1009
  ...a && { imagePath: a },
842
- ...o && { html: o },
843
- ...s && { markdown: s },
844
- ...c && { chart: c },
845
- prompt: l,
846
- slideshowId: d,
1010
+ ...o && { imageUrl: o },
1011
+ ...s && { html: s },
1012
+ ...c && { markdown: c },
1013
+ ...l && { chart: l },
1014
+ prompt: u,
1015
+ slideshowId: p,
847
1016
  slide: n.slide,
848
1017
  totalSlides: n.totalSlides,
849
1018
  title: n.title,
850
1019
  mode: n.mode
851
- }, m = n.mode === "steps" ? "step" : "slide";
1020
+ }, g = n.mode === "steps" ? "step" : "slide";
852
1021
  return {
853
- data: p,
1022
+ data: h,
854
1023
  title: n.title || `Slide ${n.slide}`,
855
1024
  message: [
856
- `${m} ${n.slide} of ${n.totalSlides} of slideshow "${d}" is on the screen`,
1025
+ `${g} ${n.slide} of ${n.totalSlides} of slideshow "${p}" is on the screen`,
1026
+ o ? `its picture is from ${o}` : "",
857
1027
  a ? `saved to ${a}` : "",
858
- u ? `its picture couldn't be drawn (${u}), so the slide is shown without it` : "",
859
- f ? "" : $("slideshow")
1028
+ f === void 0 ? "" : `the picture at ${n.imageUrl} couldn't be shown (${f}), so it was drawn instead`,
1029
+ d ? `its picture couldn't be drawn (${d}), so the slide is shown without it` : "",
1030
+ m ? "" : Z("slideshow")
860
1031
  ].filter(Boolean).join("; "),
861
- instructions: A(n),
1032
+ instructions: M(n),
862
1033
  instructionsRequired: !0,
863
- sequence: nt(n)
1034
+ sequence: ht(n)
864
1035
  };
865
1036
  }
866
- async function pt(e, t) {
867
- let n = k(t);
1037
+ async function Dt(e, t) {
1038
+ let n = A(t);
868
1039
  if (typeof n == "string") return {
869
1040
  message: n,
870
1041
  sequence: null
871
1042
  };
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)) {
1043
+ let r = _t(e), i = vt(r, n), a = n.mode === "steps";
1044
+ if (a && n.slide > i.current && i.current > 0 && !Oe(e, i.shownAt)) {
874
1045
  console.info(`[sequence] holding step ${n.slide} for the user`);
875
1046
  let e = i.shownAt === Infinity ? "is still being drawn" : "is still on the screen";
876
1047
  return {
@@ -879,15 +1050,15 @@ async function pt(e, t) {
879
1050
  };
880
1051
  }
881
1052
  let o = a ? i.slides.get(n.slide) : void 0;
882
- if (o) return Oe(e.currentResult, o) ? {
1053
+ if (o) return De(e.currentResult, o) ? {
883
1054
  message: `step ${n.slide} of ${n.totalSlides} is already on the screen`,
884
1055
  cancelled: !0
885
- } : ot(r, i, n, o);
886
- let s = r.repeats.claim(rt(i.id, n));
1056
+ } : yt(r, i, n, o);
1057
+ let s = r.repeats.claim(gt(i.id, n));
887
1058
  if ("earlier" in s) {
888
- if (!await s.earlier) return pt(e, t);
1059
+ if (!await s.earlier) return Dt(e, t);
889
1060
  let a = i.slides.get(n.slide);
890
- return a && r.lastShown !== i ? ot(r, i, n, a) : {
1061
+ return a && r.lastShown !== i ? yt(r, i, n, a) : {
891
1062
  message: `slide ${n.slide} of ${n.totalSlides} is already on the screen`,
892
1063
  cancelled: !0
893
1064
  };
@@ -899,22 +1070,22 @@ async function pt(e, t) {
899
1070
  i.current = n.slide, i.shownAt = Infinity;
900
1071
  let u = !1;
901
1072
  try {
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;
1073
+ let t = await Et(e, i, n);
1074
+ return u = Ee(t), u && (i.slides.set(n.slide, t), i.current = n.slide, i.shownAt = Date.now(), r.lastShown = i), t;
904
1075
  } finally {
905
1076
  c(u), !u && i.current === n.slide && (i.current = l.current, i.shownAt = l.shownAt);
906
1077
  }
907
1078
  }
908
1079
  //#endregion
909
1080
  //#region src/core/storyboard.ts
910
- var mt = ({ id: e, title: t, totalPanels: n }) => ({
1081
+ var Ot = ({ id: e, title: t, totalPanels: n }) => ({
911
1082
  step: 0,
912
1083
  total: n,
913
1084
  kind: "story",
914
1085
  label: `The cast of "${t}"`,
915
1086
  onShown: "introduce the characters",
916
1087
  nextCall: `call presentPanel for panel 1 of ${n} with storyboardId "${e}"`
917
- }), ht = ({ id: e, totalPanels: t }, n, r) => ({
1088
+ }), kt = ({ id: e, totalPanels: t }, n, r) => ({
918
1089
  step: n,
919
1090
  total: t,
920
1091
  kind: "story",
@@ -922,21 +1093,21 @@ var mt = ({ id: e, title: t, totalPanels: n }) => ({
922
1093
  onShown: "tell that part of the story",
923
1094
  nextCall: `call presentPanel for panel ${n + 1} of ${t} with storyboardId "${e}"`,
924
1095
  ...r.length > 0 && { waitsForUser: !0 }
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);
1096
+ }), At = (e, t) => e ? `${e}. ${t}` : t, jt = (e, { name: t, description: n }) => At(e, `Character reference sheet of ${t}: ${n}. Full body, front, side and back views, on a plain white background. No text or labels.`);
1097
+ async function Mt(e, t) {
1098
+ let n = F(t);
928
1099
  if (typeof n == "string") return {
929
1100
  message: n,
930
1101
  sequence: null
931
1102
  };
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);
1103
+ let r = await Promise.all(n.characters.map((t) => G(e, jt(n.style, t)))), i = r.map(H), a = r.find((e, t) => !i[t]?.imageData);
933
1104
  if (i.every(({ imageData: e }) => !e) && a) return {
934
1105
  ...a,
935
1106
  message: `the character sheets couldn't be made: ${a.message}`,
936
1107
  sequence: null
937
1108
  };
938
1109
  let o = {
939
- id: G(),
1110
+ id: ke(),
940
1111
  ...n,
941
1112
  characters: n.characters.map((e, t) => {
942
1113
  let n = i[t]?.imagePath;
@@ -946,7 +1117,7 @@ async function vt(e, t) {
946
1117
  };
947
1118
  }),
948
1119
  panels: {}
949
- }, 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;
1120
+ }, s = await X(e.files?.artifacts, Y, 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;
950
1121
  return {
951
1122
  data: {
952
1123
  storyboardId: o.id,
@@ -967,39 +1138,39 @@ async function vt(e, t) {
967
1138
  `storyboard "${o.id}" is ready with ${o.totalPanels} panels; the cast is on the screen`,
968
1139
  c.length ? `character sheets saved to ${c.join(", ")}` : "",
969
1140
  l.length ? `no sheet for ${l.join("; ")}: they will be drawn from their description` : "",
970
- s ? "" : $("storyboard")
1141
+ s ? "" : Z("storyboard")
971
1142
  ].filter(Boolean).join("; "),
972
- instructions: N(o),
1143
+ instructions: I(o),
973
1144
  instructionsRequired: !0,
974
- sequence: mt(o)
1145
+ sequence: Ot(o)
975
1146
  };
976
1147
  }
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}`);
1148
+ function Nt(e, t, n) {
1149
+ let r = [At(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}`);
979
1150
  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(" ");
980
1151
  }
981
- async function bt(e, t, n) {
1152
+ async function Pt(e, t, n) {
982
1153
  let r = [], i = [];
983
1154
  for (let a of n.characters) {
984
1155
  let n = t.characters.find((e) => T(e.name, a));
985
1156
  if (!n) r.push(a);
986
1157
  else if (!i.some((e) => e.character === n)) {
987
- let [t] = n.imagePath ? await K(e, [n.imagePath]) : [];
1158
+ let [t] = n.imagePath ? await je(e, [n.imagePath]) : [];
988
1159
  i.push({
989
1160
  character: n,
990
1161
  sheet: t ?? null
991
1162
  });
992
1163
  }
993
1164
  }
994
- let a = i.map(({ sheet: e }) => e).filter((e) => !!e), o = yt(t, n, i.map(({ character: e, sheet: t }) => ({
1165
+ let a = i.map(({ sheet: e }) => e).filter((e) => !!e), o = Nt(t, n, i.map(({ character: e, sheet: t }) => ({
995
1166
  character: e,
996
1167
  hasSheet: !!t
997
- }))), s = await q(e, o, a), { imageData: c, imagePath: l } = V(s);
1168
+ }))), s = await G(e, o, a), { imageData: c, imagePath: l } = H(s);
998
1169
  if (!c) return {
999
1170
  ...s,
1000
1171
  sequence: null
1001
1172
  };
1002
- let u = n.panel < t.totalPanels && n.choices.length >= 2 ? n.choices : [], d = await Q(e.files?.artifacts, Z, t.id, (e) => {
1173
+ let u = n.panel < t.totalPanels && n.choices.length >= 2 ? n.choices : [], d = await X(e.files?.artifacts, Y, t.id, (e) => {
1003
1174
  let r = e ?? t;
1004
1175
  return u.length && (r.interactive = !0), r.panels[String(n.panel)] = {
1005
1176
  caption: n.caption,
@@ -1025,25 +1196,25 @@ async function bt(e, t, n) {
1025
1196
  `panel ${n.panel} of ${t.totalPanels} is on the screen`,
1026
1197
  l ? `saved to ${l}` : "",
1027
1198
  r.length ? `not in the cast, so drawn from the prompt alone: ${r.join(", ")}` : "",
1028
- d ? "" : $("storyboard")
1199
+ d ? "" : Z("storyboard")
1029
1200
  ].filter(Boolean).join("; "),
1030
- instructions: I(t, n.panel, u),
1201
+ instructions: z(t, n.panel, u),
1031
1202
  instructionsRequired: !0,
1032
- sequence: ht(t, n.panel, u)
1203
+ sequence: kt(t, n.panel, u)
1033
1204
  };
1034
1205
  }
1035
- var xt = J(() => ({
1036
- repeats: tt(),
1206
+ var Ft = Ne(() => ({
1207
+ repeats: rt(),
1037
1208
  awaitingChoice: /* @__PURE__ */ new Map()
1038
1209
  }));
1039
- async function St(e, t) {
1040
- let n = F(t);
1210
+ async function It(e, t) {
1211
+ let n = R(t);
1041
1212
  if (!n) return {
1042
- message: P,
1213
+ message: L,
1043
1214
  sequence: null
1044
1215
  };
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`), {
1216
+ let { storyboardId: r, panel: i } = n, { repeats: a, awaitingChoice: o } = Ft(e), s = o.get(r);
1217
+ if (s && i > s.panel && !Oe(e, s.shownAt)) return console.info(`[sequence] holding panel ${i} for the user`), {
1047
1218
  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.`,
1048
1219
  cancelled: !0
1049
1220
  };
@@ -1051,7 +1222,7 @@ async function St(e, t) {
1051
1222
  if ("earlier" in c) return await c.earlier ? {
1052
1223
  message: `panel ${i} is already on the screen`,
1053
1224
  cancelled: !0
1054
- } : St(e, t);
1225
+ } : It(e, t);
1055
1226
  let { settle: l } = c, u = {
1056
1227
  panel: i,
1057
1228
  shownAt: Infinity
@@ -1059,7 +1230,7 @@ async function St(e, t) {
1059
1230
  o.set(r, u);
1060
1231
  let f = () => o.get(r) === u, p = !1;
1061
1232
  try {
1062
- let t = await $e(e.files?.artifacts, Z, r);
1233
+ let t = await tt(e.files?.artifacts, Y, r);
1063
1234
  if (!t) return {
1064
1235
  message: `there is no storyboard "${r}"; call defineStoryboard first`,
1065
1236
  sequence: null
@@ -1068,8 +1239,8 @@ async function St(e, t) {
1068
1239
  message: `storyboard "${t.id}" has ${t.totalPanels} panels`,
1069
1240
  sequence: null
1070
1241
  };
1071
- let a = await bt(e, t, n);
1072
- p = !!V(a).imageData;
1242
+ let a = await Pt(e, t, n);
1243
+ p = !!H(a).imageData;
1073
1244
  let s = a.data;
1074
1245
  return p && f() && (s?.choices?.length ? o.set(r, {
1075
1246
  panel: i,
@@ -1081,21 +1252,21 @@ async function St(e, t) {
1081
1252
  }
1082
1253
  //#endregion
1083
1254
  //#region src/core/index.ts
1084
- var Ct = {
1085
- toolDefinition: j,
1255
+ var Lt = {
1256
+ toolDefinition: P,
1086
1257
  generatingMessage: "Making the slide...",
1087
1258
  isEnabled: () => !0,
1088
- execute: (e, t) => pt(e, t)
1089
- }, wt = {
1090
- toolDefinition: R,
1259
+ execute: (e, t) => Dt(e, t)
1260
+ }, Rt = {
1261
+ toolDefinition: Ce,
1091
1262
  generatingMessage: "Drawing the characters...",
1092
1263
  isEnabled: () => !0,
1093
- execute: (e, t) => vt(e, t)
1094
- }, Tt = {
1095
- toolDefinition: z,
1264
+ execute: (e, t) => Mt(e, t)
1265
+ }, zt = {
1266
+ toolDefinition: we,
1096
1267
  generatingMessage: "Drawing the panel...",
1097
1268
  isEnabled: () => !0,
1098
- execute: (e, t) => St(e, t)
1269
+ execute: (e, t) => It(e, t)
1099
1270
  };
1100
1271
  //#endregion
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 };
1272
+ export { M as A, t as B, B as C, A as D, R as E, s as F, ae as H, h as I, l as L, fe as M, r as N, F as O, o as P, n as R, O as S, z as T, ie as U, b as V, P as _, Y as a, D as b, me as c, ve as d, _e as f, pe as g, we as h, qe as i, x as j, T as k, Ce as l, he as m, zt as n, tt as o, L as p, Lt as r, Ke as s, Rt as t, ge as u, N as v, I as w, k as x, S as y, _ as z };