bangonit 0.3.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -33
- package/app/desktopapp/dist/main/index.js +4 -2
- package/app/desktopapp/dist/main/ipc.js +96 -20
- package/app/desktopapp/dist/main/preload.js +4 -3
- package/app/desktopapp/dist/main/tabs.js +43 -3
- package/app/replay/dist/replay.css +1 -1
- package/app/replay/dist/replay.js +24 -24
- package/app/webapp/.next/standalone/app/webapp/.next/BUILD_ID +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/app-build-manifest.json +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/app-path-routes-manifest.json +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/build-manifest.json +2 -2
- package/app/webapp/.next/standalone/app/webapp/.next/prerender-manifest.json +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/_not-found.html +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/_not-found.rsc +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/app/page.js +3 -3
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/app/page_client-reference-manifest.js +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/app.html +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/app.rsc +2 -2
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/index.html +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/index.rsc +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/app/page.js +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/app-paths-manifest.json +2 -2
- package/app/webapp/.next/standalone/app/webapp/.next/server/chunks/124.js +9 -9
- package/app/webapp/.next/standalone/app/webapp/.next/server/chunks/708.js +5 -4
- package/app/webapp/.next/standalone/app/webapp/.next/server/pages/404.html +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/pages/500.html +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/server/server-reference-manifest.json +1 -1
- package/app/webapp/.next/standalone/app/webapp/.next/static/chunks/app/app/page-74ec5ee2f3d3d4a0.js +1 -0
- package/app/webapp/.next/standalone/package.json +7 -4
- package/app/webapp/.next/static/chunks/app/app/page-74ec5ee2f3d3d4a0.js +1 -0
- package/app/webapp/src/shared/api/chat.ts +7 -4
- package/app/webapp/src/shared/components/AppShell.tsx +6 -5
- package/app/webapp/src/shared/components/SessionView.tsx +4 -3
- package/app/webapp/src/shared/lib/browser/index.ts +17 -27
- package/app/webapp/src/shared/lib/browser/recorder.ts +13 -4
- package/app/webapp/src/shared/lib/browser/snapshot.ts +25 -5
- package/app/webapp/src/shared/lib/browser/types.ts +21 -6
- package/app/webapp/src/shared/types/global.d.ts +6 -4
- package/bin/src/cli/bangonit.js +19 -11
- package/package.json +7 -4
- package/scripts/regen-replays.sh +101 -0
- package/app/webapp/.next/standalone/app/webapp/.next/static/chunks/app/app/page-df00a757f649931a.js +0 -1
- package/app/webapp/.next/static/chunks/app/app/page-df00a757f649931a.js +0 -1
- /package/app/webapp/.next/standalone/app/webapp/.next/static/{bBZVP6sUilA3wyt0vYqDc → CfMl7etZBP4Q0LYMXf4ZP}/_buildManifest.js +0 -0
- /package/app/webapp/.next/standalone/app/webapp/.next/static/{bBZVP6sUilA3wyt0vYqDc → CfMl7etZBP4Q0LYMXf4ZP}/_ssgManifest.js +0 -0
- /package/app/webapp/.next/static/{bBZVP6sUilA3wyt0vYqDc → CfMl7etZBP4Q0LYMXf4ZP}/_buildManifest.js +0 -0
- /package/app/webapp/.next/static/{bBZVP6sUilA3wyt0vYqDc → CfMl7etZBP4Q0LYMXf4ZP}/_ssgManifest.js +0 -0
|
@@ -31,6 +31,7 @@ export default function SessionView({
|
|
|
31
31
|
record,
|
|
32
32
|
sessionRecorder,
|
|
33
33
|
onRegisterRecorder,
|
|
34
|
+
planDir,
|
|
34
35
|
}: {
|
|
35
36
|
agentId: string;
|
|
36
37
|
agentName: string;
|
|
@@ -44,6 +45,7 @@ export default function SessionView({
|
|
|
44
45
|
record?: boolean;
|
|
45
46
|
sessionRecorder?: SessionRecorder;
|
|
46
47
|
onRegisterRecorder?: (agentId: string, recorder: BrowserRecorder) => void;
|
|
48
|
+
planDir?: string;
|
|
47
49
|
}) {
|
|
48
50
|
const [tabs, setTabs] = useState<Tab[]>(
|
|
49
51
|
initialTabs?.map((t) => ({ ...t, initialUrl: t.url })) || [
|
|
@@ -122,8 +124,7 @@ export default function SessionView({
|
|
|
122
124
|
const clips = browserRecorderRef.current?.getClipsMeta() || [];
|
|
123
125
|
const agentInfo = [{ id: agentId, name: agentName, result: result as "pass" | "fail", summary }];
|
|
124
126
|
const replayData = sessionRecorderRef.current.toJSON(agentInfo, clips);
|
|
125
|
-
await window.bangonit?.
|
|
126
|
-
await window.bangonit?.generateReplayHtml?.({ runDir });
|
|
127
|
+
await window.bangonit?.generateReplayHtml?.({ runDir, data: JSON.stringify(replayData) });
|
|
127
128
|
}
|
|
128
129
|
} catch (e) {
|
|
129
130
|
console.error(e);
|
|
@@ -425,7 +426,7 @@ export default function SessionView({
|
|
|
425
426
|
const wcId = el.getWebContentsId?.();
|
|
426
427
|
if (wcId) {
|
|
427
428
|
registeredTabsRef.current.add(tabId);
|
|
428
|
-
window.bangonit?.registerTab(agentId, tabId, wcId, initialUrl);
|
|
429
|
+
window.bangonit?.registerTab(agentId, tabId, wcId, initialUrl, planDir);
|
|
429
430
|
if (tabId === activeTabId) {
|
|
430
431
|
window.bangonit?.setActiveTab(agentId, tabId);
|
|
431
432
|
}
|
|
@@ -93,20 +93,21 @@ export class BrowserTools {
|
|
|
93
93
|
return pressKey(this.agentId, args.key);
|
|
94
94
|
case "browser_close":
|
|
95
95
|
return tabAction(this.agentId, { action: "close" });
|
|
96
|
+
case "browser_upload": {
|
|
97
|
+
if (args.cancel) {
|
|
98
|
+
const result = await window.bangonit!.handleFileChooser(this.agentId, "cancel");
|
|
99
|
+
if (!result.ok) return `Error: ${result.error}`;
|
|
100
|
+
return "File picker cancelled.";
|
|
101
|
+
}
|
|
102
|
+
if (!args.paths?.length) return "Error: provide paths to upload, or cancel: true";
|
|
103
|
+
const result = await window.bangonit!.handleFileChooser(this.agentId, "accept", args.paths);
|
|
104
|
+
if (!result.ok) return `Error: ${result.error}`;
|
|
105
|
+
return `Uploaded ${args.paths.length} file(s).`;
|
|
106
|
+
}
|
|
96
107
|
case "browser_wait_for":
|
|
97
108
|
return waitFor(this.agentId, args);
|
|
98
109
|
case "browser_tabs":
|
|
99
110
|
return tabAction(this.agentId, args);
|
|
100
|
-
case "browser_downloads": {
|
|
101
|
-
const downloads = await window.bangonit!.getDownloads(this.agentId);
|
|
102
|
-
if (!downloads.length) return "No downloads.";
|
|
103
|
-
return downloads
|
|
104
|
-
.map((d: any) => {
|
|
105
|
-
const pct = d.totalBytes > 0 ? Math.round((d.bytes / d.totalBytes) * 100) + "%" : "";
|
|
106
|
-
return `[${d.state}] ${d.filename} ${pct} → ${d.path}`;
|
|
107
|
-
})
|
|
108
|
-
.join("\n");
|
|
109
|
-
}
|
|
110
111
|
default:
|
|
111
112
|
throw new Error(`Unknown tool: ${name}`);
|
|
112
113
|
}
|
|
@@ -180,25 +181,12 @@ export class BrowserTools {
|
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
|
|
183
|
-
// Stop recording clip
|
|
184
|
+
// Stop recording clip (base64 data is stored in the clip meta)
|
|
184
185
|
if (this.recorder) {
|
|
185
186
|
try {
|
|
186
|
-
|
|
187
|
-
if (clip) {
|
|
188
|
-
const runDir = await window.bangonit?.getRunDir?.();
|
|
189
|
-
if (runDir) {
|
|
190
|
-
const arrayBuffer = await clip.blob.arrayBuffer();
|
|
191
|
-
await window.bangonit?.saveRecordingClip?.({
|
|
192
|
-
runDir,
|
|
193
|
-
agentId: clip.meta.agentId,
|
|
194
|
-
clipIndex: clip.meta.index,
|
|
195
|
-
tabId: clip.meta.tabId,
|
|
196
|
-
data: arrayBuffer,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
187
|
+
await this.recorder.stopClip();
|
|
200
188
|
} catch (e) {
|
|
201
|
-
console.warn("Failed to
|
|
189
|
+
console.warn("Failed to stop recording clip:", e);
|
|
202
190
|
}
|
|
203
191
|
}
|
|
204
192
|
|
|
@@ -208,7 +196,7 @@ export class BrowserTools {
|
|
|
208
196
|
private actionToToolArgs(act: BrowserAction): any {
|
|
209
197
|
switch (act.action) {
|
|
210
198
|
case "navigate": return { url: act.url };
|
|
211
|
-
case "back": case "forward": case "close":
|
|
199
|
+
case "back": case "forward": case "close": return {};
|
|
212
200
|
case "mouse": {
|
|
213
201
|
const steps = (act.mouseActions || []).map((s) => {
|
|
214
202
|
if (s.action === "wait") return { action: "wait", ms: s.ms || 100 };
|
|
@@ -220,6 +208,7 @@ export class BrowserTools {
|
|
|
220
208
|
}
|
|
221
209
|
case "type": return { text: act.text };
|
|
222
210
|
case "press": return { key: act.key };
|
|
211
|
+
case "upload": return { paths: act.paths, cancel: act.cancel };
|
|
223
212
|
case "tabs": return { action: act.tabAction, tabId: act.tabId, url: act.url };
|
|
224
213
|
case "wait": return { timeout: act.timeout };
|
|
225
214
|
default: return {};
|
|
@@ -240,6 +229,7 @@ export class BrowserTools {
|
|
|
240
229
|
}
|
|
241
230
|
case "type": return `type "${(act.text || "").slice(0, 30)}"`;
|
|
242
231
|
case "press": return `press ${act.key}`;
|
|
232
|
+
case "upload": return act.cancel ? "upload cancel" : `upload ${(act.paths || []).join(", ")}`;
|
|
243
233
|
case "tabs": return `tabs ${act.tabAction}${act.tabId ? " " + act.tabId : ""}`;
|
|
244
234
|
case "wait": return `wait ${act.timeout || 10}s`;
|
|
245
235
|
default: return act.action;
|
|
@@ -7,8 +7,8 @@ export interface ClipMeta {
|
|
|
7
7
|
index: number;
|
|
8
8
|
startTime: number;
|
|
9
9
|
endTime: number;
|
|
10
|
-
path: string;
|
|
11
10
|
url?: string;
|
|
11
|
+
data: string; // base64-encoded webm video
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface CapturedFrame {
|
|
@@ -156,7 +156,7 @@ export class BrowserRecorder {
|
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
async stopClip(): Promise<{
|
|
159
|
+
async stopClip(): Promise<{ meta: ClipMeta } | null> {
|
|
160
160
|
if (!this.recording) return null;
|
|
161
161
|
this.recording = false;
|
|
162
162
|
const endTime = Date.now();
|
|
@@ -176,17 +176,26 @@ export class BrowserRecorder {
|
|
|
176
176
|
const blob = await this.compositeAndEncode(frames);
|
|
177
177
|
if (!blob || blob.size === 0) return null;
|
|
178
178
|
|
|
179
|
+
// Convert blob to base64 for self-contained replay
|
|
180
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
181
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
182
|
+
let binary = "";
|
|
183
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
184
|
+
binary += String.fromCharCode(bytes[i]);
|
|
185
|
+
}
|
|
186
|
+
const data = btoa(binary);
|
|
187
|
+
|
|
179
188
|
const meta: ClipMeta = {
|
|
180
189
|
agentId: this.agentId,
|
|
181
190
|
tabId: this.currentTabId,
|
|
182
191
|
index: this.clips.length,
|
|
183
192
|
startTime: this.clipStartTime,
|
|
184
193
|
endTime,
|
|
185
|
-
path: `clips/${this.agentId}/clip-${this.clips.length}-tab-${this.currentTabId}.webm`,
|
|
186
194
|
url: this.currentUrl || undefined,
|
|
195
|
+
data,
|
|
187
196
|
};
|
|
188
197
|
this.clips.push(meta);
|
|
189
|
-
return {
|
|
198
|
+
return { meta };
|
|
190
199
|
}
|
|
191
200
|
|
|
192
201
|
private async cancelClip(): Promise<void> {
|
|
@@ -124,9 +124,29 @@ export async function takeSnapshot(
|
|
|
124
124
|
mouseY: number,
|
|
125
125
|
tabSummary: string
|
|
126
126
|
): Promise<string> {
|
|
127
|
-
const { result } = await
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
const [{ result }, downloads, fileChooser, { result: vpResult }] = await Promise.all([
|
|
128
|
+
window.bangonit!.cdpSend(agentId, "Runtime.evaluate", {
|
|
129
|
+
expression: SNAPSHOT_JS,
|
|
130
|
+
returnByValue: true,
|
|
131
|
+
}),
|
|
132
|
+
window.bangonit!.getDownloads(agentId),
|
|
133
|
+
window.bangonit!.getFileChooserState(agentId),
|
|
134
|
+
window.bangonit!.cdpSend(agentId, "Runtime.evaluate", {
|
|
135
|
+
expression: `JSON.stringify({w:window.innerWidth,h:window.innerHeight})`,
|
|
136
|
+
returnByValue: true,
|
|
137
|
+
}),
|
|
138
|
+
]);
|
|
139
|
+
const vp = (() => { try { return JSON.parse(vpResult.value); } catch { return null; } })();
|
|
140
|
+
const vpStr = vp ? `\nViewport: ${vp.w}x${vp.h}` : "";
|
|
141
|
+
let out = (result.value || "Empty page") + `\n\nMouse position: ${mouseX},${mouseY}${vpStr}` + tabSummary;
|
|
142
|
+
if (fileChooser.open) {
|
|
143
|
+
out += `\n\n[File picker is open — use upload action with paths to select files, or cancel: true to dismiss]`;
|
|
144
|
+
}
|
|
145
|
+
if (downloads.length > 0) {
|
|
146
|
+
const lines = downloads.map((d: any) =>
|
|
147
|
+
`- ${d.filename} (${d.bytes} bytes) [${d.state}]`
|
|
148
|
+
);
|
|
149
|
+
out += `\n\nDownloads:\n${lines.join("\n")}`;
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
132
152
|
}
|
|
@@ -22,6 +22,8 @@ export interface BrowserAction {
|
|
|
22
22
|
tabAction?: string;
|
|
23
23
|
tabId?: number;
|
|
24
24
|
timeout?: number;
|
|
25
|
+
paths?: string[];
|
|
26
|
+
cancel?: boolean;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export interface BrowserToolInput {
|
|
@@ -38,7 +40,7 @@ export const ACTION_TO_TOOL: Record<string, string> = {
|
|
|
38
40
|
type: "browser_type",
|
|
39
41
|
press: "browser_press_key",
|
|
40
42
|
tabs: "browser_tabs",
|
|
41
|
-
|
|
43
|
+
upload: "browser_upload",
|
|
42
44
|
wait: "browser_wait_for",
|
|
43
45
|
close: "browser_close",
|
|
44
46
|
};
|
|
@@ -81,6 +83,24 @@ export const TOOL_DEFS = [
|
|
|
81
83
|
description: "Close the current page/tab",
|
|
82
84
|
parameters: { type: "object", properties: {} },
|
|
83
85
|
},
|
|
86
|
+
{
|
|
87
|
+
name: "browser_upload",
|
|
88
|
+
description: "Upload files to an open file picker, or cancel it. The snapshot will show when a file picker is open.",
|
|
89
|
+
parameters: {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
paths: {
|
|
93
|
+
type: "array",
|
|
94
|
+
items: { type: "string" },
|
|
95
|
+
description: "Absolute file paths to upload",
|
|
96
|
+
},
|
|
97
|
+
cancel: {
|
|
98
|
+
type: "boolean",
|
|
99
|
+
description: "Cancel the file picker instead of uploading",
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
84
104
|
{
|
|
85
105
|
name: "browser_wait_for",
|
|
86
106
|
description: "Wait for text to appear or disappear on the page, or wait a specified time",
|
|
@@ -93,11 +113,6 @@ export const TOOL_DEFS = [
|
|
|
93
113
|
},
|
|
94
114
|
},
|
|
95
115
|
},
|
|
96
|
-
{
|
|
97
|
-
name: "browser_downloads",
|
|
98
|
-
description: "List recent file downloads",
|
|
99
|
-
parameters: { type: "object", properties: {} },
|
|
100
|
-
},
|
|
101
116
|
{
|
|
102
117
|
name: "browser_tabs",
|
|
103
118
|
description: "List, create, close, or select browser tabs",
|
|
@@ -47,7 +47,7 @@ interface BangOnIt {
|
|
|
47
47
|
getURL: (agentId: string) => Promise<string | null>;
|
|
48
48
|
|
|
49
49
|
// Tab management
|
|
50
|
-
registerTab: (agentId: string, tabId: number, wcId: number, initialUrl: string) => Promise<void>;
|
|
50
|
+
registerTab: (agentId: string, tabId: number, wcId: number, initialUrl: string, planDir?: string) => Promise<void>;
|
|
51
51
|
setActiveTab: (agentId: string, tabId: number) => Promise<void>;
|
|
52
52
|
getTabInfo: (agentId: string) => Promise<{ tabs: any[]; activeTabId: number | null }>;
|
|
53
53
|
requestNewTab: (agentId: string, url: string) => Promise<void>;
|
|
@@ -57,6 +57,10 @@ interface BangOnIt {
|
|
|
57
57
|
// Downloads
|
|
58
58
|
getDownloads: (agentId: string) => Promise<any[]>;
|
|
59
59
|
|
|
60
|
+
// File chooser
|
|
61
|
+
handleFileChooser: (agentId: string, action: "accept" | "cancel", files?: string[]) => Promise<{ ok: boolean; error?: string }>;
|
|
62
|
+
getFileChooserState: (agentId: string) => Promise<{ open: boolean; mode?: string }>;
|
|
63
|
+
|
|
60
64
|
// Events — data includes agentId
|
|
61
65
|
onTabUpdated: (cb: (data: TabInfo) => void) => () => void;
|
|
62
66
|
onOpenNewTab: (cb: (data: { agentId: string; url: string }) => void) => () => void;
|
|
@@ -90,9 +94,7 @@ interface BangOnIt {
|
|
|
90
94
|
emitTestRetry?: (data: { agentId: string; attempt: number; maxRetries: number }) => void;
|
|
91
95
|
|
|
92
96
|
// Recording
|
|
93
|
-
|
|
94
|
-
saveReplayData?: (opts: { runDir: string; data: string }) => Promise<void>;
|
|
95
|
-
generateReplayHtml?: (opts: { runDir: string }) => Promise<void>;
|
|
97
|
+
generateReplayHtml?: (opts: { runDir: string; data: string }) => Promise<void>;
|
|
96
98
|
getRunDir?: () => Promise<string | null>;
|
|
97
99
|
}
|
|
98
100
|
|
package/bin/src/cli/bangonit.js
CHANGED
|
@@ -48,6 +48,7 @@ const Minio = __importStar(require("minio"));
|
|
|
48
48
|
const yargs_1 = __importDefault(require("yargs"));
|
|
49
49
|
const helpers_1 = require("yargs/helpers");
|
|
50
50
|
const is_ci_1 = __importDefault(require("is-ci"));
|
|
51
|
+
const dotenv = __importStar(require("dotenv"));
|
|
51
52
|
const args_1 = require("../../app/desktopapp/src/shared/args");
|
|
52
53
|
const ROOT = path.resolve(__dirname, "..", "..", "..");
|
|
53
54
|
const WEBAPP_DIR = path.join(ROOT, "app", "webapp");
|
|
@@ -99,17 +100,7 @@ async function waitForPort(port, timeoutMs = 30000) {
|
|
|
99
100
|
die(`Timed out waiting for port ${port}`);
|
|
100
101
|
}
|
|
101
102
|
function loadEnv() {
|
|
102
|
-
|
|
103
|
-
const envPath = path.join(process.cwd(), ".env");
|
|
104
|
-
if (fs.existsSync(envPath)) {
|
|
105
|
-
for (const line of fs.readFileSync(envPath, "utf-8").split("\n")) {
|
|
106
|
-
const match = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
|
|
107
|
-
if (match && !process.env[match[1]]) {
|
|
108
|
-
process.env[match[1]] = match[2].replace(/^["']|["']$/g, "");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
103
|
+
dotenv.config({ quiet: true });
|
|
113
104
|
}
|
|
114
105
|
// Interpolate ${ENV_VAR} references in string values throughout an object
|
|
115
106
|
function interpolateEnv(obj) {
|
|
@@ -651,6 +642,14 @@ async function run(argv, config) {
|
|
|
651
642
|
die(`Webapp server crashed (exit code ${code}). Check logs/webapp.log for details.`);
|
|
652
643
|
}
|
|
653
644
|
});
|
|
645
|
+
// Save terminal state before Electron (which inherits stdin) can modify it
|
|
646
|
+
let savedTtyState = null;
|
|
647
|
+
try {
|
|
648
|
+
savedTtyState = (0, child_process_1.execSync)("stty -g", { stdio: ["inherit", "pipe", "ignore"] }).toString().trim();
|
|
649
|
+
}
|
|
650
|
+
catch (e) {
|
|
651
|
+
console.error("[cli] stty save failed:", e.message);
|
|
652
|
+
}
|
|
654
653
|
const cleanup = () => {
|
|
655
654
|
webappCrashed = true; // suppress crash message during normal shutdown
|
|
656
655
|
try {
|
|
@@ -659,6 +658,15 @@ async function run(argv, config) {
|
|
|
659
658
|
catch (e) {
|
|
660
659
|
console.error("[cli] webappProc.kill failed:", e.message);
|
|
661
660
|
}
|
|
661
|
+
// Restore terminal state — Electron may have changed raw mode, echo, etc.
|
|
662
|
+
if (savedTtyState) {
|
|
663
|
+
try {
|
|
664
|
+
(0, child_process_1.execSync)(`stty ${savedTtyState}`, { stdio: ["inherit", "ignore", "ignore"] });
|
|
665
|
+
}
|
|
666
|
+
catch (e) {
|
|
667
|
+
console.error("[cli] stty restore failed:", e.message);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
662
670
|
};
|
|
663
671
|
process.on("exit", cleanup);
|
|
664
672
|
process.on("SIGINT", () => { cleanup(); process.exit(1); });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bangonit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "AI-powered E2E testing tool",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bangonit": "bin/src/cli/bangonit.js",
|
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"prepublishOnly": "npm run build",
|
|
12
|
-
"build": "npm
|
|
13
|
-
"build:cli": "npx tsc -p tsconfig.cli.json",
|
|
12
|
+
"build": "concurrently npm:build:cli npm:build:webapp npm:build:electron npm:build:replay",
|
|
13
|
+
"build:cli": "rm -fr bin && npx tsc -p tsconfig.cli.json && chmod +x bin/src/cli/bangonit.js",
|
|
14
14
|
"build:webapp": "cd app/webapp && npm run build && cp -r .next/static .next/standalone/app/webapp/.next/static",
|
|
15
15
|
"build:electron": "cd app/desktopapp && npx tsc",
|
|
16
|
-
"build:replay": "cd app/replay && npx vite build"
|
|
16
|
+
"build:replay": "cd app/replay && npx vite build",
|
|
17
|
+
"test": "node --test test/*.test.ts"
|
|
17
18
|
},
|
|
18
19
|
"workspaces": [
|
|
19
20
|
"app/*"
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
52
|
"@iarna/toml": "^2.2.5",
|
|
53
|
+
"dotenv": "^17.3.1",
|
|
52
54
|
"electron": "^40.8.0",
|
|
53
55
|
"electron-store": "^8.1.0",
|
|
54
56
|
"is-ci": "^4.1.0",
|
|
@@ -59,6 +61,7 @@
|
|
|
59
61
|
"devDependencies": {
|
|
60
62
|
"@types/is-ci": "^3.0.4",
|
|
61
63
|
"@types/yargs": "^17.0.35",
|
|
64
|
+
"concurrently": "^9.2.1",
|
|
62
65
|
"playwright": "^1.58.2"
|
|
63
66
|
}
|
|
64
67
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Regenerate per-agent replay HTML files from data.json + clip files.
|
|
3
|
+
# For migrating old directory-based recordings to the new per-agent format.
|
|
4
|
+
# Usage: ./scripts/regen-replays.sh [recordings-dir]
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
cd "$(dirname "$0")/.."
|
|
8
|
+
|
|
9
|
+
RECORDINGS_DIR="${1:-recordings}"
|
|
10
|
+
REPLAY_JS="app/replay/dist/replay.js"
|
|
11
|
+
REPLAY_CSS="app/replay/dist/replay.css"
|
|
12
|
+
|
|
13
|
+
if [ ! -f "$REPLAY_JS" ] || [ ! -f "$REPLAY_CSS" ]; then
|
|
14
|
+
echo "Replay bundle not found. Building..."
|
|
15
|
+
cd app/replay && npx vite build && cd ../..
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
count=0
|
|
19
|
+
for dir in "$RECORDINGS_DIR"/*/; do
|
|
20
|
+
[ -f "$dir/data.json" ] || continue
|
|
21
|
+
python3 -c "
|
|
22
|
+
import json, base64, os, re
|
|
23
|
+
|
|
24
|
+
js = open('$REPLAY_JS').read()
|
|
25
|
+
css = open('$REPLAY_CSS').read()
|
|
26
|
+
data = json.load(open('${dir}data.json'))
|
|
27
|
+
|
|
28
|
+
# Inline video clips as base64
|
|
29
|
+
for clip in data.get('clips', []):
|
|
30
|
+
clip_file = os.path.join('${dir}', clip.get('path', ''))
|
|
31
|
+
if os.path.exists(clip_file):
|
|
32
|
+
clip['data'] = base64.b64encode(open(clip_file, 'rb').read()).decode('ascii')
|
|
33
|
+
if 'path' in clip:
|
|
34
|
+
del clip['path']
|
|
35
|
+
|
|
36
|
+
agents = data.get('agents', [])
|
|
37
|
+
|
|
38
|
+
# Build slug map
|
|
39
|
+
def slugify(s):
|
|
40
|
+
return re.sub(r'^-|-$', '', re.sub(r'[^a-z0-9]+', '-', s.lower())) or 'agent'
|
|
41
|
+
|
|
42
|
+
used = set()
|
|
43
|
+
agent_files = {}
|
|
44
|
+
for agent in agents:
|
|
45
|
+
slug = slugify(agent['name'])
|
|
46
|
+
if slug in used:
|
|
47
|
+
i = 2
|
|
48
|
+
while f'{slug}-{i}' in used:
|
|
49
|
+
i += 1
|
|
50
|
+
slug = f'{slug}-{i}'
|
|
51
|
+
used.add(slug)
|
|
52
|
+
agent_files[agent['id']] = f'{slug}.html'
|
|
53
|
+
|
|
54
|
+
# Generate per-agent HTML
|
|
55
|
+
for agent in agents:
|
|
56
|
+
agent_data = dict(data)
|
|
57
|
+
agent_data['focusAgentId'] = agent['id']
|
|
58
|
+
agent_data['agentFiles'] = agent_files
|
|
59
|
+
agent_data['clips'] = [c for c in data.get('clips', []) if c.get('agentId') == agent['id']]
|
|
60
|
+
agent_data['messages'] = {agent['id']: data.get('messages', {}).get(agent['id'], [])}
|
|
61
|
+
agent_data['consoleLogs'] = {agent['id']: data.get('consoleLogs', {}).get(agent['id'], [])}
|
|
62
|
+
agent_data['timeline'] = [e for e in data.get('timeline', []) if e.get('agentId') == agent['id']]
|
|
63
|
+
|
|
64
|
+
html = '''<!DOCTYPE html>
|
|
65
|
+
<html lang=\"en\">
|
|
66
|
+
<head>
|
|
67
|
+
<meta charset=\"UTF-8\">
|
|
68
|
+
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
|
|
69
|
+
<title>''' + agent['name'] + ''' - Session Replay</title>
|
|
70
|
+
<style>''' + css + '''</style>
|
|
71
|
+
</head>
|
|
72
|
+
<body>
|
|
73
|
+
<div id=\"root\"></div>
|
|
74
|
+
<script>window.__REPLAY_DATA__ = ''' + json.dumps(agent_data) + ''';</script>
|
|
75
|
+
<script>''' + js + '''</script>
|
|
76
|
+
</body>
|
|
77
|
+
</html>'''
|
|
78
|
+
with open(os.path.join('${dir}', agent_files[agent['id']]), 'w') as f:
|
|
79
|
+
f.write(html)
|
|
80
|
+
|
|
81
|
+
# index.html redirect
|
|
82
|
+
first_file = agent_files[agents[0]['id']] if agents else ''
|
|
83
|
+
index_html = '''<!DOCTYPE html>
|
|
84
|
+
<html lang=\"en\">
|
|
85
|
+
<head>
|
|
86
|
+
<meta charset=\"UTF-8\">
|
|
87
|
+
<meta http-equiv=\"refresh\" content=\"0; url=''' + first_file + '''\">
|
|
88
|
+
<title>Session Replay</title>
|
|
89
|
+
</head>
|
|
90
|
+
<body>
|
|
91
|
+
<a href=\"''' + first_file + '''\">Open replay</a>
|
|
92
|
+
</body>
|
|
93
|
+
</html>'''
|
|
94
|
+
with open(os.path.join('${dir}', 'index.html'), 'w') as f:
|
|
95
|
+
f.write(index_html)
|
|
96
|
+
"
|
|
97
|
+
echo " Regenerated ${dir}"
|
|
98
|
+
count=$((count + 1))
|
|
99
|
+
done
|
|
100
|
+
|
|
101
|
+
echo "Done — $count recording(s) updated."
|
package/app/webapp/.next/standalone/app/webapp/.next/static/chunks/app/app/page-df00a757f649931a.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[191],{6421:function(e,t,n){Promise.resolve().then(n.bind(n,2953))},2953:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return L}});var a=n(7573),i=n(7653),r=n(774),o=n(1446),l=n(2574),s=n(3334);function c(e){let{agentId:t}=e,[n,r]=(0,i.useState)(null),[o,l]=(0,i.useState)(!1),[s,c]=(0,i.useState)(!1),[u,d]=(0,i.useState)([]),h=(0,i.useRef)(),p=(0,i.useRef)(0),b=(0,i.useCallback)(()=>{l(!0),clearTimeout(h.current),h.current=setTimeout(()=>l(!1),2e3)},[]);return((0,i.useEffect)(()=>{var e,n,a;let i=[];return i.push(null===(e=window.bangonit)||void 0===e?void 0:e.onCursorMove(e=>{e.agentId===t&&(r({x:e.x,y:e.y}),b())})),i.push(null===(n=window.bangonit)||void 0===n?void 0:n.onCursorDown(e=>{if(e.agentId!==t)return;r({x:e.x,y:e.y}),c(!0),b();let n=++p.current;d(t=>[...t,{id:n,x:e.x,y:e.y}]),setTimeout(()=>{d(e=>e.filter(e=>e.id!==n))},400)})),i.push(null===(a=window.bangonit)||void 0===a?void 0:a.onCursorUp(e=>{e.agentId===t&&(c(!1),b())})),()=>{i.forEach(e=>null==e?void 0:e()),clearTimeout(h.current)}},[t,b]),n)?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("svg",{width:"28",height:"28",viewBox:"0 0 24 24",className:"pointer-events-none absolute z-20",style:{left:n.x,top:n.y,transform:"translate(-2px, -1px) ".concat(s?"scale(0.8)":"scale(1)"),transition:"left 30ms linear, top 30ms linear, transform 80ms ease-out, opacity 400ms ease-out",opacity:o?1:0,filter:"drop-shadow(0 1px 2px rgba(0,0,0,0.5))"},children:(0,a.jsx)("path",{d:"M5 3l14 8.5-6.5 1.5-3.5 6z",fill:"white",stroke:"black",strokeWidth:"1.5",strokeLinejoin:"round"})}),u.map(e=>(0,a.jsxs)("span",{children:[(0,a.jsx)("span",{className:"pointer-events-none absolute z-20 rounded-full bg-blue-400/50",style:{left:e.x,top:e.y,width:0,height:0,transform:"translate(-50%, -50%)",animation:"cursor-ripple ".concat(400,"ms ease-out forwards")}}),(0,a.jsx)("span",{className:"pointer-events-none absolute z-20 rounded-full border-2 border-blue-400/60",style:{left:e.x,top:e.y,width:0,height:0,transform:"translate(-50%, -50%)",animation:"cursor-ripple-ring ".concat(400,"ms ease-out forwards")}})]},e.id)),(0,a.jsx)("style",{children:"\n @keyframes cursor-ripple {\n 0% { width: 0; height: 0; opacity: 0.8; }\n 100% { width: 48px; height: 48px; opacity: 0; }\n }\n @keyframes cursor-ripple-ring {\n 0% { width: 0; height: 0; opacity: 0.9; }\n 100% { width: 64px; height: 64px; opacity: 0; }\n }\n "})]}):null}async function u(e,t,n,a){let{result:i}=await window.bangonit.cdpSend(e,"Runtime.evaluate",{expression:"\n(function() {\n var MAX_CHARS = 60000;\n var MAX_ELEMENTS = 5000;\n var MAX_DEPTH = 1500;\n var totalChars = 0;\n var visited = 0;\n var truncated = false;\n var refCounter = 0;\n\n window.__dmjRefs = new Map();\n\n var SKIP_TAGS = {SCRIPT:1,STYLE:1,NOSCRIPT:1,SVG:1,PATH:1,META:1,LINK:1,TEMPLATE:1,IFRAME:1,BR:1,HR:1,WBR:1,CANVAS:1,VIDEO:1,AUDIO:1,MAP:1,AREA:1,PICTURE:1,SOURCE:1,TRACK:1,OBJECT:1,EMBED:1};\n var INTERACTIVE_ROLES = {button:1,link:1,textbox:1,checkbox:1,radio:1,combobox:1,menuitem:1,tab:1,switch:1,option:1};\n var INPUT_ROLE = {checkbox:'checkbox',radio:'radio',submit:'button',button:'button',search:'searchbox',file:'file'};\n var TAG_ROLE = {A:'link',BUTTON:'button',SELECT:'combobox',TEXTAREA:'textbox',IMG:'img',H1:'heading',H2:'heading',H3:'heading',H4:'heading',H5:'heading',H6:'heading',NAV:'navigation',MAIN:'main',FORM:'form',TABLE:'table',UL:'list',OL:'list',LI:'listitem'};\n\n function isVisible(el) {\n if (el.hidden || el.getAttribute('aria-hidden') === 'true') return false;\n if (!el.offsetParent && el.tagName !== 'BODY' && el.tagName !== 'HTML') {\n var pos = getComputedStyle(el).position;\n if (pos !== 'fixed' && pos !== 'sticky') return false;\n }\n var s = el.style;\n if (s.display === 'none' || s.visibility === 'hidden') return false;\n return true;\n }\n\n function isInteractive(el) {\n var tag = el.tagName;\n if (tag === 'A' || tag === 'BUTTON' || tag === 'SELECT' || tag === 'TEXTAREA') return true;\n if (tag === 'INPUT' && el.type !== 'hidden') return true;\n var role = el.getAttribute('role');\n if (role && INTERACTIVE_ROLES[role]) return true;\n var tabindex = el.getAttribute('tabindex');\n if (el.onclick || (tabindex !== null && tabindex >= '0')) return true;\n if (el.contentEditable === 'true') return true;\n return false;\n }\n\n function getRole(el) {\n var r = el.getAttribute('role');\n if (r) return r;\n if (el.tagName === 'INPUT') return INPUT_ROLE[(el.type||'text').toLowerCase()] || 'textbox';\n return TAG_ROLE[el.tagName] || null;\n }\n\n function getLabel(el) {\n return (el.getAttribute('aria-label') || el.getAttribute('placeholder') || el.getAttribute('alt') || el.getAttribute('title') || '').slice(0, 50);\n }\n\n function directText(el) {\n var t = '';\n for (var n = el.firstChild; n; n = n.nextSibling) {\n if (n.nodeType === 3) t += n.data;\n if (t.length > 60) break;\n }\n return t.trim().replace(/\\s+/g, ' ').slice(0, 60);\n }\n\n function walk(el, depth) {\n if (truncated || !el || el.nodeType !== 1) return '';\n if (SKIP_TAGS[el.tagName]) return '';\n if (!isVisible(el)) return '';\n if (depth > MAX_DEPTH) return '';\n if (++visited > MAX_ELEMENTS) { truncated = true; return ''; }\n\n var role = getRole(el);\n var interactive = isInteractive(el);\n var showThis = !!(role || interactive);\n var lines = [];\n\n if (showThis) {\n var label = getLabel(el);\n var dtext = directText(el);\n var line = '[' + (role || el.tagName.toLowerCase());\n var txt = label || dtext;\n if (txt) line += ' \"' + txt.replace(/\"/g, \"'\") + '\"';\n if (interactive) {\n var ref = 'e' + (++refCounter);\n window.__dmjRefs.set(ref, new WeakRef(el));\n line += ' ref=' + ref;\n }\n line += ']';\n if (el === document.activeElement) line += ' [focused]';\n if ((el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') && el.value) line += ' val=\"' + el.value.slice(0,40) + '\"';\n if (el.tagName === 'INPUT' && (el.type === 'checkbox' || el.type === 'radio')) line += el.checked ? ' [x]' : ' [ ]';\n\n totalChars += line.length;\n if (totalChars > MAX_CHARS) { truncated = true; return ''; }\n lines.push(line);\n }\n\n for (var c = el.firstElementChild; c; c = c.nextElementSibling) {\n if (truncated) break;\n var out = walk(c, showThis ? depth + 1 : depth);\n if (out) lines.push(showThis ? out.split('\\n').map(function(l){return ' '+l}).join('\\n') : out);\n }\n\n if (!showThis) {\n var dt = directText(el);\n if (dt.length > 2) {\n totalChars += dt.length;\n if (totalChars > MAX_CHARS) { truncated = true; return ''; }\n lines.push('\"' + dt + '\"');\n }\n }\n\n return lines.join('\\n');\n }\n\n var tree = walk(document.body, 0);\n var h = 'URL: ' + location.href + '\\nTitle: ' + document.title;\n if (truncated) h += '\\n[TRUNCATED - page too large]';\n return h + '\\n\\n' + tree;\n})()\n",returnByValue:!0});return(i.value||"Empty page")+"\n\nMouse position: ".concat(t,",").concat(n)+a}async function d(e,t,n){let a=window.bangonit;if(t.ref){let{result:r}=await a.cdpSend(e,"Runtime.evaluate",{expression:'(function() { var r = window.__dmjRefs && window.__dmjRefs.get("'.concat(t.ref,'"); return r ? r.deref() || null : null; })()'),returnByValue:!1});if(!r.objectId)throw Error('Element ref "'.concat(t.ref,'" not found — take a new snapshot'));try{let{model:i}=await a.cdpSend(e,"DOM.getBoxModel",{objectId:r.objectId}),o=i.content,l=Math.round((o[0]+o[2]+o[4]+o[6])/4),s=Math.round((o[1]+o[3]+o[5]+o[7])/4);if(n){let{result:t}=await a.cdpSend(e,"Runtime.evaluate",{expression:"JSON.stringify({ w: window.innerWidth, h: window.innerHeight })",returnByValue:!0}),n=JSON.parse(t.value);if(l<0||l>n.w||s<0||s>n.h){await a.cdpSend(e,"Runtime.callFunctionOn",{objectId:r.objectId,functionDeclaration:'function() { this.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); }',returnByValue:!0}),await new Promise(e=>setTimeout(e,100));let{model:t}=await a.cdpSend(e,"DOM.getBoxModel",{objectId:r.objectId}),n=t.content;l=Math.round((n[0]+n[2]+n[4]+n[6])/4),s=Math.round((n[1]+n[3]+n[5]+n[7])/4)}}else if(l<0||s<0){let{result:n}=await a.cdpSend(e,"Runtime.callFunctionOn",{objectId:r.objectId,functionDeclaration:"function() {\n var r = this.getBoundingClientRect();\n return { top: r.top, bottom: r.bottom, left: r.left, right: r.right, vh: window.innerHeight, vw: window.innerWidth };\n }",returnByValue:!0}),i=n.value;if(i){let e=i.top<0?Math.round(i.top-100):i.bottom>i.vh?Math.round(i.bottom-i.vh+100):0,n=0!==e?" Scroll ".concat(e>0?"down":"up"," ~").concat(Math.abs(e),"px (wheel dy=").concat(e," at current mouse position)"):"";throw Error('Element ref "'.concat(t.ref,'" is not in the viewport and cannot auto-scroll because this batch contains x,y coordinates that would be invalidated by scrolling.').concat(n))}}return{x:l,y:s}}catch(o){var i;if(null===(i=o.message)||void 0===i?void 0:i.includes("not in the viewport"))throw o;if(n)try{await a.cdpSend(e,"Runtime.callFunctionOn",{objectId:r.objectId,functionDeclaration:'function() { this.scrollIntoView({ block: "center", inline: "center", behavior: "instant" }); }',returnByValue:!0}),await new Promise(e=>setTimeout(e,100));let{model:t}=await a.cdpSend(e,"DOM.getBoxModel",{objectId:r.objectId}),n=t.content;return{x:Math.round((n[0]+n[2]+n[4]+n[6])/4),y:Math.round((n[1]+n[3]+n[5]+n[7])/4)}}catch(e){throw Error('Element ref "'.concat(t.ref,'" could not be scrolled into view'))}try{let{result:n}=await a.cdpSend(e,"Runtime.callFunctionOn",{objectId:r.objectId,functionDeclaration:"function() {\n var r = this.getBoundingClientRect();\n return { top: r.top, bottom: r.bottom, left: r.left, right: r.right, vh: window.innerHeight, vw: window.innerWidth };\n }",returnByValue:!0}),i=n.value;if(i){let e=i.top<0?Math.round(i.top-100):i.bottom>i.vh?Math.round(i.bottom-i.vh+100):0,n=0!==e?" Scroll ".concat(e>0?"down":"up"," ~").concat(Math.abs(e),"px (wheel dy=").concat(e," at current mouse position)"):"";throw Error('Element ref "'.concat(t.ref,'" is not in the viewport and cannot auto-scroll because this batch contains x,y coordinates that would be invalidated by scrolling.').concat(n))}}catch(e){if(e.message.includes("not in the viewport"))throw e}throw Error('Element ref "'.concat(t.ref,'" is not visible in the viewport — use only refs or scroll manually first'))}finally{a.cdpSend(e,"Runtime.releaseObject",{objectId:r.objectId}).catch(e=>console.error(e))}}return{x:t.x,y:t.y}}async function h(e,t,n,a,i,r){let o=window.bangonit,l=Math.hypot(a-t,i-n);if(l<1){null==r||r(a,i);return}let s=Math.min(Math.max(Math.round(l/15),3),40),c=Math.min(Math.max(.8*l,30),300);for(let l=1;l<=s;l++){let u=l/s,d=u<.5?4*u*u*u:1-Math.pow(-2*u+2,3)/2,h=Math.round(t+(a-t)*d),p=Math.round(n+(i-n)*d);await o.cdpSend(e,"Input.dispatchMouseEvent",{type:"mouseMoved",x:h,y:p}),null==r||r(h,p),l<s&&await new Promise(e=>setTimeout(e,c/s))}}async function p(e,t,n,a,i){var r,o,l,s,c,u,p,b;let m=window.bangonit;null===(r=i.onMouseLock)||void 0===r||r.call(i);let w=!t.some(e=>"wait"!==e.action&&void 0!==e.x),g=n,f=a;try{let n=[];for(let a of t){if("wait"===a.action){await new Promise(e=>setTimeout(e,Math.min(a.ms||100,2e3))),n.push("wait(".concat(a.ms||100,"ms)"));continue}let t=a.ref?{ref:a.ref}:{x:a.x,y:a.y},r=await d(e,t,w),b="".concat(r.x,",").concat(r.y),{x:v,y:x}=r;switch(a.action){case"down":await h(e,g,f,v,x,i.onCursorMove),g=v,f=x,null===(o=i.onCursorDown)||void 0===o||o.call(i,v,x),await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mousePressed",x:v,y:x,button:"left",clickCount:1}),n.push("down(".concat(b,")"));break;case"move":await h(e,g,f,v,x,i.onCursorMove),g=v,f=x,n.push("move(".concat(b,")"));break;case"up":await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mouseReleased",x:v,y:x,button:"left",clickCount:1}),null===(l=i.onCursorUp)||void 0===l||l.call(i,v,x),n.push("up(".concat(b,")"));break;case"click":await h(e,g,f,v,x,i.onCursorMove),g=v,f=x,null===(s=i.onCursorDown)||void 0===s||s.call(i,v,x),await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mousePressed",x:v,y:x,button:"left",clickCount:1}),await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mouseReleased",x:v,y:x,button:"left",clickCount:1}),null===(c=i.onCursorUp)||void 0===c||c.call(i,v,x),n.push("click(".concat(b,")"));break;case"dblclick":await h(e,g,f,v,x,i.onCursorMove),g=v,f=x,null===(u=i.onCursorDown)||void 0===u||u.call(i,v,x),await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mousePressed",x:v,y:x,button:"left",clickCount:1}),await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mouseReleased",x:v,y:x,button:"left",clickCount:1}),await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mousePressed",x:v,y:x,button:"left",clickCount:2}),await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mouseReleased",x:v,y:x,button:"left",clickCount:2}),null===(p=i.onCursorUp)||void 0===p||p.call(i,v,x),n.push("dblclick(".concat(b,")"));break;case"wheel":{await h(e,g,f,v,x,i.onCursorMove),g=v,f=x;let t=a.dx||0,r=a.dy||0;await m.cdpSend(e,"Input.dispatchMouseEvent",{type:"mouseWheel",x:v,y:x,deltaX:t,deltaY:r}),n.push("wheel(".concat(b,",").concat(t,",").concat(r,")"))}}}return{result:"Mouse: ".concat(n.join(" → ")),mouseX:g,mouseY:f}}finally{null===(b=i.onMouseUnlock)||void 0===b||b.call(i)}}async function b(e,t){let n=window.bangonit;for(let a of t)await n.sendInputEvent(e,{type:"keyDown",keyCode:a}),await n.sendInputEvent(e,{type:"char",keyCode:a}),await n.sendInputEvent(e,{type:"keyUp",keyCode:a}),await new Promise(e=>setTimeout(e,30+70*Math.random()));return'Typed "'.concat(t.slice(0,50),'"')}async function m(e,t){let n=window.bangonit,a=t.split("+"),i=a.pop(),r=a.map(e=>e.toLowerCase()),o=[];for(let e of r)"control"===e||"ctrl"===e?o.push("control"):"meta"===e||"command"===e||"cmd"===e?o.push("meta"):"alt"===e||"option"===e?o.push("alt"):"shift"===e&&o.push("shift");return await n.sendInputEvent(e,{type:"keyDown",keyCode:i,modifiers:o}),0===o.length&&("Enter"===i?await n.sendInputEvent(e,{type:"char",keyCode:"\r"}):1===i.length&&await n.sendInputEvent(e,{type:"char",keyCode:i})),await n.sendInputEvent(e,{type:"keyUp",keyCode:i,modifiers:o}),"Pressed ".concat(t)}let w=new Map;async function g(e){let t=new TextEncoder().encode(e);return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256",t))).map(e=>e.toString(16).padStart(2,"0")).join("")}async function f(e){let t;let n=window.bangonit;try{t=await n.capturePage(e)}catch(e){throw Error("could not capture page (page may be navigating)")}let{activeTabId:a}=await n.getTabInfo(e),i="".concat(e,":").concat(null!=a?a:0),r=await g(t);return w.get(i)===r?{type:"not_changed"}:(w.set(i,r),{type:"changed",base64:t})}async function v(e,t){let n=window.bangonit;t.startsWith("http://")||t.startsWith("https://")||(t="https://"+t);let{url:a}=await n.loadURL(e,t);return"Navigated to ".concat(a)}async function x(e){let{ok:t,url:n,reason:a}=await window.bangonit.goBack(e);return t?"Navigated back to ".concat(n):"Cannot go back — ".concat(a)}async function y(e){let{ok:t,url:n,reason:a}=await window.bangonit.goForward(e);return t?"Navigated forward to ".concat(n):"Cannot go forward — ".concat(a)}async function I(e,t){let n=window.bangonit,a=t.action;switch(a){case"list":{let{tabs:t,activeTabId:a}=await n.getTabInfo(e);if(!t.length)return"No tabs open";return t.map(e=>{let t=e.tabId===a?" (active)":"",n=e.isPopup?" (popup)":"";return"Tab ".concat(e.tabId,": ").concat(e.title||"(untitled)"," — ").concat(e.url).concat(t).concat(n)}).join("\n")}case"new":{await n.requestNewTab(e,t.url||"about:blank"),await new Promise(e=>setTimeout(e,3e3));let{activeTabId:a}=await n.getTabInfo(e);return"Opened new tab".concat(t.url?": "+t.url:"",". Active tab is now ").concat(a,".")}case"select":{let a=t.tabId;if(void 0===a)return"Error: tabId required for select";let{tabs:i}=await n.getTabInfo(e);if(!i.find(e=>e.tabId===a))return"Error: tab ".concat(a,' not found. Use browser_tabs with action "list" to see available tabs.');await n.setActiveTab(e,a),await n.requestSelectTab(e,a);let r=i.find(e=>e.tabId===a);return"Switched to tab ".concat(a,": ").concat(null==r?void 0:r.url)}case"close":{var i;let{tabs:a,activeTabId:r}=await n.getTabInfo(e),o=null!==(i=t.tabId)&&void 0!==i?i:r;if(null===o)return"Error: no tab to close";if(!a.find(e=>e.tabId===o))return"Error: tab ".concat(o," not found.");if(a.length<=1)return"Cannot close the last tab.";return await n.requestCloseTab(e,o),"Closed tab ".concat(o)}default:return'Error: unknown tab action "'.concat(a,'". Use list, new, select, or close.')}}async function k(e){let{tabs:t,activeTabId:n}=await window.bangonit.getTabInfo(e);return t.length<=1?"":"\n\nOpen tabs:\n"+t.map(e=>{let t=e.tabId===n?" (active)":"",a=e.isPopup?" (popup)":"";return" Tab ".concat(e.tabId,": ").concat(e.title||"(untitled)"," — ").concat(e.url).concat(t).concat(a)}).join("\n")}async function T(e,t){let n=window.bangonit,a=Math.min(Math.max((null==t?void 0:t.timeout)||10,.1),30),i=null==t?void 0:t.text,r="visible"===((null==t?void 0:t.state)||"visible");if(!i)return await new Promise(e=>setTimeout(e,1e3*a)),"Waited ".concat(a," seconds");let o=Date.now()+1e3*a;for(;Date.now()<o;){let{result:t}=await n.cdpSend(e,"Runtime.evaluate",{expression:"document.body.innerText.includes(".concat(JSON.stringify(i),")"),returnByValue:!0}),a=t.value;if(r&&a)return'Text "'.concat(i,'" is now visible on the page.');if(!r&&!a)return'Text "'.concat(i,'" is no longer visible on the page.');await new Promise(e=>setTimeout(e,500))}return'Timeout: text "'.concat(i,'" ').concat(r?"did not appear":"did not disappear"," within ").concat(a,"s.")}class N{start(){!this.cleanup&&window.bangonit&&(this.cleanup=window.bangonit.onCdpEvent(e=>{"Network.requestWillBeSent"===e.method?this.inflightRequests++:("Network.loadingFinished"===e.method||"Network.loadingFailed"===e.method)&&(this.inflightRequests=Math.max(0,this.inflightRequests-1))}))}stop(){var e;null===(e=this.cleanup)||void 0===e||e.call(this),this.cleanup=null,this.inflightRequests=0}async waitForIdle(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:500,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2e3,n=Date.now()+t,a=0===this.inflightRequests?Date.now():null;for(;Date.now()<n;){if(0===this.inflightRequests){if(a||(a=Date.now()),Date.now()-a>=e)return}else a=null;await new Promise(e=>setTimeout(e,50))}}constructor(){this.inflightRequests=0,this.cleanup=null}}let C={navigate:"browser_navigate",back:"browser_navigate_back",forward:"browser_go_forward",mouse:"browser_mouse",type:"browser_type",press:"browser_press_key",tabs:"browser_tabs",downloads:"browser_downloads",wait:"browser_wait_for",close:"browser_close"};var j=n(8204);let E=j.VK("type",[j.Ry({type:j.i0("not_changed")}),j.Ry({type:j.i0("changed"),base64:j.Z_()})]);j.Ry({textOutput:j.Z_(),imageOutput:E.nullable()});let S=Promise.resolve();class R{destroy(){this.networkTracker.stop()}enableRecording(e){this.recorder=e}cursorCallbacks(){let e=this.agentId,t=window.bangonit,n=this.recorder;return{onCursorMove:(a,i)=>{t.emitCursorMove(e,a,i),null==n||n.updateCursor(a,i)},onCursorDown:(a,i)=>{t.emitCursorDown(e,a,i),null==n||n.setCursorDown()},onCursorUp:(a,i)=>{t.emitCursorUp(e,a,i),null==n||n.setCursorUp()},onMouseLock:()=>t.emitMouseLock(e),onMouseUnlock:()=>t.emitMouseUnlock(e)}}async callTool(e,t){switch(e){case"browser_navigate":return v(this.agentId,t.url);case"browser_navigate_back":return x(this.agentId);case"browser_go_forward":return y(this.agentId);case"browser_mouse":{let{result:e,mouseX:n,mouseY:a}=await p(this.agentId,t.steps,this.mouseX,this.mouseY,this.cursorCallbacks());return this.mouseX=n,this.mouseY=a,e}case"browser_type":return b(this.agentId,t.text);case"browser_press_key":return m(this.agentId,t.key);case"browser_close":return I(this.agentId,{action:"close"});case"browser_wait_for":return T(this.agentId,t);case"browser_tabs":return I(this.agentId,t);case"browser_downloads":{let e=await window.bangonit.getDownloads(this.agentId);if(!e.length)return"No downloads.";return e.map(e=>{let t=e.totalBytes>0?Math.round(e.bytes/e.totalBytes*100)+"%":"";return"[".concat(e.state,"] ").concat(e.filename," ").concat(t," → ").concat(e.path)}).join("\n")}default:throw Error("Unknown tool: ".concat(e))}}async exec(e){let t=function(){let e;let t=new Promise(t=>{e=t}),n=S;return S=S.then(()=>t),{promise:n,release:e}}();await t.promise;try{return await this._exec(e)}finally{t.release()}}async _exec(e){var t,n,a,i,r,o,l;let{actions:s,observe:c}=e,d=[],h=null;if(this.recorder)try{let e=await (null===(t=window.bangonit)||void 0===t?void 0:t.getTabInfo(this.agentId)),i=null!==(a=null==e?void 0:e.activeTabId)&&void 0!==a?a:0,r=null==e?void 0:null===(n=e.tabs)||void 0===n?void 0:n.find(e=>e.tabId===i);await this.recorder.startClip(i,null==r?void 0:r.url)}catch(e){console.warn("Failed to start recording clip:",e)}for(let e=0;e<s.length;e++){let t=s[e];if(!t||!t.action)continue;let n=C[t.action];if(!n){d.push("".concat(t.action,": Error — unknown action"));continue}try{let e=this.actionToToolArgs(t),a=await this.callTool(n,e);d.push(a||"OK")}catch(e){d.push("".concat(this.actionLabel(t),": Error — ").concat(e.message))}}if(c){s.length>0&&await this.networkTracker.waitForIdle(500,2e3);try{let e=await k(this.agentId),t=await u(this.agentId,this.mouseX,this.mouseY,e);d.push(t),"snapshot_and_screenshot"===c&&(h=await f(this.agentId))}catch(e){d.push("observe: Error — ".concat(e.message))}}if(this.recorder)try{let e=await this.recorder.stopClip();if(e){let t=await (null===(r=window.bangonit)||void 0===r?void 0:null===(i=r.getRunDir)||void 0===i?void 0:i.call(r));if(t){let n=await e.blob.arrayBuffer();await (null===(l=window.bangonit)||void 0===l?void 0:null===(o=l.saveRecordingClip)||void 0===o?void 0:o.call(l,{runDir:t,agentId:e.meta.agentId,clipIndex:e.meta.index,tabId:e.meta.tabId,data:n}))}}}catch(e){console.warn("Failed to save recording clip:",e)}return{textOutput:d.join("\n\n"),imageOutput:h}}actionToToolArgs(e){switch(e.action){case"navigate":return{url:e.url};case"back":case"forward":case"close":case"downloads":default:return{};case"mouse":return{steps:(e.mouseActions||[]).map(e=>{if("wait"===e.action)return{action:"wait",ms:e.ms||100};let t=e.ref?{ref:e.ref}:{x:e.x,y:e.y};return"wheel"===e.action?{action:"wheel",...t,dx:e.dx||0,dy:e.dy||0}:{action:e.action,...t}})};case"type":return{text:e.text};case"press":return{key:e.key};case"tabs":return{action:e.tabAction,tabId:e.tabId,url:e.url};case"wait":return{timeout:e.timeout}}}actionLabel(e){switch(e.action){case"navigate":return"navigate ".concat(e.url);case"mouse":{let t=(e.mouseActions||[]).map(e=>"wait"===e.action?"wait ".concat(e.ms,"ms"):"wheel"===e.action?"wheel ".concat(e.x,",").concat(e.y," ").concat(e.dx,",").concat(e.dy):"".concat(e.action," ").concat(e.x,",").concat(e.y)).join(" → ");return"mouse ".concat(t)}case"type":return'type "'.concat((e.text||"").slice(0,30),'"');case"press":return"press ".concat(e.key);case"tabs":return"tabs ".concat(e.tabAction).concat(e.tabId?" "+e.tabId:"");case"wait":return"wait ".concat(e.timeout||10,"s");default:return e.action}}constructor(e){this.mouseX=0,this.mouseY=0,this.networkTracker=new N,this.recorder=null,this.agentId=e,this.networkTracker.start()}}class M{async startClip(e,t){this.currentUrl=t||"",this.recording&&await this.cancelClip(),this.recording=!0,this.currentTabId=e,this.currentFrames=[],this.clipStartTime=Date.now();let n=window.bangonit;this.cdpCleanup=n.onCdpEvent(e=>{if(e.agentId!==this.agentId||"Page.screencastFrame"!==e.method||!this.recording)return;let{data:t,metadata:a,sessionId:i}=e.params;this.currentFrames.push({imageData:t,cursor:{...this.cursorPos},clicking:this.clicking,ts:Date.now(),sessionId:i,deviceWidth:(null==a?void 0:a.deviceWidth)||0,deviceHeight:(null==a?void 0:a.deviceHeight)||0,scrollOffsetX:(null==a?void 0:a.scrollOffsetX)||0,scrollOffsetY:(null==a?void 0:a.scrollOffsetY)||0}),n.cdpSend(this.agentId,"Page.screencastFrameAck",{sessionId:i}).catch(e=>console.error(e))}),await n.cdpSend(this.agentId,"Page.startScreencast",{format:"png",quality:100,maxWidth:1920,maxHeight:1080})}async stopClip(){if(!this.recording)return null;this.recording=!1;let e=Date.now();await window.bangonit.cdpSend(this.agentId,"Page.stopScreencast").catch(e=>console.error(e)),this.cdpCleanup&&(this.cdpCleanup(),this.cdpCleanup=null);let t=this.currentFrames;if(this.currentFrames=[],0===t.length)return null;let n=await this.compositeAndEncode(t);if(!n||0===n.size)return null;let a={agentId:this.agentId,tabId:this.currentTabId,index:this.clips.length,startTime:this.clipStartTime,endTime:e,path:"clips/".concat(this.agentId,"/clip-").concat(this.clips.length,"-tab-").concat(this.currentTabId,".webm"),url:this.currentUrl||void 0};return this.clips.push(a),{blob:n,meta:a}}async cancelClip(){var e;this.recording=!1,this.currentFrames=[],this.cdpCleanup&&(this.cdpCleanup(),this.cdpCleanup=null),await (null===(e=window.bangonit)||void 0===e?void 0:e.cdpSend(this.agentId,"Page.stopScreencast").catch(e=>console.error(e)))}async compositeAndEncode(e){if(0===e.length)return null;let t=await this.decodeFrame(e[0].imageData);if(!t)return null;let n=t.width,a=t.height,i=document.createElement("canvas");i.width=n,i.height=a;let r=i.getContext("2d"),o=i.captureStream(0),l=o.getVideoTracks()[0],s=new MediaRecorder(o,{mimeType:"video/webm;codecs=vp8",videoBitsPerSecond:8e6}),c=[];s.ondataavailable=e=>{e.data.size>0&&c.push(e.data)};let u=new Promise(e=>{s.onstop=()=>{e(new Blob(c,{type:"video/webm"}))}});s.start();let d=[];for(let i=0;i<e.length;i++){let o=e[i],s=0===i?t:await this.decodeFrame(o.imageData);if(!s)continue;let c=o.deviceWidth>0?n/o.deviceWidth:1,u=o.deviceHeight>0?a/o.deviceHeight:1,m=o.cursor.x*c,w=o.cursor.y*u;o.clicking&&(0===i||!e[i-1].clicking)&&d.push({x:m,y:w,startTs:o.ts}),r.clearRect(0,0,n,a),r.drawImage(s,0,0,n,a);for(let e=d.length-1;e>=0;e--){var h,p,b;let t=d[e],n=o.ts-t.startTs;if(n>=400){d.splice(e,1);continue}h=t.x,p=t.y,b=n/400,r.save(),r.beginPath(),r.arc(h,p,24*b,0,2*Math.PI),r.fillStyle="rgba(96, 165, 250, ".concat(.8*(1-b),")"),r.fill(),r.restore(),r.save(),r.beginPath(),r.arc(h,p,32*b,0,2*Math.PI),r.strokeStyle="rgba(96, 165, 250, ".concat(.9*(1-b),")"),r.lineWidth=2,r.stroke(),r.restore()}if(!function(e,t,n,a){e.save(),e.translate(t-2,n-1),e.scale(28/24,28/24);let i=new Path2D("M5 3l14 8.5-6.5 1.5-3.5 6z");e.fillStyle="white",e.strokeStyle="black",e.lineWidth=1.5,e.lineJoin="round",e.fill(i),e.stroke(i),e.restore(),a&&(e.save(),e.beginPath(),e.arc(t,n,4,0,2*Math.PI),e.fillStyle="rgba(59, 130, 246, 0.5)",e.fill(),e.restore())}(r,m,w,o.clicking),l&&"function"==typeof l.requestFrame&&l.requestFrame(),i<e.length-1){let t=Math.max(16,Math.min(e[i+1].ts-o.ts,100));await new Promise(e=>setTimeout(e,t))}}return await new Promise(e=>setTimeout(e,100)),s.stop(),u}async decodeFrame(e){try{let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);let a=new Blob([n],{type:"image/png"});return createImageBitmap(a)}catch(e){return console.warn("Failed to decode frame:",e),null}}updateCursor(e,t){this.cursorPos={x:e,y:t}}setCursorDown(){this.clicking=!0}setCursorUp(){this.clicking=!1}getClipsMeta(){return[...this.clips]}constructor(e){this.clips=[],this.currentFrames=[],this.cursorPos={x:0,y:0},this.clicking=!1,this.recording=!1,this.currentTabId=0,this.clipStartTime=0,this.cdpCleanup=null,this.ripples=[],this.currentUrl="",this.agentId=e}}function z(e){var t;let{agentId:n,agentName:l,initialPrompt:s,onStatusChange:u,onRerun:d,initialMessages:h,initialTabs:p,initialActiveTabId:b,initialTodos:m,record:w,sessionRecorder:g,onRegisterRecorder:f}=e,[v,x]=(0,i.useState)((null==p?void 0:p.map(e=>({...e,initialUrl:e.url})))||[{id:0,url:"about:blank",title:"",initialUrl:"about:blank"}]),[y,I]=(0,i.useState)(null!=b?b:0),[k,T]=(0,i.useState)(()=>{let e=null==p?void 0:p.find(e=>e.id===(null!=b?b:0));return(null==e?void 0:e.url)||""}),[N,C]=(0,i.useState)(null),[j,E]=(0,i.useState)(!1),[S,z]=(0,i.useState)(!1),A=(0,i.useRef)(new Map),[_,D]=(0,i.useState)(m||[]),O=(0,i.useRef)(null),U=(0,i.useRef)(!1),L=(0,i.useRef)(p?Math.max(...p.map(e=>e.id))+1:1),F=(0,i.useRef)(new Set),[B,H]=(0,i.useState)(0),W=(0,i.useRef)(null),V=(0,i.useRef)(null);!V.current&&window.bangonit&&(V.current=new R(n));let X=(0,i.useRef)(null);w&&!X.current&&V.current&&(X.current=new M(n),V.current.enableRecording(X.current),null==f||f(n,X.current));let J=(0,i.useRef)(g);J.current=g;let q=(0,i.useMemo)(()=>new o.PD({api:"/api/chat",headers:()=>({"X-Client-Platform":navigator.platform})}),[]),Y=(0,i.useRef)(!1),G=(0,i.useCallback)((e,t)=>{var a,i;null===(i=window.bangonit)||void 0===i||null===(a=i.emitAgentOutput)||void 0===a||a.call(i,{agentId:n,type:e,text:t,name:l})},[n,l]),{messages:K,setMessages:Z,sendMessage:Q,addToolOutput:$,stop:ee,status:et,error:en}=(0,r.RJ)({transport:q,messages:h,sendAutomaticallyWhen:e=>{let{messages:t}=e;return!Y.current&&!j&&(0,o.Qk)({messages:t})},async onToolCall(e){var t,a,i,r,o,s,c,u,d,h,p;let{toolCall:b}=e;if("report_result"===b.toolName){let e=b.input,h=(null==e?void 0:e.result)==="pass"?"pass":"fail",p=(null==e?void 0:e.summary)||"";if(G("status","".concat(h.toUpperCase(),": ").concat(p)),C({result:h,summary:p}),J.current){J.current.addEvent({ts:Date.now(),agentId:n,type:"result",data:{result:h,summary:p}});try{let e=await (null===(r=window.bangonit)||void 0===r?void 0:null===(i=r.getRunDir)||void 0===i?void 0:i.call(r));if(e){let t=(null===(o=X.current)||void 0===o?void 0:o.getClipsMeta())||[],a=[{id:n,name:l,result:h,summary:p}],i=J.current.toJSON(a,t);await (null===(c=window.bangonit)||void 0===c?void 0:null===(s=c.saveReplayData)||void 0===s?void 0:s.call(c,{runDir:e,data:JSON.stringify(i)})),await (null===(d=window.bangonit)||void 0===d?void 0:null===(u=d.generateReplayHtml)||void 0===u?void 0:u.call(d,{runDir:e}))}}catch(e){console.error(e)}}null===(a=window.bangonit)||void 0===a||null===(t=a.reportTestResult)||void 0===t||t.call(a,{agentId:n,status:h,summary:p}),$({tool:b.toolName,toolCallId:b.toolCallId,output:"Test result recorded: ".concat(h)});return}if("todos"===b.toolName){let e=b.input,t=(null==e?void 0:e.todos)||_;(null==e?void 0:e.todos)&&D(e.todos),$({tool:b.toolName,toolCallId:b.toolCallId,output:JSON.stringify(t)});return}if("browser"===b.toolName){try{let e=b.input,t=((null==e?void 0:e.actions)||[]).map(e=>"navigate"===e.action?"navigate ".concat(e.url):"type"===e.action?'type "'.concat((e.text||"").slice(0,30),'"'):"press"===e.action?"press ".concat(e.key):"mouse"===e.action?"mouse ".concat((e.mouseActions||[]).map(e=>"".concat(e.action," ").concat(e.ref||"".concat(e.x,",").concat(e.y))).join(" > ")):e.action).join(", ");G("tool","browser: ".concat(t).concat((null==e?void 0:e.observe)?" [".concat(e.observe,"]"):"")),null===(h=J.current)||void 0===h||h.addEvent({ts:Date.now(),agentId:n,type:"tool-start",data:{tool:"browser",label:t}});let a=V.current,i=a?await a.exec({actions:(null==e?void 0:e.actions)||[],observe:null==e?void 0:e.observe,prompts:null==e?void 0:e.prompts}):{error:"Error: browser tools not available"};null===(p=J.current)||void 0===p||p.addEvent({ts:Date.now(),agentId:n,type:"tool-end",data:{tool:"browser"}}),$({tool:b.toolName,toolCallId:b.toolCallId,output:Y.current?{error:"[Stopped by user]"}:JSON.stringify(i)})}catch(e){$({tool:b.toolName,toolCallId:b.toolCallId,...Y.current?{output:"[Stopped by user]"}:{state:"output-error",errorText:e.message}})}return}}});(0,i.useCallback)(()=>{Y.current=!0,ee()},[ee]);let ea="submitted"===et||"streaming"===et;(0,i.useEffect)(()=>{ea&&(Y.current=!1)},[ea]);let ei=K.length>0,er=null!==N;(0,i.useEffect)(()=>{if(ei&&!W.current&&(W.current=Date.now()),!ei||er)return;let e=setInterval(()=>{W.current&&H(Math.floor((Date.now()-W.current)/1e3))},1e3);return()=>clearInterval(e)},[ei,er]);let eo=(0,i.useRef)(null),el=(0,i.useRef)(0);(0,i.useEffect)(()=>{var e;if(0===K.length)return;let t=K[K.length-1];if("assistant"!==t.role)return;let n=(null===(e=t.parts)||void 0===e?void 0:e.filter(e=>"text"===e.type).map(e=>e.text).join(""))||"";t.id!==eo.current&&(eo.current=t.id,el.current=0);let a=n.slice(el.current);a&&(G("text",a),el.current=n.length)},[K,G]);let es=(0,i.useRef)(ea),ec=(0,i.useRef)(!1);(0,i.useEffect)(()=>{!ec.current&&es.current!==ea&&(es.current=ea,ea?null==u||u(n,"running"):(null==u||u(n,"idle",null==N?void 0:N.result),(null==N?void 0:N.result)&&(ec.current=!0)))},[ea,n,u,N]);let eu=(0,i.useRef)(!1),ed=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(ed.current&&(clearTimeout(ed.current),ed.current=null),!ea&&!er&&!j&&!eu.current&&!(K.length<2))return ed.current=setTimeout(()=>{ed.current=null,eu.current||er||(eu.current=!0,Q({text:"You must call the report_result tool to finalize this test run. Call it now with the result (pass or fail) and a summary."}))},5e3),()=>{ed.current&&clearTimeout(ed.current)}},[ea,er,j,K.length,Q]),(0,i.useEffect)(()=>{var e,t;null===(t=window.bangonit)||void 0===t||null===(e=t.clearPartition)||void 0===e||e.call(t,n)},[n]),(0,i.useEffect)(()=>{J.current&&K.length>0&&J.current.setMessages(n,K)},[K,n]),(0,i.useEffect)(()=>{if(K.length>0){var e,t,a,i;null===(a=window.bangonit)||void 0===a||a.setAgentSession(n,{messages:K,initialPrompt:s,tabs:v.filter(e=>!e.isPopup).map(e=>{let{id:t,url:n,title:a}=e;return{id:t,url:n,title:a}}),activeTabId:(null===(e=v.find(e=>e.id===y))||void 0===e?void 0:e.isPopup)?null!==(i=null===(t=v.find(e=>!e.isPopup))||void 0===t?void 0:t.id)&&void 0!==i?i:0:y,todos:_})}},[K,v,y,n,s,_]);let eh=(0,i.useCallback)(e=>{var t;let a=L.current++;x(t=>[...t,{id:a,url:"about:blank",title:"",initialUrl:e}]),I(a),T("about:blank"===e?"":e),null===(t=window.bangonit)||void 0===t||t.setActiveTab(n,a)},[n]),ep=(0,i.useCallback)(e=>{x(t=>{let a=t.findIndex(t=>t.id===e);if(-1===a)return t;let i=t.filter(t=>t.id!==e);return 0===i.length?t:(I(t=>{if(t===e){var r;let e=i[Math.max(0,a-1)].id,t=i.find(t=>t.id===e);return t&&T("about:blank"===t.url?"":t.url),null===(r=window.bangonit)||void 0===r||r.setActiveTab(n,e),e}return t}),i)})},[n]),eb=(0,i.useCallback)(e=>{var t;I(e),null===(t=window.bangonit)||void 0===t||t.setActiveTab(n,e),x(t=>{let n=t.find(t=>t.id===e);return n&&T("about:blank"===n.url?"":n.url),t})},[n]),em=(0,i.useRef)(eh),ew=(0,i.useRef)(ep),eg=(0,i.useRef)(eb);em.current=eh,ew.current=ep,eg.current=eb,(0,i.useEffect)(()=>{var e,t,a,i,r;let o=[],l=e=>{e&&o.push(e)};return l(null===(e=window.bangonit)||void 0===e?void 0:e.onTabUpdated(e=>{if(e.agentId!==n)return;let t="about:blank"===e.url,a="about:blank"===e.title;x(n=>n.map(n=>n.id===e.tabId?{...n,...!t&&void 0!==e.url&&{url:e.url},...!a&&void 0!==e.title&&{title:e.title}}:n)),void 0===e.url||t||I(t=>(t===e.tabId&&T(e.url),t))})),l(null===(t=window.bangonit)||void 0===t?void 0:t.onOpenNewTab(e=>{e.agentId===n&&em.current(e.url)})),l(null===(a=window.bangonit)||void 0===a?void 0:a.onPopupOpened(e=>{e.agentId===n&&x(t=>[...t,{id:e.tabId,url:e.url||"about:blank",title:"",initialUrl:e.url||"about:blank",isPopup:!0}])})),l(null===(i=window.bangonit)||void 0===i?void 0:i.onCloseTab(e=>{e.agentId===n&&ew.current(e.tabId)})),l(null===(r=window.bangonit)||void 0===r?void 0:r.onSelectTab(e=>{e.agentId===n&&eg.current(e.tabId)})),()=>o.forEach(e=>null==e?void 0:e())},[n]),(0,i.useEffect)(()=>{U.current||(null==h?void 0:h.length)||(U.current=!0,Q({text:s}))},[s,Q,h]),(0,i.useEffect)(()=>{var e;null===(e=O.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[K]);let ef=(0,i.useCallback)((e,t,a)=>{if(!e)return;A.current.set(t,e);let i=()=>{if(!F.current.has(t))try{var i,r,o;let l=null===(i=e.getWebContentsId)||void 0===i?void 0:i.call(e);l&&(F.current.add(t),null===(r=window.bangonit)||void 0===r||r.registerTab(n,t,l,a),t===y&&(null===(o=window.bangonit)||void 0===o||o.setActiveTab(n,t)))}catch(e){console.error(e)}};i(),e.addEventListener("did-attach",i),e.addEventListener("close",()=>ew.current(t)),e._consoleListenerAttached||(e._consoleListenerAttached=!0,e.addEventListener("console-message",e=>{var t,a,i;null===(a=window.bangonit)||void 0===a||null===(t=a.emitConsoleMessage)||void 0===t||t.call(a,{agentId:n,level:e.level,message:e.message,url:e.sourceId||"",line:e.lineNumber||0}),null===(i=J.current)||void 0===i||i.addConsoleLog(n,e.level,e.message,e.sourceId||"",e.lineNumber||0)}))},[n,y]),ev=e=>"".concat(Math.floor(e/60),":").concat((e%60).toString().padStart(2,"0"));return(0,a.jsxs)("div",{className:"flex h-full w-full bg-zinc-950 overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex-1 flex flex-col border-r border-zinc-800 min-w-0",children:[(0,a.jsx)("div",{className:"flex items-center bg-zinc-900 border-b border-zinc-800 overflow-x-auto",children:v.map(e=>(0,a.jsx)("button",{onClick:()=>eb(e.id),className:"flex items-center gap-1.5 px-3 py-2 text-xs border-r border-zinc-800 min-w-0 max-w-[200px] shrink-0\n ".concat(e.id===y?"bg-zinc-800 text-zinc-200":"text-zinc-500 hover:text-zinc-300 hover:bg-zinc-850"),children:(0,a.jsxs)("span",{className:"truncate",children:[e.isPopup?"↗ ":"",e.title||(e.url&&"about:blank"!==e.url?e.url:"New Tab")]})},e.id))}),(0,a.jsx)("div",{className:"flex items-center gap-2 px-3 py-2 bg-zinc-900 border-b border-zinc-800",children:(0,a.jsx)("div",{className:"flex-1 px-3 py-1.5 bg-zinc-800 border border-zinc-700 rounded-lg text-xs text-zinc-400 truncate",children:k||"about:blank"})}),(0,a.jsxs)("div",{className:"flex-1 relative bg-white overflow-hidden",onWheel:e=>e.stopPropagation(),children:[v.map(e=>e.isPopup?e.id===y&&(0,a.jsxs)("div",{className:"absolute inset-0 flex items-center justify-center bg-zinc-900 text-zinc-400 text-sm z-[1]",children:["Popup window open — ",e.title||e.url]},e.id):(0,a.jsx)("webview",{ref:t=>ef(t,e.id,e.initialUrl),src:"about:blank",partition:"persist:agent-".concat(n),allowpopups:"",style:{width:"100%",height:"100%",position:"absolute",backgroundColor:"white",top:0,left:0,pointerEvents:e.id===y?"auto":"none",zIndex:e.id===y?1:0}},e.id)),!(null===(t=v.find(e=>e.id===y))||void 0===t?void 0:t.isPopup)&&(0,a.jsx)(c,{agentId:n}),!er&&(0,a.jsx)("div",{className:"absolute inset-0 z-10 cursor-not-allowed"})]})]}),(0,a.jsxs)("div",{className:"w-[420px] flex flex-col h-full shrink-0",children:[(0,a.jsxs)("div",{className:"flex items-center px-4 py-3 border-b border-zinc-800",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-zinc-300",children:l}),(0,a.jsx)("div",{className:"flex-1"})]}),N&&(0,a.jsxs)("div",{className:"px-4 py-2 text-sm border-b flex items-center gap-3 ".concat("pass"===N.result?"bg-green-950/30 border-green-900/50":"bg-red-950/30 border-red-900/50"),children:[(0,a.jsx)("span",{className:"font-medium ".concat("pass"===N.result?"text-green-400":"text-red-400"),children:"pass"===N.result?"PASSED":"FAILED"}),(0,a.jsx)("span",{className:"text-zinc-500 text-xs",children:ev(B)}),N.summary&&(0,a.jsx)("span",{className:"text-zinc-400 text-xs truncate flex-1",children:N.summary})]}),_.length>0&&(0,a.jsx)("div",{className:"text-xs space-y-1 px-4 py-2 border-b border-zinc-800 bg-zinc-900/80 shrink-0 max-h-48 overflow-y-auto",children:_.map((e,t)=>(0,a.jsxs)("div",{className:"flex items-center gap-2 ".concat("completed"===e.status?"text-zinc-500":"text-zinc-300"),children:[(0,a.jsx)("span",{className:"shrink-0",children:"completed"===e.status?"✓":"in_progress"===e.status?(0,a.jsx)("span",{className:"inline-block w-2 h-2 bg-blue-500 rounded-full animate-pulse"}):"○"}),(0,a.jsx)("span",{className:"completed"===e.status?"line-through":"",children:e.content})]},t))}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-4 space-y-3",children:[K.map(e=>(0,a.jsx)(P,{message:e,agentName:l},e.id)),en&&(0,a.jsx)("div",{className:"text-sm px-3 py-2 bg-red-950/30 border border-red-900/50 rounded-lg text-red-400",children:en.message}),(0,a.jsx)("div",{ref:O})]}),(0,a.jsx)("div",{className:"px-4 py-2 border-t border-zinc-800 flex items-center gap-3 shrink-0",children:er?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"inline-block w-2 h-2 rounded-full shrink-0 ".concat("pass"===N.result?"bg-green-500":"bg-red-500")}),(0,a.jsxs)("span",{className:"text-xs font-medium ".concat("pass"===N.result?"text-green-400":"text-red-400"),children:["pass"===N.result?"Passed":"Failed"," in ",ev(B)]}),(0,a.jsx)("div",{className:"flex-1"}),(0,a.jsx)("button",{onClick:()=>{let e=A.current.get(y);e&&(S?e.closeDevTools():e.openDevTools(),z(!S))},className:"text-xs px-2 py-1 rounded border transition-colors ".concat(S?"border-blue-600 text-blue-400 bg-blue-950/30":"border-zinc-700 hover:border-zinc-500 text-zinc-500 hover:text-zinc-300"),title:"Toggle DevTools",children:"DevTools"}),(0,a.jsx)("button",{onClick:()=>{var e,t;null===(t=window.bangonit)||void 0===t||null===(e=t.emitTestRerun)||void 0===e||e.call(t),null==d||d()},className:"text-xs px-3 py-1 rounded border border-zinc-700 hover:border-zinc-500 text-zinc-400 hover:text-zinc-200 transition-colors",children:"Rerun"})]}):ei?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"inline-block w-2 h-2 rounded-full shrink-0 ".concat(j?"bg-amber-500":"bg-blue-500 animate-pulse")}),(0,a.jsxs)("span",{className:"text-xs text-zinc-400",children:[j?"Paused":"Working"," ",ev(B)]}),(0,a.jsx)("div",{className:"flex-1"}),(0,a.jsx)("button",{onClick:()=>{let e=A.current.get(y);e&&(S?e.closeDevTools():e.openDevTools(),z(!S))},className:"text-xs px-2 py-1 rounded border transition-colors ".concat(S?"border-blue-600 text-blue-400 bg-blue-950/30":"border-zinc-700 hover:border-zinc-500 text-zinc-500 hover:text-zinc-300"),title:"Toggle DevTools",children:"DevTools"}),(0,a.jsx)("button",{onClick:()=>E(!j),className:"text-xs px-2 py-1 rounded border border-zinc-700 hover:border-zinc-500 text-zinc-400 hover:text-zinc-200 transition-colors",children:j?"Continue":"Pause"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"inline-block w-2 h-2 bg-zinc-600 rounded-full shrink-0"}),(0,a.jsx)("span",{className:"text-xs text-zinc-500",children:"Queued"})]})})]})]})}function P(e){var t,n;let{message:i,agentName:r}=e;if("user"===i.role){let e=null===(n=i.parts)||void 0===n?void 0:n.find(e=>"text"===e.type);return(0,a.jsxs)("div",{className:"text-sm",children:[(0,a.jsx)("span",{className:"text-xs text-zinc-500 block mb-1",children:"Test Plan"}),(0,a.jsx)("div",{className:"text-zinc-200 prose prose-invert prose-sm max-w-none",children:(0,a.jsx)(l.UG,{remarkPlugins:[s.Z],children:(null==e?void 0:e.text)||""})})]})}return(0,a.jsx)("div",{className:"text-sm space-y-2",children:null===(t=i.parts)||void 0===t?void 0:t.map((e,t)=>{var n,i;if("text"===e.type&&e.text)return(null===(i=e.providerMetadata)||void 0===i?void 0:null===(n=i.anthropic)||void 0===n?void 0:n.type)==="compaction"?null:(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:"text-xs text-zinc-500 block mb-1",children:r}),(0,a.jsx)("div",{className:"text-zinc-300 prose prose-invert prose-sm max-w-none",children:(0,a.jsx)(l.UG,{remarkPlugins:[s.Z],children:e.text})})]},t);if("dynamic-tool"===e.type||"string"==typeof e.type&&e.type.startsWith("tool-")){let n=e.toolName||("string"==typeof e.type?e.type.replace(/^tool-/,""):"");return"todos"===n||"report_result"===n?null:(0,a.jsx)(A,{part:e},t)}return null})})}function A(e){let{part:t}=e,[n,r]=(0,i.useState)(!1),o=t.input||{},l=t.output,s=t.state||"input-available",c=t.toolName||("string"==typeof t.type?t.type.replace(/^tool-/,""):""),u="input-streaming"===s?"":"browser"===c?(()=>{let e=(o.actions||[]).map(e=>{switch(e.action){case"navigate":return"navigate ".concat(e.url||"");case"mouse":{let t=(e.mouseActions||[]).map(e=>"wait"===e.action?"wait ".concat(e.ms,"ms"):"wheel"===e.action?"wheel ".concat(e.ref||"".concat(e.x,",").concat(e.y)):"".concat(e.action," ").concat(e.ref||"".concat(e.x,",").concat(e.y))).join(" → ");return"mouse ".concat(t)}case"type":return'type "'.concat((e.text||"").slice(0,40),'"');case"press":return"press ".concat(e.key||"");case"tabs":return"tabs ".concat(e.tabAction||"").concat(e.tabId?" "+e.tabId:"");default:return e.action||""}});return o.observe&&e.push(o.observe),e.join(", ")})():o.command||(Object.keys(o).length>0?JSON.stringify(o):"");return(0,a.jsxs)("div",{className:"text-sm",children:[(0,a.jsxs)("button",{onClick:()=>r(!n),className:"flex items-center gap-2 text-xs px-2 py-1.5 bg-zinc-900 border border-zinc-800 rounded-lg hover:border-zinc-700 transition-colors w-full text-left min-w-0",children:["input-streaming"===s||"input-available"===s?(0,a.jsx)("span",{className:"inline-block w-2 h-2 bg-amber-500 rounded-full animate-pulse shrink-0"}):(0,a.jsx)("span",{className:"text-green-500 shrink-0",children:"✓"}),(0,a.jsx)("span",{className:"text-zinc-400 font-mono truncate",children:u}),(0,a.jsx)("span",{className:"ml-auto transition-transform text-zinc-600 shrink-0 ".concat(n?"rotate-90":""),children:"▶"})]}),n&&(0,a.jsxs)("pre",{className:"mt-1 px-3 py-2 bg-zinc-900/50 rounded-lg border border-zinc-800 text-xs whitespace-pre-wrap overflow-x-auto max-h-60 overflow-y-auto",children:[u&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("span",{className:"text-zinc-300 select-all",children:["$ ",u]}),"\n"]}),null!=l&&(()=>{if("browser"===c&&"string"==typeof l)try{let e=JSON.parse(l);if(void 0!==e.textOutput)return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-zinc-500",children:e.textOutput}),e.imageOutput&&(0,a.jsxs)(a.Fragment,{children:["\n",(0,a.jsx)("span",{className:"changed"===e.imageOutput.type?"text-blue-400":"text-zinc-600",children:"changed"===e.imageOutput.type?"[screenshot: changed]":"[screenshot: unchanged]"})]})]})}catch(e){console.error(e)}return(0,a.jsx)("span",{className:"text-zinc-500",children:"string"==typeof l?l:JSON.stringify(l,null,2)})})()]})]})}let _={0:"debug",1:"log",2:"warn",3:"error"};class D{addEvent(e){this.events.push(e)}setMessages(e,t){let n=Date.now(),a=JSON.parse(JSON.stringify(t));for(let t=0;t<a.length;t++){let i=a[t],r="".concat(e,":").concat(t);if(this.seenParts.has(r)||this.seenParts.set(r,n),i._ts=this.seenParts.get(r),i.parts)for(let a=0;a<i.parts.length;a++){let r="".concat(e,":").concat(t,":").concat(a);this.seenParts.has(r)||this.seenParts.set(r,n),i.parts[a]._ts=this.seenParts.get(r)}}this.messages.set(e,a)}addConsoleLog(e,t,n,a,i){this.consoleLogs.has(e)||this.consoleLogs.set(e,[]),this.consoleLogs.get(e).push({ts:Date.now(),level:_[t]||"log",message:n,url:a,line:i})}toJSON(e,t){return{runId:this.runId,startTime:this.startTime,endTime:Date.now(),agents:e,timeline:[...this.events].sort((e,t)=>e.ts-t.ts),messages:Object.fromEntries(this.messages),consoleLogs:Object.fromEntries(this.consoleLogs),clips:t}}constructor(e){this.events=[],this.messages=new Map,this.consoleLogs=new Map,this.seenParts=new Map,this.runId=e,this.startTime=Date.now()}}function O(){let[e,t]=(0,i.useState)([]),[n,r]=(0,i.useState)({}),[o,l]=(0,i.useState)({}),[s,c]=(0,i.useState)(!1),[u,d]=(0,i.useState)({}),h=(0,i.useRef)(new Map),[p,b]=(0,i.useState)(null),[m,w]=(0,i.useState)(!1),[g,f]=(0,i.useState)(!1),v=(0,i.useRef)(null),x=(0,i.useRef)(new Map);(0,i.useEffect)(()=>{(async()=>{var e,n,a,i,o;let s=await (null===(e=window.bangonit)||void 0===e?void 0:e.getAgents())||[];if(0===s.length){let e={id:crypto.randomUUID(),name:"Test 1",createdAt:Date.now()};s.push(e),await (null===(a=window.bangonit)||void 0===a?void 0:a.setAgents(s))}t(s);let u={},d={};for(let e of s){let t=await (null===(i=window.bangonit)||void 0===i?void 0:i.getAgentSession(e.id));t&&(null===(o=t.messages)||void 0===o?void 0:o.length)>0&&(u[e.id]={initialPrompt:t.initialPrompt,initialMessages:t.messages.map(e=>{if("assistant"!==e.role||!e.parts)return e;let t=e.parts.map(e=>"tool-invocation"===e.type&&"result"!==e.state?{...e,state:"result",output:"[Interrupted — app was restarted]"}:e);return{...e,parts:t}}),initialTabs:t.tabs,initialActiveTabId:t.activeTabId,initialTodos:t.todos},d[e.id]="idle")}l(u),r(d),b((null===(n=s[0])||void 0===n?void 0:n.id)||null),c(!0)})()},[]);let y=(0,i.useRef)(e);y.current=e,(0,i.useEffect)(()=>{if(s&&e.length>0){var t;null===(t=window.bangonit)||void 0===t||t.setAgents(e)}},[e,s]);let I=(0,i.useCallback)(async e=>{var t,n;await (null===(n=window.bangonit)||void 0===n?void 0:null===(t=n.clearPartition)||void 0===t?void 0:t.call(n,e));let a=o[e];a&&(r(t=>({...t,[e]:"running"})),d(t=>({...t,[e]:(t[e]||0)+1})),l(t=>({...t,[e]:{initialPrompt:a.initialPrompt}})))},[o]),k=(0,i.useCallback)((e,t)=>{x.current.set(e,t)},[]),T=(0,i.useRef)(n);T.current=n;let N=(0,i.useCallback)(async(e,t)=>{var n,a,i,r,o,l;let s=v.current;if(!s)return;let c=await (null===(a=window.bangonit)||void 0===a?void 0:null===(n=a.getRunDir)||void 0===n?void 0:n.call(a));if(!c)return;let u=[];for(let e of x.current.values())u.push(...e.getClipsMeta());let d={...T.current,[e]:t},h=y.current.map(e=>{let t=d[e.id];return{id:e.id,name:e.name,result:"completed"===t?"pass":"failed"===t?"fail":void 0}}),p=s.toJSON(h,u);await (null===(r=window.bangonit)||void 0===r?void 0:null===(i=r.saveReplayData)||void 0===i?void 0:i.call(r,{runDir:c,data:JSON.stringify(p)})),await (null===(l=window.bangonit)||void 0===l?void 0:null===(o=l.generateReplayHtml)||void 0===o?void 0:o.call(l,{runDir:c}))},[]),C=(0,i.useCallback)((e,t,n)=>{let a;if(a="running"===t?"running":"pass"===n?"completed":"fail"===n?"failed":"idle",r(t=>({...t,[e]:a})),m&&("pass"===n||"fail"===n)&&N(e,a),"fail"===n){let t=h.current.get(e);if(t&&t.attempt<t.maxRetries){var i,o;t.attempt++,null===(o=window.bangonit)||void 0===o||null===(i=o.emitTestRetry)||void 0===i||i.call(o,{agentId:e,attempt:t.attempt,maxRetries:t.maxRetries}),setTimeout(()=>I(e),1e3)}}},[I,m,N]),j=(0,i.useCallback)((e,n,a)=>{a&&t(t=>t.map(t=>t.id===e?{...t,name:a}:t)),l(t=>({...t,[e]:{initialPrompt:n}})),r(t=>({...t,[e]:"running"})),b(e)},[]),E=(0,i.useCallback)(()=>{let n=crypto.randomUUID(),a={id:n,name:"Test ".concat(e.length+1),createdAt:Date.now()};t(e=>[...e,a]),b(n)},[e.length]);if((0,i.useEffect)(()=>{var e,n;let a=null===(n=window.bangonit)||void 0===n?void 0:null===(e=n.onTestPlan)||void 0===e?void 0:e.call(n,e=>{f(!0);let{agentIndex:n,testPlan:a,name:i,retries:o,extraPrompt:s,record:c}=e;if(c&&!v.current){let e=new Date().toISOString().replace(/[:.]/g,"-");v.current=new D(e),w(!0)}t(e=>{let t=n+1,a=[...e];for(;a.length<t;)a.push({id:crypto.randomUUID(),name:i||"Test ".concat(a.length+1),createdAt:Date.now()});return i&&(a=a.map((e,t)=>t===n?{...e,name:i}:e)),a}),setTimeout(()=>{t(e=>{let t=e[n];if(!t)return e;let i=s?"".concat(a,"\n\n## Additional Instructions\n").concat(s):a;return l(e=>({...e,[t.id]:{initialPrompt:i}})),r(e=>({...e,[t.id]:"running"})),o&&o>0&&h.current.set(t.id,{maxRetries:o,attempt:0,testPlan:i}),0===n&&b(t.id),e})},100)});return()=>null==a?void 0:a()},[]),(0,i.useEffect)(()=>{var e,t;let n=null===(t=window.bangonit)||void 0===t?void 0:null===(e=t.onFocusAgent)||void 0===e?void 0:e.call(t,e=>{b(e.agentId)});return()=>null==n?void 0:n()},[]),!s)return(0,a.jsx)("div",{className:"flex h-screen bg-zinc-950"});e.some(e=>o[e.id]);let S=e.find(e=>e.id===p),R=!!p&&!!o[p];return(0,a.jsxs)("div",{className:"flex h-screen bg-zinc-950 overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex flex-col bg-zinc-900 border-r border-zinc-800 shrink-0 w-48 overflow-y-auto",children:[(0,a.jsxs)("div",{className:"flex items-center px-3 py-2 border-b border-zinc-800",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-zinc-500 uppercase tracking-wider",children:"Tests"}),(0,a.jsx)("div",{className:"flex-1"}),(0,a.jsx)("button",{onClick:E,className:"text-zinc-500 hover:text-zinc-300 transition-colors text-lg leading-none",title:"Add test",children:"+"})]}),e.map(e=>{let t=n[e.id];return o[e.id],(0,a.jsx)("button",{onClick:()=>b(e.id),className:"px-3 py-2 text-xs text-left border-b border-zinc-800 transition-colors\n ".concat(e.id===p?"bg-zinc-800 text-zinc-200":"text-zinc-500 hover:text-zinc-300"),children:(0,a.jsxs)("span",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"inline-block w-2 h-2 rounded-full shrink-0 ".concat("running"===t?"bg-blue-500 animate-pulse":"completed"===t?"bg-green-500":"failed"===t?"bg-red-500":"bg-zinc-600")}),(0,a.jsx)("span",{className:"truncate",children:e.name})]})},e.id)})]}),(0,a.jsxs)("div",{className:"flex-1 min-w-0 h-full relative",children:[e.map(e=>o[e.id]?(0,a.jsx)("div",{className:"absolute inset-0 z-0",style:{display:"flex",zIndex:e.id===p?1:0,pointerEvents:e.id===p?"auto":"none"},children:(0,a.jsx)(z,{agentId:e.id,agentName:e.name,initialPrompt:o[e.id].initialPrompt,initialMessages:o[e.id].initialMessages,initialTabs:o[e.id].initialTabs,initialActiveTabId:o[e.id].initialActiveTabId,initialTodos:o[e.id].initialTodos,onStatusChange:C,onRerun:()=>I(e.id),record:m,sessionRecorder:v.current||void 0,onRegisterRecorder:k})},"".concat(e.id,"-").concat(u[e.id]||0)):null),S&&!R&&!g&&(0,a.jsx)(U,{agentId:S.id,agentName:S.name,onSubmit:j})]})]})}function U(e){let{agentId:t,agentName:n,onSubmit:r}=e,[o,l]=(0,i.useState)(""),s=(0,i.useRef)(null);(0,i.useEffect)(()=>{var e;null===(e=s.current)||void 0===e||e.focus()},[t]);let c=()=>{let e=o.trim();e&&r(t,e)};return(0,a.jsx)("div",{className:"absolute inset-0 flex items-center justify-center z-10 bg-zinc-950",children:(0,a.jsxs)("div",{className:"w-full max-w-xl px-6",children:[(0,a.jsx)("h2",{className:"text-lg font-medium text-zinc-200 mb-4",children:"What would you like to test?"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("textarea",{ref:s,value:o,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),c())},placeholder:"Describe what to test in plain English...",className:"w-full px-4 py-3 bg-zinc-800 border border-zinc-700 rounded-lg text-sm text-zinc-200 placeholder-zinc-500 resize-none focus:outline-none focus:border-zinc-500 transition-colors",rows:4}),(0,a.jsx)("button",{onClick:c,disabled:!o.trim(),className:"absolute bottom-3 right-3 px-3 py-1.5 bg-blue-600 hover:bg-blue-500 disabled:bg-zinc-700 disabled:text-zinc-500 text-white text-xs font-medium rounded transition-colors",children:"Run"})]}),(0,a.jsx)("p",{className:"text-xs text-zinc-600 mt-2",children:"Press Enter to run. Shift+Enter for a new line."}),(0,a.jsxs)("div",{className:"mt-4",children:[(0,a.jsx)("p",{className:"text-xs text-zinc-600 mb-2",children:"Examples:"}),(0,a.jsx)("div",{className:"flex flex-col gap-1.5",children:["Go to example.com and verify the homepage loads with a heading","Navigate to my-app.com/login, sign in with test@example.com / password123, and verify the dashboard loads","Go to localhost:3000, add an item to the cart, proceed to checkout, and verify the order summary"].map((e,t)=>(0,a.jsx)("button",{onClick:()=>l(e),className:"text-left text-xs text-zinc-500 hover:text-zinc-300 bg-zinc-900 hover:bg-zinc-800 px-3 py-2 rounded border border-zinc-800 transition-colors",children:e},t))})]})]})})}function L(){return(0,a.jsx)(O,{})}}},function(e){e.O(0,[46,631,293,528,744],function(){return e(e.s=6421)}),_N_E=e.O()}]);
|