ms-vite-plugin 1.4.47 → 1.4.49

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.
Files changed (43) hide show
  1. package/dist/build.js +1 -292
  2. package/dist/cli.js +6 -1234
  3. package/dist/mcp/device-config.d.ts +0 -47
  4. package/dist/mcp/device-config.js +1 -183
  5. package/dist/mcp/device-log.d.ts +0 -8
  6. package/dist/mcp/device-log.js +3 -27
  7. package/dist/mcp/doc-tools.d.ts +0 -7
  8. package/dist/mcp/doc-tools.js +2 -39
  9. package/dist/mcp/docs-service.d.ts +0 -13
  10. package/dist/mcp/docs-service.js +1 -63
  11. package/dist/mcp/httpapi-docs-service.d.ts +0 -31
  12. package/dist/mcp/httpapi-docs-service.js +1 -122
  13. package/dist/mcp/httpapi-tools.d.ts +0 -7
  14. package/dist/mcp/httpapi-tools.js +4 -222
  15. package/dist/mcp/image-tools.d.ts +0 -62
  16. package/dist/mcp/image-tools.js +8 -607
  17. package/dist/mcp/ocr-tools.d.ts +0 -25
  18. package/dist/mcp/ocr-tools.js +5 -413
  19. package/dist/mcp/project.d.ts +0 -14
  20. package/dist/mcp/project.js +1 -74
  21. package/dist/mcp/runtime-tools.d.ts +0 -7
  22. package/dist/mcp/runtime-tools.js +11 -308
  23. package/dist/mcp/tool-utils.d.ts +0 -40
  24. package/dist/mcp/tool-utils.js +1 -81
  25. package/dist/mcp/tools.d.ts +0 -12
  26. package/dist/mcp/tools.js +1 -31
  27. package/dist/mcp/types.d.ts +0 -12
  28. package/dist/mcp/types.js +1 -11
  29. package/dist/mcp-server.js +1 -85
  30. package/dist/packager.d.ts +0 -7
  31. package/dist/packager.js +1 -125
  32. package/dist/project.d.ts +0 -61
  33. package/dist/project.js +1 -619
  34. package/dist/stopGuardPlugin.d.ts +0 -6
  35. package/dist/stopGuardPlugin.js +1 -165
  36. package/dist/version.d.ts +0 -10
  37. package/dist/version.js +1 -63
  38. package/dist/ws-manager.d.ts +0 -95
  39. package/dist/ws-manager.js +1 -392
  40. package/docs/api/image.md +249 -25
  41. package/docs/apicn/image.md +245 -19
  42. package/docs/apipython/image.md +238 -18
  43. package/package.json +3 -2
