@penguinharness/use-bento-slides 0.2.17 → 0.2.19

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.
Files changed (33) hide show
  1. package/README.md +37 -0
  2. package/README.zh.md +37 -0
  3. package/THIRD-PARTY-NOTICES.md +30 -0
  4. package/ifaces.json +63 -0
  5. package/package.json +19 -21
  6. package/skills/bento-slides/SKILL.md +89 -29
  7. package/skills/bento-slides/references/bento-agents.md +511 -0
  8. package/workbenches/slides/index.ts +677 -0
  9. package/workbenches/slides/package.json +43 -0
  10. package/workbenches/slides/ui/app.js +1101 -0
  11. package/workbenches/slides/ui/bridge.js +190 -0
  12. package/workbenches/slides/ui/conversation-view.js +206 -0
  13. package/workbenches/slides/ui/conversation.css +95 -0
  14. package/workbenches/slides/ui/conversation.js +115 -0
  15. package/workbenches/slides/ui/deck-files.css +279 -0
  16. package/workbenches/slides/ui/deck-files.js +189 -0
  17. package/workbenches/slides/ui/file-menu.js +72 -0
  18. package/workbenches/slides/ui/icon.svg +9 -0
  19. package/workbenches/slides/ui/index.html +252 -0
  20. package/workbenches/slides/ui/model-choice.js +298 -0
  21. package/workbenches/slides/ui/model-control.tsx +90 -0
  22. package/workbenches/slides/ui/powerpoint.js +196 -0
  23. package/workbenches/slides/ui/sample.bento.json +33 -0
  24. package/workbenches/slides/ui/strings.js +184 -0
  25. package/workbenches/slides/ui/style.css +505 -0
  26. package/workbenches/slides/ui/sync.js +268 -0
  27. package/workbenches/slides/ui/template-picker.js +128 -0
  28. package/workbenches/slides/ui/templates.js +256 -0
  29. package/workbenches/slides/ui/vendor/LICENSE-bento.txt +21 -0
  30. package/workbenches/slides/ui/vendor/LICENSE-jszip.txt +25 -0
  31. package/workbenches/slides/ui/vendor/LICENSE-pptxgen.txt +21 -0
  32. package/workbenches/slides/ui/vendor/bento-slides-1.2.13.runtime.txt +310 -0
  33. package/workbenches/slides/ui/vendor/pptxgen-4.0.1.bundle.js +96 -0
