@deadragdoll/tellymcp 0.0.11 → 0.0.13
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-ru.md +48 -0
- package/README.md +47 -0
- package/TOOLS.md +232 -3
- package/VERSION.md +2 -2
- package/dist/cli.js +109 -1
- package/dist/services/features/telegram-mcp/browser.service.js +38 -1
- package/dist/services/features/telegram-mcp/gateway-socket.service.js +10 -0
- package/dist/services/features/telegram-mcp/mcp-server.service.js +12 -0
- package/dist/services/features/telegram-mcp/src/app/bootstrap/runtime.js +14 -0
- package/dist/services/features/telegram-mcp/src/app/config/env.js +13 -0
- package/dist/services/features/telegram-mcp/src/entities/request/model/schema.js +151 -2
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserClickTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserDomTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserFillTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserInjectScriptTool.js +28 -0
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserListAttachedInstancesTool.js +33 -0
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserListTabsTool.js +33 -0
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserOpenTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserPressTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserRecordingStartTool.js +28 -0
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserRecordingStatusTool.js +28 -0
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserRecordingStopTool.js +28 -0
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserScreenshotTool.js +1 -1
- package/dist/services/features/telegram-mcp/src/features/browser/model/browserService.js +543 -9
- package/dist/services/features/telegram-mcp/src/features/browser-attach/model/browserRecordingBundle.js +502 -0
- package/dist/services/features/telegram-mcp/src/features/browser-attach/model/firefoxAttachRegistry.js +79 -0
- package/dist/services/features/telegram-mcp/src/features/browser-attach/model/firefoxAttachServer.js +559 -0
- package/dist/services/features/telegram-mcp/src/features/browser-attach/model/types.js +2 -0
- package/dist/services/features/telegram-mcp/src/features/distributed-gateway/model/gatewayHttpService.js +48 -0
- package/dist/services/features/telegram-mcp/src/shared/i18n/resources/en.js +5 -1
- package/dist/services/features/telegram-mcp/src/shared/i18n/resources/ru.js +5 -1
- package/dist/services/features/telegram-mcp/src/shared/integrations/redis/stateStore.js +56 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transport.js +37 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportConsoleRegistry.js +13 -7
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportConstructorWiring.js +9 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportMenuShell.js +3 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportPayloadState.js +7 -0
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTerminalActions.js +231 -34
- package/dist/services/features/telegram-mcp/src/shared/integrations/telegram/transportTerminalRuntime.js +61 -6
- package/dist/services/features/telegram-mcp/src/shared/lib/terminalPromptDetection.js +200 -28
- package/docs/STANDALONE-ru.md +42 -6
- package/docs/STANDALONE.md +42 -6
- package/package.json +6 -3
- package/packages/chrome-attach-extension/dist/background.js +1326 -0
- package/packages/chrome-attach-extension/dist/icon.svg +6 -0
- package/packages/chrome-attach-extension/dist/manifest.json +36 -0
- package/packages/chrome-attach-extension/dist/options.html +312 -0
- package/packages/chrome-attach-extension/dist/options.js +593 -0
- package/packages/chrome-attach-extension/dist/popup.html +93 -0
- package/packages/chrome-attach-extension/dist/popup.js +79 -0
- package/packages/chrome-attach-extension/dist/recorder-content.js +83 -0
- package/packages/chrome-attach-extension/dist/recorder-page.js +266 -0
- package/packages/firefox-attach-extension/README.md +13 -0
- package/packages/firefox-attach-extension/dist/background.js +1242 -0
- package/packages/firefox-attach-extension/dist/icon.svg +6 -0
- package/packages/firefox-attach-extension/dist/manifest.json +56 -0
- package/packages/firefox-attach-extension/dist/options.html +312 -0
- package/packages/firefox-attach-extension/dist/options.js +527 -0
- package/packages/firefox-attach-extension/dist/popup.html +93 -0
- package/packages/firefox-attach-extension/dist/popup.js +64 -0
- package/packages/firefox-attach-extension/dist/recorder-content.js +77 -0
- package/packages/firefox-attach-extension/dist/recorder-page.js +302 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BrowserRecordingBundleWriter = void 0;
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const client_1 = require("../../../shared/integrations/terminal/client");
|
|
10
|
+
function sanitizeSegment(value) {
|
|
11
|
+
const normalized = value
|
|
12
|
+
.normalize("NFKD")
|
|
13
|
+
.replace(/[\u0300-\u036f]/gu, "")
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.replace(/[^a-z0-9]+/gu, "-")
|
|
16
|
+
.replace(/^-+/u, "")
|
|
17
|
+
.replace(/-+$/u, "");
|
|
18
|
+
return normalized || "recording";
|
|
19
|
+
}
|
|
20
|
+
function formatTimestampForDir(date) {
|
|
21
|
+
return date.toISOString().replace(/[:.]/gu, "-");
|
|
22
|
+
}
|
|
23
|
+
function formatJsonLine(value) {
|
|
24
|
+
return Buffer.from(`${JSON.stringify(value)}\n`, "utf8");
|
|
25
|
+
}
|
|
26
|
+
function sanitizeRequestId(value) {
|
|
27
|
+
return value
|
|
28
|
+
.trim()
|
|
29
|
+
.replace(/[^a-zA-Z0-9._-]+/gu, "-")
|
|
30
|
+
.replace(/^-+/u, "")
|
|
31
|
+
.replace(/-+$/u, "") || "request";
|
|
32
|
+
}
|
|
33
|
+
function detectMimeTypeFromHeaders(headers) {
|
|
34
|
+
const match = headers?.find((header) => header.name.trim().toLowerCase() === "content-type");
|
|
35
|
+
const value = match?.value?.trim();
|
|
36
|
+
return value || undefined;
|
|
37
|
+
}
|
|
38
|
+
async function allocateBundleDirName(config, session, tabTitle) {
|
|
39
|
+
const exchangeRoot = await (0, client_1.ensureXchangeDir)(config.terminal, session.cwd || "", config.exchange.dir);
|
|
40
|
+
const webRoot = node_path_1.default.resolve(exchangeRoot, "web");
|
|
41
|
+
await (0, promises_1.mkdir)(webRoot, { recursive: true });
|
|
42
|
+
const baseName = `${sanitizeSegment(tabTitle)}-${formatTimestampForDir(new Date())}`;
|
|
43
|
+
let attempt = 1;
|
|
44
|
+
while (attempt < 1000) {
|
|
45
|
+
const candidate = attempt === 1 ? baseName : `${baseName}-${attempt}`;
|
|
46
|
+
const candidatePath = node_path_1.default.resolve(webRoot, candidate);
|
|
47
|
+
try {
|
|
48
|
+
await (0, promises_1.mkdir)(candidatePath);
|
|
49
|
+
return candidate;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error &&
|
|
53
|
+
typeof error === "object" &&
|
|
54
|
+
"code" in error &&
|
|
55
|
+
error.code === "EEXIST") {
|
|
56
|
+
attempt += 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
throw new Error("Could not allocate a unique browser recording bundle directory.");
|
|
63
|
+
}
|
|
64
|
+
class BrowserRecordingBundleWriter {
|
|
65
|
+
config;
|
|
66
|
+
logger;
|
|
67
|
+
constructor(config, logger) {
|
|
68
|
+
this.config = config;
|
|
69
|
+
this.logger = logger;
|
|
70
|
+
}
|
|
71
|
+
async create(input) {
|
|
72
|
+
if (!input.session.cwd?.trim()) {
|
|
73
|
+
throw new Error("Workspace cwd is not registered for this console.");
|
|
74
|
+
}
|
|
75
|
+
const bundleDirName = await allocateBundleDirName(this.config, input.session, input.tabTitle);
|
|
76
|
+
const bundleRelativePath = `web/${bundleDirName}`;
|
|
77
|
+
const exchangeRoot = await (0, client_1.ensureXchangeDir)(this.config.terminal, input.session.cwd, this.config.exchange.dir);
|
|
78
|
+
const bundlePath = node_path_1.default.resolve(exchangeRoot, bundleRelativePath);
|
|
79
|
+
for (const segment of [
|
|
80
|
+
bundleRelativePath,
|
|
81
|
+
`${bundleRelativePath}/pages`,
|
|
82
|
+
`${bundleRelativePath}/network`,
|
|
83
|
+
`${bundleRelativePath}/network/requests`,
|
|
84
|
+
`${bundleRelativePath}/console`,
|
|
85
|
+
]) {
|
|
86
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, input.session.cwd, this.config.exchange.dir, `${segment}/.keep`, Buffer.from("", "utf8"));
|
|
87
|
+
}
|
|
88
|
+
const startedAt = new Date().toISOString();
|
|
89
|
+
const record = {
|
|
90
|
+
sessionId: input.sessionId,
|
|
91
|
+
backend: "firefox-attached",
|
|
92
|
+
recordingId: input.recordingId,
|
|
93
|
+
instanceId: input.instanceId,
|
|
94
|
+
tabId: input.tabId,
|
|
95
|
+
...(input.tabTitle ? { tabTitle: input.tabTitle } : {}),
|
|
96
|
+
...(input.tabUrl ? { tabUrl: input.tabUrl } : {}),
|
|
97
|
+
bundleDirName,
|
|
98
|
+
bundleRelativePath,
|
|
99
|
+
bundlePath,
|
|
100
|
+
startedAt,
|
|
101
|
+
status: "recording",
|
|
102
|
+
eventCount: 0,
|
|
103
|
+
};
|
|
104
|
+
const sessionJson = {
|
|
105
|
+
recording_id: record.recordingId,
|
|
106
|
+
backend: record.backend,
|
|
107
|
+
session_id: record.sessionId,
|
|
108
|
+
session_label: input.session.label || input.session.sessionId,
|
|
109
|
+
instance_id: record.instanceId,
|
|
110
|
+
tab_id: record.tabId,
|
|
111
|
+
...(record.tabTitle ? { tab_title: record.tabTitle } : {}),
|
|
112
|
+
...(record.tabUrl ? { tab_url: record.tabUrl } : {}),
|
|
113
|
+
started_at: record.startedAt,
|
|
114
|
+
status: record.status,
|
|
115
|
+
bundle_dir_name: record.bundleDirName,
|
|
116
|
+
bundle_relative_path: record.bundleRelativePath,
|
|
117
|
+
bundle_path: record.bundlePath,
|
|
118
|
+
workspace_dir: input.session.cwd,
|
|
119
|
+
exchange_dir: node_path_1.default.resolve(input.session.cwd, this.config.exchange.dir),
|
|
120
|
+
files: {
|
|
121
|
+
timeline: "timeline.ndjson",
|
|
122
|
+
session: "session.json",
|
|
123
|
+
pages: "pages",
|
|
124
|
+
network: "network",
|
|
125
|
+
network_index: "network/index.ndjson",
|
|
126
|
+
network_requests: "network/requests",
|
|
127
|
+
console: "console",
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, input.session.cwd, this.config.exchange.dir, `${bundleRelativePath}/session.json`, Buffer.from(`${JSON.stringify(sessionJson, null, 2)}\n`, "utf8"));
|
|
131
|
+
const state = {
|
|
132
|
+
record,
|
|
133
|
+
session: input.session,
|
|
134
|
+
pageCounter: 0,
|
|
135
|
+
snapshotCounter: 0,
|
|
136
|
+
requestCounter: 0,
|
|
137
|
+
requestArtifacts: new Map(),
|
|
138
|
+
};
|
|
139
|
+
await this.appendEvent(state, {
|
|
140
|
+
kind: "session_started",
|
|
141
|
+
status: "recording",
|
|
142
|
+
});
|
|
143
|
+
this.logger.info("Browser recording bundle created", {
|
|
144
|
+
sessionId: input.sessionId,
|
|
145
|
+
recordingId: input.recordingId,
|
|
146
|
+
bundlePath,
|
|
147
|
+
tabId: input.tabId,
|
|
148
|
+
tabTitle: input.tabTitle,
|
|
149
|
+
});
|
|
150
|
+
return state;
|
|
151
|
+
}
|
|
152
|
+
async appendEvent(state, event) {
|
|
153
|
+
const at = event.at?.trim() || new Date().toISOString();
|
|
154
|
+
state.record.eventCount += 1;
|
|
155
|
+
state.record.lastEventAt = at;
|
|
156
|
+
let relPath;
|
|
157
|
+
let pageId = state.currentPageId;
|
|
158
|
+
if (event.kind === "page_snapshot") {
|
|
159
|
+
const targetUrl = event.url?.trim() || state.currentPageUrl || "";
|
|
160
|
+
if (!pageId || (targetUrl && targetUrl !== state.currentPageUrl)) {
|
|
161
|
+
state.pageCounter += 1;
|
|
162
|
+
pageId = `page-${String(state.pageCounter).padStart(3, "0")}`;
|
|
163
|
+
state.currentPageId = pageId;
|
|
164
|
+
state.currentPageUrl = targetUrl || state.currentPageUrl;
|
|
165
|
+
}
|
|
166
|
+
state.snapshotCounter += 1;
|
|
167
|
+
relPath = `${state.record.bundleRelativePath}/pages/${pageId}/snapshot-${String(state.snapshotCounter).padStart(4, "0")}.html`;
|
|
168
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, relPath, Buffer.from(String(event.html || ""), "utf8"));
|
|
169
|
+
await this.appendJsonLine(state, `${state.record.bundleRelativePath}/pages/events.ndjson`, {
|
|
170
|
+
at,
|
|
171
|
+
page_id: pageId,
|
|
172
|
+
reason: event.reason || "snapshot",
|
|
173
|
+
url: event.url || state.currentPageUrl || "",
|
|
174
|
+
title: event.title || state.record.tabTitle || "",
|
|
175
|
+
ready_state: event.ready_state || "",
|
|
176
|
+
html_rel_path: relPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if (event.kind === "console_event") {
|
|
180
|
+
await this.appendJsonLine(state, `${state.record.bundleRelativePath}/console/events.ndjson`, {
|
|
181
|
+
at,
|
|
182
|
+
level: event.level || "log",
|
|
183
|
+
text: event.text || "",
|
|
184
|
+
args: event.args || [],
|
|
185
|
+
url: event.url || state.currentPageUrl || "",
|
|
186
|
+
title: event.title || state.record.tabTitle || "",
|
|
187
|
+
page_id: state.currentPageId,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
else if (event.kind.startsWith("network_") ||
|
|
191
|
+
event.kind === "cookies_snapshot") {
|
|
192
|
+
const networkEvent = await this.materializeNetworkBodyArtifact(state, event);
|
|
193
|
+
const requestArtifact = await this.upsertNetworkRequestArtifact(state, networkEvent);
|
|
194
|
+
await this.appendJsonLine(state, `${state.record.bundleRelativePath}/network/index.ndjson`, {
|
|
195
|
+
at,
|
|
196
|
+
page_id: state.currentPageId,
|
|
197
|
+
request_id: networkEvent.request_id,
|
|
198
|
+
kind: networkEvent.kind,
|
|
199
|
+
method: networkEvent.method,
|
|
200
|
+
url: networkEvent.url,
|
|
201
|
+
resource_type: networkEvent.resource_type,
|
|
202
|
+
status_code: networkEvent.status_code,
|
|
203
|
+
summary: this.buildSummary(networkEvent),
|
|
204
|
+
...(requestArtifact
|
|
205
|
+
? {
|
|
206
|
+
seq: requestArtifact.seq,
|
|
207
|
+
request_bundle_rel_path: requestArtifact.requestDirRelPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
208
|
+
meta_rel_path: requestArtifact.metaFileRelPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
209
|
+
request_rel_path: requestArtifact.requestFileRelPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
210
|
+
response_rel_path: requestArtifact.responseFileRelPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
211
|
+
...(this.extractBodyRelPath(requestArtifact)
|
|
212
|
+
? {
|
|
213
|
+
body_rel_path: this.extractBodyRelPath(requestArtifact),
|
|
214
|
+
}
|
|
215
|
+
: {}),
|
|
216
|
+
}
|
|
217
|
+
: {}),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (event.kind === "navigation") {
|
|
221
|
+
const nextUrl = event.url?.trim() || "";
|
|
222
|
+
if (nextUrl && nextUrl !== state.currentPageUrl) {
|
|
223
|
+
state.currentPageUrl = nextUrl;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (event.kind === "session_stopped") {
|
|
227
|
+
state.record.status = "stopped";
|
|
228
|
+
state.record.stoppedAt = at;
|
|
229
|
+
}
|
|
230
|
+
const eventRecord = event;
|
|
231
|
+
const requestId = typeof eventRecord.request_id === "string" ? eventRecord.request_id : "";
|
|
232
|
+
const eventUrl = typeof eventRecord.url === "string" ? eventRecord.url : "";
|
|
233
|
+
const eventTitle = typeof eventRecord.title === "string" ? eventRecord.title : "";
|
|
234
|
+
const timelineEntry = {
|
|
235
|
+
at,
|
|
236
|
+
kind: event.kind,
|
|
237
|
+
...(state.currentPageId ? { page_id: state.currentPageId } : {}),
|
|
238
|
+
...(relPath
|
|
239
|
+
? {
|
|
240
|
+
rel_path: relPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
241
|
+
}
|
|
242
|
+
: {}),
|
|
243
|
+
...(requestId.trim()
|
|
244
|
+
? { request_id: requestId.trim() }
|
|
245
|
+
: {}),
|
|
246
|
+
...(eventUrl.trim()
|
|
247
|
+
? { url: eventUrl.trim() }
|
|
248
|
+
: {}),
|
|
249
|
+
...(eventTitle.trim()
|
|
250
|
+
? { title: eventTitle.trim() }
|
|
251
|
+
: {}),
|
|
252
|
+
summary: this.buildSummary(event),
|
|
253
|
+
};
|
|
254
|
+
await this.appendJsonLine(state, `${state.record.bundleRelativePath}/timeline.ndjson`, timelineEntry);
|
|
255
|
+
await this.writeSessionJson(state);
|
|
256
|
+
return state;
|
|
257
|
+
}
|
|
258
|
+
async appendJsonLine(state, relativePath, value) {
|
|
259
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, relativePath, formatJsonLine(value), { append: true });
|
|
260
|
+
}
|
|
261
|
+
async materializeNetworkBodyArtifact(state, event) {
|
|
262
|
+
const mimeType = detectMimeTypeFromHeaders(event.headers);
|
|
263
|
+
return {
|
|
264
|
+
...event,
|
|
265
|
+
...(mimeType ? { body_mime_type: mimeType } : {}),
|
|
266
|
+
...(typeof event.body_text === "string" ? { body_encoding: "utf8" } : {}),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
async upsertNetworkRequestArtifact(state, event) {
|
|
270
|
+
const requestId = typeof event.request_id === "string" && event.request_id.trim()
|
|
271
|
+
? event.request_id.trim()
|
|
272
|
+
: "";
|
|
273
|
+
if (!requestId) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
let artifact = state.requestArtifacts.get(requestId);
|
|
277
|
+
if (!artifact) {
|
|
278
|
+
state.requestCounter += 1;
|
|
279
|
+
const requestDirRelPath = `${state.record.bundleRelativePath}/network/requests/${String(state.requestCounter).padStart(6, "0")}-${sanitizeRequestId(requestId)}`;
|
|
280
|
+
artifact = {
|
|
281
|
+
seq: state.requestCounter,
|
|
282
|
+
requestId,
|
|
283
|
+
requestDirRelPath,
|
|
284
|
+
metaFileRelPath: `${requestDirRelPath}/meta.json`,
|
|
285
|
+
requestFileRelPath: `${requestDirRelPath}/request.json`,
|
|
286
|
+
responseFileRelPath: `${requestDirRelPath}/response.json`,
|
|
287
|
+
request: {
|
|
288
|
+
request_id: requestId,
|
|
289
|
+
},
|
|
290
|
+
response: {
|
|
291
|
+
request_id: requestId,
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
state.requestArtifacts.set(requestId, artifact);
|
|
295
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, `${requestDirRelPath}/.keep`, Buffer.from("", "utf8"));
|
|
296
|
+
}
|
|
297
|
+
const kind = typeof event.kind === "string" ? event.kind : "";
|
|
298
|
+
const artifactEvent = { ...event };
|
|
299
|
+
delete artifactEvent.body_base64;
|
|
300
|
+
delete artifactEvent.body_text;
|
|
301
|
+
delete artifactEvent.body_file_rel_path;
|
|
302
|
+
delete artifactEvent.body_mime_type;
|
|
303
|
+
delete artifactEvent.body_encoding;
|
|
304
|
+
if (kind === "network_request" || kind === "network_request_headers") {
|
|
305
|
+
artifact.request = {
|
|
306
|
+
...artifact.request,
|
|
307
|
+
...artifactEvent,
|
|
308
|
+
seq: artifact.seq,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
artifact.response = {
|
|
313
|
+
...artifact.response,
|
|
314
|
+
...artifactEvent,
|
|
315
|
+
seq: artifact.seq,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, artifact.requestFileRelPath, Buffer.from(`${JSON.stringify(artifact.request, null, 2)}\n`, "utf8"));
|
|
319
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, artifact.responseFileRelPath, Buffer.from(`${JSON.stringify(artifact.response, null, 2)}\n`, "utf8"));
|
|
320
|
+
await this.writeRequestArtifactMeta(state, artifact);
|
|
321
|
+
await this.materializeRequestBodyArtifact(state, artifact, event, kind);
|
|
322
|
+
return artifact;
|
|
323
|
+
}
|
|
324
|
+
async materializeRequestBodyArtifact(state, artifact, event, kind) {
|
|
325
|
+
const bodyBase64 = typeof event.body_base64 === "string" && event.body_base64.trim()
|
|
326
|
+
? event.body_base64.trim()
|
|
327
|
+
: "";
|
|
328
|
+
const bodyText = typeof event.body_text === "string" ? event.body_text : "";
|
|
329
|
+
const bodyMimeType = typeof event.body_mime_type === "string" && event.body_mime_type.trim()
|
|
330
|
+
? event.body_mime_type.trim()
|
|
331
|
+
: undefined;
|
|
332
|
+
let bodyFileRelPath;
|
|
333
|
+
let bodyEncoding;
|
|
334
|
+
if (bodyBase64) {
|
|
335
|
+
bodyFileRelPath = `${artifact.requestDirRelPath}/${kind}-body.bin`;
|
|
336
|
+
bodyEncoding = "base64";
|
|
337
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, bodyFileRelPath, Buffer.from(bodyBase64, "base64"));
|
|
338
|
+
}
|
|
339
|
+
else if (bodyText.length > 16384) {
|
|
340
|
+
bodyFileRelPath = `${artifact.requestDirRelPath}/${kind}-body.txt`;
|
|
341
|
+
bodyEncoding = "utf8";
|
|
342
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, bodyFileRelPath, Buffer.from(bodyText, "utf8"));
|
|
343
|
+
}
|
|
344
|
+
if (kind === "network_request" || kind === "network_request_headers") {
|
|
345
|
+
artifact.request = {
|
|
346
|
+
...artifact.request,
|
|
347
|
+
...(bodyMimeType ? { body_mime_type: bodyMimeType } : {}),
|
|
348
|
+
...(bodyEncoding ? { body_encoding: bodyEncoding } : {}),
|
|
349
|
+
...(bodyFileRelPath
|
|
350
|
+
? {
|
|
351
|
+
body_file_rel_path: bodyFileRelPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
352
|
+
}
|
|
353
|
+
: {}),
|
|
354
|
+
...(!bodyFileRelPath && bodyText ? { body_text: bodyText } : {}),
|
|
355
|
+
...(bodyFileRelPath && bodyText
|
|
356
|
+
? {
|
|
357
|
+
body_text_preview: bodyText.slice(0, 4096),
|
|
358
|
+
}
|
|
359
|
+
: {}),
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
artifact.response = {
|
|
364
|
+
...artifact.response,
|
|
365
|
+
...(bodyMimeType ? { body_mime_type: bodyMimeType } : {}),
|
|
366
|
+
...(bodyEncoding ? { body_encoding: bodyEncoding } : {}),
|
|
367
|
+
...(bodyFileRelPath
|
|
368
|
+
? {
|
|
369
|
+
body_file_rel_path: bodyFileRelPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
370
|
+
}
|
|
371
|
+
: {}),
|
|
372
|
+
...(!bodyFileRelPath && bodyText ? { body_text: bodyText } : {}),
|
|
373
|
+
...(bodyFileRelPath && bodyText
|
|
374
|
+
? {
|
|
375
|
+
body_text_preview: bodyText.slice(0, 4096),
|
|
376
|
+
}
|
|
377
|
+
: {}),
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, artifact.requestFileRelPath, Buffer.from(`${JSON.stringify(artifact.request, null, 2)}\n`, "utf8"));
|
|
381
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, artifact.responseFileRelPath, Buffer.from(`${JSON.stringify(artifact.response, null, 2)}\n`, "utf8"));
|
|
382
|
+
await this.writeRequestArtifactMeta(state, artifact);
|
|
383
|
+
}
|
|
384
|
+
extractBodyRelPath(artifact) {
|
|
385
|
+
const responseBody = typeof artifact.response.body_file_rel_path === "string"
|
|
386
|
+
? artifact.response.body_file_rel_path
|
|
387
|
+
: "";
|
|
388
|
+
if (responseBody.trim()) {
|
|
389
|
+
return responseBody.trim();
|
|
390
|
+
}
|
|
391
|
+
const requestBody = typeof artifact.request.body_file_rel_path === "string"
|
|
392
|
+
? artifact.request.body_file_rel_path
|
|
393
|
+
: "";
|
|
394
|
+
return requestBody.trim() || undefined;
|
|
395
|
+
}
|
|
396
|
+
async writeRequestArtifactMeta(state, artifact) {
|
|
397
|
+
const requestAt = typeof artifact.request.at === "string" && artifact.request.at.trim()
|
|
398
|
+
? artifact.request.at.trim()
|
|
399
|
+
: undefined;
|
|
400
|
+
const responseAt = typeof artifact.response.at === "string" && artifact.response.at.trim()
|
|
401
|
+
? artifact.response.at.trim()
|
|
402
|
+
: undefined;
|
|
403
|
+
const method = typeof artifact.request.method === "string" && artifact.request.method.trim()
|
|
404
|
+
? artifact.request.method.trim()
|
|
405
|
+
: undefined;
|
|
406
|
+
const url = typeof artifact.request.url === "string" && artifact.request.url.trim()
|
|
407
|
+
? artifact.request.url.trim()
|
|
408
|
+
: typeof artifact.response.url === "string" && artifact.response.url.trim()
|
|
409
|
+
? artifact.response.url.trim()
|
|
410
|
+
: undefined;
|
|
411
|
+
const resourceType = typeof artifact.request.resource_type === "string" &&
|
|
412
|
+
artifact.request.resource_type.trim()
|
|
413
|
+
? artifact.request.resource_type.trim()
|
|
414
|
+
: typeof artifact.response.resource_type === "string" &&
|
|
415
|
+
artifact.response.resource_type.trim()
|
|
416
|
+
? artifact.response.resource_type.trim()
|
|
417
|
+
: undefined;
|
|
418
|
+
const statusCode = typeof artifact.response.status_code === "number"
|
|
419
|
+
? artifact.response.status_code
|
|
420
|
+
: undefined;
|
|
421
|
+
const requestBodyRelPath = typeof artifact.request.body_file_rel_path === "string" &&
|
|
422
|
+
artifact.request.body_file_rel_path.trim()
|
|
423
|
+
? artifact.request.body_file_rel_path.trim()
|
|
424
|
+
: undefined;
|
|
425
|
+
const responseBodyRelPath = typeof artifact.response.body_file_rel_path === "string" &&
|
|
426
|
+
artifact.response.body_file_rel_path.trim()
|
|
427
|
+
? artifact.response.body_file_rel_path.trim()
|
|
428
|
+
: undefined;
|
|
429
|
+
const meta = {
|
|
430
|
+
seq: artifact.seq,
|
|
431
|
+
request_id: artifact.requestId,
|
|
432
|
+
...(requestAt ? { request_at: requestAt } : {}),
|
|
433
|
+
...(responseAt ? { response_at: responseAt } : {}),
|
|
434
|
+
...(method ? { method } : {}),
|
|
435
|
+
...(url ? { url } : {}),
|
|
436
|
+
...(resourceType ? { resource_type: resourceType } : {}),
|
|
437
|
+
...(typeof statusCode === "number" ? { status_code: statusCode } : {}),
|
|
438
|
+
request_rel_path: artifact.requestFileRelPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
439
|
+
response_rel_path: artifact.responseFileRelPath.replace(`${state.record.bundleRelativePath}/`, ""),
|
|
440
|
+
...(requestBodyRelPath ? { request_body_rel_path: requestBodyRelPath } : {}),
|
|
441
|
+
...(responseBodyRelPath ? { response_body_rel_path: responseBodyRelPath } : {}),
|
|
442
|
+
};
|
|
443
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, artifact.metaFileRelPath, Buffer.from(`${JSON.stringify(meta, null, 2)}\n`, "utf8"));
|
|
444
|
+
}
|
|
445
|
+
async writeSessionJson(state) {
|
|
446
|
+
await (0, client_1.writeXchangeRelativeFile)(this.config.terminal, state.session.cwd || "", this.config.exchange.dir, `${state.record.bundleRelativePath}/session.json`, Buffer.from(`${JSON.stringify({
|
|
447
|
+
recording_id: state.record.recordingId,
|
|
448
|
+
backend: state.record.backend,
|
|
449
|
+
session_id: state.record.sessionId,
|
|
450
|
+
session_label: state.session.label || state.session.sessionId,
|
|
451
|
+
instance_id: state.record.instanceId,
|
|
452
|
+
tab_id: state.record.tabId,
|
|
453
|
+
...(state.record.tabTitle ? { tab_title: state.record.tabTitle } : {}),
|
|
454
|
+
...(state.record.tabUrl ? { tab_url: state.record.tabUrl } : {}),
|
|
455
|
+
started_at: state.record.startedAt,
|
|
456
|
+
...(state.record.stoppedAt
|
|
457
|
+
? { stopped_at: state.record.stoppedAt }
|
|
458
|
+
: {}),
|
|
459
|
+
status: state.record.status,
|
|
460
|
+
event_count: state.record.eventCount,
|
|
461
|
+
...(state.record.lastEventAt
|
|
462
|
+
? { last_event_at: state.record.lastEventAt }
|
|
463
|
+
: {}),
|
|
464
|
+
bundle_dir_name: state.record.bundleDirName,
|
|
465
|
+
bundle_relative_path: state.record.bundleRelativePath,
|
|
466
|
+
bundle_path: state.record.bundlePath,
|
|
467
|
+
current_page_id: state.currentPageId,
|
|
468
|
+
current_page_url: state.currentPageUrl,
|
|
469
|
+
files: {
|
|
470
|
+
timeline: "timeline.ndjson",
|
|
471
|
+
session: "session.json",
|
|
472
|
+
pages: "pages",
|
|
473
|
+
network: "network",
|
|
474
|
+
network_index: "network/index.ndjson",
|
|
475
|
+
network_requests: "network/requests",
|
|
476
|
+
console: "console",
|
|
477
|
+
},
|
|
478
|
+
}, null, 2)}\n`, "utf8"));
|
|
479
|
+
}
|
|
480
|
+
buildSummary(event) {
|
|
481
|
+
switch (event.kind) {
|
|
482
|
+
case "console_event":
|
|
483
|
+
return `${event.level || "log"} ${event.text || ""}`.trim();
|
|
484
|
+
case "page_snapshot":
|
|
485
|
+
return `${event.reason || "snapshot"} ${event.title || event.url || ""}`.trim();
|
|
486
|
+
case "network_request":
|
|
487
|
+
return `${event.method || "GET"} ${event.url || ""}`.trim();
|
|
488
|
+
case "network_response_complete":
|
|
489
|
+
return `${event.status_code || 0} ${event.url || ""}`.trim();
|
|
490
|
+
case "network_error":
|
|
491
|
+
return `${event.error || "error"} ${event.url || ""}`.trim();
|
|
492
|
+
case "navigation":
|
|
493
|
+
return `${event.status || "navigation"} ${event.url || ""}`.trim();
|
|
494
|
+
case "session_started":
|
|
495
|
+
case "session_stopped":
|
|
496
|
+
return event.kind;
|
|
497
|
+
default:
|
|
498
|
+
return event.kind;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
exports.BrowserRecordingBundleWriter = BrowserRecordingBundleWriter;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirefoxAttachRegistry = void 0;
|
|
4
|
+
class FirefoxAttachRegistry {
|
|
5
|
+
instances = new Map();
|
|
6
|
+
setConnected(input) {
|
|
7
|
+
const now = new Date().toISOString();
|
|
8
|
+
const existing = this.instances.get(input.instanceId);
|
|
9
|
+
const next = {
|
|
10
|
+
instanceId: input.instanceId,
|
|
11
|
+
browser: "firefox",
|
|
12
|
+
extensionVersion: input.extensionVersion,
|
|
13
|
+
...(input.profileName ? { profileName: input.profileName } : {}),
|
|
14
|
+
connectedAt: existing?.connectedAt ?? now,
|
|
15
|
+
lastSeenAt: now,
|
|
16
|
+
capabilities: [...input.capabilities],
|
|
17
|
+
tabs: existing?.tabs ?? [],
|
|
18
|
+
activeTab: existing?.activeTab ?? null,
|
|
19
|
+
};
|
|
20
|
+
this.instances.set(input.instanceId, next);
|
|
21
|
+
return next;
|
|
22
|
+
}
|
|
23
|
+
touch(instanceId) {
|
|
24
|
+
const existing = this.instances.get(instanceId);
|
|
25
|
+
if (!existing) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
existing.lastSeenAt = new Date().toISOString();
|
|
29
|
+
}
|
|
30
|
+
setTabs(instanceId, tabs) {
|
|
31
|
+
const existing = this.instances.get(instanceId);
|
|
32
|
+
if (!existing) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
existing.tabs = tabs.map((tab) => ({ ...tab }));
|
|
36
|
+
existing.activeTab =
|
|
37
|
+
tabs.find((tab) => tab.active) ?? existing.activeTab ?? null;
|
|
38
|
+
existing.lastSeenAt = new Date().toISOString();
|
|
39
|
+
}
|
|
40
|
+
setActiveTab(instanceId, tab) {
|
|
41
|
+
const existing = this.instances.get(instanceId);
|
|
42
|
+
if (!existing) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
existing.activeTab = tab ? { ...tab } : null;
|
|
46
|
+
existing.lastSeenAt = new Date().toISOString();
|
|
47
|
+
}
|
|
48
|
+
updateTab(instanceId, tab) {
|
|
49
|
+
const existing = this.instances.get(instanceId);
|
|
50
|
+
if (!existing) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const nextTabs = [...existing.tabs];
|
|
54
|
+
const index = nextTabs.findIndex((item) => item.tab_id === tab.tab_id);
|
|
55
|
+
if (index >= 0) {
|
|
56
|
+
nextTabs[index] = { ...nextTabs[index], ...tab };
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
nextTabs.push({ ...tab });
|
|
60
|
+
}
|
|
61
|
+
existing.tabs = nextTabs;
|
|
62
|
+
if (tab.active) {
|
|
63
|
+
existing.activeTab = { ...tab };
|
|
64
|
+
}
|
|
65
|
+
existing.lastSeenAt = new Date().toISOString();
|
|
66
|
+
}
|
|
67
|
+
remove(instanceId) {
|
|
68
|
+
this.instances.delete(instanceId);
|
|
69
|
+
}
|
|
70
|
+
listInstances() {
|
|
71
|
+
return Array.from(this.instances.values()).map((item) => ({
|
|
72
|
+
...item,
|
|
73
|
+
tabs: item.tabs.map((tab) => ({ ...tab })),
|
|
74
|
+
activeTab: item.activeTab ? { ...item.activeTab } : null,
|
|
75
|
+
capabilities: [...item.capabilities],
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.FirefoxAttachRegistry = FirefoxAttachRegistry;
|