deictic 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.
Files changed (166) hide show
  1. package/API.md +303 -0
  2. package/README.md +56 -104
  3. package/dist/annotations/index.d.ts +1 -1
  4. package/dist/astro.d.ts +1 -1
  5. package/dist/bun.d.ts +1 -1
  6. package/dist/bun.js +2 -2
  7. package/dist/client/index.d.ts +4 -2
  8. package/dist/client/index.d.ts.map +1 -1
  9. package/dist/client/index.js +130 -16
  10. package/dist/client/index.js.map +1 -1
  11. package/dist/index.d.ts +21 -218
  12. package/dist/index.js.map +1 -1
  13. package/dist/loader.js +1 -1
  14. package/dist/logs/client.d.ts +4 -0
  15. package/dist/logs/client.d.ts.map +1 -0
  16. package/dist/logs/client.js +16 -0
  17. package/dist/logs/client.js.map +1 -0
  18. package/dist/logs/index.d.ts +18 -0
  19. package/dist/logs/index.d.ts.map +1 -0
  20. package/dist/logs/index.js +21 -0
  21. package/dist/logs/index.js.map +1 -0
  22. package/dist/network/client.d.ts +4 -0
  23. package/dist/network/client.d.ts.map +1 -0
  24. package/dist/network/client.js +29 -0
  25. package/dist/network/client.js.map +1 -0
  26. package/dist/network/index.d.ts +2 -0
  27. package/dist/network/index.js +39 -0
  28. package/dist/network/index.js.map +1 -0
  29. package/dist/next.d.ts +1 -1
  30. package/dist/next.js +2 -2
  31. package/dist/recommended/index.d.ts +15 -5
  32. package/dist/recommended/index.d.ts.map +1 -1
  33. package/dist/recommended/index.js +10 -3
  34. package/dist/recommended/index.js.map +1 -1
  35. package/dist/recordings/client.d.ts +1 -1
  36. package/dist/recordings/client.d.ts.map +1 -1
  37. package/dist/recordings/client.js +177 -48
  38. package/dist/recordings/client.js.map +1 -1
  39. package/dist/recordings/index.d.ts +2 -2
  40. package/dist/recordings/index.js +3 -3
  41. package/dist/screenshots/client.d.ts +7 -1
  42. package/dist/screenshots/client.d.ts.map +1 -1
  43. package/dist/screenshots/client.js +36 -4
  44. package/dist/screenshots/client.js.map +1 -1
  45. package/dist/screenshots/dom.d.ts +1 -1
  46. package/dist/screenshots/dom.d.ts.map +1 -1
  47. package/dist/screenshots/dom.js +1 -28
  48. package/dist/screenshots/dom.js.map +1 -1
  49. package/dist/screenshots/index.d.ts +1 -1
  50. package/dist/screenshots/index.js +2 -2
  51. package/dist/screenshots/index.js.map +1 -1
  52. package/dist/screenshots/rrweb.d.ts +2 -2
  53. package/dist/screenshots/rrweb.js +5 -1
  54. package/dist/screenshots/rrweb.js.map +1 -1
  55. package/dist/{endpoints.js → shared/endpoints.js} +1 -1
  56. package/dist/shared/endpoints.js.map +1 -0
  57. package/dist/shared/index.d.ts +238 -0
  58. package/dist/shared/index.d.ts.map +1 -0
  59. package/dist/{index3.d.ts → shared/index2.d.ts} +3 -1
  60. package/dist/shared/index2.d.ts.map +1 -0
  61. package/dist/shared/index3.d.ts +112 -0
  62. package/dist/shared/index3.d.ts.map +1 -0
  63. package/dist/shared/index4.d.ts +64 -0
  64. package/dist/shared/index4.d.ts.map +1 -0
  65. package/dist/shared/index5.d.ts +220 -0
  66. package/dist/shared/index5.d.ts.map +1 -0
  67. package/dist/{index5.d.ts → shared/index6.d.ts} +2 -2
  68. package/dist/shared/index6.d.ts.map +1 -0
  69. package/dist/{integration.d.ts → shared/integration.d.ts} +4 -3
  70. package/dist/shared/integration.d.ts.map +1 -0
  71. package/dist/{integration.js → shared/integration.js} +5 -3
  72. package/dist/shared/integration.js.map +1 -0
  73. package/dist/{kept.js → shared/kept.js} +2 -2
  74. package/dist/shared/kept.js.map +1 -0
  75. package/dist/{marks.js → shared/marks.js} +6 -1
  76. package/dist/shared/marks.js.map +1 -0
  77. package/dist/shared/mask.js +107 -0
  78. package/dist/shared/mask.js.map +1 -0
  79. package/dist/{playwright.js → shared/playwright.js} +19 -4
  80. package/dist/shared/playwright.js.map +1 -0
  81. package/dist/shared/recordings.js +437 -0
  82. package/dist/shared/recordings.js.map +1 -0
  83. package/dist/shared/shortcut.js.map +1 -0
  84. package/dist/shared/tasks.js +632 -0
  85. package/dist/shared/tasks.js.map +1 -0
  86. package/dist/shared/waveform.js.map +1 -0
  87. package/dist/tailwind/client.d.ts +1 -1
  88. package/dist/tailwind/index.d.ts +1 -1
  89. package/dist/tasks/client.d.ts +1 -1
  90. package/dist/tasks/client.d.ts.map +1 -1
  91. package/dist/tasks/client.js +272 -57
  92. package/dist/tasks/client.js.map +1 -1
  93. package/dist/tasks/index.d.ts +2 -159
  94. package/dist/tasks/index.js +1 -348
  95. package/dist/vite.d.ts +11 -12
  96. package/dist/vite.d.ts.map +1 -1
  97. package/dist/vite.js +21 -4
  98. package/dist/vite.js.map +1 -1
  99. package/dist/voice/client.d.ts.map +1 -1
  100. package/dist/voice/client.js +36 -15
  101. package/dist/voice/client.js.map +1 -1
  102. package/dist/voice/index.d.ts +6 -1
  103. package/dist/voice/index.d.ts.map +1 -1
  104. package/dist/voice/index.js +13 -3
  105. package/dist/voice/index.js.map +1 -1
  106. package/dist/webpack.d.ts +1 -1
  107. package/dist/webpack.js +2 -2
  108. package/package.json +41 -2
  109. package/skills/deictic/SKILL.md +20 -14
  110. package/skills/deictic/references/install.md +32 -10
  111. package/skills/deictic/references/recordings.md +29 -0
  112. package/skills/deictic/references/tasks.md +49 -21
  113. package/skills/deictic/references/watch.md +38 -11
  114. package/skills/deictic/scripts/lib.mjs +88 -4
  115. package/skills/deictic/scripts/recording.mjs +84 -4
  116. package/skills/deictic/scripts/task.mjs +36 -7
  117. package/skills/deictic/scripts/vb.mjs +12 -0
  118. package/skills/deictic/scripts/watch.mjs +74 -10
  119. package/src/client/away.ts +105 -0
  120. package/src/client/index.ts +60 -16
  121. package/src/client/style.ts +1 -0
  122. package/src/index.ts +21 -2
  123. package/src/plugins/logs/client.ts +18 -0
  124. package/src/plugins/logs/index.ts +55 -0
  125. package/src/plugins/network/client.ts +30 -0
  126. package/src/plugins/network/index.ts +69 -0
  127. package/src/plugins/network/mask.ts +133 -0
  128. package/src/plugins/recommended/index.ts +14 -1
  129. package/src/plugins/recordings/client.ts +220 -40
  130. package/src/plugins/recordings/index.ts +111 -25
  131. package/src/plugins/recordings/marks.ts +6 -0
  132. package/src/plugins/recordings/replay.ts +159 -10
  133. package/src/plugins/screenshots/client.ts +38 -2
  134. package/src/plugins/screenshots/dom.ts +1 -32
  135. package/src/plugins/screenshots/index.ts +2 -0
  136. package/src/plugins/screenshots/playwright.ts +15 -4
  137. package/src/plugins/screenshots/rrweb.ts +2 -1
  138. package/src/plugins/tasks/client.ts +273 -41
  139. package/src/plugins/tasks/index.ts +207 -47
  140. package/src/plugins/tasks/local.ts +170 -0
  141. package/src/plugins/tasks/watchers.ts +36 -0
  142. package/src/plugins/voice/client.ts +33 -10
  143. package/src/plugins/voice/index.ts +21 -4
  144. package/src/tools/integration.ts +5 -3
  145. package/src/tools/kept.ts +2 -2
  146. package/src/vite.ts +23 -4
  147. package/dist/endpoints.js.map +0 -1
  148. package/dist/index.d.ts.map +0 -1
  149. package/dist/index2.d.ts +0 -23
  150. package/dist/index3.d.ts.map +0 -1
  151. package/dist/index4.d.ts +0 -74
  152. package/dist/index4.d.ts.map +0 -1
  153. package/dist/index5.d.ts.map +0 -1
  154. package/dist/integration.d.ts.map +0 -1
  155. package/dist/integration.js.map +0 -1
  156. package/dist/kept.js.map +0 -1
  157. package/dist/marks.js.map +0 -1
  158. package/dist/playwright.js.map +0 -1
  159. package/dist/recordings.js +0 -235
  160. package/dist/recordings.js.map +0 -1
  161. package/dist/shortcut.js.map +0 -1
  162. package/dist/tasks/index.d.ts.map +0 -1
  163. package/dist/tasks/index.js.map +0 -1
  164. package/dist/waveform.js.map +0 -1
  165. /package/dist/{shortcut.js → shared/shortcut.js} +0 -0
  166. /package/dist/{waveform.js → shared/waveform.js} +0 -0