@@ -0,0 +1,252 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Slides</title>
7
+ <link rel="stylesheet" href="./style.css" />
8
+ <link rel="stylesheet" href="./deck-files.css" />
9
+ <script type="module" src="./app.js"></script>
10
+ <link rel="stylesheet" href="conversation.css" />
11
+ </head>
12
+ <body>
13
+ <div class="app" id="app" data-view="loading">
14
+ <header class="bar">
15
+ <button id="show-decks" class="back-link" type="button">
16
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M15 18l-6-6 6-6M9 12h12" /></svg>
17
+ </button>
18
+ <div class="document-info">
19
+ <h1 id="deck-title" class="deck-title"></h1>
20
+ <span id="sync" class="sync" role="status"></span>
21
+ </div>
22
+ <div class="file-picker">
23
+ <button
24
+ id="file-button"
25
+ class="quiet-command"
26
+ type="button"
27
+ aria-haspopup="menu"
28
+ aria-expanded="false"
29
+ aria-controls="file-menu"
30
+ >
31
+ <span data-copy="fileMenu"></span>
32
+ <svg class="chevron" viewBox="0 0 24 24" aria-hidden="true">
33
+ <path d="M6 9l6 6 6-6" />
34
+ </svg>
35
+ </button>
36
+ <div id="file-menu" class="file-menu" role="menu" aria-labelledby="file-button" hidden>
37
+ <button
38
+ id="new"
39
+ type="button"
40
+ role="menuitem"
41
+ tabindex="-1"
42
+ data-copy="newTitle"
43
+ ></button>
44
+ <button
45
+ id="import"
46
+ type="button"
47
+ role="menuitem"
48
+ tabindex="-1"
49
+ data-copy="importDeck"
50
+ ></button>
51
+ <hr role="separator" />
52
+ <button id="save" type="button" role="menuitem" tabindex="-1">
53
+ <span data-copy="saveDeck"></span><kbd id="save-shortcut" aria-hidden="true"></kbd>
54
+ </button>
55
+ <button
56
+ id="history"
57
+ type="button"
58
+ role="menuitem"
59
+ tabindex="-1"
60
+ aria-haspopup="dialog"
61
+ data-copy="history"
62
+ ></button>
63
+ <hr role="separator" />
64
+ <button id="pptx" type="button" role="menuitem" tabindex="-1" data-copy="pptx"></button>
65
+ <button
66
+ id="export"
67
+ type="button"
68
+ role="menuitem"
69
+ tabindex="-1"
70
+ data-copy="exportDeck"
71
+ ></button>
72
+ </div>
73
+ </div>
74
+ <div class="editor-actions">
75
+ <button
76
+ id="rail-toggle"
77
+ type="button"
78
+ class="quiet-command"
79
+ aria-pressed="true"
80
+ aria-controls="rail"
81
+ >
82
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5h16v14H4zM14 5v14" /></svg>
83
+ <span data-copy="askAi"></span>
84
+ </button>
85
+ <button id="present" type="button" class="wb-primary">
86
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 4l13 8-13 8z" /></svg>
87
+ <span data-copy="present"></span>
88
+ </button>
89
+ </div>
90
+ <input id="file" type="file" accept=".html,.json,text/html,application/json" hidden />
91
+ </header>
92
+
93
+ <p id="notice" class="notice" role="status" hidden></p>
94
+
95
+ <main class="stage">
96
+ <section class="editor" aria-label="Deck editor">
97
+ <iframe
98
+ id="editor"
99
+ title="Bento Slides editor"
100
+ sandbox="allow-scripts allow-downloads allow-popups allow-popups-to-escape-sandbox"
101
+ ></iframe>
102
+ </section>
103
+
104
+ <aside id="rail" class="rail" aria-labelledby="rail-title">
105
+ <header class="rail-head">
106
+ <h2 id="rail-title" data-copy="railTitle"></h2>
107
+ <button id="rail-reset" type="button" class="link" data-copy="newChat"></button>
108
+ </header>
109
+ <ol id="talk" class="talk" aria-labelledby="rail-title"></ol>
110
+ <form id="ask" class="ask">
111
+ <p id="context" class="context"></p>
112
+ <textarea id="prompt" rows="3" maxlength="20000" required></textarea>
113
+ <div class="ask-actions">
114
+ <div id="chat-model" class="chat-model"></div>
115
+ <div id="chat-effort" class="chat-effort"></div>
116
+ <button id="send" type="submit" class="wb-primary" data-copy="send"></button>
117
+ <button id="stop" type="button" hidden data-copy="stop"></button>
118
+ </div>
119
+ </form>
120
+ </aside>
121
+ </main>
122
+
123
+ <section class="start" id="deck-files" aria-labelledby="start-title">
124
+ <div class="file-home">
125
+ <header class="file-header">
126
+ <h1 id="start-title" data-files-copy="title"></h1>
127
+ <button id="start-import" type="button" data-files-copy="open"></button>
128
+ </header>
129
+ <div class="file-launch">
130
+ <section class="new-presentations" aria-labelledby="new-heading">
131
+ <div class="templates-heading">
132
+ <h2 id="new-heading" data-copy="newDeck"></h2>
133
+ <button
134
+ id="start-sample"
135
+ type="button"
136
+ class="link"
137
+ data-files-copy="sample"
138
+ ></button>
139
+ </div>
140
+ <div class="file-templates" id="templates">
141
+ <button id="start-blank" type="button">
142
+ <span class="template-sheet blank-sheet" aria-hidden="true"><span>+</span></span>
143
+ <span data-copy="blankDeck"></span>
144
+ </button>
145
+ </div>
146
+ </section>
147
+ <form id="start-ask" class="start-ask">
148
+ <h2><label for="start-prompt" data-files-copy="ai"></label></h2>
149
+ <textarea id="start-prompt" rows="2" maxlength="20000" required></textarea>
150
+ <div class="ask-actions">
151
+ <div id="start-model" class="chat-model"></div>
152
+ <div id="start-effort" class="chat-effort"></div>
153
+ <button type="submit" class="wb-primary" data-copy="startGo"></button>
154
+ </div>
155
+ </form>
156
+ </div>
157
+ <h2 id="recent-heading" data-files-copy="recent"></h2>
158
+ <div class="file-head" aria-hidden="true">
159
+ <span data-files-copy="name"></span><span data-files-copy="modified"></span>
160
+ </div>
161
+ <p id="list-message" class="file-status" role="status"></p>
162
+ <button id="retry-decks" type="button" data-files-copy="retry" hidden></button>
163
+ <ul class="file-rows" id="recent-decks" aria-labelledby="recent-heading"></ul>
164
+ </div>
165
+ </section>
166
+ <dialog
167
+ id="choice-confirm"
168
+ aria-labelledby="choice-title"
169
+ aria-describedby="choice-description"
170
+ >
171
+ <form method="dialog">
172
+ <h2 id="choice-title"></h2>
173
+ <p id="choice-description"></p>
174
+ <div class="dialog-actions">
175
+ <button type="submit" value="cancel" data-copy="choiceCancel" autofocus></button>
176
+ <button
177
+ type="submit"
178
+ value="switch"
179
+ class="wb-primary"
180
+ data-copy="choiceApply"
181
+ ></button>
182
+ </div>
183
+ </form>
184
+ </dialog>
185
+ <dialog id="deck-action" aria-labelledby="deck-action-title">
186
+ <form id="deck-action-form">
187
+ <h2 id="deck-action-title"></h2>
188
+ <label id="rename-field"
189
+ ><span data-files-copy="name"></span
190
+ ><input id="rename-title" type="text" maxlength="120"
191
+ /></label>
192
+ <p id="remove-message"></p>
193
+ <p id="deck-action-message" role="alert"></p>
194
+ <div class="dialog-actions">
195
+ <button id="cancel-deck-action" type="button" data-copy="cancel"></button
196
+ ><button id="confirm-deck-action" type="submit" class="wb-primary"></button>
197
+ </div>
198
+ </form>
199
+ </dialog>
200
+
201
+ <dialog id="create-dialog" aria-labelledby="create-heading">
202
+ <form id="create-form">
203
+ <h2 id="create-heading" data-copy="newTitle"></h2>
204
+ <label
205
+ ><span data-copy="deckName"></span
206
+ ><input id="create-name" maxlength="120" required autofocus
207
+ /></label>
208
+ <label
209
+ ><span data-copy="layout"></span
210
+ ><select id="create-layout">
211
+ <option value="blank" data-copy="blankDeck"></option></select
212
+ ></label>
213
+ <figure id="template-preview" hidden>
214
+ <div id="preview-sheet" class="slide-preview"></div>
215
+ <figcaption>
216
+ <span id="preview-caption" aria-live="polite"></span>
217
+ <span class="preview-paging"
218
+ ><button id="preview-prev" type="button" data-copy="previousSlide"></button
219
+ ><button id="preview-next" type="button" data-copy="nextSlide"></button
220
+ ></span>
221
+ </figcaption>
222
+ </figure>
223
+ <p id="create-error" role="alert"></p>
224
+ <div class="dialog-actions">
225
+ <button id="create-cancel" type="button" data-copy="cancel"></button
226
+ ><button type="submit" class="wb-primary" data-copy="create"></button>
227
+ </div>
228
+ </form>
229
+ </dialog>
230
+ <dialog id="history-dialog" aria-labelledby="history-heading">
231
+ <header>
232
+ <h2 id="history-heading" data-copy="history"></h2>
233
+ <form method="dialog"><button type="submit" data-copy="close"></button></form>
234
+ </header>
235
+ <p id="history-status" role="status"></p>
236
+ <ul id="history-menu" aria-labelledby="history-heading"></ul>
237
+ </dialog>
238
+ <dialog id="player" aria-label="Presentation">
239
+ <header>
240
+ <strong id="player-title"></strong
241
+ ><button id="player-close" type="button" data-copy="backToEdit"></button>
242
+ </header>
243
+ <iframe id="player-frame" title="Presentation" sandbox="allow-scripts"></iframe>
244
+ </dialog>
245
+
246
+ <section class="unsupported" role="alert">
247
+ <h1 data-copy="unsupportedTitle"></h1>
248
+ <p data-copy="unsupportedBody"></p>
249
+ </section>
250
+ </div>
251
+ </body>
252
+ </html>
@@ -0,0 +1,298 @@
1
+ // Session settings come from the host. A choice on the start page belongs to the next deck only.
2
+ import { S } from "./strings.js";
3
+
4
+ const key = (model) => model && JSON.stringify([model.provider, model.modelId]);
5
+ const sessionPath = (id) => "/sessions/" + encodeURIComponent(id);
6
+ const label = (model) => model?.label || model?.modelId;
7
+
8
+ export function setupModelChoice({
9
+ $,
10
+ notice,
11
+ send,
12
+ loadSdk,
13
+ currentDeck,
14
+ currentTalk,
15
+ refreshTalk,
16
+ }) {
17
+ const labels = new Map();
18
+ let defaultModel;
19
+ let thinking = null;
20
+ let startModel = null;
21
+ let startEffort = null;
22
+ let startPicking = false;
23
+ let railModel, newModel, railEffort, newEffort;
24
+
25
+ function draw() {
26
+ const deck = currentDeck();
27
+ const fallback = defaultModel === null ? S.pickModel : S.defaultModel;
28
+ railModel?.(
29
+ deck?.waitingChoice?.target ?? deck?.pendingModel ?? deck?.model ?? defaultModel,
30
+ fallback,
31
+ S.chooseModel,
32
+ !deck || !!(deck.choosingModel || deck.retryingChoice),
33
+ !!deck?.choosingModel,
34
+ );
35
+ newModel?.(startModel ?? defaultModel, fallback, S.chooseModel, startPicking, startPicking);
36
+ railEffort?.(thinking, deck?.draftEffort ?? deck?.effort, !deck || !!deck.choosingModel);
37
+ newEffort?.(thinking, startEffort, startPicking);
38
+ $("send").disabled = !!(deck?.savingChoice || deck?.waitingChoice || deck?.retryingChoice);
39
+ $("rail-reset").disabled = !!deck?.savingChoice;
40
+ }
41
+
42
+ function confirm(title, description) {
43
+ const dialog = $("choice-confirm");
44
+ $("choice-title").textContent = title;
45
+ $("choice-description").textContent = description;
46
+ dialog.returnValue = "";
47
+ return new Promise((resolve) => {
48
+ dialog.addEventListener("close", () => resolve(dialog.returnValue === "switch"), {
49
+ once: true,
50
+ });
51
+ dialog.showModal();
52
+ });
53
+ }
54
+
55
+ async function ensureSession(deck, model) {
56
+ const response = await send("/ask/session", "POST", {
57
+ deck: deck.id,
58
+ ...(model ? { model } : {}),
59
+ });
60
+ const body = await response.json();
61
+ if (!response.ok) throw new Error(body.error?.message || body.error || String(response.status));
62
+ return body.sessionId;
63
+ }
64
+
65
+ async function setEffort(api, sessionId, thinkingLevel) {
66
+ const response = await fetch(api.apiBase + sessionPath(sessionId), {
67
+ method: "PATCH",
68
+ credentials: "same-origin",
69
+ headers: { "Content-Type": "application/json" },
70
+ body: JSON.stringify({ thinkingLevel }),
71
+ });
72
+ if (!response.ok) {
73
+ const body = await response.json().catch(() => null);
74
+ throw new Error(body?.error?.message ?? String(response.status));
75
+ }
76
+ }
77
+
78
+ // Only an explicit busy refusal guarantees that the first request was not accepted.
79
+ // Older hosts can still run the ordinary handoff on this Session once it becomes idle.
80
+ async function switchModel(api, deck, id, target, waitIfBusy) {
81
+ try {
82
+ const { status } = await api.transport.post(sessionPath(id) + "/switch-model", {
83
+ provider: target.provider,
84
+ modelId: target.modelId,
85
+ whenIdle: true,
86
+ });
87
+ deck.choiceRead = (deck.choiceRead || 0) + 1;
88
+ deck.waitingChoice = null;
89
+ deck.pendingModel = status === 202 ? target : null;
90
+ // Idle-only hosts do not report a pending target while they summarize the conversation.
91
+ deck.idleHandoff = !waitIfBusy && status === 202 ? target : null;
92
+ if (status === 200) deck.model = target;
93
+ } catch (error) {
94
+ if (
95
+ !waitIfBusy ||
96
+ error.status !== 409 ||
97
+ !["task_in_progress", "compacting"].includes(error.code)
98
+ )
99
+ throw error;
100
+ deck.waitingChoice = { id, target };
101
+ }
102
+ draw();
103
+ }
104
+
105
+ // The session and its label lookup are distinct reads. A slower lookup must not repaint
106
+ // an earlier selection over a later reply, or a conversation that was reset.
107
+ async function readSessionModel(deck, id) {
108
+ const revision = (deck.choiceRead = (deck.choiceRead || 0) + 1);
109
+ const api = await loadSdk();
110
+ if (!api) return;
111
+ const {
112
+ body: { session },
113
+ } = await api.transport.get(sessionPath(id));
114
+ async function named(ref) {
115
+ if (!ref) return null;
116
+ const k = key(ref);
117
+ if (!labels.has(k)) {
118
+ const row = await api.getChatModel?.(ref).catch(() => null);
119
+ labels.set(k, row?.label || ref.modelId);
120
+ }
121
+ return { provider: ref.provider, modelId: ref.modelId, label: labels.get(k) };
122
+ }
123
+ const [model, pending] = await Promise.all([named(session), named(session.pendingModel)]);
124
+ if (currentDeck() !== deck || currentTalk().sessionId !== id || deck.choiceRead !== revision)
125
+ return;
126
+ const previous = deck.pendingModel;
127
+ const failure = session.modelSwitchFailure;
128
+ if (failure && failure.id !== deck.seenSwitchFailure && key(previous) === key(failure))
129
+ notice(S.handoffFailed);
130
+ deck.seenSwitchFailure = failure?.id;
131
+ deck.model = model;
132
+ if (session.status !== "compacting" || pending) deck.idleHandoff = null;
133
+ deck.pendingModel = pending ?? deck.idleHandoff;
134
+ deck.effort = session.thinkingLevel ?? null;
135
+ const waiting = deck.waitingChoice;
136
+ if (waiting && waiting.id !== id) deck.waitingChoice = null;
137
+ else if (waiting && !deck.choosingModel && !deck.retryingChoice && session.status === "idle") {
138
+ if (key(waiting.target) !== key(pending ?? model)) {
139
+ deck.retryingChoice = true;
140
+ try {
141
+ await switchModel(api, deck, id, waiting.target, false);
142
+ } catch (error) {
143
+ if (currentDeck() === deck && currentTalk().sessionId === id)
144
+ notice(S.modelFailed(String(error.message || error)));
145
+ } finally {
146
+ deck.retryingChoice = false;
147
+ }
148
+ }
149
+ deck.waitingChoice = null;
150
+ }
151
+ draw();
152
+ }
153
+
154
+ async function choose(start, level = null) {
155
+ const deck = currentDeck();
156
+ if (start ? startPicking : !deck || deck.choosingModel || deck.retryingChoice) return;
157
+ if (start) startPicking = true;
158
+ else deck.choosingModel = true;
159
+ draw();
160
+ try {
161
+ const api = await loadSdk();
162
+ if (!api?.chooseChatModel) {
163
+ notice(S.modelUnsupported);
164
+ return;
165
+ }
166
+ let choice = null;
167
+ if (level === null) {
168
+ choice = await api.chooseChatModel(
169
+ start
170
+ ? (startModel ?? defaultModel)
171
+ : (deck.waitingChoice?.target ?? deck.pendingModel ?? deck.model ?? defaultModel),
172
+ );
173
+ if (!choice) return;
174
+ labels.set(key(choice), label(choice));
175
+ }
176
+ if (start) {
177
+ if (choice) startModel = choice;
178
+ else startEffort = level;
179
+ return;
180
+ }
181
+ if (currentDeck() !== deck) return;
182
+ const talk = currentTalk();
183
+ const initialId = talk.sessionId;
184
+ if (level !== null && !initialId && defaultModel === null && !deck.model) {
185
+ deck.draftEffort = level;
186
+ return;
187
+ }
188
+ // The first task can already be running when its acknowledgement has not reached the
189
+ // rail. This endpoint returns the deck's existing Session or creates its first one.
190
+ const id = initialId ?? (await ensureSession(deck, choice));
191
+ const stillHere = () => {
192
+ const current = currentTalk().sessionId;
193
+ return currentDeck() === deck && (current === initialId || current === id);
194
+ };
195
+ if (!stillHere()) return;
196
+ const {
197
+ body: { session },
198
+ } = await api.transport.get(sessionPath(id));
199
+ if (!stillHere()) return;
200
+ if (choice && key(choice) === key(deck.waitingChoice?.target)) return;
201
+ if (choice && key(choice) === key(session.pendingModel ?? session)) {
202
+ deck.waitingChoice = null;
203
+ await refreshTalk();
204
+ return;
205
+ }
206
+ if (
207
+ session.hasTrace ||
208
+ session.status !== "idle" ||
209
+ talk.messages.some((m) => m.role === "user")
210
+ ) {
211
+ const copy = choice
212
+ ? key(choice) !== key(session) && S.modelCost(label(choice))
213
+ : (session.thinkingLevel ?? thinking?.defaultLevel) !== level && S.effortCost;
214
+ if (copy && !(await confirm(choice ? S.chooseModel : thinking.title, copy))) return;
215
+ }
216
+ if (!stillHere()) return;
217
+ deck.savingChoice = true;
218
+ draw();
219
+ if (level !== null) await setEffort(api, id, level);
220
+ else await switchModel(api, deck, id, choice, true);
221
+ if (deck.draftEffort) {
222
+ await setEffort(api, id, deck.draftEffort);
223
+ deck.draftEffort = null;
224
+ }
225
+ await refreshTalk();
226
+ } catch (error) {
227
+ if (start || currentDeck() === deck)
228
+ notice(
229
+ error.name === "WorkbenchHostUnavailable"
230
+ ? S.modelUnsupported
231
+ : S.choiceFailed(String(error.message || error)),
232
+ );
233
+ } finally {
234
+ if (start) startPicking = false;
235
+ else {
236
+ deck.choosingModel = false;
237
+ deck.savingChoice = false;
238
+ }
239
+ draw();
240
+ if (level === null)
241
+ requestAnimationFrame(() => {
242
+ if (start || currentDeck() === deck)
243
+ $(start ? "start-model" : "chat-model")
244
+ .querySelector("button")
245
+ ?.focus();
246
+ });
247
+ }
248
+ }
249
+
250
+ async function prepareStart(deck) {
251
+ if (startEffort === null) return;
252
+ const id = await ensureSession(deck, startModel);
253
+ const api = await loadSdk();
254
+ await setEffort(api, id, startEffort);
255
+ }
256
+
257
+ void import("./model-control.js")
258
+ .then(({ mountModelControl, mountEffortControl }) => {
259
+ railModel = mountModelControl($("chat-model"), () => void choose(false));
260
+ newModel = mountModelControl($("start-model"), () => void choose(true));
261
+ railEffort = mountEffortControl($("chat-effort"), (level) => void choose(false, level));
262
+ newEffort = mountEffortControl($("start-effort"), (level) => void choose(true, level));
263
+ draw();
264
+ void loadSdk().then((api) => {
265
+ void api
266
+ ?.getChatModel?.()
267
+ .then((model) => {
268
+ defaultModel = model;
269
+ draw();
270
+ })
271
+ .catch(() => {});
272
+ void api
273
+ ?.getChatThinkingOptions?.()
274
+ .then((levels) => {
275
+ thinking = levels;
276
+ draw();
277
+ })
278
+ .catch((error) => notice(S.choiceFailed(error.message)));
279
+ });
280
+ })
281
+ .catch(() => {
282
+ /* Static previews have no host UI runtime. */
283
+ });
284
+
285
+ return {
286
+ draw,
287
+ readSessionModel,
288
+ prepareStart,
289
+ startChoice: () => startModel,
290
+ clearStartChoice() {
291
+ startModel = null;
292
+ startEffort = null;
293
+ draw();
294
+ },
295
+ needsModel: (deck) => defaultModel === null && !(deck ? deck.model : startModel),
296
+ pick: (start) => void choose(start),
297
+ };
298
+ }
@@ -0,0 +1,90 @@
1
+ import { createRoot } from "react-dom/client";
2
+ import { useState } from "react";
3
+ import { FormPicker, MenuSelectBody, ModelSelect } from "@prismshadow/penguin-ui";
4
+
5
+ export type Model = { provider: string; modelId: string; label?: string };
6
+
7
+ export function mountModelControl(element: HTMLElement, choose: () => void) {
8
+ const root = createRoot(element);
9
+ return (
10
+ model: Model | null,
11
+ label: string,
12
+ name: string,
13
+ disabled: boolean,
14
+ expanded: boolean,
15
+ ) => {
16
+ const display = model?.label || model?.modelId || label;
17
+ element.title = name + " · " + display;
18
+ root.render(
19
+ <ModelSelect
20
+ label={display}
21
+ provider={model?.provider ?? null}
22
+ ariaLabel={name + " · " + display}
23
+ tooltip={name + " · " + display}
24
+ variant="form"
25
+ disabled={disabled}
26
+ muted={!model}
27
+ expanded={expanded}
28
+ onClick={choose}
29
+ />,
30
+ );
31
+ };
32
+ }
33
+
34
+ type Thinking = {
35
+ defaultLevel: string;
36
+ title: string;
37
+ names: Record<string, string>;
38
+ options: Array<{ value: string; label: string }>;
39
+ };
40
+
41
+ function EffortControl({
42
+ levels,
43
+ value,
44
+ disabled,
45
+ pick,
46
+ }: {
47
+ levels: Thinking;
48
+ value: string;
49
+ disabled: boolean;
50
+ pick: (value: string) => void;
51
+ }) {
52
+ const [open, setOpen] = useState(false);
53
+ const name = levels.names[value] ?? value;
54
+ return (
55
+ <FormPicker
56
+ open={open}
57
+ setOpen={setOpen}
58
+ disabled={disabled}
59
+ label={name}
60
+ ariaLabel={levels.title + " · " + name}
61
+ menuClass="w-max min-w-36"
62
+ >
63
+ <MenuSelectBody
64
+ title={levels.title}
65
+ options={levels.options}
66
+ value={value}
67
+ onPick={(level) => {
68
+ setOpen(false);
69
+ pick(level);
70
+ }}
71
+ />
72
+ </FormPicker>
73
+ );
74
+ }
75
+
76
+ export function mountEffortControl(element: HTMLElement, pick: (value: string) => void) {
77
+ const root = createRoot(element);
78
+ return (levels: Thinking | null, pin: string | null, disabled: boolean) => {
79
+ root.render(
80
+ levels && (
81
+ <EffortControl
82
+ levels={levels}
83
+ value={pin || levels.defaultLevel}
84
+ disabled={disabled}
85
+ pick={pick}
86
+ />
87
+ ),
88
+ );
89
+ };
90
+ }