@mbws/plugin-sdk 0.5.3 → 0.5.5

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.
package/README.md CHANGED
@@ -255,6 +255,10 @@ const registered = await mbws.caps.exec.registerOutput({
255
255
  占位卡;编码完成后宿主自动转正并可预览/上传。字段值全程不变(占位符稳定);
256
256
  - 面板中途关闭:宿主对账三触发源(registerOutput / job 终态 / 兜底扫描)任一到达
257
257
  即转正 reserved 条目并广播 onUpload 事件——重开面板 `caps.uploads.list()` 自动跟上;
258
+ - **同名接管(0.5.3 宿主)**:move 登记时,同插件 + 同页面作用域(同一条记录)+
259
+ 同文件名的旧条目被新产物自动接管——旧的移出上传队列(正在上传的等传完即清),
260
+ 反复重跑同一交付物不会在宿主上传队列累积条目;仍被延迟提交引用的条目除外。
261
+ 同一条记录要交付多个同名产物时请用不同 filename。
258
262
 
259
263
  ### 产物直落用户文件夹(canonical,大产物防工作区膨胀)
260
264
 
package/dist/client.d.ts CHANGED
@@ -436,11 +436,13 @@ export interface CreateMbwsOptions {
436
436
  timeoutMs?: number;
437
437
  /** 单次 invoke 的默认超时(ms),超时按 E_TIMEOUT 拒绝。默认 30_000。 */
438
438
  invokeTimeoutMs?: number;
439
+ /**
440
+ * 长操作方法(ensureAttachment/localize/expandZip/pick 系列/registerOutput)的独立
441
+ * 超时(ms)。默认 600_000——这些调用等用户交互或传输大文件,进度走事件流,
442
+ * 30s 常规超时会在 Windows 首次使用(同意弹窗 + 下载附件)时误杀。
443
+ */
444
+ longInvokeTimeoutMs?: number;
439
445
  }
440
- /**
441
- * callId 生成走专用 uuid()(getRandomValues 直拼)——randomUUID 是 secure-context-only,
442
- * 插件面板经 http 的 registry 代理装载(dev)时不存在,历史上已踩坑。
443
- */
444
446
  /** 分层可测:纯端口逻辑(不碰 window),单测用 Node MessageChannel 直连 broker。 */
445
447
  export declare function connectMbwsPort<C extends MbwsContractTypes = MbwsContractTypes>(port: MessagePort, init: {
446
448
  grants: string[];
@@ -449,7 +451,7 @@ export declare function connectMbwsPort<C extends MbwsContractTypes = MbwsContra
449
451
  autoParams?: Record<string, unknown>;
450
452
  theme?: Record<string, string>;
451
453
  attachments?: AttachmentState[];
452
- }, opts?: Pick<CreateMbwsOptions, "invokeTimeoutMs">): MbwsClient<C>;
454
+ }, opts?: Pick<CreateMbwsOptions, "invokeTimeoutMs" | "longInvokeTimeoutMs">): MbwsClient<C>;
453
455
  /**
454
456
  * 生产引导的窗口层:等宿主 init(带端口),超时/顶窗口降级 dev mock。
455
457
  * 抽成独立函数(接受窗口注入)以支持单测用假 window 驱动。
package/dist/client.js CHANGED
@@ -111,9 +111,26 @@ export function reserveOutputInvalid(req) {
111
111
  * callId 生成走专用 uuid()(getRandomValues 直拼)——randomUUID 是 secure-context-only,
112
112
  * 插件面板经 http 的 registry 代理装载(dev)时不存在,历史上已踩坑。
113
113
  */
114
+ /**
115
+ * 长操作方法集(caps.exec):耗时由用户交互或传输决定,不受常规 30s 约束——
116
+ * ensureAttachment(同意弹窗 + 下载几十 MB)、localize(输入视频落地)、
117
+ * expandZip(大包解压)、pickDirectory/pickFile(等用户选)、registerOutput
118
+ * (录入判重命中时等用户裁决)。进度经 onAttachment/onUpload 事件流实时下发,
119
+ * 超时只兜底「宿主死了」的极端场景(10 分钟)。
120
+ */
121
+ const LONG_RUNNING_INVOKE_METHODS = new Set([
122
+ "caps.exec.ensureAttachment",
123
+ "caps.exec.localize",
124
+ "caps.exec.expandZip",
125
+ "caps.exec.pickDirectory",
126
+ "caps.exec.pickFile",
127
+ "caps.exec.registerOutput",
128
+ ]);
129
+ const DEFAULT_INVOKE_TIMEOUT_MS = 30_000;
130
+ const DEFAULT_LONG_INVOKE_TIMEOUT_MS = 10 * 60_000;
114
131
  /** 分层可测:纯端口逻辑(不碰 window),单测用 Node MessageChannel 直连 broker。 */
115
132
  export function connectMbwsPort(port, init, opts = {}) {
116
- const invokeTimeoutMs = opts.invokeTimeoutMs ?? 30_000;
133
+ const invokeTimeoutMs = opts.invokeTimeoutMs ?? DEFAULT_INVOKE_TIMEOUT_MS;
117
134
  const pending = new Map();
118
135
  const abortController = new AbortController();
119
136
  let beforeCloseCb = null;
@@ -122,13 +139,18 @@ export function connectMbwsPort(port, init, opts = {}) {
122
139
  };
123
140
  const invoke = (ns, method, args) => new Promise((resolve, reject) => {
124
141
  const callId = uuid();
142
+ // 显式 invokeTimeoutMs 优先(全量覆盖);否则长操作方法走独立的长超时
143
+ const timeoutMs = opts.invokeTimeoutMs ??
144
+ (LONG_RUNNING_INVOKE_METHODS.has(`${ns}.${method}`)
145
+ ? (opts.longInvokeTimeoutMs ?? DEFAULT_LONG_INVOKE_TIMEOUT_MS)
146
+ : invokeTimeoutMs);
125
147
  const timer = setTimeout(() => {
126
148
  pending.delete(callId);
127
149
  reject(new MbwsInvokeError({
128
150
  code: MBWS_ERROR_CODES.E_TIMEOUT,
129
151
  message: `${ns}.${method} 调用超时`,
130
152
  }));
131
- }, invokeTimeoutMs);
153
+ }, timeoutMs);
132
154
  pending.set(callId, { resolve, reject, timer });
133
155
  post({
134
156
  v: PROTOCOL_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mbws/plugin-sdk",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Moye 插件开发 SDK——panel/viewer 与宿主的类型定义与运行时端口适配",
5
5
  "license": "MIT",
6
6
  "type": "module",