@mbws/plugin-sdk 0.4.0 → 0.5.4
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/dist/client.d.ts +7 -5
- package/dist/client.js +24 -2
- package/package.json +38 -18
package/dist/client.d.ts
CHANGED
|
@@ -405,11 +405,13 @@ export interface CreateMbwsOptions {
|
|
|
405
405
|
timeoutMs?: number;
|
|
406
406
|
/** 单次 invoke 的默认超时(ms),超时按 E_TIMEOUT 拒绝。默认 30_000。 */
|
|
407
407
|
invokeTimeoutMs?: number;
|
|
408
|
+
/**
|
|
409
|
+
* 长操作方法(ensureAttachment/localize/expandZip/pick 系列/registerOutput)的独立
|
|
410
|
+
* 超时(ms)。默认 600_000——这些调用等用户交互或传输大文件,进度走事件流,
|
|
411
|
+
* 30s 常规超时会在 Windows 首次使用(同意弹窗 + 下载附件)时误杀。
|
|
412
|
+
*/
|
|
413
|
+
longInvokeTimeoutMs?: number;
|
|
408
414
|
}
|
|
409
|
-
/**
|
|
410
|
-
* callId 生成走专用 uuid()(getRandomValues 直拼)——randomUUID 是 secure-context-only,
|
|
411
|
-
* 插件面板经 http 的 registry 代理装载(dev)时不存在,历史上已踩坑。
|
|
412
|
-
*/
|
|
413
415
|
/** 分层可测:纯端口逻辑(不碰 window),单测用 Node MessageChannel 直连 broker。 */
|
|
414
416
|
export declare function connectMbwsPort<C extends MbwsContractTypes = MbwsContractTypes>(port: MessagePort, init: {
|
|
415
417
|
grants: string[];
|
|
@@ -418,7 +420,7 @@ export declare function connectMbwsPort<C extends MbwsContractTypes = MbwsContra
|
|
|
418
420
|
autoParams?: Record<string, unknown>;
|
|
419
421
|
theme?: Record<string, string>;
|
|
420
422
|
attachments?: AttachmentState[];
|
|
421
|
-
}, opts?: Pick<CreateMbwsOptions, "invokeTimeoutMs">): MbwsClient<C>;
|
|
423
|
+
}, opts?: Pick<CreateMbwsOptions, "invokeTimeoutMs" | "longInvokeTimeoutMs">): MbwsClient<C>;
|
|
422
424
|
/**
|
|
423
425
|
* 生产引导的窗口层:等宿主 init(带端口),超时/顶窗口降级 dev mock。
|
|
424
426
|
* 抽成独立函数(接受窗口注入)以支持单测用假 window 驱动。
|
package/dist/client.js
CHANGED
|
@@ -93,9 +93,26 @@ export function reserveOutputInvalid(req) {
|
|
|
93
93
|
* callId 生成走专用 uuid()(getRandomValues 直拼)——randomUUID 是 secure-context-only,
|
|
94
94
|
* 插件面板经 http 的 registry 代理装载(dev)时不存在,历史上已踩坑。
|
|
95
95
|
*/
|
|
96
|
+
/**
|
|
97
|
+
* 长操作方法集(caps.exec):耗时由用户交互或传输决定,不受常规 30s 约束——
|
|
98
|
+
* ensureAttachment(同意弹窗 + 下载几十 MB)、localize(输入视频落地)、
|
|
99
|
+
* expandZip(大包解压)、pickDirectory/pickFile(等用户选)、registerOutput
|
|
100
|
+
* (录入判重命中时等用户裁决)。进度经 onAttachment/onUpload 事件流实时下发,
|
|
101
|
+
* 超时只兜底「宿主死了」的极端场景(10 分钟)。
|
|
102
|
+
*/
|
|
103
|
+
const LONG_RUNNING_INVOKE_METHODS = new Set([
|
|
104
|
+
"caps.exec.ensureAttachment",
|
|
105
|
+
"caps.exec.localize",
|
|
106
|
+
"caps.exec.expandZip",
|
|
107
|
+
"caps.exec.pickDirectory",
|
|
108
|
+
"caps.exec.pickFile",
|
|
109
|
+
"caps.exec.registerOutput",
|
|
110
|
+
]);
|
|
111
|
+
const DEFAULT_INVOKE_TIMEOUT_MS = 30_000;
|
|
112
|
+
const DEFAULT_LONG_INVOKE_TIMEOUT_MS = 10 * 60_000;
|
|
96
113
|
/** 分层可测:纯端口逻辑(不碰 window),单测用 Node MessageChannel 直连 broker。 */
|
|
97
114
|
export function connectMbwsPort(port, init, opts = {}) {
|
|
98
|
-
const invokeTimeoutMs = opts.invokeTimeoutMs ??
|
|
115
|
+
const invokeTimeoutMs = opts.invokeTimeoutMs ?? DEFAULT_INVOKE_TIMEOUT_MS;
|
|
99
116
|
const pending = new Map();
|
|
100
117
|
const abortController = new AbortController();
|
|
101
118
|
let beforeCloseCb = null;
|
|
@@ -104,13 +121,18 @@ export function connectMbwsPort(port, init, opts = {}) {
|
|
|
104
121
|
};
|
|
105
122
|
const invoke = (ns, method, args) => new Promise((resolve, reject) => {
|
|
106
123
|
const callId = uuid();
|
|
124
|
+
// 显式 invokeTimeoutMs 优先(全量覆盖);否则长操作方法走独立的长超时
|
|
125
|
+
const timeoutMs = opts.invokeTimeoutMs ??
|
|
126
|
+
(LONG_RUNNING_INVOKE_METHODS.has(`${ns}.${method}`)
|
|
127
|
+
? (opts.longInvokeTimeoutMs ?? DEFAULT_LONG_INVOKE_TIMEOUT_MS)
|
|
128
|
+
: invokeTimeoutMs);
|
|
107
129
|
const timer = setTimeout(() => {
|
|
108
130
|
pending.delete(callId);
|
|
109
131
|
reject(new MbwsInvokeError({
|
|
110
132
|
code: MBWS_ERROR_CODES.E_TIMEOUT,
|
|
111
133
|
message: `${ns}.${method} 调用超时`,
|
|
112
134
|
}));
|
|
113
|
-
},
|
|
135
|
+
}, timeoutMs);
|
|
114
136
|
pending.set(callId, { resolve, reject, timer });
|
|
115
137
|
post({
|
|
116
138
|
v: PROTOCOL_VERSION,
|
package/package.json
CHANGED
|
@@ -1,42 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbws/plugin-sdk",
|
|
3
|
-
"version": "0.4
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Moye 插件开发 SDK——panel/viewer 与宿主的类型定义与运行时端口适配",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "./
|
|
8
|
-
"types": "./
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"@mbws/source": "./src/index.ts",
|
|
12
|
+
"types": "./src/index.ts",
|
|
13
|
+
"default": "./src/index.ts"
|
|
13
14
|
},
|
|
14
15
|
"./package.json": "./package.json",
|
|
15
16
|
"./vite": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
17
|
+
"@mbws/source": "./src/vite.ts",
|
|
18
|
+
"types": "./src/vite.ts",
|
|
19
|
+
"default": "./src/vite.ts"
|
|
18
20
|
},
|
|
19
21
|
"./expand-zip": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
+
"@mbws/source": "./src/expand-zip.ts",
|
|
23
|
+
"types": "./src/expand-zip.ts",
|
|
24
|
+
"default": "./src/expand-zip.ts"
|
|
22
25
|
}
|
|
23
26
|
},
|
|
24
27
|
"publishConfig": {
|
|
25
|
-
"access": "public"
|
|
28
|
+
"access": "public",
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json",
|
|
37
|
+
"./vite": {
|
|
38
|
+
"types": "./dist/vite.d.ts",
|
|
39
|
+
"default": "./dist/vite.js"
|
|
40
|
+
},
|
|
41
|
+
"./expand-zip": {
|
|
42
|
+
"types": "./dist/expand-zip.d.ts",
|
|
43
|
+
"default": "./dist/expand-zip.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
26
46
|
},
|
|
27
47
|
"files": [
|
|
28
48
|
"dist"
|
|
29
49
|
],
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"json-schema-to-typescript": "^16.0.0",
|
|
32
|
-
"zod": "^4.4.3"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"vite": "^8.0.14"
|
|
36
|
-
},
|
|
37
50
|
"scripts": {
|
|
38
51
|
"build": "node -e \"fs.rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
39
52
|
"test": "vitest run",
|
|
40
53
|
"pack:sdk": "pnpm build && pnpm pack"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"json-schema-to-typescript": "catalog:",
|
|
57
|
+
"zod": "catalog:"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"vite": "catalog:"
|
|
41
61
|
}
|
|
42
|
-
}
|
|
62
|
+
}
|