@sqaitech/playground 0.30.14 → 0.30.16
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/local-execution.mjs +1 -1
- package/dist/es/adapters/local-execution.mjs.map +1 -1
- package/dist/es/common.mjs +1 -1
- package/dist/es/common.mjs.map +1 -1
- package/dist/lib/adapters/local-execution.js +1 -1
- package/dist/lib/adapters/local-execution.js.map +1 -1
- package/dist/lib/common.js +1 -1
- package/dist/lib/common.js.map +1 -1
- package/package.json +3 -3
|
@@ -28,7 +28,7 @@ class LocalExecutionAdapter extends BasePlaygroundAdapter {
|
|
|
28
28
|
}
|
|
29
29
|
formatErrorMessage(error) {
|
|
30
30
|
const errorMessage = (null == error ? void 0 : error.message) || '';
|
|
31
|
-
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://
|
|
31
|
+
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://sqai.tech/quick-experience.html#faq';
|
|
32
32
|
return this.formatBasicErrorMessage(error);
|
|
33
33
|
}
|
|
34
34
|
async getActionSpace(context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapters\\local-execution.mjs","sources":["webpack://@sqaitech/playground/./src/adapters/local-execution.ts"],"sourcesContent":["import type { DeviceAction } from '@sqaitech/core';\r\nimport { overrideAIConfig } from '@sqaitech/shared/env';\r\nimport { uuid } from '@sqaitech/shared/utils';\r\nimport { executeAction, parseStructuredParams } from '../common';\r\nimport type { ExecutionOptions, FormValue, PlaygroundAgent } from '../types';\r\nimport { BasePlaygroundAdapter } from './base';\r\n\r\nexport class LocalExecutionAdapter extends BasePlaygroundAdapter {\r\n private agent: PlaygroundAgent;\r\n private taskProgressTips: Record<string, string> = {};\r\n private progressCallback?: (tip: string) => void;\r\n private readonly _id: string; // Unique identifier for this local adapter instance\r\n private currentRequestId?: string; // Track current request to prevent stale callbacks\r\n\r\n constructor(agent: PlaygroundAgent) {\r\n super();\r\n this.agent = agent;\r\n this._id = uuid(); // Generate unique ID for local adapter\r\n }\r\n\r\n // Get adapter ID\r\n get id(): string {\r\n return this._id;\r\n }\r\n\r\n setProgressCallback(callback: (tip: string) => void): void {\r\n // Clear any existing callback before setting new one\r\n this.progressCallback = undefined;\r\n // Set the new callback\r\n this.progressCallback = callback;\r\n }\r\n\r\n private cleanup(requestId: string): void {\r\n delete this.taskProgressTips[requestId];\r\n }\r\n\r\n async parseStructuredParams(\r\n action: DeviceAction<unknown>,\r\n params: Record<string, unknown>,\r\n options: ExecutionOptions,\r\n ): Promise<unknown[]> {\r\n // Use shared implementation from common.ts\r\n return await parseStructuredParams(action, params, options);\r\n }\r\n\r\n formatErrorMessage(error: any): string {\r\n const errorMessage = error?.message || '';\r\n if (errorMessage.includes('of different extension')) {\r\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';\r\n }\r\n return this.formatBasicErrorMessage(error);\r\n }\r\n\r\n // Local execution - use base implementation\r\n // (inherits default executeAction from BasePlaygroundAdapter)\r\n\r\n // Local execution gets actionSpace from internal agent (parameter is for backward compatibility)\r\n async getActionSpace(context?: unknown): Promise<DeviceAction<unknown>[]> {\r\n // Priority 1: Use agent's getActionSpace method\r\n if (this.agent?.getActionSpace) {\r\n return await this.agent.getActionSpace();\r\n }\r\n\r\n // Priority 2: Use agent's interface.actionSpace method\r\n if (\r\n this.agent &&\r\n 'interface' in this.agent &&\r\n typeof this.agent.interface === 'object'\r\n ) {\r\n const page = this.agent.interface as {\r\n actionSpace?: () => Promise<DeviceAction<unknown>[]>;\r\n };\r\n if (page?.actionSpace) {\r\n return await page.actionSpace();\r\n }\r\n }\r\n\r\n // Priority 3: Fallback to context parameter (for backward compatibility with tests)\r\n if (context && typeof context === 'object' && 'actionSpace' in context) {\r\n const contextPage = context as {\r\n actionSpace: () => Promise<DeviceAction<unknown>[]>;\r\n };\r\n return await contextPage.actionSpace();\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // Local execution doesn't use a server, so always return true\r\n async checkStatus(): Promise<boolean> {\r\n return true;\r\n }\r\n\r\n async overrideConfig(aiConfig: Record<string, unknown>): Promise<void> {\r\n // For local execution, use the shared env override function\r\n overrideAIConfig(aiConfig);\r\n }\r\n\r\n async executeAction(\r\n actionType: string,\r\n value: FormValue,\r\n options: ExecutionOptions,\r\n ): Promise<unknown> {\r\n // Get actionSpace using our simplified getActionSpace method\r\n const actionSpace = await this.getActionSpace();\r\n let originalOnTaskStartTip: ((tip: string) => void) | undefined;\r\n\r\n // Setup progress tracking if requestId is provided\r\n if (options.requestId && this.agent) {\r\n // Track current request ID to prevent stale callbacks\r\n this.currentRequestId = options.requestId;\r\n originalOnTaskStartTip = this.agent.onTaskStartTip;\r\n\r\n // Set up a fresh callback\r\n this.agent.onTaskStartTip = (tip: string) => {\r\n // Only process if this is still the current request\r\n if (this.currentRequestId !== options.requestId) {\r\n return;\r\n }\r\n\r\n // Store tip for our progress tracking\r\n this.taskProgressTips[options.requestId!] = tip;\r\n\r\n // Call the direct progress callback set via setProgressCallback\r\n if (this.progressCallback) {\r\n this.progressCallback(tip);\r\n }\r\n\r\n if (typeof originalOnTaskStartTip === 'function') {\r\n originalOnTaskStartTip(tip);\r\n }\r\n };\r\n }\r\n\r\n try {\r\n // Call the base implementation with the original signature\r\n const result = await executeAction(\r\n this.agent,\r\n actionType,\r\n actionSpace,\r\n value,\r\n options,\r\n );\r\n\r\n // For local execution, we need to package the result with dump and reportHTML\r\n // similar to how the server does it\r\n const response = {\r\n result,\r\n dump: null as unknown,\r\n reportHTML: null as string | null,\r\n error: null as string | null,\r\n };\r\n\r\n try {\r\n // Get dump and reportHTML from agent like the server does\r\n if (this.agent.dumpDataString) {\r\n const dumpString = this.agent.dumpDataString();\r\n if (dumpString) {\r\n response.dump = JSON.parse(dumpString);\r\n }\r\n }\r\n\r\n if (this.agent.reportHTMLString) {\r\n response.reportHTML = this.agent.reportHTMLString() || null;\r\n }\r\n\r\n // Write out action dumps\r\n if (this.agent.writeOutActionDumps) {\r\n this.agent.writeOutActionDumps();\r\n }\r\n } catch (error: unknown) {\r\n console.error('Failed to get dump/reportHTML from agent:', error);\r\n }\r\n\r\n this.agent.resetDump();\r\n\r\n return response;\r\n } finally {\r\n // Always clean up progress tracking to prevent memory leaks\r\n if (options.requestId) {\r\n this.cleanup(options.requestId);\r\n // Clear the agent callback to prevent accumulation\r\n if (this.agent) {\r\n this.agent.onTaskStartTip = originalOnTaskStartTip;\r\n }\r\n }\r\n }\r\n }\r\n\r\n async getTaskProgress(requestId: string): Promise<{ tip?: string }> {\r\n // Return the stored tip for this requestId\r\n return { tip: this.taskProgressTips[requestId] || undefined };\r\n }\r\n\r\n // Local execution task cancellation - minimal implementation\r\n async cancelTask(\r\n _requestId: string,\r\n ): Promise<{ error?: string; success?: boolean }> {\r\n if (!this.agent) {\r\n return { error: 'No active agent found for this requestId' };\r\n }\r\n\r\n try {\r\n await this.agent.destroy?.();\r\n return { success: true };\r\n } catch (error: unknown) {\r\n const errorMessage =\r\n error instanceof Error ? error.message : 'Unknown error';\r\n console.error(`Failed to cancel agent: ${errorMessage}`);\r\n return { error: `Failed to cancel: ${errorMessage}` };\r\n }\r\n }\r\n\r\n // Get interface information from the agent\r\n async getInterfaceInfo(): Promise<{\r\n type: string;\r\n description?: string;\r\n } | null> {\r\n if (!this.agent?.interface) {\r\n return null;\r\n }\r\n\r\n try {\r\n const type = this.agent.interface.interfaceType || 'Unknown';\r\n const description = this.agent.interface.describe?.() || undefined;\r\n\r\n return {\r\n type,\r\n description,\r\n };\r\n } catch (error: unknown) {\r\n console.error('Failed to get interface info:', error);\r\n return null;\r\n }\r\n }\r\n}\r\n"],"names":["LocalExecutionAdapter","BasePlaygroundAdapter","callback","undefined","requestId","action","params","options","parseStructuredParams","error","errorMessage","context","_this_agent","page","contextPage","aiConfig","overrideAIConfig","actionType","value","actionSpace","originalOnTaskStartTip","tip","result","executeAction","response","dumpString","JSON","console","_requestId","Error","_this_agent_interface","type","description","agent","uuid"],"mappings":";;;;;;;;;;;;;;AAOO,MAAMA,8BAA8BC;IAczC,IAAI,KAAa;QACf,OAAO,IAAI,CAAC,GAAG;IACjB;IAEA,oBAAoBC,QAA+B,EAAQ;QAEzD,IAAI,CAAC,gBAAgB,GAAGC;QAExB,IAAI,CAAC,gBAAgB,GAAGD;IAC1B;IAEQ,QAAQE,SAAiB,EAAQ;QACvC,OAAO,IAAI,CAAC,gBAAgB,CAACA,UAAU;IACzC;IAEA,MAAM,sBACJC,MAA6B,EAC7BC,MAA+B,EAC/BC,OAAyB,EACL;QAEpB,OAAO,MAAMC,sBAAsBH,QAAQC,QAAQC;IACrD;IAEA,mBAAmBE,KAAU,EAAU;QACrC,MAAMC,eAAeD,AAAAA,CAAAA,QAAAA,QAAAA,KAAAA,IAAAA,MAAO,OAAO,AAAD,KAAK;QACvC,IAAIC,aAAa,QAAQ,CAAC,2BACxB,OAAO;QAET,OAAO,IAAI,CAAC,uBAAuB,CAACD;IACtC;IAMA,MAAM,eAAeE,OAAiB,EAAoC;YAEpEC;QAAJ,IAAI,QAAAA,CAAAA,cAAAA,IAAI,CAAC,KAAK,AAAD,IAATA,KAAAA,IAAAA,YAAY,cAAc,EAC5B,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc;QAIxC,IACE,IAAI,CAAC,KAAK,IACV,eAAe,IAAI,CAAC,KAAK,IACzB,AAAgC,YAAhC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,EAC3B;YACA,MAAMC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS;YAGjC,IAAIA,QAAAA,OAAAA,KAAAA,IAAAA,KAAM,WAAW,EACnB,OAAO,MAAMA,KAAK,WAAW;QAEjC;QAGA,IAAIF,WAAW,AAAmB,YAAnB,OAAOA,WAAwB,iBAAiBA,SAAS;YACtE,MAAMG,cAAcH;YAGpB,OAAO,MA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A,CAAAA,wBAAAA,IAAI,CAAC,KAAK,CAAC,SAAS,AAAD,EAAE,QAAQ,AAAD,IAA5BA,KAAAA,IAAAA,+BAAAA,IAAAA,CAAAA,sBAAAA,KAAqC3B;YAEzD,OAAO;gBACL4B;gBACAC;YACF;QACF,EAAE,OAAOvB,OAAgB;YACvBkB,QAAQ,KAAK,CAAC,iCAAiClB;YAC/C,OAAO;QACT;IACF;IA5NA,YAAYwB,KAAsB,CAAE;QAClC,KAAK,IAPP,uBAAQ,SAAR,SACA,uBAAQ,oBAA2C,CAAC,IACpD,uBAAQ,oBAAR,SACA,uBAAiB,OAAjB,SACA,uBAAQ,oBAAR;QAIE,IAAI,CAAC,KAAK,GAAGA;QACb,IAAI,CAAC,GAAG,GAAGC;IACb;AAyNF"}
|
|
1
|
+
{"version":3,"file":"adapters\\local-execution.mjs","sources":["webpack://@sqaitech/playground/./src/adapters/local-execution.ts"],"sourcesContent":["import type { DeviceAction } from '@sqaitech/core';\r\nimport { overrideAIConfig } from '@sqaitech/shared/env';\r\nimport { uuid } from '@sqaitech/shared/utils';\r\nimport { executeAction, parseStructuredParams } from '../common';\r\nimport type { ExecutionOptions, FormValue, PlaygroundAgent } from '../types';\r\nimport { BasePlaygroundAdapter } from './base';\r\n\r\nexport class LocalExecutionAdapter extends BasePlaygroundAdapter {\r\n private agent: PlaygroundAgent;\r\n private taskProgressTips: Record<string, string> = {};\r\n private progressCallback?: (tip: string) => void;\r\n private readonly _id: string; // Unique identifier for this local adapter instance\r\n private currentRequestId?: string; // Track current request to prevent stale callbacks\r\n\r\n constructor(agent: PlaygroundAgent) {\r\n super();\r\n this.agent = agent;\r\n this._id = uuid(); // Generate unique ID for local adapter\r\n }\r\n\r\n // Get adapter ID\r\n get id(): string {\r\n return this._id;\r\n }\r\n\r\n setProgressCallback(callback: (tip: string) => void): void {\r\n // Clear any existing callback before setting new one\r\n this.progressCallback = undefined;\r\n // Set the new callback\r\n this.progressCallback = callback;\r\n }\r\n\r\n private cleanup(requestId: string): void {\r\n delete this.taskProgressTips[requestId];\r\n }\r\n\r\n async parseStructuredParams(\r\n action: DeviceAction<unknown>,\r\n params: Record<string, unknown>,\r\n options: ExecutionOptions,\r\n ): Promise<unknown[]> {\r\n // Use shared implementation from common.ts\r\n return await parseStructuredParams(action, params, options);\r\n }\r\n\r\n formatErrorMessage(error: any): string {\r\n const errorMessage = error?.message || '';\r\n if (errorMessage.includes('of different extension')) {\r\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://sqai.tech/quick-experience.html#faq';\r\n }\r\n return this.formatBasicErrorMessage(error);\r\n }\r\n\r\n // Local execution - use base implementation\r\n // (inherits default executeAction from BasePlaygroundAdapter)\r\n\r\n // Local execution gets actionSpace from internal agent (parameter is for backward compatibility)\r\n async getActionSpace(context?: unknown): Promise<DeviceAction<unknown>[]> {\r\n // Priority 1: Use agent's getActionSpace method\r\n if (this.agent?.getActionSpace) {\r\n return await this.agent.getActionSpace();\r\n }\r\n\r\n // Priority 2: Use agent's interface.actionSpace method\r\n if (\r\n this.agent &&\r\n 'interface' in this.agent &&\r\n typeof this.agent.interface === 'object'\r\n ) {\r\n const page = this.agent.interface as {\r\n actionSpace?: () => Promise<DeviceAction<unknown>[]>;\r\n };\r\n if (page?.actionSpace) {\r\n return await page.actionSpace();\r\n }\r\n }\r\n\r\n // Priority 3: Fallback to context parameter (for backward compatibility with tests)\r\n if (context && typeof context === 'object' && 'actionSpace' in context) {\r\n const contextPage = context as {\r\n actionSpace: () => Promise<DeviceAction<unknown>[]>;\r\n };\r\n return await contextPage.actionSpace();\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // Local execution doesn't use a server, so always return true\r\n async checkStatus(): Promise<boolean> {\r\n return true;\r\n }\r\n\r\n async overrideConfig(aiConfig: Record<string, unknown>): Promise<void> {\r\n // For local execution, use the shared env override function\r\n overrideAIConfig(aiConfig);\r\n }\r\n\r\n async executeAction(\r\n actionType: string,\r\n value: FormValue,\r\n options: ExecutionOptions,\r\n ): Promise<unknown> {\r\n // Get actionSpace using our simplified getActionSpace method\r\n const actionSpace = await this.getActionSpace();\r\n let originalOnTaskStartTip: ((tip: string) => void) | undefined;\r\n\r\n // Setup progress tracking if requestId is provided\r\n if (options.requestId && this.agent) {\r\n // Track current request ID to prevent stale callbacks\r\n this.currentRequestId = options.requestId;\r\n originalOnTaskStartTip = this.agent.onTaskStartTip;\r\n\r\n // Set up a fresh callback\r\n this.agent.onTaskStartTip = (tip: string) => {\r\n // Only process if this is still the current request\r\n if (this.currentRequestId !== options.requestId) {\r\n return;\r\n }\r\n\r\n // Store tip for our progress tracking\r\n this.taskProgressTips[options.requestId!] = tip;\r\n\r\n // Call the direct progress callback set via setProgressCallback\r\n if (this.progressCallback) {\r\n this.progressCallback(tip);\r\n }\r\n\r\n if (typeof originalOnTaskStartTip === 'function') {\r\n originalOnTaskStartTip(tip);\r\n }\r\n };\r\n }\r\n\r\n try {\r\n // Call the base implementation with the original signature\r\n const result = await executeAction(\r\n this.agent,\r\n actionType,\r\n actionSpace,\r\n value,\r\n options,\r\n );\r\n\r\n // For local execution, we need to package the result with dump and reportHTML\r\n // similar to how the server does it\r\n const response = {\r\n result,\r\n dump: null as unknown,\r\n reportHTML: null as string | null,\r\n error: null as string | null,\r\n };\r\n\r\n try {\r\n // Get dump and reportHTML from agent like the server does\r\n if (this.agent.dumpDataString) {\r\n const dumpString = this.agent.dumpDataString();\r\n if (dumpString) {\r\n response.dump = JSON.parse(dumpString);\r\n }\r\n }\r\n\r\n if (this.agent.reportHTMLString) {\r\n response.reportHTML = this.agent.reportHTMLString() || null;\r\n }\r\n\r\n // Write out action dumps\r\n if (this.agent.writeOutActionDumps) {\r\n this.agent.writeOutActionDumps();\r\n }\r\n } catch (error: unknown) {\r\n console.error('Failed to get dump/reportHTML from agent:', error);\r\n }\r\n\r\n this.agent.resetDump();\r\n\r\n return response;\r\n } finally {\r\n // Always clean up progress tracking to prevent memory leaks\r\n if (options.requestId) {\r\n this.cleanup(options.requestId);\r\n // Clear the agent callback to prevent accumulation\r\n if (this.agent) {\r\n this.agent.onTaskStartTip = originalOnTaskStartTip;\r\n }\r\n }\r\n }\r\n }\r\n\r\n async getTaskProgress(requestId: string): Promise<{ tip?: string }> {\r\n // Return the stored tip for this requestId\r\n return { tip: this.taskProgressTips[requestId] || undefined };\r\n }\r\n\r\n // Local execution task cancellation - minimal implementation\r\n async cancelTask(\r\n _requestId: string,\r\n ): Promise<{ error?: string; success?: boolean }> {\r\n if (!this.agent) {\r\n return { error: 'No active agent found for this requestId' };\r\n }\r\n\r\n try {\r\n await this.agent.destroy?.();\r\n return { success: true };\r\n } catch (error: unknown) {\r\n const errorMessage =\r\n error instanceof Error ? error.message : 'Unknown error';\r\n console.error(`Failed to cancel agent: ${errorMessage}`);\r\n return { error: `Failed to cancel: ${errorMessage}` };\r\n }\r\n }\r\n\r\n // Get interface information from the agent\r\n async getInterfaceInfo(): Promise<{\r\n type: string;\r\n description?: string;\r\n } | null> {\r\n if (!this.agent?.interface) {\r\n return null;\r\n }\r\n\r\n try {\r\n const type = this.agent.interface.interfaceType || 'Unknown';\r\n const description = this.agent.interface.describe?.() || undefined;\r\n\r\n return {\r\n type,\r\n description,\r\n };\r\n } catch (error: unknown) {\r\n console.error('Failed to get interface info:', error);\r\n return null;\r\n }\r\n }\r\n}\r\n"],"names":["LocalExecutionAdapter","BasePlaygroundAdapter","callback","undefined","requestId","action","params","options","parseStructuredParams","error","errorMessage","context","_this_agent","page","contextPage","aiConfig","overrideAIConfig","actionType","value","actionSpace","originalOnTaskStartTip","tip","result","executeAction","response","dumpString","JSON","console","_requestId","Error","_this_agent_interface","type","description","agent","uuid"],"mappings":";;;;;;;;;;;;;;AAOO,MAAMA,8BAA8BC;IAczC,IAAI,KAAa;QACf,OAAO,IAAI,CAAC,GAAG;IACjB;IAEA,oBAAoBC,QAA+B,EAAQ;QAEzD,IAAI,CAAC,gBAAgB,GAAGC;QAExB,IAAI,CAAC,gBAAgB,GAAGD;IAC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E;QAClC,KAAK,IAPP,uBAAQ,SAAR,SACA,uBAAQ,oBAA2C,CAAC,IACpD,uBAAQ,oBAAR,SACA,uBAAiB,OAAjB,SACA,uBAAQ,oBAAR;QAIE,IAAI,CAAC,KAAK,GAAGA;QACb,IAAI,CAAC,GAAG,GAAGC;IACb;AAyNF"}
|
package/dist/es/common.mjs
CHANGED
|
@@ -17,7 +17,7 @@ const noReplayAPIs = [
|
|
|
17
17
|
];
|
|
18
18
|
const formatErrorMessage = (e)=>{
|
|
19
19
|
const errorMessage = (null == e ? void 0 : e.message) || '';
|
|
20
|
-
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://
|
|
20
|
+
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://sqai.tech/quick-experience.html#faq';
|
|
21
21
|
if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) return 'Further actions cannot be performed in the current environment';
|
|
22
22
|
return errorMessage || 'Unknown error';
|
|
23
23
|
};
|
package/dist/es/common.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.mjs","sources":["webpack://@sqaitech/playground/./src/common.ts"],"sourcesContent":["import type { DeviceAction } from '@sqaitech/core';\r\nimport { findAllMidsceneLocatorField } from '@sqaitech/core/ai-model';\r\nimport { buildDetailedLocateParam } from '@sqaitech/core/yaml';\r\nimport type {\r\n ExecutionOptions,\r\n FormValue,\r\n PlaygroundAgent,\r\n ValidationResult,\r\n} from './types';\r\n\r\n// APIs that should not generate replay scripts\r\nexport const dataExtractionAPIs = [\r\n 'aiQuery',\r\n 'aiBoolean',\r\n 'aiNumber',\r\n 'aiString',\r\n 'aiAsk',\r\n];\r\n\r\nexport const validationAPIs = ['aiAssert', 'aiWaitFor'];\r\n\r\nexport const noReplayAPIs = [...dataExtractionAPIs, ...validationAPIs];\r\n\r\nexport const formatErrorMessage = (e: any): string => {\r\n const errorMessage = e?.message || '';\r\n\r\n if (errorMessage.includes('of different extension')) {\r\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';\r\n }\r\n\r\n if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) {\r\n return 'Further actions cannot be performed in the current environment';\r\n }\r\n\r\n return errorMessage || 'Unknown error';\r\n};\r\n\r\n// Parse structured parameters for callActionInActionSpace\r\nexport async function parseStructuredParams(\r\n action: DeviceAction<unknown>,\r\n params: Record<string, unknown>,\r\n options: ExecutionOptions = {},\r\n): Promise<unknown[]> {\r\n if (!action?.paramSchema || !('shape' in action.paramSchema)) {\r\n return [params.prompt || '', options];\r\n }\r\n\r\n const schema = action.paramSchema;\r\n const keys =\r\n schema && 'shape' in schema\r\n ? Object.keys((schema as { shape: Record<string, unknown> }).shape)\r\n : [];\r\n\r\n const paramObj: Record<string, unknown> = { ...options };\r\n\r\n keys.forEach((key) => {\r\n if (\r\n params[key] !== undefined &&\r\n params[key] !== null &&\r\n params[key] !== ''\r\n ) {\r\n paramObj[key] = params[key];\r\n }\r\n });\r\n\r\n // Check if there's a locate field that needs detailed locate param processing\r\n if (schema) {\r\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\r\n locatorFieldKeys.forEach((locateKey: string) => {\r\n const locatePrompt = params[locateKey];\r\n if (locatePrompt && typeof locatePrompt === 'string') {\r\n // Build detailed locate param using the locate prompt and options\r\n const detailedLocateParam = buildDetailedLocateParam(locatePrompt, {\r\n deepThink: options.deepThink,\r\n cacheable: true, // Default to true for playground\r\n });\r\n if (detailedLocateParam) {\r\n paramObj[locateKey] = detailedLocateParam;\r\n }\r\n }\r\n });\r\n }\r\n\r\n return [paramObj];\r\n}\r\n\r\nexport function validateStructuredParams(\r\n value: FormValue,\r\n action: DeviceAction<unknown> | undefined,\r\n): ValidationResult {\r\n if (!value.params) {\r\n return { valid: false, errorMessage: 'Parameters are required' };\r\n }\r\n\r\n if (!action?.paramSchema) {\r\n return { valid: true };\r\n }\r\n\r\n try {\r\n const paramsForValidation = { ...value.params };\r\n\r\n const schema = action.paramSchema;\r\n if (schema) {\r\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\r\n locatorFieldKeys.forEach((key: string) => {\r\n if (typeof paramsForValidation[key] === 'string') {\r\n paramsForValidation[key] = {\r\n midscene_location_field_flag: true,\r\n prompt: paramsForValidation[key],\r\n center: [0, 0],\r\n rect: { left: 0, top: 0, width: 0, height: 0 },\r\n };\r\n }\r\n });\r\n }\r\n\r\n action.paramSchema?.parse(paramsForValidation);\r\n return { valid: true };\r\n } catch (error: unknown) {\r\n const zodError = error as {\r\n errors?: Array<{ path: string[]; message: string }>;\r\n };\r\n if (zodError.errors && zodError.errors.length > 0) {\r\n const errorMessages = zodError.errors\r\n .filter((err) => {\r\n const path = err.path.join('.');\r\n return (\r\n !path.includes('center') &&\r\n !path.includes('rect') &&\r\n !path.includes('midscene_location_field_flag')\r\n );\r\n })\r\n .map((err) => {\r\n const field = err.path.join('.');\r\n return `${field}: ${err.message}`;\r\n });\r\n\r\n if (errorMessages.length > 0) {\r\n return {\r\n valid: false,\r\n errorMessage: `Validation error: ${errorMessages.join(', ')}`,\r\n };\r\n }\r\n } else {\r\n const errorMsg =\r\n error instanceof Error ? error.message : 'Unknown validation error';\r\n return {\r\n valid: false,\r\n errorMessage: `Parameter validation failed: ${errorMsg}`,\r\n };\r\n }\r\n }\r\n\r\n return { valid: true };\r\n}\r\n\r\nexport async function executeAction(\r\n activeAgent: PlaygroundAgent,\r\n actionType: string,\r\n actionSpace: DeviceAction<unknown>[],\r\n value: FormValue,\r\n options: ExecutionOptions,\r\n): Promise<unknown> {\r\n const action = actionSpace?.find(\r\n (a: DeviceAction<unknown>) =>\r\n a.interfaceAlias === actionType || a.name === actionType,\r\n );\r\n\r\n if (action && typeof activeAgent.callActionInActionSpace === 'function') {\r\n if (value.params) {\r\n const parsedParams = await parseStructuredParams(\r\n action,\r\n value.params,\r\n options,\r\n );\r\n return await activeAgent.callActionInActionSpace(\r\n action.name,\r\n parsedParams[0],\r\n );\r\n } else {\r\n // For prompt-based actions, we need to build the detailed locate param\r\n const detailedLocateParam = value.prompt\r\n ? buildDetailedLocateParam(value.prompt, {\r\n deepThink: options.deepThink,\r\n cacheable: true,\r\n })\r\n : undefined;\r\n\r\n return await activeAgent.callActionInActionSpace(action.name, {\r\n locate: detailedLocateParam,\r\n ...options,\r\n });\r\n }\r\n } else {\r\n const prompt = value.prompt;\r\n\r\n if (actionType === 'aiAssert') {\r\n const { pass, thought } =\r\n (await activeAgent?.aiAssert?.(prompt || '', undefined, {\r\n keepRawResponse: true,\r\n ...options,\r\n })) || {};\r\n return { pass: pass || false, thought: thought || '' };\r\n }\r\n\r\n // Fallback for methods not found in actionSpace\r\n if (activeAgent && typeof activeAgent[actionType] === 'function') {\r\n return await activeAgent[actionType](prompt, options);\r\n }\r\n\r\n throw new Error(`Unknown action type: ${actionType}`);\r\n }\r\n}\r\n"],"names":["dataExtractionAPIs","validationAPIs","noReplayAPIs","formatErrorMessage","e","errorMessage","parseStructuredParams","action","params","options","schema","keys","Object","paramObj","key","undefined","locatorFieldKeys","findAllMidsceneLocatorField","locateKey","locatePrompt","detailedLocateParam","buildDetailedLocateParam","validateStructuredParams","value","_action_paramSchema","paramsForValidation","error","zodError","errorMessages","err","path","field","errorMsg","Error","executeAction","activeAgent","actionType","actionSpace","a","parsedParams","prompt","pass","thought"],"mappings":";;AAWO,MAAMA,qBAAqB;IAChC;IACA;IACA;IACA;IACA;CACD;AAEM,MAAMC,iBAAiB;IAAC;IAAY;CAAY;AAEhD,MAAMC,eAAe;OAAIF;OAAuBC;CAAe;AAE/D,MAAME,qBAAqB,CAACC;IACjC,MAAMC,eAAeD,AAAAA,CAAAA,QAAAA,IAAAA,KAAAA,IAAAA,EAAG,OAAO,AAAD,KAAK;IAEnC,IAAIC,aAAa,QAAQ,CAAC,2BACxB,OAAO;IAGT,IAAIA,aAAa,QAAQ,C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AW,CAACC,WAAW,EAC/C,OAAO,MAAMD,WAAW,CAACC,WAAW,CAACI,QAAQ/B;QAG/C,MAAM,IAAIwB,MAAM,CAAC,qBAAqB,EAAEG,YAAY;IACtD;AACF"}
|
|
1
|
+
{"version":3,"file":"common.mjs","sources":["webpack://@sqaitech/playground/./src/common.ts"],"sourcesContent":["import type { DeviceAction } from '@sqaitech/core';\r\nimport { findAllMidsceneLocatorField } from '@sqaitech/core/ai-model';\r\nimport { buildDetailedLocateParam } from '@sqaitech/core/yaml';\r\nimport type {\r\n ExecutionOptions,\r\n FormValue,\r\n PlaygroundAgent,\r\n ValidationResult,\r\n} from './types';\r\n\r\n// APIs that should not generate replay scripts\r\nexport const dataExtractionAPIs = [\r\n 'aiQuery',\r\n 'aiBoolean',\r\n 'aiNumber',\r\n 'aiString',\r\n 'aiAsk',\r\n];\r\n\r\nexport const validationAPIs = ['aiAssert', 'aiWaitFor'];\r\n\r\nexport const noReplayAPIs = [...dataExtractionAPIs, ...validationAPIs];\r\n\r\nexport const formatErrorMessage = (e: any): string => {\r\n const errorMessage = e?.message || '';\r\n\r\n if (errorMessage.includes('of different extension')) {\r\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://sqai.tech/quick-experience.html#faq';\r\n }\r\n\r\n if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) {\r\n return 'Further actions cannot be performed in the current environment';\r\n }\r\n\r\n return errorMessage || 'Unknown error';\r\n};\r\n\r\n// Parse structured parameters for callActionInActionSpace\r\nexport async function parseStructuredParams(\r\n action: DeviceAction<unknown>,\r\n params: Record<string, unknown>,\r\n options: ExecutionOptions = {},\r\n): Promise<unknown[]> {\r\n if (!action?.paramSchema || !('shape' in action.paramSchema)) {\r\n return [params.prompt || '', options];\r\n }\r\n\r\n const schema = action.paramSchema;\r\n const keys =\r\n schema && 'shape' in schema\r\n ? Object.keys((schema as { shape: Record<string, unknown> }).shape)\r\n : [];\r\n\r\n const paramObj: Record<string, unknown> = { ...options };\r\n\r\n keys.forEach((key) => {\r\n if (\r\n params[key] !== undefined &&\r\n params[key] !== null &&\r\n params[key] !== ''\r\n ) {\r\n paramObj[key] = params[key];\r\n }\r\n });\r\n\r\n // Check if there's a locate field that needs detailed locate param processing\r\n if (schema) {\r\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\r\n locatorFieldKeys.forEach((locateKey: string) => {\r\n const locatePrompt = params[locateKey];\r\n if (locatePrompt && typeof locatePrompt === 'string') {\r\n // Build detailed locate param using the locate prompt and options\r\n const detailedLocateParam = buildDetailedLocateParam(locatePrompt, {\r\n deepThink: options.deepThink,\r\n cacheable: true, // Default to true for playground\r\n });\r\n if (detailedLocateParam) {\r\n paramObj[locateKey] = detailedLocateParam;\r\n }\r\n }\r\n });\r\n }\r\n\r\n return [paramObj];\r\n}\r\n\r\nexport function validateStructuredParams(\r\n value: FormValue,\r\n action: DeviceAction<unknown> | undefined,\r\n): ValidationResult {\r\n if (!value.params) {\r\n return { valid: false, errorMessage: 'Parameters are required' };\r\n }\r\n\r\n if (!action?.paramSchema) {\r\n return { valid: true };\r\n }\r\n\r\n try {\r\n const paramsForValidation = { ...value.params };\r\n\r\n const schema = action.paramSchema;\r\n if (schema) {\r\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\r\n locatorFieldKeys.forEach((key: string) => {\r\n if (typeof paramsForValidation[key] === 'string') {\r\n paramsForValidation[key] = {\r\n midscene_location_field_flag: true,\r\n prompt: paramsForValidation[key],\r\n center: [0, 0],\r\n rect: { left: 0, top: 0, width: 0, height: 0 },\r\n };\r\n }\r\n });\r\n }\r\n\r\n action.paramSchema?.parse(paramsForValidation);\r\n return { valid: true };\r\n } catch (error: unknown) {\r\n const zodError = error as {\r\n errors?: Array<{ path: string[]; message: string }>;\r\n };\r\n if (zodError.errors && zodError.errors.length > 0) {\r\n const errorMessages = zodError.errors\r\n .filter((err) => {\r\n const path = err.path.join('.');\r\n return (\r\n !path.includes('center') &&\r\n !path.includes('rect') &&\r\n !path.includes('midscene_location_field_flag')\r\n );\r\n })\r\n .map((err) => {\r\n const field = err.path.join('.');\r\n return `${field}: ${err.message}`;\r\n });\r\n\r\n if (errorMessages.length > 0) {\r\n return {\r\n valid: false,\r\n errorMessage: `Validation error: ${errorMessages.join(', ')}`,\r\n };\r\n }\r\n } else {\r\n const errorMsg =\r\n error instanceof Error ? error.message : 'Unknown validation error';\r\n return {\r\n valid: false,\r\n errorMessage: `Parameter validation failed: ${errorMsg}`,\r\n };\r\n }\r\n }\r\n\r\n return { valid: true };\r\n}\r\n\r\nexport async function executeAction(\r\n activeAgent: PlaygroundAgent,\r\n actionType: string,\r\n actionSpace: DeviceAction<unknown>[],\r\n value: FormValue,\r\n options: ExecutionOptions,\r\n): Promise<unknown> {\r\n const action = actionSpace?.find(\r\n (a: DeviceAction<unknown>) =>\r\n a.interfaceAlias === actionType || a.name === actionType,\r\n );\r\n\r\n if (action && typeof activeAgent.callActionInActionSpace === 'function') {\r\n if (value.params) {\r\n const parsedParams = await parseStructuredParams(\r\n action,\r\n value.params,\r\n options,\r\n );\r\n return await activeAgent.callActionInActionSpace(\r\n action.name,\r\n parsedParams[0],\r\n );\r\n } else {\r\n // For prompt-based actions, we need to build the detailed locate param\r\n const detailedLocateParam = value.prompt\r\n ? buildDetailedLocateParam(value.prompt, {\r\n deepThink: options.deepThink,\r\n cacheable: true,\r\n })\r\n : undefined;\r\n\r\n return await activeAgent.callActionInActionSpace(action.name, {\r\n locate: detailedLocateParam,\r\n ...options,\r\n });\r\n }\r\n } else {\r\n const prompt = value.prompt;\r\n\r\n if (actionType === 'aiAssert') {\r\n const { pass, thought } =\r\n (await activeAgent?.aiAssert?.(prompt || '', undefined, {\r\n keepRawResponse: true,\r\n ...options,\r\n })) || {};\r\n return { pass: pass || false, thought: thought || '' };\r\n }\r\n\r\n // Fallback for methods not found in actionSpace\r\n if (activeAgent && typeof activeAgent[actionType] === 'function') {\r\n return await activeAgent[actionType](prompt, options);\r\n }\r\n\r\n throw new Error(`Unknown action type: ${actionType}`);\r\n }\r\n}\r\n"],"names":["dataExtractionAPIs","validationAPIs","noReplayAPIs","formatErrorMessage","e","errorMessage","parseStructuredParams","action","params","options","schema","keys","Object","paramObj","key","undefined","locatorFieldKeys","findAllMidsceneLocatorField","locateKey","locatePrompt","detailedLocateParam","buildDetailedLocateParam","validateStructuredParams","value","_action_paramSchema","paramsForValidation","error","zodError","errorMessages","err","path","field","errorMsg","Error","executeAction","activeAgent","actionType","actionSpace","a","parsedParams","prompt","pass","thought"],"mappings":";;AAWO,MAAMA,qBAAqB;IAChC;IACA;IACA;IACA;IACA;CACD;AAEM,MAAMC,iBAAiB;IAAC;IAAY;CAAY;AAEhD,MAAMC,eAAe;OAAIF;OAAuBC;CAAe;AAE/D,MAAME,qBAAqB,CAACC;IACjC,MAAMC,eAAeD,AAAAA,CAAAA,QAAAA,IAAAA,KAAAA,IAAAA,EAAG,OAAO,AAAD,KAAK;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,CAAAA,QAAAA,SAAAA,KAAAA,IAAAA,OAAQ,WAAW,AAAD,KAAK,CAAE,YAAWA,OAAO,WAAU,GACxD,OAAO;QAACC,OAAO,MAAM,IAAI;QAAIC;KAAQ;IAGvC,MAAMC,SAASH,OAAO,WAAW;IACjC,MAAMI,OACJD,UAAU,WAAWA,SACjBE,OAAO,IAAI,CAAEF,OAA8C,KAAK,IAChE,EAAE;IAER,MAAMG,WAAoC;QAAE,GAAGJ,OAAO;IAAC;IAEvDE,KAAK,OAAO,CAAC,CAACG;QACZ,IACEN,AAAgBO,WAAhBP,MAAM,CAACM,IAAI,IACXN,AAAgB,SAAhBA,MAAM,CAACM,IAAI,IACXN,AAAgB,O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MAAM,MAAM,GACpCF,yBAAyBE,MAAM,MAAM,EAAE;YACrC,WAAWd,QAAQ,SAAS;YAC5B,WAAW;QACb,KACAM;QAEJ,OAAO,MAAMoB,YAAY,uBAAuB,CAAC5B,OAAO,IAAI,EAAE;YAC5D,QAAQa;YACR,GAAGX,OAAO;QACZ;IACF;IACK;QACL,MAAM+B,SAASjB,MAAM,MAAM;QAE3B,IAAIa,AAAe,eAAfA,YAA2B;gBAEpBD;YADT,MAAM,EAAEM,IAAI,EAAEC,OAAO,EAAE,GACpB,MAAMP,CAAAA,QAAAA,cAAAA,KAAAA,IAAAA,QAAAA,CAAAA,wBAAAA,YAAa,QAAQ,AAAD,IAApBA,KAAAA,IAAAA,sBAAAA,IAAAA,CAAAA,aAAwBK,UAAU,IAAIzB,QAAW;gBACtD,iBAAiB;gBACjB,GAAGN,OAAO;YACZ,EAAC,KAAM,CAAC;YACV,OAAO;gBAAE,MAAMgC,QAAQ;gBAAO,SAASC,WAAW;YAAG;QACvD;QAGA,IAAIP,eAAe,AAAmC,cAAnC,OAAOA,WAAW,CAACC,WAAW,EAC/C,OAAO,MAAMD,WAAW,CAACC,WAAW,CAACI,QAAQ/B;QAG/C,MAAM,IAAIwB,MAAM,CAAC,qBAAqB,EAAEG,YAAY;IACtD;AACF"}
|
|
@@ -56,7 +56,7 @@ class LocalExecutionAdapter extends external_base_js_namespaceObject.BasePlaygro
|
|
|
56
56
|
}
|
|
57
57
|
formatErrorMessage(error) {
|
|
58
58
|
const errorMessage = (null == error ? void 0 : error.message) || '';
|
|
59
|
-
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://
|
|
59
|
+
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://sqai.tech/quick-experience.html#faq';
|
|
60
60
|
return this.formatBasicErrorMessage(error);
|
|
61
61
|
}
|
|
62
62
|
async getActionSpace(context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapters\\local-execution.js","sources":["webpack://@sqaitech/playground/webpack/runtime/define_property_getters","webpack://@sqaitech/playground/webpack/runtime/has_own_property","webpack://@sqaitech/playground/webpack/runtime/make_namespace_object","webpack://@sqaitech/playground/./src/adapters/local-execution.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 '@sqaitech/core';\r\nimport { overrideAIConfig } from '@sqaitech/shared/env';\r\nimport { uuid } from '@sqaitech/shared/utils';\r\nimport { executeAction, parseStructuredParams } from '../common';\r\nimport type { ExecutionOptions, FormValue, PlaygroundAgent } from '../types';\r\nimport { BasePlaygroundAdapter } from './base';\r\n\r\nexport class LocalExecutionAdapter extends BasePlaygroundAdapter {\r\n private agent: PlaygroundAgent;\r\n private taskProgressTips: Record<string, string> = {};\r\n private progressCallback?: (tip: string) => void;\r\n private readonly _id: string; // Unique identifier for this local adapter instance\r\n private currentRequestId?: string; // Track current request to prevent stale callbacks\r\n\r\n constructor(agent: PlaygroundAgent) {\r\n super();\r\n this.agent = agent;\r\n this._id = uuid(); // Generate unique ID for local adapter\r\n }\r\n\r\n // Get adapter ID\r\n get id(): string {\r\n return this._id;\r\n }\r\n\r\n setProgressCallback(callback: (tip: string) => void): void {\r\n // Clear any existing callback before setting new one\r\n this.progressCallback = undefined;\r\n // Set the new callback\r\n this.progressCallback = callback;\r\n }\r\n\r\n private cleanup(requestId: string): void {\r\n delete this.taskProgressTips[requestId];\r\n }\r\n\r\n async parseStructuredParams(\r\n action: DeviceAction<unknown>,\r\n params: Record<string, unknown>,\r\n options: ExecutionOptions,\r\n ): Promise<unknown[]> {\r\n // Use shared implementation from common.ts\r\n return await parseStructuredParams(action, params, options);\r\n }\r\n\r\n formatErrorMessage(error: any): string {\r\n const errorMessage = error?.message || '';\r\n if (errorMessage.includes('of different extension')) {\r\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';\r\n }\r\n return this.formatBasicErrorMessage(error);\r\n }\r\n\r\n // Local execution - use base implementation\r\n // (inherits default executeAction from BasePlaygroundAdapter)\r\n\r\n // Local execution gets actionSpace from internal agent (parameter is for backward compatibility)\r\n async getActionSpace(context?: unknown): Promise<DeviceAction<unknown>[]> {\r\n // Priority 1: Use agent's getActionSpace method\r\n if (this.agent?.getActionSpace) {\r\n return await this.agent.getActionSpace();\r\n }\r\n\r\n // Priority 2: Use agent's interface.actionSpace method\r\n if (\r\n this.agent &&\r\n 'interface' in this.agent &&\r\n typeof this.agent.interface === 'object'\r\n ) {\r\n const page = this.agent.interface as {\r\n actionSpace?: () => Promise<DeviceAction<unknown>[]>;\r\n };\r\n if (page?.actionSpace) {\r\n return await page.actionSpace();\r\n }\r\n }\r\n\r\n // Priority 3: Fallback to context parameter (for backward compatibility with tests)\r\n if (context && typeof context === 'object' && 'actionSpace' in context) {\r\n const contextPage = context as {\r\n actionSpace: () => Promise<DeviceAction<unknown>[]>;\r\n };\r\n return await contextPage.actionSpace();\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // Local execution doesn't use a server, so always return true\r\n async checkStatus(): Promise<boolean> {\r\n return true;\r\n }\r\n\r\n async overrideConfig(aiConfig: Record<string, unknown>): Promise<void> {\r\n // For local execution, use the shared env override function\r\n overrideAIConfig(aiConfig);\r\n }\r\n\r\n async executeAction(\r\n actionType: string,\r\n value: FormValue,\r\n options: ExecutionOptions,\r\n ): Promise<unknown> {\r\n // Get actionSpace using our simplified getActionSpace method\r\n const actionSpace = await this.getActionSpace();\r\n let originalOnTaskStartTip: ((tip: string) => void) | undefined;\r\n\r\n // Setup progress tracking if requestId is provided\r\n if (options.requestId && this.agent) {\r\n // Track current request ID to prevent stale callbacks\r\n this.currentRequestId = options.requestId;\r\n originalOnTaskStartTip = this.agent.onTaskStartTip;\r\n\r\n // Set up a fresh callback\r\n this.agent.onTaskStartTip = (tip: string) => {\r\n // Only process if this is still the current request\r\n if (this.currentRequestId !== options.requestId) {\r\n return;\r\n }\r\n\r\n // Store tip for our progress tracking\r\n this.taskProgressTips[options.requestId!] = tip;\r\n\r\n // Call the direct progress callback set via setProgressCallback\r\n if (this.progressCallback) {\r\n this.progressCallback(tip);\r\n }\r\n\r\n if (typeof originalOnTaskStartTip === 'function') {\r\n originalOnTaskStartTip(tip);\r\n }\r\n };\r\n }\r\n\r\n try {\r\n // Call the base implementation with the original signature\r\n const result = await executeAction(\r\n this.agent,\r\n actionType,\r\n actionSpace,\r\n value,\r\n options,\r\n );\r\n\r\n // For local execution, we need to package the result with dump and reportHTML\r\n // similar to how the server does it\r\n const response = {\r\n result,\r\n dump: null as unknown,\r\n reportHTML: null as string | null,\r\n error: null as string | null,\r\n };\r\n\r\n try {\r\n // Get dump and reportHTML from agent like the server does\r\n if (this.agent.dumpDataString) {\r\n const dumpString = this.agent.dumpDataString();\r\n if (dumpString) {\r\n response.dump = JSON.parse(dumpString);\r\n }\r\n }\r\n\r\n if (this.agent.reportHTMLString) {\r\n response.reportHTML = this.agent.reportHTMLString() || null;\r\n }\r\n\r\n // Write out action dumps\r\n if (this.agent.writeOutActionDumps) {\r\n this.agent.writeOutActionDumps();\r\n }\r\n } catch (error: unknown) {\r\n console.error('Failed to get dump/reportHTML from agent:', error);\r\n }\r\n\r\n this.agent.resetDump();\r\n\r\n return response;\r\n } finally {\r\n // Always clean up progress tracking to prevent memory leaks\r\n if (options.requestId) {\r\n this.cleanup(options.requestId);\r\n // Clear the agent callback to prevent accumulation\r\n if (this.agent) {\r\n this.agent.onTaskStartTip = originalOnTaskStartTip;\r\n }\r\n }\r\n }\r\n }\r\n\r\n async getTaskProgress(requestId: string): Promise<{ tip?: string }> {\r\n // Return the stored tip for this requestId\r\n return { tip: this.taskProgressTips[requestId] || undefined };\r\n }\r\n\r\n // Local execution task cancellation - minimal implementation\r\n async cancelTask(\r\n _requestId: string,\r\n ): Promise<{ error?: string; success?: boolean }> {\r\n if (!this.agent) {\r\n return { error: 'No active agent found for this requestId' };\r\n }\r\n\r\n try {\r\n await this.agent.destroy?.();\r\n return { success: true };\r\n } catch (error: unknown) {\r\n const errorMessage =\r\n error instanceof Error ? error.message : 'Unknown error';\r\n console.error(`Failed to cancel agent: ${errorMessage}`);\r\n return { error: `Failed to cancel: ${errorMessage}` };\r\n }\r\n }\r\n\r\n // Get interface information from the agent\r\n async getInterfaceInfo(): Promise<{\r\n type: string;\r\n description?: string;\r\n } | null> {\r\n if (!this.agent?.interface) {\r\n return null;\r\n }\r\n\r\n try {\r\n const type = this.agent.interface.interfaceType || 'Unknown';\r\n const description = this.agent.interface.describe?.() || undefined;\r\n\r\n return {\r\n type,\r\n description,\r\n };\r\n } catch (error: unknown) {\r\n console.error('Failed to get interface info:', error);\r\n return null;\r\n }\r\n }\r\n}\r\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","LocalExecutionAdapter","BasePlaygroundAdapter","callback","undefined","requestId","action","params","options","parseStructuredParams","error","errorMessage","context","_this_agent","page","contextPage","aiConfig","overrideAIConfig","actionType","value","actionSpace","originalOnTaskStartTip","tip","result","executeAction","response","dumpString","JSON","console","_requestId","Error","_this_agent_interface","type","description","agent","uuid"],"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,Y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AC3CkB,QAAQ,KAAK,CAAC,CAAC,wBAAwB,EAAEjB,cAAc;YACvD,OAAO;gBAAE,OAAO,CAAC,kBAAkB,EAAEA,cAAc;YAAC;QACtD;IACF;IAGA,MAAM,mBAGI;YACHE;QAAL,IAAI,UAACA,CAAAA,cAAAA,IAAI,CAAC,KAAK,AAAD,IAATA,KAAAA,IAAAA,YAAY,SAAS,AAAD,GACvB,OAAO;QAGT,IAAI;gBAEkBkB,gCAAAA;YADpB,MAAMC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,aAAa,IAAI;YACnD,MAAMC,cAAcF,AAAAA,SAAAA,CAAAA,iCAAAA,AAAAA,CAAAA,wBAAAA,IAAI,CAAC,KAAK,CAAC,SAAS,AAAD,EAAE,QAAQ,AAAD,IAA5BA,KAAAA,IAAAA,+BAAAA,IAAAA,CAAAA,sBAAAA,KAAqC3B;YAEzD,OAAO;gBACL4B;gBACAC;YACF;QACF,EAAE,OAAOvB,OAAgB;YACvBkB,QAAQ,KAAK,CAAC,iCAAiClB;YAC/C,OAAO;QACT;IACF;IA5NA,YAAYwB,KAAsB,CAAE;QAClC,KAAK,IAPP,uBAAQ,SAAR,SACA,uBAAQ,oBAA2C,CAAC,IACpD,uBAAQ,oBAAR,SACA,uBAAiB,OAAjB,SACA,uBAAQ,oBAAR;QAIE,IAAI,CAAC,KAAK,GAAGA;QACb,IAAI,CAAC,GAAG,GAAGC,AAAAA,IAAAA,sBAAAA,IAAAA,AAAAA;IACb;AAyNF"}
|
|
1
|
+
{"version":3,"file":"adapters\\local-execution.js","sources":["webpack://@sqaitech/playground/webpack/runtime/define_property_getters","webpack://@sqaitech/playground/webpack/runtime/has_own_property","webpack://@sqaitech/playground/webpack/runtime/make_namespace_object","webpack://@sqaitech/playground/./src/adapters/local-execution.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 '@sqaitech/core';\r\nimport { overrideAIConfig } from '@sqaitech/shared/env';\r\nimport { uuid } from '@sqaitech/shared/utils';\r\nimport { executeAction, parseStructuredParams } from '../common';\r\nimport type { ExecutionOptions, FormValue, PlaygroundAgent } from '../types';\r\nimport { BasePlaygroundAdapter } from './base';\r\n\r\nexport class LocalExecutionAdapter extends BasePlaygroundAdapter {\r\n private agent: PlaygroundAgent;\r\n private taskProgressTips: Record<string, string> = {};\r\n private progressCallback?: (tip: string) => void;\r\n private readonly _id: string; // Unique identifier for this local adapter instance\r\n private currentRequestId?: string; // Track current request to prevent stale callbacks\r\n\r\n constructor(agent: PlaygroundAgent) {\r\n super();\r\n this.agent = agent;\r\n this._id = uuid(); // Generate unique ID for local adapter\r\n }\r\n\r\n // Get adapter ID\r\n get id(): string {\r\n return this._id;\r\n }\r\n\r\n setProgressCallback(callback: (tip: string) => void): void {\r\n // Clear any existing callback before setting new one\r\n this.progressCallback = undefined;\r\n // Set the new callback\r\n this.progressCallback = callback;\r\n }\r\n\r\n private cleanup(requestId: string): void {\r\n delete this.taskProgressTips[requestId];\r\n }\r\n\r\n async parseStructuredParams(\r\n action: DeviceAction<unknown>,\r\n params: Record<string, unknown>,\r\n options: ExecutionOptions,\r\n ): Promise<unknown[]> {\r\n // Use shared implementation from common.ts\r\n return await parseStructuredParams(action, params, options);\r\n }\r\n\r\n formatErrorMessage(error: any): string {\r\n const errorMessage = error?.message || '';\r\n if (errorMessage.includes('of different extension')) {\r\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://sqai.tech/quick-experience.html#faq';\r\n }\r\n return this.formatBasicErrorMessage(error);\r\n }\r\n\r\n // Local execution - use base implementation\r\n // (inherits default executeAction from BasePlaygroundAdapter)\r\n\r\n // Local execution gets actionSpace from internal agent (parameter is for backward compatibility)\r\n async getActionSpace(context?: unknown): Promise<DeviceAction<unknown>[]> {\r\n // Priority 1: Use agent's getActionSpace method\r\n if (this.agent?.getActionSpace) {\r\n return await this.agent.getActionSpace();\r\n }\r\n\r\n // Priority 2: Use agent's interface.actionSpace method\r\n if (\r\n this.agent &&\r\n 'interface' in this.agent &&\r\n typeof this.agent.interface === 'object'\r\n ) {\r\n const page = this.agent.interface as {\r\n actionSpace?: () => Promise<DeviceAction<unknown>[]>;\r\n };\r\n if (page?.actionSpace) {\r\n return await page.actionSpace();\r\n }\r\n }\r\n\r\n // Priority 3: Fallback to context parameter (for backward compatibility with tests)\r\n if (context && typeof context === 'object' && 'actionSpace' in context) {\r\n const contextPage = context as {\r\n actionSpace: () => Promise<DeviceAction<unknown>[]>;\r\n };\r\n return await contextPage.actionSpace();\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // Local execution doesn't use a server, so always return true\r\n async checkStatus(): Promise<boolean> {\r\n return true;\r\n }\r\n\r\n async overrideConfig(aiConfig: Record<string, unknown>): Promise<void> {\r\n // For local execution, use the shared env override function\r\n overrideAIConfig(aiConfig);\r\n }\r\n\r\n async executeAction(\r\n actionType: string,\r\n value: FormValue,\r\n options: ExecutionOptions,\r\n ): Promise<unknown> {\r\n // Get actionSpace using our simplified getActionSpace method\r\n const actionSpace = await this.getActionSpace();\r\n let originalOnTaskStartTip: ((tip: string) => void) | undefined;\r\n\r\n // Setup progress tracking if requestId is provided\r\n if (options.requestId && this.agent) {\r\n // Track current request ID to prevent stale callbacks\r\n this.currentRequestId = options.requestId;\r\n originalOnTaskStartTip = this.agent.onTaskStartTip;\r\n\r\n // Set up a fresh callback\r\n this.agent.onTaskStartTip = (tip: string) => {\r\n // Only process if this is still the current request\r\n if (this.currentRequestId !== options.requestId) {\r\n return;\r\n }\r\n\r\n // Store tip for our progress tracking\r\n this.taskProgressTips[options.requestId!] = tip;\r\n\r\n // Call the direct progress callback set via setProgressCallback\r\n if (this.progressCallback) {\r\n this.progressCallback(tip);\r\n }\r\n\r\n if (typeof originalOnTaskStartTip === 'function') {\r\n originalOnTaskStartTip(tip);\r\n }\r\n };\r\n }\r\n\r\n try {\r\n // Call the base implementation with the original signature\r\n const result = await executeAction(\r\n this.agent,\r\n actionType,\r\n actionSpace,\r\n value,\r\n options,\r\n );\r\n\r\n // For local execution, we need to package the result with dump and reportHTML\r\n // similar to how the server does it\r\n const response = {\r\n result,\r\n dump: null as unknown,\r\n reportHTML: null as string | null,\r\n error: null as string | null,\r\n };\r\n\r\n try {\r\n // Get dump and reportHTML from agent like the server does\r\n if (this.agent.dumpDataString) {\r\n const dumpString = this.agent.dumpDataString();\r\n if (dumpString) {\r\n response.dump = JSON.parse(dumpString);\r\n }\r\n }\r\n\r\n if (this.agent.reportHTMLString) {\r\n response.reportHTML = this.agent.reportHTMLString() || null;\r\n }\r\n\r\n // Write out action dumps\r\n if (this.agent.writeOutActionDumps) {\r\n this.agent.writeOutActionDumps();\r\n }\r\n } catch (error: unknown) {\r\n console.error('Failed to get dump/reportHTML from agent:', error);\r\n }\r\n\r\n this.agent.resetDump();\r\n\r\n return response;\r\n } finally {\r\n // Always clean up progress tracking to prevent memory leaks\r\n if (options.requestId) {\r\n this.cleanup(options.requestId);\r\n // Clear the agent callback to prevent accumulation\r\n if (this.agent) {\r\n this.agent.onTaskStartTip = originalOnTaskStartTip;\r\n }\r\n }\r\n }\r\n }\r\n\r\n async getTaskProgress(requestId: string): Promise<{ tip?: string }> {\r\n // Return the stored tip for this requestId\r\n return { tip: this.taskProgressTips[requestId] || undefined };\r\n }\r\n\r\n // Local execution task cancellation - minimal implementation\r\n async cancelTask(\r\n _requestId: string,\r\n ): Promise<{ error?: string; success?: boolean }> {\r\n if (!this.agent) {\r\n return { error: 'No active agent found for this requestId' };\r\n }\r\n\r\n try {\r\n await this.agent.destroy?.();\r\n return { success: true };\r\n } catch (error: unknown) {\r\n const errorMessage =\r\n error instanceof Error ? error.message : 'Unknown error';\r\n console.error(`Failed to cancel agent: ${errorMessage}`);\r\n return { error: `Failed to cancel: ${errorMessage}` };\r\n }\r\n }\r\n\r\n // Get interface information from the agent\r\n async getInterfaceInfo(): Promise<{\r\n type: string;\r\n description?: string;\r\n } | null> {\r\n if (!this.agent?.interface) {\r\n return null;\r\n }\r\n\r\n try {\r\n const type = this.agent.interface.interfaceType || 'Unknown';\r\n const description = this.agent.interface.describe?.() || undefined;\r\n\r\n return {\r\n type,\r\n description,\r\n };\r\n } catch (error: unknown) {\r\n console.error('Failed to get interface info:', error);\r\n return null;\r\n }\r\n }\r\n}\r\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","LocalExecutionAdapter","BasePlaygroundAdapter","callback","undefined","requestId","action","params","options","parseStructuredParams","error","errorMessage","context","_this_agent","page","contextPage","aiConfig","overrideAIConfig","actionType","value","actionSpace","originalOnTaskStartTip","tip","result","executeAction","response","dumpString","JSON","console","_requestId","Error","_this_agent_interface","type","description","agent","uuid"],"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,OA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AAMC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,aAAa,IAAI;YACnD,MAAMC,cAAcF,AAAAA,SAAAA,CAAAA,iCAAAA,AAAAA,CAAAA,wBAAAA,IAAI,CAAC,KAAK,CAAC,SAAS,AAAD,EAAE,QAAQ,AAAD,IAA5BA,KAAAA,IAAAA,+BAAAA,IAAAA,CAAAA,sBAAAA,KAAqC3B;YAEzD,OAAO;gBACL4B;gBACAC;YACF;QACF,EAAE,OAAOvB,OAAgB;YACvBkB,QAAQ,KAAK,CAAC,iCAAiClB;YAC/C,OAAO;QACT;IACF;IA5NA,YAAYwB,KAAsB,CAAE;QAClC,KAAK,IAPP,uBAAQ,SAAR,SACA,uBAAQ,oBAA2C,CAAC,IACpD,uBAAQ,oBAAR,SACA,uBAAiB,OAAjB,SACA,uBAAQ,oBAAR;QAIE,IAAI,CAAC,KAAK,GAAGA;QACb,IAAI,CAAC,GAAG,GAAGC,AAAAA,IAAAA,sBAAAA,IAAAA,AAAAA;IACb;AAyNF"}
|
package/dist/lib/common.js
CHANGED
|
@@ -51,7 +51,7 @@ const noReplayAPIs = [
|
|
|
51
51
|
];
|
|
52
52
|
const formatErrorMessage = (e)=>{
|
|
53
53
|
const errorMessage = (null == e ? void 0 : e.message) || '';
|
|
54
|
-
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://
|
|
54
|
+
if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://sqai.tech/quick-experience.html#faq';
|
|
55
55
|
if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) return 'Further actions cannot be performed in the current environment';
|
|
56
56
|
return errorMessage || 'Unknown error';
|
|
57
57
|
};
|
package/dist/lib/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sources":["webpack://@sqaitech/playground/webpack/runtime/define_property_getters","webpack://@sqaitech/playground/webpack/runtime/has_own_property","webpack://@sqaitech/playground/webpack/runtime/make_namespace_object","webpack://@sqaitech/playground/./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 '@sqaitech/core';\r\nimport { findAllMidsceneLocatorField } from '@sqaitech/core/ai-model';\r\nimport { buildDetailedLocateParam } from '@sqaitech/core/yaml';\r\nimport type {\r\n ExecutionOptions,\r\n FormValue,\r\n PlaygroundAgent,\r\n ValidationResult,\r\n} from './types';\r\n\r\n// APIs that should not generate replay scripts\r\nexport const dataExtractionAPIs = [\r\n 'aiQuery',\r\n 'aiBoolean',\r\n 'aiNumber',\r\n 'aiString',\r\n 'aiAsk',\r\n];\r\n\r\nexport const validationAPIs = ['aiAssert', 'aiWaitFor'];\r\n\r\nexport const noReplayAPIs = [...dataExtractionAPIs, ...validationAPIs];\r\n\r\nexport const formatErrorMessage = (e: any): string => {\r\n const errorMessage = e?.message || '';\r\n\r\n if (errorMessage.includes('of different extension')) {\r\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';\r\n }\r\n\r\n if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) {\r\n return 'Further actions cannot be performed in the current environment';\r\n }\r\n\r\n return errorMessage || 'Unknown error';\r\n};\r\n\r\n// Parse structured parameters for callActionInActionSpace\r\nexport async function parseStructuredParams(\r\n action: DeviceAction<unknown>,\r\n params: Record<string, unknown>,\r\n options: ExecutionOptions = {},\r\n): Promise<unknown[]> {\r\n if (!action?.paramSchema || !('shape' in action.paramSchema)) {\r\n return [params.prompt || '', options];\r\n }\r\n\r\n const schema = action.paramSchema;\r\n const keys =\r\n schema && 'shape' in schema\r\n ? Object.keys((schema as { shape: Record<string, unknown> }).shape)\r\n : [];\r\n\r\n const paramObj: Record<string, unknown> = { ...options };\r\n\r\n keys.forEach((key) => {\r\n if (\r\n params[key] !== undefined &&\r\n params[key] !== null &&\r\n params[key] !== ''\r\n ) {\r\n paramObj[key] = params[key];\r\n }\r\n });\r\n\r\n // Check if there's a locate field that needs detailed locate param processing\r\n if (schema) {\r\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\r\n locatorFieldKeys.forEach((locateKey: string) => {\r\n const locatePrompt = params[locateKey];\r\n if (locatePrompt && typeof locatePrompt === 'string') {\r\n // Build detailed locate param using the locate prompt and options\r\n const detailedLocateParam = buildDetailedLocateParam(locatePrompt, {\r\n deepThink: options.deepThink,\r\n cacheable: true, // Default to true for playground\r\n });\r\n if (detailedLocateParam) {\r\n paramObj[locateKey] = detailedLocateParam;\r\n }\r\n }\r\n });\r\n }\r\n\r\n return [paramObj];\r\n}\r\n\r\nexport function validateStructuredParams(\r\n value: FormValue,\r\n action: DeviceAction<unknown> | undefined,\r\n): ValidationResult {\r\n if (!value.params) {\r\n return { valid: false, errorMessage: 'Parameters are required' };\r\n }\r\n\r\n if (!action?.paramSchema) {\r\n return { valid: true };\r\n }\r\n\r\n try {\r\n const paramsForValidation = { ...value.params };\r\n\r\n const schema = action.paramSchema;\r\n if (schema) {\r\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\r\n locatorFieldKeys.forEach((key: string) => {\r\n if (typeof paramsForValidation[key] === 'string') {\r\n paramsForValidation[key] = {\r\n midscene_location_field_flag: true,\r\n prompt: paramsForValidation[key],\r\n center: [0, 0],\r\n rect: { left: 0, top: 0, width: 0, height: 0 },\r\n };\r\n }\r\n });\r\n }\r\n\r\n action.paramSchema?.parse(paramsForValidation);\r\n return { valid: true };\r\n } catch (error: unknown) {\r\n const zodError = error as {\r\n errors?: Array<{ path: string[]; message: string }>;\r\n };\r\n if (zodError.errors && zodError.errors.length > 0) {\r\n const errorMessages = zodError.errors\r\n .filter((err) => {\r\n const path = err.path.join('.');\r\n return (\r\n !path.includes('center') &&\r\n !path.includes('rect') &&\r\n !path.includes('midscene_location_field_flag')\r\n );\r\n })\r\n .map((err) => {\r\n const field = err.path.join('.');\r\n return `${field}: ${err.message}`;\r\n });\r\n\r\n if (errorMessages.length > 0) {\r\n return {\r\n valid: false,\r\n errorMessage: `Validation error: ${errorMessages.join(', ')}`,\r\n };\r\n }\r\n } else {\r\n const errorMsg =\r\n error instanceof Error ? error.message : 'Unknown validation error';\r\n return {\r\n valid: false,\r\n errorMessage: `Parameter validation failed: ${errorMsg}`,\r\n };\r\n }\r\n }\r\n\r\n return { valid: true };\r\n}\r\n\r\nexport async function executeAction(\r\n activeAgent: PlaygroundAgent,\r\n actionType: string,\r\n actionSpace: DeviceAction<unknown>[],\r\n value: FormValue,\r\n options: ExecutionOptions,\r\n): Promise<unknown> {\r\n const action = actionSpace?.find(\r\n (a: DeviceAction<unknown>) =>\r\n a.interfaceAlias === actionType || a.name === actionType,\r\n );\r\n\r\n if (action && typeof activeAgent.callActionInActionSpace === 'function') {\r\n if (value.params) {\r\n const parsedParams = await parseStructuredParams(\r\n action,\r\n value.params,\r\n options,\r\n );\r\n return await activeAgent.callActionInActionSpace(\r\n action.name,\r\n parsedParams[0],\r\n );\r\n } else {\r\n // For prompt-based actions, we need to build the detailed locate param\r\n const detailedLocateParam = value.prompt\r\n ? buildDetailedLocateParam(value.prompt, {\r\n deepThink: options.deepThink,\r\n cacheable: true,\r\n })\r\n : undefined;\r\n\r\n return await activeAgent.callActionInActionSpace(action.name, {\r\n locate: detailedLocateParam,\r\n ...options,\r\n });\r\n }\r\n } else {\r\n const prompt = value.prompt;\r\n\r\n if (actionType === 'aiAssert') {\r\n const { pass, thought } =\r\n (await activeAgent?.aiAssert?.(prompt || '', undefined, {\r\n keepRawResponse: true,\r\n ...options,\r\n })) || {};\r\n return { pass: pass || false, thought: thought || '' };\r\n }\r\n\r\n // Fallback for methods not found in actionSpace\r\n if (activeAgent && typeof activeAgent[actionType] === 'function') {\r\n return await activeAgent[actionType](prompt, options);\r\n }\r\n\r\n throw new Error(`Unknown action type: ${actionType}`);\r\n }\r\n}\r\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","dataExtractionAPIs","validationAPIs","noReplayAPIs","formatErrorMessage","e","errorMessage","parseStructuredParams","action","params","options","schema","keys","paramObj","undefined","locatorFieldKeys","findAllMidsceneLocatorField","locateKey","locatePrompt","detailedLocateParam","buildDetailedLocateParam","validateStructuredParams","value","_action_paramSchema","paramsForValidation","error","zodError","errorMessages","err","path","field","errorMsg","Error","executeAction","activeAgent","actionType","actionSpace","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,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,MAAM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AM;QAE3B,IAAIa,AAAe,eAAfA,YAA2B;gBAEpBD;YADT,MAAM,EAAEM,IAAI,EAAEC,OAAO,EAAE,GACpB,MAAMP,CAAAA,QAAAA,cAAAA,KAAAA,IAAAA,QAAAA,CAAAA,wBAAAA,YAAa,QAAQ,AAAD,IAApBA,KAAAA,IAAAA,sBAAAA,IAAAA,CAAAA,aAAwBK,UAAU,IAAIzB,QAAW;gBACtD,iBAAiB;gBACjB,GAAGJ,OAAO;YACZ,EAAC,KAAM,CAAC;YACV,OAAO;gBAAE,MAAM8B,QAAQ;gBAAO,SAASC,WAAW;YAAG;QACvD;QAGA,IAAIP,eAAe,AAAmC,cAAnC,OAAOA,WAAW,CAACC,WAAW,EAC/C,OAAO,MAAMD,WAAW,CAACC,WAAW,CAACI,QAAQ7B;QAG/C,MAAM,IAAIsB,MAAM,CAAC,qBAAqB,EAAEG,YAAY;IACtD;AACF"}
|
|
1
|
+
{"version":3,"file":"common.js","sources":["webpack://@sqaitech/playground/webpack/runtime/define_property_getters","webpack://@sqaitech/playground/webpack/runtime/has_own_property","webpack://@sqaitech/playground/webpack/runtime/make_namespace_object","webpack://@sqaitech/playground/./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 '@sqaitech/core';\r\nimport { findAllMidsceneLocatorField } from '@sqaitech/core/ai-model';\r\nimport { buildDetailedLocateParam } from '@sqaitech/core/yaml';\r\nimport type {\r\n ExecutionOptions,\r\n FormValue,\r\n PlaygroundAgent,\r\n ValidationResult,\r\n} from './types';\r\n\r\n// APIs that should not generate replay scripts\r\nexport const dataExtractionAPIs = [\r\n 'aiQuery',\r\n 'aiBoolean',\r\n 'aiNumber',\r\n 'aiString',\r\n 'aiAsk',\r\n];\r\n\r\nexport const validationAPIs = ['aiAssert', 'aiWaitFor'];\r\n\r\nexport const noReplayAPIs = [...dataExtractionAPIs, ...validationAPIs];\r\n\r\nexport const formatErrorMessage = (e: any): string => {\r\n const errorMessage = e?.message || '';\r\n\r\n if (errorMessage.includes('of different extension')) {\r\n return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://sqai.tech/quick-experience.html#faq';\r\n }\r\n\r\n if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) {\r\n return 'Further actions cannot be performed in the current environment';\r\n }\r\n\r\n return errorMessage || 'Unknown error';\r\n};\r\n\r\n// Parse structured parameters for callActionInActionSpace\r\nexport async function parseStructuredParams(\r\n action: DeviceAction<unknown>,\r\n params: Record<string, unknown>,\r\n options: ExecutionOptions = {},\r\n): Promise<unknown[]> {\r\n if (!action?.paramSchema || !('shape' in action.paramSchema)) {\r\n return [params.prompt || '', options];\r\n }\r\n\r\n const schema = action.paramSchema;\r\n const keys =\r\n schema && 'shape' in schema\r\n ? Object.keys((schema as { shape: Record<string, unknown> }).shape)\r\n : [];\r\n\r\n const paramObj: Record<string, unknown> = { ...options };\r\n\r\n keys.forEach((key) => {\r\n if (\r\n params[key] !== undefined &&\r\n params[key] !== null &&\r\n params[key] !== ''\r\n ) {\r\n paramObj[key] = params[key];\r\n }\r\n });\r\n\r\n // Check if there's a locate field that needs detailed locate param processing\r\n if (schema) {\r\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\r\n locatorFieldKeys.forEach((locateKey: string) => {\r\n const locatePrompt = params[locateKey];\r\n if (locatePrompt && typeof locatePrompt === 'string') {\r\n // Build detailed locate param using the locate prompt and options\r\n const detailedLocateParam = buildDetailedLocateParam(locatePrompt, {\r\n deepThink: options.deepThink,\r\n cacheable: true, // Default to true for playground\r\n });\r\n if (detailedLocateParam) {\r\n paramObj[locateKey] = detailedLocateParam;\r\n }\r\n }\r\n });\r\n }\r\n\r\n return [paramObj];\r\n}\r\n\r\nexport function validateStructuredParams(\r\n value: FormValue,\r\n action: DeviceAction<unknown> | undefined,\r\n): ValidationResult {\r\n if (!value.params) {\r\n return { valid: false, errorMessage: 'Parameters are required' };\r\n }\r\n\r\n if (!action?.paramSchema) {\r\n return { valid: true };\r\n }\r\n\r\n try {\r\n const paramsForValidation = { ...value.params };\r\n\r\n const schema = action.paramSchema;\r\n if (schema) {\r\n const locatorFieldKeys = findAllMidsceneLocatorField(schema);\r\n locatorFieldKeys.forEach((key: string) => {\r\n if (typeof paramsForValidation[key] === 'string') {\r\n paramsForValidation[key] = {\r\n midscene_location_field_flag: true,\r\n prompt: paramsForValidation[key],\r\n center: [0, 0],\r\n rect: { left: 0, top: 0, width: 0, height: 0 },\r\n };\r\n }\r\n });\r\n }\r\n\r\n action.paramSchema?.parse(paramsForValidation);\r\n return { valid: true };\r\n } catch (error: unknown) {\r\n const zodError = error as {\r\n errors?: Array<{ path: string[]; message: string }>;\r\n };\r\n if (zodError.errors && zodError.errors.length > 0) {\r\n const errorMessages = zodError.errors\r\n .filter((err) => {\r\n const path = err.path.join('.');\r\n return (\r\n !path.includes('center') &&\r\n !path.includes('rect') &&\r\n !path.includes('midscene_location_field_flag')\r\n );\r\n })\r\n .map((err) => {\r\n const field = err.path.join('.');\r\n return `${field}: ${err.message}`;\r\n });\r\n\r\n if (errorMessages.length > 0) {\r\n return {\r\n valid: false,\r\n errorMessage: `Validation error: ${errorMessages.join(', ')}`,\r\n };\r\n }\r\n } else {\r\n const errorMsg =\r\n error instanceof Error ? error.message : 'Unknown validation error';\r\n return {\r\n valid: false,\r\n errorMessage: `Parameter validation failed: ${errorMsg}`,\r\n };\r\n }\r\n }\r\n\r\n return { valid: true };\r\n}\r\n\r\nexport async function executeAction(\r\n activeAgent: PlaygroundAgent,\r\n actionType: string,\r\n actionSpace: DeviceAction<unknown>[],\r\n value: FormValue,\r\n options: ExecutionOptions,\r\n): Promise<unknown> {\r\n const action = actionSpace?.find(\r\n (a: DeviceAction<unknown>) =>\r\n a.interfaceAlias === actionType || a.name === actionType,\r\n );\r\n\r\n if (action && typeof activeAgent.callActionInActionSpace === 'function') {\r\n if (value.params) {\r\n const parsedParams = await parseStructuredParams(\r\n action,\r\n value.params,\r\n options,\r\n );\r\n return await activeAgent.callActionInActionSpace(\r\n action.name,\r\n parsedParams[0],\r\n );\r\n } else {\r\n // For prompt-based actions, we need to build the detailed locate param\r\n const detailedLocateParam = value.prompt\r\n ? buildDetailedLocateParam(value.prompt, {\r\n deepThink: options.deepThink,\r\n cacheable: true,\r\n })\r\n : undefined;\r\n\r\n return await activeAgent.callActionInActionSpace(action.name, {\r\n locate: detailedLocateParam,\r\n ...options,\r\n });\r\n }\r\n } else {\r\n const prompt = value.prompt;\r\n\r\n if (actionType === 'aiAssert') {\r\n const { pass, thought } =\r\n (await activeAgent?.aiAssert?.(prompt || '', undefined, {\r\n keepRawResponse: true,\r\n ...options,\r\n })) || {};\r\n return { pass: pass || false, thought: thought || '' };\r\n }\r\n\r\n // Fallback for methods not found in actionSpace\r\n if (activeAgent && typeof activeAgent[actionType] === 'function') {\r\n return await activeAgent[actionType](prompt, options);\r\n }\r\n\r\n throw new Error(`Unknown action type: ${actionType}`);\r\n }\r\n}\r\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","dataExtractionAPIs","validationAPIs","noReplayAPIs","formatErrorMessage","e","errorMessage","parseStructuredParams","action","params","options","schema","keys","paramObj","undefined","locatorFieldKeys","findAllMidsceneLocatorField","locateKey","locatePrompt","detailedLocateParam","buildDetailedLocateParam","validateStructuredParams","value","_action_paramSchema","paramsForValidation","error","zodError","errorMessages","err","path","field","errorMsg","Error","executeAction","activeAgent","actionType","actionSpace","a","parsedParams","prompt","pass","th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ED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqaitech/playground",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.16",
|
|
4
4
|
"description": "SQAI playground utilities for web integration",
|
|
5
5
|
"author": "sqai 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
|
-
"@sqaitech/
|
|
29
|
-
"@sqaitech/
|
|
28
|
+
"@sqaitech/core": "0.30.16",
|
|
29
|
+
"@sqaitech/shared": "0.30.16"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@rslib/core": "^0.11.2",
|