@midscene/shared 1.0.1-beta-20251208070218.0 → 1.0.1-beta-20251208075922.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/mcp/inject-report-html-plugin.mjs +14 -3
- package/dist/lib/mcp/inject-report-html-plugin.js +14 -3
- package/dist/types/mcp/base-tools.d.ts +7 -3
- package/dist/types/mcp/types.d.ts +3 -2
- package/package.json +1 -1
- package/src/mcp/base-tools.ts +9 -3
- package/src/mcp/inject-report-html-plugin.ts +24 -3
- package/src/mcp/types.ts +3 -2
|
@@ -12,9 +12,20 @@ function injectReportHtmlFromCore(packageDir) {
|
|
|
12
12
|
if (!node_fs.existsSync(coreUtilsPath)) return void console.warn('[inject-report-html] @midscene/core dist not found, skipping');
|
|
13
13
|
const coreContent = node_fs.readFileSync(coreUtilsPath, 'utf-8');
|
|
14
14
|
if (!coreContent.includes(REPLACED_MARK)) return void console.warn('[inject-report-html] HTML not found in core dist. Ensure report builds first.');
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const markerIndex = coreContent.indexOf(REPLACED_MARK);
|
|
16
|
+
const jsonStart = markerIndex + REPLACED_MARK.length;
|
|
17
|
+
let jsonEnd = jsonStart;
|
|
18
|
+
if ('"' === coreContent[jsonStart]) {
|
|
19
|
+
jsonEnd = jsonStart + 1;
|
|
20
|
+
while(jsonEnd < coreContent.length)if ('\\' === coreContent[jsonEnd]) jsonEnd += 2;
|
|
21
|
+
else if ('"' === coreContent[jsonEnd]) {
|
|
22
|
+
jsonEnd += 1;
|
|
23
|
+
break;
|
|
24
|
+
} else jsonEnd += 1;
|
|
25
|
+
}
|
|
26
|
+
const jsonString = coreContent.slice(jsonStart, jsonEnd);
|
|
27
|
+
if (!jsonString || jsonString.length < 10) return void console.warn('[inject-report-html] Failed to extract HTML from core');
|
|
28
|
+
const finalContent = `${REPLACED_MARK}${jsonString}`;
|
|
18
29
|
const distDir = node_path.join(packageDir, 'dist');
|
|
19
30
|
if (!node_fs.existsSync(distDir)) return;
|
|
20
31
|
const jsFiles = node_fs.readdirSync(distDir).filter((f)=>f.endsWith('.js'));
|
|
@@ -51,9 +51,20 @@ function injectReportHtmlFromCore(packageDir) {
|
|
|
51
51
|
if (!external_node_fs_default().existsSync(coreUtilsPath)) return void console.warn('[inject-report-html] @midscene/core dist not found, skipping');
|
|
52
52
|
const coreContent = external_node_fs_default().readFileSync(coreUtilsPath, 'utf-8');
|
|
53
53
|
if (!coreContent.includes(REPLACED_MARK)) return void console.warn('[inject-report-html] HTML not found in core dist. Ensure report builds first.');
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const markerIndex = coreContent.indexOf(REPLACED_MARK);
|
|
55
|
+
const jsonStart = markerIndex + REPLACED_MARK.length;
|
|
56
|
+
let jsonEnd = jsonStart;
|
|
57
|
+
if ('"' === coreContent[jsonStart]) {
|
|
58
|
+
jsonEnd = jsonStart + 1;
|
|
59
|
+
while(jsonEnd < coreContent.length)if ('\\' === coreContent[jsonEnd]) jsonEnd += 2;
|
|
60
|
+
else if ('"' === coreContent[jsonEnd]) {
|
|
61
|
+
jsonEnd += 1;
|
|
62
|
+
break;
|
|
63
|
+
} else jsonEnd += 1;
|
|
64
|
+
}
|
|
65
|
+
const jsonString = coreContent.slice(jsonStart, jsonEnd);
|
|
66
|
+
if (!jsonString || jsonString.length < 10) return void console.warn('[inject-report-html] Failed to extract HTML from core');
|
|
67
|
+
const finalContent = `${REPLACED_MARK}${jsonString}`;
|
|
57
68
|
const distDir = external_node_path_default().join(packageDir, 'dist');
|
|
58
69
|
if (!external_node_fs_default().existsSync(distDir)) return;
|
|
59
70
|
const jsFiles = external_node_fs_default().readdirSync(distDir).filter((f)=>f.endsWith('.js'));
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { BaseAgent, BaseDevice, IMidsceneTools, ToolDefinition } from './types';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Base class for platform-specific MCP tools
|
|
5
|
+
* Generic type TAgent allows subclasses to use their specific agent types
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseAgent> implements IMidsceneTools {
|
|
4
8
|
protected mcpServer?: McpServer;
|
|
5
|
-
protected agent?:
|
|
9
|
+
protected agent?: TAgent;
|
|
6
10
|
protected toolDefinitions: ToolDefinition[];
|
|
7
11
|
/**
|
|
8
12
|
* Ensure agent is initialized and ready for use.
|
|
@@ -11,7 +15,7 @@ export declare abstract class BaseMidsceneTools implements IMidsceneTools {
|
|
|
11
15
|
* @returns Promise resolving to initialized agent instance
|
|
12
16
|
* @throws Error if agent initialization fails
|
|
13
17
|
*/
|
|
14
|
-
protected abstract ensureAgent(initParam?: string): Promise<
|
|
18
|
+
protected abstract ensureAgent(initParam?: string): Promise<TAgent>;
|
|
15
19
|
/**
|
|
16
20
|
* Optional: prepare platform-specific tools (e.g., device connection)
|
|
17
21
|
*/
|
|
@@ -72,6 +72,7 @@ export interface ActionSpaceItem {
|
|
|
72
72
|
/**
|
|
73
73
|
* Base agent interface
|
|
74
74
|
* Represents a platform-specific agent (Android, iOS, Web)
|
|
75
|
+
* Note: Return types use `unknown` for compatibility with platform-specific implementations
|
|
75
76
|
*/
|
|
76
77
|
export interface BaseAgent {
|
|
77
78
|
getActionSpace(): Promise<ActionSpaceItem[]>;
|
|
@@ -79,8 +80,8 @@ export interface BaseAgent {
|
|
|
79
80
|
page?: {
|
|
80
81
|
screenshotBase64(): Promise<string>;
|
|
81
82
|
};
|
|
82
|
-
aiAction?: (description: string, params?: Record<string, unknown>) => Promise<
|
|
83
|
-
aiWaitFor?: (assertion: string, options: Record<string, unknown>) => Promise<
|
|
83
|
+
aiAction?: (description: string, params?: Record<string, unknown>) => Promise<unknown>;
|
|
84
|
+
aiWaitFor?: (assertion: string, options: Record<string, unknown>) => Promise<unknown>;
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
87
|
* Base device interface for temporary device instances
|
package/package.json
CHANGED
package/src/mcp/base-tools.ts
CHANGED
|
@@ -15,9 +15,15 @@ import type {
|
|
|
15
15
|
|
|
16
16
|
const debug = getDebug('mcp:base-tools');
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Base class for platform-specific MCP tools
|
|
20
|
+
* Generic type TAgent allows subclasses to use their specific agent types
|
|
21
|
+
*/
|
|
22
|
+
export abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseAgent>
|
|
23
|
+
implements IMidsceneTools
|
|
24
|
+
{
|
|
19
25
|
protected mcpServer?: McpServer;
|
|
20
|
-
protected agent?:
|
|
26
|
+
protected agent?: TAgent;
|
|
21
27
|
protected toolDefinitions: ToolDefinition[] = [];
|
|
22
28
|
|
|
23
29
|
/**
|
|
@@ -27,7 +33,7 @@ export abstract class BaseMidsceneTools implements IMidsceneTools {
|
|
|
27
33
|
* @returns Promise resolving to initialized agent instance
|
|
28
34
|
* @throws Error if agent initialization fails
|
|
29
35
|
*/
|
|
30
|
-
protected abstract ensureAgent(initParam?: string): Promise<
|
|
36
|
+
protected abstract ensureAgent(initParam?: string): Promise<TAgent>;
|
|
31
37
|
|
|
32
38
|
/**
|
|
33
39
|
* Optional: prepare platform-specific tools (e.g., device connection)
|
|
@@ -48,13 +48,34 @@ export function injectReportHtmlFromCore(packageDir: string) {
|
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// Extract the JSON string after the marker
|
|
52
|
+
// JSON strings can contain escaped quotes, so we need to properly parse it
|
|
53
|
+
const markerIndex = coreContent.indexOf(REPLACED_MARK);
|
|
54
|
+
const jsonStart = markerIndex + REPLACED_MARK.length;
|
|
55
|
+
|
|
56
|
+
// Find the end of the JSON string by tracking quote escaping
|
|
57
|
+
let jsonEnd = jsonStart;
|
|
58
|
+
if (coreContent[jsonStart] === '"') {
|
|
59
|
+
jsonEnd = jsonStart + 1;
|
|
60
|
+
while (jsonEnd < coreContent.length) {
|
|
61
|
+
if (coreContent[jsonEnd] === '\\') {
|
|
62
|
+
jsonEnd += 2; // Skip escaped character
|
|
63
|
+
} else if (coreContent[jsonEnd] === '"') {
|
|
64
|
+
jsonEnd += 1; // Include closing quote
|
|
65
|
+
break;
|
|
66
|
+
} else {
|
|
67
|
+
jsonEnd += 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const jsonString = coreContent.slice(jsonStart, jsonEnd);
|
|
73
|
+
if (!jsonString || jsonString.length < 10) {
|
|
53
74
|
console.warn('[inject-report-html] Failed to extract HTML from core');
|
|
54
75
|
return;
|
|
55
76
|
}
|
|
56
77
|
|
|
57
|
-
const finalContent = `${REPLACED_MARK}${
|
|
78
|
+
const finalContent = `${REPLACED_MARK}${jsonString}`;
|
|
58
79
|
const distDir = path.join(packageDir, 'dist');
|
|
59
80
|
|
|
60
81
|
if (!fs.existsSync(distDir)) return;
|
package/src/mcp/types.ts
CHANGED
|
@@ -72,6 +72,7 @@ export interface ActionSpaceItem {
|
|
|
72
72
|
/**
|
|
73
73
|
* Base agent interface
|
|
74
74
|
* Represents a platform-specific agent (Android, iOS, Web)
|
|
75
|
+
* Note: Return types use `unknown` for compatibility with platform-specific implementations
|
|
75
76
|
*/
|
|
76
77
|
export interface BaseAgent {
|
|
77
78
|
getActionSpace(): Promise<ActionSpaceItem[]>;
|
|
@@ -82,11 +83,11 @@ export interface BaseAgent {
|
|
|
82
83
|
aiAction?: (
|
|
83
84
|
description: string,
|
|
84
85
|
params?: Record<string, unknown>,
|
|
85
|
-
) => Promise<
|
|
86
|
+
) => Promise<unknown>;
|
|
86
87
|
aiWaitFor?: (
|
|
87
88
|
assertion: string,
|
|
88
89
|
options: Record<string, unknown>,
|
|
89
|
-
) => Promise<
|
|
90
|
+
) => Promise<unknown>;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
/**
|