@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,375 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser Management Handlers for MCP Browser Automation
|
|
3
|
-
*
|
|
4
|
-
* Provides tools for MCP to manage browser:
|
|
5
|
-
* - List and switch tabs
|
|
6
|
-
* - Open and close tabs (auto session management)
|
|
7
|
-
* - Navigate active tab
|
|
8
|
-
*
|
|
9
|
-
* Control model:
|
|
10
|
-
* - Each chat session can control multiple tabs (accumulated via switch/open)
|
|
11
|
-
* - A tab can only be controlled by one chat session at a time
|
|
12
|
-
* - All controlled tabs are released when the chat stream ends
|
|
13
|
-
* - list_tabs shows MCP control status so AI avoids conflicts
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { debug } from "$shared/utils/logger";
|
|
17
|
-
import { browserMcpControl, browserPreviewServiceManager, type BrowserPreviewService } from "$backend/preview";
|
|
18
|
-
import { projectContextService } from "$backend/mcp/internal/project-context";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get BrowserPreviewService for current MCP execution context
|
|
22
|
-
*/
|
|
23
|
-
function getPreviewService(projectId?: string): BrowserPreviewService {
|
|
24
|
-
if (projectId) {
|
|
25
|
-
return browserPreviewServiceManager.getService(projectId);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const contextProjectId = projectContextService.getCurrentProjectId();
|
|
29
|
-
if (contextProjectId) {
|
|
30
|
-
return browserPreviewServiceManager.getService(contextProjectId);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const activeProjects = browserPreviewServiceManager.getActiveProjects();
|
|
34
|
-
if (activeProjects.length > 0) {
|
|
35
|
-
debug.warn('mcp', `⚠️ No project context found, falling back to first active project: ${activeProjects[0]}`);
|
|
36
|
-
return browserPreviewServiceManager.getService(activeProjects[0]);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
throw new Error('No active browser preview service found. Project isolation requires projectId.');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get chatSessionId from current execution context.
|
|
44
|
-
* Required for session-scoped MCP control.
|
|
45
|
-
*/
|
|
46
|
-
function getChatSessionId(): string {
|
|
47
|
-
const chatSessionId = projectContextService.getCurrentChatSessionId();
|
|
48
|
-
if (!chatSessionId) {
|
|
49
|
-
throw new Error('No chat session context available. Cannot acquire MCP control.');
|
|
50
|
-
}
|
|
51
|
-
return chatSessionId;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Internal helper: Get active tab for MCP operations.
|
|
56
|
-
* Automatically acquires MCP control for the chat session.
|
|
57
|
-
*
|
|
58
|
-
* If this chat session already controls tabs, uses the most recently
|
|
59
|
-
* controlled tab (not necessarily the frontend's active tab).
|
|
60
|
-
*/
|
|
61
|
-
export async function getActiveTabSession(projectId?: string) {
|
|
62
|
-
const previewService = getPreviewService(projectId);
|
|
63
|
-
const resolvedProjectId = previewService.getProjectId();
|
|
64
|
-
const chatSessionId = getChatSessionId();
|
|
65
|
-
|
|
66
|
-
// Check if this session already controls any tabs — use the last one
|
|
67
|
-
const sessionTabs = browserMcpControl.getSessionTabs(chatSessionId);
|
|
68
|
-
if (sessionTabs.length > 0) {
|
|
69
|
-
// Use the last tab this session was working with
|
|
70
|
-
const lastTabId = sessionTabs[sessionTabs.length - 1];
|
|
71
|
-
const controlledTab = previewService.getTab(lastTabId);
|
|
72
|
-
if (controlledTab) {
|
|
73
|
-
debug.log('mcp', `🎮 Using session-controlled tab: ${controlledTab.id}`);
|
|
74
|
-
return { tab: controlledTab, session: controlledTab };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// No controlled tab — use the frontend's active tab and acquire control
|
|
79
|
-
const tab = previewService.getActiveTab();
|
|
80
|
-
if (!tab) {
|
|
81
|
-
throw new Error("No active tab found. Open a tab first using 'open_new_tab'.");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Acquire control (will fail if another session owns this tab)
|
|
85
|
-
const acquired = browserMcpControl.acquireControl(tab.id, chatSessionId, resolvedProjectId);
|
|
86
|
-
if (!acquired) {
|
|
87
|
-
const owner = browserMcpControl.getTabOwner(tab.id);
|
|
88
|
-
throw new Error(`Tab '${tab.id}' is controlled by another chat session (${owner?.slice(0, 8)}...). Use a different tab.`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return { tab, session: tab };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* List all open tabs in the browser preview.
|
|
96
|
-
* Shows MCP control status so AI can avoid conflicts.
|
|
97
|
-
*/
|
|
98
|
-
export async function listTabsHandler(projectId?: string) {
|
|
99
|
-
try {
|
|
100
|
-
const previewService = getPreviewService(projectId);
|
|
101
|
-
const tabs = previewService.getAllTabs();
|
|
102
|
-
const chatSessionId = projectContextService.getCurrentChatSessionId();
|
|
103
|
-
|
|
104
|
-
if (tabs.length === 0) {
|
|
105
|
-
return {
|
|
106
|
-
content: [{
|
|
107
|
-
type: "text" as const,
|
|
108
|
-
text: `No browser tabs are currently open.`
|
|
109
|
-
}]
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const tabList = tabs.map((tab: any, index: number) => {
|
|
114
|
-
const owner = browserMcpControl.getTabOwner(tab.id);
|
|
115
|
-
let status = '';
|
|
116
|
-
if (owner) {
|
|
117
|
-
status = owner === chatSessionId
|
|
118
|
-
? ' (MCP: this session)'
|
|
119
|
-
: ' (MCP: another session)';
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return `${index + 1}. ${tab.isActive ? '* ' : ' '}[${tab.id}] ${tab.title || 'Untitled'}${status}\n URL: ${tab.url || '(empty)'}`;
|
|
123
|
-
}).join('\n\n');
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
content: [{
|
|
127
|
-
type: "text" as const,
|
|
128
|
-
text: `Browser Tabs (${tabs.length}):\n\n${tabList}`
|
|
129
|
-
}]
|
|
130
|
-
};
|
|
131
|
-
} catch (error) {
|
|
132
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
133
|
-
return {
|
|
134
|
-
content: [{
|
|
135
|
-
type: "text" as const,
|
|
136
|
-
text: `Failed to list tabs: ${errorMessage}`
|
|
137
|
-
}],
|
|
138
|
-
isError: true
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Switch to a specific tab by ID.
|
|
145
|
-
* Adds the tab to this session's controlled set (does NOT release other tabs).
|
|
146
|
-
*/
|
|
147
|
-
export async function switchTabHandler(args: { tabId: string; projectId?: string }) {
|
|
148
|
-
try {
|
|
149
|
-
debug.log('mcp', `🔄 MCP switching to tab: ${args.tabId}`);
|
|
150
|
-
|
|
151
|
-
const previewService = getPreviewService(args.projectId);
|
|
152
|
-
const chatSessionId = getChatSessionId();
|
|
153
|
-
const resolvedProjectId = previewService.getProjectId();
|
|
154
|
-
|
|
155
|
-
const success = previewService.switchTab(args.tabId);
|
|
156
|
-
if (!success) {
|
|
157
|
-
return {
|
|
158
|
-
content: [{
|
|
159
|
-
type: "text" as const,
|
|
160
|
-
text: `Failed to switch tab: Tab '${args.tabId}' not found`
|
|
161
|
-
}],
|
|
162
|
-
isError: true
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Acquire control of the new tab (adds to session's set, doesn't release others)
|
|
167
|
-
const tab = previewService.getTab(args.tabId);
|
|
168
|
-
if (tab) {
|
|
169
|
-
const acquired = browserMcpControl.acquireControl(tab.id, chatSessionId, resolvedProjectId);
|
|
170
|
-
if (!acquired) {
|
|
171
|
-
const owner = browserMcpControl.getTabOwner(tab.id);
|
|
172
|
-
return {
|
|
173
|
-
content: [{
|
|
174
|
-
type: "text" as const,
|
|
175
|
-
text: `Tab '${args.tabId}' is controlled by another chat session (${owner?.slice(0, 8)}...). Cannot switch to it.`
|
|
176
|
-
}],
|
|
177
|
-
isError: true
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
// Promote tab to end of session's set so getActiveTabSession() targets it next
|
|
181
|
-
browserMcpControl.promoteSessionTab(tab.id, chatSessionId);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
content: [{
|
|
186
|
-
type: "text" as const,
|
|
187
|
-
text: `Switched to tab '${args.tabId}'.\n\nTitle: ${tab?.title || 'Untitled'}\nURL: ${tab?.url || '(empty)'}`
|
|
188
|
-
}]
|
|
189
|
-
};
|
|
190
|
-
} catch (error) {
|
|
191
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
192
|
-
return {
|
|
193
|
-
content: [{
|
|
194
|
-
type: "text" as const,
|
|
195
|
-
text: `Failed to switch tab: ${errorMessage}`
|
|
196
|
-
}],
|
|
197
|
-
isError: true
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Open a new tab with optional URL and viewport configuration.
|
|
204
|
-
* Auto-acquires MCP control for the new tab.
|
|
205
|
-
*/
|
|
206
|
-
export async function openNewTabHandler(args: { url?: string; deviceSize?: 'desktop' | 'laptop' | 'tablet' | 'mobile'; rotation?: 'portrait' | 'landscape'; projectId?: string }) {
|
|
207
|
-
try {
|
|
208
|
-
const deviceSize = args.deviceSize || 'laptop';
|
|
209
|
-
|
|
210
|
-
let rotation: 'portrait' | 'landscape';
|
|
211
|
-
if (args.rotation) {
|
|
212
|
-
rotation = args.rotation;
|
|
213
|
-
} else {
|
|
214
|
-
rotation = (deviceSize === 'desktop' || deviceSize === 'laptop') ? 'landscape' : 'portrait';
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
debug.log('mcp', `📑 MCP opening new tab with URL: ${args.url || '(empty)'}`);
|
|
218
|
-
|
|
219
|
-
const previewService = getPreviewService(args.projectId);
|
|
220
|
-
const chatSessionId = getChatSessionId();
|
|
221
|
-
const resolvedProjectId = previewService.getProjectId();
|
|
222
|
-
|
|
223
|
-
const tab = await previewService.createTab(args.url || undefined, deviceSize, rotation);
|
|
224
|
-
debug.log('mcp', `✅ Tab created: ${tab.id}`);
|
|
225
|
-
|
|
226
|
-
// Acquire control of the new tab (adds to session's set)
|
|
227
|
-
browserMcpControl.acquireControl(tab.id, chatSessionId, resolvedProjectId);
|
|
228
|
-
|
|
229
|
-
return {
|
|
230
|
-
content: [{
|
|
231
|
-
type: "text" as const,
|
|
232
|
-
text: `New tab opened successfully.\n\nTab ID: ${tab.id}\nTitle: ${tab.title}\nURL: ${tab.url || '(empty)'}\nViewport: ${deviceSize} (${rotation})`
|
|
233
|
-
}]
|
|
234
|
-
};
|
|
235
|
-
} catch (error) {
|
|
236
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
237
|
-
return {
|
|
238
|
-
content: [{
|
|
239
|
-
type: "text" as const,
|
|
240
|
-
text: `Failed to open new tab: ${errorMessage}`
|
|
241
|
-
}],
|
|
242
|
-
isError: true
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Close a specific tab by ID.
|
|
249
|
-
* Releases MCP control for the closed tab only.
|
|
250
|
-
*/
|
|
251
|
-
export async function closeTabHandler(args: { tabId: string; projectId?: string }) {
|
|
252
|
-
try {
|
|
253
|
-
debug.log('mcp', `❌ MCP closing tab: ${args.tabId}`);
|
|
254
|
-
|
|
255
|
-
const previewService = getPreviewService(args.projectId);
|
|
256
|
-
const result = await previewService.closeTab(args.tabId);
|
|
257
|
-
|
|
258
|
-
if (!result.success) {
|
|
259
|
-
return {
|
|
260
|
-
content: [{
|
|
261
|
-
type: "text" as const,
|
|
262
|
-
text: `Failed to close tab: Tab '${args.tabId}' not found`
|
|
263
|
-
}],
|
|
264
|
-
isError: true
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// releaseTab is already called by autoReleaseForTab inside closeTab()
|
|
269
|
-
// No need to manually release here
|
|
270
|
-
|
|
271
|
-
let responseText = `Tab '${args.tabId}' closed successfully.`;
|
|
272
|
-
if (result.newActiveTabId) {
|
|
273
|
-
const newActiveTab = previewService.getTab(result.newActiveTabId);
|
|
274
|
-
if (newActiveTab) {
|
|
275
|
-
responseText += `\n\nNew active tab: ${newActiveTab.id}\nURL: ${newActiveTab.url || '(empty)'}`;
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
responseText += `\n\nNo remaining tabs.`;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return {
|
|
282
|
-
content: [{
|
|
283
|
-
type: "text" as const,
|
|
284
|
-
text: responseText
|
|
285
|
-
}]
|
|
286
|
-
};
|
|
287
|
-
} catch (error) {
|
|
288
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
289
|
-
return {
|
|
290
|
-
content: [{
|
|
291
|
-
type: "text" as const,
|
|
292
|
-
text: `Failed to close tab: ${errorMessage}`
|
|
293
|
-
}],
|
|
294
|
-
isError: true
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Navigate active tab to a different URL.
|
|
301
|
-
* Waits for page load. Session state preserved.
|
|
302
|
-
*/
|
|
303
|
-
export async function navigateHandler(args: { url: string; projectId?: string }) {
|
|
304
|
-
try {
|
|
305
|
-
const { session } = await getActiveTabSession(args.projectId);
|
|
306
|
-
|
|
307
|
-
await session.page.goto(args.url, {
|
|
308
|
-
waitUntil: 'domcontentloaded',
|
|
309
|
-
timeout: 30000
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
313
|
-
|
|
314
|
-
const finalUrl = session.page.url();
|
|
315
|
-
|
|
316
|
-
return {
|
|
317
|
-
content: [{
|
|
318
|
-
type: "text" as const,
|
|
319
|
-
text: `Navigation successful.\n\nFinal URL: ${finalUrl}`
|
|
320
|
-
}]
|
|
321
|
-
};
|
|
322
|
-
} catch (error) {
|
|
323
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
324
|
-
return {
|
|
325
|
-
content: [{
|
|
326
|
-
type: "text" as const,
|
|
327
|
-
text: `Navigation failed: ${errorMessage}`
|
|
328
|
-
}],
|
|
329
|
-
isError: true
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Change viewport settings (device size and rotation) for active tab.
|
|
336
|
-
*/
|
|
337
|
-
export async function setViewportHandler(args: { deviceSize?: 'desktop' | 'laptop' | 'tablet' | 'mobile'; rotation?: 'portrait' | 'landscape'; projectId?: string }) {
|
|
338
|
-
try {
|
|
339
|
-
const { tab } = await getActiveTabSession(args.projectId);
|
|
340
|
-
|
|
341
|
-
const deviceSize = args.deviceSize || tab.deviceSize;
|
|
342
|
-
const rotation = args.rotation || tab.rotation;
|
|
343
|
-
|
|
344
|
-
debug.log('mcp', `📱 MCP changing viewport for tab ${tab.id}: ${deviceSize} (${rotation})`);
|
|
345
|
-
|
|
346
|
-
const previewService = getPreviewService(args.projectId);
|
|
347
|
-
const success = await previewService.setViewport(tab.id, deviceSize, rotation);
|
|
348
|
-
|
|
349
|
-
if (!success) {
|
|
350
|
-
return {
|
|
351
|
-
content: [{
|
|
352
|
-
type: "text" as const,
|
|
353
|
-
text: `Failed to change viewport for tab '${tab.id}'`
|
|
354
|
-
}],
|
|
355
|
-
isError: true
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return {
|
|
360
|
-
content: [{
|
|
361
|
-
type: "text" as const,
|
|
362
|
-
text: `Viewport changed successfully.\n\nTab ID: ${tab.id}\nDevice: ${deviceSize}\nRotation: ${rotation}`
|
|
363
|
-
}]
|
|
364
|
-
};
|
|
365
|
-
} catch (error) {
|
|
366
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
367
|
-
return {
|
|
368
|
-
content: [{
|
|
369
|
-
type: "text" as const,
|
|
370
|
-
text: `Failed to change viewport: ${errorMessage}`
|
|
371
|
-
}],
|
|
372
|
-
isError: true
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
}
|