@midscene/shared 1.0.1-beta-20251208071759.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.
@@ -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
- export declare abstract class BaseMidsceneTools implements IMidsceneTools {
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?: BaseAgent;
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<BaseAgent>;
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<void>;
83
- aiWaitFor?: (assertion: string, options: Record<string, unknown>) => Promise<void>;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.0.1-beta-20251208071759.0",
3
+ "version": "1.0.1-beta-20251208075922.0",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -15,9 +15,15 @@ import type {
15
15
 
16
16
  const debug = getDebug('mcp:base-tools');
17
17
 
18
- export abstract class BaseMidsceneTools implements IMidsceneTools {
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?: BaseAgent;
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<BaseAgent>;
36
+ protected abstract ensureAgent(initParam?: string): Promise<TAgent>;
31
37
 
32
38
  /**
33
39
  * Optional: prepare platform-specific tools (e.g., device connection)
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<void>;
86
+ ) => Promise<unknown>;
86
87
  aiWaitFor?: (
87
88
  assertion: string,
88
89
  options: Record<string, unknown>,
89
- ) => Promise<void>;
90
+ ) => Promise<unknown>;
90
91
  }
91
92
 
92
93
  /**