@mbws/plugin-sdk 0.3.22 → 0.5.3
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 +231 -2
- package/dist/caps.d.ts +1 -1
- package/dist/caps.js +4 -0
- package/dist/client.d.ts +77 -0
- package/dist/client.js +117 -3
- package/dist/config.d.ts +62 -0
- package/dist/dev-mock.js +128 -1
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +6 -0
- package/dist/manifest.d.ts +38 -0
- package/dist/manifest.js +69 -0
- package/dist/protocol.d.ts +35 -1
- package/dist/protocol.js +67 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vite.d.ts +9 -0
- package/dist/vite.js +103 -4
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -19,6 +19,63 @@ import { type AttachmentDecl, type AttachmentRef, type Manifest } from "./manife
|
|
|
19
19
|
*/
|
|
20
20
|
declare const UserConfigSchema: z.ZodObject<{
|
|
21
21
|
version: z.ZodString;
|
|
22
|
+
panel: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
display: z.ZodDefault<z.ZodEnum<{
|
|
24
|
+
default: "default";
|
|
25
|
+
maximized: "maximized";
|
|
26
|
+
}>>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
auto: z.ZodOptional<z.ZodObject<{
|
|
29
|
+
params: z.ZodUnion<readonly [z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodType<string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | {
|
|
30
|
+
[key: string]: string | number | boolean | /*elided*/ any | /*elided*/ any | null;
|
|
31
|
+
} | null)[] | {
|
|
32
|
+
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
33
|
+
} | null)[] | {
|
|
34
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
35
|
+
} | null)[] | {
|
|
36
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
37
|
+
} | null)[] | {
|
|
38
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
39
|
+
} | null)[] | {
|
|
40
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
41
|
+
} | null)[] | {
|
|
42
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
43
|
+
} | null)[] | {
|
|
44
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
45
|
+
} | null)[] | {
|
|
46
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
47
|
+
} | null)[] | {
|
|
48
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
49
|
+
} | null)[] | {
|
|
50
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
51
|
+
} | null)[] | {
|
|
52
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
53
|
+
} | null, unknown, z.core.$ZodTypeInternals<string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | {
|
|
54
|
+
[key: string]: string | number | boolean | /*elided*/ any | /*elided*/ any | null;
|
|
55
|
+
} | null)[] | {
|
|
56
|
+
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
57
|
+
} | null)[] | {
|
|
58
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
59
|
+
} | null)[] | {
|
|
60
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
61
|
+
} | null)[] | {
|
|
62
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
63
|
+
} | null)[] | {
|
|
64
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
65
|
+
} | null)[] | {
|
|
66
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
67
|
+
} | null)[] | {
|
|
68
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
69
|
+
} | null)[] | {
|
|
70
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
71
|
+
} | null)[] | {
|
|
72
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
73
|
+
} | null)[] | {
|
|
74
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
75
|
+
} | null)[] | {
|
|
76
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
77
|
+
} | null, unknown>>>]>;
|
|
78
|
+
}, z.core.$strip>>;
|
|
22
79
|
kind: z.ZodEnum<{
|
|
23
80
|
producer: "producer";
|
|
24
81
|
validator: "validator";
|
|
@@ -73,6 +130,11 @@ declare const UserConfigSchema: z.ZodObject<{
|
|
|
73
130
|
} | null)[] | {
|
|
74
131
|
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
75
132
|
} | null, unknown>>>]>>;
|
|
133
|
+
credentials: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
134
|
+
name: z.ZodString;
|
|
135
|
+
env: z.ZodString;
|
|
136
|
+
description: z.ZodOptional<z.ZodString>;
|
|
137
|
+
}, z.core.$strip>>>;
|
|
76
138
|
permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
77
139
|
automation: z.ZodEnum<{
|
|
78
140
|
batchable: "batchable";
|
package/dist/dev-mock.js
CHANGED
|
@@ -23,12 +23,25 @@
|
|
|
23
23
|
* (.mbws/attachments/ 缓存命中 = ready,否则 missing),attachmentStatus 本地读。
|
|
24
24
|
*/
|
|
25
25
|
import { asMbwsRef, CAPS_EXEC_METHODS, CAPS_UPLOADS_METHODS, METHOD_INTRODUCED_AT, mergeAttachmentEvent, mergeUploadEvent, sdkVersionAtLeast, } from "./caps.js";
|
|
26
|
-
import { jobFailedError, MbwsInvokeError, reserveOutputInvalid, writeFileInvalid, } from "./client.js";
|
|
26
|
+
import { jobFailedError, MbwsInvokeError, removePathInvalid, reserveOutputInvalid, writeFileInvalid, } from "./client.js";
|
|
27
27
|
import { contractFieldAllowed, fetchContract } from "./contract.js";
|
|
28
28
|
import { isStorageKeyValid, MemoryDevStorage, utf8ByteLength } from "./dev-storage.js";
|
|
29
29
|
import { MBWS_ERROR_CODES } from "./errors.js";
|
|
30
30
|
import { SDK_VERSION } from "./version.js";
|
|
31
31
|
const DEV_REPLAY_MAX_LINES = 200;
|
|
32
|
+
/** 工作区预览 MIME 白名单(与宿主 plugin-caps 的 PREVIEW_MIME 同口径:仅图片/视频) */
|
|
33
|
+
const DEV_PREVIEW_MIME = {
|
|
34
|
+
".png": "image/png",
|
|
35
|
+
".jpg": "image/jpeg",
|
|
36
|
+
".jpeg": "image/jpeg",
|
|
37
|
+
".webp": "image/webp",
|
|
38
|
+
".gif": "image/gif",
|
|
39
|
+
".bmp": "image/bmp",
|
|
40
|
+
".mp4": "video/mp4",
|
|
41
|
+
".m4v": "video/mp4",
|
|
42
|
+
".webm": "video/webm",
|
|
43
|
+
".mov": "video/quicktime",
|
|
44
|
+
};
|
|
32
45
|
/** 与宿主 job.read 同口径:默认 1MB、硬上限 4MB(超过按 null 回,不读) */
|
|
33
46
|
const DEV_READ_DEFAULT_BYTES = 1024 * 1024;
|
|
34
47
|
const DEV_READ_MAX_BYTES = 4 * 1024 * 1024;
|
|
@@ -168,6 +181,46 @@ async function writeDevFile(req) {
|
|
|
168
181
|
}
|
|
169
182
|
throw new MbwsInvokeError({ code: code, message });
|
|
170
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* dev remove:删除工程目录内的文件/目录(递归、幂等)。越界校验与宿主同形
|
|
186
|
+
* (相对路径 / `..` 段 / 等于根拒),由 `/__mbws__/dev/remove` 中间件执行;
|
|
187
|
+
* 端点不可达(非 vite dev)时无盘可删,按能力不可用拒绝——不假装成功。
|
|
188
|
+
* 上传引用联动(E_PATH_IN_USE)仅桌面宿主有——dev 假上传队列不记磁盘路径。
|
|
189
|
+
*/
|
|
190
|
+
async function removeDevFile(path) {
|
|
191
|
+
const invalid = removePathInvalid(path);
|
|
192
|
+
if (invalid)
|
|
193
|
+
throw invalid;
|
|
194
|
+
let response;
|
|
195
|
+
try {
|
|
196
|
+
response = await fetch("/__mbws__/dev/remove", {
|
|
197
|
+
method: "POST",
|
|
198
|
+
headers: { "content-type": "application/json" },
|
|
199
|
+
body: JSON.stringify({ path }),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
throw new MbwsInvokeError({
|
|
204
|
+
code: MBWS_ERROR_CODES.E_CAPABILITY_UNAVAILABLE,
|
|
205
|
+
message: "caps.exec.remove 需要 vite dev server(mbwsVitePlugin 中间件执行删除)",
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (response.ok)
|
|
209
|
+
return;
|
|
210
|
+
let code = MBWS_ERROR_CODES.E_INVALID_ARGS;
|
|
211
|
+
let message = "删除失败";
|
|
212
|
+
try {
|
|
213
|
+
const body = (await response.json());
|
|
214
|
+
if (typeof body.message === "string" && body.message)
|
|
215
|
+
message = body.message;
|
|
216
|
+
if (body.code === MBWS_ERROR_CODES.E_INVALID_ARGS)
|
|
217
|
+
code = body.code;
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
// 非 JSON 错误体用默认文案
|
|
221
|
+
}
|
|
222
|
+
throw new MbwsInvokeError({ code: code, message });
|
|
223
|
+
}
|
|
171
224
|
// ===== 宿主面模拟(MBWS_DEV_HOST_FACE=<ver>):模拟旧宿主缺席新方法 =====
|
|
172
225
|
/**
|
|
173
226
|
* 面版本来源:浏览器经 vite define 注入的 process.env.MBWS_DEV_HOST_FACE
|
|
@@ -640,6 +693,15 @@ function storageKeyInvalid(key) {
|
|
|
640
693
|
export function createDevMockMbws() {
|
|
641
694
|
// 无 dev server 时的 storage 兜底(每个客户端一份 = 页面生命周期)
|
|
642
695
|
const memoryStorage = new MemoryDevStorage();
|
|
696
|
+
// dev auto 面(0.4.0):与端口客户端同形——注册只存回调,不自动触发(dev 无宿主
|
|
697
|
+
// 发 mode=auto 的 init);window.__mbwsDev.autoRun(params?) 手动驱动(harness/开发者
|
|
698
|
+
// 手测 auto 分支用,params 即宿主按 manifest.auto.params 收集后下发的运行参数——
|
|
699
|
+
// 缺省空对象,与端口客户端 init.autoParams 缺省回落同形)。会话级单执行:与端口
|
|
700
|
+
// 客户端 autoStarted 同语义。
|
|
701
|
+
let devAutoStarted = false;
|
|
702
|
+
const devAutoController = new AbortController();
|
|
703
|
+
let devAutoRunCb = null;
|
|
704
|
+
let devAutoDoneResult = null;
|
|
643
705
|
const client = {
|
|
644
706
|
data: {
|
|
645
707
|
inputs: fetchDevSamples,
|
|
@@ -783,9 +845,36 @@ export function createDevMockMbws() {
|
|
|
783
845
|
return (await response.json());
|
|
784
846
|
},
|
|
785
847
|
spawn: (req) => spawnDevJob(req),
|
|
848
|
+
// 工作区文件预览(0.5.0):dev 工作区 = 工程根(spawn cwd 同源),直接映射到
|
|
849
|
+
// dev 文件端点(Range/MIME 齐备,handleDevFile);存在性交给端点 404(dev 惰性
|
|
850
|
+
// 口径,与 mediaUrl 的 devlocal 分支同风格)。路径/扩展名校验与宿主同形。
|
|
851
|
+
previewUrl: async (pathArg) => {
|
|
852
|
+
const rel = pathArg ?? "";
|
|
853
|
+
if (!rel ||
|
|
854
|
+
/^(?:[a-zA-Z]:[\\/]|\\\\|\/)/.test(rel) ||
|
|
855
|
+
rel.split(/[/\\]/).includes("..")) {
|
|
856
|
+
throw new MbwsInvokeError({
|
|
857
|
+
code: MBWS_ERROR_CODES.E_INVALID_ARGS,
|
|
858
|
+
message: "path 须为工作区内的相对路径",
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
const ext = rel.slice(rel.lastIndexOf(".")).toLowerCase();
|
|
862
|
+
const mime = DEV_PREVIEW_MIME[ext];
|
|
863
|
+
if (!mime) {
|
|
864
|
+
throw new MbwsInvokeError({
|
|
865
|
+
code: MBWS_ERROR_CODES.E_INVALID_ARGS,
|
|
866
|
+
message: "仅支持图片/视频预览",
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
return Promise.resolve({
|
|
870
|
+
url: `/__mbws__/dev/file?path=${encodeURIComponent(rel)}`,
|
|
871
|
+
mime,
|
|
872
|
+
});
|
|
873
|
+
},
|
|
786
874
|
attachJob: (jobId) => Promise.resolve(attachDevJob(jobId)),
|
|
787
875
|
jobResult: (jobId) => Promise.resolve(devJobResult(jobId)),
|
|
788
876
|
writeFile: (req) => writeDevFile(req),
|
|
877
|
+
remove: (path) => removeDevFile(path),
|
|
789
878
|
// 落点契约与宿主 reserveTargetDir 同形(共享 reserveOutputInvalid):无绝对
|
|
790
879
|
// dir 且无 jobId 拒 E_INVALID_ARGS——job 沙箱是 spawn 时才建的,spawn 前不
|
|
791
880
|
// 存在,缺省落点本就无从解析(真宿主必拒,dev 不能静默放过:face-mosaic
|
|
@@ -997,7 +1086,45 @@ export function createDevMockMbws() {
|
|
|
997
1086
|
return contractFieldAllowed(devContractSnapshot.outputs, outputKey, fieldPath);
|
|
998
1087
|
},
|
|
999
1088
|
},
|
|
1089
|
+
// auto 无头执行面 dev mock:注册只存回调(dev 无宿主发 mode=auto 的 init,不会
|
|
1090
|
+
// 自动进 auto 形态);经 window.__mbwsDev.autoRun() 手动驱动——面板/自动两分支
|
|
1091
|
+
// 同一份插件代码在浏览器 dev 即可联调。回调抛错 console.warn(dev 无宿主可发
|
|
1092
|
+
// auto:error),单执行语义与端口客户端一致
|
|
1093
|
+
auto: {
|
|
1094
|
+
onRun: (cb, _opts) => {
|
|
1095
|
+
// opts.timeoutMs(超时协商)dev 无宿主可发 auto:ready——收下不动作(dev 无超时)
|
|
1096
|
+
devAutoRunCb = cb;
|
|
1097
|
+
},
|
|
1098
|
+
// dev 同形:done 只记状态(无宿主可发 auto:done,控制台留痕);重复调用忽略
|
|
1099
|
+
done: (result) => {
|
|
1100
|
+
console.info("[mbws:dev] auto.done", result.status, result.message ?? "");
|
|
1101
|
+
devAutoDoneResult = { ...result };
|
|
1102
|
+
},
|
|
1103
|
+
},
|
|
1000
1104
|
};
|
|
1105
|
+
// dev 触发口:autoRun() 手动驱动 auto 分支(幂等——会话内只执行首个注册的回调)
|
|
1106
|
+
if (typeof window !== "undefined") {
|
|
1107
|
+
const win = window;
|
|
1108
|
+
const devFace = win.__mbwsDev ?? {};
|
|
1109
|
+
devFace.autoRun = async (params) => {
|
|
1110
|
+
if (devAutoStarted || !devAutoRunCb)
|
|
1111
|
+
return;
|
|
1112
|
+
devAutoStarted = true;
|
|
1113
|
+
try {
|
|
1114
|
+
await devAutoRunCb({
|
|
1115
|
+
params: params ?? {},
|
|
1116
|
+
signal: devAutoController.signal,
|
|
1117
|
+
timeoutMs: 300_000,
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
catch (error) {
|
|
1121
|
+
console.warn("[mbws:dev] auto.onRun 回调抛错", error);
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
// 上一次 auto.done 的结果(harness/开发者断言 skipped/failed 分支用)
|
|
1125
|
+
devFace.autoDone = () => devAutoDoneResult;
|
|
1126
|
+
win.__mbwsDev = devFace;
|
|
1127
|
+
}
|
|
1001
1128
|
// 面模拟收尾:不满足 face 的方法属性从对象上真删(capabilities 列表已过滤,
|
|
1002
1129
|
// 这里让 typeof 探测的降级分支也真实成立)
|
|
1003
1130
|
if (readDevHostFace() && client.caps) {
|
package/dist/errors.d.ts
CHANGED
|
@@ -40,5 +40,11 @@ export declare const MBWS_ERROR_CODES: {
|
|
|
40
40
|
readonly E_CANCELLED: "E_CANCELLED";
|
|
41
41
|
/** 消息本身违反协议(缺 v、未知 type、方向错误) */
|
|
42
42
|
readonly E_PROTOCOL_VIOLATION: "E_PROTOCOL_VIOLATION";
|
|
43
|
+
/**
|
|
44
|
+
* 路径被本插件上传队列活跃条目(reserved/registered/pending/uploading)引用,
|
|
45
|
+
* 暂不可删/不可清理——待上传终态(done/failed)或 purge 后重试。
|
|
46
|
+
* 与 E_INVALID_ARGS 的区别:参数本身合法,是暂时性占用状态
|
|
47
|
+
*/
|
|
48
|
+
readonly E_PATH_IN_USE: "E_PATH_IN_USE";
|
|
43
49
|
};
|
|
44
50
|
export type MbwsErrorCode = (typeof MBWS_ERROR_CODES)[keyof typeof MBWS_ERROR_CODES];
|
package/dist/errors.js
CHANGED
|
@@ -40,4 +40,10 @@ export const MBWS_ERROR_CODES = {
|
|
|
40
40
|
E_CANCELLED: "E_CANCELLED",
|
|
41
41
|
/** 消息本身违反协议(缺 v、未知 type、方向错误) */
|
|
42
42
|
E_PROTOCOL_VIOLATION: "E_PROTOCOL_VIOLATION",
|
|
43
|
+
/**
|
|
44
|
+
* 路径被本插件上传队列活跃条目(reserved/registered/pending/uploading)引用,
|
|
45
|
+
* 暂不可删/不可清理——待上传终态(done/failed)或 purge 后重试。
|
|
46
|
+
* 与 E_INVALID_ARGS 的区别:参数本身合法,是暂时性占用状态
|
|
47
|
+
*/
|
|
48
|
+
E_PATH_IN_USE: "E_PATH_IN_USE",
|
|
43
49
|
};
|
package/dist/manifest.d.ts
CHANGED
|
@@ -60,6 +60,30 @@ export declare const AttachmentRefSchema: z.ZodObject<{
|
|
|
60
60
|
url: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
61
61
|
}, z.core.$strip>;
|
|
62
62
|
export type AttachmentRef = z.output<typeof AttachmentRefSchema>;
|
|
63
|
+
/**
|
|
64
|
+
* 凭据环境变量名格式:大写字母/数字/下划线,首字符不可为数字(跨平台惯例,
|
|
65
|
+
* 且避免与 shell 特殊变量如 `$1` / `$PATH` 的小写形态混淆)。
|
|
66
|
+
*/
|
|
67
|
+
export declare const CREDENTIAL_ENV_RE: RegExp;
|
|
68
|
+
/**
|
|
69
|
+
* 宿主关键环境变量禁改清单:凭据注入不得覆盖宿主/Node 运行时赖以工作的变量
|
|
70
|
+
* (PATH 劫持、NODE_OPTIONS 注入等)。桌面 main 与 vite dev 注入前都会再验一遍(纵深防御)。
|
|
71
|
+
*/
|
|
72
|
+
export declare const CRITICAL_ENV_NAMES: Set<string>;
|
|
73
|
+
/** 关键环境变量判定(CRITICAL_ENV_NAMES 全集 + NODE_* 前缀兜底)。 */
|
|
74
|
+
export declare function isCriticalEnvName(name: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* 凭据声明(0.5.0 起,可选):插件声明它在附件二进制里读哪些环境变量,
|
|
77
|
+
* 用户在桌面端「设置 → 插件凭据」按声明填值,宿主 spawn 时只注入**声明过的** env 名——
|
|
78
|
+
* 声明即白名单,环境变量不可能成为面板侧的任意注入/外泄通道(spawn 请求无 env 字段)。
|
|
79
|
+
* 值只落本机(plugin-credentials.json),不上传服务端、不进产物。
|
|
80
|
+
*/
|
|
81
|
+
export declare const ManifestCredentialSchema: z.ZodObject<{
|
|
82
|
+
name: z.ZodString;
|
|
83
|
+
env: z.ZodString;
|
|
84
|
+
description: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
export type ManifestCredential = z.output<typeof ManifestCredentialSchema>;
|
|
63
87
|
export declare const ManifestSchema: z.ZodObject<{
|
|
64
88
|
id: z.ZodString;
|
|
65
89
|
version: z.ZodString;
|
|
@@ -84,15 +108,29 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
84
108
|
}>>;
|
|
85
109
|
}, z.core.$strip>>;
|
|
86
110
|
}, z.core.$strip>>>;
|
|
111
|
+
credentials: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
112
|
+
name: z.ZodString;
|
|
113
|
+
env: z.ZodString;
|
|
114
|
+
description: z.ZodOptional<z.ZodString>;
|
|
115
|
+
}, z.core.$strip>>>;
|
|
87
116
|
permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
88
117
|
automation: z.ZodEnum<{
|
|
89
118
|
batchable: "batchable";
|
|
90
119
|
"interactive-only": "interactive-only";
|
|
91
120
|
}>;
|
|
121
|
+
auto: z.ZodOptional<z.ZodObject<{
|
|
122
|
+
params: z.ZodUnion<readonly [z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>]>;
|
|
123
|
+
}, z.core.$strip>>;
|
|
92
124
|
components: z.ZodOptional<z.ZodObject<{
|
|
93
125
|
panel: z.ZodOptional<z.ZodString>;
|
|
94
126
|
viewer: z.ZodOptional<z.ZodString>;
|
|
95
127
|
}, z.core.$strip>>;
|
|
128
|
+
panel: z.ZodOptional<z.ZodObject<{
|
|
129
|
+
display: z.ZodDefault<z.ZodEnum<{
|
|
130
|
+
default: "default";
|
|
131
|
+
maximized: "maximized";
|
|
132
|
+
}>>;
|
|
133
|
+
}, z.core.$strip>>;
|
|
96
134
|
sdk: z.ZodOptional<z.ZodString>;
|
|
97
135
|
meta: z.ZodObject<{
|
|
98
136
|
title: z.ZodString;
|
package/dist/manifest.js
CHANGED
|
@@ -80,6 +80,52 @@ export const AttachmentRefSchema = AttachmentDeclSchema.omit({ platforms: true }
|
|
|
80
80
|
devPath: z.string().optional(),
|
|
81
81
|
url: z.union([z.string(), z.record(z.string(), z.string())]).optional(),
|
|
82
82
|
});
|
|
83
|
+
/**
|
|
84
|
+
* 凭据环境变量名格式:大写字母/数字/下划线,首字符不可为数字(跨平台惯例,
|
|
85
|
+
* 且避免与 shell 特殊变量如 `$1` / `$PATH` 的小写形态混淆)。
|
|
86
|
+
*/
|
|
87
|
+
export const CREDENTIAL_ENV_RE = /^[A-Z_][A-Z0-9_]*$/;
|
|
88
|
+
/**
|
|
89
|
+
* 宿主关键环境变量禁改清单:凭据注入不得覆盖宿主/Node 运行时赖以工作的变量
|
|
90
|
+
* (PATH 劫持、NODE_OPTIONS 注入等)。桌面 main 与 vite dev 注入前都会再验一遍(纵深防御)。
|
|
91
|
+
*/
|
|
92
|
+
export const CRITICAL_ENV_NAMES = new Set([
|
|
93
|
+
"PATH",
|
|
94
|
+
"HOME",
|
|
95
|
+
"TMPDIR",
|
|
96
|
+
"SHELL",
|
|
97
|
+
"USER",
|
|
98
|
+
"LOGNAME",
|
|
99
|
+
"LANG",
|
|
100
|
+
"LC_ALL",
|
|
101
|
+
"PWD",
|
|
102
|
+
"NODE_OPTIONS",
|
|
103
|
+
"NODE_PATH",
|
|
104
|
+
"NODE_ENV",
|
|
105
|
+
]);
|
|
106
|
+
/** 关键环境变量判定(CRITICAL_ENV_NAMES 全集 + NODE_* 前缀兜底)。 */
|
|
107
|
+
export function isCriticalEnvName(name) {
|
|
108
|
+
return CRITICAL_ENV_NAMES.has(name) || name.startsWith("NODE_");
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 凭据声明(0.5.0 起,可选):插件声明它在附件二进制里读哪些环境变量,
|
|
112
|
+
* 用户在桌面端「设置 → 插件凭据」按声明填值,宿主 spawn 时只注入**声明过的** env 名——
|
|
113
|
+
* 声明即白名单,环境变量不可能成为面板侧的任意注入/外泄通道(spawn 请求无 env 字段)。
|
|
114
|
+
* 值只落本机(plugin-credentials.json),不上传服务端、不进产物。
|
|
115
|
+
*/
|
|
116
|
+
export const ManifestCredentialSchema = z.object({
|
|
117
|
+
/** 展示名(设置页渲染用,如「通义千问 API Key」) */
|
|
118
|
+
name: z.string().min(1).max(64),
|
|
119
|
+
/** 注入的环境变量名(spawn 时唯一真正注入的名字) */
|
|
120
|
+
env: z
|
|
121
|
+
.string()
|
|
122
|
+
.regex(CREDENTIAL_ENV_RE)
|
|
123
|
+
.refine((v) => !isCriticalEnvName(v), {
|
|
124
|
+
message: "环境变量名不得覆盖宿主关键变量(PATH/HOME/NODE_* 等)",
|
|
125
|
+
}),
|
|
126
|
+
/** 填值指引(设置页渲染用) */
|
|
127
|
+
description: z.string().optional(),
|
|
128
|
+
});
|
|
83
129
|
/**
|
|
84
130
|
* 权限声明,两种语法(CSP connect-src 与权限预览文案的推导输入,设计稿 §6.5):
|
|
85
131
|
* - `ai.<purpose>`:走项目 AI 中心的调用(如 `ai.ocr`)
|
|
@@ -109,10 +155,22 @@ export const ManifestSchema = z.object({
|
|
|
109
155
|
* 取代旧 requiresCapabilities(typed 能力包模型已裁撤,见 docs/plan §7.6 偏离记录)。
|
|
110
156
|
*/
|
|
111
157
|
attachments: z.array(AttachmentDeclSchema).max(8).default([]),
|
|
158
|
+
/** 凭据声明(0.5.0):spawn 时按声明注入环境变量,值存本机凭据存储(见 ManifestCredentialSchema) */
|
|
159
|
+
credentials: z.array(ManifestCredentialSchema).max(16).default([]),
|
|
112
160
|
/** 权限逐条授予:consent 列表与 CSP 白名单的推导源 */
|
|
113
161
|
permissions: z.array(z.string().regex(PERMISSION_RE)).default([]),
|
|
114
162
|
/** interactive-only 不进入批量/自动驱动 */
|
|
115
163
|
automation: z.enum(["batchable", "interactive-only"]),
|
|
164
|
+
/**
|
|
165
|
+
* auto 无头执行声明(0.4.0 起,可选):
|
|
166
|
+
* - `params`:批量运行参数的 JSON Schema(object 形态,默认值内嵌
|
|
167
|
+
* `properties.*.default`)——宿主「本地工具批量预跑」入队时按它收集一次性参数
|
|
168
|
+
* (缺省不弹参数表单,零成本),收集值经 init.autoParams 下发、插件在
|
|
169
|
+
* `auto.onRun` 回调的 `ctx.params` 原样收到。与顶层 paramsSchema(spec 侧
|
|
170
|
+
* 参数位)互不相干:auto.params 只服务无头批量这一条通道;
|
|
171
|
+
* - 面板形态不消费本字段。
|
|
172
|
+
*/
|
|
173
|
+
auto: z.object({ params: JsonSchemaValue }).optional(),
|
|
116
174
|
/** 产物组件的 html 相对路径,缺省 `panel.html` / `viewer.html` */
|
|
117
175
|
components: z
|
|
118
176
|
.object({
|
|
@@ -120,6 +178,17 @@ export const ManifestSchema = z.object({
|
|
|
120
178
|
viewer: z.string().optional(),
|
|
121
179
|
})
|
|
122
180
|
.optional(),
|
|
181
|
+
/**
|
|
182
|
+
* 面板展示偏好(0.5.1 起,可选):复杂画布类工具(视频标注、大时间轴等)可声明
|
|
183
|
+
* `display: "maximized"`——宿主打开工具弹窗时直接最大化铺满视口(等价弹窗外壳的
|
|
184
|
+
* defaultFullscreen 初始态),用户仍可手动切回常规弹窗。只影响初始形态,
|
|
185
|
+
* 关闭询问/写回等行为面不变;宿主页面显式传 prop 时以页面为准。
|
|
186
|
+
*/
|
|
187
|
+
panel: z
|
|
188
|
+
.object({
|
|
189
|
+
display: z.enum(["default", "maximized"]).default("default"),
|
|
190
|
+
})
|
|
191
|
+
.optional(),
|
|
123
192
|
/** build 写入的 SDK 版本(版本闸门用),手写无效——市场发布时以构建器写入为准 */
|
|
124
193
|
sdk: z.string().optional(),
|
|
125
194
|
meta: z.object({
|
package/dist/protocol.d.ts
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* 与 PROTOCOL_VERSION 不符的消息按协议违规直接拒绝(不静默兼容)。
|
|
6
6
|
*
|
|
7
7
|
* 方向约定(防线在宿主 broker 对每条进入消息独立校验,本模块只是契约形状):
|
|
8
|
-
* - plugin → host:调用(mbws:invoke)、生命周期上报(panel:ready / panel:resize / panel:before-close-reply / mbws:init-ack)
|
|
8
|
+
* - plugin → host:调用(mbws:invoke)、生命周期上报(panel:ready / panel:resize / panel:before-close-reply / mbws:init-ack / auto:ready / auto:error / auto:done)
|
|
9
|
+
*
|
|
10
|
+
* auto 形态(mode=auto,0.4.0 起)的协议边界:**与容器无关**——本层消息族不依赖
|
|
11
|
+
* 「隐藏 iframe」这一宿主实现(将来可换 worker / 轻量 core 运行时,插件代码不改);
|
|
12
|
+
* 插件 auto 回调里不应依赖 DOM 可用(不保证 document/window 的 UI)。
|
|
9
13
|
* - host → plugin:握手(mbws:init)、调用结果(mbws:resolve / mbws:reject)、事件(mbws:event)、
|
|
10
14
|
* 生命周期询问(panel:before-close)
|
|
11
15
|
*/
|
|
@@ -24,6 +28,8 @@ export declare const MBWS_NAMESPACES: readonly ["data", "runtime", "storage", "u
|
|
|
24
28
|
* payload 形状见 caps.ts。
|
|
25
29
|
*/
|
|
26
30
|
export declare const MBWS_EVENT_KINDS: readonly ["progress", "log", "cancel", "theme", "job", "attachment", "upload", "viewer"];
|
|
31
|
+
/** auto:error message 的截断上限(与 panel:before-close-reply message 同口径) */
|
|
32
|
+
export declare const AUTO_ERROR_MESSAGE_MAX = 200;
|
|
27
33
|
/**
|
|
28
34
|
* 关闭询问等待插件应答的超时(ms):超时按「无未保存」放行(防插件锁死面板)。
|
|
29
35
|
* 宿主 broker 的缺省值与插件文档的口径都以本常量为准。
|
|
@@ -41,6 +47,12 @@ export declare const MbwsMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
41
47
|
type: z.ZodLiteral<"mbws:init">;
|
|
42
48
|
protocolVersion: z.ZodLiteral<1>;
|
|
43
49
|
grants: z.ZodArray<z.ZodString>;
|
|
50
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
51
|
+
panel: "panel";
|
|
52
|
+
auto: "auto";
|
|
53
|
+
}>>;
|
|
54
|
+
autoTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
55
|
+
autoParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
44
56
|
theme: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
45
57
|
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
46
58
|
name: z.ZodString;
|
|
@@ -74,6 +86,7 @@ export declare const MbwsMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
74
86
|
readonly E_TIMEOUT: "E_TIMEOUT";
|
|
75
87
|
readonly E_CANCELLED: "E_CANCELLED";
|
|
76
88
|
readonly E_PROTOCOL_VIOLATION: "E_PROTOCOL_VIOLATION";
|
|
89
|
+
readonly E_PATH_IN_USE: "E_PATH_IN_USE";
|
|
77
90
|
}>;
|
|
78
91
|
message: z.ZodOptional<z.ZodString>;
|
|
79
92
|
data: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -110,6 +123,24 @@ export declare const MbwsMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
110
123
|
}, z.core.$strip>, z.ZodObject<{
|
|
111
124
|
v: z.ZodLiteral<1>;
|
|
112
125
|
type: z.ZodLiteral<"panel:close">;
|
|
126
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
127
|
+
v: z.ZodLiteral<1>;
|
|
128
|
+
type: z.ZodLiteral<"auto:ready">;
|
|
129
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
130
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
131
|
+
v: z.ZodLiteral<1>;
|
|
132
|
+
type: z.ZodLiteral<"auto:error">;
|
|
133
|
+
message: z.ZodString;
|
|
134
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
135
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
136
|
+
v: z.ZodLiteral<1>;
|
|
137
|
+
type: z.ZodLiteral<"auto:done">;
|
|
138
|
+
status: z.ZodEnum<{
|
|
139
|
+
failed: "failed";
|
|
140
|
+
succeeded: "succeeded";
|
|
141
|
+
skipped: "skipped";
|
|
142
|
+
}>;
|
|
143
|
+
message: z.ZodOptional<z.ZodString>;
|
|
113
144
|
}, z.core.$strip>], "type">;
|
|
114
145
|
export type MbwsMessage = z.output<typeof MbwsMessageSchema>;
|
|
115
146
|
/** 消息方向表:契约形状层即可判定,broker 在此之上再做权限/配额校验 */
|
|
@@ -125,6 +156,9 @@ export declare const MESSAGE_DIRECTION: {
|
|
|
125
156
|
readonly "panel:before-close": "host-to-plugin";
|
|
126
157
|
readonly "panel:before-close-reply": "plugin-to-host";
|
|
127
158
|
readonly "panel:close": "plugin-to-host";
|
|
159
|
+
readonly "auto:ready": "plugin-to-host";
|
|
160
|
+
readonly "auto:error": "plugin-to-host";
|
|
161
|
+
readonly "auto:done": "plugin-to-host";
|
|
128
162
|
};
|
|
129
163
|
export type MessageDirection = (typeof MESSAGE_DIRECTION)[keyof typeof MESSAGE_DIRECTION];
|
|
130
164
|
export declare function isPluginToHost(message: MbwsMessage): boolean;
|
package/dist/protocol.js
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* 与 PROTOCOL_VERSION 不符的消息按协议违规直接拒绝(不静默兼容)。
|
|
6
6
|
*
|
|
7
7
|
* 方向约定(防线在宿主 broker 对每条进入消息独立校验,本模块只是契约形状):
|
|
8
|
-
* - plugin → host:调用(mbws:invoke)、生命周期上报(panel:ready / panel:resize / panel:before-close-reply / mbws:init-ack)
|
|
8
|
+
* - plugin → host:调用(mbws:invoke)、生命周期上报(panel:ready / panel:resize / panel:before-close-reply / mbws:init-ack / auto:ready / auto:error / auto:done)
|
|
9
|
+
*
|
|
10
|
+
* auto 形态(mode=auto,0.4.0 起)的协议边界:**与容器无关**——本层消息族不依赖
|
|
11
|
+
* 「隐藏 iframe」这一宿主实现(将来可换 worker / 轻量 core 运行时,插件代码不改);
|
|
12
|
+
* 插件 auto 回调里不应依赖 DOM 可用(不保证 document/window 的 UI)。
|
|
9
13
|
* - host → plugin:握手(mbws:init)、调用结果(mbws:resolve / mbws:reject)、事件(mbws:event)、
|
|
10
14
|
* 生命周期询问(panel:before-close)
|
|
11
15
|
*/
|
|
@@ -52,6 +56,27 @@ const InitMessage = z.object({
|
|
|
52
56
|
protocolVersion: z.literal(PROTOCOL_VERSION),
|
|
53
57
|
/** 本次授予的能力清单:客户端只构造已授予的命名空间(按授权构造) */
|
|
54
58
|
grants: z.array(z.string()),
|
|
59
|
+
/**
|
|
60
|
+
* 宿主装载形态(0.4.0 起可选):
|
|
61
|
+
* - panel(缺省):交互面板——用户打开工具弹窗的常规形态;
|
|
62
|
+
* - auto:无头自动执行(批量预跑)——宿主开隐藏 iframe 无人值守驱动,
|
|
63
|
+
* 插件注册 client.auto.onRun 后 SDK 发 auto:ready 握手。
|
|
64
|
+
* 旧宿主 init 不带 mode(zod 缺省)——插件侧 auto 面缺席即面板形态,零分支兼容。
|
|
65
|
+
*/
|
|
66
|
+
mode: z.enum(["panel", "auto"]).optional(),
|
|
67
|
+
/**
|
|
68
|
+
* auto 形态的总超时(ms,mode=auto 时宿主下发;插件可经 auto:ready.timeoutMs
|
|
69
|
+
* 协商上调,最终值 = max(宿主配置, 插件声明))。onRun 回调 ctx.timeoutMs 同源——
|
|
70
|
+
* 长任务据此自行设 checkpoint。旧宿主不带 → SDK 用缺省 300_000。
|
|
71
|
+
*/
|
|
72
|
+
autoTimeoutMs: z.number().positive().optional(),
|
|
73
|
+
/**
|
|
74
|
+
* auto 形态的运行参数(mode=auto 时宿主下发;形状 = manifest.auto.params 收集值,
|
|
75
|
+
* 平铺键值)。插件侧 SDK 原样放进 onRun 回调的 ctx.params——插件按声明自己的
|
|
76
|
+
* schema 消费,协议层不做二次校验(收集侧按 schema 生成表单,天然合形)。
|
|
77
|
+
* 旧宿主/面板形态不带——ctx.params 回落空对象。
|
|
78
|
+
*/
|
|
79
|
+
autoParams: z.record(z.string(), z.unknown()).optional(),
|
|
55
80
|
/** 主题 token 表(CSS 自定义属性 → 值),插件侧写入 :root 跟随宿主主题 */
|
|
56
81
|
theme: z.record(z.string(), z.string()).optional(),
|
|
57
82
|
/**
|
|
@@ -123,6 +148,41 @@ const PanelCloseMessage = z.object({
|
|
|
123
148
|
v: z.literal(PROTOCOL_VERSION),
|
|
124
149
|
type: z.literal("panel:close"),
|
|
125
150
|
});
|
|
151
|
+
/**
|
|
152
|
+
* auto 模式握手(0.4.0 起,mode=auto 装载形态专用):
|
|
153
|
+
* 插件注册 client.auto.onRun 后 SDK 发 auto:ready——宿主据此确认「本插件支持
|
|
154
|
+
* 无头自动执行」(旧 SDK 插件不发 → 宿主按 no-auto 快速失败,不耗整条超时猜)。
|
|
155
|
+
* timeoutMs(可选,正数):插件声明本次执行的建议超时上限——宿主取
|
|
156
|
+
* max(声明值, 自身配置) 计算总超时(视频类长任务按需协商,缺省 300s)。
|
|
157
|
+
*/
|
|
158
|
+
const AutoReadyMessage = z.object({
|
|
159
|
+
v: z.literal(PROTOCOL_VERSION),
|
|
160
|
+
type: z.literal("auto:ready"),
|
|
161
|
+
timeoutMs: z.number().positive().optional(),
|
|
162
|
+
});
|
|
163
|
+
/** auto 模式执行失败上报(onRun 回调抛错时 SDK 代发;200 字符截断防滥用;data 可带 stderrTail 等结构化尾巴) */
|
|
164
|
+
const AutoErrorMessage = z.object({
|
|
165
|
+
v: z.literal(PROTOCOL_VERSION),
|
|
166
|
+
type: z.literal("auto:error"),
|
|
167
|
+
message: z.string().max(200),
|
|
168
|
+
data: z.unknown().optional(),
|
|
169
|
+
});
|
|
170
|
+
/**
|
|
171
|
+
* auto 模式显式完成(0.4.0 起):onRun 回调内调 client.auto.done() 声明结局——
|
|
172
|
+
* 三态有别于「apply=成功 / error=失败」的隐式两分:
|
|
173
|
+
* - succeeded:成功(未 apply 的「无需写值」完成也走这里);
|
|
174
|
+
* - skipped:业务性跳过(如人脸检测 0 张脸:不算失败、不写值、留给人工);
|
|
175
|
+
* - failed:插件自判失败(message 写原因)。
|
|
176
|
+
* 兼容:不调 done 而直接 data.apply/commit 的旧写法仍等价 succeeded(apply 触发即收)。
|
|
177
|
+
*/
|
|
178
|
+
const AutoDoneMessage = z.object({
|
|
179
|
+
v: z.literal(PROTOCOL_VERSION),
|
|
180
|
+
type: z.literal("auto:done"),
|
|
181
|
+
status: z.enum(["succeeded", "skipped", "failed"]),
|
|
182
|
+
message: z.string().max(200).optional(),
|
|
183
|
+
});
|
|
184
|
+
/** auto:error message 的截断上限(与 panel:before-close-reply message 同口径) */
|
|
185
|
+
export const AUTO_ERROR_MESSAGE_MAX = 200;
|
|
126
186
|
/**
|
|
127
187
|
* 关闭询问等待插件应答的超时(ms):超时按「无未保存」放行(防插件锁死面板)。
|
|
128
188
|
* 宿主 broker 的缺省值与插件文档的口径都以本常量为准。
|
|
@@ -140,6 +200,9 @@ export const MbwsMessageSchema = z.discriminatedUnion("type", [
|
|
|
140
200
|
PanelBeforeCloseMessage,
|
|
141
201
|
PanelBeforeCloseReplyMessage,
|
|
142
202
|
PanelCloseMessage,
|
|
203
|
+
AutoReadyMessage,
|
|
204
|
+
AutoErrorMessage,
|
|
205
|
+
AutoDoneMessage,
|
|
143
206
|
]);
|
|
144
207
|
/** 消息方向表:契约形状层即可判定,broker 在此之上再做权限/配额校验 */
|
|
145
208
|
export const MESSAGE_DIRECTION = {
|
|
@@ -154,6 +217,9 @@ export const MESSAGE_DIRECTION = {
|
|
|
154
217
|
"panel:before-close": "host-to-plugin",
|
|
155
218
|
"panel:before-close-reply": "plugin-to-host",
|
|
156
219
|
"panel:close": "plugin-to-host",
|
|
220
|
+
"auto:ready": "plugin-to-host",
|
|
221
|
+
"auto:error": "plugin-to-host",
|
|
222
|
+
"auto:done": "plugin-to-host",
|
|
157
223
|
};
|
|
158
224
|
export function isPluginToHost(message) {
|
|
159
225
|
return MESSAGE_DIRECTION[message.type] === "plugin-to-host";
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED