@sqaitech/playground 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/adapters/base.mjs +131 -0
- package/dist/es/adapters/base.mjs.map +1 -0
- package/dist/es/adapters/local-execution.mjs +140 -0
- package/dist/es/adapters/local-execution.mjs.map +1 -0
- package/dist/es/adapters/remote-execution.mjs +308 -0
- package/dist/es/adapters/remote-execution.mjs.map +1 -0
- package/dist/es/common.mjs +148 -0
- package/dist/es/common.mjs.map +1 -0
- package/dist/es/index.browser.mjs +9 -0
- package/dist/es/index.browser.mjs.map +1 -0
- package/dist/es/index.mjs +8 -0
- package/dist/es/launcher.mjs +95 -0
- package/dist/es/launcher.mjs.map +1 -0
- package/dist/es/sdk/index.mjs +102 -0
- package/dist/es/sdk/index.mjs.map +1 -0
- package/dist/es/server.mjs +385 -0
- package/dist/es/server.mjs.map +1 -0
- package/dist/es/types.mjs +0 -0
- package/dist/lib/adapters/base.js +165 -0
- package/dist/lib/adapters/base.js.map +1 -0
- package/dist/lib/adapters/local-execution.js +174 -0
- package/dist/lib/adapters/local-execution.js.map +1 -0
- package/dist/lib/adapters/remote-execution.js +342 -0
- package/dist/lib/adapters/remote-execution.js.map +1 -0
- package/dist/lib/common.js +200 -0
- package/dist/lib/common.js.map +1 -0
- package/dist/lib/index.browser.js +73 -0
- package/dist/lib/index.browser.js.map +1 -0
- package/dist/lib/index.js +77 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/launcher.js +140 -0
- package/dist/lib/launcher.js.map +1 -0
- package/dist/lib/sdk/index.js +136 -0
- package/dist/lib/sdk/index.js.map +1 -0
- package/dist/lib/server.js +435 -0
- package/dist/lib/server.js.map +1 -0
- package/dist/lib/types.js +20 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/types/adapters/base.d.ts +20 -0
- package/dist/types/adapters/local-execution.d.ts +31 -0
- package/dist/types/adapters/remote-execution.d.ts +38 -0
- package/dist/types/common.d.ts +9 -0
- package/dist/types/index.browser.d.ts +7 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/launcher.d.ts +97 -0
- package/dist/types/sdk/index.d.ts +31 -0
- package/dist/types/server.d.ts +75 -0
- package/dist/types/types.d.ts +49 -0
- package/package.json +51 -0
- package/static/favicon.ico +0 -0
- package/static/index.html +1 -0
- package/static/static/css/index.60c69390.css +2 -0
- package/static/static/css/index.60c69390.css.map +1 -0
- package/static/static/image/sqai-logo.b7f781cd.png +0 -0
- package/static/static/js/931.dc961e99.js +620 -0
- package/static/static/js/931.dc961e99.js.LICENSE.txt +146 -0
- package/static/static/js/931.dc961e99.js.map +1 -0
- package/static/static/js/async/173.9cf6b074.js +3 -0
- package/static/static/js/async/173.9cf6b074.js.map +1 -0
- package/static/static/js/async/212.e243c338.js +158 -0
- package/static/static/js/async/212.e243c338.js.map +1 -0
- package/static/static/js/async/329.f888b505.js +26 -0
- package/static/static/js/async/329.f888b505.js.map +1 -0
- package/static/static/js/async/364.1821e74b.js +30 -0
- package/static/static/js/async/364.1821e74b.js.map +1 -0
- package/static/static/js/async/544.b73fa603.js +2 -0
- package/static/static/js/async/544.b73fa603.js.map +1 -0
- package/static/static/js/async/582.5dccae2d.js +21 -0
- package/static/static/js/async/582.5dccae2d.js.map +1 -0
- package/static/static/js/async/624.45ee2b2c.js +3 -0
- package/static/static/js/async/624.45ee2b2c.js.map +1 -0
- package/static/static/js/async/644.6bdc4065.js +1 -0
- package/static/static/js/async/659.9afd03db.js +21 -0
- package/static/static/js/async/659.9afd03db.js.map +1 -0
- package/static/static/js/async/702.60261735.js +231 -0
- package/static/static/js/async/702.60261735.js.map +1 -0
- package/static/static/js/async/920.7d9a9aa8.js +2 -0
- package/static/static/js/async/920.7d9a9aa8.js.map +1 -0
- package/static/static/js/async/983.8b91303f.js +1 -0
- package/static/static/js/index.0c5d4f3b.js +10 -0
- package/static/static/js/index.0c5d4f3b.js.LICENSE.txt +7 -0
- package/static/static/js/index.0c5d4f3b.js.map +1 -0
- package/static/static/js/index.3890f2de.js +10 -0
- package/static/static/js/index.3890f2de.js.LICENSE.txt +7 -0
- package/static/static/js/index.3890f2de.js.map +1 -0
- package/static/static/js/index.39b0d1ea.js +10 -0
- package/static/static/js/index.39b0d1ea.js.LICENSE.txt +7 -0
- package/static/static/js/index.39b0d1ea.js.map +1 -0
- package/static/static/js/index.3f24d218.js +10 -0
- package/static/static/js/index.3f24d218.js.LICENSE.txt +7 -0
- package/static/static/js/index.3f24d218.js.map +1 -0
- package/static/static/js/index.5cccbdaf.js +10 -0
- package/static/static/js/index.5cccbdaf.js.LICENSE.txt +7 -0
- package/static/static/js/index.5cccbdaf.js.map +1 -0
- package/static/static/js/index.8a10896b.js +10 -0
- package/static/static/js/index.8a10896b.js.LICENSE.txt +7 -0
- package/static/static/js/index.8a10896b.js.map +1 -0
- package/static/static/js/index.afc8ef37.js +10 -0
- package/static/static/js/index.afc8ef37.js.LICENSE.txt +7 -0
- package/static/static/js/index.afc8ef37.js.map +1 -0
- package/static/static/js/index.b8a17a87.js +10 -0
- package/static/static/js/index.b8a17a87.js.LICENSE.txt +7 -0
- package/static/static/js/index.b8a17a87.js.map +1 -0
- package/static/static/js/index.d0dcab60.js +10 -0
- package/static/static/js/index.d0dcab60.js.LICENSE.txt +7 -0
- package/static/static/js/index.d0dcab60.js.map +1 -0
- package/static/static/js/index.f21bb1df.js +10 -0
- package/static/static/js/index.f21bb1df.js.LICENSE.txt +7 -0
- package/static/static/js/index.f21bb1df.js.map +1 -0
- package/static/static/js/lib-react.f566a9ed.js +3 -0
- package/static/static/js/lib-react.f566a9ed.js.LICENSE.txt +39 -0
- package/static/static/js/lib-react.f566a9ed.js.map +1 -0
- package/static/static/svg/server-offline-foreground.3113df3c.svg +36 -0
- package/static/static/wasm/9e906fbf55e08f98.module.wasm +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
PlaygroundSDK: ()=>PlaygroundSDK
|
|
28
|
+
});
|
|
29
|
+
const constants_namespaceObject = require("@sqaitech/shared/constants");
|
|
30
|
+
const local_execution_js_namespaceObject = require("../adapters/local-execution.js");
|
|
31
|
+
const remote_execution_js_namespaceObject = require("../adapters/remote-execution.js");
|
|
32
|
+
function _define_property(obj, key, value) {
|
|
33
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
34
|
+
value: value,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true
|
|
38
|
+
});
|
|
39
|
+
else obj[key] = value;
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
class PlaygroundSDK {
|
|
43
|
+
createAdapter(type, serverUrl, agent) {
|
|
44
|
+
switch(type){
|
|
45
|
+
case 'local-execution':
|
|
46
|
+
if (!agent) throw new Error('Agent is required for local execution');
|
|
47
|
+
return new local_execution_js_namespaceObject.LocalExecutionAdapter(agent);
|
|
48
|
+
case 'remote-execution':
|
|
49
|
+
{
|
|
50
|
+
const finalServerUrl = serverUrl || ('undefined' != typeof window && window.location.protocol.includes('http') ? window.location.origin : `http://localhost:${constants_namespaceObject.PLAYGROUND_SERVER_PORT}`);
|
|
51
|
+
return new remote_execution_js_namespaceObject.RemoteExecutionAdapter(finalServerUrl);
|
|
52
|
+
}
|
|
53
|
+
default:
|
|
54
|
+
throw new Error(`Unsupported execution type: ${type}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async executeAction(actionType, value, options) {
|
|
58
|
+
const result = await this.adapter.executeAction(actionType, value, options);
|
|
59
|
+
if (options.requestId) this.stopProgressPolling(options.requestId);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
async getActionSpace(context) {
|
|
63
|
+
return this.adapter.getActionSpace(context);
|
|
64
|
+
}
|
|
65
|
+
validateStructuredParams(value, action) {
|
|
66
|
+
return this.adapter.validateParams(value, action);
|
|
67
|
+
}
|
|
68
|
+
formatErrorMessage(error) {
|
|
69
|
+
return this.adapter.formatErrorMessage(error);
|
|
70
|
+
}
|
|
71
|
+
createDisplayContent(value, needsStructuredParams, action) {
|
|
72
|
+
return this.adapter.createDisplayContent(value, needsStructuredParams, action);
|
|
73
|
+
}
|
|
74
|
+
get id() {
|
|
75
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) return this.adapter.id;
|
|
76
|
+
if (this.adapter instanceof local_execution_js_namespaceObject.LocalExecutionAdapter) return this.adapter.id;
|
|
77
|
+
}
|
|
78
|
+
async checkStatus() {
|
|
79
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) return this.adapter.checkStatus();
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
async overrideConfig(aiConfig) {
|
|
83
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) return this.adapter.overrideConfig(aiConfig);
|
|
84
|
+
}
|
|
85
|
+
async getTaskProgress(requestId) {
|
|
86
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) return this.adapter.getTaskProgress(requestId);
|
|
87
|
+
if (this.adapter instanceof local_execution_js_namespaceObject.LocalExecutionAdapter) return this.adapter.getTaskProgress(requestId);
|
|
88
|
+
return {
|
|
89
|
+
tip: void 0
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async cancelTask(requestId) {
|
|
93
|
+
this.stopProgressPolling(requestId);
|
|
94
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) return this.adapter.cancelTask(requestId);
|
|
95
|
+
return {
|
|
96
|
+
error: 'Cancel task not supported in local execution mode'
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
onProgressUpdate(callback) {
|
|
100
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) this.adapter.setProgressCallback(callback);
|
|
101
|
+
else if (this.adapter instanceof local_execution_js_namespaceObject.LocalExecutionAdapter) this.adapter.setProgressCallback(callback);
|
|
102
|
+
}
|
|
103
|
+
startProgressPolling(requestId) {
|
|
104
|
+
console.warn('startProgressPolling is deprecated - polling is now automatic');
|
|
105
|
+
}
|
|
106
|
+
stopProgressPolling(requestId) {
|
|
107
|
+
console.warn('stopProgressPolling is deprecated - polling cleanup is now automatic');
|
|
108
|
+
}
|
|
109
|
+
async cancelExecution(requestId) {
|
|
110
|
+
this.stopProgressPolling(requestId);
|
|
111
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) await this.adapter.cancelTask(requestId);
|
|
112
|
+
else if (this.adapter instanceof local_execution_js_namespaceObject.LocalExecutionAdapter) console.warn('Local execution cancellation not fully implemented');
|
|
113
|
+
}
|
|
114
|
+
async getScreenshot() {
|
|
115
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) return this.adapter.getScreenshot();
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
async getInterfaceInfo() {
|
|
119
|
+
if (this.adapter instanceof local_execution_js_namespaceObject.LocalExecutionAdapter) return this.adapter.getInterfaceInfo();
|
|
120
|
+
if (this.adapter instanceof remote_execution_js_namespaceObject.RemoteExecutionAdapter) return this.adapter.getInterfaceInfo();
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
constructor(config){
|
|
124
|
+
_define_property(this, "adapter", void 0);
|
|
125
|
+
this.adapter = this.createAdapter(config.type, config.serverUrl, config.agent);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.PlaygroundSDK = __webpack_exports__.PlaygroundSDK;
|
|
129
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
130
|
+
"PlaygroundSDK"
|
|
131
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
132
|
+
Object.defineProperty(exports, '__esModule', {
|
|
133
|
+
value: true
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk\\index.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/sdk/index.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 { PLAYGROUND_SERVER_PORT } from '@sqaitech/shared/constants';\r\nimport type { BasePlaygroundAdapter } from '../adapters/base';\r\nimport { LocalExecutionAdapter } from '../adapters/local-execution';\r\nimport { RemoteExecutionAdapter } from '../adapters/remote-execution';\r\nimport type {\r\n ExecutionOptions,\r\n FormValue,\r\n PlaygroundAgent,\r\n PlaygroundConfig,\r\n ValidationResult,\r\n} from '../types';\r\n\r\nexport class PlaygroundSDK {\r\n private adapter: BasePlaygroundAdapter;\r\n\r\n constructor(config: PlaygroundConfig) {\r\n this.adapter = this.createAdapter(\r\n config.type,\r\n config.serverUrl,\r\n config.agent,\r\n );\r\n }\r\n\r\n private createAdapter(\r\n type: string,\r\n serverUrl?: string,\r\n agent?: PlaygroundAgent,\r\n ): BasePlaygroundAdapter {\r\n switch (type) {\r\n case 'local-execution':\r\n if (!agent) {\r\n throw new Error('Agent is required for local execution');\r\n }\r\n return new LocalExecutionAdapter(agent);\r\n case 'remote-execution': {\r\n // Use provided serverUrl first, then fallback to localhost if current page origin is file:// or default\r\n const finalServerUrl =\r\n serverUrl ||\r\n (typeof window !== 'undefined' &&\r\n window.location.protocol.includes('http')\r\n ? window.location.origin\r\n : `http://localhost:${PLAYGROUND_SERVER_PORT}`);\r\n\r\n return new RemoteExecutionAdapter(finalServerUrl);\r\n }\r\n default:\r\n throw new Error(`Unsupported execution type: ${type}`);\r\n }\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 const result = await this.adapter.executeAction(actionType, value, options);\r\n\r\n // Stop any active polling for this request after execution completes\r\n if (options.requestId) {\r\n this.stopProgressPolling(options.requestId);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n async getActionSpace(context?: unknown): Promise<DeviceAction<unknown>[]> {\r\n // Both adapters now accept context parameter\r\n // Local will prioritize internal agent, Remote will use server + fallback\r\n return this.adapter.getActionSpace(context);\r\n }\r\n\r\n validateStructuredParams(\r\n value: FormValue,\r\n action: DeviceAction<unknown> | undefined,\r\n ): ValidationResult {\r\n return this.adapter.validateParams(value, action);\r\n }\r\n\r\n formatErrorMessage(error: any): string {\r\n return this.adapter.formatErrorMessage(error);\r\n }\r\n\r\n createDisplayContent(\r\n value: FormValue,\r\n needsStructuredParams: boolean,\r\n action: DeviceAction<unknown> | undefined,\r\n ): string {\r\n return this.adapter.createDisplayContent(\r\n value,\r\n needsStructuredParams,\r\n action,\r\n );\r\n }\r\n\r\n // Get adapter ID (works for both remote and local execution)\r\n get id(): string | undefined {\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n return this.adapter.id;\r\n }\r\n if (this.adapter instanceof LocalExecutionAdapter) {\r\n return this.adapter.id;\r\n }\r\n return undefined;\r\n }\r\n\r\n // Server communication methods (for remote execution)\r\n async checkStatus(): Promise<boolean> {\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n return this.adapter.checkStatus();\r\n }\r\n return true; // For local execution, always return true\r\n }\r\n\r\n async overrideConfig(aiConfig: any): Promise<void> {\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n return this.adapter.overrideConfig(aiConfig);\r\n }\r\n // For local execution, this is a no-op\r\n }\r\n\r\n async getTaskProgress(requestId: string): Promise<{ tip?: string }> {\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n return this.adapter.getTaskProgress(requestId);\r\n }\r\n if (this.adapter instanceof LocalExecutionAdapter) {\r\n return this.adapter.getTaskProgress(requestId);\r\n }\r\n return { tip: undefined }; // Fallback\r\n }\r\n\r\n // Cancel task (for remote execution)\r\n async cancelTask(requestId: string): Promise<any> {\r\n // Stop progress polling for this request\r\n this.stopProgressPolling(requestId);\r\n\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n return this.adapter.cancelTask(requestId);\r\n }\r\n return { error: 'Cancel task not supported in local execution mode' };\r\n }\r\n\r\n // Progress callback management\r\n onProgressUpdate(callback: (tip: string) => void): void {\r\n // Pass the callback to the adapter if it supports it\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n this.adapter.setProgressCallback(callback);\r\n } else if (this.adapter instanceof LocalExecutionAdapter) {\r\n this.adapter.setProgressCallback(callback);\r\n }\r\n }\r\n\r\n // Start progress polling for remote execution (deprecated - now handled by adapter)\r\n startProgressPolling(requestId: string): void {\r\n // This method is now handled by the RemoteExecutionAdapter automatically\r\n // when executeAction is called with a requestId\r\n console.warn(\r\n 'startProgressPolling is deprecated - polling is now automatic',\r\n );\r\n }\r\n\r\n // Stop progress polling for a specific request (deprecated - now handled by adapter)\r\n stopProgressPolling(requestId: string): void {\r\n // This method is now handled by the RemoteExecutionAdapter automatically\r\n console.warn(\r\n 'stopProgressPolling is deprecated - polling cleanup is now automatic',\r\n );\r\n }\r\n\r\n // Cancel execution - supports both remote and local\r\n async cancelExecution(requestId: string): Promise<void> {\r\n this.stopProgressPolling(requestId);\r\n\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n await this.adapter.cancelTask(requestId);\r\n } else if (this.adapter instanceof LocalExecutionAdapter) {\r\n // For local execution, we might need to implement agent cancellation\r\n console.warn('Local execution cancellation not fully implemented');\r\n }\r\n }\r\n\r\n // Screenshot method for remote execution\r\n async getScreenshot(): Promise<{\r\n screenshot: string;\r\n timestamp: number;\r\n } | null> {\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n return this.adapter.getScreenshot();\r\n }\r\n return null; // For local execution, not supported yet\r\n }\r\n\r\n // Get interface information (type and description)\r\n async getInterfaceInfo(): Promise<{\r\n type: string;\r\n description?: string;\r\n } | null> {\r\n if (this.adapter instanceof LocalExecutionAdapter) {\r\n return this.adapter.getInterfaceInfo();\r\n }\r\n if (this.adapter instanceof RemoteExecutionAdapter) {\r\n return this.adapter.getInterfaceInfo();\r\n }\r\n return null;\r\n }\r\n}\r\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","PlaygroundSDK","type","serverUrl","agent","Error","LocalExecutionAdapter","finalServerUrl","window","PLAYGROUND_SERVER_PORT","RemoteExecutionAdapter","actionType","value","options","result","context","action","error","needsStructuredParams","aiConfig","requestId","undefined","callback","console","config"],"mappings":"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"}
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
+
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
+
}();
|
|
5
|
+
var __webpack_require__ = {};
|
|
6
|
+
(()=>{
|
|
7
|
+
__webpack_require__.n = (module)=>{
|
|
8
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
9
|
+
__webpack_require__.d(getter, {
|
|
10
|
+
a: getter
|
|
11
|
+
});
|
|
12
|
+
return getter;
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
17
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: definition[key]
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.r = (exports1)=>{
|
|
28
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
29
|
+
value: 'Module'
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
32
|
+
value: true
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __webpack_exports__ = {};
|
|
37
|
+
__webpack_require__.r(__webpack_exports__);
|
|
38
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
39
|
+
PlaygroundServer: ()=>PlaygroundServer,
|
|
40
|
+
default: ()=>server
|
|
41
|
+
});
|
|
42
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
43
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
44
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
45
|
+
const utils_namespaceObject = require("@sqaitech/core/utils");
|
|
46
|
+
const constants_namespaceObject = require("@sqaitech/shared/constants");
|
|
47
|
+
const env_namespaceObject = require("@sqaitech/shared/env");
|
|
48
|
+
const shared_utils_namespaceObject = require("@sqaitech/shared/utils");
|
|
49
|
+
const external_express_namespaceObject = require("express");
|
|
50
|
+
var external_express_default = /*#__PURE__*/ __webpack_require__.n(external_express_namespaceObject);
|
|
51
|
+
const external_common_js_namespaceObject = require("./common.js");
|
|
52
|
+
require("dotenv/config");
|
|
53
|
+
function _define_property(obj, key, value) {
|
|
54
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
55
|
+
value: value,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true
|
|
59
|
+
});
|
|
60
|
+
else obj[key] = value;
|
|
61
|
+
return obj;
|
|
62
|
+
}
|
|
63
|
+
const defaultPort = constants_namespaceObject.PLAYGROUND_SERVER_PORT;
|
|
64
|
+
const server_filename = (0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
|
|
65
|
+
const server_dirname = (0, external_node_path_namespaceObject.dirname)(server_filename);
|
|
66
|
+
const STATIC_PATH = (0, external_node_path_namespaceObject.join)(server_dirname, '..', '..', 'static');
|
|
67
|
+
const errorHandler = (err, req, res, next)=>{
|
|
68
|
+
console.error(err);
|
|
69
|
+
const errorMessage = err instanceof Error ? err.message : 'Internal server error';
|
|
70
|
+
res.status(500).json({
|
|
71
|
+
error: errorMessage
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
class PlaygroundServer {
|
|
75
|
+
get app() {
|
|
76
|
+
return this._app;
|
|
77
|
+
}
|
|
78
|
+
initializeApp() {
|
|
79
|
+
if (this._initialized) return;
|
|
80
|
+
this._app.use(external_express_default().json({
|
|
81
|
+
limit: '50mb'
|
|
82
|
+
}));
|
|
83
|
+
this._app.use((req, _res, next)=>{
|
|
84
|
+
const { context } = req.body || {};
|
|
85
|
+
if (context && 'updateContext' in this.agent.interface && 'function' == typeof this.agent.interface.updateContext) {
|
|
86
|
+
this.agent.interface.updateContext(context);
|
|
87
|
+
console.log('Context updated by PlaygroundServer middleware');
|
|
88
|
+
}
|
|
89
|
+
next();
|
|
90
|
+
});
|
|
91
|
+
this.setupRoutes();
|
|
92
|
+
this.setupStaticRoutes();
|
|
93
|
+
this._app.use(errorHandler);
|
|
94
|
+
this._initialized = true;
|
|
95
|
+
}
|
|
96
|
+
filePathForUuid(uuid) {
|
|
97
|
+
return (0, external_node_path_namespaceObject.join)(this.tmpDir, `${uuid}.json`);
|
|
98
|
+
}
|
|
99
|
+
saveContextFile(uuid, context) {
|
|
100
|
+
const tmpFile = this.filePathForUuid(uuid);
|
|
101
|
+
console.log(`save context file: ${tmpFile}`);
|
|
102
|
+
(0, external_node_fs_namespaceObject.writeFileSync)(tmpFile, context);
|
|
103
|
+
return tmpFile;
|
|
104
|
+
}
|
|
105
|
+
async recreateAgent() {
|
|
106
|
+
if (!this.agentFactory) return void console.warn('Cannot recreate agent: factory function not provided. Agent recreation is only available when using factory mode.');
|
|
107
|
+
console.log('Recreating agent to cancel current task...');
|
|
108
|
+
try {
|
|
109
|
+
if (this.agent && 'function' == typeof this.agent.destroy) await this.agent.destroy();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.warn('Failed to destroy old agent:', error);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
this.agent = await this.agentFactory();
|
|
115
|
+
console.log('Agent recreated successfully');
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error('Failed to recreate agent:', error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
setupRoutes() {
|
|
122
|
+
this._app.get('/status', async (req, res)=>{
|
|
123
|
+
res.send({
|
|
124
|
+
status: 'ok',
|
|
125
|
+
id: this.id
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
this._app.get('/context/:uuid', async (req, res)=>{
|
|
129
|
+
const { uuid } = req.params;
|
|
130
|
+
const contextFile = this.filePathForUuid(uuid);
|
|
131
|
+
if (!(0, external_node_fs_namespaceObject.existsSync)(contextFile)) return res.status(404).json({
|
|
132
|
+
error: 'Context not found'
|
|
133
|
+
});
|
|
134
|
+
const context = (0, external_node_fs_namespaceObject.readFileSync)(contextFile, 'utf8');
|
|
135
|
+
res.json({
|
|
136
|
+
context
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
this._app.get('/task-progress/:requestId', async (req, res)=>{
|
|
140
|
+
const { requestId } = req.params;
|
|
141
|
+
res.json({
|
|
142
|
+
tip: this.taskProgressTips[requestId] || ''
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
this._app.post('/action-space', async (req, res)=>{
|
|
146
|
+
try {
|
|
147
|
+
let actionSpace = [];
|
|
148
|
+
actionSpace = await this.agent.interface.actionSpace();
|
|
149
|
+
const processedActionSpace = actionSpace.map((action)=>{
|
|
150
|
+
if (action && 'object' == typeof action && 'paramSchema' in action) {
|
|
151
|
+
const typedAction = action;
|
|
152
|
+
if (typedAction.paramSchema && 'object' == typeof typedAction.paramSchema) {
|
|
153
|
+
let processedSchema = null;
|
|
154
|
+
try {
|
|
155
|
+
if (typedAction.paramSchema.shape && 'object' == typeof typedAction.paramSchema.shape) processedSchema = {
|
|
156
|
+
type: 'ZodObject',
|
|
157
|
+
shape: typedAction.paramSchema.shape
|
|
158
|
+
};
|
|
159
|
+
} catch (e) {
|
|
160
|
+
const actionName = 'name' in typedAction && 'string' == typeof typedAction.name ? typedAction.name : 'unknown';
|
|
161
|
+
console.warn('Failed to process paramSchema for action:', actionName, e);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
...typedAction,
|
|
165
|
+
paramSchema: processedSchema
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return action;
|
|
170
|
+
});
|
|
171
|
+
res.json(processedActionSpace);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
174
|
+
console.error('Failed to get action space:', error);
|
|
175
|
+
res.status(500).json({
|
|
176
|
+
error: errorMessage
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
this._app.post('/playground-with-context', async (req, res)=>{
|
|
181
|
+
const context = req.body.context;
|
|
182
|
+
if (!context) return res.status(400).json({
|
|
183
|
+
error: 'context is required'
|
|
184
|
+
});
|
|
185
|
+
const requestId = (0, shared_utils_namespaceObject.uuid)();
|
|
186
|
+
this.saveContextFile(requestId, context);
|
|
187
|
+
return res.json({
|
|
188
|
+
location: `/playground/${requestId}`,
|
|
189
|
+
uuid: requestId
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
this._app.post('/execute', async (req, res)=>{
|
|
193
|
+
const { type, prompt, params, requestId, deepThink, screenshotIncluded, domIncluded } = req.body;
|
|
194
|
+
if (!type) return res.status(400).json({
|
|
195
|
+
error: 'type is required'
|
|
196
|
+
});
|
|
197
|
+
if (this.currentTaskId) return res.status(409).json({
|
|
198
|
+
error: 'Another task is already running',
|
|
199
|
+
currentTaskId: this.currentTaskId
|
|
200
|
+
});
|
|
201
|
+
if (requestId) {
|
|
202
|
+
this.currentTaskId = requestId;
|
|
203
|
+
this.taskProgressTips[requestId] = '';
|
|
204
|
+
this.agent.onTaskStartTip = (tip)=>{
|
|
205
|
+
this.taskProgressTips[requestId] = tip;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
const response = {
|
|
209
|
+
result: null,
|
|
210
|
+
dump: null,
|
|
211
|
+
error: null,
|
|
212
|
+
reportHTML: null,
|
|
213
|
+
requestId
|
|
214
|
+
};
|
|
215
|
+
const startTime = Date.now();
|
|
216
|
+
try {
|
|
217
|
+
const actionSpace = await this.agent.interface.actionSpace();
|
|
218
|
+
const value = {
|
|
219
|
+
type,
|
|
220
|
+
prompt,
|
|
221
|
+
params
|
|
222
|
+
};
|
|
223
|
+
response.result = await (0, external_common_js_namespaceObject.executeAction)(this.agent, type, actionSpace, value, {
|
|
224
|
+
deepThink,
|
|
225
|
+
screenshotIncluded,
|
|
226
|
+
domIncluded
|
|
227
|
+
});
|
|
228
|
+
} catch (error) {
|
|
229
|
+
response.error = (0, external_common_js_namespaceObject.formatErrorMessage)(error);
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
response.dump = JSON.parse(this.agent.dumpDataString());
|
|
233
|
+
response.reportHTML = this.agent.reportHTMLString() || null;
|
|
234
|
+
this.agent.writeOutActionDumps();
|
|
235
|
+
this.agent.resetDump();
|
|
236
|
+
} catch (error) {
|
|
237
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
238
|
+
console.error(`write out dump failed: requestId: ${requestId}, ${errorMessage}`);
|
|
239
|
+
}
|
|
240
|
+
res.send(response);
|
|
241
|
+
const timeCost = Date.now() - startTime;
|
|
242
|
+
if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
|
|
243
|
+
else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
|
|
244
|
+
if (requestId) {
|
|
245
|
+
delete this.taskProgressTips[requestId];
|
|
246
|
+
if (this.currentTaskId === requestId) this.currentTaskId = null;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
this._app.post('/cancel/:requestId', async (req, res)=>{
|
|
250
|
+
const { requestId } = req.params;
|
|
251
|
+
if (!requestId) return res.status(400).json({
|
|
252
|
+
error: 'requestId is required'
|
|
253
|
+
});
|
|
254
|
+
try {
|
|
255
|
+
if (this.currentTaskId !== requestId) return res.json({
|
|
256
|
+
status: 'not_found',
|
|
257
|
+
message: 'Task not found or already completed'
|
|
258
|
+
});
|
|
259
|
+
console.log(`Cancelling task: ${requestId}`);
|
|
260
|
+
await this.recreateAgent();
|
|
261
|
+
delete this.taskProgressTips[requestId];
|
|
262
|
+
this.currentTaskId = null;
|
|
263
|
+
res.json({
|
|
264
|
+
status: 'cancelled',
|
|
265
|
+
message: 'Task cancelled successfully by recreating agent'
|
|
266
|
+
});
|
|
267
|
+
} catch (error) {
|
|
268
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
269
|
+
console.error(`Failed to cancel: ${errorMessage}`);
|
|
270
|
+
res.status(500).json({
|
|
271
|
+
error: `Failed to cancel: ${errorMessage}`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
this._app.get('/screenshot', async (_req, res)=>{
|
|
276
|
+
try {
|
|
277
|
+
if ('function' != typeof this.agent.interface.screenshotBase64) return res.status(500).json({
|
|
278
|
+
error: 'Screenshot method not available on current interface'
|
|
279
|
+
});
|
|
280
|
+
const base64Screenshot = await this.agent.interface.screenshotBase64();
|
|
281
|
+
res.json({
|
|
282
|
+
screenshot: base64Screenshot,
|
|
283
|
+
timestamp: Date.now()
|
|
284
|
+
});
|
|
285
|
+
} catch (error) {
|
|
286
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
287
|
+
console.error(`Failed to take screenshot: ${errorMessage}`);
|
|
288
|
+
res.status(500).json({
|
|
289
|
+
error: `Failed to take screenshot: ${errorMessage}`
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
this._app.get('/interface-info', async (_req, res)=>{
|
|
294
|
+
try {
|
|
295
|
+
var _this_agent_interface_describe, _this_agent_interface;
|
|
296
|
+
const type = this.agent.interface.interfaceType || 'Unknown';
|
|
297
|
+
const description = (null == (_this_agent_interface_describe = (_this_agent_interface = this.agent.interface).describe) ? void 0 : _this_agent_interface_describe.call(_this_agent_interface)) || void 0;
|
|
298
|
+
res.json({
|
|
299
|
+
type,
|
|
300
|
+
description
|
|
301
|
+
});
|
|
302
|
+
} catch (error) {
|
|
303
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
304
|
+
console.error(`Failed to get interface info: ${errorMessage}`);
|
|
305
|
+
res.status(500).json({
|
|
306
|
+
error: `Failed to get interface info: ${errorMessage}`
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
this.app.post('/config', async (req, res)=>{
|
|
311
|
+
const { aiConfig } = req.body;
|
|
312
|
+
if (!aiConfig || 'object' != typeof aiConfig) return res.status(400).json({
|
|
313
|
+
error: 'aiConfig is required and must be an object'
|
|
314
|
+
});
|
|
315
|
+
if (0 === Object.keys(aiConfig).length) return res.json({
|
|
316
|
+
status: 'ok',
|
|
317
|
+
message: 'AI config not changed due to empty object'
|
|
318
|
+
});
|
|
319
|
+
try {
|
|
320
|
+
(0, env_namespaceObject.overrideAIConfig)(aiConfig);
|
|
321
|
+
return res.json({
|
|
322
|
+
status: 'ok',
|
|
323
|
+
message: 'AI config updated successfully'
|
|
324
|
+
});
|
|
325
|
+
} catch (error) {
|
|
326
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
327
|
+
console.error(`Failed to update AI config: ${errorMessage}`);
|
|
328
|
+
return res.status(500).json({
|
|
329
|
+
error: `Failed to update AI config: ${errorMessage}`
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
setupStaticRoutes() {
|
|
335
|
+
this._app.get('/', (_req, res)=>{
|
|
336
|
+
this.serveHtmlWithPorts(res);
|
|
337
|
+
});
|
|
338
|
+
this._app.get('/index.html', (_req, res)=>{
|
|
339
|
+
this.serveHtmlWithPorts(res);
|
|
340
|
+
});
|
|
341
|
+
this._app.use(external_express_default()["static"](this.staticPath));
|
|
342
|
+
this._app.get('*', (_req, res)=>{
|
|
343
|
+
this.serveHtmlWithPorts(res);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
serveHtmlWithPorts(res) {
|
|
347
|
+
try {
|
|
348
|
+
const htmlPath = (0, external_node_path_namespaceObject.join)(this.staticPath, 'index.html');
|
|
349
|
+
let html = (0, external_node_fs_namespaceObject.readFileSync)(htmlPath, 'utf8');
|
|
350
|
+
const scrcpyPort = global.scrcpyServerPort || this.port + 1;
|
|
351
|
+
const configScript = `
|
|
352
|
+
<script>
|
|
353
|
+
window.SCRCPY_PORT = ${scrcpyPort};
|
|
354
|
+
</script>
|
|
355
|
+
`;
|
|
356
|
+
html = html.replace('</head>', `${configScript}</head>`);
|
|
357
|
+
res.setHeader('Content-Type', 'text/html');
|
|
358
|
+
res.send(html);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
console.error('Error serving HTML with ports:', error);
|
|
361
|
+
res.status(500).send('Internal Server Error');
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
async launch(port) {
|
|
365
|
+
if (this.agentFactory) {
|
|
366
|
+
console.log('Initializing agent from factory function...');
|
|
367
|
+
this.agent = await this.agentFactory();
|
|
368
|
+
console.log('Agent initialized successfully');
|
|
369
|
+
}
|
|
370
|
+
this.initializeApp();
|
|
371
|
+
this.port = port || defaultPort;
|
|
372
|
+
return new Promise((resolve)=>{
|
|
373
|
+
const serverPort = this.port;
|
|
374
|
+
this.server = this._app.listen(serverPort, ()=>{
|
|
375
|
+
resolve(this);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
async close() {
|
|
380
|
+
return new Promise((resolve, reject)=>{
|
|
381
|
+
if (this.server) {
|
|
382
|
+
try {
|
|
383
|
+
this.agent.destroy();
|
|
384
|
+
} catch (error) {
|
|
385
|
+
console.warn('Failed to destroy agent:', error);
|
|
386
|
+
}
|
|
387
|
+
this.taskProgressTips = {};
|
|
388
|
+
this.server.close((error)=>{
|
|
389
|
+
if (error) reject(error);
|
|
390
|
+
else {
|
|
391
|
+
this.server = void 0;
|
|
392
|
+
resolve();
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
} else resolve();
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
constructor(agent, staticPath = STATIC_PATH, id){
|
|
399
|
+
_define_property(this, "_app", void 0);
|
|
400
|
+
_define_property(this, "tmpDir", void 0);
|
|
401
|
+
_define_property(this, "server", void 0);
|
|
402
|
+
_define_property(this, "port", void 0);
|
|
403
|
+
_define_property(this, "agent", void 0);
|
|
404
|
+
_define_property(this, "staticPath", void 0);
|
|
405
|
+
_define_property(this, "taskProgressTips", void 0);
|
|
406
|
+
_define_property(this, "id", void 0);
|
|
407
|
+
_define_property(this, "_initialized", false);
|
|
408
|
+
_define_property(this, "agentFactory", void 0);
|
|
409
|
+
_define_property(this, "currentTaskId", null);
|
|
410
|
+
this._app = external_express_default()();
|
|
411
|
+
this.tmpDir = (0, utils_namespaceObject.getTmpDir)();
|
|
412
|
+
this.staticPath = staticPath;
|
|
413
|
+
this.taskProgressTips = {};
|
|
414
|
+
this.id = id || (0, shared_utils_namespaceObject.uuid)();
|
|
415
|
+
if ('function' == typeof agent) {
|
|
416
|
+
this.agentFactory = agent;
|
|
417
|
+
this.agent = null;
|
|
418
|
+
} else {
|
|
419
|
+
this.agent = agent;
|
|
420
|
+
this.agentFactory = null;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const server = PlaygroundServer;
|
|
425
|
+
exports.PlaygroundServer = __webpack_exports__.PlaygroundServer;
|
|
426
|
+
exports["default"] = __webpack_exports__["default"];
|
|
427
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
428
|
+
"PlaygroundServer",
|
|
429
|
+
"default"
|
|
430
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
431
|
+
Object.defineProperty(exports, '__esModule', {
|
|
432
|
+
value: true
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
//# sourceMappingURL=server.js.map
|