@myrialabs/clopen 0.4.20 → 0.4.22
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 +2 -1
- package/backend/artifacts/generate.ts +11 -5
- package/backend/auth/permissions.ts +8 -8
- package/backend/bootstrap.ts +39 -0
- package/backend/chat/stream-manager.ts +15 -0
- package/backend/database/migrations/065_add_session_reasoning_effort.ts +28 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/session-queries.ts +10 -0
- package/backend/engine/README.md +11 -8
- package/backend/engine/adapters/claude/models.ts +46 -23
- package/backend/engine/adapters/claude/stream.ts +18 -4
- package/backend/engine/adapters/codex/error-handler.ts +1 -1
- package/backend/engine/adapters/codex/models.ts +19 -2
- package/backend/engine/adapters/codex/stream.ts +10 -3
- package/backend/engine/adapters/copilot/models.ts +20 -1
- package/backend/engine/adapters/copilot/stream.ts +11 -1
- package/backend/engine/adapters/cursor/models.ts +27 -3
- package/backend/engine/adapters/cursor/stream.ts +23 -3
- package/backend/engine/adapters/pi/models.ts +20 -2
- package/backend/engine/adapters/pi/stream.ts +6 -3
- package/backend/engine/adapters/qwen/error-handler.ts +1 -1
- package/backend/engine/bootstrap-default-engine.ts +18 -5
- package/backend/engine/docs/adapter-contract.md +66 -2
- package/backend/engine/docs/adding-an-engine.md +46 -7
- package/backend/engine/docs/frontend-and-chat.md +80 -17
- package/backend/engine/docs/lessons-learned.md +126 -7
- package/backend/engine/docs/quick-reference.md +12 -3
- package/backend/engine/docs/{system-tools.md → stack.md} +35 -6
- package/backend/engine/docs/websocket-routes.md +54 -15
- package/backend/engine/install-runner.ts +4 -4
- package/backend/engine/resolve-model.ts +87 -0
- package/backend/engine/structured-helpers.test.ts +64 -0
- package/backend/engine/structured-helpers.ts +105 -13
- package/backend/engine/types.ts +6 -0
- package/backend/index.ts +6 -9
- package/backend/mcp/README.md +32 -11
- package/backend/mcp/internal/config.ts +3 -20
- package/backend/mcp/internal/servers/browser-automation/actions/console.ts +65 -0
- package/backend/mcp/internal/servers/browser-automation/actions/dom-analyze.ts +202 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +31 -0
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +332 -0
- package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +158 -0
- package/backend/mcp/internal/servers/browser-automation/actions/navigation.ts +157 -0
- package/backend/mcp/internal/servers/browser-automation/actions/shared.ts +60 -0
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +146 -0
- package/backend/mcp/internal/servers/browser-automation/actions/types.ts +63 -0
- package/backend/mcp/internal/servers/browser-automation/context.ts +82 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +59 -0
- package/backend/mcp/internal/servers/browser-automation/format.ts +56 -0
- package/backend/mcp/internal/servers/browser-automation/index.ts +36 -784
- package/backend/mcp/internal/servers/browser-automation/paths.ts +71 -0
- package/backend/mcp/internal/servers/browser-automation/runner.ts +260 -0
- package/backend/mcp/internal/servers/browser-automation/schema.ts +26 -0
- package/backend/preview/browser/browser-console-manager.ts +310 -156
- package/backend/preview/browser/browser-dialog-handler.ts +45 -16
- package/backend/preview/browser/browser-host-bridge.ts +471 -0
- package/backend/preview/browser/browser-interaction-handler.ts +868 -297
- package/backend/preview/browser/browser-mcp-control.ts +7 -2
- package/backend/preview/browser/browser-native-ui-handler.ts +455 -81
- package/backend/preview/browser/browser-navigation-tracker.ts +56 -0
- package/backend/preview/browser/browser-pool.ts +83 -9
- package/backend/preview/browser/browser-preview-service.ts +432 -53
- package/backend/preview/browser/browser-tab-manager.ts +16 -16
- package/backend/preview/browser/browser-video-capture.ts +1334 -386
- package/backend/preview/browser/capture-profile.ts +213 -0
- package/backend/preview/browser/element-locator.ts +357 -0
- package/backend/preview/browser/frame-targeting.ts +92 -0
- package/backend/preview/browser/scripts/audio-stream.ts +258 -78
- package/backend/preview/browser/scripts/host-bridge.ts +1277 -0
- package/backend/preview/browser/scripts/video-stream.ts +803 -177
- package/backend/preview/browser/types.ts +397 -37
- package/backend/utils/cli.ts +1 -1
- package/backend/utils/path-enrich.ts +2 -2
- package/backend/ws/README.md +1 -1
- package/backend/ws/artifacts/generate.ts +2 -1
- package/backend/ws/chat/stream.ts +38 -2
- package/backend/ws/engine/codex/accounts.ts +1 -1
- package/backend/ws/engine/codex/status.ts +1 -1
- package/backend/ws/git/branch-name.ts +11 -5
- package/backend/ws/git/commit-message.ts +11 -5
- package/backend/ws/index.ts +3 -3
- package/backend/ws/preview/browser/host.ts +95 -0
- package/backend/ws/preview/browser/interact.ts +204 -10
- package/backend/ws/preview/browser/native-ui.ts +31 -1
- package/backend/ws/preview/browser/tab-info.ts +10 -1
- package/backend/ws/preview/browser/tab.ts +43 -0
- package/backend/ws/preview/browser/webcodecs.ts +180 -53
- package/backend/ws/preview/index.ts +58 -1
- package/backend/ws/{system-tools → stack}/access.ts +1 -1
- package/backend/ws/stack/index.ts +16 -0
- package/backend/ws/{system-tools → stack}/install.ts +7 -7
- package/backend/ws/{system-tools → stack}/status.ts +7 -7
- package/backend/ws/system/device-info.ts +290 -0
- package/backend/ws/system/index.ts +2 -0
- package/backend/ws/system/operations.ts +7 -0
- package/backend/ws/user/crud.ts +6 -3
- package/dist/assets/{index-BqBxKeAv.js → index-DH_GO0Lf.js} +1 -1
- package/dist/assets/{index-DdrcY5TE.js → index-igSQ3JaM.js} +1 -1
- package/dist/assets/main-BD3-qPfT.css +1 -0
- package/dist/assets/main-D-d8SFfW.js +616 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js +1 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/shared/constants/engines.ts +23 -0
- package/shared/types/database/schema.ts +1 -0
- package/shared/types/stores/settings.ts +12 -0
- package/shared/types/unified/engine.ts +33 -0
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +6 -0
- package/shared/types/unified/stream.ts +6 -0
- package/backend/mcp/internal/servers/browser-automation/actions.ts +0 -159
- package/backend/mcp/internal/servers/browser-automation/browser.ts +0 -375
- package/backend/mcp/internal/servers/browser-automation/inspection.ts +0 -495
- package/backend/ws/system-tools/index.ts +0 -16
- package/dist/assets/main-BBxAj17T.js +0 -582
- package/dist/assets/main-Cry3pLcl.css +0 -1
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Page Inspection Handlers
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { browserPreviewServiceManager, type BrowserPreviewService } from "$backend/preview";
|
|
6
|
-
import { projectContextService } from "$backend/mcp/internal/project-context";
|
|
7
|
-
import { getActiveTabSession } from "./browser";
|
|
8
|
-
import { debug } from "$shared/utils/logger";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get BrowserPreviewService for current MCP execution context
|
|
12
|
-
*/
|
|
13
|
-
function getPreviewService(projectId?: string): BrowserPreviewService {
|
|
14
|
-
// 1. Use explicit projectId if provided
|
|
15
|
-
if (projectId) {
|
|
16
|
-
debug.log('mcp', `Using explicit projectId: ${projectId}`);
|
|
17
|
-
return browserPreviewServiceManager.getService(projectId);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// 2. Try to get projectId from current execution context
|
|
21
|
-
const contextProjectId = projectContextService.getCurrentProjectId();
|
|
22
|
-
if (contextProjectId) {
|
|
23
|
-
debug.log('mcp', `Using projectId from context: ${contextProjectId}`);
|
|
24
|
-
return browserPreviewServiceManager.getService(contextProjectId);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 3. Fallback: Get first available project's service
|
|
28
|
-
const activeProjects = browserPreviewServiceManager.getActiveProjects();
|
|
29
|
-
if (activeProjects.length > 0) {
|
|
30
|
-
const fallbackProjectId = activeProjects[0];
|
|
31
|
-
debug.warn('mcp', `⚠️ No project context found, falling back to first active project: ${fallbackProjectId}`);
|
|
32
|
-
return browserPreviewServiceManager.getService(fallbackProjectId);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
throw new Error('No active browser preview service found. Project isolation requires projectId.');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function getConsoleLogsHandler(args: {
|
|
39
|
-
limit?: number;
|
|
40
|
-
projectId?: string;
|
|
41
|
-
}) {
|
|
42
|
-
try {
|
|
43
|
-
// Get active tab and session
|
|
44
|
-
const { tab } = await getActiveTabSession(args.projectId);
|
|
45
|
-
const sessionId = tab.id;
|
|
46
|
-
|
|
47
|
-
// Get preview service
|
|
48
|
-
const previewService = getPreviewService(args.projectId);
|
|
49
|
-
const logs = previewService.getConsoleLogs(sessionId);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (logs.length === 0) {
|
|
54
|
-
return {
|
|
55
|
-
content: [{
|
|
56
|
-
type: "text" as const,
|
|
57
|
-
text: "No console logs available."
|
|
58
|
-
}]
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const limit = Math.min(args.limit || 20, 100);
|
|
63
|
-
const limitedLogs = logs.slice(-limit);
|
|
64
|
-
const formattedLogs = limitedLogs.map((log: any) => {
|
|
65
|
-
const timestamp = new Date(log.timestamp).toLocaleTimeString();
|
|
66
|
-
const type = log.type.toUpperCase().padEnd(5);
|
|
67
|
-
return `[${timestamp}] ${type} ${log.text}`;
|
|
68
|
-
}).join('\n');
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
content: [{
|
|
72
|
-
type: "text" as const,
|
|
73
|
-
text: `Console Logs (${limitedLogs.length} of ${logs.length} total):\n\n${formattedLogs}`
|
|
74
|
-
}]
|
|
75
|
-
};
|
|
76
|
-
} catch (error) {
|
|
77
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
78
|
-
return {
|
|
79
|
-
content: [{
|
|
80
|
-
type: "text" as const,
|
|
81
|
-
text: `Failed to get console logs: ${errorMessage}`
|
|
82
|
-
}],
|
|
83
|
-
isError: true
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export async function clearConsoleLogsHandler(args: { projectId?: string } = {}) {
|
|
89
|
-
try {
|
|
90
|
-
// Get active tab and session
|
|
91
|
-
const { tab } = await getActiveTabSession(args.projectId);
|
|
92
|
-
const sessionId = tab.id;
|
|
93
|
-
|
|
94
|
-
// Get preview service
|
|
95
|
-
const previewService = getPreviewService(args.projectId);
|
|
96
|
-
const success = previewService.clearConsoleLogs(sessionId);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (!success) {
|
|
101
|
-
return {
|
|
102
|
-
content: [{
|
|
103
|
-
type: "text" as const,
|
|
104
|
-
text: `Failed to clear console logs.`
|
|
105
|
-
}],
|
|
106
|
-
isError: true
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
content: [{
|
|
112
|
-
type: "text" as const,
|
|
113
|
-
text: "Console logs cleared successfully."
|
|
114
|
-
}]
|
|
115
|
-
};
|
|
116
|
-
} catch (error) {
|
|
117
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
118
|
-
return {
|
|
119
|
-
content: [{
|
|
120
|
-
type: "text" as const,
|
|
121
|
-
text: `Failed to clear console logs: ${errorMessage}`
|
|
122
|
-
}],
|
|
123
|
-
isError: true
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export async function executeConsoleHandler(args: {
|
|
129
|
-
command: string;
|
|
130
|
-
projectId?: string;
|
|
131
|
-
}) {
|
|
132
|
-
try {
|
|
133
|
-
// Get active tab and session
|
|
134
|
-
const { tab } = await getActiveTabSession(args.projectId);
|
|
135
|
-
const sessionId = tab.id;
|
|
136
|
-
|
|
137
|
-
// Get preview service
|
|
138
|
-
const previewService = getPreviewService(args.projectId);
|
|
139
|
-
const result = await previewService.executeConsoleCommand(sessionId, args.command);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
content: [{
|
|
145
|
-
type: "text" as const,
|
|
146
|
-
text: `Execution successful.\n\nCommand: ${args.command}\n\nResult:\n${JSON.stringify(result, null, 2)}`
|
|
147
|
-
}]
|
|
148
|
-
};
|
|
149
|
-
} catch (error) {
|
|
150
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
151
|
-
return {
|
|
152
|
-
content: [{
|
|
153
|
-
type: "text" as const,
|
|
154
|
-
text: `Console execution failed: ${errorMessage}`
|
|
155
|
-
}],
|
|
156
|
-
isError: true
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export async function analyzeDomHandler(args: {
|
|
162
|
-
include?: ('navigation' | 'structure' | 'content' | 'forms' | 'summary')[];
|
|
163
|
-
} = {}) {
|
|
164
|
-
try {
|
|
165
|
-
// Get active tab and session
|
|
166
|
-
const { session } = await getActiveTabSession();
|
|
167
|
-
|
|
168
|
-
// Execute comprehensive DOM analysis
|
|
169
|
-
const analysis = await session.page.evaluate(() => {
|
|
170
|
-
// Helper: Get visible text with proper spacing
|
|
171
|
-
const getVisibleText = (el: Element, maxLength: number = 500): string => {
|
|
172
|
-
// Helper to check if element is block-level
|
|
173
|
-
const isBlockElement = (elem: Element): boolean => {
|
|
174
|
-
const style = window.getComputedStyle(elem);
|
|
175
|
-
return style.display === 'block' ||
|
|
176
|
-
style.display === 'flex' ||
|
|
177
|
-
style.display === 'grid' ||
|
|
178
|
-
style.display === 'list-item' ||
|
|
179
|
-
style.display === 'table';
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
// Helper to check if element is visible
|
|
183
|
-
const isVisible = (elem: Element): boolean => {
|
|
184
|
-
const style = window.getComputedStyle(elem);
|
|
185
|
-
if (style.display === 'none' || style.visibility === 'hidden') {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
const tagName = elem.tagName.toLowerCase();
|
|
189
|
-
return tagName !== 'script' && tagName !== 'style';
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// Recursively extract text with proper separators
|
|
193
|
-
const extractText = (node: Node): string[] => {
|
|
194
|
-
const parts: string[] = [];
|
|
195
|
-
|
|
196
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
197
|
-
const text = node.textContent?.trim();
|
|
198
|
-
if (text && text.length > 0) {
|
|
199
|
-
parts.push(text);
|
|
200
|
-
}
|
|
201
|
-
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
|
202
|
-
const elem = node as Element;
|
|
203
|
-
|
|
204
|
-
if (!isVisible(elem)) {
|
|
205
|
-
return parts;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const isBlock = isBlockElement(elem);
|
|
209
|
-
const childParts: string[] = [];
|
|
210
|
-
|
|
211
|
-
// Process all children
|
|
212
|
-
for (let i = 0; i < node.childNodes.length; i++) {
|
|
213
|
-
const childResults = extractText(node.childNodes[i]);
|
|
214
|
-
if (childResults.length > 0) {
|
|
215
|
-
childParts.push(...childResults);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (childParts.length > 0) {
|
|
220
|
-
// Join child parts and add to results
|
|
221
|
-
const joined = childParts.join(' ');
|
|
222
|
-
parts.push(joined);
|
|
223
|
-
|
|
224
|
-
// Add block separator marker if this is a block element
|
|
225
|
-
if (isBlock && node.nextSibling) {
|
|
226
|
-
parts.push('|BLOCK|');
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return parts;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
// Extract all text parts
|
|
235
|
-
const textParts = extractText(el);
|
|
236
|
-
|
|
237
|
-
// Join parts and handle block separators
|
|
238
|
-
let result = textParts.join(' ');
|
|
239
|
-
|
|
240
|
-
// Replace block separator markers with ' || '
|
|
241
|
-
result = result.replace(/\s*\|BLOCK\|\s*/g, ' || ');
|
|
242
|
-
|
|
243
|
-
// Normalize whitespace (collapse multiple spaces)
|
|
244
|
-
result = result.replace(/\s+/g, ' ').trim();
|
|
245
|
-
|
|
246
|
-
// Clean up any remaining separator artifacts
|
|
247
|
-
// result = result.replace(/\|\s+\|/g, '').replace(/^\|\s*|\s*\|$/g, '');
|
|
248
|
-
result = result.replace(/\|\s+\|/g, '').replace(/\|\s+\|/g, '').replace(/^\|\s*|\s*\|$/g, '').replace(/^\|\s*|\s*\|$/g, '');
|
|
249
|
-
|
|
250
|
-
return result.substring(0, maxLength);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// Helper: Check if in viewport
|
|
254
|
-
// const inViewport = (el: Element): boolean => {
|
|
255
|
-
// const rect = el.getBoundingClientRect();
|
|
256
|
-
// return rect.top >= 0 && rect.left >= 0 &&
|
|
257
|
-
// rect.bottom <= window.innerHeight && rect.right <= window.innerWidth;
|
|
258
|
-
// };
|
|
259
|
-
|
|
260
|
-
// Summary
|
|
261
|
-
const summary = {
|
|
262
|
-
url: window.location.href,
|
|
263
|
-
title: document.title,
|
|
264
|
-
hasIframes: document.querySelectorAll('iframe').length > 0,
|
|
265
|
-
hasCaptcha: !!(
|
|
266
|
-
// reCAPTCHA
|
|
267
|
-
document.querySelector('iframe[src*="recaptcha"]') ||
|
|
268
|
-
document.querySelector('iframe[title*="recaptcha" i]') ||
|
|
269
|
-
document.querySelector('.g-recaptcha') ||
|
|
270
|
-
document.querySelector('[data-sitekey]') ||
|
|
271
|
-
// hCaptcha
|
|
272
|
-
document.querySelector('iframe[src*="hcaptcha"]') ||
|
|
273
|
-
document.querySelector('.h-captcha') ||
|
|
274
|
-
// Cloudflare
|
|
275
|
-
document.querySelector('.cf-challenge-running') ||
|
|
276
|
-
document.querySelector('#challenge-running') ||
|
|
277
|
-
document.querySelector('div[id*="cf-challenge"]') ||
|
|
278
|
-
// Turnstile
|
|
279
|
-
document.querySelector('iframe[src*="turnstile"]') ||
|
|
280
|
-
document.querySelector('.cf-turnstile') ||
|
|
281
|
-
// FunCaptcha/ArkoseLabs
|
|
282
|
-
document.querySelector('iframe[src*="funcaptcha"]') ||
|
|
283
|
-
document.querySelector('iframe[src*="arkoselabs"]') ||
|
|
284
|
-
// Generic captcha indicators
|
|
285
|
-
document.querySelector('[class*="captcha" i]') ||
|
|
286
|
-
document.querySelector('[id*="captcha" i]') ||
|
|
287
|
-
// Image/text based captchas
|
|
288
|
-
document.querySelector('img[alt*="captcha" i]') ||
|
|
289
|
-
document.querySelector('img[src*="captcha" i]')
|
|
290
|
-
),
|
|
291
|
-
scrollableHeight: Math.max(
|
|
292
|
-
document.body.scrollHeight,
|
|
293
|
-
document.documentElement.scrollHeight
|
|
294
|
-
),
|
|
295
|
-
viewportHeight: window.innerHeight
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
// Forms structure
|
|
299
|
-
const forms: any[] = [];
|
|
300
|
-
document.querySelectorAll('form').forEach((form, formIdx) => {
|
|
301
|
-
const fields: any[] = [];
|
|
302
|
-
|
|
303
|
-
form.querySelectorAll('input, textarea, select').forEach((field) => {
|
|
304
|
-
const tagName = field.tagName.toLowerCase();
|
|
305
|
-
const type = tagName === 'input' ? (field as HTMLInputElement).type : tagName;
|
|
306
|
-
|
|
307
|
-
let label = '';
|
|
308
|
-
const id = field.id;
|
|
309
|
-
if (id) {
|
|
310
|
-
const labelEl = document.querySelector(`label[for="${id}"]`);
|
|
311
|
-
if (labelEl) label = getVisibleText(labelEl);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (!label) {
|
|
315
|
-
label = (field as any).placeholder || (field as any).name || '(no label)';
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
fields.push({
|
|
319
|
-
label,
|
|
320
|
-
type,
|
|
321
|
-
name: (field as any).name || '',
|
|
322
|
-
placeholder: (field as any).placeholder || '',
|
|
323
|
-
required: (field as any).required || false,
|
|
324
|
-
currentValue: (field as any).value || ''
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
forms.push({
|
|
329
|
-
formId: form.id || `form-${formIdx}`,
|
|
330
|
-
action: form.action || '',
|
|
331
|
-
fields
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
// Navigation - collect ALL links (not just nav), then deduplicate
|
|
336
|
-
const navigation = {
|
|
337
|
-
menus: [] as any[],
|
|
338
|
-
links: [] as any[]
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
// Collect all links with href
|
|
342
|
-
const seenHrefs = new Set<string>();
|
|
343
|
-
document.querySelectorAll('a[href]').forEach((link) => {
|
|
344
|
-
const href = (link as HTMLAnchorElement).href;
|
|
345
|
-
const text = getVisibleText(link, 150);
|
|
346
|
-
|
|
347
|
-
// Skip if: empty href, empty text, already seen, or anchor-only link
|
|
348
|
-
if (!href || !text || seenHrefs.has(href) || href.startsWith('#')) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
seenHrefs.add(href);
|
|
353
|
-
navigation.links.push({
|
|
354
|
-
text,
|
|
355
|
-
href
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
// Page structure
|
|
360
|
-
const structure = {
|
|
361
|
-
headings: [] as any[],
|
|
362
|
-
sections: [] as any[]
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
// Collect headings
|
|
366
|
-
document.querySelectorAll('h1, h2, h3, h4, h5, h6').forEach((heading) => {
|
|
367
|
-
structure.headings.push({
|
|
368
|
-
level: parseInt(heading.tagName.substring(1)),
|
|
369
|
-
text: getVisibleText(heading),
|
|
370
|
-
id: heading.id || ''
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
// Collect sections
|
|
375
|
-
document.querySelectorAll('section, article, main').forEach((section, idx) => {
|
|
376
|
-
const heading = section.querySelector('h1, h2, h3, h4, h5, h6');
|
|
377
|
-
const headingText = heading ? getVisibleText(heading, 200) : `Section ${idx + 1}`;
|
|
378
|
-
const summary = getVisibleText(section, 400);
|
|
379
|
-
|
|
380
|
-
structure.sections.push({
|
|
381
|
-
heading: headingText,
|
|
382
|
-
summary
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
// Text content - collect from various element types
|
|
387
|
-
const content = {
|
|
388
|
-
paragraphs: [] as string[]
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
// Collect text from paragraphs, divs, list items, table cells, spans
|
|
392
|
-
const seenTexts = new Set<string>();
|
|
393
|
-
const textSelectors = 'p, div:not(:has(p)):not(:has(div)), li, td, span:not(:has(span))';
|
|
394
|
-
|
|
395
|
-
document.querySelectorAll(textSelectors).forEach((el) => {
|
|
396
|
-
const text = getVisibleText(el, 800);
|
|
397
|
-
|
|
398
|
-
// Skip if: too short, already seen, or likely navigation/UI element
|
|
399
|
-
if (text.length < 10 || seenTexts.has(text)) {
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// Limit to 100 text items to avoid overflow
|
|
404
|
-
if (content.paragraphs.length >= 100) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
seenTexts.add(text);
|
|
409
|
-
content.paragraphs.push(text);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
return {
|
|
413
|
-
navigation,
|
|
414
|
-
structure,
|
|
415
|
-
content,
|
|
416
|
-
forms,
|
|
417
|
-
summary
|
|
418
|
-
};
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
// Filter sections if include provided
|
|
422
|
-
const includeSet = args.include ? new Set(args.include) : null;
|
|
423
|
-
let filtered: any = {};
|
|
424
|
-
|
|
425
|
-
if (includeSet) {
|
|
426
|
-
// Only include requested sections (in priority order)
|
|
427
|
-
if (includeSet.has('navigation')) filtered.navigation = analysis.navigation;
|
|
428
|
-
if (includeSet.has('structure')) filtered.structure = analysis.structure;
|
|
429
|
-
if (includeSet.has('content')) filtered.content = analysis.content;
|
|
430
|
-
if (includeSet.has('forms')) filtered.forms = analysis.forms;
|
|
431
|
-
if (includeSet.has('summary')) filtered.summary = analysis.summary;
|
|
432
|
-
} else {
|
|
433
|
-
// Include all sections
|
|
434
|
-
filtered = analysis;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return {
|
|
440
|
-
content: [{
|
|
441
|
-
type: "text" as const,
|
|
442
|
-
text: JSON.stringify(filtered, null, 2)
|
|
443
|
-
}]
|
|
444
|
-
};
|
|
445
|
-
} catch (error) {
|
|
446
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
447
|
-
return {
|
|
448
|
-
content: [{
|
|
449
|
-
type: "text" as const,
|
|
450
|
-
text: `DOM analysis failed: ${errorMessage}`
|
|
451
|
-
}],
|
|
452
|
-
isError: true
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
export async function takeScreenshotHandler() {
|
|
458
|
-
try {
|
|
459
|
-
// Get active tab and session
|
|
460
|
-
const { session } = await getActiveTabSession();
|
|
461
|
-
|
|
462
|
-
// ALWAYS capture viewport only (cost-efficient, fast)
|
|
463
|
-
const screenshot = await session.page.screenshot({
|
|
464
|
-
encoding: 'base64',
|
|
465
|
-
fullPage: false, // viewport only
|
|
466
|
-
type: 'png'
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return {
|
|
472
|
-
content: [
|
|
473
|
-
{
|
|
474
|
-
type: "image" as const,
|
|
475
|
-
data: screenshot,
|
|
476
|
-
mimeType: "image/png"
|
|
477
|
-
},
|
|
478
|
-
{
|
|
479
|
-
type: "text" as const,
|
|
480
|
-
text: `Screenshot captured successfully (viewport only).`
|
|
481
|
-
}
|
|
482
|
-
]
|
|
483
|
-
};
|
|
484
|
-
} catch (error) {
|
|
485
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
486
|
-
|
|
487
|
-
return {
|
|
488
|
-
content: [{
|
|
489
|
-
type: "text" as const,
|
|
490
|
-
text: `Screenshot failed: ${errorMessage}`
|
|
491
|
-
}],
|
|
492
|
-
isError: true
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* System Tools Router
|
|
3
|
-
*
|
|
4
|
-
* Entry point for install-related WebSocket handlers:
|
|
5
|
-
* - system-tools:status / status-all — detection + recipe
|
|
6
|
-
* - system-tools:install-start / install-cancel / install-session
|
|
7
|
-
* - Server → client stream events
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { createRouter } from '$shared/utils/ws-server';
|
|
11
|
-
import { systemToolsStatusHandler } from './status';
|
|
12
|
-
import { systemToolsInstallHandler } from './install';
|
|
13
|
-
|
|
14
|
-
export const systemToolsRouter = createRouter()
|
|
15
|
-
.merge(systemToolsStatusHandler)
|
|
16
|
-
.merge(systemToolsInstallHandler);
|