@hangox/mg-cli 1.4.0 → 1.5.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.
@@ -41,6 +41,9 @@ declare const HEARTBEAT_INTERVAL = 30000;
41
41
  declare const HEARTBEAT_TIMEOUT = 90000;
42
42
  /** 请求超时(毫秒)- 30 秒 */
43
43
  declare const REQUEST_TIMEOUT = 30000;
44
+ /** 请求超时上限(毫秒)- 10 分钟。写操作(如 create_node 大树)可通过
45
+ * 请求消息的 timeoutMs 字段放宽超时,此常量防止传入过大值长期占用资源 */
46
+ declare const MAX_REQUEST_TIMEOUT = 600000;
44
47
  /** Server 启动等待超时(毫秒)- 5 秒 */
45
48
  declare const SERVER_START_TIMEOUT = 5000;
46
49
  /** CLI 重试间隔(毫秒) */
@@ -63,13 +66,21 @@ declare enum MessageType {
63
66
  REGISTER = "register",
64
67
  REGISTER_ACK = "register_ack",
65
68
  GET_NODE_BY_ID = "get_node_by_id",
69
+ GET_NODE_CONTEXT = "get_node_context",
66
70
  GET_PAGE_BY_ID = "get_page_by_id",
67
71
  GET_ALL_NODES = "get_all_nodes",
68
72
  GET_SELECTION = "get_selection",
69
73
  EXPORT_IMAGE = "export_image",
70
74
  EXECUTE_CODE = "execute_code",
75
+ LIST_FONTS = "list_fonts",
76
+ LIST_LIBRARY = "list_library",
77
+ IMPORT_COMPONENT = "import_component",
71
78
  GET_ALL_PAGES = "get_all_pages",
72
79
  GET_COMMENTS = "get_comments",
80
+ CREATE_PAGE = "create_page",
81
+ CREATE_NODE = "create_node",
82
+ DELETE_NODE = "delete_node",
83
+ UPDATE_NODE = "update_node",
73
84
  LIST_EXTENSIONS = "list_extensions",
74
85
  OPEN_PAGE = "open_page",
75
86
  NAVIGATE_TO_NODE = "navigate_to_node",
@@ -120,6 +131,10 @@ declare enum ErrorCode {
120
131
  CONNECTION_LOST = "E017",
121
132
  /** 没有扩展连接到 Server */
122
133
  NO_EXTENSION_CONNECTED = "E018",
134
+ /** 页面只读 / 无编辑权限,无法执行写操作 */
135
+ EDIT_NOT_ALLOWED = "E019",
136
+ /** 创建节点整体性失败(根节点都建不出来) */
137
+ CREATE_NODE_FAILED = "E020",
123
138
  /** 未知错误 */
124
139
  UNKNOWN_ERROR = "E099"
125
140
  }
@@ -181,6 +196,11 @@ interface RequestMessage extends BaseMessage {
181
196
  pageUrl?: string;
182
197
  /** 请求参数 */
183
198
  params?: Record<string, unknown>;
199
+ /**
200
+ * 请求超时(毫秒)。Server 转发时以此为准(上限 MAX_REQUEST_TIMEOUT),
201
+ * 缺省使用 REQUEST_TIMEOUT。用于 create_node 等大树写操作放宽超时
202
+ */
203
+ timeoutMs?: number;
184
204
  }
185
205
  /** 响应消息 */
186
206
  interface ResponseMessage extends BaseMessage {
@@ -399,6 +419,180 @@ interface NodeInfo {
399
419
  /** 其他属性(根据节点类型不同而不同) */
400
420
  [key: string]: unknown;
401
421
  }
422
+ /** MasterGo 可用字体条目 */
423
+ interface AvailableFontInfo {
424
+ fontName: {
425
+ family: string;
426
+ style: string;
427
+ };
428
+ localizedFontName?: {
429
+ family: string;
430
+ style: string;
431
+ };
432
+ dataStyle?: number;
433
+ referrer?: string;
434
+ [key: string]: unknown;
435
+ }
436
+ /** LIST_FONTS 请求参数 */
437
+ interface ListFontsParams {
438
+ /** 按字体 family/style/localized 名称做大小写不敏感过滤 */
439
+ filter?: string;
440
+ /** 索引签名(适配 request params 约束) */
441
+ [key: string]: unknown;
442
+ }
443
+ /** LIST_FONTS 响应数据 */
444
+ interface ListFontsResult {
445
+ fonts: AvailableFontInfo[];
446
+ total: number;
447
+ filter?: string;
448
+ }
449
+ /** LIST_LIBRARY 请求参数 */
450
+ interface ListLibraryParams {
451
+ /** 按库名/组件名做大小写不敏感过滤 */
452
+ filter?: string;
453
+ /** 索引签名(适配 request params 约束) */
454
+ [key: string]: unknown;
455
+ }
456
+ /** 团队库组件/组件集信息 */
457
+ interface LibraryComponentInfo {
458
+ id: string;
459
+ name: string;
460
+ ukey: string;
461
+ description?: string;
462
+ type: 'COMPONENT' | 'COMPONENT_SET';
463
+ cover?: string;
464
+ width?: number;
465
+ height?: number;
466
+ componentSetUkey?: string;
467
+ libraryId: string;
468
+ libraryName: string;
469
+ }
470
+ /** 单个团队库信息 */
471
+ interface LibraryInfo {
472
+ id: string;
473
+ name: string;
474
+ components: LibraryComponentInfo[];
475
+ componentCount: number;
476
+ styleCounts: Record<string, number>;
477
+ }
478
+ /** LIST_LIBRARY 响应数据 */
479
+ interface ListLibraryResult {
480
+ libraries: LibraryInfo[];
481
+ totalLibraries: number;
482
+ totalComponents: number;
483
+ filter?: string;
484
+ }
485
+ /** IMPORT_COMPONENT 请求参数:ukey/ukeySet 二选一;placeInstance=true 时会额外摆放一个可见 INSTANCE */
486
+ interface ImportComponentParams {
487
+ ukey?: string;
488
+ ukeySet?: string;
489
+ /** 是否在导入组件定义后立即创建并摆放一个 INSTANCE */
490
+ placeInstance?: boolean;
491
+ /** INSTANCE 目标父节点 ID,缺省 = 当前页面 */
492
+ parentId?: string;
493
+ /** INSTANCE 放置位置 X */
494
+ x?: number;
495
+ /** INSTANCE 放置位置 Y */
496
+ y?: number;
497
+ /** 索引签名(适配 request params 约束) */
498
+ [key: string]: unknown;
499
+ }
500
+ /** 已摆放的实例信息 */
501
+ interface PlacedInstanceInfo {
502
+ id: string;
503
+ nodeId: string;
504
+ name: string;
505
+ type: 'INSTANCE';
506
+ parentId?: string;
507
+ x?: number;
508
+ y?: number;
509
+ }
510
+ /** IMPORT_COMPONENT 响应数据 */
511
+ interface ImportComponentResult {
512
+ /** 导入到当前文件的组件/组件集定义 ID(不是画布实例) */
513
+ id: string;
514
+ nodeId: string;
515
+ name: string;
516
+ type: 'COMPONENT' | 'COMPONENT_SET';
517
+ ukey: string;
518
+ /** placeInstance=true 时返回实际摆到画布上的 INSTANCE */
519
+ instance?: PlacedInstanceInfo;
520
+ instanceId?: string;
521
+ }
522
+ /** 创建节点 warning 分类 */
523
+ type CreateNodeWarningKind =
524
+ /** 类型不支持,降级为 FRAME 占位 */
525
+ 'UNSUPPORTED_TYPE_DOWNGRADED'
526
+ /** 属性 setter 抛异常 */
527
+ | 'PROPERTY_SET_FAILED'
528
+ /** 明知不支持主动跳过(如 IMAGE fill 资源) */
529
+ | 'PROPERTY_SKIPPED'
530
+ /** 字体加载失败用了回退字体 */
531
+ | 'FONT_FALLBACK';
532
+ /** 创建节点过程中的单条 warning */
533
+ interface CreateNodeWarning {
534
+ /** 出问题的源节点 */
535
+ sourceNodeId: string;
536
+ kind: CreateNodeWarningKind;
537
+ /** 相关属性名 */
538
+ property?: string;
539
+ message: string;
540
+ }
541
+ /** CREATE_NODE 请求参数 */
542
+ interface CreateNodeParams {
543
+ /**
544
+ * 节点 JSON。整树模式:get_node_by_id --raw 导出的全树(含 children);
545
+ * 逐节点模式:单节点(无 children 的退化树),字段与 NodeInfo 同名(读写对称)
546
+ */
547
+ node: NodeInfo;
548
+ /** 目标父节点 ID,缺省 = 当前页面 (mg.document.currentPage) */
549
+ parentId?: string;
550
+ /** 覆盖根节点放置位置(缺省用 node.x / node.y) */
551
+ x?: number;
552
+ y?: number;
553
+ /**
554
+ * 仅 type=GROUP 的逐节点模式:把已存在的节点成组(mg.group)。
555
+ * 与 node.children 互斥——childIds 引用已建好的节点,children 是待递归创建的数据
556
+ */
557
+ childIds?: string[];
558
+ /** 索引签名(适配 request params 约束) */
559
+ [key: string]: unknown;
560
+ }
561
+ /** CREATE_NODE 响应数据 */
562
+ interface CreateNodeResult {
563
+ /** 新建根节点 ID */
564
+ nodeId: string;
565
+ /** 源节点 ID → 新建节点 ID(全树) */
566
+ idMap: Record<string, string>;
567
+ warnings: CreateNodeWarning[];
568
+ }
569
+ /** DELETE_NODE 请求参数 */
570
+ interface DeleteNodeParams {
571
+ nodeId: string;
572
+ /** 索引签名(适配 request params 约束) */
573
+ [key: string]: unknown;
574
+ }
575
+ /** DELETE_NODE 响应数据 */
576
+ interface DeleteNodeResult {
577
+ deleted: true;
578
+ }
579
+ /** UPDATE_NODE 请求参数 */
580
+ interface UpdateNodeParams {
581
+ /** 要更新的节点 ID */
582
+ nodeId: string;
583
+ /**
584
+ * 要设置的属性(字段与 NodeInfo 同名,读写对称)。
585
+ * 语义:仅设置给出的字段,未给出的字段不动
586
+ */
587
+ props: Partial<NodeInfo>;
588
+ /** 索引签名(适配 request params 约束) */
589
+ [key: string]: unknown;
590
+ }
591
+ /** UPDATE_NODE 响应数据 */
592
+ interface UpdateNodeResult {
593
+ nodeId: string;
594
+ warnings: CreateNodeWarning[];
595
+ }
402
596
  /** 空间节点信息(仅包含位置和尺寸,用于 AI 理解空间布局) */
403
597
  interface SpaceNodeInfo {
404
598
  /** 节点 ID */
@@ -437,6 +631,127 @@ interface GetNodeParams {
437
631
  /** 索引签名 */
438
632
  [key: string]: unknown;
439
633
  }
634
+ /** 获取节点上下文参数(get_node_context) */
635
+ interface GetNodeContextParams {
636
+ /** 目标节点 ID */
637
+ nodeId: string;
638
+ /** 向上取几层祖先:-1 = 直到并包含 PAGE(对应 CLI `all`),n>0 = 取 n 层 */
639
+ ancestorLevels?: number;
640
+ /** 是否返回 siblings 数组,默认 true */
641
+ includeSiblings?: boolean;
642
+ /** 兄弟数量上限,超出时以目标为中心开窗,默认 50 */
643
+ maxSiblings?: number;
644
+ /** 目标节点自身子树深度,默认 1 */
645
+ maxDepth?: number;
646
+ /** 是否包含不可见节点(仅作用于 siblings 过滤与 node 子树,不影响祖先链) */
647
+ includeInvisible?: boolean;
648
+ /** 索引签名 */
649
+ [key: string]: unknown;
650
+ }
651
+ /**
652
+ * 祖先节点摘要信息(浅提取,固定字段清单,无 children)
653
+ * AutoLayout 组输出规则:flexMode 恒输出(含 "NONE");组内其余字段仅当 flexMode 存在且 ≠ NONE 时输出。
654
+ * CLI 侧不对 ancestors 做 trimNodeDefaults
655
+ */
656
+ interface AncestorInfo {
657
+ /** 层级,从 1(直接父)递增 */
658
+ level: number;
659
+ /** 节点 ID */
660
+ id: string;
661
+ /** 节点名称 */
662
+ name: string;
663
+ /** 节点类型(含 PAGE) */
664
+ type: string;
665
+ /** 是否可见(不可见祖先不断链,标 false) */
666
+ visible?: boolean;
667
+ /** X 坐标(PAGE 无 LayoutMixin,不含几何组) */
668
+ x?: number;
669
+ /** Y 坐标 */
670
+ y?: number;
671
+ /** 宽度 */
672
+ width?: number;
673
+ /** 高度 */
674
+ height?: number;
675
+ /** 直接子节点数量 */
676
+ childCount?: number;
677
+ /** 自动布局方向 (NONE | HORIZONTAL | VERTICAL) */
678
+ flexMode?: string;
679
+ /** 换行设置 */
680
+ flexWrap?: string;
681
+ /** 主轴间距 */
682
+ itemSpacing?: number;
683
+ /** 交叉轴间距 */
684
+ crossAxisSpacing?: number;
685
+ /** 主轴对齐 */
686
+ mainAxisAlignItems?: string;
687
+ /** 交叉轴对齐 */
688
+ crossAxisAlignItems?: string;
689
+ /** 主轴尺寸模式 (FIXED | AUTO) */
690
+ mainAxisSizingMode?: string;
691
+ /** 交叉轴尺寸模式 (FIXED | AUTO) */
692
+ crossAxisSizingMode?: string;
693
+ /** 内边距(上) */
694
+ paddingTop?: number;
695
+ /** 内边距(右) */
696
+ paddingRight?: number;
697
+ /** 内边距(下) */
698
+ paddingBottom?: number;
699
+ /** 内边距(左) */
700
+ paddingLeft?: number;
701
+ /** 裁剪内容 */
702
+ clipsContent?: boolean;
703
+ /** 布局定位方式 (AUTO | ABSOLUTE) */
704
+ layoutPositioning?: string;
705
+ /** 主组件 ID(INSTANCE 专属) */
706
+ mainComponentId?: string;
707
+ }
708
+ /** 兄弟节点摘要信息(含目标自己,isSelf: true) */
709
+ interface SiblingInfo {
710
+ /** 过滤前真实序号(与 indexInParent 同源,0-based) */
711
+ index: number;
712
+ /** 节点 ID */
713
+ id: string;
714
+ /** 节点名称 */
715
+ name: string;
716
+ /** 节点类型 */
717
+ type: string;
718
+ /** 是否可见 */
719
+ visible: boolean;
720
+ /** X 坐标 */
721
+ x?: number;
722
+ /** Y 坐标 */
723
+ y?: number;
724
+ /** 宽度 */
725
+ width?: number;
726
+ /** 高度 */
727
+ height?: number;
728
+ /** 布局定位方式(absolute 定位的兄弟不参与 AutoLayout 流) */
729
+ layoutPositioning?: string;
730
+ /** 是否是目标节点自己 */
731
+ isSelf: boolean;
732
+ }
733
+ /**
734
+ * 节点上下文信息(get_node_context 响应)
735
+ * 序列化 key 顺序:contextSummary 排第一位,node 大对象排最后
736
+ */
737
+ interface NodeContextInfo {
738
+ /** 人类/AI 可读摘要。仅供阅读,不得作为机器解析对象 */
739
+ contextSummary: string;
740
+ /** 目标在父节点 children 中的序号(过滤前真实序号,0-based);无父节点时为 -1 */
741
+ indexInParent: number;
742
+ /** 父节点过滤前 children 总数(含目标自己),恒等于 ancestors[0].childCount */
743
+ siblingCount: number;
744
+ /** true = siblings 被 maxSiblings 开窗截断。false 时省略 */
745
+ siblingsTruncated?: boolean;
746
+ /** true = parent 链中断(未走到 PAGE),已返回部分祖先。false 时省略 */
747
+ ancestorsIncomplete?: boolean;
748
+ /** 祖先链,level 从 1(直接父)递增,直到并包含 PAGE */
749
+ ancestors: AncestorInfo[];
750
+ /** 兄弟摘要(含目标自己),按真实 index 升序。--no-siblings 时省略 */
751
+ siblings?: SiblingInfo[];
752
+ /** 目标节点完整 NodeInfo(深度 = maxDepth) */
753
+ node: NodeInfo;
754
+ }
440
755
  /** 获取页面参数 */
441
756
  interface GetPageParams {
442
757
  /** 页面 ID */
@@ -625,6 +940,30 @@ interface AllPagesInfo {
625
940
  /** 页面总数 */
626
941
  totalCount: number;
627
942
  }
943
+ /** CREATE_PAGE 请求参数 */
944
+ interface CreatePageParams {
945
+ /** 新页面名称;未提供时使用 MasterGo 默认命名(页面 N) */
946
+ name?: string;
947
+ /** 索引签名(适配 request params 约束) */
948
+ [key: string]: unknown;
949
+ }
950
+ /** CREATE_PAGE 响应数据 */
951
+ interface CreatePageResult {
952
+ /** 新页面 ID */
953
+ pageId: string;
954
+ /** 新页面 ID(兼容 id 字段) */
955
+ id: string;
956
+ /** 新页面名称 */
957
+ name: string;
958
+ /** 节点类型,固定为 PAGE */
959
+ type: 'PAGE';
960
+ /** 直接子节点数量,新建页面默认为 0 */
961
+ childCount: number;
962
+ /** 创建前当前页面 ID */
963
+ previousPageId?: string;
964
+ /** 是否已自动切换到新页面 */
965
+ current: boolean;
966
+ }
628
967
  /** 扩展实例信息 */
629
968
  interface ExtensionInfo {
630
969
  /** 扩展实例序号(1-based) */
@@ -812,6 +1151,7 @@ declare class MGServer {
812
1151
  stats: {
813
1152
  providers: number;
814
1153
  consumers: number;
1154
+ extensions: number;
815
1155
  total: number;
816
1156
  };
817
1157
  connectedPages: string[];
@@ -990,4 +1330,4 @@ declare class RequestHandler {
990
1330
  cleanupAll(): void;
991
1331
  }
992
1332
 
993
- export { type MgPageInfo as $, type PongMessage as A, type BaseMessage as B, CONFIG_DIR as C, DEV_DEFAULT_PORT as D, ErrorCode as E, type ConnectionInfo as F, type GetNodeParams as G, HEARTBEAT_INTERVAL as H, IS_DEV_MODE as I, type GetPageParams as J, type GetAllNodesParams as K, LOG_DIR as L, MessageType as M, type NodeInfo as N, type ExportImageParams as O, PROD_DEFAULT_PORT as P, type CommentLocation as Q, REQUEST_TIMEOUT as R, type ServerInfo as S, type CommentUserInfo as T, type CommentNearbyNode as U, type CommentInfo as V, type GetCommentsParams as W, type GetCommentsResult as X, type OutputFormatter as Y, type CliOptions as Z, type RGBA as _, type SpaceNodeInfo as a, type AllPagesInfo as a0, type ExtensionInfo as a1, type OpenPageParams as a2, type NavigateToNodeParams as a3, type ConnectedPageInfo as a4, type ServerStatusResponse as a5, MGServer as a6, createServer as a7, type ServerOptions as a8, ConnectionManager as a9, type ManagedWebSocket as aa, RequestHandler as ab, Logger as ac, createLogger as ad, LogLevel as ae, type LoggerOptions as af, PROD_PORT_RANGE_START as b, PROD_PORT_RANGE_END as c, DEV_PORT_RANGE_START as d, DEV_PORT_RANGE_END as e, DEFAULT_PORT as f, PORT_RANGE_START as g, PORT_RANGE_END as h, MAX_PORT_ATTEMPTS as i, PORT_SCAN_TIMEOUT as j, SERVER_INFO_FILE as k, SERVER_LOG_FILE as l, HEARTBEAT_TIMEOUT as m, SERVER_START_TIMEOUT as n, RETRY_INTERVALS as o, MAX_RETRY_COUNT as p, ConnectionType as q, ErrorNames as r, ErrorMessages as s, MGError as t, createError as u, type RequestMessage as v, type ResponseMessage as w, type ErrorInfo as x, type RegisterMessage as y, type PingMessage as z };
1333
+ export { type CreateNodeParams as $, type PingMessage as A, type BaseMessage as B, CONFIG_DIR as C, DEV_DEFAULT_PORT as D, ErrorCode as E, type PongMessage as F, type ConnectionInfo as G, HEARTBEAT_INTERVAL as H, IS_DEV_MODE as I, type AvailableFontInfo as J, type ListFontsParams as K, LOG_DIR as L, MessageType as M, type NodeInfo as N, type ListFontsResult as O, PROD_DEFAULT_PORT as P, type ListLibraryParams as Q, REQUEST_TIMEOUT as R, type ServerInfo as S, type LibraryComponentInfo as T, type LibraryInfo as U, type ListLibraryResult as V, type ImportComponentParams as W, type PlacedInstanceInfo as X, type ImportComponentResult as Y, type CreateNodeWarningKind as Z, type CreateNodeWarning as _, type SpaceNodeInfo as a, type CreateNodeResult as a0, type DeleteNodeParams as a1, type DeleteNodeResult as a2, type UpdateNodeParams as a3, type UpdateNodeResult as a4, type GetNodeParams as a5, type GetNodeContextParams as a6, type AncestorInfo as a7, type SiblingInfo as a8, type NodeContextInfo as a9, RequestHandler as aA, Logger as aB, createLogger as aC, LogLevel as aD, type LoggerOptions as aE, type GetPageParams as aa, type GetAllNodesParams as ab, type ExportImageParams as ac, type CommentLocation as ad, type CommentUserInfo as ae, type CommentNearbyNode as af, type CommentInfo as ag, type GetCommentsParams as ah, type GetCommentsResult as ai, type OutputFormatter as aj, type CliOptions as ak, type RGBA as al, type MgPageInfo as am, type AllPagesInfo as an, type CreatePageParams as ao, type CreatePageResult as ap, type ExtensionInfo as aq, type OpenPageParams as ar, type NavigateToNodeParams as as, type ConnectedPageInfo as at, type ServerStatusResponse as au, MGServer as av, createServer as aw, type ServerOptions as ax, ConnectionManager as ay, type ManagedWebSocket as az, PROD_PORT_RANGE_START as b, PROD_PORT_RANGE_END as c, DEV_PORT_RANGE_START as d, DEV_PORT_RANGE_END as e, DEFAULT_PORT as f, PORT_RANGE_START as g, PORT_RANGE_END as h, MAX_PORT_ATTEMPTS as i, PORT_SCAN_TIMEOUT as j, SERVER_INFO_FILE as k, SERVER_LOG_FILE as l, HEARTBEAT_TIMEOUT as m, MAX_REQUEST_TIMEOUT as n, SERVER_START_TIMEOUT as o, RETRY_INTERVALS as p, MAX_RETRY_COUNT as q, ConnectionType as r, ErrorNames as s, ErrorMessages as t, MGError as u, createError as v, type RequestMessage as w, type ResponseMessage as x, type ErrorInfo as y, type RegisterMessage as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as ServerInfo, N as NodeInfo, a as SpaceNodeInfo, M as MessageType } from './index-AVsoGQ0e.js';
2
- export { a0 as AllPagesInfo, B as BaseMessage, C as CONFIG_DIR, Z as CliOptions, V as CommentInfo, Q as CommentLocation, U as CommentNearbyNode, T as CommentUserInfo, a4 as ConnectedPageInfo, F as ConnectionInfo, a9 as ConnectionManager, q as ConnectionType, f as DEFAULT_PORT, D as DEV_DEFAULT_PORT, e as DEV_PORT_RANGE_END, d as DEV_PORT_RANGE_START, E as ErrorCode, x as ErrorInfo, s as ErrorMessages, r as ErrorNames, O as ExportImageParams, a1 as ExtensionInfo, K as GetAllNodesParams, W as GetCommentsParams, X as GetCommentsResult, G as GetNodeParams, J as GetPageParams, H as HEARTBEAT_INTERVAL, m as HEARTBEAT_TIMEOUT, I as IS_DEV_MODE, L as LOG_DIR, ae as LogLevel, ac as Logger, af as LoggerOptions, i as MAX_PORT_ATTEMPTS, p as MAX_RETRY_COUNT, t as MGError, a6 as MGServer, aa as ManagedWebSocket, $ as MgPageInfo, a3 as NavigateToNodeParams, a2 as OpenPageParams, Y as OutputFormatter, h as PORT_RANGE_END, g as PORT_RANGE_START, j as PORT_SCAN_TIMEOUT, P as PROD_DEFAULT_PORT, c as PROD_PORT_RANGE_END, b as PROD_PORT_RANGE_START, z as PingMessage, A as PongMessage, R as REQUEST_TIMEOUT, o as RETRY_INTERVALS, _ as RGBA, y as RegisterMessage, ab as RequestHandler, v as RequestMessage, w as ResponseMessage, k as SERVER_INFO_FILE, l as SERVER_LOG_FILE, n as SERVER_START_TIMEOUT, a8 as ServerOptions, a5 as ServerStatusResponse, u as createError, ad as createLogger, a7 as createServer } from './index-AVsoGQ0e.js';
1
+ import { S as ServerInfo, N as NodeInfo, a as SpaceNodeInfo, M as MessageType } from './index-DuCpsEXk.js';
2
+ export { an as AllPagesInfo, a7 as AncestorInfo, J as AvailableFontInfo, B as BaseMessage, C as CONFIG_DIR, ak as CliOptions, ag as CommentInfo, ad as CommentLocation, af as CommentNearbyNode, ae as CommentUserInfo, at as ConnectedPageInfo, G as ConnectionInfo, ay as ConnectionManager, r as ConnectionType, $ as CreateNodeParams, a0 as CreateNodeResult, _ as CreateNodeWarning, Z as CreateNodeWarningKind, ao as CreatePageParams, ap as CreatePageResult, f as DEFAULT_PORT, D as DEV_DEFAULT_PORT, e as DEV_PORT_RANGE_END, d as DEV_PORT_RANGE_START, a1 as DeleteNodeParams, a2 as DeleteNodeResult, E as ErrorCode, y as ErrorInfo, t as ErrorMessages, s as ErrorNames, ac as ExportImageParams, aq as ExtensionInfo, ab as GetAllNodesParams, ah as GetCommentsParams, ai as GetCommentsResult, a6 as GetNodeContextParams, a5 as GetNodeParams, aa as GetPageParams, H as HEARTBEAT_INTERVAL, m as HEARTBEAT_TIMEOUT, I as IS_DEV_MODE, W as ImportComponentParams, Y as ImportComponentResult, L as LOG_DIR, T as LibraryComponentInfo, U as LibraryInfo, K as ListFontsParams, O as ListFontsResult, Q as ListLibraryParams, V as ListLibraryResult, aD as LogLevel, aB as Logger, aE as LoggerOptions, i as MAX_PORT_ATTEMPTS, n as MAX_REQUEST_TIMEOUT, q as MAX_RETRY_COUNT, u as MGError, av as MGServer, az as ManagedWebSocket, am as MgPageInfo, as as NavigateToNodeParams, a9 as NodeContextInfo, ar as OpenPageParams, aj as OutputFormatter, h as PORT_RANGE_END, g as PORT_RANGE_START, j as PORT_SCAN_TIMEOUT, P as PROD_DEFAULT_PORT, c as PROD_PORT_RANGE_END, b as PROD_PORT_RANGE_START, A as PingMessage, X as PlacedInstanceInfo, F as PongMessage, R as REQUEST_TIMEOUT, p as RETRY_INTERVALS, al as RGBA, z as RegisterMessage, aA as RequestHandler, w as RequestMessage, x as ResponseMessage, k as SERVER_INFO_FILE, l as SERVER_LOG_FILE, o as SERVER_START_TIMEOUT, ax as ServerOptions, au as ServerStatusResponse, a8 as SiblingInfo, a3 as UpdateNodeParams, a4 as UpdateNodeResult, v as createError, aC as createLogger, aw as createServer } from './index-DuCpsEXk.js';
3
3
  import 'ws';
4
4
 
5
5
  /**
@@ -246,12 +246,15 @@ declare class MGClient {
246
246
  private register;
247
247
  /**
248
248
  * 发送请求并等待响应
249
+ * @param timeoutMs 请求超时(毫秒),缺省 REQUEST_TIMEOUT。
250
+ * 会随消息透传给 Server,使 Server 侧转发超时同步放宽
249
251
  */
250
- request<T = unknown>(type: MessageType, params?: Record<string, unknown>, pageUrl?: string): Promise<T>;
252
+ request<T = unknown>(type: MessageType, params?: Record<string, unknown>, pageUrl?: string, timeoutMs?: number): Promise<T>;
251
253
  /**
252
254
  * 带重试的请求
255
+ * @param timeoutMs 请求超时(毫秒),透传给 request()
253
256
  */
254
- requestWithRetry<T = unknown>(type: MessageType, params?: Record<string, unknown>, pageUrl?: string): Promise<T>;
257
+ requestWithRetry<T = unknown>(type: MessageType, params?: Record<string, unknown>, pageUrl?: string, timeoutMs?: number): Promise<T>;
255
258
  /**
256
259
  * 关闭连接
257
260
  */
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var SERVER_LOG_FILE = join(LOG_DIR, "server.log");
20
20
  var HEARTBEAT_INTERVAL = 3e4;
21
21
  var HEARTBEAT_TIMEOUT = 9e4;
22
22
  var REQUEST_TIMEOUT = 3e4;
23
+ var MAX_REQUEST_TIMEOUT = 6e5;
23
24
  var SERVER_START_TIMEOUT = 5e3;
24
25
  var RETRY_INTERVALS = [1e3, 2e3, 4e3];
25
26
  var MAX_RETRY_COUNT = 3;
@@ -35,13 +36,21 @@ var MessageType = /* @__PURE__ */ ((MessageType2) => {
35
36
  MessageType2["REGISTER"] = "register";
36
37
  MessageType2["REGISTER_ACK"] = "register_ack";
37
38
  MessageType2["GET_NODE_BY_ID"] = "get_node_by_id";
39
+ MessageType2["GET_NODE_CONTEXT"] = "get_node_context";
38
40
  MessageType2["GET_PAGE_BY_ID"] = "get_page_by_id";
39
41
  MessageType2["GET_ALL_NODES"] = "get_all_nodes";
40
42
  MessageType2["GET_SELECTION"] = "get_selection";
41
43
  MessageType2["EXPORT_IMAGE"] = "export_image";
42
44
  MessageType2["EXECUTE_CODE"] = "execute_code";
45
+ MessageType2["LIST_FONTS"] = "list_fonts";
46
+ MessageType2["LIST_LIBRARY"] = "list_library";
47
+ MessageType2["IMPORT_COMPONENT"] = "import_component";
43
48
  MessageType2["GET_ALL_PAGES"] = "get_all_pages";
44
49
  MessageType2["GET_COMMENTS"] = "get_comments";
50
+ MessageType2["CREATE_PAGE"] = "create_page";
51
+ MessageType2["CREATE_NODE"] = "create_node";
52
+ MessageType2["DELETE_NODE"] = "delete_node";
53
+ MessageType2["UPDATE_NODE"] = "update_node";
45
54
  MessageType2["LIST_EXTENSIONS"] = "list_extensions";
46
55
  MessageType2["OPEN_PAGE"] = "open_page";
47
56
  MessageType2["NAVIGATE_TO_NODE"] = "navigate_to_node";
@@ -72,6 +81,8 @@ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
72
81
  ErrorCode2["SERVER_ALREADY_RUNNING"] = "E016";
73
82
  ErrorCode2["CONNECTION_LOST"] = "E017";
74
83
  ErrorCode2["NO_EXTENSION_CONNECTED"] = "E018";
84
+ ErrorCode2["EDIT_NOT_ALLOWED"] = "E019";
85
+ ErrorCode2["CREATE_NODE_FAILED"] = "E020";
75
86
  ErrorCode2["UNKNOWN_ERROR"] = "E099";
76
87
  return ErrorCode2;
77
88
  })(ErrorCode || {});
@@ -94,6 +105,8 @@ var ErrorNames = {
94
105
  ["E016" /* SERVER_ALREADY_RUNNING */]: "SERVER_ALREADY_RUNNING",
95
106
  ["E017" /* CONNECTION_LOST */]: "CONNECTION_LOST",
96
107
  ["E018" /* NO_EXTENSION_CONNECTED */]: "NO_EXTENSION_CONNECTED",
108
+ ["E019" /* EDIT_NOT_ALLOWED */]: "EDIT_NOT_ALLOWED",
109
+ ["E020" /* CREATE_NODE_FAILED */]: "CREATE_NODE_FAILED",
97
110
  ["E099" /* UNKNOWN_ERROR */]: "UNKNOWN_ERROR"
98
111
  };
99
112
  var ErrorMessages = {
@@ -115,6 +128,8 @@ var ErrorMessages = {
115
128
  ["E016" /* SERVER_ALREADY_RUNNING */]: "Server \u5DF2\u5728\u8FD0\u884C\u4E2D",
116
129
  ["E017" /* CONNECTION_LOST */]: "\u8FDE\u63A5\u65AD\u5F00",
117
130
  ["E018" /* NO_EXTENSION_CONNECTED */]: "\u6CA1\u6709 Chrome \u6269\u5C55\u8FDE\u63A5\u5230 Server\u3002\u8BF7\u786E\u4FDD\u6D4F\u89C8\u5668\u5DF2\u6253\u5F00\u5E76\u5B89\u88C5\u4E86 MG Plugin",
131
+ ["E019" /* EDIT_NOT_ALLOWED */]: "\u9875\u9762\u53EA\u8BFB\u6216\u65E0\u7F16\u8F91\u6743\u9650\uFF0C\u65E0\u6CD5\u6267\u884C\u5199\u64CD\u4F5C",
132
+ ["E020" /* CREATE_NODE_FAILED */]: "\u521B\u5EFA\u8282\u70B9\u5931\u8D25\uFF08\u6839\u8282\u70B9\u65E0\u6CD5\u521B\u5EFA\uFF09",
118
133
  ["E099" /* UNKNOWN_ERROR */]: "\u672A\u77E5\u9519\u8BEF"
119
134
  };
120
135
  var MGError = class extends Error {
@@ -481,7 +496,6 @@ var NODE_DEFAULTS = {
481
496
  layoutPositioning: "AUTO",
482
497
  constrainProportions: false,
483
498
  // 容器专属属性 (FrameNode)
484
- flexMode: "NONE",
485
499
  flexWrap: "NO_WRAP",
486
500
  itemSpacing: 0,
487
501
  crossAxisSpacing: 0,
@@ -894,6 +908,12 @@ var ConnectionManager = class {
894
908
  };
895
909
 
896
910
  // src/server/request-handler.ts
911
+ function resolveRequestTimeout(timeoutMs) {
912
+ if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
913
+ return REQUEST_TIMEOUT;
914
+ }
915
+ return Math.min(timeoutMs, MAX_REQUEST_TIMEOUT);
916
+ }
897
917
  var RequestHandler = class {
898
918
  logger;
899
919
  connectionManager;
@@ -926,7 +946,7 @@ var RequestHandler = class {
926
946
  }
927
947
  const timer = setTimeout(() => {
928
948
  this.handleTimeout(requestId);
929
- }, REQUEST_TIMEOUT);
949
+ }, resolveRequestTimeout(message.timeoutMs));
930
950
  this.pendingRequests.set(requestId, {
931
951
  id: requestId,
932
952
  consumer,
@@ -1739,8 +1759,10 @@ var MGClient = class {
1739
1759
  }
1740
1760
  /**
1741
1761
  * 发送请求并等待响应
1762
+ * @param timeoutMs 请求超时(毫秒),缺省 REQUEST_TIMEOUT。
1763
+ * 会随消息透传给 Server,使 Server 侧转发超时同步放宽
1742
1764
  */
1743
- async request(type, params, pageUrl) {
1765
+ async request(type, params, pageUrl, timeoutMs) {
1744
1766
  if (!this.ws) {
1745
1767
  throw new MGError("E001" /* CONNECTION_FAILED */, "\u672A\u8FDE\u63A5\u5230 Server");
1746
1768
  }
@@ -1750,12 +1772,13 @@ var MGClient = class {
1750
1772
  type,
1751
1773
  params,
1752
1774
  pageUrl,
1775
+ timeoutMs,
1753
1776
  timestamp: Date.now()
1754
1777
  };
1755
1778
  return new Promise((resolve2, reject) => {
1756
1779
  const timer = setTimeout(() => {
1757
1780
  reject(new MGError("E012" /* REQUEST_TIMEOUT */, ErrorMessages["E012" /* REQUEST_TIMEOUT */]));
1758
- }, REQUEST_TIMEOUT);
1781
+ }, timeoutMs ?? REQUEST_TIMEOUT);
1759
1782
  const messageHandler = (data) => {
1760
1783
  try {
1761
1784
  const response = JSON.parse(data.toString());
@@ -1783,15 +1806,16 @@ var MGClient = class {
1783
1806
  }
1784
1807
  /**
1785
1808
  * 带重试的请求
1809
+ * @param timeoutMs 请求超时(毫秒),透传给 request()
1786
1810
  */
1787
- async requestWithRetry(type, params, pageUrl) {
1811
+ async requestWithRetry(type, params, pageUrl, timeoutMs) {
1788
1812
  if (this.options.noRetry) {
1789
- return this.request(type, params, pageUrl);
1813
+ return this.request(type, params, pageUrl, timeoutMs);
1790
1814
  }
1791
1815
  let lastError = null;
1792
1816
  for (let attempt = 0; attempt <= MAX_RETRY_COUNT; attempt++) {
1793
1817
  try {
1794
- return await this.request(type, params, pageUrl);
1818
+ return await this.request(type, params, pageUrl, timeoutMs);
1795
1819
  } catch (error) {
1796
1820
  lastError = error instanceof Error ? error : new Error(String(error));
1797
1821
  if (error instanceof MGError) {
@@ -1840,6 +1864,7 @@ export {
1840
1864
  LogLevel,
1841
1865
  Logger,
1842
1866
  MAX_PORT_ATTEMPTS,
1867
+ MAX_REQUEST_TIMEOUT,
1843
1868
  MAX_RETRY_COUNT,
1844
1869
  MGClient,
1845
1870
  MGError,