@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";const C={0:"vp8",1:"vp09.00.10.08",2:"avc1.42E033"},r={decoder:null,codecId:-1,preferHardware:!0};let o=null,p=0,h=0,k=!0,u=0,g=0,m=0,l=0;const s=new Map;function a(t,e){e&&e.length>0?self.postMessage(t,e):self.postMessage(t)}function d(){if(r.decoder)try{r.decoder.reset(),r.decoder.close()}catch{}r.decoder=null,r.codecId=-1,s.clear()}async function H(t){const e=s.get(t.timestamp);e!==void 0&&(s.delete(t.timestamp),m+=performance.now()-e,l++),g++;const n={t:"frame",timestamp:t.timestamp,width:t.displayWidth,height:t.displayHeight};if(k)try{a({...n,frame:t,kind:"videoframe"},[t]);return}catch{k=!1}try{const c=await createImageBitmap(t);a({...n,frame:c,kind:"imagebitmap"},[c])}catch{}finally{try{t.close()}catch{}}}async function I(t){if(r.decoder&&r.codecId===t)return!0;d();const e=C[t];if(!e)return!1;const n={codec:e,optimizeForLatency:!0,hardwareAcceleration:r.preferHardware?"prefer-hardware":"no-preference"};try{let c=await VideoDecoder.isConfigSupported(n);return!c.supported&&r.preferHardware&&(n.hardwareAcceleration="no-preference",c=await VideoDecoder.isConfigSupported(n)),c.supported?(r.decoder=new VideoDecoder({output:f=>{H(f)},error:()=>{d(),a({t:"keyframe-request"})}}),r.decoder.configure(n),r.codecId=t,a({t:"codec",codecId:t,codec:e}),!0):!1}catch{return d(),!1}}async function U(t,e,n,c){if(r.decoder&&n&&c!==r.codecId&&d(),!r.decoder&&n&&await I(c),!r.decoder){a({t:"keyframe-request"});return}try{s.set(e,performance.now()),r.decoder.decode(new EncodedVideoChunk({type:n?"key":"delta",timestamp:e,data:t}))}catch{s.delete(e),d(),a({t:"keyframe-request"})}}function L(t){const e=new DataView(t),n=e.getUint8(0);if(n===0){const c=Number(e.getBigUint64(1,!0)),f=e.getUint8(9)===1,y=e.getUint8(10),w=e.getUint32(11,!0);u++,U(new Uint8Array(t,15,w),c,f,y);return}if(n===2){const c=Number(e.getBigUint64(1,!0)),f=e.getUint8(9)===1,y=e.getUint8(10),w=e.getUint16(11,!0),z=e.getUint16(13,!0),A=e.getUint32(15,!0),T=new Uint8Array(t,19,A);(!o||p!==c)&&(o=[],p=c,h=z),o[w]=T;let v=0;for(const i of o)i&&v++;if(v!==h)return;let b=0;for(const i of o)b+=i.byteLength;const D=new Uint8Array(b);let S=0;for(const i of o)D.set(i,S),S+=i.byteLength;o=null,u++,U(D,c,f,y)}}function V(){const t={t:"stats",decodeQueueSize:r.decoder?.decodeQueueSize??0,decodeLatencyMs:l>0?m/l:0,framesReceived:u,framesDecoded:g};u=0,g=0,m=0,l=0,a(t)}self.onmessage=t=>{const e=t.data;switch(e?.t){case"packet":try{L(e.buffer)}catch{}break;case"stats":V();break;case"reset":d(),o=null,p=0;break;case"init":r.preferHardware=e.preferHardware!==!1,a({t:"ready",ok:typeof VideoDecoder<"u"});break;case"close":d(),self.close();break}}})();
|
package/dist/index.html
CHANGED
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
}
|
|
59
59
|
})();
|
|
60
60
|
</script>
|
|
61
|
-
<script type="module" crossorigin src="/assets/main-
|
|
62
|
-
<link rel="stylesheet" crossorigin href="/assets/main-
|
|
61
|
+
<script type="module" crossorigin src="/assets/main-D-d8SFfW.js"></script>
|
|
62
|
+
<link rel="stylesheet" crossorigin href="/assets/main-BD3-qPfT.css">
|
|
63
63
|
</head>
|
|
64
64
|
<body
|
|
65
65
|
class="min-h-dvh bg-white text-slate-900 dark:bg-slate-950 dark:text-slate-100 transition-colors duration-200"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myrialabs/clopen",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.22",
|
|
4
4
|
"description": "All-in-one web workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor — with chat, terminal, git, browser preview, database client, checkpoints, and real-time collaboration",
|
|
5
5
|
"author": "Myria Labs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -139,6 +139,7 @@
|
|
|
139
139
|
"qrcode": "1.5.4",
|
|
140
140
|
"sharp": "0.34.5",
|
|
141
141
|
"ssh2": "1.17.0",
|
|
142
|
+
"systeminformation": "5.33.1",
|
|
142
143
|
"typebox": "1.1.38"
|
|
143
144
|
},
|
|
144
145
|
"trustedDependencies": [
|
|
@@ -119,6 +119,29 @@ export const getModelsByEngine = (engine: EngineType): EngineModel[] => {
|
|
|
119
119
|
return modelRegistry.filter(model => model.engine.type === engine);
|
|
120
120
|
};
|
|
121
121
|
|
|
122
|
+
/** Display labels for the native reasoning/thinking level tokens across engines. */
|
|
123
|
+
const REASONING_LEVEL_LABELS: Record<string, string> = {
|
|
124
|
+
off: 'Off',
|
|
125
|
+
auto: 'Auto',
|
|
126
|
+
adaptive: 'Auto',
|
|
127
|
+
minimal: 'Minimal',
|
|
128
|
+
low: 'Low',
|
|
129
|
+
medium: 'Medium',
|
|
130
|
+
high: 'High',
|
|
131
|
+
xhigh: 'X-High',
|
|
132
|
+
max: 'Max',
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** Human label for a reasoning level token (falls back to capitalizing the token). */
|
|
136
|
+
export function reasoningLevelLabel(value: string): string {
|
|
137
|
+
return REASONING_LEVEL_LABELS[value] ?? value.charAt(0).toUpperCase() + value.slice(1);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Build ordered `{ value, label }` reasoning options from native level tokens. */
|
|
141
|
+
export function toReasoningOptions(values: readonly string[]): { value: string; label: string }[] {
|
|
142
|
+
return values.map((value) => ({ value, label: reasoningLevelLabel(value) }));
|
|
143
|
+
}
|
|
144
|
+
|
|
122
145
|
/** Get human-readable tags for a model (capabilities + input modalities) */
|
|
123
146
|
export function getModelTags(model: EngineModel): string[] {
|
|
124
147
|
const tags: string[] = [];
|
|
@@ -30,6 +30,7 @@ export interface ChatSession {
|
|
|
30
30
|
account_id?: number; // Engine account used for this session
|
|
31
31
|
account_name?: string; // Display name of the selected account
|
|
32
32
|
profile_id?: number | null; // Active Profile bundle for this session (null = use project default / none)
|
|
33
|
+
reasoning_effort?: string | null; // Reasoning/thinking level token (native per engine; null = engine default)
|
|
33
34
|
|
|
34
35
|
// ── HEAD state (re-derived when HEAD changes: undo/redo/restore/branch) ──
|
|
35
36
|
head_message_id?: string; // Git-like HEAD pointer to current branch tip
|
|
@@ -19,6 +19,11 @@ export interface CommitGeneratorSettings {
|
|
|
19
19
|
/** When false, uses the chat model (selectedEngine/selectedModel). When true, uses custom engine/model below. */
|
|
20
20
|
useCustomModel: boolean;
|
|
21
21
|
engine: EngineType;
|
|
22
|
+
/**
|
|
23
|
+
* Provider of `modelId`. Write it with `modelFieldsOf()` so it can never lag
|
|
24
|
+
* behind a model change — the backend re-derives it anyway
|
|
25
|
+
* (`backend/engine/resolve-model.ts`), but a stale value here is misleading.
|
|
26
|
+
*/
|
|
22
27
|
provider: string;
|
|
23
28
|
modelId: string;
|
|
24
29
|
modelName: string;
|
|
@@ -37,6 +42,7 @@ export interface CommitGeneratorSettings {
|
|
|
37
42
|
export interface ArtifactGeneratorSettings {
|
|
38
43
|
useCustomModel: boolean;
|
|
39
44
|
engine: EngineType;
|
|
45
|
+
/** See `CommitGeneratorSettings.provider` — write via `modelFieldsOf()`. */
|
|
40
46
|
provider: string;
|
|
41
47
|
modelId: string;
|
|
42
48
|
modelName: string;
|
|
@@ -71,6 +77,12 @@ export interface AppSettings {
|
|
|
71
77
|
artifactGenerator?: ArtifactGeneratorSettings;
|
|
72
78
|
/** Pinned model IDs — shown at top of provider group in model picker */
|
|
73
79
|
pinnedModels: string[];
|
|
80
|
+
/**
|
|
81
|
+
* Per-model reasoning/thinking level defaults, keyed by model id. Stores the
|
|
82
|
+
* native level token (e.g. 'high'). Seeds new sessions and remembers the last
|
|
83
|
+
* level chosen per model. Absent key → use the engine/model default.
|
|
84
|
+
*/
|
|
85
|
+
reasoningDefaults: Record<string, string>;
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
/** Authentication mode */
|
|
@@ -11,6 +11,33 @@ import type { MessageEngine } from './message';
|
|
|
11
11
|
// Re-export EngineType from common (canonical source)
|
|
12
12
|
export type { EngineType } from './common';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* One selectable reasoning/thinking level for a model.
|
|
16
|
+
*
|
|
17
|
+
* `value` is the opaque wire token handed back to the engine adapter (usually a
|
|
18
|
+
* native SDK level like `'medium'` or `'high'`; for Cursor it encodes the
|
|
19
|
+
* model-parameter id as `"<paramId>::<value>"` so the adapter can rebuild a
|
|
20
|
+
* `ModelSelection.params` entry). `label` is the human-facing text.
|
|
21
|
+
*/
|
|
22
|
+
export interface ReasoningOption {
|
|
23
|
+
value: string;
|
|
24
|
+
label: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Per-model reasoning/thinking-effort control. Present ONLY on models whose
|
|
29
|
+
* engine exposes a runtime knob (Claude `effort`/`thinking`, Codex
|
|
30
|
+
* `modelReasoningEffort`, Pi `thinkingLevel`, Copilot `reasoningEffort`, Cursor
|
|
31
|
+
* model params). Absent → the UI hides the selector and the engine's own
|
|
32
|
+
* default applies. Levels are native per engine (no cross-engine normalization).
|
|
33
|
+
*/
|
|
34
|
+
export interface ReasoningControl {
|
|
35
|
+
/** Selectable levels, ordered low → high. */
|
|
36
|
+
levels: ReasoningOption[];
|
|
37
|
+
/** The value applied when the user hasn't chosen one (mirrors the engine default). */
|
|
38
|
+
default: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
// Engine model definition
|
|
15
42
|
export interface EngineModel {
|
|
16
43
|
engine: MessageEngine;
|
|
@@ -41,6 +68,12 @@ export interface EngineModel {
|
|
|
41
68
|
reasoning: boolean;
|
|
42
69
|
tools: boolean;
|
|
43
70
|
structuredOutput: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Runtime reasoning-effort control for this model, when the engine exposes
|
|
73
|
+
* one. Undefined → no selector (engine default applies). See
|
|
74
|
+
* {@link ReasoningControl}.
|
|
75
|
+
*/
|
|
76
|
+
reasoningControl?: ReasoningControl;
|
|
44
77
|
/**
|
|
45
78
|
* Auth modes the model is compatible with. Models that require a
|
|
46
79
|
* ChatGPT (OAuth) login are flagged `'chatgpt'`; models that only
|
|
@@ -43,6 +43,12 @@ export interface MessageEngine {
|
|
|
43
43
|
provider: string;
|
|
44
44
|
model: MessageModel;
|
|
45
45
|
account: MessageAccount;
|
|
46
|
+
/**
|
|
47
|
+
* Reasoning/thinking level applied to this turn (native per engine — see
|
|
48
|
+
* `EngineModel.capabilities.reasoningControl`). Present only when the
|
|
49
|
+
* engine/model exposes a reasoning knob; absent for engines/models without one.
|
|
50
|
+
*/
|
|
51
|
+
reasoningEffort?: string | null;
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
/** Common fields present on every message */
|
|
@@ -176,6 +176,12 @@ export interface StreamRequest {
|
|
|
176
176
|
prompt: UserMessage;
|
|
177
177
|
engine: MessageEngine;
|
|
178
178
|
sender: MessageSender;
|
|
179
|
+
/**
|
|
180
|
+
* Reasoning/thinking level token chosen for this session (native per engine).
|
|
181
|
+
* `null`/absent → the engine's own default applies. Persisted to
|
|
182
|
+
* `chat_sessions.reasoning_effort` like engine/model.
|
|
183
|
+
*/
|
|
184
|
+
reasoningEffort?: string | null;
|
|
179
185
|
/**
|
|
180
186
|
* Active Profile chosen for this session (bundle of Skills/Commands/Subagents/
|
|
181
187
|
* MCP/Permissions). `null` = explicit "no profile"; `undefined` = client didn't
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser Action Handlers
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { browserPreviewServiceManager, type BrowserPreviewService } from "$backend/preview";
|
|
6
|
-
import type { BrowserAutonomousAction } from "$backend/preview/browser/types";
|
|
7
|
-
import { projectContextService } from "$backend/mcp/internal/project-context";
|
|
8
|
-
import { getActiveTabSession } from "./browser";
|
|
9
|
-
import { debug } from "$shared/utils/logger";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Get BrowserPreviewService for current MCP execution context
|
|
13
|
-
*/
|
|
14
|
-
function getPreviewService(projectId?: string): BrowserPreviewService {
|
|
15
|
-
// 1. Use explicit projectId if provided
|
|
16
|
-
if (projectId) {
|
|
17
|
-
debug.log('mcp', `Using explicit projectId: ${projectId}`);
|
|
18
|
-
return browserPreviewServiceManager.getService(projectId);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// 2. Try to get projectId from current execution context
|
|
22
|
-
const contextProjectId = projectContextService.getCurrentProjectId();
|
|
23
|
-
if (contextProjectId) {
|
|
24
|
-
debug.log('mcp', `Using projectId from context: ${contextProjectId}`);
|
|
25
|
-
return browserPreviewServiceManager.getService(contextProjectId);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// 3. Fallback: Get first available project's service
|
|
29
|
-
const activeProjects = browserPreviewServiceManager.getActiveProjects();
|
|
30
|
-
if (activeProjects.length > 0) {
|
|
31
|
-
const fallbackProjectId = activeProjects[0];
|
|
32
|
-
debug.warn('mcp', `⚠️ No project context found, falling back to first active project: ${fallbackProjectId}`);
|
|
33
|
-
return browserPreviewServiceManager.getService(fallbackProjectId);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
throw new Error('No active browser preview service found. Project isolation requires projectId.');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Define action types using discriminated union
|
|
40
|
-
type ClickAction = {
|
|
41
|
-
type: 'click';
|
|
42
|
-
x: number;
|
|
43
|
-
y: number;
|
|
44
|
-
click?: 'left' | 'right' | 'middle';
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type TypeAction = {
|
|
48
|
-
type: 'type';
|
|
49
|
-
text?: string; // text OR key (mutually exclusive)
|
|
50
|
-
key?: string; // text OR key (mutually exclusive)
|
|
51
|
-
clearFirst?: boolean;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type MoveAction = {
|
|
55
|
-
type: 'move';
|
|
56
|
-
x: number;
|
|
57
|
-
y: number;
|
|
58
|
-
steps?: number;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
type ScrollAction = {
|
|
62
|
-
type: 'scroll';
|
|
63
|
-
deltaX?: number; // deltaX or deltaY or both
|
|
64
|
-
deltaY?: number; // deltaX or deltaY or both
|
|
65
|
-
smooth?: boolean;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
type WaitAction = {
|
|
69
|
-
type: 'wait';
|
|
70
|
-
delay: number;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
type ExtractDataAction = {
|
|
74
|
-
type: 'extract_data';
|
|
75
|
-
selector: string;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
type BrowserAction =
|
|
79
|
-
| ClickAction
|
|
80
|
-
| TypeAction
|
|
81
|
-
| MoveAction
|
|
82
|
-
| ScrollAction
|
|
83
|
-
| WaitAction
|
|
84
|
-
| ExtractDataAction;
|
|
85
|
-
|
|
86
|
-
export async function actionsHandler(args: {
|
|
87
|
-
actions: BrowserAction[];
|
|
88
|
-
projectId?: string;
|
|
89
|
-
}) {
|
|
90
|
-
try {
|
|
91
|
-
// Get active tab and session
|
|
92
|
-
const { tab } = await getActiveTabSession(args.projectId);
|
|
93
|
-
const sessionId = tab.id;
|
|
94
|
-
|
|
95
|
-
// Get preview service
|
|
96
|
-
const previewService = getPreviewService(args.projectId);
|
|
97
|
-
|
|
98
|
-
// Process actions and apply MCP-optimized defaults
|
|
99
|
-
const processedActions: BrowserAutonomousAction[] = args.actions.map(action => {
|
|
100
|
-
const processed: BrowserAutonomousAction = { ...action } as any;
|
|
101
|
-
|
|
102
|
-
// Apply MCP-optimized default delay for type actions with text (30ms)
|
|
103
|
-
if (action.type === 'type' && 'text' in action && action.text && !('delay' in action)) {
|
|
104
|
-
(processed as any).delay = 30;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Apply clearFirst = true by default for MCP autonomous type actions
|
|
108
|
-
if (action.type === 'type' && 'text' in action && action.text && action.clearFirst === undefined) {
|
|
109
|
-
processed.clearFirst = true;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return processed;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Note: Cursor events are emitted by performAutonomousActions internally
|
|
116
|
-
// with proper delays between each action. No need to emit here.
|
|
117
|
-
// Pass the chat stream's AbortSignal so the action loop breaks the
|
|
118
|
-
// moment the user clicks interrupt — without this, multi-step click
|
|
119
|
-
// sequences keep firing for a few seconds after the engine subprocess
|
|
120
|
-
// dies (the "preview keeps moving by itself" symptom).
|
|
121
|
-
const abortSignal = projectContextService.getCurrentSignal();
|
|
122
|
-
const results = await previewService.performAutonomousActions(sessionId, processedActions, abortSignal);
|
|
123
|
-
|
|
124
|
-
// Format response with extracted data if any
|
|
125
|
-
const extractedData = results?.filter((r: any) => r.action === 'extract_data') || [];
|
|
126
|
-
|
|
127
|
-
let responseText = `Successfully performed ${args.actions.length} action(s) in sequence.`;
|
|
128
|
-
|
|
129
|
-
if (extractedData.length > 0) {
|
|
130
|
-
responseText += '\n\nExtracted Data:';
|
|
131
|
-
extractedData.forEach((item: any, idx: number) => {
|
|
132
|
-
if (item.error) {
|
|
133
|
-
responseText += `\n [${idx + 1}] Error from '${item.selector}': ${item.error}`;
|
|
134
|
-
} else if (item.data !== null && item.data !== undefined) {
|
|
135
|
-
const attrInfo = item.attribute ? ` (via ${item.attribute})` : '';
|
|
136
|
-
responseText += `\n [${idx + 1}] From '${item.selector}'${attrInfo}: ${item.data}`;
|
|
137
|
-
} else {
|
|
138
|
-
responseText += `\n [${idx + 1}] From '${item.selector}': (element not found or empty)`;
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
content: [{
|
|
145
|
-
type: "text" as const,
|
|
146
|
-
text: responseText
|
|
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: `Actions execution failed: ${errorMessage}`
|
|
155
|
-
}],
|
|
156
|
-
isError: true
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|