webloom-framework 0.1.0 → 0.3.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.
@@ -2,10 +2,8 @@
2
2
  type LifecycleScopeKind = string;
3
3
  /** 作用域状态;stopping 表示已撤权但异步收尾还未结束。 */
4
4
  type LifecycleScopeState = "active" | "stopping" | "stopped";
5
- /** 插件默认存活范围;名称由宿主定义,单次请求可由宿主派生。 */
6
- type PluginLifetime = string;
7
- /** 插件运行代码所在环境;名称由宿主定义。 */
8
- type PluginExecution = string;
5
+ /** 浏览器中由 WebLoom 管理的真实 JavaScript 运行空间。 */
6
+ type RuntimeKind = "window-main" | "shared-worker";
9
7
  /** 权限动作名称;权限集合和最终 I/O allowlist 由宿主定义。 */
10
8
  type PluginPermission = string;
11
9
  /** 一个运行作用域的身份绑定;敏感句柄必须带上这些字段。 */
@@ -172,68 +170,42 @@ interface PermissionLease {
172
170
  interface RemoteServiceReference {
173
171
  /** 服务契约标识。 */
174
172
  capabilityId: string;
175
- /** 提供该服务的运行实例;实例重建后必须变化。 */
176
- providerInstanceId: string;
177
- /** 提供者所在执行环境。 */
178
- execution: PluginExecution;
179
- /** 服务契约版本;第一阶段要求精确匹配。 */
173
+ /** 要求精确匹配的服务契约版本。 */
180
174
  contractVersion: string;
175
+ /** 提供者所在真实 Runtime。 */
176
+ runtime: RuntimeKind;
181
177
  /** 提供环境的启动身份;重启后变化。 */
182
- authorityInstanceId: string;
183
- /** 提供者作用域身份。 */
184
- scopeId: string;
185
- /** 提供者所在 Coordinator 的升级接管世代;旧 Worker 引用不能跨世代使用。 */
186
- handoverGeneration: number;
187
- /** 宿主绑定的只读服务属性;服务桥不解释其业务含义。 */
188
- attributes: Readonly<Record<string, unknown>>;
178
+ runtimeInstanceId: string;
179
+ /** 服务实例身份;撤销后永不复用。 */
180
+ serviceInstanceId: string;
189
181
  /** 当前服务目录状态。 */
190
182
  status: "starting" | "ready" | "unavailable" | "failed";
191
- /** 当前权威目录流修订号。 */
192
- snapshotRevision: number;
183
+ /** 宿主绑定的只读服务属性;服务桥不解释其业务含义。 */
184
+ attributes: Readonly<Record<string, unknown>>;
193
185
  /** 可选的外部授权标识;引用不是授权本身,Provider 仍需查权威状态。 */
194
186
  grantId?: string;
195
187
  /** 服务端授权策略修订;策略变化时旧引用必须失效。 */
196
188
  authorizationRevision?: number;
197
189
  }
198
- /** 服务桥握手输入;connectionId 必须由实际端口连接生成。 */
199
- interface RemoteServiceHandshake {
200
- /** 当前端口 / MessagePort 连接标识。 */
201
- connectionId: string;
202
- /** 对端提供环境的启动身份。 */
203
- authorityInstanceId: string;
204
- /** 桥协议版本。 */
205
- protocolVersion: string;
206
- }
207
- /** 一次服务目录基线或增量快照。 */
190
+ /** 传给服务桥的完整目录快照;Runtime Host 是它的唯一权威发布者。 */
208
191
  interface RemoteServiceSnapshot {
209
- /** 快照来自哪条端口连接。 */
210
- connectionId: string;
211
- /** 快照来自哪个权威启动身份。 */
212
- authorityInstanceId: string;
213
- /** 同一启动身份、同一订阅范围内单调递增。 */
214
- snapshotRevision: number;
215
- /** 是否为包含完整订阅范围的基线。 */
216
- baseline: boolean;
217
- /** 当前订阅范围内的服务引用。 */
192
+ /** 快照协议版本;解析成功但版本不匹配时不得当成可用目录。 */
193
+ protocolVersion: string;
194
+ /** 权威 Runtime 的逻辑标识;独立服务桥可省略。 */
195
+ runtimeId?: string;
196
+ /** 权威 Runtime 类型;独立服务桥可省略。 */
197
+ runtimeKind?: RuntimeKind;
198
+ /** 每次 Worker 启动唯一的 Runtime 身份。 */
199
+ runtimeInstanceId: string;
200
+ /** 当前完整目录修订;同一 Runtime 只接受严格递增值。 */
201
+ revision: number;
202
+ /** Runtime 当前状态。 */
203
+ state?: "starting" | "ready" | "stopping" | "failed" | "disposed";
204
+ /** 当前完整服务目录。 */
218
205
  services: readonly RemoteServiceReference[];
219
206
  }
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";
207
+ /** MessagePort 服务消息类别;codec 只承载调用生命周期。 */
208
+ type RemoteServiceMessageKind = "call" | "result" | "error" | "cancel";
237
209
  /** 服务桥 wire codec;负责类型名、编解码和协议版本,不让传输层散落字符串判断。 */
238
210
  interface RemoteServiceMessageCodec {
239
211
  /** codec 对应的协议版本。 */
@@ -245,7 +217,7 @@ interface RemoteServiceMessageCodec {
245
217
  /** 将 wire 数据解码为对象;无效消息返回 undefined。 */
246
218
  decode(input: unknown): Record<string, unknown> | undefined;
247
219
  }
248
- /** 创建默认 WebLoom codec;产品可用同一工厂绑定旧协议前缀。 */
220
+ /** 创建 WebLoom v2 codec;产品可以只替换 wire 前缀,不能恢复控制消息。 */
249
221
  declare function createRemoteServiceMessageCodec(options?: {
250
222
  prefix?: string;
251
223
  protocolVersion?: string;
@@ -256,84 +228,91 @@ interface RemoteServiceLookup {
256
228
  capabilityId: string;
257
229
  /** 要求的精确契约版本。 */
258
230
  contractVersion: string;
259
- /** 可选的预期提供环境。 */
260
- execution?: PluginExecution;
261
- /** 可选的预期作用域。 */
262
- scopeId?: string;
231
+ /** 可选的预期提供 Runtime。 */
232
+ runtime?: RuntimeKind;
263
233
  }
264
234
  /** 服务代理调用上下文;服务端必须在最终边界重新检查引用和租约。 */
265
235
  interface RemoteServiceCallContext {
266
236
  /** 业务操作标识;可由调用方复用,用于审计和幂等,不作为传输关联键。 */
267
237
  operationId?: string;
268
- /** 实际建立代理的端口连接标识。 */
269
- connectionId: string;
270
238
  /** 创建代理时捕获的不可变引用。 */
271
239
  reference: RemoteServiceReference;
272
240
  /** 引用绑定的外部授权标识,供最终服务边界再次核验。 */
273
241
  grantId?: string;
274
242
  /** 同时受消费者作用域和本次请求控制的 signal。 */
275
243
  signal: AbortSignal;
244
+ /** 从调用开始计算的总 deadline;等待目录和远程执行共用它。 */
245
+ deadlineAt?: number;
246
+ /** 传输直调用时的总 timeout;桥调用会同时提供 deadlineAt。 */
247
+ timeoutMs?: number;
276
248
  }
277
249
  /** 跨环境传输实现;桥不负责自动重放有外部副作用的请求。 */
278
250
  interface RemoteServiceTransport {
279
251
  call<TRequest, TResult>(request: TRequest, context: RemoteServiceCallContext): Promise<TResult>;
280
252
  }
281
- /** 已绑定服务引用的代理;提供者重建后旧代理永久失效。 */
253
+ interface RemoteServiceCallOptions {
254
+ signal?: AbortSignal;
255
+ operationId?: string;
256
+ /** 兼容旧业务命名;只作为 operationId,不作为传输 callId。 */
257
+ requestId?: string;
258
+ /** 覆盖 RuntimeHandle 的默认有限 deadline。 */
259
+ timeoutMs?: number;
260
+ }
261
+ /** 惰性服务代理;第一次成功调用后永久绑定一份服务引用。 */
282
262
  interface RemoteServiceProxy {
283
- readonly reference: RemoteServiceReference;
263
+ /** 未绑定时为 undefined;绑定后引用永远不换绑。 */
264
+ readonly reference?: RemoteServiceReference;
284
265
  readonly revoked: boolean;
285
- call<TRequest, TResult>(request: TRequest, options?: {
286
- signal?: AbortSignal;
287
- operationId?: string; /** 旧 requestId 调用方别名;不作为传输 callId。 */
288
- requestId?: string;
289
- }): Promise<TResult>;
266
+ call<TRequest, TResult>(request: TRequest, options?: RemoteServiceCallOptions): Promise<TResult>;
290
267
  revoke(reason?: string): void;
291
268
  }
292
- type RemoteServiceBridgeState = "disconnected" | "handshaking" | "ready" | "stale";
293
- /** 服务桥快照结果;调用方据此决定等待、重新握手或重新同步基线。 */
269
+ type RemoteServiceBridgeState = "empty" | "ready" | "stale" | "disposed";
270
+ /** 服务桥完整快照结果;旧/重复 revision 直接忽略,不清空当前目录。 */
294
271
  type RemoteServiceSnapshotResult = {
295
272
  accepted: true;
296
273
  state: RemoteServiceBridgeState;
297
- snapshotRevision: number;
274
+ revision: number;
298
275
  } | {
299
276
  accepted: false;
300
- reason: "wrong-connection" | "wrong-authority" | "stale-revision" | "baseline-required" | "revision-gap";
301
- expectedRevision?: number;
302
- receivedRevision: number;
277
+ reason: "stale-revision" | "protocol-mismatch" | "invalid-snapshot" | "disposed";
278
+ receivedRevision?: number;
303
279
  };
280
+ /** WebLoom v2 调用错误的稳定码;业务 handler 可以附加自己的 code。 */
281
+ type RemoteServiceErrorCode = "transport_unavailable" | "call_timeout" | "runtime_initialization_failed" | "protocol_mismatch" | "capability_unavailable" | "contract_version_mismatch" | "service_stale" | "service_revoked" | "permission_denied" | "request_cancelled" | "request_clone_failed" | "handler_failed" | (string & {});
282
+ declare class RemoteServiceError extends Error {
283
+ readonly code: RemoteServiceErrorCode;
284
+ readonly details?: Readonly<Record<string, unknown>>;
285
+ constructor(code: RemoteServiceErrorCode, message: string, details?: Readonly<Record<string, unknown>>);
286
+ }
304
287
  /** 跨 Worker 服务桥最小本地契约。 */
305
288
  interface RemoteServiceBridge {
306
289
  /** 当前端口连接状态。 */
307
290
  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
- /** 应用基线或连续增量快照;乱序和旧连接快照会被丢弃。 */
291
+ /** 当前权威 Runtime 启动身份。 */
292
+ readonly runtimeInstanceId?: string;
293
+ /** 应用一份完整快照;第一次调用可以早于它到达。 */
318
294
  applySnapshot(snapshot: RemoteServiceSnapshot): RemoteServiceSnapshotResult;
319
- /** 查询当前 ready 且版本精确匹配的服务代理。 */
295
+ /** 记录可解析但版本不兼容的对端;后续调用返回 protocol_mismatch。 */
296
+ markProtocolMismatch(reason?: string): void;
297
+ /** 记录权威 Runtime 初始化失败;后续调用返回 runtime_initialization_failed。 */
298
+ markInitializationFailed(reason?: string): void;
299
+ /** 总 deadline 默认值;必须是有限且大于零的毫秒数。 */
300
+ readonly defaultCallTimeoutMs: number;
301
+ /** 获取一个惰性、单次绑定代理;不得因当前目录为空同步失败。 */
320
302
  getProxy(lookup: RemoteServiceLookup, scope?: LifecycleScope): RemoteServiceProxy | undefined;
321
- /** 查询代理失败时抛出稳定错误。 */
303
+ /** 获取惰性代理的显式别名;只在桥 disposed 后仍返回会失败的代理。 */
322
304
  requireProxy(lookup: RemoteServiceLookup, scope?: LifecycleScope): RemoteServiceProxy;
323
305
  /** 同步撤下全部代理;不等待远端。 */
324
306
  invalidate(reason?: string): void;
325
- /** 端口断线;清除当前连接身份,后续快照必须等待新握手和基线。 */
307
+ /** 端口断线;旧代理永久失效,后续恢复必须创建新 RuntimeHandle。 */
326
308
  disconnect(reason?: string): void;
309
+ /** 永久销毁桥,并拒绝所有等待绑定和 pending call。 */
310
+ dispose(reason?: string): void;
327
311
  /** 订阅桥状态和服务目录变化。 */
328
312
  subscribe(listener: () => void): () => void;
329
313
  /** 只读当前有效服务引用。 */
330
314
  services(): readonly RemoteServiceReference[];
331
315
  }
332
- /** 服务桥未就绪或代理已失效。 */
333
- declare class RemoteServiceUnavailableError extends Error {
334
- readonly code: "service.unavailable";
335
- constructor(message?: string);
336
- }
337
316
  /** 首次发布采用的升级并存策略。冷切换要求旧环境先退出;两阶段允许
338
317
  * 短暂并存,但必须先在写入边界完成同一接管世代的排空。 */
339
318
  type UpgradeMode = "cold-switch" | "two-phase";
@@ -769,60 +748,57 @@ interface PluginContext<TConfig extends PluginConfig = PluginConfig, TExtension
769
748
  /** 宿主注入的只读配置;不与启停意图存储混用。 */
770
749
  readonly config?: TConfig;
771
750
  }
772
- /** 产品级依赖描述;简单插件可使用,跨环境单元应使用严格依赖。 */
773
- interface PluginDependency {
751
+ /** v1 运行时依赖;跨 Runtime 绑定必须使用精确契约版本和来源 Runtime。 */
752
+ interface RuntimeDependency {
774
753
  /** 依赖的 capability 标识。 */
775
754
  capability: string;
776
- /** 精确契约版本;跨环境依赖不得省略。 */
755
+ /** 精确契约版本;跨 Runtime 依赖必须显式填写,本地可由 helper 推导。 */
777
756
  contractVersion?: string;
778
- /** 提供者代码所在执行环境;由宿主定义。 */
779
- sourceExecution?: PluginExecution;
780
- /** 提供者允许存在的生命周期;由宿主定义。 */
781
- scope?: PluginLifetime;
757
+ /** 提供者实际运行空间;省略时由当前 Runtime 补齐。 */
758
+ sourceRuntime?: RuntimeKind;
782
759
  /** 可选的人类可读诊断说明。 */
783
760
  reason?: string;
784
761
  /** 缺失时只关闭局部能力,不阻止主体运行。 */
785
762
  optional?: boolean;
786
763
  }
764
+ /** 简单插件的产品级依赖别名。 */
765
+ type PluginDependency = RuntimeDependency;
787
766
  /** 运行单元的严格依赖描述。 */
788
767
  interface RuntimeUnitDependency {
789
768
  /** 依赖的 capability 标识。 */
790
769
  capability: string;
791
770
  /** 精确契约版本;第一阶段只接受完全匹配。 */
792
771
  contractVersion: string;
793
- /** 提供者实际运行环境。 */
794
- sourceExecution: PluginExecution;
795
- /** 提供者允许存在的生命周期。 */
796
- scope: PluginLifetime;
772
+ /** 提供者实际运行空间;跨 Runtime 依赖在 materialize/validate 边界必须补齐。 */
773
+ sourceRuntime: RuntimeKind;
797
774
  /** 可选的人类可读诊断说明。 */
798
775
  reason?: string;
799
776
  /** 缺失时只关闭局部能力;未填写表示硬依赖。 */
800
777
  optional?: boolean;
801
778
  }
779
+ /** 作者入口的未归一化 unit 依赖;进入 Host 前必须补齐版本和来源 Runtime。 */
780
+ type RuntimeUnitDependencyInput = Omit<RuntimeUnitDependency, "contractVersion" | "sourceRuntime"> & {
781
+ contractVersion?: string;
782
+ sourceRuntime?: RuntimeKind;
783
+ };
802
784
  /** 返回稳定的 capability 契约版本。 */
803
785
  declare function runtimeCapabilityContractVersion(capability: string): string;
804
786
  /** 将依赖清单补齐为严格运行单元依赖。 */
805
- declare function defineRuntimeUnitDependencies(dependencies: readonly Pick<PluginDependency, "capability" | "reason" | "optional">[], defaults?: Partial<Pick<RuntimeUnitDependency, "sourceExecution" | "scope">>): RuntimeUnitDependency[];
787
+ declare function defineRuntimeUnitDependencies(dependencies: readonly Pick<PluginDependency, "capability" | "reason" | "optional">[], defaults: {
788
+ sourceRuntime: RuntimeKind;
789
+ }): RuntimeUnitDependency[];
806
790
  /** 为运行单元生成精确的 capability 契约版本表。 */
807
791
  declare function defineRuntimeUnitProvidedContracts(capabilities: readonly string[]): Record<string, string>;
808
792
  /** 插件在产品清单中的启动要求。 */
809
793
  type PluginStartupMode = "required" | "optional";
810
- /** 插件展示元数据;kind、group execution 都由宿主或产品定义。 */
794
+ /** 插件装配元数据;v1 不解释产品分类字段。 */
811
795
  interface PluginMeta {
812
- /** 产品自定义分类,不由 WebLoom 解释。 */
813
- kind?: string;
814
796
  /** 首次装配时默认是否启用。 */
815
797
  defaultEnabled: boolean;
816
798
  /** 是否允许产品控制面禁用。 */
817
799
  canDisable: boolean;
818
800
  /** 是否属于启动必需插件。 */
819
801
  startup?: PluginStartupMode;
820
- /** 产品自定义展示分组。 */
821
- displayGroup?: string;
822
- /** 默认运行生命周期;未填写时使用宿主默认值。 */
823
- lifetime?: PluginLifetime;
824
- /** 默认执行环境;不从 UI 或实现类型推断。 */
825
- execution?: PluginExecution;
826
802
  }
827
803
  /** 插件 setup 返回的清理函数。 */
828
804
  type PluginTeardown = () => void | Promise<void>;
@@ -837,10 +813,8 @@ interface RuntimeUnitImplementationRegistry<TConfig extends PluginConfig = Plugi
837
813
  interface RuntimeUnitDescriptor<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig> {
838
814
  /** 稳定运行单元标识。 */
839
815
  id: string;
840
- /** 运行代码所在环境。 */
841
- execution: PluginExecution;
842
- /** 依附的作用域寿命。 */
843
- lifetime: PluginLifetime;
816
+ /** 运行代码所在真实 Runtime。 */
817
+ runtime: RuntimeKind;
844
818
  /** 本单元所需的精确 capability 契约。 */
845
819
  dependencies?: RuntimeUnitDependency[];
846
820
  /** 本单元提供的 capability。 */
@@ -854,6 +828,11 @@ interface RuntimeUnitDescriptor<TContribution = PluginContribution, TConfig exte
854
828
  /** 单元专属只读配置声明或装配默认值。 */
855
829
  config?: TConfig;
856
830
  }
831
+ /** 作者入口的未归一化运行单元;runtime 可由 createWindowApp/startSharedWorkerApp 注入。 */
832
+ type RuntimeUnitDescriptorInput<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig> = Omit<RuntimeUnitDescriptor<TContribution, TConfig>, "runtime" | "dependencies"> & {
833
+ runtime?: RuntimeKind;
834
+ dependencies?: readonly RuntimeUnitDependencyInput[];
835
+ };
857
836
  /** 插件清单;插件作者导出的唯一静态描述。 */
858
837
  interface PluginManifest<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> {
859
838
  /** 全局稳定产品标识。 */
@@ -877,6 +856,10 @@ interface PluginManifest<TContribution = PluginContribution, TConfig extends Plu
877
856
  /** 简单插件的只读配置。 */
878
857
  config?: TConfig;
879
858
  }
859
+ /** 作者入口的未归一化静态清单;进入 Host 前必须 materialize 成 PluginManifest。 */
860
+ type PluginManifestInput<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> = Omit<PluginManifest<TContribution, TConfig, TExtension>, "units"> & {
861
+ units?: readonly RuntimeUnitDescriptorInput<TContribution, TConfig>[];
862
+ };
880
863
  /** 插件运行状态类别;registered 不代表已经运行。 */
881
864
  type PluginStateKind = "registered" | "starting" | "stopping" | "enabled" | "disabled" | "blocked" | "error-disabled" | "cleanup-pending" | "unknown";
882
865
  /** 对外稳定的产品运行语义。 */
@@ -912,8 +895,8 @@ interface PluginUnitState {
912
895
  pluginId: string;
913
896
  /** 稳定运行单元标识。 */
914
897
  unitId: string;
915
- /** 运行环境。 */
916
- execution: PluginExecution;
898
+ /** 真实运行空间。 */
899
+ runtime: RuntimeKind;
917
900
  /** 当前运行实例。 */
918
901
  instanceId?: string;
919
902
  /** 当前意图修订。 */
@@ -961,8 +944,8 @@ interface PluginUnitGraph {
961
944
  pluginId: string;
962
945
  /** 稳定运行单元标识。 */
963
946
  unitId: string;
964
- /** 运行环境。 */
965
- execution: PluginExecution;
947
+ /** 真实运行空间。 */
948
+ runtime: RuntimeKind;
966
949
  /** capability 依赖。 */
967
950
  dependencies: string[];
968
951
  /** 精确依赖描述。 */
@@ -993,6 +976,8 @@ interface StartupCapabilityErrorDetails {
993
976
  interface StartupPluginErrorDetails {
994
977
  /** 产品标识。 */
995
978
  pluginId: string;
979
+ /** 失败的运行单元。 */
980
+ unitId?: string;
996
981
  /** 能力列表。 */
997
982
  capabilities: string[];
998
983
  /** 当前状态。 */
@@ -1115,37 +1100,6 @@ interface PluginConfigStore {
1115
1100
  }
1116
1101
  /** 创建内存配置端口;产品可通过 configStore 注入持久化实现。 */
1117
1102
  declare function createInMemoryPluginConfigStore(initial?: Readonly<Record<string, boolean>>, readOnly?: boolean): PluginConfigStore;
1118
- /** ScopeResolver 的输入;宿主可以基于当前状态决定 Scope 是否存在。 */
1119
- interface ScopeResolverInput {
1120
- /** 产品标识。 */
1121
- pluginId: string;
1122
- /** 稳定运行单元标识。 */
1123
- unitId: string;
1124
- /** 当前单元声明的生命周期标签。 */
1125
- lifetime: PluginLifetime;
1126
- /** 完整静态清单。 */
1127
- manifest: PluginManifest;
1128
- }
1129
- /** 一个运行单元当前是否可以挂载。 */
1130
- interface ScopeResolution {
1131
- /** 是否允许创建实例 Scope。 */
1132
- available: boolean;
1133
- /** 不可用时的稳定诊断原因。 */
1134
- reason?: string;
1135
- /** 父 Scope;未提供时使用 Host 根 Scope。 */
1136
- parent?: LifecycleScope;
1137
- /** Scope 身份的只读扩展属性。 */
1138
- attributes?: Readonly<Record<string, unknown>>;
1139
- /** 宿主用于检测身份变化的稳定键。 */
1140
- key?: string;
1141
- }
1142
- /** Scope 状态变化订阅端口。 */
1143
- interface ScopeResolver {
1144
- /** 解析当前单元是否具备可用父 Scope。 */
1145
- resolve(input: ScopeResolverInput): ScopeResolution;
1146
- /** 状态变化后通知 Host 重新协调;可选。 */
1147
- subscribe?(listener: () => void): () => void;
1148
- }
1149
1103
  /** 权限策略输入;申请、批准和会话约束必须分开计算。 */
1150
1104
  interface PermissionPolicyInput {
1151
1105
  /** 产品标识。 */
@@ -1208,24 +1162,38 @@ interface ContributionAdapter {
1208
1162
  /** 注册一份泛型贡献。 */
1209
1163
  register(input: ContributionAdapterInput): void | ContributionHandle | (() => void | Promise<void>) | Promise<void | ContributionHandle | (() => void | Promise<void>)>;
1210
1164
  }
1165
+ /** 运行单元可用性检查;返回稳定原因表示当前实例不能装配。 */
1166
+ interface RuntimeUnitAvailabilityInput {
1167
+ /** 产品标识。 */
1168
+ pluginId: string;
1169
+ /** 运行单元标识。 */
1170
+ unitId: string;
1171
+ /** 真实 Runtime。 */
1172
+ runtime: RuntimeKind;
1173
+ }
1174
+ /** 新运行单元 Scope 的身份属性输入。 */
1175
+ interface RuntimeUnitAttributesInput extends RuntimeUnitAvailabilityInput {
1176
+ /** 静态产品清单。 */
1177
+ manifest: PluginManifest;
1178
+ }
1179
+ /** 为运行单元选择父 Scope;未提供时运行单元直接挂在 Host 根 Scope。 */
1180
+ type RuntimeUnitParentScopeInput = RuntimeUnitAttributesInput;
1211
1181
  /** 通用运行单元快照;用于展示远端单元未知/恢复状态。 */
1212
1182
  interface RuntimeUnitSnapshot {
1213
1183
  /** 产品标识。 */
1214
1184
  pluginId: string;
1215
1185
  /** 单元标识。 */
1216
1186
  unitId: string;
1217
- /** 执行环境。 */
1218
- execution: string;
1187
+ /** 真实 Runtime。 */
1188
+ runtime: RuntimeKind;
1219
1189
  /** 远端实例标识。 */
1220
1190
  instanceId?: string;
1221
1191
  /** 远端当前状态。 */
1222
1192
  state: PluginStateKind;
1223
1193
  }
1224
1194
  interface CreatePluginHostOptions {
1225
- /** 当前 Host 所在执行环境;用于选择运行单元。 */
1226
- execution?: string;
1227
- /** 默认插件生命周期。 */
1228
- defaultLifetime?: string;
1195
+ /** 当前 Host 所在真实 Runtime。 */
1196
+ runtime?: RuntimeKind;
1229
1197
  /** 根 Scope 的宿主只读属性。 */
1230
1198
  rootAttributes?: Readonly<Record<string, unknown>>;
1231
1199
  /** 预注入的内建 capability;不归属于任何插件实例。 */
@@ -1240,8 +1208,6 @@ interface CreatePluginHostOptions {
1240
1208
  contextExtension?: (input: ContextExtensionInput) => Readonly<Record<string, unknown>>;
1241
1209
  /** 校验产品清单中的宿主扩展字段。 */
1242
1210
  manifestValidator?: (manifest: PluginManifest) => void;
1243
- /** 解析当前生命周期是否存在以及其父 Scope。 */
1244
- scopeResolver?: ScopeResolver;
1245
1211
  /** 计算权限批准与会话交集。 */
1246
1212
  permissionPolicy?: (input: PermissionPolicyInput) => PermissionPolicyResult;
1247
1213
  /** 启停意图持久化端口。 */
@@ -1254,12 +1220,22 @@ interface CreatePluginHostOptions {
1254
1220
  serviceBridgeForPlugin?: (pluginId: string, instanceId: string) => RemoteServiceBridge | undefined;
1255
1221
  /** 当前执行环境的运行单元实现注册表。 */
1256
1222
  runtimeUnitImplementationRegistry?: RuntimeUnitImplementationRegistry;
1223
+ /** 当前身份/授权不允许装配时返回稳定的 blockedBy 原因。 */
1224
+ runtimeUnitAvailability?: (input: RuntimeUnitAvailabilityInput) => string | undefined;
1225
+ /** 为每次新建运行单元 Scope 生成当前绑定的只读属性。 */
1226
+ runtimeUnitAttributes?: (input: RuntimeUnitAttributesInput) => Readonly<Record<string, unknown>> | undefined;
1227
+ /** 为每次新建运行单元 Scope 选择生命周期父级;返回 undefined 使用 Host 根 Scope。 */
1228
+ runtimeUnitParentScope?: (input: RuntimeUnitParentScopeInput) => LifecycleScope | undefined;
1257
1229
  /** 贡献适配器集合。 */
1258
1230
  contributionAdapters?: readonly ContributionAdapter[];
1259
1231
  /** 允许每一项清理等待的时间。 */
1260
1232
  lifecycleCleanupTimeoutMs?: number;
1261
1233
  /** 读取远端单元真实状态。 */
1262
1234
  runtimeSnapshots?: () => readonly RuntimeUnitSnapshot[];
1235
+ /** 读取其它真实 Runtime 当前已接受的服务目录。 */
1236
+ remoteServiceReferences?: () => readonly RemoteServiceReference[];
1237
+ /** 允许来源 Runtime 不同且尚未出现在本地 manifest 集合中的依赖。 */
1238
+ externalRuntimeDependencies?: boolean;
1263
1239
  }
1264
1240
  declare class StartupCapabilityError extends Error {
1265
1241
  readonly details: StartupCapabilityErrorDetails[];
@@ -1327,6 +1303,8 @@ interface PluginHost {
1327
1303
  ok: false;
1328
1304
  reason: string;
1329
1305
  }>;
1306
+ /** 暂停当前实例但保留启用意图;供宿主身份世代切换时撤权重建。 */
1307
+ suspend(pluginId: string, reason?: string): Promise<void>;
1330
1308
  /** 从 Host 删除一个插件。 */
1331
1309
  unregister(pluginId: string): Promise<void>;
1332
1310
  /** 停止所有实例并释放根 Scope。 */
@@ -1337,4 +1315,4 @@ interface PluginHost {
1337
1315
  }): void;
1338
1316
  }
1339
1317
 
1340
- export { type PluginContribution as $, type LifecycleScopeState as A, type Message as B, type CreateUpgradeGateOptions as C, type DispatchOptions as D, type EventHandler as E, type MessageBusSnapshot as F, type MessageHandler as G, type HandlerOptions as H, type MessageMode as I, PermissionDeniedError as J, type PermissionLeaseBinding as K, type LifecycleScope as L, type MessageBus as M, type PermissionLeaseBindingExpectation as N, type OwnedResourceDefinition as O, type PluginExecution as P, PermissionLeaseRevokedError as Q, type RemoteServiceHandshake as R, type ScopedTaskScheduler as S, type PermissionPolicyInput as T, type UpgradeGate as U, type PermissionPolicyResult as V, type PluginAttributes as W, type PluginConfig as X, type PluginConfigStore as Y, type PluginContext as Z, type PluginContextExtension as _, type PluginManifest as a, createInMemoryPluginConfigStore as a$, type PluginHost as a0, type PluginIntentCommand as a1, type PluginIntentCommandResult as a2, type PluginIntentController as a3, type PluginIntentCoordinator as a4, type PluginIntentSnapshot as a5, type PluginIntentSubmissionResult as a6, type PluginLifecycleState as a7, type PluginLifetime as a8, type PluginMeta as a9, type ResourceRegistry as aA, type ResourceSnapshot as aB, type ResourceStatus as aC, type ResourceStoreApi as aD, type RuntimeUnitDependency as aE, type RuntimeUnitDescriptor as aF, type RuntimeUnitImplementationRegistry as aG, type RuntimeUnitSnapshot as aH, SCOPED_TASK_SCHEDULER_CAPABILITY as aI, type ScopeResolution as aJ, type ScopeResolver as aK, type ScopeResolverInput as aL, type ScopedTaskDefinition as aM, type ScopedTaskSnapshot as aN, StartupCapabilityError as aO, type StartupCapabilityErrorDetails as aP, StartupPluginError as aQ, type StartupPluginErrorDetails as aR, type UpgradeDrainResult as aS, UpgradeGateRejectedError as aT, type UpgradeGateState as aU, type UpgradeHandshake as aV, type UpgradeHandshakeResult as aW, type UpgradeIoLease as aX, type UpgradeMode as aY, type UpgradeSession as aZ, createCapabilityRegistry as a_, type PluginSetup as aa, type PluginStartupMode as ab, type PluginState as ac, type PluginStateKind as ad, type PluginTeardown as ae, type PluginUnitGraph as af, type PluginUnitState as ag, type PublishOptions as ah, RESOURCE_OWNER as ai, RESOURCE_REGISTRY_CAPABILITY as aj, RUNTIME_MESSAGE_BUS as ak, type RemoteServiceBridge as al, type RemoteServiceBridgeState as am, type RemoteServiceCallContext as an, type RemoteServiceLookup as ao, type RemoteServiceMessageKind as ap, type RemoteServicePortControlMessage as aq, type RemoteServiceProxy as ar, type RemoteServiceReference as as, type RemoteServiceSnapshotResult as at, type RemoteServiceTransport as au, RemoteServiceUnavailableError as av, type RequestOptions as aw, type ResourceContext as ax, type ResourceDefinition as ay, type ResourceKey as az, type PluginGraph as b, createPluginHost as b0, createRemoteServiceMessageCodec as b1, createResourceStore as b2, defineRuntimeUnitDependencies as b3, defineRuntimeUnitProvidedContracts as b4, lifecycleErrorText as b5, runtimeCapabilityContractVersion as b6, type PluginDependency as c, type PluginReverseDep as d, type LifecycleScopeIdentity as e, type PluginPermission as f, type PermissionLease as g, type RemoteServiceSnapshot as h, type RemoteServiceMessageCodec as i, type CapabilityRegistry as j, type ContextExtensionInput as k, type ContributionAdapter as l, type ContributionAdapterInput as m, type ContributionHandle as n, type CreatePluginHostOptions as o, type HostListener as p, LIFECYCLE_ERROR_TEXT as q, type LifecycleCleanup as r, type LifecycleCleanupIssue as s, type LifecycleCleanupPhase as t, type LifecycleDisposeOptions as u, type LifecycleDisposeResult as v, type LifecycleResourceHandle as w, type LifecycleResourceSnapshot as x, type LifecycleScopeKind as y, LifecycleScopeRevokedError as z };
1318
+ export { PermissionLeaseRevokedError as $, type LifecycleCleanup as A, type LifecycleCleanupIssue as B, type CreatePluginHostOptions as C, type DispatchOptions as D, type EventHandler as E, type LifecycleCleanupPhase as F, type LifecycleDisposeOptions as G, type HandlerOptions as H, type LifecycleResourceHandle as I, type LifecycleResourceSnapshot as J, type LifecycleScopeKind as K, type LifecycleDisposeResult as L, type MessageBus as M, LifecycleScopeRevokedError as N, type LifecycleScopeState as O, type PluginManifest as P, type Message as Q, type RuntimeKind as R, type ScopedTaskScheduler as S, type MessageBusSnapshot as T, type UpgradeGate as U, type MessageHandler as V, type MessageMode as W, type OwnedResourceDefinition as X, PermissionDeniedError as Y, type PermissionLeaseBinding as Z, type PermissionLeaseBindingExpectation as _, type PluginGraph as a, type UpgradeMode as a$, type PermissionPolicyInput as a0, type PermissionPolicyResult as a1, type PluginAttributes as a2, type PluginConfigStore as a3, type PluginContext as a4, type PluginIntentCommand as a5, type PluginIntentCommandResult as a6, type PluginIntentController as a7, type PluginIntentCoordinator as a8, type PluginIntentSnapshot 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 PluginIntentSubmissionResult as aa, type PluginLifecycleState as ab, type PluginStartupMode as ac, type PluginState as ad, type PluginStateKind as ae, type PluginTeardown as af, type PluginUnitGraph as ag, type PluginUnitState as ah, type PublishOptions as ai, RESOURCE_OWNER as aj, RESOURCE_REGISTRY_CAPABILITY as ak, RUNTIME_MESSAGE_BUS as al, type RemoteServiceBridge as am, type RemoteServiceBridgeState as an, type RemoteServiceCallContext as ao, type RemoteServiceCallOptions as ap, RemoteServiceError as aq, type RemoteServiceErrorCode as ar, type RemoteServiceLookup as as, type RemoteServiceMessageKind as at, type RemoteServiceProxy as au, type RemoteServiceSnapshot as av, type RemoteServiceSnapshotResult as aw, type RemoteServiceTransport 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 PluginHost as m, type LifecycleScope as n, type LifecycleScopeIdentity as o, type PermissionLease as p, type CreateUpgradeGateOptions as q, type RemoteServiceReference as r, type RemoteServiceMessageCodec as s, type CapabilityRegistry as t, type ContextExtensionInput as u, type ContributionAdapter as v, type ContributionAdapterInput as w, type ContributionHandle as x, type HostListener as y, LIFECYCLE_ERROR_TEXT as z };