@midscene/web 0.27.5 → 0.27.6

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.
Files changed (49) hide show
  1. package/bin/midscene-playground +1 -1
  2. package/dist/es/bin.mjs +7 -0
  3. package/dist/es/bin.mjs.map +1 -0
  4. package/dist/es/bridge-mode/io-client.mjs +1 -1
  5. package/dist/es/bridge-mode/io-server.mjs +2 -2
  6. package/dist/es/bridge-mode/page-browser-side.mjs +1 -1
  7. package/dist/es/index.mjs +2 -3
  8. package/dist/es/web-element.mjs +3 -3
  9. package/dist/es/web-element.mjs.map +1 -1
  10. package/dist/lib/bin.js +13 -0
  11. package/dist/lib/bin.js.map +1 -0
  12. package/dist/lib/bridge-mode/io-client.js +1 -1
  13. package/dist/lib/bridge-mode/io-server.js +2 -2
  14. package/dist/lib/bridge-mode/page-browser-side.js +1 -1
  15. package/dist/lib/index.js +6 -16
  16. package/dist/lib/web-element.js +5 -5
  17. package/dist/lib/web-element.js.map +1 -1
  18. package/dist/types/index.d.ts +2 -3
  19. package/dist/types/web-element.d.ts +3 -11
  20. package/package.json +7 -25
  21. package/dist/es/playground/agent.mjs +0 -10
  22. package/dist/es/playground/agent.mjs.map +0 -1
  23. package/dist/es/playground/bin.mjs +0 -8
  24. package/dist/es/playground/bin.mjs.map +0 -1
  25. package/dist/es/playground/common.mjs +0 -130
  26. package/dist/es/playground/common.mjs.map +0 -1
  27. package/dist/es/playground/index.mjs +0 -5
  28. package/dist/es/playground/server.mjs +0 -256
  29. package/dist/es/playground/server.mjs.map +0 -1
  30. package/dist/es/playground/static-page.mjs +0 -104
  31. package/dist/es/playground/static-page.mjs.map +0 -1
  32. package/dist/lib/playground/agent.js +0 -44
  33. package/dist/lib/playground/agent.js.map +0 -1
  34. package/dist/lib/playground/bin.js +0 -36
  35. package/dist/lib/playground/bin.js.map +0 -1
  36. package/dist/lib/playground/common.js +0 -179
  37. package/dist/lib/playground/common.js.map +0 -1
  38. package/dist/lib/playground/index.js +0 -66
  39. package/dist/lib/playground/index.js.map +0 -1
  40. package/dist/lib/playground/server.js +0 -302
  41. package/dist/lib/playground/server.js.map +0 -1
  42. package/dist/lib/playground/static-page.js +0 -138
  43. package/dist/lib/playground/static-page.js.map +0 -1
  44. package/dist/types/playground/agent.d.ts +0 -5
  45. package/dist/types/playground/common.d.ts +0 -10
  46. package/dist/types/playground/index.d.ts +0 -5
  47. package/dist/types/playground/server.d.ts +0 -20
  48. package/dist/types/playground/static-page.d.ts +0 -39
  49. /package/dist/types/{playground/bin.d.ts → bin.d.ts} +0 -0
