ms-vite-plugin 1.1.19 → 1.1.21

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.
@@ -34,20 +34,16 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.registerRuntimeTools = registerRuntimeTools;
37
- const z = __importStar(require("zod/v4"));
38
37
  const fsExtra = __importStar(require("fs-extra"));
39
38
  const os = __importStar(require("os"));
40
39
  const path = __importStar(require("path"));
40
+ const z = __importStar(require("zod/v4"));
41
41
  const packager_1 = require("../packager");
42
42
  const project_1 = require("../project");
43
- const project_2 = require("./project");
44
43
  const device_config_1 = require("./device-config");
45
44
  const device_log_1 = require("./device-log");
45
+ const project_2 = require("./project");
46
46
  const tool_utils_1 = require("./tool-utils");
47
- const control_tools_1 = require("./control-tools");
48
- const hid_tools_1 = require("./hid-tools");
49
- const ime_tools_1 = require("./ime-tools");
50
- const mirror_tools_1 = require("./mirror-tools");
51
47
  /**
52
48
  * 注册设备与项目执行工具
53
49
  * @param server MCP 服务实例
@@ -148,83 +144,6 @@ function registerRuntimeTools(server) {
148
144
  }
149
145
  return (0, tool_utils_1.createTextToolResult)(`当前默认设备: ${config.ip}:${config.port}`);
150
146
  });
151
- server.registerTool("get_active_app_info", {
152
- title: "Get Active App Info",
153
- description: "获取当前激活应用信息。",
154
- inputSchema: {},
155
- }, async () => {
156
- const target = await (0, tool_utils_1.resolveRuntimeHttpTarget)();
157
- const payload = await (0, tool_utils_1.requestRuntimeJsonApi)(target, "activeAppInfo");
158
- return (0, tool_utils_1.createTextToolResult)(`当前激活应用信息:\n${(0, tool_utils_1.formatRuntimeJsonText)((0, tool_utils_1.unwrapRuntimeData)(payload, "activeAppInfo"))}`);
159
- });
160
- server.registerTool("take_me_to_front", {
161
- title: "Take Me To Front",
162
- description: "将当前应用切到前台。",
163
- inputSchema: {},
164
- }, async () => {
165
- const target = await (0, tool_utils_1.resolveRuntimeHttpTarget)();
166
- const payload = await (0, tool_utils_1.requestRuntimeJsonApi)(target, "takeMeToFront");
167
- return (0, tool_utils_1.createTextToolResult)(payload.success === true
168
- ? `切到前台成功: ${target.label}`
169
- : `切到前台失败: ${target.label}`, payload.success !== true);
170
- });
171
- server.registerTool("get_all_config", {
172
- title: "Get All Config",
173
- description: "获取当前设备全部配置参数。",
174
- inputSchema: {},
175
- }, async () => {
176
- const target = await (0, tool_utils_1.resolveRuntimeHttpTarget)();
177
- const payload = await (0, tool_utils_1.requestRuntimeJsonApi)(target, "getAllConfig");
178
- return (0, tool_utils_1.createTextToolResult)(`当前配置:\n${(0, tool_utils_1.formatRuntimeJsonText)((0, tool_utils_1.unwrapRuntimeData)(payload, "getAllConfig"))}`);
179
- });
180
- server.registerTool("set_all_config", {
181
- title: "Set All Config",
182
- description: "批量设置当前设备全部配置参数。",
183
- inputSchema: {
184
- config: z
185
- .record(z.string(), z.unknown())
186
- .describe("完整配置对象,会直接提交到 setAllConfig"),
187
- },
188
- }, async ({ config }) => {
189
- const target = await (0, tool_utils_1.resolveRuntimeHttpTarget)();
190
- const payload = await (0, tool_utils_1.requestRuntimeJsonApi)(target, "setAllConfig", "POST", config);
191
- return (0, tool_utils_1.createTextToolResult)(payload.success === true
192
- ? `批量设置配置成功: ${target.label}`
193
- : `批量设置配置失败: ${target.label}`, payload.success !== true);
194
- });
195
- server.registerTool("set_config", {
196
- title: "Set Config",
197
- description: "设置单个配置参数。",
198
- inputSchema: {
199
- key: z.string().min(1).describe("配置键名"),
200
- value: z.unknown().describe("配置值,支持任意 JSON 兼容类型"),
201
- },
202
- }, async ({ key, value }) => {
203
- const target = await (0, tool_utils_1.resolveRuntimeHttpTarget)();
204
- const payload = await (0, tool_utils_1.requestRuntimeJsonApi)(target, "setConfig", "POST", {
205
- key,
206
- value,
207
- });
208
- return (0, tool_utils_1.createTextToolResult)(payload.success === true
209
- ? `配置设置成功: ${key}`
210
- : `配置设置失败: ${key}`, payload.success !== true);
211
- });
212
- server.registerTool("run_script", {
213
- title: "Run Script",
214
- description: "在当前设备上执行一段 JavaScript 并返回结果。",
215
- inputSchema: {
216
- script: z.string().min(1).describe("要执行的 JavaScript 代码"),
217
- },
218
- }, async ({ script }) => {
219
- const target = await (0, tool_utils_1.resolveRuntimeHttpTarget)();
220
- const payload = await (0, tool_utils_1.requestRuntimeJsonApi)(target, "runScript", "POST", {
221
- script,
222
- });
223
- const success = payload.success === true;
224
- return (0, tool_utils_1.createTextToolResult)(success
225
- ? `脚本执行成功:\n${(0, tool_utils_1.formatRuntimeJsonText)(payload)}`
226
- : `脚本执行失败:\n${(0, tool_utils_1.formatRuntimeJsonText)(payload)}`, !success);
227
- });
228
147
  server.registerTool("take_screenshot", {
229
148
  title: "Take Screenshot",
230
149
  description: "获取当前默认设备截图。可返回 base64,或落地到文件后返回文件路径(默认写入系统临时目录)。",
@@ -384,8 +303,4 @@ function registerRuntimeTools(server) {
384
303
  await (0, project_1.stopOnDevice)((0, tool_utils_1.createRuntimeHttpRequestOptions)(target));
385
304
  return (0, tool_utils_1.createTextToolResult)(`停止请求已发送到 ${target.label}`);
386
305
  });
387
- (0, control_tools_1.registerControlTools)(server);
388
- (0, hid_tools_1.registerHidTools)(server);
389
- (0, ime_tools_1.registerImeTools)(server);
390
- (0, mirror_tools_1.registerMirrorTools)(server);
391
306
  }
@@ -53,36 +53,6 @@ export declare function createRuntimeHttpRequestOptions(target: RuntimeHttpTarge
53
53
  * const target = await resolveRuntimeHttpTarget()
54
54
  */