@@ -1,165 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createStopGuardPlugin = createStopGuardPlugin;
37
- const acorn = __importStar(require("acorn"));
38
- const MagicString = require("magic-string");
39
- const STOP_GUARD_ERROR = "__kuaijs_stop_guard_error";
40
- const STOP_GUARD_ERROR_TEXT = "__kuaijs_stop_guard_error_text";
41
- const STOP_EXCEPTION_NAME = "KuaiJSManualExitException";
42
- const STOP_RELATED_FUNCTION_ERROR = "is not a function";
43
- /**
44
- * 为最终 JS chunk 的 catch 块补充停止异常转抛逻辑。
45
- *
46
- * 这个插件运行在 renderChunk 阶段:Vite 已经把 TS/模块语法编译成最终 JS,但尚未写入文件。
47
- * 使用 MagicString 返回 sourcemap,让新增保护代码不映射到用户源码,原有代码继续保持映射。
48
- */
49
- function createStopGuardPlugin() {
50
- return {
51
- name: "kuaijs-stop-guard",
52
- enforce: "post",
53
- renderChunk(code) {
54
- const edits = createStopGuardEdits(code);
55
- if (edits.length === 0) {
56
- return null;
57
- }
58
- const magic = new MagicString(code);
59
- for (const edit of edits) {
60
- if (edit.start === edit.end) {
61
- magic.appendLeft(edit.start, edit.text);
62
- }
63
- else {
64
- magic.overwrite(edit.start, edit.end, edit.text);
65
- }
66
- }
67
- return {
68
- code: magic.toString(),
69
- map: magic.generateMap({ hires: true }),
70
- };
71
- },
72
- };
73
- }
74
- function createStopGuardEdits(code) {
75
- const ast = parseJavaScript(code);
76
- const edits = [];
77
- walkAst(ast, (node) => {
78
- if (node.type === "CatchClause" && node.body?.type === "BlockStatement") {
79
- addCatchStopExceptionGuard(edits, node, code);
80
- }
81
- });
82
- return edits;
83
- }
84
- function parseJavaScript(code) {
85
- try {
86
- return acorn.parse(code, {
87
- allowHashBang: true,
88
- ecmaVersion: "latest",
89
- sourceType: "script",
90
- });
91
- }
92
- catch {
93
- return acorn.parse(code, {
94
- allowHashBang: true,
95
- ecmaVersion: "latest",
96
- sourceType: "module",
97
- });
98
- }
99
- }
100
- function addCatchStopExceptionGuard(edits, catchClause, code) {
101
- if (typeof catchClause.body.start !== "number") {
102
- return;
103
- }
104
- let errorExpression = STOP_GUARD_ERROR;
105
- let restoreCatchPattern = "";
106
- if (catchClause.param) {
107
- if (catchClause.param.type === "Identifier") {
108
- errorExpression = catchClause.param.name;
109
- }
110
- else if (typeof catchClause.param.start === "number" &&
111
- typeof catchClause.param.end === "number") {
112
- const originalPattern = code.slice(catchClause.param.start, catchClause.param.end);
113
- edits.push({
114
- start: catchClause.param.start,
115
- end: catchClause.param.end,
116
- text: STOP_GUARD_ERROR,
117
- });
118
- restoreCatchPattern = `let ${originalPattern}=${STOP_GUARD_ERROR};`;
119
- }
120
- }
121
- else {
122
- edits.push({
123
- start: catchClause.body.start,
124
- end: catchClause.body.start,
125
- text: `(${STOP_GUARD_ERROR})`,
126
- });
127
- }
128
- const stopGuard = `const ${STOP_GUARD_ERROR_TEXT}=String(${errorExpression});` +
129
- `if(${STOP_GUARD_ERROR_TEXT}.includes("${STOP_EXCEPTION_NAME}")||` +
130
- `${STOP_GUARD_ERROR_TEXT}.includes("${STOP_RELATED_FUNCTION_ERROR}")){` +
131
- `throw ${errorExpression};` +
132
- `}`;
133
- edits.push({
134
- start: catchClause.body.start + 1,
135
- end: catchClause.body.start + 1,
136
- text: stopGuard + restoreCatchPattern,
137
- });
138
- }
139
- function walkAst(node, visit) {
140
- if (!node || typeof node !== "object") {
141
- return;
142
- }
143
- if (typeof node.type === "string") {
144
- visit(node);
145
- }
146
- for (const key of Object.keys(node)) {
147
- if (key === "parent" ||
148
- key === "start" ||
149
- key === "end" ||
150
- key === "loc" ||
151
- key === "range" ||
152
- key === "raw") {
153
- continue;
154
- }
155
- const value = node[key];
156
- if (Array.isArray(value)) {
157
- for (const child of value) {
158
- walkAst(child, visit);
159
- }
160
- }
161
- else if (value && typeof value === "object") {
162
- walkAst(value, visit);
163
- }
164
- }
165
- }
1
+ "use strict";var p=exports&&exports.__createBinding||(Object.create?(function(r,t,n,e){e===void 0&&(e=n);var a=Object.getOwnPropertyDescriptor(t,n);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(r,e,a)}):(function(r,t,n,e){e===void 0&&(e=n),r[e]=t[n]})),l=exports&&exports.__setModuleDefault||(Object.create?(function(r,t){Object.defineProperty(r,"default",{enumerable:!0,value:t})}):function(r,t){r.default=t}),_=exports&&exports.__importStar||(function(){var r=function(t){return r=Object.getOwnPropertyNames||function(n){var e=[];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[e.length]=a);return e},r(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var e=r(t),a=0;a<e.length;a++)e[a]!=="default"&&p(n,t,e[a]);return l(n,t),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.createStopGuardPlugin=b;const s=_(require("acorn")),d=require("magic-string"),i="__kuaijs_stop_guard_error",o="__kuaijs_stop_guard_error_text",y="KuaiJSManualExitException",g="is not a function";function b(){return{name:"kuaijs-stop-guard",enforce:"post",renderChunk(r){const t=O(r);if(t.length===0)return null;const n=new d(r);for(const e of t)e.start===e.end?n.appendLeft(e.start,e.text):n.overwrite(e.start,e.end,e.text);return{code:n.toString(),map:n.generateMap({hires:!0})}}}}function O(r){const t=m(r),n=[];return u(t,e=>{e.type==="CatchClause"&&e.body?.type==="BlockStatement"&&S(n,e,r)}),n}function m(r){try{return s.parse(r,{allowHashBang:!0,ecmaVersion:"latest",sourceType:"script"})}catch{return s.parse(r,{allowHashBang:!0,ecmaVersion:"latest",sourceType:"module"})}}function S(r,t,n){if(typeof t.body.start!="number")return;let e=i,a="";if(t.param){if(t.param.type==="Identifier")e=t.param.name;else if(typeof t.param.start=="number"&&typeof t.param.end=="number"){const c=n.slice(t.param.start,t.param.end);r.push({start:t.param.start,end:t.param.end,text:i}),a=`let ${c}=${i};`}}else r.push({start:t.body.start,end:t.body.start,text:`(${i})`});const f=`const ${o}=String(${e});if(${o}.includes("${y}")||${o}.includes("${g}")){throw ${e};}`;r.push({start:t.body.start+1,end:t.body.start+1,text:f+a})}function u(r,t){if(!(!r||typeof r!="object")){typeof r.type=="string"&&t(r);for(const n of Object.keys(r)){if(n==="parent"||n==="start"||n==="end"||n==="loc"||n==="range"||n==="raw")continue;const e=r[n];if(Array.isArray(e))for(const a of e)u(a,t);else e&&typeof e=="object"&&u(e,t)}}}
package/dist/version.d.ts CHANGED
@@ -1,12 +1,2 @@
1
- /**
2
- * 读取当前包版本号(自动定位 package.json)
3
- * @param fallbackVersion 读取失败时回退版本号,默认 dev
4
- * @returns 返回版本号字符串
5
- * @example
6
- * const version = readPackageVersion()
7
- */
8
1
  export declare function readPackageVersion(fallbackVersion?: string): string;
9
- /**
10
- * 当前包版本号(模块加载时读取)
11
- */
12
2
  export declare const PACKAGE_VERSION: string;
package/dist/version.js CHANGED
@@ -1,63 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.PACKAGE_VERSION = void 0;
37
- exports.readPackageVersion = readPackageVersion;
38
- const fsExtra = __importStar(require("fs-extra"));
39
- const path = __importStar(require("path"));
40
- /**
41
- * 读取当前包版本号(自动定位 package.json)
42
- * @param fallbackVersion 读取失败时回退版本号,默认 dev
43
- * @returns 返回版本号字符串
44
- * @example
45
- * const version = readPackageVersion()
46
- */
47
- function readPackageVersion(fallbackVersion = "dev") {
48
- try {
49
- const packageJsonPath = path.resolve(__dirname, "..", "package.json");
50
- const packageJson = fsExtra.readJSONSync(packageJsonPath);
51
- if (typeof packageJson.version === "string" && packageJson.version.trim()) {
52
- return packageJson.version.trim();
53
- }
54
- }
55
- catch {
56
- // ignore and fallback
57
- }
58
- return fallbackVersion;
59
- }
60
- /**
61
- * 当前包版本号(模块加载时读取)
62
- */
63
- exports.PACKAGE_VERSION = readPackageVersion();
1
+ "use strict";var c=exports&&exports.__createBinding||(Object.create?(function(i,e,t,r){r===void 0&&(r=t);var n=Object.getOwnPropertyDescriptor(e,t);(!n||("get"in n?!e.__esModule:n.writable||n.configurable))&&(n={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(i,r,n)}):(function(i,e,t,r){r===void 0&&(r=t),i[r]=e[t]})),f=exports&&exports.__setModuleDefault||(Object.create?(function(i,e){Object.defineProperty(i,"default",{enumerable:!0,value:e})}):function(i,e){i.default=e}),a=exports&&exports.__importStar||(function(){var i=function(e){return i=Object.getOwnPropertyNames||function(t){var r=[];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[r.length]=n);return r},i(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=i(e),n=0;n<r.length;n++)r[n]!=="default"&&c(t,e,r[n]);return f(t,e),t}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.PACKAGE_VERSION=void 0,exports.readPackageVersion=u;const o=a(require("fs-extra")),s=a(require("path"));function u(i="dev"){try{const e=s.resolve(__dirname,"..","package.json"),t=o.readJSONSync(e);if(typeof t.version=="string"&&t.version.trim())return t.version.trim()}catch{}return i}exports.PACKAGE_VERSION=u();
@@ -1,15 +1,9 @@
1
- /**
2
- * WS 响应数据结构
3
- */
4
1
  export type WsResponse = {
5
2
  requestId: string;
6
3
  success: boolean;
7
4
  message?: unknown;
8
5
  data?: unknown;
9
6
  };
10
- /**
11
- * CLI 版 WebSocket 管理器
12
- */
13
7
  export declare class WSManager {
14
8
  private static instance;
15
9
  private wss;
@@ -19,107 +13,18 @@ export declare class WSManager {
19
13
  private readonly hostIp;
20
14
  private port;
21
15
  private pending;
22
- /**
23
- * 获取 WS 管理器单例
24
- * @returns 返回单例实例
25
- * @example
26
- * const ws = WSManager.get()
27
- */
28
16
  static get(): WSManager;
29
- /**
30
- * 判断是否已有设备连接
31
- * @returns 已连接返回 true,否则 false
32
- * @example
33
- * WSManager.isConnected()
34
- */
35
17
  static isConnected(): boolean;
36
- /**
37
- * 静态请求入口
38
- * @param type 请求类型
39
- * @param message 请求参数
40
- * @param timeoutMs 超时时间(毫秒)
41
- * @returns 返回设备响应
42
- * @example
43
- * await WSManager.request("runtime_status", {}, 5000)
44
- */
45
18
  static request(type: string, message?: Record<string, unknown>, timeoutMs?: number): Promise<WsResponse>;
46
- /**
47
- * 获取监听地址
48
- * @returns 返回 ws 地址
49
- * @example
50
- * ws.getAddress()
51
- */
52
19
  getAddress(): string;
53
- /**
54
- * 判断服务器是否已启动
55
- * @returns 已启动返回 true,否则 false
56
- * @example
57
- * ws.isStarted()
58
- */
59
20
  isStarted(): boolean;
60
- /**
61
- * 获取设备连接状态
62
- * @returns 已连接返回 true,否则 false
63
- * @example
64
- * ws.isClientConnected()
65
- */
66
21
  isClientConnected(): boolean;
67
- /**
68
- * 获取当前连接设备 IP
69
- * @returns 返回设备 IP,未连接时返回 null
70
- * @example
71
- * ws.getConnectedClientIp()
72
- */
73
22
  getConnectedClientIp(): string | null;
74
- /**
75
- * 启动 WS 服务
76
- * @param port 指定端口,默认 31111
77
- * @returns 启动完成后返回 Promise<void>
78
- * @example
79
- * await ws.start(31111)
80
- */
81
23
  start(port?: number): Promise<void>;
82
- /**
83
- * 等待设备连接
84
- * @param timeoutMs 超时时间(毫秒)
85
- * @returns 成功连接后返回 Promise<void>
86
- * @example
87
- * await ws.waitForClient(30000)
88
- */
89
24
  waitForClient(timeoutMs?: number): Promise<void>;
90
- /**
91
- * 发送请求并等待响应
92
- * @param type 请求类型
93
- * @param message 请求消息
94
- * @param timeoutMs 超时时间(毫秒)
95
- * @returns 返回设备响应
96
- * @example
97
- * await ws.request("files", {}, 60000)
98
- */
99
25
  request(type: string, message?: Record<string, unknown>, timeoutMs?: number): Promise<WsResponse>;
100
- /**
101
- * 停止 WS 服务
102
- * @returns 停止完成后返回 Promise<void>
103
- * @example
104
- * await ws.stop()
105
- */
106
26
  stop(): Promise<void>;
107
- /**
108
- * 启动运行状态轮询
109
- * @returns 无返回值
110
- * @example
111
- * ws.startStatusInterval()
112
- */
113
27
  private startStatusInterval;
114
- /**
115
- * 停止运行状态轮询
116
- * @returns 无返回值
117
- * @example
118
- * ws.stopStatusInterval()
119
- */
120
28
  private stopStatusInterval;
121
29
  }
122
- /**
123
- * 对齐原有命名导出
124
- */
125
30
  export declare const WebSocketServerManager: typeof WSManager;