webloom-framework 0.1.0 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { P as PluginExecution, a as PluginManifest, b as PluginGraph, c as PluginDependency, d as PluginReverseDep, M as MessageBus, L as LifecycleScope, e as LifecycleScopeIdentity, f as PluginPermission, g as PermissionLease, S as ScopedTaskScheduler, C as CreateUpgradeGateOptions, U as UpgradeGate, R as RemoteServiceHandshake, h as RemoteServiceSnapshot, i as RemoteServiceMessageCodec } from './createPluginHost-CcW9sPNs.js';
2
- export { j as CapabilityRegistry, k as ContextExtensionInput, l as ContributionAdapter, m as ContributionAdapterInput, n as ContributionHandle, o as CreatePluginHostOptions, D as DispatchOptions, E as EventHandler, H as HandlerOptions, p as HostListener, q as LIFECYCLE_ERROR_TEXT, r as LifecycleCleanup, s as LifecycleCleanupIssue, t as LifecycleCleanupPhase, u as LifecycleDisposeOptions, v as LifecycleDisposeResult, w as LifecycleResourceHandle, x as LifecycleResourceSnapshot, y as LifecycleScopeKind, z as LifecycleScopeRevokedError, A as LifecycleScopeState, B as Message, F as MessageBusSnapshot, G as MessageHandler, I as MessageMode, O as OwnedResourceDefinition, J as PermissionDeniedError, K as PermissionLeaseBinding, N as PermissionLeaseBindingExpectation, Q as PermissionLeaseRevokedError, T as PermissionPolicyInput, V as PermissionPolicyResult, W as PluginAttributes, X as PluginConfig, Y as PluginConfigStore, Z as PluginContext, _ as PluginContextExtension, $ as PluginContribution, a0 as PluginHost, a1 as PluginIntentCommand, a2 as PluginIntentCommandResult, a3 as PluginIntentController, a4 as PluginIntentCoordinator, a5 as PluginIntentSnapshot, a6 as PluginIntentSubmissionResult, a7 as PluginLifecycleState, a8 as PluginLifetime, a9 as PluginMeta, aa as PluginSetup, ab as PluginStartupMode, ac as PluginState, ad as PluginStateKind, ae as PluginTeardown, af as PluginUnitGraph, ag as PluginUnitState, ah as PublishOptions, ai as RESOURCE_OWNER, aj as RESOURCE_REGISTRY_CAPABILITY, ak as RUNTIME_MESSAGE_BUS, al as RemoteServiceBridge, am as RemoteServiceBridgeState, an as RemoteServiceCallContext, ao as RemoteServiceLookup, ap as RemoteServiceMessageKind, aq as RemoteServicePortControlMessage, ar as RemoteServiceProxy, as as RemoteServiceReference, at as RemoteServiceSnapshotResult, au as RemoteServiceTransport, av as RemoteServiceUnavailableError, aw as RequestOptions, ax as ResourceContext, ay as ResourceDefinition, az as ResourceKey, aA as ResourceRegistry, aB as ResourceSnapshot, aC as ResourceStatus, aD as ResourceStoreApi, aE as RuntimeUnitDependency, aF as RuntimeUnitDescriptor, aG as RuntimeUnitImplementationRegistry, aH as RuntimeUnitSnapshot, aI as SCOPED_TASK_SCHEDULER_CAPABILITY, aJ as ScopeResolution, aK as ScopeResolver, aL as ScopeResolverInput, aM as ScopedTaskDefinition, aN as ScopedTaskSnapshot, aO as StartupCapabilityError, aP as StartupCapabilityErrorDetails, aQ as StartupPluginError, aR as StartupPluginErrorDetails, aS as UpgradeDrainResult, aT as UpgradeGateRejectedError, aU as UpgradeGateState, aV as UpgradeHandshake, aW as UpgradeHandshakeResult, aX as UpgradeIoLease, aY as UpgradeMode, aZ as UpgradeSession, a_ as createCapabilityRegistry, a$ as createInMemoryPluginConfigStore, b0 as createPluginHost, b1 as createRemoteServiceMessageCodec, b2 as createResourceStore, b3 as defineRuntimeUnitDependencies, b4 as defineRuntimeUnitProvidedContracts, b5 as lifecycleErrorText, b6 as runtimeCapabilityContractVersion } from './createPluginHost-CcW9sPNs.js';
3
- import { R as RemoteServicePortCallMessage } from './resourceRegistry-BAnqKcp7.js';
4
- export { C as CreateMessagePortServiceTransportOptions, a as CreatePluginIntentControllerOptions, b as CreateResourceScopeOptions, c as CreateServiceBridgeOptions, d as RemoteServicePortCancelMessage, e as RemoteServicePortErrorMessage, f as RemoteServicePortResponseMessage, g as RemoteServicePortResultMessage, h as ResourceScopeOptions, i as RuntimeUnitImplementation, j as createLifecycleScope, k as createMessageBus, l as createMessagePortServiceTransport, m as createPluginIntentController, n as createRemoteServiceBridge, o as createResourceRegistry, p as createResourceScope, q as createRuntimeUnitImplementationRegistry, r as createServiceBridge, s as registerOwnedResource } from './resourceRegistry-BAnqKcp7.js';
1
+ import { R as RuntimeKind, P as PluginManifest, a as PluginGraph, b as PluginDependency, c as PluginReverseDep, d as PluginContribution, e as PluginConfig, f as PluginContextExtension, g as PluginManifestInput, h as RuntimeUnitDescriptorInput, i as PluginSetup, j as RuntimeDependency, k as PluginPermission, l as PluginMeta, m as PluginStateKind, n as RemoteServiceReference, o as RemoteServiceMessageCodec, p as PluginUnitState, q as RemoteServiceBridge, r as RemoteServiceProxy, s as PluginHost, L as LifecycleDisposeResult, C as CreatePluginHostOptions, M as MessageBus, t as LifecycleScope, u as LifecycleScopeIdentity, v as PermissionLease, S as ScopedTaskScheduler, w as CreateUpgradeGateOptions, U as UpgradeGate, x as RemoteServiceHandshake, y as RemoteServiceSnapshot } from './createPluginHost-ChJNBTsX.js';
2
+ export { z as CapabilityRegistry, A as ContextExtensionInput, B as ContributionAdapter, D as ContributionAdapterInput, E as ContributionHandle, F as DispatchOptions, G as EventHandler, H as HandlerOptions, I as HostListener, J as LIFECYCLE_ERROR_TEXT, K as LifecycleCleanup, N as LifecycleCleanupIssue, O as LifecycleCleanupPhase, Q as LifecycleDisposeOptions, T as LifecycleResourceHandle, V as LifecycleResourceSnapshot, W as LifecycleScopeKind, X as LifecycleScopeRevokedError, Y as LifecycleScopeState, Z as Message, _ as MessageBusSnapshot, $ as MessageHandler, a0 as MessageMode, a1 as OwnedResourceDefinition, a2 as PermissionDeniedError, a3 as PermissionLeaseBinding, a4 as PermissionLeaseBindingExpectation, a5 as PermissionLeaseRevokedError, a6 as PermissionPolicyInput, a7 as PermissionPolicyResult, a8 as PluginAttributes, a9 as PluginConfigStore, aa as PluginContext, ab as PluginIntentCommand, ac as PluginIntentCommandResult, ad as PluginIntentController, ae as PluginIntentCoordinator, af as PluginIntentSnapshot, ag as PluginIntentSubmissionResult, ah as PluginLifecycleState, ai as PluginStartupMode, aj as PluginState, ak as PluginTeardown, al as PluginUnitGraph, am as PublishOptions, an as RESOURCE_OWNER, ao as RESOURCE_REGISTRY_CAPABILITY, ap as RUNTIME_MESSAGE_BUS, aq as RemoteServiceBridgeState, ar as RemoteServiceCallContext, as as RemoteServiceLookup, at as RemoteServiceMessageKind, au as RemoteServicePortControlMessage, av as RemoteServiceSnapshotResult, aw as RemoteServiceTransport, ax as RemoteServiceUnavailableError, ay as RequestOptions, az as ResourceContext, aA as ResourceDefinition, aB as ResourceKey, aC as ResourceRegistry, aD as ResourceSnapshot, aE as ResourceStatus, aF as ResourceStoreApi, aG as RuntimeUnitAttributesInput, aH as RuntimeUnitAvailabilityInput, aI as RuntimeUnitDependency, aJ as RuntimeUnitDependencyInput, aK as RuntimeUnitDescriptor, aL as RuntimeUnitImplementationRegistry, aM as RuntimeUnitParentScopeInput, aN as RuntimeUnitSnapshot, aO as SCOPED_TASK_SCHEDULER_CAPABILITY, aP as ScopedTaskDefinition, aQ as ScopedTaskSnapshot, aR as StartupCapabilityError, aS as StartupCapabilityErrorDetails, aT as StartupPluginError, aU as StartupPluginErrorDetails, aV as UpgradeDrainResult, aW as UpgradeGateRejectedError, aX as UpgradeGateState, aY as UpgradeHandshake, aZ as UpgradeHandshakeResult, a_ as UpgradeIoLease, a$ as UpgradeMode, b0 as UpgradeSession, b1 as createCapabilityRegistry, b2 as createInMemoryPluginConfigStore, b3 as createPluginHost, b4 as createRemoteServiceMessageCodec, b5 as createResourceStore, b6 as defineRuntimeUnitDependencies, b7 as defineRuntimeUnitProvidedContracts, b8 as lifecycleErrorText, b9 as runtimeCapabilityContractVersion } from './createPluginHost-ChJNBTsX.js';
3
+ import { R as RemoteServicePortCallMessage } from './resourceRegistry-MNM1c7od.js';
4
+ export { C as CreateMessagePortServiceTransportOptions, a as CreatePluginIntentControllerOptions, b as CreateResourceScopeOptions, c as CreateServiceBridgeOptions, d as RemoteServicePortCancelMessage, e as RemoteServicePortErrorMessage, f as RemoteServicePortResponseMessage, g as RemoteServicePortResultMessage, h as ResourceScopeOptions, i as RuntimeUnitImplementation, j as createLifecycleScope, k as createMessageBus, l as createMessagePortServiceTransport, m as createPluginIntentController, n as createRemoteServiceBridge, o as createResourceRegistry, p as createResourceScope, q as createRuntimeUnitImplementationRegistry, r as createServiceBridge, s as registerOwnedResource } from './resourceRegistry-MNM1c7od.js';
5
5
 