55
55
  export declare function resolveRuntimeHttpTarget(): Promise<RuntimeHttpTarget>;
56
- /**
57
- * 请求设备通用 JSON API
58
- * @param target 当前默认设备目标
59
- * @param endpoint API 路径(不含前导 `/api/`)
60
- * @param method 请求方法
61
- * @param body 可选 JSON 请求体
62
- * @returns 返回解析后的 JSON 数据
63
- * @example
64
- * const payload = await requestRuntimeJsonApi(target, "activeAppInfo")
65
- */
66
- export declare function requestRuntimeJsonApi(target: RuntimeHttpTarget, endpoint: string, method?: "GET" | "POST", body?: Record<string, unknown>): Promise<Record<string, unknown>>;
67
- /**
68
- * 请求任意相对路径 JSON API,并可附带 query 参数
69
- * @param target 当前默认设备目标
70
- * @param routePath 相对路径,例如 `/api/control/click`
71
- * @param query 可选查询参数
72
- * @returns 返回解析后的 JSON 数据
73
- * @example
74
- * const payload = await requestRuntimePathJson(target, "/api/ime/getText")
75
- */
76
- export declare function requestRuntimePathJson(target: RuntimeHttpTarget, routePath: string, query?: Record<string, RuntimeQueryValue>): Promise<Record<string, unknown>>;
77
- /**
78
- * 从通用 JSON 响应中读取 `data` 字段
79
- * @param payload API 返回 JSON
80
- * @param endpoint API 路径名,用于错误提示
81
- * @returns 返回 `data` 字段内容
82
- * @example
83
- * const data = unwrapRuntimeData(payload, "getAllConfig")
84
- */
85
- export declare function unwrapRuntimeData(payload: Record<string, unknown>, endpoint: string): unknown;
86
56
  /**
87
57
  * 将任意 JSON 兼容值格式化为文本
88
58
  * @param value 任意待展示值
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTextToolResult = createTextToolResult;
4
4
  exports.createRuntimeHttpRequestOptions = createRuntimeHttpRequestOptions;
5
5
  exports.resolveRuntimeHttpTarget = resolveRuntimeHttpTarget;
6
- exports.requestRuntimeJsonApi = requestRuntimeJsonApi;
7
- exports.requestRuntimePathJson = requestRuntimePathJson;
8
- exports.unwrapRuntimeData = unwrapRuntimeData;
9
6
  exports.formatRuntimeJsonText = formatRuntimeJsonText;
10
7
  exports.formatApiDocSummary = formatApiDocSummary;
11
8
  const docs_service_1 = require("./docs-service");
@@ -71,77 +68,6 @@ async function resolveRuntimeHttpTarget() {
71
68
  label: `${device.ip}:${device.port}`,
72
69
  };
73
70
  }
74
- /**
75
- * 请求设备通用 JSON API
76
- * @param target 当前默认设备目标
77
- * @param endpoint API 路径(不含前导 `/api/`)
78
- * @param method 请求方法
79
- * @param body 可选 JSON 请求体
80
- * @returns 返回解析后的 JSON 数据
81
- * @example
82
- * const payload = await requestRuntimeJsonApi(target, "activeAppInfo")
83
- */
84
- async function requestRuntimeJsonApi(target, endpoint, method = "GET", body) {
85
- const url = `http://${target.ip}:${target.port}/api/${endpoint}`;
86
- const response = await fetch(url, {
87
- method,
88
- headers: body ? { "Content-Type": "application/json" } : undefined,
89
- body: body ? JSON.stringify(body) : undefined,
90
- });
91
- if (!response.ok) {
92
- throw new Error(`${endpoint} 请求失败,状态码: ${response.status}`);
93
- }
94
- const payload = (await response.json());
95
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
96
- throw new Error(`${endpoint} 返回了无效响应`);
97
- }
98
- return payload;
99
- }
100
- /**
101
- * 请求任意相对路径 JSON API,并可附带 query 参数
102
- * @param target 当前默认设备目标
103
- * @param routePath 相对路径,例如 `/api/control/click`
104
- * @param query 可选查询参数
105
- * @returns 返回解析后的 JSON 数据
106
- * @example
107
- * const payload = await requestRuntimePathJson(target, "/api/ime/getText")
108
- */
109
- async function requestRuntimePathJson(target, routePath, query) {
110
- const url = new URL(`http://${target.ip}:${target.port}${routePath}`);
111
- if (query) {
112
- for (const [key, value] of Object.entries(query)) {
113
- if (value === undefined || value === null) {
114
- continue;
115
- }
116
- url.searchParams.set(key, String(value));
117
- }
118
- }
119
- const response = await fetch(url.toString(), {
120
- method: "GET",
121
- });
122
- if (!response.ok) {
123
- throw new Error(`${routePath} 请求失败,状态码: ${response.status}`);
124
- }
125
- const payload = (await response.json());
126
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
127
- throw new Error(`${routePath} 返回了无效响应`);
128
- }
129
- return payload;
130
- }
131
- /**
132
- * 从通用 JSON 响应中读取 `data` 字段
133
- * @param payload API 返回 JSON
134
- * @param endpoint API 路径名,用于错误提示
135
- * @returns 返回 `data` 字段内容
136
- * @example
137
- * const data = unwrapRuntimeData(payload, "getAllConfig")
138
- */
139
- function unwrapRuntimeData(payload, endpoint) {
140
- if (payload.success !== true) {
141
- throw new Error(String(payload.message ?? `${endpoint} 返回失败`));
142
- }
143
- return payload.data;
144
- }
145
71
  /**
146
72
  * 将任意 JSON 兼容值格式化为文本
147
73
  * @param value 任意待展示值
package/dist/mcp/tools.js CHANGED
@@ -7,6 +7,7 @@ const version_1 = require("../version");
7
7
  const device_config_1 = require("./device-config");
8
8
  Object.defineProperty(exports, "DEFAULT_DEVICE_PORT", { enumerable: true, get: function () { return device_config_1.DEFAULT_DEVICE_PORT; } });
9
9
  const doc_tools_1 = require("./doc-tools");
10
+ const httpapi_tools_1 = require("./httpapi-tools");
10
11
  const runtime_tools_1 = require("./runtime-tools");
11
12
  /**
12
13
  * 创建并注册 MCP 工具
@@ -21,6 +22,7 @@ function createMcpServer() {
21
22
  });
22
23
  (0, doc_tools_1.registerDocResources)(server);
23
24
  (0, doc_tools_1.registerDocTools)(server);
25
+ (0, httpapi_tools_1.registerHttpApiTools)(server);
24
26
  (0, runtime_tools_1.registerRuntimeTools)(server);
25
27
  return server;
26
28
  }
@@ -111,9 +111,6 @@ logi(`服务器设备ID: ${serverDeviceId}`);
111
111
 
112
112
  ### getECID - 获取设备 ECID。
113
113
 
114
- **注意事项:**
115
-
116
- - 这个 ID 只有自激活一次后才能获取
117
114
 
118
115
  ```typescript
119
116
  function getECID(): string;
@@ -135,9 +132,6 @@ logi(`ECID: ${ecid}`);
135
132
 
136
133
  ### getUDID - 获取设备 UDID。
137
134
 
138
- **注意事项:**
139
-
140
- - 这个 ID 只有自激活一次后才能获取
141
135
 
142
136
  ```typescript
143
137
  function getUDID(): string;
@@ -111,9 +111,6 @@ $打印信息日志(`服务器设备ID: ${serverDeviceId}`);
111
111
 
112
112
  ### 获取 ECID
113
113
 
114
- **注意事项:**
115
-
116
- - 这个 ID 只有自激活一次后才能获取
117
114
 
118
115
  ```typescript
119
116
  function 获取ECID(): 字符串;
@@ -135,9 +132,6 @@ $打印信息日志(`ECID: ${ecid}`);
135
132
 
136
133
  ### 获取 UDID
137
134
 
138
- **注意事项:**
139
-
140
- - 这个 ID 只有自激活一次后才能获取
141
135
 
142
136
  ```typescript
143
137
  function 获取UDID(): 字符串;
@@ -115,9 +115,6 @@ print(device.getServerDeviceId())
115
115
 
116
116
  ### getECID - 获取设备 ECID。
117
117
 
118
- **注意事项:**
119
-
120
- - 这个 ID 只有自激活一次后才能获取
121
118
 
122
119
  ```python
123
120
  def getECID() -> str
@@ -138,9 +135,6 @@ print(device.getECID())
138
135
 
139
136
  ### getUDID - 获取设备 UDID。
140
137
 
141
- **注意事项:**
142
-
143
- - 这个 ID 只有自激活一次后才能获取
144
138
 
145
139
  ```python
146
140
  def getUDID() -> str