@@ -1,348 +1 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { Refusal, definePlugin } from "../index.js";
4
- // src/plugins/tasks/index.ts
5
- /**
6
- * `deictic/tasks`: open its tab on an element to add a task about it to a Vercel Board
7
- * (`@vercel/board`). The task says what to change, in the words typed, and where: the element's file,
8
- * line and tag, the page and the project, all as labels beside the short facts (viewport, how many, where
9
- * it is in the shot). Whatever works the board's tasks (a person, or an agent of theirs claiming them) takes it
10
- * from there; deictic only adds them.
11
- *
12
- * Adding one is a change like any other: undo cancels the task, while no one has claimed it, and redo
13
- * adds it again, as a new task. Each task carries `deictic.at=<file:line:column>`, so the panel
14
- * lists the ones about the element clicked, until its line moves.
15
- */
16
- const AT = "deictic.at";
17
- /** What parts what was typed from the rest of a task's text. */
18
- const REST = "\n---\n";
19
- const OPEN = /* @__PURE__ */ new Set([
20
- "waiting",
21
- "ready",
22
- "blocked"
23
- ]);
24
- function tasks(options = {}) {
25
- const channel = options.channel ?? "deictic";
26
- let team;
27
- const boardOf = () => team ??= options.board ? Promise.resolve(options.board) : import("@vercel/board").then((m) => m.board());
28
- let link;
29
- const linkOf = () => link ??= (options.link ? Promise.resolve(options.link(channel)) : boardOf().then((b) => localPage(b, channel))).catch(() => {
30
- link = void 0;
31
- });
32
- /** A task's page: what `link` says, or its thread on the channel's own page on this machine. */
33
- const taskLink = (page, id) => options.link ? options.link(channel, id) : page === void 0 ? void 0 : `${page}?thread=${encodeURIComponent(id)}`;
34
- /**
35
- * One of this channel's tasks about an element, while it's still open: the page names it by ID, so
36
- * nothing else on the board is its to change, nor a task someone has taken up.
37
- */
38
- const openTask = async (team, id, verb) => {
39
- const { message } = await team.thread(id);
40
- if (message.channel !== channel || message.labels[AT] === void 0) throw new Refusal(`#${id} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
41
- const { task } = message;
42
- if (task !== void 0 && !OPEN.has(task.state)) throw new Refusal(`task ${id} is ${task.state}${task.claim ? ` by ${task.claim.actor}` : ""} now: ${verb} it on the board if you still mean to`);
43
- return message;
44
- };
45
- /** Cancels an open task of ours, and answers it as it was. */
46
- const cancel = async (id, reason) => {
47
- const team = await boardOf();
48
- const message = await openTask(team, id, "cancel");
49
- await team.tasks.cancel(id, reason);
50
- return message;
51
- };
52
- /** Puts a task's text from one to the other, unless it reads as neither any more. */
53
- const rewrite = async (id, from, to) => {
54
- const team = await boardOf();
55
- const message = await openTask(team, id, "edit");
56
- if (message.text === to) return;
57
- if (message.text !== from) throw new Refusal(`task ${id} has been edited since: change it on the board`);
58
- await team.edit(id, to, { revision: message.revision });
59
- };
60
- const create = async (record) => {
61
- const { task } = await (await boardOf()).tasks.create(record.channel, {
62
- text: record.text,
63
- labels: record.labels,
64
- ...record.attachments === void 0 ? {} : { attachments: record.attachments }
65
- });
66
- return {
67
- ...record,
68
- id: task.id
69
- };
70
- };
71
- let context;
72
- let project = options.project;
73
- /** The screenshots and recordings to attach, uploaded to the board, or nothing when there are none. */
74
- const attach = async (op) => {
75
- const files = [
76
- ...(op.screenshots ?? []).map(({ id }) => {
77
- const shot = context?.use("screenshots")?.read(id);
78
- if (shot === void 0) throw new Refusal(`screenshot ${id} isn't kept any more: take it again`);
79
- return shot;
80
- }),
81
- ...(op.recordings ?? []).map(({ id }) => {
82
- const recording = context?.use("recordings")?.read(id);
83
- if (recording === void 0) throw new Refusal(`recording ${id} isn't kept any more: record it again`);
84
- return recording;
85
- }),
86
- ...[...(op.recordings ?? []).flatMap((r) => r.voice ?? []), ...(op.voice ?? []).map((v) => v.id)].map((id) => {
87
- const clip = context?.use("voice")?.read(id);
88
- if (clip === void 0) throw new Refusal(`voice clip ${id} isn't kept any more: record it again`);
89
- return clip;
90
- })
91
- ];
92
- if (files.length === 0) return void 0;
93
- const team = await boardOf();
94
- return Promise.all(files.map(async (file) => (await team.upload(file)).id));
95
- };
96
- return definePlugin({
97
- name: "tasks",
98
- client: "deictic/tasks/client",
99
- shortcut: options.shortcut,
100
- setup: (given) => {
101
- context = given;
102
- project ??= nameOf(given.root);
103
- },
104
- read: (_source, target) => asked(async () => {
105
- const [{ tasks: found }, page] = await Promise.all([(await boardOf()).tasks.list({
106
- channel,
107
- label: { [AT]: atOf(target) },
108
- state: "all"
109
- }), linkOf()]);
110
- return {
111
- channel,
112
- ...page === void 0 ? {} : { link: page },
113
- tasks: found.map(({ message }) => {
114
- const text = message.text.split(REST, 1)[0];
115
- const state = message.task?.state ?? "ready";
116
- const to = taskLink(page, message.id);
117
- return {
118
- id: message.id,
119
- title: text.split("\n", 1)[0],
120
- text,
121
- state,
122
- open: OPEN.has(state),
123
- ...to === void 0 ? {} : { link: to }
124
- };
125
- }).filter((t) => t.state !== "canceled")
126
- };
127
- }),
128
- apply: (source, target, op) => {
129
- if ("remove" in op) return asked(async () => {
130
- const message = await cancel(op.remove, "deleted in deictic");
131
- const labels = Object.fromEntries(Object.entries(message.labels).filter(([key]) => !key.startsWith("board.")));
132
- const attachments = message.attachments.map((a) => a.id);
133
- return { done: {
134
- kind: "removed",
135
- channel,
136
- id: op.remove,
137
- text: message.text,
138
- labels,
139
- ...attachments.length === 0 ? {} : { attachments }
140
- } };
141
- });
142
- if (op.text.trim() === "" && ("edit" in op || shown(op) === void 0)) throw new Refusal("say what should change first");
143
- if ("edit" in op) return asked(async () => {
144
- const before = (await openTask(await boardOf(), op.edit, "edit")).text;
145
- const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : "";
146
- const after = clip(op.text.trim(), 1e4 - rest.length) + rest;
147
- await rewrite(op.edit, before, after);
148
- return { done: {
149
- kind: "edited",
150
- id: op.edit,
151
- before,
152
- after
153
- } };
154
- });
155
- const labels = {
156
- ...options.labels,
157
- ...project === void 0 ? {} : { "deictic.project": clip(project, LABEL) },
158
- ...labelsOf(source, target, op)
159
- };
160
- return asked(async () => {
161
- const attachments = await attach(op);
162
- return { done: await create({
163
- channel,
164
- text: textOf(op),
165
- labels,
166
- ...attachments === void 0 ? {} : { attachments }
167
- }) };
168
- });
169
- },
170
- undo: (record) => asked(async () => {
171
- if (!("kind" in record)) {
172
- await cancel(record.id, "undone in deictic");
173
- return;
174
- }
175
- if (record.kind === "edited") {
176
- await rewrite(record.id, record.after, record.before);
177
- return;
178
- }
179
- const { kind, id: _, ...task } = record;
180
- return {
181
- kind,
182
- ...await create(task)
183
- };
184
- }),
185
- redo: (record) => asked(async () => {
186
- if (!("kind" in record)) {
187
- const { id: _, ...added } = record;
188
- return create(added);
189
- }
190
- if (record.kind === "edited") {
191
- await rewrite(record.id, record.before, record.after);
192
- return record;
193
- }
194
- await cancel(record.id, "deleted in deictic");
195
- return record;
196
- }),
197
- describe: (op, before) => {
198
- const named = (id) => `task "${clip(before.tasks.find((t) => t.id === id)?.title ?? `#${id}`, 60)}"`;
199
- if ("remove" in op) return `delete ${named(op.remove)}`;
200
- if ("edit" in op) return `edit ${named(op.edit)}`;
201
- return `task "${clip(wordsOf(op).split("\n", 1)[0], 60)}"`;
202
- }
203
- });
204
- }
205
- /**
206
- * The channel's page on a board `vb serve` runs on this machine, which serves its pages beside its API:
207
- * `/api/board` there, `/c/<channel>` beside it. Nothing for any other board.
208
- */
209
- async function localPage(team, channel) {
210
- const url = new URL((await team.discovery()).url);
211
- if (![
212
- "127.0.0.1",
213
- "localhost",
214
- "[::1]"
215
- ].includes(url.hostname) || !url.pathname.endsWith("/api/board")) return void 0;
216
- return `${url.origin}${url.pathname.slice(0, -10)}/c/${channel.split("/").map(encodeURIComponent).join("/")}`;
217
- }
218
- const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
219
- const said = (notes) => notes.length === 0 ? "" : `; the notes say: ${notes.map((n) => JSON.stringify(n)).join(", ")}`;
220
- /** What was marked on the page: how many marks, and what the notes say. */
221
- function annotated({ count, notes }, shots, recordings) {
222
- const where = [...shots === 0 ? [] : [shots === 1 ? "the screenshot" : "the screenshots"], ...recordings === 0 ? [] : [recordings === 1 ? "the recording" : "the recordings"]];
223
- const drawn = where.length === 0 ? "" : `, drawn in ${where.join(" and ")}`;
224
- return `${plural(count, "mark")} on the page${drawn}${said(notes)}`;
225
- }
226
- /** How long each recording ran, and where it plays back, while the dev server keeps it. */
227
- function recordingsOf(recordings) {
228
- return recordings.map(({ duration, replay, voice }, i) => {
229
- const name = recordings.length === 1 ? "A recording" : `Recording ${i + 1}`;
230
- const spoken = voice === void 0 || voice.length === 0 ? "" : `, with the voice (${voice.map((id) => `voice-${id}`).join(", ")})`;
231
- return `${name}, ${clock(duration)} long, attached as rrweb events${spoken}; it replays at ${replay}`;
232
- });
233
- }
234
- /** How long each voice note runs, and the attachment it's in. */
235
- function voicesOf(voice) {
236
- return voice.map(({ id, duration }, i) => {
237
- return `${voice.length === 1 ? "A voice note" : `Voice note ${i + 1}`}, ${clock(duration)} long, attached as voice-${id}`;
238
- });
239
- }
240
- const clock = (ms) => {
241
- const s = Math.round(ms / 1e3);
242
- return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
243
- };
244
- /**
245
- * What was drawn on each shot, and with several, where the element is in each: nothing marks it there. One
246
- * shot's place is the `deictic.position` and `deictic.size` labels, so a shot with no marks has no line.
247
- */
248
- function shotsOf(shots) {
249
- const [only] = shots;
250
- if (shots.length === 1 && only !== void 0) {
251
- const { marks } = only;
252
- return marks === void 0 || marks.count === 0 ? [] : [`The screenshot has ${plural(marks.count, "mark")} drawn on it${said(marks.notes)}`];
253
- }
254
- return shots.map(({ box, marks }, i) => {
255
- const drawn = marks === void 0 || marks.count === 0 ? "" : `, with ${plural(marks.count, "mark")} drawn on it${said(marks.notes)}`;
256
- const [x, y, width, height] = boxOf(box);
257
- return `In screenshot ${i + 1} at x ${x}, y ${y}, ${width}×${height}${drawn}`;
258
- });
259
- }
260
- /** A box as `x,y,width,height`, in whole CSS pixels from the shot's top left. */
261
- const boxOf = ({ x, y, width, height }) => [
262
- x,
263
- y,
264
- width,
265
- height
266
- ].map(Math.round);
267
- /** A label's value: a board holds 256 characters. */
268
- const LABEL = 256;
269
- /** The project's name: the `name` in the root's `package.json`, or nothing where it has none. */
270
- function nameOf(root) {
271
- try {
272
- const { name } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
273
- return typeof name === "string" && name !== "" ? name : void 0;
274
- } catch {
275
- return;
276
- }
277
- }
278
- /**
279
- * The facts about the element, as labels: short values a script reads without parsing the text, and a watch
280
- * filters by. `deictic.line` is the opening tag's first line as the task saw it, to tell later that it moved.
281
- * `deictic.url` is the page's whole URL, where a label holds it: `textOf` says a longer one.
282
- */
283
- function labelsOf({ code, element }, target, op) {
284
- const [shot] = op.screenshots ?? [];
285
- return {
286
- [AT]: atOf(target),
287
- "deictic.tag": target.tag,
288
- "deictic.line": clip(code.slice(element.start, element.end).split("\n", 1)[0].trim(), LABEL),
289
- "deictic.page": clip(new URL(op.page).pathname, LABEL),
290
- ...op.page.length <= LABEL ? { "deictic.url": op.page } : {},
291
- "deictic.viewport": `${op.viewport.width}x${op.viewport.height}`,
292
- "deictic.count": String(op.count),
293
- ...op.screenshots?.length === 1 && shot !== void 0 ? placeOf(shot.box) : {}
294
- };
295
- }
296
- /** Where the element is in the one shot, from its top left, and how big: `87,387` and `138x32`, as the viewport is written. */
297
- function placeOf(box) {
298
- const [x, y, width, height] = boxOf(box);
299
- return {
300
- "deictic.position": `${x},${y}`,
301
- "deictic.size": `${width}x${height}`
302
- };
303
- }
304
- const atOf = ({ loc }) => `${loc.file}:${loc.line}:${loc.column}`;
305
- /**
306
- * The task's text: what was typed, and after a `---` only what no label holds: what's attached and drawn, what
307
- * was pointed at inside the element, and a URL too long for one. A board holds 10,000 characters.
308
- */
309
- function textOf(op) {
310
- const more = [
311
- ...op.page.length <= LABEL ? [] : [op.page],
312
- ...shotsOf(op.screenshots ?? []),
313
- ...recordingsOf(op.recordings ?? []),
314
- ...voicesOf(op.voice ?? []),
315
- ...op.annotations === void 0 ? [] : [annotated(op.annotations, op.screenshots?.length ?? 0, op.recordings?.length ?? 0)],
316
- ...op.pointed === void 0 ? [] : [`Pointed at, inside it: \`${op.pointed.path}\``, fence(op.pointed.html, "html")]
317
- ];
318
- const tail = more.length === 0 ? "" : REST + more.join("\n");
319
- return clip(wordsOf(op), 1e4 - tail.length) + tail;
320
- }
321
- /** The task's words: what was typed, or where nothing was, a line that sends the reader to what's attached. */
322
- const wordsOf = (op) => op.text.trim() === "" ? shown(op) ?? "" : op.text.trim();
323
- /** `See the recording and the voice note`: what stands for the words of a task sent with none, where something is attached. */
324
- function shown(op) {
325
- const named = (count, word) => count === void 0 || count === 0 ? [] : [`the ${word}${count === 1 ? "" : "s"}`];
326
- const attached = [
327
- ...named(op.screenshots?.length, "screenshot"),
328
- ...named(op.recordings?.length, "recording"),
329
- ...named(op.voice?.length, "voice note")
330
- ];
331
- return attached.length === 0 ? void 0 : `See ${new Intl.ListFormat("en", { type: "conjunction" }).format(attached)}`;
332
- }
333
- const fence = (text, lang) => `\`\`\`\`${lang}\n${clip(text, 1500)}\n\`\`\`\``;
334
- const clip = (text, max) => text.length <= max ? text : `${text.slice(0, max - 1)}…`;
335
- /** The board's answer, or a `Refusal` saying what to do when there's no board to ask or it said no. */
336
- async function asked(ask) {
337
- try {
338
- return await ask();
339
- } catch (e) {
340
- if (e instanceof Refusal) throw e;
341
- const { code, message, hint } = e;
342
- if (typeof code === "string") throw new Refusal(`the board says: ${message}${hint === void 0 ? "" : ` (${hint})`}`, { cause: e });
343
- throw new Refusal(`can't reach the board (${message ?? String(e)}): run \`npx vb serve\` and set BOARD_URL for the dev server, or \`vercel login\``, { cause: e });
344
- }
345
- }
346
- export { tasks as default, tasks };
347
-
348
- //# sourceMappingURL=index.js.map
1
+ export { t as default, t as tasks, n as local } from "../shared/tasks.js";
package/dist/vite.d.ts CHANGED
@@ -1,17 +1,16 @@
1
- /**
2
- * `deictic/vite`: deictic in Vite's dev server. Nothing runs in a build.
3
- *
4
- * Its transform runs `pre`, so each JSX module's host elements are marked with their place in the
5
- * source as written (`tools/locate.ts`). In the browser each marked module also imports the client
6
- * module, which starts the overlay with every plugin's panel: imports run first and only once, so no
7
- * line moves and frameworks that render their own HTML get it too. The endpoints are middleware on
8
- * Vite's server, and a place opens through Vite's own `/__open-in-editor`, so the editor is whichever
9
- * Vite already launches. A write reaches the page through Vite's usual update for the file.
10
- */
11
1
  import { Plugin } from "vite";