@@ -1,179 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- formatErrorMessage: ()=>formatErrorMessage,
28
- validateStructuredParams: ()=>validateStructuredParams,
29
- validationAPIs: ()=>validationAPIs,
30
- dataExtractionAPIs: ()=>dataExtractionAPIs,
31
- executeAction: ()=>executeAction,
32
- noReplayAPIs: ()=>noReplayAPIs
33
- });
34
- const ai_model_namespaceObject = require("@midscene/core/ai-model");
35
- const dataExtractionAPIs = [
36
- 'aiQuery',
37
- 'aiBoolean',
38
- 'aiNumber',
39
- 'aiString',
40
- 'aiAsk'
41
- ];
42
- const validationAPIs = [
43
- 'aiAssert',
44
- 'aiWaitFor'
45
- ];
46
- const noReplayAPIs = [
47
- ...dataExtractionAPIs,
48
- ...validationAPIs
49
- ];
50
- const formatErrorMessage = (e)=>{
51
- const errorMessage = (null == e ? void 0 : e.message) || '';
52
- 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';
53
- return errorMessage || 'Unknown error';
54
- };
55
- async function parseStructuredParams(action, params, options = {}) {
56
- if (!(null == action ? void 0 : action.paramSchema) || !('shape' in action.paramSchema)) return [
57
- params.prompt || '',
58
- options
59
- ];
60
- const schema = action.paramSchema;
61
- const keys = Object.keys(schema.shape);
62
- const paramObj = {
63
- ...options
64
- };
65
- keys.forEach((key)=>{
66
- if (void 0 !== params[key] && null !== params[key] && '' !== params[key]) paramObj[key] = params[key];
67
- });
68
- return [
69
- paramObj
70
- ];
71
- }
72
- function validateStructuredParams(value, action) {
73
- if (!value.params) return {
74
- valid: false,
75
- errorMessage: 'Parameters are required'
76
- };
77
- if (!(null == action ? void 0 : action.paramSchema)) return {
78
- valid: true
79
- };
80
- try {
81
- var _action_paramSchema;
82
- const paramsForValidation = {
83
- ...value.params
84
- };
85
- const schema = action.paramSchema;
86
- if (schema) {
87
- const locatorFieldKeys = (0, ai_model_namespaceObject.findAllMidsceneLocatorField)(schema);
88
- locatorFieldKeys.forEach((key)=>{
89
- if ('string' == typeof paramsForValidation[key]) paramsForValidation[key] = {
90
- midscene_location_field_flag: true,
91
- prompt: paramsForValidation[key],
92
- center: [
93
- 0,
94
- 0
95
- ],
96
- rect: {
97
- left: 0,
98
- top: 0,
99
- width: 0,
100
- height: 0
101
- }
102
- };
103
- });
104
- }
105
- null == (_action_paramSchema = action.paramSchema) || _action_paramSchema.parse(paramsForValidation);
106
- } catch (error) {
107
- const zodError = error;
108
- if (zodError.errors && zodError.errors.length > 0) {
109
- const errorMessages = zodError.errors.filter((err)=>{
110
- const path = err.path.join('.');
111
- return !path.includes('center') && !path.includes('rect') && !path.includes('midscene_location_field_flag');
112
- }).map((err)=>{
113
- const field = err.path.join('.');
114
- return `${field}: ${err.message}`;
115
- });
116
- if (errorMessages.length > 0) return {
117
- valid: false,
118
- errorMessage: `Validation error: ${errorMessages.join(', ')}`
119
- };
120
- } else {
121
- const errorMsg = error instanceof Error ? error.message : 'Unknown validation error';
122
- return {
123
- valid: false,
124
- errorMessage: `Parameter validation failed: ${errorMsg}`
125
- };
126
- }
127
- }
128
- return {
129
- valid: true
130
- };
131
- }
132
- async function executeAction(activeAgent, actionType, actionSpace, value, deepThink) {
133
- const action = null == actionSpace ? void 0 : actionSpace.find((a)=>a.interfaceAlias === actionType || a.name === actionType);
134
- if (action && 'function' == typeof activeAgent.callActionInActionSpace) if (!value.params) return await activeAgent.callActionInActionSpace(action.name, {
135
- prompt: value.prompt,
136
- deepThink
137
- });
138
- else {
139
- const parsedParams = await parseStructuredParams(action, value.params, {
140
- deepThink
141
- });
142
- return await activeAgent.callActionInActionSpace(action.name, parsedParams[0]);
143
- }
144
- {
145
- const prompt = value.prompt;
146
- if ('aiAssert' === actionType) {
147
- const { pass, thought } = await (null == activeAgent ? void 0 : activeAgent.aiAssert(prompt, void 0, {
148
- keepRawResponse: true
149
- })) || {};
150
- return {
151
- pass,
152
- thought
153
- };
154
- }
155
- if (activeAgent && 'function' == typeof activeAgent[actionType]) return await activeAgent[actionType](prompt, {
156
- deepThink
157
- });
158
- throw new Error(`Unknown action type: ${actionType}`);
159
- }
160
- }
161
- exports.dataExtractionAPIs = __webpack_exports__.dataExtractionAPIs;
162
- exports.executeAction = __webpack_exports__.executeAction;
163
- exports.formatErrorMessage = __webpack_exports__.formatErrorMessage;
164
- exports.noReplayAPIs = __webpack_exports__.noReplayAPIs;
165
- exports.validateStructuredParams = __webpack_exports__.validateStructuredParams;
166
- exports.validationAPIs = __webpack_exports__.validationAPIs;
167
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
168
- "dataExtractionAPIs",
169
- "executeAction",
170
- "formatErrorMessage",
171
- "noReplayAPIs",
172
- "validateStructuredParams",
173
- "validationAPIs"
174
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
175
- Object.defineProperty(exports, '__esModule', {
176
- value: true
177
- });
178
-
179
- //# sourceMappingURL=common.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"playground/common.js","sources":["webpack://@midscene/web/webpack/runtime/define_property_getters","webpack://@midscene/web/webpack/runtime/has_own_property","webpack://@midscene/web/webpack/runtime/make_namespace_object","webpack://@midscene/web/./src/playground/common.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { DeviceAction } from '@midscene/core';\nimport { findAllMidsceneLocatorField } from '@midscene/core/ai-model';\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<any>,\n params: Record<string, any>,\n options: { deepThink?: boolean } = {},\n): Promise<any[]> {\n if (!action?.paramSchema || !('shape' in action.paramSchema)) {\n return [params.prompt || '', options];\n }\n\n const schema = action.paramSchema as any;\n const keys = Object.keys(schema.shape);\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: any,\n action: DeviceAction<any> | undefined,\n): { valid: boolean; errorMessage?: string } {\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: any,\n actionType: string,\n actionSpace: DeviceAction<any>[],\n value: any,\n deepThink: boolean,\n): Promise<any> {\n const action = actionSpace?.find(\n (a: DeviceAction<any>) =>\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(action, value.params, {\n deepThink,\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 deepThink,\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 })) || {};\n return { pass, thought };\n }\n\n // Fallback for methods not found in actionSpace\n if (activeAgent && typeof activeAgent[actionType] === 'function') {\n return await activeAgent[actionType](prompt, {\n deepThink,\n });\n }\n\n throw new Error(`Unknown action type: ${actionType}`);\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","dataExtractionAPIs","validationAPIs","noReplayAPIs","formatErrorMessage","e","errorMessage","parseStructuredParams","action","params","options","schema","keys","paramObj","undefined","validateStructuredParams","value","_action_paramSchema","paramsForValidation","locatorFieldKeys","findAllMidsceneLocatorField","error","zodError","errorMessages","err","path","field","errorMsg","Error","executeAction","activeAgent","actionType","actionSpace","deepThink","a","parsedParams","prompt","pass","thought"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,S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,MAAMD,WAAW,CAACC,WAAW,CAACK,QAAQ;YAC3CH;QACF;QAGF,MAAM,IAAIL,MAAM,CAAC,qBAAqB,EAAEG,YAAY;IACtD;AACF"}
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- StaticPageAgent: ()=>external_agent_js_namespaceObject.StaticPageAgent,
37
- ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED: ()=>common_namespaceObject.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED,
38
- StaticPage: ()=>external_static_page_js_default(),
39
- dataExtractionAPIs: ()=>external_common_js_namespaceObject.dataExtractionAPIs,
40
- noReplayAPIs: ()=>external_common_js_namespaceObject.noReplayAPIs,
41
- validationAPIs: ()=>external_common_js_namespaceObject.validationAPIs
42
- });
43
- const common_namespaceObject = require("@midscene/shared/common");
44
- const external_agent_js_namespaceObject = require("./agent.js");
45
- const external_common_js_namespaceObject = require("./common.js");
46
- const external_static_page_js_namespaceObject = require("./static-page.js");
47
- var external_static_page_js_default = /*#__PURE__*/ __webpack_require__.n(external_static_page_js_namespaceObject);
48
- exports.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = __webpack_exports__.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED;
49
- exports.StaticPage = __webpack_exports__.StaticPage;
50
- exports.StaticPageAgent = __webpack_exports__.StaticPageAgent;
51
- exports.dataExtractionAPIs = __webpack_exports__.dataExtractionAPIs;
52
- exports.noReplayAPIs = __webpack_exports__.noReplayAPIs;
53
- exports.validationAPIs = __webpack_exports__.validationAPIs;
54
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
55
- "ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED",
56
- "StaticPage",
57
- "StaticPageAgent",
58
- "dataExtractionAPIs",
59
- "noReplayAPIs",
60
- "validationAPIs"
61
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
62
- Object.defineProperty(exports, '__esModule', {
63
- value: true
64
- });
65
-
66
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"playground/index.js","sources":["webpack://@midscene/web/webpack/runtime/compat_get_default_export","webpack://@midscene/web/webpack/runtime/define_property_getters","webpack://@midscene/web/webpack/runtime/has_own_property","webpack://@midscene/web/webpack/runtime/make_namespace_object"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol"],"mappings":";;;IACAA,oBAAoB,CAAC,GAAG,CAACC;QACxB,IAAIC,SAASD,UAAUA,OAAO,UAAU,GACvC,IAAOA,MAAM,CAAC,UAAU,GACxB,IAAOA;QACRD,oBAAoB,CAAC,CAACE,QAAQ;YAAE,GAAGA;QAAO;QAC1C,OAAOA;IACR;;;ICPAF,oBAAoB,CAAC,GAAG,CAAC,UAASG;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGH,oBAAoB,CAAC,CAACG,YAAYC,QAAQ,CAACJ,oBAAoB,CAAC,CAAC,UAASI,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAJ,oBAAoB,CAAC,GAAG,CAACM,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFP,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOQ,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D"}
@@ -1,302 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- default: ()=>PlaygroundServer
37
- });
38
- const external_node_crypto_namespaceObject = require("node:crypto");
39
- const external_node_fs_namespaceObject = require("node:fs");
40
- const external_node_path_namespaceObject = require("node:path");
41
- const utils_namespaceObject = require("@midscene/core/utils");
42
- const constants_namespaceObject = require("@midscene/shared/constants");
43
- const env_namespaceObject = require("@midscene/shared/env");
44
- const shared_utils_namespaceObject = require("@midscene/shared/utils");
45
- const external_cors_namespaceObject = require("cors");
46
- var external_cors_default = /*#__PURE__*/ __webpack_require__.n(external_cors_namespaceObject);
47
- const external_dotenv_namespaceObject = require("dotenv");
48
- var external_dotenv_default = /*#__PURE__*/ __webpack_require__.n(external_dotenv_namespaceObject);
49
- const external_express_namespaceObject = require("express");
50
- var external_express_default = /*#__PURE__*/ __webpack_require__.n(external_express_namespaceObject);
51
- const external_common_js_namespaceObject = require("./common.js");
52
- function _define_property(obj, key, value) {
53
- if (key in obj) Object.defineProperty(obj, key, {
54
- value: value,
55
- enumerable: true,
56
- configurable: true,
57
- writable: true
58
- });
59
- else obj[key] = value;
60
- return obj;
61
- }
62
- const defaultPort = constants_namespaceObject.PLAYGROUND_SERVER_PORT;
63
- const errorHandler = (err, req, res, next)=>{
64
- console.error(err);
65
- res.status(500).json({
66
- error: err.message
67
- });
68
- };
69
- const setup = async ()=>{
70
- if (!shared_utils_namespaceObject.ifInBrowser && !shared_utils_namespaceObject.ifInWorker) external_dotenv_default().config();
71
- };
72
- class PlaygroundServer {
73
- filePathForUuid(uuid) {
74
- return (0, external_node_path_namespaceObject.join)(this.tmpDir, `${uuid}.json`);
75
- }
76
- saveContextFile(uuid, context) {
77
- const tmpFile = this.filePathForUuid(uuid);
78
- console.log(`save context file: ${tmpFile}`);
79
- (0, external_node_fs_namespaceObject.writeFileSync)(tmpFile, context);
80
- return tmpFile;
81
- }
82
- async launch(port) {
83
- this.port = port || defaultPort;
84
- this.app.use(errorHandler);
85
- this.app.use(external_cors_default()({
86
- origin: '*',
87
- credentials: true
88
- }));
89
- this.app.get('/status', async (req, res)=>{
90
- res.send({
91
- status: 'ok'
92
- });
93
- });
94
- this.app.get('/context/:uuid', async (req, res)=>{
95
- const { uuid } = req.params;
96
- const contextFile = this.filePathForUuid(uuid);
97
- if (!(0, external_node_fs_namespaceObject.existsSync)(contextFile)) return res.status(404).json({
98
- error: 'Context not found'
99
- });
100
- const context = (0, external_node_fs_namespaceObject.readFileSync)(contextFile, 'utf8');
101
- res.json({
102
- context
103
- });
104
- });
105
- this.app.get('/task-progress/:requestId', async (req, res)=>{
106
- const { requestId } = req.params;
107
- res.json({
108
- tip: this.taskProgressTips[requestId] || ''
109
- });
110
- });
111
- this.app.post('/action-space', external_express_default().json({
112
- limit: '30mb'
113
- }), async (req, res)=>{
114
- const { context } = req.body;
115
- if (!context) return res.status(400).json({
116
- error: 'context is required'
117
- });
118
- try {
119
- const page = new this.pageClass(context);
120
- const actionSpace = await page.actionSpace();
121
- const processedActionSpace = actionSpace.map((action)=>{
122
- if (action.paramSchema && 'object' == typeof action.paramSchema) {
123
- let processedSchema = null;
124
- try {
125
- if (action.paramSchema.shape && 'object' == typeof action.paramSchema.shape) processedSchema = {
126
- type: 'ZodObject',
127
- shape: action.paramSchema.shape
128
- };
129
- } catch (e) {
130
- console.warn('Failed to process paramSchema for action:', action.name, e);
131
- }
132
- return {
133
- ...action,
134
- paramSchema: processedSchema
135
- };
136
- }
137
- return action;
138
- });
139
- res.json(processedActionSpace);
140
- } catch (error) {
141
- console.error('Failed to get action space:', error);
142
- res.status(500).json({
143
- error: error.message
144
- });
145
- }
146
- });
147
- this.app.post('/playground-with-context', external_express_default().json({
148
- limit: '50mb'
149
- }), async (req, res)=>{
150
- const context = req.body.context;
151
- if (!context) return res.status(400).json({
152
- error: 'context is required'
153
- });
154
- const uuid = (0, external_node_crypto_namespaceObject.randomUUID)();
155
- this.saveContextFile(uuid, context);
156
- return res.json({
157
- location: `/playground/${uuid}`,
158
- uuid
159
- });
160
- });
161
- this.app.post('/execute', external_express_default().json({
162
- limit: '30mb'
163
- }), async (req, res)=>{
164
- const { context, type, prompt, params, requestId, deepThink, screenshotIncluded, domIncluded } = req.body;
165
- if (!context) return res.status(400).json({
166
- error: 'context is required'
167
- });
168
- if (!type) return res.status(400).json({
169
- error: 'type is required'
170
- });
171
- const page = new this.pageClass(context);
172
- const agent = new this.agentClass(page);
173
- if (requestId) {
174
- this.taskProgressTips[requestId] = '';
175
- this.activeAgents[requestId] = agent;
176
- agent.onTaskStartTip = (tip)=>{
177
- this.taskProgressTips[requestId] = tip;
178
- };
179
- }
180
- const response = {
181
- result: null,
182
- dump: null,
183
- error: null,
184
- reportHTML: null,
185
- requestId
186
- };
187
- const startTime = Date.now();
188
- try {
189
- const actionSpace = await page.actionSpace();
190
- const value = {
191
- prompt,
192
- params
193
- };
194
- response.result = await (0, external_common_js_namespaceObject.executeAction)(agent, type, actionSpace, value, deepThink || false);
195
- } catch (error) {
196
- response.error = (0, external_common_js_namespaceObject.formatErrorMessage)(error);
197
- }
198
- try {
199
- response.dump = JSON.parse(agent.dumpDataString());
200
- response.reportHTML = agent.reportHTMLString() || null;
201
- agent.writeOutActionDumps();
202
- agent.destroy();
203
- } catch (error) {
204
- console.error(`write out dump failed: requestId: ${requestId}, ${error.message}`);
205
- }
206
- res.send(response);
207
- const timeCost = Date.now() - startTime;
208
- if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
209
- else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
210
- if (requestId && this.activeAgents[requestId]) delete this.activeAgents[requestId];
211
- });
212
- this.app.get('/cancel/:requestId', async (req, res)=>{
213
- const { requestId } = req.params;
214
- if (!requestId) return res.status(400).json({
215
- error: 'requestId is required'
216
- });
217
- const agent = this.activeAgents[requestId];
218
- if (!agent) return res.status(404).json({
219
- error: 'No active agent found for this requestId'
220
- });
221
- try {
222
- await agent.destroy();
223
- delete this.activeAgents[requestId];
224
- res.json({
225
- status: 'cancelled'
226
- });
227
- } catch (error) {
228
- console.error(`Failed to cancel agent: ${error.message}`);
229
- res.status(500).json({
230
- error: `Failed to cancel: ${error.message}`
231
- });
232
- }
233
- });
234
- this.app.post('/config', external_express_default().json({
235
- limit: '1mb'
236
- }), async (req, res)=>{
237
- const { aiConfig } = req.body;
238
- if (!aiConfig || 'object' != typeof aiConfig) return res.status(400).json({
239
- error: 'aiConfig is required and must be an object'
240
- });
241
- try {
242
- (0, env_namespaceObject.overrideAIConfig)(aiConfig);
243
- return res.json({
244
- status: 'ok',
245
- message: 'AI config updated successfully'
246
- });
247
- } catch (error) {
248
- console.error(`Failed to update AI config: ${error.message}`);
249
- return res.status(500).json({
250
- error: `Failed to update AI config: ${error.message}`
251
- });
252
- }
253
- });
254
- if (this.staticPath) {
255
- this.app.get('/', (_req, res)=>{
256
- res.redirect('/index.html');
257
- });
258
- this.app.get('*', (req, res)=>{
259
- const requestedPath = (0, external_node_path_namespaceObject.join)(this.staticPath, req.path);
260
- if ((0, external_node_fs_namespaceObject.existsSync)(requestedPath)) res.sendFile(requestedPath);
261
- else res.sendFile((0, external_node_path_namespaceObject.join)(this.staticPath, 'index.html'));
262
- });
263
- }
264
- return new Promise((resolve)=>{
265
- const port = this.port;
266
- this.server = this.app.listen(port, ()=>{
267
- resolve(this);
268
- });
269
- });
270
- }
271
- close() {
272
- if (this.server) return this.server.close();
273
- }
274
- constructor(pageClass, agentClass, staticPath){
275
- _define_property(this, "app", void 0);
276
- _define_property(this, "tmpDir", void 0);
277
- _define_property(this, "server", void 0);
278
- _define_property(this, "port", void 0);
279
- _define_property(this, "pageClass", void 0);
280
- _define_property(this, "agentClass", void 0);
281
- _define_property(this, "staticPath", void 0);
282
- _define_property(this, "taskProgressTips", void 0);
283
- _define_property(this, "activeAgents", void 0);
284
- this.app = external_express_default()();
285
- this.tmpDir = (0, utils_namespaceObject.getTmpDir)();
286
- this.pageClass = pageClass;
287
- this.agentClass = agentClass;
288
- this.staticPath = staticPath;
289
- this.taskProgressTips = {};
290
- this.activeAgents = {};
291
- setup();
292
- }
293
- }
294
- exports["default"] = __webpack_exports__["default"];
295
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
296
- "default"
297
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
298
- Object.defineProperty(exports, '__esModule', {
299
- value: true
300
- });
301
-
302
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"playground/server.js","sources":["webpack://@midscene/web/webpack/runtime/compat_get_default_export","webpack://@midscene/web/webpack/runtime/define_property_getters","webpack://@midscene/web/webpack/runtime/has_own_property","webpack://@midscene/web/webpack/runtime/make_namespace_object","webpack://@midscene/web/./src/playground/server.ts"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","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';\n\nconst defaultPort = PLAYGROUND_SERVER_PORT;\n// const staticPath = join(__dirname, '../../static');\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 prompt,\n params,\n };\n\n response.result = await executeAction(\n agent,\n type,\n actionSpace,\n value,\n deepThink || false,\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":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","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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