webloom-framework 0.2.0 → 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 +74 -43
- package/dist/advanced.d.ts +168 -0
- package/dist/advanced.js +441 -0
- package/dist/advanced.js.map +1 -0
- package/dist/chunk-4DSINPZD.js +158 -0
- package/dist/chunk-4DSINPZD.js.map +1 -0
- package/dist/chunk-JHJZIO2H.js +4018 -0
- package/dist/chunk-JHJZIO2H.js.map +1 -0
- package/dist/chunk-RAQOFUZY.js +1737 -0
- package/dist/chunk-RAQOFUZY.js.map +1 -0
- package/dist/chunk-YOIH6H36.js +433 -0
- package/dist/chunk-YOIH6H36.js.map +1 -0
- package/dist/index.d.ts +38 -443
- package/dist/index.js +38 -1967
- package/dist/index.js.map +1 -1
- package/dist/messageBus-CtrwkjrO.d.ts +5 -0
- package/dist/messagePortServiceTransport-B0FyJr43.d.ts +264 -0
- package/dist/react.d.ts +41 -28
- package/dist/react.js +79 -88
- package/dist/react.js.map +1 -1
- package/dist/runtimeTypes-DquUCHz-.d.ts +1640 -0
- package/dist/sharedWorkerHost-Cb2a1_KD.d.ts +190 -0
- package/dist/testing.d.ts +18 -17
- package/dist/testing.js +23 -15
- package/dist/testing.js.map +1 -1
- package/dist/windowRuntime-B6Ue8jso.d.ts +23 -0
- package/docs/api.md +149 -111
- package/docs/migration-baseline.md +2 -2
- package/docs/proposals/browser-runtime-v1/implementation-plan.md +7 -1
- package/docs/proposals/browser-runtime-v1/requirements.md +6 -1
- package/docs/proposals/browser-runtime-v1/verification.md +20 -13
- package/docs/proposals/shared-worker-call-first/SWCF-009-typed-transfer-follow-up.md +34 -0
- package/docs/proposals/shared-worker-call-first/implementation-plan.md +567 -0
- package/docs/proposals/webloom-v4/implementation-plan.md +443 -0
- package/docs/proposals/webloom-v4/requirements.md +555 -0
- package/docs/proposals/webloom-v4/verification.md +84 -0
- package/package.json +9 -2
- package/dist/chunk-URY3E6UH.js +0 -3802
- package/dist/chunk-URY3E6UH.js.map +0 -1
- package/dist/createPluginHost-ChJNBTsX.d.ts +0 -1339
- package/dist/resourceRegistry-MNM1c7od.d.ts +0 -157
|
@@ -1,1339 +0,0 @@
|
|
|
1
|
-
/** 运行实例的作用域类型;名称由宿主定义,WebLoom 只比较和调度。 */
|
|
2
|
-
type LifecycleScopeKind = string;
|
|
3
|
-
/** 作用域状态;stopping 表示已撤权但异步收尾还未结束。 */
|
|
4
|
-
type LifecycleScopeState = "active" | "stopping" | "stopped";
|
|
5
|
-
/** 浏览器中由 WebLoom 管理的真实 JavaScript 运行空间。 */
|
|
6
|
-
type RuntimeKind = "window-main" | "shared-worker";
|
|
7
|
-
/** 权限动作名称;权限集合和最终 I/O allowlist 由宿主定义。 */
|
|
8
|
-
type PluginPermission = string;
|
|
9
|
-
/** 一个运行作用域的身份绑定;敏感句柄必须带上这些字段。 */
|
|
10
|
-
interface LifecycleScopeIdentity<TAttributes extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>> {
|
|
11
|
-
/** 作用域唯一标识;每次重建都必须不同。 */
|
|
12
|
-
scopeId: string;
|
|
13
|
-
/** 运行实例唯一标识;A -> B -> A 也不能复用旧实例。 */
|
|
14
|
-
instanceId: string;
|
|
15
|
-
/** 作用域类型;只作为宿主提供的稳定标签。 */
|
|
16
|
-
kind: LifecycleScopeKind;
|
|
17
|
-
/** 父作用域标识;跨环境时只传标识,不传 Context。 */
|
|
18
|
-
parentScopeId?: string;
|
|
19
|
-
/** 插件标识。由 Host 绑定,调用方不可从请求参数替换。 */
|
|
20
|
-
pluginId?: string;
|
|
21
|
-
/** 宿主绑定的只读扩展元数据;不得放入私密材料。 */
|
|
22
|
-
attributes: TAttributes;
|
|
23
|
-
}
|
|
24
|
-
/** 释放回调;reason 是中文 UI 之外的稳定审计原因。 */
|
|
25
|
-
type LifecycleCleanup = (reason: string) => void | Promise<void>;
|
|
26
|
-
/** 清理阶段;Registry 等技术注册项通常在 legacy teardown 之后释放。 */
|
|
27
|
-
type LifecycleCleanupPhase = "before-teardown" | "after-teardown";
|
|
28
|
-
/** 作用域内一项资源的结构化快照。 */
|
|
29
|
-
interface LifecycleResourceSnapshot {
|
|
30
|
-
/** 资源唯一标识。 */
|
|
31
|
-
resourceId: string;
|
|
32
|
-
/** 当前阶段。 */
|
|
33
|
-
state: "acquiring" | "active" | "released" | "pending";
|
|
34
|
-
/** 最近一次释放错误。 */
|
|
35
|
-
error?: string;
|
|
36
|
-
}
|
|
37
|
-
/** 释放失败或超时的结构化记录。 */
|
|
38
|
-
interface LifecycleCleanupIssue {
|
|
39
|
-
/** 对应资源或清理回调标识。 */
|
|
40
|
-
resourceId: string;
|
|
41
|
-
/** 错误稳定码。 */
|
|
42
|
-
code: "lifecycle.cleanup_failed" | "lifecycle.cleanup_timeout";
|
|
43
|
-
/** 便于日志和诊断的错误文本。 */
|
|
44
|
-
message: string;
|
|
45
|
-
}
|
|
46
|
-
/** 作用域停止的结果;清理不完整时仍然返回,而不是伪装成功。 */
|
|
47
|
-
interface LifecycleDisposeResult {
|
|
48
|
-
/** 作用域标识。 */
|
|
49
|
-
scopeId: string;
|
|
50
|
-
/** 停止后的状态。 */
|
|
51
|
-
state: "stopped";
|
|
52
|
-
/** 尝试执行的释放项数量。 */
|
|
53
|
-
attempted: number;
|
|
54
|
-
/** 已完成的释放项数量。 */
|
|
55
|
-
released: number;
|
|
56
|
-
/** 超时或仍在异步收尾的资源标识。 */
|
|
57
|
-
pending: string[];
|
|
58
|
-
/** 所有释放错误;一个错误不阻止其它项执行。 */
|
|
59
|
-
errors: LifecycleCleanupIssue[];
|
|
60
|
-
/** 是否存在未完成收尾。 */
|
|
61
|
-
cleanupIncomplete: boolean;
|
|
62
|
-
}
|
|
63
|
-
/** 作用域停止选项。 */
|
|
64
|
-
interface LifecycleDisposeOptions {
|
|
65
|
-
/** 每一项释放允许等待的毫秒数;不填则等待到完成。 */
|
|
66
|
-
timeoutMs?: number;
|
|
67
|
-
/** 释放原因。 */
|
|
68
|
-
reason?: string;
|
|
69
|
-
/** 在 before-teardown 资源完成后执行的旧 teardown / 领域收尾。 */
|
|
70
|
-
teardown?: LifecycleCleanup;
|
|
71
|
-
/**
|
|
72
|
-
* 某项清理超过 timeoutMs 后最终成功时回调;回调只用于本地状态投影,
|
|
73
|
-
* 不改变已经完成的撤权边界。resourceId 是稳定资源标识,result 是同一
|
|
74
|
-
* 次 dispose 返回的可变快照(可能尚未生成)。
|
|
75
|
-
*/
|
|
76
|
-
onLateSuccess?: (resourceId: string, result?: LifecycleDisposeResult) => void;
|
|
77
|
-
/**
|
|
78
|
-
* 某项清理在超时后最终失败时回调;调用方必须保留 cleanup-pending,
|
|
79
|
-
* 不能把失败的迟到结果当成新实例成功。
|
|
80
|
-
*/
|
|
81
|
-
onLateFailure?: (resourceId: string, error: unknown, result?: LifecycleDisposeResult) => void;
|
|
82
|
-
}
|
|
83
|
-
/** 已登记资源的可控释放句柄。 */
|
|
84
|
-
interface LifecycleResourceHandle {
|
|
85
|
-
/** 资源标识。 */
|
|
86
|
-
readonly resourceId: string;
|
|
87
|
-
/** 资源是否已经完成释放。 */
|
|
88
|
-
readonly released: boolean;
|
|
89
|
-
/** 幂等释放;重复调用不会再次执行资源释放函数。 */
|
|
90
|
-
release(reason?: string): Promise<void>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* 作用域公开 API。
|
|
94
|
-
*
|
|
95
|
-
* `revoke()` 只做同步安全撤权;`dispose()` 负责异步资源收尾。业务不需要
|
|
96
|
-
* 接触底层框架 Context,也不能在 stopping/stopped 作用域中注册新资源。
|
|
97
|
-
*/
|
|
98
|
-
interface LifecycleScope {
|
|
99
|
-
readonly identity: LifecycleScopeIdentity;
|
|
100
|
-
readonly state: LifecycleScopeState;
|
|
101
|
-
readonly signal: AbortSignal;
|
|
102
|
-
/** 订阅同步撤权事件;返回值用于取消该订阅。 */
|
|
103
|
-
onRevoke(listener: (reason: string) => void): () => void;
|
|
104
|
-
/** 登记一个释放回调;返回取消登记函数。 */
|
|
105
|
-
onDispose(cleanup: LifecycleCleanup, resourceId?: string, phase?: LifecycleCleanupPhase): () => void;
|
|
106
|
-
/** 登记已有资源并返回幂等释放句柄。 */
|
|
107
|
-
track<T>(resource: T, release: (resource: T, reason: string) => void | Promise<void>, resourceId?: string): T;
|
|
108
|
-
/** 受控异步创建:停止期间才返回的资源会被立即释放且不会进入旧实例。 */
|
|
109
|
-
acquire<T>(resourceId: string, create: (signal: AbortSignal) => T | Promise<T>, release: (resource: T, reason: string) => void | Promise<void>): Promise<T>;
|
|
110
|
-
/** 创建同一运行实例下的子作用域。 */
|
|
111
|
-
child(kind: LifecycleScopeKind, metadata?: Partial<Omit<LifecycleScopeIdentity, "scopeId" | "instanceId" | "kind" | "parentScopeId">>): LifecycleScope;
|
|
112
|
-
/** 同步撤销权限、发出 signal.abort,并阻止新资源登记。 */
|
|
113
|
-
revoke(reason?: string): void;
|
|
114
|
-
/** 异步释放全部已登记资源,结果可见且幂等。 */
|
|
115
|
-
dispose(options?: LifecycleDisposeOptions): Promise<LifecycleDisposeResult>;
|
|
116
|
-
/** 作用域已撤权时抛出稳定错误。 */
|
|
117
|
-
assertActive(): void;
|
|
118
|
-
/** 只读资源快照。 */
|
|
119
|
-
resources(): readonly LifecycleResourceSnapshot[];
|
|
120
|
-
}
|
|
121
|
-
/** 生命周期作用域已撤权。 */
|
|
122
|
-
declare class LifecycleScopeRevokedError extends Error {
|
|
123
|
-
readonly code: "lifecycle.scope_revoked";
|
|
124
|
-
constructor(message?: string);
|
|
125
|
-
}
|
|
126
|
-
/** 权限租约已撤销或身份不匹配。 */
|
|
127
|
-
declare class PermissionLeaseRevokedError extends Error {
|
|
128
|
-
readonly code: "permission.lease_revoked";
|
|
129
|
-
constructor(message?: string);
|
|
130
|
-
}
|
|
131
|
-
/** 没有得到可信装配批准的权限。 */
|
|
132
|
-
declare class PermissionDeniedError extends Error {
|
|
133
|
-
readonly code: "permission.denied";
|
|
134
|
-
readonly permission: PluginPermission;
|
|
135
|
-
constructor(permission: PluginPermission, message?: string);
|
|
136
|
-
}
|
|
137
|
-
/** 权限租约的不可变身份绑定。 */
|
|
138
|
-
interface PermissionLeaseBinding extends LifecycleScopeIdentity {
|
|
139
|
-
/** 插件申请的权限;申请不等于批准。 */
|
|
140
|
-
requested: readonly PluginPermission[];
|
|
141
|
-
/** 可信装配层批准的权限。 */
|
|
142
|
-
approved: readonly PluginPermission[];
|
|
143
|
-
/** 当前会话额外允许的权限;未提供会话限制时由装配层视为全量允许。 */
|
|
144
|
-
sessionConstraints?: readonly PluginPermission[];
|
|
145
|
-
/** 内置可信策略修订;策略扩大或收窄都会触发重新发租约。 */
|
|
146
|
-
policyRevision?: number;
|
|
147
|
-
/** Connect 用户授权修订;内置插件可以省略。 */
|
|
148
|
-
grantRevision?: number;
|
|
149
|
-
/** Connect/外部授权的不可猜测授权标识;最终服务边界必须核验。 */
|
|
150
|
-
grantId?: string;
|
|
151
|
-
}
|
|
152
|
-
/** 最终 RPC / I/O 边界可比较的租约身份字段。 */
|
|
153
|
-
type PermissionLeaseBindingExpectation = Partial<Pick<LifecycleScopeIdentity, "pluginId" | "instanceId">> & {
|
|
154
|
-
attributes?: Readonly<Record<string, unknown>>;
|
|
155
|
-
} & Partial<Pick<PermissionLeaseBinding, "policyRevision" | "grantRevision" | "grantId">>;
|
|
156
|
-
/** 权限租约;实现必须在最终 RPC/I/O 边界再次校验。 */
|
|
157
|
-
interface PermissionLease {
|
|
158
|
-
readonly binding: PermissionLeaseBinding;
|
|
159
|
-
readonly revoked: boolean;
|
|
160
|
-
/** 当前租约是否同时满足申请、批准和作用域状态。 */
|
|
161
|
-
has(permission: PluginPermission): boolean;
|
|
162
|
-
/** 校验权限;失败抛稳定错误。 */
|
|
163
|
-
assert(permission: PluginPermission): void;
|
|
164
|
-
/** 校验绑定身份;不允许替换 owner、插件或世代。 */
|
|
165
|
-
assertBinding(expected: PermissionLeaseBindingExpectation): void;
|
|
166
|
-
/** 撤销租约;重复调用幂等。 */
|
|
167
|
-
revoke(reason?: string): void;
|
|
168
|
-
}
|
|
169
|
-
/** 跨 Worker 服务的可序列化引用;引用本身不是授权凭据。 */
|
|
170
|
-
interface RemoteServiceReference {
|
|
171
|
-
/** 服务契约标识。 */
|
|
172
|
-
capabilityId: string;
|
|
173
|
-
/** 提供该服务的运行实例;实例重建后必须变化。 */
|
|
174
|
-
providerInstanceId: string;
|
|
175
|
-
/** 提供者所在真实 Runtime。 */
|
|
176
|
-
runtime: RuntimeKind;
|
|
177
|
-
/** 服务契约版本;第一阶段要求精确匹配。 */
|
|
178
|
-
contractVersion: string;
|
|
179
|
-
/** 提供环境的启动身份;重启后变化。 */
|
|
180
|
-
authorityInstanceId: string;
|
|
181
|
-
/** 提供者作用域身份。 */
|
|
182
|
-
scopeId: string;
|
|
183
|
-
/** 提供者所在 Coordinator 的升级接管世代;旧 Worker 引用不能跨世代使用。 */
|
|
184
|
-
handoverGeneration: number;
|
|
185
|
-
/** 宿主绑定的只读服务属性;服务桥不解释其业务含义。 */
|
|
186
|
-
attributes: Readonly<Record<string, unknown>>;
|
|
187
|
-
/** 当前服务目录状态。 */
|
|
188
|
-
status: "starting" | "ready" | "unavailable" | "failed";
|
|
189
|
-
/** 该引用所属的物理端口连接;本地服务可省略。 */
|
|
190
|
-
connectionId?: string;
|
|
191
|
-
/** 当前权威目录流修订号。 */
|
|
192
|
-
snapshotRevision: number;
|
|
193
|
-
/** 可选的外部授权标识;引用不是授权本身,Provider 仍需查权威状态。 */
|
|
194
|
-
grantId?: string;
|
|
195
|
-
/** 服务端授权策略修订;策略变化时旧引用必须失效。 */
|
|
196
|
-
authorizationRevision?: number;
|
|
197
|
-
}
|
|
198
|
-
/** 服务桥握手输入;connectionId 必须由实际端口连接生成。 */
|
|
199
|
-
interface RemoteServiceHandshake {
|
|
200
|
-
/** 当前端口 / MessagePort 连接标识。 */
|
|
201
|
-
connectionId: string;
|
|
202
|
-
/** 对端提供环境的启动身份。 */
|
|
203
|
-
authorityInstanceId: string;
|
|
204
|
-
/** 桥协议版本。 */
|
|
205
|
-
protocolVersion: string;
|
|
206
|
-
}
|
|
207
|
-
/** 一次服务目录基线或增量快照。 */
|
|
208
|
-
interface RemoteServiceSnapshot {
|
|
209
|
-
/** 快照来自哪条端口连接。 */
|
|
210
|
-
connectionId: string;
|
|
211
|
-
/** 快照来自哪个权威启动身份。 */
|
|
212
|
-
authorityInstanceId: string;
|
|
213
|
-
/** 同一启动身份、同一订阅范围内单调递增。 */
|
|
214
|
-
snapshotRevision: number;
|
|
215
|
-
/** 是否为包含完整订阅范围的基线。 */
|
|
216
|
-
baseline: boolean;
|
|
217
|
-
/** 当前订阅范围内的服务引用。 */
|
|
218
|
-
services: readonly RemoteServiceReference[];
|
|
219
|
-
}
|
|
220
|
-
/** 服务桥在独立 MessagePort 上发送的控制消息。 */
|
|
221
|
-
type RemoteServicePortControlMessage = {
|
|
222
|
-
/** 控制消息类型由 codec 绑定,核心不固定产品前缀。 */
|
|
223
|
-
type: string;
|
|
224
|
-
handshake: RemoteServiceHandshake;
|
|
225
|
-
} | {
|
|
226
|
-
type: string;
|
|
227
|
-
snapshot: RemoteServiceSnapshot;
|
|
228
|
-
} | {
|
|
229
|
-
type: string;
|
|
230
|
-
reason?: string;
|
|
231
|
-
} | {
|
|
232
|
-
type: string;
|
|
233
|
-
reason?: string;
|
|
234
|
-
};
|
|
235
|
-
/** MessagePort 服务消息类别;具体字符串由 codec 统一编码。 */
|
|
236
|
-
type RemoteServiceMessageKind = "call" | "result" | "error" | "cancel" | "handshake" | "snapshot" | "invalidate" | "disconnect";
|
|
237
|
-
/** 服务桥 wire codec;负责类型名、编解码和协议版本,不让传输层散落字符串判断。 */
|
|
238
|
-
interface RemoteServiceMessageCodec {
|
|
239
|
-
/** codec 对应的协议版本。 */
|
|
240
|
-
readonly protocolVersion: string;
|
|
241
|
-
/** 各消息类别对应的 wire type。 */
|
|
242
|
-
type(kind: RemoteServiceMessageKind): string;
|
|
243
|
-
/** 将结构化消息编码为可结构化克隆的数据。 */
|
|
244
|
-
encode(message: Record<string, unknown>): unknown;
|
|
245
|
-
/** 将 wire 数据解码为对象;无效消息返回 undefined。 */
|
|
246
|
-
decode(input: unknown): Record<string, unknown> | undefined;
|
|
247
|
-
}
|
|
248
|
-
/** 创建默认 WebLoom codec;产品可用同一工厂绑定旧协议前缀。 */
|
|
249
|
-
declare function createRemoteServiceMessageCodec(options?: {
|
|
250
|
-
prefix?: string;
|
|
251
|
-
protocolVersion?: string;
|
|
252
|
-
}): RemoteServiceMessageCodec;
|
|
253
|
-
/** 服务桥查询条件;不匹配时不能返回“差不多兼容”的代理。 */
|
|
254
|
-
interface RemoteServiceLookup {
|
|
255
|
-
/** 要求的服务契约标识。 */
|
|
256
|
-
capabilityId: string;
|
|
257
|
-
/** 要求的精确契约版本。 */
|
|
258
|
-
contractVersion: string;
|
|
259
|
-
/** 可选的预期提供 Runtime。 */
|
|
260
|
-
runtime?: RuntimeKind;
|
|
261
|
-
/** 可选的预期作用域。 */
|
|
262
|
-
scopeId?: string;
|
|
263
|
-
}
|
|
264
|
-
/** 服务代理调用上下文;服务端必须在最终边界重新检查引用和租约。 */
|
|
265
|
-
interface RemoteServiceCallContext {
|
|
266
|
-
/** 业务操作标识;可由调用方复用,用于审计和幂等,不作为传输关联键。 */
|
|
267
|
-
operationId?: string;
|
|
268
|
-
/** 实际建立代理的端口连接标识。 */
|
|
269
|
-
connectionId: string;
|
|
270
|
-
/** 创建代理时捕获的不可变引用。 */
|
|
271
|
-
reference: RemoteServiceReference;
|
|
272
|
-
/** 引用绑定的外部授权标识,供最终服务边界再次核验。 */
|
|
273
|
-
grantId?: string;
|
|
274
|
-
/** 同时受消费者作用域和本次请求控制的 signal。 */
|
|
275
|
-
signal: AbortSignal;
|
|
276
|
-
}
|
|
277
|
-
/** 跨环境传输实现;桥不负责自动重放有外部副作用的请求。 */
|
|
278
|
-
interface RemoteServiceTransport {
|
|
279
|
-
call<TRequest, TResult>(request: TRequest, context: RemoteServiceCallContext): Promise<TResult>;
|
|
280
|
-
}
|
|
281
|
-
/** 已绑定服务引用的代理;提供者重建后旧代理永久失效。 */
|
|
282
|
-
interface RemoteServiceProxy {
|
|
283
|
-
readonly reference: RemoteServiceReference;
|
|
284
|
-
readonly revoked: boolean;
|
|
285
|
-
call<TRequest, TResult>(request: TRequest, options?: {
|
|
286
|
-
signal?: AbortSignal;
|
|
287
|
-
operationId?: string; /** 旧 requestId 调用方别名;不作为传输 callId。 */
|
|
288
|
-
requestId?: string;
|
|
289
|
-
}): Promise<TResult>;
|
|
290
|
-
revoke(reason?: string): void;
|
|
291
|
-
}
|
|
292
|
-
type RemoteServiceBridgeState = "disconnected" | "handshaking" | "ready" | "stale";
|
|
293
|
-
/** 服务桥快照结果;调用方据此决定等待、重新握手或重新同步基线。 */
|
|
294
|
-
type RemoteServiceSnapshotResult = {
|
|
295
|
-
accepted: true;
|
|
296
|
-
state: RemoteServiceBridgeState;
|
|
297
|
-
snapshotRevision: number;
|
|
298
|
-
} | {
|
|
299
|
-
accepted: false;
|
|
300
|
-
reason: "wrong-connection" | "wrong-authority" | "stale-revision" | "baseline-required" | "revision-gap";
|
|
301
|
-
expectedRevision?: number;
|
|
302
|
-
receivedRevision: number;
|
|
303
|
-
};
|
|
304
|
-
/** 跨 Worker 服务桥最小本地契约。 */
|
|
305
|
-
interface RemoteServiceBridge {
|
|
306
|
-
/** 当前端口连接状态。 */
|
|
307
|
-
readonly state: RemoteServiceBridgeState;
|
|
308
|
-
/** 当前握手连接标识。 */
|
|
309
|
-
readonly connectionId?: string;
|
|
310
|
-
/** 当前权威启动身份。 */
|
|
311
|
-
readonly authorityInstanceId?: string;
|
|
312
|
-
/** 接受一次新握手;新连接会使旧代理全部失效。 */
|
|
313
|
-
handshake(input: RemoteServiceHandshake): {
|
|
314
|
-
accepted: boolean;
|
|
315
|
-
reason?: "protocol-mismatch";
|
|
316
|
-
};
|
|
317
|
-
/** 应用基线或连续增量快照;乱序和旧连接快照会被丢弃。 */
|
|
318
|
-
applySnapshot(snapshot: RemoteServiceSnapshot): RemoteServiceSnapshotResult;
|
|
319
|
-
/** 查询当前 ready 且版本精确匹配的服务代理。 */
|
|
320
|
-
getProxy(lookup: RemoteServiceLookup, scope?: LifecycleScope): RemoteServiceProxy | undefined;
|
|
321
|
-
/** 查询代理失败时抛出稳定错误。 */
|
|
322
|
-
requireProxy(lookup: RemoteServiceLookup, scope?: LifecycleScope): RemoteServiceProxy;
|
|
323
|
-
/** 同步撤下全部代理;不等待远端。 */
|
|
324
|
-
invalidate(reason?: string): void;
|
|
325
|
-
/** 端口断线;清除当前连接身份,后续快照必须等待新握手和基线。 */
|
|
326
|
-
disconnect(reason?: string): void;
|
|
327
|
-
/** 订阅桥状态和服务目录变化。 */
|
|
328
|
-
subscribe(listener: () => void): () => void;
|
|
329
|
-
/** 只读当前有效服务引用。 */
|
|
330
|
-
services(): readonly RemoteServiceReference[];
|
|
331
|
-
}
|
|
332
|
-
/** 服务桥未就绪或代理已失效。 */
|
|
333
|
-
declare class RemoteServiceUnavailableError extends Error {
|
|
334
|
-
readonly code: "service.unavailable";
|
|
335
|
-
constructor(message?: string);
|
|
336
|
-
}
|
|
337
|
-
/** 首次发布采用的升级并存策略。冷切换要求旧环境先退出;两阶段允许
|
|
338
|
-
* 短暂并存,但必须先在写入边界完成同一接管世代的排空。 */
|
|
339
|
-
type UpgradeMode = "cold-switch" | "two-phase";
|
|
340
|
-
/** 升级接管门禁状态;draining 仍可等待旧 I/O,但不接受新业务 I/O。 */
|
|
341
|
-
type UpgradeGateState = "active" | "draining" | "closed";
|
|
342
|
-
/** 新旧 Worker / 客户端接管握手。 */
|
|
343
|
-
interface UpgradeHandshake {
|
|
344
|
-
/** 发起握手的实际连接标识;会话不能脱离这条连接转移使用。 */
|
|
345
|
-
connectionId: string;
|
|
346
|
-
/** 控制协议版本;不兼容时拒绝业务接入。 */
|
|
347
|
-
protocolVersion: string;
|
|
348
|
-
/** 构建产物标识;不同构建只有显式兼容时才可接入。 */
|
|
349
|
-
buildId: string;
|
|
350
|
-
/** 当前运行环境启动身份。 */
|
|
351
|
-
authorityInstanceId: string;
|
|
352
|
-
/** 写入接管世代;旧世代不能重新取得租约。 */
|
|
353
|
-
handoverGeneration: number;
|
|
354
|
-
/** 对端支持的精确服务契约版本。 */
|
|
355
|
-
supportedContractVersions: readonly string[];
|
|
356
|
-
}
|
|
357
|
-
/** 升级握手结果。 */
|
|
358
|
-
type UpgradeHandshakeResult = {
|
|
359
|
-
accepted: true;
|
|
360
|
-
mode: UpgradeMode;
|
|
361
|
-
handoverGeneration: number;
|
|
362
|
-
contractVersion: string;
|
|
363
|
-
/** 只有握手返回的绑定会话才可申请 I/O 租约。 */
|
|
364
|
-
connectionId: string;
|
|
365
|
-
sessionId: string;
|
|
366
|
-
session: UpgradeSession;
|
|
367
|
-
} | {
|
|
368
|
-
accepted: false;
|
|
369
|
-
reason: "protocol-mismatch" | "build-incompatible" | "stale-generation" | "future-generation" | "contract-mismatch" | "draining" | "closed";
|
|
370
|
-
};
|
|
371
|
-
/** 一次已获准的 I/O 接管租约;排空期间已发租约可完成,close 后失效。 */
|
|
372
|
-
interface UpgradeIoLease {
|
|
373
|
-
/** 发放租约的实际连接标识。 */
|
|
374
|
-
readonly connectionId: string;
|
|
375
|
-
/** 发放该租约的握手会话。 */
|
|
376
|
-
readonly sessionId: string;
|
|
377
|
-
/** 发放租约的权威启动身份。 */
|
|
378
|
-
readonly authorityInstanceId: string;
|
|
379
|
-
/** 发放租约时的接管世代。 */
|
|
380
|
-
readonly handoverGeneration: number;
|
|
381
|
-
/** 精确匹配的服务契约版本。 */
|
|
382
|
-
readonly contractVersion: string;
|
|
383
|
-
/** 本次 I/O 类型;写入边界必须额外做领域校验。 */
|
|
384
|
-
readonly operation: "read" | "write";
|
|
385
|
-
/** 租约是否已撤销或主动释放。 */
|
|
386
|
-
readonly revoked: boolean;
|
|
387
|
-
/** 与本次 I/O 合并的取消信号。 */
|
|
388
|
-
readonly signal: AbortSignal;
|
|
389
|
-
/** 在最终提交前检查租约仍属于当前接管门禁。 */
|
|
390
|
-
assertActive(): void;
|
|
391
|
-
/** 释放租约;重复调用幂等。 */
|
|
392
|
-
release(): void;
|
|
393
|
-
}
|
|
394
|
-
/** 一次通过握手、绑定权威/世代/契约版本的接管会话。 */
|
|
395
|
-
interface UpgradeSession {
|
|
396
|
-
/** 会话绑定的实际连接标识;换连接必须重新握手。 */
|
|
397
|
-
readonly connectionId: string;
|
|
398
|
-
/** 不可猜测的会话标识;跨端传输时作为 opaque token。 */
|
|
399
|
-
readonly sessionId: string;
|
|
400
|
-
/** 发放会话的当前权威启动身份。 */
|
|
401
|
-
readonly authorityInstanceId: string;
|
|
402
|
-
/** 发放会话时的接管世代。 */
|
|
403
|
-
readonly handoverGeneration: number;
|
|
404
|
-
/** 握手协商出的精确服务契约版本。 */
|
|
405
|
-
readonly contractVersion: string;
|
|
406
|
-
/** 会话是否已撤销。 */
|
|
407
|
-
readonly revoked: boolean;
|
|
408
|
-
/** 会话撤销信号。 */
|
|
409
|
-
readonly signal: AbortSignal;
|
|
410
|
-
/** 校验会话仍可申请 I/O。 */
|
|
411
|
-
assertActive(): void;
|
|
412
|
-
/** 只能申请握手协商出的契约版本,不接受调用方换版本。 */
|
|
413
|
-
admit(input: {
|
|
414
|
-
operation: "read" | "write";
|
|
415
|
-
signal?: AbortSignal;
|
|
416
|
-
}): UpgradeIoLease;
|
|
417
|
-
/** 关闭当前握手会话并撤销其尚未完成的 I/O。 */
|
|
418
|
-
close(reason?: string): void;
|
|
419
|
-
}
|
|
420
|
-
/** 升级排空结果;超时不会伪装成已排空。 */
|
|
421
|
-
interface UpgradeDrainResult {
|
|
422
|
-
/** 排空时的门禁状态。 */
|
|
423
|
-
state: UpgradeGateState;
|
|
424
|
-
/** 是否确认所有已发 I/O 租约都已释放。 */
|
|
425
|
-
drained: boolean;
|
|
426
|
-
/** 仍未释放的 I/O 数量。 */
|
|
427
|
-
pending: number;
|
|
428
|
-
}
|
|
429
|
-
/** 接管门禁创建参数。 */
|
|
430
|
-
interface CreateUpgradeGateOptions {
|
|
431
|
-
/** 当前接受的控制协议版本。 */
|
|
432
|
-
protocolVersion: string;
|
|
433
|
-
/** 当前构建产物标识。 */
|
|
434
|
-
buildId: string;
|
|
435
|
-
/** 当前 Worker / 执行环境启动身份。 */
|
|
436
|
-
authorityInstanceId: string;
|
|
437
|
-
/** 当前写入接管世代。 */
|
|
438
|
-
handoverGeneration: number;
|
|
439
|
-
/** 当前允许的精确服务契约版本集合。 */
|
|
440
|
-
supportedContractVersions: readonly string[];
|
|
441
|
-
/** 冷切换或两阶段并存;默认冷切换。 */
|
|
442
|
-
mode?: UpgradeMode;
|
|
443
|
-
/** 显式允许接入的旧构建;不填时只接受同 buildId。 */
|
|
444
|
-
compatibleBuildIds?: ReadonlySet<string>;
|
|
445
|
-
/** 更复杂部署可提供显式构建兼容规则。 */
|
|
446
|
-
isBuildCompatible?: (buildId: string) => boolean;
|
|
447
|
-
}
|
|
448
|
-
/** 跨 Worker 写入接管门禁。它不负责选主、不负责调度插件。 */
|
|
449
|
-
interface UpgradeGate {
|
|
450
|
-
readonly state: UpgradeGateState;
|
|
451
|
-
readonly mode: UpgradeMode;
|
|
452
|
-
readonly authorityInstanceId: string;
|
|
453
|
-
readonly handoverGeneration: number;
|
|
454
|
-
/** 校验版本、构建、接管世代和精确契约版本。 */
|
|
455
|
-
handshake(input: UpgradeHandshake): UpgradeHandshakeResult;
|
|
456
|
-
/** 当前仍允许发放新业务 I/O 租约。 */
|
|
457
|
-
assertAccepting(): void;
|
|
458
|
-
/** 发放绑定当前握手会话、权威和世代的 I/O 租约。 */
|
|
459
|
-
admit(input: {
|
|
460
|
-
session: UpgradeSession;
|
|
461
|
-
operation: "read" | "write";
|
|
462
|
-
signal?: AbortSignal;
|
|
463
|
-
}): UpgradeIoLease;
|
|
464
|
-
/** 同步关闭新 I/O 入口;不等待已提交 I/O。 */
|
|
465
|
-
beginDrain(reason?: string): void;
|
|
466
|
-
/** 等待已发租约释放;超时后仍保持 draining。 */
|
|
467
|
-
drain(timeoutMs?: number): Promise<UpgradeDrainResult>;
|
|
468
|
-
/** 永久关闭并撤销尚未释放的租约。 */
|
|
469
|
-
close(reason?: string): void;
|
|
470
|
-
/** 当前已发且尚未释放的 I/O 数量。 */
|
|
471
|
-
activeIo(): number;
|
|
472
|
-
}
|
|
473
|
-
/** 升级门禁拒绝或租约失效。 */
|
|
474
|
-
declare class UpgradeGateRejectedError extends Error {
|
|
475
|
-
readonly code: "upgrade.gate_rejected";
|
|
476
|
-
readonly reason: string;
|
|
477
|
-
constructor(reason: string, message?: string);
|
|
478
|
-
}
|
|
479
|
-
/** 单次插件启停控制命令;目标是绝对意图,不是 toggle。 */
|
|
480
|
-
interface PluginIntentCommand {
|
|
481
|
-
/** 客户端生成的幂等命令标识。 */
|
|
482
|
-
commandId: string;
|
|
483
|
-
/** 命令发送方握手得到的控制面启动身份。 */
|
|
484
|
-
authorityInstanceId: string;
|
|
485
|
-
/** 客户端观察到的全局修订。 */
|
|
486
|
-
expectedRevision: number;
|
|
487
|
-
/** 目标产品标识。 */
|
|
488
|
-
pluginId: string;
|
|
489
|
-
/** 目标启用意图。 */
|
|
490
|
-
desiredEnabled: boolean;
|
|
491
|
-
}
|
|
492
|
-
/** 控制面持久化的插件意图快照。 */
|
|
493
|
-
interface PluginIntentSnapshot {
|
|
494
|
-
/** 控制面全局修订。 */
|
|
495
|
-
revision: number;
|
|
496
|
-
/** 每个产品当前的绝对启用意图。 */
|
|
497
|
-
desiredEnabled: Readonly<Record<string, boolean>>;
|
|
498
|
-
/** 每个产品自己的意图修订。 */
|
|
499
|
-
desiredRevision: Readonly<Record<string, number>>;
|
|
500
|
-
}
|
|
501
|
-
/** 启停命令的结构化结果;accepted 只表示意图已持久化。 */
|
|
502
|
-
type PluginIntentCommandResult = {
|
|
503
|
-
status: "accepted" | "duplicate";
|
|
504
|
-
commandId: string;
|
|
505
|
-
snapshot: PluginIntentSnapshot;
|
|
506
|
-
persisted: true;
|
|
507
|
-
} | {
|
|
508
|
-
status: "stale-authority";
|
|
509
|
-
commandId: string;
|
|
510
|
-
expectedAuthorityInstanceId: string;
|
|
511
|
-
} | {
|
|
512
|
-
status: "command-conflict";
|
|
513
|
-
commandId: string;
|
|
514
|
-
message: string;
|
|
515
|
-
} | {
|
|
516
|
-
status: "revision-conflict";
|
|
517
|
-
commandId: string;
|
|
518
|
-
snapshot: PluginIntentSnapshot;
|
|
519
|
-
} | {
|
|
520
|
-
status: "persistence-failed";
|
|
521
|
-
commandId: string;
|
|
522
|
-
message: string;
|
|
523
|
-
snapshot: PluginIntentSnapshot;
|
|
524
|
-
};
|
|
525
|
-
/** 意图 RPC 的完整结果;transport-error 不代表意图已保存。 */
|
|
526
|
-
type PluginIntentSubmissionResult = PluginIntentCommandResult | {
|
|
527
|
-
status: "transport-error";
|
|
528
|
-
message: string;
|
|
529
|
-
retryable: boolean;
|
|
530
|
-
};
|
|
531
|
-
/** 单一控制面上的命令去重、修订比较和持久化边界。 */
|
|
532
|
-
interface PluginIntentController {
|
|
533
|
-
/** 当前控制面启动身份;Worker 重启后必须更换。 */
|
|
534
|
-
readonly authorityInstanceId: string;
|
|
535
|
-
/** 当前意图快照。 */
|
|
536
|
-
snapshot(): PluginIntentSnapshot;
|
|
537
|
-
/** 串行提交一次绝对意图命令。 */
|
|
538
|
-
submit(command: PluginIntentCommand): Promise<PluginIntentCommandResult>;
|
|
539
|
-
/** 订阅持久化成功后的意图变化。 */
|
|
540
|
-
subscribe(listener: (snapshot: PluginIntentSnapshot) => void): () => void;
|
|
541
|
-
}
|
|
542
|
-
/** Host 使用的意图控制面适配器;生产实现位于 Coordinator client。 */
|
|
543
|
-
interface PluginIntentCoordinator {
|
|
544
|
-
/** 当前 SharedWorker authority;Worker 重启后变化。 */
|
|
545
|
-
readonly authorityInstanceId: string;
|
|
546
|
-
/** 当前权威意图快照。 */
|
|
547
|
-
snapshot(): PluginIntentSnapshot;
|
|
548
|
-
/** 提交绝对启停意图;不直接承诺运行实例已启动。 */
|
|
549
|
-
submit(command: PluginIntentCommand): Promise<PluginIntentSubmissionResult>;
|
|
550
|
-
/** 接收其它页面或 Worker 广播的持久化快照。 */
|
|
551
|
-
subscribe(listener: (snapshot: PluginIntentSnapshot) => void): () => void;
|
|
552
|
-
}
|
|
553
|
-
/** 带实例取消信号的后台任务定义;不负责持久化外部副作用。 */
|
|
554
|
-
interface ScopedTaskDefinition {
|
|
555
|
-
/** 全局唯一任务标识。 */
|
|
556
|
-
id: string;
|
|
557
|
-
/** 所属插件;默认由作用域身份提供。 */
|
|
558
|
-
pluginId?: string;
|
|
559
|
-
/** 展示名称。 */
|
|
560
|
-
label: string;
|
|
561
|
-
/** 周期;缺省表示只响应显式触发。 */
|
|
562
|
-
intervalMs?: number;
|
|
563
|
-
/** 任务执行体。 */
|
|
564
|
-
run(context: {
|
|
565
|
-
signal: AbortSignal;
|
|
566
|
-
reason: string;
|
|
567
|
-
}): void | Promise<void>;
|
|
568
|
-
}
|
|
569
|
-
/** 作用域任务的运行快照。 */
|
|
570
|
-
interface ScopedTaskSnapshot {
|
|
571
|
-
/** 任务标识。 */
|
|
572
|
-
id: string;
|
|
573
|
-
/** 所属插件。 */
|
|
574
|
-
pluginId: string;
|
|
575
|
-
/** 展示名称。 */
|
|
576
|
-
label: string;
|
|
577
|
-
/** 当前任务状态。 */
|
|
578
|
-
state: "idle" | "queued" | "running" | "failed";
|
|
579
|
-
/** 最近一次错误。 */
|
|
580
|
-
error?: string;
|
|
581
|
-
/** 最近成功时间。 */
|
|
582
|
-
lastCompletedAt?: string;
|
|
583
|
-
/** 下一次周期触发时间。 */
|
|
584
|
-
nextRunAt?: string;
|
|
585
|
-
}
|
|
586
|
-
/** 绑定作用域的最小任务调度器。 */
|
|
587
|
-
interface ScopedTaskScheduler {
|
|
588
|
-
/** 注册任务并返回幂等取消句柄。 */
|
|
589
|
-
register(definition: ScopedTaskDefinition): () => void;
|
|
590
|
-
/** 显式触发一次;同一任务运行中只合并一次重跑请求。 */
|
|
591
|
-
runNow(id: string, reason?: string): Promise<void>;
|
|
592
|
-
/** 取消当前任务实例并等待其退出。 */
|
|
593
|
-
cancel(id: string): Promise<void>;
|
|
594
|
-
/** 获取当前任务快照。 */
|
|
595
|
-
snapshot(): readonly ScopedTaskSnapshot[];
|
|
596
|
-
/** 订阅快照变化。 */
|
|
597
|
-
subscribe(listener: (snapshot: readonly ScopedTaskSnapshot[]) => void): () => void;
|
|
598
|
-
}
|
|
599
|
-
/** 作用域后台任务调度器 capability key。 */
|
|
600
|
-
declare const SCOPED_TASK_SCHEDULER_CAPABILITY = "runtime.task-scheduler";
|
|
601
|
-
/** 用户可见的稳定生命周期错误中文说明。 */
|
|
602
|
-
declare const LIFECYCLE_ERROR_TEXT: Readonly<Record<string, string>>;
|
|
603
|
-
/** 将稳定错误码映射到中文 UI 文案;未知错误返回通用提示。 */
|
|
604
|
-
declare function lifecycleErrorText(code: string): string;
|
|
605
|
-
|
|
606
|
-
/** runtime messageBus capability key;manifest 通过 ctx.get<...> 取出。 */
|
|
607
|
-
declare const RUNTIME_MESSAGE_BUS = "webloom.messageBus";
|
|
608
|
-
/** 消息调用语义。 */
|
|
609
|
-
type MessageMode = "event" | "command" | "request";
|
|
610
|
-
/** 消息 envelope。 */
|
|
611
|
-
interface Message<TPayload = unknown> {
|
|
612
|
-
id: string;
|
|
613
|
-
type: string;
|
|
614
|
-
mode: MessageMode;
|
|
615
|
-
payload: TPayload;
|
|
616
|
-
/** 由哪个 actor mailbox 消费。缺省时同步调用 subscriber 或无 mailbox。 */
|
|
617
|
-
target?: string;
|
|
618
|
-
/** 数值越大越优先(actor 内部解读)。 */
|
|
619
|
-
priority?: number;
|
|
620
|
-
/** 超时(ms);超时后 message 标记为超时失败。 */
|
|
621
|
-
timeoutMs?: number;
|
|
622
|
-
/**
|
|
623
|
-
* MessageBus 内部维护的 abort signal。
|
|
624
|
-
* - 来自调用方 DispatchOptions.signal 的 upstream 取消会触发。
|
|
625
|
-
* - 来自 MessageBus 自身的 timeout 触发。
|
|
626
|
-
* - 来自 actor / MessageBus 内部主动 abort。
|
|
627
|
-
* handler 应优先用此 signal 取消 fetch 等异步操作;payload.signal 仍
|
|
628
|
-
* 可保留以兼容旧调用方。
|
|
629
|
-
*/
|
|
630
|
-
signal?: AbortSignal;
|
|
631
|
-
causationId?: string;
|
|
632
|
-
createdAt: number;
|
|
633
|
-
}
|
|
634
|
-
/** 消息 handler 签名。 */
|
|
635
|
-
type MessageHandler<TPayload = unknown, TResult = unknown> = (message: Message<TPayload>) => TResult | Promise<TResult>;
|
|
636
|
-
/** publish 行为:仅同步广播给订阅者,不等待异步 handler 完成。 */
|
|
637
|
-
interface PublishOptions {
|
|
638
|
-
/** 关联上一条消息(同一业务动作触发的子事件)。 */
|
|
639
|
-
causationId?: string;
|
|
640
|
-
/** 自定义 message id;缺省由 MessageBus 生成。 */
|
|
641
|
-
messageId?: string;
|
|
642
|
-
}
|
|
643
|
-
/**
|
|
644
|
-
* dispatch 行为:投递给 actor mailbox;返回 messageId。
|
|
645
|
-
* - target 必填:dispatch 期望被 actor 处理,不退化为 publish 语义。
|
|
646
|
-
* - 找到 handler 时消息会真正入 mailbox 并被 pump 串行消费。
|
|
647
|
-
* - 找不到 handler 时消息被记为 failed + lastError,但**不抛**给调用方
|
|
648
|
-
* (dispatch 不返回结果)。
|
|
649
|
-
*/
|
|
650
|
-
interface DispatchOptions extends PublishOptions {
|
|
651
|
-
target: string;
|
|
652
|
-
priority?: number;
|
|
653
|
-
signal?: AbortSignal;
|
|
654
|
-
timeoutMs?: number;
|
|
655
|
-
/** 消息进入终态后调用一次;生命周期 facade 用它释放临时 signal 监听。 */
|
|
656
|
-
onSettled?: () => void;
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* request 行为:等待 actor 返回结果;选项语义与 dispatch 完全一致。
|
|
660
|
-
* - 行为差异:request 返回 Promise<TResult>,handler reject 即 promise reject。
|
|
661
|
-
* - 找不到 handler / no target 时立即 reject。
|
|
662
|
-
* - timeoutMs 触发时会先 abort 内部 signal,再 reject 外层 promise;
|
|
663
|
-
* handler 内部应该监听 message.signal 取消 fetch。
|
|
664
|
-
*/
|
|
665
|
-
type RequestOptions = DispatchOptions;
|
|
666
|
-
/** handle 注册选项。 */
|
|
667
|
-
interface HandlerOptions {
|
|
668
|
-
target?: string;
|
|
669
|
-
priority?: number;
|
|
670
|
-
/**
|
|
671
|
-
* 同 target 投递并发上限。
|
|
672
|
-
* 缺省 1:同 target actor 严格串行。
|
|
673
|
-
* 同 target 全部 handler 注册时必须使用一致 concurrency,否则
|
|
674
|
-
* MessageBus 抛 `Conflicting concurrency for target "..."`。
|
|
675
|
-
* 注意:这是 MessageBus 投递并发,不是 handler 内部副作用(如网络
|
|
676
|
-
* 请求)的并发;高并发适合"内部 actor 自己做限流"的场景(如 WOC
|
|
677
|
-
* 内部 mailbox)。
|
|
678
|
-
*/
|
|
679
|
-
concurrency?: number;
|
|
680
|
-
}
|
|
681
|
-
/** 快照。 */
|
|
682
|
-
interface MessageBusSnapshot {
|
|
683
|
-
/** 消息总数(含已完成、失败、被取消)。 */
|
|
684
|
-
total: number;
|
|
685
|
-
/** 队列中尚未处理的消息数。 */
|
|
686
|
-
queued: number;
|
|
687
|
-
/** 飞行中消息数。 */
|
|
688
|
-
inFlight: number;
|
|
689
|
-
/** 已成功完成的消息数。 */
|
|
690
|
-
completed: number;
|
|
691
|
-
/** handler 抛错或被 lastError 路径标记失败的消息数。 */
|
|
692
|
-
failed: number;
|
|
693
|
-
/** 被 abort signal 取消的消息数。 */
|
|
694
|
-
canceled: number;
|
|
695
|
-
/** 最近一次错误。 */
|
|
696
|
-
lastError?: string;
|
|
697
|
-
/** 各 target 队列长度。 */
|
|
698
|
-
byTarget: Record<string, number>;
|
|
699
|
-
}
|
|
700
|
-
/** 订阅事件快捷方式:仅接收 mode=event 的消息。 */
|
|
701
|
-
type EventHandler<TPayload = unknown> = (payload: TPayload) => void;
|
|
702
|
-
/**
|
|
703
|
-
* MessageBus 契约。
|
|
704
|
-
* 设计缘由:业务插件调用方只看到这一套入口。
|
|
705
|
-
*/
|
|
706
|
-
interface MessageBus {
|
|
707
|
-
/** 事件广播:已发生的事实,不等待业务完成;同步调用 subscriber。 */
|
|
708
|
-
publish<TPayload>(type: string, payload: TPayload, options?: PublishOptions): string;
|
|
709
|
-
/** 事件订阅:仅接收 mode=event 的消息;返回取消订阅函数。 */
|
|
710
|
-
subscribe<TPayload>(type: string, handler: EventHandler<TPayload>): () => void;
|
|
711
|
-
/**
|
|
712
|
-
* 命令投递:把消息入 actor mailbox,返回 messageId。
|
|
713
|
-
* 不等待 handler 完成;handler 抛错 / 超时 / 找不到 handler 仅写
|
|
714
|
-
* snapshot.lastError,不冒泡。
|
|
715
|
-
*/
|
|
716
|
-
dispatch<TPayload>(type: string, payload: TPayload, options: DispatchOptions): string;
|
|
717
|
-
/** 请求响应:等待 actor 返回结果。 */
|
|
718
|
-
request<TPayload, TResult>(type: string, payload: TPayload, options: RequestOptions): Promise<TResult>;
|
|
719
|
-
/** 注册 handler:带 target 时进入对应 actor mailbox。 */
|
|
720
|
-
handle<TPayload, TResult>(type: string, handler: MessageHandler<TPayload, TResult>, options?: HandlerOptions): () => void;
|
|
721
|
-
/** 快照。 */
|
|
722
|
-
snapshot(): MessageBusSnapshot;
|
|
723
|
-
/** 订阅快照变更。 */
|
|
724
|
-
onSnapshot(handler: (snapshot: MessageBusSnapshot) => void): () => void;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/** 宿主注入的只读结构化属性;不得放入私钥、口令或 Seed。 */
|
|
728
|
-
type PluginAttributes = Readonly<Record<string, unknown>>;
|
|
729
|
-
/** 插件配置的默认形状;具体配置由产品通过泛型约束。 */
|
|
730
|
-
type PluginConfig = Readonly<Record<string, unknown>>;
|
|
731
|
-
/** 插件对宿主贡献的默认形状;具体贡献由产品通过泛型约束。 */
|
|
732
|
-
type PluginContribution = unknown;
|
|
733
|
-
/** 插件 Context Extension 的默认形状;领域服务只能从这里注入。 */
|
|
734
|
-
type PluginContextExtension = Readonly<Record<string, unknown>>;
|
|
735
|
-
/** 插件运行时上下文,由 Host 创建并传入运行单元实现。 */
|
|
736
|
-
interface PluginContext<TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> {
|
|
737
|
-
/** Host 绑定的稳定产品标识;插件不能从调用参数伪造其它标识。 */
|
|
738
|
-
readonly pluginId: string;
|
|
739
|
-
/** 本次装配生成的实例标识;重启不得复用。 */
|
|
740
|
-
readonly instanceId: string;
|
|
741
|
-
/** 稳定运行单元标识;不等于本次启动的 instanceId。 */
|
|
742
|
-
readonly unitId: string;
|
|
743
|
-
/** 当前插件实例的作用域;业务资源应登记到此作用域。 */
|
|
744
|
-
readonly scope: LifecycleScope;
|
|
745
|
-
/** 作用域撤权信号;停止、禁用和宿主关闭时触发。 */
|
|
746
|
-
readonly signal: AbortSignal;
|
|
747
|
-
/** 可信装配层批准后的权限视图;插件自声明不能扩大集合。 */
|
|
748
|
-
readonly permissions: readonly PluginPermission[];
|
|
749
|
-
/** 绑定当前实例和权限身份的租约;最终 I/O 仍需再次校验。 */
|
|
750
|
-
readonly permissionLease: PermissionLease;
|
|
751
|
-
/** 已完成握手和快照校验的远程服务桥。 */
|
|
752
|
-
readonly serviceBridge?: RemoteServiceBridge;
|
|
753
|
-
/** 绑定当前插件实例的后台任务注册面。 */
|
|
754
|
-
readonly taskScheduler?: ScopedTaskScheduler;
|
|
755
|
-
/** 宿主注入的领域扩展;只读且不能替换实例身份。 */
|
|
756
|
-
readonly extension: TExtension;
|
|
757
|
-
/** 注册在停止前运行的清理函数;重复停止必须幂等。 */
|
|
758
|
-
onDispose(cleanup: PluginTeardown): void;
|
|
759
|
-
/** 注册 capability;重复注册会抛错。 */
|
|
760
|
-
provide<T>(key: string, value: T): void;
|
|
761
|
-
/** 读取 capability;缺失会抛错。 */
|
|
762
|
-
get<T>(key: string): T;
|
|
763
|
-
/** 探测 capability 是否存在。 */
|
|
764
|
-
has(key: string): boolean;
|
|
765
|
-
/** 要求 capability 存在,否则抛错。 */
|
|
766
|
-
require(key: string): void;
|
|
767
|
-
/** 事件、命令和请求响应的统一入口。 */
|
|
768
|
-
readonly messageBus: MessageBus;
|
|
769
|
-
/** 宿主注入的只读配置;不与启停意图存储混用。 */
|
|
770
|
-
readonly config?: TConfig;
|
|
771
|
-
}
|
|
772
|
-
/** v1 运行时依赖;跨 Runtime 绑定必须使用精确契约版本和来源 Runtime。 */
|
|
773
|
-
interface RuntimeDependency {
|
|
774
|
-
/** 依赖的 capability 标识。 */
|
|
775
|
-
capability: string;
|
|
776
|
-
/** 精确契约版本;跨 Runtime 依赖必须显式填写,本地可由 helper 推导。 */
|
|
777
|
-
contractVersion?: string;
|
|
778
|
-
/** 提供者实际运行空间;省略时由当前 Runtime 补齐。 */
|
|
779
|
-
sourceRuntime?: RuntimeKind;
|
|
780
|
-
/** 可选的人类可读诊断说明。 */
|
|
781
|
-
reason?: string;
|
|
782
|
-
/** 缺失时只关闭局部能力,不阻止主体运行。 */
|
|
783
|
-
optional?: boolean;
|
|
784
|
-
}
|
|
785
|
-
/** 简单插件的产品级依赖别名。 */
|
|
786
|
-
type PluginDependency = RuntimeDependency;
|
|
787
|
-
/** 运行单元的严格依赖描述。 */
|
|
788
|
-
interface RuntimeUnitDependency {
|
|
789
|
-
/** 依赖的 capability 标识。 */
|
|
790
|
-
capability: string;
|
|
791
|
-
/** 精确契约版本;第一阶段只接受完全匹配。 */
|
|
792
|
-
contractVersion: string;
|
|
793
|
-
/** 提供者实际运行空间;跨 Runtime 依赖在 materialize/validate 边界必须补齐。 */
|
|
794
|
-
sourceRuntime: RuntimeKind;
|
|
795
|
-
/** 可选的人类可读诊断说明。 */
|
|
796
|
-
reason?: string;
|
|
797
|
-
/** 缺失时只关闭局部能力;未填写表示硬依赖。 */
|
|
798
|
-
optional?: boolean;
|
|
799
|
-
}
|
|
800
|
-
/** 作者入口的未归一化 unit 依赖;进入 Host 前必须补齐版本和来源 Runtime。 */
|
|
801
|
-
type RuntimeUnitDependencyInput = Omit<RuntimeUnitDependency, "contractVersion" | "sourceRuntime"> & {
|
|
802
|
-
contractVersion?: string;
|
|
803
|
-
sourceRuntime?: RuntimeKind;
|
|
804
|
-
};
|
|
805
|
-
/** 返回稳定的 capability 契约版本。 */
|
|
806
|
-
declare function runtimeCapabilityContractVersion(capability: string): string;
|
|
807
|
-
/** 将依赖清单补齐为严格运行单元依赖。 */
|
|
808
|
-
declare function defineRuntimeUnitDependencies(dependencies: readonly Pick<PluginDependency, "capability" | "reason" | "optional">[], defaults: {
|
|
809
|
-
sourceRuntime: RuntimeKind;
|
|
810
|
-
}): RuntimeUnitDependency[];
|
|
811
|
-
/** 为运行单元生成精确的 capability 契约版本表。 */
|
|
812
|
-
declare function defineRuntimeUnitProvidedContracts(capabilities: readonly string[]): Record<string, string>;
|
|
813
|
-
/** 插件在产品清单中的启动要求。 */
|
|
814
|
-
type PluginStartupMode = "required" | "optional";
|
|
815
|
-
/** 插件装配元数据;v1 不解释产品分类字段。 */
|
|
816
|
-
interface PluginMeta {
|
|
817
|
-
/** 首次装配时默认是否启用。 */
|
|
818
|
-
defaultEnabled: boolean;
|
|
819
|
-
/** 是否允许产品控制面禁用。 */
|
|
820
|
-
canDisable: boolean;
|
|
821
|
-
/** 是否属于启动必需插件。 */
|
|
822
|
-
startup?: PluginStartupMode;
|
|
823
|
-
}
|
|
824
|
-
/** 插件 setup 返回的清理函数。 */
|
|
825
|
-
type PluginTeardown = () => void | Promise<void>;
|
|
826
|
-
/** 插件运行单元的无 UI 装配入口。 */
|
|
827
|
-
type PluginSetup<TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> = (ctx: PluginContext<TConfig, TExtension>) => void | Promise<void> | PluginTeardown | Promise<PluginTeardown>;
|
|
828
|
-
/** 当前执行环境中按 productId + unitId 解析实现。 */
|
|
829
|
-
interface RuntimeUnitImplementationRegistry<TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> {
|
|
830
|
-
/** 未装配实现时返回 undefined。 */
|
|
831
|
-
get(pluginId: string, unitId: string): PluginSetup<TConfig, TExtension> | undefined;
|
|
832
|
-
}
|
|
833
|
-
/** 一个产品可以装配的运行单元。 */
|
|
834
|
-
interface RuntimeUnitDescriptor<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig> {
|
|
835
|
-
/** 稳定运行单元标识。 */
|
|
836
|
-
id: string;
|
|
837
|
-
/** 运行代码所在真实 Runtime。 */
|
|
838
|
-
runtime: RuntimeKind;
|
|
839
|
-
/** 本单元所需的精确 capability 契约。 */
|
|
840
|
-
dependencies?: RuntimeUnitDependency[];
|
|
841
|
-
/** 本单元提供的 capability。 */
|
|
842
|
-
provides?: string[];
|
|
843
|
-
/** 本单元每个 capability 的精确版本。 */
|
|
844
|
-
providedContracts?: Record<string, string>;
|
|
845
|
-
/** 宿主贡献;内容由产品泛型定义。 */
|
|
846
|
-
contribution?: TContribution;
|
|
847
|
-
/** 本单元申请的权限。 */
|
|
848
|
-
permissions?: PluginPermission[];
|
|
849
|
-
/** 单元专属只读配置声明或装配默认值。 */
|
|
850
|
-
config?: TConfig;
|
|
851
|
-
}
|
|
852
|
-
/** 作者入口的未归一化运行单元;runtime 可由 createWindowApp/startSharedWorkerApp 注入。 */
|
|
853
|
-
type RuntimeUnitDescriptorInput<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig> = Omit<RuntimeUnitDescriptor<TContribution, TConfig>, "runtime" | "dependencies"> & {
|
|
854
|
-
runtime?: RuntimeKind;
|
|
855
|
-
dependencies?: readonly RuntimeUnitDependencyInput[];
|
|
856
|
-
};
|
|
857
|
-
/** 插件清单;插件作者导出的唯一静态描述。 */
|
|
858
|
-
interface PluginManifest<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> {
|
|
859
|
-
/** 全局稳定产品标识。 */
|
|
860
|
-
id: string;
|
|
861
|
-
/** 展示名称。 */
|
|
862
|
-
name: string;
|
|
863
|
-
/** 展示描述。 */
|
|
864
|
-
description?: string;
|
|
865
|
-
/** 简单插件的宿主贡献;复杂产品通过运行单元声明。 */
|
|
866
|
-
contribution?: TContribution;
|
|
867
|
-
/** 简单插件的兼容依赖。 */
|
|
868
|
-
dependencies?: PluginDependency[];
|
|
869
|
-
/** 简单插件声明提供的 capability;多单元插件必须放入 unit.provides。 */
|
|
870
|
-
provides?: string[];
|
|
871
|
-
/** 产品元数据。 */
|
|
872
|
-
meta: PluginMeta;
|
|
873
|
-
/** 简单插件的申请权限。 */
|
|
874
|
-
permissions?: PluginPermission[];
|
|
875
|
-
/** 多环境插件的静态运行单元描述。 */
|
|
876
|
-
units?: readonly RuntimeUnitDescriptor<TContribution, TConfig>[];
|
|
877
|
-
/** 简单插件的只读配置。 */
|
|
878
|
-
config?: TConfig;
|
|
879
|
-
}
|
|
880
|
-
/** 作者入口的未归一化静态清单;进入 Host 前必须 materialize 成 PluginManifest。 */
|
|
881
|
-
type PluginManifestInput<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> = Omit<PluginManifest<TContribution, TConfig, TExtension>, "units"> & {
|
|
882
|
-
units?: readonly RuntimeUnitDescriptorInput<TContribution, TConfig>[];
|
|
883
|
-
};
|
|
884
|
-
/** 插件运行状态类别;registered 不代表已经运行。 */
|
|
885
|
-
type PluginStateKind = "registered" | "starting" | "stopping" | "enabled" | "disabled" | "blocked" | "error-disabled" | "cleanup-pending" | "unknown";
|
|
886
|
-
/** 对外稳定的产品运行语义。 */
|
|
887
|
-
type PluginLifecycleState = "disabled" | "waiting" | "starting" | "running" | "stopping" | "failed";
|
|
888
|
-
/** Host 查询到的插件状态。 */
|
|
889
|
-
interface PluginState {
|
|
890
|
-
/** 产品标识。 */
|
|
891
|
-
id: string;
|
|
892
|
-
/** 兼容状态类别。 */
|
|
893
|
-
kind: PluginStateKind;
|
|
894
|
-
/** 稳定生命周期语义。 */
|
|
895
|
-
lifecycleState?: PluginLifecycleState;
|
|
896
|
-
/** 最近一次错误。 */
|
|
897
|
-
error?: string;
|
|
898
|
-
/** 持久化启用意图。 */
|
|
899
|
-
desiredEnabled?: boolean;
|
|
900
|
-
/** 当前产品意图修订。 */
|
|
901
|
-
desiredRevision?: number;
|
|
902
|
-
/** 当前运行实例标识。 */
|
|
903
|
-
instanceId?: string;
|
|
904
|
-
/** 当前运行单元标识。 */
|
|
905
|
-
unitId?: string;
|
|
906
|
-
/** 当前阻塞或清理原因。 */
|
|
907
|
-
blockedBy?: string[];
|
|
908
|
-
/** 最近一次结构化清理结果。 */
|
|
909
|
-
cleanup?: LifecycleDisposeResult;
|
|
910
|
-
/** 当前产品下的运行单元状态。 */
|
|
911
|
-
units?: readonly PluginUnitState[];
|
|
912
|
-
}
|
|
913
|
-
/** 运行单元状态;唯一身份由 product、unit 和 instance 共同组成。 */
|
|
914
|
-
interface PluginUnitState {
|
|
915
|
-
/** 所属产品标识。 */
|
|
916
|
-
pluginId: string;
|
|
917
|
-
/** 稳定运行单元标识。 */
|
|
918
|
-
unitId: string;
|
|
919
|
-
/** 真实运行空间。 */
|
|
920
|
-
runtime: RuntimeKind;
|
|
921
|
-
/** 当前运行实例。 */
|
|
922
|
-
instanceId?: string;
|
|
923
|
-
/** 当前意图修订。 */
|
|
924
|
-
desiredRevision?: number;
|
|
925
|
-
/** 单元状态。 */
|
|
926
|
-
kind: PluginStateKind;
|
|
927
|
-
/** 单元失败原因。 */
|
|
928
|
-
error?: string;
|
|
929
|
-
/** 单元清理结果。 */
|
|
930
|
-
cleanup?: LifecycleDisposeResult;
|
|
931
|
-
}
|
|
932
|
-
/** 依赖图中的反向依赖者。 */
|
|
933
|
-
interface PluginReverseDep {
|
|
934
|
-
/** 反向依赖产品标识。 */
|
|
935
|
-
pluginId: string;
|
|
936
|
-
/** 依赖者当前是否运行。 */
|
|
937
|
-
enabled: boolean;
|
|
938
|
-
/** 触发依赖的 capability。 */
|
|
939
|
-
capabilities: string[];
|
|
940
|
-
}
|
|
941
|
-
/** 插件依赖图快照。 */
|
|
942
|
-
interface PluginGraph {
|
|
943
|
-
/** 已知产品标识列表。 */
|
|
944
|
-
plugins: string[];
|
|
945
|
-
/** 产品依赖的 capability。 */
|
|
946
|
-
dependencies: Record<string, string[]>;
|
|
947
|
-
/** 产品的可选依赖。 */
|
|
948
|
-
optionalDependencies?: Record<string, string[]>;
|
|
949
|
-
/** 产品声明提供的 capability。 */
|
|
950
|
-
provides: Record<string, string[]>;
|
|
951
|
-
/** capability 到反向依赖者。 */
|
|
952
|
-
reverse: Record<string, PluginReverseDep[]>;
|
|
953
|
-
/** capability 到声明提供者。 */
|
|
954
|
-
providers?: Record<string, string[]>;
|
|
955
|
-
/** 精确依赖描述。 */
|
|
956
|
-
dependencyDetails?: Record<string, PluginDependency[]>;
|
|
957
|
-
/** 发现的硬依赖环。 */
|
|
958
|
-
cycles?: string[][];
|
|
959
|
-
/** 当前图中的运行单元。 */
|
|
960
|
-
units?: Record<string, PluginUnitGraph>;
|
|
961
|
-
}
|
|
962
|
-
/** 运行单元依赖图节点。 */
|
|
963
|
-
interface PluginUnitGraph {
|
|
964
|
-
/** 所属产品标识。 */
|
|
965
|
-
pluginId: string;
|
|
966
|
-
/** 稳定运行单元标识。 */
|
|
967
|
-
unitId: string;
|
|
968
|
-
/** 真实运行空间。 */
|
|
969
|
-
runtime: RuntimeKind;
|
|
970
|
-
/** capability 依赖。 */
|
|
971
|
-
dependencies: string[];
|
|
972
|
-
/** 精确依赖描述。 */
|
|
973
|
-
dependencyDetails?: RuntimeUnitDependency[];
|
|
974
|
-
/** capability 提供。 */
|
|
975
|
-
provides: string[];
|
|
976
|
-
/** capability 精确版本。 */
|
|
977
|
-
providedContracts?: Record<string, string>;
|
|
978
|
-
}
|
|
979
|
-
/** Host 版本或状态变化监听器。 */
|
|
980
|
-
type HostListener = (snapshot: {
|
|
981
|
-
version: number;
|
|
982
|
-
}) => void;
|
|
983
|
-
/** 启动前能力检查的结构化详情。 */
|
|
984
|
-
interface StartupCapabilityErrorDetails {
|
|
985
|
-
/** 缺失 capability 标识。 */
|
|
986
|
-
capability: string;
|
|
987
|
-
/** 已知提供者产品标识。 */
|
|
988
|
-
providerPluginId?: string;
|
|
989
|
-
/** 提供者状态。 */
|
|
990
|
-
providerState?: PluginStateKind;
|
|
991
|
-
/** 提供者错误。 */
|
|
992
|
-
providerError?: string;
|
|
993
|
-
/** 当前持久化意图。 */
|
|
994
|
-
configuredEnabled?: boolean;
|
|
995
|
-
}
|
|
996
|
-
/** 启动插件失败的结构化详情。 */
|
|
997
|
-
interface StartupPluginErrorDetails {
|
|
998
|
-
/** 产品标识。 */
|
|
999
|
-
pluginId: string;
|
|
1000
|
-
/** 失败的运行单元。 */
|
|
1001
|
-
unitId?: string;
|
|
1002
|
-
/** 能力列表。 */
|
|
1003
|
-
capabilities: string[];
|
|
1004
|
-
/** 当前状态。 */
|
|
1005
|
-
state: PluginStateKind;
|
|
1006
|
-
/** 最近错误。 */
|
|
1007
|
-
error?: string;
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
/** 资源键:稳定、可比较且不含秘密的字符串元组。 */
|
|
1011
|
-
type ResourceKey = readonly [resourceId: string, ...parts: readonly string[]];
|
|
1012
|
-
/** 资源当前状态。 */
|
|
1013
|
-
type ResourceStatus = "pending" | "ready" | "stale" | "error" | "blocked";
|
|
1014
|
-
/** 资源快照:状态、数据、错误和单调修订。 */
|
|
1015
|
-
interface ResourceSnapshot<T> {
|
|
1016
|
-
/** 资源键。 */
|
|
1017
|
-
readonly key: ResourceKey;
|
|
1018
|
-
/** 当前加载状态。 */
|
|
1019
|
-
readonly status: ResourceStatus;
|
|
1020
|
-
/** 当前数据;未 ready 时可以为空。 */
|
|
1021
|
-
readonly data: T | undefined;
|
|
1022
|
-
/** 稳定错误码和可展示错误信息。 */
|
|
1023
|
-
readonly error?: {
|
|
1024
|
-
readonly code: string;
|
|
1025
|
-
readonly message: string;
|
|
1026
|
-
};
|
|
1027
|
-
/** 快照修订,每次有效变化递增。 */
|
|
1028
|
-
readonly revision: number;
|
|
1029
|
-
}
|
|
1030
|
-
/** 资源读取上下文;只提供通用 capability 和宿主扩展属性。 */
|
|
1031
|
-
interface ResourceContext<TAttributes extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>> {
|
|
1032
|
-
/** 读取已注入的 capability;不存在时返回 undefined。 */
|
|
1033
|
-
getCapability<T>(id: string): T | undefined;
|
|
1034
|
-
/** 资源定义所属的插件实例标识;由注册表绑定,插件不能伪造。 */
|
|
1035
|
-
readonly ownerId: string;
|
|
1036
|
-
/** 宿主绑定的当前作用域属性;资源定义不能写入。 */
|
|
1037
|
-
readonly attributes: TAttributes;
|
|
1038
|
-
}
|
|
1039
|
-
/** Runtime-only metadata used to bind a definition to an owner. */
|
|
1040
|
-
declare const RESOURCE_OWNER: unique symbol;
|
|
1041
|
-
type OwnedResourceDefinition = ResourceDefinition<unknown, readonly string[]> & {
|
|
1042
|
-
readonly [RESOURCE_OWNER]?: string;
|
|
1043
|
-
};
|
|
1044
|
-
/** 资源定义:描述键、加载、失效订阅与比较方式。 */
|
|
1045
|
-
interface ResourceDefinition<T, TArgs extends readonly string[] = readonly string[]> {
|
|
1046
|
-
/** 资源唯一标识。 */
|
|
1047
|
-
readonly id: string;
|
|
1048
|
-
/** 资源所依附的生命周期标签,由宿主解释。 */
|
|
1049
|
-
readonly scope: string;
|
|
1050
|
-
/** 生成资源键。 */
|
|
1051
|
-
key(args: TArgs, context: ResourceContext): ResourceKey;
|
|
1052
|
-
/** 加载资源数据;实现必须响应 signal。 */
|
|
1053
|
-
load(args: TArgs, context: ResourceContext, signal: AbortSignal): Promise<T>;
|
|
1054
|
-
/** 订阅失效事件;只表达失效,不直接改写快照。 */
|
|
1055
|
-
subscribe?(args: TArgs, context: ResourceContext, invalidate: () => void): () => void;
|
|
1056
|
-
/** 语义相等判断;返回 true 时不发布新数据快照。 */
|
|
1057
|
-
equals?(previous: T | undefined, next: T | undefined): boolean;
|
|
1058
|
-
/** 同一事件循环内是否合并失效通知。 */
|
|
1059
|
-
readonly invalidation: "immediate" | "microtask";
|
|
1060
|
-
}
|
|
1061
|
-
/** 资源定义注册表。 */
|
|
1062
|
-
interface ResourceRegistry {
|
|
1063
|
-
/** 注册资源定义。 */
|
|
1064
|
-
register<T, TArgs extends readonly string[]>(definition: ResourceDefinition<T, TArgs>): void;
|
|
1065
|
-
/** 注销资源定义。 */
|
|
1066
|
-
unregister(id: string): void;
|
|
1067
|
-
/** 查询资源定义。 */
|
|
1068
|
-
get<T, TArgs extends readonly string[]>(id: string): ResourceDefinition<T, TArgs> | undefined;
|
|
1069
|
-
/** 调试和宿主清理使用的定义标识。 */
|
|
1070
|
-
_ids(): string[];
|
|
1071
|
-
}
|
|
1072
|
-
/** Resource Registry 的 capability 标识。 */
|
|
1073
|
-
declare const RESOURCE_REGISTRY_CAPABILITY = "webloom.resource.registry";
|
|
1074
|
-
|
|
1075
|
-
interface CapabilityRegistry {
|
|
1076
|
-
provide<T>(key: string, value: T): void;
|
|
1077
|
-
/**
|
|
1078
|
-
* 硬切换 001:撤销一个 capability。
|
|
1079
|
-
* 不存在时 no-op;存在则移除。提供方应保证自己负责的 capability
|
|
1080
|
-
* 被撤销时,相关订阅/资源也被清理(这通常由 host 的 plugin teardown
|
|
1081
|
-
* 流程负责)。
|
|
1082
|
-
*/
|
|
1083
|
-
revoke(key: string): void;
|
|
1084
|
-
get<T>(key: string): T;
|
|
1085
|
-
has(key: string): boolean;
|
|
1086
|
-
require(key: string): void;
|
|
1087
|
-
/** 仅用于调试。 */
|
|
1088
|
-
keys(): string[];
|
|
1089
|
-
}
|
|
1090
|
-
declare function createCapabilityRegistry(): CapabilityRegistry;
|
|
1091
|
-
|
|
1092
|
-
/** Resource Store 公共 API。 */
|
|
1093
|
-
interface ResourceStoreApi {
|
|
1094
|
-
/** 确保资源已加载,并返回当前快照。 */
|
|
1095
|
-
ensure<T>(definitionId: string, args: readonly string[]): ResourceSnapshot<T>;
|
|
1096
|
-
/** 订阅资源变更。 */
|
|
1097
|
-
subscribe(definitionId: string, args: readonly string[], callback: () => void): () => void;
|
|
1098
|
-
/** 读取资源快照,不触发加载。 */
|
|
1099
|
-
read<T>(definitionId: string, args: readonly string[]): ResourceSnapshot<T> | undefined;
|
|
1100
|
-
/** 使资源失效并重新加载。 */
|
|
1101
|
-
invalidate(definitionId: string, args: readonly string[]): void;
|
|
1102
|
-
/** 清理指定 owner 的所有资源记录。 */
|
|
1103
|
-
disposeOwner(ownerId: string): void;
|
|
1104
|
-
/** 宿主属性或 capability 变化后刷新绑定。 */
|
|
1105
|
-
refreshRuntimeBindings(): void;
|
|
1106
|
-
/** 订阅宿主 Context 变化。 */
|
|
1107
|
-
subscribeContext(callback: () => void): () => void;
|
|
1108
|
-
}
|
|
1109
|
-
type Attributes = Readonly<Record<string, unknown>>;
|
|
1110
|
-
/** 创建通用 Resource Store。 */
|
|
1111
|
-
declare function createResourceStore(registry: ResourceRegistry, getCapability: <T>(id: string) => T | undefined, getAttributes?: (ownerId?: string) => Attributes): ResourceStoreApi;
|
|
1112
|
-
|
|
1113
|
-
/** 插件启停意图的通用持久化端口。 */
|
|
1114
|
-
interface PluginConfigStore {
|
|
1115
|
-
/** 读取产品级绝对启停意图。 */
|
|
1116
|
-
read(): Readonly<Record<string, boolean>>;
|
|
1117
|
-
/** 写入一个产品的绝对启停意图。 */
|
|
1118
|
-
setEnabled(pluginId: string, enabled: boolean): void;
|
|
1119
|
-
/** 订阅外部控制面带来的变化。 */
|
|
1120
|
-
subscribe(listener: (snapshot: Readonly<Record<string, boolean>>) => void): () => void;
|
|
1121
|
-
}
|
|
1122
|
-
/** 创建内存配置端口;产品可通过 configStore 注入持久化实现。 */
|
|
1123
|
-
declare function createInMemoryPluginConfigStore(initial?: Readonly<Record<string, boolean>>, readOnly?: boolean): PluginConfigStore;
|
|
1124
|
-
/** 权限策略输入;申请、批准和会话约束必须分开计算。 */
|
|
1125
|
-
interface PermissionPolicyInput {
|
|
1126
|
-
/** 产品标识。 */
|
|
1127
|
-
pluginId: string;
|
|
1128
|
-
/** 运行单元标识。 */
|
|
1129
|
-
unitId: string;
|
|
1130
|
-
/** 当前 Scope 身份。 */
|
|
1131
|
-
identity: LifecycleScopeIdentity;
|
|
1132
|
-
/** 清单申请的权限。 */
|
|
1133
|
-
requested: readonly PluginPermission[];
|
|
1134
|
-
}
|
|
1135
|
-
/** 权限策略结果;Host 只发放三者交集。 */
|
|
1136
|
-
interface PermissionPolicyResult {
|
|
1137
|
-
/** 可信装配批准集合;缺省为申请集合。 */
|
|
1138
|
-
approved?: readonly PluginPermission[];
|
|
1139
|
-
/** 当前会话的额外限制。 */
|
|
1140
|
-
sessionConstraints?: readonly PluginPermission[];
|
|
1141
|
-
/** 绑定到租约的策略/授权修订。 */
|
|
1142
|
-
binding?: Partial<Pick<PermissionLeaseBinding, "policyRevision" | "grantRevision" | "grantId">>;
|
|
1143
|
-
}
|
|
1144
|
-
/** Context Extension 生成输入。 */
|
|
1145
|
-
interface ContextExtensionInput {
|
|
1146
|
-
/** 产品标识。 */
|
|
1147
|
-
pluginId: string;
|
|
1148
|
-
/** 运行单元标识。 */
|
|
1149
|
-
unitId: string;
|
|
1150
|
-
/** 本次实例标识。 */
|
|
1151
|
-
instanceId: string;
|
|
1152
|
-
/** 实例 Scope。 */
|
|
1153
|
-
scope: LifecycleScope;
|
|
1154
|
-
/** 静态清单。 */
|
|
1155
|
-
manifest: PluginManifest;
|
|
1156
|
-
}
|
|
1157
|
-
/** 贡献注册的运行时输入。 */
|
|
1158
|
-
interface ContributionAdapterInput {
|
|
1159
|
-
/** 产品标识。 */
|
|
1160
|
-
pluginId: string;
|
|
1161
|
-
/** 运行单元标识。 */
|
|
1162
|
-
unitId: string;
|
|
1163
|
-
/** 实例标识。 */
|
|
1164
|
-
instanceId: string;
|
|
1165
|
-
/** 实例 Scope。 */
|
|
1166
|
-
scope: LifecycleScope;
|
|
1167
|
-
/** 泛型产品贡献。 */
|
|
1168
|
-
contribution: unknown;
|
|
1169
|
-
/** 完整静态清单。 */
|
|
1170
|
-
manifest: PluginManifest;
|
|
1171
|
-
}
|
|
1172
|
-
/** 贡献适配器返回的同步撤权/异步清理句柄。 */
|
|
1173
|
-
interface ContributionHandle {
|
|
1174
|
-
/** 同步撤下 UI、命令或其它入口;不能等待网络。 */
|
|
1175
|
-
revoke?(): void;
|
|
1176
|
-
/** 异步完成底层清理;失败必须可观察。 */
|
|
1177
|
-
dispose?(): void | Promise<void>;
|
|
1178
|
-
}
|
|
1179
|
-
/** 宿主贡献适配器;具体产品可以注册多个不同领域的适配器。 */
|
|
1180
|
-
interface ContributionAdapter {
|
|
1181
|
-
/** 适配器名称,仅用于诊断。 */
|
|
1182
|
-
name?: string;
|
|
1183
|
-
/** 注册一份泛型贡献。 */
|
|
1184
|
-
register(input: ContributionAdapterInput): void | ContributionHandle | (() => void | Promise<void>) | Promise<void | ContributionHandle | (() => void | Promise<void>)>;
|
|
1185
|
-
}
|
|
1186
|
-
/** 运行单元可用性检查;返回稳定原因表示当前实例不能装配。 */
|
|
1187
|
-
interface RuntimeUnitAvailabilityInput {
|
|
1188
|
-
/** 产品标识。 */
|
|
1189
|
-
pluginId: string;
|
|
1190
|
-
/** 运行单元标识。 */
|
|
1191
|
-
unitId: string;
|
|
1192
|
-
/** 真实 Runtime。 */
|
|
1193
|
-
runtime: RuntimeKind;
|
|
1194
|
-
}
|
|
1195
|
-
/** 新运行单元 Scope 的身份属性输入。 */
|
|
1196
|
-
interface RuntimeUnitAttributesInput extends RuntimeUnitAvailabilityInput {
|
|
1197
|
-
/** 静态产品清单。 */
|
|
1198
|
-
manifest: PluginManifest;
|
|
1199
|
-
}
|
|
1200
|
-
/** 为运行单元选择父 Scope;未提供时运行单元直接挂在 Host 根 Scope。 */
|
|
1201
|
-
type RuntimeUnitParentScopeInput = RuntimeUnitAttributesInput;
|
|
1202
|
-
/** 通用运行单元快照;用于展示远端单元未知/恢复状态。 */
|
|
1203
|
-
interface RuntimeUnitSnapshot {
|
|
1204
|
-
/** 产品标识。 */
|
|
1205
|
-
pluginId: string;
|
|
1206
|
-
/** 单元标识。 */
|
|
1207
|
-
unitId: string;
|
|
1208
|
-
/** 真实 Runtime。 */
|
|
1209
|
-
runtime: RuntimeKind;
|
|
1210
|
-
/** 远端实例标识。 */
|
|
1211
|
-
instanceId?: string;
|
|
1212
|
-
/** 远端当前状态。 */
|
|
1213
|
-
state: PluginStateKind;
|
|
1214
|
-
}
|
|
1215
|
-
interface CreatePluginHostOptions {
|
|
1216
|
-
/** 当前 Host 所在真实 Runtime。 */
|
|
1217
|
-
runtime?: RuntimeKind;
|
|
1218
|
-
/** 根 Scope 的宿主只读属性。 */
|
|
1219
|
-
rootAttributes?: Readonly<Record<string, unknown>>;
|
|
1220
|
-
/** 预注入的内建 capability;不归属于任何插件实例。 */
|
|
1221
|
-
capabilities?: Readonly<Record<string, unknown>> | ReadonlyMap<string, unknown>;
|
|
1222
|
-
/** 可选的资源定义注册表;适配器可把领域 facade 绑定到同一个 Store。 */
|
|
1223
|
-
resourceRegistry?: ResourceRegistry;
|
|
1224
|
-
/** 可选的消息总线;适配器可为 legacy capability 保持同一实例。 */
|
|
1225
|
-
messageBus?: MessageBus;
|
|
1226
|
-
/** builtin capability 的别名,便于适配器明确表达用途。 */
|
|
1227
|
-
builtinCapabilities?: Readonly<Record<string, unknown>> | ReadonlyMap<string, unknown>;
|
|
1228
|
-
/** 生成领域 Context Extension;结果会浅冻结。 */
|
|
1229
|
-
contextExtension?: (input: ContextExtensionInput) => Readonly<Record<string, unknown>>;
|
|
1230
|
-
/** 校验产品清单中的宿主扩展字段。 */
|
|
1231
|
-
manifestValidator?: (manifest: PluginManifest) => void;
|
|
1232
|
-
/** 计算权限批准与会话交集。 */
|
|
1233
|
-
permissionPolicy?: (input: PermissionPolicyInput) => PermissionPolicyResult;
|
|
1234
|
-
/** 启停意图持久化端口。 */
|
|
1235
|
-
configStore?: PluginConfigStore;
|
|
1236
|
-
/** 兼容测试的内存启停意图。 */
|
|
1237
|
-
initialPluginConfig?: Readonly<Record<string, boolean>>;
|
|
1238
|
-
/** 多页面唯一启停控制面。 */
|
|
1239
|
-
pluginIntentCoordinator?: PluginIntentCoordinator;
|
|
1240
|
-
/** 为实例绑定远程服务桥。 */
|
|
1241
|
-
serviceBridgeForPlugin?: (pluginId: string, instanceId: string) => RemoteServiceBridge | undefined;
|
|
1242
|
-
/** 当前执行环境的运行单元实现注册表。 */
|
|
1243
|
-
runtimeUnitImplementationRegistry?: RuntimeUnitImplementationRegistry;
|
|
1244
|
-
/** 当前身份/授权不允许装配时返回稳定的 blockedBy 原因。 */
|
|
1245
|
-
runtimeUnitAvailability?: (input: RuntimeUnitAvailabilityInput) => string | undefined;
|
|
1246
|
-
/** 为每次新建运行单元 Scope 生成当前绑定的只读属性。 */
|
|
1247
|
-
runtimeUnitAttributes?: (input: RuntimeUnitAttributesInput) => Readonly<Record<string, unknown>> | undefined;
|
|
1248
|
-
/** 为每次新建运行单元 Scope 选择生命周期父级;返回 undefined 使用 Host 根 Scope。 */
|
|
1249
|
-
runtimeUnitParentScope?: (input: RuntimeUnitParentScopeInput) => LifecycleScope | undefined;
|
|
1250
|
-
/** 贡献适配器集合。 */
|
|
1251
|
-
contributionAdapters?: readonly ContributionAdapter[];
|
|
1252
|
-
/** 允许每一项清理等待的时间。 */
|
|
1253
|
-
lifecycleCleanupTimeoutMs?: number;
|
|
1254
|
-
/** 读取远端单元真实状态。 */
|
|
1255
|
-
runtimeSnapshots?: () => readonly RuntimeUnitSnapshot[];
|
|
1256
|
-
/** 读取其它真实 Runtime 当前已接受的服务目录。 */
|
|
1257
|
-
remoteServiceReferences?: () => readonly RemoteServiceReference[];
|
|
1258
|
-
/** 允许来源 Runtime 不同且尚未出现在本地 manifest 集合中的依赖。 */
|
|
1259
|
-
externalRuntimeDependencies?: boolean;
|
|
1260
|
-
}
|
|
1261
|
-
declare class StartupCapabilityError extends Error {
|
|
1262
|
-
readonly details: StartupCapabilityErrorDetails[];
|
|
1263
|
-
constructor(details: StartupCapabilityErrorDetails[], phase?: string);
|
|
1264
|
-
}
|
|
1265
|
-
declare class StartupPluginError extends Error {
|
|
1266
|
-
readonly details: StartupPluginErrorDetails;
|
|
1267
|
-
constructor(details: StartupPluginErrorDetails);
|
|
1268
|
-
}
|
|
1269
|
-
/** 创建一个只包含通用生命周期核心的 Plugin Host。 */
|
|
1270
|
-
declare function createPluginHost(options?: CreatePluginHostOptions): PluginHost;
|
|
1271
|
-
interface PluginHost {
|
|
1272
|
-
/** 通用 capability 注册表。 */
|
|
1273
|
-
capabilities: CapabilityRegistry;
|
|
1274
|
-
/** 通用消息总线。 */
|
|
1275
|
-
messageBus: MessageBus;
|
|
1276
|
-
/** 通用资源定义注册表。 */
|
|
1277
|
-
resourceRegistry: ResourceRegistry;
|
|
1278
|
-
/** 通用资源缓存和订阅 Store。 */
|
|
1279
|
-
resourceStore: ResourceStoreApi;
|
|
1280
|
-
/** Host 根生命周期 Scope。 */
|
|
1281
|
-
readonly rootScope: LifecycleScope;
|
|
1282
|
-
/** 根 Scope 的任务调度器。 */
|
|
1283
|
-
readonly taskScheduler: ScopedTaskScheduler;
|
|
1284
|
-
/** 已知产品标识。 */
|
|
1285
|
-
installed(): string[];
|
|
1286
|
-
/** 已知产品标识;installed 的兼容别名。 */
|
|
1287
|
-
manifests(): string[];
|
|
1288
|
-
/** 查询产品运行状态。 */
|
|
1289
|
-
state(pluginId: string): PluginState;
|
|
1290
|
-
/** 查询当前实例 Scope。 */
|
|
1291
|
-
scope(pluginId: string): LifecycleScope | undefined;
|
|
1292
|
-
/** 让宿主重新读取远端运行单元快照。 */
|
|
1293
|
-
refreshRuntimeUnitSnapshots(): void;
|
|
1294
|
-
/** 让领域适配器在 Scope 身份变化后立即完成一次协调。 */
|
|
1295
|
-
reconcile(): Promise<void>;
|
|
1296
|
-
/** 获取依赖图。 */
|
|
1297
|
-
graph(): PluginGraph;
|
|
1298
|
-
/** Host 版本。 */
|
|
1299
|
-
version(): number;
|
|
1300
|
-
/** 订阅 Host 变化。 */
|
|
1301
|
-
subscribe(listener: HostListener): () => void;
|
|
1302
|
-
/** 获取清单。 */
|
|
1303
|
-
getManifest(pluginId: string): PluginManifest | undefined;
|
|
1304
|
-
/** 查询反向依赖。 */
|
|
1305
|
-
reverseDeps(pluginId: string): PluginReverseDep[];
|
|
1306
|
-
/** 校验一组清单。 */
|
|
1307
|
-
validateManifestSet(manifests: readonly PluginManifest[]): void;
|
|
1308
|
-
/** 注入一个不归属插件实例的内建 capability。 */
|
|
1309
|
-
provide<T>(key: string, value: T): void;
|
|
1310
|
-
/** 注册并按当前意图尝试启动。 */
|
|
1311
|
-
register(manifest: PluginManifest): Promise<void>;
|
|
1312
|
-
/** 批量注册并按依赖顺序协调。 */
|
|
1313
|
-
registerAll(manifests: readonly PluginManifest[]): Promise<void>;
|
|
1314
|
-
/** 启动一个插件。 */
|
|
1315
|
-
enable(pluginId: string): Promise<void>;
|
|
1316
|
-
/** 清除失败状态并重试。 */
|
|
1317
|
-
retry(pluginId: string): Promise<void>;
|
|
1318
|
-
/** 提交绝对启停意图。 */
|
|
1319
|
-
submitIntent(pluginId: string, desiredEnabled: boolean): Promise<PluginIntentSubmissionResult>;
|
|
1320
|
-
/** 停止一个插件及其反向依赖者。 */
|
|
1321
|
-
disable(pluginId: string): Promise<{
|
|
1322
|
-
ok: true;
|
|
1323
|
-
} | {
|
|
1324
|
-
ok: false;
|
|
1325
|
-
reason: string;
|
|
1326
|
-
}>;
|
|
1327
|
-
/** 暂停当前实例但保留启用意图;供宿主身份世代切换时撤权重建。 */
|
|
1328
|
-
suspend(pluginId: string, reason?: string): Promise<void>;
|
|
1329
|
-
/** 从 Host 删除一个插件。 */
|
|
1330
|
-
unregister(pluginId: string): Promise<void>;
|
|
1331
|
-
/** 停止所有实例并释放根 Scope。 */
|
|
1332
|
-
dispose(reason?: string): Promise<LifecycleDisposeResult>;
|
|
1333
|
-
/** 启动前检查 capability。 */
|
|
1334
|
-
assertCapabilities(capabilities: readonly string[], options?: {
|
|
1335
|
-
phase?: string;
|
|
1336
|
-
}): void;
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
export { type MessageHandler as $, type ContextExtensionInput as A, type ContributionAdapter as B, type CreatePluginHostOptions as C, type ContributionAdapterInput as D, type ContributionHandle as E, type DispatchOptions as F, type EventHandler as G, type HandlerOptions as H, type HostListener as I, LIFECYCLE_ERROR_TEXT as J, type LifecycleCleanup as K, type LifecycleDisposeResult as L, type MessageBus as M, type LifecycleCleanupIssue as N, type LifecycleCleanupPhase as O, type PluginManifest as P, type LifecycleDisposeOptions as Q, type RuntimeKind as R, type ScopedTaskScheduler as S, type LifecycleResourceHandle as T, type UpgradeGate as U, type LifecycleResourceSnapshot as V, type LifecycleScopeKind as W, LifecycleScopeRevokedError as X, type LifecycleScopeState as Y, type Message as Z, type MessageBusSnapshot as _, type PluginGraph as a, type UpgradeMode as a$, type MessageMode as a0, type OwnedResourceDefinition as a1, PermissionDeniedError as a2, type PermissionLeaseBinding as a3, type PermissionLeaseBindingExpectation as a4, PermissionLeaseRevokedError as a5, type PermissionPolicyInput as a6, type PermissionPolicyResult as a7, type PluginAttributes as a8, type PluginConfigStore as a9, type ResourceDefinition as aA, type ResourceKey as aB, type ResourceRegistry as aC, type ResourceSnapshot as aD, type ResourceStatus as aE, type ResourceStoreApi as aF, type RuntimeUnitAttributesInput as aG, type RuntimeUnitAvailabilityInput as aH, type RuntimeUnitDependency as aI, type RuntimeUnitDependencyInput as aJ, type RuntimeUnitDescriptor as aK, type RuntimeUnitImplementationRegistry as aL, type RuntimeUnitParentScopeInput as aM, type RuntimeUnitSnapshot as aN, SCOPED_TASK_SCHEDULER_CAPABILITY as aO, type ScopedTaskDefinition as aP, type ScopedTaskSnapshot as aQ, StartupCapabilityError as aR, type StartupCapabilityErrorDetails as aS, StartupPluginError as aT, type StartupPluginErrorDetails as aU, type UpgradeDrainResult as aV, UpgradeGateRejectedError as aW, type UpgradeGateState as aX, type UpgradeHandshake as aY, type UpgradeHandshakeResult as aZ, type UpgradeIoLease as a_, type PluginContext as aa, type PluginIntentCommand as ab, type PluginIntentCommandResult as ac, type PluginIntentController as ad, type PluginIntentCoordinator as ae, type PluginIntentSnapshot as af, type PluginIntentSubmissionResult as ag, type PluginLifecycleState as ah, type PluginStartupMode as ai, type PluginState as aj, type PluginTeardown as ak, type PluginUnitGraph as al, type PublishOptions as am, RESOURCE_OWNER as an, RESOURCE_REGISTRY_CAPABILITY as ao, RUNTIME_MESSAGE_BUS as ap, type RemoteServiceBridgeState as aq, type RemoteServiceCallContext as ar, type RemoteServiceLookup as as, type RemoteServiceMessageKind as at, type RemoteServicePortControlMessage as au, type RemoteServiceSnapshotResult as av, type RemoteServiceTransport as aw, RemoteServiceUnavailableError as ax, type RequestOptions as ay, type ResourceContext as az, type PluginDependency as b, type UpgradeSession as b0, createCapabilityRegistry as b1, createInMemoryPluginConfigStore as b2, createPluginHost as b3, createRemoteServiceMessageCodec as b4, createResourceStore as b5, defineRuntimeUnitDependencies as b6, defineRuntimeUnitProvidedContracts as b7, lifecycleErrorText as b8, runtimeCapabilityContractVersion as b9, type PluginReverseDep as c, type PluginContribution as d, type PluginConfig as e, type PluginContextExtension as f, type PluginManifestInput as g, type RuntimeUnitDescriptorInput as h, type PluginSetup as i, type RuntimeDependency as j, type PluginPermission as k, type PluginMeta as l, type PluginStateKind as m, type RemoteServiceReference as n, type RemoteServiceMessageCodec as o, type PluginUnitState as p, type RemoteServiceBridge as q, type RemoteServiceProxy as r, type PluginHost as s, type LifecycleScope as t, type LifecycleScopeIdentity as u, type PermissionLease as v, type CreateUpgradeGateOptions as w, type RemoteServiceHandshake as x, type RemoteServiceSnapshot as y, type CapabilityRegistry as z };
|