@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
|
@@ -260,6 +260,62 @@ export class BrowserNavigationTracker extends EventEmitter {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Reuse the tab's tracking CDP session, creating one if setup failed or ran
|
|
265
|
+
* before this call. History reads happen on every navigation, so attaching a
|
|
266
|
+
* fresh session each time would be wasteful.
|
|
267
|
+
*/
|
|
268
|
+
private async getCdpSession(sessionId: string, page: Page): Promise<CDPSession> {
|
|
269
|
+
const existing = this.cdpSessions.get(sessionId);
|
|
270
|
+
if (existing) return existing;
|
|
271
|
+
|
|
272
|
+
const cdp = await page.createCDPSession();
|
|
273
|
+
this.cdpSessions.set(sessionId, cdp);
|
|
274
|
+
return cdp;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Read the tab's real navigation history from CDP.
|
|
279
|
+
*
|
|
280
|
+
* `window.history.length` cannot answer "can I go forward?" and over-counts
|
|
281
|
+
* for SPAs; `Page.getNavigationHistory` returns the actual entry list plus
|
|
282
|
+
* the current index, which is what a real browser's buttons read.
|
|
283
|
+
*/
|
|
284
|
+
async getNavigationHistory(
|
|
285
|
+
sessionId: string,
|
|
286
|
+
page: Page
|
|
287
|
+
): Promise<{ currentIndex: number; entries: Array<{ id: number; url: string; title: string }> } | null> {
|
|
288
|
+
try {
|
|
289
|
+
const cdp = await this.getCdpSession(sessionId, page);
|
|
290
|
+
const history = await cdp.send('Page.getNavigationHistory');
|
|
291
|
+
return {
|
|
292
|
+
currentIndex: history.currentIndex,
|
|
293
|
+
entries: history.entries.map((entry) => ({
|
|
294
|
+
id: entry.id,
|
|
295
|
+
url: entry.url,
|
|
296
|
+
title: entry.title || entry.url
|
|
297
|
+
}))
|
|
298
|
+
};
|
|
299
|
+
} catch (error) {
|
|
300
|
+
debug.warn('preview', `⚠️ Failed to read navigation history for ${sessionId}:`, error);
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Jump to a specific history entry by CDP entry id.
|
|
307
|
+
*/
|
|
308
|
+
async navigateToHistoryEntry(sessionId: string, page: Page, entryId: number): Promise<boolean> {
|
|
309
|
+
try {
|
|
310
|
+
const cdp = await this.getCdpSession(sessionId, page);
|
|
311
|
+
await cdp.send('Page.navigateToHistoryEntry', { entryId });
|
|
312
|
+
return true;
|
|
313
|
+
} catch (error) {
|
|
314
|
+
debug.warn('preview', `⚠️ Failed to navigate to history entry ${entryId} for ${sessionId}:`, error);
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
263
319
|
/**
|
|
264
320
|
* Cleanup CDP session for a tab
|
|
265
321
|
*/
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* - Direct launch() ensures puppeteer-extra wraps ALL page creation correctly.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import { existsSync } from 'fs';
|
|
18
19
|
import type { Browser, BrowserContext, Page } from 'puppeteer';
|
|
19
20
|
import { debug } from '$shared/utils/logger';
|
|
20
21
|
import puppeteer from 'puppeteer-extra';
|
|
@@ -45,15 +46,88 @@ const DEFAULT_CONFIG: PoolConfig = {
|
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
|
-
* Chrome launch arguments
|
|
49
|
+
* Chrome launch arguments.
|
|
50
|
+
*
|
|
51
|
+
* Three groups, kept separate because they answer different questions:
|
|
52
|
+
* stealth (Cloudflare bypass — matches test-cf.ts), capture (what the preview
|
|
53
|
+
* pipeline needs from the renderer), and host adaptation (what a headless VPS
|
|
54
|
+
* needs that a desktop doesn't).
|
|
49
55
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
function buildChromeArgs(): string[] {
|
|
57
|
+
// Chrome only honours the last `--disable-features`, so every entry has to
|
|
58
|
+
// live in one combined flag.
|
|
59
|
+
const disabledFeatures = [
|
|
60
|
+
'AudioServiceOutOfProcess',
|
|
61
|
+
'WebRtcHideLocalIpsWithMdns',
|
|
62
|
+
// Occlusion detection throttles renderers Chrome thinks nobody is
|
|
63
|
+
// looking at — which is every headless tab, including the one we are
|
|
64
|
+
// actively streaming.
|
|
65
|
+
'CalculateNativeWinOcclusion'
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const args = [
|
|
69
|
+
'--no-sandbox',
|
|
70
|
+
'--disable-blink-features=AutomationControlled',
|
|
71
|
+
'--window-size=1366,768',
|
|
72
|
+
'--autoplay-policy=no-user-gesture-required',
|
|
73
|
+
|
|
74
|
+
// In-page capture (getDisplayMedia({preferCurrentTab})) — lets the
|
|
75
|
+
// encoder read compositor frames directly instead of round-tripping
|
|
76
|
+
// JPEG through CDP. Without this the call would wait on a picker that
|
|
77
|
+
// can never be answered in headless.
|
|
78
|
+
'--auto-accept-this-tab-capture',
|
|
79
|
+
|
|
80
|
+
// A headless tab is never "visible" or "focused", and Chrome
|
|
81
|
+
// aggressively de-prioritises renderers in that state — timers get
|
|
82
|
+
// clamped and compositing stalls, which reads as a frozen preview.
|
|
83
|
+
'--disable-background-timer-throttling',
|
|
84
|
+
'--disable-backgrounding-occluded-windows',
|
|
85
|
+
'--disable-renderer-backgrounding',
|
|
86
|
+
|
|
87
|
+
// Containers and small VPS instances often ship a 64MB /dev/shm;
|
|
88
|
+
// exceeding it crashes the renderer mid-stream.
|
|
89
|
+
'--disable-dev-shm-usage',
|
|
90
|
+
|
|
91
|
+
'--no-first-run',
|
|
92
|
+
'--no-default-browser-check',
|
|
93
|
+
'--disable-hang-monitor',
|
|
94
|
+
'--metrics-recording-only',
|
|
95
|
+
'--force-color-profile=srgb'
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
if (shouldDisableGpu()) {
|
|
99
|
+
// Without a real GPU, Chrome falls back to SwiftShader — a software
|
|
100
|
+
// GL implementation whose setup and per-frame cost exceed plain CPU
|
|
101
|
+
// rasterisation for the 2D content a preview shows.
|
|
102
|
+
args.push('--disable-gpu', '--disable-software-rasterizer');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
args.push(`--disable-features=${disabledFeatures.join(',')}`);
|
|
106
|
+
|
|
107
|
+
return args;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether this host benefits from skipping GPU compositing entirely.
|
|
112
|
+
*
|
|
113
|
+
* `auto` only disables it on Linux hosts with no render node, i.e. headless
|
|
114
|
+
* servers — a Linux desktop keeps its GPU so WebGL previews still work.
|
|
115
|
+
*/
|
|
116
|
+
function shouldDisableGpu(): boolean {
|
|
117
|
+
const override = (process.env.CLOPEN_PREVIEW_GPU || '').trim().toLowerCase();
|
|
118
|
+
if (override === 'off') return true;
|
|
119
|
+
if (override === 'on') return false;
|
|
120
|
+
|
|
121
|
+
if (process.platform !== 'linux') return false;
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
return !existsSync('/dev/dri');
|
|
125
|
+
} catch {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const CHROME_ARGS = buildChromeArgs();
|
|
57
131
|
|
|
58
132
|
class BrowserPool {
|
|
59
133
|
private browser: Browser | null = null;
|
|
@@ -104,7 +178,7 @@ class BrowserPool {
|
|
|
104
178
|
// via the distro package manager (Linux).
|
|
105
179
|
const executablePath = getChromeExecutablePath();
|
|
106
180
|
if (!executablePath) {
|
|
107
|
-
throw new Error('Chrome not installed. Go to Settings →
|
|
181
|
+
throw new Error('Chrome not installed. Go to Settings → Stack and click Install.');
|
|
108
182
|
}
|
|
109
183
|
debug.log('preview', ` using Chrome at: ${executablePath}`);
|
|
110
184
|
|