6
6
  interface BuildPluginGraphOptions {
7
7
  /** 当前真正运行的插件;不传时使用 manifest.meta.defaultEnabled。 */
8
8
  enabledPluginIds?: ReadonlySet<string>;
9
- /** 当前 Host 实际执行环境;未选中的 Worker/Window 单元不会进入图。 */
10
- execution?: PluginExecution;
9
+ /** 当前 Host 的真实 Runtime;未选中的 Window/Worker 单元不会进入图。 */
10
+ runtime?: RuntimeKind;
11
11
  }
12
12
  interface ValidatePluginGraphOptions extends BuildPluginGraphOptions {
13
13
  /** 平台内建 capability,不需要由某个 manifest 提供。 */
@@ -16,10 +16,15 @@ interface ValidatePluginGraphOptions extends BuildPluginGraphOptions {
16
16
  multiProviderCapabilities?: ReadonlySet<string>;
17
17
  /** Host 分批注册时允许 provider 尚未注册;真正装配前仍会进入 blocked。 */
18
18
  allowMissingDependencies?: boolean;
19
+ /**
20
+ * 允许依赖当前图之外的另一个真实 Runtime;实际是否 ready 由运行时
21
+ * snapshot 和 RemoteServiceBridge 在 Host reconcile 时决定。
22
+ */
23
+ externalRuntimeDependencies?: boolean;
19
24
  }
20
25
  interface PluginGraphDiagnostic {
21
26
  /** 稳定诊断码。 */
22
- code: "plugin.duplicate_id" | "capability.duplicate_provider" | "plugin.missing_dependency" | "plugin.dependency_cycle" | "plugin.dependency_contract_invalid" | "plugin.dependency_contract_unavailable" | "plugin.runtime_declaration_at_product_level";
27
+ code: "plugin.duplicate_id" | "capability.duplicate_provider" | "plugin.missing_dependency" | "plugin.dependency_cycle" | "plugin.dependency_contract_invalid" | "plugin.dependency_contract_unavailable" | "plugin.runtime_invalid" | "plugin.runtime_declaration_at_product_level";
23
28
  /** 相关插件或 capability。 */
24
29
  ids: string[];
25
30
  /** 中文诊断原因,供设置页直接显示或再做 i18n 映射。 */
@@ -43,9 +48,9 @@ declare function validateRuntimeUnitDependencyContracts(manifests: readonly Plug
43
48
  * 返回当前执行环境的依赖;显式运行单元不会继承产品级依赖。
44
49
  * 只有没有 units 的简单插件才读取历史 product-level dependencies。
45
50
  */
46
- declare function dependenciesOfManifest(manifest: PluginManifest, execution?: PluginExecution): PluginDependency[];
51
+ declare function dependenciesOfManifest(manifest: PluginManifest, runtime?: RuntimeKind): PluginDependency[];
47
52
  /** 返回当前执行环境提供的 capability;显式单元不会继承产品级摘要。 */
48
- declare function providesOfManifest(manifest: PluginManifest, execution?: PluginExecution): string[];
53
+ declare function providesOfManifest(manifest: PluginManifest, runtime?: RuntimeKind): string[];
49
54
  /** 从 manifest 列表构造依赖、提供者和反向依赖。 */
50
55
  declare function buildPluginGraph(manifests: PluginManifest[], options?: BuildPluginGraphOptions): PluginGraph;
51
56
  /** 在任何 setup 前校验重复提供、缺失硬依赖和硬依赖环。 */
@@ -53,6 +58,291 @@ declare function validatePluginGraph(manifests: readonly PluginManifest[], optio
53
58
  /** 查询当前启用的逆依赖者;禁用提供者时应按此集合先停止消费者。 */
54
59
  declare function reverseDependentsOf(graph: PluginGraph, pluginId: string, enabledSet: ReadonlySet<string>): PluginReverseDep[];
55
60
 
61
+ interface DefinePluginOptions<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> {
62
+ /** 全局稳定插件标识。 */
63
+ id: string;
64
+ /** 默认展示名称。 */
65
+ name?: string;
66
+ /** 可选诊断描述。 */
67
+ description?: string;
68
+ /** 普通插件的可执行实现;不会进入静态 descriptor。 */
69
+ setup: PluginSetup<TConfig, TExtension>;
70
+ /** 默认目标 Runtime;普通 Window 插件通常省略,由 App 注入。 */
71
+ runtime?: RuntimeKind;
72
+ /** 默认 unit id;省略时使用插件 id。 */
73
+ unitId?: string;
74
+ /** 插件依赖;helper 会为本地依赖补齐 v1 契约版本。 */
75
+ dependencies?: readonly (RuntimeDependency | PluginDependency)[];
76
+ /** 本单元提供的 capability。 */
77
+ provides?: readonly string[];
78
+ /** 跨 Runtime 时可显式覆盖 capability 契约版本。 */
79
+ providedContracts?: Readonly<Record<string, string>>;
80
+ /** 请求的权限集合。 */
81
+ permissions?: readonly PluginPermission[];
82
+ /** 单元只读配置。 */
83
+ config?: TConfig;
84
+ /** 产品贡献;不会被框架解释。 */
85
+ contribution?: TContribution;
86
+ /** 是否默认启用;默认为 true。 */
87
+ defaultEnabled?: boolean;
88
+ /** 是否允许控制面停用;默认为 true。 */
89
+ canDisable?: boolean;
90
+ /** required 插件在 App 初始启动时必须成功。 */
91
+ required?: boolean;
92
+ /** 显式启动模式;required=true 时不能覆盖为 optional。 */
93
+ startup?: "required" | "optional";
94
+ /** 仅用于兼容低层消费方的静态 meta 扩展;WebLoom 不解释分类字段。 */
95
+ meta?: Partial<PluginMeta>;
96
+ }
97
+ /** 静态 descriptor 与当前 realm 的实现函数分离。 */
98
+ interface PluginDefinition<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension> {
99
+ readonly manifest: PluginManifestInput<TContribution, TConfig, TExtension>;
100
+ readonly descriptor: RuntimeUnitDescriptorInput<TContribution, TConfig>;
101
+ readonly setup: PluginSetup<TConfig, TExtension>;
102
+ }
103
+ /**
104
+ * 声明一个插件。
105
+ *
106
+ * 该函数不创建 Host,也不启动 setup;真正的启动边界由
107
+ * createWindowApp()/startSharedWorkerApp() 拥有。
108
+ */
109
+ declare function definePlugin<TContribution = PluginContribution, TConfig extends PluginConfig = PluginConfig, TExtension extends PluginContextExtension = PluginContextExtension>(options: DefinePluginOptions<TContribution, TConfig, TExtension>): PluginDefinition<TContribution, TConfig, TExtension>;
110
+
111
+ type RuntimePluginDefinition = PluginDefinition<any, any, any> | {
112
+ readonly manifest: PluginManifest | PluginManifestInput;
113
+ readonly setup: PluginSetup<any, any>;
114
+ /** 多 unit manifest 中 setup 所实现的目标 unit;单一匹配 unit 可省略。 */
115
+ readonly unitId?: string;
116
+ };
117
+ interface MaterializedPluginDefinition {
118
+ readonly manifest: PluginManifest;
119
+ /** 当前 Runtime 中由 setup 实现的 unit。 */
120
+ readonly unitId: string;
121
+ readonly setup: PluginSetup;
122
+ }
123
+ /** 将作者定义绑定到真实 Runtime;不把 setup 复制进 manifest。 */
124
+ declare function materializePluginDefinition(input: RuntimePluginDefinition, runtime: RuntimeKind): MaterializedPluginDefinition;
125
+ declare function materializePluginDefinitions(inputs: readonly RuntimePluginDefinition[], runtime: RuntimeKind): MaterializedPluginDefinition[];
126
+
127
+ declare const RUNTIME_PROTOCOL_VERSION = "webloom.runtime.v1";
128
+ declare const RUNTIME_HELLO_TYPE = "webloom.runtime.hello";
129
+ declare const RUNTIME_SNAPSHOT_TYPE = "webloom.runtime.snapshot";
130
+ declare const RUNTIME_RESYNC_TYPE = "webloom.runtime.resync";
131
+ declare const RUNTIME_ERROR_TYPE = "webloom.runtime.error";
132
+ interface RuntimeHelloMessage {
133
+ type: typeof RUNTIME_HELLO_TYPE;
134
+ protocolVersion: string;
135
+ connectionId: string;
136
+ runtimeId: string;
137
+ }
138
+ interface RuntimeResyncMessage {
139
+ type: typeof RUNTIME_RESYNC_TYPE;
140
+ connectionId: string;
141
+ }
142
+ interface RuntimeErrorMessage {
143
+ type: typeof RUNTIME_ERROR_TYPE;
144
+ protocolVersion: string;
145
+ code: "runtime.protocol_mismatch" | "runtime.initialization_failed" | "runtime.invalid_connection";
146
+ message: string;
147
+ pluginId?: string;
148
+ unitId?: string;
149
+ phase?: string;
150
+ }
151
+ interface RuntimeSnapshot {
152
+ type: typeof RUNTIME_SNAPSHOT_TYPE;
153
+ protocolVersion: string;
154
+ runtimeId: string;
155
+ runtimeKind: RuntimeKind;
156
+ runtimeInstanceId: string;
157
+ connectionId: string;
158
+ snapshotRevision: number;
159
+ baseline: boolean;
160
+ state: "starting" | "ready" | "stopping" | "failed" | "disposed";
161
+ units: readonly RuntimeSnapshotUnit[];
162
+ services: readonly RemoteServiceReference[];
163
+ }
164
+ interface RuntimeSnapshotUnit {
165
+ pluginId: string;
166
+ unitId: string;
167
+ runtime: RuntimeKind;
168
+ instanceId?: string;
169
+ state: PluginStateKind;
170
+ }
171
+ declare function createRuntimeMessageCodec(): RemoteServiceMessageCodec;
172
+ declare function isRuntimeHello(input: unknown): input is RuntimeHelloMessage;
173
+ declare function isRuntimeResync(input: unknown): input is RuntimeResyncMessage;
174
+ declare function isRuntimeSnapshot(input: unknown): input is RuntimeSnapshot;
175
+ declare function isRuntimeError(input: unknown): input is RuntimeErrorMessage;
176
+ /** 将 Host 的 PluginUnitState 映射成不会泄露领域配置的运行时快照。 */
177
+ declare function unitSnapshotFromState(state: PluginUnitState, runtime: RuntimeKind): RuntimeSnapshotUnit;
178
+
179
+ type RuntimeAppState = "starting" | "ready" | "stopping" | "failed" | "disposed" | "connecting" | "disconnected";
180
+ interface RuntimeStatusSnapshot {
181
+ runtimeId: string;
182
+ runtimeKind: RuntimeKind;
183
+ runtimeInstanceId: string;
184
+ state: RuntimeAppState;
185
+ snapshotRevision: number;
186
+ connectionId?: string;
187
+ units: readonly RuntimeSnapshotUnit[];
188
+ services: readonly RemoteServiceReference[];
189
+ error?: string;
190
+ }
191
+ type RuntimeStatusListener = (snapshot: RuntimeStatusSnapshot) => void;
192
+ interface WindowApp {
193
+ readonly runtimeKind: "window-main";
194
+ readonly runtimeId: string;
195
+ readonly runtimeInstanceId: string;
196
+ /** 已由 createWindowApp 装配并注册完成的本地 Host。 */
197
+ readonly host: PluginHost;
198
+ state(): RuntimeStatusSnapshot;
199
+ /** 获取当前本地 capability;停止或销毁后同步抛错。 */
200
+ capability<T>(capabilityId: string): T;
201
+ subscribe(listener: RuntimeStatusListener): () => void;
202
+ dispose(reason?: string): Promise<LifecycleDisposeResult>;
203
+ }
204
+ interface RuntimeHandle {
205
+ readonly runtimeKind: "shared-worker";
206
+ readonly runtimeId: string;
207
+ /** 当前连接绑定的 Worker 启动身份;未握手时为 undefined。 */
208
+ readonly runtimeInstanceId?: string;
209
+ /** 当前物理连接身份;未握手时为 undefined。 */
210
+ readonly connectionId?: string;
211
+ /** 当前连接已校验的服务桥;不暴露原始 MessagePort。 */
212
+ readonly serviceBridge: RemoteServiceBridge;
213
+ state(): RuntimeStatusSnapshot;
214
+ ready(): Promise<void>;
215
+ capability<T = unknown>(capabilityId: string, options?: {
216
+ contractVersion?: string;
217
+ }): RemoteServiceProxy & {
218
+ readonly serviceType?: T;
219
+ };
220
+ subscribe(listener: RuntimeStatusListener): () => void;
221
+ dispose(reason?: string): Promise<void>;
222
+ }
223
+ /** 跨 realm 初始化失败;不把 required 插件错误包装成成功状态。 */
224
+ interface RuntimeInitializationErrorDetails {
225
+ pluginId?: string;
226
+ unitId?: string;
227
+ phase: "validate" | "register" | "startup" | "snapshot" | "handshake";
228
+ error: string;
229
+ }
230
+ declare class RuntimeInitializationError extends Error {
231
+ readonly code: "runtime.initialization_failed";
232
+ readonly details: RuntimeInitializationErrorDetails;
233
+ constructor(details: RuntimeInitializationErrorDetails);
234
+ }
235
+ declare class RuntimeUnavailableError extends Error {
236
+ readonly code: "runtime.unavailable";
237
+ constructor(message?: string);
238
+ }
239
+
240
+ interface CreateWindowAppOptions extends Omit<CreatePluginHostOptions, "runtime" | "runtimeUnitImplementationRegistry"> {
241
+ /** 逻辑 Runtime 标识;同一页面通常只创建一个 App。 */
242
+ id?: string;
243
+ /** 当前 Window 的插件定义;setup 只在当前 Window realm 执行。 */
244
+ plugins: readonly RuntimePluginDefinition[];
245
+ /**
246
+ * 供领域适配层接管分阶段注册时复用已经创建的 Window Host。
247
+ * 普通插件应省略该字段;传入后由调用方负责后续 register,App 仍负责
248
+ * Window Runtime 快照、远端投影和最终 dispose。
249
+ */
250
+ host?: PluginHost;
251
+ /** 可选的 SharedWorker Runtime;Window 单元只投影其状态,不创建 Worker 假实例。 */
252
+ remoteRuntime?: RuntimeHandle;
253
+ }
254
+ /** 创建当前 Window 的唯一 window-main Runtime。 */
255
+ declare function createWindowApp(options: CreateWindowAppOptions): Promise<WindowApp>;
256
+
257
+ interface SharedWorkerScopeLike {
258
+ onconnect: ((event: {
259
+ ports: MessagePort[];
260
+ }) => void) | null;
261
+ }
262
+ interface StartSharedWorkerAppOptions extends Omit<CreatePluginHostOptions, "runtime" | "runtimeUnitImplementationRegistry"> {
263
+ /** SharedWorker 的逻辑稳定标识。 */
264
+ id: string;
265
+ /** 只在 SharedWorker realm 执行的插件定义。 */
266
+ plugins: readonly RuntimePluginDefinition[];
267
+ /** 测试 fixture 可注入结构等价的 SharedWorkerGlobalScope。 */
268
+ globalScope?: SharedWorkerScopeLike;
269
+ /**
270
+ * 复用已有领域 Worker 入口的 onconnect 装配。回调只负责安装领域协议
271
+ * listener;WebLoom 仍在同一端口上安装自己的 Runtime listener,不会创建
272
+ * 第二个 Worker 或第二条物理连接。
273
+ */
274
+ onPortConnect?: (event: {
275
+ ports: MessagePort[];
276
+ }) => void;
277
+ }
278
+ interface SharedWorkerApp {
279
+ readonly runtimeKind: "shared-worker";
280
+ readonly runtimeId: string;
281
+ readonly runtimeInstanceId: string;
282
+ ready(): Promise<void>;
283
+ /** 重新按当前外部身份/意图对账运行单元;不会创建第二个 Worker。 */
284
+ reconcile(): Promise<void>;
285
+ state(): RuntimeStatusSnapshot;
286
+ subscribe(listener: RuntimeStatusListener): () => void;
287
+ dispose(reason?: string): Promise<LifecycleDisposeResult>;
288
+ }
289
+ /** 在当前 SharedWorkerGlobalScope 中安装唯一的 Worker Runtime。 */
290
+ declare function startSharedWorkerApp(options: StartSharedWorkerAppOptions): SharedWorkerApp;
291
+
292
+ interface SharedWorkerLike {
293
+ readonly port: MessagePort;
294
+ onerror?: (event: Event) => void;
295
+ /** 浏览器 SharedWorker 的错误事件;测试 fake 可省略。 */
296
+ addEventListener?(type: "error", listener: (event: Event) => void): void;
297
+ removeEventListener?(type: "error", listener: (event: Event) => void): void;
298
+ }
299
+ type SharedWorkerFactory = (url: string | URL, options: {
300
+ type: "module";
301
+ name?: string;
302
+ }) => SharedWorkerLike;
303
+ /**
304
+ * 供仍需在同一物理连接上承载产品 RPC 的装配层使用。
305
+ *
306
+ * 普通调用方不需要这个接缝;它们只使用 RuntimeHandle 的状态和
307
+ * serviceBridge。已有大量领域 RPC 的应用迁移时可以先把
308
+ * Runtime 握手与旧 RPC 复用同一 MessagePort,再逐步把领域调用收敛到
309
+ * capability service,而不会偷偷创建第二个 SharedWorker 连接。
310
+ */
311
+ interface SharedWorkerConnectionContext {
312
+ readonly worker: SharedWorkerLike;
313
+ readonly port: MessagePort;
314
+ readonly connectionId: string;
315
+ }
316
+ interface ConnectSharedWorkerOptions {
317
+ /** Worker 入口的逻辑 Runtime 标识。 */
318
+ id: string;
319
+ /** module SharedWorker URL;默认直接传给 new SharedWorker。 */
320
+ url: string | URL;
321
+ /** 可选的浏览器 SharedWorker name;不传时由 URL 参与实例隔离。 */
322
+ name?: string;
323
+ /** 断线后是否建立新连接;旧代理仍永久失效。默认为 true。 */
324
+ autoReconnect?: boolean;
325
+ /** 自动重连等待毫秒数。 */
326
+ reconnectDelayMs?: number;
327
+ /** 首个 runtime snapshot 到达前的握手超时;默认 10000ms。 */
328
+ handshakeTimeoutMs?: number;
329
+ /** 测试 fixture 使用;生产默认使用 globalThis.SharedWorker。 */
330
+ workerFactory?: SharedWorkerFactory;
331
+ /**
332
+ * 每次建立实际物理连接时调用一次;自动重连会再次调用。
333
+ * 回调可以在同一端口上安装产品协议,但不得替换 Runtime 的消息
334
+ * 监听器,也不得把旧端口保存为可重用连接。
335
+ */
336
+ onConnection?: (context: SharedWorkerConnectionContext) => void | Promise<void>;
337
+ }
338
+ /**
339
+ * 从 Window 连接真实 module SharedWorker。
340
+ *
341
+ * Promise 只在首个完整 baseline 快照到达后成功;调用方得到的代理均绑定
342
+ * 当前 connection/runtime/provider/revision,断线或重启不会静默换绑旧代理。
343
+ */
344
+ declare function connectSharedWorker(options: ConnectSharedWorkerOptions): Promise<RuntimeHandle>;
345
+
56
346
  /** 创建绑定到指定插件实例的 MessageBus 视图。 */
57
347
  declare function createScopedMessageBus(base: MessageBus, scope: LifecycleScope): MessageBus;
58
348
 
@@ -156,4 +446,4 @@ interface MessagePortServiceProvider {
156
446
  /** 创建一个只服务于一条实际 MessagePort 连接的 Provider 端点。 */
157
447
  declare function createMessagePortServiceProvider(options: CreateMessagePortServiceProviderOptions): MessagePortServiceProvider;
158
448
 
159
- export { type BuildPluginGraphOptions, type CreateMessagePortServiceProviderOptions, type CreatePermissionLeaseOptions, type CreateScopedRegistryFacadeOptions, type CreateScopedTaskSchedulerOptions, CreateUpgradeGateOptions, LifecycleScope, LifecycleScopeIdentity, MessageBus, type MessagePortServiceCallInput, type MessagePortServiceProvider, PermissionLease, PluginDependency, PluginExecution, PluginGraph, type PluginGraphDiagnostic, PluginGraphValidationError, PluginManifest, PluginPermission, PluginReverseDep, RemoteServiceHandshake, RemoteServiceMessageCodec, RemoteServicePortCallMessage, RemoteServiceSnapshot, type ScopedRegistryRegistration, ScopedTaskScheduler, UpgradeGate, type ValidatePluginGraphOptions, type VerifyPermissionLeaseOptions, buildPluginGraph, createMessagePortServiceProvider, createPermissionLease, createScopedMessageBus, createScopedRegistryFacade, createScopedTaskScheduler, createUpgradeGate, dependenciesOfManifest, providesOfManifest, reverseDependentsOf, validatePluginGraph, validateRuntimeUnitDependencyContracts, verifyPermissionLease };
449
+ export { type BuildPluginGraphOptions, type ConnectSharedWorkerOptions, type CreateMessagePortServiceProviderOptions, type CreatePermissionLeaseOptions, CreatePluginHostOptions, type CreateScopedRegistryFacadeOptions, type CreateScopedTaskSchedulerOptions, CreateUpgradeGateOptions, type CreateWindowAppOptions, type DefinePluginOptions, LifecycleDisposeResult, LifecycleScope, LifecycleScopeIdentity, type MaterializedPluginDefinition, MessageBus, type MessagePortServiceCallInput, type MessagePortServiceProvider, PermissionLease, PluginConfig, PluginContextExtension, PluginContribution, type PluginDefinition, PluginDependency, PluginGraph, type PluginGraphDiagnostic, PluginGraphValidationError, PluginHost, PluginManifest, PluginManifestInput, PluginMeta, PluginPermission, PluginReverseDep, PluginSetup, PluginStateKind, PluginUnitState, RUNTIME_ERROR_TYPE, RUNTIME_HELLO_TYPE, RUNTIME_PROTOCOL_VERSION, RUNTIME_RESYNC_TYPE, RUNTIME_SNAPSHOT_TYPE, RemoteServiceBridge, RemoteServiceHandshake, RemoteServiceMessageCodec, RemoteServicePortCallMessage, RemoteServiceProxy, RemoteServiceReference, RemoteServiceSnapshot, type RuntimeAppState, RuntimeDependency, type RuntimeErrorMessage, type RuntimeHandle, type RuntimeHelloMessage, RuntimeInitializationError, type RuntimeInitializationErrorDetails, RuntimeKind, type RuntimePluginDefinition, type RuntimeResyncMessage, type RuntimeSnapshot, type RuntimeSnapshotUnit, type RuntimeStatusListener, type RuntimeStatusSnapshot, RuntimeUnavailableError, RuntimeUnitDescriptorInput, type ScopedRegistryRegistration, ScopedTaskScheduler, type SharedWorkerApp, type SharedWorkerConnectionContext, type SharedWorkerFactory, type SharedWorkerLike, type SharedWorkerScopeLike, type StartSharedWorkerAppOptions, UpgradeGate, type ValidatePluginGraphOptions, type VerifyPermissionLeaseOptions, type WindowApp, buildPluginGraph, connectSharedWorker, createMessagePortServiceProvider, createPermissionLease, createRuntimeMessageCodec, createScopedMessageBus, createScopedRegistryFacade, createScopedTaskScheduler, createUpgradeGate, createWindowApp, definePlugin, dependenciesOfManifest, isRuntimeError, isRuntimeHello, isRuntimeResync, isRuntimeSnapshot, materializePluginDefinition, materializePluginDefinitions, providesOfManifest, reverseDependentsOf, startSharedWorkerApp, unitSnapshotFromState, validatePluginGraph, validateRuntimeUnitDependencyContracts, verifyPermissionLease };