@godscene/shared 1.7.11
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/README.md +9 -0
- package/dist/es/baseDB.mjs +109 -0
- 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 +122 -0
- package/dist/es/cli/index.mjs +4 -0
- package/dist/es/common.mjs +37 -0
- package/dist/es/constants/example-code.mjs +227 -0
- package/dist/es/constants/index.mjs +124 -0
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/constants.mjs +110 -0
- package/dist/es/env/global-config-manager.mjs +94 -0
- package/dist/es/env/helper.mjs +43 -0
- package/dist/es/env/index.mjs +5 -0
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config-manager.mjs +79 -0
- package/dist/es/env/parse-model-config.mjs +165 -0
- package/dist/es/env/types.mjs +232 -0
- package/dist/es/env/utils.mjs +18 -0
- package/dist/es/extractor/constants.mjs +2 -0
- package/dist/es/extractor/cs_postmessage.mjs +61 -0
- package/dist/es/extractor/customLocator.mjs +641 -0
- package/dist/es/extractor/debug.mjs +6 -0
- package/dist/es/extractor/dom-util.mjs +96 -0
- package/dist/es/extractor/index.mjs +5 -0
- package/dist/es/extractor/locator.mjs +250 -0
- package/dist/es/extractor/tree.mjs +78 -0
- package/dist/es/extractor/util.mjs +245 -0
- package/dist/es/extractor/web-extractor.mjs +393 -0
- package/dist/es/img/box-select.mjs +824 -0
- package/dist/es/img/canvas-fallback.mjs +238 -0
- package/dist/es/img/get-photon.mjs +45 -0
- package/dist/es/img/get-sharp.mjs +11 -0
- package/dist/es/img/index.mjs +4 -0
- package/dist/es/img/info.mjs +35 -0
- package/dist/es/img/transform.mjs +275 -0
- package/dist/es/index.mjs +2 -0
- package/dist/es/key-alias-utils.mjs +19 -0
- package/dist/es/logger.mjs +64 -0
- package/dist/es/mcp/base-server.mjs +282 -0
- package/dist/es/mcp/base-tools.mjs +159 -0
- package/dist/es/mcp/chrome-path.mjs +35 -0
- 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 +9 -0
- package/dist/es/mcp/init-arg-utils.mjs +38 -0
- package/dist/es/mcp/inject-report-html-plugin.mjs +53 -0
- package/dist/es/mcp/launcher-helper.mjs +52 -0
- package/dist/es/mcp/tool-generator.mjs +419 -0
- package/dist/es/mcp/types.mjs +3 -0
- package/dist/es/node/fs.mjs +44 -0
- package/dist/es/node/index.mjs +2 -0
- package/dist/es/node/port.mjs +24 -0
- package/dist/es/polyfills/async-hooks.mjs +2 -0
- package/dist/es/polyfills/index.mjs +1 -0
- package/dist/es/types/index.mjs +3 -0
- package/dist/es/us-keyboard-layout.mjs +1414 -0
- package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
- package/dist/es/utils.mjs +72 -0
- package/dist/es/zod-schema-utils.mjs +54 -0
- package/dist/lib/baseDB.js +149 -0
- 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 +181 -0
- package/dist/lib/cli/index.js +53 -0
- package/dist/lib/common.js +93 -0
- package/dist/lib/constants/example-code.js +264 -0
- package/dist/lib/constants/index.js +221 -0
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/constants.js +153 -0
- package/dist/lib/env/global-config-manager.js +128 -0
- package/dist/lib/env/helper.js +80 -0
- package/dist/lib/env/index.js +90 -0
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config-manager.js +113 -0
- package/dist/lib/env/parse-model-config.js +211 -0
- package/dist/lib/env/types.js +572 -0
- package/dist/lib/env/utils.js +61 -0
- package/dist/lib/extractor/constants.js +42 -0
- package/dist/lib/extractor/cs_postmessage.js +98 -0
- package/dist/lib/extractor/customLocator.js +693 -0
- package/dist/lib/extractor/debug.js +12 -0
- package/dist/lib/extractor/dom-util.js +157 -0
- package/dist/lib/extractor/index.js +87 -0
- package/dist/lib/extractor/locator.js +296 -0
- package/dist/lib/extractor/tree.js +124 -0
- package/dist/lib/extractor/util.js +336 -0
- package/dist/lib/extractor/web-extractor.js +442 -0
- package/dist/lib/img/box-select.js +875 -0
- package/dist/lib/img/canvas-fallback.js +305 -0
- package/dist/lib/img/get-photon.js +82 -0
- package/dist/lib/img/get-sharp.js +45 -0
- package/dist/lib/img/index.js +95 -0
- package/dist/lib/img/info.js +92 -0
- package/dist/lib/img/transform.js +364 -0
- package/dist/lib/index.js +36 -0
- package/dist/lib/key-alias-utils.js +62 -0
- package/dist/lib/logger.js +114 -0
- package/dist/lib/mcp/base-server.js +332 -0
- package/dist/lib/mcp/base-tools.js +193 -0
- package/dist/lib/mcp/chrome-path.js +72 -0
- 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 +114 -0
- package/dist/lib/mcp/init-arg-utils.js +78 -0
- package/dist/lib/mcp/inject-report-html-plugin.js +98 -0
- package/dist/lib/mcp/launcher-helper.js +86 -0
- package/dist/lib/mcp/tool-generator.js +456 -0
- package/dist/lib/mcp/types.js +40 -0
- package/dist/lib/node/fs.js +97 -0
- package/dist/lib/node/index.js +65 -0
- package/dist/lib/node/port.js +61 -0
- package/dist/lib/polyfills/async-hooks.js +36 -0
- package/dist/lib/polyfills/index.js +58 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/us-keyboard-layout.js +1457 -0
- package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
- package/dist/lib/utils.js +148 -0
- package/dist/lib/zod-schema-utils.js +97 -0
- package/dist/types/baseDB.d.ts +25 -0
- 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 +19 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/constants/example-code.d.ts +2 -0
- package/dist/types/constants/index.d.ts +61 -0
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/constants.d.ts +50 -0
- package/dist/types/env/global-config-manager.d.ts +32 -0
- package/dist/types/env/helper.d.ts +4 -0
- package/dist/types/env/index.d.ts +4 -0
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config-manager.d.ts +25 -0
- package/dist/types/env/parse-model-config.d.ts +31 -0
- package/dist/types/env/types.d.ts +339 -0
- package/dist/types/env/utils.d.ts +7 -0
- package/dist/types/extractor/constants.d.ts +1 -0
- package/dist/types/extractor/cs_postmessage.d.ts +2 -0
- package/dist/types/extractor/customLocator.d.ts +69 -0
- package/dist/types/extractor/debug.d.ts +1 -0
- package/dist/types/extractor/dom-util.d.ts +57 -0
- package/dist/types/extractor/index.d.ts +33 -0
- package/dist/types/extractor/locator.d.ts +9 -0
- package/dist/types/extractor/tree.d.ts +6 -0
- package/dist/types/extractor/util.d.ts +47 -0
- package/dist/types/extractor/web-extractor.d.ts +24 -0
- package/dist/types/img/box-select.d.ts +26 -0
- package/dist/types/img/canvas-fallback.d.ts +105 -0
- package/dist/types/img/get-photon.d.ts +19 -0
- package/dist/types/img/get-sharp.d.ts +3 -0
- package/dist/types/img/index.d.ts +3 -0
- package/dist/types/img/info.d.ts +34 -0
- package/dist/types/img/transform.d.ts +98 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/key-alias-utils.d.ts +9 -0
- package/dist/types/logger.d.ts +5 -0
- package/dist/types/mcp/base-server.d.ts +93 -0
- package/dist/types/mcp/base-tools.d.ts +148 -0
- package/dist/types/mcp/chrome-path.d.ts +2 -0
- 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 +9 -0
- package/dist/types/mcp/init-arg-utils.d.ts +13 -0
- package/dist/types/mcp/inject-report-html-plugin.d.ts +18 -0
- package/dist/types/mcp/launcher-helper.d.ts +94 -0
- package/dist/types/mcp/tool-generator.d.ts +10 -0
- package/dist/types/mcp/types.d.ts +113 -0
- package/dist/types/node/fs.d.ts +15 -0
- package/dist/types/node/index.d.ts +2 -0
- package/dist/types/node/port.d.ts +8 -0
- package/dist/types/polyfills/async-hooks.d.ts +6 -0
- package/dist/types/polyfills/index.d.ts +4 -0
- package/dist/types/types/index.d.ts +36 -0
- package/dist/types/us-keyboard-layout.d.ts +32 -0
- package/dist/types/utils.d.ts +34 -0
- package/dist/types/zod-schema-utils.d.ts +23 -0
- package/package.json +125 -0
- package/src/baseDB.ts +158 -0
- package/src/cli/cli-args.ts +173 -0
- package/src/cli/cli-error.ts +24 -0
- package/src/cli/cli-runner.ts +230 -0
- package/src/cli/index.ts +4 -0
- package/src/common.ts +67 -0
- package/src/constants/example-code.ts +227 -0
- package/src/constants/index.ts +139 -0
- package/src/env/basic.ts +12 -0
- package/src/env/constants.ts +303 -0
- package/src/env/global-config-manager.ts +191 -0
- package/src/env/helper.ts +58 -0
- package/src/env/index.ts +4 -0
- package/src/env/init-debug.ts +34 -0
- package/src/env/model-config-manager.ts +149 -0
- package/src/env/parse-model-config.ts +357 -0
- package/src/env/types.ts +583 -0
- package/src/env/utils.ts +39 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/cs_postmessage.ts +136 -0
- package/src/extractor/customLocator.ts +1245 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +231 -0
- package/src/extractor/index.ts +50 -0
- package/src/extractor/locator.ts +469 -0
- package/src/extractor/tree.ts +179 -0
- package/src/extractor/util.ts +482 -0
- package/src/extractor/web-extractor.ts +617 -0
- package/src/img/box-select.ts +588 -0
- package/src/img/canvas-fallback.ts +393 -0
- package/src/img/get-photon.ts +108 -0
- package/src/img/get-sharp.ts +18 -0
- package/src/img/index.ts +27 -0
- package/src/img/info.ts +102 -0
- package/src/img/transform.ts +553 -0
- package/src/index.ts +1 -0
- package/src/key-alias-utils.ts +23 -0
- package/src/logger.ts +96 -0
- package/src/mcp/base-server.ts +500 -0
- package/src/mcp/base-tools.ts +391 -0
- package/src/mcp/chrome-path.ts +48 -0
- package/src/mcp/cli-report-session.ts +130 -0
- package/src/mcp/error-formatter.ts +52 -0
- package/src/mcp/index.ts +9 -0
- package/src/mcp/init-arg-utils.ts +105 -0
- package/src/mcp/inject-report-html-plugin.ts +119 -0
- package/src/mcp/launcher-helper.ts +200 -0
- package/src/mcp/tool-generator.ts +658 -0
- package/src/mcp/types.ts +131 -0
- package/src/node/fs.ts +84 -0
- package/src/node/index.ts +2 -0
- package/src/node/port.ts +37 -0
- package/src/polyfills/async-hooks.ts +6 -0
- package/src/polyfills/index.ts +4 -0
- package/src/types/index.ts +54 -0
- package/src/us-keyboard-layout.ts +723 -0
- package/src/utils.ts +149 -0
- package/src/zod-schema-utils.ts +133 -0
package/src/mcp/types.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
// Avoid circular dependency: don't import from @godscene/core
|
|
5
|
+
// Instead, use generic types that will be provided by implementation
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Default timeout constants for app loading verification
|
|
9
|
+
*/
|
|
10
|
+
export const defaultAppLoadingTimeoutMs = 10000;
|
|
11
|
+
export const defaultAppLoadingCheckIntervalMs = 2000;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Content item types for tool results (MCP compatible)
|
|
15
|
+
*/
|
|
16
|
+
export type ToolResultContent =
|
|
17
|
+
| { type: 'text'; text: string }
|
|
18
|
+
| { type: 'image'; data: string; mimeType: string }
|
|
19
|
+
| { type: 'audio'; data: string; mimeType: string }
|
|
20
|
+
| {
|
|
21
|
+
type: 'resource';
|
|
22
|
+
resource:
|
|
23
|
+
| { text: string; uri: string; mimeType?: string }
|
|
24
|
+
| { uri: string; blob: string; mimeType?: string };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Result type for tool execution (MCP compatible)
|
|
29
|
+
*/
|
|
30
|
+
export interface ToolResult {
|
|
31
|
+
[x: string]: unknown;
|
|
32
|
+
content: ToolResultContent[];
|
|
33
|
+
isError?: boolean;
|
|
34
|
+
_meta?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Tool handler function type
|
|
39
|
+
* Takes parsed arguments and returns a tool result
|
|
40
|
+
*/
|
|
41
|
+
export type ToolHandler<T = Record<string, unknown>> = (
|
|
42
|
+
args: T,
|
|
43
|
+
) => Promise<ToolResult>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Tool schema type using Zod
|
|
47
|
+
*/
|
|
48
|
+
export type ToolSchema = Record<string, z.ZodTypeAny>;
|
|
49
|
+
|
|
50
|
+
export interface ToolCliOption {
|
|
51
|
+
preferredName?: string;
|
|
52
|
+
aliases?: string[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ToolCliMetadata {
|
|
56
|
+
options?: Record<string, ToolCliOption>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Tool definition for MCP server
|
|
61
|
+
*/
|
|
62
|
+
export interface ToolDefinition<T = Record<string, unknown>> {
|
|
63
|
+
name: string;
|
|
64
|
+
description: string;
|
|
65
|
+
schema: ToolSchema;
|
|
66
|
+
handler: ToolHandler<T>;
|
|
67
|
+
cli?: ToolCliMetadata;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Tool type for mcpKitForAgent return value
|
|
72
|
+
*/
|
|
73
|
+
export type Tool = ToolDefinition;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Action space item definition
|
|
77
|
+
* Note: Intentionally no index signature to maintain compatibility with DeviceAction
|
|
78
|
+
*/
|
|
79
|
+
export interface ActionSpaceItem {
|
|
80
|
+
name: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
args?: Record<string, unknown>;
|
|
83
|
+
paramSchema?: z.ZodTypeAny;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Base agent interface
|
|
88
|
+
* Represents a platform-specific agent (Android, iOS, Web)
|
|
89
|
+
* Note: Return types use `unknown` for compatibility with platform-specific implementations
|
|
90
|
+
*/
|
|
91
|
+
export interface BaseAgent {
|
|
92
|
+
getActionSpace(): Promise<ActionSpaceItem[]>;
|
|
93
|
+
destroy?(): Promise<void>;
|
|
94
|
+
page?: {
|
|
95
|
+
screenshotBase64(): Promise<string>;
|
|
96
|
+
};
|
|
97
|
+
callActionInActionSpace?: (
|
|
98
|
+
actionName: string,
|
|
99
|
+
params?: unknown,
|
|
100
|
+
) => Promise<unknown>;
|
|
101
|
+
aiAction?: (
|
|
102
|
+
description: string,
|
|
103
|
+
params?: Record<string, unknown>,
|
|
104
|
+
) => Promise<unknown>;
|
|
105
|
+
aiWaitFor?: (
|
|
106
|
+
assertion: string,
|
|
107
|
+
options: Record<string, unknown>,
|
|
108
|
+
) => Promise<unknown>;
|
|
109
|
+
aiAssert?: (
|
|
110
|
+
assertion: string,
|
|
111
|
+
msg?: string,
|
|
112
|
+
options?: Record<string, unknown>,
|
|
113
|
+
) => Promise<unknown>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Base device interface for temporary device instances
|
|
118
|
+
*/
|
|
119
|
+
export interface BaseDevice {
|
|
120
|
+
actionSpace(): ActionSpaceItem[];
|
|
121
|
+
destroy?(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Interface for platform-specific MCP tools manager
|
|
126
|
+
*/
|
|
127
|
+
export interface IMidsceneTools {
|
|
128
|
+
attachToServer(server: McpServer): void;
|
|
129
|
+
initTools(): Promise<void>;
|
|
130
|
+
destroy?(): Promise<void>;
|
|
131
|
+
}
|
package/src/node/fs.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { ifInBrowser, ifInWorker } from '../utils';
|
|
4
|
+
|
|
5
|
+
declare const __HTML_ELEMENT_SCRIPT__: string;
|
|
6
|
+
|
|
7
|
+
interface PkgInfo {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
dir: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const pkgCacheMap: Record<string, PkgInfo> = {};
|
|
14
|
+
|
|
15
|
+
export function getRunningPkgInfo(dir?: string): PkgInfo | null {
|
|
16
|
+
if (ifInBrowser || ifInWorker) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const dirToCheck = dir || process.cwd();
|
|
20
|
+
if (pkgCacheMap[dirToCheck]) {
|
|
21
|
+
return pkgCacheMap[dirToCheck];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const pkgDir = findNearestPackageJson(dirToCheck);
|
|
25
|
+
const pkgJsonFile = pkgDir ? join(pkgDir, 'package.json') : null;
|
|
26
|
+
|
|
27
|
+
if (pkgDir && pkgJsonFile) {
|
|
28
|
+
const { name, version } = JSON.parse(readFileSync(pkgJsonFile, 'utf-8'));
|
|
29
|
+
pkgCacheMap[dirToCheck] = {
|
|
30
|
+
name: name || 'midscene-unknown-package-name',
|
|
31
|
+
version: version || '0.0.0',
|
|
32
|
+
dir: pkgDir,
|
|
33
|
+
};
|
|
34
|
+
return pkgCacheMap[dirToCheck];
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
name: 'midscene-unknown-package-name',
|
|
38
|
+
version: '0.0.0',
|
|
39
|
+
dir: dirToCheck,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Find the nearest package.json file recursively
|
|
45
|
+
* @param {string} dir - Home directory
|
|
46
|
+
* @returns {string|null} - The most recent package.json file path or null
|
|
47
|
+
*/
|
|
48
|
+
export function findNearestPackageJson(dir: string): string | null {
|
|
49
|
+
const packageJsonPath = join(dir, 'package.json');
|
|
50
|
+
if (existsSync(packageJsonPath)) {
|
|
51
|
+
return dir;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const parentDir = dirname(dir);
|
|
55
|
+
|
|
56
|
+
// Return null if the root directory has been reached
|
|
57
|
+
if (parentDir === dir) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return findNearestPackageJson(parentDir);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function getElementInfosScriptContent() {
|
|
65
|
+
const htmlElementScript = __HTML_ELEMENT_SCRIPT__;
|
|
66
|
+
|
|
67
|
+
if (!htmlElementScript) {
|
|
68
|
+
throw new Error('HTML_ELEMENT_SCRIPT inject failed.');
|
|
69
|
+
}
|
|
70
|
+
return htmlElementScript;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function getExtraReturnLogic(tree = false) {
|
|
74
|
+
if (ifInBrowser || ifInWorker) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const elementInfosScriptContent = `${getElementInfosScriptContent()};`;
|
|
79
|
+
|
|
80
|
+
if (tree) {
|
|
81
|
+
return `${elementInfosScriptContent}midscene_element_inspector.webExtractNodeTree()`;
|
|
82
|
+
}
|
|
83
|
+
return `${elementInfosScriptContent}midscene_element_inspector.webExtractTextWithPosition()`;
|
|
84
|
+
}
|
package/src/node/port.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createServer } from 'node:net';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if a port is available
|
|
5
|
+
*/
|
|
6
|
+
export async function isPortAvailable(port: number): Promise<boolean> {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const server = createServer();
|
|
9
|
+
server.on('error', () => resolve(false));
|
|
10
|
+
server.listen(port, () => {
|
|
11
|
+
server.close(() => resolve(true));
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Find an available port starting from the given port
|
|
18
|
+
*/
|
|
19
|
+
export async function findAvailablePort(
|
|
20
|
+
startPort: number,
|
|
21
|
+
maxAttempts = 15,
|
|
22
|
+
): Promise<number> {
|
|
23
|
+
let port = startPort;
|
|
24
|
+
let attempts = 0;
|
|
25
|
+
|
|
26
|
+
while (!(await isPortAvailable(port))) {
|
|
27
|
+
attempts++;
|
|
28
|
+
if (attempts >= maxAttempts) {
|
|
29
|
+
console.error(
|
|
30
|
+
`❌ Unable to find available port after ${maxAttempts} attempts starting from ${startPort}`,
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
port++;
|
|
35
|
+
}
|
|
36
|
+
return port;
|
|
37
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { NodeType } from '../constants';
|
|
2
|
+
import type { ElementInfo } from '../extractor';
|
|
3
|
+
|
|
4
|
+
export interface Point {
|
|
5
|
+
left: number;
|
|
6
|
+
top: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Size {
|
|
10
|
+
width: number; // The image sent to AI model will be resized to this width, also the coordinates in the action space will be scaled to the range [0, width]. Usually you should set it to the logical pixel size
|
|
11
|
+
height: number; // The image sent to AI model will be resized to this height, also the coordinates in the action space will be scaled to the range [0, height]. Usually you should set it to the logical pixel size
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type Rect = Point & Size;
|
|
15
|
+
|
|
16
|
+
export abstract class BaseElement {
|
|
17
|
+
abstract id: string;
|
|
18
|
+
|
|
19
|
+
// abstract indexId?: number; // markerId for web
|
|
20
|
+
|
|
21
|
+
abstract attributes: {
|
|
22
|
+
nodeType: NodeType;
|
|
23
|
+
[key: string]: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
abstract content: string;
|
|
27
|
+
|
|
28
|
+
abstract rect: Rect;
|
|
29
|
+
|
|
30
|
+
abstract center: [number, number];
|
|
31
|
+
|
|
32
|
+
// abstract xpaths?: string[];
|
|
33
|
+
|
|
34
|
+
abstract isVisible: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ElementTreeNode<
|
|
38
|
+
ElementType extends BaseElement = BaseElement,
|
|
39
|
+
> {
|
|
40
|
+
node: ElementType | null;
|
|
41
|
+
children: ElementTreeNode<ElementType>[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface WebElementInfo extends ElementInfo {
|
|
45
|
+
zoom: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type LocateResultElement = {
|
|
49
|
+
description: string; // the description of the element
|
|
50
|
+
center: [number, number];
|
|
51
|
+
rect: Rect;
|
|
52
|
+
allPaths?: any[],
|
|
53
|
+
containerPaths?: any[]
|
|
54
|
+
};
|