@tangle-network/agent-app 0.60.115 → 0.60.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/VaultPane-OWOPGPXP.js +7 -0
- package/dist/assistant/index.js +11 -11
- package/dist/chat-react/index.js +4 -4
- package/dist/chat-routes/index.js +13 -6
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/wire.d.ts +3 -1
- package/dist/chat-store/index.js +2 -2
- package/dist/{chunk-Y4WLCFDZ.js → chunk-2FLSODOX.js} +6 -6
- package/dist/{chunk-6XE77PTT.js → chunk-2NHJNINW.js} +1 -1
- package/dist/chunk-2NHJNINW.js.map +1 -0
- package/dist/{chunk-56GPDCOJ.js → chunk-7DXRHQZO.js} +7 -7
- package/dist/chunk-BTEVD7HG.js +198 -0
- package/dist/chunk-BTEVD7HG.js.map +1 -0
- package/dist/{chunk-RQSYR4AV.js → chunk-CLB4IQEG.js} +5 -5
- package/dist/{chunk-F2FH354I.js → chunk-D52LB6UQ.js} +2 -2
- package/dist/chunk-FVI2MHUL.js +1152 -0
- package/dist/chunk-FVI2MHUL.js.map +1 -0
- package/dist/{chunk-4G7HH6WQ.js → chunk-GU7OZFU7.js} +2 -2
- package/dist/{chunk-OGDEUCNW.js → chunk-JGLK5RDK.js} +176 -1
- package/dist/chunk-JGLK5RDK.js.map +1 -0
- package/dist/{chunk-FJQUMIM6.js → chunk-JZUSVGRJ.js} +3 -3
- package/dist/{chunk-AB63T2LM.js → chunk-KBJZMR4E.js} +8 -1
- package/dist/chunk-KBJZMR4E.js.map +1 -0
- package/dist/{chunk-JCSHTJT6.js → chunk-MGON3FE6.js} +22 -3
- package/dist/chunk-MGON3FE6.js.map +1 -0
- package/dist/{chunk-RQSNTJTW.js → chunk-MO7PDQRZ.js} +526 -187
- package/dist/chunk-MO7PDQRZ.js.map +1 -0
- package/dist/{chunk-MEUNTJL5.js → chunk-N3CYCSKK.js} +6 -1
- package/dist/chunk-N3CYCSKK.js.map +1 -0
- package/dist/journeys/cli.d.ts +2 -0
- package/dist/journeys/cli.js +165 -0
- package/dist/journeys/cli.js.map +1 -0
- package/dist/journeys/config.d.ts +96 -0
- package/dist/journeys/index.d.ts +18 -0
- package/dist/journeys/index.js +731 -0
- package/dist/journeys/index.js.map +1 -0
- package/dist/journeys/journey.d.ts +173 -0
- package/dist/journeys/page-reading.d.ts +42 -0
- package/dist/journeys/report.d.ts +51 -0
- package/dist/journeys/score.d.ts +115 -0
- package/dist/journeys/scrub.d.ts +21 -0
- package/dist/journeys/send.d.ts +46 -0
- package/dist/journeys/session.d.ts +27 -0
- package/dist/journeys/trace-zip.d.ts +28 -0
- package/dist/journeys/video.d.ts +53 -0
- package/dist/public-consultation/index.d.ts +2 -2
- package/dist/public-consultation/index.js +3 -3
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/router-turn.d.ts +23 -2
- package/dist/runtime/router-turn.js +1 -1
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/sandbox/index.js +13 -1
- package/dist/sandbox/sandbox-exec-tool.d.ts +68 -0
- package/dist/sandbox/sandbox-run-tool.d.ts +70 -0
- package/dist/studio-react/index.js +2 -2
- package/dist/teams/index.js +10 -6
- package/dist/teams/invitations-api.js +6 -3
- package/dist/teams/invitations-api.js.map +1 -1
- package/dist/teams/invitations.d.ts +4 -0
- package/dist/teams/members-api.js +2 -1
- package/dist/teams-react/components/InviteForm.d.ts +20 -0
- package/dist/teams-react/contracts.d.ts +2 -0
- package/dist/teams-react/index.js +196 -217
- package/dist/teams-react/index.js.map +1 -1
- package/dist/vault/VaultContentResults.d.ts +29 -0
- package/dist/vault/VaultHistoryPanel.d.ts +20 -0
- package/dist/vault/VaultPane.d.ts +3 -1
- package/dist/vault/contracts.d.ts +38 -0
- package/dist/vault/index.js +1 -1
- package/dist/vault/lazy.js +1 -1
- package/dist/web-react/index.js +25 -25
- package/dist/workspace-export/index.js +4 -193
- package/dist/workspace-export/index.js.map +1 -1
- package/dist/workspace-react/index.js +9 -7
- package/dist/workspace-react/index.js.map +1 -1
- package/dist/workspace-react/workspace-list.d.ts +7 -1
- package/package.json +8 -2
- package/dist/VaultPane-JUSNGOV7.js +0 -7
- package/dist/chunk-6XE77PTT.js.map +0 -1
- package/dist/chunk-AB63T2LM.js.map +0 -1
- package/dist/chunk-JCSHTJT6.js.map +0 -1
- package/dist/chunk-MEUNTJL5.js.map +0 -1
- package/dist/chunk-OGDEUCNW.js.map +0 -1
- package/dist/chunk-RQSNTJTW.js.map +0 -1
- /package/dist/{VaultPane-JUSNGOV7.js.map → VaultPane-OWOPGPXP.js.map} +0 -0
- /package/dist/{chunk-Y4WLCFDZ.js.map → chunk-2FLSODOX.js.map} +0 -0
- /package/dist/{chunk-56GPDCOJ.js.map → chunk-7DXRHQZO.js.map} +0 -0
- /package/dist/{chunk-RQSYR4AV.js.map → chunk-CLB4IQEG.js.map} +0 -0
- /package/dist/{chunk-F2FH354I.js.map → chunk-D52LB6UQ.js.map} +0 -0
- /package/dist/{chunk-4G7HH6WQ.js.map → chunk-GU7OZFU7.js.map} +0 -0
- /package/dist/{chunk-FJQUMIM6.js.map → chunk-JZUSVGRJ.js.map} +0 -0
|
@@ -0,0 +1,731 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONFIG_FILE_NAMES,
|
|
3
|
+
DEFAULT_AUTH_PATHS,
|
|
4
|
+
DEFAULT_CHAT_CONTRACT,
|
|
5
|
+
DEFAULT_FAILURE_TEXT,
|
|
6
|
+
DEFAULT_STOPPED_TEXT,
|
|
7
|
+
MAX_HIGHLIGHTS_S,
|
|
8
|
+
STATUS_STALE_MS,
|
|
9
|
+
TurnEvidence,
|
|
10
|
+
assertNoSecrets,
|
|
11
|
+
chapterCues,
|
|
12
|
+
collectJourneyFiles,
|
|
13
|
+
credentialNames,
|
|
14
|
+
defineJourneys,
|
|
15
|
+
extractFrames,
|
|
16
|
+
highlightPlan,
|
|
17
|
+
loadJourneysConfig,
|
|
18
|
+
postProcessVideo,
|
|
19
|
+
rebuildVideo,
|
|
20
|
+
renderIndex,
|
|
21
|
+
resolveJourneysConfig,
|
|
22
|
+
scoreTurn,
|
|
23
|
+
scrubTrace,
|
|
24
|
+
secretNeedles,
|
|
25
|
+
sessionUser,
|
|
26
|
+
storageStateFor,
|
|
27
|
+
tallyTurns,
|
|
28
|
+
threadRouteIn,
|
|
29
|
+
turnLooksActive
|
|
30
|
+
} from "../chunk-FVI2MHUL.js";
|
|
31
|
+
import "../chunk-BTEVD7HG.js";
|
|
32
|
+
|
|
33
|
+
// src/journeys/journey.ts
|
|
34
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
35
|
+
import { hostname } from "os";
|
|
36
|
+
import { join } from "path";
|
|
37
|
+
|
|
38
|
+
// src/journeys/page-reading.ts
|
|
39
|
+
function promptHead(prompt) {
|
|
40
|
+
const first = prompt.split("\n").map((line) => line.replace(/\s+/g, " ").trim()).find(Boolean);
|
|
41
|
+
return first ? first.slice(0, 48) : null;
|
|
42
|
+
}
|
|
43
|
+
function readChatPage(c) {
|
|
44
|
+
const squash = (s) => s.replace(/\s+/g, " ").trim();
|
|
45
|
+
const clean = (e) => squash(e.textContent ?? "");
|
|
46
|
+
const region = document.querySelector(c.transcript);
|
|
47
|
+
const composer = document.querySelector(c.composer);
|
|
48
|
+
const assistantNodes = c.assistant ? Array.from(document.querySelectorAll(c.assistant)) : [];
|
|
49
|
+
const within = (sel) => region ? Array.from(region.querySelectorAll(sel)) : [];
|
|
50
|
+
let anchor = null;
|
|
51
|
+
if (region && c.promptHead) {
|
|
52
|
+
const walker = document.createTreeWalker(region, NodeFilter.SHOW_TEXT);
|
|
53
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
54
|
+
if (!squash(node.nodeValue ?? "").includes(c.promptHead)) continue;
|
|
55
|
+
if (composer?.contains(node) || assistantNodes.some((a) => a.contains(node))) continue;
|
|
56
|
+
anchor = node;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const after = (e) => anchor === null || (anchor.compareDocumentPosition(e) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;
|
|
60
|
+
const full = region?.innerText ?? "";
|
|
61
|
+
let text = full;
|
|
62
|
+
const composerText = composer && region?.contains(composer) ? composer.innerText.trim() : "";
|
|
63
|
+
if (composerText) {
|
|
64
|
+
const at = text.lastIndexOf(composerText);
|
|
65
|
+
if (at >= 0) text = text.slice(0, at) + text.slice(at + composerText.length);
|
|
66
|
+
}
|
|
67
|
+
let lines = text.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
68
|
+
if (anchor && c.promptHead) {
|
|
69
|
+
const replyLines = new Set(assistantNodes.flatMap((a) => a.innerText.split("\n").map(squash)));
|
|
70
|
+
let last = -1;
|
|
71
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
72
|
+
const line = squash(lines[i]);
|
|
73
|
+
if (line.includes(c.promptHead) && !replyLines.has(line)) last = i;
|
|
74
|
+
}
|
|
75
|
+
lines = lines.slice(last + 1);
|
|
76
|
+
}
|
|
77
|
+
const status = within(c.status).map(clean).filter(Boolean);
|
|
78
|
+
const failureNodes = within(c.failureNodes).filter(after).map(clean).filter(Boolean);
|
|
79
|
+
const retry = new RegExp(c.retrySource, c.retryFlags);
|
|
80
|
+
const retryButtons = within("button").filter((b) => after(b) && retry.test((b.getAttribute("aria-label") ?? b.textContent ?? "").trim())).length;
|
|
81
|
+
const assistant = c.assistant ? assistantNodes.map((e) => e.innerText).join("\n").trim().length : -1;
|
|
82
|
+
const stopVisible = composer !== null && Array.from(composer.querySelectorAll("button")).some((b) => (b.getAttribute("aria-label") ?? b.textContent ?? "").trim() === c.stopName && b.getClientRects().length > 0);
|
|
83
|
+
return { lines, failureNodes, retryButtons, status, assistant, transcriptChars: full.trim().length, stopVisible, anchored: anchor !== null };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/journeys/send.ts
|
|
87
|
+
function routeSubmitPaths(routePath) {
|
|
88
|
+
const singleFetch = routePath.endsWith("/") ? `${routePath}_.data` : `${routePath}.data`;
|
|
89
|
+
return [routePath, singleFetch];
|
|
90
|
+
}
|
|
91
|
+
function createSubmissionTracker(routeUrl, sendPaths) {
|
|
92
|
+
if (!/^https?:\/\//i.test(routeUrl)) throw new Error(`createSubmissionTracker needs the page's full URL, got "${routeUrl}"`);
|
|
93
|
+
const route = new URL(routeUrl);
|
|
94
|
+
const exact = new Set(routeSubmitPaths(route.pathname));
|
|
95
|
+
let count = 0;
|
|
96
|
+
const matches = (method, url) => {
|
|
97
|
+
if (method !== "POST") return false;
|
|
98
|
+
let parsed;
|
|
99
|
+
try {
|
|
100
|
+
parsed = new URL(url, route.origin);
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (parsed.origin !== route.origin) return false;
|
|
105
|
+
return exact.has(parsed.pathname) || sendPaths.some((p) => p.test(parsed.pathname));
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
matches,
|
|
109
|
+
observe(method, url) {
|
|
110
|
+
if (matches(method, url)) count += 1;
|
|
111
|
+
},
|
|
112
|
+
get count() {
|
|
113
|
+
return count;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function clickUntilSubmitted(ops) {
|
|
118
|
+
for (let attempt = 0; attempt < ops.attempts; attempt += 1) {
|
|
119
|
+
if (ops.landed()) return;
|
|
120
|
+
try {
|
|
121
|
+
await ops.ready();
|
|
122
|
+
if (ops.landed()) return;
|
|
123
|
+
await ops.click();
|
|
124
|
+
} catch (cause) {
|
|
125
|
+
if (!ops.landed()) throw cause;
|
|
126
|
+
}
|
|
127
|
+
if (ops.landed()) return;
|
|
128
|
+
await ops.wait();
|
|
129
|
+
}
|
|
130
|
+
if (ops.landed()) return;
|
|
131
|
+
throw new Error(`Send never submitted: the composer refused ${ops.attempts} presses`);
|
|
132
|
+
}
|
|
133
|
+
async function settleText(read, wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), timeoutMs = 2e4) {
|
|
134
|
+
const deadline = Date.now() + timeoutMs;
|
|
135
|
+
let previous = null;
|
|
136
|
+
let stable = 0;
|
|
137
|
+
for (; ; ) {
|
|
138
|
+
const current = await read().catch(() => null);
|
|
139
|
+
if (current === null) {
|
|
140
|
+
stable = 0;
|
|
141
|
+
} else {
|
|
142
|
+
stable = current === previous ? stable + 1 : 1;
|
|
143
|
+
previous = current;
|
|
144
|
+
if (stable >= 6) return current;
|
|
145
|
+
}
|
|
146
|
+
if (Date.now() >= deadline) return previous ?? "";
|
|
147
|
+
await wait(500);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/journeys/journey.ts
|
|
152
|
+
var DESKTOP = { width: 1440, height: 900 };
|
|
153
|
+
var PHONE = { width: 390, height: 844 };
|
|
154
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
155
|
+
var secs = (ms) => Math.round(ms / 100) / 10;
|
|
156
|
+
var CURSOR_SCRIPT = `(() => {
|
|
157
|
+
const install = () => {
|
|
158
|
+
if (document.getElementById('__journey_cursor') || !document.body) return
|
|
159
|
+
const dot = document.createElement('div')
|
|
160
|
+
dot.id = '__journey_cursor'
|
|
161
|
+
dot.setAttribute('aria-hidden', 'true')
|
|
162
|
+
Object.assign(dot.style, { position: 'fixed', zIndex: '2147483647', width: '24px', height: '24px',
|
|
163
|
+
margin: '-12px 0 0 -12px', borderRadius: '50%', background: 'rgba(255,72,48,.28)',
|
|
164
|
+
border: '2px solid rgba(255,72,48,.95)', pointerEvents: 'none', left: (window.__jx ?? -100) + 'px',
|
|
165
|
+
top: (window.__jy ?? -100) + 'px', transition: 'transform .12s ease-out' })
|
|
166
|
+
document.body.appendChild(dot)
|
|
167
|
+
}
|
|
168
|
+
addEventListener('mousemove', (e) => { window.__jx = e.clientX; window.__jy = e.clientY
|
|
169
|
+
const d = document.getElementById('__journey_cursor'); if (d) { d.style.left = e.clientX + 'px'; d.style.top = e.clientY + 'px' } }, true)
|
|
170
|
+
addEventListener('mousedown', () => { const d = document.getElementById('__journey_cursor'); if (d) d.style.transform = 'scale(.55)' }, true)
|
|
171
|
+
addEventListener('mouseup', () => { const d = document.getElementById('__journey_cursor'); if (d) d.style.transform = 'scale(1)' }, true)
|
|
172
|
+
// After hydration, so the framework never meets a node it did not render.
|
|
173
|
+
addEventListener('load', () => setTimeout(install, 1500))
|
|
174
|
+
setInterval(install, 2000)
|
|
175
|
+
})()`;
|
|
176
|
+
var Journey = class {
|
|
177
|
+
constructor(id, config, browser, opts) {
|
|
178
|
+
this.id = id;
|
|
179
|
+
this.config = config;
|
|
180
|
+
this.browser = browser;
|
|
181
|
+
this.opts = opts;
|
|
182
|
+
this.outDir = join(config.outDir, id);
|
|
183
|
+
this.rawDir = join(config.stateDir, "raw", `${id}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}`);
|
|
184
|
+
mkdirSync(join(this.outDir, "video"), { recursive: true });
|
|
185
|
+
mkdirSync(join(this.outDir, "turns"), { recursive: true });
|
|
186
|
+
mkdirSync(this.rawDir, { recursive: true, mode: 448 });
|
|
187
|
+
}
|
|
188
|
+
id;
|
|
189
|
+
config;
|
|
190
|
+
browser;
|
|
191
|
+
opts;
|
|
192
|
+
outDir;
|
|
193
|
+
rawDir;
|
|
194
|
+
chapters = [];
|
|
195
|
+
steps = [];
|
|
196
|
+
turns = [];
|
|
197
|
+
recorded = [];
|
|
198
|
+
phones = /* @__PURE__ */ new Map();
|
|
199
|
+
startedAt = Date.now();
|
|
200
|
+
/**
|
|
201
|
+
* A recorded, traced 1440x900 context. A config identity starts signed in
|
|
202
|
+
* from the cached session (no login form is ever recorded); `'anon'` starts
|
|
203
|
+
* signed out, for public pages. Open at most two per journey.
|
|
204
|
+
*/
|
|
205
|
+
async open(label, identity, opts = {}) {
|
|
206
|
+
if (this.recorded.some((r) => r.label === label)) throw new Error(`a context labelled ${label} is already open`);
|
|
207
|
+
if (!/^[a-z0-9][a-z0-9-]{0,30}$/.test(label)) throw new Error("context label: lowercase letters, digits and dashes");
|
|
208
|
+
const storageState = identity === "anon" ? void 0 : (await storageStateFor(this.config, identity, opts)).path;
|
|
209
|
+
const rawDir = join(this.rawDir, label);
|
|
210
|
+
const context = await this.browser.newContext({
|
|
211
|
+
baseURL: this.config.baseUrl,
|
|
212
|
+
storageState,
|
|
213
|
+
viewport: DESKTOP,
|
|
214
|
+
recordVideo: { dir: rawDir, size: DESKTOP },
|
|
215
|
+
locale: "en-US",
|
|
216
|
+
timezoneId: "America/Denver"
|
|
217
|
+
});
|
|
218
|
+
context.setDefaultTimeout(2e4);
|
|
219
|
+
context.setDefaultNavigationTimeout(6e4);
|
|
220
|
+
if (this.opts.cursor) await context.addInitScript(CURSOR_SCRIPT);
|
|
221
|
+
if (process.env.JOURNEY_DEBUG_CLOCK === "1") {
|
|
222
|
+
await context.addInitScript((t0) => {
|
|
223
|
+
setInterval(() => {
|
|
224
|
+
let d = document.getElementById("__journey_clock");
|
|
225
|
+
if (!d && document.body) {
|
|
226
|
+
d = document.createElement("div");
|
|
227
|
+
d.id = "__journey_clock";
|
|
228
|
+
Object.assign(d.style, { position: "fixed", left: "50%", top: "0", zIndex: "2147483647", font: "bold 20px monospace", background: "#ff0", color: "#000", padding: "2px 6px", pointerEvents: "none" });
|
|
229
|
+
document.body.appendChild(d);
|
|
230
|
+
}
|
|
231
|
+
if (d) d.textContent = ((Date.now() - t0) / 1e3).toFixed(1);
|
|
232
|
+
}, 100);
|
|
233
|
+
}, Date.now());
|
|
234
|
+
}
|
|
235
|
+
await context.tracing.start({ screenshots: true, snapshots: true, title: `${this.id} ${label}` });
|
|
236
|
+
const page = await context.newPage();
|
|
237
|
+
this.recorded.push({ label, identity, context, page, t0: Date.now(), rawDir });
|
|
238
|
+
return page;
|
|
239
|
+
}
|
|
240
|
+
recordedFor(page) {
|
|
241
|
+
const r = page ? this.recorded.find((x) => x.page === page) : this.recorded[0];
|
|
242
|
+
if (!r) throw new Error("no recorded context for that page; call open() first");
|
|
243
|
+
return r;
|
|
244
|
+
}
|
|
245
|
+
/** A chapter at this instant: one plain line, shown in the caption bar and the .srt. */
|
|
246
|
+
mark(caption, page) {
|
|
247
|
+
const label = page ? this.recordedFor(page).label : null;
|
|
248
|
+
this.chapters.push({ at: Date.now(), caption, label, kind: "step" });
|
|
249
|
+
console.log(`[${secs(Date.now() - this.startedAt).toFixed(1)}s] ${label ? `${label}: ` : ""}${caption}`);
|
|
250
|
+
}
|
|
251
|
+
/** A timed step with its own chapter. A failure is recorded, captioned, then rethrown. */
|
|
252
|
+
async step(caption, work, page) {
|
|
253
|
+
this.mark(caption, page);
|
|
254
|
+
const start = Date.now();
|
|
255
|
+
const entry = { caption, label: page ? this.recordedFor(page).label : null, startS: secs(start - this.startedAt), durationS: 0, ok: true };
|
|
256
|
+
this.steps.push(entry);
|
|
257
|
+
try {
|
|
258
|
+
return await work();
|
|
259
|
+
} catch (error) {
|
|
260
|
+
entry.ok = false;
|
|
261
|
+
entry.error = String(error?.message ?? error).slice(0, 400);
|
|
262
|
+
this.mark(`Step failed: ${caption}`, page);
|
|
263
|
+
throw error;
|
|
264
|
+
} finally {
|
|
265
|
+
entry.durationS = secs(Date.now() - start);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** A waiting span: real speed in the full video, sped up and labelled in the highlights. */
|
|
269
|
+
async wait(caption, work, page) {
|
|
270
|
+
const label = page ? this.recordedFor(page).label : null;
|
|
271
|
+
const chapter = { at: Date.now(), caption, label, kind: "wait", until: Date.now() };
|
|
272
|
+
this.chapters.push(chapter);
|
|
273
|
+
console.log(`[${secs(Date.now() - this.startedAt).toFixed(1)}s] ${label ? `${label}: ` : ""}(wait) ${caption}`);
|
|
274
|
+
try {
|
|
275
|
+
return await work();
|
|
276
|
+
} finally {
|
|
277
|
+
chapter.until = Date.now();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
pause(ms = 700) {
|
|
281
|
+
return sleep(ms);
|
|
282
|
+
}
|
|
283
|
+
/** Move the visible pointer there, pause, click, pause. */
|
|
284
|
+
async click(target, opts = {}) {
|
|
285
|
+
await target.scrollIntoViewIfNeeded();
|
|
286
|
+
const box = await target.boundingBox();
|
|
287
|
+
if (box) await target.page().mouse.move(box.x + box.width / 2, box.y + box.height / 2, { steps: 14 });
|
|
288
|
+
await sleep(250);
|
|
289
|
+
await target.click();
|
|
290
|
+
await sleep(opts.pauseAfter ?? 600);
|
|
291
|
+
}
|
|
292
|
+
/** Type at a readable pace into an input or textarea. */
|
|
293
|
+
async type(target, text, opts = {}) {
|
|
294
|
+
await this.click(target, { pauseAfter: 200 });
|
|
295
|
+
const delay = opts.delay ?? 28;
|
|
296
|
+
await target.pressSequentially(text, { delay, timeout: 3e4 + text.length * (delay + 60) });
|
|
297
|
+
await sleep(400);
|
|
298
|
+
}
|
|
299
|
+
/** The composer's message input. */
|
|
300
|
+
composerInput(page) {
|
|
301
|
+
return page.locator(this.config.chat.composer).getByRole("textbox", { name: this.config.chat.inputName });
|
|
302
|
+
}
|
|
303
|
+
composerButton(page, name) {
|
|
304
|
+
return page.locator(this.config.chat.composer).getByRole("button", { name, exact: true });
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Type into the chat composer at a readable pace. A line break is typed as
|
|
308
|
+
* Shift+Enter, because Enter sends. Retries fast when hydration dropped
|
|
309
|
+
* keystrokes. Never `fill()` a rich-text composer.
|
|
310
|
+
*/
|
|
311
|
+
async typePrompt(page, prompt, opts = {}) {
|
|
312
|
+
const box = this.composerInput(page);
|
|
313
|
+
await box.waitFor({ state: "visible", timeout: 3e4 });
|
|
314
|
+
await sleep(1200);
|
|
315
|
+
const delay = opts.delay ?? (prompt.length > 400 ? 8 : 22);
|
|
316
|
+
const want = prompt.replace(/\s+/g, " ").trim().slice(0, 80);
|
|
317
|
+
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
318
|
+
await this.click(box, { pauseAfter: 150 });
|
|
319
|
+
await box.press("ControlOrMeta+a");
|
|
320
|
+
await box.press("Backspace");
|
|
321
|
+
const lines = prompt.split("\n");
|
|
322
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
323
|
+
if (i > 0) await box.press("Shift+Enter");
|
|
324
|
+
const line = lines[i];
|
|
325
|
+
if (line) await box.pressSequentially(line, { delay: attempt === 0 ? delay : 0, timeout: 3e4 + line.length * (delay + 60) });
|
|
326
|
+
}
|
|
327
|
+
const text = (await box.innerText().catch(() => "")).replace(/\s+/g, " ").trim();
|
|
328
|
+
if (text.includes(want)) return;
|
|
329
|
+
await sleep(1e3);
|
|
330
|
+
}
|
|
331
|
+
throw new Error("the composer never held the prompt");
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Which parts of the chat contract this page shows, without sending
|
|
335
|
+
* anything. Run it on a second app before trusting turn timings there.
|
|
336
|
+
*/
|
|
337
|
+
async checkChatContract(page) {
|
|
338
|
+
const visible = (l) => l.first().isVisible().catch(() => false);
|
|
339
|
+
return {
|
|
340
|
+
transcript: await visible(page.locator(this.config.chat.transcript)),
|
|
341
|
+
composer: await visible(page.locator(this.config.chat.composer)),
|
|
342
|
+
input: await visible(this.composerInput(page)),
|
|
343
|
+
send: await visible(this.composerButton(page, this.config.chat.sendName))
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Desktop screenshot of the recorded page, then the same URL in a phone
|
|
348
|
+
* context (390x844, same identity). Look at both before judging the screen.
|
|
349
|
+
*/
|
|
350
|
+
async shot(name, page, opts = {}) {
|
|
351
|
+
const r = this.recordedFor(page);
|
|
352
|
+
const slug = name.replace(/[^a-z0-9-]+/gi, "-").toLowerCase();
|
|
353
|
+
const desktop = join(this.outDir, `${slug}-desktop.png`);
|
|
354
|
+
const cursor = (display) => r.page.evaluate((d) => {
|
|
355
|
+
const c = document.getElementById("__journey_cursor");
|
|
356
|
+
if (c) c.style.display = d;
|
|
357
|
+
}, display).catch(() => {
|
|
358
|
+
});
|
|
359
|
+
await cursor("none");
|
|
360
|
+
await r.page.screenshot({ path: desktop, fullPage: opts.fullPage ?? false });
|
|
361
|
+
await cursor("");
|
|
362
|
+
if (opts.phone === false) return { desktop };
|
|
363
|
+
const phonePath = join(this.outDir, `${slug}-phone.png`);
|
|
364
|
+
let ctx = this.phones.get(r.identity);
|
|
365
|
+
if (!ctx) {
|
|
366
|
+
const storageState = r.identity === "anon" ? void 0 : (await storageStateFor(this.config, r.identity)).path;
|
|
367
|
+
ctx = await this.browser.newContext({ baseURL: this.config.baseUrl, storageState, viewport: PHONE, deviceScaleFactor: 2, isMobile: true, hasTouch: true, locale: "en-US", timezoneId: "America/Denver" });
|
|
368
|
+
this.phones.set(r.identity, ctx);
|
|
369
|
+
}
|
|
370
|
+
const phone = await ctx.newPage();
|
|
371
|
+
try {
|
|
372
|
+
await phone.goto(opts.phoneUrl ?? r.page.url(), { waitUntil: "load" });
|
|
373
|
+
await phone.waitForLoadState("networkidle", { timeout: 8e3 }).catch(() => {
|
|
374
|
+
});
|
|
375
|
+
await sleep(1500);
|
|
376
|
+
await phone.screenshot({ path: phonePath, fullPage: opts.fullPage ?? false });
|
|
377
|
+
} finally {
|
|
378
|
+
await phone.close();
|
|
379
|
+
}
|
|
380
|
+
return { desktop, phone: phonePath };
|
|
381
|
+
}
|
|
382
|
+
budgetTurn() {
|
|
383
|
+
if (this.turns.length >= this.config.maxTurns) {
|
|
384
|
+
throw new Error(`this journey already sent ${this.turns.length} chat turns, its budget (maxTurns ${this.config.maxTurns})`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Start a new thread: open `from` when given, type the prompt, press Send
|
|
389
|
+
* like a person (again only while the page has not submitted; never deletes
|
|
390
|
+
* a duplicate), wait for the thread, then measure the turn.
|
|
391
|
+
*/
|
|
392
|
+
async sendNew(page, prompt, opts = {}) {
|
|
393
|
+
this.budgetTurn();
|
|
394
|
+
if (opts.from && !page.url().startsWith(new URL(opts.from, this.config.baseUrl).href)) await page.goto(opts.from);
|
|
395
|
+
await this.typePrompt(page, prompt, { delay: opts.delay });
|
|
396
|
+
const send = this.composerButton(page, this.config.chat.sendName);
|
|
397
|
+
await send.waitFor({ state: "visible" });
|
|
398
|
+
const box = await send.boundingBox();
|
|
399
|
+
if (box) await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2, { steps: 14 });
|
|
400
|
+
await sleep(400);
|
|
401
|
+
const before = await this.read(page, prompt);
|
|
402
|
+
const evidence = new TurnEvidence(this.patterns(), prompt);
|
|
403
|
+
evidence.begin(before);
|
|
404
|
+
const tracker = createSubmissionTracker(page.url(), this.config.chat.sendPaths);
|
|
405
|
+
const count = (request) => tracker.observe(request.method(), request.url());
|
|
406
|
+
page.on("request", count);
|
|
407
|
+
this.mark(opts.caption ?? `Sends: "${oneLine(prompt, 90)}"`, page);
|
|
408
|
+
const sentAt = Date.now();
|
|
409
|
+
const onThread = () => threadRouteIn(page.url(), this.config) !== null;
|
|
410
|
+
try {
|
|
411
|
+
await clickUntilSubmitted({
|
|
412
|
+
landed: () => tracker.count > 0 || onThread(),
|
|
413
|
+
ready: () => send.click({ trial: true, timeout: 5e3 }),
|
|
414
|
+
click: () => send.click({ timeout: 5e3 }),
|
|
415
|
+
wait: () => page.waitForRequest((r) => tracker.matches(r.method(), r.url()), { timeout: 1e3 }).then(() => void 0).catch(() => void 0),
|
|
416
|
+
attempts: 15
|
|
417
|
+
});
|
|
418
|
+
if (this.config.chat.threadPath) await page.waitForURL((url) => threadRouteIn(url.href, this.config) !== null, { timeout: 45e3 });
|
|
419
|
+
} catch (error) {
|
|
420
|
+
return this.notSent(page, prompt, sentAt, String(error.message).slice(0, 300));
|
|
421
|
+
} finally {
|
|
422
|
+
page.off("request", count);
|
|
423
|
+
}
|
|
424
|
+
if (tracker.count > 1) console.warn(`the composer submitted ${tracker.count} times; a duplicate thread may exist (left in place)`);
|
|
425
|
+
return this.measureTurn(page, prompt, sentAt, evidence, before, 0, opts);
|
|
426
|
+
}
|
|
427
|
+
/** A follow-up in the open thread: type, one Send press, measure. */
|
|
428
|
+
async sendInThread(page, prompt, opts = {}) {
|
|
429
|
+
this.budgetTurn();
|
|
430
|
+
await this.typePrompt(page, prompt, { delay: opts.delay });
|
|
431
|
+
const send = this.composerButton(page, this.config.chat.sendName);
|
|
432
|
+
const before = await this.read(page, prompt);
|
|
433
|
+
const evidence = new TurnEvidence(this.patterns(), prompt);
|
|
434
|
+
evidence.begin(before);
|
|
435
|
+
const tracker = createSubmissionTracker(page.url(), this.config.chat.sendPaths);
|
|
436
|
+
const posted = page.waitForRequest((r) => tracker.matches(r.method(), r.url()), { timeout: 3e4 });
|
|
437
|
+
this.mark(opts.caption ?? `Follows up: "${oneLine(prompt, 90)}"`, page);
|
|
438
|
+
const sentAt = Date.now();
|
|
439
|
+
await this.click(send, { pauseAfter: 0 });
|
|
440
|
+
const sent = await posted.then(() => true).catch(() => false);
|
|
441
|
+
if (!sent) return this.notSent(page, prompt, sentAt, "no chat request within 30 s of pressing Send");
|
|
442
|
+
return this.measureTurn(page, prompt, sentAt, evidence, before, Math.max(0, before.assistantChars), opts);
|
|
443
|
+
}
|
|
444
|
+
patterns() {
|
|
445
|
+
return { failure: this.config.chat.failureText, stopped: this.config.chat.stoppedText };
|
|
446
|
+
}
|
|
447
|
+
blankTurn(page, prompt, sentAt) {
|
|
448
|
+
return {
|
|
449
|
+
label: this.recordedFor(page).label,
|
|
450
|
+
prompt,
|
|
451
|
+
threadId: threadRouteIn(page.url(), this.config)?.threadId ?? null,
|
|
452
|
+
sentAt: new Date(sentAt).toISOString(),
|
|
453
|
+
firstProgressS: null,
|
|
454
|
+
firstProgressText: null,
|
|
455
|
+
firstTextS: null,
|
|
456
|
+
firstFailureS: null,
|
|
457
|
+
completeS: null,
|
|
458
|
+
outcome: "timeout",
|
|
459
|
+
error: null,
|
|
460
|
+
failures: [],
|
|
461
|
+
evidenceScope: null,
|
|
462
|
+
replyChars: 0,
|
|
463
|
+
stages: [],
|
|
464
|
+
stopPressedS: null,
|
|
465
|
+
replyFile: null
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
notSent(page, prompt, sentAt, why) {
|
|
469
|
+
const t = { ...this.blankTurn(page, prompt, sentAt), ...scoreTurn({ notSent: why, timedOut: false, evidence: { failures: [], stopped: [], retryAppeared: false }, replyChars: 0, stopPressed: false }) };
|
|
470
|
+
this.turns.push(t);
|
|
471
|
+
this.mark(`Turn not sent: ${oneLine(why, 90)}`, page);
|
|
472
|
+
return t;
|
|
473
|
+
}
|
|
474
|
+
/** One read of the transcript, composer and failure marks; with a prompt, the evidence that follows it. */
|
|
475
|
+
async read(page, prompt = null) {
|
|
476
|
+
const c = this.config.chat;
|
|
477
|
+
const { assistant, ...reading } = await page.evaluate(readChatPage, {
|
|
478
|
+
transcript: c.transcript,
|
|
479
|
+
status: c.status,
|
|
480
|
+
failureNodes: c.failureNodes,
|
|
481
|
+
retrySource: c.retryName.source,
|
|
482
|
+
retryFlags: c.retryName.flags,
|
|
483
|
+
assistant: c.assistant,
|
|
484
|
+
composer: c.composer,
|
|
485
|
+
stopName: c.stopName,
|
|
486
|
+
promptHead: prompt === null ? null : promptHead(prompt)
|
|
487
|
+
});
|
|
488
|
+
return { ...reading, assistantChars: assistant };
|
|
489
|
+
}
|
|
490
|
+
async runningTurns(page, route) {
|
|
491
|
+
if (!route || !this.config.chat.runningTurns) return null;
|
|
492
|
+
const res = await page.request.get(this.config.chat.runningTurns(route));
|
|
493
|
+
if (!res.ok()) throw new Error(`running turns answered ${res.status()}`);
|
|
494
|
+
const body = await res.json();
|
|
495
|
+
if (!Array.isArray(body.running)) throw new Error("running turns returned no `running` array");
|
|
496
|
+
return body.running.map(String);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Time to first visible progress (a new status line or reply text), first
|
|
500
|
+
* reply text, and the turn's end, polled every 300 ms. Failure evidence is
|
|
501
|
+
* read after the turn's own prompt when the page shows it. The turn has ended
|
|
502
|
+
* when, for two reads in a row, {@link turnLooksActive} is false and, where
|
|
503
|
+
* the app lists running turns, the server lists none. Status lines already
|
|
504
|
+
* on the page before Send are not progress. The outcome comes from
|
|
505
|
+
* {@link scoreTurn}.
|
|
506
|
+
*/
|
|
507
|
+
async measureTurn(page, prompt, sentAt, evidence, before, baselineChars, opts) {
|
|
508
|
+
const t = this.blankTurn(page, prompt, sentAt);
|
|
509
|
+
this.turns.push(t);
|
|
510
|
+
const route = threadRouteIn(page.url(), this.config);
|
|
511
|
+
t.threadId = route?.threadId ?? null;
|
|
512
|
+
const timeoutMs = opts.timeoutMs ?? 15 * 6e4;
|
|
513
|
+
const since = () => secs(Date.now() - sentAt);
|
|
514
|
+
const standingStatus = new Set(before.status);
|
|
515
|
+
let growthBase = null;
|
|
516
|
+
let growth = 0;
|
|
517
|
+
let sawActive = false;
|
|
518
|
+
let quiet = 0;
|
|
519
|
+
let lastServerCheck = 0;
|
|
520
|
+
let serverRunning = null;
|
|
521
|
+
let lastStage = "";
|
|
522
|
+
let lastStatus = "";
|
|
523
|
+
let statusChangedAt = Date.now();
|
|
524
|
+
let finished = false;
|
|
525
|
+
await this.wait("Waiting for the agent", async () => {
|
|
526
|
+
while (Date.now() - sentAt < timeoutMs) {
|
|
527
|
+
const s = await this.read(page, prompt).catch(() => null);
|
|
528
|
+
if (s) {
|
|
529
|
+
t.evidenceScope = s.anchored ? "after-prompt" : "whole-transcript";
|
|
530
|
+
const shown = evidence.observe(s);
|
|
531
|
+
if (shown.length) {
|
|
532
|
+
t.firstFailureS ??= since();
|
|
533
|
+
this.mark(`Failure shown after ${since()} s: ${oneLine(shown[0], 90)}`, page);
|
|
534
|
+
}
|
|
535
|
+
const status = s.status.filter((line) => !standingStatus.has(line));
|
|
536
|
+
growthBase ??= s.transcriptChars;
|
|
537
|
+
const chars = s.assistantChars >= 0 ? s.assistantChars - baselineChars : s.transcriptChars - growthBase - status.join(" ").length;
|
|
538
|
+
growth = Math.max(growth, chars);
|
|
539
|
+
const stage = status.join(" | ").replace(/\b\d+(\.\d+)?\s?s\b/g, "").trim();
|
|
540
|
+
if (stage && stage !== lastStage) {
|
|
541
|
+
t.stages.push({ s: since(), text: status.join(" | ").slice(0, 160) });
|
|
542
|
+
lastStage = stage;
|
|
543
|
+
}
|
|
544
|
+
if (status.join(" | ") !== lastStatus) {
|
|
545
|
+
lastStatus = status.join(" | ");
|
|
546
|
+
statusChangedAt = Date.now();
|
|
547
|
+
}
|
|
548
|
+
if (t.firstProgressS === null && (status.length || chars > 0)) {
|
|
549
|
+
t.firstProgressS = since();
|
|
550
|
+
t.firstProgressText = status[0] ?? "reply text";
|
|
551
|
+
this.mark(`First visible progress after ${t.firstProgressS} s: ${oneLine(t.firstProgressText, 70)}`, page);
|
|
552
|
+
}
|
|
553
|
+
if (t.firstTextS === null && chars > 0) {
|
|
554
|
+
t.firstTextS = since();
|
|
555
|
+
this.mark(`First text after ${t.firstTextS} s`, page);
|
|
556
|
+
}
|
|
557
|
+
const stopDue = opts.stopAfter === "first-text" ? t.firstTextS !== null : typeof opts.stopAfter === "number" && since() >= opts.stopAfter;
|
|
558
|
+
if (t.stopPressedS === null && stopDue && s.stopVisible) {
|
|
559
|
+
t.stopPressedS = since();
|
|
560
|
+
this.mark(`Presses Stop after ${t.stopPressedS} s`, page);
|
|
561
|
+
await this.click(this.composerButton(page, this.config.chat.stopName), { pauseAfter: 200 }).catch((e) => console.warn(`Stop press failed: ${e}`));
|
|
562
|
+
}
|
|
563
|
+
if (status.length > 0) sawActive = true;
|
|
564
|
+
const active = turnLooksActive({ stopVisible: s.stopVisible, statusLines: status.length, msSinceStatusChanged: Date.now() - statusChangedAt });
|
|
565
|
+
quiet = active ? 0 : quiet + 1;
|
|
566
|
+
}
|
|
567
|
+
if (route && this.config.chat.runningTurns && Date.now() - lastServerCheck > 2e3) {
|
|
568
|
+
lastServerCheck = Date.now();
|
|
569
|
+
serverRunning = await this.runningTurns(page, route).catch(() => serverRunning);
|
|
570
|
+
if (serverRunning?.length) sawActive = true;
|
|
571
|
+
}
|
|
572
|
+
const started = sawActive || t.firstTextS !== null || Date.now() - sentAt > 45e3;
|
|
573
|
+
const serverDone = !this.config.chat.runningTurns || !route || serverRunning?.length === 0;
|
|
574
|
+
if (started && quiet >= 2 && serverDone) {
|
|
575
|
+
finished = true;
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
await sleep(300);
|
|
579
|
+
}
|
|
580
|
+
}, page);
|
|
581
|
+
t.completeS = finished ? since() : null;
|
|
582
|
+
await settleText(() => this.read(page, prompt).then((r) => `${r.transcriptChars}:${r.failureNodes.length}:${r.retryButtons}`));
|
|
583
|
+
const last = await this.read(page, prompt);
|
|
584
|
+
t.evidenceScope = last.anchored ? "after-prompt" : "whole-transcript";
|
|
585
|
+
evidence.observe(last);
|
|
586
|
+
const finalText = this.config.chat.assistant ? await this.replyText(page) : "";
|
|
587
|
+
t.replyChars = this.config.chat.assistant ? Math.max(0, finalText.length - baselineChars) : Math.max(0, growth);
|
|
588
|
+
Object.assign(t, scoreTurn({ timedOut: !finished, evidence: evidence.added(), replyChars: t.replyChars, stopPressed: t.stopPressedS !== null }));
|
|
589
|
+
const n = this.turns.length;
|
|
590
|
+
t.replyFile = join("turns", `${String(n).padStart(2, "0")}-${t.label}.md`);
|
|
591
|
+
const reply = this.config.chat.assistant ? finalText.slice(baselineChars).trim() : "(this app configures no assistant selector; read the reply in the video or the trace)";
|
|
592
|
+
const failures = t.failures.length ? `
|
|
593
|
+
|
|
594
|
+
## Failure evidence
|
|
595
|
+
|
|
596
|
+
${t.failures.map((f) => `- ${f}`).join("\n")}` : "";
|
|
597
|
+
writeFileSync(join(this.outDir, t.replyFile), `# Turn ${n} (${t.label})
|
|
598
|
+
|
|
599
|
+
## Prompt
|
|
600
|
+
|
|
601
|
+
${prompt}
|
|
602
|
+
|
|
603
|
+
## Reply (${t.outcome})
|
|
604
|
+
|
|
605
|
+
${reply}${failures}
|
|
606
|
+
`);
|
|
607
|
+
this.mark(
|
|
608
|
+
t.outcome === "completed" ? `Turn complete after ${t.completeS} s (${t.replyChars} chars)` : `Turn ${t.outcome.toUpperCase()} after ${t.completeS ?? since()} s${t.error ? `: ${oneLine(t.error, 80)}` : ""}`,
|
|
609
|
+
page
|
|
610
|
+
);
|
|
611
|
+
return t;
|
|
612
|
+
}
|
|
613
|
+
async replyText(page) {
|
|
614
|
+
const sel = this.config.chat.assistant;
|
|
615
|
+
if (!sel) return "";
|
|
616
|
+
return settleText(async () => (await page.locator(sel).allInnerTexts()).join("\n").trim());
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Close everything, then per context: a captioned full .mp4, a highlights cut
|
|
620
|
+
* (at most 178 s, long waits sped up and labelled), an .srt and a scrubbed
|
|
621
|
+
* trace.zip; plus timings.json and chapters.json. Refuses (throws) when any
|
|
622
|
+
* output file still holds a password or cookie value.
|
|
623
|
+
*/
|
|
624
|
+
async finish(opts = {}) {
|
|
625
|
+
for (const ctx of this.phones.values()) await ctx.close().catch(() => {
|
|
626
|
+
});
|
|
627
|
+
const files = [];
|
|
628
|
+
const stopped = [];
|
|
629
|
+
for (const r of this.recorded) {
|
|
630
|
+
const endedAt = Date.now();
|
|
631
|
+
const rawTrace = join(r.rawDir, "trace.raw.zip");
|
|
632
|
+
await r.context.tracing.stop({ path: rawTrace }).catch((e) => console.warn(`tracing.stop failed for ${r.label}: ${e}`));
|
|
633
|
+
const video = r.page.video();
|
|
634
|
+
await r.context.close();
|
|
635
|
+
stopped.push({ r, rawTrace, webm: video ? await video.path().catch(() => null) : null, endedAt });
|
|
636
|
+
}
|
|
637
|
+
const needles = secretNeedles(this.config);
|
|
638
|
+
for (const { r, rawTrace, webm, endedAt } of stopped) {
|
|
639
|
+
if (webm) {
|
|
640
|
+
files.push(...postProcessVideo({
|
|
641
|
+
webm,
|
|
642
|
+
workDir: r.rawDir,
|
|
643
|
+
videoDir: join(this.outDir, "video"),
|
|
644
|
+
label: r.label,
|
|
645
|
+
t0: r.t0,
|
|
646
|
+
wallSeconds: (endedAt - r.t0) / 1e3,
|
|
647
|
+
chapters: this.chapters.filter((c) => c.label === null || c.label === r.label),
|
|
648
|
+
speedup2x: opts.speedup2x ?? false
|
|
649
|
+
}));
|
|
650
|
+
}
|
|
651
|
+
try {
|
|
652
|
+
const clean = join(this.outDir, "video", `${r.label}-trace.zip`);
|
|
653
|
+
const result = scrubTrace(rawTrace, clean, [...needles.hard, ...needles.soft]);
|
|
654
|
+
console.log(`trace ${r.label}: ${result.entries} entries, ${result.dropped} sensitive bodies dropped, ${result.rewritten} rewritten`);
|
|
655
|
+
files.push(clean);
|
|
656
|
+
} catch (error) {
|
|
657
|
+
console.warn(`trace ${r.label} not written: ${error.message}`);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
writeFileSync(join(this.outDir, "chapters.json"), JSON.stringify(this.chapters.map((c) => ({ ...c, at: new Date(c.at).toISOString(), until: c.until ? new Date(c.until).toISOString() : void 0, offsetS: secs(c.at - this.startedAt) })), null, 2));
|
|
661
|
+
writeFileSync(join(this.outDir, "timings.json"), JSON.stringify({ journey: this.id, app: this.config.app, base: this.config.baseUrl, startedAt: new Date(this.startedAt).toISOString(), wallS: secs(Date.now() - this.startedAt), steps: this.steps, turns: this.turns }, null, 2));
|
|
662
|
+
await this.browser.close();
|
|
663
|
+
assertNoSecrets(this.outDir, needles);
|
|
664
|
+
console.log(`
|
|
665
|
+
${this.id}: ${this.steps.length} steps, ${this.turns.length} turns, wall ${secs(Date.now() - this.startedAt)} s`);
|
|
666
|
+
for (const t of this.turns) {
|
|
667
|
+
console.log(` turn[${t.label}] ${t.outcome}: progress ${t.firstProgressS ?? "-"} s, first text ${t.firstTextS ?? "-"} s, end ${t.completeS ?? "-"} s, ${t.replyChars} chars${t.error ? ` | ${oneLine(t.error, 100)}` : ""}`);
|
|
668
|
+
}
|
|
669
|
+
const host = process.env.JOURNEYS_HOST_ALIAS ?? hostname();
|
|
670
|
+
console.log(`output: ${this.outDir}
|
|
671
|
+
copy it (run where you will watch it):
|
|
672
|
+
rsync -a ${host}:${this.outDir}/ "<dest>/${this.id}/"`);
|
|
673
|
+
return { outDir: this.outDir, files };
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
function oneLine(text, max) {
|
|
677
|
+
const s = text.replace(/\s+/g, " ").trim();
|
|
678
|
+
return s.length > max ? `${s.slice(0, max - 1)}\u2026` : s;
|
|
679
|
+
}
|
|
680
|
+
async function startJourney(id, opts = {}) {
|
|
681
|
+
if (!/^[a-z0-9][a-z0-9-]{1,60}$/.test(id)) throw new Error("journey id: lowercase letters, digits and dashes");
|
|
682
|
+
const config = opts.config ? resolveJourneysConfig(opts.config) : await loadJourneysConfig();
|
|
683
|
+
let chromium;
|
|
684
|
+
try {
|
|
685
|
+
chromium = (await import("playwright")).chromium;
|
|
686
|
+
} catch {
|
|
687
|
+
throw new Error("journeys need the optional `playwright` peer: install playwright in the app that runs them");
|
|
688
|
+
}
|
|
689
|
+
const browser = await chromium.launch({ headless: opts.headless ?? true });
|
|
690
|
+
return new Journey(id, config, browser, { cursor: opts.cursor ?? true });
|
|
691
|
+
}
|
|
692
|
+
export {
|
|
693
|
+
CONFIG_FILE_NAMES,
|
|
694
|
+
DEFAULT_AUTH_PATHS,
|
|
695
|
+
DEFAULT_CHAT_CONTRACT,
|
|
696
|
+
DEFAULT_FAILURE_TEXT,
|
|
697
|
+
DEFAULT_STOPPED_TEXT,
|
|
698
|
+
DESKTOP,
|
|
699
|
+
Journey,
|
|
700
|
+
MAX_HIGHLIGHTS_S,
|
|
701
|
+
PHONE,
|
|
702
|
+
STATUS_STALE_MS,
|
|
703
|
+
TurnEvidence,
|
|
704
|
+
assertNoSecrets,
|
|
705
|
+
chapterCues,
|
|
706
|
+
clickUntilSubmitted,
|
|
707
|
+
collectJourneyFiles,
|
|
708
|
+
createSubmissionTracker,
|
|
709
|
+
credentialNames,
|
|
710
|
+
defineJourneys,
|
|
711
|
+
extractFrames,
|
|
712
|
+
highlightPlan,
|
|
713
|
+
loadJourneysConfig,
|
|
714
|
+
oneLine,
|
|
715
|
+
postProcessVideo,
|
|
716
|
+
rebuildVideo,
|
|
717
|
+
renderIndex,
|
|
718
|
+
resolveJourneysConfig,
|
|
719
|
+
routeSubmitPaths,
|
|
720
|
+
scoreTurn,
|
|
721
|
+
scrubTrace,
|
|
722
|
+
secretNeedles,
|
|
723
|
+
sessionUser,
|
|
724
|
+
settleText,
|
|
725
|
+
startJourney,
|
|
726
|
+
storageStateFor,
|
|
727
|
+
tallyTurns,
|
|
728
|
+
threadRouteIn,
|
|
729
|
+
turnLooksActive
|
|
730
|
+
};
|
|
731
|
+
//# sourceMappingURL=index.js.map
|