@hangox/mg-cli 1.0.0 → 1.0.1

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 (42) hide show
  1. package/dist/cli.js +1574 -0
  2. package/dist/cli.js.map +1 -0
  3. package/dist/daemon-runner.js +794 -0
  4. package/dist/daemon-runner.js.map +1 -0
  5. package/dist/index-DNrszrq9.d.ts +568 -0
  6. package/dist/index.d.ts +129 -0
  7. package/dist/index.js +950 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/server.d.ts +2 -0
  10. package/dist/server.js +689 -0
  11. package/dist/server.js.map +1 -0
  12. package/package.json +5 -1
  13. package/.eslintrc.cjs +0 -26
  14. package/CLAUDE.md +0 -43
  15. package/src/cli/client.ts +0 -266
  16. package/src/cli/commands/execute-code.ts +0 -59
  17. package/src/cli/commands/export-image.ts +0 -193
  18. package/src/cli/commands/get-all-nodes.ts +0 -81
  19. package/src/cli/commands/get-all-pages.ts +0 -118
  20. package/src/cli/commands/get-node-by-id.ts +0 -83
  21. package/src/cli/commands/get-node-by-link.ts +0 -105
  22. package/src/cli/commands/server.ts +0 -130
  23. package/src/cli/index.ts +0 -33
  24. package/src/index.ts +0 -9
  25. package/src/server/connection-manager.ts +0 -211
  26. package/src/server/daemon-runner.ts +0 -22
  27. package/src/server/daemon.ts +0 -211
  28. package/src/server/index.ts +0 -8
  29. package/src/server/logger.ts +0 -117
  30. package/src/server/request-handler.ts +0 -192
  31. package/src/server/websocket-server.ts +0 -297
  32. package/src/shared/constants.ts +0 -90
  33. package/src/shared/errors.ts +0 -131
  34. package/src/shared/index.ts +0 -8
  35. package/src/shared/types.ts +0 -227
  36. package/src/shared/utils.ts +0 -352
  37. package/tests/unit/shared/constants.test.ts +0 -66
  38. package/tests/unit/shared/errors.test.ts +0 -82
  39. package/tests/unit/shared/utils.test.ts +0 -208
  40. package/tsconfig.json +0 -22
  41. package/tsup.config.ts +0 -33
  42. package/vitest.config.ts +0 -22
