@gui-chat-plugin/sequence 0.1.0 → 0.3.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.
- package/CHANGELOG.md +20 -0
- package/README.md +36 -10
- package/dist/core/definitions.d.ts +15 -5
- package/dist/core/host.d.ts +14 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/slideHtml.d.ts +23 -0
- package/dist/core-B1EsmU-q.cjs +46 -0
- package/dist/core-BALd7sgj.js +706 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/style.css +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +91 -33
- package/package.json +3 -3
- package/dist/core-55UuKHJb.cjs +0 -1
- package/dist/core-D0F2WGN6.js +0 -619
package/dist/core-D0F2WGN6.js
DELETED
|
@@ -1,619 +0,0 @@
|
|
|
1
|
-
import { createSerialLock as e } from "gui-chat-protocol";
|
|
2
|
-
//#region src/core/definitions.ts
|
|
3
|
-
var t = "presentSlide", n = "defineStoryboard", r = "presentPanel", i = 4, a = 12, o = 3, s = /^[0-9a-f]{12}$/, c = (e) => typeof e == "object" && !!e && !Array.isArray(e), l = (e) => typeof e == "string" ? e.trim() : "", u = (e, t) => e.toLowerCase() === t.toLowerCase(), d = (e) => typeof e == "number" && Number.isInteger(e), f = "presentSlide needs slide and totalSlides (whole numbers, slide from 1 to totalSlides) and an imagePrompt";
|
|
4
|
-
function p(e) {
|
|
5
|
-
let { slide: t, totalSlides: n, title: r, imagePrompt: i } = e;
|
|
6
|
-
return !d(t) || !d(n) || t < 1 || n < t || typeof i != "string" || !i.trim() ? null : {
|
|
7
|
-
slide: t,
|
|
8
|
-
totalSlides: n,
|
|
9
|
-
title: typeof r == "string" ? r : "",
|
|
10
|
-
imagePrompt: i,
|
|
11
|
-
mode: e.mode === "steps" ? "steps" : "presentation"
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
var m = ({ slide: e, totalSlides: t, title: n, mode: r }) => {
|
|
15
|
-
let i = n ? ` ("${n}")` : "";
|
|
16
|
-
if (r === "steps") {
|
|
17
|
-
let n = `Step ${e} of ${t}${i}`;
|
|
18
|
-
return e < t ? `${n} is now on the screen. Explain what to do in this step, 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. Explain what to do, then wrap up the guide once the user is done.`;
|
|
19
|
-
}
|
|
20
|
-
let a = `Slide ${e} of ${t}${i}`;
|
|
21
|
-
return e < t ? `${a} is now on the screen. Explain it, then, in this same reply and without waiting for the user, call presentSlide for slide ${e + 1}. If the user has asked you to stop, or asked something else, since the slideshow began, answer them instead of going on.` : `${a}, the last one, is now on the screen. Explain it, then wrap up the slideshow.`;
|
|
22
|
-
}, h = "When the user asks for a slideshow (or to explain something with slides), plan four to six slides, then show them one at a time with presentSlide: slide 1 first, and each next slide only after you have explained the one on the screen. Go on to the last slide without asking whether to continue. 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.", g = {
|
|
23
|
-
type: "function",
|
|
24
|
-
name: t,
|
|
25
|
-
prompt: h,
|
|
26
|
-
description: "Show one slide of a slideshow: a picture generated from imagePrompt, full screen. 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.",
|
|
27
|
-
parameters: {
|
|
28
|
-
type: "object",
|
|
29
|
-
properties: {
|
|
30
|
-
slide: {
|
|
31
|
-
type: "integer",
|
|
32
|
-
description: "This slide's number, starting at 1."
|
|
33
|
-
},
|
|
34
|
-
totalSlides: {
|
|
35
|
-
type: "integer",
|
|
36
|
-
description: "How many slides the slideshow has. Keep it the same for every slide."
|
|
37
|
-
},
|
|
38
|
-
title: {
|
|
39
|
-
type: "string",
|
|
40
|
-
description: "The slide's title."
|
|
41
|
-
},
|
|
42
|
-
imagePrompt: {
|
|
43
|
-
type: "string",
|
|
44
|
-
description: "The picture for this slide: a clear illustration or diagram of its point, with the title as its only large text. Be concrete. For a step, show the action: hands, tools and the object."
|
|
45
|
-
},
|
|
46
|
-
mode: {
|
|
47
|
-
type: "string",
|
|
48
|
-
enum: ["presentation", "steps"],
|
|
49
|
-
description: "\"presentation\" (the default) goes on by itself; \"steps\" is a how-to the user does along with you, and waits for them after each step. Keep it the same for every slide."
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
required: [
|
|
53
|
-
"slide",
|
|
54
|
-
"totalSlides",
|
|
55
|
-
"title",
|
|
56
|
-
"imagePrompt"
|
|
57
|
-
]
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
function _(e) {
|
|
61
|
-
let { totalPanels: t } = e;
|
|
62
|
-
if (!d(t) || t < 1 || t > 12) return "totalPanels must be a whole number from 1 to 12";
|
|
63
|
-
let n = [];
|
|
64
|
-
for (let t of Array.isArray(e.characters) ? e.characters : []) {
|
|
65
|
-
let e = c(t) ? l(t.name) : "", r = c(t) ? l(t.description) : "";
|
|
66
|
-
if (!e || !r) return "every character needs a name and a description";
|
|
67
|
-
if (n.some((t) => u(t.name, e))) return `two characters are named ${e}`;
|
|
68
|
-
n.push({
|
|
69
|
-
name: e,
|
|
70
|
-
description: r
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return n.length < 1 || n.length > 4 ? "a storyboard has 1 to 4 characters" : {
|
|
74
|
-
title: l(e.title),
|
|
75
|
-
style: l(e.style),
|
|
76
|
-
totalPanels: t,
|
|
77
|
-
characters: n,
|
|
78
|
-
interactive: e.interactive === !0
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
var v = ({ title: e, id: t }) => `The cast of "${e}" is now on the screen. Introduce the characters briefly, then, in this same reply and without waiting for the user, call presentPanel for panel 1 with storyboardId "${t}". If the user has asked you to stop, or asked something else, answer them instead of going on.`, y = "presentPanel needs a storyboardId, a panel number (from 1) and an imagePrompt";
|
|
82
|
-
function b(e) {
|
|
83
|
-
let { panel: t } = e, n = l(e.storyboardId), r = l(e.imagePrompt);
|
|
84
|
-
if (!n || !r || !d(t) || t < 1) return null;
|
|
85
|
-
let i = (e) => (Array.isArray(e) ? e : []).map(l).filter(Boolean);
|
|
86
|
-
return {
|
|
87
|
-
storyboardId: n,
|
|
88
|
-
panel: t,
|
|
89
|
-
characters: i(e.characters),
|
|
90
|
-
imagePrompt: r,
|
|
91
|
-
caption: l(e.caption),
|
|
92
|
-
choices: i(e.choices).slice(0, 3)
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function x(e, t, n) {
|
|
96
|
-
let { id: r, totalPanels: i } = e;
|
|
97
|
-
return n.length ? `Panel ${t} of ${i} is now on the screen, with the user's choices: ${n.map((e, t) => `${t + 1}. ${e}`).join(" ")} Tell this part of the story, then read the choices out and ask the user which one they pick, and wait for their answer. Then call presentPanel for panel ${t + 1} with storyboardId "${r}", going on the way they chose.` : t < i ? `Panel ${t} of ${i} is now on the screen. Tell this part of the story, then, in this same reply and without waiting for the user, call presentPanel for panel ${t + 1} with storyboardId "${r}". If the user has asked you to stop, or asked something else, since the story began, answer them instead of going on.` : `Panel ${t} of ${i}, the last one, is now on the screen. Tell this part of the story, then bring it to an end.`;
|
|
98
|
-
}
|
|
99
|
-
var S = "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.", C = {
|
|
100
|
-
type: "function",
|
|
101
|
-
name: n,
|
|
102
|
-
prompt: S,
|
|
103
|
-
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.",
|
|
104
|
-
parameters: {
|
|
105
|
-
type: "object",
|
|
106
|
-
properties: {
|
|
107
|
-
title: {
|
|
108
|
-
type: "string",
|
|
109
|
-
description: "The story's title."
|
|
110
|
-
},
|
|
111
|
-
style: {
|
|
112
|
-
type: "string",
|
|
113
|
-
description: "The art style of every picture, in one sentence (for example: soft watercolor, children's picture book)."
|
|
114
|
-
},
|
|
115
|
-
totalPanels: {
|
|
116
|
-
type: "integer",
|
|
117
|
-
description: "How many panels the story has, at most 12; four to eight is usual."
|
|
118
|
-
},
|
|
119
|
-
interactive: {
|
|
120
|
-
type: "boolean",
|
|
121
|
-
description: "The user chooses what happens: panels can offer choices, and the story waits for the pick."
|
|
122
|
-
},
|
|
123
|
-
characters: {
|
|
124
|
-
type: "array",
|
|
125
|
-
description: "The characters who appear in more than one panel, 1 to 4.",
|
|
126
|
-
items: {
|
|
127
|
-
type: "object",
|
|
128
|
-
properties: {
|
|
129
|
-
name: {
|
|
130
|
-
type: "string",
|
|
131
|
-
description: "A short name, used in presentPanel."
|
|
132
|
-
},
|
|
133
|
-
description: {
|
|
134
|
-
type: "string",
|
|
135
|
-
description: "How they look: age, build, face, hair, clothes and colors. Be concrete: it is drawn once and reused in every panel."
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
required: ["name", "description"]
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
required: [
|
|
143
|
-
"title",
|
|
144
|
-
"style",
|
|
145
|
-
"totalPanels",
|
|
146
|
-
"characters"
|
|
147
|
-
]
|
|
148
|
-
}
|
|
149
|
-
}, w = {
|
|
150
|
-
type: "function",
|
|
151
|
-
name: r,
|
|
152
|
-
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.",
|
|
153
|
-
parameters: {
|
|
154
|
-
type: "object",
|
|
155
|
-
properties: {
|
|
156
|
-
storyboardId: {
|
|
157
|
-
type: "string",
|
|
158
|
-
description: "The storyboardId defineStoryboard returned."
|
|
159
|
-
},
|
|
160
|
-
panel: {
|
|
161
|
-
type: "integer",
|
|
162
|
-
description: "This panel's number, starting at 1."
|
|
163
|
-
},
|
|
164
|
-
characters: {
|
|
165
|
-
type: "array",
|
|
166
|
-
items: { type: "string" },
|
|
167
|
-
description: "The names (as in defineStoryboard) of the characters in this panel."
|
|
168
|
-
},
|
|
169
|
-
imagePrompt: {
|
|
170
|
-
type: "string",
|
|
171
|
-
description: "What the panel shows: the setting, what happens, expressions and the camera angle. Refer to characters by name; don't describe their looks again."
|
|
172
|
-
},
|
|
173
|
-
caption: {
|
|
174
|
-
type: "string",
|
|
175
|
-
description: "One short line shown under the picture."
|
|
176
|
-
},
|
|
177
|
-
choices: {
|
|
178
|
-
type: "array",
|
|
179
|
-
items: { type: "string" },
|
|
180
|
-
description: "Only in an interactive story, and not on the last panel: two or three short options for what happens next. The story waits for the user's pick."
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
required: [
|
|
184
|
-
"storyboardId",
|
|
185
|
-
"panel",
|
|
186
|
-
"characters",
|
|
187
|
-
"imagePrompt"
|
|
188
|
-
]
|
|
189
|
-
}
|
|
190
|
-
}, T = (e) => typeof e == "object" && !!e && !Array.isArray(e), ee = (e) => T(e) && typeof e.message == "string";
|
|
191
|
-
function E(e) {
|
|
192
|
-
let t = T(e?.data) ? e.data : {};
|
|
193
|
-
return {
|
|
194
|
-
...typeof t.imageData == "string" && { imageData: t.imageData },
|
|
195
|
-
...typeof t.imagePath == "string" && { imagePath: t.imagePath }
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function te(e, t) {
|
|
199
|
-
let n = E(e), r = E(t);
|
|
200
|
-
return n.imagePath && r.imagePath ? n.imagePath === r.imagePath : !!n.imageData && n.imageData === r.imageData;
|
|
201
|
-
}
|
|
202
|
-
var D = (e, t) => e.userSpokeAt === void 0 || e.userSpokeAt > t, O = () => crypto.randomUUID().replace(/-/g, "").slice(0, 12), k = "artifacts/";
|
|
203
|
-
async function A(e, t) {
|
|
204
|
-
let n = e.files?.artifacts;
|
|
205
|
-
if (!e.app?.editImages || !n) return [];
|
|
206
|
-
let r = [];
|
|
207
|
-
for (let e of t) if (e.startsWith(k)) try {
|
|
208
|
-
await n.exists(e.slice(10)) && r.push(e);
|
|
209
|
-
} catch {}
|
|
210
|
-
return r;
|
|
211
|
-
}
|
|
212
|
-
async function j(e, t, n = []) {
|
|
213
|
-
let r = e.app, i = r?.editImages, a = r?.generateImage;
|
|
214
|
-
try {
|
|
215
|
-
let e;
|
|
216
|
-
if (n.length && i) e = await i(t, [...n]);
|
|
217
|
-
else if (a) e = await a(t);
|
|
218
|
-
else return { message: "image generation isn't available" };
|
|
219
|
-
return ee(e) ? e : { message: "image generation returned an unrecognized result" };
|
|
220
|
-
} catch (e) {
|
|
221
|
-
return { message: `image generation failed: ${e instanceof Error ? e.message : String(e)}` };
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
//#endregion
|
|
225
|
-
//#region src/core/records.ts
|
|
226
|
-
var M = "slideshows", N = "storyboards", P = {}, F = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap();
|
|
227
|
-
function L(e) {
|
|
228
|
-
let t = F.get(e);
|
|
229
|
-
return t || F.set(e, t = /* @__PURE__ */ new Map()), t;
|
|
230
|
-
}
|
|
231
|
-
function R(t, n) {
|
|
232
|
-
let r = I.get(t);
|
|
233
|
-
r || I.set(t, r = /* @__PURE__ */ new Map());
|
|
234
|
-
let i = r.get(n);
|
|
235
|
-
return i || r.set(n, i = e()), i;
|
|
236
|
-
}
|
|
237
|
-
var z = (e, t) => `${e}/${t}.json`;
|
|
238
|
-
async function B(e, t) {
|
|
239
|
-
let n = L(e ?? P), r = n.get(t);
|
|
240
|
-
if (r) return r;
|
|
241
|
-
if (!e) return null;
|
|
242
|
-
try {
|
|
243
|
-
let r = JSON.parse(await e.read(t));
|
|
244
|
-
return n.set(t, r), r;
|
|
245
|
-
} catch {
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
async function V(e, t, n) {
|
|
250
|
-
return s.test(n) ? B(e, z(t, n)) : null;
|
|
251
|
-
}
|
|
252
|
-
async function H(e, t, n, r) {
|
|
253
|
-
let i = z(t, n), a = e ?? P;
|
|
254
|
-
return R(a, i)(async () => {
|
|
255
|
-
let t = r(await B(e, i));
|
|
256
|
-
if (L(a).set(i, t), !e) return !1;
|
|
257
|
-
try {
|
|
258
|
-
return await e.write(i, JSON.stringify(t, null, 2)), !0;
|
|
259
|
-
} catch (e) {
|
|
260
|
-
return console.warn("[sequence] could not save", i, e), !1;
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
var U = (e) => `the ${e} could not be saved, so it lasts only until the app or server restarts`, ne = 6e4;
|
|
265
|
-
function W() {
|
|
266
|
-
let e = /* @__PURE__ */ new Map();
|
|
267
|
-
return { claim: (t) => {
|
|
268
|
-
let n = Date.now();
|
|
269
|
-
for (let [t, r] of e) n - r.at > ne && e.delete(t);
|
|
270
|
-
let r = e.get(t);
|
|
271
|
-
if (r) return { earlier: r.shown };
|
|
272
|
-
let i = () => void 0, a = new Promise((e) => i = e);
|
|
273
|
-
return e.set(t, {
|
|
274
|
-
at: n,
|
|
275
|
-
shown: a
|
|
276
|
-
}), { settle: (n) => {
|
|
277
|
-
!n && e.get(t)?.shown === a && e.delete(t), i(n);
|
|
278
|
-
} };
|
|
279
|
-
} };
|
|
280
|
-
}
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region src/core/presentSlide.ts
|
|
283
|
-
function G({ slide: e, totalSlides: t, mode: n }) {
|
|
284
|
-
return n === "steps" ? {
|
|
285
|
-
step: e,
|
|
286
|
-
total: t,
|
|
287
|
-
kind: "guide",
|
|
288
|
-
label: `Step ${e} of ${t}`,
|
|
289
|
-
onShown: "explain it",
|
|
290
|
-
nextCall: `call presentSlide for step ${e + 1} of ${t} with mode "steps"`,
|
|
291
|
-
waitsForUser: !0
|
|
292
|
-
} : {
|
|
293
|
-
step: e,
|
|
294
|
-
total: t,
|
|
295
|
-
kind: "slideshow",
|
|
296
|
-
label: `Slide ${e} of ${t}`,
|
|
297
|
-
onShown: "explain it",
|
|
298
|
-
nextCall: `call presentSlide for slide ${e + 1} of ${t}`
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
var re = W(), ie = (e, { slide: t, totalSlides: n, title: r, imagePrompt: i }) => JSON.stringify([
|
|
302
|
-
e,
|
|
303
|
-
t,
|
|
304
|
-
n,
|
|
305
|
-
r,
|
|
306
|
-
i
|
|
307
|
-
]), K = {
|
|
308
|
-
presentation: null,
|
|
309
|
-
steps: null
|
|
310
|
-
}, q = null;
|
|
311
|
-
function J(e) {
|
|
312
|
-
let t = K[e.mode], n = t?.totalSlides === e.totalSlides && (e.slide !== 1 || t.firstTitle === e.title);
|
|
313
|
-
if (t && n) return t;
|
|
314
|
-
let r = {
|
|
315
|
-
id: O(),
|
|
316
|
-
mode: e.mode,
|
|
317
|
-
totalSlides: e.totalSlides,
|
|
318
|
-
firstTitle: e.slide === 1 ? e.title : "",
|
|
319
|
-
slides: /* @__PURE__ */ new Map(),
|
|
320
|
-
current: 0,
|
|
321
|
-
shownAt: -Infinity
|
|
322
|
-
};
|
|
323
|
-
return K[e.mode] = r, r;
|
|
324
|
-
}
|
|
325
|
-
function Y(e, t, n) {
|
|
326
|
-
e.current = t.slide, e.shownAt = Date.now(), q = e;
|
|
327
|
-
let r = t.mode === "steps" ? "step" : "slide", { uuid: i, ...a } = n;
|
|
328
|
-
return {
|
|
329
|
-
...a,
|
|
330
|
-
message: `${r} ${t.slide} of ${t.totalSlides} is on the screen again, as it was`,
|
|
331
|
-
instructions: m(t),
|
|
332
|
-
instructionsRequired: !0,
|
|
333
|
-
sequence: G(t)
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
function ae(e, t) {
|
|
337
|
-
if (e.mode !== "steps") return e.title ? `A presentation slide titled "${e.title}". ${e.imagePrompt}` : e.imagePrompt;
|
|
338
|
-
let n = e.title ? `, "${e.title}"` : "";
|
|
339
|
-
return [
|
|
340
|
-
`An instructional illustration of step ${e.slide} of ${e.totalSlides}${n}. ${e.imagePrompt}`,
|
|
341
|
-
t ? "The reference image is the previous step: keep the same objects, hands, tools and setting, and show what this step changes." : "",
|
|
342
|
-
"Show the action clearly, with little or no text."
|
|
343
|
-
].filter(Boolean).join(" ");
|
|
344
|
-
}
|
|
345
|
-
async function oe(e, t, n) {
|
|
346
|
-
let r = t.slides.get(n.slide - 1), i = n.mode === "steps" ? E(r).imagePath : void 0, a = i ? await A(e, [i]) : [], o = ae(n, a.length > 0), s = await j(e, o, a), { imageData: c, imagePath: l } = E(s);
|
|
347
|
-
if (!c) return {
|
|
348
|
-
...s,
|
|
349
|
-
sequence: null
|
|
350
|
-
};
|
|
351
|
-
let u = t.id, d = await H(e.files?.artifacts, M, u, (e) => {
|
|
352
|
-
let t = e ?? {
|
|
353
|
-
id: u,
|
|
354
|
-
title: "",
|
|
355
|
-
mode: n.mode,
|
|
356
|
-
totalSlides: n.totalSlides,
|
|
357
|
-
slides: {}
|
|
358
|
-
};
|
|
359
|
-
return n.slide === 1 && (t.title = n.title), t.slides[String(n.slide)] = {
|
|
360
|
-
title: n.title,
|
|
361
|
-
imagePrompt: n.imagePrompt,
|
|
362
|
-
...l && { imagePath: l }
|
|
363
|
-
}, t;
|
|
364
|
-
}), f = {
|
|
365
|
-
imageData: c,
|
|
366
|
-
...l && { imagePath: l },
|
|
367
|
-
prompt: o,
|
|
368
|
-
slideshowId: u,
|
|
369
|
-
slide: n.slide,
|
|
370
|
-
totalSlides: n.totalSlides,
|
|
371
|
-
title: n.title,
|
|
372
|
-
mode: n.mode
|
|
373
|
-
}, p = n.mode === "steps" ? "step" : "slide";
|
|
374
|
-
return {
|
|
375
|
-
data: f,
|
|
376
|
-
title: n.title || `Slide ${n.slide}`,
|
|
377
|
-
message: [
|
|
378
|
-
`${p} ${n.slide} of ${n.totalSlides} of slideshow "${u}" is on the screen`,
|
|
379
|
-
l ? `saved to ${l}` : "",
|
|
380
|
-
d ? "" : U("slideshow")
|
|
381
|
-
].filter(Boolean).join("; "),
|
|
382
|
-
instructions: m(n),
|
|
383
|
-
instructionsRequired: !0,
|
|
384
|
-
sequence: G(n)
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
async function X(e, t) {
|
|
388
|
-
let n = p(t);
|
|
389
|
-
if (!n) return {
|
|
390
|
-
message: f,
|
|
391
|
-
sequence: null
|
|
392
|
-
};
|
|
393
|
-
let r = J(n), i = n.mode === "steps";
|
|
394
|
-
if (i && n.slide > r.current && r.current > 0 && !D(e, r.shownAt)) {
|
|
395
|
-
console.info(`[sequence] holding step ${n.slide} for the user`);
|
|
396
|
-
let e = r.shownAt === Infinity ? "is still being drawn" : "is still on the screen";
|
|
397
|
-
return {
|
|
398
|
-
message: `step ${n.slide} was not shown: the user hasn't said they're ready yet, and step ${r.current} ${e}. Wait for them before calling presentSlide for step ${n.slide}.`,
|
|
399
|
-
cancelled: !0
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
let a = i ? r.slides.get(n.slide) : void 0;
|
|
403
|
-
if (a) return te(e.currentResult, a) ? {
|
|
404
|
-
message: `step ${n.slide} of ${n.totalSlides} is already on the screen`,
|
|
405
|
-
cancelled: !0
|
|
406
|
-
} : Y(r, n, a);
|
|
407
|
-
let o = re.claim(ie(r.id, n));
|
|
408
|
-
if ("earlier" in o) {
|
|
409
|
-
if (!await o.earlier) return X(e, t);
|
|
410
|
-
let i = r.slides.get(n.slide);
|
|
411
|
-
return i && q !== r ? Y(r, n, i) : {
|
|
412
|
-
message: `slide ${n.slide} of ${n.totalSlides} is already on the screen`,
|
|
413
|
-
cancelled: !0
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
let { settle: s } = o, c = {
|
|
417
|
-
current: r.current,
|
|
418
|
-
shownAt: r.shownAt
|
|
419
|
-
};
|
|
420
|
-
r.current = n.slide, r.shownAt = Infinity;
|
|
421
|
-
let l = !1;
|
|
422
|
-
try {
|
|
423
|
-
let t = await oe(e, r, n);
|
|
424
|
-
return l = !!E(t).imageData, l && (r.slides.set(n.slide, t), r.current = n.slide, r.shownAt = Date.now(), q = r), t;
|
|
425
|
-
} finally {
|
|
426
|
-
s(l), !l && r.current === n.slide && (r.current = c.current, r.shownAt = c.shownAt);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
//#endregion
|
|
430
|
-
//#region src/core/storyboard.ts
|
|
431
|
-
var se = ({ id: e, title: t, totalPanels: n }) => ({
|
|
432
|
-
step: 0,
|
|
433
|
-
total: n,
|
|
434
|
-
kind: "story",
|
|
435
|
-
label: `The cast of "${t}"`,
|
|
436
|
-
onShown: "introduce the characters",
|
|
437
|
-
nextCall: `call presentPanel for panel 1 of ${n} with storyboardId "${e}"`
|
|
438
|
-
}), ce = ({ id: e, totalPanels: t }, n, r) => ({
|
|
439
|
-
step: n,
|
|
440
|
-
total: t,
|
|
441
|
-
kind: "story",
|
|
442
|
-
label: `Panel ${n} of ${t}`,
|
|
443
|
-
onShown: "tell that part of the story",
|
|
444
|
-
nextCall: `call presentPanel for panel ${n + 1} of ${t} with storyboardId "${e}"`,
|
|
445
|
-
...r.length > 0 && { waitsForUser: !0 }
|
|
446
|
-
}), Z = (e, t) => e ? `${e}. ${t}` : t, le = (e, { name: t, description: n }) => Z(e, `Character reference sheet of ${t}: ${n}. Full body, front, side and back views, on a plain white background. No text or labels.`);
|
|
447
|
-
async function ue(e, t) {
|
|
448
|
-
let n = _(t);
|
|
449
|
-
if (typeof n == "string") return {
|
|
450
|
-
message: n,
|
|
451
|
-
sequence: null
|
|
452
|
-
};
|
|
453
|
-
let r = await Promise.all(n.characters.map((t) => j(e, le(n.style, t)))), i = r.map(E), a = r.find((e, t) => !i[t]?.imageData);
|
|
454
|
-
if (i.every(({ imageData: e }) => !e) && a) return {
|
|
455
|
-
...a,
|
|
456
|
-
message: `the character sheets couldn't be made: ${a.message}`,
|
|
457
|
-
sequence: null
|
|
458
|
-
};
|
|
459
|
-
let o = {
|
|
460
|
-
id: O(),
|
|
461
|
-
...n,
|
|
462
|
-
characters: n.characters.map((e, t) => {
|
|
463
|
-
let n = i[t]?.imagePath;
|
|
464
|
-
return {
|
|
465
|
-
...e,
|
|
466
|
-
...n && { imagePath: n }
|
|
467
|
-
};
|
|
468
|
-
}),
|
|
469
|
-
panels: {}
|
|
470
|
-
}, s = await H(e.files?.artifacts, N, 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;
|
|
471
|
-
return {
|
|
472
|
-
data: {
|
|
473
|
-
storyboardId: o.id,
|
|
474
|
-
title: o.title,
|
|
475
|
-
totalPanels: o.totalPanels,
|
|
476
|
-
...u && { imageData: u },
|
|
477
|
-
characters: o.characters.map(({ name: e, imagePath: t }, n) => {
|
|
478
|
-
let r = i[n]?.imageData;
|
|
479
|
-
return {
|
|
480
|
-
name: e,
|
|
481
|
-
...r && { imageData: r },
|
|
482
|
-
...t && { imagePath: t }
|
|
483
|
-
};
|
|
484
|
-
})
|
|
485
|
-
},
|
|
486
|
-
title: o.title,
|
|
487
|
-
message: [
|
|
488
|
-
`storyboard "${o.id}" is ready with ${o.totalPanels} panels; the cast is on the screen`,
|
|
489
|
-
c.length ? `character sheets saved to ${c.join(", ")}` : "",
|
|
490
|
-
l.length ? `no sheet for ${l.join("; ")}: they will be drawn from their description` : "",
|
|
491
|
-
s ? "" : U("storyboard")
|
|
492
|
-
].filter(Boolean).join("; "),
|
|
493
|
-
instructions: v(o),
|
|
494
|
-
instructionsRequired: !0,
|
|
495
|
-
sequence: se(o)
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
function de(e, t, n) {
|
|
499
|
-
let r = [Z(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}`);
|
|
500
|
-
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(" ");
|
|
501
|
-
}
|
|
502
|
-
async function fe(e, t, n) {
|
|
503
|
-
let r = [], i = [];
|
|
504
|
-
for (let a of n.characters) {
|
|
505
|
-
let n = t.characters.find((e) => u(e.name, a));
|
|
506
|
-
if (!n) r.push(a);
|
|
507
|
-
else if (!i.some((e) => e.character === n)) {
|
|
508
|
-
let [t] = n.imagePath ? await A(e, [n.imagePath]) : [];
|
|
509
|
-
i.push({
|
|
510
|
-
character: n,
|
|
511
|
-
sheet: t ?? null
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
let a = i.map(({ sheet: e }) => e).filter((e) => !!e), o = de(t, n, i.map(({ character: e, sheet: t }) => ({
|
|
516
|
-
character: e,
|
|
517
|
-
hasSheet: !!t
|
|
518
|
-
}))), s = await j(e, o, a), { imageData: c, imagePath: l } = E(s);
|
|
519
|
-
if (!c) return {
|
|
520
|
-
...s,
|
|
521
|
-
sequence: null
|
|
522
|
-
};
|
|
523
|
-
let d = n.panel < t.totalPanels && n.choices.length >= 2 ? n.choices : [], f = await H(e.files?.artifacts, N, t.id, (e) => {
|
|
524
|
-
let r = e ?? t;
|
|
525
|
-
return d.length && (r.interactive = !0), r.panels[String(n.panel)] = {
|
|
526
|
-
caption: n.caption,
|
|
527
|
-
characters: i.map(({ character: e }) => e.name),
|
|
528
|
-
imagePrompt: n.imagePrompt,
|
|
529
|
-
...l && { imagePath: l },
|
|
530
|
-
...d.length && { choices: d }
|
|
531
|
-
}, r;
|
|
532
|
-
});
|
|
533
|
-
return {
|
|
534
|
-
data: {
|
|
535
|
-
imageData: c,
|
|
536
|
-
...l && { imagePath: l },
|
|
537
|
-
prompt: o,
|
|
538
|
-
storyboardId: t.id,
|
|
539
|
-
panel: n.panel,
|
|
540
|
-
totalPanels: t.totalPanels,
|
|
541
|
-
caption: n.caption,
|
|
542
|
-
...d.length && { choices: d }
|
|
543
|
-
},
|
|
544
|
-
title: n.caption || `Panel ${n.panel}`,
|
|
545
|
-
message: [
|
|
546
|
-
`panel ${n.panel} of ${t.totalPanels} is on the screen`,
|
|
547
|
-
l ? `saved to ${l}` : "",
|
|
548
|
-
r.length ? `not in the cast, so drawn from the prompt alone: ${r.join(", ")}` : "",
|
|
549
|
-
f ? "" : U("storyboard")
|
|
550
|
-
].filter(Boolean).join("; "),
|
|
551
|
-
instructions: x(t, n.panel, d),
|
|
552
|
-
instructionsRequired: !0,
|
|
553
|
-
sequence: ce(t, n.panel, d)
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
var pe = W(), Q = /* @__PURE__ */ new Map();
|
|
557
|
-
async function $(e, t) {
|
|
558
|
-
let n = b(t);
|
|
559
|
-
if (!n) return {
|
|
560
|
-
message: y,
|
|
561
|
-
sequence: null
|
|
562
|
-
};
|
|
563
|
-
let { storyboardId: r, panel: i } = n, a = Q.get(r);
|
|
564
|
-
if (a && i > a.panel && !D(e, a.shownAt)) return console.info(`[sequence] holding panel ${i} for the user`), {
|
|
565
|
-
message: a.shownAt === Infinity ? `panel ${i} was not shown: panel ${a.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 ${a.panel} is still on the screen. Wait for their answer.`,
|
|
566
|
-
cancelled: !0
|
|
567
|
-
};
|
|
568
|
-
let o = pe.claim(JSON.stringify(n));
|
|
569
|
-
if ("earlier" in o) return await o.earlier ? {
|
|
570
|
-
message: `panel ${i} is already on the screen`,
|
|
571
|
-
cancelled: !0
|
|
572
|
-
} : $(e, t);
|
|
573
|
-
let { settle: s } = o, c = {
|
|
574
|
-
panel: i,
|
|
575
|
-
shownAt: Infinity
|
|
576
|
-
}, l = Q.get(r);
|
|
577
|
-
Q.set(r, c);
|
|
578
|
-
let u = () => Q.get(r) === c, d = !1;
|
|
579
|
-
try {
|
|
580
|
-
let t = await V(e.files?.artifacts, N, r);
|
|
581
|
-
if (!t) return {
|
|
582
|
-
message: `there is no storyboard "${r}"; call defineStoryboard first`,
|
|
583
|
-
sequence: null
|
|
584
|
-
};
|
|
585
|
-
if (i > t.totalPanels) return {
|
|
586
|
-
message: `storyboard "${t.id}" has ${t.totalPanels} panels`,
|
|
587
|
-
sequence: null
|
|
588
|
-
};
|
|
589
|
-
let a = await fe(e, t, n);
|
|
590
|
-
d = !!E(a).imageData;
|
|
591
|
-
let o = a.data;
|
|
592
|
-
return d && u() && (o?.choices?.length ? Q.set(r, {
|
|
593
|
-
panel: i,
|
|
594
|
-
shownAt: Date.now()
|
|
595
|
-
}) : Q.delete(r)), a;
|
|
596
|
-
} finally {
|
|
597
|
-
s(d), !d && u() && (l ? Q.set(r, l) : Q.delete(r));
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
//#endregion
|
|
601
|
-
//#region src/core/index.ts
|
|
602
|
-
var me = {
|
|
603
|
-
toolDefinition: g,
|
|
604
|
-
generatingMessage: "Making the slide...",
|
|
605
|
-
isEnabled: () => !0,
|
|
606
|
-
execute: (e, t) => X(e, t)
|
|
607
|
-
}, he = {
|
|
608
|
-
toolDefinition: C,
|
|
609
|
-
generatingMessage: "Drawing the characters...",
|
|
610
|
-
isEnabled: () => !0,
|
|
611
|
-
execute: (e, t) => ue(e, t)
|
|
612
|
-
}, ge = {
|
|
613
|
-
toolDefinition: w,
|
|
614
|
-
generatingMessage: "Drawing the panel...",
|
|
615
|
-
isEnabled: () => !0,
|
|
616
|
-
execute: (e, t) => $(e, t)
|
|
617
|
-
};
|
|
618
|
-
//#endregion
|
|
619
|
-
export { b as C, m as D, u as E, x as S, _ as T, h as _, N as a, S as b, C as c, a as d, y as f, g, t as h, M as i, i as l, w as m, ge as n, V as o, r as p, me as r, n as s, he as t, o as u, s as v, p as w, v as x, f as y };
|