Repository navigation
Expand file tree
/
Copy pathjourneys.mjs
More file actions
868 lines (852 loc) · 43.3 KB
/
Copy pathjourneys.mjs
File metadata and controls
868 lines (852 loc) · 43.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
// What the survey does, in order: each journey is one feature, done the way a person would with the defaults, from
// where they'd usually start. They run one after another on the same fresh Lens, so later ones can use what earlier
// ones made (the admin account, an imported transcript). Keep ids stable: the baseline compares by id. `ns` starts a
// journey with that namespace picked ("" for all namespaces, as on a fresh install) rather than whatever the journey
// before left picked.
import crypto from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const INSTALLER = "http://localhost:3990";
/** A page in the primary navigation (the sidebar). */
const nav = (page, label) =>
page
.getByRole("navigation", { name: "Primary" })
.getByRole("link", { name: new RegExp(`^${label}( \\d+)?$`) }) // a count can follow the label (Library 1)
.first();
/** Opens a page from the primary navigation. On a phone the navigation sits behind the menu button. */
async function go({ page, meter, phone }, label) {
if (phone) await meter.click(page.getByRole("button", { name: "Open navigation" }), "Open navigation (menu)");
await meter.click(nav(page, label), label);
}
/** The palette that jumps to a recording or a page: Ctrl+K on a computer, the Jump to box in the top bar on a phone. */
async function jumpTo({ page, meter, phone }) {
if (phone) await meter.click(page.getByRole("banner").getByRole("button", { name: /^Jump to/ }), "Jump to (top bar)");
else await meter.press("Control+k", "Ctrl+K");
}
/** Import: the top bar's button (an icon on a phone). */
async function openImport({ page, meter }) {
await meter.click(page.getByRole("banner").getByRole("link", { name: "Import" }), "Import (top bar)");
await page.waitForURL(/\/import/);
}
/** Waits, not counted, until the page at `where` shows `locator`: something made in the background, which a person
* would come back to later. Then back to `from`, where the journey starts. */
async function madeInBackground({ page, base }, where, locator, from, what) {
for (let i = 0; !(await locator.isVisible()); i++) {
if (i === 60) throw new Error(`${what} wasn't there after 5 minutes`);
await page.goto(base + where, { waitUntil: "domcontentloaded" });
await page.waitForTimeout(5000);
}
await page.goto(base + from, { waitUntil: "domcontentloaded" });
await page.getByRole("banner").waitFor();
await page.waitForTimeout(2000);
}
/** Opens the namespace switcher: in the top bar, or at the top of the navigation drawer on a phone. */
async function openSwitcher(ctx) {
const { page, meter, phone } = ctx;
if (phone) await meter.click(page.getByRole("button", { name: "Open navigation" }), "Open navigation (menu)");
const switcher = page.getByRole("button", { name: /^Namespace: / }).first();
await needs(ctx, switcher, "the namespace switcher");
await meter.click(switcher, "the namespace switcher");
}
/** Opens a settings section from the sections list, which a phone opens from the current section's name. */
async function section({ page, meter, phone }, label) {
if (phone) await meter.click(page.getByRole("button", { name: /^Settings section/ }), "Settings sections");
await meter.click(page.getByRole("link", { name: label }), label);
}
/** Fails the journey with the reason when a control isn't on the screen at all (on a phone some are hidden). */
async function needs({ phone }, locator, what) {
try {
await locator.waitFor({ state: "visible", timeout: phone ? 5000 : 20000 });
} catch {
throw new Error(`${what} isn't on the screen${phone ? " on a phone" : ""}`);
}
}
/** Saves a settings form: Ctrl+S on a computer, the Save button on a phone (no keyboard shortcuts there). */
async function save({ page, meter, phone }) {
if (phone) await meter.click(page.getByRole("main").getByRole("button", { name: /^Save/ }).first(), "Save");
else await meter.press("Control+s", "Ctrl+S to save");
}
/** The model-backed answer the stand-in model gives (fake-model.mjs). */
const ANSWER = /stand-in model answering/;
/** The stand-in model's answer, in the newest answer on the page: not anywhere on it, where the list of conversations
* beside it carries titles, and an earlier answer may read the same. */
const answered = (page) => page.getByRole("article", { name: "Answer" }).last().getByText(ANSWER);
const TRANSCRIPT = [
"Host A: Welcome back. Today we talk about local models on small computers.",
"Host B: A Raspberry Pi can run Lens when the models are in the cloud.",
"Host A: And everything stays on your own hardware.",
].join("\n");
export const JOURNEYS = [
// --- Setup -------------------------------------------------------------------------------------------------------
{
id: "install",
module: "Setup",
feature: "Install with the web installer (defaults, local model found)",
note: "The install line in a terminal, then the browser installer. The browser opens on its own on a desktop; on a server the link is opened by hand (counted). A computer missing Docker also asks for its password.",
needs: "installer",
async run(ctx) {
const { page, meter, base } = ctx;
meter.record("terminal", "paste the install line and press Enter", 0, 2);
meter.openLink("open the installer link");
await page.goto(`${INSTALLER}/?t=survey-token`);
const quick = page.locator("#quick");
await page.locator("#next").waitFor();
if (await quick.count()) {
await meter.click(quick, "Install with the defaults");
} else {
await meter.click(page.locator("#next"), "Continue (this computer)");
await page.getByRole("heading", { name: "How Lens runs" }).waitFor();
await meter.click(page.locator("#next"), "Continue (how it runs)");
const found = page.getByRole("button", { name: /Ollama · \d+ models/ });
await found.waitFor();
// picked already when it's the only one found
if (!(await found.evaluate((el) => el.classList.contains("on"))))
await meter.click(found, "pick the model server found on this computer");
await meter.click(page.locator("#next"), "Continue (AI model)");
await page.getByRole("heading", { name: "Ready to install" }).waitFor();
await meter.click(page.locator("#next"), "Install Lens");
}
const open = page.getByRole("button", { name: "Open Lens" });
await open.waitFor({ timeout: 60000 });
await meter.click(open, "Open Lens");
await page.waitForURL(`${base}/setup**`);
},
},
{
id: "first-admin",
module: "Setup",
feature: "Create the first admin (passkey)",
note: "From the setup link, which fills in the setup code.",
async run(ctx) {
const { page, meter, base, code, installer } = ctx;
if (!installer) {
meter.openLink("open the setup link the server printed");
await page.goto(`${base}/setup?code=${code}`);
}
await page.getByRole("heading", { name: "Set up this server" }).waitFor();
await meter.type(page.getByRole("textbox", { name: "Email" }), "admin@example.com", "email");
await meter.click(page.getByRole("button", { name: /Create admin/ }), "Create admin with a passkey");
meter.passkey("create the passkey");
await page.waitForURL(`${base}/welcome`);
},
},
{
id: "setup-wizard",
module: "Setup",
feature: "First-run setup wizard, every step with its defaults",
note: "It asks only what has no default: the model provider, filled in from the local model found (and a budget for a cloud one). The survey's Lens started before its stand-in installer, so the model isn't set yet; after the real web installer, which sets it, the wizard doesn't open. The namespace, storage, apps and telemetry keep their defaults.",
async run(ctx) {
const { page, meter, base } = ctx;
await page.getByRole("heading", { name: "Connect a model provider" }).waitFor();
await page.getByRole("button", { name: /Ollama 2 models/ }).waitFor();
const save = page.getByRole("button", { name: "Save and continue" });
await meter.click(save, "Save and continue (Connect a model provider)");
await page.waitForURL(`${base}/`);
},
},
{
id: "first-question",
module: "Setup",
feature: "Ask the first question from the welcome tour",
async run(ctx) {
const { page, meter } = ctx;
const dialog = page.getByRole("dialog", { name: "Welcome to Lens" });
await dialog.waitFor();
await meter.type(dialog.getByRole("textbox", { name: "Ask the assistant" }), "What did the hosts say about Raspberry Pi?", "question");
await meter.press("Enter", "Enter to ask");
// The tour opens Chat with the question in the composer, not sent
const composer = page.getByRole("textbox", { name: "Your question" });
await composer.waitFor();
if (!(await answered(page).isVisible().catch(() => false))) {
await page.waitForTimeout(1500);
if ((await composer.inputValue()).trim()) await meter.press("Enter", "Enter again: the question waits in Chat's composer");
}
await answered(page).waitFor({ timeout: 60000 });
},
},
// --- Everyday use: each starts on Home, as after signing in -----------------------------------------------------
{
id: "import-paste",
module: "Import",
feature: "Import a pasted transcript",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await openImport(ctx);
await meter.click(page.getByRole("tab", { name: "Paste" }), "Paste tab");
await meter.paste(page.getByRole("textbox", { name: "Paste a transcript" }), TRANSCRIPT, "paste the transcript");
await page.getByText("3 turns").waitFor();
await meter.click(page.getByRole("main").getByRole("button", { name: "Import", exact: true }), "Import");
await page.getByText(/import sent/).waitFor({ timeout: 30000 });
},
},
{
id: "library-open",
module: "Library",
feature: "Open a recording from the Library",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Library");
const item = page.getByRole("main").getByRole("link", { name: /Welcome back/ }).first();
await item.waitFor();
await meter.click(item, "the recording");
await page.waitForURL(/\/(recordings|resources)\//);
},
},
{
id: "search-word",
module: "Search",
feature: "Search for a word and see where it was said",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Search");
await meter.type(page.getByRole("searchbox", { name: "Search your assets" }), "raspberry", "the word");
await meter.press("Enter", "Enter to search");
await page.getByRole("main").getByText(/Raspberry Pi can run Lens/).first().waitFor();
},
},
{
id: "jump-to",
module: "Navigation",
feature: "Jump to a recording with Ctrl+K",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await jumpTo(ctx);
await meter.type(page.getByRole("combobox", { name: /^Search assets/ }), "welcome", "part of its title");
await page.getByRole("option", { name: /Welcome back/ }).first().waitFor();
await meter.press("Enter", "Enter to open");
await page.waitForURL(/\/(recordings|resources)\//);
},
},
{
id: "chat-ask",
module: "Chat",
feature: "Ask the assistant in Chat",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Chat");
const question = page.getByRole("textbox", { name: "Your question" });
// A phone's Chat opens on the list of conversations once there is one
if (!(await question.waitFor({ timeout: 3000 }).then(() => true, () => false)))
await meter.click(page.getByRole("button", { name: "New conversation" }), "New conversation");
await meter.type(question, "Who said what about Raspberry Pi?", "question");
await meter.press("Enter", "Enter to send");
await answered(page).waitFor({ timeout: 60000 });
},
},
{
id: "note-create",
module: "Notes",
feature: "Write a note",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Notes");
await meter.click(page.getByRole("main").getByRole("button", { name: "New note" }).first(), "New note");
await page.waitForURL(/\/notes\/\d+/);
const title = page.getByRole("textbox", { name: "Title" });
// A person starts typing once the note has loaded and its title has the cursor (a click is counted if it never does)
await page.waitForFunction((el) => el === document.activeElement, await title.elementHandle(), { timeout: 5000 }).catch(() => {});
await meter.replace(title, "Pi setup", "title");
const editor = page.locator("main affine-page-root .inline-editor").first();
await editor.waitFor(); // the page has loaded its editor
await meter.press("Enter", "Enter to go to the first line");
await meter.type(editor, "Use cloud models on the Pi.", "first line");
await page.getByText("Saved").first().waitFor();
},
},
{
id: "topic-add",
module: "Topics",
feature: "Add a topic",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Topics");
await meter.click(page.getByRole("main").getByRole("button", { name: "Add topic" }).first(), "Add topic");
await meter.type(page.getByRole("textbox", { name: "Label", exact: true }), "Hardware", "label");
await meter.press("Enter", "Enter to add");
await page.getByRole("main").getByText("Hardware").first().waitFor();
},
},
{
id: "pipeline-create",
module: "Pipelines",
feature: "Make a pipeline from the standard steps",
note: "Lens guesses the name from the steps; it can be renamed on the pipeline's page.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Pipelines");
await meter.click(page.getByRole("main").getByRole("link", { name: "New pipeline" }), "New pipeline");
await page.getByRole("textbox", { name: "Pipeline name" }).waitFor(); // named for you
await page.waitForFunction(() => document.activeElement?.tagName === "INPUT");
await meter.press("Enter", "Enter to create");
await page.waitForURL(/\/pipelines\/\d+/);
},
},
{
id: "routine-create",
module: "Routines",
feature: "Make a nightly routine (sync sources, the default action)",
note: "Lens guesses the name from when it runs and what it does; it can be renamed later.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
// routines open from Automations (and its Schedules tab), which has New routine at the top for admins
await go(ctx, "Automations");
await meter.click(page.getByRole("main").getByRole("link", { name: "New routine" }), "New routine");
await page.getByRole("textbox", { name: "Name" }).waitFor(); // named for you
await page.waitForFunction(() => document.activeElement?.tagName === "INPUT");
await meter.press("Enter", "Enter to create");
await page.waitForURL(/\/routines\/\d+/);
},
},
{
id: "extension-add",
module: "Extensions",
feature: "Add the example skill to the assistant",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Extensions");
await meter.click(page.getByRole("main").getByRole("link", { name: "New", exact: true }), "New");
await meter.click(page.getByRole("button", { name: "Add to the assistant" }), "Add to the assistant");
await page.waitForURL(/\/extensions\/\d+/);
},
},
{
id: "sensor-webhook",
module: "Sensors",
feature: "Make a webhook sensor",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Sensors");
await meter.click(page.getByRole("main").getByRole("button", { name: "Add sensor" }).first(), "Add sensor");
await meter.click(page.getByRole("dialog").getByRole("button", { name: "Make webhook" }), "Make webhook");
await page.getByRole("dialog").getByText(/token/i).first().waitFor();
},
},
{
id: "settings-change",
module: "Settings",
feature: "Change the model's timeout",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Settings");
await section(ctx, "LLM provider");
await meter.replace(page.getByRole("textbox", { name: "Timeout (seconds)" }), "120", "timeout");
await save(ctx);
await page.getByText(/Saved|Last saved/).first().waitFor();
},
},
{
id: "person-add",
module: "Admin",
feature: "Add a person as a viewer",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Admin");
await meter.click(page.getByRole("button", { name: "Create account" }), "Create account");
const d = page.getByRole("dialog");
await meter.type(d.getByRole("textbox", { name: "Email" }), "viewer@example.com", "email");
await meter.click(d.getByRole("button", { name: "Create account" }), "Create account");
// The sign-in link is shown once, to send to them
await meter.click(d.getByRole("button", { name: /Copy/ }), "Copy the sign-in link");
await meter.click(d.getByRole("button", { name: "Done" }), "Done");
await page.getByRole("main").getByText("viewer@example.com").first().waitFor();
},
},
{
id: "api-token",
module: "Account",
feature: "Make an API token",
note: "Lens guesses the name from the scope; it can be renamed in the list.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await meter.click(page.getByRole("button", { name: "Account menu" }), "Account menu");
await meter.click(page.getByRole("menuitem", { name: /API tokens/ }), "API tokens");
const d = page.getByRole("dialog");
await page.waitForURL(/\/account\/tokens/);
await page.waitForTimeout(500);
// the form is open already when there are no tokens yet
if (!(await d.isVisible()))
await meter.click(page.getByRole("main").getByRole("button", { name: "New token" }).first(), "New token");
await meter.click(d.getByRole("button", { name: "Create token" }), "Create token");
await page.getByText(/copy/i).first().waitFor();
},
},
{
id: "namespace-switch",
module: "Navigation",
feature: "Switch to another namespace",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await openSwitcher(ctx);
await meter.click(page.getByRole("option", { name: /^podcasts/ }), "podcasts");
// on a phone the drawer closes after the pick, switcher and all
await page.waitForFunction(() => localStorage.getItem("lens.namespace") === "podcasts");
},
},
// --- Modules the first survey left out: one everyday task each ---------------------------------------------------
{
id: "agent-connect",
ns: "",
module: "Agents",
feature: "Connect an AI assistant (Claude, ChatGPT, Cursor) over MCP",
note: "Copy MCP address in the account menu; in the assistant: add a connector and paste the address; the assistant opens Lens's consent page, where the person allows it.",
from: "/",
async run(ctx) {
const { page, meter, base } = ctx;
const mcp = `${base}/mcp`;
await page.context().grantPermissions(["clipboard-read", "clipboard-write"], { origin: base });
await meter.click(page.getByRole("button", { name: "Account menu" }), "Account menu");
await meter.click(page.getByRole("menuitem", { name: "Copy MCP address" }), "Copy MCP address");
await page.getByText("MCP address copied").waitFor();
const copied = await page.evaluate(() => navigator.clipboard.readText());
if (copied !== mcp) throw new Error(`copied ${copied}, not ${mcp}`);
meter.record("outside", "in the assistant: add a connector, paste Lens's MCP address, add it", 2, 1);
// What the assistant does by itself (RFC 7591 registration, PKCE), then it opens the consent page
const redirect = "http://127.0.0.1:9/callback";
const r = await fetch(`${base}/api/v1/oauth/register`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ client_name: "Claude", redirect_uris: [redirect], token_endpoint_auth_method: "none" }),
});
if (!r.ok) throw new Error(`registering the assistant: ${r.status} ${await r.text()}`);
const { client_id } = await r.json();
const verifier = crypto.randomBytes(32).toString("base64url");
const challenge = crypto.createHash("sha256").update(verifier).digest("base64url");
const q = new URLSearchParams({
client_id, redirect_uri: redirect, response_type: "code", code_challenge: challenge,
code_challenge_method: "S256", state: "survey", scope: "read write",
});
// The assistant's own page that the browser is sent back to
await page.route(`${redirect}**`, (route) => route.fulfill({ contentType: "text/html", body: "Back in the assistant" }));
await page.goto(`${base}/oauth/authorize?${q}`, { waitUntil: "domcontentloaded" });
await meter.click(page.getByRole("button", { name: "Allow" }), "Allow");
await page.waitForURL(`${redirect}**`);
const code = new URL(page.url()).searchParams.get("code");
await page.unroute(`${redirect}**`);
if (!code) throw new Error("the consent page gave the assistant no code");
},
},
{
id: "import-file",
ns: "",
module: "Import",
feature: "Upload a transcript file",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
const file = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "lens-clicks-")), "pi-episode.txt");
fs.writeFileSync(file, TRANSCRIPT.replaceAll("Welcome back", "Hello again") + "\n");
await openImport(ctx);
await meter.upload(page.getByRole("main").getByRole("button", { name: "Choose files" }), [file], "Choose files, then the file");
await meter.click(page.getByRole("main").getByRole("button", { name: /^Import/ }).last(), "Import");
await page.getByText(/import sent|sent \d|imported/i).first().waitFor({ timeout: 30000 });
},
},
{
id: "source-folder",
ns: "",
module: "Sensors",
feature: "Watch a folder on this machine for new files",
note: "Needs rclone, as the Lens image has (CI copies the image's version); the folders offered are the allowed ones set at startup.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Sensors");
// Straight to this machine's allowed folders, its connection made on the way (nothing to test or name)
await meter.click(page.getByRole("main").getByRole("link", { name: "Watch a local folder" }), "Watch a local folder");
const browse = page.getByRole("dialog", { name: /^Browse/ });
await meter.click(browse.getByRole("table").getByRole("button", { name: /^Watch / }).first(), "Watch, on the allowed folder");
await meter.click(page.getByRole("dialog", { name: /^Watch/ }).getByRole("button", { name: "Start watching" }), "Start watching");
await page.getByRole("dialog").waitFor({ state: "hidden" });
await page.getByRole("main").getByText(/[1-9]\d* watched folders?/).first().waitFor();
},
},
{
id: "entity-find",
ns: "",
module: "Entities",
feature: "Find an entity and see where it was mentioned",
note: "Its name opens its own page, /wiki/<namespace>/Raspberry_Pi, with its notes and every line that says it.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
const entity = page.getByRole("main").getByRole("link", { name: "Raspberry Pi", exact: true });
await madeInBackground(ctx, "/entities", entity, "/", "the entity the imports' analysis makes");
await go(ctx, "Entities");
await meter.type(page.getByRole("searchbox", { name: "Find entities" }), "rasp", "part of its name");
// the list filters as you type: the other entity leaves it
await page.getByRole("main").getByRole("table").getByText("Lens", { exact: true }).waitFor({ state: "hidden" });
await meter.click(entity, "Raspberry Pi");
await page.waitForURL(/\/wiki\/[^/]+\/Raspberry_Pi$/);
await page.getByText(/Raspberry Pi can run Lens/).first().waitFor();
},
},
{
id: "graph-find",
ns: "",
module: "Graph",
feature: "Find a speaker in the graph of what was imported",
note: "The first namespace keeps its graph to itself, so the graph opens empty until it is picked as the namespace.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Graph");
const find = page.getByRole("combobox", { name: "Find in graph" });
await page.getByRole("region", { name: "Graph" }).waitFor();
await page.waitForTimeout(1000);
if (await page.getByRole("heading", { name: /^No graph/ }).isVisible().catch(() => false)) {
await openSwitcher(ctx);
await meter.click(page.getByRole("listbox", { name: "Namespaces" }).getByRole("option", { name: /^interviews/ }), "interviews");
}
// On a phone the filters, the find box among them, sit behind a button
if (!(await find.isVisible())) await meter.click(page.getByRole("button", { name: "Filters" }), "Filters");
await meter.type(find, "host b", "part of the name");
await page.getByRole("option", { name: /Host B/ }).first().waitFor();
await meter.press("Enter", "Enter to pick it");
// On a phone the filters stay open over the node picked
const filters = page.getByRole("dialog", { name: "Graph filters" });
if (await filters.isVisible().catch(() => false))
await meter.click(filters.getByRole("button", { name: "Close" }), "close the filters (they stay open over the node)");
await page.getByRole("heading", { name: "Host B" }).first().waitFor();
},
},
{
id: "podcast-create",
ns: "",
module: "Podcasts",
feature: "Make a podcast from a recording",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Library");
// the pasted transcript, not the uploaded file (pi-episode): its title is in the dialog, so its height depends on it
const recording = page.getByRole("main").getByRole("link", { name: /Welcome back/ }).filter({ hasNotText: "pi-episode" });
await meter.click(recording.first(), "the recording");
await page.waitForURL(/\/(recordings|resources)\//);
await meter.click(page.getByRole("main").getByRole("button", { name: "More actions" }), "More actions");
await meter.click(page.getByRole("menuitem", { name: /Create podcast/ }), "Create podcast…");
await meter.click(page.getByRole("dialog").getByRole("button", { name: "Create podcast" }), "Create podcast");
await page.waitForURL(/\/podcasts\/\d+/, { timeout: 30000 });
},
},
{
id: "report-pdf",
ns: "",
module: "Reports",
feature: "Save the namespace report as a PDF",
note: "The browser's print dialog does the saving (one click there, counted).",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Reports");
await page.evaluate(() => {
window.__printed = false;
window.print = () => (window.__printed = true);
});
await meter.click(page.getByRole("main").getByRole("button", { name: "PDF / HTML" }), "PDF / HTML");
await meter.click(page.getByRole("menuitem", { name: "Print or save as PDF" }), "Print or save as PDF");
await page.waitForFunction(() => window.__printed);
meter.record("outside", "the print dialog: Save", 1, 0);
},
},
{
id: "workflow-create",
ns: "",
module: "Pipelines",
feature: "Make a workflow",
from: "/",
note: "Lens guesses the name from what it runs on; it can be renamed on the workflow's page.",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Pipelines");
await meter.click(page.getByRole("tab", { name: /^Workflows/ }), "Workflows tab");
await meter.click(page.getByRole("main").getByRole("link", { name: "New workflow" }), "New workflow");
await meter.click(page.getByRole("button", { name: "Create workflow" }), "Create workflow");
await page.waitForURL(/\/workflows\/\d+/);
},
},
{
id: "template-create",
ns: "",
module: "Pipelines",
feature: "Make a prompt template",
from: "/",
note: "Lens guesses the name from the kind; it can be renamed on the template's page.",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Pipelines");
await meter.click(page.getByRole("tab", { name: /^Templates/ }), "Templates tab");
await meter.click(page.getByRole("main").getByRole("link", { name: "New template" }), "New template");
await meter.click(page.getByRole("button", { name: "Create and edit" }), "Create and edit");
await page.waitForURL(/\/templates\/\d+/);
},
},
{
id: "namespace-create",
ns: "",
module: "Admin",
feature: "Make a namespace",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Admin");
await meter.click(page.getByRole("tab", { name: /^Namespaces/ }), "Namespaces tab");
await meter.click(page.getByRole("main").getByRole("button", { name: "New namespace" }), "New namespace");
const d = page.getByRole("dialog");
await meter.type(d.getByRole("textbox", { name: "Name" }), "customer-calls", "name");
await meter.press("Enter", "Enter to create");
await page.getByRole("main").getByRole(&quo
10BC8
t;link", { name: "customer-calls" }).first().waitFor();
},
},
{
id: "speaker-rename",
ns: "interviews",
module: "Speakers",
feature: "Name a speaker",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Settings");
await meter.click(page.getByRole("main").getByRole("link", { name: "Host A", exact: true }), "Host A");
await meter.click(page.getByRole("main").getByRole("button", { name: "Rename" }), "Rename");
await meter.replace(page.getByRole("textbox").first(), "Alice", "the name");
await meter.press("Enter", "Enter to save");
await page.getByRole("heading", { name: "Alice", level: 1 }).waitFor();
},
},
{
id: "entity-merge",
// the namespace the imports above went to: with all namespaces picked, Entities opens the first by name, which
// namespace-create has made the empty customer-calls
ns: "interviews",
module: "Entities",
feature: "Merge two entities into one, then undo it",
note: "The merge happens at once and the notice has Undo, so nothing asks to confirm; Undo puts both back.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
// A slow machine can still be reading import-file's pi-episode here, and its mentions of Lens and Raspberry Pi
// landing between the merge and its Undo leave both out of the graph for graph-merge; so wait for the jobs to
// finish (not counted)
const idle = page.getByRole("button", { name: /^Activity: (Nothing running|\d+ failed)$/ });
await madeInBackground(ctx, "/", idle, "/", "the imports' jobs finished");
await go(ctx, "Entities");
const main = page.getByRole("main");
await meter.click(main.getByRole("checkbox", { name: "Pick Lens", exact: true }), "tick Lens");
await meter.click(main.getByRole("checkbox", { name: "Pick Raspberry Pi", exact: true }), "tick Raspberry Pi");
const bar = page.getByRole("toolbar", { name: "2 entities selected" });
await meter.click(bar.getByRole("button", { name: /^Merge into / }), "Merge into the one it keeps");
await page.getByText(/^Merged (Lens|Raspberry Pi) into /).first().waitFor();
await meter.click(page.getByRole("button", { name: "Undo" }), "Undo on the notice");
await page.getByText("Merge undone").first().waitFor();
},
},
{
id: "graph-merge",
ns: "interviews",
module: "Graph",
feature: "Merge an entity into another from the graph, then undo it",
note: "Find the node, Merge in its panel, type the other's name and Enter; the notice has Undo, so nothing asks to confirm.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
// An entity is in the graph once something links it twice (graph.min_edge_weight), which takes import-file's
// pi-episode as well; a slow machine can still be reading it here, so wait for the jobs to finish (not counted)
const idle = page.getByRole("button", { name: /^Activity: (Nothing running|\d+ failed)$/ });
await madeInBackground(ctx, "/", idle, "/", "the imports' jobs finished");
await go(ctx, "Graph");
const find = page.getByRole("combobox", { name: "Find in graph" });
await page.getByRole("region", { name: "Graph" }).waitFor();
await page.waitForTimeout(1000);
// On a phone the filters, the find box among them, sit behind a button
if (!(await find.isVisible())) await meter.click(page.getByRole("button", { name: "Filters" }), "Filters");
await meter.type(find, "rasp", "part of the name");
await page.getByRole("option", { name: /Raspberry Pi/ }).first().waitFor();
await meter.press("Enter", "Enter to pick it");
const filters = page.getByRole("dialog", { name: "Graph filters" });
if (await filters.isVisible().catch(() => false))
await meter.click(filters.getByRole("button", { name: "Close" }), "close the filters (they stay open over the node)");
await page.getByRole("heading", { name: "Raspberry Pi" }).first().waitFor();
await meter.click(page.getByRole("button", { name: "Merge", exact: true }).first(), "Merge in its panel");
await meter.type(page.getByRole("combobox", { name: "Entity to merge into Raspberry Pi" }), "lens", "the other's name");
await page.getByRole("option", { name: /^Lens/ }).first().waitFor();
await meter.press("Enter", "Enter to merge it");
await page.getByText("Merged Lens into Raspberry Pi").first().waitFor();
await meter.click(page.getByRole("button", { name: "Undo" }), "Undo on the notice");
await page.getByText("Merge undone").first().waitFor();
},
},
// --- Chat: versions, copying, exporting and tools. The new journeys go here, before cloud-model, which has to stay
// last: these need the stand-in model to answer ---------------------------------------------------------------------
{
id: "chat-regenerate",
ns: "",
module: "Chat",
feature: "Regenerate an answer, then switch back to the first version",
note: "In the conversation chat-ask started: Regenerate writes another answer beside it (2 / 2), and the arrow before the count shows the first again.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Chat");
await page.waitForURL(/\/chat$/);
// a computer's Chat lists the conversations beside a new one; a phone's opens on the list. Lens titles each
// after its first answer (the stand-in model from the question, fake-model.mjs)
const conversation = page
.getByRole("navigation", { name: "Conversations" })
.getByRole("link", { name: /Who said what about Raspberry Pi/ })
.first();
await meter.click(conversation, "the conversation");
await page.waitForURL(/\/chat\/\d+/);
await answered(page).waitFor();
const answer = page.getByRole("article", { name: "Answer" }).last();
await meter.click(answer.getByRole("button", { name: "Regenerate", exact: true }), "Regenerate");
// the stand-in model says which version it's writing (fake-model.mjs)
await page.getByRole("article", { name: "Answer" }).last().getByText(/answering, version 2/).waitFor({ timeout: 60000 });
const versions = page.getByRole("group", { name: "Versions of this answer" }).last();
await versions.getByText("2 / 2").waitFor();
await meter.click(versions.getByRole("button", { name: "Previous version of this answer" }), "Previous version (‹)");
await versions.getByText("1 / 2").waitFor();
await page.getByRole("article", { name: "Answer" }).last().getByText(/answering, version 2/).waitFor({ state: "hidden" });
},
},
{
id: "chat-copy",
module: "Chat",
feature: "Copy an answer",
note: "Continues chat-regenerate, in its conversation. Copy copies it as Markdown, its citations as footnotes; the arrow beside it has Copy text and Export.",
async run(ctx) {
const { page, meter, base } = ctx;
await page.context().grantPermissions(["clipboard-read", "clipboard-write"], { origin: base });
await page.evaluate(() => navigator.clipboard.writeText(""));
const answer = page.getByRole("article", { name: "Answer" }).last();
await meter.click(answer.getByRole("button", { name: "Copy", exact: true }), "Copy");
await page.getByText("Copied as Markdown").first().waitFor();
const copied = await page.evaluate(() => navigator.clipboard.readText());
if (!ANSWER.test(copied)) throw new Error(`copied ${JSON.stringify(copied.slice(0, 80))}, not the answer`);
},
},
{
id: "chat-export-pdf",
module: "Chat",
feature: "Export a conversation as a PDF",
note: "Continues chat-copy. The download icon in the conversation's header, then PDF. Where the server can make the PDF (Chromium, anytopdf or LibreOffice) the browser saves it; where it can't, the browser's print dialog opens on the conversation and does the saving (one click there, counted).",
async run(ctx) {
const { page, meter } = ctx;
await page.evaluate(() => {
window.__printed = false;
window.print = () => (window.__printed = true);
});
// anytopdf is fetched the first time a PDF is made, so the first can take a while
const wait = 180000;
const saved = page.waitForEvent("download", { timeout: wait }).then((d) => d, () => null);
await meter.click(page.getByRole("button", { name: "Export conversation" }), "Export conversation (the header's download icon)");
await meter.click(page.getByRole("menuitem", { name: "PDF" }), "PDF");
const printed = page.waitForFunction(() => window.__printed, null, { timeout: wait }).then(() => "printed", () => null);
const got = await Promise.race([saved, printed]);
if (got === "printed") {
await page.getByText("Printing it instead").first().waitFor();
meter.record("outside", "the print dialog: Save", 1, 0);
} else if (got) {
if (!got.suggestedFilename().endsWith(".pdf")) throw new Error(`downloaded ${got.suggestedFilename()}, not a PDF`);
} else throw new Error("neither a PDF nor the print dialog came");
},
},
{
id: "chat-tools",
module: "Chat",
feature: "Pick the tools and a tool-call limit for a conversation",
note: "Continues chat-export-pdf. The Tools chip beside the scope: switching one group off keeps the others (Auto goes off), and the limit starts at 10 calls. Each change is saved to the conversation as it's made, and new conversations start with it.",
async run(ctx) {
const { page, meter } = ctx;
await meter.click(page.getByRole("button", { name: /^Tools: Auto\. Choose the tools/ }), "the Tools chip (Tools: Auto)");
const picker = page.getByRole("dialog").filter({ has: page.getByRole("list", { name: "Tool groups" }) });
await meter.click(picker.getByRole("switch", { name: "The server", exact: true }), "switch off The server");
await meter.click(picker.getByRole("switch", { name: "Limit tool calls per answer" }), "Limit tool calls per answer (10)");
await meter.click(picker.getByRole("button", { name: "Done" }), "Done");
await page.getByRole("button", { name: /^Tools: \d+ picked · 10 calls\. / }).waitFor();
},
},
{
id: "chat-research",
ns: "podcasts",
module: "Chat",
feature: "Research a goal, approve its plan and save the report as a note",
note: "A new conversation in one namespace: the Deep research switch beside the composer, the goal and Enter; the plan comes back as a card to approve (Approve, or Enter in it), then the run's progress, then the cited report with Save as note. The stand-in model plans three sub-questions without asking anything first.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Chat");
const question = page.getByRole("textbox", { name: "Your question" });
// A phone's Chat opens on the list of conversations once there is one
if (!(await question.waitFor({ timeout: 3000 }).then(() => true, () => false)))
await meter.click(page.getByRole("button", { name: "New conversation" }), "New conversation");
await meter.click(page.getByRole("button", { name: "Deep research", exact: true }), "Deep research");
await meter.type(question, "What was said about Raspberry Pi?", "the goal");
await meter.press("Enter", "Enter to plan it");
const plan = page.getByRole("form", { name: "Research plan" });
await plan.waitFor({ timeout: 60000 });
await meter.click(plan.getByRole("button", { name: "Approve", exact: true }), "Approve");
// it runs in the background: the progress card, then the report and what can be done with it
const actions = page.getByRole("group", { name: "Report actions" });
await actions.waitFor({ timeout: 120000 });
await meter.click(actions.getByRole("button", { name: "Save as note" }), "Save as note");
await page.getByText("Saved as a note in podcasts").first().waitFor();
},
},
{
id: "automation-starter",
module: "Automations",
feature: "Make an automation from a starter and turn it on",
note: "The starter fills the builder in (When an email from the school arrives, tell me); it is saved switched on.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Automations");
await meter.click(page.getByRole("main").getByRole("link", { name: "New automation" }).first(), "New automation");
const starters = page.getByRole("group", { name: "Starters" });
await meter.click(starters.getByRole("button", { name: "Tell me about school emails" }), "the school starter");
await page.waitForFunction(() =>
[...document.querySelectorAll("input[aria-label=Name]")].some((i) => i.value === "Tell me about school emails"),
);
await meter.click(page.getByRole("button", { name: "Save and turn on" }), "Save and turn on");
await page.waitForURL(/\/automations\/\d+/);
},
},
{
// Last: it points Lens at a cloud model, which the stand-in model behind the journeys above isn't
id: "cloud-model",
ns: "",
module: "Setup",
feature: "Switch to a cloud model with an API key",
note: "What a Raspberry Pi install does after the installer: a cloud provider picked from the presets fills in its address and model, then a pasted key.",
from: "/",
async run(ctx) {
const { page, meter } = ctx;
await go(ctx, "Settings");
await section(ctx, "LLM provider");
const cloud = page.getByRole("group", { name: "Cloud providers" }).getByRole("button", { name: "OpenAI" });
await meter.click(cloud, "OpenAI (fills in the address and the model)");
// The key field takes the focus: a person sees the cursor land there before pasting
await page.waitForFunction(() => document.activeElement?.type === "password", null, { timeout: 3000 }).catch(() => {});
await meter.paste(page.getByRole("textbox", { name: "API key" }), "sk-survey-0000000000000000", "paste the API key");
await save(ctx);
await page.getByText(/Saved|Last saved/).first().waitFor();
},
},
];
export { TRANSCRIPT, ANSWER };