@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.
- package/README.md +37 -0
- package/README.zh.md +37 -0
- package/THIRD-PARTY-NOTICES.md +30 -0
- package/ifaces.json +63 -0
- package/package.json +19 -21
- package/skills/bento-slides/SKILL.md +89 -29
- package/skills/bento-slides/references/bento-agents.md +511 -0
- package/workbenches/slides/index.ts +677 -0
- package/workbenches/slides/package.json +43 -0
- package/workbenches/slides/ui/app.js +1101 -0
- package/workbenches/slides/ui/bridge.js +190 -0
- package/workbenches/slides/ui/conversation-view.js +206 -0
- package/workbenches/slides/ui/conversation.css +95 -0
- package/workbenches/slides/ui/conversation.js +115 -0
- package/workbenches/slides/ui/deck-files.css +279 -0
- package/workbenches/slides/ui/deck-files.js +189 -0
- package/workbenches/slides/ui/file-menu.js +72 -0
- package/workbenches/slides/ui/icon.svg +9 -0
- package/workbenches/slides/ui/index.html +252 -0
- package/workbenches/slides/ui/model-choice.js +298 -0
- package/workbenches/slides/ui/model-control.tsx +90 -0
- package/workbenches/slides/ui/powerpoint.js +196 -0
- package/workbenches/slides/ui/sample.bento.json +33 -0
- package/workbenches/slides/ui/strings.js +184 -0
- package/workbenches/slides/ui/style.css +505 -0
- package/workbenches/slides/ui/sync.js +268 -0
- package/workbenches/slides/ui/template-picker.js +128 -0
- package/workbenches/slides/ui/templates.js +256 -0
- package/workbenches/slides/ui/vendor/LICENSE-bento.txt +21 -0
- package/workbenches/slides/ui/vendor/LICENSE-jszip.txt +25 -0
- package/workbenches/slides/ui/vendor/LICENSE-pptxgen.txt +21 -0
- package/workbenches/slides/ui/vendor/bento-slides-1.2.13.runtime.txt +310 -0
- package/workbenches/slides/ui/vendor/pptxgen-4.0.1.bundle.js +96 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// A workbench can be opened from a LAN host over HTTP, where randomUUID is unavailable.
|
|
2
|
+
export function editorToken() {
|
|
3
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
4
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** The embedded editor starts a sharing room unless the document explicitly turns it off. */
|
|
8
|
+
export function editorDocument(doc) {
|
|
9
|
+
if (typeof globalThis.crypto?.subtle?.generateKey === "function") return doc;
|
|
10
|
+
const local = { ...doc, collab: { on: false } };
|
|
11
|
+
if (local.template) {
|
|
12
|
+
// Bento opens templates as fresh documents and discards their room. Let it assign the
|
|
13
|
+
// new document id while retaining the offline setting for this editor only.
|
|
14
|
+
delete local.template;
|
|
15
|
+
delete local.docId;
|
|
16
|
+
}
|
|
17
|
+
return local;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Installed in the head of the editor and presentation before Bento attaches its own file
|
|
21
|
+
// shortcuts. The standalone HTML download retains the original runtime's file controls.
|
|
22
|
+
export function captureSave(event) {
|
|
23
|
+
if (event.type === "keydown") {
|
|
24
|
+
if (
|
|
25
|
+
!(event.ctrlKey || event.metaKey) ||
|
|
26
|
+
event.altKey ||
|
|
27
|
+
event.shiftKey ||
|
|
28
|
+
event.key.toLowerCase() !== "s"
|
|
29
|
+
)
|
|
30
|
+
return false;
|
|
31
|
+
} else if (!event.target.closest?.("button")?.querySelector(".ed-dirty")) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
event.stopImmediatePropagation();
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function connectSave(token, capture, label) {
|
|
40
|
+
function save(event) {
|
|
41
|
+
if (!capture(event)) return;
|
|
42
|
+
// Bento commits the active text box and table cell on blur, including the last input.
|
|
43
|
+
const active = document.activeElement;
|
|
44
|
+
if (active?.isContentEditable || active?.matches("input, textarea")) active.blur();
|
|
45
|
+
parent.postMessage({ __slides: 1, token, type: "save" }, "*");
|
|
46
|
+
}
|
|
47
|
+
window.addEventListener("keydown", save, true);
|
|
48
|
+
window.addEventListener("click", save, true);
|
|
49
|
+
// The standalone editor's button describes overwriting a disk file. Here it saves to the desk.
|
|
50
|
+
const decorate = () => {
|
|
51
|
+
const dot = document.querySelector(".ed-dirty"),
|
|
52
|
+
button = dot?.closest("button");
|
|
53
|
+
if (!button) return;
|
|
54
|
+
button.title = dot.title = label;
|
|
55
|
+
button.setAttribute("aria-label", label);
|
|
56
|
+
};
|
|
57
|
+
window.addEventListener("DOMContentLoaded", () => {
|
|
58
|
+
decorate();
|
|
59
|
+
new MutationObserver(decorate).observe(document.body, { subtree: true, childList: true });
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Runs INSIDE the editor frame, next to the Bento app: the only code that touches `window.bento`.
|
|
64
|
+
//
|
|
65
|
+
// The frame is sandboxed without `allow-same-origin`, so the workbench page cannot reach into
|
|
66
|
+
// it; the two talk by messages. This script reports the document whenever the person changed it,
|
|
67
|
+
// reports which slide and elements they are on, and loads a document the page hands it. It is
|
|
68
|
+
// written to be read as text and placed in the frame's HTML: one function, no imports. `token`
|
|
69
|
+
// names this mounting of the editor, so a message from a frame the page has since replaced is
|
|
70
|
+
// told apart.
|
|
71
|
+
export function bridge(token, locale) {
|
|
72
|
+
var TAG = "__slides";
|
|
73
|
+
var POLL_MS = 400;
|
|
74
|
+
var EDIT_WAIT_MS = 20000;
|
|
75
|
+
var post = function (message) {
|
|
76
|
+
message[TAG] = 1;
|
|
77
|
+
message.token = token;
|
|
78
|
+
parent.postMessage(message, "*");
|
|
79
|
+
};
|
|
80
|
+
// Everything but the bytes of the pictures: enough to tell that the document changed.
|
|
81
|
+
var signature = function (doc) {
|
|
82
|
+
var assets = doc.assets || {};
|
|
83
|
+
var sizes = Object.keys(assets)
|
|
84
|
+
.sort()
|
|
85
|
+
.map(function (key) {
|
|
86
|
+
return key + ":" + String(assets[key]).length;
|
|
87
|
+
});
|
|
88
|
+
var rest = {};
|
|
89
|
+
for (var key in doc) if (key !== "assets") rest[key] = doc[key];
|
|
90
|
+
return JSON.stringify(rest) + "|" + sizes.join(",");
|
|
91
|
+
};
|
|
92
|
+
var ready = function () {
|
|
93
|
+
return !!(window.bento && typeof window.bento.read === "function" && window.bento.doc);
|
|
94
|
+
};
|
|
95
|
+
var typing = function () {
|
|
96
|
+
var el = document.activeElement;
|
|
97
|
+
return !!(el && (el.isContentEditable || /^(INPUT|TEXTAREA)$/.test(el.tagName)));
|
|
98
|
+
};
|
|
99
|
+
var slideIndex = function () {
|
|
100
|
+
var active = document.querySelector(".ed-thumb.active");
|
|
101
|
+
var index = active ? Number(active.getAttribute("data-index")) : 0;
|
|
102
|
+
return isFinite(index) ? index : 0;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
var last = null;
|
|
106
|
+
var cursor = "";
|
|
107
|
+
var announced = false;
|
|
108
|
+
|
|
109
|
+
function tick() {
|
|
110
|
+
if (!ready()) return;
|
|
111
|
+
var doc = window.bento.read();
|
|
112
|
+
var now = signature(doc);
|
|
113
|
+
if (!announced) {
|
|
114
|
+
const language = window.bento.i18n;
|
|
115
|
+
if (language && language.locale() !== locale) language.setLocale(locale);
|
|
116
|
+
announced = true;
|
|
117
|
+
last = now;
|
|
118
|
+
post({ type: "ready", doc: doc, version: (window.bento.updates || {}).version || null });
|
|
119
|
+
} else if (now !== last) {
|
|
120
|
+
last = now;
|
|
121
|
+
post({ type: "changed", doc: doc });
|
|
122
|
+
}
|
|
123
|
+
var index = slideIndex();
|
|
124
|
+
var selection = (window.bento.selection || []).slice(0, 40);
|
|
125
|
+
var at = index + "|" + selection.join(",");
|
|
126
|
+
if (at !== cursor) {
|
|
127
|
+
cursor = at;
|
|
128
|
+
var slide = (doc.slides || [])[index];
|
|
129
|
+
post({
|
|
130
|
+
type: "cursor",
|
|
131
|
+
index: index,
|
|
132
|
+
slideId: slide ? slide.id : null,
|
|
133
|
+
selection: selection,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// A document from the page replaces the editor's. Not while the person is typing in a text box:
|
|
139
|
+
// replacing the document under a caret throws their sentence away, so it waits for them to
|
|
140
|
+
// leave the box (or long enough that they have stopped).
|
|
141
|
+
function load(id, json, started) {
|
|
142
|
+
if (typing() && Date.now() - started < EDIT_WAIT_MS) {
|
|
143
|
+
setTimeout(function () {
|
|
144
|
+
load(id, json, started);
|
|
145
|
+
}, 250);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
var before = window.bento.read();
|
|
149
|
+
var slide = (before.slides || [])[slideIndex()];
|
|
150
|
+
var report = false;
|
|
151
|
+
try {
|
|
152
|
+
report = window.bento.loadDoc(json);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
report = false;
|
|
155
|
+
}
|
|
156
|
+
var doc = window.bento.read();
|
|
157
|
+
last = signature(doc);
|
|
158
|
+
// Stay on the slide the person was on, when the new document still has it.
|
|
159
|
+
if (slide) {
|
|
160
|
+
var at = (doc.slides || []).findIndex(function (s) {
|
|
161
|
+
return s.id === slide.id;
|
|
162
|
+
});
|
|
163
|
+
var thumb = at >= 0 ? document.querySelector('.ed-thumb[data-index="' + at + '"]') : null;
|
|
164
|
+
if (thumb && at !== slideIndex()) thumb.click();
|
|
165
|
+
}
|
|
166
|
+
post({ type: "loaded", id: id, ok: report !== false, before: before, doc: doc });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
window.addEventListener("message", function (event) {
|
|
170
|
+
var data = event.data;
|
|
171
|
+
if (event.source !== parent || !data || data[TAG] !== 1 || data.token !== token) return;
|
|
172
|
+
if (data.type === "load" && ready()) load(data.id, data.json, Date.now());
|
|
173
|
+
if (data.type === "read" && ready()) {
|
|
174
|
+
const active = document.activeElement;
|
|
175
|
+
if (active?.isContentEditable || active?.matches("input, textarea")) active.blur();
|
|
176
|
+
post({ type: "read", id: data.id, doc: window.bento.read() });
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
tick();
|
|
180
|
+
setInterval(tick, POLL_MS);
|
|
181
|
+
["pointerup", "keyup", "paste", "drop", "focusout"].forEach(function (name) {
|
|
182
|
+
document.addEventListener(
|
|
183
|
+
name,
|
|
184
|
+
function () {
|
|
185
|
+
setTimeout(tick, 80);
|
|
186
|
+
},
|
|
187
|
+
true,
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { turnsFor } from "./conversation.js";
|
|
2
|
+
|
|
3
|
+
const labels = {
|
|
4
|
+
en: {
|
|
5
|
+
running: "Working",
|
|
6
|
+
reading: "Reading a file",
|
|
7
|
+
executing: "Running a command",
|
|
8
|
+
waiting: "Approval needed",
|
|
9
|
+
allow: "Allow",
|
|
10
|
+
deny: "Deny",
|
|
11
|
+
queued: "Queued",
|
|
12
|
+
completed: "Completed",
|
|
13
|
+
failed: "Failed",
|
|
14
|
+
interrupted: "Stopped",
|
|
15
|
+
thinking: "Thinking",
|
|
16
|
+
tool: "Tool call",
|
|
17
|
+
tools: {
|
|
18
|
+
exec_command: "Run command",
|
|
19
|
+
read_file: "Read file",
|
|
20
|
+
write_file: "Write file",
|
|
21
|
+
edit_file: "Edit file",
|
|
22
|
+
run_subagent: "Consult an assistant",
|
|
23
|
+
},
|
|
24
|
+
input: "Arguments",
|
|
25
|
+
output: "Result",
|
|
26
|
+
retry: "Retry",
|
|
27
|
+
stopped: "Stopped",
|
|
28
|
+
cancelled: "Stopped",
|
|
29
|
+
aborted: "Stopped",
|
|
30
|
+
},
|
|
31
|
+
zh: {
|
|
32
|
+
running: "处理中",
|
|
33
|
+
reading: "正在读取文件",
|
|
34
|
+
executing: "正在运行命令",
|
|
35
|
+
waiting: "需要批准",
|
|
36
|
+
allow: "允许",
|
|
37
|
+
deny: "拒绝",
|
|
38
|
+
queued: "排队中",
|
|
39
|
+
completed: "已完成",
|
|
40
|
+
failed: "失败",
|
|
41
|
+
interrupted: "已停止",
|
|
42
|
+
thinking: "思考",
|
|
43
|
+
tool: "工具调用",
|
|
44
|
+
tools: {
|
|
45
|
+
exec_command: "运行命令",
|
|
46
|
+
read_file: "读取文件",
|
|
47
|
+
write_file: "写入文件",
|
|
48
|
+
edit_file: "编辑文件",
|
|
49
|
+
run_subagent: "调用子助手",
|
|
50
|
+
},
|
|
51
|
+
input: "参数",
|
|
52
|
+
output: "结果",
|
|
53
|
+
retry: "重试",
|
|
54
|
+
stopped: "已停止",
|
|
55
|
+
cancelled: "已停止",
|
|
56
|
+
aborted: "已停止",
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
function element(tag, cls, text) {
|
|
60
|
+
const el = document.createElement(tag);
|
|
61
|
+
if (cls) el.className = cls;
|
|
62
|
+
if (text) el.textContent = text;
|
|
63
|
+
return el;
|
|
64
|
+
}
|
|
65
|
+
function details(label, key, opened, cls = "turn-step") {
|
|
66
|
+
const item = element("details", cls);
|
|
67
|
+
item.dataset.disclosure = key;
|
|
68
|
+
item.open = opened.has(key);
|
|
69
|
+
item.append(element("summary", "", label));
|
|
70
|
+
return item;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function showConversation(list, messages, trace, options) {
|
|
74
|
+
const { locale, running, hint, retry, approvals = [], decidingCalls, decide } = options;
|
|
75
|
+
const S = labels[locale] || labels.en;
|
|
76
|
+
const stick = list.scrollHeight - list.clientHeight - list.scrollTop < 40;
|
|
77
|
+
const previous = list.scrollTop;
|
|
78
|
+
const opened = new Set(
|
|
79
|
+
[...list.querySelectorAll("details[open]")].map((el) => el.dataset.disclosure),
|
|
80
|
+
);
|
|
81
|
+
const scrolled = [...list.querySelectorAll("details[open] pre")].map((el) => el.scrollTop);
|
|
82
|
+
const focused = document.activeElement?.closest("details")?.dataset.disclosure;
|
|
83
|
+
const grouped = turnsFor(messages, trace);
|
|
84
|
+
const runningTurn = trace.current?.status === "running" ? trace.current : null;
|
|
85
|
+
const out = document.createDocumentFragment();
|
|
86
|
+
let row,
|
|
87
|
+
prompt = "";
|
|
88
|
+
for (const [i, msg] of messages.entries()) {
|
|
89
|
+
if (msg.role !== "user") {
|
|
90
|
+
if (!row) {
|
|
91
|
+
row = element("li", "conversation-turn");
|
|
92
|
+
out.append(row);
|
|
93
|
+
}
|
|
94
|
+
const traceTurn = grouped.get(i - 1);
|
|
95
|
+
const last = traceTurn?.parts.at(-1);
|
|
96
|
+
if (msg.role === "assistant" && last?.kind === "text" && last.text.trim() === msg.text.trim())
|
|
97
|
+
continue;
|
|
98
|
+
if (msg.role !== "error" || traceTurn?.error !== msg.text)
|
|
99
|
+
row.append(element("div", msg.role === "error" ? "turn-error" : "turn-answer", msg.text));
|
|
100
|
+
if (msg.role === "error" && prompt) addRetry(row, prompt);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
row = element("li", "conversation-turn");
|
|
104
|
+
out.append(row);
|
|
105
|
+
prompt = msg.text;
|
|
106
|
+
row.append(element("div", "me", prompt));
|
|
107
|
+
const turn = grouped.get(i);
|
|
108
|
+
const next = messages[i + 1];
|
|
109
|
+
const status =
|
|
110
|
+
turn?.status ??
|
|
111
|
+
(next && next.role !== "user"
|
|
112
|
+
? next.role === "error"
|
|
113
|
+
? "failed"
|
|
114
|
+
: "completed"
|
|
115
|
+
: running
|
|
116
|
+
? runningTurn
|
|
117
|
+
? "queued"
|
|
118
|
+
: "running"
|
|
119
|
+
: null);
|
|
120
|
+
const active = status === "running" || status === "queued";
|
|
121
|
+
const parts = turn?.parts || [];
|
|
122
|
+
const waiting = runningTurn && turn === runningTurn ? approvals : [];
|
|
123
|
+
const last = parts.at(-1);
|
|
124
|
+
let state = S[status] || status;
|
|
125
|
+
if (waiting.length) state = S.waiting;
|
|
126
|
+
else if (active && last?.kind === "thinking") state = S.thinking;
|
|
127
|
+
else if (active && last?.kind === "tool" && last.status === "running") {
|
|
128
|
+
if (last.name === "read_file") state = S.reading;
|
|
129
|
+
else if (last.name === "exec_command") state = S.executing;
|
|
130
|
+
else state = S.tools[last.name] || S.running;
|
|
131
|
+
}
|
|
132
|
+
// The optimistic user message gets its server timestamp on the next poll.
|
|
133
|
+
// The Session task timestamp stays the same for the entire trace.
|
|
134
|
+
const key = turn?.at || msg.at || String(i);
|
|
135
|
+
let group;
|
|
136
|
+
if (waiting.length || parts.some((part) => part.kind !== "text")) {
|
|
137
|
+
group = details(state, key, opened, "turn-history");
|
|
138
|
+
group.firstElementChild.className = "turn-state";
|
|
139
|
+
row.append(group);
|
|
140
|
+
} else if (state) row.append(element("span", "turn-state", state));
|
|
141
|
+
for (const { tool_call: call } of waiting) {
|
|
142
|
+
const actions = element("div", "turn-approval");
|
|
143
|
+
actions.append(element("span", "", S.tools[call.name] || call.name || S.tool));
|
|
144
|
+
// Show the actual request before asking to authorize it, including the command or file.
|
|
145
|
+
const args =
|
|
146
|
+
typeof call.arguments === "string" ? call.arguments : JSON.stringify(call.arguments);
|
|
147
|
+
if (args) actions.append(element("pre", "", args));
|
|
148
|
+
for (const decision of ["allow", "deny"]) {
|
|
149
|
+
const btn = element("button", "", S[decision]);
|
|
150
|
+
btn.type = "button";
|
|
151
|
+
btn.disabled = decidingCalls?.has(call.tool_call_id) ?? false;
|
|
152
|
+
btn.onclick = () => decide(call.tool_call_id, decision);
|
|
153
|
+
actions.append(btn);
|
|
154
|
+
}
|
|
155
|
+
group.append(actions);
|
|
156
|
+
}
|
|
157
|
+
for (const [j, part] of parts.entries()) {
|
|
158
|
+
if (part.kind === "text") {
|
|
159
|
+
if (part.text)
|
|
160
|
+
(group && part !== last ? group : row).append(element("div", "turn-answer", part.text));
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const item = details(
|
|
164
|
+
part.kind === "tool" ? (S.tools[part.name] ?? part.name) || S.tool : S.thinking,
|
|
165
|
+
key + "-" + j,
|
|
166
|
+
opened,
|
|
167
|
+
);
|
|
168
|
+
if (part.kind === "thinking") item.append(element("div", "turn-thought", part.text));
|
|
169
|
+
else {
|
|
170
|
+
if (S.tools[part.name]) item.firstElementChild.title = part.name;
|
|
171
|
+
if (part.input) item.append(element("small", "", S.input), element("pre", "", part.input));
|
|
172
|
+
if (part.output || part.status !== "running") {
|
|
173
|
+
item.append(
|
|
174
|
+
element("small", "", S.output + (part.status === "failed" ? " · " + S.failed : "")),
|
|
175
|
+
element("pre", "", part.output),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
group.append(item);
|
|
180
|
+
}
|
|
181
|
+
if (turn?.error) row.append(element("div", "turn-error", turn.error));
|
|
182
|
+
if (
|
|
183
|
+
(status === "failed" || status === "interrupted" || status === "aborted") &&
|
|
184
|
+
next?.role !== "error"
|
|
185
|
+
)
|
|
186
|
+
addRetry(row, prompt);
|
|
187
|
+
}
|
|
188
|
+
if (!messages.length) out.append(element("li", "hint", hint));
|
|
189
|
+
list.replaceChildren(out);
|
|
190
|
+
[...list.querySelectorAll("details[open] pre")].forEach((el, i) => {
|
|
191
|
+
el.scrollTop = scrolled[i] || 0;
|
|
192
|
+
});
|
|
193
|
+
if (focused)
|
|
194
|
+
list
|
|
195
|
+
.querySelector('[data-disclosure="' + CSS.escape(focused) + '"] > summary')
|
|
196
|
+
?.focus({ preventScroll: true });
|
|
197
|
+
list.scrollTop = stick ? list.scrollHeight : previous;
|
|
198
|
+
|
|
199
|
+
function addRetry(target, text) {
|
|
200
|
+
const action = element("button", "turn-retry", S.retry);
|
|
201
|
+
action.type = "button";
|
|
202
|
+
action.disabled = running;
|
|
203
|
+
action.addEventListener("click", () => retry(text));
|
|
204
|
+
target.append(action);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
.talk .conversation-turn {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-flow: column;
|
|
4
|
+
gap: 0.5rem;
|
|
5
|
+
min-width: 0;
|
|
6
|
+
white-space: normal;
|
|
7
|
+
}
|
|
8
|
+
.conversation-turn + .conversation-turn {
|
|
9
|
+
margin-top: 0.8rem;
|
|
10
|
+
}
|
|
11
|
+
.conversation-turn .me,
|
|
12
|
+
.turn-answer,
|
|
13
|
+
.turn-thought,
|
|
14
|
+
.turn-error {
|
|
15
|
+
white-space: pre-wrap;
|
|
16
|
+
overflow-wrap: anywhere;
|
|
17
|
+
}
|
|
18
|
+
.turn-state,
|
|
19
|
+
.turn-step small {
|
|
20
|
+
color: var(--wb-muted);
|
|
21
|
+
font-size: 0.77rem;
|
|
22
|
+
}
|
|
23
|
+
.turn-step {
|
|
24
|
+
min-width: 0;
|
|
25
|
+
align-self: stretch;
|
|
26
|
+
border-inline-start: 2px solid var(--wb-line);
|
|
27
|
+
padding-inline-start: 0.65rem;
|
|
28
|
+
}
|
|
29
|
+
.turn-history > summary,
|
|
30
|
+
.turn-step summary {
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
width: fit-content;
|
|
33
|
+
max-width: 100%;
|
|
34
|
+
overflow-wrap: anywhere;
|
|
35
|
+
}
|
|
36
|
+
.turn-history > summary:focus-visible,
|
|
37
|
+
.turn-step summary:focus-visible,
|
|
38
|
+
.turn-retry:focus-visible {
|
|
39
|
+
outline: 2px solid currentColor;
|
|
40
|
+
outline-offset: 2px;
|
|
41
|
+
}
|
|
42
|
+
.turn-step[open] > :not(summary) {
|
|
43
|
+
margin-block: 0.4rem;
|
|
44
|
+
}
|
|
45
|
+
.turn-step small {
|
|
46
|
+
display: block;
|
|
47
|
+
}
|
|
48
|
+
.turn-step pre {
|
|
49
|
+
white-space: pre-wrap;
|
|
50
|
+
overflow-wrap: anywhere;
|
|
51
|
+
margin: 0;
|
|
52
|
+
max-height: 16rem;
|
|
53
|
+
overflow: auto;
|
|
54
|
+
font-size: 0.8rem;
|
|
55
|
+
}
|
|
56
|
+
.turn-error {
|
|
57
|
+
color: var(--wb-danger, var(--wb-fg));
|
|
58
|
+
}
|
|
59
|
+
.turn-retry {
|
|
60
|
+
align-self: flex-start;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.turn-history > .turn-step {
|
|
64
|
+
margin-block-start: 0.4rem;
|
|
65
|
+
margin-inline-start: 0.4rem;
|
|
66
|
+
}
|
|
67
|
+
.turn-approval pre {
|
|
68
|
+
white-space: pre-wrap;
|
|
69
|
+
overflow-wrap: anywhere;
|
|
70
|
+
max-height: 12rem;
|
|
71
|
+
overflow: auto;
|
|
72
|
+
}
|
|
73
|
+
.turn-approval button + button {
|
|
74
|
+
margin-inline-start: 0.4rem;
|
|
75
|
+
}
|
|
76
|
+
.turn-step summary {
|
|
77
|
+
font-weight: 550;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.chat-model {
|
|
81
|
+
flex: 0 1 10.5rem;
|
|
82
|
+
min-width: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Full-screen workbenches carry an exit control at the lower right. */
|
|
86
|
+
.rail .ask-actions {
|
|
87
|
+
padding-inline-end: 2.75rem;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.ask-actions {
|
|
91
|
+
flex-wrap: wrap;
|
|
92
|
+
}
|
|
93
|
+
.chat-effort {
|
|
94
|
+
flex: 0 1 auto;
|
|
95
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// SessionReader sends durable history first, then live trace records in the same
|
|
2
|
+
// order. A reset discards the projection and lets the SDK replay the Session.
|
|
3
|
+
export function newConversation() {
|
|
4
|
+
return { turns: [], current: null };
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function readConversation(model, record) {
|
|
8
|
+
const p = record.payload;
|
|
9
|
+
if (record.origin?.length || !p?.type) return;
|
|
10
|
+
if (p.type === "task_begin") {
|
|
11
|
+
const turn = {
|
|
12
|
+
prompt: "",
|
|
13
|
+
status: "running",
|
|
14
|
+
at: record.timestamp,
|
|
15
|
+
parts: [],
|
|
16
|
+
calls: new Map(),
|
|
17
|
+
compacting: false,
|
|
18
|
+
};
|
|
19
|
+
model.turns.push(turn);
|
|
20
|
+
model.current = turn;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const turn = model.current;
|
|
24
|
+
if (!turn) return;
|
|
25
|
+
if (p.type === "text" && p.role === "user") {
|
|
26
|
+
const prefix = "\nTheir request: ";
|
|
27
|
+
const suffix = "\nUse the bento-slides skill.";
|
|
28
|
+
const begin = p.text.indexOf(prefix),
|
|
29
|
+
end = p.text.lastIndexOf(suffix);
|
|
30
|
+
turn.prompt = begin >= 0 && end > begin ? p.text.slice(begin + prefix.length, end) : p.text;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (p.type === "compaction_begin" || p.type === "compaction_end") {
|
|
34
|
+
turn.compacting = p.type === "compaction_begin";
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (p.type === "request_begin") {
|
|
38
|
+
turn.failure = null;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (p.type === "request_end" && p.status !== "completed" && p.retry_in_ms === undefined) {
|
|
42
|
+
turn.failure = { status: "failed", error: p.error_message || "" };
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (p.type === "abort") {
|
|
46
|
+
turn.failure = { status: "interrupted", error: p.error_message || p.reason || "" };
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (p.type === "task_end") {
|
|
50
|
+
Object.assign(turn, turn.failure ?? { status: "completed" });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (turn.compacting || turn.status !== "running") return;
|
|
54
|
+
if (["partial_thinking", "thinking", "partial_text", "text"].includes(p.type)) {
|
|
55
|
+
if (p.role !== "assistant") return;
|
|
56
|
+
const kind = p.type.endsWith("thinking") ? "thinking" : "text";
|
|
57
|
+
const partial = p.type.startsWith("partial_");
|
|
58
|
+
const value = kind === "thinking" ? p.thinking : p.text;
|
|
59
|
+
let part = turn.parts.at(-1);
|
|
60
|
+
if (p.event_type === "stop") return;
|
|
61
|
+
if (!part || part.kind !== kind || !part.partial) {
|
|
62
|
+
part = { kind, text: "", partial: true };
|
|
63
|
+
turn.parts.push(part);
|
|
64
|
+
}
|
|
65
|
+
if (!partial || p.event_type === "start") part.text = value || "";
|
|
66
|
+
else if (value) part.text += value;
|
|
67
|
+
part.partial = partial;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (
|
|
71
|
+
!["partial_tool_call", "tool_call", "partial_tool_call_output", "tool_call_output"].includes(
|
|
72
|
+
p.type,
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
return;
|
|
76
|
+
const id = p.tool_call_id;
|
|
77
|
+
const isResult = p.type.endsWith("output");
|
|
78
|
+
let call = turn.calls.get(id);
|
|
79
|
+
if (!call || (!isResult && call.complete)) {
|
|
80
|
+
call = { kind: "tool", name: "", input: "", output: "", complete: false, status: "running" };
|
|
81
|
+
turn.parts.push(call);
|
|
82
|
+
turn.calls.set(id, call);
|
|
83
|
+
}
|
|
84
|
+
if (p.name) call.name = p.name;
|
|
85
|
+
const key = isResult ? "output" : "input";
|
|
86
|
+
const data = isResult ? p.output : p.arguments;
|
|
87
|
+
if (!p.type.startsWith("partial_") || p.event_type === "start") {
|
|
88
|
+
call[key] = typeof data === "string" ? data : data == null ? "" : JSON.stringify(data, null, 2);
|
|
89
|
+
} else if (p.event_type === "delta" && typeof data === "string") call[key] += data;
|
|
90
|
+
if (p.type === "tool_call") call.complete = true;
|
|
91
|
+
if (p.type === "tool_call_output") call.status = p.status || "completed";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Match backwards so an older, trimmed duplicate of the same prompt cannot
|
|
95
|
+
// take the newer turn. The workbench stores the person's text, without its
|
|
96
|
+
// internal deck path and instructions. SessionReader supplies the visible work.
|
|
97
|
+
export function turnsFor(messages, trace) {
|
|
98
|
+
const linked = new Map();
|
|
99
|
+
let end = trace.turns.length;
|
|
100
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
101
|
+
if (messages[i].role !== "user") continue;
|
|
102
|
+
for (let j = end - 1; j >= 0; j--) {
|
|
103
|
+
const turn = trace.turns[j];
|
|
104
|
+
if (
|
|
105
|
+
turn.prompt !== messages[i].text ||
|
|
106
|
+
(turn.at && messages[i].at && turn.at < messages[i].at)
|
|
107
|
+
)
|
|
108
|
+
continue;
|
|
109
|
+
linked.set(i, trace.turns[j]);
|
|
110
|
+
end = j;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return linked;
|
|
115
|
+
}
|