@midscene/playground 1.5.0 → 1.5.1
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/adapters/remote-execution.mjs +4 -0
- package/dist/es/adapters/remote-execution.mjs.map +1 -1
- package/dist/es/common.mjs +7 -2
- package/dist/es/common.mjs.map +1 -1
- package/dist/es/server.mjs +2 -1
- package/dist/es/server.mjs.map +1 -1
- package/dist/lib/adapters/remote-execution.js +4 -0
- package/dist/lib/adapters/remote-execution.js.map +1 -1
- package/dist/lib/common.js +7 -2
- package/dist/lib/common.js.map +1 -1
- package/dist/lib/server.js +2 -1
- package/dist/lib/server.js.map +1 -1
- package/dist/types/types.d.ts +1 -0
- package/package.json +3 -3
- package/static/index.html +1 -1
- package/static/static/js/{index.9c511a82.js → index.04c353bc.js} +4 -4
- package/static/static/js/index.04c353bc.js.map +1 -0
- package/static/static/js/index.9c511a82.js.map +0 -1
- /package/static/static/js/{index.9c511a82.js.LICENSE.txt → index.04c353bc.js.LICENSE.txt} +0 -0
package/dist/lib/common.js
CHANGED
|
@@ -76,7 +76,7 @@ async function parseStructuredParams(action, params, options = {}) {
|
|
|
76
76
|
const locatePrompt = params[locateKey];
|
|
77
77
|
if (locatePrompt && 'string' == typeof locatePrompt) {
|
|
78
78
|
const detailedLocateParam = (0, yaml_namespaceObject.buildDetailedLocateParam)(locatePrompt, {
|
|
79
|
-
|
|
79
|
+
deepLocate: options.deepLocate,
|
|
80
80
|
cacheable: true
|
|
81
81
|
});
|
|
82
82
|
if (detailedLocateParam) paramObj[locateKey] = detailedLocateParam;
|
|
@@ -147,13 +147,18 @@ function validateStructuredParams(value, action) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
async function executeAction(activeAgent, actionType, actionSpace, value, options) {
|
|
150
|
+
if ('aiAct' !== actionType && void 0 !== options.deepThink) console.warn('[Playground] Received deepThink in non-aiAct action options. deepThink is expected to be used with aiAct during migration.', {
|
|
151
|
+
actionType,
|
|
152
|
+
requestId: options.requestId,
|
|
153
|
+
options
|
|
154
|
+
});
|
|
150
155
|
const action = actionSpace?.find((a)=>a.interfaceAlias === actionType || a.name === actionType);
|
|
151
156
|
if (action && 'function' == typeof activeAgent.callActionInActionSpace) if (value.params) {
|
|
152
157
|
const parsedParams = await parseStructuredParams(action, value.params, options);
|
|
153
158
|
return await activeAgent.callActionInActionSpace(action.name, parsedParams[0]);
|
|
154
159
|
} else {
|
|
155
160
|
const detailedLocateParam = value.prompt ? (0, yaml_namespaceObject.buildDetailedLocateParam)(value.prompt, {
|
|
156
|
-
|
|
161
|
+
deepLocate: options.deepLocate,
|
|
157
162
|
cacheable: true
|
|
158
163
|
}) : void 0;
|
|
159
164
|
const { deviceOptions: _, ...optionsWithoutDeviceOptions } = options;
|
package/dist/lib/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/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';\nimport { buildDetailedLocateParam } from '@midscene/core/yaml';\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\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\n if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) {\n return 'Further actions cannot be performed in the current environment';\n }\n\n return errorMessage || 'Unknown error';\n};\n\n// Parse structured parameters for callActionInActionSpace\nexport async 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 // Start with options and merge deviceOptions into the same level\n // Destructure to exclude deviceOptions from the final object\n const { deviceOptions: _, ...optionsWithoutDeviceOptions } = options;\n const paramObj: Record<string, unknown> = {\n ...optionsWithoutDeviceOptions,\n ...(options.deviceOptions || {}),\n };\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 // Check if there's a locate field that needs detailed locate param processing\n if (schema) {\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\n locatorFieldKeys.forEach((locateKey: string) => {\n const locatePrompt = params[locateKey];\n if (locatePrompt && typeof locatePrompt === 'string') {\n // Build detailed locate param using the locate prompt and options\n const detailedLocateParam = buildDetailedLocateParam(locatePrompt, {\n deepThink: options.deepThink,\n cacheable: true, // Default to true for playground\n });\n if (detailedLocateParam) {\n paramObj[locateKey] = detailedLocateParam;\n }\n }\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: string) => {\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 // For prompt-based actions, we need to build the detailed locate param\n const detailedLocateParam = value.prompt\n ? buildDetailedLocateParam(value.prompt, {\n deepThink: options.deepThink,\n cacheable: true,\n })\n : undefined;\n\n // Flatten deviceOptions into the params\n // Destructure to exclude deviceOptions from the final object\n const { deviceOptions: _, ...optionsWithoutDeviceOptions } = options;\n const actionParams = {\n locate: detailedLocateParam,\n ...optionsWithoutDeviceOptions,\n ...(options.deviceOptions || {}),\n };\n\n return await activeAgent.callActionInActionSpace(\n action.name,\n actionParams,\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":["__webpack_require__","definition","key","Object","obj","prop","Symbol","dataExtractionAPIs","validationAPIs","noReplayAPIs","formatErrorMessage","e","errorMessage","parseStructuredParams","action","params","options","schema","keys","_","optionsWithoutDeviceOptions","paramObj","undefined","locatorFieldKeys","findAllMidsceneLocatorField","locateKey","locatePrompt","detailedLocateParam","buildDetailedLocateParam","validateStructuredParams","value","paramsForValidation","error","zodError","errorMessages","err","path","field","errorMsg","Error","executeAction","activeAgent","actionType","actionSpace","a","parsedParams","actionParams","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,SAA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AAyBE,MAAM,MAAM,EAAE;YACrC,WAAWd,QAAQ,SAAS;YAC5B,WAAW;QACb,KACAM;QAIJ,MAAM,EAAE,eAAeH,CAAC,EAAE,GAAGC,6BAA6B,GAAGJ;QAC7D,MAAM8B,eAAe;YACnB,QAAQnB;YACR,GAAGP,2BAA2B;YAC9B,GAAIJ,QAAQ,aAAa,IAAI,CAAC,CAAC;QACjC;QAEA,OAAO,MAAMyB,YAAY,uBAAuB,CAC9C3B,OAAO,IAAI,EACXgC;IAEJ;IACK;QACL,MAAMC,SAASjB,MAAM,MAAM;QAE3B,IAAIY,AAAe,eAAfA,YAA2B;YAC7B,MAAM,EAAEM,IAAI,EAAEC,OAAO,EAAE,GACpB,MAAMR,aAAa,WAAWM,UAAU,IAAIzB,QAAW;gBACtD,iBAAiB;gBACjB,GAAGN,OAAO;YACZ,MAAO,CAAC;YACV,OAAO;gBAAE,MAAMgC,QAAQ;gBAAO,SAASC,WAAW;YAAG;QACvD;QAGA,IAAIR,eAAe,AAAmC,cAAnC,OAAOA,WAAW,CAACC,WAAW,EAC/C,OAAO,MAAMD,WAAW,CAACC,WAAW,CAACK,QAAQ/B;QAG/C,MAAM,IAAIuB,MAAM,CAAC,qBAAqB,EAAEG,YAAY;IACtD;AACF"}
|
|
1
|
+
{"version":3,"file":"common.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/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';\nimport { buildDetailedLocateParam } from '@midscene/core/yaml';\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\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\n if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) {\n return 'Further actions cannot be performed in the current environment';\n }\n\n return errorMessage || 'Unknown error';\n};\n\n// Parse structured parameters for callActionInActionSpace\nexport async 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 // Start with options and merge deviceOptions into the same level\n // Destructure to exclude deviceOptions from the final object\n const { deviceOptions: _, ...optionsWithoutDeviceOptions } = options;\n const paramObj: Record<string, unknown> = {\n ...optionsWithoutDeviceOptions,\n ...(options.deviceOptions || {}),\n };\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 // Check if there's a locate field that needs detailed locate param processing\n if (schema) {\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\n locatorFieldKeys.forEach((locateKey: string) => {\n const locatePrompt = params[locateKey];\n if (locatePrompt && typeof locatePrompt === 'string') {\n // Build detailed locate param using the locate prompt and options\n const detailedLocateParam = buildDetailedLocateParam(locatePrompt, {\n deepLocate: options.deepLocate,\n cacheable: true, // Default to true for playground\n });\n if (detailedLocateParam) {\n paramObj[locateKey] = detailedLocateParam;\n }\n }\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: string) => {\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 if (actionType !== 'aiAct' && options.deepThink !== undefined) {\n console.warn(\n '[Playground] Received deepThink in non-aiAct action options. deepThink is expected to be used with aiAct during migration.',\n {\n actionType,\n requestId: options.requestId,\n options,\n },\n );\n }\n\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 // For prompt-based actions, we need to build the detailed locate param\n const detailedLocateParam = value.prompt\n ? buildDetailedLocateParam(value.prompt, {\n deepLocate: options.deepLocate,\n cacheable: true,\n })\n : undefined;\n\n // Flatten deviceOptions into the params\n // Destructure to exclude deviceOptions from the final object\n const { deviceOptions: _, ...optionsWithoutDeviceOptions } = options;\n const actionParams = {\n locate: detailedLocateParam,\n ...optionsWithoutDeviceOptions,\n ...(options.deviceOptions || {}),\n };\n\n return await activeAgent.callActionInActionSpace(\n action.name,\n actionParams,\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":["__webpack_require__","definition","key","Object","obj","prop","Symbol","dataExtractionAPIs","validationAPIs","noReplayAPIs","formatErrorMessage","e","errorMessage","parseStructuredParams","action","params","options","schema","keys","_","optionsWithoutDeviceOptions","paramObj","undefined","locatorFieldKeys","findAllMidsceneLocatorField","locateKey","locatePrompt","detailedLocateParam","buildDetailedLocateParam","validateStructuredParams","value","paramsForValidation","error","zodError","errorMessages","err","path","field","errorMsg","Error","executeAction","activeAgent","actionType","actionSpace","console","a","parsedParams","actionParams","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,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;ACKO,MAAMI,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,GAAG,WAAW;IAEnC,IAAIC,aAAa,QAAQ,CAAC,2BACxB,OAAO;IAGT,IAAIA,aAAa,QAAQ,CAAC,gCACxB,OAAO;IAGT,OAAOA,gBAAgB;AACzB;AAGO,eAAeC,sBACpBC,MAA6B,EAC7BC,MAA+B,EAC/BC,UAA4B,CAAC,CAAC;IAE9B,IAAI,CAACF,QAAQ,eAAe,CAAE,YAAWA,OAAO,WAAU,GACxD,OAAO;QAACC,OAAO,MAAM,IAAI;QAAIC;KAAQ;IAGvC,MAAMC,SAASH,OAAO,WAAW;IACjC,MAAMI,OACJD,UAAU,WAAWA,SACjBd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AAW,CAACM,QAAQhC;QAG/C,MAAM,IAAIuB,MAAM,CAAC,qBAAqB,EAAEG,YAAY;IACtD;AACF"}
|
package/dist/lib/server.js
CHANGED
|
@@ -209,7 +209,7 @@ class PlaygroundServer {
|
|
|
209
209
|
});
|
|
210
210
|
});
|
|
211
211
|
this._app.post('/execute', async (req, res)=>{
|
|
212
|
-
const { type, prompt, params, requestId, deepThink, screenshotIncluded, domIncluded, deviceOptions } = req.body;
|
|
212
|
+
const { type, prompt, params, requestId, deepLocate, deepThink, screenshotIncluded, domIncluded, deviceOptions } = req.body;
|
|
213
213
|
if (!type) return res.status(400).json({
|
|
214
214
|
error: 'type is required'
|
|
215
215
|
});
|
|
@@ -265,6 +265,7 @@ class PlaygroundServer {
|
|
|
265
265
|
params
|
|
266
266
|
};
|
|
267
267
|
response.result = await (0, external_common_js_namespaceObject.executeAction)(this.agent, type, actionSpace, value, {
|
|
268
|
+
deepLocate,
|
|
268
269
|
deepThink,
|
|
269
270
|
screenshotIncluded,
|
|
270
271
|
domIncluded,
|
package/dist/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/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 { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport http from 'node:http';\nimport type { Server } from 'node:http';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ExecutionDump } from '@midscene/core';\nimport { GroupedActionDump } from '@midscene/core';\nimport type { Agent as PageAgent } from '@midscene/core/agent';\nimport { getTmpDir } from '@midscene/core/utils';\nimport { PLAYGROUND_SERVER_PORT } from '@midscene/shared/constants';\nimport {\n globalModelConfigManager,\n overrideAIConfig,\n} from '@midscene/shared/env';\nimport { uuid } from '@midscene/shared/utils';\nimport express, { type Request, type Response } from 'express';\nimport { executeAction, formatErrorMessage } from './common';\n\nimport 'dotenv/config';\n\nconst defaultPort = PLAYGROUND_SERVER_PORT;\n\n// Static path for playground files\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst STATIC_PATH = join(__dirname, '..', '..', 'static');\n\nconst errorHandler = (\n err: unknown,\n req: Request,\n res: Response,\n next: express.NextFunction,\n) => {\n console.error(err);\n const errorMessage =\n err instanceof Error ? err.message : 'Internal server error';\n res.status(500).json({\n error: errorMessage,\n });\n};\n\nclass PlaygroundServer {\n private _app: express.Application;\n tmpDir: string;\n server?: Server;\n port?: number | null;\n agent: PageAgent;\n staticPath: string;\n taskExecutionDumps: Record<string, ExecutionDump | null>; // Store execution dumps directly\n id: string; // Unique identifier for this server instance\n\n private _initialized = false;\n\n // Native MJPEG stream probe: null = not tested, true/false = result\n private _nativeMjpegAvailable: boolean | null = null;\n\n // Factory function for recreating agent\n private agentFactory?: (() => PageAgent | Promise<PageAgent>) | null;\n\n // Track current running task\n private currentTaskId: string | null = null;\n\n // Flag to pause MJPEG polling during agent recreation\n private _agentReady = true;\n\n constructor(\n agent: PageAgent | (() => PageAgent) | (() => Promise<PageAgent>),\n staticPath = STATIC_PATH,\n id?: string, // Optional override ID\n ) {\n this._app = express();\n this.tmpDir = getTmpDir()!;\n this.staticPath = staticPath;\n this.taskExecutionDumps = {}; // Initialize as empty object\n // Use provided ID, or generate random UUID for each startup\n this.id = id || uuid();\n\n // Support both instance and factory function modes\n if (typeof agent === 'function') {\n this.agentFactory = agent;\n this.agent = null as any; // Will be initialized in launch()\n } else {\n this.agent = agent;\n this.agentFactory = null;\n }\n }\n\n /**\n * Get the Express app instance for custom configuration\n *\n * IMPORTANT: Add middleware (like CORS) BEFORE calling launch()\n * The routes are initialized when launch() is called, so middleware\n * added after launch() will not affect the API routes.\n *\n * @example\n * ```typescript\n * import cors from 'cors';\n *\n * const server = new PlaygroundServer(agent);\n *\n * // Add CORS middleware before launch\n * server.app.use(cors({\n * origin: true,\n * credentials: true,\n * methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']\n * }));\n *\n * await server.launch();\n * ```\n */\n get app(): express.Application {\n return this._app;\n }\n\n /**\n * Initialize Express app with all routes and middleware\n * Called automatically by launch() if not already initialized\n */\n private initializeApp(): void {\n if (this._initialized) return;\n\n // Built-in middleware to parse JSON bodies\n this._app.use(express.json({ limit: '50mb' }));\n\n // Context update middleware (after JSON parsing)\n this._app.use(\n (req: Request, _res: Response, next: express.NextFunction) => {\n const { context } = req.body || {};\n if (\n context &&\n 'updateContext' in this.agent.interface &&\n typeof this.agent.interface.updateContext === 'function'\n ) {\n this.agent.interface.updateContext(context);\n console.log('Context updated by PlaygroundServer middleware');\n }\n next();\n },\n );\n\n // NOTE: CORS middleware should be added externally via server.app.use()\n // before calling server.launch() if needed\n\n // API routes\n this.setupRoutes();\n\n // Static file serving (if staticPath is provided)\n this.setupStaticRoutes();\n\n // Error handler middleware (must be last)\n this._app.use(errorHandler);\n\n this._initialized = true;\n }\n\n filePathForUuid(uuid: string) {\n // Validate uuid to prevent path traversal attacks\n // Only allow alphanumeric characters and hyphens\n if (!/^[a-zA-Z0-9-]+$/.test(uuid)) {\n throw new Error('Invalid uuid format');\n }\n const filePath = join(this.tmpDir, `${uuid}.json`);\n // Double-check that resolved path is within tmpDir\n const resolvedPath = resolve(filePath);\n const resolvedTmpDir = resolve(this.tmpDir);\n if (!resolvedPath.startsWith(resolvedTmpDir)) {\n throw new Error('Invalid path');\n }\n return filePath;\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 /**\n * Recreate agent instance (for cancellation)\n */\n private async recreateAgent(): Promise<void> {\n if (!this.agentFactory) {\n throw new Error(\n 'Cannot recreate agent: factory function not provided. Attempting to destroy existing agent only.',\n );\n }\n\n this._agentReady = false;\n console.log('Recreating agent to cancel current task...');\n\n // Destroy old agent instance\n try {\n if (this.agent && typeof this.agent.destroy === 'function') {\n await this.agent.destroy();\n }\n } catch (error) {\n console.warn('Failed to destroy old agent:', error);\n }\n\n // Create new agent instance\n try {\n this.agent = await this.agentFactory();\n this._agentReady = true;\n console.log('Agent recreated successfully');\n } catch (error) {\n this._agentReady = true;\n console.error('Failed to recreate agent:', error);\n throw error;\n }\n }\n\n /**\n * Setup all API routes\n */\n private setupRoutes(): void {\n this._app.get('/status', async (req: Request, res: Response) => {\n res.send({\n status: 'ok',\n id: this.id,\n });\n });\n\n this._app.get('/context/:uuid', async (req: Request, res: Response) => {\n const { uuid } = req.params;\n let contextFile: string;\n try {\n contextFile = this.filePathForUuid(uuid);\n } catch {\n return res.status(400).json({\n error: 'Invalid uuid format',\n });\n }\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(\n '/task-progress/:requestId',\n async (req: Request, res: Response) => {\n const { requestId } = req.params;\n const executionDump = this.taskExecutionDumps[requestId] || null;\n\n res.json({\n executionDump,\n });\n },\n );\n\n this._app.post('/action-space', async (req: Request, res: Response) => {\n try {\n let actionSpace = [];\n\n actionSpace = this.agent.interface.actionSpace();\n\n // Process actionSpace to make paramSchema serializable with shape info\n const processedActionSpace = actionSpace.map((action: unknown) => {\n if (action && typeof action === 'object' && 'paramSchema' in action) {\n const typedAction = action as {\n paramSchema?: { shape?: object; [key: string]: unknown };\n [key: string]: unknown;\n };\n if (\n typedAction.paramSchema &&\n typeof typedAction.paramSchema === 'object'\n ) {\n // Extract shape information from Zod schema\n let processedSchema = null;\n\n try {\n // Extract shape from runtime Zod object\n if (\n typedAction.paramSchema.shape &&\n typeof typedAction.paramSchema.shape === 'object'\n ) {\n processedSchema = {\n type: 'ZodObject',\n shape: typedAction.paramSchema.shape,\n };\n }\n } catch (e) {\n const actionName =\n 'name' in typedAction && typeof typedAction.name === 'string'\n ? typedAction.name\n : 'unknown';\n console.warn(\n 'Failed to process paramSchema for action:',\n actionName,\n e,\n );\n }\n\n return {\n ...typedAction,\n paramSchema: processedSchema,\n };\n }\n }\n return action;\n });\n\n res.json(processedActionSpace);\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error('Failed to get action space:', error);\n res.status(500).json({\n error: errorMessage,\n });\n }\n });\n\n // -------------------------\n // actions from report file\n this._app.post(\n '/playground-with-context',\n async (req: Request, res: Response) => {\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 requestId = uuid();\n this.saveContextFile(requestId, context);\n return res.json({\n location: `/playground/${requestId}`,\n uuid: requestId,\n });\n },\n );\n\n this._app.post('/execute', async (req: Request, res: Response) => {\n const {\n type,\n prompt,\n params,\n requestId,\n deepThink,\n screenshotIncluded,\n domIncluded,\n deviceOptions,\n } = req.body;\n\n if (!type) {\n return res.status(400).json({\n error: 'type is required',\n });\n }\n\n // Always recreate agent before execution to ensure latest config is applied\n if (this.agentFactory) {\n this._agentReady = false;\n console.log('Destroying old agent before execution...');\n try {\n if (this.agent && typeof this.agent.destroy === 'function') {\n await this.agent.destroy();\n }\n } catch (error) {\n console.warn('Failed to destroy old agent:', error);\n }\n\n console.log('Creating new agent with latest config...');\n try {\n this.agent = await this.agentFactory();\n this._agentReady = true;\n console.log('Agent created successfully');\n } catch (error) {\n this._agentReady = true;\n console.error('Failed to create agent:', error);\n return res.status(500).json({\n error: `Failed to create agent: ${error instanceof Error ? error.message : 'Unknown error'}`,\n });\n }\n }\n\n // Update device options if provided\n if (\n deviceOptions &&\n this.agent.interface &&\n 'options' in this.agent.interface\n ) {\n this.agent.interface.options = {\n ...(this.agent.interface.options || {}),\n ...deviceOptions,\n };\n }\n\n // Check if another task is running\n if (this.currentTaskId) {\n return res.status(409).json({\n error: 'Another task is already running',\n currentTaskId: this.currentTaskId,\n });\n }\n\n // Lock this task\n if (requestId) {\n this.currentTaskId = requestId;\n this.taskExecutionDumps[requestId] = null;\n\n // Use onDumpUpdate to receive and store executionDump directly\n this.agent.onDumpUpdate = (\n _dump: string,\n executionDump?: ExecutionDump,\n ) => {\n if (executionDump) {\n // Store the execution dump directly without transformation\n this.taskExecutionDumps[requestId] = executionDump;\n }\n };\n }\n\n const response: {\n result: unknown;\n dump: ExecutionDump | 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 = this.agent.interface.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 this.agent,\n type,\n actionSpace,\n value,\n {\n deepThink,\n screenshotIncluded,\n domIncluded,\n deviceOptions,\n },\n );\n } catch (error: unknown) {\n response.error = formatErrorMessage(error);\n }\n\n try {\n const dumpString = this.agent.dumpDataString({\n inlineScreenshots: true,\n });\n if (dumpString) {\n const groupedDump =\n GroupedActionDump.fromSerializedString(dumpString);\n // Extract first execution from grouped dump, matching local execution adapter behavior\n response.dump = groupedDump.executions?.[0] || null;\n } else {\n response.dump = null;\n }\n response.reportHTML =\n this.agent.reportHTMLString({ inlineScreenshots: true }) || null;\n\n this.agent.writeOutActionDumps();\n this.agent.resetDump();\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(\n `write out dump failed: requestId: ${requestId}, ${errorMessage}`,\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 task execution dumps and unlock after execution completes\n if (requestId) {\n delete this.taskExecutionDumps[requestId];\n // Release the lock\n if (this.currentTaskId === requestId) {\n this.currentTaskId = null;\n }\n }\n });\n\n this._app.post(\n '/cancel/:requestId',\n async (req: Request, res: Response) => {\n const { requestId } = req.params;\n\n if (!requestId) {\n return res.status(400).json({\n error: 'requestId is required',\n });\n }\n\n try {\n // Check if this is the current running task\n if (this.currentTaskId !== requestId) {\n return res.json({\n status: 'not_found',\n message: 'Task not found or already completed',\n });\n }\n\n console.log(`Cancelling task: ${requestId}`);\n\n // Get current execution data before cancelling (dump and reportHTML)\n let dump: any = null;\n let reportHTML: string | null = null;\n\n try {\n const dumpString = this.agent.dumpDataString?.({\n inlineScreenshots: true,\n });\n if (dumpString) {\n const groupedDump =\n GroupedActionDump.fromSerializedString(dumpString);\n // Extract first execution from grouped dump\n dump = groupedDump.executions?.[0] || null;\n }\n\n reportHTML =\n this.agent.reportHTMLString?.({ inlineScreenshots: true }) ||\n null;\n } catch (error: unknown) {\n console.warn('Failed to get execution data before cancel:', error);\n }\n\n // Destroy agent to cancel the current task\n // No need to recreate here — /execute always creates a fresh agent before each run\n try {\n if (this.agent && typeof this.agent.destroy === 'function') {\n await this.agent.destroy();\n }\n } catch (error) {\n console.warn('Failed to destroy agent during cancel:', error);\n }\n\n // Clean up\n delete this.taskExecutionDumps[requestId];\n this.currentTaskId = null;\n\n res.json({\n status: 'cancelled',\n message: 'Task cancelled successfully',\n dump,\n reportHTML,\n });\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`Failed to cancel: ${errorMessage}`);\n res.status(500).json({\n error: `Failed to cancel: ${errorMessage}`,\n });\n }\n },\n );\n\n // Screenshot API for real-time screenshot polling\n this._app.get('/screenshot', async (_req: Request, res: Response) => {\n try {\n // Check if page has screenshotBase64 method\n if (typeof this.agent.interface.screenshotBase64 !== 'function') {\n return res.status(500).json({\n error: 'Screenshot method not available on current interface',\n });\n }\n\n const base64Screenshot = await this.agent.interface.screenshotBase64();\n\n res.json({\n screenshot: base64Screenshot,\n timestamp: Date.now(),\n });\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`Failed to take screenshot: ${errorMessage}`);\n res.status(500).json({\n error: `Failed to take screenshot: ${errorMessage}`,\n });\n }\n });\n\n // MJPEG streaming endpoint for real-time screen preview\n // Proxies native MJPEG stream (e.g. WDA MJPEG server) when available,\n // falls back to polling screenshotBase64() otherwise.\n this._app.get('/mjpeg', async (req: Request, res: Response) => {\n const nativeUrl = this.agent?.interface?.mjpegStreamUrl;\n\n if (nativeUrl && this._nativeMjpegAvailable !== false) {\n const proxyOk = await this.probeAndProxyNativeMjpeg(\n nativeUrl,\n req,\n res,\n );\n if (proxyOk) return;\n }\n\n if (typeof this.agent?.interface?.screenshotBase64 !== 'function') {\n return res.status(500).json({\n error: 'Screenshot method not available on current interface',\n });\n }\n\n await this.startPollingMjpegStream(req, res);\n });\n\n // Interface info API for getting interface type and description\n this._app.get('/interface-info', async (_req: Request, res: Response) => {\n try {\n const type = this.agent.interface.interfaceType || 'Unknown';\n const description = this.agent.interface.describe?.() || undefined;\n\n res.json({\n type,\n description,\n });\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`Failed to get interface info: ${errorMessage}`);\n res.status(500).json({\n error: `Failed to get interface info: ${errorMessage}`,\n });\n }\n });\n\n this.app.post('/config', async (req: Request, res: Response) => {\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 if (Object.keys(aiConfig).length === 0) {\n return res.json({\n status: 'ok',\n message: 'AI config not changed due to empty object',\n });\n }\n\n try {\n overrideAIConfig(aiConfig);\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`Failed to update AI config: ${errorMessage}`);\n return res.status(500).json({\n error: `Failed to update AI config: ${errorMessage}`,\n });\n }\n\n // Validate the config immediately so the frontend gets early feedback\n try {\n globalModelConfigManager.getModelConfig('default');\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`AI config validation failed: ${errorMessage}`);\n return res.status(400).json({\n error: errorMessage,\n });\n }\n\n // Note: Agent will be recreated on next execution to apply new config\n return res.json({\n status: 'ok',\n message:\n 'AI config updated. Agent will be recreated on next execution.',\n });\n });\n }\n\n /**\n * Probe and proxy a native MJPEG stream (e.g. WDA MJPEG server).\n * Result is cached so we only probe once per server lifetime.\n */\n private probeAndProxyNativeMjpeg(\n nativeUrl: string,\n req: Request,\n res: Response,\n ): Promise<boolean> {\n return new Promise<boolean>((resolve) => {\n console.log(`MJPEG: trying native stream from ${nativeUrl}`);\n const proxyReq = http.get(nativeUrl, (proxyRes) => {\n this._nativeMjpegAvailable = true;\n console.log('MJPEG: streaming via native WDA MJPEG server');\n const contentType = proxyRes.headers['content-type'];\n if (contentType) {\n res.setHeader('Content-Type', contentType);\n }\n res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');\n res.setHeader('Connection', 'keep-alive');\n proxyRes.pipe(res);\n req.on('close', () => proxyReq.destroy());\n resolve(true);\n });\n proxyReq.on('error', (err) => {\n this._nativeMjpegAvailable = false;\n console.warn(\n `MJPEG: native stream unavailable (${err.message}), using polling mode`,\n );\n resolve(false);\n });\n });\n }\n\n /**\n * Stream screenshots as MJPEG by polling screenshotBase64().\n */\n private async startPollingMjpegStream(\n req: Request,\n res: Response,\n ): Promise<void> {\n const defaultMjpegFps = 10;\n const maxMjpegFps = 30;\n const maxErrorBackoffMs = 3000;\n const errorLogThreshold = 3;\n\n const parsedFps = Number(req.query.fps);\n const fps = Math.min(\n Math.max(Number.isNaN(parsedFps) ? defaultMjpegFps : parsedFps, 1),\n maxMjpegFps,\n );\n const interval = Math.round(1000 / fps);\n const boundary = 'mjpeg-boundary';\n console.log(`MJPEG: streaming via polling mode (${fps}fps)`);\n\n res.setHeader(\n 'Content-Type',\n `multipart/x-mixed-replace; boundary=${boundary}`,\n );\n res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');\n res.setHeader('Connection', 'keep-alive');\n\n let stopped = false;\n let consecutiveErrors = 0;\n req.on('close', () => {\n stopped = true;\n });\n\n while (!stopped) {\n // Skip frame while agent is being recreated\n if (!this._agentReady) {\n await new Promise((r) => setTimeout(r, 200));\n continue;\n }\n\n const frameStart = Date.now();\n try {\n const base64 = await this.agent.interface.screenshotBase64();\n if (stopped) break;\n consecutiveErrors = 0;\n\n const raw = base64.replace(/^data:image\\/\\w+;base64,/, '');\n const buf = Buffer.from(raw, 'base64');\n\n res.write(`--${boundary}\\r\\n`);\n res.write('Content-Type: image/jpeg\\r\\n');\n res.write(`Content-Length: ${buf.length}\\r\\n\\r\\n`);\n res.write(buf);\n res.write('\\r\\n');\n } catch (err) {\n if (stopped) break;\n consecutiveErrors++;\n if (consecutiveErrors <= errorLogThreshold) {\n console.error('MJPEG frame error:', err);\n } else if (consecutiveErrors === errorLogThreshold + 1) {\n console.error(\n 'MJPEG: suppressing further errors, retrying silently...',\n );\n }\n const backoff = Math.min(1000 * consecutiveErrors, maxErrorBackoffMs);\n await new Promise((r) => setTimeout(r, backoff));\n continue;\n }\n\n const elapsed = Date.now() - frameStart;\n const remaining = interval - elapsed;\n if (remaining > 0) {\n await new Promise((r) => setTimeout(r, remaining));\n }\n }\n }\n\n /**\n * Setup static file serving routes\n */\n private setupStaticRoutes(): void {\n // Handle index.html with port injection\n this._app.get('/', (_req: Request, res: Response) => {\n this.serveHtmlWithPorts(res);\n });\n\n this._app.get('/index.html', (_req: Request, res: Response) => {\n this.serveHtmlWithPorts(res);\n });\n\n // Use express.static middleware for secure static file serving\n this._app.use(express.static(this.staticPath));\n\n // Fallback to index.html for SPA routing\n this._app.get('*', (_req: Request, res: Response) => {\n this.serveHtmlWithPorts(res);\n });\n }\n\n /**\n * Serve HTML with injected port configuration\n */\n private serveHtmlWithPorts(res: Response): void {\n try {\n const htmlPath = join(this.staticPath, 'index.html');\n let html = readFileSync(htmlPath, 'utf8');\n\n // Get scrcpy server port from global\n const scrcpyPort = (global as any).scrcpyServerPort || this.port! + 1;\n\n // Inject scrcpy port configuration script into HTML head\n const configScript = `\n <script>\n window.SCRCPY_PORT = ${scrcpyPort};\n </script>\n `;\n\n // Insert the script before closing </head> tag\n html = html.replace('</head>', `${configScript}</head>`);\n\n res.setHeader('Content-Type', 'text/html');\n res.send(html);\n } catch (error) {\n console.error('Error serving HTML with ports:', error);\n res.status(500).send('Internal Server Error');\n }\n }\n\n /**\n * Launch the server on specified port\n */\n async launch(port?: number): Promise<PlaygroundServer> {\n // If using factory mode, initialize agent\n if (this.agentFactory) {\n console.log('Initializing agent from factory function...');\n this.agent = await this.agentFactory();\n console.log('Agent initialized successfully');\n }\n\n // Initialize routes now, after any middleware has been added\n this.initializeApp();\n\n this.port = port || defaultPort;\n\n return new Promise((resolve) => {\n const serverPort = this.port;\n this.server = this._app.listen(serverPort, () => {\n resolve(this);\n });\n });\n }\n\n /**\n * Close the server and clean up resources\n */\n async close(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (this.server) {\n // Clean up the single agent\n try {\n this.agent.destroy();\n } catch (error) {\n console.warn('Failed to destroy agent:', error);\n }\n this.taskExecutionDumps = {};\n\n // Close the server\n this.server.close((error) => {\n if (error) {\n reject(error);\n } else {\n this.server = undefined;\n resolve();\n }\n });\n } else {\n resolve();\n }\n });\n }\n}\n\nexport default PlaygroundServer;\nexport { PlaygroundServer };\n"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","defaultPort","PLAYGROUND_SERVER_PORT","__filename","fileURLToPath","__dirname","dirname","STATIC_PATH","join","errorHandler","err","req","res","next","console","errorMessage","Error","PlaygroundServer","express","_res","context","uuid","filePath","resolvedPath","resolve","resolvedTmpDir","tmpFile","writeFileSync","error","contextFile","existsSync","readFileSync","requestId","executionDump","actionSpace","processedActionSpace","action","typedAction","processedSchema","e","actionName","type","prompt","params","deepThink","screenshotIncluded","domIncluded","deviceOptions","_dump","response","startTime","Date","value","executeAction","formatErrorMessage","dumpString","groupedDump","GroupedActionDump","timeCost","dump","reportHTML","_req","base64Screenshot","nativeUrl","proxyOk","description","undefined","aiConfig","overrideAIConfig","globalModelConfigManager","Promise","proxyReq","http","proxyRes","contentType","defaultMjpegFps","maxMjpegFps","maxErrorBackoffMs","errorLogThreshold","parsedFps","Number","fps","Math","interval","boundary","stopped","consecutiveErrors","r","setTimeout","frameStart","base64","raw","buf","Buffer","backoff","elapsed","remaining","htmlPath","html","scrcpyPort","global","configScript","port","serverPort","reject","agent","staticPath","id","getTmpDir"],"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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AAEA,eAAexF"}
|
|
1
|
+
{"version":3,"file":"server.js","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/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 { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport http from 'node:http';\nimport type { Server } from 'node:http';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ExecutionDump } from '@midscene/core';\nimport { GroupedActionDump } from '@midscene/core';\nimport type { Agent as PageAgent } from '@midscene/core/agent';\nimport { getTmpDir } from '@midscene/core/utils';\nimport { PLAYGROUND_SERVER_PORT } from '@midscene/shared/constants';\nimport {\n globalModelConfigManager,\n overrideAIConfig,\n} from '@midscene/shared/env';\nimport { uuid } from '@midscene/shared/utils';\nimport express, { type Request, type Response } from 'express';\nimport { executeAction, formatErrorMessage } from './common';\n\nimport 'dotenv/config';\n\nconst defaultPort = PLAYGROUND_SERVER_PORT;\n\n// Static path for playground files\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst STATIC_PATH = join(__dirname, '..', '..', 'static');\n\nconst errorHandler = (\n err: unknown,\n req: Request,\n res: Response,\n next: express.NextFunction,\n) => {\n console.error(err);\n const errorMessage =\n err instanceof Error ? err.message : 'Internal server error';\n res.status(500).json({\n error: errorMessage,\n });\n};\n\nclass PlaygroundServer {\n private _app: express.Application;\n tmpDir: string;\n server?: Server;\n port?: number | null;\n agent: PageAgent;\n staticPath: string;\n taskExecutionDumps: Record<string, ExecutionDump | null>; // Store execution dumps directly\n id: string; // Unique identifier for this server instance\n\n private _initialized = false;\n\n // Native MJPEG stream probe: null = not tested, true/false = result\n private _nativeMjpegAvailable: boolean | null = null;\n\n // Factory function for recreating agent\n private agentFactory?: (() => PageAgent | Promise<PageAgent>) | null;\n\n // Track current running task\n private currentTaskId: string | null = null;\n\n // Flag to pause MJPEG polling during agent recreation\n private _agentReady = true;\n\n constructor(\n agent: PageAgent | (() => PageAgent) | (() => Promise<PageAgent>),\n staticPath = STATIC_PATH,\n id?: string, // Optional override ID\n ) {\n this._app = express();\n this.tmpDir = getTmpDir()!;\n this.staticPath = staticPath;\n this.taskExecutionDumps = {}; // Initialize as empty object\n // Use provided ID, or generate random UUID for each startup\n this.id = id || uuid();\n\n // Support both instance and factory function modes\n if (typeof agent === 'function') {\n this.agentFactory = agent;\n this.agent = null as any; // Will be initialized in launch()\n } else {\n this.agent = agent;\n this.agentFactory = null;\n }\n }\n\n /**\n * Get the Express app instance for custom configuration\n *\n * IMPORTANT: Add middleware (like CORS) BEFORE calling launch()\n * The routes are initialized when launch() is called, so middleware\n * added after launch() will not affect the API routes.\n *\n * @example\n * ```typescript\n * import cors from 'cors';\n *\n * const server = new PlaygroundServer(agent);\n *\n * // Add CORS middleware before launch\n * server.app.use(cors({\n * origin: true,\n * credentials: true,\n * methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']\n * }));\n *\n * await server.launch();\n * ```\n */\n get app(): express.Application {\n return this._app;\n }\n\n /**\n * Initialize Express app with all routes and middleware\n * Called automatically by launch() if not already initialized\n */\n private initializeApp(): void {\n if (this._initialized) return;\n\n // Built-in middleware to parse JSON bodies\n this._app.use(express.json({ limit: '50mb' }));\n\n // Context update middleware (after JSON parsing)\n this._app.use(\n (req: Request, _res: Response, next: express.NextFunction) => {\n const { context } = req.body || {};\n if (\n context &&\n 'updateContext' in this.agent.interface &&\n typeof this.agent.interface.updateContext === 'function'\n ) {\n this.agent.interface.updateContext(context);\n console.log('Context updated by PlaygroundServer middleware');\n }\n next();\n },\n );\n\n // NOTE: CORS middleware should be added externally via server.app.use()\n // before calling server.launch() if needed\n\n // API routes\n this.setupRoutes();\n\n // Static file serving (if staticPath is provided)\n this.setupStaticRoutes();\n\n // Error handler middleware (must be last)\n this._app.use(errorHandler);\n\n this._initialized = true;\n }\n\n filePathForUuid(uuid: string) {\n // Validate uuid to prevent path traversal attacks\n // Only allow alphanumeric characters and hyphens\n if (!/^[a-zA-Z0-9-]+$/.test(uuid)) {\n throw new Error('Invalid uuid format');\n }\n const filePath = join(this.tmpDir, `${uuid}.json`);\n // Double-check that resolved path is within tmpDir\n const resolvedPath = resolve(filePath);\n const resolvedTmpDir = resolve(this.tmpDir);\n if (!resolvedPath.startsWith(resolvedTmpDir)) {\n throw new Error('Invalid path');\n }\n return filePath;\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 /**\n * Recreate agent instance (for cancellation)\n */\n private async recreateAgent(): Promise<void> {\n if (!this.agentFactory) {\n throw new Error(\n 'Cannot recreate agent: factory function not provided. Attempting to destroy existing agent only.',\n );\n }\n\n this._agentReady = false;\n console.log('Recreating agent to cancel current task...');\n\n // Destroy old agent instance\n try {\n if (this.agent && typeof this.agent.destroy === 'function') {\n await this.agent.destroy();\n }\n } catch (error) {\n console.warn('Failed to destroy old agent:', error);\n }\n\n // Create new agent instance\n try {\n this.agent = await this.agentFactory();\n this._agentReady = true;\n console.log('Agent recreated successfully');\n } catch (error) {\n this._agentReady = true;\n console.error('Failed to recreate agent:', error);\n throw error;\n }\n }\n\n /**\n * Setup all API routes\n */\n private setupRoutes(): void {\n this._app.get('/status', async (req: Request, res: Response) => {\n res.send({\n status: 'ok',\n id: this.id,\n });\n });\n\n this._app.get('/context/:uuid', async (req: Request, res: Response) => {\n const { uuid } = req.params;\n let contextFile: string;\n try {\n contextFile = this.filePathForUuid(uuid);\n } catch {\n return res.status(400).json({\n error: 'Invalid uuid format',\n });\n }\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(\n '/task-progress/:requestId',\n async (req: Request, res: Response) => {\n const { requestId } = req.params;\n const executionDump = this.taskExecutionDumps[requestId] || null;\n\n res.json({\n executionDump,\n });\n },\n );\n\n this._app.post('/action-space', async (req: Request, res: Response) => {\n try {\n let actionSpace = [];\n\n actionSpace = this.agent.interface.actionSpace();\n\n // Process actionSpace to make paramSchema serializable with shape info\n const processedActionSpace = actionSpace.map((action: unknown) => {\n if (action && typeof action === 'object' && 'paramSchema' in action) {\n const typedAction = action as {\n paramSchema?: { shape?: object; [key: string]: unknown };\n [key: string]: unknown;\n };\n if (\n typedAction.paramSchema &&\n typeof typedAction.paramSchema === 'object'\n ) {\n // Extract shape information from Zod schema\n let processedSchema = null;\n\n try {\n // Extract shape from runtime Zod object\n if (\n typedAction.paramSchema.shape &&\n typeof typedAction.paramSchema.shape === 'object'\n ) {\n processedSchema = {\n type: 'ZodObject',\n shape: typedAction.paramSchema.shape,\n };\n }\n } catch (e) {\n const actionName =\n 'name' in typedAction && typeof typedAction.name === 'string'\n ? typedAction.name\n : 'unknown';\n console.warn(\n 'Failed to process paramSchema for action:',\n actionName,\n e,\n );\n }\n\n return {\n ...typedAction,\n paramSchema: processedSchema,\n };\n }\n }\n return action;\n });\n\n res.json(processedActionSpace);\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error('Failed to get action space:', error);\n res.status(500).json({\n error: errorMessage,\n });\n }\n });\n\n // -------------------------\n // actions from report file\n this._app.post(\n '/playground-with-context',\n async (req: Request, res: Response) => {\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 requestId = uuid();\n this.saveContextFile(requestId, context);\n return res.json({\n location: `/playground/${requestId}`,\n uuid: requestId,\n });\n },\n );\n\n this._app.post('/execute', async (req: Request, res: Response) => {\n const {\n type,\n prompt,\n params,\n requestId,\n deepLocate,\n deepThink,\n screenshotIncluded,\n domIncluded,\n deviceOptions,\n } = req.body;\n\n if (!type) {\n return res.status(400).json({\n error: 'type is required',\n });\n }\n\n // Always recreate agent before execution to ensure latest config is applied\n if (this.agentFactory) {\n this._agentReady = false;\n console.log('Destroying old agent before execution...');\n try {\n if (this.agent && typeof this.agent.destroy === 'function') {\n await this.agent.destroy();\n }\n } catch (error) {\n console.warn('Failed to destroy old agent:', error);\n }\n\n console.log('Creating new agent with latest config...');\n try {\n this.agent = await this.agentFactory();\n this._agentReady = true;\n console.log('Agent created successfully');\n } catch (error) {\n this._agentReady = true;\n console.error('Failed to create agent:', error);\n return res.status(500).json({\n error: `Failed to create agent: ${error instanceof Error ? error.message : 'Unknown error'}`,\n });\n }\n }\n\n // Update device options if provided\n if (\n deviceOptions &&\n this.agent.interface &&\n 'options' in this.agent.interface\n ) {\n this.agent.interface.options = {\n ...(this.agent.interface.options || {}),\n ...deviceOptions,\n };\n }\n\n // Check if another task is running\n if (this.currentTaskId) {\n return res.status(409).json({\n error: 'Another task is already running',\n currentTaskId: this.currentTaskId,\n });\n }\n\n // Lock this task\n if (requestId) {\n this.currentTaskId = requestId;\n this.taskExecutionDumps[requestId] = null;\n\n // Use onDumpUpdate to receive and store executionDump directly\n this.agent.onDumpUpdate = (\n _dump: string,\n executionDump?: ExecutionDump,\n ) => {\n if (executionDump) {\n // Store the execution dump directly without transformation\n this.taskExecutionDumps[requestId] = executionDump;\n }\n };\n }\n\n const response: {\n result: unknown;\n dump: ExecutionDump | 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 = this.agent.interface.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 this.agent,\n type,\n actionSpace,\n value,\n {\n deepLocate,\n deepThink,\n screenshotIncluded,\n domIncluded,\n deviceOptions,\n },\n );\n } catch (error: unknown) {\n response.error = formatErrorMessage(error);\n }\n\n try {\n const dumpString = this.agent.dumpDataString({\n inlineScreenshots: true,\n });\n if (dumpString) {\n const groupedDump =\n GroupedActionDump.fromSerializedString(dumpString);\n // Extract first execution from grouped dump, matching local execution adapter behavior\n response.dump = groupedDump.executions?.[0] || null;\n } else {\n response.dump = null;\n }\n response.reportHTML =\n this.agent.reportHTMLString({ inlineScreenshots: true }) || null;\n\n this.agent.writeOutActionDumps();\n this.agent.resetDump();\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(\n `write out dump failed: requestId: ${requestId}, ${errorMessage}`,\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 task execution dumps and unlock after execution completes\n if (requestId) {\n delete this.taskExecutionDumps[requestId];\n // Release the lock\n if (this.currentTaskId === requestId) {\n this.currentTaskId = null;\n }\n }\n });\n\n this._app.post(\n '/cancel/:requestId',\n async (req: Request, res: Response) => {\n const { requestId } = req.params;\n\n if (!requestId) {\n return res.status(400).json({\n error: 'requestId is required',\n });\n }\n\n try {\n // Check if this is the current running task\n if (this.currentTaskId !== requestId) {\n return res.json({\n status: 'not_found',\n message: 'Task not found or already completed',\n });\n }\n\n console.log(`Cancelling task: ${requestId}`);\n\n // Get current execution data before cancelling (dump and reportHTML)\n let dump: any = null;\n let reportHTML: string | null = null;\n\n try {\n const dumpString = this.agent.dumpDataString?.({\n inlineScreenshots: true,\n });\n if (dumpString) {\n const groupedDump =\n GroupedActionDump.fromSerializedString(dumpString);\n // Extract first execution from grouped dump\n dump = groupedDump.executions?.[0] || null;\n }\n\n reportHTML =\n this.agent.reportHTMLString?.({ inlineScreenshots: true }) ||\n null;\n } catch (error: unknown) {\n console.warn('Failed to get execution data before cancel:', error);\n }\n\n // Destroy agent to cancel the current task\n // No need to recreate here — /execute always creates a fresh agent before each run\n try {\n if (this.agent && typeof this.agent.destroy === 'function') {\n await this.agent.destroy();\n }\n } catch (error) {\n console.warn('Failed to destroy agent during cancel:', error);\n }\n\n // Clean up\n delete this.taskExecutionDumps[requestId];\n this.currentTaskId = null;\n\n res.json({\n status: 'cancelled',\n message: 'Task cancelled successfully',\n dump,\n reportHTML,\n });\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`Failed to cancel: ${errorMessage}`);\n res.status(500).json({\n error: `Failed to cancel: ${errorMessage}`,\n });\n }\n },\n );\n\n // Screenshot API for real-time screenshot polling\n this._app.get('/screenshot', async (_req: Request, res: Response) => {\n try {\n // Check if page has screenshotBase64 method\n if (typeof this.agent.interface.screenshotBase64 !== 'function') {\n return res.status(500).json({\n error: 'Screenshot method not available on current interface',\n });\n }\n\n const base64Screenshot = await this.agent.interface.screenshotBase64();\n\n res.json({\n screenshot: base64Screenshot,\n timestamp: Date.now(),\n });\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`Failed to take screenshot: ${errorMessage}`);\n res.status(500).json({\n error: `Failed to take screenshot: ${errorMessage}`,\n });\n }\n });\n\n // MJPEG streaming endpoint for real-time screen preview\n // Proxies native MJPEG stream (e.g. WDA MJPEG server) when available,\n // falls back to polling screenshotBase64() otherwise.\n this._app.get('/mjpeg', async (req: Request, res: Response) => {\n const nativeUrl = this.agent?.interface?.mjpegStreamUrl;\n\n if (nativeUrl && this._nativeMjpegAvailable !== false) {\n const proxyOk = await this.probeAndProxyNativeMjpeg(\n nativeUrl,\n req,\n res,\n );\n if (proxyOk) return;\n }\n\n if (typeof this.agent?.interface?.screenshotBase64 !== 'function') {\n return res.status(500).json({\n error: 'Screenshot method not available on current interface',\n });\n }\n\n await this.startPollingMjpegStream(req, res);\n });\n\n // Interface info API for getting interface type and description\n this._app.get('/interface-info', async (_req: Request, res: Response) => {\n try {\n const type = this.agent.interface.interfaceType || 'Unknown';\n const description = this.agent.interface.describe?.() || undefined;\n\n res.json({\n type,\n description,\n });\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`Failed to get interface info: ${errorMessage}`);\n res.status(500).json({\n error: `Failed to get interface info: ${errorMessage}`,\n });\n }\n });\n\n this.app.post('/config', async (req: Request, res: Response) => {\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 if (Object.keys(aiConfig).length === 0) {\n return res.json({\n status: 'ok',\n message: 'AI config not changed due to empty object',\n });\n }\n\n try {\n overrideAIConfig(aiConfig);\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`Failed to update AI config: ${errorMessage}`);\n return res.status(500).json({\n error: `Failed to update AI config: ${errorMessage}`,\n });\n }\n\n // Validate the config immediately so the frontend gets early feedback\n try {\n globalModelConfigManager.getModelConfig('default');\n } catch (error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error';\n console.error(`AI config validation failed: ${errorMessage}`);\n return res.status(400).json({\n error: errorMessage,\n });\n }\n\n // Note: Agent will be recreated on next execution to apply new config\n return res.json({\n status: 'ok',\n message:\n 'AI config updated. Agent will be recreated on next execution.',\n });\n });\n }\n\n /**\n * Probe and proxy a native MJPEG stream (e.g. WDA MJPEG server).\n * Result is cached so we only probe once per server lifetime.\n */\n private probeAndProxyNativeMjpeg(\n nativeUrl: string,\n req: Request,\n res: Response,\n ): Promise<boolean> {\n return new Promise<boolean>((resolve) => {\n console.log(`MJPEG: trying native stream from ${nativeUrl}`);\n const proxyReq = http.get(nativeUrl, (proxyRes) => {\n this._nativeMjpegAvailable = true;\n console.log('MJPEG: streaming via native WDA MJPEG server');\n const contentType = proxyRes.headers['content-type'];\n if (contentType) {\n res.setHeader('Content-Type', contentType);\n }\n res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');\n res.setHeader('Connection', 'keep-alive');\n proxyRes.pipe(res);\n req.on('close', () => proxyReq.destroy());\n resolve(true);\n });\n proxyReq.on('error', (err) => {\n this._nativeMjpegAvailable = false;\n console.warn(\n `MJPEG: native stream unavailable (${err.message}), using polling mode`,\n );\n resolve(false);\n });\n });\n }\n\n /**\n * Stream screenshots as MJPEG by polling screenshotBase64().\n */\n private async startPollingMjpegStream(\n req: Request,\n res: Response,\n ): Promise<void> {\n const defaultMjpegFps = 10;\n const maxMjpegFps = 30;\n const maxErrorBackoffMs = 3000;\n const errorLogThreshold = 3;\n\n const parsedFps = Number(req.query.fps);\n const fps = Math.min(\n Math.max(Number.isNaN(parsedFps) ? defaultMjpegFps : parsedFps, 1),\n maxMjpegFps,\n );\n const interval = Math.round(1000 / fps);\n const boundary = 'mjpeg-boundary';\n console.log(`MJPEG: streaming via polling mode (${fps}fps)`);\n\n res.setHeader(\n 'Content-Type',\n `multipart/x-mixed-replace; boundary=${boundary}`,\n );\n res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');\n res.setHeader('Connection', 'keep-alive');\n\n let stopped = false;\n let consecutiveErrors = 0;\n req.on('close', () => {\n stopped = true;\n });\n\n while (!stopped) {\n // Skip frame while agent is being recreated\n if (!this._agentReady) {\n await new Promise((r) => setTimeout(r, 200));\n continue;\n }\n\n const frameStart = Date.now();\n try {\n const base64 = await this.agent.interface.screenshotBase64();\n if (stopped) break;\n consecutiveErrors = 0;\n\n const raw = base64.replace(/^data:image\\/\\w+;base64,/, '');\n const buf = Buffer.from(raw, 'base64');\n\n res.write(`--${boundary}\\r\\n`);\n res.write('Content-Type: image/jpeg\\r\\n');\n res.write(`Content-Length: ${buf.length}\\r\\n\\r\\n`);\n res.write(buf);\n res.write('\\r\\n');\n } catch (err) {\n if (stopped) break;\n consecutiveErrors++;\n if (consecutiveErrors <= errorLogThreshold) {\n console.error('MJPEG frame error:', err);\n } else if (consecutiveErrors === errorLogThreshold + 1) {\n console.error(\n 'MJPEG: suppressing further errors, retrying silently...',\n );\n }\n const backoff = Math.min(1000 * consecutiveErrors, maxErrorBackoffMs);\n await new Promise((r) => setTimeout(r, backoff));\n continue;\n }\n\n const elapsed = Date.now() - frameStart;\n const remaining = interval - elapsed;\n if (remaining > 0) {\n await new Promise((r) => setTimeout(r, remaining));\n }\n }\n }\n\n /**\n * Setup static file serving routes\n */\n private setupStaticRoutes(): void {\n // Handle index.html with port injection\n this._app.get('/', (_req: Request, res: Response) => {\n this.serveHtmlWithPorts(res);\n });\n\n this._app.get('/index.html', (_req: Request, res: Response) => {\n this.serveHtmlWithPorts(res);\n });\n\n // Use express.static middleware for secure static file serving\n this._app.use(express.static(this.staticPath));\n\n // Fallback to index.html for SPA routing\n this._app.get('*', (_req: Request, res: Response) => {\n this.serveHtmlWithPorts(res);\n });\n }\n\n /**\n * Serve HTML with injected port configuration\n */\n private serveHtmlWithPorts(res: Response): void {\n try {\n const htmlPath = join(this.staticPath, 'index.html');\n let html = readFileSync(htmlPath, 'utf8');\n\n // Get scrcpy server port from global\n const scrcpyPort = (global as any).scrcpyServerPort || this.port! + 1;\n\n // Inject scrcpy port configuration script into HTML head\n const configScript = `\n <script>\n window.SCRCPY_PORT = ${scrcpyPort};\n </script>\n `;\n\n // Insert the script before closing </head> tag\n html = html.replace('</head>', `${configScript}</head>`);\n\n res.setHeader('Content-Type', 'text/html');\n res.send(html);\n } catch (error) {\n console.error('Error serving HTML with ports:', error);\n res.status(500).send('Internal Server Error');\n }\n }\n\n /**\n * Launch the server on specified port\n */\n async launch(port?: number): Promise<PlaygroundServer> {\n // If using factory mode, initialize agent\n if (this.agentFactory) {\n console.log('Initializing agent from factory function...');\n this.agent = await this.agentFactory();\n console.log('Agent initialized successfully');\n }\n\n // Initialize routes now, after any middleware has been added\n this.initializeApp();\n\n this.port = port || defaultPort;\n\n return new Promise((resolve) => {\n const serverPort = this.port;\n this.server = this._app.listen(serverPort, () => {\n resolve(this);\n });\n });\n }\n\n /**\n * Close the server and clean up resources\n */\n async close(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (this.server) {\n // Clean up the single agent\n try {\n this.agent.destroy();\n } catch (error) {\n console.warn('Failed to destroy agent:', error);\n }\n this.taskExecutionDumps = {};\n\n // Close the server\n this.server.close((error) => {\n if (error) {\n reject(error);\n } else {\n this.server = undefined;\n resolve();\n }\n });\n } else {\n resolve();\n }\n });\n }\n}\n\nexport default PlaygroundServer;\nexport { PlaygroundServer };\n"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","defaultPort","PLAYGROUND_SERVER_PORT","__filename","fileURLToPath","__dirname","dirname","STATIC_PATH","join","errorHandler","err","req","res","next","console","errorMessage","Error","PlaygroundServer","express","_res","context","uuid","filePath","resolvedPath","resolve","resolvedTmpDir","tmpFile","writeFileSync","error","contextFile","existsSync","readFileSync","requestId","executionDump","actionSpace","processedActionSpace","action","typedAction","processedSchema","e","actionName","type","prompt","params","deepLocate","deepThink","screenshotIncluded","domIncluded","deviceOptions","_dump","response","startTime","Date","value","executeAction","formatErrorMessage","dumpString","groupedDump","GroupedActionDump","timeCost","dump","reportHTML","_req","base64Screenshot","nativeUrl","proxyOk","description","undefined","aiConfig","overrideAIConfig","globalModelConfigManager","Promise","proxyReq","http","proxyRes","contentType","defaultMjpegFps","maxMjpegFps","maxErrorBackoffMs","errorLogThreshold","parsedFps","Number","fps","Math","interval","boundary","stopped","consecutiveErrors","r","setTimeout","frameStart","base64","raw","buf","Buffer","backoff","elapsed","remaining","htmlPath","html","scrcpyPort","global","configScript","port","serverPort","reject","agent","staticPath","id","getTmpDir"],"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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACcA,MAAMI,cAAcC,0BAAAA,sBAAsBA;AAG1C,MAAMC,kBAAaC,AAAAA,IAAAA,kCAAAA,aAAAA,AAAAA,EAAc;AACjC,MAAMC,iBAAYC,AAAAA,IAAAA,mCAAAA,OAAAA,AAAAA,EAAQH;AAC1B,MAAMI,cAAcC,AAAAA,IAAAA,mCAAAA,IAAAA,AAAAA,EAAKH,gBAAW,MAAM,MAAM;AAEhD,MAAMI,eAAe,CACnBC,K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AQ,QAAR;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QAEA,uBAAQ,gBAAe;QAGvB,uBAAQ,yBAAwC;QAGhD,uBAAQ,gBAAR;QAGA,uBAAQ,iBAA+B;QAGvC,uBAAQ,eAAc;QAOpB,IAAI,CAAC,IAAI,GAAG1F;QACZ,IAAI,CAAC,MAAM,GAAG2F,AAAAA,IAAAA,sBAAAA,SAAAA,AAAAA;QACd,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,kBAAkB,GAAG,CAAC;QAE3B,IAAI,CAAC,EAAE,GAAGC,MAAMvF,AAAAA,IAAAA,6BAAAA,IAAAA,AAAAA;QAGhB,IAAI,AAAiB,cAAjB,OAAOqF,OAAsB;YAC/B,IAAI,CAAC,YAAY,GAAGA;YACpB,IAAI,CAAC,KAAK,GAAG;QACf,OAAO;YACL,IAAI,CAAC,KAAK,GAAGA;YACb,IAAI,CAAC,YAAY,GAAG;QACtB;IACF;AAu0BF;AAEA,eAAezF"}
|
package/dist/types/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/playground",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Midscene playground utilities for web integration",
|
|
5
5
|
"author": "midscene team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"express": "^4.21.2",
|
|
26
26
|
"open": "10.1.0",
|
|
27
27
|
"uuid": "11.1.0",
|
|
28
|
-
"@midscene/core": "1.5.
|
|
29
|
-
"@midscene/shared": "1.5.
|
|
28
|
+
"@midscene/core": "1.5.1",
|
|
29
|
+
"@midscene/shared": "1.5.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@rslib/core": "^0.18.3",
|
package/static/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.7b1abe58.js"></script><script defer src="/static/js/853.673222dd.js"></script><script defer src="/static/js/index.
|
|
1
|
+
<!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.7b1abe58.js"></script><script defer src="/static/js/853.673222dd.js"></script><script defer src="/static/js/index.04c353bc.js"></script><link href="/static/css/index.33fcd75b.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
|