@midscene/playground 0.27.6-beta-20250831000753.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/LICENSE +21 -0
- package/dist/es/common.mjs +128 -0
- package/dist/es/common.mjs.map +1 -0
- package/dist/es/index.browser.mjs +7 -0
- package/dist/es/index.browser.mjs.map +1 -0
- package/dist/es/index.mjs +5 -0
- package/dist/es/server.mjs +261 -0
- package/dist/es/server.mjs.map +1 -0
- package/dist/es/static-agent.mjs +10 -0
- package/dist/es/static-agent.mjs.map +1 -0
- package/dist/es/static-page.mjs +129 -0
- package/dist/es/static-page.mjs.map +1 -0
- package/dist/es/types.mjs +0 -0
- package/dist/lib/common.js +177 -0
- package/dist/lib/common.js.map +1 -0
- package/dist/lib/index.browser.js +75 -0
- package/dist/lib/index.browser.js.map +1 -0
- package/dist/lib/index.js +76 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/server.js +307 -0
- package/dist/lib/server.js.map +1 -0
- package/dist/lib/static-agent.js +44 -0
- package/dist/lib/static-agent.js.map +1 -0
- package/dist/lib/static-page.js +163 -0
- package/dist/lib/static-page.js.map +1 -0
- package/dist/lib/types.js +20 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/types/common.d.ts +8 -0
- package/dist/types/index.browser.d.ts +5 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/server.d.ts +20 -0
- package/dist/types/static-agent.d.ts +5 -0
- package/dist/types/static-page.d.ts +51 -0
- package/dist/types/types.d.ts +31 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Bytedance, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { findAllMidsceneLocatorField } from "@midscene/core/ai-model";
|
|
2
|
+
const dataExtractionAPIs = [
|
|
3
|
+
'aiQuery',
|
|
4
|
+
'aiBoolean',
|
|
5
|
+
'aiNumber',
|
|
6
|
+
'aiString',
|
|
7
|
+
'aiAsk'
|
|
8
|
+
];
|
|
9
|
+
const validationAPIs = [
|
|
10
|
+
'aiAssert',
|
|
11
|
+
'aiWaitFor'
|
|
12
|
+
];
|
|
13
|
+
const noReplayAPIs = [
|
|
14
|
+
...dataExtractionAPIs,
|
|
15
|
+
...validationAPIs
|
|
16
|
+
];
|
|
17
|
+
const formatErrorMessage = (e)=>{
|
|
18
|
+
const errorMessage = (null == e ? void 0 : e.message) || '';
|
|
19
|
+
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';
|
|
20
|
+
return errorMessage || 'Unknown error';
|
|
21
|
+
};
|
|
22
|
+
async function parseStructuredParams(action, params, options = {}) {
|
|
23
|
+
if (!(null == action ? void 0 : action.paramSchema) || !('shape' in action.paramSchema)) return [
|
|
24
|
+
params.prompt || '',
|
|
25
|
+
options
|
|
26
|
+
];
|
|
27
|
+
const schema = action.paramSchema;
|
|
28
|
+
const keys = schema && 'shape' in schema ? Object.keys(schema.shape) : [];
|
|
29
|
+
const paramObj = {
|
|
30
|
+
...options
|
|
31
|
+
};
|
|
32
|
+
keys.forEach((key)=>{
|
|
33
|
+
if (void 0 !== params[key] && null !== params[key] && '' !== params[key]) paramObj[key] = params[key];
|
|
34
|
+
});
|
|
35
|
+
return [
|
|
36
|
+
paramObj
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
function validateStructuredParams(value, action) {
|
|
40
|
+
if (!value.params) return {
|
|
41
|
+
valid: false,
|
|
42
|
+
errorMessage: 'Parameters are required'
|
|
43
|
+
};
|
|
44
|
+
if (!(null == action ? void 0 : action.paramSchema)) return {
|
|
45
|
+
valid: true
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
var _action_paramSchema;
|
|
49
|
+
const paramsForValidation = {
|
|
50
|
+
...value.params
|
|
51
|
+
};
|
|
52
|
+
const schema = action.paramSchema;
|
|
53
|
+
if (schema) {
|
|
54
|
+
const locatorFieldKeys = findAllMidsceneLocatorField(schema);
|
|
55
|
+
locatorFieldKeys.forEach((key)=>{
|
|
56
|
+
if ('string' == typeof paramsForValidation[key]) paramsForValidation[key] = {
|
|
57
|
+
midscene_location_field_flag: true,
|
|
58
|
+
prompt: paramsForValidation[key],
|
|
59
|
+
center: [
|
|
60
|
+
0,
|
|
61
|
+
0
|
|
62
|
+
],
|
|
63
|
+
rect: {
|
|
64
|
+
left: 0,
|
|
65
|
+
top: 0,
|
|
66
|
+
width: 0,
|
|
67
|
+
height: 0
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
null == (_action_paramSchema = action.paramSchema) || _action_paramSchema.parse(paramsForValidation);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const zodError = error;
|
|
75
|
+
if (zodError.errors && zodError.errors.length > 0) {
|
|
76
|
+
const errorMessages = zodError.errors.filter((err)=>{
|
|
77
|
+
const path = err.path.join('.');
|
|
78
|
+
return !path.includes('center') && !path.includes('rect') && !path.includes('midscene_location_field_flag');
|
|
79
|
+
}).map((err)=>{
|
|
80
|
+
const field = err.path.join('.');
|
|
81
|
+
return `${field}: ${err.message}`;
|
|
82
|
+
});
|
|
83
|
+
if (errorMessages.length > 0) return {
|
|
84
|
+
valid: false,
|
|
85
|
+
errorMessage: `Validation error: ${errorMessages.join(', ')}`
|
|
86
|
+
};
|
|
87
|
+
} else {
|
|
88
|
+
const errorMsg = error instanceof Error ? error.message : 'Unknown validation error';
|
|
89
|
+
return {
|
|
90
|
+
valid: false,
|
|
91
|
+
errorMessage: `Parameter validation failed: ${errorMsg}`
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
valid: true
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async function executeAction(activeAgent, actionType, actionSpace, value, options) {
|
|
100
|
+
const action = null == actionSpace ? void 0 : actionSpace.find((a)=>a.interfaceAlias === actionType || a.name === actionType);
|
|
101
|
+
if (action && 'function' == typeof activeAgent.callActionInActionSpace) if (!value.params) return await activeAgent.callActionInActionSpace(action.name, {
|
|
102
|
+
prompt: value.prompt,
|
|
103
|
+
...options
|
|
104
|
+
});
|
|
105
|
+
else {
|
|
106
|
+
const parsedParams = await parseStructuredParams(action, value.params, options);
|
|
107
|
+
return await activeAgent.callActionInActionSpace(action.name, parsedParams[0]);
|
|
108
|
+
}
|
|
109
|
+
{
|
|
110
|
+
const prompt = value.prompt;
|
|
111
|
+
if ('aiAssert' === actionType) {
|
|
112
|
+
var _activeAgent_aiAssert;
|
|
113
|
+
const { pass, thought } = await (null == activeAgent ? void 0 : null == (_activeAgent_aiAssert = activeAgent.aiAssert) ? void 0 : _activeAgent_aiAssert.call(activeAgent, prompt || '', void 0, {
|
|
114
|
+
keepRawResponse: true,
|
|
115
|
+
...options
|
|
116
|
+
})) || {};
|
|
117
|
+
return {
|
|
118
|
+
pass: pass || false,
|
|
119
|
+
thought: thought || ''
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (activeAgent && 'function' == typeof activeAgent[actionType]) return await activeAgent[actionType](prompt, options);
|
|
123
|
+
throw new Error(`Unknown action type: ${actionType}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export { dataExtractionAPIs, executeAction, formatErrorMessage, noReplayAPIs, validateStructuredParams, validationAPIs };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=common.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.mjs","sources":["webpack://@midscene/playground/./src/common.ts"],"sourcesContent":["import type { DeviceAction } from '@midscene/core';\nimport { findAllMidsceneLocatorField } from '@midscene/core/ai-model';\nimport type {\n ExecutionOptions,\n FormValue,\n PlaygroundAgent,\n ValidationResult,\n} from './types';\n\n// APIs that should not generate replay scripts\nexport const dataExtractionAPIs = [\n 'aiQuery',\n 'aiBoolean',\n 'aiNumber',\n 'aiString',\n 'aiAsk',\n];\n\nexport const validationAPIs = ['aiAssert', 'aiWaitFor'];\n\nexport const noReplayAPIs = [...dataExtractionAPIs, ...validationAPIs];\n\nexport const formatErrorMessage = (e: any): string => {\n const errorMessage = e?.message || '';\n if (errorMessage.includes('of different extension')) {\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';\n }\n // Always return the actual error message, including NOT_IMPLEMENTED_AS_DESIGNED errors\n return errorMessage || 'Unknown error';\n};\n\n// Parse structured parameters for callActionInActionSpace\nasync function parseStructuredParams(\n action: DeviceAction<unknown>,\n params: Record<string, unknown>,\n options: ExecutionOptions = {},\n): Promise<unknown[]> {\n if (!action?.paramSchema || !('shape' in action.paramSchema)) {\n return [params.prompt || '', options];\n }\n\n const schema = action.paramSchema;\n const keys =\n schema && 'shape' in schema\n ? Object.keys((schema as { shape: Record<string, unknown> }).shape)\n : [];\n\n const paramObj: Record<string, unknown> = { ...options };\n\n keys.forEach((key) => {\n if (\n params[key] !== undefined &&\n params[key] !== null &&\n params[key] !== ''\n ) {\n paramObj[key] = params[key];\n }\n });\n\n return [paramObj];\n}\n\nexport function validateStructuredParams(\n value: FormValue,\n action: DeviceAction<unknown> | undefined,\n): ValidationResult {\n if (!value.params) {\n return { valid: false, errorMessage: 'Parameters are required' };\n }\n\n if (!action?.paramSchema) {\n return { valid: true };\n }\n\n try {\n const paramsForValidation = { ...value.params };\n\n const schema = action.paramSchema;\n if (schema) {\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\n locatorFieldKeys.forEach((key) => {\n if (typeof paramsForValidation[key] === 'string') {\n paramsForValidation[key] = {\n midscene_location_field_flag: true,\n prompt: paramsForValidation[key],\n center: [0, 0],\n rect: { left: 0, top: 0, width: 0, height: 0 },\n };\n }\n });\n }\n\n action.paramSchema?.parse(paramsForValidation);\n return { valid: true };\n } catch (error: unknown) {\n const zodError = error as {\n errors?: Array<{ path: string[]; message: string }>;\n };\n if (zodError.errors && zodError.errors.length > 0) {\n const errorMessages = zodError.errors\n .filter((err) => {\n const path = err.path.join('.');\n return (\n !path.includes('center') &&\n !path.includes('rect') &&\n !path.includes('midscene_location_field_flag')\n );\n })\n .map((err) => {\n const field = err.path.join('.');\n return `${field}: ${err.message}`;\n });\n\n if (errorMessages.length > 0) {\n return {\n valid: false,\n errorMessage: `Validation error: ${errorMessages.join(', ')}`,\n };\n }\n } else {\n const errorMsg =\n error instanceof Error ? error.message : 'Unknown validation error';\n return {\n valid: false,\n errorMessage: `Parameter validation failed: ${errorMsg}`,\n };\n }\n }\n\n return { valid: true };\n}\n\nexport async function executeAction(\n activeAgent: PlaygroundAgent,\n actionType: string,\n actionSpace: DeviceAction<unknown>[],\n value: FormValue,\n options: ExecutionOptions,\n): Promise<unknown> {\n const action = actionSpace?.find(\n (a: DeviceAction<unknown>) =>\n a.interfaceAlias === actionType || a.name === actionType,\n );\n\n if (action && typeof activeAgent.callActionInActionSpace === 'function') {\n if (value.params) {\n const parsedParams = await parseStructuredParams(\n action,\n value.params,\n options,\n );\n return await activeAgent.callActionInActionSpace(\n action.name,\n parsedParams[0],\n );\n } else {\n return await activeAgent.callActionInActionSpace(action.name, {\n prompt: value.prompt,\n ...options,\n });\n }\n } else {\n const prompt = value.prompt;\n\n if (actionType === 'aiAssert') {\n const { pass, thought } =\n (await activeAgent?.aiAssert?.(prompt || '', undefined, {\n keepRawResponse: true,\n ...options,\n })) || {};\n return { pass: pass || false, thought: thought || '' };\n }\n\n // Fallback for methods not found in actionSpace\n if (activeAgent && typeof activeAgent[actionType] === 'function') {\n return await activeAgent[actionType](prompt, options);\n }\n\n throw new Error(`Unknown action type: ${actionType}`);\n }\n}\n"],"names":["dataExtractionAPIs","validationAPIs","noReplayAPIs","formatErrorMessage","e","errorMessage","parseStructuredParams","action","params","options","schema","keys","Object","paramObj","key","undefined","validateStructuredParams","value","_action_paramSchema","paramsForValidation","locatorFieldKeys","findAllMidsceneLocatorField","error","zodError","errorMessages","err","path","field","errorMsg","Error","executeAction","activeAgent","actionType","actionSpace","a","parsedParams","prompt","pass","thought"],"mappings":";AAUO,MAAMA,qBAAqB;IAChC;IACA;IACA;IACA;IACA;CACD;AAEM,MAAMC,iBAAiB;IAAC;IAAY;CAAY;AAEhD,MAAMC,eAAe;OAAIF;OAAuBC;CAAe;AAE/D,MAAME,qBAAqB,CAACC;IACjC,MAAMC,eAAeD,AAAAA,CAAAA,QAAAA,IAAAA,KAAAA,IAAAA,EAAG,OAAO,AAAD,KAAK;IACnC,IAAIC,aAAa,QAAQ,CAAC,2BACxB,OAAO;IAGT,OAAOA,gBAAgB;AACzB;AAGA,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OAAO,MAAMc,YAAY,uBAAuB,CAACxB,OAAO,IAAI,EAAE;QAC5D,QAAQU,MAAM,MAAM;QACpB,GAAGR,OAAO;IACZ;SAdgB;QAChB,MAAM0B,eAAe,MAAM7B,sBACzBC,QACAU,MAAM,MAAM,EACZR;QAEF,OAAO,MAAMsB,YAAY,uBAAuB,CAC9CxB,OAAO,IAAI,EACX4B,YAAY,CAAC,EAAE;IAEnB;IAMK;QACL,MAAMC,SAASnB,MAAM,MAAM;QAE3B,IAAIe,AAAe,eAAfA,YAA2B;gBAEpBD;YADT,MAAM,EAAEM,IAAI,EAAEC,OAAO,EAAE,GACpB,MAAMP,CAAAA,QAAAA,cAAAA,KAAAA,IAAAA,QAAAA,CAAAA,wBAAAA,YAAa,QAAQ,AAAD,IAApBA,KAAAA,IAAAA,sBAAAA,IAAAA,CAAAA,aAAwBK,UAAU,IAAIrB,QAAW;gBACtD,iBAAiB;gBACjB,GAAGN,OAAO;YACZ,EAAC,KAAM,CAAC;YACV,OAAO;gBAAE,MAAM4B,QAAQ;gBAAO,SAASC,WAAW;YAAG;QACvD;QAGA,IAAIP,eAAe,AAAmC,cAAnC,OAAOA,WAAW,CAACC,WAAW,EAC/C,OAAO,MAAMD,WAAW,CAACC,WAAW,CAACI,QAAQ3B;QAG/C,MAAM,IAAIoB,MAAM,CAAC,qBAAqB,EAAEG,YAAY;IACtD;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StaticPageAgent } from "./static-agent.mjs";
|
|
2
|
+
import { dataExtractionAPIs, executeAction, formatErrorMessage, noReplayAPIs, validateStructuredParams, validationAPIs } from "./common.mjs";
|
|
3
|
+
import static_page from "./static-page.mjs";
|
|
4
|
+
const PlaygroundServer = void 0;
|
|
5
|
+
export { PlaygroundServer, static_page as StaticPage, StaticPageAgent, dataExtractionAPIs, executeAction, formatErrorMessage, noReplayAPIs, validateStructuredParams, validationAPIs };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=index.browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.mjs","sources":["webpack://@midscene/playground/./src/index.browser.ts"],"sourcesContent":["// Browser-safe version of playground exports (excludes server)\nexport { StaticPageAgent } from './static-agent';\nexport {\n dataExtractionAPIs,\n noReplayAPIs,\n validationAPIs,\n formatErrorMessage,\n validateStructuredParams,\n executeAction,\n} from './common';\nexport { default as StaticPage } from './static-page';\n\n// PlaygroundServer is not available in browser environments\nexport const PlaygroundServer = undefined;\n\nexport type {\n ExecutionOptions,\n FormValue,\n PlaygroundAgent,\n ValidationResult,\n} from './types';\n"],"names":["PlaygroundServer","undefined"],"mappings":";;;AAaO,MAAMA,mBAAmBC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { dataExtractionAPIs, executeAction, formatErrorMessage, noReplayAPIs, validateStructuredParams, validationAPIs } from "./common.mjs";
|
|
2
|
+
import { StaticPageAgent } from "./static-agent.mjs";
|
|
3
|
+
import static_page from "./static-page.mjs";
|
|
4
|
+
import server from "./server.mjs";
|
|
5
|
+
export { server as PlaygroundServer, static_page as StaticPage, StaticPageAgent, dataExtractionAPIs, executeAction, formatErrorMessage, noReplayAPIs, validateStructuredParams, validationAPIs };
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { getTmpDir } from "@midscene/core/utils";
|
|
5
|
+
import { PLAYGROUND_SERVER_PORT } from "@midscene/shared/constants";
|
|
6
|
+
import { overrideAIConfig } from "@midscene/shared/env";
|
|
7
|
+
import { ifInBrowser, ifInWorker } from "@midscene/shared/utils";
|
|
8
|
+
import cors from "cors";
|
|
9
|
+
import dotenv from "dotenv";
|
|
10
|
+
import express from "express";
|
|
11
|
+
import { executeAction, formatErrorMessage } from "./common.mjs";
|
|
12
|
+
function _define_property(obj, key, value) {
|
|
13
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
14
|
+
value: value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
else obj[key] = value;
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
const defaultPort = PLAYGROUND_SERVER_PORT;
|
|
23
|
+
const errorHandler = (err, req, res, next)=>{
|
|
24
|
+
console.error(err);
|
|
25
|
+
res.status(500).json({
|
|
26
|
+
error: err.message
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const setup = async ()=>{
|
|
30
|
+
if (!ifInBrowser && !ifInWorker) dotenv.config();
|
|
31
|
+
};
|
|
32
|
+
class PlaygroundServer {
|
|
33
|
+
filePathForUuid(uuid) {
|
|
34
|
+
return join(this.tmpDir, `${uuid}.json`);
|
|
35
|
+
}
|
|
36
|
+
saveContextFile(uuid, context) {
|
|
37
|
+
const tmpFile = this.filePathForUuid(uuid);
|
|
38
|
+
console.log(`save context file: ${tmpFile}`);
|
|
39
|
+
writeFileSync(tmpFile, context);
|
|
40
|
+
return tmpFile;
|
|
41
|
+
}
|
|
42
|
+
async launch(port) {
|
|
43
|
+
this.port = port || defaultPort;
|
|
44
|
+
this.app.use(errorHandler);
|
|
45
|
+
this.app.use(cors({
|
|
46
|
+
origin: '*',
|
|
47
|
+
credentials: true
|
|
48
|
+
}));
|
|
49
|
+
this.app.get('/status', async (req, res)=>{
|
|
50
|
+
res.send({
|
|
51
|
+
status: 'ok'
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
this.app.get('/context/:uuid', async (req, res)=>{
|
|
55
|
+
const { uuid } = req.params;
|
|
56
|
+
const contextFile = this.filePathForUuid(uuid);
|
|
57
|
+
if (!existsSync(contextFile)) return res.status(404).json({
|
|
58
|
+
error: 'Context not found'
|
|
59
|
+
});
|
|
60
|
+
const context = readFileSync(contextFile, 'utf8');
|
|
61
|
+
res.json({
|
|
62
|
+
context
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
this.app.get('/task-progress/:requestId', async (req, res)=>{
|
|
66
|
+
const { requestId } = req.params;
|
|
67
|
+
res.json({
|
|
68
|
+
tip: this.taskProgressTips[requestId] || ''
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
this.app.post('/action-space', express.json({
|
|
72
|
+
limit: '30mb'
|
|
73
|
+
}), async (req, res)=>{
|
|
74
|
+
const { context } = req.body;
|
|
75
|
+
if (!context) return res.status(400).json({
|
|
76
|
+
error: 'context is required'
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
const page = new this.pageClass(context);
|
|
80
|
+
const actionSpace = await page.actionSpace();
|
|
81
|
+
const processedActionSpace = actionSpace.map((action)=>{
|
|
82
|
+
if (action.paramSchema && 'object' == typeof action.paramSchema) {
|
|
83
|
+
let processedSchema = null;
|
|
84
|
+
try {
|
|
85
|
+
if (action.paramSchema.shape && 'object' == typeof action.paramSchema.shape) processedSchema = {
|
|
86
|
+
type: 'ZodObject',
|
|
87
|
+
shape: action.paramSchema.shape
|
|
88
|
+
};
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.warn('Failed to process paramSchema for action:', action.name, e);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...action,
|
|
94
|
+
paramSchema: processedSchema
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return action;
|
|
98
|
+
});
|
|
99
|
+
res.json(processedActionSpace);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('Failed to get action space:', error);
|
|
102
|
+
res.status(500).json({
|
|
103
|
+
error: error.message
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
this.app.post('/playground-with-context', express.json({
|
|
108
|
+
limit: '50mb'
|
|
109
|
+
}), async (req, res)=>{
|
|
110
|
+
const context = req.body.context;
|
|
111
|
+
if (!context) return res.status(400).json({
|
|
112
|
+
error: 'context is required'
|
|
113
|
+
});
|
|
114
|
+
const uuid = randomUUID();
|
|
115
|
+
this.saveContextFile(uuid, context);
|
|
116
|
+
return res.json({
|
|
117
|
+
location: `/playground/${uuid}`,
|
|
118
|
+
uuid
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
this.app.post('/execute', express.json({
|
|
122
|
+
limit: '30mb'
|
|
123
|
+
}), async (req, res)=>{
|
|
124
|
+
const { context, type, prompt, params, requestId, deepThink, screenshotIncluded, domIncluded } = req.body;
|
|
125
|
+
if (!context) return res.status(400).json({
|
|
126
|
+
error: 'context is required'
|
|
127
|
+
});
|
|
128
|
+
if (!type) return res.status(400).json({
|
|
129
|
+
error: 'type is required'
|
|
130
|
+
});
|
|
131
|
+
const page = new this.pageClass(context);
|
|
132
|
+
const agent = new this.agentClass(page);
|
|
133
|
+
if (requestId) {
|
|
134
|
+
this.taskProgressTips[requestId] = '';
|
|
135
|
+
this.activeAgents[requestId] = agent;
|
|
136
|
+
agent.onTaskStartTip = (tip)=>{
|
|
137
|
+
this.taskProgressTips[requestId] = tip;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const response = {
|
|
141
|
+
result: null,
|
|
142
|
+
dump: null,
|
|
143
|
+
error: null,
|
|
144
|
+
reportHTML: null,
|
|
145
|
+
requestId
|
|
146
|
+
};
|
|
147
|
+
const startTime = Date.now();
|
|
148
|
+
try {
|
|
149
|
+
const actionSpace = await page.actionSpace();
|
|
150
|
+
const value = {
|
|
151
|
+
type,
|
|
152
|
+
prompt,
|
|
153
|
+
params
|
|
154
|
+
};
|
|
155
|
+
response.result = await executeAction(agent, type, actionSpace, value, {
|
|
156
|
+
deepThink: deepThink || false,
|
|
157
|
+
screenshotIncluded,
|
|
158
|
+
domIncluded
|
|
159
|
+
});
|
|
160
|
+
} catch (error) {
|
|
161
|
+
response.error = formatErrorMessage(error);
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
response.dump = JSON.parse(agent.dumpDataString());
|
|
165
|
+
response.reportHTML = agent.reportHTMLString() || null;
|
|
166
|
+
agent.writeOutActionDumps();
|
|
167
|
+
agent.destroy();
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error(`write out dump failed: requestId: ${requestId}, ${error.message}`);
|
|
170
|
+
}
|
|
171
|
+
res.send(response);
|
|
172
|
+
const timeCost = Date.now() - startTime;
|
|
173
|
+
if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
|
|
174
|
+
else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
|
|
175
|
+
if (requestId && this.activeAgents[requestId]) delete this.activeAgents[requestId];
|
|
176
|
+
});
|
|
177
|
+
this.app.get('/cancel/:requestId', async (req, res)=>{
|
|
178
|
+
const { requestId } = req.params;
|
|
179
|
+
if (!requestId) return res.status(400).json({
|
|
180
|
+
error: 'requestId is required'
|
|
181
|
+
});
|
|
182
|
+
const agent = this.activeAgents[requestId];
|
|
183
|
+
if (!agent) return res.status(404).json({
|
|
184
|
+
error: 'No active agent found for this requestId'
|
|
185
|
+
});
|
|
186
|
+
try {
|
|
187
|
+
await agent.destroy();
|
|
188
|
+
delete this.activeAgents[requestId];
|
|
189
|
+
res.json({
|
|
190
|
+
status: 'cancelled'
|
|
191
|
+
});
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error(`Failed to cancel agent: ${error.message}`);
|
|
194
|
+
res.status(500).json({
|
|
195
|
+
error: `Failed to cancel: ${error.message}`
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
this.app.post('/config', express.json({
|
|
200
|
+
limit: '1mb'
|
|
201
|
+
}), async (req, res)=>{
|
|
202
|
+
const { aiConfig } = req.body;
|
|
203
|
+
if (!aiConfig || 'object' != typeof aiConfig) return res.status(400).json({
|
|
204
|
+
error: 'aiConfig is required and must be an object'
|
|
205
|
+
});
|
|
206
|
+
try {
|
|
207
|
+
overrideAIConfig(aiConfig);
|
|
208
|
+
return res.json({
|
|
209
|
+
status: 'ok',
|
|
210
|
+
message: 'AI config updated successfully'
|
|
211
|
+
});
|
|
212
|
+
} catch (error) {
|
|
213
|
+
console.error(`Failed to update AI config: ${error.message}`);
|
|
214
|
+
return res.status(500).json({
|
|
215
|
+
error: `Failed to update AI config: ${error.message}`
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
if (this.staticPath) {
|
|
220
|
+
this.app.get('/', (_req, res)=>{
|
|
221
|
+
res.redirect('/index.html');
|
|
222
|
+
});
|
|
223
|
+
this.app.get('*', (req, res)=>{
|
|
224
|
+
const requestedPath = join(this.staticPath, req.path);
|
|
225
|
+
if (existsSync(requestedPath)) res.sendFile(requestedPath);
|
|
226
|
+
else res.sendFile(join(this.staticPath, 'index.html'));
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return new Promise((resolve)=>{
|
|
230
|
+
const port = this.port;
|
|
231
|
+
this.server = this.app.listen(port, ()=>{
|
|
232
|
+
resolve(this);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
close() {
|
|
237
|
+
if (this.server) return this.server.close();
|
|
238
|
+
}
|
|
239
|
+
constructor(pageClass, agentClass, staticPath){
|
|
240
|
+
_define_property(this, "app", void 0);
|
|
241
|
+
_define_property(this, "tmpDir", void 0);
|
|
242
|
+
_define_property(this, "server", void 0);
|
|
243
|
+
_define_property(this, "port", void 0);
|
|
244
|
+
_define_property(this, "pageClass", void 0);
|
|
245
|
+
_define_property(this, "agentClass", void 0);
|
|
246
|
+
_define_property(this, "staticPath", void 0);
|
|
247
|
+
_define_property(this, "taskProgressTips", void 0);
|
|
248
|
+
_define_property(this, "activeAgents", void 0);
|
|
249
|
+
this.app = express();
|
|
250
|
+
this.tmpDir = getTmpDir();
|
|
251
|
+
this.pageClass = pageClass;
|
|
252
|
+
this.agentClass = agentClass;
|
|
253
|
+
this.staticPath = staticPath;
|
|
254
|
+
this.taskProgressTips = {};
|
|
255
|
+
this.activeAgents = {};
|
|
256
|
+
setup();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
export { PlaygroundServer as default };
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.mjs","sources":["webpack://@midscene/playground/./src/server.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport type { Server } from 'node:http';\nimport { join } from 'node:path';\nimport type { Agent as PageAgent } from '@midscene/core/agent';\nimport type { AbstractInterface } from '@midscene/core/device';\nimport { getTmpDir } from '@midscene/core/utils';\nimport { PLAYGROUND_SERVER_PORT } from '@midscene/shared/constants';\nimport { overrideAIConfig } from '@midscene/shared/env';\nimport { ifInBrowser, ifInWorker } from '@midscene/shared/utils';\nimport cors from 'cors';\nimport dotenv from 'dotenv';\nimport express from 'express';\nimport { executeAction, formatErrorMessage } from './common';\nimport type { PlaygroundAgent } from './types';\n\nconst defaultPort = PLAYGROUND_SERVER_PORT;\n\nconst errorHandler = (err: any, req: any, res: any, next: any) => {\n console.error(err);\n res.status(500).json({\n error: err.message,\n });\n};\n\nconst setup = async () => {\n if (!ifInBrowser && !ifInWorker) {\n dotenv.config();\n }\n};\n\nexport default class PlaygroundServer {\n app: express.Application;\n tmpDir: string;\n server?: Server;\n port?: number | null;\n pageClass: new (\n ...args: any[]\n ) => AbstractInterface;\n agentClass: new (\n ...args: any[]\n ) => PageAgent;\n staticPath?: string;\n taskProgressTips: Record<string, string>;\n activeAgents: Record<string, PageAgent>;\n\n constructor(\n pageClass: new (...args: any[]) => AbstractInterface,\n agentClass: new (...args: any[]) => PageAgent,\n staticPath?: string,\n ) {\n this.app = express();\n this.tmpDir = getTmpDir()!;\n this.pageClass = pageClass;\n this.agentClass = agentClass;\n this.staticPath = staticPath;\n this.taskProgressTips = {};\n this.activeAgents = {};\n setup();\n }\n\n filePathForUuid(uuid: string) {\n return join(this.tmpDir, `${uuid}.json`);\n }\n\n saveContextFile(uuid: string, context: string) {\n const tmpFile = this.filePathForUuid(uuid);\n console.log(`save context file: ${tmpFile}`);\n writeFileSync(tmpFile, context);\n return tmpFile;\n }\n\n async launch(port?: number) {\n this.port = port || defaultPort;\n this.app.use(errorHandler);\n\n this.app.use(\n cors({\n origin: '*',\n credentials: true,\n }),\n );\n\n this.app.get('/status', async (req, res) => {\n // const modelName = g\n res.send({\n status: 'ok',\n });\n });\n\n this.app.get('/context/:uuid', async (req, res) => {\n const { uuid } = req.params;\n const contextFile = this.filePathForUuid(uuid);\n\n if (!existsSync(contextFile)) {\n return res.status(404).json({\n error: 'Context not found',\n });\n }\n\n const context = readFileSync(contextFile, 'utf8');\n res.json({\n context,\n });\n });\n\n this.app.get('/task-progress/:requestId', async (req, res) => {\n const { requestId } = req.params;\n res.json({\n tip: this.taskProgressTips[requestId] || '',\n });\n });\n\n this.app.post(\n '/action-space',\n express.json({ limit: '30mb' }),\n async (req, res) => {\n const { context } = req.body;\n\n if (!context) {\n return res.status(400).json({\n error: 'context is required',\n });\n }\n\n try {\n // Create agent with context like in /execute\n const page = new this.pageClass(context);\n const actionSpace = await page.actionSpace();\n\n // Process actionSpace to make paramSchema serializable\n const processedActionSpace = actionSpace.map((action: any) => {\n if (action.paramSchema && typeof action.paramSchema === 'object') {\n // Extract shape information from Zod schema\n let processedSchema = null;\n\n try {\n // Extract shape from runtime Zod object\n if (\n action.paramSchema.shape &&\n typeof action.paramSchema.shape === 'object'\n ) {\n processedSchema = {\n type: 'ZodObject',\n shape: action.paramSchema.shape,\n };\n }\n } catch (e) {\n console.warn(\n 'Failed to process paramSchema for action:',\n action.name,\n e,\n );\n }\n\n return {\n ...action,\n paramSchema: processedSchema,\n };\n }\n return action;\n });\n\n res.json(processedActionSpace);\n } catch (error: any) {\n console.error('Failed to get action space:', error);\n res.status(500).json({\n error: error.message,\n });\n }\n },\n );\n\n // -------------------------\n // actions from report file\n this.app.post(\n '/playground-with-context',\n express.json({ limit: '50mb' }),\n async (req, res) => {\n const context = req.body.context;\n\n if (!context) {\n return res.status(400).json({\n error: 'context is required',\n });\n }\n\n const uuid = randomUUID();\n this.saveContextFile(uuid, context);\n return res.json({\n location: `/playground/${uuid}`,\n uuid,\n });\n },\n );\n\n this.app.post(\n '/execute',\n express.json({ limit: '30mb' }),\n async (req, res) => {\n const {\n context,\n type,\n prompt,\n params,\n requestId,\n deepThink,\n screenshotIncluded,\n domIncluded,\n } = req.body;\n\n if (!context) {\n return res.status(400).json({\n error: 'context is required',\n });\n }\n\n if (!type) {\n return res.status(400).json({\n error: 'type is required',\n });\n }\n\n // build an agent with context\n const page = new this.pageClass(context);\n const agent = new this.agentClass(page);\n\n if (requestId) {\n this.taskProgressTips[requestId] = '';\n this.activeAgents[requestId] = agent;\n\n agent.onTaskStartTip = (tip: string) => {\n this.taskProgressTips[requestId] = tip;\n };\n }\n\n const response: {\n result: any;\n dump: string | null;\n error: string | null;\n reportHTML: string | null;\n requestId?: string;\n } = {\n result: null,\n dump: null,\n error: null,\n reportHTML: null,\n requestId,\n };\n\n const startTime = Date.now();\n try {\n // Get action space to check for dynamic actions\n const actionSpace = await page.actionSpace();\n\n // Prepare value object for executeAction\n const value = {\n type,\n prompt,\n params,\n };\n\n response.result = await executeAction(\n agent as unknown as PlaygroundAgent,\n type,\n actionSpace,\n value,\n {\n deepThink: deepThink || false,\n screenshotIncluded,\n domIncluded,\n },\n );\n } catch (error: any) {\n response.error = formatErrorMessage(error);\n }\n\n try {\n response.dump = JSON.parse(agent.dumpDataString());\n response.reportHTML = agent.reportHTMLString() || null;\n\n agent.writeOutActionDumps();\n agent.destroy();\n } catch (error: any) {\n console.error(\n `write out dump failed: requestId: ${requestId}, ${error.message}`,\n );\n }\n\n res.send(response);\n const timeCost = Date.now() - startTime;\n\n if (response.error) {\n console.error(\n `handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`,\n );\n } else {\n console.log(\n `handle request done after ${timeCost}ms: requestId: ${requestId}`,\n );\n }\n\n // Clean up the agent from activeAgents after execution completes\n if (requestId && this.activeAgents[requestId]) {\n delete this.activeAgents[requestId];\n }\n },\n );\n\n this.app.get('/cancel/:requestId', async (req, res) => {\n const { requestId } = req.params;\n\n if (!requestId) {\n return res.status(400).json({\n error: 'requestId is required',\n });\n }\n\n const agent = this.activeAgents[requestId];\n if (!agent) {\n return res.status(404).json({\n error: 'No active agent found for this requestId',\n });\n }\n\n try {\n await agent.destroy();\n delete this.activeAgents[requestId];\n res.json({ status: 'cancelled' });\n } catch (error: any) {\n console.error(`Failed to cancel agent: ${error.message}`);\n res.status(500).json({\n error: `Failed to cancel: ${error.message}`,\n });\n }\n });\n\n this.app.post(\n '/config',\n express.json({ limit: '1mb' }),\n async (req, res) => {\n const { aiConfig } = req.body;\n\n if (!aiConfig || typeof aiConfig !== 'object') {\n return res.status(400).json({\n error: 'aiConfig is required and must be an object',\n });\n }\n\n try {\n overrideAIConfig(aiConfig);\n\n return res.json({\n status: 'ok',\n message: 'AI config updated successfully',\n });\n } catch (error: any) {\n console.error(`Failed to update AI config: ${error.message}`);\n return res.status(500).json({\n error: `Failed to update AI config: ${error.message}`,\n });\n }\n },\n );\n\n // Set up static file serving after all API routes are defined\n if (this.staticPath) {\n this.app.get('/', (_req, res) => {\n // compatible with windows\n res.redirect('/index.html');\n });\n\n this.app.get('*', (req, res) => {\n const requestedPath = join(this.staticPath!, req.path);\n if (existsSync(requestedPath)) {\n res.sendFile(requestedPath);\n } else {\n res.sendFile(join(this.staticPath!, 'index.html'));\n }\n });\n }\n\n return new Promise((resolve) => {\n const port = this.port;\n this.server = this.app.listen(port, () => {\n resolve(this);\n });\n });\n }\n\n close() {\n // close the server\n if (this.server) {\n return this.server.close();\n }\n }\n}\n"],"names":["defaultPort","PLAYGROUND_SERVER_PORT","errorHandler","err","req","res","next","console","setup","ifInBrowser","ifInWorker","dotenv","PlaygroundServer","uuid","join","context","tmpFile","writeFileSync","port","cors","contextFile","existsSync","readFileSync","requestId","express","page","actionSpace","processedActionSpace","action","processedSchema","e","error","randomUUID","type","prompt","params","deepThink","screenshotIncluded","domIncluded","agent","tip","response","startTime","Date","value","executeAction","formatErrorMessage","JSON","timeCost","aiConfig","overrideAIConfig","_req","requestedPath","Promise","resolve","pageClass","agentClass","staticPath","getTmpDir"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgBA,MAAMA,cAAcC;AAEpB,MAAMC,eAAe,CAACC,KAAUC,KAAUC,KAAUC;IAClDC,QAAQ,KAAK,CAACJ;IACdE,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC;QACnB,OAAOF,IAAI,OAAO;IACpB;AACF;AAEA,MAAMK,QAAQ;IACZ,IAAI,CAACC,eAAe,CAACC,YACnBC,OAAO,MAAM;AAEjB;AAEe,MAAMC;IA8BnB,gBAAgBC,IAAY,EAAE;QAC5B,OAAOC,KAAK,IAAI,CAAC,MAAM,EAAE,GAAGD,KAAK,KAAK,CAAC;IACzC;IAEA,gBAAgBA,IAAY,EAAEE,OAAe,EAAE;QAC7C,MAAMC,UAAU,IAAI,CAAC,eAAe,CAACH;QACrCN,QAAQ,GAAG,CAAC,CAAC,mBAAmB,EAAES,SAAS;QAC3CC,cAAcD,SAASD;QACvB,OAAOC;IACT;IAEA,MAAM,OAAOE,IAAa,EAAE;QAC1B,IAAI,CAAC,IAAI,GAAGA,QAAQlB;QACpB,IAAI,CAAC,GAAG,CAAC,GAAG,CAACE;QAEb,IAAI,CAAC,GAAG,CAAC,GAAG,CACViB,KAAK;YACH,QAAQ;YACR,aAAa;QACf;QAGF,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,OAAOf,KAAKC;YAElCA,IAAI,IAAI,CAAC;gBACP,QAAQ;YACV;QACF;QAEA,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,kBAAkB,OAAOD,KAAKC;YACzC,MAAM,EAAEQ,IAAI,EAAE,GAAGT,IAAI,MAAM;YAC3B,MAAMgB,cAAc,IAAI,CAAC,eAAe,CAACP;YAEzC,IAAI,CAACQ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,CAACoB,MAAM9C;gBAEvBA,IAAI,QAAQ,CAAC;YACf;YAEA,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAACD,KAAKC;gBACtB,MAAM+C,gBAAgBtC,KAAK,IAAI,CAAC,UAAU,EAAGV,IAAI,IAAI;gBACrD,IAAIiB,WAAW+B,gBACb/C,IAAI,QAAQ,CAAC+C;qBAEb/C,IAAI,QAAQ,CAACS,KAAK,IAAI,CAAC,UAAU,EAAG;YAExC;QACF;QAEA,OAAO,IAAIuC,QAAQ,CAACC;YAClB,MAAMpC,OAAO,IAAI,CAAC,IAAI;YACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAACA,MAAM;gBAClCoC,QAAQ,IAAI;YACd;QACF;IACF;IAEA,QAAQ;QAEN,IAAI,IAAI,CAAC,MAAM,EACb,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK;IAE5B;IA7VA,YACEC,SAAoD,EACpDC,UAA6C,EAC7CC,UAAmB,CACnB;QAlBF;QACA;QACA;QACA;QACA;QAGA;QAGA;QACA;QACA;QAOE,IAAI,CAAC,GAAG,GAAGjC;QACX,IAAI,CAAC,MAAM,GAAGkC;QACd,IAAI,CAAC,SAAS,GAAGH;QACjB,IAAI,CAAC,UAAU,GAAGC;QAClB,IAAI,CAAC,UAAU,GAAGC;QAClB,IAAI,CAAC,gBAAgB,GAAG,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,CAAC;QACrBjD;IACF;AAiVF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-agent.mjs","sources":["webpack://@midscene/playground/./src/static-agent.ts"],"sourcesContent":["import { Agent as PageAgent } from '@midscene/core/agent';\nimport type StaticPage from './static-page';\n\nexport class StaticPageAgent extends PageAgent {\n constructor(page: StaticPage) {\n super(page, {});\n this.dryMode = true;\n }\n}\n"],"names":["StaticPageAgent","PageAgent","page"],"mappings":";AAGO,MAAMA,wBAAwBC;IACnC,YAAYC,IAAgB,CAAE;QAC5B,KAAK,CAACA,MAAM,CAAC;QACb,IAAI,CAAC,OAAO,GAAG;IACjB;AACF"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { defineActionDragAndDrop, defineActionHover, defineActionInput, defineActionKeyboardPress, defineActionRightClick, defineActionScroll, defineActionTap } from "@midscene/core/device";
|
|
2
|
+
import { ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED } from "@midscene/shared/common";
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
5
|
+
value: value,
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true
|
|
9
|
+
});
|
|
10
|
+
else obj[key] = value;
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
const ThrowNotImplemented = (methodName)=>{
|
|
14
|
+
throw new Error(`The method "${methodName}" is not implemented as designed since this is a static UI context. (${ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED})`);
|
|
15
|
+
};
|
|
16
|
+
class StaticPage {
|
|
17
|
+
actionSpace() {
|
|
18
|
+
return [
|
|
19
|
+
defineActionTap(async (param)=>{
|
|
20
|
+
ThrowNotImplemented('Tap');
|
|
21
|
+
}),
|
|
22
|
+
defineActionRightClick(async (param)=>{
|
|
23
|
+
ThrowNotImplemented('RightClick');
|
|
24
|
+
}),
|
|
25
|
+
defineActionHover(async (param)=>{
|
|
26
|
+
ThrowNotImplemented('Hover');
|
|
27
|
+
}),
|
|
28
|
+
defineActionInput(async (param)=>{
|
|
29
|
+
ThrowNotImplemented('Input');
|
|
30
|
+
}),
|
|
31
|
+
defineActionKeyboardPress(async (param)=>{
|
|
32
|
+
ThrowNotImplemented('KeyboardPress');
|
|
33
|
+
}),
|
|
34
|
+
defineActionScroll(async (param)=>{
|
|
35
|
+
ThrowNotImplemented('Scroll');
|
|
36
|
+
}),
|
|
37
|
+
defineActionDragAndDrop(async (param)=>{
|
|
38
|
+
ThrowNotImplemented('DragAndDrop');
|
|
39
|
+
})
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
async evaluateJavaScript(script) {
|
|
43
|
+
return ThrowNotImplemented('evaluateJavaScript');
|
|
44
|
+
}
|
|
45
|
+
async getElementsInfo() {
|
|
46
|
+
return ThrowNotImplemented('getElementsInfo');
|
|
47
|
+
}
|
|
48
|
+
async getElementsNodeTree() {
|
|
49
|
+
return ThrowNotImplemented('getElementsNodeTree');
|
|
50
|
+
}
|
|
51
|
+
async getXpathsById(id) {
|
|
52
|
+
return ThrowNotImplemented('getXpathsById');
|
|
53
|
+
}
|
|
54
|
+
async getXpathsByPoint(point) {
|
|
55
|
+
return ThrowNotImplemented('getXpathsByPoint');
|
|
56
|
+
}
|
|
57
|
+
async getElementInfoByXpath(xpath) {
|
|
58
|
+
return ThrowNotImplemented('getElementInfoByXpath');
|
|
59
|
+
}
|
|
60
|
+
async size() {
|
|
61
|
+
return {
|
|
62
|
+
...this.uiContext.size,
|
|
63
|
+
dpr: this.uiContext.size.dpr || 1
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async screenshotBase64() {
|
|
67
|
+
const base64 = this.uiContext.screenshotBase64;
|
|
68
|
+
if (!base64) throw new Error('screenshot base64 is empty');
|
|
69
|
+
return base64;
|
|
70
|
+
}
|
|
71
|
+
async url() {
|
|
72
|
+
return Promise.resolve('https://static_page_without_url');
|
|
73
|
+
}
|
|
74
|
+
async scrollUntilTop(startingPoint) {
|
|
75
|
+
return ThrowNotImplemented('scrollUntilTop');
|
|
76
|
+
}
|
|
77
|
+
async scrollUntilBottom(startingPoint) {
|
|
78
|
+
return ThrowNotImplemented('scrollUntilBottom');
|
|
79
|
+
}
|
|
80
|
+
async scrollUntilLeft(startingPoint) {
|
|
81
|
+
return ThrowNotImplemented('scrollUntilLeft');
|
|
82
|
+
}
|
|
83
|
+
async scrollUntilRight(startingPoint) {
|
|
84
|
+
return ThrowNotImplemented('scrollUntilRight');
|
|
85
|
+
}
|
|
86
|
+
async scrollUp(distance, startingPoint) {
|
|
87
|
+
return ThrowNotImplemented('scrollUp');
|
|
88
|
+
}
|
|
89
|
+
async scrollDown(distance, startingPoint) {
|
|
90
|
+
return ThrowNotImplemented('scrollDown');
|
|
91
|
+
}
|
|
92
|
+
async scrollLeft(distance, startingPoint) {
|
|
93
|
+
return ThrowNotImplemented('scrollLeft');
|
|
94
|
+
}
|
|
95
|
+
async scrollRight(distance, startingPoint) {
|
|
96
|
+
return ThrowNotImplemented('scrollRight');
|
|
97
|
+
}
|
|
98
|
+
async clearInput() {
|
|
99
|
+
return ThrowNotImplemented('clearInput');
|
|
100
|
+
}
|
|
101
|
+
async destroy() {}
|
|
102
|
+
async getContext() {
|
|
103
|
+
return this.uiContext;
|
|
104
|
+
}
|
|
105
|
+
constructor(uiContext){
|
|
106
|
+
_define_property(this, "interfaceType", 'static');
|
|
107
|
+
_define_property(this, "uiContext", void 0);
|
|
108
|
+
_define_property(this, "mouse", {
|
|
109
|
+
click: ThrowNotImplemented.bind(null, 'mouse.click'),
|
|
110
|
+
wheel: ThrowNotImplemented.bind(null, 'mouse.wheel'),
|
|
111
|
+
move: ThrowNotImplemented.bind(null, 'mouse.move'),
|
|
112
|
+
drag: ThrowNotImplemented.bind(null, 'mouse.drag')
|
|
113
|
+
});
|
|
114
|
+
_define_property(this, "keyboard", {
|
|
115
|
+
type: ThrowNotImplemented.bind(null, 'keyboard.type'),
|
|
116
|
+
press: ThrowNotImplemented.bind(null, 'keyboard.press')
|
|
117
|
+
});
|
|
118
|
+
if (uiContext.tree) this.uiContext = uiContext;
|
|
119
|
+
else this.uiContext = Object.assign(uiContext, {
|
|
120
|
+
tree: {
|
|
121
|
+
node: null,
|
|
122
|
+
children: []
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export { StaticPage as default };
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=static-page.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-page.mjs","sources":["webpack://@midscene/playground/./src/static-page.ts"],"sourcesContent":["import type { DeviceAction, Point, UIContext } from '@midscene/core';\nimport type { AbstractInterface } from '@midscene/core/device';\nimport {\n defineActionDragAndDrop,\n defineActionHover,\n defineActionInput,\n defineActionKeyboardPress,\n defineActionRightClick,\n defineActionScroll,\n defineActionTap,\n} from '@midscene/core/device';\nimport { ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED } from '@midscene/shared/common';\n\ntype WebUIContext = UIContext & {\n screenshotBase64?: string;\n size: { width: number; height: number; dpr?: number };\n};\n\nconst ThrowNotImplemented = (methodName: string) => {\n throw new Error(\n `The method \"${methodName}\" is not implemented as designed since this is a static UI context. (${ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED})`,\n );\n};\n\nexport default class StaticPage implements AbstractInterface {\n interfaceType = 'static';\n\n private uiContext: WebUIContext;\n\n constructor(uiContext: WebUIContext) {\n if (uiContext.tree) {\n this.uiContext = uiContext;\n } else {\n this.uiContext = Object.assign(uiContext, {\n tree: {\n node: null,\n children: [],\n },\n });\n }\n }\n\n actionSpace(): DeviceAction[] {\n // Return available actions for static page - they will throw \"not implemented\" errors when executed\n // but need to be available for planning phase\n return [\n defineActionTap(async (param) => {\n ThrowNotImplemented('Tap');\n }),\n defineActionRightClick(async (param) => {\n ThrowNotImplemented('RightClick');\n }),\n defineActionHover(async (param) => {\n ThrowNotImplemented('Hover');\n }),\n defineActionInput(async (param) => {\n ThrowNotImplemented('Input');\n }),\n defineActionKeyboardPress(async (param) => {\n ThrowNotImplemented('KeyboardPress');\n }),\n defineActionScroll(async (param) => {\n ThrowNotImplemented('Scroll');\n }),\n defineActionDragAndDrop(async (param) => {\n ThrowNotImplemented('DragAndDrop');\n }),\n ];\n }\n\n async evaluateJavaScript<T = unknown>(script: string): Promise<T> {\n return ThrowNotImplemented('evaluateJavaScript');\n }\n\n // @deprecated\n async getElementsInfo() {\n return ThrowNotImplemented('getElementsInfo');\n }\n\n async getElementsNodeTree() {\n return ThrowNotImplemented('getElementsNodeTree');\n }\n\n async getXpathsById(id: string) {\n return ThrowNotImplemented('getXpathsById');\n }\n\n async getXpathsByPoint(point: Point) {\n return ThrowNotImplemented('getXpathsByPoint');\n }\n\n async getElementInfoByXpath(xpath: string) {\n return ThrowNotImplemented('getElementInfoByXpath');\n }\n\n async size() {\n return {\n ...this.uiContext.size,\n dpr: this.uiContext.size.dpr || 1,\n };\n }\n\n async screenshotBase64() {\n const base64 = this.uiContext.screenshotBase64;\n if (!base64) {\n throw new Error('screenshot base64 is empty');\n }\n return base64;\n }\n\n async url() {\n return Promise.resolve('https://static_page_without_url');\n }\n\n async scrollUntilTop(startingPoint?: Point) {\n return ThrowNotImplemented('scrollUntilTop');\n }\n\n async scrollUntilBottom(startingPoint?: Point) {\n return ThrowNotImplemented('scrollUntilBottom');\n }\n\n async scrollUntilLeft(startingPoint?: Point) {\n return ThrowNotImplemented('scrollUntilLeft');\n }\n\n async scrollUntilRight(startingPoint?: Point) {\n return ThrowNotImplemented('scrollUntilRight');\n }\n\n async scrollUp(distance?: number, startingPoint?: Point) {\n return ThrowNotImplemented('scrollUp');\n }\n\n async scrollDown(distance?: number, startingPoint?: Point) {\n return ThrowNotImplemented('scrollDown');\n }\n\n async scrollLeft(distance?: number, startingPoint?: Point) {\n return ThrowNotImplemented('scrollLeft');\n }\n\n async scrollRight(distance?: number, startingPoint?: Point) {\n return ThrowNotImplemented('scrollRight');\n }\n\n async clearInput() {\n return ThrowNotImplemented('clearInput');\n }\n\n mouse = {\n click: ThrowNotImplemented.bind(null, 'mouse.click'),\n wheel: ThrowNotImplemented.bind(null, 'mouse.wheel'),\n move: ThrowNotImplemented.bind(null, 'mouse.move'),\n drag: ThrowNotImplemented.bind(null, 'mouse.drag'),\n };\n\n keyboard = {\n type: ThrowNotImplemented.bind(null, 'keyboard.type'),\n press: ThrowNotImplemented.bind(null, 'keyboard.press'),\n };\n\n async destroy(): Promise<void> {\n //\n }\n\n async getContext(): Promise<UIContext> {\n return this.uiContext;\n }\n}\n"],"names":["ThrowNotImplemented","methodName","Error","ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED","StaticPage","defineActionTap","param","defineActionRightClick","defineActionHover","defineActionInput","defineActionKeyboardPress","defineActionScroll","defineActionDragAndDrop","script","id","point","xpath","base64","Promise","startingPoint","distance","uiContext","Object"],"mappings":";;;;;;;;;;;;AAkBA,MAAMA,sBAAsB,CAACC;IAC3B,MAAM,IAAIC,MACR,CAAC,YAAY,EAAED,WAAW,qEAAqE,EAAEE,uCAAuC,CAAC,CAAC;AAE9I;AAEe,MAAMC;IAkBnB,cAA8B;QAG5B,OAAO;YACLC,gBAAgB,OAAOC;gBACrBN,oBAAoB;YACtB;YACAO,uBAAuB,OAAOD;gBAC5BN,oBAAoB;YACtB;YACAQ,kBAAkB,OAAOF;gBACvBN,oBAAoB;YACtB;YACAS,kBAAkB,OAAOH;gBACvBN,oBAAoB;YACtB;YACAU,0BAA0B,OAAOJ;gBAC/BN,oBAAoB;YACtB;YACAW,mBAAmB,OAAOL;gBACxBN,oBAAoB;YACtB;YACAY,wBAAwB,OAAON;gBAC7BN,oBAAoB;YACtB;SACD;IACH;IAEA,MAAM,mBAAgCa,MAAc,EAAc;QAChE,OAAOb,oBAAoB;IAC7B;IAGA,MAAM,kBAAkB;QACtB,OAAOA,oBAAoB;IAC7B;IAEA,MAAM,sBAAsB;QAC1B,OAAOA,oBAAoB;IAC7B;IAEA,MAAM,cAAcc,EAAU,EAAE;QAC9B,OAAOd,oBAAoB;IAC7B;IAEA,MAAM,iBAAiBe,KAAY,EAAE;QACnC,OAAOf,oBAAoB;IAC7B;IAEA,MAAM,sBAAsBgB,KAAa,EAAE;QACzC,OAAOhB,oBAAoB;IAC7B;IAEA,MAAM,OAAO;QACX,OAAO;YACL,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI;YACtB,KAAK,IAAI,CAAC,SAAS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