@aiscene/shared 8.0.2 → 8.0.3
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/cli/cli-args.mjs +95 -0
- package/dist/es/cli/cli-error.mjs +24 -0
- package/dist/es/cli/cli-runner.mjs +10 -40
- package/dist/es/cli/index.mjs +4 -2
- package/dist/es/constants/example-code.mjs +2 -2
- package/dist/es/constants/index.mjs +6 -1
- package/dist/es/env/model-config-manager.mjs +3 -0
- package/dist/es/env/parse-model-config.mjs +6 -1
- package/dist/es/env/types.mjs +2 -1
- package/dist/es/env/utils.mjs +1 -9
- package/dist/es/extractor/index.mjs +2 -2
- package/dist/es/img/index.mjs +2 -2
- package/dist/es/img/info.mjs +18 -21
- package/dist/es/key-alias-utils.mjs +19 -0
- package/dist/es/mcp/base-server.mjs +10 -9
- package/dist/es/mcp/base-tools.mjs +72 -4
- package/dist/es/mcp/cli-report-session.mjs +78 -0
- package/dist/es/mcp/error-formatter.mjs +19 -0
- package/dist/es/mcp/index.mjs +2 -0
- package/dist/es/mcp/init-arg-utils.mjs +38 -0
- package/dist/es/mcp/inject-report-html-plugin.mjs +1 -1
- package/dist/es/mcp/tool-generator.mjs +65 -17
- package/dist/es/node/fs.mjs +1 -1
- package/dist/lib/cli/cli-args.js +138 -0
- package/dist/lib/cli/cli-error.js +61 -0
- package/dist/lib/cli/cli-runner.js +19 -46
- package/dist/lib/cli/index.js +8 -3
- package/dist/lib/constants/example-code.js +2 -2
- package/dist/lib/constants/index.js +23 -3
- package/dist/lib/env/model-config-manager.js +3 -0
- package/dist/lib/env/parse-model-config.js +6 -1
- package/dist/lib/env/types.js +4 -0
- package/dist/lib/env/utils.js +0 -11
- package/dist/lib/extractor/index.js +3 -0
- package/dist/lib/img/index.js +3 -0
- package/dist/lib/img/info.js +21 -21
- package/dist/lib/key-alias-utils.js +62 -0
- package/dist/lib/mcp/base-server.js +11 -10
- package/dist/lib/mcp/base-tools.js +74 -6
- package/dist/lib/mcp/cli-report-session.js +121 -0
- package/dist/lib/mcp/error-formatter.js +53 -0
- package/dist/lib/mcp/index.js +24 -10
- package/dist/lib/mcp/init-arg-utils.js +78 -0
- package/dist/lib/mcp/inject-report-html-plugin.js +1 -1
- package/dist/lib/mcp/tool-generator.js +74 -26
- package/dist/lib/node/fs.js +1 -1
- package/dist/types/cli/cli-args.d.ts +8 -0
- package/dist/types/cli/cli-error.d.ts +5 -0
- package/dist/types/cli/cli-runner.d.ts +4 -7
- package/dist/types/cli/index.d.ts +3 -1
- package/dist/types/constants/example-code.d.ts +1 -1
- package/dist/types/constants/index.d.ts +5 -0
- package/dist/types/env/types.d.ts +10 -2
- package/dist/types/env/utils.d.ts +0 -31
- package/dist/types/extractor/index.d.ts +1 -1
- package/dist/types/img/index.d.ts +1 -1
- package/dist/types/img/info.d.ts +5 -0
- package/dist/types/key-alias-utils.d.ts +9 -0
- package/dist/types/mcp/base-tools.d.ts +74 -5
- package/dist/types/mcp/cli-report-session.d.ts +12 -0
- package/dist/types/mcp/error-formatter.d.ts +12 -0
- package/dist/types/mcp/index.d.ts +2 -0
- package/dist/types/mcp/init-arg-utils.d.ts +13 -0
- package/dist/types/mcp/inject-report-html-plugin.d.ts +2 -2
- package/dist/types/mcp/launcher-helper.d.ts +3 -3
- package/dist/types/mcp/tool-generator.d.ts +3 -3
- package/dist/types/mcp/types.d.ts +9 -0
- package/package.json +1 -1
- package/src/cli/cli-args.ts +173 -0
- package/src/cli/cli-error.ts +24 -0
- package/src/cli/cli-runner.ts +37 -56
- package/src/cli/index.ts +3 -7
- package/src/constants/example-code.ts +2 -2
- package/src/constants/index.ts +10 -0
- package/src/env/model-config-manager.ts +3 -0
- package/src/env/parse-model-config.ts +19 -1
- package/src/env/types.ts +11 -2
- package/src/env/utils.ts +0 -50
- package/src/extractor/index.ts +1 -1
- package/src/img/index.ts +2 -0
- package/src/img/info.ts +36 -45
- package/src/key-alias-utils.ts +23 -0
- package/src/mcp/base-server.ts +10 -12
- package/src/mcp/base-tools.ts +218 -11
- package/src/mcp/cli-report-session.ts +130 -0
- package/src/mcp/error-formatter.ts +52 -0
- package/src/mcp/index.ts +2 -0
- package/src/mcp/init-arg-utils.ts +105 -0
- package/src/mcp/inject-report-html-plugin.ts +3 -3
- package/src/mcp/launcher-helper.ts +3 -3
- package/src/mcp/tool-generator.ts +98 -20
- package/src/mcp/types.ts +16 -1
|
@@ -33,10 +33,11 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
CLIError: ()=>CLIError,
|
|
37
|
-
parseCliArgs: ()=>parseCliArgs,
|
|
38
|
-
parseValue: ()=>parseValue,
|
|
36
|
+
CLIError: ()=>external_cli_error_js_namespaceObject.CLIError,
|
|
37
|
+
parseCliArgs: ()=>external_cli_args_js_namespaceObject.parseCliArgs,
|
|
38
|
+
parseValue: ()=>external_cli_args_js_namespaceObject.parseValue,
|
|
39
39
|
runToolsCLI: ()=>runToolsCLI,
|
|
40
|
+
reportCLIError: ()=>external_cli_error_js_namespaceObject.reportCLIError,
|
|
40
41
|
removePrefix: ()=>removePrefix
|
|
41
42
|
});
|
|
42
43
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
@@ -45,44 +46,9 @@ const external_node_path_namespaceObject = require("node:path");
|
|
|
45
46
|
const external_dotenv_namespaceObject = require("dotenv");
|
|
46
47
|
var external_dotenv_default = /*#__PURE__*/ __webpack_require__.n(external_dotenv_namespaceObject);
|
|
47
48
|
const external_logger_js_namespaceObject = require("../logger.js");
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
value: value,
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true,
|
|
53
|
-
writable: true
|
|
54
|
-
});
|
|
55
|
-
else obj[key] = value;
|
|
56
|
-
return obj;
|
|
57
|
-
}
|
|
49
|
+
const external_cli_args_js_namespaceObject = require("./cli-args.js");
|
|
50
|
+
const external_cli_error_js_namespaceObject = require("./cli-error.js");
|
|
58
51
|
const debug = (0, external_logger_js_namespaceObject.getDebug)('cli-runner');
|
|
59
|
-
class CLIError extends Error {
|
|
60
|
-
constructor(message, exitCode = 1){
|
|
61
|
-
super(message), _define_property(this, "exitCode", void 0), this.exitCode = exitCode;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function parseValue(raw) {
|
|
65
|
-
if (raw.startsWith('{') || raw.startsWith('[')) try {
|
|
66
|
-
return JSON.parse(raw);
|
|
67
|
-
} catch {}
|
|
68
|
-
if (/^-?\d+(\.\d+)?$/.test(raw)) return Number(raw);
|
|
69
|
-
return raw;
|
|
70
|
-
}
|
|
71
|
-
function parseCliArgs(args) {
|
|
72
|
-
const result = {};
|
|
73
|
-
for(let i = 0; i < args.length; i++){
|
|
74
|
-
const arg = args[i];
|
|
75
|
-
if (!arg.startsWith('--')) continue;
|
|
76
|
-
const body = arg.slice(2);
|
|
77
|
-
const eqIdx = body.indexOf('=');
|
|
78
|
-
if (eqIdx >= 0) result[body.slice(0, eqIdx)] = parseValue(body.slice(eqIdx + 1));
|
|
79
|
-
else if (args[i + 1] && !args[i + 1].startsWith('--')) {
|
|
80
|
-
i++;
|
|
81
|
-
result[body] = parseValue(args[i]);
|
|
82
|
-
} else result[body] = true;
|
|
83
|
-
}
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
52
|
function outputContentItem(item, isError) {
|
|
87
53
|
switch(item.type){
|
|
88
54
|
case 'text':
|
|
@@ -114,10 +80,13 @@ function printCommandHelp(scriptName, cmd) {
|
|
|
114
80
|
console.log(def.description);
|
|
115
81
|
const schemaEntries = Object.entries(def.schema);
|
|
116
82
|
if (schemaEntries.length > 0) {
|
|
83
|
+
const optionWidth = Math.max(22, ...schemaEntries.map(([key])=>(0, external_cli_args_js_namespaceObject.getCliOptionDisplay)(key, def.cli?.options?.[key]).label.length));
|
|
117
84
|
console.log('\nOptions:');
|
|
118
85
|
for (const [key, zodType] of schemaEntries){
|
|
86
|
+
const { label, aliases } = (0, external_cli_args_js_namespaceObject.getCliOptionDisplay)(key, def.cli?.options?.[key]);
|
|
119
87
|
const desc = zodType.description ?? '';
|
|
120
|
-
|
|
88
|
+
const aliasText = aliases.length > 0 ? ` (aliases: ${aliases.join(', ')})` : '';
|
|
89
|
+
console.log(` ${label.padEnd(optionWidth)} ${desc}${aliasText}`);
|
|
121
90
|
}
|
|
122
91
|
}
|
|
123
92
|
}
|
|
@@ -167,7 +136,7 @@ async function runToolsCLI(tools, scriptName, options) {
|
|
|
167
136
|
return;
|
|
168
137
|
}
|
|
169
138
|
if ('--version' === commandName || '-v' === commandName || 'version' === commandName.toLowerCase()) {
|
|
170
|
-
if (!cliVersion) throw new CLIError('Failed to determine CLI version');
|
|
139
|
+
if (!cliVersion) throw new external_cli_error_js_namespaceObject.CLIError('Failed to determine CLI version');
|
|
171
140
|
printVersion(scriptName, cliVersion);
|
|
172
141
|
return;
|
|
173
142
|
}
|
|
@@ -176,31 +145,35 @@ async function runToolsCLI(tools, scriptName, options) {
|
|
|
176
145
|
debug('unknown command: %s', commandName);
|
|
177
146
|
console.error(`Unknown command: ${commandName}`);
|
|
178
147
|
printHelp(scriptName, commands, cliVersion);
|
|
179
|
-
throw new CLIError(`Unknown command: ${commandName}`);
|
|
148
|
+
throw new external_cli_error_js_namespaceObject.CLIError(`Unknown command: ${commandName}`);
|
|
180
149
|
}
|
|
181
|
-
const parsedArgs = parseCliArgs(restArgs);
|
|
182
|
-
debug('command: %s, args: %s', match.name, JSON.stringify(parsedArgs));
|
|
150
|
+
const parsedArgs = (0, external_cli_args_js_namespaceObject.parseCliArgs)(restArgs);
|
|
183
151
|
if (true === parsedArgs.help) {
|
|
184
152
|
debug('showing command help for: %s', match.name);
|
|
185
153
|
printCommandHelp(scriptName, match);
|
|
186
154
|
return;
|
|
187
155
|
}
|
|
156
|
+
const cliValidationError = (0, external_cli_args_js_namespaceObject.formatCliValidationError)(scriptName, match.name, match.def, parsedArgs);
|
|
157
|
+
if (cliValidationError) throw new external_cli_error_js_namespaceObject.CLIError(cliValidationError);
|
|
158
|
+
debug('command: %s, args: %s', match.name, JSON.stringify(parsedArgs));
|
|
188
159
|
const result = await match.def.handler(parsedArgs);
|
|
189
160
|
debug('command %s completed, isError: %s', match.name, result.isError ?? false);
|
|
190
161
|
outputResult(result);
|
|
191
162
|
await tools.destroy();
|
|
192
|
-
if (result.isError) throw new CLIError('Command failed', 1);
|
|
163
|
+
if (result.isError) throw new external_cli_error_js_namespaceObject.CLIError('Command failed', 1);
|
|
193
164
|
}
|
|
194
165
|
exports.CLIError = __webpack_exports__.CLIError;
|
|
195
166
|
exports.parseCliArgs = __webpack_exports__.parseCliArgs;
|
|
196
167
|
exports.parseValue = __webpack_exports__.parseValue;
|
|
197
168
|
exports.removePrefix = __webpack_exports__.removePrefix;
|
|
169
|
+
exports.reportCLIError = __webpack_exports__.reportCLIError;
|
|
198
170
|
exports.runToolsCLI = __webpack_exports__.runToolsCLI;
|
|
199
171
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
200
172
|
"CLIError",
|
|
201
173
|
"parseCliArgs",
|
|
202
174
|
"parseValue",
|
|
203
175
|
"removePrefix",
|
|
176
|
+
"reportCLIError",
|
|
204
177
|
"runToolsCLI"
|
|
205
178
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
206
179
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/lib/cli/index.js
CHANGED
|
@@ -24,23 +24,28 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
CLIError: ()=>
|
|
28
|
-
parseCliArgs: ()=>
|
|
29
|
-
parseValue: ()=>
|
|
27
|
+
CLIError: ()=>external_cli_error_js_namespaceObject.CLIError,
|
|
28
|
+
parseCliArgs: ()=>external_cli_args_js_namespaceObject.parseCliArgs,
|
|
29
|
+
parseValue: ()=>external_cli_args_js_namespaceObject.parseValue,
|
|
30
30
|
runToolsCLI: ()=>external_cli_runner_js_namespaceObject.runToolsCLI,
|
|
31
|
+
reportCLIError: ()=>external_cli_error_js_namespaceObject.reportCLIError,
|
|
31
32
|
removePrefix: ()=>external_cli_runner_js_namespaceObject.removePrefix
|
|
32
33
|
});
|
|
34
|
+
const external_cli_error_js_namespaceObject = require("./cli-error.js");
|
|
35
|
+
const external_cli_args_js_namespaceObject = require("./cli-args.js");
|
|
33
36
|
const external_cli_runner_js_namespaceObject = require("./cli-runner.js");
|
|
34
37
|
exports.CLIError = __webpack_exports__.CLIError;
|
|
35
38
|
exports.parseCliArgs = __webpack_exports__.parseCliArgs;
|
|
36
39
|
exports.parseValue = __webpack_exports__.parseValue;
|
|
37
40
|
exports.removePrefix = __webpack_exports__.removePrefix;
|
|
41
|
+
exports.reportCLIError = __webpack_exports__.reportCLIError;
|
|
38
42
|
exports.runToolsCLI = __webpack_exports__.runToolsCLI;
|
|
39
43
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
40
44
|
"CLIError",
|
|
41
45
|
"parseCliArgs",
|
|
42
46
|
"parseValue",
|
|
43
47
|
"removePrefix",
|
|
48
|
+
"reportCLIError",
|
|
44
49
|
"runToolsCLI"
|
|
45
50
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
46
51
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -57,8 +57,8 @@ aiQuery<T>(queryObject: Record<string, string>): Promise<T> // Extracts data fro
|
|
|
57
57
|
// The following is test code for Midscene AI, for reference
|
|
58
58
|
// The following is Playwright syntax, you can use Playwright to assist in test generation
|
|
59
59
|
import { test as base } from '@playwright/test';
|
|
60
|
-
import type { PlayWrightAiFixtureType } from '@
|
|
61
|
-
import { PlaywrightAiFixture } from '@
|
|
60
|
+
import type { PlayWrightAiFixtureType } from '@aiscene/web/playwright';
|
|
61
|
+
import { PlaywrightAiFixture } from '@aiscene/web/playwright';
|
|
62
62
|
|
|
63
63
|
const test = base.extend<PlayWrightAiFixtureType>(PlaywrightAiFixture({
|
|
64
64
|
waitForNetworkIdleTimeout: 2000, // optional, the timeout for waiting for network idle between each action, default is 2000ms
|
|
@@ -25,17 +25,22 @@ var __webpack_exports__ = {};
|
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT: ()=>DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT,
|
|
28
|
-
|
|
28
|
+
SCRCPY_PUSH_TIMEOUT_MS: ()=>SCRCPY_PUSH_TIMEOUT_MS,
|
|
29
29
|
CONTAINER_MINI_WIDTH: ()=>CONTAINER_MINI_WIDTH,
|
|
30
30
|
DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY: ()=>DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
|
|
31
31
|
DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT: ()=>DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT,
|
|
32
|
-
PLAYGROUND_SERVER_PORT: ()=>PLAYGROUND_SERVER_PORT,
|
|
33
32
|
TEXT_MAX_SIZE: ()=>TEXT_MAX_SIZE,
|
|
33
|
+
SCRCPY_PREVIEW_METADATA_TIMEOUT_MS: ()=>SCRCPY_PREVIEW_METADATA_TIMEOUT_MS,
|
|
34
34
|
WEBDRIVER_ELEMENT_ID_KEY: ()=>WEBDRIVER_ELEMENT_ID_KEY,
|
|
35
|
+
YAML_EXAMPLE_CODE: ()=>external_example_code_js_namespaceObject.YAML_EXAMPLE_CODE,
|
|
36
|
+
CONTAINER_MINI_HEIGHT: ()=>CONTAINER_MINI_HEIGHT,
|
|
37
|
+
SCRCPY_VIDEO_STREAM_TIMEOUT_MS: ()=>SCRCPY_VIDEO_STREAM_TIMEOUT_MS,
|
|
38
|
+
SCRCPY_ADB_CONNECT_TIMEOUT_MS: ()=>SCRCPY_ADB_CONNECT_TIMEOUT_MS,
|
|
39
|
+
SCRCPY_START_TIMEOUT_MS: ()=>SCRCPY_START_TIMEOUT_MS,
|
|
40
|
+
PLAYGROUND_SERVER_PORT: ()=>PLAYGROUND_SERVER_PORT,
|
|
35
41
|
DEFAULT_WDA_PORT: ()=>DEFAULT_WDA_PORT,
|
|
36
42
|
NodeType: ()=>constants_NodeType,
|
|
37
43
|
PLAYWRIGHT_EXAMPLE_CODE: ()=>external_example_code_js_namespaceObject.PLAYWRIGHT_EXAMPLE_CODE,
|
|
38
|
-
CONTAINER_MINI_HEIGHT: ()=>CONTAINER_MINI_HEIGHT,
|
|
39
44
|
SCRCPY_SERVER_PORT: ()=>SCRCPY_SERVER_PORT,
|
|
40
45
|
TEXT_SIZE_THRESHOLD: ()=>TEXT_SIZE_THRESHOLD
|
|
41
46
|
});
|
|
@@ -56,6 +61,11 @@ var constants_NodeType = /*#__PURE__*/ function(NodeType) {
|
|
|
56
61
|
}({});
|
|
57
62
|
const PLAYGROUND_SERVER_PORT = 5800;
|
|
58
63
|
const SCRCPY_SERVER_PORT = 5700;
|
|
64
|
+
const SCRCPY_ADB_CONNECT_TIMEOUT_MS = 10000;
|
|
65
|
+
const SCRCPY_PUSH_TIMEOUT_MS = 10000;
|
|
66
|
+
const SCRCPY_START_TIMEOUT_MS = 15000;
|
|
67
|
+
const SCRCPY_VIDEO_STREAM_TIMEOUT_MS = 15000;
|
|
68
|
+
const SCRCPY_PREVIEW_METADATA_TIMEOUT_MS = SCRCPY_ADB_CONNECT_TIMEOUT_MS + SCRCPY_PUSH_TIMEOUT_MS + SCRCPY_START_TIMEOUT_MS + SCRCPY_VIDEO_STREAM_TIMEOUT_MS + 5000;
|
|
59
69
|
const WEBDRIVER_ELEMENT_ID_KEY = 'element-6066-11e4-a52e-4f735466cecf';
|
|
60
70
|
const DEFAULT_WDA_PORT = 8100;
|
|
61
71
|
const DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT = 5000;
|
|
@@ -70,7 +80,12 @@ exports.DEFAULT_WDA_PORT = __webpack_exports__.DEFAULT_WDA_PORT;
|
|
|
70
80
|
exports.NodeType = __webpack_exports__.NodeType;
|
|
71
81
|
exports.PLAYGROUND_SERVER_PORT = __webpack_exports__.PLAYGROUND_SERVER_PORT;
|
|
72
82
|
exports.PLAYWRIGHT_EXAMPLE_CODE = __webpack_exports__.PLAYWRIGHT_EXAMPLE_CODE;
|
|
83
|
+
exports.SCRCPY_ADB_CONNECT_TIMEOUT_MS = __webpack_exports__.SCRCPY_ADB_CONNECT_TIMEOUT_MS;
|
|
84
|
+
exports.SCRCPY_PREVIEW_METADATA_TIMEOUT_MS = __webpack_exports__.SCRCPY_PREVIEW_METADATA_TIMEOUT_MS;
|
|
85
|
+
exports.SCRCPY_PUSH_TIMEOUT_MS = __webpack_exports__.SCRCPY_PUSH_TIMEOUT_MS;
|
|
73
86
|
exports.SCRCPY_SERVER_PORT = __webpack_exports__.SCRCPY_SERVER_PORT;
|
|
87
|
+
exports.SCRCPY_START_TIMEOUT_MS = __webpack_exports__.SCRCPY_START_TIMEOUT_MS;
|
|
88
|
+
exports.SCRCPY_VIDEO_STREAM_TIMEOUT_MS = __webpack_exports__.SCRCPY_VIDEO_STREAM_TIMEOUT_MS;
|
|
74
89
|
exports.TEXT_MAX_SIZE = __webpack_exports__.TEXT_MAX_SIZE;
|
|
75
90
|
exports.TEXT_SIZE_THRESHOLD = __webpack_exports__.TEXT_SIZE_THRESHOLD;
|
|
76
91
|
exports.WEBDRIVER_ELEMENT_ID_KEY = __webpack_exports__.WEBDRIVER_ELEMENT_ID_KEY;
|
|
@@ -85,7 +100,12 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
85
100
|
"NodeType",
|
|
86
101
|
"PLAYGROUND_SERVER_PORT",
|
|
87
102
|
"PLAYWRIGHT_EXAMPLE_CODE",
|
|
103
|
+
"SCRCPY_ADB_CONNECT_TIMEOUT_MS",
|
|
104
|
+
"SCRCPY_PREVIEW_METADATA_TIMEOUT_MS",
|
|
105
|
+
"SCRCPY_PUSH_TIMEOUT_MS",
|
|
88
106
|
"SCRCPY_SERVER_PORT",
|
|
107
|
+
"SCRCPY_START_TIMEOUT_MS",
|
|
108
|
+
"SCRCPY_VIDEO_STREAM_TIMEOUT_MS",
|
|
89
109
|
"TEXT_MAX_SIZE",
|
|
90
110
|
"TEXT_SIZE_THRESHOLD",
|
|
91
111
|
"WEBDRIVER_ELEMENT_ID_KEY",
|
|
@@ -52,14 +52,17 @@ class ModelConfigManager {
|
|
|
52
52
|
this.modelConfigMap = {
|
|
53
53
|
default: {
|
|
54
54
|
...defaultConfig,
|
|
55
|
+
intent: 'default',
|
|
55
56
|
createOpenAIClient: this.createOpenAIClientFn
|
|
56
57
|
},
|
|
57
58
|
insight: {
|
|
58
59
|
...insightConfig || defaultConfig,
|
|
60
|
+
intent: 'insight',
|
|
59
61
|
createOpenAIClient: this.createOpenAIClientFn
|
|
60
62
|
},
|
|
61
63
|
planning: {
|
|
62
64
|
...planningConfig || defaultConfig,
|
|
65
|
+
intent: 'planning',
|
|
63
66
|
createOpenAIClient: this.createOpenAIClientFn
|
|
64
67
|
}
|
|
65
68
|
};
|
|
@@ -36,6 +36,9 @@ const external_logger_js_namespaceObject = require("../logger.js");
|
|
|
36
36
|
const external_utils_js_namespaceObject = require("../utils.js");
|
|
37
37
|
const external_helper_js_namespaceObject = require("./helper.js");
|
|
38
38
|
const external_init_debug_js_namespaceObject = require("./init-debug.js");
|
|
39
|
+
const MODEL_CONFIG_DOC_URL = 'https://midscenejs.com/model-common-config.html';
|
|
40
|
+
const getCurrentVersion = ()=>"8.0.3";
|
|
41
|
+
const getInvalidModelFamilyMessage = (modelFamily)=>`Invalid MIDSCENE_MODEL_FAMILY value: ${modelFamily}. Current version v${getCurrentVersion()} accepts the following model families: ${external_types_js_namespaceObject.MODEL_FAMILY_VALUES.join(', ')}. You can also visit ${MODEL_CONFIG_DOC_URL} for the latest configuration information.`;
|
|
39
42
|
const KEYS_MAP = {
|
|
40
43
|
insight: external_constants_js_namespaceObject.INSIGHT_MODEL_CONFIG_KEYS,
|
|
41
44
|
planning: external_constants_js_namespaceObject.PLANNING_MODEL_CONFIG_KEYS,
|
|
@@ -46,7 +49,7 @@ const getUITarsModelVersion = (modelFamily)=>{
|
|
|
46
49
|
if ('vlm-ui-tars-doubao' === modelFamily || 'vlm-ui-tars-doubao-1.5' === modelFamily) return external_types_js_namespaceObject.UITarsModelVersion.DOUBAO_1_5_20B;
|
|
47
50
|
};
|
|
48
51
|
const validateModelFamily = (modelFamily)=>{
|
|
49
|
-
if (modelFamily && !external_types_js_namespaceObject.MODEL_FAMILY_VALUES.includes(modelFamily)) throw new Error(
|
|
52
|
+
if (modelFamily && !external_types_js_namespaceObject.MODEL_FAMILY_VALUES.includes(modelFamily)) throw new Error(getInvalidModelFamilyMessage(modelFamily));
|
|
50
53
|
};
|
|
51
54
|
const legacyConfigToModelFamily = (provider)=>{
|
|
52
55
|
const isDoubao = provider[external_types_js_namespaceObject.MIDSCENE_USE_DOUBAO_VISION];
|
|
@@ -122,6 +125,7 @@ const parseOpenaiSdkConfig = ({ keys, provider, useLegacyLogic = false })=>{
|
|
|
122
125
|
modelName: modelName,
|
|
123
126
|
modelDescription,
|
|
124
127
|
intent: '-',
|
|
128
|
+
slot: '-',
|
|
125
129
|
timeout: provider[keys.timeout] ? Number(provider[keys.timeout]) : void 0,
|
|
126
130
|
temperature,
|
|
127
131
|
retryCount: (()=>{
|
|
@@ -164,6 +168,7 @@ const decideModelConfigFromIntentConfig = (intent, configMap)=>{
|
|
|
164
168
|
useLegacyLogic: 'default' === intent
|
|
165
169
|
});
|
|
166
170
|
finalResult.intent = intent;
|
|
171
|
+
finalResult.slot = intent;
|
|
167
172
|
debugLog('decideModelConfig result by agent.modelConfig() with intent', intent, (0, external_helper_js_namespaceObject.maskConfig)({
|
|
168
173
|
...finalResult
|
|
169
174
|
}));
|
package/dist/lib/env/types.js
CHANGED
|
@@ -55,6 +55,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
55
55
|
MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY: ()=>MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY,
|
|
56
56
|
MIDSCENE_INSIGHT_MODEL_TEMPERATURE: ()=>MIDSCENE_INSIGHT_MODEL_TEMPERATURE,
|
|
57
57
|
MIDSCENE_INSIGHT_MODEL_TIMEOUT: ()=>MIDSCENE_INSIGHT_MODEL_TIMEOUT,
|
|
58
|
+
MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE: ()=>MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE,
|
|
58
59
|
MIDSCENE_IOS_DEVICE_UDID: ()=>MIDSCENE_IOS_DEVICE_UDID,
|
|
59
60
|
MIDSCENE_IOS_SIMULATOR_UDID: ()=>MIDSCENE_IOS_SIMULATOR_UDID,
|
|
60
61
|
MIDSCENE_LANGFUSE_DEBUG: ()=>MIDSCENE_LANGFUSE_DEBUG,
|
|
@@ -154,6 +155,7 @@ const MIDSCENE_ADB_REMOTE_PORT = 'MIDSCENE_ADB_REMOTE_PORT';
|
|
|
154
155
|
const MIDSCENE_ANDROID_IME_STRATEGY = 'MIDSCENE_ANDROID_IME_STRATEGY';
|
|
155
156
|
const MIDSCENE_IOS_DEVICE_UDID = 'MIDSCENE_IOS_DEVICE_UDID';
|
|
156
157
|
const MIDSCENE_IOS_SIMULATOR_UDID = 'MIDSCENE_IOS_SIMULATOR_UDID';
|
|
158
|
+
const MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE = 'MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE';
|
|
157
159
|
const MIDSCENE_CACHE = 'MIDSCENE_CACHE';
|
|
158
160
|
const MIDSCENE_USE_VLM_UI_TARS = 'MIDSCENE_USE_VLM_UI_TARS';
|
|
159
161
|
const MIDSCENE_USE_QWEN_VL = 'MIDSCENE_USE_QWEN_VL';
|
|
@@ -359,6 +361,7 @@ exports.MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL = __webpack_exports__.MIDSCENE_INS
|
|
|
359
361
|
exports.MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY = __webpack_exports__.MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY;
|
|
360
362
|
exports.MIDSCENE_INSIGHT_MODEL_TEMPERATURE = __webpack_exports__.MIDSCENE_INSIGHT_MODEL_TEMPERATURE;
|
|
361
363
|
exports.MIDSCENE_INSIGHT_MODEL_TIMEOUT = __webpack_exports__.MIDSCENE_INSIGHT_MODEL_TIMEOUT;
|
|
364
|
+
exports.MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE = __webpack_exports__.MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE;
|
|
362
365
|
exports.MIDSCENE_IOS_DEVICE_UDID = __webpack_exports__.MIDSCENE_IOS_DEVICE_UDID;
|
|
363
366
|
exports.MIDSCENE_IOS_SIMULATOR_UDID = __webpack_exports__.MIDSCENE_IOS_SIMULATOR_UDID;
|
|
364
367
|
exports.MIDSCENE_LANGFUSE_DEBUG = __webpack_exports__.MIDSCENE_LANGFUSE_DEBUG;
|
|
@@ -452,6 +455,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
452
455
|
"MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY",
|
|
453
456
|
"MIDSCENE_INSIGHT_MODEL_TEMPERATURE",
|
|
454
457
|
"MIDSCENE_INSIGHT_MODEL_TIMEOUT",
|
|
458
|
+
"MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE",
|
|
455
459
|
"MIDSCENE_IOS_DEVICE_UDID",
|
|
456
460
|
"MIDSCENE_IOS_SIMULATOR_UDID",
|
|
457
461
|
"MIDSCENE_LANGFUSE_DEBUG",
|
package/dist/lib/env/utils.js
CHANGED
|
@@ -27,7 +27,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
overrideAIConfig: ()=>overrideAIConfig,
|
|
28
28
|
globalModelConfigManager: ()=>globalModelConfigManager,
|
|
29
29
|
getPreferredLanguage: ()=>getPreferredLanguage,
|
|
30
|
-
getCurrentTime: ()=>getCurrentTime,
|
|
31
30
|
globalConfigManager: ()=>globalConfigManager
|
|
32
31
|
});
|
|
33
32
|
const external_global_config_manager_js_namespaceObject = require("./global-config-manager.js");
|
|
@@ -37,14 +36,6 @@ const globalModelConfigManager = new external_model_config_manager_js_namespaceO
|
|
|
37
36
|
const globalConfigManager = new external_global_config_manager_js_namespaceObject.GlobalConfigManager();
|
|
38
37
|
globalConfigManager.registerModelConfigManager(globalModelConfigManager);
|
|
39
38
|
globalModelConfigManager.registerGlobalConfigManager(globalConfigManager);
|
|
40
|
-
async function getCurrentTime(device, useDeviceTimestamp) {
|
|
41
|
-
if (useDeviceTimestamp && device?.getTimestamp) try {
|
|
42
|
-
return await device.getTimestamp();
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.warn(`Failed to get device time, falling back to system time: ${error}`);
|
|
45
|
-
}
|
|
46
|
-
return Date.now();
|
|
47
|
-
}
|
|
48
39
|
const getPreferredLanguage = ()=>{
|
|
49
40
|
const prefer = globalConfigManager.getEnvConfigValue(external_types_js_namespaceObject.MIDSCENE_PREFERRED_LANGUAGE);
|
|
50
41
|
if (prefer) return prefer;
|
|
@@ -55,13 +46,11 @@ const getPreferredLanguage = ()=>{
|
|
|
55
46
|
const overrideAIConfig = (newConfig, extendMode = false)=>{
|
|
56
47
|
globalConfigManager.overrideAIConfig(newConfig, extendMode);
|
|
57
48
|
};
|
|
58
|
-
exports.getCurrentTime = __webpack_exports__.getCurrentTime;
|
|
59
49
|
exports.getPreferredLanguage = __webpack_exports__.getPreferredLanguage;
|
|
60
50
|
exports.globalConfigManager = __webpack_exports__.globalConfigManager;
|
|
61
51
|
exports.globalModelConfigManager = __webpack_exports__.globalModelConfigManager;
|
|
62
52
|
exports.overrideAIConfig = __webpack_exports__.overrideAIConfig;
|
|
63
53
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
64
|
-
"getCurrentTime",
|
|
65
54
|
"getPreferredLanguage",
|
|
66
55
|
"globalConfigManager",
|
|
67
56
|
"globalModelConfigManager",
|
|
@@ -24,6 +24,7 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
generateElementByPoint: ()=>external_dom_util_js_namespaceObject.generateElementByPoint,
|
|
27
28
|
getNodeInfoByXpath: ()=>external_locator_js_namespaceObject.getNodeInfoByXpath,
|
|
28
29
|
getXpathsById: ()=>external_locator_js_namespaceObject.getXpathsById,
|
|
29
30
|
trimAttributes: ()=>external_tree_js_namespaceObject.trimAttributes,
|
|
@@ -45,6 +46,7 @@ const external_web_extractor_js_namespaceObject = require("./web-extractor.js");
|
|
|
45
46
|
const external_locator_js_namespaceObject = require("./locator.js");
|
|
46
47
|
const external_dom_util_js_namespaceObject = require("./dom-util.js");
|
|
47
48
|
exports.descriptionOfTree = __webpack_exports__.descriptionOfTree;
|
|
49
|
+
exports.generateElementByPoint = __webpack_exports__.generateElementByPoint;
|
|
48
50
|
exports.generateElementByRect = __webpack_exports__.generateElementByRect;
|
|
49
51
|
exports.getElementInfoByXpath = __webpack_exports__.getElementInfoByXpath;
|
|
50
52
|
exports.getElementXpath = __webpack_exports__.getElementXpath;
|
|
@@ -61,6 +63,7 @@ exports.webExtractNodeTreeAsString = __webpack_exports__.webExtractNodeTreeAsStr
|
|
|
61
63
|
exports.webExtractTextWithPosition = __webpack_exports__.webExtractTextWithPosition;
|
|
62
64
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
63
65
|
"descriptionOfTree",
|
|
66
|
+
"generateElementByPoint",
|
|
64
67
|
"generateElementByRect",
|
|
65
68
|
"getElementInfoByXpath",
|
|
66
69
|
"getElementXpath",
|
package/dist/lib/img/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
resizeImgBase64: ()=>external_transform_js_namespaceObject.resizeImgBase64,
|
|
32
32
|
saveBase64Image: ()=>external_transform_js_namespaceObject.saveBase64Image,
|
|
33
33
|
isValidImageBuffer: ()=>external_info_js_namespaceObject.isValidImageBuffer,
|
|
34
|
+
validateScreenshotBuffer: ()=>external_info_js_namespaceObject.validateScreenshotBuffer,
|
|
34
35
|
preProcessImageUrl: ()=>external_transform_js_namespaceObject.preProcessImageUrl,
|
|
35
36
|
annotateRects: ()=>external_box_select_js_namespaceObject.annotateRects,
|
|
36
37
|
compositeElementInfoImg: ()=>external_box_select_js_namespaceObject.compositeElementInfoImg,
|
|
@@ -65,6 +66,7 @@ exports.resizeAndConvertImgBuffer = __webpack_exports__.resizeAndConvertImgBuffe
|
|
|
65
66
|
exports.resizeImgBase64 = __webpack_exports__.resizeImgBase64;
|
|
66
67
|
exports.saveBase64Image = __webpack_exports__.saveBase64Image;
|
|
67
68
|
exports.scaleImage = __webpack_exports__.scaleImage;
|
|
69
|
+
exports.validateScreenshotBuffer = __webpack_exports__.validateScreenshotBuffer;
|
|
68
70
|
exports.zoomForGPT4o = __webpack_exports__.zoomForGPT4o;
|
|
69
71
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
70
72
|
"annotateRects",
|
|
@@ -85,6 +87,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
85
87
|
"resizeImgBase64",
|
|
86
88
|
"saveBase64Image",
|
|
87
89
|
"scaleImage",
|
|
90
|
+
"validateScreenshotBuffer",
|
|
88
91
|
"zoomForGPT4o"
|
|
89
92
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
90
93
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/lib/img/info.js
CHANGED
|
@@ -35,6 +35,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
36
|
isValidPNGImageBuffer: ()=>isValidPNGImageBuffer,
|
|
37
37
|
isValidImageBuffer: ()=>isValidImageBuffer,
|
|
38
|
+
validateScreenshotBuffer: ()=>validateScreenshotBuffer,
|
|
38
39
|
imageInfoOfBase64: ()=>imageInfoOfBase64,
|
|
39
40
|
isValidJPEGImageBuffer: ()=>isValidJPEGImageBuffer
|
|
40
41
|
});
|
|
@@ -43,27 +44,18 @@ var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_
|
|
|
43
44
|
const external_get_photon_js_namespaceObject = require("./get-photon.js");
|
|
44
45
|
var external_get_photon_js_default = /*#__PURE__*/ __webpack_require__.n(external_get_photon_js_namespaceObject);
|
|
45
46
|
async function imageInfoOfBase64(imageBase64) {
|
|
46
|
-
|
|
47
|
+
const { PhotonImage } = await external_get_photon_js_default()();
|
|
47
48
|
const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, '');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
external_node_assert_default()(width && height, 'Invalid image: cannot get width or height');
|
|
59
|
-
return {
|
|
60
|
-
width,
|
|
61
|
-
height
|
|
62
|
-
};
|
|
63
|
-
} catch (error) {
|
|
64
|
-
if (error instanceof Error && error.message.includes('unreachable')) throw new Error(`Failed to decode image: invalid or corrupted image data. Original error: ${error.message}`);
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
49
|
+
const result = PhotonImage.new_from_base64(base64Data);
|
|
50
|
+
const image = result instanceof Promise ? await result : result;
|
|
51
|
+
const width = image.get_width();
|
|
52
|
+
const height = image.get_height();
|
|
53
|
+
image.free();
|
|
54
|
+
external_node_assert_default()(width && height, 'Invalid image: cannot get width or height');
|
|
55
|
+
return {
|
|
56
|
+
width,
|
|
57
|
+
height
|
|
58
|
+
};
|
|
67
59
|
}
|
|
68
60
|
function isValidPNGImageBuffer(buffer) {
|
|
69
61
|
if (!buffer || buffer.length < 8) return false;
|
|
@@ -77,15 +69,23 @@ function isValidJPEGImageBuffer(buffer) {
|
|
|
77
69
|
function isValidImageBuffer(buffer) {
|
|
78
70
|
return isValidPNGImageBuffer(buffer) || isValidJPEGImageBuffer(buffer);
|
|
79
71
|
}
|
|
72
|
+
function validateScreenshotBuffer(screenshotBuffer, { label, minBufferSize = 0 }) {
|
|
73
|
+
const bufferSize = screenshotBuffer?.length ?? 0;
|
|
74
|
+
if (!screenshotBuffer || 0 === bufferSize) throw new Error(`${label} validation failed: buffer size ${bufferSize} bytes`);
|
|
75
|
+
if (!isValidImageBuffer(screenshotBuffer)) throw new Error(`${label} buffer has invalid image format`);
|
|
76
|
+
if (minBufferSize > 0 && bufferSize < minBufferSize) throw new Error(`${label} validation failed: buffer size ${bufferSize} bytes (minimum: ${minBufferSize})`);
|
|
77
|
+
}
|
|
80
78
|
exports.imageInfoOfBase64 = __webpack_exports__.imageInfoOfBase64;
|
|
81
79
|
exports.isValidImageBuffer = __webpack_exports__.isValidImageBuffer;
|
|
82
80
|
exports.isValidJPEGImageBuffer = __webpack_exports__.isValidJPEGImageBuffer;
|
|
83
81
|
exports.isValidPNGImageBuffer = __webpack_exports__.isValidPNGImageBuffer;
|
|
82
|
+
exports.validateScreenshotBuffer = __webpack_exports__.validateScreenshotBuffer;
|
|
84
83
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
85
84
|
"imageInfoOfBase64",
|
|
86
85
|
"isValidImageBuffer",
|
|
87
86
|
"isValidJPEGImageBuffer",
|
|
88
|
-
"isValidPNGImageBuffer"
|
|
87
|
+
"isValidPNGImageBuffer",
|
|
88
|
+
"validateScreenshotBuffer"
|
|
89
89
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
90
90
|
Object.defineProperty(exports, '__esModule', {
|
|
91
91
|
value: true
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
camelToKebab: ()=>camelToKebab,
|
|
28
|
+
getKeyAliases: ()=>getKeyAliases,
|
|
29
|
+
isRecord: ()=>isRecord,
|
|
30
|
+
kebabToCamel: ()=>kebabToCamel
|
|
31
|
+
});
|
|
32
|
+
function kebabToCamel(str) {
|
|
33
|
+
return str.replace(/-([a-z])/g, (_, letter)=>letter.toUpperCase());
|
|
34
|
+
}
|
|
35
|
+
function camelToKebab(str) {
|
|
36
|
+
return str.replace(/[A-Z]/g, (letter)=>`-${letter.toLowerCase()}`).replace(/^-/, '');
|
|
37
|
+
}
|
|
38
|
+
function getKeyAliases(key) {
|
|
39
|
+
return [
|
|
40
|
+
...new Set([
|
|
41
|
+
key,
|
|
42
|
+
kebabToCamel(key),
|
|
43
|
+
camelToKebab(key)
|
|
44
|
+
])
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
function isRecord(value) {
|
|
48
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
49
|
+
}
|
|
50
|
+
exports.camelToKebab = __webpack_exports__.camelToKebab;
|
|
51
|
+
exports.getKeyAliases = __webpack_exports__.getKeyAliases;
|
|
52
|
+
exports.isRecord = __webpack_exports__.isRecord;
|
|
53
|
+
exports.kebabToCamel = __webpack_exports__.kebabToCamel;
|
|
54
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
55
|
+
"camelToKebab",
|
|
56
|
+
"getKeyAliases",
|
|
57
|
+
"isRecord",
|
|
58
|
+
"kebabToCamel"
|
|
59
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
60
|
+
Object.defineProperty(exports, '__esModule', {
|
|
61
|
+
value: true
|
|
62
|
+
});
|
|
@@ -38,12 +38,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
38
38
|
BaseMCPServer: ()=>BaseMCPServer
|
|
39
39
|
});
|
|
40
40
|
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
41
|
+
const utils_namespaceObject = require("@aiscene/shared/utils");
|
|
41
42
|
const mcp_js_namespaceObject = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
42
43
|
const stdio_js_namespaceObject = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
43
44
|
const streamableHttp_js_namespaceObject = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
44
45
|
const external_express_namespaceObject = require("express");
|
|
45
46
|
var external_express_default = /*#__PURE__*/ __webpack_require__.n(external_express_namespaceObject);
|
|
46
|
-
const
|
|
47
|
+
const external_error_formatter_js_namespaceObject = require("./error-formatter.js");
|
|
47
48
|
function _define_property(obj, key, value) {
|
|
48
49
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
49
50
|
value: value,
|
|
@@ -80,12 +81,12 @@ const CLEANUP_INTERVAL_MS = 300000;
|
|
|
80
81
|
const MAX_SESSIONS = 100;
|
|
81
82
|
class BaseMCPServer {
|
|
82
83
|
async initializeToolsManager() {
|
|
83
|
-
(0,
|
|
84
|
+
(0, utils_namespaceObject.setIsMcp)(true);
|
|
84
85
|
this.toolsManager = this.providedToolsManager || this.createToolsManager();
|
|
85
86
|
try {
|
|
86
87
|
await this.toolsManager.initTools();
|
|
87
88
|
} catch (error) {
|
|
88
|
-
const message =
|
|
89
|
+
const message = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
89
90
|
console.error(`Failed to initialize tools: ${message}`);
|
|
90
91
|
console.error('Tools will be initialized on first use');
|
|
91
92
|
}
|
|
@@ -111,7 +112,7 @@ class BaseMCPServer {
|
|
|
111
112
|
try {
|
|
112
113
|
await this.mcpServer.connect(transport);
|
|
113
114
|
} catch (error) {
|
|
114
|
-
const message =
|
|
115
|
+
const message = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
115
116
|
console.error(`Failed to connect MCP stdio transport: ${message}`);
|
|
116
117
|
throw new Error(`Failed to initialize MCP stdio transport: ${message}`);
|
|
117
118
|
}
|
|
@@ -182,7 +183,7 @@ class BaseMCPServer {
|
|
|
182
183
|
});
|
|
183
184
|
}
|
|
184
185
|
} catch (error) {
|
|
185
|
-
const message =
|
|
186
|
+
const message = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
186
187
|
const duration = Date.now() - startTime;
|
|
187
188
|
console.error(`[${new Date().toISOString()}] [${requestId}] MCP request error after ${duration}ms: ${message}`);
|
|
188
189
|
if (!res.headersSent) res.status(500).json({
|
|
@@ -210,7 +211,7 @@ class BaseMCPServer {
|
|
|
210
211
|
for (const session of sessions.values())try {
|
|
211
212
|
await session.transport.close();
|
|
212
213
|
} catch (error) {
|
|
213
|
-
const message =
|
|
214
|
+
const message = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
214
215
|
console.error(`Failed to close session ${session.transport.sessionId}: ${message}`);
|
|
215
216
|
}
|
|
216
217
|
sessions.clear();
|
|
@@ -245,7 +246,7 @@ class BaseMCPServer {
|
|
|
245
246
|
try {
|
|
246
247
|
await this.mcpServer.connect(transport);
|
|
247
248
|
} catch (error) {
|
|
248
|
-
const message =
|
|
249
|
+
const message = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
249
250
|
console.error(`[${new Date().toISOString()}] Failed to connect MCP transport: ${message}`);
|
|
250
251
|
if (transport.sessionId) sessions.delete(transport.sessionId);
|
|
251
252
|
throw new Error(`Failed to initialize MCP session: ${message}`);
|
|
@@ -264,7 +265,7 @@ class BaseMCPServer {
|
|
|
264
265
|
sessions.delete(sid);
|
|
265
266
|
console.log(`[${new Date().toISOString()}] Session ${sid} cleaned up due to inactivity (remaining: ${sessions.size})`);
|
|
266
267
|
} catch (error) {
|
|
267
|
-
const message =
|
|
268
|
+
const message = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
268
269
|
console.error(`[${new Date().toISOString()}] Failed to close session ${sid} during cleanup: ${message}`);
|
|
269
270
|
sessions.delete(sid);
|
|
270
271
|
}
|
|
@@ -277,7 +278,7 @@ class BaseMCPServer {
|
|
|
277
278
|
for (const session of sessions.values())try {
|
|
278
279
|
session.transport.close();
|
|
279
280
|
} catch (error) {
|
|
280
|
-
const message =
|
|
281
|
+
const message = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
281
282
|
console.error(`Error closing session during shutdown: ${message}`);
|
|
282
283
|
}
|
|
283
284
|
sessions.clear();
|
|
@@ -290,7 +291,7 @@ class BaseMCPServer {
|
|
|
290
291
|
this.performCleanup().finally(()=>process.exit(1));
|
|
291
292
|
}, 5000);
|
|
292
293
|
} catch (error) {
|
|
293
|
-
const message =
|
|
294
|
+
const message = (0, external_error_formatter_js_namespaceObject.getErrorMessage)(error);
|
|
294
295
|
console.error(`Error closing HTTP server: ${message}`);
|
|
295
296
|
this.performCleanup().finally(()=>process.exit(1));
|
|
296
297
|
}
|