@@ -0,0 +1,568 @@
1
+ import { WebSocket } from 'ws';
2
+
3
+ /**
4
+ * MG Plugin 常量定义
5
+ */
6
+ /** 默认端口 */
7
+ declare const DEFAULT_PORT = 9527;
8
+ /** 端口范围:起始 */
9
+ declare const PORT_RANGE_START = 9527;
10
+ /** 端口范围:结束 */
11
+ declare const PORT_RANGE_END = 9536;
12
+ /** 最大尝试端口数 */
13
+ declare const MAX_PORT_ATTEMPTS = 10;
14
+ /** 端口扫描超时(毫秒) */
15
+ declare const PORT_SCAN_TIMEOUT = 500;
16
+ /** 配置目录 */
17
+ declare const CONFIG_DIR: string;
18
+ /** Server 状态文件 */
19
+ declare const SERVER_INFO_FILE: string;
20
+ /** 日志目录 */
21
+ declare const LOG_DIR: string;
22
+ /** Server 日志文件 */
23
+ declare const SERVER_LOG_FILE: string;
24
+ /** 心跳间隔(毫秒)- 30 秒 */
25
+ declare const HEARTBEAT_INTERVAL = 30000;
26
+ /** 心跳超时(毫秒)- 90 秒(3 次心跳) */
27
+ declare const HEARTBEAT_TIMEOUT = 90000;
28
+ /** 请求超时(毫秒)- 30 秒 */
29
+ declare const REQUEST_TIMEOUT = 30000;
30
+ /** Server 启动等待超时(毫秒)- 5 秒 */
31
+ declare const SERVER_START_TIMEOUT = 5000;
32
+ /** CLI 重试间隔(毫秒) */
33
+ declare const RETRY_INTERVALS: number[];
34
+ /** 最大重试次数 */
35
+ declare const MAX_RETRY_COUNT = 3;
36
+ /** 连接类型 */
37
+ declare enum ConnectionType {
38
+ /** 获取端 (CLI/MCP) */
39
+ CONSUMER = "consumer",
40
+ /** 提供端 (Injector) */
41
+ PROVIDER = "provider"
42
+ }
43
+ /** WebSocket 消息类型 */
44
+ declare enum MessageType {
45
+ PING = "ping",
46
+ PONG = "pong",
47
+ REGISTER = "register",
48
+ REGISTER_ACK = "register_ack",
49
+ GET_NODE_BY_ID = "get_node_by_id",
50
+ GET_ALL_NODES = "get_all_nodes",
51
+ GET_SELECTION = "get_selection",
52
+ EXPORT_IMAGE = "export_image",
53
+ EXECUTE_CODE = "execute_code",
54
+ GET_ALL_PAGES = "get_all_pages",
55
+ RESPONSE = "response",
56
+ ERROR = "error"
57
+ }
58
+
59
+ /**
60
+ * MG Plugin 错误码定义
61
+ */
62
+ /** 错误码枚举 */
63
+ declare enum ErrorCode {
64
+ /** 无法连接到 MG Server */
65
+ CONNECTION_FAILED = "E001",
66
+ /** 连接超时 */
67
+ CONNECTION_TIMEOUT = "E002",
68
+ /** 没有 MasterGo 页面连接到 Server */
69
+ NO_PAGE_CONNECTED = "E003",
70
+ /** 未找到匹配的页面 */
71
+ PAGE_NOT_FOUND = "E004",
72
+ /** 节点不存在 */
73
+ NODE_NOT_FOUND = "E005",
74
+ /** 没有选中任何节点 */
75
+ NO_SELECTION = "E006",
76
+ /** mg 对象不可用 */
77
+ MG_UNAVAILABLE = "E007",
78
+ /** 导出图片失败 */
79
+ EXPORT_FAILED = "E008",
80
+ /** 文件写入失败 */
81
+ FILE_WRITE_FAILED = "E009",
82
+ /** 无效的 mgp:// 链接格式 */
83
+ INVALID_LINK = "E010",
84
+ /** 参数校验失败 */
85
+ INVALID_PARAMS = "E011",
86
+ /** 请求超时 */
87
+ REQUEST_TIMEOUT = "E012",
88
+ /** 所有备选端口均被占用 */
89
+ PORT_EXHAUSTED = "E013",
90
+ /** 无法发现 Server (端口扫描失败) */
91
+ SERVER_DISCOVERY_FAILED = "E014",
92
+ /** 自动启动 Server 失败 */
93
+ SERVER_START_FAILED = "E015",
94
+ /** Server 已在运行中 */
95
+ SERVER_ALREADY_RUNNING = "E016",
96
+ /** 连接断开 */
97
+ CONNECTION_LOST = "E017",
98
+ /** 未知错误 */
99
+ UNKNOWN_ERROR = "E099"
100
+ }
101
+ /** 错误码对应的错误名称 */
102
+ declare const ErrorNames: Record<ErrorCode, string>;
103
+ /** 错误码对应的默认消息 */
104
+ declare const ErrorMessages: Record<ErrorCode, string>;
105
+ /** MG Plugin 错误类 */
106
+ declare class MGError extends Error {
107
+ /** 错误码 */
108
+ code: ErrorCode;
109
+ /** 错误名称 */
110
+ errorName: string;
111
+ /** 额外详情 */
112
+ details?: Record<string, unknown>;
113
+ constructor(code: ErrorCode, message?: string, details?: Record<string, unknown>);
114
+ /** 转换为 JSON 格式 */
115
+ toJSON(): {
116
+ code: ErrorCode;
117
+ name: string;
118
+ message: string;
119
+ details: Record<string, unknown> | undefined;
120
+ };
121
+ /** 格式化输出 */
122
+ toString(): string;
123
+ }
124
+ /**
125
+ * 创建错误
126
+ */
127
+ declare function createError(code: ErrorCode, message?: string, details?: Record<string, unknown>): MGError;
128
+
129
+ /**
130
+ * MG Plugin 类型定义
131
+ */
132
+
133
+ /** Server 运行信息 */
134
+ interface ServerInfo {
135
+ /** 监听端口 */
136
+ port: number;
137
+ /** 进程 ID */
138
+ pid: number;
139
+ /** 启动时间 (ISO 8601) */
140
+ startedAt: string;
141
+ }
142
+ /** 基础消息结构 */
143
+ interface BaseMessage {
144
+ /** 消息 ID */
145
+ id?: string;
146
+ /** 消息类型 */
147
+ type: MessageType | string;
148
+ /** 时间戳 */
149
+ timestamp?: number;
150
+ }
151
+ /** 请求消息 */
152
+ interface RequestMessage extends BaseMessage {
153
+ /** 目标页面 URL(标准化后的) */
154
+ pageUrl?: string;
155
+ /** 请求参数 */
156
+ params?: Record<string, unknown>;
157
+ }
158
+ /** 响应消息 */
159
+ interface ResponseMessage extends BaseMessage {
160
+ /** 对应请求的 ID */
161
+ id: string;
162
+ /** 是否成功 */
163
+ success: boolean;
164
+ /** 成功时的数据 */
165
+ data?: unknown;
166
+ /** 失败时的错误信息 */
167
+ error?: ErrorInfo | null;
168
+ }
169
+ /** 错误信息 */
170
+ interface ErrorInfo {
171
+ /** 错误码 */
172
+ code: ErrorCode;
173
+ /** 错误名称 */
174
+ name: string;
175
+ /** 错误消息 */
176
+ message: string;
177
+ /** 额外详情 */
178
+ details?: Record<string, unknown>;
179
+ }
180
+ /** 注册消息 */
181
+ interface RegisterMessage extends BaseMessage {
182
+ type: 'register';
183
+ data: {
184
+ /** 连接类型 */
185
+ connectionType: ConnectionType;
186
+ /** 页面 URL(Provider 必需) */
187
+ pageUrl?: string;
188
+ /** 页面唯一 ID */
189
+ pageId?: string;
190
+ };
191
+ }
192
+ /** 心跳消息 */
193
+ interface PingMessage extends BaseMessage {
194
+ type: 'ping';
195
+ timestamp: number;
196
+ }
197
+ interface PongMessage extends BaseMessage {
198
+ type: 'pong';
199
+ timestamp: number;
200
+ }
201
+ /** 连接信息 */
202
+ interface ConnectionInfo {
203
+ /** 连接 ID */
204
+ id: string;
205
+ /** 连接类型 */
206
+ type: ConnectionType;
207
+ /** 页面 URL(仅 Provider) */
208
+ pageUrl?: string;
209
+ /** 页面 ID(仅 Provider) */
210
+ pageId?: string;
211
+ /** 连接时间 */
212
+ connectedAt: Date;
213
+ /** 最后活跃时间 */
214
+ lastActiveAt: Date;
215
+ }
216
+ /** 节点信息(简化版) */
217
+ interface NodeInfo {
218
+ /** 节点 ID */
219
+ id: string;
220
+ /** 节点名称 */
221
+ name: string;
222
+ /** 节点类型 */
223
+ type: string;
224
+ /** 是否可见 */
225
+ visible: boolean;
226
+ /** X 坐标 */
227
+ x?: number;
228
+ /** Y 坐标 */
229
+ y?: number;
230
+ /** 宽度 */
231
+ width?: number;
232
+ /** 高度 */
233
+ height?: number;
234
+ /** 子节点 */
235
+ children?: NodeInfo[];
236
+ /** 其他属性 */
237
+ [key: string]: unknown;
238
+ }
239
+ /** 获取节点参数 */
240
+ interface GetNodeParams {
241
+ /** 节点 ID */
242
+ nodeId: string;
243
+ /** 遍历深度 */
244
+ maxDepth?: number;
245
+ /** 是否包含不可见节点 */
246
+ includeInvisible?: boolean;
247
+ /** 索引签名 */
248
+ [key: string]: unknown;
249
+ }
250
+ /** 获取所有节点参数 */
251
+ interface GetAllNodesParams {
252
+ /** 遍历深度 */
253
+ maxDepth?: number;
254
+ /** 是否包含不可见节点 */
255
+ includeInvisible?: boolean;
256
+ /** 索引签名 */
257
+ [key: string]: unknown;
258
+ }
259
+ /** 导出图片参数 */
260
+ interface ExportImageParams {
261
+ /** 节点 ID(可选,默认第一个选中节点) */
262
+ nodeId?: string;
263
+ /** 导出格式 */
264
+ format?: 'PNG' | 'JPG' | 'SVG' | 'PDF' | 'WEBP';
265
+ /** 缩放倍率 */
266
+ scale?: number;
267
+ /** 固定宽度 */
268
+ width?: number;
269
+ /** 固定高度 */
270
+ height?: number;
271
+ /** 是否使用完整尺寸 */
272
+ useAbsoluteBounds?: boolean;
273
+ /** 是否包含特效和外描边 */
274
+ useRenderBounds?: boolean;
275
+ }
276
+ /** CLI 输出格式化函数类型 */
277
+ type OutputFormatter = (data: Record<string, unknown>) => void;
278
+ /** CLI 命令选项 */
279
+ interface CliOptions {
280
+ /** 输出文件路径 */
281
+ output?: string;
282
+ /** 遍历深度 */
283
+ maxDepth?: number;
284
+ /** 包含不可见节点 */
285
+ includeInvisible?: boolean;
286
+ /** 禁用自动重试 */
287
+ noRetry?: boolean;
288
+ /** 禁用自动启动 Server */
289
+ noAutoStart?: boolean;
290
+ /** Server 端口 */
291
+ port?: number;
292
+ /** 前台模式运行 */
293
+ foreground?: boolean;
294
+ }
295
+ /** RGBA 颜色 */
296
+ interface RGBA {
297
+ r: number;
298
+ g: number;
299
+ b: number;
300
+ a: number;
301
+ }
302
+ /** 单个页面信息 */
303
+ interface MgPageInfo {
304
+ /** 页面 ID */
305
+ id: string;
306
+ /** 页面名称 */
307
+ name: string;
308
+ /** 页面背景色 */
309
+ bgColor?: RGBA;
310
+ /** 直接子节点数量 */
311
+ childCount: number;
312
+ }
313
+ /** 所有页面信息 */
314
+ interface AllPagesInfo {
315
+ /** 文档 ID */
316
+ documentId: string;
317
+ /** 文档名称 */
318
+ documentName: string;
319
+ /** 页面列表 */
320
+ pages: MgPageInfo[];
321
+ /** 页面总数 */
322
+ totalCount: number;
323
+ }
324
+
325
+ /**
326
+ * 日志模块
327
+ */
328
+ declare enum LogLevel {
329
+ DEBUG = "DEBUG",
330
+ INFO = "INFO",
331
+ WARN = "WARN",
332
+ ERROR = "ERROR"
333
+ }
334
+ interface LoggerOptions {
335
+ /** 是否输出到控制台 */
336
+ console?: boolean;
337
+ /** 是否输出到文件 */
338
+ file?: boolean;
339
+ /** 日志文件路径 */
340
+ filePath?: string;
341
+ /** 最小日志级别 */
342
+ minLevel?: LogLevel;
343
+ }
344
+ /**
345
+ * 日志记录器
346
+ */
347
+ declare class Logger {
348
+ private options;
349
+ constructor(options?: LoggerOptions);
350
+ /**
351
+ * 记录日志
352
+ */
353
+ private log;
354
+ debug(message: string, ...args: unknown[]): void;
355
+ info(message: string, ...args: unknown[]): void;
356
+ warn(message: string, ...args: unknown[]): void;
357
+ error(message: string, ...args: unknown[]): void;
358
+ }
359
+ /** 创建默认日志记录器 */
360
+ declare function createLogger(options?: LoggerOptions): Logger;
361
+
362
+ /**
363
+ * WebSocket 服务器
364
+ */
365
+
366
+ interface ServerOptions {
367
+ /** 监听端口 */
368
+ port?: number;
369
+ /** 日志选项 */
370
+ logger?: Logger;
371
+ }
372
+ /**
373
+ * MG WebSocket 服务器
374
+ */
375
+ declare class MGServer {
376
+ private wss;
377
+ private logger;
378
+ private connectionManager;
379
+ private requestHandler;
380
+ private port;
381
+ private isRunning;
382
+ constructor(options?: ServerOptions);
383
+ /**
384
+ * 启动服务器
385
+ */
386
+ start(): Promise<number>;
387
+ /**
388
+ * 查找可用端口
389
+ */
390
+ private findAvailablePort;
391
+ /**
392
+ * 检查端口是否可用
393
+ */
394
+ private isPortAvailable;
395
+ /**
396
+ * 处理新连接
397
+ */
398
+ private handleConnection;
399
+ /**
400
+ * 处理注册消息
401
+ */
402
+ private handleRegister;
403
+ /**
404
+ * 处理消息
405
+ */
406
+ private handleMessage;
407
+ /**
408
+ * 处理心跳
409
+ */
410
+ private handlePing;
411
+ /**
412
+ * 停止服务器
413
+ */
414
+ stop(): Promise<void>;
415
+ /**
416
+ * 获取运行状态
417
+ */
418
+ getStatus(): {
419
+ running: boolean;
420
+ port: number;
421
+ stats: {
422
+ providers: number;
423
+ consumers: number;
424
+ total: number;
425
+ };
426
+ connectedPages: string[];
427
+ };
428
+ /**
429
+ * 获取端口
430
+ */
431
+ getPort(): number;
432
+ /**
433
+ * 是否运行中
434
+ */
435
+ isServerRunning(): boolean;
436
+ }
437
+ /**
438
+ * 创建服务器实例
439
+ */
440
+ declare function createServer(options?: ServerOptions): MGServer;
441
+
442
+ /**
443
+ * 连接管理器
444
+ * 管理 Provider 和 Consumer 的 WebSocket 连接
445
+ */
446
+
447
+ /** 带连接信息的 WebSocket */
448
+ interface ManagedWebSocket extends WebSocket {
449
+ /** 连接 ID */
450
+ connectionId: string;
451
+ /** 连接信息 */
452
+ connectionInfo: ConnectionInfo;
453
+ /** 是否存活 */
454
+ isAlive: boolean;
455
+ }
456
+ /**
457
+ * 连接管理器
458
+ */
459
+ declare class ConnectionManager {
460
+ private logger;
461
+ /** Provider 连接(按页面 URL 索引) */
462
+ private providers;
463
+ /** Consumer 连接 */
464
+ private consumers;
465
+ /** 所有连接(按 ID 索引) */
466
+ private allConnections;
467
+ /** 心跳检查定时器 */
468
+ private heartbeatTimer;
469
+ constructor(logger: Logger);
470
+ /**
471
+ * 启动心跳检查
472
+ */
473
+ startHeartbeatCheck(interval?: number): void;
474
+ /**
475
+ * 停止心跳检查
476
+ */
477
+ stopHeartbeatCheck(): void;
478
+ /**
479
+ * 检查所有连接的心跳
480
+ */
481
+ private checkHeartbeats;
482
+ /**
483
+ * 添加连接
484
+ */
485
+ addConnection(ws: WebSocket, type: ConnectionType, pageUrl?: string, pageId?: string): ManagedWebSocket;
486
+ /**
487
+ * 移除连接
488
+ */
489
+ removeConnection(ws: ManagedWebSocket): void;
490
+ /**
491
+ * 更新连接活跃时间
492
+ */
493
+ updateLastActive(ws: ManagedWebSocket): void;
494
+ /**
495
+ * 根据页面 URL 查找 Provider
496
+ */
497
+ findProviderByPageUrl(pageUrl: string): ManagedWebSocket | undefined;
498
+ /**
499
+ * 获取第一个可用的 Provider
500
+ */
501
+ getFirstProvider(): ManagedWebSocket | undefined;
502
+ /**
503
+ * 获取所有 Provider 信息
504
+ */
505
+ getAllProviders(): ConnectionInfo[];
506
+ /**
507
+ * 获取连接统计
508
+ */
509
+ getStats(): {
510
+ providers: number;
511
+ consumers: number;
512
+ total: number;
513
+ };
514
+ /**
515
+ * 获取所有已连接的页面 URL
516
+ */
517
+ getConnectedPageUrls(): string[];
518
+ /**
519
+ * 关闭所有连接
520
+ */
521
+ closeAll(): void;
522
+ }
523
+
524
+ /**
525
+ * 请求处理器
526
+ * 处理 Consumer 请求,转发给 Provider
527
+ */
528
+
529
+ /**
530
+ * 请求处理器
531
+ */
532
+ declare class RequestHandler {
533
+ private logger;
534
+ private connectionManager;
535
+ /** 待处理的请求 */
536
+ private pendingRequests;
537
+ constructor(connectionManager: ConnectionManager, logger: Logger);
538
+ /**
539
+ * 处理 Consumer 请求
540
+ */
541
+ handleRequest(consumer: ManagedWebSocket, message: RequestMessage): Promise<void>;
542
+ /**
543
+ * 处理 Provider 响应
544
+ */
545
+ handleResponse(response: ResponseMessage): void;
546
+ /**
547
+ * 处理请求超时
548
+ */
549
+ private handleTimeout;
550
+ /**
551
+ * 清理请求
552
+ */
553
+ private cleanupRequest;
554
+ /**
555
+ * 发送错误响应
556
+ */
557
+ private sendError;
558
+ /**
559
+ * 清理特定连接的所有待处理请求
560
+ */
561
+ cleanupConnectionRequests(connectionId: string): void;
562
+ /**
563
+ * 清理所有待处理请求
564
+ */
565
+ cleanupAll(): void;
566
+ }
567
+
568
+ export { type AllPagesInfo as A, type BaseMessage as B, CONFIG_DIR as C, DEFAULT_PORT as D, ErrorCode as E, MGServer as F, type GetNodeParams as G, HEARTBEAT_INTERVAL as H, createServer as I, type ServerOptions as J, ConnectionManager as K, LOG_DIR as L, MAX_PORT_ATTEMPTS as M, type NodeInfo as N, type OutputFormatter as O, PORT_RANGE_START as P, type ManagedWebSocket as Q, REQUEST_TIMEOUT as R, type ServerInfo as S, RequestHandler as T, Logger as U, createLogger as V, LogLevel as W, type LoggerOptions as X, PORT_RANGE_END as a, PORT_SCAN_TIMEOUT as b, SERVER_INFO_FILE as c, SERVER_LOG_FILE as d, HEARTBEAT_TIMEOUT as e, SERVER_START_TIMEOUT as f, RETRY_INTERVALS as g, MAX_RETRY_COUNT as h, ConnectionType as i, MessageType as j, ErrorNames as k, ErrorMessages as l, MGError as m, createError as n, type RequestMessage as o, type ResponseMessage as p, type ErrorInfo as q, type RegisterMessage as r, type PingMessage as s, type PongMessage as t, type ConnectionInfo as u, type GetAllNodesParams as v, type ExportImageParams as w, type CliOptions as x, type RGBA as y, type MgPageInfo as z };
@@ -0,0 +1,129 @@
1
+ import { S as ServerInfo } from './index-DNrszrq9.js';
2
+ export { A as AllPagesInfo, B as BaseMessage, C as CONFIG_DIR, x as CliOptions, u as ConnectionInfo, K as ConnectionManager, i as ConnectionType, D as DEFAULT_PORT, E as ErrorCode, q as ErrorInfo, l as ErrorMessages, k as ErrorNames, w as ExportImageParams, v as GetAllNodesParams, G as GetNodeParams, H as HEARTBEAT_INTERVAL, e as HEARTBEAT_TIMEOUT, L as LOG_DIR, W as LogLevel, U as Logger, X as LoggerOptions, M as MAX_PORT_ATTEMPTS, h as MAX_RETRY_COUNT, m as MGError, F as MGServer, Q as ManagedWebSocket, j as MessageType, z as MgPageInfo, N as NodeInfo, O as OutputFormatter, a as PORT_RANGE_END, P as PORT_RANGE_START, b as PORT_SCAN_TIMEOUT, s as PingMessage, t as PongMessage, R as REQUEST_TIMEOUT, g as RETRY_INTERVALS, y as RGBA, r as RegisterMessage, T as RequestHandler, o as RequestMessage, p as ResponseMessage, c as SERVER_INFO_FILE, d as SERVER_LOG_FILE, f as SERVER_START_TIMEOUT, J as ServerOptions, n as createError, V as createLogger, I as createServer } from './index-DNrszrq9.js';
3
+ import 'ws';
4
+
5
+ /**
6
+ * MG Plugin 工具函数
7
+ */
8
+
9
+ /**
10
+ * 确保目录存在
11
+ */
12
+ declare function ensureDir(dir: string): void;
13
+ /**
14
+ * 确保配置目录存在
15
+ */
16
+ declare function ensureConfigDir(): void;
17
+ /**
18
+ * 读取 Server 信息文件
19
+ */
20
+ declare function readServerInfo(): ServerInfo | null;
21
+ /**
22
+ * 写入 Server 信息文件
23
+ */
24
+ declare function writeServerInfo(info: ServerInfo): void;
25
+ /**
26
+ * 删除 Server 信息文件
27
+ */
28
+ declare function deleteServerInfo(): void;
29
+ /**
30
+ * 解析输出路径(支持相对路径和绝对路径)
31
+ */
32
+ declare function resolveOutputPath(outputPath: string): string;
33
+ /**
34
+ * 确保输出路径的目录存在
35
+ */
36
+ declare function ensureOutputDir(outputPath: string): void;
37
+ /**
38
+ * 检查进程是否存在
39
+ */
40
+ declare function isProcessRunning(pid: number): boolean;
41
+ /**
42
+ * 终止进程
43
+ */
44
+ declare function killProcess(pid: number): boolean;
45
+ /**
46
+ * 标准化页面 URL
47
+ *
48
+ * 输入: https://mastergo.netease.com/file/174135798361888?fileOpenFrom=home&page_id=0%3A8347
49
+ * 输出: mastergo.netease.com/file/174135798361888
50
+ */
51
+ declare function normalizePageUrl(url: string): string;
52
+ /**
53
+ * 检查是否是设计页面 URL
54
+ */
55
+ declare function isDesignPageUrl(url: string): boolean;
56
+ /**
57
+ * 解析 mgp:// 链接
58
+ *
59
+ * 支持的格式 (queryParams 格式,nodeId 需要 URL 编码):
60
+ * - mgp://mastergo.netease.com/file/174135798361888?nodeId=123%3A456 (单个节点)
61
+ * - mgp://mastergo.netease.com/file/174135798361888?nodeId=0%3A8633&nodePath=314%3A13190%2F0%3A8633 (带父节点路径)
62
+ *
63
+ * 输出: { pageUrl: 'mastergo.netease.com/file/174135798361888', nodeId: '0:8633', nodePath: ['314:13190', '0:8633'] }
64
+ */
65
+ declare function parseMgpLink(link: string): {
66
+ pageUrl: string;
67
+ nodeId: string;
68
+ nodePath?: string[];
69
+ } | null;
70
+ /**
71
+ * 生成 mgp:// 链接
72
+ *
73
+ * @param pageUrl 页面 URL(会被标准化)
74
+ * @param nodeId 节点 ID(会被 URL 编码)
75
+ * @param nodePath 可选的父节点路径(会被 URL 编码)
76
+ */
77
+ declare function generateMgpLink(pageUrl: string, nodeId: string, nodePath?: string[]): string;
78
+ /**
79
+ * 格式化文件大小
80
+ */
81
+ declare function formatFileSize(bytes: number): string;
82
+ /**
83
+ * 格式化时间间隔
84
+ */
85
+ declare function formatDuration(ms: number): string;
86
+ /**
87
+ * 生成唯一 ID
88
+ */
89
+ declare function generateId(): string;
90
+ /**
91
+ * 获取当前时间的 ISO 格式字符串
92
+ */
93
+ declare function getCurrentISOTime(): string;
94
+ /**
95
+ * 格式化日期时间用于日志
96
+ */
97
+ declare function formatLogTime(date?: Date): string;
98
+ /**
99
+ * 从完整 URL 提取 fileId
100
+ *
101
+ * 支持格式:
102
+ * - https://mastergo.netease.com/file/174875497054651?page_id=321%3A11979
103
+ * - mastergo.netease.com/file/174875497054651
104
+ *
105
+ * @returns fileId 或 null
106
+ */
107
+ declare function extractFileIdFromUrl(url: string): string | null;
108
+ /**
109
+ * 从 mgp:// 链接提取 fileId
110
+ *
111
+ * 支持格式:
112
+ * - mgp://mastergo.netease.com/file/174875497054651?nodeId=xxx
113
+ *
114
+ * @returns fileId 或 null
115
+ */
116
+ declare function extractFileIdFromMgpLink(link: string): string | null;
117
+ /**
118
+ * 统一处理输入,提取 fileId
119
+ *
120
+ * 支持三种输入格式:
121
+ * 1. 完整 URL: https://mastergo.netease.com/file/174875497054651?page_id=xxx
122
+ * 2. mgp 协议: mgp://mastergo.netease.com/file/174875497054651?nodeId=xxx
123
+ * 3. 纯 fileId: 174875497054651
124
+ *
125
+ * @returns fileId 或 null
126
+ */
127
+ declare function extractFileId(input: string): string | null;
128
+
129
+ export { ServerInfo, deleteServerInfo, ensureConfigDir, ensureDir, ensureOutputDir, extractFileId, extractFileIdFromMgpLink, extractFileIdFromUrl, formatDuration, formatFileSize, formatLogTime, generateId, generateMgpLink, getCurrentISOTime, isDesignPageUrl, isProcessRunning, killProcess, normalizePageUrl, parseMgpLink, readServerInfo, resolveOutputPath, writeServerInfo };