@mica-js/editor 0.14.0 → 0.15.1

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 CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  `@mica-js/editor/fused` 提供 React 19 工作台,直接编辑融合 `.sch` v2 文档。器件底图、逐引脚接线与动态覆盖共用实例坐标;主线程处理文档和交互,模型与 `view2d.js` 分别运行在现有 `SandboxWorker` 中。进入「运行」自动启动,切回「编辑」释放运行会话,下次运行从初态开始。暂停与继续只作为宿主 API 提供,工具条不显示相应控件:`workbench.executeCommand('simulation.pause')` 在仿真端确认后停止推进,保留模型、视图和订阅,实例音频随之暂停;`workbench.executeCommand('simulation.resume')` 在同一会话上继续。两个命令都串行于模式切换,编辑模式下拒绝,已处于目标状态时不重复操作。`getState().simulationStatus` 与 `onDidChangeState` 报告运行会话的实际状态,编辑模式下为 `undefined`。
8
8
 
9
+ 仿真处于 `starting` 时,画布覆盖黑色半透明遮罩,背景模糊并提高饱和度,中央显示白色加载动画和「仿真启动中…」。启用减少动态效果时隐藏动画,保留遮罩和文字提示。
10
+
9
11
  ```typescript
10
12
  import { createWorkbench } from '@mica-js/editor/fused';
11
13
  import '@mica-js/editor/fused/style.css';
@@ -35,6 +37,8 @@ await workbench.dispose();
35
37
 
36
38
  宿主直接传入 `FusedDocument`,自行维护项目身份和存储。`getDocument()` / `onDidChangeContent` 提供当前快照;可选的 `saveDocument(snapshot)` 完成后标记对应版本已保存,缺失时 `save()` 明确拒绝。器件 Provider 返回锁定发布版本的 `PackageFiles`,工作台校验文件清单和摘要。
37
39
 
40
+ 「问题」面板显示诊断及其技术详情,宿主可用 `onDidReportDiagnostic` 收集诊断。工作台界面发起的操作失败时,`onDidFailOperation(({ operation, code, error }) => …)` 在操作结束后通知宿主,由宿主决定如何提示用户。工具条的「运行」「停止」「重启」分别使用 `simulation.start`、`simulation.stop`、`simulation.restart`,扩展工具条操作使用贡献项 ID。宿主直接调用 `setMode()`、`save()` 或 `executeCommand()` 时,通过返回的 Promise 处理失败。运行中进入 `faulted` 状态可通过 `onDidChangeState` 观察。
41
+
38
42
  `deviceStateProvider` 可持久化指定器件的二进制运行状态。`bindings` 按器件 ID 和锁定版本选择启动属性、查询方法与变化事件。启动时优先装载 `read` 返回的映像,缺失时使用电路配置。宿主用文档作用域与状态槽键定位 `read` / `write`,写入确认后运行时才视为已保存。工作台在停止、重启和关闭时等待保存,失败后可重试。预热不访问此存储。
39
43
 
40
44
  `assetProvider.select({ kind, formats, signal })` 打开宿主资产库 UI,返回 `{ id, name }` 或以 `undefined` 取消;`name` 包含文件扩展名。`read(id, signal)` 返回二进制,编辑器不枚举资产。普通资源仅支持 `asset` / `package`;`program` 另支持 `project`,使用 `programs.projects.select({ ...target, templateIds }, signal)` 选择项目、`resolve(id, target, signal?)` 取得程序产物。项目选择能力可省略,已有引用仍可解析;程序文件集资产使用 ZIP,校验解包后交给模型只读访问。
@@ -45,9 +49,11 @@ await workbench.dispose();
45
49
 
46
50
  `accessProvider.evaluateDocument` 分别决定编辑和运行权限,`canAddDevice` 决定能否新增指定发布版本。新增、属性修改、通用事务、粘贴、撤销重做与保存均经过文档会话授权。宿主可将包含付费器件的文档整体设为只读,并通过 `onDidChange` 通知授权变化;持久化服务仍应验证最终写入。只读文档中的面板位置调整仅保留在当前工作台会话。
47
51
 
48
- 器件声明的 HTML Views 在 Run 中开放。侧栏属性固定在顶部,HTML Views 支持折叠、排序、调整高度与浮动;浮动面板可拖动四条边与四个角调整尺寸,最小 180×100,键盘方向键每次调整 10px、按住 Shift 调整 40px。浮动面板保留所属实例,停靠切换保留同一 iframe 与同一套订阅;折叠只隐藏页面,不卸载。运行结束释放这些环境。
52
+ 器件声明的 HTML Views 在 Run 中开放。侧栏属性固定在顶部,HTML Views 支持折叠、排序、调整高度与浮动;浮动面板可拖动四条边与四个角调整尺寸,最小 180×100,键盘方向键每次调整 10px、按住 Shift 调整 40px。浮动面板的标题栏提供停靠按钮,将视图放回所属实例的侧栏。停靠切换保留同一 iframe 与同一套订阅;折叠只隐藏页面,不卸载。运行结束释放这些环境。
53
+
54
+ 每个视图环境由同源的 `index.html`(可信外层页)和 `content.html`(内层沙箱)组成,与工作台跨源隔离。编辑器通过控制端口向外层提供主题、生命周期和经过验证的包资源读取,内层通过专用端口直连编辑器的器件 API。内层 bootstrap 安装 `acquireDeviceViewApi`、监听器和包资源授权后,外层写入作者文档,两层页面身份保持稳定。作者侧通过一次性的 `acquireDeviceViewApi` 使用器件 API。
49
55
 
50
- 每个视图环境是两个同源(但与工作台隔离)的 frame,两者都是部署目录里的真实文档:可信外层页 `index.html` 只保留生命周期控制通道(加载、主题中继、失败上报)与作者文档写入,并在整个视图生命周期内不变;内层沙箱 frame 加载同一目录的 `content.html`,因此两边的 origin 都是具体值、按精确值校验。编辑器为每个视图创建两条专用 `MessagePort`:一条直连内层作者 frame(`DeviceViewApi` 的 props、模型方法与事件、包资源读取、视图身份与关闭通知),一条直连该环境的 Service Worker(包资源读取)。外层只在内层 frame 报出本次环境令牌后转交端口,自身不转发任何作者调用或包读取。内层 bootstrap 先安装 `acquireDeviceViewApi`、监听器与包资源授权,再向外层宣告就绪;外层随后把作者文档写入 `frame.contentDocument`(`document.open/write/close`),window 与两个 frame 身份都保持不变。作者侧只拿到一次性的 `acquireDeviceViewApi`,拿不到 `MessagePort`、宿主代理或编辑器 DOM;包资源只有授予该环境的页面与它用令牌授权的内层 frame 可读,其它客户端、页面跳转与未声明文件一律拒绝。专用端口与当前视图租约绑定,视图释放或任一端关闭时立即关闭相关订阅与端口,失败后不会重新授予端口;作者文档的跳转或重新加载(重新启动 `content.html` 的 bootstrap)会明确报告 `view/execution-failed`,不会重新打开环境。
56
+ 包资源 Worker 每次读取时连接当前外层页,外层只为经过登记的页面客户端读取锁定包中声明的文件。视图持有资源授权,Worker 退出后可在下一次读取时重新启动。视图释放时撤销授权和模型订阅。作者文档的跳转或重新加载会报告 `view/execution-failed`。
51
57
 
52
58
  工作台主题以计算后的颜色转发给每个环境:`--mica-*` 变量与 `color-scheme` 在任意作者脚本执行前注入内层文档根,之后主题或系统明暗变化就地更新同一文档根,不重载 frame,也不丢失作者输入、模型会话或文档历史。加载期的底色也不会白闪:加载中的视图由容器槽位绘制当前视图背景(`panel.background`,即 `--mica-panel`,同时保留既有加载提示),owner 在加载期间保持透明,frame 在作者文档写入并应用主题前保持隐藏(`visibility`,不卸载、不重建,脚本照常运行),因此浏览器为未着色子文档绘制的白色画布不会被看到;环境报告就绪后 owner 取得当前主题底色并显示 frame。这条链路由 `setTheme` / 主题中继实时重绘,所以外层模块或内层 bootstrap 被延迟时切换主题,显示的始终是最新颜色而不是首次快照。没有转发主题的独立宿主使用完整暗色默认值,示例监视器的 `body` 也使用同一 `--mica-panel`,作者样式加载前后底色一致。
53
59
 
@@ -55,7 +61,7 @@ await workbench.dispose();
55
61
 
56
62
  ### 主题与颜色 Token
57
63
 
58
- 信息容器固定在活动栏首位。当前模式只有属性视图时,容器头部合并为“属性”及其操作,内容始终展开,保留收起整个侧栏的操作;包含器件视图时,头部显示“信息”,各视图保留自己的标题并支持折叠。最后一个展开的视图填满剩余高度,其后的折叠标题随之推到底部,保持视图顺序;空间不足时在容器内滚动。已打开的浮动视图隐藏头部入口,关闭后重新显示入口。折叠、停靠和浮动均不改变可用视图的计数;属性视图固定在首位。
64
+ 信息容器固定在活动栏首位。当前模式只有属性视图时,容器头部合并为“属性”及其操作,内容始终展开,保留收起整个侧栏的操作;包含器件视图时,头部显示“信息”,各视图保留自己的标题并支持折叠。最后一个展开的视图填满剩余高度,其后的折叠标题随之推到底部,保持视图顺序;空间不足时在容器内滚动。归属浮动且未打开的视图在头部显示入口。折叠、停靠和浮动均不改变可用视图的计数;属性视图固定在首位。
59
65
 
60
66
  电源、接地端子和网络标签的符号、文字与默认偏移使用场景单位,已放置内容与幽灵预览均随画布缩放。导线预览、提交和器件移动使用共用的正交路由;端子、网标与器件放置一次后返回选择工具,Esc 取消放置且不写入文档。新建电源符号默认使用 `VCC` 网名与 `3.3 V` 电压,幽灵预览显示同一默认值;接地符号固定 `0 V` 且不保存网名。点击端子符号或网名只选择对象,点击其接线锚点才进入画线状态。拖动独立网标时连接端与名称一起移动,附着导线的折点随节点重排;命名引脚或共享节点的网标只移动名称,连接端留在原处。属性面板对选中的电压参考显示类型与连接端,并可直接修改角度、电压与网名,接地符号固定 `0 V` 且不提供电压和网名编辑;普通网标可直接修改网名;导线与连接节点显示只读身份。
61
67
 
@@ -105,13 +105,10 @@ declare type FusedViewInputType = 'pointerdown' | 'pointerup' | 'pointermove';
105
105
  /** Acknowledgement the environment posts back once it owns the transferred port. */
106
106
  export declare const HTML_VIEW_ACK = "mica:view:ack";
107
107
 
108
- /** Control message that grants the environment's asset worker its package channel. */
109
- export declare const HTML_VIEW_ASSETS = "mica:view:assets";
108
+ /** The asset worker requests a port for one package fetch. */
109
+ export declare const HTML_VIEW_ASSET_READ = "mica:view:asset-read";
110
110
 
111
- /** Acknowledgement of {@link HTML_VIEW_ASSETS}: the worker owns the package port. */
112
- export declare const HTML_VIEW_ASSETS_ACK = "mica:view:assets-ack";
113
-
114
- /** Control message the inner frame posts into the asset worker to authorize its own requests. */
111
+ /** Control message the inner frame sends through the asset worker to authorize its requests. */
115
112
  export declare const HTML_VIEW_ATTACH = "mica:view:attach";
116
113
 
117
114
  /** Acknowledgement of {@link HTML_VIEW_ATTACH}; only then may the author document load. */
@@ -269,6 +266,8 @@ declare interface IFusedDisplayLayout {
269
266
 
270
267
  /** Request that mounts presentation for one mode. */
271
268
  declare interface IFusedDisplayPrepareInput {
269
+ /** Optional request time in the host's Performance timeline. */
270
+ readonly requestedAt?: number;
272
271
  /**
273
272
  * `run` mounts models first and hands every presentation its model client; `edit` releases the
274
273
  * models and prepares the same instances without a model.
@@ -290,10 +289,10 @@ declare interface IFusedFirmwareSnapshot {
290
289
  readonly segments: readonly IFusedFirmwareSegment[];
291
290
  }
292
291
 
293
- /** Package bytes the editor answers one asset request with. */
292
+ /** Package bytes the trusted outer frame answers one asset request with. */
294
293
  export declare interface IFusedHtmlAssetService {
295
- /** Reads one package file for an asset request; every failure answers `404`. */
296
- read(path: string): Promise<Uint8Array>;
294
+ /** Reads a verified package file for this fetch, or returns undefined for an unauthorized client. */
295
+ read(path: string): Promise<Uint8Array | undefined>;
297
296
  }
298
297
 
299
298
  /**
@@ -307,14 +306,9 @@ export declare interface IFusedHtmlContentViewService {
307
306
  view(): Promise<IHtmlViewContent>;
308
307
  }
309
308
 
310
- /**
311
- * Lifecycle capabilities of the trusted outer frame, served directly by the editor.
312
- *
313
- * This lane carries no model call and no author resource read: the outer loads the view, relays the
314
- * theme, reports failures and hands the two dedicated ports on.
315
- */
309
+ /** Lifecycle and verified package reads of the trusted outer frame. */
316
310
  export declare interface IFusedHtmlHostControlService {
317
- /** Reads one declared package file of this view; the outer reads its author document with it. */
311
+ /** Reads one declared package file of this view, including the entry document. */
318
312
  readAsset(path: string): Promise<Uint8Array>;
319
313
  /** Computed theme of the workbench at this moment. */
320
314
  getTheme(): Promise<IHtmlViewTheme>;
@@ -326,13 +320,6 @@ export declare interface IFusedHtmlHostControlService {
326
320
  reportFailure(code: string, message: string): Promise<void>;
327
321
  /** Announces that the environment goes away without an editor request. */
328
322
  closed(): void;
329
- /**
330
- * Grants the dedicated package lane of this view's asset worker, once.
331
- *
332
- * The port is transferred into the worker straight from the outer frame, so no author document
333
- * and no editor page ever holds it; the grant token decides which clients it serves.
334
- */
335
- assetPort(): Promise<MessagePort>;
336
323
  /**
337
324
  * Grants the dedicated author lane of this view's inner frame, once.
338
325
  *
@@ -503,25 +490,6 @@ export declare interface IHtmlViewAckMessage {
503
490
  readonly token: string;
504
491
  }
505
492
 
506
- export declare interface IHtmlViewAssetAckMessage {
507
- readonly type: typeof HTML_VIEW_ASSETS_ACK;
508
- readonly token: string;
509
- }
510
-
511
- /**
512
- * Grant of the package asset worker: the prefix it serves plus two ports.
513
- *
514
- * The first port is the dedicated package lane of the editor, the second one is where the worker
515
- * acknowledges the grant. The environment page that installs the grant is the only client the
516
- * registry admits, and it never answers a package read itself.
517
- */
518
- export declare interface IHtmlViewAssetGrantMessage {
519
- readonly type: typeof HTML_VIEW_ASSETS;
520
- readonly token: string;
521
- /** URL pathname of the package asset root this worker serves. */
522
- readonly root: string;
523
- }
524
-
525
493
  export declare interface IHtmlViewAttachAckMessage {
526
494
  readonly type: typeof HTML_VIEW_ATTACH_ACK;
527
495
  readonly token: string;
@@ -1 +1 @@
1
- export { y as ASSET_ROOT_DIRECTORY, s as DEFAULT_HTML_VIEW_THEME, b as ENVIRONMENT_BOOTSTRAP_FILE, x as ENVIRONMENT_CONTENT_DOCUMENT_FILE, S as ENVIRONMENT_CONTENT_FILE, C as ENVIRONMENT_DOCUMENT_FILE, w as ENVIRONMENT_WORKER_FILE, L as HTML_VIEW_ACK, R as HTML_VIEW_ASSETS, z as HTML_VIEW_ASSETS_ACK, B as HTML_VIEW_ATTACH, V as HTML_VIEW_ATTACH_ACK, H as HTML_VIEW_CHILD_CONNECT, U as HTML_VIEW_CHILD_HELLO, W as HTML_VIEW_CHILD_PREPARED, G as HTML_VIEW_CONNECT, T as HTML_VIEW_CONTENT_POLICY, E as HTML_VIEW_ENVIRONMENT_POLICY, K as HTML_VIEW_FRAME_PARAM, q as HtmlViewError, N as VIEW_ENV_LABEL, c as applyHtmlViewTheme, t as assertAssetPath, D as assetRootUrl, O as authorBaseUrl, n as createDeviceViewSession, a as createHtmlViewHost, r as createHtmlViewRuntimeSource, k as decodeDocument, J as fusedHtmlAssetService, Y as fusedHtmlContentViewService, X as fusedHtmlHostControlService, Z as fusedHtmlHostService, P as htmlEnvironmentUrl, i as htmlViewDeviceDeclaration, o as htmlViewKey, l as htmlViewThemeCss, u as htmlViewThemeEquals, Q as isHtmlViewError, A as mimeTypeOf, F as newHtmlEnvironmentId, d as normalizeHtmlViewTheme, I as parseHtmlViewBase, j as resolveAssetRequest, M as withHtmlDocumentPreamble } from "./html-CyZiE7kS.js";
1
+ export { y as ASSET_ROOT_DIRECTORY, s as DEFAULT_HTML_VIEW_THEME, b as ENVIRONMENT_BOOTSTRAP_FILE, x as ENVIRONMENT_CONTENT_DOCUMENT_FILE, S as ENVIRONMENT_CONTENT_FILE, C as ENVIRONMENT_DOCUMENT_FILE, w as ENVIRONMENT_WORKER_FILE, L as HTML_VIEW_ACK, R as HTML_VIEW_ASSET_READ, z as HTML_VIEW_ATTACH, B as HTML_VIEW_ATTACH_ACK, V as HTML_VIEW_CHILD_CONNECT, H as HTML_VIEW_CHILD_HELLO, U as HTML_VIEW_CHILD_PREPARED, W as HTML_VIEW_CONNECT, T as HTML_VIEW_CONTENT_POLICY, E as HTML_VIEW_ENVIRONMENT_POLICY, G as HTML_VIEW_FRAME_PARAM, K as HtmlViewError, N as VIEW_ENV_LABEL, c as applyHtmlViewTheme, t as assertAssetPath, D as assetRootUrl, O as authorBaseUrl, n as createDeviceViewSession, a as createHtmlViewHost, r as createHtmlViewRuntimeSource, k as decodeDocument, q as fusedHtmlAssetService, J as fusedHtmlContentViewService, Y as fusedHtmlHostControlService, X as fusedHtmlHostService, P as htmlEnvironmentUrl, i as htmlViewDeviceDeclaration, o as htmlViewKey, l as htmlViewThemeCss, u as htmlViewThemeEquals, Z as isHtmlViewError, A as mimeTypeOf, F as newHtmlEnvironmentId, d as normalizeHtmlViewTheme, I as parseHtmlViewBase, j as resolveAssetRequest, M as withHtmlDocumentPreamble } from "./html-B0pN-5Mx.js";
@@ -9,6 +9,8 @@ import { WidgetAudioOptions as IFusedAudioOptions } from '@mica-js/widget/audio-
9
9
  import { WidgetAudioStreamOptions as IFusedAudioStreamOptions } from '@mica-js/widget/audio-guest';
10
10
  import { WidgetAudioTone as IFusedAudioTone } from '@mica-js/widget/audio-guest';
11
11
  import { WidgetAudioToneOptions as IFusedAudioToneOptions } from '@mica-js/widget/audio-guest';
12
+ import { LogLevel } from '@mica-js/core/logging';
13
+ import { LogRecord } from '@mica-js/core/logging';
12
14
  import { MemoryProgram } from '@mica-js/sdk/fused';
13
15
  import { ModelEvent } from '@mica-js/sdk/fused';
14
16
  import { PackageFile } from '@mica-js/document/fused';
@@ -24,6 +26,7 @@ import { RpcEndpoint } from '@mica-js/core/rpc';
24
26
  import { RpcProxy } from '@mica-js/core/rpc';
25
27
  import { RpcServiceId } from '@mica-js/core/rpc';
26
28
  import { RuntimeDiagnostic } from '@mica-js/sdk/fused';
29
+ import { SandboxWorkerError } from '@mica-js/sandbox';
27
30
  import { TimePs } from '@mica-js/core';
28
31
  import { Value } from '@mica-js/document/fused';
29
32
  import { WidgetAudioApi } from '@mica-js/widget/audio-guest';
@@ -96,6 +99,8 @@ export declare const fusedHostPackageService: RpcServiceId<IFusedHostPackageServ
96
99
  /** Wire name of the host resource access of the simulation guest. */
97
100
  export declare const fusedHostResourceService: RpcServiceId<IFusedHostResourceService>;
98
101
 
102
+ export declare type FusedLogSource = 'workbench' | 'simulation' | 'display' | 'widget' | 'audio';
103
+
99
104
  /** Wire name of the model lane the simulation guest serves. */
100
105
  export declare const fusedModelChannelService: RpcServiceId<IFusedModelChannelService>;
101
106
 
@@ -131,6 +136,10 @@ export declare type FusedSimulationPacing = 'realtime' | 'unlimited';
131
136
  /** Wire name of the simulation guest. */
132
137
  export declare const fusedSimulationService: RpcServiceId<IFusedSimulationService>;
133
138
 
139
+ export declare type FusedStartupKind = 'start' | 'resume' | 'restart';
140
+
141
+ export declare type FusedStartupOutcome = 'success' | 'failure' | 'cancelled';
142
+
134
143
  export declare type FusedSurfaceFactory = (width: number, height: number) => IFusedOverlaySurface;
135
144
 
136
145
  /** Default export of a `view2d.entry` module. */
@@ -138,6 +147,8 @@ export declare type FusedView2DFactory = (context: IFusedView2DContext) => IFuse
138
147
 
139
148
  export declare type FusedViewInputType = 'pointerdown' | 'pointerup' | 'pointermove';
140
149
 
150
+ export declare type FusedWarmupProgress = 'not-started' | 'partial' | 'completed';
151
+
141
152
  declare interface IDeviceStateBinding {
142
153
  readonly device: string;
143
154
  readonly version: string;
@@ -185,6 +196,12 @@ export { IFusedAudioTone }
185
196
 
186
197
  export { IFusedAudioToneOptions }
187
198
 
199
+ declare interface IFusedBootCompletion {
200
+ readonly runId: string;
201
+ readonly outcome: FusedStartupOutcome;
202
+ readonly warmup?: FusedWarmupProgress;
203
+ }
204
+
188
205
  export declare interface IFusedBridgeErrorOptions {
189
206
  readonly instanceId?: string;
190
207
  readonly details?: Value;
@@ -212,7 +229,9 @@ export declare interface IFusedConnectionOptions {
212
229
  readonly container?: HTMLElement;
213
230
  readonly resolveResource?: ResourceResolver;
214
231
  readonly programs?: ProgramSources;
215
- readonly onDiagnostic?: (diagnostic: RuntimeDiagnostic) => void;
232
+ readonly onDiagnostic?: (diagnostic: RuntimeDiagnostic, source: FusedLogSource) => void;
233
+ readonly observability?: IFusedObservabilityOptions;
234
+ readonly onDisconnect?: (source: 'simulation' | 'display') => void;
216
235
  }
217
236
 
218
237
  /** A configured slot and, if available, its persisted startup bytes. */
@@ -294,6 +313,8 @@ export declare interface IFusedDisplayLayout {
294
313
 
295
314
  /** Request that mounts presentation for one mode. */
296
315
  export declare interface IFusedDisplayPrepareInput {
316
+ /** Optional request time in the host's Performance timeline. */
317
+ readonly requestedAt?: number;
297
318
  /**
298
319
  * `run` mounts models first and hands every presentation its model client; `edit` releases the
299
320
  * models and prepares the same instances without a model.
@@ -412,6 +433,7 @@ export declare interface IFusedInvalidateEvent {
412
433
 
413
434
  /** Request that creates the models of one run session. */
414
435
  export declare interface IFusedLoadRequest {
436
+ readonly observation?: IFusedObservation;
415
437
  readonly document: FusedDocument;
416
438
  /** Fixed positive step of every advance, in picoseconds. */
417
439
  readonly step: TimePs;
@@ -422,6 +444,12 @@ export declare interface IFusedLoadRequest {
422
444
  readonly stateGeneration?: number;
423
445
  }
424
446
 
447
+ export declare interface IFusedLogRecord extends LogRecord {
448
+ readonly source: FusedLogSource;
449
+ /** Workbench receive time, in Unix epoch milliseconds. */
450
+ readonly receivedAt: number;
451
+ }
452
+
425
453
  /** Model lane served by the simulation guest to the display guest over the direct port. */
426
454
  export declare interface IFusedModelChannelService {
427
455
  call(instanceId: string, method: string, params: Value): Promise<Value>;
@@ -473,6 +501,23 @@ export declare interface IFusedModelSinkService {
473
501
  deliver(event: IFusedModelEventWire): void;
474
502
  }
475
503
 
504
+ export declare interface IFusedObservabilityOptions {
505
+ /** Defaults to info. A workbench writes to its Console when no sink is supplied. */
506
+ readonly logLevel?: LogLevel;
507
+ readonly onLog?: (record: IFusedLogRecord) => void;
508
+ /** Enables User Timing and startup sampling. Defaults to false. */
509
+ readonly performance?: boolean;
510
+ readonly onSample?: (sample: IFusedStartupSample) => void;
511
+ }
512
+
513
+ declare interface IFusedObservation {
514
+ readonly debug: boolean;
515
+ readonly performance: boolean;
516
+ readonly runId?: string;
517
+ readonly sessionId?: string;
518
+ readonly kind?: FusedStartupKind;
519
+ }
520
+
476
521
  /** Rendered overlay of one instance; the bitmap lives in the host after the transfer. */
477
522
  export declare interface IFusedOverlayFrame extends IFusedDisplayLayout {
478
523
  readonly instanceId: string;
@@ -496,6 +541,7 @@ export declare interface IFusedPackageFilesWire {
496
541
 
497
542
  /** Preparation request of the simulation guest: verify packages and describe the scene. */
498
543
  export declare interface IFusedPrepareRequest {
544
+ readonly observation?: IFusedObservation;
499
545
  readonly document: FusedDocument;
500
546
  readonly mode: FusedDisplayMode;
501
547
  readonly deviceState?: readonly IFusedDeviceStateImage[];
@@ -560,6 +606,9 @@ export declare interface IFusedRuntime {
560
606
  }
561
607
 
562
608
  export declare interface IFusedRuntimeOptions {
609
+ readonly observability?: IFusedObservabilityOptions;
610
+ /** Optional request time for an initial run, in the host's Performance timeline. */
611
+ readonly requestedAt?: number;
563
612
  readonly deviceStateProvider?: IDeviceStateProvider;
564
613
  /** Caller-owned browser context; resume it directly within a user gesture for autoplay. */
565
614
  readonly audio?: IFusedAudioOptions;
@@ -627,7 +676,7 @@ export declare interface IFusedSimulationService {
627
676
  */
628
677
  warmup(request: IFusedWarmupRequest): Promise<void>;
629
678
  step(): Promise<IFusedSessionState>;
630
- resume(): Promise<void>;
679
+ resume(observation?: IFusedObservation): Promise<void>;
631
680
  /** Stops advancement synchronously; the RPC result acknowledges the paused state. */
632
681
  pause(): void;
633
682
  reset(): Promise<void>;
@@ -642,12 +691,38 @@ export declare interface IFusedSimulationService {
642
691
  invalidatePrograms(projectId?: string, fingerprint?: string): Promise<void>;
643
692
  call(instanceId: string, method: string, params: Value): Promise<Value>;
644
693
  getState(): IFusedSessionState;
645
- onDidChangeState(listener: (state: IFusedSessionState) => void): () => void;
694
+ onDidChangeState(listener: (state: IFusedSessionState, boot?: IFusedBootCompletion) => void): () => void;
646
695
  onDidReportDiagnostic(listener: (diagnostic: RuntimeDiagnostic) => void): () => void;
647
696
  /** Every model event of the session, in production order. */
648
697
  onDidModelEvent(listener: (event: IFusedModelEventWire) => void): () => void;
649
698
  }
650
699
 
700
+ export declare interface IFusedStartupSample {
701
+ readonly phase: 'device-package' | 'simulation-load' | 'first-step' | 'workbench-startup';
702
+ readonly outcome: FusedStartupOutcome;
703
+ readonly durationMs: number;
704
+ readonly runId?: string;
705
+ readonly sessionId?: string;
706
+ readonly kind?: FusedStartupKind;
707
+ readonly warmup?: FusedWarmupProgress;
708
+ readonly packageId?: string;
709
+ readonly version?: string;
710
+ }
711
+
712
+ export declare interface IFusedStartupSummary {
713
+ readonly phase: IFusedStartupSample['phase'];
714
+ readonly kind?: FusedStartupKind;
715
+ readonly warmup?: FusedWarmupProgress;
716
+ readonly packageId?: string;
717
+ readonly version?: string;
718
+ readonly count: number;
719
+ readonly failed: number;
720
+ readonly cancelled: number;
721
+ readonly p50Ms: number | null;
722
+ readonly p95Ms: number | null;
723
+ readonly maxMs: number | null;
724
+ }
725
+
651
726
  /** Object a `view2d.entry` default factory returns (RFC 0022). */
652
727
  export declare interface IFusedView2D {
653
728
  initialize?(): void | Promise<void>;
@@ -715,6 +790,7 @@ export declare interface IFusedViewSessionOptions {
715
790
 
716
791
  /** Request that prepares the boot path ahead of a run session. */
717
792
  declare interface IFusedWarmupRequest {
793
+ readonly observation?: IFusedObservation;
718
794
  readonly document: FusedDocument;
719
795
  /** Fixed positive step of every advance, in picoseconds. */
720
796
  readonly step: TimePs;
@@ -726,6 +802,7 @@ declare interface IFusedWarmupRequest {
726
802
  export declare interface IFusedWorker {
727
803
  readonly state: 'ready' | 'terminated';
728
804
  readonly ready: Promise<void>;
805
+ onError?(listener: (error: SandboxWorkerError) => void): () => void;
729
806
  postMessage(message: unknown, options?: readonly Transferable[]): void;
730
807
  terminate(reason?: string): Promise<void>;
731
808
  }
@@ -1,3 +1,3 @@
1
1
  import { c as toWireFailure, i as isFusedBridgeError, n as FusedBridgeError, o as mapWireFailure, r as fromWireFailure, t as FUSED_WIRE_FAILURE } from "./wire-Di4FVpnu.js";
2
- import { _ as fusedModelSinkService, a as createFusedRuntime, c as createModelEventRouter, d as createHostPackageGateway, f as packageLockKey, g as fusedModelChannelService, h as fusedHostResourceService, i as startFusedSimulationGuest, l as createFusedDisplay, m as fusedHostPackageService, n as startFusedDisplayGuest, o as createHostModelRouter, p as fusedDisplayService, r as createViewSession, s as channelKey, t as loadFusedWorkerFactories, u as connectFusedWorkbench, v as fusedSimulationService } from "./runtime-_9IqvWDa.js";
2
+ import { S as fusedSimulationService, _ as fusedDisplayService, a as createFusedRuntime, b as fusedModelChannelService, c as createModelEventRouter, g as packageLockKey, h as createHostPackageGateway, i as startFusedSimulationGuest, l as createFusedDisplay, n as startFusedDisplayGuest, o as createHostModelRouter, r as createViewSession, s as channelKey, t as loadFusedWorkerFactories, u as connectFusedWorkbench, v as fusedHostPackageService, x as fusedModelSinkService, y as fusedHostResourceService } from "./runtime-DuxZ_yVl.js";
3
3
  export { FUSED_WIRE_FAILURE, FusedBridgeError, channelKey, connectFusedWorkbench, createFusedDisplay, createFusedRuntime, createHostModelRouter, createHostPackageGateway, createModelEventRouter, createViewSession, fromWireFailure, fusedDisplayService, fusedHostPackageService, fusedHostResourceService, fusedModelChannelService, fusedModelSinkService, fusedSimulationService, isFusedBridgeError, loadFusedWorkerFactories, mapWireFailure, packageLockKey, startFusedDisplayGuest, startFusedSimulationGuest, toWireFailure };
package/dist/fused.d.ts CHANGED
@@ -13,6 +13,8 @@ import { WidgetAudioStreamOptions as IFusedAudioStreamOptions } from '@mica-js/w
13
13
  import { WidgetAudioTone as IFusedAudioTone } from '@mica-js/widget/audio-guest';
14
14
  import { WidgetAudioToneOptions as IFusedAudioToneOptions } from '@mica-js/widget/audio-guest';
15
15
  import { InstanceViewLayout } from '@mica-js/document/fused';
16
+ import { LogLevel } from '@mica-js/core/logging';
17
+ import { LogRecord } from '@mica-js/core/logging';
16
18
  import { Placement2D } from '@mica-js/document/fused';
17
19
  import { Point2D } from '@mica-js/document/fused';
18
20
  import { ProgramFile } from '@mica-js/sdk/fused';
@@ -94,6 +96,8 @@ export { FusedAudioState }
94
96
 
95
97
  export { FusedDocument }
96
98
 
99
+ export declare type FusedLogSource = 'workbench' | 'simulation' | 'display' | 'widget' | 'audio';
100
+
97
101
  /** Read-only plain property snapshot handed to a 2D presentation. */
98
102
  declare type FusedPresentationProps = Readonly<Record<string, FusedPresentationValue>>;
99
103
 
@@ -112,6 +116,12 @@ declare type FusedSessionStatus = 'idle' | 'starting' | 'paused' | 'running' | '
112
116
  /** Wall-clock pacing of continuous simulation in the editor worker. */
113
117
  export declare type FusedSimulationPacing = 'realtime' | 'unlimited';
114
118
 
119
+ export declare type FusedStartupKind = 'start' | 'resume' | 'restart';
120
+
121
+ export declare type FusedStartupOutcome = 'success' | 'failure' | 'cancelled';
122
+
123
+ export declare type FusedWarmupProgress = 'not-started' | 'partial' | 'completed';
124
+
115
125
  export declare interface IAssetInfo {
116
126
  readonly id: string;
117
127
  /** File name including its extension; used to identify program formats. */
@@ -367,11 +377,52 @@ declare interface IFusedInstancePresentation {
367
377
  readonly events: readonly string[];
368
378
  }
369
379
 
380
+ export declare interface IFusedLogRecord extends LogRecord {
381
+ readonly source: FusedLogSource;
382
+ /** Workbench receive time, in Unix epoch milliseconds. */
383
+ readonly receivedAt: number;
384
+ }
385
+
386
+ export declare interface IFusedObservabilityOptions {
387
+ /** Defaults to info. A workbench writes to its Console when no sink is supplied. */
388
+ readonly logLevel?: LogLevel;
389
+ readonly onLog?: (record: IFusedLogRecord) => void;
390
+ /** Enables User Timing and startup sampling. Defaults to false. */
391
+ readonly performance?: boolean;
392
+ readonly onSample?: (sample: IFusedStartupSample) => void;
393
+ }
394
+
370
395
  declare interface IFusedProgramFilesSnapshot {
371
396
  readonly kind: 'filesystem';
372
397
  readonly files: readonly ProgramFile[];
373
398
  }
374
399
 
400
+ export declare interface IFusedStartupSample {
401
+ readonly phase: 'device-package' | 'simulation-load' | 'first-step' | 'workbench-startup';
402
+ readonly outcome: FusedStartupOutcome;
403
+ readonly durationMs: number;
404
+ readonly runId?: string;
405
+ readonly sessionId?: string;
406
+ readonly kind?: FusedStartupKind;
407
+ readonly warmup?: FusedWarmupProgress;
408
+ readonly packageId?: string;
409
+ readonly version?: string;
410
+ }
411
+
412
+ export declare interface IFusedStartupSummary {
413
+ readonly phase: IFusedStartupSample['phase'];
414
+ readonly kind?: FusedStartupKind;
415
+ readonly warmup?: FusedWarmupProgress;
416
+ readonly packageId?: string;
417
+ readonly version?: string;
418
+ readonly count: number;
419
+ readonly failed: number;
420
+ readonly cancelled: number;
421
+ readonly p50Ms: number | null;
422
+ readonly p95Ms: number | null;
423
+ readonly maxMs: number | null;
424
+ }
425
+
375
426
  declare interface IFusedTextTarget {
376
427
  readonly kind: 'designator' | 'label' | 'reference';
377
428
  readonly id: string;
@@ -383,11 +434,15 @@ export declare interface IResolvedWorkbenchTheme {
383
434
  }
384
435
 
385
436
  export declare interface IWorkbench {
437
+ /** Startup distributions over the most recent retained samples. */
438
+ getStartupPerformance(): readonly IFusedStartupSummary[];
386
439
  readonly contextKeys: IContextKeyService;
387
440
  readonly onDidChangeContent: Event_2<FusedDocument>;
388
441
  readonly onDidChangeSelection: Event_2<readonly IWorkbenchTarget[]>;
389
442
  readonly onDidChangeState: Event_2<IWorkbenchState>;
390
443
  readonly onDidReportDiagnostic: Event_2<IWorkbenchDiagnostic>;
444
+ /** Reports failed workbench UI operations. Direct API calls reject their own promises. */
445
+ readonly onDidFailOperation: Event_2<IWorkbenchOperationFailure>;
391
446
  readonly onDidRequestOpenProject: Event_2<{
392
447
  readonly projectId: string;
393
448
  }>;
@@ -553,7 +608,15 @@ export declare interface IWorkbenchExtensionContext {
553
608
  readonly signal: AbortSignal;
554
609
  }
555
610
 
611
+ export declare interface IWorkbenchOperationFailure {
612
+ /** Identifier of the UI operation, e.g. `simulation.start` or a toolbar contribution ID. */
613
+ readonly operation: string;
614
+ readonly code: string;
615
+ readonly error: unknown;
616
+ }
617
+
556
618
  export declare interface IWorkbenchOptions {
619
+ readonly observability?: IFusedObservabilityOptions;
557
620
  readonly deviceStateProvider?: IDeviceStateProvider;
558
621
  /** Caller-owned browser context, automatically resumed on document-wide user gestures. */
559
622
  readonly audio?: IFusedAudioOptions;
@@ -562,6 +625,8 @@ export declare interface IWorkbenchOptions {
562
625
  readonly saveDocument?: (document: FusedDocument) => Promise<void>;
563
626
  readonly assetProvider?: IAssetProvider;
564
627
  readonly deviceProvider: IDeviceProvider;
628
+ /** Defaults to `compatible` when the device provider supports version resolution. */
629
+ readonly deviceVersionPolicy?: 'compatible' | 'locked';
565
630
  readonly programs?: ProgramSources;
566
631
  readonly accessProvider?: IWorkbenchAccessProvider;
567
632
  readonly viewBaseUrlTemplate: string;