@mbws/plugin-sdk 0.3.22 → 0.4.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.
- package/README.md +48 -0
- package/dist/client.d.ts +46 -0
- package/dist/client.js +92 -3
- package/dist/config.d.ts +51 -0
- package/dist/dev-mock.js +47 -0
- package/dist/manifest.d.ts +3 -0
- package/dist/manifest.js +10 -0
- package/dist/protocol.d.ts +34 -1
- package/dist/protocol.js +67 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -285,6 +285,36 @@ viewer 容器 grants 还含 caps(有桥时)——`caps.exec.mediaUrl(local:
|
|
|
285
285
|
|
|
286
286
|
- **生产(宿主 sandbox iframe 内)**:等待宿主经 `window.postMessage` 递来的
|
|
287
287
|
`MessagePort`,完成 init 握手后按授权构造命名空间。此后所有调用都走端口消息。
|
|
288
|
+
生产又分两种装载形态(init 的 `mode` 字段声明,0.4.0 起):
|
|
289
|
+
- **panel(缺省)**:交互面板——工人打开工具弹窗的常规形态;
|
|
290
|
+
- **auto**:无头自动执行——宿主无人值守驱动(「本地工具批量预跑」)。注册
|
|
291
|
+
`mbws.auto?.onRun(async ({ params, signal, timeoutMs }) => { ... })` 即支持:
|
|
292
|
+
SDK 发 `auto:ready` 握手后回调被调一次。收尾两条路径任一到达即结束:
|
|
293
|
+
1. `data.apply/commit` 写回(等价 succeeded);
|
|
294
|
+
2. `mbws.auto.done({ status })` 显式声明——`skipped` 是一等态(如人脸检测
|
|
295
|
+
0 张脸:不算失败、不写值、留给人工复核),`succeeded` 用于「成功但无需写值」,
|
|
296
|
+
`failed` 携带 message。回调既不写回也不 done 就返回 → SDK 代发
|
|
297
|
+
done(failed)(视为插件缺陷,明确报错优于挂到超时)。
|
|
298
|
+
面板形态 `mbws.auto === undefined`——按它分支即可;建议 panel 与 onRun 共用同一份
|
|
299
|
+
核心逻辑(脚手架 starter 即此结构)。要求 manifest `automation: "batchable"`。
|
|
300
|
+
|
|
301
|
+
**运行参数(声明式参数通道)**:插件需要可调参数(打码强度、检测阈值等)时在
|
|
302
|
+
mbws.config.ts 声明 `auto: { params: <JSON Schema> }`(object 形态,默认值内嵌
|
|
303
|
+
`properties.*.default`)——宿主批量预跑入队时按 schema 弹表单收集一次性参数
|
|
304
|
+
(不声明则不弹表单,零成本),收集值(默认值 ← 表单值合并)经 init 下发,
|
|
305
|
+
`onRun` 回调 `ctx.params` 原样收到(未声明恒空对象)。与顶层 `paramsSchema`
|
|
306
|
+
(spec 侧参数位)互不相干。进度上报用既有 `mbws.runtime.progress(ratio, message)`
|
|
307
|
+
——auto 模式照常可用,宿主转发到批量队列逐条展示。
|
|
308
|
+
|
|
309
|
+
**auto 模式的三条边界约定**:
|
|
310
|
+
- **不保证 DOM**:当前宿主实现是隐藏 iframe,但协议按「与容器无关」规范——auto
|
|
311
|
+
回调里不要依赖 `document`/`window` 上任何 UI(将来换 worker/轻量 core 运行时,
|
|
312
|
+
同一份插件代码不改);
|
|
313
|
+
- **不授予 ui**:auto 形态 `mbws.ui === undefined`(宿主 grants 不含 ui,客户端
|
|
314
|
+
不构造该面)——无头代码不要调用 confirm/toast;
|
|
315
|
+
- **超时可协商**:宿主 init 带 `autoTimeoutMs`(ctx.timeoutMs 同源);插件需要更长
|
|
316
|
+
时间时在 onRun 里……见下——目前协议面是插件经 `auto:ready` 声明(SDK 按需扩展
|
|
317
|
+
透传,宿主取 max(声明值, 自身配置),只升不降)。
|
|
288
318
|
- **开发(本地 `pnpm dev` / 顶窗口 / 端口等待超时)**:自动降级为 dev mock——
|
|
289
319
|
`data.inputs` / `viewer.inputs` 读工程内 `samples/inputs.json`、`viewer.outputs` /
|
|
290
320
|
`data.outputs` 读 `samples/outputs.json`(均原样返回,缺省回落 per-key 合并);
|
|
@@ -316,6 +346,24 @@ dev 面模拟:`MBWS_DEV_HOST_FACE=<ver>` 环境变量让 dev mock 按
|
|
|
316
346
|
`host.capabilities()` 一致生效)——降级分支在浏览器 dev 即可测试,如
|
|
317
347
|
`MBWS_DEV_HOST_FACE=0.3.9 pnpm dev`。
|
|
318
348
|
|
|
349
|
+
**auto 无头链路的 dev 工作流(0.4.0 起,不装桌面端即可 e2e)**:
|
|
350
|
+
`pnpm dev` 起 panel(dev mock 形态),控制台调 `await window.__mbwsDev.autoRun(params?)`
|
|
351
|
+
——它以 `{ params: params ?? {}, signal, timeoutMs: 300_000 }` 调一次你注册的
|
|
352
|
+
`auto.onRun` 回调(params 即宿主按 `auto.params` 声明收集下发的运行参数,模拟传参),
|
|
353
|
+
与宿主无头装载同一入口签名;输入读 `samples/inputs.json` 夹具、`data.apply` 写回
|
|
354
|
+
`samples/outputs.json`(与面板一致)。模拟各结局:
|
|
355
|
+
|
|
356
|
+
| 想模拟的结局 | 做法 |
|
|
357
|
+
| --- | --- |
|
|
358
|
+
| skipped(业务性跳过) | 回调里 `mbws.auto.done({ status: "skipped", message: "原因" })` |
|
|
359
|
+
| failed(自判失败) | 回调里 `mbws.auto.done({ status: "failed", message: "原因" })` |
|
|
360
|
+
| failed(抛错,含 stderr 尾巴) | 回调里 `throw jobFailedError(...)` 或任意 Error |
|
|
361
|
+
| 取消 | devRun 前拿不到 signal 句柄——直接在回调里检查传入的 `ctx.signal` 分支覆盖 |
|
|
362
|
+
|
|
363
|
+
`window.__mbwsDev.autoDone()` 返回最近一次 `auto.done` 的 `{ status, message }`
|
|
364
|
+
(harness 断言用;未调用过为 null)。会话级单执行与端口客户端一致(autoRun 只生效
|
|
365
|
+
首次)。
|
|
366
|
+
|
|
319
367
|
dev 故障模拟:`MBWS_DEV_SIMULATE=<token>[,<token>...]` 往 happy path 里注入指定
|
|
320
368
|
故障,插件的降级/重试分支浏览器 dev 即可覆盖(语义与宿主对齐):
|
|
321
369
|
|
package/dist/client.d.ts
CHANGED
|
@@ -305,6 +305,36 @@ export interface MbwsClient<C extends MbwsContractTypes = MbwsContractTypes> {
|
|
|
305
305
|
outputs(): Promise<Partial<MbwsContractOutputs<C>>>;
|
|
306
306
|
onChange(cb: (outputs: Partial<MbwsContractOutputs<C>>) => void): () => void;
|
|
307
307
|
};
|
|
308
|
+
/**
|
|
309
|
+
* auto 无头执行面(0.4.0 起;宿主 init `mode:"auto"` 装载形态才构造——面板形态
|
|
310
|
+
* undefined,插件按 `mbws.auto?.onRun` 判断分支。auto 模式宿主不授 ui 面权限,
|
|
311
|
+
* `mbws.ui` 为 undefined——无头代码不要调用 ui.confirm/toast):
|
|
312
|
+
*
|
|
313
|
+
* - `onRun(cb)`:注册即握手——SDK 发 auto:ready 告知宿主「本插件支持自动执行」,
|
|
314
|
+
* 随后回调被调一次(ctx 见 AutoRunContext:params/signal/timeoutMs 定型)。
|
|
315
|
+
* 回调内两条收尾路径任一到达即结束:
|
|
316
|
+
* 1. `data.apply/commit` 写回(兼容旧写法,等价 succeeded);
|
|
317
|
+
* 2. `done({ status })` 显式声明结局——skipped 是一等态(如人脸检测 0 张脸:
|
|
318
|
+
* 不算失败、不写值、留给人工复核),succeeded 用于「成功但无需写值」,
|
|
319
|
+
* failed 携带 message。回调既不写回也不 done 就返回 → SDK 代发
|
|
320
|
+
* done(failed)(视为插件缺陷,明确报错优于挂到超时)。
|
|
321
|
+
* - 回调抛错 → SDK 代发 auto:error(message 200 字符截断;MbwsInvokeError 的
|
|
322
|
+
* data(如 stderrTail)随消息透传,宿主可展示失败原因尾巴)。
|
|
323
|
+
*/
|
|
324
|
+
auto?: {
|
|
325
|
+
/**
|
|
326
|
+
* 注册自动执行回调(opts.timeoutMs 声明本次执行的建议超时上限,随 auto:ready
|
|
327
|
+
* 上报——宿主取 max(声明值, 自身配置) 只升不降;视频类长任务按需协商)
|
|
328
|
+
*/
|
|
329
|
+
onRun(cb: (ctx: AutoRunContext) => Promise<void> | void, opts?: {
|
|
330
|
+
timeoutMs?: number;
|
|
331
|
+
}): void;
|
|
332
|
+
/** 显式声明结局(见上;fire-and-forget,调用后不要再发 apply/done) */
|
|
333
|
+
done(result: {
|
|
334
|
+
status: "succeeded" | "skipped" | "failed";
|
|
335
|
+
message?: string;
|
|
336
|
+
}): void;
|
|
337
|
+
};
|
|
308
338
|
/**
|
|
309
339
|
* 数据结构(契约)面:拉关联任务的最新契约。不经宿主端口——服务端按插件编号
|
|
310
340
|
* (manifest.id)公开派生,dev 预览/宿主内同一调用;故不随 grants 增减、恒在。
|
|
@@ -319,6 +349,19 @@ export interface MbwsClient<C extends MbwsContractTypes = MbwsContractTypes> {
|
|
|
319
349
|
allows(outputKey: string, fieldPath: string): Promise<boolean>;
|
|
320
350
|
};
|
|
321
351
|
}
|
|
352
|
+
/** auto 无头执行回调上下文(onRun 定型签名;字段随版本只加不减) */
|
|
353
|
+
export interface AutoRunContext {
|
|
354
|
+
/**
|
|
355
|
+
* 运行参数(0.4.0 声明式参数通道):宿主按 manifest.auto.params 声明收集的
|
|
356
|
+
* 一次性参数(schema 默认值 ← 入队表单值合并后下发);未声明/未下发 → 空对象。
|
|
357
|
+
* dev 预览经 window.__mbwsDev.autoRun(params) 手动传入。
|
|
358
|
+
*/
|
|
359
|
+
params: Record<string, unknown>;
|
|
360
|
+
/** 宿主取消信号(abort 后应尽快收尾/丢弃写回) */
|
|
361
|
+
signal: AbortSignal;
|
|
362
|
+
/** 本次执行总超时(宿主下发;长任务据此设 checkpoint) */
|
|
363
|
+
timeoutMs: number;
|
|
364
|
+
}
|
|
322
365
|
/** 调用被拒时抛出的规范错误(error.code 是 9 错误码之一) */
|
|
323
366
|
export declare class MbwsInvokeError extends Error {
|
|
324
367
|
readonly code: MbwsErrorCode;
|
|
@@ -370,6 +413,9 @@ export interface CreateMbwsOptions {
|
|
|
370
413
|
/** 分层可测:纯端口逻辑(不碰 window),单测用 Node MessageChannel 直连 broker。 */
|
|
371
414
|
export declare function connectMbwsPort<C extends MbwsContractTypes = MbwsContractTypes>(port: MessagePort, init: {
|
|
372
415
|
grants: string[];
|
|
416
|
+
mode?: "panel" | "auto";
|
|
417
|
+
autoTimeoutMs?: number;
|
|
418
|
+
autoParams?: Record<string, unknown>;
|
|
373
419
|
theme?: Record<string, string>;
|
|
374
420
|
attachments?: AttachmentState[];
|
|
375
421
|
}, opts?: Pick<CreateMbwsOptions, "invokeTimeoutMs">): MbwsClient<C>;
|
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import { asMbwsRef, CAPS_WRITE_FILE_MAX_BYTES, mergeAttachmentEvent, mergeUpload
|
|
|
2
2
|
import { contractFieldAllowed, fetchContract, } from "./contract.js";
|
|
3
3
|
import { createDevMockMbws } from "./dev-mock.js";
|
|
4
4
|
import { MBWS_ERROR_CODES } from "./errors.js";
|
|
5
|
-
import { parseMbwsMessage } from "./protocol.js";
|
|
5
|
+
import { AUTO_ERROR_MESSAGE_MAX, parseMbwsMessage } from "./protocol.js";
|
|
6
6
|
import { uuid } from "./uuid.js";
|
|
7
7
|
import { PROTOCOL_VERSION, SDK_VERSION } from "./version.js";
|
|
8
8
|
/** 调用被拒时抛出的规范错误(error.code 是 9 错误码之一) */
|
|
@@ -197,6 +197,72 @@ export function connectMbwsPort(port, init, opts = {}) {
|
|
|
197
197
|
};
|
|
198
198
|
/** 已结算 job 的 wait() 结果:exit 0 resolve,非零 reject(与 dev-mock 同一构造函数) */
|
|
199
199
|
const settleJobWait = (result) => result.exitCode === 0 ? Promise.resolve(result) : Promise.reject(jobFailedError(result));
|
|
200
|
+
// auto 无头执行(mode=auto 装载形态):onRun 注册即发 auto:ready 并执行一次(会话
|
|
201
|
+
// 内只执行首个注册的回调,重复注册忽略);收尾三路——data.apply/commit(等价
|
|
202
|
+
// succeeded,旧写法兼容)、显式 done()(succeeded/skipped/failed 三态)、回调抛错
|
|
203
|
+
// (代发 auto:error,MbwsInvokeError 的 data 如 stderrTail 透传)。回调正常返回但
|
|
204
|
+
// 既未写回也未 done → 代发 done(failed)(插件缺陷明确报错,优于挂到超时)。未注册
|
|
205
|
+
// 不发 ready——宿主按 no-auto 快速失败,不耗整条超时额度去猜
|
|
206
|
+
let autoStarted = false;
|
|
207
|
+
let autoApplyInitiated = false;
|
|
208
|
+
let autoDoneSent = false;
|
|
209
|
+
const autoCtx = {
|
|
210
|
+
params: init.autoParams ?? {},
|
|
211
|
+
signal: abortController.signal,
|
|
212
|
+
timeoutMs: init.autoTimeoutMs ?? 300_000,
|
|
213
|
+
};
|
|
214
|
+
const postAutoError = (error) => {
|
|
215
|
+
console.warn("[mbws] auto.onRun 回调抛错", error);
|
|
216
|
+
const text = (error instanceof Error ? error.message : String(error)).slice(0, AUTO_ERROR_MESSAGE_MAX);
|
|
217
|
+
const data = error?.data;
|
|
218
|
+
post({
|
|
219
|
+
v: PROTOCOL_VERSION,
|
|
220
|
+
type: "auto:error",
|
|
221
|
+
message: text,
|
|
222
|
+
...(data !== undefined ? { data } : {}),
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
const runAuto = (cb, opts) => {
|
|
226
|
+
if (autoStarted)
|
|
227
|
+
return;
|
|
228
|
+
autoStarted = true;
|
|
229
|
+
const declared = typeof opts?.timeoutMs === "number" && opts.timeoutMs > 0 ? opts.timeoutMs : undefined;
|
|
230
|
+
post({ v: PROTOCOL_VERSION, type: "auto:ready", ...(declared ? { timeoutMs: declared } : {}) });
|
|
231
|
+
// 异步链包一层:回调同步抛错同样落进 catch → auto:error(不冒泡到插件入口)
|
|
232
|
+
void Promise.resolve()
|
|
233
|
+
.then(() => cb(autoCtx))
|
|
234
|
+
.then(() => {
|
|
235
|
+
if (autoApplyInitiated || autoDoneSent)
|
|
236
|
+
return;
|
|
237
|
+
autoDoneSent = true;
|
|
238
|
+
post({
|
|
239
|
+
v: PROTOCOL_VERSION,
|
|
240
|
+
type: "auto:done",
|
|
241
|
+
status: "failed",
|
|
242
|
+
message: "onRun 回调既未写回(data.apply/commit)也未声明完成(auto.done)",
|
|
243
|
+
});
|
|
244
|
+
})
|
|
245
|
+
.catch((error) => {
|
|
246
|
+
if (autoDoneSent || autoApplyInitiated)
|
|
247
|
+
return;
|
|
248
|
+
postAutoError(error);
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
const autoDone = (result) => {
|
|
252
|
+
if (autoDoneSent || autoApplyInitiated) {
|
|
253
|
+
console.warn("[mbws] auto.done 在已收尾后再次调用,忽略");
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
autoDoneSent = true;
|
|
257
|
+
post({
|
|
258
|
+
v: PROTOCOL_VERSION,
|
|
259
|
+
type: "auto:done",
|
|
260
|
+
status: result.status,
|
|
261
|
+
...(result.message !== undefined
|
|
262
|
+
? { message: result.message.slice(0, AUTO_ERROR_MESSAGE_MAX) }
|
|
263
|
+
: {}),
|
|
264
|
+
});
|
|
265
|
+
};
|
|
200
266
|
/** spawn 返回的裸 jobId 包装成 ExecJob(wait 以 exit 事件结算,断线走 jobResult 兜底) */
|
|
201
267
|
const makeExecJob = (jobId) => {
|
|
202
268
|
jobSessionOf(jobId);
|
|
@@ -301,8 +367,18 @@ export function connectMbwsPort(port, init, opts = {}) {
|
|
|
301
367
|
inputs: () => invoke("data", "inputs"),
|
|
302
368
|
outputs: () => invoke("data", "outputs"),
|
|
303
369
|
blob: (key) => invoke("data", "blob", { key }),
|
|
304
|
-
apply: (outputs) =>
|
|
305
|
-
|
|
370
|
+
apply: (outputs) => {
|
|
371
|
+
// auto 模式:apply 发起即视为收尾信号(宿主收到 outputs 立即结案,
|
|
372
|
+
// 插件随后 return 不触发 done(failed) 兜底)
|
|
373
|
+
if (init.mode === "auto")
|
|
374
|
+
autoApplyInitiated = true;
|
|
375
|
+
return invoke("data", "apply", { outputs });
|
|
376
|
+
},
|
|
377
|
+
commit: (outputs) => {
|
|
378
|
+
if (init.mode === "auto")
|
|
379
|
+
autoApplyInitiated = true;
|
|
380
|
+
return invoke("data", "commit", { outputs });
|
|
381
|
+
},
|
|
306
382
|
},
|
|
307
383
|
}
|
|
308
384
|
: {}),
|
|
@@ -523,6 +599,16 @@ export function connectMbwsPort(port, init, opts = {}) {
|
|
|
523
599
|
},
|
|
524
600
|
}
|
|
525
601
|
: {}),
|
|
602
|
+
// auto 无头执行面:mode=auto 装载形态才构造(面板形态 undefined,插件按
|
|
603
|
+
// mbws.auto?.onRun 分支);dev mock 同形(dev 触发口手动驱动)
|
|
604
|
+
...(init.mode === "auto"
|
|
605
|
+
? {
|
|
606
|
+
auto: {
|
|
607
|
+
onRun: (cb, opts) => runAuto(cb, opts),
|
|
608
|
+
done: autoDone,
|
|
609
|
+
},
|
|
610
|
+
}
|
|
611
|
+
: {}),
|
|
526
612
|
// 契约面与端口无关(HTTP 直连),端口客户端/dev mock 同形,插件代码零分支
|
|
527
613
|
contract: {
|
|
528
614
|
get: (opts = {}) => fetchContract(opts),
|
|
@@ -571,6 +657,9 @@ export function bootstrapFromWindow(win, opts = {}) {
|
|
|
571
657
|
}
|
|
572
658
|
finish(connectMbwsPort(port, {
|
|
573
659
|
grants: message.grants,
|
|
660
|
+
...(message.mode ? { mode: message.mode } : {}),
|
|
661
|
+
...(message.autoTimeoutMs ? { autoTimeoutMs: message.autoTimeoutMs } : {}),
|
|
662
|
+
...(message.autoParams ? { autoParams: message.autoParams } : {}),
|
|
574
663
|
theme: message.theme,
|
|
575
664
|
...(message.attachments
|
|
576
665
|
? { attachments: message.attachments }
|
package/dist/config.d.ts
CHANGED
|
@@ -19,6 +19,57 @@ import { type AttachmentDecl, type AttachmentRef, type Manifest } from "./manife
|
|
|
19
19
|
*/
|
|
20
20
|
declare const UserConfigSchema: z.ZodObject<{
|
|
21
21
|
version: z.ZodString;
|
|
22
|
+
auto: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
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 | {
|
|
24
|
+
[key: string]: string | number | boolean | /*elided*/ any | /*elided*/ any | null;
|
|
25
|
+
} | null)[] | {
|
|
26
|
+
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
27
|
+
} | null)[] | {
|
|
28
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
29
|
+
} | null)[] | {
|
|
30
|
+
[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;
|
|
31
|
+
} | null)[] | {
|
|
32
|
+
[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;
|
|
33
|
+
} | null)[] | {
|
|
34
|
+
[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;
|
|
35
|
+
} | null)[] | {
|
|
36
|
+
[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;
|
|
37
|
+
} | null)[] | {
|
|
38
|
+
[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;
|
|
39
|
+
} | null)[] | {
|
|
40
|
+
[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;
|
|
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 | (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;
|
|
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 | (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;
|
|
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 | (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;
|
|
47
|
+
} | 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 | {
|
|
48
|
+
[key: string]: string | number | boolean | /*elided*/ any | /*elided*/ any | null;
|
|
49
|
+
} | null)[] | {
|
|
50
|
+
[key: string]: string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
51
|
+
} | null)[] | {
|
|
52
|
+
[key: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | /*elided*/ any | null)[] | /*elided*/ any | null;
|
|
53
|
+
} | null)[] | {
|
|
54
|
+
[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;
|
|
55
|
+
} | null)[] | {
|
|
56
|
+
[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;
|
|
57
|
+
} | null)[] | {
|
|
58
|
+
[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;
|
|
59
|
+
} | null)[] | {
|
|
60
|
+
[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;
|
|
61
|
+
} | null)[] | {
|
|
62
|
+
[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;
|
|
63
|
+
} | null)[] | {
|
|
64
|
+
[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;
|
|
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 | (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;
|
|
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 | (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;
|
|
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 | (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;
|
|
71
|
+
} | null, unknown>>>]>;
|
|
72
|
+
}, z.core.$strip>>;
|
|
22
73
|
kind: z.ZodEnum<{
|
|
23
74
|
producer: "producer";
|
|
24
75
|
validator: "validator";
|
package/dist/dev-mock.js
CHANGED
|
@@ -640,6 +640,15 @@ function storageKeyInvalid(key) {
|
|
|
640
640
|
export function createDevMockMbws() {
|
|
641
641
|
// 无 dev server 时的 storage 兜底(每个客户端一份 = 页面生命周期)
|
|
642
642
|
const memoryStorage = new MemoryDevStorage();
|
|
643
|
+
// dev auto 面(0.4.0):与端口客户端同形——注册只存回调,不自动触发(dev 无宿主
|
|
644
|
+
// 发 mode=auto 的 init);window.__mbwsDev.autoRun(params?) 手动驱动(harness/开发者
|
|
645
|
+
// 手测 auto 分支用,params 即宿主按 manifest.auto.params 收集后下发的运行参数——
|
|
646
|
+
// 缺省空对象,与端口客户端 init.autoParams 缺省回落同形)。会话级单执行:与端口
|
|
647
|
+
// 客户端 autoStarted 同语义。
|
|
648
|
+
let devAutoStarted = false;
|
|
649
|
+
const devAutoController = new AbortController();
|
|
650
|
+
let devAutoRunCb = null;
|
|
651
|
+
let devAutoDoneResult = null;
|
|
643
652
|
const client = {
|
|
644
653
|
data: {
|
|
645
654
|
inputs: fetchDevSamples,
|
|
@@ -997,7 +1006,45 @@ export function createDevMockMbws() {
|
|
|
997
1006
|
return contractFieldAllowed(devContractSnapshot.outputs, outputKey, fieldPath);
|
|
998
1007
|
},
|
|
999
1008
|
},
|
|
1009
|
+
// auto 无头执行面 dev mock:注册只存回调(dev 无宿主发 mode=auto 的 init,不会
|
|
1010
|
+
// 自动进 auto 形态);经 window.__mbwsDev.autoRun() 手动驱动——面板/自动两分支
|
|
1011
|
+
// 同一份插件代码在浏览器 dev 即可联调。回调抛错 console.warn(dev 无宿主可发
|
|
1012
|
+
// auto:error),单执行语义与端口客户端一致
|
|
1013
|
+
auto: {
|
|
1014
|
+
onRun: (cb, _opts) => {
|
|
1015
|
+
// opts.timeoutMs(超时协商)dev 无宿主可发 auto:ready——收下不动作(dev 无超时)
|
|
1016
|
+
devAutoRunCb = cb;
|
|
1017
|
+
},
|
|
1018
|
+
// dev 同形:done 只记状态(无宿主可发 auto:done,控制台留痕);重复调用忽略
|
|
1019
|
+
done: (result) => {
|
|
1020
|
+
console.info("[mbws:dev] auto.done", result.status, result.message ?? "");
|
|
1021
|
+
devAutoDoneResult = { ...result };
|
|
1022
|
+
},
|
|
1023
|
+
},
|
|
1000
1024
|
};
|
|
1025
|
+
// dev 触发口:autoRun() 手动驱动 auto 分支(幂等——会话内只执行首个注册的回调)
|
|
1026
|
+
if (typeof window !== "undefined") {
|
|
1027
|
+
const win = window;
|
|
1028
|
+
const devFace = win.__mbwsDev ?? {};
|
|
1029
|
+
devFace.autoRun = async (params) => {
|
|
1030
|
+
if (devAutoStarted || !devAutoRunCb)
|
|
1031
|
+
return;
|
|
1032
|
+
devAutoStarted = true;
|
|
1033
|
+
try {
|
|
1034
|
+
await devAutoRunCb({
|
|
1035
|
+
params: params ?? {},
|
|
1036
|
+
signal: devAutoController.signal,
|
|
1037
|
+
timeoutMs: 300_000,
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
catch (error) {
|
|
1041
|
+
console.warn("[mbws:dev] auto.onRun 回调抛错", error);
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
// 上一次 auto.done 的结果(harness/开发者断言 skipped/failed 分支用)
|
|
1045
|
+
devFace.autoDone = () => devAutoDoneResult;
|
|
1046
|
+
win.__mbwsDev = devFace;
|
|
1047
|
+
}
|
|
1001
1048
|
// 面模拟收尾:不满足 face 的方法属性从对象上真删(capabilities 列表已过滤,
|
|
1002
1049
|
// 这里让 typeof 探测的降级分支也真实成立)
|
|
1003
1050
|
if (readDevHostFace() && client.caps) {
|
package/dist/manifest.d.ts
CHANGED
|
@@ -89,6 +89,9 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
89
89
|
batchable: "batchable";
|
|
90
90
|
"interactive-only": "interactive-only";
|
|
91
91
|
}>;
|
|
92
|
+
auto: z.ZodOptional<z.ZodObject<{
|
|
93
|
+
params: z.ZodUnion<readonly [z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>]>;
|
|
94
|
+
}, z.core.$strip>>;
|
|
92
95
|
components: z.ZodOptional<z.ZodObject<{
|
|
93
96
|
panel: z.ZodOptional<z.ZodString>;
|
|
94
97
|
viewer: z.ZodOptional<z.ZodString>;
|
package/dist/manifest.js
CHANGED
|
@@ -113,6 +113,16 @@ export const ManifestSchema = z.object({
|
|
|
113
113
|
permissions: z.array(z.string().regex(PERMISSION_RE)).default([]),
|
|
114
114
|
/** interactive-only 不进入批量/自动驱动 */
|
|
115
115
|
automation: z.enum(["batchable", "interactive-only"]),
|
|
116
|
+
/**
|
|
117
|
+
* auto 无头执行声明(0.4.0 起,可选):
|
|
118
|
+
* - `params`:批量运行参数的 JSON Schema(object 形态,默认值内嵌
|
|
119
|
+
* `properties.*.default`)——宿主「本地工具批量预跑」入队时按它收集一次性参数
|
|
120
|
+
* (缺省不弹参数表单,零成本),收集值经 init.autoParams 下发、插件在
|
|
121
|
+
* `auto.onRun` 回调的 `ctx.params` 原样收到。与顶层 paramsSchema(spec 侧
|
|
122
|
+
* 参数位)互不相干:auto.params 只服务无头批量这一条通道;
|
|
123
|
+
* - 面板形态不消费本字段。
|
|
124
|
+
*/
|
|
125
|
+
auto: z.object({ params: JsonSchemaValue }).optional(),
|
|
116
126
|
/** 产物组件的 html 相对路径,缺省 `panel.html` / `viewer.html` */
|
|
117
127
|
components: z
|
|
118
128
|
.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;
|
|
@@ -110,6 +122,24 @@ export declare const MbwsMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
110
122
|
}, z.core.$strip>, z.ZodObject<{
|
|
111
123
|
v: z.ZodLiteral<1>;
|
|
112
124
|
type: z.ZodLiteral<"panel:close">;
|
|
125
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
126
|
+
v: z.ZodLiteral<1>;
|
|
127
|
+
type: z.ZodLiteral<"auto:ready">;
|
|
128
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
129
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
130
|
+
v: z.ZodLiteral<1>;
|
|
131
|
+
type: z.ZodLiteral<"auto:error">;
|
|
132
|
+
message: z.ZodString;
|
|
133
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
134
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
135
|
+
v: z.ZodLiteral<1>;
|
|
136
|
+
type: z.ZodLiteral<"auto:done">;
|
|
137
|
+
status: z.ZodEnum<{
|
|
138
|
+
failed: "failed";
|
|
139
|
+
succeeded: "succeeded";
|
|
140
|
+
skipped: "skipped";
|
|
141
|
+
}>;
|
|
142
|
+
message: z.ZodOptional<z.ZodString>;
|
|
113
143
|
}, z.core.$strip>], "type">;
|
|
114
144
|
export type MbwsMessage = z.output<typeof MbwsMessageSchema>;
|
|
115
145
|
/** 消息方向表:契约形状层即可判定,broker 在此之上再做权限/配额校验 */
|
|
@@ -125,6 +155,9 @@ export declare const MESSAGE_DIRECTION: {
|
|
|
125
155
|
readonly "panel:before-close": "host-to-plugin";
|
|
126
156
|
readonly "panel:before-close-reply": "plugin-to-host";
|
|
127
157
|
readonly "panel:close": "plugin-to-host";
|
|
158
|
+
readonly "auto:ready": "plugin-to-host";
|
|
159
|
+
readonly "auto:error": "plugin-to-host";
|
|
160
|
+
readonly "auto:done": "plugin-to-host";
|
|
128
161
|
};
|
|
129
162
|
export type MessageDirection = (typeof MESSAGE_DIRECTION)[keyof typeof MESSAGE_DIRECTION];
|
|
130
163
|
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