12
- import { n as clientModule, t as DeicticOptions } from "./integration.js";
2
+ import { n as clientModule, t as DeicticOptions } from "./shared/integration.js";
3
+ export interface ViteOptions extends DeicticOptions {
4
+ /**
5
+ * deictic in a build too, for a page that shows it with no dev server behind it (a deployed demo): a module of
6
+ * the page's, from the root, whose default export answers the overlay's requests there (a `Standalone`, from
7
+ * `deictic`). The build's elements are marked and the overlay is in its bundle. The dev server answers as ever.
8
+ * Without it, the default, nothing of deictic is in a build.
9
+ */
10
+ standalone?: string;
11
+ }
13
12
  /** The client module's ID, which a page can import itself where nothing it bundles is JSX (Astro's pages). */
14
13
  export declare const CLIENT = "virtual:deictic/client";
15
- export declare function deictic(options?: DeicticOptions): Plugin;
14
+ export declare function deictic(options?: ViteOptions): Plugin;
16
15
  export { type DeicticOptions, clientModule, deictic as default };
17
16
  //# sourceMappingURL=vite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","names":[],"sources":["../src/vite.ts"],"mappings":";;;;;;;;;;;;;qBAkBa;wBAGG,QAAQ,UAAS,iBAAsB"}
1
+ {"version":3,"file":"vite.d.ts","names":[],"sources":["../src/vite.ts"],"mappings":";;iBAmBiB,oBAAoB;;;;;;;EAOnC;;;qBAIW;wBAGG,QAAQ,UAAS,cAAmB"}
package/dist/vite.js CHANGED
@@ -1,6 +1,17 @@
1
- import { n as nodeMiddleware, r as redirect, t as endpoints } from "./endpoints.js";
2
- import { a as markAstro, i as mark, n as clientModule, o as prepare } from "./integration.js";
1
+ import { resolve } from "node:path";
2
+ import { n as nodeMiddleware, r as redirect, t as endpoints } from "./shared/endpoints.js";
3
+ import { a as markAstro, i as mark, n as clientModule, o as prepare } from "./shared/integration.js";
3
4
  // src/vite.ts
5
+ /**
6
+ * `deictic/vite`: deictic in Vite's dev server. Nothing runs in a build, unless `standalone` asks for it.
7
+ *
8
+ * Its transform runs `pre`, so each JSX module's host elements are marked with their place in the
9
+ * source as written (`tools/locate.ts`). In the browser each marked module also imports the client
10
+ * module, which starts the overlay with every plugin's panel: imports run first and only once, so no
11
+ * line moves and frameworks that render their own HTML get it too. The endpoints are middleware on
12
+ * Vite's server, and a place opens through Vite's own `/__open-in-editor`, so the editor is whichever
13
+ * Vite already launches. A write reaches the page through Vite's usual update for the file.
14
+ */
4
15
  /** The client module's ID, which a page can import itself where nothing it bundles is JSX (Astro's pages). */
5
16
  const CLIENT = "virtual:deictic/client";
6
17
  const CLIENT_ID = "\0deictic/client";
@@ -8,14 +19,16 @@ function deictic(options = {}) {
8
19
  const { plugins, shortcut } = prepare(options);
9
20
  let root = "";
10
21
  let base = "/";
22
+ let building = false;
11
23
  return {
12
24
  name: "deictic",
13
25
  enforce: "pre",
14
- apply: "serve",
26
+ apply: (_, { command }) => command === "serve" || options.standalone !== void 0,
15
27
  config: () => ({ optimizeDeps: { exclude: ["deictic"] } }),
16
28
  configResolved(config) {
17
29
  root = config.root;
18
30
  base = config.base;
31
+ building = config.command === "build";
19
32
  },
20
33
  configureServer(server) {
21
34
  const handle = endpoints({
@@ -27,7 +40,11 @@ function deictic(options = {}) {
27
40
  server.middlewares.use(nodeMiddleware(handle));
28
41
  },
29
42
  resolveId: (id) => id === "virtual:deictic/client" ? CLIENT_ID : void 0,
30
- load: (id) => id === CLIENT_ID ? clientModule(plugins, base, shortcut) : void 0,
43
+ load(id) {
44
+ if (id !== CLIENT_ID) return void 0;
45
+ const server = building && options.standalone !== void 0 ? resolve(root, options.standalone).replaceAll("\\", "/") : void 0;
46
+ return clientModule(plugins, base, shortcut, server);
47
+ },
31
48
  transform: {
32
49
  order: "pre",
33
50
  handler(code, id) {
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["/**\n * `deictic/vite`: deictic in Vite's dev server. Nothing runs in a build.\n *\n * Its transform runs `pre`, so each JSX module's host elements are marked with their place in the\n * source as written (`tools/locate.ts`). In the browser each marked module also imports the client\n * module, which starts the overlay with every plugin's panel: imports run first and only once, so no\n * line moves and frameworks that render their own HTML get it too. The endpoints are middleware on\n * Vite's server, and a place opens through Vite's own `/__open-in-editor`, so the editor is whichever\n * Vite already launches. A write reaches the page through Vite's usual update for the file.\n */\nimport type { Plugin } from 'vite';\n\nimport { endpoints, nodeMiddleware, redirect } from './tools/endpoints.ts';\nimport { clientModule, type DeicticOptions, mark, markAstro, prepare } from './tools/integration.ts';\n\nexport { clientModule, type DeicticOptions };\n\n/** The client module's ID, which a page can import itself where nothing it bundles is JSX (Astro's pages). */\nexport const CLIENT = 'virtual:deictic/client';\nconst CLIENT_ID = '\\0deictic/client';\n\nexport function deictic(options: DeicticOptions = {}): Plugin {\n const { plugins, shortcut } = prepare(options);\n let root = '';\n let base = '/';\n return {\n name: 'deictic',\n enforce: 'pre',\n apply: 'serve',\n // The client is the app's to bundle as it changes, not a dependency to prebundle once.\n config: () => ({ optimizeDeps: { exclude: ['deictic'] } }),\n configResolved(config) {\n root = config.root;\n base = config.base;\n },\n configureServer(server) {\n const handle = endpoints({\n root,\n plugins,\n base,\n open: (path, { line, column }) => redirect(`${base}__open-in-editor?${new URLSearchParams({ file: `${path}:${line}:${column}` })}`),\n });\n server.middlewares.use(nodeMiddleware(handle));\n },\n resolveId: (id) => (id === CLIENT ? CLIENT_ID : undefined),\n load: (id) => (id === CLIENT_ID ? clientModule(plugins, base, shortcut) : undefined),\n transform: {\n // First of all, not only first of the `pre` plugins: the React Compiler (`react({ compiler: true })`) is\n // `pre` too and compiles the JSX away, so after it there'd be no element to mark, wherever deictic is listed.\n order: 'pre',\n handler(code, id) {\n const [path = ''] = id.split('?');\n // An `.astro` component itself, not the styles and scripts Astro loads from it by a query.\n if (path.endsWith('.astro')) return id === path ? markAstro(code, path, root) : undefined;\n const browser = this.environment.config.consumer === 'client';\n return mark(code, path, root, browser ? `\\nimport ${JSON.stringify(CLIENT)};\\n` : '');\n },\n },\n };\n}\n\nexport default deictic;\n"],"mappings":";;;;AAkBA,MAAa,SAAS;AACtB,MAAM,YAAY;AAElB,SAAgB,QAAQ,UAA0B,CAAC,GAAW;CAC5D,MAAM,EAAE,SAAS,aAAa,QAAQ,OAAO;CAC7C,IAAI,OAAO;CACX,IAAI,OAAO;CACX,OAAO;EACL,MAAM;EACN,SAAS;EACT,OAAO;EAEP,eAAe,EAAE,cAAc,EAAE,SAAS,CAAC,SAAS,EAAE,EAAE;EACxD,eAAe,QAAQ;GACrB,OAAO,OAAO;GACd,OAAO,OAAO;EAChB;EACA,gBAAgB,QAAQ;GACtB,MAAM,SAAS,UAAU;IACvB;IACA;IACA;IACA,OAAO,MAAM,EAAE,MAAM,aAAa,SAAS,GAAG,KAAK,mBAAmB,IAAI,gBAAgB,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC,GAAG;GACpI,CAAC;GACD,OAAO,YAAY,IAAI,eAAe,MAAM,CAAC;EAC/C;EACA,YAAY,OAAQ,OAAA,2BAAgB,YAAY,KAAA;EAChD,OAAO,OAAQ,OAAO,YAAY,aAAa,SAAS,MAAM,QAAQ,IAAI,KAAA;EAC1E,WAAW;GAGT,OAAO;GACP,QAAQ,MAAM,IAAI;IAChB,MAAM,CAAC,OAAO,MAAM,GAAG,MAAM,GAAG;IAEhC,IAAI,KAAK,SAAS,QAAQ,GAAG,OAAO,OAAO,OAAO,UAAU,MAAM,MAAM,IAAI,IAAI,KAAA;IAChF,MAAM,UAAU,KAAK,YAAY,OAAO,aAAa;IACrD,OAAO,KAAK,MAAM,MAAM,MAAM,UAAU,YAAY,KAAK,UAAU,MAAM,EAAE,OAAO,EAAE;GACtF;EACF;CACF;AACF"}
1
+ {"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["/**\n * `deictic/vite`: deictic in Vite's dev server. Nothing runs in a build, unless `standalone` asks for it.\n *\n * Its transform runs `pre`, so each JSX module's host elements are marked with their place in the\n * source as written (`tools/locate.ts`). In the browser each marked module also imports the client\n * module, which starts the overlay with every plugin's panel: imports run first and only once, so no\n * line moves and frameworks that render their own HTML get it too. The endpoints are middleware on\n * Vite's server, and a place opens through Vite's own `/__open-in-editor`, so the editor is whichever\n * Vite already launches. A write reaches the page through Vite's usual update for the file.\n */\nimport { resolve } from 'node:path';\n\nimport type { Plugin } from 'vite';\n\nimport { endpoints, nodeMiddleware, redirect } from './tools/endpoints.ts';\nimport { clientModule, type DeicticOptions, mark, markAstro, prepare } from './tools/integration.ts';\n\nexport { clientModule, type DeicticOptions };\n\nexport interface ViteOptions extends DeicticOptions {\n /**\n * deictic in a build too, for a page that shows it with no dev server behind it (a deployed demo): a module of\n * the page's, from the root, whose default export answers the overlay's requests there (a `Standalone`, from\n * `deictic`). The build's elements are marked and the overlay is in its bundle. The dev server answers as ever.\n * Without it, the default, nothing of deictic is in a build.\n */\n standalone?: string;\n}\n\n/** The client module's ID, which a page can import itself where nothing it bundles is JSX (Astro's pages). */\nexport const CLIENT = 'virtual:deictic/client';\nconst CLIENT_ID = '\\0deictic/client';\n\nexport function deictic(options: ViteOptions = {}): Plugin {\n const { plugins, shortcut } = prepare(options);\n let root = '';\n let base = '/';\n let building = false;\n return {\n name: 'deictic',\n enforce: 'pre',\n apply: (_, { command }) => command === 'serve' || options.standalone !== undefined,\n // The client is the app's to bundle as it changes, not a dependency to prebundle once.\n config: () => ({ optimizeDeps: { exclude: ['deictic'] } }),\n configResolved(config) {\n root = config.root;\n base = config.base;\n building = config.command === 'build';\n },\n configureServer(server) {\n const handle = endpoints({\n root,\n plugins,\n base,\n open: (path, { line, column }) => redirect(`${base}__open-in-editor?${new URLSearchParams({ file: `${path}:${line}:${column}` })}`),\n });\n server.middlewares.use(nodeMiddleware(handle));\n },\n resolveId: (id) => (id === CLIENT ? CLIENT_ID : undefined),\n load(id) {\n if (id !== CLIENT_ID) return undefined;\n // Only a build's page asks the module: the dev server is there to answer.\n const server = building && options.standalone !== undefined ? resolve(root, options.standalone).replaceAll('\\\\', '/') : undefined;\n return clientModule(plugins, base, shortcut, server);\n },\n transform: {\n // First of all, not only first of the `pre` plugins: the React Compiler (`react({ compiler: true })`) is\n // `pre` too and compiles the JSX away, so after it there'd be no element to mark, wherever deictic is listed.\n order: 'pre',\n handler(code, id) {\n const [path = ''] = id.split('?');\n // An `.astro` component itself, not the styles and scripts Astro loads from it by a query.\n if (path.endsWith('.astro')) return id === path ? markAstro(code, path, root) : undefined;\n const browser = this.environment.config.consumer === 'client';\n return mark(code, path, root, browser ? `\\nimport ${JSON.stringify(CLIENT)};\\n` : '');\n },\n },\n };\n}\n\nexport default deictic;\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,MAAa,SAAS;AACtB,MAAM,YAAY;AAElB,SAAgB,QAAQ,UAAuB,CAAC,GAAW;CACzD,MAAM,EAAE,SAAS,aAAa,QAAQ,OAAO;CAC7C,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,WAAW;CACf,OAAO;EACL,MAAM;EACN,SAAS;EACT,QAAQ,GAAG,EAAE,cAAc,YAAY,WAAW,QAAQ,eAAe,KAAA;EAEzE,eAAe,EAAE,cAAc,EAAE,SAAS,CAAC,SAAS,EAAE,EAAE;EACxD,eAAe,QAAQ;GACrB,OAAO,OAAO;GACd,OAAO,OAAO;GACd,WAAW,OAAO,YAAY;EAChC;EACA,gBAAgB,QAAQ;GACtB,MAAM,SAAS,UAAU;IACvB;IACA;IACA;IACA,OAAO,MAAM,EAAE,MAAM,aAAa,SAAS,GAAG,KAAK,mBAAmB,IAAI,gBAAgB,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC,GAAG;GACpI,CAAC;GACD,OAAO,YAAY,IAAI,eAAe,MAAM,CAAC;EAC/C;EACA,YAAY,OAAQ,OAAA,2BAAgB,YAAY,KAAA;EAChD,KAAK,IAAI;GACP,IAAI,OAAO,WAAW,OAAO,KAAA;GAE7B,MAAM,SAAS,YAAY,QAAQ,eAAe,KAAA,IAAY,QAAQ,MAAM,QAAQ,UAAU,CAAC,CAAC,WAAW,MAAM,GAAG,IAAI,KAAA;GACxH,OAAO,aAAa,SAAS,MAAM,UAAU,MAAM;EACrD;EACA,WAAW;GAGT,OAAO;GACP,QAAQ,MAAM,IAAI;IAChB,MAAM,CAAC,OAAO,MAAM,GAAG,MAAM,GAAG;IAEhC,IAAI,KAAK,SAAS,QAAQ,GAAG,OAAO,OAAO,OAAO,UAAU,MAAM,MAAM,IAAI,IAAI,KAAA;IAChF,MAAM,UAAU,KAAK,YAAY,OAAO,aAAa;IACrD,OAAO,KAAK,MAAM,MAAM,MAAM,UAAU,YAAY,KAAK,UAAU,MAAM,EAAE,OAAO,EAAE;GACtF;EACF;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/plugins/voice/client.ts"],"mappings":";cAYA,4B"}
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/plugins/voice/client.ts"],"mappings":";cAgBA,4B"}
@@ -2,8 +2,10 @@ import { defineClientPlugin } from "../index.js";
2
2
  // src/plugins/voice/client.ts
3
3
  /**
4
4
  * The voice plugin's page half: `start()` asks for the mic (the browser asks the user the first time) and
5
- * records it with `MediaRecorder`. `stop` sends the take to the `add` route and lets the mic go, so the
6
- * browser's recording light goes out between takes.
5
+ * records it with `MediaRecorder`, sending what's spoken each second: the take's start to the `add` route,
6
+ * the rest to `more/<id>`. So a take the page leaves in the middle of (a recording that goes on to another
7
+ * page) is kept up to there. `stop` sends the last of it and lets the mic go, so the browser's recording
8
+ * light goes out between takes.
7
9
  */
8
10
  /** What the browser can record, best first: Opus in WebM where it can (Chrome, Firefox), else MP4 (Safari). */
9
11
  const TYPES = [
@@ -12,6 +14,8 @@ const TYPES = [
12
14
  "audio/ogg;codecs=opus",
13
15
  "audio/mp4"
14
16
  ];
17
+ /** How often what's spoken is sent, in milliseconds: what a page load can lose of a take. */
18
+ const EVERY = 1e3;
15
19
  var client_default = defineClientPlugin({
16
20
  name: "voice",
17
21
  setup: ({ base, request }) => ({ start: async () => {
@@ -21,10 +25,30 @@ var client_default = defineClientPlugin({
21
25
  });
22
26
  const mimeType = TYPES.find((t) => MediaRecorder.isTypeSupported(t));
23
27
  const recorder = new MediaRecorder(stream, mimeType === void 0 ? {} : { mimeType });
24
- const chunks = [];
25
- recorder.addEventListener("dataavailable", (e) => chunks.push(e.data));
28
+ const typeOf = () => (recorder.mimeType || mimeType || "audio/webm").split(";")[0];
29
+ let id;
30
+ let url;
31
+ let sent = Promise.resolve();
32
+ const send = (body, last = false) => {
33
+ sent = sent.then(async () => {
34
+ if (id === void 0 && body === void 0) throw new Error("voice: the clip is empty: speak for a moment longer");
35
+ const res = await request(id === void 0 ? "add" : `more/${id}${last ? "?last" : ""}`, {
36
+ method: "POST",
37
+ headers: { "content-type": typeOf() },
38
+ ...body ? { body } : {}
39
+ });
40
+ const answer = await res.json();
41
+ if (answer.id === void 0) throw new Error(`voice: ${answer.problem ?? res.statusText}`);
42
+ id = answer.id;
43
+ url = answer.url ?? url;
44
+ });
45
+ return sent;
46
+ };
47
+ recorder.addEventListener("dataavailable", (e) => {
48
+ if (e.data.size > 0) send(new Blob([e.data], { type: typeOf() })).catch(() => {});
49
+ });
26
50
  const started = Date.now();
27
- recorder.start();
51
+ recorder.start(EVERY);
28
52
  const release = () => {
29
53
  for (const track of stream.getTracks()) track.stop();
30
54
  };
@@ -36,6 +60,10 @@ var client_default = defineClientPlugin({
36
60
  return {
37
61
  started,
38
62
  stream,
63
+ soFar: () => id === void 0 ? void 0 : {
64
+ id,
65
+ duration: Date.now() - started
66
+ },
39
67
  cancel: () => {
40
68
  ended().then(release);
41
69
  },
@@ -43,19 +71,12 @@ var client_default = defineClientPlugin({
43
71
  await ended();
44
72
  release();
45
73
  const duration = Date.now() - started;
46
- const type = (recorder.mimeType || mimeType || "audio/webm").split(";")[0];
47
- const res = await request("add", {
48
- method: "POST",
49
- headers: { "content-type": type },
50
- body: new Blob(chunks, { type })
51
- });
52
- const { id, problem } = await res.json();
53
- if (id === void 0) throw new Error(`voice: ${problem ?? res.statusText}`);
74
+ await send(void 0, true);
54
75
  return {
55
76
  id,
56
- url: `${base}__deictic/plugins/voice/clip/${id}`,
77
+ url: url ?? `${base}__deictic/plugins/voice/clip/${id}`,
57
78
  duration,
58
- type
79
+ type: typeOf()
59
80
  };
60
81
  }
61
82
  };
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/voice/client.ts"],"sourcesContent":["/**\n * The voice plugin's page half: `start()` asks for the mic (the browser asks the user the first time) and\n * records it with `MediaRecorder`. `stop` sends the take to the `add` route and lets the mic go, so the\n * browser's recording light goes out between takes.\n */\nimport { defineClientPlugin } from '#src/index.ts';\n\nimport type { Clip, Voice } from './index.ts';\n\n/** What the browser can record, best first: Opus in WebM where it can (Chrome, Firefox), else MP4 (Safari). */\nconst TYPES = ['audio/webm;codecs=opus', 'audio/webm', 'audio/ogg;codecs=opus', 'audio/mp4'];\n\nexport default defineClientPlugin<never, never, Voice>({\n name: 'voice',\n setup: ({ base, request }) => ({\n start: async () => {\n if (typeof MediaRecorder === 'undefined' || navigator.mediaDevices?.getUserMedia === undefined)\n throw new Error(\"voice: this browser can't record the mic here: it needs a secure page (https or localhost)\");\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true }).catch((e: unknown) => {\n throw new Error(`voice: the mic isn't available: ${e instanceof Error ? e.message : String(e)}`, { cause: e });\n });\n const mimeType = TYPES.find((t) => MediaRecorder.isTypeSupported(t));\n const recorder = new MediaRecorder(stream, mimeType === undefined ? {} : { mimeType });\n const chunks: Blob[] = [];\n recorder.addEventListener('dataavailable', (e) => chunks.push(e.data));\n const started = Date.now();\n recorder.start();\n const release = () => {\n for (const track of stream.getTracks()) track.stop();\n };\n const ended = () =>\n new Promise<void>((done) => {\n if (recorder.state === 'inactive') return done();\n recorder.addEventListener('stop', () => done(), { once: true });\n recorder.stop();\n });\n\n return {\n started,\n stream,\n cancel: () => {\n void ended().then(release);\n },\n stop: async (): Promise<Clip> => {\n await ended();\n release();\n const duration = Date.now() - started;\n const type = (recorder.mimeType || mimeType || 'audio/webm').split(';')[0]!;\n const res = await request('add', { method: 'POST', headers: { 'content-type': type }, body: new Blob(chunks, { type }) });\n const { id, problem } = (await res.json()) as { id?: string; problem?: string };\n if (id === undefined) throw new Error(`voice: ${problem ?? res.statusText}`);\n return { id, url: `${base}__deictic/plugins/voice/clip/${id}`, duration, type };\n },\n };\n },\n }),\n});\n"],"mappings":";;;;;;;;AAUA,MAAM,QAAQ;CAAC;CAA0B;CAAc;CAAyB;AAAW;AAE3F,IAAA,iBAAe,mBAAwC;CACrD,MAAM;CACN,QAAQ,EAAE,MAAM,eAAe,EAC7B,OAAO,YAAY;EACjB,IAAI,OAAO,kBAAkB,eAAe,UAAU,cAAc,iBAAiB,KAAA,GACnF,MAAM,IAAI,MAAM,4FAA4F;EAC9G,MAAM,SAAS,MAAM,UAAU,aAAa,aAAa,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,MAAe;GAC9F,MAAM,IAAI,MAAM,mCAAmC,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;EAC/G,CAAC;EACD,MAAM,WAAW,MAAM,MAAM,MAAM,cAAc,gBAAgB,CAAC,CAAC;EACnE,MAAM,WAAW,IAAI,cAAc,QAAQ,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,CAAC;EACrF,MAAM,SAAiB,CAAC;EACxB,SAAS,iBAAiB,kBAAkB,MAAM,OAAO,KAAK,EAAE,IAAI,CAAC;EACrE,MAAM,UAAU,KAAK,IAAI;EACzB,SAAS,MAAM;EACf,MAAM,gBAAgB;GACpB,KAAK,MAAM,SAAS,OAAO,UAAU,GAAG,MAAM,KAAK;EACrD;EACA,MAAM,cACJ,IAAI,SAAe,SAAS;GAC1B,IAAI,SAAS,UAAU,YAAY,OAAO,KAAK;GAC/C,SAAS,iBAAiB,cAAc,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;GAC9D,SAAS,KAAK;EAChB,CAAC;EAEH,OAAO;GACL;GACA;GACA,cAAc;IACP,MAAM,CAAC,CAAC,KAAK,OAAO;GAC3B;GACA,MAAM,YAA2B;IAC/B,MAAM,MAAM;IACZ,QAAQ;IACR,MAAM,WAAW,KAAK,IAAI,IAAI;IAC9B,MAAM,QAAQ,SAAS,YAAY,YAAY,aAAA,CAAc,MAAM,GAAG,CAAC,CAAC;IACxE,MAAM,MAAM,MAAM,QAAQ,OAAO;KAAE,QAAQ;KAAQ,SAAS,EAAE,gBAAgB,KAAK;KAAG,MAAM,IAAI,KAAK,QAAQ,EAAE,KAAK,CAAC;IAAE,CAAC;IACxH,MAAM,EAAE,IAAI,YAAa,MAAM,IAAI,KAAK;IACxC,IAAI,OAAO,KAAA,GAAW,MAAM,IAAI,MAAM,UAAU,WAAW,IAAI,YAAY;IAC3E,OAAO;KAAE;KAAI,KAAK,GAAG,KAAK,+BAA+B;KAAM;KAAU;IAAK;GAChF;EACF;CACF,EACF;AACF,CAAC"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/voice/client.ts"],"sourcesContent":["/**\n * The voice plugin's page half: `start()` asks for the mic (the browser asks the user the first time) and\n * records it with `MediaRecorder`, sending what's spoken each second: the take's start to the `add` route,\n * the rest to `more/<id>`. So a take the page leaves in the middle of (a recording that goes on to another\n * page) is kept up to there. `stop` sends the last of it and lets the mic go, so the browser's recording\n * light goes out between takes.\n */\nimport { defineClientPlugin } from '#src/index.ts';\n\nimport type { Clip, Voice } from './index.ts';\n\n/** What the browser can record, best first: Opus in WebM where it can (Chrome, Firefox), else MP4 (Safari). */\nconst TYPES = ['audio/webm;codecs=opus', 'audio/webm', 'audio/ogg;codecs=opus', 'audio/mp4'];\n/** How often what's spoken is sent, in milliseconds: what a page load can lose of a take. */\nconst EVERY = 1000;\n\nexport default defineClientPlugin<never, never, Voice>({\n name: 'voice',\n setup: ({ base, request }) => ({\n start: async () => {\n if (typeof MediaRecorder === 'undefined' || navigator.mediaDevices?.getUserMedia === undefined)\n throw new Error(\"voice: this browser can't record the mic here: it needs a secure page (https or localhost)\");\n const stream = await navigator.mediaDevices.getUserMedia({ audio: true }).catch((e: unknown) => {\n throw new Error(`voice: the mic isn't available: ${e instanceof Error ? e.message : String(e)}`, { cause: e });\n });\n const mimeType = TYPES.find((t) => MediaRecorder.isTypeSupported(t));\n const recorder = new MediaRecorder(stream, mimeType === undefined ? {} : { mimeType });\n const typeOf = () => (recorder.mimeType || mimeType || 'audio/webm').split(';')[0]!;\n // The clip, once its start is kept, and where it is, where what keeps it says (a `standalone` build's does).\n let id: string | undefined;\n let url: string | undefined;\n // One request at a time, in the order spoken: the audio is its pieces end to end. The first problem ends the sending.\n let sent: Promise<void> = Promise.resolve();\n const send = (body: Blob | undefined, last = false) => {\n sent = sent.then(async () => {\n if (id === undefined && body === undefined) throw new Error('voice: the clip is empty: speak for a moment longer');\n const route = id === undefined ? 'add' : `more/${id}${last ? '?last' : ''}`;\n const res = await request(route, { method: 'POST', headers: { 'content-type': typeOf() }, ...(body ? { body } : {}) });\n const answer = (await res.json()) as { id?: string; url?: string; problem?: string };\n if (answer.id === undefined) throw new Error(`voice: ${answer.problem ?? res.statusText}`);\n id = answer.id;\n url = answer.url ?? url;\n });\n return sent;\n };\n recorder.addEventListener('dataavailable', (e) => {\n // Heard only at `stop`, with the rest: a problem here is that one's.\n if (e.data.size > 0) send(new Blob([e.data], { type: typeOf() })).catch(() => {});\n });\n const started = Date.now();\n recorder.start(EVERY);\n const release = () => {\n for (const track of stream.getTracks()) track.stop();\n };\n const ended = () =>\n new Promise<void>((done) => {\n if (recorder.state === 'inactive') return done();\n recorder.addEventListener('stop', () => done(), { once: true });\n recorder.stop();\n });\n\n return {\n started,\n stream,\n soFar: () => (id === undefined ? undefined : { id, duration: Date.now() - started }),\n cancel: () => {\n void ended().then(release);\n },\n stop: async (): Promise<Clip> => {\n await ended();\n release();\n const duration = Date.now() - started;\n // The last piece came as it stopped. This says it's over, to what names the clip's place only then.\n await send(undefined, true);\n return { id: id!, url: url ?? `${base}__deictic/plugins/voice/clip/${id}`, duration, type: typeOf() };\n },\n };\n },\n }),\n});\n"],"mappings":";;;;;;;;;;AAYA,MAAM,QAAQ;CAAC;CAA0B;CAAc;CAAyB;AAAW;;AAE3F,MAAM,QAAQ;AAEd,IAAA,iBAAe,mBAAwC;CACrD,MAAM;CACN,QAAQ,EAAE,MAAM,eAAe,EAC7B,OAAO,YAAY;EACjB,IAAI,OAAO,kBAAkB,eAAe,UAAU,cAAc,iBAAiB,KAAA,GACnF,MAAM,IAAI,MAAM,4FAA4F;EAC9G,MAAM,SAAS,MAAM,UAAU,aAAa,aAAa,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,MAAe;GAC9F,MAAM,IAAI,MAAM,mCAAmC,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;EAC/G,CAAC;EACD,MAAM,WAAW,MAAM,MAAM,MAAM,cAAc,gBAAgB,CAAC,CAAC;EACnE,MAAM,WAAW,IAAI,cAAc,QAAQ,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,CAAC;EACrF,MAAM,gBAAgB,SAAS,YAAY,YAAY,aAAA,CAAc,MAAM,GAAG,CAAC,CAAC;EAEhF,IAAI;EACJ,IAAI;EAEJ,IAAI,OAAsB,QAAQ,QAAQ;EAC1C,MAAM,QAAQ,MAAwB,OAAO,UAAU;GACrD,OAAO,KAAK,KAAK,YAAY;IAC3B,IAAI,OAAO,KAAA,KAAa,SAAS,KAAA,GAAW,MAAM,IAAI,MAAM,qDAAqD;IAEjH,MAAM,MAAM,MAAM,QADJ,OAAO,KAAA,IAAY,QAAQ,QAAQ,KAAK,OAAO,UAAU,MACtC;KAAE,QAAQ;KAAQ,SAAS,EAAE,gBAAgB,OAAO,EAAE;KAAG,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;IAAG,CAAC;IACrH,MAAM,SAAU,MAAM,IAAI,KAAK;IAC/B,IAAI,OAAO,OAAO,KAAA,GAAW,MAAM,IAAI,MAAM,UAAU,OAAO,WAAW,IAAI,YAAY;IACzF,KAAK,OAAO;IACZ,MAAM,OAAO,OAAO;GACtB,CAAC;GACD,OAAO;EACT;EACA,SAAS,iBAAiB,kBAAkB,MAAM;GAEhD,IAAI,EAAE,KAAK,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,EAAE,IAAI,GAAG,EAAE,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;EAClF,CAAC;EACD,MAAM,UAAU,KAAK,IAAI;EACzB,SAAS,MAAM,KAAK;EACpB,MAAM,gBAAgB;GACpB,KAAK,MAAM,SAAS,OAAO,UAAU,GAAG,MAAM,KAAK;EACrD;EACA,MAAM,cACJ,IAAI,SAAe,SAAS;GAC1B,IAAI,SAAS,UAAU,YAAY,OAAO,KAAK;GAC/C,SAAS,iBAAiB,cAAc,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;GAC9D,SAAS,KAAK;EAChB,CAAC;EAEH,OAAO;GACL;GACA;GACA,aAAc,OAAO,KAAA,IAAY,KAAA,IAAY;IAAE;IAAI,UAAU,KAAK,IAAI,IAAI;GAAQ;GAClF,cAAc;IACP,MAAM,CAAC,CAAC,KAAK,OAAO;GAC3B;GACA,MAAM,YAA2B;IAC/B,MAAM,MAAM;IACZ,QAAQ;IACR,MAAM,WAAW,KAAK,IAAI,IAAI;IAE9B,MAAM,KAAK,KAAA,GAAW,IAAI;IAC1B,OAAO;KAAM;KAAK,KAAK,OAAO,GAAG,KAAK,+BAA+B;KAAM;KAAU,MAAM,OAAO;IAAE;GACtG;EACF;CACF,EACF;AACF,CAAC"}
@@ -5,12 +5,17 @@ export interface Clip {
5
5
  duration: number;
6
6
  type: string;
7
7
  }
8
- /** A take going on: `stop` ends it and keeps it, `cancel` ends it and keeps nothing. */
8
+ /** A take going on: `stop` ends it and answers its clip, `cancel` ends it with none (what was sent of it goes as the oldest clips do). */
9
9
  export interface Take {
10
10
  /** When it started, as `Date.now()`. */
11
11
  started: number;
12
12
  /** The mic, while it's recorded: to show it's heard (`liveWaveform` from `deictic/client`). */
13
13
  stream: MediaStream;
14
+ /**
15
+ * What's kept of it by now, as the clip it would be if it ended here, or nothing before its first second is:
16
+ * for a page that's going, with no time left to `stop` it.
17
+ */
18
+ soFar(): Pick<Clip, 'id' | 'duration'> | undefined;
14
19
  stop(): Promise<Clip>;
15
20
  cancel(): void;
16
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/plugins/voice/index.ts"],"mappings":";iBAaiB;EACf;EACA;EACA;EACA;;;iBAIe;;EAEf;;EAEA,QAAQ;EACR,QAAQ,QAAQ;EAChB;;;iBAIe;;EAEf,SAAS,QAAQ;;;iBAIF;;EAEf,KAAK;IAAe,MAAM,WAAW;IAAc;IAAc;;;;YAIvD;IACR,OAAO;;YAEC;IACR,OAAO;;;iBAIM;;EAEf;;EAEA;;wBASc,MAAM,UAAS,iCAAiB,kCAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/plugins/voice/index.ts"],"mappings":";iBAciB;EACf;EACA;EACA;EACA;;;iBAIe;;EAEf;;EAEA,QAAQ;;;;;EAKR,SAAS,KAAK;EACd,QAAQ,QAAQ;EAChB;;;iBAIe;;EAEf,SAAS,QAAQ;;;iBAIF;;EAEf,KAAK;IAAe,MAAM,WAAW;IAAc;IAAc;;;;YAIvD;IACR,OAAO;;YAEC;IACR,OAAO;;;iBAIM;;EAEf;;EAEA;;wBASc,MAAM,UAAS,iCAAiB,kCAAA"}
@@ -1,12 +1,13 @@
1
- import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
2
2
  import { join, resolve } from "node:path";
3
3
  import { definePlugin } from "../index.js";
4
- import { t as keptIn } from "../kept.js";
4
+ import { t as keptIn } from "../shared/kept.js";
5
5
  // src/plugins/voice/index.ts
6
6
  /**
7
7
  * `deictic/voice`: records the mic, for other plugins to attach (tasks does) or play along with
8
8
  * something (a recording does). No tab of its own. The page half asks for the mic the first time, records
9
- * with `MediaRecorder` and sends each take to the `add` route; the server half keeps the latest `keep`
9
+ * with `MediaRecorder` and sends each take as it's spoken, its start to the `add` route and the rest to
10
+ * `more/<id>`, so one a page load cuts short is kept up to there; the server half keeps the latest `keep`
10
11
  * clips under `.deictic/voice` and serves them at `clip/<id>`.
11
12
  */
12
13
  const ID = /^[a-z0-9]+-[a-z0-9]+$/;
@@ -58,6 +59,15 @@ function voice(options = {}) {
58
59
  if (body.byteLength > MAX) return Response.json({ problem: `a clip may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });
59
60
  return Response.json({ id: keepClip(body, ext) });
60
61
  },
62
+ more: async (req) => {
63
+ const id = new URL(req.url).pathname.split("/").at(-1) ?? "";
64
+ const file = fileOf(id);
65
+ if (file === void 0) return Response.json({ problem: `clip ${id} isn't kept any more: record it again` }, { status: 404 });
66
+ const body = new Uint8Array(await req.arrayBuffer());
67
+ if (statSync(join(dir, file)).size + body.byteLength > MAX) return Response.json({ problem: `a clip may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });
68
+ appendFileSync(join(dir, file), body);
69
+ return Response.json({ id });
70
+ },
61
71
  clip: (req) => {
62
72
  const found = read(new URL(req.url).pathname.split("/").at(-1) ?? "");
63
73
  if (found === void 0) return new Response("no such clip, or not kept any more", { status: 404 });