@midscene/computer-playground 1.17.7 → 1.17.8-beta-20261110095715.0
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/dist/es/109.mjs +183 -0
- package/dist/es/bin.mjs +3 -184
- package/dist/es/index.mjs +1 -183
- package/dist/lib/index.js +1 -1
- package/package.json +8 -8
- package/static/index.html +1 -1
- package/static/static/js/208.3403aeba.js +314 -0
- package/static/static/js/{799.7828433c.js.LICENSE.txt → 208.3403aeba.js.LICENSE.txt} +0 -4
- package/static/static/js/208.3403aeba.js.map +1 -0
- package/static/static/js/async/195.161da394.js +3 -0
- package/static/static/js/async/{195.0f8d6081.js.map → 195.161da394.js.map} +1 -1
- package/static/static/js/async/236.e8e04e6d.js +2 -0
- package/static/static/js/async/{236.a5d2c1b1.js.map → 236.e8e04e6d.js.map} +1 -1
- package/static/static/js/index.cb9a6e1e.js +897 -0
- package/static/static/js/index.cb9a6e1e.js.map +1 -0
- package/static/static/js/lib-react.f0532bd6.js +3 -0
- package/static/static/js/{lib-react.ee71e525.js.map → lib-react.f0532bd6.js.map} +1 -1
- package/static/static/js/799.7828433c.js +0 -315
- package/static/static/js/799.7828433c.js.map +0 -1
- package/static/static/js/async/195.0f8d6081.js +0 -3
- package/static/static/js/async/236.a5d2c1b1.js +0 -2
- package/static/static/js/index.c51aa5c1.js +0 -887
- package/static/static/js/index.c51aa5c1.js.map +0 -1
- package/static/static/js/lib-react.ee71e525.js +0 -3
- /package/static/static/js/{index.c51aa5c1.js.LICENSE.txt → index.cb9a6e1e.js.LICENSE.txt} +0 -0
- /package/static/static/js/{lib-react.ee71e525.js.LICENSE.txt → lib-react.f0532bd6.js.LICENSE.txt} +0 -0
package/dist/es/109.mjs
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { ComputerDevice, agentFromComputer, checkAccessibilityPermission, checkScreenRecordingPermission, getConnectedDisplays } from "@midscene/computer";
|
|
3
|
+
import { createScreenshotPreviewDescriptor, definePlaygroundPlatform, launchPreparedPlaygroundPlatform } from "@midscene/playground";
|
|
4
|
+
import { PLAYGROUND_SERVER_PORT } from "@midscene/shared/constants";
|
|
5
|
+
import { findAvailablePort } from "@midscene/shared/node";
|
|
6
|
+
const computerPlaygroundPlatform = definePlaygroundPlatform({
|
|
7
|
+
id: 'computer',
|
|
8
|
+
title: 'Midscene Computer Playground',
|
|
9
|
+
description: "Computer playground platform descriptor",
|
|
10
|
+
async prepare (options) {
|
|
11
|
+
const initialAccessibility = checkAccessibilityPermission(true);
|
|
12
|
+
const initialScreenRecording = checkScreenRecordingPermission(true);
|
|
13
|
+
const evaluatePermissions = ()=>{
|
|
14
|
+
const accessibilityCheck = checkAccessibilityPermission(false);
|
|
15
|
+
const screenRecordingCheck = checkScreenRecordingPermission(false);
|
|
16
|
+
const permissionError = !accessibilityCheck.hasPermission && accessibilityCheck.error || !screenRecordingCheck.hasPermission && screenRecordingCheck.error || void 0;
|
|
17
|
+
return {
|
|
18
|
+
accessibilityCheck,
|
|
19
|
+
screenRecordingCheck,
|
|
20
|
+
permissionError,
|
|
21
|
+
allPermissionsGranted: accessibilityCheck.hasPermission && screenRecordingCheck.hasPermission
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const staticDir = options?.staticDir || node_path.join(__dirname, '../../static');
|
|
25
|
+
const availablePort = await findAvailablePort(PLAYGROUND_SERVER_PORT);
|
|
26
|
+
if (availablePort !== PLAYGROUND_SERVER_PORT) console.log(`⚠️ Port ${PLAYGROUND_SERVER_PORT} is busy, using port ${availablePort} instead`);
|
|
27
|
+
const sessionManager = {
|
|
28
|
+
async getSetupSchema () {
|
|
29
|
+
const { allPermissionsGranted, permissionError } = evaluatePermissions();
|
|
30
|
+
const displays = await getConnectedDisplays();
|
|
31
|
+
const defaultDisplay = displays.find((display)=>display.primary) || displays[0];
|
|
32
|
+
return {
|
|
33
|
+
title: 'Connect Computer Agent',
|
|
34
|
+
description: allPermissionsGranted ? 'Create a Computer Agent for the selected display.' : permissionError,
|
|
35
|
+
primaryActionLabel: 'Create Agent',
|
|
36
|
+
fields: [
|
|
37
|
+
{
|
|
38
|
+
key: 'displayId',
|
|
39
|
+
label: 'Display',
|
|
40
|
+
type: 'select',
|
|
41
|
+
required: true,
|
|
42
|
+
options: displays.map((display)=>({
|
|
43
|
+
label: display.name,
|
|
44
|
+
value: String(display.id),
|
|
45
|
+
description: display.primary ? 'Primary display' : void 0
|
|
46
|
+
})),
|
|
47
|
+
defaultValue: defaultDisplay ? String(defaultDisplay.id) : '',
|
|
48
|
+
placeholder: 'Select a display'
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
targets: displays.map((display)=>({
|
|
52
|
+
id: String(display.id),
|
|
53
|
+
label: display.name,
|
|
54
|
+
description: display.primary ? 'Primary display' : void 0,
|
|
55
|
+
isDefault: display.primary
|
|
56
|
+
}))
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
async listTargets () {
|
|
60
|
+
const displays = await getConnectedDisplays();
|
|
61
|
+
return displays.map((display)=>({
|
|
62
|
+
id: String(display.id),
|
|
63
|
+
label: display.name,
|
|
64
|
+
description: display.primary ? 'Primary display' : void 0,
|
|
65
|
+
isDefault: display.primary
|
|
66
|
+
}));
|
|
67
|
+
},
|
|
68
|
+
async createSession (input) {
|
|
69
|
+
const { allPermissionsGranted, permissionError } = evaluatePermissions();
|
|
70
|
+
if (!allPermissionsGranted) throw new Error(permissionError || 'Accessibility and Screen Recording permissions are required');
|
|
71
|
+
const displayId = input?.displayId === void 0 || null === input.displayId ? void 0 : String(input.displayId);
|
|
72
|
+
const agent = await agentFromComputer({
|
|
73
|
+
...options?.getAgentOptions?.(),
|
|
74
|
+
...displayId ? {
|
|
75
|
+
displayId
|
|
76
|
+
} : {}
|
|
77
|
+
});
|
|
78
|
+
const displays = await getConnectedDisplays();
|
|
79
|
+
const selectedDisplay = displays.find((display)=>display.id === displayId) || displays.find((display)=>display.primary) || displays[0];
|
|
80
|
+
return {
|
|
81
|
+
agent,
|
|
82
|
+
agentFactory: ()=>agentFromComputer({
|
|
83
|
+
...options?.getAgentOptions?.(),
|
|
84
|
+
...selectedDisplay ? {
|
|
85
|
+
displayId: selectedDisplay.id
|
|
86
|
+
} : {}
|
|
87
|
+
}),
|
|
88
|
+
preview: createScreenshotPreviewDescriptor({
|
|
89
|
+
title: 'Desktop preview'
|
|
90
|
+
}),
|
|
91
|
+
displayName: selectedDisplay?.name || 'Desktop',
|
|
92
|
+
metadata: {
|
|
93
|
+
displayId: selectedDisplay?.id,
|
|
94
|
+
executionUx: 'countdown-before-run'
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
platformId: 'computer',
|
|
101
|
+
title: 'Midscene Computer Playground',
|
|
102
|
+
sessionManager,
|
|
103
|
+
launchOptions: {
|
|
104
|
+
port: availablePort,
|
|
105
|
+
openBrowser: false,
|
|
106
|
+
verbose: false,
|
|
107
|
+
staticPath: staticDir
|
|
108
|
+
},
|
|
109
|
+
executionHooks: {
|
|
110
|
+
async beforeExecute () {
|
|
111
|
+
const windowController = options?.getWindowController?.();
|
|
112
|
+
if (!windowController) return void console.warn('⚠️ Window controller not initialized yet, skipping window control');
|
|
113
|
+
await new Promise((resolve)=>setTimeout(resolve, 1500));
|
|
114
|
+
await windowController.minimize();
|
|
115
|
+
},
|
|
116
|
+
async afterExecute () {
|
|
117
|
+
const windowController = options?.getWindowController?.();
|
|
118
|
+
if (!windowController) return;
|
|
119
|
+
await windowController.restore();
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
preview: createScreenshotPreviewDescriptor({
|
|
123
|
+
title: 'Desktop preview'
|
|
124
|
+
}),
|
|
125
|
+
metadata: {
|
|
126
|
+
executionUx: 'countdown-before-run',
|
|
127
|
+
sessionConnected: false,
|
|
128
|
+
setupState: initialAccessibility.hasPermission && initialScreenRecording.hasPermission ? 'required' : 'blocked',
|
|
129
|
+
setupBlockingReason: !initialAccessibility.hasPermission && initialAccessibility.error || !initialScreenRecording.hasPermission && initialScreenRecording.error || void 0
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
function _define_property(obj, key, value) {
|
|
135
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
136
|
+
value: value,
|
|
137
|
+
enumerable: true,
|
|
138
|
+
configurable: true,
|
|
139
|
+
writable: true
|
|
140
|
+
});
|
|
141
|
+
else obj[key] = value;
|
|
142
|
+
return obj;
|
|
143
|
+
}
|
|
144
|
+
class BrowserWindowController {
|
|
145
|
+
async minimize() {
|
|
146
|
+
try {
|
|
147
|
+
await this.session.send('Browser.setWindowBounds', {
|
|
148
|
+
windowId: this.windowId,
|
|
149
|
+
bounds: {
|
|
150
|
+
windowState: 'minimized'
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
console.log('🔽 Window minimized, starting task execution...');
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.warn('⚠️ Failed to minimize window:', error);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async restore() {
|
|
159
|
+
try {
|
|
160
|
+
await Promise.all([
|
|
161
|
+
this.session.send('Browser.setWindowBounds', {
|
|
162
|
+
windowId: this.windowId,
|
|
163
|
+
bounds: {
|
|
164
|
+
windowState: 'normal'
|
|
165
|
+
}
|
|
166
|
+
}),
|
|
167
|
+
this.page.bringToFront()
|
|
168
|
+
]);
|
|
169
|
+
console.log('🔼 Window restored');
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.warn('⚠️ Failed to restore window:', error);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
constructor(session, page, windowId){
|
|
175
|
+
_define_property(this, "session", void 0);
|
|
176
|
+
_define_property(this, "page", void 0);
|
|
177
|
+
_define_property(this, "windowId", void 0);
|
|
178
|
+
this.session = session;
|
|
179
|
+
this.page = page;
|
|
180
|
+
this.windowId = windowId;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export { BrowserWindowController, ComputerDevice, computerPlaygroundPlatform, launchPreparedPlaygroundPlatform, node_path };
|
package/dist/es/bin.mjs
CHANGED
|
@@ -1,188 +1,7 @@
|
|
|
1
1
|
import node_os from "node:os";
|
|
2
|
-
import node_path from "node:path";
|
|
3
|
-
import { ComputerDevice, agentFromComputer, checkAccessibilityPermission, checkScreenRecordingPermission, getConnectedDisplays } from "@midscene/computer";
|
|
4
|
-
import { createScreenshotPreviewDescriptor, definePlaygroundPlatform, launchPreparedPlaygroundPlatform } from "@midscene/playground";
|
|
5
2
|
import puppeteer from "puppeteer";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
function _define_property(obj, key, value) {
|
|
9
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
10
|
-
value: value,
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true
|
|
14
|
-
});
|
|
15
|
-
else obj[key] = value;
|
|
16
|
-
return obj;
|
|
17
|
-
}
|
|
18
|
-
class BrowserWindowController {
|
|
19
|
-
async minimize() {
|
|
20
|
-
try {
|
|
21
|
-
await this.session.send('Browser.setWindowBounds', {
|
|
22
|
-
windowId: this.windowId,
|
|
23
|
-
bounds: {
|
|
24
|
-
windowState: 'minimized'
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
console.log('🔽 Window minimized, starting task execution...');
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.warn('⚠️ Failed to minimize window:', error);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async restore() {
|
|
33
|
-
try {
|
|
34
|
-
await Promise.all([
|
|
35
|
-
this.session.send('Browser.setWindowBounds', {
|
|
36
|
-
windowId: this.windowId,
|
|
37
|
-
bounds: {
|
|
38
|
-
windowState: 'normal'
|
|
39
|
-
}
|
|
40
|
-
}),
|
|
41
|
-
this.page.bringToFront()
|
|
42
|
-
]);
|
|
43
|
-
console.log('🔼 Window restored');
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.warn('⚠️ Failed to restore window:', error);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
constructor(session, page, windowId){
|
|
49
|
-
_define_property(this, "session", void 0);
|
|
50
|
-
_define_property(this, "page", void 0);
|
|
51
|
-
_define_property(this, "windowId", void 0);
|
|
52
|
-
this.session = session;
|
|
53
|
-
this.page = page;
|
|
54
|
-
this.windowId = windowId;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const computerPlaygroundPlatform = definePlaygroundPlatform({
|
|
58
|
-
id: 'computer',
|
|
59
|
-
title: 'Midscene Computer Playground',
|
|
60
|
-
description: "Computer playground platform descriptor",
|
|
61
|
-
async prepare (options) {
|
|
62
|
-
const initialAccessibility = checkAccessibilityPermission(true);
|
|
63
|
-
const initialScreenRecording = checkScreenRecordingPermission(true);
|
|
64
|
-
const evaluatePermissions = ()=>{
|
|
65
|
-
const accessibilityCheck = checkAccessibilityPermission(false);
|
|
66
|
-
const screenRecordingCheck = checkScreenRecordingPermission(false);
|
|
67
|
-
const permissionError = !accessibilityCheck.hasPermission && accessibilityCheck.error || !screenRecordingCheck.hasPermission && screenRecordingCheck.error || void 0;
|
|
68
|
-
return {
|
|
69
|
-
accessibilityCheck,
|
|
70
|
-
screenRecordingCheck,
|
|
71
|
-
permissionError,
|
|
72
|
-
allPermissionsGranted: accessibilityCheck.hasPermission && screenRecordingCheck.hasPermission
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
const staticDir = options?.staticDir || node_path.join(__dirname, '../../static');
|
|
76
|
-
const availablePort = await findAvailablePort(PLAYGROUND_SERVER_PORT);
|
|
77
|
-
if (availablePort !== PLAYGROUND_SERVER_PORT) console.log(`⚠️ Port ${PLAYGROUND_SERVER_PORT} is busy, using port ${availablePort} instead`);
|
|
78
|
-
const sessionManager = {
|
|
79
|
-
async getSetupSchema () {
|
|
80
|
-
const { allPermissionsGranted, permissionError } = evaluatePermissions();
|
|
81
|
-
const displays = await getConnectedDisplays();
|
|
82
|
-
const defaultDisplay = displays.find((display)=>display.primary) || displays[0];
|
|
83
|
-
return {
|
|
84
|
-
title: 'Connect Computer Agent',
|
|
85
|
-
description: allPermissionsGranted ? 'Create a Computer Agent for the selected display.' : permissionError,
|
|
86
|
-
primaryActionLabel: 'Create Agent',
|
|
87
|
-
fields: [
|
|
88
|
-
{
|
|
89
|
-
key: 'displayId',
|
|
90
|
-
label: 'Display',
|
|
91
|
-
type: 'select',
|
|
92
|
-
required: true,
|
|
93
|
-
options: displays.map((display)=>({
|
|
94
|
-
label: display.name,
|
|
95
|
-
value: String(display.id),
|
|
96
|
-
description: display.primary ? 'Primary display' : void 0
|
|
97
|
-
})),
|
|
98
|
-
defaultValue: defaultDisplay ? String(defaultDisplay.id) : '',
|
|
99
|
-
placeholder: 'Select a display'
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
|
-
targets: displays.map((display)=>({
|
|
103
|
-
id: String(display.id),
|
|
104
|
-
label: display.name,
|
|
105
|
-
description: display.primary ? 'Primary display' : void 0,
|
|
106
|
-
isDefault: display.primary
|
|
107
|
-
}))
|
|
108
|
-
};
|
|
109
|
-
},
|
|
110
|
-
async listTargets () {
|
|
111
|
-
const displays = await getConnectedDisplays();
|
|
112
|
-
return displays.map((display)=>({
|
|
113
|
-
id: String(display.id),
|
|
114
|
-
label: display.name,
|
|
115
|
-
description: display.primary ? 'Primary display' : void 0,
|
|
116
|
-
isDefault: display.primary
|
|
117
|
-
}));
|
|
118
|
-
},
|
|
119
|
-
async createSession (input) {
|
|
120
|
-
const { allPermissionsGranted, permissionError } = evaluatePermissions();
|
|
121
|
-
if (!allPermissionsGranted) throw new Error(permissionError || 'Accessibility and Screen Recording permissions are required');
|
|
122
|
-
const displayId = input?.displayId === void 0 || null === input.displayId ? void 0 : String(input.displayId);
|
|
123
|
-
const agent = await agentFromComputer({
|
|
124
|
-
...options?.getAgentOptions?.(),
|
|
125
|
-
...displayId ? {
|
|
126
|
-
displayId
|
|
127
|
-
} : {}
|
|
128
|
-
});
|
|
129
|
-
const displays = await getConnectedDisplays();
|
|
130
|
-
const selectedDisplay = displays.find((display)=>display.id === displayId) || displays.find((display)=>display.primary) || displays[0];
|
|
131
|
-
return {
|
|
132
|
-
agent,
|
|
133
|
-
agentFactory: ()=>agentFromComputer({
|
|
134
|
-
...options?.getAgentOptions?.(),
|
|
135
|
-
...selectedDisplay ? {
|
|
136
|
-
displayId: selectedDisplay.id
|
|
137
|
-
} : {}
|
|
138
|
-
}),
|
|
139
|
-
preview: createScreenshotPreviewDescriptor({
|
|
140
|
-
title: 'Desktop preview'
|
|
141
|
-
}),
|
|
142
|
-
displayName: selectedDisplay?.name || 'Desktop',
|
|
143
|
-
metadata: {
|
|
144
|
-
displayId: selectedDisplay?.id,
|
|
145
|
-
executionUx: 'countdown-before-run'
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
return {
|
|
151
|
-
platformId: 'computer',
|
|
152
|
-
title: 'Midscene Computer Playground',
|
|
153
|
-
sessionManager,
|
|
154
|
-
launchOptions: {
|
|
155
|
-
port: availablePort,
|
|
156
|
-
openBrowser: false,
|
|
157
|
-
verbose: false,
|
|
158
|
-
staticPath: staticDir
|
|
159
|
-
},
|
|
160
|
-
executionHooks: {
|
|
161
|
-
async beforeExecute () {
|
|
162
|
-
const windowController = options?.getWindowController?.();
|
|
163
|
-
if (!windowController) return void console.warn('⚠️ Window controller not initialized yet, skipping window control');
|
|
164
|
-
await new Promise((resolve)=>setTimeout(resolve, 1500));
|
|
165
|
-
await windowController.minimize();
|
|
166
|
-
},
|
|
167
|
-
async afterExecute () {
|
|
168
|
-
const windowController = options?.getWindowController?.();
|
|
169
|
-
if (!windowController) return;
|
|
170
|
-
await windowController.restore();
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
preview: createScreenshotPreviewDescriptor({
|
|
174
|
-
title: 'Desktop preview'
|
|
175
|
-
}),
|
|
176
|
-
metadata: {
|
|
177
|
-
executionUx: 'countdown-before-run',
|
|
178
|
-
sessionConnected: false,
|
|
179
|
-
setupState: initialAccessibility.hasPermission && initialScreenRecording.hasPermission ? 'required' : 'blocked',
|
|
180
|
-
setupBlockingReason: !initialAccessibility.hasPermission && initialAccessibility.error || !initialScreenRecording.hasPermission && initialScreenRecording.error || void 0
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
const bin_staticDir = node_path.join(__dirname, '../../static');
|
|
3
|
+
import { BrowserWindowController, node_path, launchPreparedPlaygroundPlatform, computerPlaygroundPlatform, ComputerDevice } from "./109.mjs";
|
|
4
|
+
const staticDir = node_path.join(__dirname, '../../static');
|
|
186
5
|
const main = async ()=>{
|
|
187
6
|
try {
|
|
188
7
|
const displays = await ComputerDevice.listDisplays();
|
|
@@ -193,7 +12,7 @@ const main = async ()=>{
|
|
|
193
12
|
let windowController = null;
|
|
194
13
|
console.log('🚀 Starting server...');
|
|
195
14
|
const prepared = await computerPlaygroundPlatform.prepare({
|
|
196
|
-
staticDir:
|
|
15
|
+
staticDir: staticDir,
|
|
197
16
|
getWindowController: ()=>windowController
|
|
198
17
|
});
|
|
199
18
|
const { server: playgroundServer } = await launchPreparedPlaygroundPlatform(prepared);
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,183 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { agentFromComputer, checkAccessibilityPermission, checkScreenRecordingPermission, getConnectedDisplays } from "@midscene/computer";
|
|
3
|
-
import { createScreenshotPreviewDescriptor, definePlaygroundPlatform } from "@midscene/playground";
|
|
4
|
-
import { PLAYGROUND_SERVER_PORT } from "@midscene/shared/constants";
|
|
5
|
-
import { findAvailablePort } from "@midscene/shared/node";
|
|
6
|
-
const computerPlaygroundPlatform = definePlaygroundPlatform({
|
|
7
|
-
id: 'computer',
|
|
8
|
-
title: 'Midscene Computer Playground',
|
|
9
|
-
description: "Computer playground platform descriptor",
|
|
10
|
-
async prepare (options) {
|
|
11
|
-
const initialAccessibility = checkAccessibilityPermission(true);
|
|
12
|
-
const initialScreenRecording = checkScreenRecordingPermission(true);
|
|
13
|
-
const evaluatePermissions = ()=>{
|
|
14
|
-
const accessibilityCheck = checkAccessibilityPermission(false);
|
|
15
|
-
const screenRecordingCheck = checkScreenRecordingPermission(false);
|
|
16
|
-
const permissionError = !accessibilityCheck.hasPermission && accessibilityCheck.error || !screenRecordingCheck.hasPermission && screenRecordingCheck.error || void 0;
|
|
17
|
-
return {
|
|
18
|
-
accessibilityCheck,
|
|
19
|
-
screenRecordingCheck,
|
|
20
|
-
permissionError,
|
|
21
|
-
allPermissionsGranted: accessibilityCheck.hasPermission && screenRecordingCheck.hasPermission
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
const staticDir = options?.staticDir || node_path.join(__dirname, '../../static');
|
|
25
|
-
const availablePort = await findAvailablePort(PLAYGROUND_SERVER_PORT);
|
|
26
|
-
if (availablePort !== PLAYGROUND_SERVER_PORT) console.log(`⚠️ Port ${PLAYGROUND_SERVER_PORT} is busy, using port ${availablePort} instead`);
|
|
27
|
-
const sessionManager = {
|
|
28
|
-
async getSetupSchema () {
|
|
29
|
-
const { allPermissionsGranted, permissionError } = evaluatePermissions();
|
|
30
|
-
const displays = await getConnectedDisplays();
|
|
31
|
-
const defaultDisplay = displays.find((display)=>display.primary) || displays[0];
|
|
32
|
-
return {
|
|
33
|
-
title: 'Connect Computer Agent',
|
|
34
|
-
description: allPermissionsGranted ? 'Create a Computer Agent for the selected display.' : permissionError,
|
|
35
|
-
primaryActionLabel: 'Create Agent',
|
|
36
|
-
fields: [
|
|
37
|
-
{
|
|
38
|
-
key: 'displayId',
|
|
39
|
-
label: 'Display',
|
|
40
|
-
type: 'select',
|
|
41
|
-
required: true,
|
|
42
|
-
options: displays.map((display)=>({
|
|
43
|
-
label: display.name,
|
|
44
|
-
value: String(display.id),
|
|
45
|
-
description: display.primary ? 'Primary display' : void 0
|
|
46
|
-
})),
|
|
47
|
-
defaultValue: defaultDisplay ? String(defaultDisplay.id) : '',
|
|
48
|
-
placeholder: 'Select a display'
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
targets: displays.map((display)=>({
|
|
52
|
-
id: String(display.id),
|
|
53
|
-
label: display.name,
|
|
54
|
-
description: display.primary ? 'Primary display' : void 0,
|
|
55
|
-
isDefault: display.primary
|
|
56
|
-
}))
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
async listTargets () {
|
|
60
|
-
const displays = await getConnectedDisplays();
|
|
61
|
-
return displays.map((display)=>({
|
|
62
|
-
id: String(display.id),
|
|
63
|
-
label: display.name,
|
|
64
|
-
description: display.primary ? 'Primary display' : void 0,
|
|
65
|
-
isDefault: display.primary
|
|
66
|
-
}));
|
|
67
|
-
},
|
|
68
|
-
async createSession (input) {
|
|
69
|
-
const { allPermissionsGranted, permissionError } = evaluatePermissions();
|
|
70
|
-
if (!allPermissionsGranted) throw new Error(permissionError || 'Accessibility and Screen Recording permissions are required');
|
|
71
|
-
const displayId = input?.displayId === void 0 || null === input.displayId ? void 0 : String(input.displayId);
|
|
72
|
-
const agent = await agentFromComputer({
|
|
73
|
-
...options?.getAgentOptions?.(),
|
|
74
|
-
...displayId ? {
|
|
75
|
-
displayId
|
|
76
|
-
} : {}
|
|
77
|
-
});
|
|
78
|
-
const displays = await getConnectedDisplays();
|
|
79
|
-
const selectedDisplay = displays.find((display)=>display.id === displayId) || displays.find((display)=>display.primary) || displays[0];
|
|
80
|
-
return {
|
|
81
|
-
agent,
|
|
82
|
-
agentFactory: ()=>agentFromComputer({
|
|
83
|
-
...options?.getAgentOptions?.(),
|
|
84
|
-
...selectedDisplay ? {
|
|
85
|
-
displayId: selectedDisplay.id
|
|
86
|
-
} : {}
|
|
87
|
-
}),
|
|
88
|
-
preview: createScreenshotPreviewDescriptor({
|
|
89
|
-
title: 'Desktop preview'
|
|
90
|
-
}),
|
|
91
|
-
displayName: selectedDisplay?.name || 'Desktop',
|
|
92
|
-
metadata: {
|
|
93
|
-
displayId: selectedDisplay?.id,
|
|
94
|
-
executionUx: 'countdown-before-run'
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
return {
|
|
100
|
-
platformId: 'computer',
|
|
101
|
-
title: 'Midscene Computer Playground',
|
|
102
|
-
sessionManager,
|
|
103
|
-
launchOptions: {
|
|
104
|
-
port: availablePort,
|
|
105
|
-
openBrowser: false,
|
|
106
|
-
verbose: false,
|
|
107
|
-
staticPath: staticDir
|
|
108
|
-
},
|
|
109
|
-
executionHooks: {
|
|
110
|
-
async beforeExecute () {
|
|
111
|
-
const windowController = options?.getWindowController?.();
|
|
112
|
-
if (!windowController) return void console.warn('⚠️ Window controller not initialized yet, skipping window control');
|
|
113
|
-
await new Promise((resolve)=>setTimeout(resolve, 1500));
|
|
114
|
-
await windowController.minimize();
|
|
115
|
-
},
|
|
116
|
-
async afterExecute () {
|
|
117
|
-
const windowController = options?.getWindowController?.();
|
|
118
|
-
if (!windowController) return;
|
|
119
|
-
await windowController.restore();
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
preview: createScreenshotPreviewDescriptor({
|
|
123
|
-
title: 'Desktop preview'
|
|
124
|
-
}),
|
|
125
|
-
metadata: {
|
|
126
|
-
executionUx: 'countdown-before-run',
|
|
127
|
-
sessionConnected: false,
|
|
128
|
-
setupState: initialAccessibility.hasPermission && initialScreenRecording.hasPermission ? 'required' : 'blocked',
|
|
129
|
-
setupBlockingReason: !initialAccessibility.hasPermission && initialAccessibility.error || !initialScreenRecording.hasPermission && initialScreenRecording.error || void 0
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
function _define_property(obj, key, value) {
|
|
135
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
136
|
-
value: value,
|
|
137
|
-
enumerable: true,
|
|
138
|
-
configurable: true,
|
|
139
|
-
writable: true
|
|
140
|
-
});
|
|
141
|
-
else obj[key] = value;
|
|
142
|
-
return obj;
|
|
143
|
-
}
|
|
144
|
-
class BrowserWindowController {
|
|
145
|
-
async minimize() {
|
|
146
|
-
try {
|
|
147
|
-
await this.session.send('Browser.setWindowBounds', {
|
|
148
|
-
windowId: this.windowId,
|
|
149
|
-
bounds: {
|
|
150
|
-
windowState: 'minimized'
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
console.log('🔽 Window minimized, starting task execution...');
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.warn('⚠️ Failed to minimize window:', error);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
async restore() {
|
|
159
|
-
try {
|
|
160
|
-
await Promise.all([
|
|
161
|
-
this.session.send('Browser.setWindowBounds', {
|
|
162
|
-
windowId: this.windowId,
|
|
163
|
-
bounds: {
|
|
164
|
-
windowState: 'normal'
|
|
165
|
-
}
|
|
166
|
-
}),
|
|
167
|
-
this.page.bringToFront()
|
|
168
|
-
]);
|
|
169
|
-
console.log('🔼 Window restored');
|
|
170
|
-
} catch (error) {
|
|
171
|
-
console.warn('⚠️ Failed to restore window:', error);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
constructor(session, page, windowId){
|
|
175
|
-
_define_property(this, "session", void 0);
|
|
176
|
-
_define_property(this, "page", void 0);
|
|
177
|
-
_define_property(this, "windowId", void 0);
|
|
178
|
-
this.session = session;
|
|
179
|
-
this.page = page;
|
|
180
|
-
this.windowId = windowId;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
export { BrowserWindowController, computerPlaygroundPlatform };
|
|
1
|
+
export { BrowserWindowController, computerPlaygroundPlatform } from "./109.mjs";
|
package/dist/lib/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __webpack_require__ = {};
|
|
|
22
22
|
})();
|
|
23
23
|
(()=>{
|
|
24
24
|
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if (
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
26
|
value: 'Module'
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports1, '__esModule', {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/computer-playground",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.8-beta-20261110095715.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/midscene.git",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"cors": "^2.8.5",
|
|
25
|
-
"express": "^4.
|
|
26
|
-
"puppeteer": "24.
|
|
27
|
-
"@midscene/computer": "1.17.
|
|
28
|
-
"@midscene/
|
|
29
|
-
"@midscene/
|
|
30
|
-
"@midscene/shared": "1.17.
|
|
25
|
+
"express": "^4.22.3",
|
|
26
|
+
"puppeteer": "24.43.1",
|
|
27
|
+
"@midscene/computer": "1.17.8-beta-20261110095715.0",
|
|
28
|
+
"@midscene/core": "1.17.8-beta-20261110095715.0",
|
|
29
|
+
"@midscene/playground": "1.17.8-beta-20261110095715.0",
|
|
30
|
+
"@midscene/shared": "1.17.8-beta-20261110095715.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@rslib/core": "
|
|
33
|
+
"@rslib/core": "~0.19.6",
|
|
34
34
|
"@rstest/core": "0.12.0",
|
|
35
35
|
"@types/cors": "^2.8.17",
|
|
36
36
|
"@types/express": "^4.17.21",
|
package/static/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!
|
|
1
|
+
<!DOCTYPE html><html><head><title>Midscene Computer Playground</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.f0532bd6.js"></script><script defer src="/static/js/208.3403aeba.js"></script><script defer src="/static/js/index.cb9a6e1e.js"></script><link href="/static/css/index.67caac18.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
|